1 #ifndef RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h 2 #define RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h 13 #include <unordered_map> 44 template<
typename OutputType>
51 template<
typename ObjType,
typename MapType>
60 template<
typename MapType,
typename OutputType=MapType>
64 using ValueMaps = std::unordered_map<std::string,ValMapToken>;
82 void setEvent(
const edm::Event&) override final;
84 void setConsumes(
edm::ConsumesCollector&) override final;
86 void modifyObject(
pat::
Electron&) const override final;
87 void modifyObject(
pat::
Photon&) const override final;
93 std::unordered_map<
unsigned,
edm::Ptr<
reco::GsfElectron> > eles_by_oop;
97 mutable
unsigned ele_idx,pho_idx;
101 template<typename MapType,typename OutputType>
108 if( conf.exists(
"electron_config") ) {
119 if( conf.exists(
"photon_config") ) {
130 ele_idx = pho_idx = 0;
135 inline void get_product(
const edm::Event& evt,
142 template<
typename MapType,
typename OutputType>
150 ele_idx = pho_idx = 0;
152 if( !e_conf.tok_electron_src.isUninitialized() ) {
156 for(
unsigned i = 0;
i < eles->size(); ++
i ) {
158 eles_by_oop[
i] = ptr;
162 for(
auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
163 get_product(evt,itr->second,ele_vmaps);
166 if( !ph_conf.tok_photon_src.isUninitialized() ) {
170 for(
unsigned i = 0;
i < phos->size(); ++
i ) {
172 phos_by_oop[
i] = ptr;
176 for(
auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
177 get_product(evt,itr->second,pho_vmaps);
182 template<
typename MapType,
typename OutputType>
191 {
if( !(empty_tag == tag) ) token = cc.
consumes<
T>(
tag); }
194 template<
typename MapType,
typename OutputType>
200 for(
auto itr = e_conf.valuemaps.begin(); itr != e_conf.valuemaps.end(); ++itr ) {
201 make_consumes(itr->second,e_conf.tok_valuemaps[itr->first],sumes);
207 for(
auto itr = ph_conf.valuemaps.begin(); itr != ph_conf.valuemaps.end(); ++itr ) {
208 make_consumes(itr->second,ph_conf.tok_valuemaps[itr->first],sumes);
213 template<
typename T,
typename U,
typename V,
typename MapType >
214 inline void assignValue(
const T& ptr,
const U& tok,
const V&
map, MapType&
value) {
215 if( !tok.isUninitialized() ) value = map.find(tok.index())->
second->get(ptr.id(),ptr.key());
219 template<
typename MapType,
typename OutputType>
226 if( !e_conf.tok_electron_src.isUninitialized() ) {
227 auto key = eles_by_oop.find(ele_idx);
228 if(
key != eles_by_oop.end() ) {
233 <<
" not found in cache!";
237 for(
auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
243 template<
typename MapType,
typename OutputType>
250 if( !ph_conf.tok_photon_src.isUninitialized() ) {
251 auto key = phos_by_oop.find(pho_idx);
252 if(
key != phos_by_oop.end() ) {
256 <<
"Original object pointer with key = " << pho.
originalObjectRef().
key() <<
" not found in cache!";
260 for(
auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
267 template<
typename OutputType>
268 template<
typename ObjType,
typename MapType>
276 assignValue(ptr,val_map.second,vmaps,
value);
277 if( !obj.hasUserData(val_map.first) ) {
278 obj.addUserData(val_map.first,
value);
281 <<
"Trying to add new UserData = " << val_map.first
282 <<
" failed because it already exists!";
287 template<
typename ObjType,
typename MapType>
295 assignValue(ptr,val_map.second,vmaps,value);
296 if( !obj.hasUserFloat(val_map.first) ) {
297 obj.addUserFloat(val_map.first,value);
300 <<
"Trying to add new UserFloat = " << val_map.first
301 <<
" failed because it already exists!";
306 template<
typename ObjType,
typename MapType>
314 assignValue(ptr,val_map.second,vmaps,value);
315 if( !obj.hasUserInt(val_map.first) ) {
316 obj.addUserInt(val_map.first,value);
319 <<
"Trying to add new UserInt = " << val_map.first
320 <<
" failed because it already exists!";
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Analysis-level Photon class.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
EGXtraModFromVMObjFiller()=delete
U second(std::pair< T, U > const &p)
~EGXtraModFromVMObjFiller()=delete
def template(fileName, svg, replaceme="REPLACEME")
std::vector< std::string > getParameterNames() const
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Analysis-level electron class.
static void addValueToObject(ObjType &obj, const edm::Ptr< reco::Candidate > &ptr, const std::unordered_map< unsigned, edm::Handle< edm::ValueMap< MapType > > > &vmaps, const std::pair< const std::string, edm::EDGetTokenT< edm::ValueMap< MapType > > > &val_map)