Hi,
I’m trying to read a stl collection of std::vector<std::vector >, unfortunately its proving difficult.
When I open my input file using root, I don’t get any errors about nested vectors, but when I try to use the following minimal example:
tree-bug.cxx:
#include "TFile.h"
#include "TTree.h"
#include <iostream>
#include <vector>
using namespace std;
int main(void){
TFile file("ntuple.root");
TTree* tree = dynamic_cast<TTree*>(file.Get("JPsi"));
std::vector<std::vector<int> > *mu_trk_idx=NULL;
tree->SetBranchAddress("MUONS_index",&mu_trk_idx);
cout << tree << " "<< tree->GetName() << " "<< tree->GetEntries()<<endl;
for(int i = 0; i < tree->GetEntries(); i++){
tree->GetEntry(i);
}
return 0;
}
I get the following error:
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "MUONS_index". The class expected (vector<vector<int> >) refers to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector<vector<int> >)
0x143cca0 JPsi 23171
Here’s the rules from my Makefile:
src/dict.cxx: include/LinkDef.h
rootcint -f $@ -c $(CXXFLAGS) -p $^
src/libDict.so: src/dict.cxx
$(CC) -shared -fPIC -o$@ $(CXXFLAGS) $^
bin/tree-bug: bin/tree-bug.o src/libDict.so
$(CC) $^ -o $@ $(LDFLAGS) -L ./src -l Dict
My LinkDef.h looks like:
#include <vector>
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ std::vector<std::vector<int> >+;
#endif
I don’t understand what I’m doing wrong. I’ve read Chapter 15 of the Users Guide, and I didn’t find anything that I’m doing something wrong. To be absolutely explicit, here’s the list of commands that my Makefile simplifies to:
rootcint -f src/dict.cxx -c -m64 -pg -I/home/dave/tree-test/include -I/home/dave/root/include -I/home/dave/local/include -O0 -g3 -fno-inline -Wextra -Wall -ansi -p include/LinkDef.h
g++ -shared -fPIC -osrc/libDict.so -m64 -pg -I/home/dave/tree-test/include -I/home/dave/root/include -I/home/dave/local/include -O0 -g3 -fno-inline -Wextra -Wall -ansi src/dict.cxx
g++ bin/tree-bug.o src/libDict.so -o bin/tree-bug -L/home/dave/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -Wl,-rpath,/home/dave/local/lib -lm -L/home/dave/local/lib -lfastjettools -lfastjet -lNsubjettiness -L ./src -l Dict
Here’s my root version:
ROOT 5.34/26 (v5-34-26@v5-34-26, Feb 20 2015, 13:23:25 on linuxx8664gcc)
And if it matters my machine and gcc version:
$ uname -a
Linux XXXXXX 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux
$ g++ --version
g++ (Debian 4.9.2-10) 4.9.2