Using std::map in a ROOT macro

Hello,

I’d like to write a macro for plotting several histos and to simplify this, I want to use std:mapstd::string,TH1F*

The relevant part of my macro is:

std::mapstd::string,TH1F* h1_;
h1_[“sihih_10_20_EB_zee” ] = ((TH3F*)fzee ->Get(“eta_0_1450/htptempl_eta_0_1450_all”))->Project3D(“x”);

While trying to run this:
root -l macro.C

I get the error as follows:

Error: Can’t call map<string,TH1F*,less,allocator<pair<const string,TH1F*> > >::operator in current scope compareTemplates_pl.C:42:
Possible candidates are…
(in map<string,TH1F*,less,allocator<pair<const string,TH1F*> > >)
Error: improper lvalue compareTemplates_pl.C:42:
(class TH1F*)0x8d74990
*** Interpreter error recovered ***

However, I use this stuff in compiled version of my code where it works.

I’d really appreciate any help in solving this issue.

Best regards,

[quote=“devdatta”]Hello,

I’d like to write a macro for plotting several histos and to simplify this, I want to use std:mapstd::string,TH1F*

The relevant part of my macro is:

std::mapstd::string,TH1F* h1_;
h1_[“sihih_10_20_EB_zee” ] = ((TH3F*)fzee ->Get(“eta_0_1450/htptempl_eta_0_1450_all”))->Project3D(“x”);

While trying to run this:
root -l macro.C

I get the error as follows:

Error: Can’t call map<string,TH1F*,less,allocator<pair<const string,TH1F*> > >::operator in current scope compareTemplates_pl.C:42:
Possible candidates are…
(in map<string,TH1F*,less,allocator<pair<const string,TH1F*> > >)
Error: improper lvalue compareTemplates_pl.C:42:
(class TH1F*)0x8d74990
*** Interpreter error recovered ***

However, I use this stuff in compiled version of my code where it works.
[/quote]

I’m sure Axel will respond, but when I last tried this, map just didn’t work well in Cint. Either use compiled code or PyRoot.
Cheers, Charles

Hi,

yes, Charles is right: you shoudl create a dictionary for std:mapstd::string,TH1F*, see e.g. root.cern.ch/drupal/faq#n627 on how to do that.

Cheers, Axel.

Hi,

Thanks for the reply. Got it working. Just to confirm, my loader script for generating the dictionary is this:
// File loader.C
#include
#include
#include “TH1.h”
#ifdef MAKECINT
#pragma link C++ class std::mapstd::string,TH1*+;
#endif

and I invoke this as .L loader.C+ for generating the shared object. I get several warnings (do not understand if these are harmless):

Info in TUnixSystem::ACLiC: creating shared library /media/DEVDATTA2/Analysis/EWK/Multiboson/Systematics/TemplateMethod/SignalShape/./loader_C.so
In file included from /media/DEVDATTA2/Analysis/EWK/Multiboson/Systematics/TemplateMethod/SignalShape/./fileBXwew2.cxx:18:
/usr/include/root/TCollectionProxyInfo.h: In member function ‘T& ROOT::TCollectionProxyInfo::Environ::iter() [with T = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits, std::allocator >, TH1*> >]’:
/usr/include/root/TCollectionProxyInfo.h:140: instantiated from ‘static void* ROOT::TCollectionProxyInfo::Type::first(void*) [with T = std::map<std::basic_string<char, std::char_traits, std::allocator >, TH1*, std::less<std::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits, std::allocator >, TH1*> > >]’
/usr/include/root/TCollectionProxyInfo.h:352: instantiated from ‘static ROOT::TCollectionProxyInfo* ROOT::TCollectionProxyInfo::Generate(const T&) [with T = ROOT::TCollectionProxyInfo::MapInsert<std::map<std::basic_string<char, std::char_traits, std::allocator >, TH1*, std::less<std::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits, std::allocator >, TH1*> > > >]’
/media/DEVDATTA2/Analysis/EWK/Multiboson/Systematics/TemplateMethod/SignalShape/./fileBXwew2.cxx:63: instantiated from here
/usr/include/root/TCollectionProxyInfo.h:66: warning: dereferencing type-punned pointer will break strict-aliasing rules

Best regards,

Devdatta.

Hi,

they’re fine.

Cheers, Axel.