Hi,
There is a much simpler solution to your problem. I strongly recommend
you to read the tutorials on writing/reading Trees and the Users Guide.
In your particular example, you should only set the branch addresses
in your reading program and call TTree::GetEntry or TBranch::GetEntry.
For example:
treeRun->SetBranchAddress("run",&run.run);
treeRun->setBranchAddress("trig",run.trig);
...
for (int i=0;i<runList->GetN();i++) {
treeRun->GetEntry(runList->GetEntry(i));
cout <<"run.run=<<run.run<<", run.trig="<<run.trig<<endl;
}
The variables in your structure run will be filled automatically bt
treeRun->GetEntry(..
Rene Brun
On Tue, 3 Jun 2003 A.Dietz@mpi-hd.mpg.de wrote:
> Dear Rooters,
>
> I created a TTree with some elements in it, e.g.:
>
> ...
> treeRun->Branch("run",&run.run,"run/I");
> treeRun->Branch("trig",run.trig,"trig[5]/I");
> ...
>
> I can work very well with thie TTree but I have some problems in accessing
> the elements of the TTree.
> To access the values of the variable 'run' I do the following:
>
>
> treeRun->Draw(">>runList");
> TEventList* runList=(TEventList*)gDirectory->Get("runList");
>
> for (int i=0;i<runList->GetN();i++) {
>
> treeRun->GetEntry(runList->GetEntry(i));
> TBranch* branch=treeRun->GetBranch("run");
> TLeaf* leaf=(TLeaf*)branch->FindLeaf("run");
> int run=*( (Int_t*)leaf->GetValuePointer());
> }
>
> This works fine (but seems to be very cumbersonely).
> But how can I access the different elements of the vector 'trig' in my
> TTree.
> Neither
>
> TBranch* branch=treeRun->GetBranch("trig[1]");
> TLeaf* leaf=(TLeaf*)branch->FindLeaf("trig[1]");
> int trig=*( (Int_t*)leaf->GetValuePointer());
>
> nor
>
> TBranch* branch=treeRun->GetBranch("trig");
> TLeaf* leaf=(TLeaf*)branch->FindLeaf("trig");
> int* trig=( (Int_t*)leaf->GetValuePointer());
>
> is working!
>
>
> Does someone has any idea how to handle that?
>
>
> Cheers
> Alexander
>
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET