Hi Christian,
Thanks for the remark. I have added comments in the TLeaf::GetValue
functions in the current version in CVS.
Rene Brun
On Mon, 9 Sep 2002, cstrato wrote:
> Dear Rene
>
> Thank you for this explanation. Maybe, it could be mentioned
> in the class reference for TLeaf, that the argument should only
> be used in case of an array.
>
> Best regards
> Christian
>
>
> Rene Brun wrote:
>
> > Hi Christian,
> >
> > The basic I/O transaction is at the branch level, not the leaf level.
> > One branch has one buffer only for all leaves. Reading one leaf
> > implies reading the complete branch.
> > If, in your code, you replace:
> > output << name->GetValue(i) << sep
> > << num->GetValue(i) << endl;
> > by
> > output << name->GetValue(0) << sep
> > << num->GetValue(0) << endl;
> > or simply
> > output << name->GetValue() << sep
> > << num->GetValue() << endl;
> > you will get the right answer. You should use the argument
> > only in case the leaf is an array and you want to retrieve
> > the jth element of the array.
> >
> > why not TBranch::GetLeafEntry(entry, leafname)?
> > It would be very inefficient to do string manipulation
> > at each entry.
> >
> > Rene Brun
> >
> >
> >
> > On Sun, 8 Sep 2002, cstrato wrote:
> >
> >
> >>Dear Rooters
> >>
> >>Suppose, that I have filled tree(s) with one branch for:
> >>class MyClass: public TObject {
> >> TString fName;
> >> Int__t fNum
> >> Double_t fValue1
> >> Double_t fValue2
> >>}
> >>
> >>The following example exports all leafes from one tree:
> >>void Export(const char *treename, const char *outname)
> >>{
> >> output << "Name" << "\t" << "Number" << "\t"
> >> << "Value1" << "\t" << "Value2" << endl;
> >>
> >> MyClass *myclass = 0;
> >> TTree *tree = (TTree*)gDirectory->Get(treename);
> >> tree->SetBranchAddress("MyBranch", &myclass);
> >>
> >> ofstream output(outname, ios::out);
> >> Int_t entries = (Int_t)(tree->GetEntries());
> >> for (Int_t i=0; i<entries; i++) {
> >> tree->GetEntry(i);
> >> output << myclass->GetName() << "\t"
> >> << myclass->GetNumber() << "\t"
> >> << myclass->GetValue1() << "\t"
> >> << myclass->GetValue2() << endl;
> >> }
> >> output.close();
> >>}
> >>
> >>Now I would like to expand this function in two ways:
> >>1, I want to export selected leafes only, e.g.
> >> Export("mytree", "outname", "fNum:fValue2")
> >>2, I want to export selected leaves from all trees in a file, e.g.
> >> Export("*", "outname", "fValue1")
> >>
> >>ad 1) Export selected leafes:
> >>I could simply do: if("fNum") myclass->GetNumber(), but:
> >>analogously to be able to read selected branches, is there
> >>a similar way to read selected leafes?
> >>I have tried the following but got a bus error:
> >> MyClass *myclass = 0;
> >> TTree *tree = (TTree*)gDirectory->Get(treename);
> >> TBranch *branch = 0;
> >> branch = tree->GetBranch("MyBranch");
> >> if (branch) branch->SetAddress(&myclass);
> >>
> >> TLeaf *name = branch->GetLeaf("fName");
> >> TLeaf *num = branch->GetLeaf("fNum");
> >> Int_t entries = (Int_t)(tree->GetEntries());
> >> for (Int_t i=0; i<entries; i++) {
> >> branch->GetEntry(i);
> >> output << name->GetValue(i) << sep
> >> << num->GetValue(i) << endl;
> >> }
> >>What is wrong with this code, and how can I read selected leafes?
> >>It would be great if there would be a function such as
> >>TBranch::GetLeafEntry(entry, leafname)?
> >>
> >>ad 2) Export chains of trees
> >>I could try to loop over all trees in TFile, but the question
> >>is if there is a simpler and more elegant way to do it, where
> >>I could take advantage of TChain or of tree friends?
> >>
> >>Thank you in advance for your help.
> >>
> >>Best regards
> >>Christian
> >>_._._._._._._._._._._._._._._._
> >>C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
> >>V.i.e.n.n.a A.u.s.t.r.i.a
> >>_._._._._._._._._._._._._._._._
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:09 MET