Hello, I am trying to do the following:
I want to make aTClonesArray (to be reused as arbitrary number of
times) which holds Objects of type “myclass”. myclass in turn has a
datamember TList* tl, which holds an arbitrary number of another
userdefined type. (In my attached example macro it’s just TVector.)
ACLIC compiles the macro and I can write the TClonesAraray, but
the tcloneslist_analyse() function bombs when I access the TLists.
Also removing the comment in front of tl->Clear() leads to a crash
when writing the TClonesArray.
Applying TClonesArray::bypassStreamer(kFALSE) did not cure the
problem.
Is there something I do wrong?
Thanks for any help
Tassilo
#include "TVector.h"
#include "TList.h"
#include "TFile.h"
#include "TClonesArray.h"
#include "TString.h"
class myclass : public TNamed
{
public:
myclass(void){};
myclass(Char_t* name, Char_t* title,Int_t len):TNamed(name,title)
{
tl=new TList();
tl->SetOwner(kTRUE);
//tl->Clear();
tl->Add(new TVector());
cout <<"Made a new list with "<< tl->GetSize() <<" elements" << endl;
}
void print() {cout << tl <<endl;}
~myclass(void){};
TList* tl;
ClassDef(myclass,1);
};
void tcloneslist_write()
{
TFile* outfile = new TFile("tcloneout.root","RECREATE");
TClonesArray TCA("myclass",10,kFALSE);
for(Int_t i=0;i<10;i++)
{
char name[16];
sprintf(name,"%s%d","myclass",i);
TCA[i]= new myclass(name,name,i);
}
TCA.Write();
outfile->Close();
}
void tcloneslist_analyse()
{
TFile *_file0 = TFile::Open("tcloneout.root");
myclass* myPtr=0;
for(Int_t j=0;j<10;j++)
{
char name[16];
sprintf(name,"%s%d","myclass",j);
cout << "Retrieving object nr: " << j << endl;
myPtr = (myclass*)gDirectory->Get(name);
//myPtr->print();
}
}