Hi Rene,
thanks to your help I manage to write the code,
but here's a question I think can be of interest
for everybody: I want a dynamic tree, id est I tried the following
code, which compiled and run but doesn't fill the tree.
//--------------------------A.h
#include "TObject.h"
#include <vector>
class Clas_event : public TObject
{
public:
Clas_event();
virtual ~Clas_event();
Electron(Double_t x);
VI();
Clear();
vector<double> A; <<----------------- lenght if elements may vary
ClassDef(Clas_event,1)
};
//------------------------A.cxx
#include "A.h"
ClassImp(Clas_event)
Clas_event::Clas_event() {}
Clas_event::~Clas_event() {}
Clas_event::Electron(Double_t x)
{
A.push_back(x); <<----------------- Here I put stuff in A
}
Clas_event::Clear()
{
A.clear(); <<----------------- Remove from memory A
}
Clas_event::VI() <<----------------- This to see A while the
code is running. I'm
seeing the right things
{
cout << "Size: " << A.size() << " - Contents : " ;
for (Int_t i=0;i<A.size();i++)
{
cout << " " << A[i];
}
cout << endl;
}
//-----------------------AMain.cxx
#include <iostream>
using namespace std;
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TTree.h"
#include "TBranch.h"
#include "A.h"
Clas_event *CC = new Clas_event;
TROOT Mauri("Bos_to_Root","Bos Banks to Root file conversion");
main()
{
TFile *myfile;
myfile = new TFile("file.root","RECREATE","TTree Dynamic ROOT file");
TTree *mytree = new TTree("T","My tree");
mytree->Branch("abcBranch","Clas_event",&CC);
for (Int_t i=0;i<10;++i)
{
for (Int_t j=0;j<i;++j)
{
CC->Electron(i);
}
mytree->Fill();
CC->VI();
CC->Clear();
}
mytree->Write();
mytree->Print();
return 0;
}
Mauri
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET