Rooters, I already responded to following question, but I missed an important point. So, I'll answer this again. In following macro, WPmass function is used in a loop. ROOT/CINT interpreter automatically compiles loops into bytecode. In this case, the loop includes call to an interpreted function WPmass. Cint tries to compile the WPmass function. If it is successful, bytecode WPmass is used. However there are several limitations to bytecode compilation. In this case, having automatic objects of class 'TVector v1(1,4)' is caught as limitation. The interpreter should detect this limitation, stop bytecode compilation and interpret the fuction. If this works fine, everything is OK except it is slow. There was a bug in above senario which cause the problem you saw. I fixed this bug and it should work in future ROOT/CINT release. For the time being I give you a couple of workarounds. 1) Use '.O3' command to turn off bytecode compilation of function. root [0] .L TVfill.C root [1] .L WPmass.C root [2] .O3 root [3] .x exam2.C 2) Don't use automatic class objects in WPmass.C. Double_t WPmass (Float_t Pjetp[4][4]){ TVector *v1=new TVector(1,4); TVector *v2=new TVector(1,4); TVector *v3=new TVector(1,4); TVector *v4=new TVector(1,4); *v1=TVini4(Pjetp[0]); *v2=TVini4(Pjetp[1]); *v3=TVini4(Pjetp[2]); *v4=TVini4(Pjetp[3]); Double_t result = (TVMass4(v1+=v2)+TVMass4(v3+=v4))/2.: delete v1; delete v2; deleve v3; deleve v4; return result; } Masaharu Goto >Hi > >I have a lot of trouble with loops both with for-loop and with while-loop >using the root interpreter. It seams that thinks that work fine outside >a loop don't work inside. If I replace the loop by a goto it works fine. > >I have appended an example of the Problem. I have both the files and >a copy of the ROOT commands I gave and the output from ROOT. > > Raimund > >FILE :WPmass.C >------------------------------------------------------- >Double_t WPmass (Float_t Pjetp[4][4]){ > TVector v1(1,4); > TVector v2(1,4); > TVector v3(1,4); > TVector v4(1,4); > v1=TVini4(Pjetp[0]); > v2=TVini4(Pjetp[1]); > v3=TVini4(Pjetp[2]); > v4=TVini4(Pjetp[3]); > return (TVMass4(v1+=v2)+TVMass4(v3+=v4))/2.; >} >------------------------------------------------------- >--------------------------------------------------------------------------- >{ // exam2.C > Float_t Pjetp[4][4]; > Int_t nentries = 5; > for (Int_t i=0;i<4;i++){ > for (Int_t j=0;j<4;j++){ > Pjetp[i][j]=0; > } > } > mwp = new TH1F("mwp","w mass",100, 70., 90.); > cout << "t1" << endl; > mwp->Fill(WPmass(Pjetp)); > cout << "t2" << endl; > Int_t i=0; > > while ( i<nentries) { > i++; > mwp->Fill(WPmass(Pjetp)); // WPmass() is used in loop -> bytecode > cout << "t3 " << i << endl; > } >// if( i<nentries ) goto L100; >} >--------------------------------------------------------------------------- >root [0] .L TVfill.C >root [1] .L WPmass.C >root [2] .x exam2.C
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:33 MET