Hi,
I am trying to use multimap in ROOT 5.27. But there is always complaints that the multimap iterator is not defined:
The following is my code:
//read_map_struct.h
#include <iostream>
using namespace std;
struct map_info_struct
{
int run; //.. run number
int eventnumber_min; //.. max eventnumber in this file
int eventnumber_max; //.. min eventnumber in this file
string fname; //.. file name
};
Here is the dictionary of the multimap
//AutoDict_multimap_int_map_info_struct__.cxx
#include "map"
#include "./read_map_struct.h"
#ifdef __CINT__
#pragma link C++ nestedclasses;
#pragma link C++ nestedtypedefs;
#pragma link C++ class multimap<int,map_info_struct*>+;
#pragma link C++ class multimap<int,map_info_struct*>::*;
#pragma link C++ operators multimap<int,map_info_struct*>::iterator;
#pragma link C++ operators multimap<int,map_info_struct*>::const_iterator;
#pragma link C++ operators multimap<int,map_info_struct*>::reverse_iterator;
#endif
And then it is my main code:
#include <iostream>
#include <map>
#include <TFile.h>
#include <TSystem.h>
#include <TTree.h>
#include "read_map_struct.h"
using namespace std;
void read_map_struct()
{
gSystem->Load("../../../../lib/slc5_amd64_gcc434/libAna00.so");
map_info* a = new map_info;
TFile f("mapRunLumiHfTreeFile_highPt_PbPb_0To2.root");
TTree* tmap = (TTree*)f.Get("tmap");
tmap->SetBranchAddress("map_info", &a);
gROOT->ProcessLine(".L AutoDict_multimap_int_map_info_struct__.cxx+");
std::multimap<int, map_info_struct*> * listOfHFTreeFile = new multimap<int, map_info_struct*>;
for (int i = 0; i<tmap->GetEntries(); i++) {
tmap->GetEntry(i);
int run = a->get_run();
cout << "run ==" << a->get_run() << "***eventnumbermin ==" << a->get_eventnumber_min() << "***eventnumbermax ==" << a->get_eventnumber_max() << endl;
cout << "file name===" << a->get_fname() << endl;
cout << "test filled" << endl;
map_info_struct *b = new map_info_struct;
b->run = a->get_run();
b->eventnumber_min = a->get_eventnumber_min();
b->eventnumber_max = a->get_eventnumber_max();
cout << "struct filled" << endl;
listOfHFTreeFile->insert(make_pair(run, b));
}
cout << "all filled" << endl;
for( typename multimap<int, map_info_struct*>::iterator tt = listOfHFTreeFile->begin();tt!=listOfHFTreeFile->end(); tt++) {
cout << "in loop" << endl;
cout<< tt->first << endl;
}
}
libAna00.so is a library including the definition of map_info class.
With this code, I want to read the information inside map_info and fill it in multimap.
I run the code with “root -l read_map_struct.C”
And I got the following errors:
root [0]
Processing read_map_struct.C…
run ==182798***eventnumbermin ==8196864***eventnumbermax ==8236920
file name===HeavyFlavor_PbPb_160_1_EUK.root
test filled
struct filled
run ==182798***eventnumbermin ==8237415***eventnumbermax ==8277207
file name===HeavyFlavor_PbPb_163_1_7VV.root
test filled
struct filled
all filled
in loop
Error: Symbol tt is not defined in current scope read_map_struct.C:49:
Error: Failed to evaluate tt->first
(class G__CINT_ENDL)438940704
*** Interpreter error recovered ***
I think the multimap is filled correctly, but I fill to read the information in the multimap. I have tried many different things, but no improvement. I really have no idea what is wrong with my code.
Thanks.
Jian