Hi Oliver, TTree::MakeClass should be slightly modified in case of a TChain. You can, however, work with the code generated by MakeClass if you load the first event of the chain. In your case, the Root session could be: Root > .L bllac.C Root > .L MyClass.C Root > open_all("crab.root_list",... Root > con->LoadTree(0); //this is the important line Root > MyClass *ana = new MyClass(con) Root > ana->Show(10); Root > ana->Loop(); A better alternative is to add the following line in your MyClass.h file in the function MyClass::Init, after the statement: if (tree == 0) return; add the line if (tree->InheritsFrom("TChain")) ((TChain*)tree)->LoadTree(0); Rene Brun Oliver Mang wrote: > > Hi Rooters, > I'm having a problem with the class generated by MakeClass() and > initialization with a TChain. I start with a TChain object containing > several files and call MakeClass(). When I produce an object of this > class and start the Loop(), all branches (one leaf per branch) are read > as zeros. If I call TChain::Draw(), everything works as expected (i.e. > leaves are non-zero). > > Another oddity: I start root, read the Classfile, set up the TChain, but > when I initialize the ClassObject with the Chain, I get a segfault. If I > call the Draw()-function first, the Object is initialized !? > > ------------- start session log --------------------- > ifkpe1> root > ******************************************* > * * > * W E L C O M E to R O O T * > * * > * Version 2.22/09 19 July 1999 * > * * > * You are welcome to visit our Web site * > * http://root.cern.ch * > * * > ******************************************* > > CINT/ROOT C/C++ Interpreter version 5.14.9, Jul 17 1999 > Type ? for help. Commands must be C++ statements. > Enclose multiple statements between { }. > root [0] .L bllac.C // contains macro open_all() > root [1] .L MyClass.C > root [2] open_all("crab.root_list","bllac.root_list") // set up TChain > root [3] MyClass *ana = new MyClass(con) > > *** Break *** segmentation violation > Root > > root [4] con->Draw("len") > Warning in <MakeDefCanvas>: creating a default canvas with name c1 > root [5] MyClass *ana = new MyClass(con) > root [6] > [...] > root [8] ana->Loop() > Alpha: 0, > *** Break *** segmentation violation > Root > > ----------- end session log ------------------------ > > con is of type (TTree *) and points to the TChain. > The offending statement in MyClass::Loop() is obviously > b_alpha->GetEntry(i): > > ---- begin code snippet from MyClass::Loop() ---------- > for (Int_t i=0; i<nentries;i++) > { > nb = fTree->GetEntry(i); nbytes += nb; > cout << "Alpha: " << alpha << ", "; > b_alpha->GetEntry(i); > cout << alpha << endl; > } > ---- end code snippet -------------------- > > Any help is highly appreciated. > Regards, Oliver > -- > Oliver Mang > Institut fuer Experimentelle und Angewandte Physik, CAU Kiel > Phone: ++49/431/880-2482 E-Mail: mang@ifkhep.uni-kiel.de > --------------------------------------------------------------- > "The future is not what it used to be"
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:37 MET