RE: [ROOT] Overlapping TObjects?

From: Simon Dean (sdean@hep.man.ac.uk)
Date: Thu Apr 04 2002 - 00:48:10 MEST


To answer your questions..............

On Wed, 3 Apr 2002, Philippe Canal wrote:

> Hi Simon,
> 
> Theoritically, since you create a new object and do set the value to 0,
> it should still be zero at the end of the constructor.  However (and I
> do not have enough information to guess properly) there are many situations
> were this could happen, all depend on your actual code.  Some of this 
> situations included one where the pointer you are using is not refreshed to
> the new address, some other objects has kept a pointer to the old object
> (eventhough it was deleted) and is using it and writing stuff in it,
> or the constructor is not executed eventhough you thought it should, etc........
> 
> More concretely, how do you destroy the object, how do you create the
> new object, how do you check/print the new value.

In my program, I maintain a pointer called fSdaq. First I do:

fSdaq = new SDAQ(runnumber, fCanvas, fCrateMap);

then later on, I do

delete fSdaq;

followed by the same 'new' command (the arguments have changed by this
time):

fSdaq = new SDAQ(runnumber, fCanvas, fCrateMap);

Now, the way I check values is to insert strategic output comands in the
source code. The following code shows where I make this output:

SDAQ::SDAQ()
{
  (other integers set to zero here)
  numHDI              = 0;
  cout << "numHDI is " << numHDI << " at end of constructor" << endl;
}

SDAQ::SDAQ(Int_t run, TCanvas *canvas = 0, Cratemap *cratemap = 0)
{
  if (canvas) fCanvas = canvas;
  if (cratemap) fCrateMap = cratemap;
  cout << "numHDI is " << numHDI << " before default constructor" << endl;
  SDAQ(); // <--------Default constructor
  cout << "numHDI is " << numHDI << " after default constructor" << endl;
  fillRuns(run);
}

when running, my program gives (amongst other stuff) the following output 
after deleting a SDAQ with numHDI=70 and making a new one (as desribed
above):

numHDI is 70 before default constructor
numHDI is 0 at end of constructor
numHDI is 70 after default constructor



> Cheers,
> Philippe.
> 
> PS. A priori the ROOT system does not hold any information about your
> object and should not be a factor in this situtation ....

cheers,

Simon

PS...	The problem is pseudo-solved by setting all of the previous
	SDAQ's values to zero in the destructor. This is an unnerving
	solution, however.... :)



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:48 MET