Hi! I have a map<int, vector<double>> in a root file and I want to open it and access the vectors inside.
At first, ROOT didn’t seem to recognize the map<int, vector<double>> type, so I added this line in LinkDef.h
#pragma link C++ class map<int, vector<double>>;
And here is my script:
(Bunch of #include)
using namespace std;
void macro_test ( ) {
TFile *f = new TFile("datafile.root");
map<int, vector<double>> *MyMap;
TTree *T = (TTree*)f->Get("SomeData");
T->SetBranchAddress("m_map",&MyMap);
T->GetEntry(0);
cout << (*MyMap).size <<endl ; //size is correctly printed
for(map<int, vector<double> >::iterator it = (*MyMap).begin(); it != (*MyMap).end(); ++it) {
cout << it->first << " ";
}
cout << endl;
}
But then I get this error :
Error: Symbol it is not defined in current scope macro_test.C
Error: Failed to evaluate it->first
I also tried using (*it).first but I got the same result. It seems that the iterator itself doesn’t exist, but the loop runs correctly if I print a simple statement like cout << "Loop iteration works! << endl;".
I’m using ROOT 5.34. And you’re right, I forgot to load the library using gSystem->Load("Mylib.so").
I’ve added this command but then I got the following error, which makes no sense to me :
Error: operator== not defined for map<int,vector<double,allocator<double> >,less<int>,allocator<pair<const int,vector<double,allocator<double> > > > >::iteratorError: operator== not defined for map<int,vector<double,allocator<double> >,less<int>,allocator<pair<const int,vector<double,allocator<double> > > > >::iterator function.h:33:
Error: non class,struct,union object it used with . or ->
Error: << Illegal operator for pointer 3
Then I thought maybe I need to define the iterator as well as the map in the LinkDef, so I added #pragma link C++ class map<int, vector<double>>::iterator; but then I got the same error as in my first post (Symbol it is not defined).
You also need to generate the dictionary for the operators.
#pragma link C++ operators map<int, vector<double>>;
#pragma link C++ operator map<int, vector<double>>::iterator;
#pragma link C++ operator map<int, vector<double>>::const_iterator;
#pragma link C++ operator map<int, vector<double>>::reverse_iterator;