Re: [ROOT] cannot create object of class TIter

From: 0ndrej Chvala (ondrejch@gw.amu.cz)
Date: Thu Oct 16 2003 - 15:16:31 MEST


Hi Axel and other root masters :)

thanks for explanation, now I understant.
It might be a good idea to add this info (interrators cannot be saved 
into TFile and here's how to deal with it) into Chapter14 of the 
UserGuide. I found some notice about "//!" in the chaper about IO (page 
174, UG ver 3.05), however even from that I would not decode that it 
concerns iterrators and how....

thanks for the great root (the more I know it the more I appreciate the 
developers...) and excellent support
cheers
0ndrej

>The important part is the "!" after the comment, which tells root not to
>save this member. The other puzzle: if you create a TFile beforehand, root
>will use that to cache / auto-save whatever tree you're dealing with - i.e.
>it will try to write that tree to file, and it will fail because one of your
>classes has a TIter member.
>
>Adding //! will prevent root from taking this member into account when
>writing (you mark that member as non-persistent), and now you can place your
>file creation wherever you want.
>
>Axel.
>
>
>  
>
>>-----Original Message-----
>>From: owner-roottalk@pcroot.cern.ch
>>[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of 0ndrej Chvala
>>Sent: Wednesday, October 15, 2003 8:01 PM
>>To: Philippe Canal; roottalk@pcroot.cern.ch
>>Subject: Re: [ROOT] cannot create object of class TIter
>>
>>
>>Hi Philippe,
>>
>>Thanks for explanation, I just found that if I do not create the TFile
>>beforehand, it sudenly works, which puzzled me.
>>However I do not understand how should I modify the class to allow
>>saving the data into a TFile - your code looks same as the original.
>>Should I write my own streamer without the fpart_iter?
>>
>>thanks for help, best regards
>>0ndrej
>>
>>Philippe Canal wrote:
>>
>>    
>>
>>>Hi Ondrej,
>>>
>>>A TIter object can not be saved onto a file (hence the system
>>>      
>>>
>>you not even
>>    
>>
>>>try to look it up).
>>>As a workaround (and a clarification of your code anyway, just
>>>      
>>>
>>modify your
>>    
>>
>>>class as follow:
>>>
>>>  TClonesArray *fParticles; // Array with particles
>>>  TIter *fpart_iter;                 //! caching the current ptr to
>>>iterator
>>>
>>>-----Original Message-----
>>>From: owner-roottalk@pcroot.cern.ch
>>>      
>>>
>[mailto:owner-roottalk@pcroot.cern.ch]On
>  
>
>>Behalf Of 0ndrej Chvala
>>Sent: Wednesday, October 15, 2003 7:05 AM
>>To: roottalk@pcroot.cern.ch
>>Subject: [ROOT] cannot create object of class TIter
>>
>>
>>Dear rooters,
>>
>>I have 2 classes, one describes an event and the other a track in that
>>event. The event contains a TClonesArray with the tracks and the iterrator:
>>
>>   TClonesArray *fParticles;            // Array with particles
>>   TIter *fpart_iter;                   // ptr to iterator
>>
>>When an new event is created, the TClonesArray is created:
>>
>> fParticles = new TClonesArray("TBigDSWriteParticle",1000);
>> fpart_iter = new TIter(fParticles);
>>
>>The classes can be compiled, loaded into root runtime, but when I try to
>>make a branch, it complaints:
>>root [0] .L /cern/root/lib/libEG.so
>>root [1] .L /cern/root/lib/libPhysics.so
>>root [2] .L ../lib/libmicro.so
>>root [3]   TFile *tfile= new TFile("/tmp/dsttest.root","RECREATE");
>>root [4]   TTree *tft = new TTree("tft","");
>>root [5]   tfile->SetCompressionLevel(2);
>>root [6]   TBigDSWriteEvent *myevent=new TBigDSWriteEvent();
>>root [7]   TBigDSWriteParticle *mypart;
>>root [8]
>>tft->Branch("TBigDSWriteEvent","TBigDSWriteEvent",&myevent,5000000,1);
>>Error in <TClass::New>: cannot create object of class TIter
>>
>>The source codes are atached.
>>
>>Any help is greatly welcomed, I already tried to use other container
>>objects (TList, TObjArray), asked whom I can around but I'm still stucked.
>>
>>Thank you
>>0ndrej Chvala, NA49 << File: TBigDSWriteEvent.h >>  << File:
>>TBigDSWriteParticle.h >>  << File: TBigDSWriteEvent.cxx >>  << File:
>>TBigDSWriteParticle.cxx >>
>>
>>
>>
>>    
>>
>
>
>
>  
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET