Re: TTree and class with pointers

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Tue, 13 Oct 2009 19:35:05 -0500


Hi Manuel,

In C++ you need to make sure to initialize all data members, especially pointers. In addition if you
use static data member which are pointer are delete what they are pointed to, you ought to reset the
value of those static pointers. So you need to updates your code at least with the following:

TManuEvent::TManuEvent()
{
.....

   fHeader = 0;
}

and

   TManuHeader() : fBeamPosition(0),fBeamPositionSigma(0) {}

and

TManuEvent::~TManuEvent()
{

   delete fgVertices; fgVertices = 0;
   delete fgTracks; fgVertices = 0;
  if (fHeader) delete fHeader;
}

Cheers,
Philippe.

Manuel Mussini wrote:
> Hi,
> I'm trying to create a TTree containing objects of the attached event
> class (to select some CDF event's infos).
> The class members are 3:
> - a header
> - an array of tracks
> - an array of vertices (not filled yet !!!)
>
> I've tried to modify the tree4.C example in the tutorials to fit my
> needs but something works wrong!
>
> The first step is to run the skimmer in CDF's environment to write the
> file!
> I've removed in the code all the stuff not related to this issue!
> Here I get no errors; this is how the output looks like:
>
> ...
> Run = 161792, Event = 90512, InstLumi = 1.510291e+31,
> Triggered = 1 ( 12, 31)
> Beam = (-1.876444e-01,
> 4.996734e-01) +- (5.521803e-06, 4.988194e-06)
> Pt = 1.882, Eta = 0.79, Charge = 1
> Pt = 1.267, Eta = 0.16, Charge = 1
> Pt = 1.216, Eta = 1.72, Charge = 1
> Pt = 1.080, Eta = 1.15, Charge = -1
> Pt = 1.008, Eta = 0.59, Charge = -1
> Pt = 0.947, Eta = -0.64, Charge = 1
> Pt = 0.857, Eta = 0.34, Charge = -1
> ...
>
>
> But with the second step (read the file) I can see that it seems to be
> empty:
>
>
> root [0]
> Processing TManuEvent.C("ReducedStntuple.root")...
> TFile** ReducedStntuple.root Events with at least one D0 ->
> K pi candidate
> TFile* ReducedStntuple.root Events with at least one D0 ->
> K pi candidate
> KEY: TTree MinBiasCDF;1 MinBias Tree
>
> OBJ: TTree MinBiasCDF MinBias Tree : 0 at: 0x91e3208
>
> ==>Dumping object at:9227978, name=TManuEvent, class=TManuEvent
>
> *fHeader ->f5050000
> fNTracks 0
> *fTracks ->9227f08 ->array with all tracks
> fNVertices 0
> *fVertices ->92279a0 ->array with all vertices
> fUniqueID 0 object unique identifier
> fBits 50331648 bit field status word
>
> Error: illegal pointer to class object branch 0x0 473
> FILE:TManuEvent.C LINE:15
> *** Interpreter error recovered ***
> root [1]
>
>
> What am I missing?
> Did I forget to set something related to the pointers of my class data
> members?
>
> Thanks in advance!
>
>
>
> Bye...
>
>
>
>
>
>
Received on Wed Oct 14 2009 - 02:35:11 CEST

This archive was generated by hypermail 2.2.0 : Wed Oct 14 2009 - 11:50:05 CEST