Re: GetEntry & SetBranchAddress problem

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Wed, 10 Aug 2005 15:45:10 +0200 (MEST)


Vincent,

I do not understand what you are doing.
You disable all branches but one (that contains only one integer). We need more info and if possible a very small setup reproducing the problem.

Rene brun

On Wed,
10 Aug 2005, Vincent
Roberfroid wrote:

> Dear root users,
>
> I get strange behavior using TTree:GetEntry().
> I am using root 4.04/02.
> Here is a piece of code to resume the problem:
> --------------------------------
> // I use of a global variable defined elsewhere
> // gtt_output is a structure
> extern gtt_output outbank;
>
> int main(int argc, char **argv)
> {
> // I set the address of a simple branch in a root file to a variable
> TFile *file = new TFile("file.root","read");
> TTree *fTree = (TTree*)file->Get("h1");
> fTree->SetBranchStatus("*",0);
> Int_t Eventnr;
> fTree->SetBranchStatus("Eventnr",1);
> fTree->SetBranchAddress("Eventnr",&Eventnr);
>
> // I get the tracks and the first hit of the first track from the global
> variable outbank
> track** trk = outbank.tracks;
> hit* tmphit = (trk[0]->hit)[0];
>
> // I print out the phi position of the hit and the address of trk and tmphit:
> cout << "phi = " << tmphit->phi << endl;
> cout << trk << " " << tmphit << endl;
>
> // I read the variable Eventnr in the first entry of the root file
> fTree->GetEntry(0);
>
> // I print out once more the phi position of the hit and the address of trk
> and tmphit:
> cout << "phi = " << tmphit->phi << endl;
> cout << trk << " " << tmphit << endl;
> }
> ------------------------------
> Here is the output that I get sometimes (1/100 events) :
>
> phi = 2.78284
> 0xd8b4580 0x10fd37c0
> phi = 2.17482e-42
> 0xd8b4580 0x10fd37c0
>
> In the other case the phi is inchanged.
> That means that GetEntry() modify sometimes the content of some memory space
> allocated to a global variable.
> The address of the pointer does not change.
> I maybe made a mistake somewhere. Do you have any ideas ?
>
> Thank you very much in advance.
>
> Regards,
> Vincent
>
Received on Wed Aug 10 2005 - 15:46:41 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:11 MET