[ROOT] speed problem for unexecuted statements

From: Peter Shanahan (shanahan@fnal.gov)
Date: Sun Feb 08 2004 - 21:29:48 MET


Dear Rooters,

     I have a strange speed problem with an unnamed macro.  I am
looping over the bins in a TH2C, getting the contents, and doing
various things based on them, mainly plotting other histograms.  I find
that the execution is very slow, even for cases where each of the "if
(stat&...) shown below are false. (I've verified this with print
statements, watching how long it takes to get to the next bin in the
histogram.)

    I've removed the actual code inside the if{} blocks below for sake of
brevity, but I find that just removing a reference to gPad
(SetLogx(0 or 1)) within each of the if blocks speeds up the execution by
factors of 10.  I need the gPad reference to set log/non-log depending on
the case.

    Does someone know:

     1) why does the performance speed depend on the presence or absence
        of statements that don't get executed because they are inside
        false if statements?  Is it some interpreter optimization that
        tries to determine whether the state of gPad has changed?

     2) is there something I can do about it?   Many thanks,

Peter Shanahan


{

	TH2C* ChanStatus=(TH2C*)f.Get("ChanStatus");

	TCanvas* myCanvas=new TCanvas();
	gPad->SetLogx(0);
	Bool_t doRandoms=false;
	Bool_t doBadRes=true;
	Bool_t doBadRms=true;
	Bool_t doBadPed=true;

	for (Int_t ix=40; ix<=140; ix++)
	{
		Int_t jx=ix-1;
		for (Int_t iy=1; iy<=40; iy++)
		{

			Int_t jy=iy-1;
			Char_t stat=ChanStatus->GetBinContent(ix,iy);
			Int_t crate=jx/48+(jy/32)*4;
			Int_t module=(jx%48)/4;
			Int_t masterch=7-(jy%32)/4;
			Int_t minderch=jx%4+(jy%4)*4;
			cout << ix <<" "<<iy<<" "<<(Int_t) stat<<endl;

			if (stat&1 && doRandoms)
			{
				cout << "stat 1"<<endl;
			} // if Random

			if (stat&2 && doBadRes)
			{
				cout << "stat 2"<<endl;
			} // if badres

			if (stat&4 && doBadRms)
			{
				cout << "stat 4"<<endl;
			} // if Rms

			if (stat&8 && doBadPed)
			{
				cout << "stat 8"<<endl;
			} // if badped

		}  // iy

	}  // ix


	delete myCanvas;
	myCanvas=0;


}


=======================================================================
  Fermilab MS-220                            Phone: (+1) 630 840 8378
  P.O. Box 500                               Fax:   (+1) 630 840 6039
  Batavia, IL 60510 USA



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET