Hi Rene,
many thanks and sorry to disturb you again but unfortunately i suspetc I'm
forced to put the array (or
TList) in the top class, I mean I cannot use the constructor
T.Branch(list) because my tree should contain an event class (similarly to
the example in $ROOTSYS/test/Event.*) so that I have to use something like
TBranch *branch = tree->Branch("event", "Event", &event,bsize, split);
and then it is inside the Event.h that I tried to put the array of
clonesarray:
class Event : public TObject{
Int_t nmu;
Int_t nTTtrk;
Int_t nCStrk;
Int_t nSStrk;
Int_t nBLtrk[36];
EventHeader evthdr;
TClonesArray *pTTtrack; // three different clonesarray
TClonesArray *pCStrack; // of tracks (use different
TClonesArray *pSStrack; // classes)
TClonesArray *pBLtrack[36]; // 36 identical clonesarray (same
// class)
static TClonesArray *gTTtrack;
static TClonesArray *gCStrack;
static TClonesArray *gSStrack;
static TClonesArray *gBLtrack[36];
......................................
while in Event.cpp:
TClonesArray *Event::gTTtrack = 0;
TClonesArray *Event::gCStrack = 0;
TClonesArray *Event::gSStrack = 0;
TClonesArray *Event::gBLtrack[36] = {0,0,0,......,0;
Event::Event(){
.....................................
for (Int_t i=0;i<36;i++) {
if (!gBLtrack[i]) gBLtrack[i] = new TClonesArray("BLtrack");
pBLtrack[i]=gBLtrack[i];
nBLtrk[i]=0;
}
......
}
void Event::AddBLtrack(i,.....){
TClonesArray &bl_tr=*pBLtrack[i];
new(bl_tr[nBLtrk[i]++]) BLtrack(.......)
}
..........................
void Event::Clear(Option_t *option){
for (Int_t i=0;i<36;i++) {
pBLtrack[i]->Clear(option);
nBLtrk[i]=0;
}
}
..........................
void Event::Reset(Option_t *option){
for (Int_t i=0;i<36;i++) {
delete gBLtrack[i]; gBLtrack[i] = 0;
}
}
In such a way the program runs and ends normally but then the
clonesarray pBLtrack[i] results to be empty. I was not able to use the
TList in these conditions as well.
On Mon, 1 Oct 2001, Rene Brun wrote:
> Hi Pierpaolo,
>
> I suggest the following:
>
> {
> TList *list = new TList();
> for (Int_t i=0;i<36;i++) {
> TClonesArray *carray = new TClonesArray("myclass",...);
> char name[32];
> sprintf(name,"ftracks%d",i);
> carray->SetName(name);
> list->Add(carray);
> }
>
> TTree T("T","..");
> T.Branch(list);
> T.Print();
> }
>
> This special Branch constructor takes a dynamic TList as input.
> The TList may contain TClonesArray or any other object.
> It is better than hardwired pointers or arrays in the top level class.
>
> Rene Brun
>
> Pierpaolo Righini wrote:
> >
> > Hello,
> > I have to write a root tree with events containing, each one, many tracks
> > that are identical for what concerns the informations contained (i.e. the
> > class definition is the same for all of them) but that should be tagged
> > differently because they came from different part of the apparatus. So
> > I would like to see them splitted using for example the TTree viewer.
> >
> > I tried to do an array of TClonesArray with
> >
> > TClonesArray *ftrack[36];
> >
> > instead of
> >
> > TClonesArray *f1track;
> > TClonesArray *f2track;
> > .......................
> > TClonesArray *f36track;
> >
> > in my Event class, but it seems not to work properly. Is there the chance
> > to do that? Many thanks in any cases.
> >
> > Pierpaolo
>
Pierpaolo
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:02 MET