TClonesArray within an class that is a member of an event

Hi all.

I am having a problem getting the member variables of the objects in my TClonesArray to be written to file properly. When I open my output root file and browse to those member variables, they are always set to zero! The number of entries is correct, but the value is always zero.

I am using root v5.26 on mac os x.

Here’s a simple explanation:

EventBase {
 var1
}

Event : EventBase {
 var2
 SystemRecord fSysRecord;
}

SystemRecord {
 var3
 TClonesArray *fSubRecords; 

}

SubRecord : TObject {
 var4
 var5
}

//then i have a standard fill tree routine
fillEvent {
 TFile f("out.root");
 TTree *t = new TTree("T","mytree");
 Event *e = new Event();
 t->SetBranchAddress("EventBranch", &e, 32000, 99);
 
 forloop {
   e.fSysRecord.ClearClonesArrays(); //which calls fSubRecord->Clear("C")
   e.var1 = randomNumber
   e.var2 = randomNumber
   e.fSysRecord.var3 = randomNumber
   SubRecord *mSub = e.fSysRecord->AddSubRecord();
   mSub->var4 = randomNumber
   mSub->var5 = randomNumber
   t->Fill();
   
  }
  
  t->Write();
  f.Close();
  delete e;

In my output root file the values of var4 and var5 are always zero. But the values of var1, var2, var3 are written correctly.

In my code, If I “remove” the SystemRecord class and have the following structure, it works exactly as expected. So the problem occurs when I put the TClonesArray in SystemRecord. For example, the following works and I see all of the vars correctly in my output file.

EventBase {
 var1
}

Event : EventBase {
 var2
 TClonesArray *fTypeASubRecords; 
 TClonesArray *fTypeBSubRecords;
}


TypeASubRecord : TObject {
 var4
 var5
}

TypeBSubRecord : TObject {
 var6
 var7
}

As you can see, I’ve indicated that I’ve convinced myself that I can add any number of TClonesArrays at the Event level.

Okay. Any ideas? Thanks in advance.

Adam

Hi,

do you use ClassDef in the classes deriving (directly or indirectly) from TObject? Do they have dictionaries?

Cheers, Axel.

Hi,

One of the important part is how did you implement AddSubRecord?

Philippe.

Hi. Thanks for your replies.

Yes, I use ClassDef and I build a dictionary using rootcint.

AddSubRecord looks like this

SubRecord* Event::AddSubRecord()
{
	TClonesArray &mArrayRef = *mArray;
	SubRecord* mNewSubRecord = new(mArrayRef[mCount++]) SubRecord();
	return mNewSubRecord;
}

which, I am sure, is like in the example.

Like I said, I can fill the objects in TClonesArray and write out the values in the second scenario where the TClonesArray pointers are not contained within my SystemRecord class.

I can reproduce my problem by adding a SystemRecord class to the example in $ROOTSYS/test.

Attached is my code. When I compile and then run Event, the resulting output root file shows the same problem. The members in the SystemRecord branch (fSysRec) are always set to zero.

Thanks,
Adam
Rootsys_test_Event.zip (11.7 KB)

Correction to my last post: I meant to say that the members in the SubRecord branch are always zero! :slight_smile:

Adam

Hi Adam,

I can not reproduce your problem. I download your zip file, overlaid it into $ROOTSYS/test, did make Event and ran ./Event 100 and then did:[code]poire:test pcanal$ root.exe -l -b Event.root
root [0]
Attaching file Event.root as _file0…
Warning in TClass::TClass: no dictionary for class Event is available
Warning in TClass::TClass: no dictionary for class EventHeader is available
Warning in TClass::TClass: no dictionary for class SystemRecord is available
Warning in TClass::TClass: no dictionary for class Track is available
root [1] T->Scan(“fSysRec.fTracks.fNpoint”)


  • Row * Instance * fSysRec.f *

  •    0 *        0 *        64 *
    
  •    0 *        1 *        61 *
    
  •    0 *        2 *        65 *
    
  •    0 *        3 *        64 *
    
  •    0 *        4 *        66 *
    
  •    0 *        5 *        64 *
    
  •    0 *        6 *        65 *[/code]which shows non-zero value in fSysRec ....
    

Cheers,
Philippe.

hmmm… well, its the values in the fSubRecord objects that are in TClonesArray that are the problem.

If you open up the file and click through with a TBrowser do you see non-zero values in the data stored in the fSubRecord?

Thanks again,
Adam

Ugg… Sorry, I’m confusing my code. There is no SubRecord in my latest example… just

Event {

SystemRecord {
TClonesArray *fTracks
}

}

Anyways, so, when I do exactly what you do I see all zeros. Totally weird.

root [0] TFile f("Event.root")
Warning in <TClass::TClass>: no dictionary for class Event is available
Warning in <TClass::TClass>: no dictionary for class EventHeader is available
Warning in <TClass::TClass>: no dictionary for class SystemRecord is available
Warning in <TClass::TClass>: no dictionary for class Track is available
root [1] T->Scan("fSysRec.fTracks.fNpoint")
***********************************
*    Row   * Instance * fSysRec.f *
***********************************
*        0 *        0 *         0 *
*        1 *        0 *         0 *
*        2 *        0 *         0 *
*        3 *        0 *         0 *
*        4 *        0 *         0 *
*        5 *        0 *         0 *
*        6 *        0 *         0 *
*        7 *        0 *         0 *
*        8 *        0 *         0 *
*        9 *        0 *         0 *
*       10 *        0 *         0 *
*       11 *        0 *         0 *
*       12 *        0 *         0 *
*       13 *        0 *         0 *
*       14 *        0 *         0 *

Hey. My row and instance columns are different from yours. ??

Adam

ps - mac os 10.6.2 and root 5.26.00 – no patches.

Hi,

Ah … [quote]and root 5.26.00 – no patches.[/quote]this was the missing piece of information :slight_smile:. This problem has been fixed a few days ago in revision 32772 of the trunk (and today in the patch branch of v5-26).

Cheers,
Philippe.