Re: [ROOT] Storing not event related objects in a TTree

From: Axel Naumann (naumann@hef.kun.nl)
Date: Tue Aug 27 2002 - 13:13:45 MEST


Hi,

this is kind of a recurring problem (see also "I have some static var, 
and I don't want that to be stored in each event"). I can think of two 
possible solutions for that, as long as MyParameter derives from 
TObject. I believe I've even used both of them once...
a) Create a class MyWorld that contains both your TTree and some 
container of MyParameter objects. 
b) If you store the TTree in a file, also store a container of 
MyParameters in this file.

In the MyEvent objects which are stored in TTree, store TRefs to 
MyParameter objects instead of MyParameter*s. If you don't have a good 
reason for choosing option b), use option a) - in my point of view it's 
much "cleaner" (expandable, TBrowsable, thread-safe, independent of open 
files, error handeling is far easier etc).

By the way: If your parameter set is the same for the whole tree you 
obviously don't need a _container_ of MyParameter objects. You don't 
even need to store the TRefs (i.e.: you don't need to store any 
reference to a MyParameter object in MyEvent), instead you should write 
a MyEvent::GetParameter which retrieves the one and only parameter set 
(case a: forward to some MyWorld::GetParameter(), case b: make 
MyParameter a singleton, which reads itself once from MyWorld's 
TTree::GetFile()).

Hope that works and helps,
Axel.

Ole Streicher wrote:

>Hi!
>
>Sorry for filling the list up with questions ;-)
>
>How can I store objects in a TTree which are not local to an event?
>Example: I have a class that stores a set of parameters and a class
>that stores the event.
>
>class MyParameter {
> private: 
>  int p1[10000];
>//...
> ClassDef(MyParameter,1)
>};
>
>class MyEvent {
> private:
>  MyParameter* par;
>  MyTrack *track;
>//...
> ClassDef(MyEvent,1)
>};
>
>Now, I have two Parameter sets "MyParameter par1, par2;", and I want 
>-- based on some algorithm -- to put into my event either a link to
>par1 or par2. The problem here is that I want ofcourse not the
>complete parameter set to be stored in each event, but each different
>parameter set should be stored only once.
>
>How do I do that? I found no option that allows me to distinguish
>between data that are stored within each event (like the track in the
>example above) and which are stored only once.
>
>Ole
>
>
>
>



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