V5.18.00d: Reading STL from TTree in a compiled program

Hi,

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?

Thanks and Best Regards,

Will

Hi,

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>

Cheers,
Philippe.

Hi Philippe,

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.

Is there a way of not creating stl.h?

Thanks and Best Regards,

Will

[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 :slight_smile: 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.

Cheers,
Philippe.

Hi Philippe,

Thanks for your email. I’ve added the suggested additional pragma statement and dropped the stl.h file.

I assume the warnings from rootcint are harmless?

Thanks and Best Regards,

Will

[quote]I assume the warnings from rootcint are harmless? [/quote]Mostly :slight_smile:. 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.

Cheers,
Philippe.