RE: [ROOT] how to get array from TLeaf

From: Philippe Canal (pcanal@popgtw.fnal.gov)
Date: Tue Aug 15 2000 - 18:57:34 MEST


Hi Valentin,

I tried your example on ROOT v2.25/01 and have no problem with it 
(beside a few possible typos and omitions).

>   TBranch* B_GTRACK = chain->GetBranch("GTRACK");
>   B_GTRACK->Print();
>   TLeaf* TL_ngtrk = B_GTRACK->GetLeaf("ngtrk");

before grabbing the values, you have to load the date in memory

    Int_t the_entry_i_want = 3;
    B_GTRACK->GetEntry( the_entry_i_want );

>   Float_t ngtrk = TL_ngtrk->GetValue();
>   cout << "ntrk = " << B_GTRACK->GetLeaf("ngtrk")->GetValue(1) << endl;

here I changed it to

   cout << "ntrk = " << B_GTRACK->GetLeaf("ngtrk")->GetValue() << endl;

or in your case simplier:

  cout << "ntrk = " << ngtrk  << endl;

Then I to output the array either:

   cout << "qoverpt[0]" << B_GTRACK->GetLeaf("qoverpt")->GetValue(0) << endl;
   cout << "qoverpt[1]" << B_GTRACK->GetLeaf("qoverpt")->GetValue(1) << endl;

or 

   TLeaf *TL_qoverpt = B_GTRACK->GetLeaf("qoverpt");
   cout << "qoverpt[0]" << TL_qoverpt->GetValue(0) << endl;
   cout << "qoverpt[1]" << TL_qoverpt->GetValue(1) << endl;

or 

   Float_t * qoverpt = B_GTRACK->GetLeaf("qoverpt")->GetValuePointer();
   cout << "qoverpt[0]" << qoverpt[0] << endl;
   cout << "qoverpt[1]" << qoverpt[1] << endl;


In any case, I would recommend that instead of this, You go through the
TTree::MakeClass (or MakeCode) facility, it would take care of all this
setup for you.

Philippe.



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:31 MET