I was trying to extract some TTree branch contains std::vector<TVector3> type values, I know I can write a macro and add a line: #pragma link C++ class std::vector<TVector3>+; and do something like: root macro.cxx++ to make it work.
But I want to compile my code by c++ compiler, which means it starts from int main(int argc, char** argv) instead of some function. How can I make it work instead of getting this error:
Error in <TTree::SetBranchAddress>: The class requested (vector<TVector3>) for the branch "trkDir" is an instance of an stl collection and does not have a compiled CollectionProxy.
Please generate the dictionary for this collection (vector<TVector3>) to avoid to write corrupted data.
Thank you for your reply, but I don’t have any custom classes in my code, I just want to use std::vector where std::vector is a STL class and TVector3 is a ROOT class both are already implemented, how can I use the combination of them?
Thank you for the information! I think the point is I don’t know what should I write in the std::vector<TVector3> cxx file and hxx file… normal custom TObject class has there own definitions, but what should I write in a std::vector<TVector3> class?
I mean, I need to give a name of the custom class at first, right? like:
class custom : public TVector3, public std::vector<TVector3>
{
};
After defining your own custom class (in files .h, .cxx), use pragmas to make the dictionary for the class and possible containers, as in the example. If you want to use a vector of TVector3, I think it is enough to add the corresponding pragma in the file LinkDef.h,
#pragma link C++ class std::vector<TVector3>+;
If TVector3 is a class of ROOT, in order to make the dictionary maybe it is enough to include the header and link against the corresponding root shared library wherever the definition of that class is.
But how to define my class aka. std::vector …? I don’t know what should I write in the class file, what I need is only the variable type of std::vector<TVector3> where std::vector and TVector3 are already defined in STL and ROOT
Excellent: thanks for sharing.
The + after the class name enables extra features and performance improvements in the I/O of the type (for more details, see here.