Add a vector<vector<float> > to a TTree

Hello everydoy,
I am trying to store a matrix into a TTree but I get the follwoing problem with Branch

“Error in TTree::Branch: The pointer specified for matrice is not of a class or type known to ROOT”

This is kind of weired because I can use STL vectors, but not vectors of vectors …

TFile *f = TFile::Open(jetfilename, "RECREATE");

				if (!f) {
					puts("file non trovato");
					exit(0);
				}

				std::vector<float> vpx;
				std::vector<float> vpy;
				std::vector<float> vpz;
				std::vector<float> vrand;
				std::vector<vector<float> > matrix;

				// Create a TTree
				TTree *t = new TTree("tvec", "Tree with vectors");
				t->Branch("vpx", &vpx);
				t->Branch("vpy", &vpy);
				t->Branch("vpz", &vpz);
				t->Branch("vrand", &vrand);
/******* the following addition of a Branch gives the error *****/
				t->Branch("matrice", &matrix);

Notice I have the following line of code

	gROOT->ProcessLine("#include <vector>");

placed before what the part where I add the branch. This line is crucial to not get a similar error for vector variables such as the vpx used in the above code, but I have no idea how to change it to allow also nested vectors.

Thanks for your help
Roberto

Hi,

you need to create a dictionary for vector<vector >. See e.g. root.cern.ch/phpBB2/viewtopic.php?t=2061

Cheers, Axel.

Thanks a lot for answering and suggesting building a dictionary (whatever does it mean). Apparently this dictionary thing does not help.

In facts I can compile and run properly using vectors of floats both with and without the following

#ifdef __MAKECINT__
#pragma link C++ class std::vector<float>+;
#endif

I tried to add

#ifdef __MAKECINT__
#pragma link C++ class std::vector<vector<float> >+;
#endif

but it does not help.

The only thing which seem crucial is the line with

gROOT->ProcessLine("#include <vector>");

which I do not know how to extend to encompass vectors of vectors.

Thanks for reading.
Roberto

Hi Roberto,

[quote]Thanks a lot for answering and suggesting building a dictionary (whatever does it mean).[/quote]Please re-read the User’s Guide which explain what a dictionary is in the context of ROOT, your symptoms indicates that you have not generated the dictionary (or not compiled it or not linked it or not loaded it, all four steps are necessary).

Cheers,
Philippe.

thanks for answering. After your reply I did generate the dictionary as explained in
root.cern.ch/phpBB2/viewtopic.php?t=2294

and I got .so file

Now I think I know how to use it for the compilation and linking, I hope, but the loading part you are referring to … what you meant? Should I have something in the code? I am getting confused …

Hi,

Simply do gSystem->Load("mylibrary.so");

Cheers,
Philippe

thanks for replying
your line seems to do the same of adding the .so to list of files to be used in g++
as in
gcc -o bbar.exe bbar.cpp mylib.so

now it does not complain any longer of the unknown type. never the less it seems the content is not properly understood.
I have to go deeper to see what’s in the file.
For the moment many thanks.
Roberto