Howot use a std::vector as TTree branch

Dear all,
i would like to use a std::vector as branch for a TTree.
Can you please point me to an example or similar ?

Thanks,
Max

i’ve tried successfully with this code

#include
#include “TFile.h”
#include “TRandom.h”
#include “TTree.h”
#if defined (MAKECINT)
#pragma link C++ class vector+;
#endif

void test()
{
TFile f(“tree.root”,“RECREATE”);

std::vector* vec = new std::vector;
TRandom r;
TTree *tree = new TTree(“tree”,“tree”);
tree->Branch(“var”, &vec);

for(int i=0; i<100;i++) (*vec).push_back(r.Rndm()*10);

tree->Fill();

f.Write();
}

and it works both on CINT both compiled.
Now i would like to include it in an (atlas) athena algorithm, but it seems to crash on tree Fill() call. Do you know about some implementation working as example ?

Thanks,
Max

[quote]Now i would like to include it in an (atlas) athena algorithm, but it seems to crash on tree Fill() call. Do you know about some implementation working as example ? [/quote]I don’t know the details of the athena framework, however, most likely, the issue is that the dictionary for vector has not been loaded.

Cheers,
Philippe.

Dear Philippe,
can you please point me to some info about what it’s meant for dictionary (i guess probably in ROOT user guide?) and how to load it ?

Max

Hi,

Yes you will find an explanation of what a dictionary is and how to make them in the User’s Guide.
In short this is a source file which contain a description of your classes. This source file (the dictionary) is generated by rootcint (or by genreflex in some case). Once you compile and load this dictionary into a ROOT session, CINT and ROOT know about your classes. You can then use them in the interpreter or save them into a ROOT file.

Your framework must have its own way of inducing the generation, compilation and linking of the dictionary. In some case, you need to write a ‘linkdef’ file and place it in the right or you may have to write a selection.xml file (Both thoses files are means to tell the dictionary generator (rootcint/genreflex) which classes to generate a dictionary for).

Cheers,
Philippe