Dear rooters,
I have 2 classes, one describes an event and the other a track in that
event. The event contains a TClonesArray with the tracks and the iterrator:
TClonesArray *fParticles; // Array with particles
TIter *fpart_iter; // ptr to iterator
When an new event is created, the TClonesArray is created:
fParticles = new TClonesArray("TBigDSWriteParticle",1000);
fpart_iter = new TIter(fParticles);
The classes can be compiled, loaded into root runtime, but when I try to
make a branch, it complaints:
root [0] .L /cern/root/lib/libEG.so
root [1] .L /cern/root/lib/libPhysics.so
root [2] .L ../lib/libmicro.so
root [3] TFile *tfile= new TFile("/tmp/dsttest.root","RECREATE");
root [4] TTree *tft = new TTree("tft","");
root [5] tfile->SetCompressionLevel(2);
root [6] TBigDSWriteEvent *myevent=new TBigDSWriteEvent();
root [7] TBigDSWriteParticle *mypart;
root [8]
tft->Branch("TBigDSWriteEvent","TBigDSWriteEvent",&myevent,5000000,1);
Error in <TClass::New>: cannot create object of class TIter
The source codes are atached.
Any help is greatly welcomed, I already tried to use other container
objects (TList, TObjArray), asked whom I can around but I'm still stucked.
Thank you
0ndrej Chvala, NA49
#ifndef TBigDSWriteEvent_Header
#define TBigDSWriteEvent_Header
#include "TObject.h"
#include "TClonesArray.h"
#include "TBigDSWriteParticle.h"
class TBigDSWriteEvent : public TObject
{
protected :
Int_t fNRun; // Run number
Int_t fNEvent; // Event number
Int_t fNParticles; // Number of particles in event
Int_t fbi; // b_i
Int_t fbg; // b_g
Int_t ftriggers;
Float_t fvtxx; // vertex X
Float_t fvtxy; // vertex Y
Float_t fvtxz; // vertex Z
Float_t fchi2; // chi2 of vtx fit
Int_t fNGrey; // Number of grey particles in event
Int_t fWFABeam[20]; // beam hits in WFA
Int_t fWFAInt[5]; // interaction hits in WFA
Int_t fWFAflag; // WFA flag
Int_t fBPDflag; // BPD flag
// Int_t fvpc[80]; // VPCs
Float_t fEveto; // Veto energy
Float_t fWeight;
TClonesArray *fParticles; // Array with particles
TClonesArray *fgParticles;
TIter *fpart_iter; // ptr to iterator
public :
TBigDSWriteEvent(); // Default constructor
~TBigDSWriteEvent(); // destrucor
Int_t GetNRun() {return fNRun;}; // Get run Number
Int_t GetNEvent() {return fNEvent;}; // Get event number
Int_t GetNParticles() {return fNParticles;}; // Get number of particles
Int_t GetBi() {return fbi;}; // Get number of gated interactions
Int_t GetBg() {return fbg;}; // Get number of gated beams
Int_t GetTriggers() {return ftriggers;}; // Get number of gated triggers
Int_t GetNGrey() {return fNGrey;}; // Get number of grey particles
Int_t GetWFAFlag() {return fWFAflag;}; // Get flag
Int_t GetBPDFlag() {return fBPDflag;}; // Get flag
Float_t GetVtxX() {return fvtxx;}; // Get X position of the main vertex
Float_t GetVtxY() {return fvtxy;}; // Get Y position of the main vertex
Float_t GetVtxZ() {return fvtxz;}; // Get Z position of the main vertex
Float_t GetChi2() {return fchi2;}; // Get chi^2 the main vertex fit
Float_t GetEveto() {return fEveto;}; // Get Veto energy
Float_t GetWeight(){return fWeight;}; // Get weight
void SetNRun(Int_t run) {fNRun=run;}; // Set run number
void SetNEvent(Int_t event) {fNEvent=event;};
// Set event number
void SetNParticles(Int_t particles) {fNParticles=particles;};
// Set number of particles.
// Warning AddParticle increase value of fNParticles
void SetNGrey(Int_t grey) {fNGrey=grey;}; // Set number of grey particles
void SetBi(Int_t bi) {fbi=bi;}; // Set bi
void SetBg(Int_t bg) {fbg=bg;}; // Set bg
void SetTriggers(Int_t trigg) {ftriggers=trigg;}; // Set # of triggers
void SetWFAFlag(Int_t wfaflag) {fWFAflag=wfaflag;}; // Set flag
void SetBPDFlag(Int_t bpdflag) {fBPDflag=bpdflag;}; // Set flag
void SetVtxX(Float_t vtxx) {fvtxx=vtxx;}; // Set X position of the main vertex
void SetVtxY(Float_t vtxy) {fvtxy=vtxy;}; // Set Y position of the main vertex
void SetVtxZ(Float_t vtxz) {fvtxz=vtxz;}; // Set Z position of the main vertex
void SetChi2(Float_t chi2) {fchi2=chi2;}; // Set chi2the main vertex
void SetEveto(Float_t eveto) {fEveto=eveto;}; // Set veto energy
void SetWeight(Float_t w){fWeight=w;};
Int_t GetWFABeam(Int_t slot);
Int_t GetWFAInt(Int_t slot);
Int_t SetWFABeam(Int_t wfa_b, Int_t slot);
Int_t SetWFAInt(Int_t wfa_i, Int_t slot);
TBigDSWriteParticle *AddParticle(Float_t px, Float_t py, Float_t pz);
// Add particle with 3 momenta in lab
TBigDSWriteParticle *AddParticle(TBigDSWriteParticle *anopart);
// Add particle, data members are
// copied from anopart
void SetToFirst(); // sets iterator to first particle
TBigDSWriteParticle* GetNext(); // returns pointer to next particle
TClonesArray *GetParticles() {return fParticles;}; // Get array of particles
void Copy(TBigDSWriteEvent *anoevent); // Copy anoevent to this event
void Clear() {fParticles->Clear();};
void Delete() {fParticles->Delete();};
ClassDef(TBigDSWriteEvent,2)
};
#endif
#ifndef TBigDSWriteParticle_Header
#define TBigDSWriteParticle_Header
#include "TObject.h"
#define fgMaxClust 200 // max clusters / track
class TBigDSWriteParticle : public TObject
{
private :
Float_t fPx; // Momenta in x direction in LAB
Float_t fPy; // Momenta in y direction in LAB
Float_t fPz; // Momenta in z direction in LAB
Int_t fNClusters; // Number of clusters in particle track
/* Float_t fClustX[fgMaxClust];
Float_t fClustY[fgMaxClust];
Float_t fClustZ[fgMaxClust];
Int_t fClustPos[fgMaxClust];
Int_t fClustCha[fgMaxClust];
Int_t fClustSig[fgMaxClust];
Int_t fClustVar[fgMaxClust];*/
Short_t flag; // inflag
Short_t fch; // charge
public :
TBigDSWriteParticle();
TBigDSWriteParticle(TBigDSWriteParticle *anopart);
TBigDSWriteParticle(Float_t px,Float_t py, Float_t pz);
~TBigDSWriteParticle();
void SetPx(Float_t px) {fPx=px;}; // Set px
void SetPy(Float_t py) {fPy=py;}; // Set py
void SetPz(Float_t pz) {fPz=pz;}; // Set pz
Float_t GetPx() {return fPx;}; // Returns px
Float_t GetPy() {return fPy;}; // Returns py
Float_t GetPz() {return fPz;}; // Returns pz
void SetCharge(Short_t ch) {fch=ch;}; // Set charge
void SetFlag(Short_t ff) {flag=ff;}; // Set flag
Short_t GetCharge() {return fch;}; // Get particle charge
Short_t GetCh() {return fch;}; // Get particle charge
Short_t GetFlag() {return flag;}; // Get flag
Int_t GetNClusters() {return fNClusters;}; // Get number of clusters
void SetNClusters(Int_t clusters) {fNClusters=clusters;};
/* Int_t AddCluster(Float_t x, Float_t y, Float_t z, Int_t pos, Int_t cha, Int_t sig, Int_t var); // Add cluster
Int_t GetCluster(Float_t clustp[3], Int_t clustn[4], Int_t nclust); // Get cluster
Int_t GetCluster(Float_t clustp[3], Int_t nclust); // Get cluster
//void Copy(TBigDSWriteParticle *anopart); // Copy another particle to this particle
*/
ClassDef(TBigDSWriteParticle,1) // Event base class
};
#endif
#include "TObject.h"
#include "TClonesArray.h"
#include "TBigDSWriteParticle.h"
#include "TBigDSWriteEvent.h"
//////////////////////////////////////////////////////////////////////////
// This class contain data about one measured event. There are methods
// for setting all data members and methods which returns values of data
// members.
// WARNING : Method AddParticle also increase value of fNParticles, so
// you don't need to set number of particles in event, this is
// set automatically.
//
// Date: 6.10.2003
// Author: Ondrej Chvala, based on TWriteEvent and TBigDSWriteEvent by Michal Kreps
//
ClassImp(TBigDSWriteEvent)
TBigDSWriteEvent::TBigDSWriteEvent()
{
/*
* Default constructor. Set all members in event to 0 and init array for
* particles.
*/
fNRun=0;
fNEvent=0;
fNParticles=0;
fNGrey=0;
fEveto=0;
fNRun=0;
fNEvent=0;
fbi=0;
fbg=0;
ftriggers=0;
fvtxx=0;
fvtxy=0;
fvtxz=0;
//if(!fgParticles)
fParticles = new TClonesArray("TBigDSWriteParticle",1000);
// fgParticles = fParticles;
fpart_iter = new TIter(fParticles);
}
TBigDSWriteEvent::~TBigDSWriteEvent()
{
// Destructor, deletes also all particles.
delete fpart_iter;
delete fParticles;
}
Int_t TBigDSWriteEvent::GetWFABeam(Int_t slot)
{
if(slot < 20) {
return fWFABeam[slot];
} else {
return -999;
}
}
Int_t TBigDSWriteEvent::GetWFAInt(Int_t slot)
{
if(slot < 5) {
return fWFAInt[slot];
} else {
return -999;
}
}
Int_t TBigDSWriteEvent::SetWFABeam(Int_t wfa_b, Int_t slot)
{
if(slot < 20) {
fWFABeam[slot]=wfa_b;
return 0;
} else {
return -1;
}
}
Int_t TBigDSWriteEvent::SetWFAInt(Int_t wfa_i, Int_t slot)
{
if(slot < 5) {
fWFAInt[slot]=wfa_i;
return 0;
} else {
return -1;
}
}
TBigDSWriteParticle *TBigDSWriteEvent::AddParticle(Float_t px, Float_t py, Float_t pz)
{
//
// Method which add one measured particle to event. Arguments are 3 momenta
// of this particle and method returns pointer to this new particle. This
// pointer is usefull for setting another data members of this particle.
// Method has one side effect, namely automatic increase of number of
// particles in event.
//
TClonesArray &track=*fParticles;
new(track[fNParticles++]) TBigDSWriteParticle(px,py,pz);
return ((TBigDSWriteParticle*)fParticles->At(fNParticles-1));
}
TBigDSWriteParticle *TBigDSWriteEvent::AddParticle(TBigDSWriteParticle *anopart)
{
//
// Method which add one measured particle to event. Argument is another
// measured particle which is used for setting data members of new one
// particle. Here is also side effect which increase fNParticles.
// Return value is pointer to added particle.
//
TClonesArray &track=*fParticles;
new(track[fNParticles++]) TBigDSWriteParticle(anopart);
return ((TBigDSWriteParticle*)fParticles->At(fNParticles-1));
}
void TBigDSWriteEvent::Copy(TBigDSWriteEvent *anoevent)
{
//
// Method which copy another event to this one. During this operation is
// previous information in this event destroyed.
//
Int_t npart;
TClonesArray *array;
npart=anoevent->GetNParticles();
array=anoevent->GetParticles();
fNParticles=0;
for (int i=0;i<npart;i++)
this->AddParticle((TBigDSWriteParticle*)array->At(i));
fNRun=anoevent->GetNRun();
fNEvent=anoevent->GetNEvent();
fNGrey=anoevent->GetNGrey();
fEveto=anoevent->GetEveto();
fWeight=anoevent->GetWeight();
fbi=anoevent->GetBi();
fbg=anoevent->GetBg();
ftriggers=anoevent->GetTriggers();
fvtxx=anoevent->GetVtxX();
fvtxy=anoevent->GetVtxY();
fvtxz=anoevent->GetVtxZ();
}
inline void TBigDSWriteEvent::SetToFirst()
{
// Sets the iterator to first particle, so GetNext() method will give first
// one.
fpart_iter->Reset();
}
inline TBigDSWriteParticle* TBigDSWriteEvent::GetNext()
{
// Returns next particle. If we are at end of the list, it returns 0.
return( (TBigDSWriteParticle *) fpart_iter->Next() );
}
#include "TObject.h"
#include "TBigDSWriteParticle.h"
/*
Class to handle tracks witch clusters
071003 [ondrej] created, based upon Michals T[Mer,Write][Event,Particle]
*/
ClassImp(TBigDSWriteParticle)
TBigDSWriteParticle::TBigDSWriteParticle()
{
// default constructor - zeros and emty array of clusters
fPx=0;
fPy=0;
fPz=0;
fNClusters=0;
}
TBigDSWriteParticle::TBigDSWriteParticle(Float_t px,Float_t py, Float_t pz)
{
fPx=px;
fPy=py;
fPz=pz;
fNClusters=0;
}
/*
TBigDSWriteParticle::TBigDSWriteParticle(TBigDSWriteParticle *anopart)
{
// this->Copy(anopart);
Int_t nclust, fgn;
Float_t fftmpp[3];
Int_t fftmpn[4];
nclust=anopart->GetNClusters();
fNClusters=0;
for (int i=0;i<nclust;i++)
{
fgn=anopart->GetCluster(fftmpp,fftmpn,i);
this->AddCluster(fftmpp[0], fftmpp[1], fftmpp[2], fftmpn[0],fftmpn[1],fftmpn[2],fftmpn[3]);
}
fPx=anopart->GetPx();
fPy=anopart->GetPy();
fPz=anopart->GetPz();
flag=anopart->GetFlag();
fch=anopart->GetCharge();
}
*/
TBigDSWriteParticle::~TBigDSWriteParticle()
{
// remove clusters
}
/*
Int_t TBigDSWriteParticle::AddCluster(Float_t x, Float_t y, Float_t z, Int_t pos, Int_t cha, Int_t sig, Int_t var)
{
fClustX[fNClusters]=x;
fClustY[fNClusters]=y;
fClustZ[fNClusters]=z;
fClustPos[fNClusters]=pos;
fClustCha[fNClusters]=cha;
fClustSig[fNClusters]=sig;
fClustVar[fNClusters]=var;
fNClusters++;
return fNClusters;
}
Int_t TBigDSWriteParticle::GetCluster(Float_t clustp[3], Int_t clustn[4], Int_t nclust)
{
clustp[0]=fClustX[nclust];
clustp[1]=fClustY[nclust];
clustp[2]=fClustZ[nclust];
clustn[0]=fClustPos[nclust];
clustn[1]=fClustCha[nclust];
clustn[2]=fClustSig[nclust];
clustn[3]=fClustVar[nclust];
return 0;
}
Int_t TBigDSWriteParticle::GetCluster(Float_t clustp[3], Int_t nclust)
{
if(nclust < fNClusters) {
clustp[0]=fClustX[nclust];
clustp[1]=fClustY[nclust];
clustp[2]=fClustZ[nclust];
return 0;
} else {
return -1;
}
}
void TBigDSWriteParticle::Copy(TBigDSWriteParticle *anopart)
{
//
// Method which copy another particle to this one. During this operation is
// previous information in this particle destroyed.
//
Int_t nclust, fgn;
Float_t fftmpp[3];
Int_t fftmpn[4];
nclust=anopart->GetNClusters();
fNClusters=0;
for (int i=0;i<nclust;i++)
{
fgn=anopart->GetCluster(fftmpp,fftmpn,i);
this->AddCluster(fftmpp[0], fftmpp[1], fftmpp[2], fftmpn[0],fftmpn[1],fftmpn[2],fftmpn[3]);
}
fPx=anopart->GetPx();
fPy=anopart->GetPy();
fPz=anopart->GetPz();
flag=anopart->GetFlag();
fch=anopart->GetCharge();
}
*/
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET