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
EGExtraInfoModifierFromFloatValueMaps Class Reference
Inheritance diagram for EGExtraInfoModifierFromFloatValueMaps:
ModifyObjectValueBase

Classes

struct  electron_config
 
struct  photon_config
 

Public Types

typedef edm::EDGetTokenT
< edm::ValueMap< float > > 
ValMapFloatToken
 
typedef std::unordered_map
< std::string,
ValMapFloatToken
ValueMaps
 
typedef std::unordered_map
< std::string, edm::InputTag
ValueMapsTags
 

Public Member Functions

 EGExtraInfoModifierFromFloatValueMaps (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
< float > > > 
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
< float > > > 
pho_vmaps
 
std::unordered_map< unsigned,
edm::Ptr< reco::Photon > > 
phos_by_oop
 

Detailed Description

Definition at line 17 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Member Typedef Documentation

Definition at line 19 of file EGExtraInfoModifierFromFloatValueMaps.cc.

typedef std::unordered_map<std::string,ValMapFloatToken> EGExtraInfoModifierFromFloatValueMaps::ValueMaps

Definition at line 20 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Definition at line 21 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Constructor & Destructor Documentation

EGExtraInfoModifierFromFloatValueMaps::EGExtraInfoModifierFromFloatValueMaps ( const edm::ParameterSet conf)

Definition at line 60 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References constexpr, EGExtraInfoModifierFromFloatValueMaps::electron_config::electron_src, HI_PhotonSkim_cff::electrons, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), ModifyObjectValueBase::name(), Parameters::parameters, EGExtraInfoModifierFromFloatValueMaps::photon_config::photon_src, interactiveExample::photons, AlCaHLTBitMon_QueryRunRegistry::string, EGExtraInfoModifierFromFloatValueMaps::electron_config::valuemaps, and EGExtraInfoModifierFromFloatValueMaps::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:185
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 EGExtraInfoModifierFromFloatValueMaps::modifyObject ( pat::Electron ele) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 164 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

164  {
165  // we encounter two cases here, either we are running AOD -> MINIAOD
166  // and the value maps are to the reducedEG object, can use original object ptr
167  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
170  auto key = eles_by_oop.find(ele_idx);
171  if( key != eles_by_oop.end() ) {
172  ptr = key->second;
173  } else {
174  throw cms::Exception("BadElectronKey")
175  << "Original object pointer with key = " << ele.originalObjectRef().key()
176  << " not found in cache!";
177  }
178  }
179  //now we go through and modify the objects using the valuemaps we read in
180  for( auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
181  float value(0.0);
182  assignValue(ptr,itr->second,ele_vmaps,value);
183  if( !ele.hasUserFloat(itr->first) ) {
184  ele.addUserFloat(itr->first,value);
185  } else {
186  throw cms::Exception("ValueNameAlreadyExists")
187  << "Trying to add new UserFloat = " << itr->first
188  << " failed because it already exists!";
189  }
190  }
191  ++ele_idx;
192 }
key_type key() const
Definition: Ptr.h:169
bool hasUserFloat(const std::string &key) const
Return true if there is a user-defined float with a given name.
Definition: PATObject.h:325
void assignValue(const T &ptr, const U &tok, const V &map, float &value)
void addUserFloat(const std::string &label, float data)
Set user-defined float.
Definition: PATObject.h:765
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:484
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
bool isUninitialized() const
Definition: EDGetToken.h:71
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
void EGExtraInfoModifierFromFloatValueMaps::modifyObject ( pat::Photon pho) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 195 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

195  {
196  // we encounter two cases here, either we are running AOD -> MINIAOD
197  // and the value maps are to the reducedEG object, can use original object ptr
198  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
201  auto key = phos_by_oop.find(pho_idx);
202  if( key != phos_by_oop.end() ) {
203  ptr = key->second;
204  } else {
205  throw cms::Exception("BadPhotonKey")
206  << "Original object pointer with key = " << pho.originalObjectRef().key() << " not found in cache!";
207  }
208  }
209  //now we go through and modify the objects using the valuemaps we read in
210  for( auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
211  float value(0.0);
212  assignValue(ptr,itr->second,pho_vmaps,value);
213  if( !pho.hasUserFloat(itr->first) ) {
214  pho.addUserFloat(itr->first,value);
215  } else {
216  throw cms::Exception("ValueNameAlreadyExists")
217  << "Trying to add new UserFloat = " << itr->first
218  << " failed because it already exists!";
219  }
220  }
221  ++pho_idx;
222 }
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps
key_type key() const
Definition: Ptr.h:169
bool hasUserFloat(const std::string &key) const
Return true if there is a user-defined float with a given name.
Definition: PATObject.h:325
void assignValue(const T &ptr, const U &tok, const V &map, float &value)
void addUserFloat(const std::string &label, float data)
Set user-defined float.
Definition: PATObject.h:765
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:484
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
bool isUninitialized() const
Definition: EDGetToken.h:71
void EGExtraInfoModifierFromFloatValueMaps::setConsumes ( edm::ConsumesCollector sumes)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 142 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

142  {
143  //setup electrons
145 
146  for( auto itr = e_conf.valuemaps.begin(); itr != e_conf.valuemaps.end(); ++itr ) {
147  make_consumes(itr->second,e_conf.tok_valuemaps[itr->first],sumes);
148  }
149 
150  // setup photons
152 
153  for( auto itr = ph_conf.valuemaps.begin(); itr != ph_conf.valuemaps.end(); ++itr ) {
154  make_consumes(itr->second,ph_conf.tok_valuemaps[itr->first],sumes);
155  }
156 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void make_consumes(T &tag, U &tok, V &sume)
void EGExtraInfoModifierFromFloatValueMaps::setEvent ( const edm::Event evt)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 97 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

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

Reimplemented from ModifyObjectValueBase.

Definition at line 135 of file EGExtraInfoModifierFromFloatValueMaps.cc.

135  {
136 }

Member Data Documentation

electron_config EGExtraInfoModifierFromFloatValueMaps::e_conf
private

Definition at line 46 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

unsigned EGExtraInfoModifierFromFloatValueMaps::ele_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > EGExtraInfoModifierFromFloatValueMaps::ele_vmaps
private

Definition at line 49 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

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

Definition at line 48 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

photon_config EGExtraInfoModifierFromFloatValueMaps::ph_conf
private

Definition at line 47 of file EGExtraInfoModifierFromFloatValueMaps.cc.

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

unsigned EGExtraInfoModifierFromFloatValueMaps::pho_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > EGExtraInfoModifierFromFloatValueMaps::pho_vmaps
private

Definition at line 51 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

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

Definition at line 50 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().