While there are several examples of how to access TBranch STL container elements from the Root interpreter and there are examples of how to add a new class to a TBranch in a compiled program, I can not see how to access TBranch STL container elements from a compiled program. For example:
std::vector<float> *lvl2_mbts_times;
// setup the TChain chain
chain->SetBranchAddress("lvl2_mbts_times", &lvl2_mbts_times);
// process the data
compiles but when the program runs there are errors of the form
It would seem that I should use something like
#include <vector>
#ifdef __MAKECINT__
#pragma link C++ class std::vector<float>+;
#endif
but how is this turned into a dictionary I can link to?
The dictonary for vector of int, float and double are pre-generated and can not be regenarated (i.e. when creating your dictionary you should have seen a note about vector, etc.).
In ROOT v5.20, the loading of this pre-generated dictionary has been automated. In ROOT v5.18, you need explicitly load it by asking the interpreter to execute #include . E.g.root [] #include <vector>
I am using a compiled program rather than the interpreter. The errors I mentioned come from running my compiled program.
I have a fix to my problem that seems to work. I’ve created a LinkDef.h containing all of the STL classes which I am using that are missing in v5.18.00d
#include <vector>
#ifdef __MAKECINT__
#pragma link C++ class std::vector<bool>+;
#pragma link C++ class std::vector<short>+;
#pragma link C++ class std::vector<int>+;
#pragma link C++ class std::vector<long>+;
#pragma link C++ class std::vector<float>+;
#pragma link C++ class std::vector<std::vector<double> >+;
#endif
then generated the dictionary with rootcint
where stl.h just contains
(Without stl.h the generated RootDictionary.h does not include vector and therefore does not compile.) I then compile the RootDictionary.cxx and link it with my code.
[quote]I am using a compiled program rather than the interpreter. The errors I mentioned come from running my compiled program. [/quote]In a compiled macro the advice is the almost the same do:gROOT->ProcessLine("#include <vector>");However you will still need to generate the dictionary for vector<vector >.
[quote](Without stl.h the generated RootDictionary.h does not include vector and therefore does not compile.) I then compile the RootDictionary.cxx and link it with my code. [/quote]Add the line #pragma extra_include "vector"; to you linkdef file.
[quote]I assume the warnings from rootcint are harmless? [/quote]Mostly . They mean that your dictionary will not contains any information about those vectors and that you still need to execute:gROOT->ProcessLine("#include <vector>");in order to load their dictionary.