Problems reading a TTree

Hello,

I am attaching to this message a root file containing a TTree made of a particular class, which is also attached to this message. Now I am trying to call a method of this class in TTree::Draw:

root [1] balls.Draw("dcoor(1,0)")

This segfaults, and I cannot understand the source of the problem in the debuggger.

Do you know what I may be doing wrong?

[code]#ifndef TDDATA_HH
#define TDDATA_HH

#include “TObject.h”
#include “TString.h”

class TdData : public TObject
{
public:
TdData ();
virtual ~TdData ();

TString elementname;
TString barcode;
Int_t nballs;
TString *ballname; //[nballs]
Double_t *x; //[nballs]
Double_t *y; //[nballs]
Double_t *z; //[nballs]
Double_t *xnom; //[nballs]
Double_t *ynom; //[nballs]
Double_t *znom; //[nballs]

void setNBalls (Int_t n);
void setElementName (TString s);
void setBarCode (TString s);
void setXYZ (Int_t i, Double_t xx, Double_t yy, Double_t zz);
void setXYZNom (Int_t i, Double_t xx, Double_t yy, Double_t zz);
void setBallName (Int_t i, TString s);

Int_t getType (Int_t i) const;

Double_t coor (Int_t i, Int_t c) const;
Double_t coorNom (Int_t i, Int_t c) const;
Double_t dcoor (Int_t i, Int_t c) const;

ClassDef(TdData,1) // tridim data
};
#endif
[/code]

[code]#include “TdData.hh”
#include
using namespace std;

TdData::TdData ()
{
elementname = “”;
barcode = “”;
nballs = 0;
ballname = 0;
x = y = z = 0;
xnom = ynom = znom = 0;
}

TdData::~TdData ()
{
delete[] ballname;
delete[] x;
delete[] y;
delete[] z;
delete[] xnom;
delete[] ynom;
delete[] znom;
}

void
TdData::setNBalls (Int_t n)
{
nballs = n;
delete[] ballname;
delete[] x;
delete[] y;
delete[] z;
delete[] xnom;
delete[] ynom;
delete[] znom;
ballname = new TString[n];
x = new Double_t[n];
y = new Double_t[n];
z = new Double_t[n];
xnom = new Double_t[n];
ynom = new Double_t[n];
znom = new Double_t[n];
}

void
TdData::setElementName (TString s)
{
elementname = s;
}

void
TdData::setBarCode (TString s)
{
barcode = s;
}

void
TdData::setXYZ (Int_t i, Double_t xx, Double_t yy, Double_t zz)
{
if (i>=nballs)
{
cerr << “TdData::setXYZ: trying to set coordinates in unallocated space "
<< “i=” << i << " nballs=” << nballs << endl;
abort();
}
x[i] = xx;
y[i] = yy;
z[i] = zz;
}

void
TdData::setXYZNom (Int_t i, Double_t xx, Double_t yy, Double_t zz)
{
if (i>=nballs)
{
cerr << “TdData::setXYZNom: trying to set coordinates in unallocated space "
<< “i=” << i << " nballs=” << nballs << endl;
abort();
}
xnom[i] = xx;
ynom[i] = yy;
znom[i] = zz;
}

void
TdData::setBallName (Int_t i, TString s)
{
if (i>=nballs)
{
cerr << “TdData::setBallName: trying to set name in unallocated space "
<< “i=” << i << " nballs=” << nballs << endl;
abort();
}
//cout << s << endl;
ballname[i] = s;
}

Int_t
TdData::getType (Int_t i) const
{
if (i>nballs) return 0;
if (ballname[i].Contains("_cone")) return 1;
if (ballname[i].Contains("_elon")) return 2;
if (ballname[i].Contains("_flat")) return 3;
return 0;
}

Double_t
TdData::coor (Int_t i, Int_t c) const
{
for (int j=0; j<nballs; j++)
{
if (getType(j) == i)
{
switch ©
{
case 0:
return x[j];
case 1:
return y[j];
case 2:
return z[j];
default:
cerr << “TdData::coor: c=” << c << " is undefined" << endl;
return 0.;
}
}
}
cerr << “TdData::coor: i=” << i << " not found" << endl;
return 0.;
}

Double_t
TdData::coorNom (Int_t i, Int_t c) const
{
for (int j=0; j<nballs; j++)
{
if (getType(j) == i)
{
switch ©
{
case 0:
return xnom[j];
case 1:
return ynom[j];
case 2:
return znom[j];
default:
cerr << “TdData::coorNom: c=” << c << " is undefined" << endl;
return 0.;
}
}
}
cerr << “TdData::coorNom: i=” << i << " not found" << endl;
return 0.;
}

Double_t
TdData::dcoor (Int_t i, Int_t c) const
{
return coor (i, c) - dcoor (i, c);
}
[/code]
balls.root (58.9 KB)

Hello,

my problem was obvious: the method dcoor was infinitely recursive.