[ROOT] problem in streaming TClonesArray in 3.03/9 - 2nd witness

From: Paul Balm (r45@nikhef.nl)
Date: Wed Nov 20 2002 - 10:09:16 MET


  Hello,

I have seen this problem as well in root 3.03/09 on Linux RH6, in a 
slightly different situation.
I have a class called TVertex, deriving from TVector3 (the vertex 
position). TVertex contains a TLorentzVector, which in turn also 
contains a TVector3. So I have a class (TVertex) deriving from TVector3 
and, through TLorentzVector, also containing a TVector3.
I have spent quite a bit of time trying to isolate this problem, but 
eventually gave up. I have appended my macros to read and write someting 
from/to a file below, perhaps Wouter can compare and see what he is 
doing differently.
I don't think the specific implementation of the TVertex class is 
relevant (other than what I explained above), but you could have a look 
at it at http://www.nikhef.nl/~r45/root

Thanks,

Paul

---------------------------------------
void write_tree() {

TFile tf("test_lv.root","recreate");
TTree* tt = new TTree("a_tree","see if I can write this tree"); 
TClonesArray* clarr = new TClonesArray("seed::TVertex",4);
tt->Branch("thearray",&clarr, 32000, 0); // case C in TTree doc

seed::TVertex* vtx=new ((*clarr)[0]) seed::TVertex();
seed::TTrack trk;
trk.SetPxPyPzE(1,2,3,4);
vtx->SetParentTrack(trk);
cout << "storing a vertex with a mas of "<<vtx->GetMass() << endl;
cout << "momentum: ("<<vtx->GetLorentzVector()->Px()<< ", "
     << vtx->GetLorentzVector().Py() << ", "
     << vtx->GetLorentzVector().Pz() << " )"<<endl;
cout << "array has "<< clarr.GetEntries()<<" entries"<<endl;

 tt->Fill();
tt->Write();

tf.Close();

}


void read_tree() {

TFile tf2("test_lv.root");

 TTree* tt = tf2->Get("a_tree");
 TClonesArray* clarr = new TClonesArray("seed::TVertex",5);
 cout << "Got TClonesArray at "<<clarr<<endl;
 tt->SetBranchAddress("thearray",&clarr);

 cout << "Got TClonesArray at "<<clarr<<endl;
 cout << "It has "<<clarr->GetEntries()<<" entries. Getting first tree 
entry now"<<endl;
 tt->GetEntry(0);
 cout << "Got it. Array now has "<<clarr->GetEntries()<<" entries."<<endl;
 
 seed::TVertex* vtx2;
 if(clarr) vtx2 = (seed::TVertex*) (*clarr)[0];
 else {
   cout << "Got null for clarr"<<endl;
   return;
 }

cout << "got vertex at "<<vtx2<<endl;
cout << "this vertex has a mass of "<<vtx2->GetMass()<<endl;
cout << "momentum: ("<<vtx2.GetLorentzVector().Px()<< ", "
     << vtx2.GetLorentzVector().Py() << ", "
     << vtx2.GetLorentzVector().Pz() << " )"<<endl;
}


> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Wouter Hulsbergen
> Sent: Tuesday, November 19, 2002 7:06 PM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] problem in streaming TClonesArray in 3.03/9
>
>
>
> Dear developers,
>
> I have an event class which contains a TClonesArray of objects of type B,
> derived from type A. Type B also contains an object of type A:
>
> class A : public TObject
> {
> }
>
> class B : public A
> {
> private:
>   A _anA ;
> }
>
> class Event
> {
> private:
>   TClonesArray* theAs ;
>   TClonesArray* theBs ;
> }
>
> Processing the tree with tree->GetEvent(i) in a macro in interactive root,
> I found something strange:  The TClonesArray `theAs' and `theBs' are
> properly filled, except for one thing: The branches containing the
> elements `B::_anA' are all empty (zero).
>
> If I use the TBrowser to browse through the elements `B::_anA', they are
> not zero, but instead take the values that are given to the corresponding
> elements in B itself (derived from A). So something is really mixed
> up.
>
> I am sure that the elements are properly set before the ClonesArray is
> streamed. However, I cannot check that the TClonesArray is properly
> written to file, since I do not know how to implement a private Streamer
> in 3.03/09: The Streamer that I have written is not called.
>
> What could be wrong?
>
> Thanks and best regards,
> Wouter
>
>



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