Hi Gene, I suspect you do not load the class definition of the StGG class. You are splitting the object by setting the split-level (the last parameter) to 1. >m1->Branch("br1","StGG",&v1,64000,1); This will create a branch for each data member of the StGG class, and allows you to directly access any of them by typing: >m1->Scan("val1"); To make Scan work with the class and method name you will have to load the class definition. > m1->Scan("br1.Val()"); For example to use the event methods on the Event.root file in the $ROOTSYS/test directory, you have to load the libEvent.so to make the Event class available: >.L libEvent.so > TFile f("$ROOTSYS/test/Event.root") > T->Scan("event.GetTemperature()") It looks like your allocation of an instance, causes the class to laod. Try making an instance, and then try: m1->Scan("br1.Val()"); >If I actually allocate an instance of the class, >set the TTree branch address to it, and then >call GetEvent() on the TTree, then the member >functions work correctly on the instance of >the class... Cheers, Suzanne -----Original Message----- From: Gene Van Buren <gene@bnl.gov> To: roottalk@pcroot.cern.ch <roottalk@pcroot.cern.ch> Date: Wednesday, March 08, 2000 10:28 AM Subject: Using stored class member funcs in TTrees >Hi - I'm wondering if there's something special >I need to do in order to be able to use member >functions of a class I store with a TTree in the Draw() >or Scan() functions of the TTree??? > >I'm using Root 2.23/12. > >I have tried storing a class (StGG) with just four members; >a function Gene() wihich returns the float 3.5 >a float data member val1 >a function Val() which returns val1 >a function Add() which adds 1.0 to val1 > >When I store a bunch of these in a TTree, save it >to a file, and then look at the TTree in the file: >All the values of val1 appear to be correct, >but both Gene() and Val() return garbage. > >I store the class in a macro like this: > >{ >gSystem->Load("..."); >TFile a1("gg.root","RECREATE"); >StGG* v1 = new StGG(); >TTree* m1 = new TTree("myTree","This is my tree"); >m1->Branch("br1","StGG",&v1,64000,1); >for (int i=0; i<25; i++) { > v1->Add(); > m1->Fill(); >} >a1.Write(); >a1.Close(); >} > >I then read it back into memory in another Root >session: > >gSystem->Load("..."); >TFile a1("gg.root"); >TTree* m1 = (TTree*) a1.Get("myTree"); > >If I type: >m1->Scan("val1"); >everything looks like I expect. But if I type >m1->Scan("br1.Val()"); >or >m1->Scan("br1.Gene()"); >all 25 values come out as zero or garbage. >Scan() doesn't even complain if I enter a >bogus member name - spits back >zeros or garbage also! Draw() at least >requires that I get the member name >correct (e.g., Draw("Val()") returns an >error, while Draw("br1.Val()") draws a hist >with 25 entries at zero). > >If I actually allocate an instance of the class, >set the TTree branch address to it, and then >call GetEvent() on the TTree, then the member >functions work correctly on the instance of >the class... > >...Just not in the Draw() and Scan() of the TTree. >Anyone know why? > >-Gene Van Buren > >
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET