CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
EGExtraInfoModifierFromIntValueMaps Class Reference
Inheritance diagram for EGExtraInfoModifierFromIntValueMaps:
ModifyObjectValueBase

Classes

struct  electron_config
 
struct  photon_config
 

Public Types

typedef edm::EDGetTokenT
< edm::ValueMap< int > > 
ValMapIntToken
 
typedef std::unordered_map
< std::string, ValMapIntToken
ValueMaps
 
typedef std::unordered_map
< std::string, edm::InputTag
ValueMapsTags
 

Public Member Functions

 EGExtraInfoModifierFromIntValueMaps (const edm::ParameterSet &conf)
 
void modifyObject (pat::Electron &) const overridefinal
 
void modifyObject (pat::Photon &) const overridefinal
 
void setConsumes (edm::ConsumesCollector &) overridefinal
 
void setEvent (const edm::Event &) overridefinal
 
void setEventContent (const edm::EventSetup &) overridefinal
 
- Public Member Functions inherited from ModifyObjectValueBase
virtual void modifyObject (pat::Muon &) const
 
virtual void modifyObject (pat::Tau &) const
 
virtual void modifyObject (pat::Jet &) const
 
 ModifyObjectValueBase (const edm::ParameterSet &conf)
 
const std::string & name () const
 
virtual ~ModifyObjectValueBase ()
 

Private Attributes

electron_config e_conf
 
unsigned ele_idx
 
std::unordered_map< unsigned,
edm::Handle< edm::ValueMap
< int > > > 
ele_vmaps
 
std::unordered_map< unsigned,
edm::Ptr< reco::GsfElectron > > 
eles_by_oop
 
photon_config ph_conf
 
unsigned pho_idx
 
std::unordered_map< unsigned,
edm::Handle< edm::ValueMap
< int > > > 
pho_vmaps
 
std::unordered_map< unsigned,
edm::Ptr< reco::Photon > > 
phos_by_oop
 

Detailed Description

Definition at line 17 of file EGExtraInfoModifierFromIntValueMaps.cc.

Member Typedef Documentation

Definition at line 19 of file EGExtraInfoModifierFromIntValueMaps.cc.

typedef std::unordered_map<std::string,ValMapIntToken> EGExtraInfoModifierFromIntValueMaps::ValueMaps

Definition at line 20 of file EGExtraInfoModifierFromIntValueMaps.cc.

typedef std::unordered_map<std::string,edm::InputTag> EGExtraInfoModifierFromIntValueMaps::ValueMapsTags

Definition at line 21 of file EGExtraInfoModifierFromIntValueMaps.cc.

Constructor & Destructor Documentation

EGExtraInfoModifierFromIntValueMaps::EGExtraInfoModifierFromIntValueMaps ( const edm::ParameterSet conf)

Definition at line 60 of file EGExtraInfoModifierFromIntValueMaps.cc.

References constexpr, EGExtraInfoModifierFromIntValueMaps::electron_config::electron_src, HI_PhotonSkim_cff::electrons, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), ModifyObjectValueBase::name(), Parameters::parameters, EGExtraInfoModifierFromIntValueMaps::photon_config::photon_src, interactiveExample::photons, AlCaHLTBitMon_QueryRunRegistry::string, EGExtraInfoModifierFromIntValueMaps::electron_config::valuemaps, and EGExtraInfoModifierFromIntValueMaps::photon_config::valuemaps.

60  :
61  ModifyObjectValueBase(conf) {
62  constexpr char electronSrc[] = "electronSrc";
63  constexpr char photonSrc[] = "photonSrc";
64 
65  if( conf.exists("electron_config") ) {
66  const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
67  if( electrons.exists(electronSrc) ) e_conf.electron_src = electrons.getParameter<edm::InputTag>(electronSrc);
68  const std::vector<std::string> parameters = electrons.getParameterNames();
69  for( const std::string& name : parameters ) {
70  if( std::string(electronSrc) == name ) continue;
71  if( electrons.existsAs<edm::InputTag>(name) ) {
73  }
74  }
75  }
76  if( conf.exists("photon_config") ) {
77  const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
78  if( photons.exists(photonSrc) ) ph_conf.photon_src = photons.getParameter<edm::InputTag>(photonSrc);
79  const std::vector<std::string> parameters = photons.getParameterNames();
80  for( const std::string& name : parameters ) {
81  if( std::string(photonSrc) == name ) continue;
82  if( photons.existsAs<edm::InputTag>(name) ) {
84  }
85  }
86  }
87  ele_idx = pho_idx = 0;
88 }
T getParameter(std::string const &) const
dictionary parameters
Definition: Parameters.py:2
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define constexpr
const std::string & name() const
std::vector< std::string > getParameterNames() const
ModifyObjectValueBase(const edm::ParameterSet &conf)

Member Function Documentation

void EGExtraInfoModifierFromIntValueMaps::modifyObject ( pat::Electron ele) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 170 of file EGExtraInfoModifierFromIntValueMaps.cc.

References pat::PATObject< ObjectType >::addUserInt(), e_conf, ele_idx, ele_vmaps, eles_by_oop, edm::hlt::Exception, pat::PATObject< ObjectType >::hasUserInt(), edm::EDGetTokenT< T >::isUninitialized(), edm::Ptr< T >::key(), relval_steps::key, pat::PATObject< ObjectType >::originalObjectRef(), EGExtraInfoModifierFromIntValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromIntValueMaps::electron_config::tok_valuemaps, and relativeConstraints::value.

170  {
171  // we encounter two cases here, either we are running AOD -> MINIAOD
172  // and the value maps are to the reducedEG object, can use original object ptr
173  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
176  auto key = eles_by_oop.find(ele_idx);
177  if( key != eles_by_oop.end() ) {
178  ptr = key->second;
179  } else {
180  throw cms::Exception("BadElectronKey")
181  << "Original object pointer with key = " << ele.originalObjectRef().key()
182  << " not found in cache!";
183  }
184  }
185  //now we go through and modify the objects using the valuemaps we read in
186  for( auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
187  int value(0);
188  assignValue(ptr,itr->second,ele_vmaps,value);
189  if( !ele.hasUserInt(itr->first) ) {
190  ele.addUserInt(itr->first,value);
191  } else {
192  throw cms::Exception("ValueNameAlreadyExists")
193  << "Trying to add new UserInt = " << itr->first
194  << " failed because it already exists!";
195  }
196  }
197  ++ele_idx;
198 }
key_type key() const
Definition: Ptr.h:186
bool hasUserInt(const std::string &key) const
Return true if there is a user-defined int with a given name.
Definition: PATObject.h:339
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > ele_vmaps
void addUserInt(const std::string &label, int32_t data)
Set user-defined int.
Definition: PATObject.h:784
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:484
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool isUninitialized() const
Definition: EDGetToken.h:71
void EGExtraInfoModifierFromIntValueMaps::modifyObject ( pat::Photon pho) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 201 of file EGExtraInfoModifierFromIntValueMaps.cc.

References pat::PATObject< ObjectType >::addUserInt(), edm::hlt::Exception, pat::PATObject< ObjectType >::hasUserInt(), edm::EDGetTokenT< T >::isUninitialized(), edm::Ptr< T >::key(), relval_steps::key, pat::PATObject< ObjectType >::originalObjectRef(), ph_conf, pho_idx, pho_vmaps, phos_by_oop, EGExtraInfoModifierFromIntValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromIntValueMaps::photon_config::tok_valuemaps, and relativeConstraints::value.

201  {
202  // we encounter two cases here, either we are running AOD -> MINIAOD
203  // and the value maps are to the reducedEG object, can use original object ptr
204  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
207  auto key = phos_by_oop.find(pho_idx);
208  if( key != phos_by_oop.end() ) {
209  ptr = key->second;
210  } else {
211  throw cms::Exception("BadPhotonKey")
212  << "Original object pointer with key = " << pho.originalObjectRef().key() << " not found in cache!";
213  }
214  }
215  //now we go through and modify the objects using the valuemaps we read in
216  for( auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
217  int value(0);
218  assignValue(ptr,itr->second,pho_vmaps,value);
219  if( !pho.hasUserInt(itr->first) ) {
220  pho.addUserInt(itr->first,value);
221  } else {
222  throw cms::Exception("ValueNameAlreadyExists")
223  << "Trying to add new UserInt = " << itr->first
224  << " failed because it already exists!";
225  }
226  }
227  ++pho_idx;
228 }
key_type key() const
Definition: Ptr.h:186
bool hasUserInt(const std::string &key) const
Return true if there is a user-defined int with a given name.
Definition: PATObject.h:339
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
void addUserInt(const std::string &label, int32_t data)
Set user-defined int.
Definition: PATObject.h:784
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:484
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > pho_vmaps
bool isUninitialized() const
Definition: EDGetToken.h:71
void EGExtraInfoModifierFromIntValueMaps::setConsumes ( edm::ConsumesCollector sumes)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 146 of file EGExtraInfoModifierFromIntValueMaps.cc.

References edm::ConsumesCollector::consumes(), e_conf, EGExtraInfoModifierFromIntValueMaps::electron_config::electron_src, ph_conf, EGExtraInfoModifierFromIntValueMaps::photon_config::photon_src, EGExtraInfoModifierFromIntValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromIntValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromIntValueMaps::electron_config::tok_valuemaps, EGExtraInfoModifierFromIntValueMaps::photon_config::tok_valuemaps, EGExtraInfoModifierFromIntValueMaps::electron_config::valuemaps, and EGExtraInfoModifierFromIntValueMaps::photon_config::valuemaps.

146  {
147  //setup electrons
149 
150  for( auto itr = e_conf.valuemaps.begin(); itr != e_conf.valuemaps.end(); ++itr ) {
151  make_consumes(itr->second,e_conf.tok_valuemaps[itr->first],sumes);
152  }
153 
154  // setup photons
156 
157  for( auto itr = ph_conf.valuemaps.begin(); itr != ph_conf.valuemaps.end(); ++itr ) {
158  make_consumes(itr->second,ph_conf.tok_valuemaps[itr->first],sumes);
159  }
160 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
void EGExtraInfoModifierFromIntValueMaps::setEvent ( const edm::Event evt)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 99 of file EGExtraInfoModifierFromIntValueMaps.cc.

References e_conf, ele_idx, ele_vmaps, eles_by_oop, edm::Event::getByToken(), i, edm::EDGetTokenT< T >::isUninitialized(), ph_conf, pho_idx, pho_vmaps, phos_by_oop, EGExtraInfoModifierFromIntValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromIntValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromIntValueMaps::electron_config::tok_valuemaps, and EGExtraInfoModifierFromIntValueMaps::photon_config::tok_valuemaps.

99  {
100  eles_by_oop.clear();
101  phos_by_oop.clear();
102  ele_vmaps.clear();
103  pho_vmaps.clear();
104 
105  ele_idx = pho_idx = 0;
106 
110 
111  for( unsigned i = 0; i < eles->size(); ++i ) {
112  edm::Ptr<pat::Electron> ptr = eles->ptrAt(i);
113  eles_by_oop[i] = ptr;
114  }
115  }
116 
117  for( auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
118  get_product(evt,itr->second,ele_vmaps);
119  }
120 
124 
125  for( unsigned i = 0; i < phos->size(); ++i ) {
126  edm::Ptr<pat::Photon> ptr = phos->ptrAt(i);
127  phos_by_oop[i] = ptr;
128  }
129  }
130 
131  for( auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
132  get_product(evt,itr->second,pho_vmaps);
133  }
134 }
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > ele_vmaps
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > pho_vmaps
bool isUninitialized() const
Definition: EDGetToken.h:71
void EGExtraInfoModifierFromIntValueMaps::setEventContent ( const edm::EventSetup evs)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 137 of file EGExtraInfoModifierFromIntValueMaps.cc.

137  {
138 }

Member Data Documentation

electron_config EGExtraInfoModifierFromIntValueMaps::e_conf
private

Definition at line 46 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), setConsumes(), and setEvent().

unsigned EGExtraInfoModifierFromIntValueMaps::ele_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<int> > > EGExtraInfoModifierFromIntValueMaps::ele_vmaps
private

Definition at line 49 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Ptr<reco::GsfElectron> > EGExtraInfoModifierFromIntValueMaps::eles_by_oop
private

Definition at line 48 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().

photon_config EGExtraInfoModifierFromIntValueMaps::ph_conf
private

Definition at line 47 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), setConsumes(), and setEvent().

unsigned EGExtraInfoModifierFromIntValueMaps::pho_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<int> > > EGExtraInfoModifierFromIntValueMaps::pho_vmaps
private

Definition at line 51 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Ptr<reco::Photon> > EGExtraInfoModifierFromIntValueMaps::phos_by_oop
private

Definition at line 50 of file EGExtraInfoModifierFromIntValueMaps.cc.

Referenced by modifyObject(), and setEvent().