Default value for transient data member

(root 5.34/09)

Hello-

I have a tree with a branch defined by my own custom class SimEvent, and it has the following member:


Settings* settings; //! transient

This pointer is set in the constructor, and can also be set with a setter. I would expect that since this member is transient, when I call TTree::GetEntry in my Analoop it would not be affected. This is in fact not the case, calling GetEntry fills the members defined in the class and saved in the TTree, but it also obliterates transient members (see snippet below). How can I get the default value of a transient data member to persist when calling GetEntry?

// In Analoop::Process cout << hex << "before: "<< (unsigned long long)simevent->settings << endl; fChain->GetTree()->GetEntry(entry); cout << hex << "after: "<< (unsigned long long)simevent->settings << endl;

  -- output --                     

(First call to Analoop::Process)
before: 24ab1f0
after: 0

(Second call to Analoop::Process)
before: 0
after: 0

(Nth call to Analoop::Process)
before: 0
after: ffffffff

Hi,

Usually the value is untouched during reading, however it really depends on the data model and there are also many cases (value held by pointer, most collections) where there is no choice but to recreate a new object (in which case the value should always return to the one set by the default constructor).

Cheers,
Philippe.

Can you describe for me a model in which the object is not (re)constructed – so that the default value of the transient member persists? The default constructor does not sufficiently build the class structure at runtime and dynamically rebuilding the SimEvent object each event is inefficient.

Thanks

Hi,

In the following example:Event *e = nullptr; tree->SetBranchAddress("event.",&e); for(Long64_t entry = 0; entry < tree->GetEntries(); ++entry) { } The Event object is not reconstructed (unless explicitly deleted by the user) during the reading. Any subobject of Event would also not be reconstructed. Objects held by pointer by Event would be reconstructed. Things held in a TClonesArray would not. Things in a STL collection are likely to be reconstructed.

Cheers,
Philippe.