Hi Volker, With old versions of ROOT before 3.01, the default was to delete the object at the specified pointer address and to recreate a new object at each call to TTree::GetEntry. For example, if you had Event *event = 0; At the first call to GetEntry, a new Event object was created and pointed by event. At the second call, GetEntry was deleting event and recreating again a new object. This was the default behaviour unless you had called mybranch->SetAutoDelete(kFALSE); //default was kTRUE In version 3.01 and 02 I changed the default to be SetAutoDelete(kFALSE). This default is more efficient. It saves calls to the Event constructor. Instead of creating a new Event, TTree::GetEntry will reuse/overwrite the Event object pointed by event, such that the pointer event should have the same value for all events. If you want to obtain the old behaviour, you must call myBranch->setAutoDelete(kTRUE). Note that before overwriting the Event object, GetEntry "cleans" the previous instance in case it contains pointers to other objects dynamically allocated. If your class Event,eg, contains: MyClass *fObject; TObjArray *fArray; GetEntry will automatically call delete fObject; delete fArray; In the case of the TObjArray, the objects in the fArray will be automatically deleted if the array is the owner of the objects (See function SetOwner). If this is not the case, you should call a function like Event::Clear before reading the next entry or use the old behaviour by calling once myBranch->SetAutoDelete(kTRUE) to force a call to your Event destructor at each entry. Rene Brun Volker Hejny wrote: > > Hi all, > > there is one point concerning reading objects from a tree, which I'm > not sure about. In SetBrachAddress, I give the address of a pointer > variable. Does this mean, that the address of the object changes for > different events? In a modular analysis, is it enough to distribute > the pointer to object in the beginning or do I have to use the > address of the pointer for this purpose? > > Best regards, > Volker > > -- > Dr. Volker Hejny Tel: 02461/616853 ** > Institut f. Kernphysik Fax: 02461/613930 ** > ---------------------------------------------------------------- ** ** --- > Forschungszentrum Juelich GmbH, D-52425 Juelich **
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET