First of all I would like to thank you in advance for any help. I am developing a program in C++/QT5 in which I have linked the ROOT libraries. I am using root 5.34 for the moment. I am facing the following very trivial problem but I cannot find a way to solve it.
I am creating a TTree which I want to fill, for example :
I think we really need a dictionary here.
Could you post the header file and implementation of the class of which chIdVariable is an instance? That is all one needs to create a dictionary.
Thanks a lot for the reply. I attach the file here. The mainwindow.h is the header file in which I am declaring the vectors (line 82) and the mainwindow.cpp the class implementation where I am using them to declare the branches (line 2282). Sorry I am not a good programmer as you will see and thatās why I need some help ! Thank you very very much in advance !
as far as I can see you need only to write std::vector instances.
ROOT already provides the dictionaries to perform this operation, so no need to generate any new dictionary or doing anything special. I/O of stl collections in trees is seamlessly supported.
See for example this tutorial: root.cern.ch/root/html/tutorial ⦠ion.C.html
Thanks for the help I appreciate it. I think Iāve seen the example but I couldnāt really manage to succeed. For example root can generate by gIntepreter->GenerateDictionary command a dictionary for vector of vectors but I have not succeed to use them⦠I am still getting the same errorsā¦
If we restrict our focus to the files you posted, there is no vector of vectors branch in your tree, just vector. This must work with ROOT w/o generating dictionaries. If it does not in your case, one fruitful strategy could be to slim down the usecase to a bunch of lines which reproduce the problem.
if you need to persist a vector of vectors, you need to create a dictionary: root does not ship it by default. In this case, what is the issue with the dictionary generation?
I use vector<vector > in the code and thatās where I run into problems. With these vector of vectors when I use them in branches I get the error that ROOT
Error in TTree::Branch: The pointer specified for channel is not of a class or type known to ROOT
although itās a vector of vectors of int. Thatās what I donāt understand either.
I had the same issue with just vectors which I solve by doing :
evSizeBranch = vmm2->Branch(āeventSizeā,āstd::vectorā,&evSizeVariable);
instead of
evSizeBranch = vmm2->Branch(āeventSizeā,&evSizeVariable);
If I do the same with vector of vectors of int I run into problems⦠The thing is that this is a huge code in QT which I donāt know how to make it small and show you a small reproducible problem.
What is more surprising is that this code was working in root 5.28 with no issuesā¦
For āstd::vector<std::vector >ā see [url=https://root-forum.cern.ch/t/storing-2d-vector-vector-vector-into-a-ttree/14331/2
For āstd::vector<std::vectorstd::string >ā see [url=https://root-forum.cern.ch/t/problem-in-getting-the-vector-vector-string-branch/14608/4
I missed the type of the branch as the code was spread between a long-ish header and implementation
So, here you can find the steps to create a dictionary, compile it as a shared lib, load it into a program. a.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class vector<vector<int> >+;
#endif
I owe you a beer for sure !! Thank you very much, I think I managed to implement this correctly, at least I get no errors once I initialise the branches now. Having it for ROOT 6 would be nice because soon Iāll be into it.
for ROOT6, you can just use the same commands: the two versions are compatible.
Alternatively, you could formulate the selection as follows myselection.xml
You noticed the generation of the rootmap. This file allows root to automatically load the library and can be generated together with the dictionaries in version 6. Concretely, you donāt have to bother loading the library yourself, i.e. you can remove āgSystem->Load(ālibMylib.soā);ā.