#include "TClonesArray.h" #include "TClass.h" #include "TObject.h" #include "TParameter.h" #include "TFile.h" #include "TTree.h" #include using namespace std; class MyTClonesArray : public TClonesArray { public: MyTClonesArray() : TClonesArray() {} MyTClonesArray(const TClonesArray& tc) : TClonesArray(tc) {} MyTClonesArray(const char* classname, Int_t size = 1000, Bool_t call_dtor = kFALSE) : TClonesArray(classname, size, call_dtor) {} MyTClonesArray(const TClass* cl, Int_t size = 1000, Bool_t call_dtor = kFALSE) : TClonesArray(cl, size, call_dtor) {} ClassDef(MyTClonesArray,1) }; ClassImp(MyTClonesArray) class MyWrapper : public TObject { public: MyWrapper() : TObject() {fArray = new MyTClonesArray("TParameter", 1000);} MyTClonesArray* fArray; //-> void InsertValue(); ~MyWrapper() {fArray->Clear("C");} ClassDef(MyWrapper,1) }; ClassImp(MyWrapper) void MyWrapper::InsertValue() { MyTClonesArray& MyArray = *fArray; new(MyArray[0]) TParameter("par_name", 8); } void tclwrite() { TFile MyFile("Mytcl.root","RECREATE"); TTree MyTree("tree","test tcl"); MyWrapper* fWrapper = new MyWrapper; MyTree.Branch("branch", &fWrapper, 100000, 0); fWrapper->InsertValue(); MyTree.Fill(); MyFile.Write(); } void tclread() { cout<<"If the read was successful, then the code will output 8."<GetBranch("branch"); MyBranch->SetAddress(&fWrapper); MyTree->GetEntry(0); TParameter* MyInt = (TParameter*) fWrapper->fArray->At(0); cout<<"Output: "<GetVal()<