I am trying to create a Tree Branch containing a simple two-dimensional array consisting of vector<vector<int> >
Here is some simple test code:
TTree T;
vector<vector<int> > testbranch;
T.Branch("testbranch", &testbranch);
The code above produces the error message:
Error in TTree::Branch: The class requested (
vector<vector<int> >
) for the branch “testbranch” is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (vector<vector<int> >
) to avoid to write corrupted data.
However, the following code with vector<vector<double> >
generates no error message:
vector<vector<double> > testbranch2;
T.Branch("testbranch2",&testbranch2);
My first question is: Why does vector<vector<double> >
work but vector<vector<int> >
not work (at least not automatically)?
By searching the forum, I was able to get vector<vector<int> >
to work in an interactive root session using:
gInterpreter->GenerateDictionary("vector<vector<int> >","vector");
T.Branch("testbranch3",&testbranch);
which gives no error. Which is fine for an interactive ROOT session or a standalone ROOT macro. But I need to create such a branch in a large TTree that is created within a large, complicated program that uses ROOT and GEANT4, and has a somewhat complex CMake-based build system. Which leads to my second question:
What would be the recommended way to generate the appropriate dictionary and link it into some larger program where I want to create a TTree branch of vector<vector<int> >
, and said larger program is using a CMake build system? The program already uses ROOT_GENERATE_DICTIONARY in the CMakeLists.txt to generate the dictionary and shared library for another class that inherits from TObject and is used by that larger program. But I’m not creating a new class here. I just want to make a TTree Branch with a simple two-dimensional STL vector within this large program. I already have lots of other branches consisting of one-dimensional STL vectors of basic data types. And the two-dimensional vector with doubles works without any extra code. But for vector<vector<int> >
, the program compiles but doesn’t work at run time, in the sense that it spits out this error message and doesn’t create the tree branch in question. Your advice would be much appreciated.
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.22.08
Platform: Mac OS X 10.15.7
Compiler: Apple clang version 12.0.0 (clang-1200.0.32.29)