Hi Robert, You may have missed that the TTree::Branch method has a default parameter indicating the 'split level' of the branch: virtual TBranch* Branch(const char* name, const char* classname, void* addobj, Int_t bufsize = 32000, Int_t splitlevel = 99) This split level indicate how many sub-branch should be built from the object. With split level 1, one branch is built per data member of your class (i.e. MyClass in your case). With split level 2, each of the data members are also decomposed (if they are classes). And so on. The default is 99 which means that your class is fully decomposed into its simpliest elements. This is also means that each of the data member is saved separately, thus bypassing your custom streamer. To ensure that your custom streamer is used, to set the split level to 0. mytree->Branch("test1", myclass->IsA()->GetName(), &myclass, 32000, 0); -----Original Message----- From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Robert Michaels Sent: Wednesday, July 24, 2002 2:58 PM To: roottalk@pcroot.cern.ch Subject: [ROOT] Customized Streamer for a TObject as TBranch ? Using root 3.01-06 on Redhat 6.2 Linux with kernel 2.2.19-6.2.7 (Ok, I should upgrade). I have a TTree which contains TBranch that holds a class MyClass which inherits from TObject. I want to customize the output by writing my own MyClass::Streamer() method, but for some reason I have not understood from various documentation my customized method does not get called. How can I fix this ? The following root scripts illustrate what "works" and what does "not work". By "work" I mean the MyClass::Streamer() is called. MyClass is loaded as a shared library in an interactive root session. { // This root script proves that MyClass::Streamer() is called TFile* f = new TFile("test.root","RECREATE"); MyClass* myclass = new MyClass(); myclass->Init(); for (Int_t i = 0; i < 20; i++) { myclass->Process(); myclass->Write(); } } { // This root script shows MyClass::Streamer() is NOT called. // But I want mytree to contain customized output from MyClass::Streamer MyClass* myclass = new MyClass(); TTree *mytree = new TTree("T", "test tree"); mytree->Branch("test1", myclass->IsA()->GetName(), &myclass); TFile* f = new TFile("test.root","RECREATE"); myclass->Init(); for (Int_t i=0; i < 20; i++) { myclass->Process(); mytree->Fill(); } } I think this is enough to illustrate, but in case you need to see MyClass and other details, see http://www.jlab.org/~rom/rootex1/streamex1.html (I didn't want to fill up everyone's mailbox.) Thanks ! ------------------------------------------------------ Robert W. Michaels www.jlab.org/~rom phone (757) 269 7410 pager (757) 584 7410 Thomas Jefferson National Accelerator Facility 12000 Jefferson Ave, Newport News, VA 23606 USA
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:01 MET