Problem reading back a TTree

Hi rooters.

I try to read back a raw data file (“PH207_31_0.root”) and to apply an energy calibration from the “chikkyTest.root” file. I obtain a segfault depending on the order of root files declaration.

The following piece of code is working:

[code]void test()
{
TFile *inFile = new TFile("~/scratch/ph207/RAW/ROOT/PH207_37_0.root");
TTree tree = (TTree) inFile->Get(“T”);
TRawData *rawData = new TRawData();
tree->SetBranchAddress(“rawData”, &rawData);

TFile *inFileCalib = new TFile("$PH207/root/chikkyTest.root");

Int_t nentries = (Int_t)tree->GetEntries();
for (Int_t i = 0; i < nentries; i++) {
tree->GetEntry(i);
}
}
[/code]

but, this one is not working, why? (the errors reported by cint are attached)

void test()
{
   TFile *inFileCalib = new TFile("$PH207/root/chikkyTest.root");
   
   TFile *inFile = new TFile("~/scratch/ph207/RAW/ROOT/PH207_37_0.root");
   TTree *tree = (TTree*) inFile->Get("T");
   TRawData *rawData = new TRawData();
   tree->SetBranchAddress("rawData", &rawData);

   Int_t nentries = (Int_t)tree->GetEntries();
   for (Int_t i = 0; i < nentries; i++) {
      tree->GetEntry(i);
   }
}

Another problem is that if I run twice the first code with “.x test.C” I obtain the same segfault.

I think it must be something stupid related to scope problem but I couldn’t solve it. Tell me if you need the root files or the description of the TRawData class.

Any help will be appreciated, thanks
Nicolas

RH7.3, ROOT 4.01/03
log.txt (4.54 KB)

Hi,

Most likely the default constructor of TRawData is not properly intializing all the data members (of TRawData) or the rawData does not contains a rawData (but a TClonesArray of TRawData).

Cheers,
Philippe

Hi Philippe!

Thank you for your fast answer! You are right, I forgot to initialize the default constructor! Now it’s working like a charm…

However I am not sure whether I did a good initialization. I put here the relevant part of the TRawData.h and TRawData.cxx files. Could you tell me if it’s OK?

Thanks in advance,
Nicolas

TRawData.h:

 private:
   Int_t         fEvtNum;
   // TDC
   Int_t         fNTdc;
   Short_t      *fTdcID;      //[fNTdc]
   Short_t      *fTdcCh;      //[fNTdc]
   Short_t      *fTdcData;    //[fNTdc]
   // ADC
   Int_t         fNAdc;
   Short_t      *fAdcID;      //[fNAdc]
   Short_t      *fAdcCh;      //[fNAdc]
   Short_t      *fAdcData;    //[fNAdc]

TRawData.cxx

TRawData::TRawData()
{
   // Default constructor
   fEvtNum = 0;
   fNTdc   = 0;
   fNAdc   = 0;

   fTdcID   = 0;
   fTdcCh   = 0;
   fTdcData = 0;
   fAdcID   = 0;
   fAdcCh   = 0;
   fAdcData = 0;
}

That seems good.

Philippe.