[ROOT] Problem in retrieving Data from TChain

From: Steve Udriot (steve.udriot@cern.ch)
Date: Tue Apr 09 2002 - 10:35:23 MEST


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->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