Hi,
I’m fairly new to root. I’m using Version 4.04/02b 3 June 2005 on Linux and my program is a standalone.
I’ve created a tree using a Class I defined. While trying to get the entries of the tree I’m able to do so for the first two entries. On the third, the GetEntry prints the following warning and then crashes:
Error in TExMap::Remove: key 65536 not found at 147
Warning in TBuffer::CheckObject: reference to object of unavailable class TClonesArray, offset=65536 pointer will be 0
Error in TExMap::Remove: key 768 not found at 266
Warning in TBuffer::CheckObject: reference to object of unavailable class TClonesArray, offset=768 pointer will be 0
Error in TBuffer::ReadObject: Got object of wrong class (Got RawTrack while expecting TClonesArray)
Error in TExMap::Remove: key 50331648 not found at 463
Warning in TBuffer::CheckObject: reference to object of unavailable class TClonesArray, offset=50331648 pointer will be 0
Error in TBuffer::ReadObject: Got object of wrong class (Got RawTrack while expecting TClonesArray)
I’m unable to understand what’s going on. I would really appreaciate your help with this issue.
Thanks,
Pedro M Duarte
Following is the code for my program:
//create ROOT tree
TTree *raw = new TTree(“Raw”,“Raw Data Tree”);
RawTrack *rtrack = new RawTrack();
raw->Branch(“RawTrackBranch”,“RawTrack”,&rtrack,32000,99);
//fill the tree
…
…
//read the tree to fill histograms
Int_t n = raw->GetEntries(); <----------------- It crashes here.----------
for( Int_t i=0; i!=n; i++) {
raw->GetEntry(i);
for( Int_t de=0; de!=p->fMax; de++){
if( rtrack->fHits[de] ) {
TClonesArray &hits = *( rtrack->fHits[de] );
for (Int_t hit=0; hit!=rtrack->fNHits[de]; hit++){
RawHit h = ((RawHit)hits[hit]) ;
hM[de][h->fNPlane][h->fWire]->Fill( h->fData );
}
}
}
rtrack->Clear();
}
//________________________________________________________________
class RawHit : public TObject {
private:
Bool_t fIsValid;
public:
char fPlane; // plane name
Int_t fNPlane; // plane number
Int_t fWire; // wire number
Int_t fData; // time
RawHit();
~RawHit();
RawHit(Int_t t, Int_t c, Int_t d, PWCSetup *p);
void Print() const;
ClassDef(RawHit,1) //Raw mwpc hit
};
//________________________________________________________________
class RawTrack : public TObject {
private:
Bool_t fIsValid; //
public:
Int_t fMax; //number of devices
TClonesArray *fHits[10]; //an array of hits per device
Int_t fNHits[10]; //hits per device
RawTrack();
~RawTrack();
void Clear();
void AddHit(Int_t t, Int_t c, Int_t d, PWCSetup *p);
Int_t GetNHits(Int_t i) {return fNHits[i];};
void Print() const;
ClassDef(RawTrack,1) //Raw track for an event
};
//________________________________________________________________
RawHit::RawHit() : fIsValid(kFALSE)
{
// Create a RawHit object.
}
//________________________________________________________________
RawHit::~RawHit()
{
// Destructs a RawHit object.
}
//________________________________________________________________
RawHit::RawHit(Int_t t, Int_t c, Int_t d, PWCSetup *p)
{
// Create a RawHit object.
fIsValid = kTRUE;
fPlane = p->Setup[t][c]->fPlane;
fNPlane = p->Setup[t][c]->fNPlane;
fWire = p->Setup[t][c]->fWireN;
fData = d;
}
//________________________________________________________________
void RawHit::Print() const
{
if (fIsValid){
std::cout << “plane:” << fPlane << " planeNum:" << fNPlane << " wire:" << fWire << " data:" << fData << std::endl;
}
else {
std::cout << “Initialize the object before printing!” << std::endl;
}
}
//________________________________________________________________
RawTrack::RawTrack()
{
// Create a RawTrack object.
fMax = NDEVICES;
for(Int_t i=0; i!=fMax; i++){
fHits[i] = 0; //default initialization of pointer
fNHits[i]=0;
}
fIsValid = kTRUE;
}
//________________________________________________________________
RawTrack::~RawTrack()
{
// Destruct a RawTrack object.
Clear();
}
//________________________________________________________________
void RawTrack::Clear()
{
for(Int_t i=0; i!=fMax; i++) {
if (fHits[i]) {
fHits[i]->Delete();
fHits[i]=0; //default initialization of pointer
}
fNHits[i]=0;
}
}
//________________________________________________________________
void RawTrack::AddHit(Int_t t, Int_t c, Int_t d, PWCSetup *p)
{
Int_t station = p->Setup[t][c]->fStation;
if ( d>TDCLOWCUT && d<TDCHIGHCUT ){
if (station < fMax ){
if (!fHits[station]) fHits[station] = new TClonesArray(“RawHit”,200);
TClonesArray &hits = *fHits[station];
new(hits[fNHits[station]]) RawHit(t,c,d,p);
fNHits[station]++;
}
}
else{
std::cout << “Time out of cuts:: Station :” << station << " Time : " << d << std::endl;
}
}
//________________________________________________________________
void RawTrack::Print() const
{
if (fIsValid){
std::cout << “Mwpc Hits” << std::endl;
for(Int_t j=0; j!=fMax; j++){
std::cout << “Station " << j+1 << std::endl;
if ( fHits[j] ){
TClonesArray &hits = fHits[j];
for(Int_t i=0; i<fNHits[j]; i++)
((RawHit)hits[i])->Print();
if( fNHits ==0 )
std::cout << " -empty-” << std::endl;
}
else {
std::cout << " -empty-" << std::endl;
}
}
}
else {
std::cout << “Initialize the object before printing!” << std::endl;
}
}