Hi Kate,
Ouil!!
You should not declare the variable as int* if it is an int.
In your case, if you just want to read the branch "EventNo", do:
static int evtnr;
TBranch *branch = amstree->GetBranch("EventNo");
branch->SetAddress(&evtnr);
branch->GetEntry(0); to read the first entry
now the variable evtnr should contain the value of EventNo for the first
entry.
It is in general a bad idea to use local variables to store the result
of a Tree entry. You better put your variable(s) inside a class.
That is what TTree::MakeClass is doing for you.
It is likely that you did not declare int evtnr as a static variable.
In case you exit/enter again from/in the function where this variable is
declared, the variable has been destroyed meanwhile.
Rene Brun
On Wed, 4 Jul 2001, Kate Scholberg wrote:
> >
> > Yes, you can set individual branch addresses and read only one or a few
> > branches. The problem in your case is that you seem to have a branch
> > with an int*. You cannot read this branch alone. You also need the
> > accompanying branch holding the length of the array.
> > Currently, I assume that both the counter and the array are in the same class.
> >
>
> Hmm, the sub-branch I'm trying to read isn't an int*, it's just a
> plain int. (However the class for the super-branch does have a couple
> of arrays).
>
> Here's the full class for the split branch:
>
> class EventNtuple: public TObject {
> public:
> int Eventno;
> int Run;
> int RunType;
> int Time[2];
> int RawWords;
> float RadS;
> float ThetaS;
> float PhiS;
> float Yaw;
> float Pitch;
> float Roll;
> float VelocityS;
> float VelTheta;
> float VelPhi;
> float ThetaM;
> float PhiM;
> int Particles;
> int Tracks;
> int Betas;
> int Charges;
> int TrRecHits;
> int TrClusters;
> int TrRawClusters;
> int TrMCClusters;
> int TOFClusters;
> int TOFMCClusters;
> int CTCClusters;
> int CTCMCClusters;
> int AntiMCClusters;
> int AntiClusters;
> int EventStatus;
> };
>
>
> I'm trying to set the branch address using
>
> int* evptr = 0;
> amstree->SetBranchAddress("Eventno",&evptr)
>
> The 2nd argument of SetBranchAddress should be the address of a
> pointer, right? I tried all sorts of other things, too... I tried
> putting in the address of an int instead , I tried first instantiating the
> int that evptr is pointing to, etc.)
>
> But GetEvent reads in nothing for the sub-branch, although it works fine for
> setting the top branch level address.
>
> Kate.
>
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:51 MET