Seg violation during TTree::Branch

From: Ulrich Husemann (husemann@physik.uni-dortmund.de)
Date: Wed Feb 23 2000 - 10:48:12 MET


Dear Rooters!

I adopted your Event class for my own purposes. While building a tree to
fill in objects of the Event class ROOT crashes with a segmentation
violation. Are there any restrictions to this class? The header looks like
this:

#include "TObject.h"
#include "TClonesArray.h"
#include <cmath>
#include <iostream>

class TDirectory;

//****************************************************************************
class EventHeader : public TObject
{
  // Event Header class

public:
  EventHeader();
  virtual ~EventHeader();
  Int_t GetEvtNum() const;
  Int_t GetRunNum() const;
  Int_t GetDate() const;
  Int_t GetTime() const;
  Int_t GetBX() const;
  
  void SetEvtNum(Int_t EvtNum);
  void SetRunNum(Int_t RunNum);
  void SetDate(Int_t Date);
  void SetTime(Int_t Time);
  void SetBX(Int_t BX);
  void SetAll(Int_t EvtNum, Int_t RunNum, Int_t Date, Int_t Time, Int_t
BX);

private:
  Int_t fEvtNum;
  Int_t fRunNum;
  Int_t fDate;
  Int_t fTime;
  Int_t fBX;

  ClassDef(EventHeader,1)
};  

inline Int_t EventHeader::GetEvtNum() const {return fEvtNum;}
inline Int_t EventHeader::GetRunNum() const {return fRunNum;}
inline Int_t EventHeader::GetDate() const {return fDate;}
inline Int_t EventHeader::GetTime() const {return fTime;}
inline Int_t EventHeader::GetBX() const {return fBX;}
inline void EventHeader::SetEvtNum(Int_t EvtNum) {fEvtNum = EvtNum;}
inline void EventHeader::SetRunNum(Int_t RunNum) {fRunNum = RunNum;}
inline void EventHeader::SetDate(Int_t Date) {fDate = Date;}
inline void EventHeader::SetTime(Int_t Time) {fTime = Time;}
inline void EventHeader::SetBX(Int_t BX) {fBX = BX;}

//****************************************************************************

class Mimp : public TObject
{
 public:
  Mimp(Float_t x = 0, Float_t y =0, Float_t z = 0, Float_t px = 0, Float_t
py = 0, 
       Float_t pz = 0, Int_t cmp = 0, Int_t nsl = 0)
    : fX(x), fY(y), fZ(z), fPx(px), fPy(py), fPz(pz), fCmp(cmp), fNsl(nsl)
    {}
  Mimp(Int_t cmp, Int_t nsl, Float_t x, Float_t y, Float_t z, Float_t tx,
Float_t ty, Float_t p)
    : fX(x), fY(y), fZ(z), fCmp(cmp), fNsl(nsl)
    {
      SetConvertedMomenta(tx,ty,p);
    }
  Mimp(const Mimp* mymimp)
    : fX(mymimp->GetX()), fY(mymimp->GetY()), fZ(mymimp->GetZ()), 
    fPx(mymimp->GetPx()), fPy(mymimp->GetPy()), fPz(mymimp->GetPz()), 
    fCmp(mymimp->GetCmp()), fNsl(mymimp->GetNsl()) { }
  virtual ~Mimp() { }
  void Clear();
  Float_t GetX() const;
  Float_t GetY() const;
  Float_t GetZ() const;
  Float_t GetPx() const;
  Float_t GetPy() const;
  Float_t GetPz() const;
  Float_t GetPt() const;
  Int_t GetCmp() const;
  Int_t GetNsl() const;
  void SetX(Float_t x);
  void SetY(Float_t y);
  void SetZ(Float_t z);
  void SetPx(Float_t px);
  void SetPy(Float_t py);
  void SetPz(Float_t pz);
  void SetCmp(Int_t cmp);
  void SetNsl(Int_t nsl);
  void SetConvertedMomenta(Float_t tx, Float_t ty, Float_t p);

 private:
  Float_t fX;  // x coordinate of MIMP
  Float_t fY;  // y coordinate of MIMP
  Float_t fZ;  // z coordinate of MIMP 
  Float_t fPx; // px of track
  Float_t fPy; // py of track
  Float_t fPz; // pz of track
  Int_t fCmp;  // component where MIMP was found
  Int_t fNsl;  // superlayer where MIMP was found

  ClassDef(Mimp,1)
};

inline Float_t Mimp::GetX() const {return fX;}
inline Float_t Mimp::GetY() const {return fY;}
inline Float_t Mimp::GetZ() const {return fZ;}
inline Float_t Mimp::GetPx() const {return fPx;}
inline Float_t Mimp::GetPy() const {return fPy;}
inline Float_t Mimp::GetPz() const {return fPz;}
inline Float_t Mimp::GetPt() const {return sqrt(fPx*fPx + fPy*fPy);}
inline Int_t Mimp::GetCmp() const {return fCmp;}
inline Int_t Mimp::GetNsl() const {return fNsl;}
inline void Mimp::SetX(Float_t x){fX = x;}
inline void Mimp::SetY(Float_t y){fY = y;}
inline void Mimp::SetZ(Float_t z){fZ = z;}
inline void Mimp::SetPx(Float_t px) {fPx = px;}
inline void Mimp::SetPy(Float_t py) {fPy = py;}
inline void Mimp::SetPz(Float_t pz) {fPz = pz;}
inline void Mimp::SetCmp(Int_t cmp) {fCmp = cmp;}
inline void Mimp::SetNsl(Int_t nsl) {fNsl = nsl;}


//****************************************************************************

class Event : public TObject
{
  // Main event class
public:
  Event();
  virtual ~Event();
  void Clear(Option_t *option = "");
  void Reset(Option_t *option = "");

  Int_t GetNb0sMimps() const;
  Int_t GetNmuplusMimps() const;
  Int_t GetNmuminusMimps() const;
  EventHeader* GetHeader();
  TClonesArray* GetB0sMimps() const;
  TClonesArray* GetMuplusMimps() const;
  TClonesArray* GetMuminusMimps() const;

  void SetNb0sMimps(Int_t n);
  void SetNmuplusMimps(Int_t n);
  void SetNmuminusMimps(Int_t n);
  void SetHeader(Int_t EvtNum, Int_t RunNum, Int_t Date, Int_t Time, Int_t
BX);

  void AddB0sMimp(const Mimp*);
  void AddMuplusMimp(const Mimp*);
  void AddMuminusMimp(const Mimp*);
  void AddMimp(const Mimp*, char *particle);

private:
  Int_t fNb0sMimps;
  Int_t fNmuplusMimps;
  Int_t fNmuminusMimps;
  EventHeader fEvtHdr;
  TClonesArray* fB0sMimps;
  TClonesArray* fMuplusMimps;
  TClonesArray* fMuminusMimps;

  static TClonesArray* fgB0sMimps;
  static TClonesArray* fgMuplusMimps;
  static TClonesArray* fgMuminusMimps;

  ClassDef(Event,1)
};

inline Int_t Event::GetNb0sMimps() const {return fNb0sMimps;}
inline Int_t Event::GetNmuplusMimps() const {return fNmuplusMimps;}
inline Int_t Event::GetNmuminusMimps() const {return fNmuminusMimps;} 
inline EventHeader* Event::GetHeader() {return &fEvtHdr;}
inline TClonesArray* Event::GetB0sMimps() const {return fB0sMimps;}
inline TClonesArray* Event::GetMuplusMimps() const {return fMuplusMimps;}
inline TClonesArray* Event::GetMuminusMimps() const {return
fMuminusMimps;}

inline void Event::SetNb0sMimps(Int_t n) {fNb0sMimps = n;}
inline void Event::SetNmuplusMimps(Int_t n) {fNmuplusMimps = n;}
inline void Event::SetNmuminusMimps(Int_t n) {fNmuminusMimps = n;}

#endif



Ulrich Husemann



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:19 MET