Hi Steve,
See the additional line added in your function B::Address.
One must call TTree::SetMakeClass when the original Tree was created
with a top level branch being a class and you want to read only
a subset of the tree without given the address of the top level branch.
This is the case for the code generated by TTree::MakeClass.
In your case, you could have generated the code with T13.MakeClass("myClass").
You will see that the function myClass::Init includes a call to
fChain->SetMakeClass(1);
Rene Brun
Steve Udriot wrote:
>
> Hello,
>
> I have a problem while retrieving data from a TChain (root v.3.03/02). I
> appended a macro which illustrates it.
>
> The addresses where to retrieve the data are those of data members of an
> object (class A) initialized in the class responsible for handling the
> TChain (class B which is a friend of A). There are two data members in
> the example macro.
>
> The problem is that I cannot retrieve both data in the same time. I can
> retrieve one, as long as I put into comments the statement
> fChain->GetBranch("branchname") of the other one and reversely.
>
> Thank you in advance for your help,
>
> Steve
>
> class A {
> private:
> int fRun;
> int fBurst;
>
> public:
> A() { }
> ~A() { }
>
> const int GetRun() { return fRun; }
> const int GetBurst() { return fBurst; }
>
> friend class B;
> };
>
> class B {
> private:
> TChain *fChain;
>
> TBranch* fRunBranch;
> TBranch* fBurstBranch;
>
> A fA;
>
> public:
> B() : fChain(0), fRunBranch(0), fBurstBranch(0) { }
> ~B() {
> if fChain {delete fChain; fChain = 0;}
> fRunBranch = 0;
> fBurstBranch = 0;
> }
>
> void Chain();
> void Address();
> void RetrieveAt(const int);
> void Close();
> void Print();
> };
>
> void B::Chain() {
> if (!fChain)
> fChain = new TChain("T13");
> fChain->Add("./h4p11212.root");
> fChain->Add("./h4p11229.root");
> }
>
> void B::Address() {
> if (fChain == 0)
> return;
>
fChain->SetMakeClass(1); //<==========NEW LINE
> fChain->SetBranchAddress("fRunNum", &fA.fRun);
> fRunBranch = fChain->GetBranch("fRunNum");
>
> fChain->SetBranchAddress("fBurstNum", &fA.fBurst);
> fBurstBranch = fChain->GetBranch("fBurstNum");
> }
>
> void B::RetrieveAt(const int entry) {
>
> if (fRunBranch)
> fRunBranch->GetEntry(entry);
>
> if (fBurstBranch)
> fBurstBranch->GetEntry(entry);
> }
>
> void B::Close() {
> fRunBranch = 0;
> fBurstBranch = 0;
> fChain->Reset();
> }
>
> void B::Print() {
> cout << "Run : " << fA.GetRun() << endl
> << "Burst : " << fA.GetBurst() << endl;
> }
>
> int main() {
>
> B aB;
> aB.Chain();
> aB.Address();
> aB.RetrieveAt(1500);
> aB.Close();
> aB.Print();
>
> return 0;
> }
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:48 MET