Hi, I wanted to adapt the Event and Track classes to my needs, so I just renamed the Track class as Hit, removed some methods and the ClassImp, ClassDef. I may have removed too many things, cause now I get this message when adding a Hit to the TClonesArray in Event : Error in <TClonesArray::operator[]>: invalid class specified in TClonesArray ctor Then a segmentation fault occurs in the TObject constructor (Hit inherits from TObject). Could you help ? thanks, Colin #include "Event.h" TClonesArray *Event::fgHits = 0; //______________________________________________________________________________ Event::Event() { // Create an Event object. // When the constructor is invoked for the first time, the class static // variable fgHits is 0 and the TClonesArray fgHits is created. if (!fgHits) fgHits = new TClonesArray("Hit", 1000); fHits = fgHits; fNHit = 0; } //______________________________________________________________________________ Event::~Event() { Clear(); } //______________________________________________________________________________ void Event::AddHit(TString* detname, int channel, float data, int type) { TClonesArray &Hits = *fHits; new(Hits[fNHit++]) Hit(detname,channel,data,type); } //______________________________________________________________________________ void Event::Clear(Option_t *option) { fHits->Clear(option); } //______________________________________________________________________________ void Event::Reset(Option_t *option) { // Static function to reset all static objects for this event // fgHits->Delete(option); delete fgHits; fgHits = 0; } //______________________________________________________________________________ void Event::SetHeader(Int_t i, Int_t run) { fNHit = 0; fEvtHdr.Set(i, run); } //______________________________________________________________________________ Hit::Hit(TString* detname, int channel, float data, int type) : TObject() { fDetname=new TString(*detname); fChannel=channel; fData=data; fType=type; } Hit::IsMeanTimer() { if (fType=1) return 1; else return 0; } Hit::IsAdc() { if (fType=2) return 1; else return 0; } #ifndef MY_Event #define MY_Event #include <TString.h> #include <TObject.h> #include <TClonesArray.h> class EventHeader { private: Int_t fEvtNum; Int_t fRun; public: EventHeader() : fEvtNum(0), fRun(0) { } virtual ~EventHeader() { } void Set(Int_t i, Int_t r) { fEvtNum = i; fRun = r;} Int_t GetEvtNum() const { return fEvtNum; } Int_t GetRun() const { return fRun; } }; class Event : public TObject { private: Int_t fNHit; UInt_t fFlag; EventHeader fEvtHdr; TClonesArray *fHits; static TClonesArray *fgHits; public: Event(); virtual ~Event(); void Clear(Option_t *option =""); static void Reset(Option_t *option =""); void SetNhits(Int_t n) { fNHit = n; } void SetFlag(UInt_t f) { fFlag = f; } void SetHeader(Int_t i, Int_t run); void AddHit(TString* detname, int channel, float data, int type); Int_t GetNhits() const { return fNHit; } UInt_t GetFlag() const { return fFlag; } EventHeader* GetHeader() { return &fEvtHdr; } TClonesArray* GetHits() const { return fHits; } }; class Hit : public TObject { private: TString *fDetname; int fChannel; float fData; int fType; public: Hit() { } Hit(TString* detname, int channel, float data, int type); virtual ~Hit() { } int IsMeanTimer(); int IsAdc(); }; #endif
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:28 MET