Hi,
Using root v 4.04/02b and g++ v3.4.3 on Linux
I am trying to create a branch with a TObjArray using this TTree method:
Int_t Branch(TCollection *li, Int_t bufsize, Int_t splitlevel, const char *name)
Here is the file with the main function:
//FILE: test_array_imp.cpp
#include "test_array.hpp"
#include "TFile.h"
#include "TTree.h"
#include "TObject.h"
#include <iostream>
using namespace std;
int main()
{
TFile * f = new TFile("test_array.root","RECREATE");
TTree * tree = new TTree("mytree","mytree");
TObjArray s(10);
tree->Branch(&s,64000,4,"stuff");
for( int i = 0; i<100 ; ++i) {
for ( int j = 0; j<7; ++j) {
s.Add(new MyCand(i,j));
cout << s.GetEntriesFast() << endl;
}
tree->Fill();
s.Delete();
cout << s.GetEntriesFast() << endl;
}
tree->Print();
tree->Write();
delete f;
return 0;
}
Here is the class implementation:
//FILE: test_array.cpp
#include "test_array.hpp"
#include "TObject.h"
ClassImp(MyCand);
MyCand::MyCand()
{
_i=0;
_j=0;
}
MyCand::MyCand(Int_t i, Int_t j)
{
_i=i;
_j=j;
}
//end test_array.cpp
//FILE: test_array.hpp
#include "TObject.h"
#include "Rtypes.h"
class MyCand : public TObject {
Int_t _i;
Int_t _j;
public:
MyCand();
MyCand(Int_t i, Int_t j);
ClassDef(MyCand,1)
};
//end test_array.hpp
//File: test_array_linkdef.h
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#ifdef __CINT__
#ifndef INCLUDE_CAND_CLASSES_LINKDEF
#define INCLUDE_CAND_CLASSES_LINKDEF
#pragma link C++ class MyCand+;
#endif
#endif // __CINT__
I compile this with
> rootcint -f test_arrayDict.cpp -c -I${ROOTSYS}/include est_array.hpp test_array_linkdef.h
> g++$(root-config --cflags) -c test_array.cpp test_arrayDict.cpp test_array_imp.cpp
> g+ -O -Wl $(root-config --ldflags) test_array.o test_array_imp.o test_arrayDict.o $(root-config --libs) -o test_array
The program runs and TObjArray::GetEntriesFast() returns the right number but there is no data in the tree
What can I do to put a TObjArray into a branch?
Thanks for your help,
Burair