Branch of map in root tree

Hello all,

I am trying to make branch of map in root tree.
The way I am doing is :

[code]std::map<std::string, int> *triggermap;
myTree->Branch(“triggermap”,“map<string,int>”,&triggermap);
triggermap = new std::map<string,int>;
triggermap->clear();

triggermap->insert(pair<string,int>(“is_HLT_Ele10_SW_L1R_event”,is_HLT_Ele10_SW_L1R_event));
triggermap->insert(pair<string,int>(“is_HLT_Ele15_SW_L1R_event”,is_HLT_Ele15_SW_L1R_event));
[/code]

And in mt .cc code I add the following lines :

#include <map> #ifdef __MAKECINT__ #pragma link C++ class map<string,int>+; #pragma link C++ class map<string,int>::iterator; #pragma link C++ class pair<string,int>; #endif

Now if I run the code I get the following error :

So even if I add the lines to generate the library, why is this error coming?
Could sombody please help me with th eerror ?

Thanks & Regards,
Shilpi

Hello,

I would like to add one more thing :
On one of the lxplus machines it worked with these lines.
But on the other it didn’t.
and I am using :
/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.22.00a-cms17/

Could anyone please tell me what needs to be done
so as to make this work on other machines as well?

Thanks,
Best Regards,
Shilpi

Hi,

you need to create the dictionary, see root.cern.ch/phpBB2/viewtopic.php?t=10029 Adding the pragma statements to your source is not sufficient.

Cheers, Axel.

Hello Axel,

Thanks much for the reply.
I tried that.
This is how my loader.C looks like :

#include <map> #ifdef __MAKECINT__ #pragma link C++ class map<string,int>; #pragma link C++ class map<string,int>::iterator; #pragma link C++ class pair<string,int>; #endif

I did :

but I get the following error :

Info in <TUnixSystem::ACLiC>: creating shared library /afs/cern.ch/user/s/shilpi/private/compile_files/cmssw314/treeBasedFiles/./loader_C.so Note: Link requested for already precompiled class map<string,int,less<string>,allocator<pair<const string,int> > > (ignore this message) :0: Note: Link requested for undefined class pair<string,int> (ignore this message) :0: Note: Link requested for already precompiled class map<string,int,less<string>,allocator<pair<const string,int> > >::iterator (ignore this message) :0: Error in <ACLiC>: Dictionary generation failed! Info in <ACLiC>: Invoking compiler to check macro's validity Info in <ACLiC>: The compiler has not found any problem with your macro. Probably your macro uses something rootcint can't parse. Check http://root.cern.ch/root/Cint.phtml?limitations for Cint's limitations.

Could you please tell me what is it that I missing?

Thanks,
Best Regards,
Shilpi

Hi,

You are problably just missing #include

Cheers,
Philippe.

Hello Philippe,

Thanks a lot.
I tried that. But its still giving me
the same error.

Best Regards,
Shilpi

Hi,

I can not reproduce your compilation error.

However map<string,int> is one of the container for which we provide a dictionary so just need to make sure that the interpreter see #include before passing a map to TTree::Branch. If your code is compiled just issue (literaly):gROOT->ProcessLine("#include <map>");(and add #include “TROOT.h”).

Cheers,
Philippe.

Hello Philippe,

Many thanks. That worked.

Best Regards,
Shilpi