Dear colleagues,
I have found a problem which seems to be version-dependent (the code included below works in 5.06/00, but does not in 5.14/00g or 5.18/00). It happens when a TTree is filled (function Fill()) with data in a TClonesArray. I tried to simplify the code to the maximum.
In version 5.06/00 the output TTree contains, in the leaf value, the four array elements (myTest). But for the newer versions, the output is filled with zero. Could you please indicate me where I have a problem in the code (as I assume that the function Fill is not faulty )
The code (two files, problemTest.C and problemTest.h, also included as attachment) is the following:
//
// Testing a ROOT-version dependent problem filling a TTree with a TClonesArray. Run it with:
//
// > .L problemTest.C;
// > digitEvents("output_file_name");
//
#include "problemTest.h"
action theAction;
run(char* outputFile){
//output File and Tree
TFile* outFile = new TFile(outputFile,"RECREATE");
outFile->cd();
TTree* outputTree = new TTree("outputTree","output Tree");
TClonesArray* dataCA;
data** myData;
dataCA = new TClonesArray("data",5);
outputTree->Branch("myData",&dataCA);
theAction.Calculate(dataCA,outputTree);
outFile->Write();
outFile->Close();
}
//
// Testing a ROOT-version dependent problem filling a TTree with TClonesArray
//
class action;
class data;
class data : public TObject {
private:
Float_t value; //pad control number
public:
data();
~data();
Float_t GetValue(){return value;}
void SetValue(Float_t cha){value=cha;}
};
data::data(){ value=0.; }
data::~data(){ }
class action{
public:
action();
~action();
void Calculate(TClonesArray* clo);
};
action::action(){ }
action::~action(){ }
void action::Calculate(TClonesArray* clo, TTree* tre) {
Double_t myTest[4] = {0.1,0.2,0.3,0.4};
data** theData;
theData = new data*[4];
for(Int_t iterOnPads=0;iterOnPads<4;iterOnPads++){
theData[iterOnPads] = new data();
theData[iterOnPads]->SetValue(myTest[iterOnPads]);
new((*clo)[iterOnPads])data(*theData[iterOnPads]);
}
tre->Fill();
}
Thank you very much in advance for your support,
problemTest.h (868 Bytes)
problemTest.C (608 Bytes)