Newbie Tree question

Hello,

I have a rather newbie-ish question, which may be more a result of my general programming ignorance rather than a ROOT-specific question…

I am attempting to fill a TTree with homemade objects that are descendents of TObject (as in Example 4 in Chapter 12 of the Users Guide) – essentially a simplified version of the example Event class.

So it’s something like this:

[code] class MCNPHistory : public TObject {

private:
Int_t fNHist; // history number
Int_t fNEvent; // number of events in history
TClonesArray *fEvents; //-> array of PTRAC events for this history
MCNPHeader *fHeader; // Info that is the same for each history
[/code]

The member MCNPHeader is another TObject derived class that just has a few arrays in it:

class MCNPHeader : public TNamed { private: Int_t fN[20]; // the N's Int_t fL[12][30]; // the L's time_t ftime; // time of the run deque<float> fKeywordEntries[13];

This header information is the same for each entry in the TTree.

Right now when I fill the TTree and then write the tree to a file, it looks like the MCNPHeader gets written for each tree entry. For only 10000 entries, the fHeader branch seems to be rather large:

*............................................................................* *Br 6 :fHeader : * *Entries : 10000 : Total Size= 17336480 bytes File Size = 629898 * *Baskets : 277 : Basket Size= 64000 bytes Compression= 27.44 * *............................................................................*

I thought since I was using a pointer to the MCNPHeader in my MCNPHistory class that it would get written only once, but that seems not to be the case. Is there a way to do this so the header gets written only once? I’d like to keep the header as a member of MCNPHistory since some of the methods need information from the header.

Thank you very much for your help

I forgot to say that I’m doing this with root version 4.00/08

[quote]I thought since I was using a pointer to the MCNPHeader in my
MCNPHistory class that it would get written only once,[/quote]
Nope. The fact that you refer to the object by pointer does not tell the system that you object in invariant from entry to entry (for example you refer to the TClonesArray also by pointer!).

You will need to declare the pointer to be transient:

MCNPHeader *fHeader;   //!  Info that is the same for each history 

and store the pointer in the TTree list of User info

tree->GetUserInfo()->Add(fHeader);

(this is available in ROOT 4.00/04 and above)

Cheers,
Philippe

deque<float>    fKeywordEntries[13];

Are you sure you want 13 deques? Or do you want a deque with 13 elements?