1 #ifndef RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h
2 #define RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h
13 #include <unordered_map>
49 namespace egmodifier {
53 template <
typename OutputType>
60 template <
typename ObjType,
typename MapType>
65 bool overrideExistingValues);
67 template <
typename ObjType,
typename MapType>
73 bool overrideExistingValues) {
74 for (
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr) {
80 template <
typename MapType,
typename OutputType = MapType>
84 using ValueMaps = std::unordered_map<std::string, ValMapToken>;
114 template <typename MapType, typename OutputType>
116 edm::ConsumesCollector& cc)
118 constexpr
char electronSrc[] =
"electronSrc";
119 constexpr
char photonSrc[] =
"photonSrc";
120 overrideExistingValues_ =
121 conf.exists(
"overrideExistingValues") ? conf.getParameter<
bool>(
"overrideExistingValues") :
false;
122 if (conf.exists(
"electron_config")) {
124 if (electrons.
exists(electronSrc))
137 if (conf.exists(
"photon_config")) {
139 if (photons.
exists(photonSrc))
150 ele_idx = pho_idx = 0;
153 template <
typename MapType,
typename OutputType>
186 template <
typename T,
typename U,
typename V,
typename MapType>
187 inline void assignValue(
const T& ptr,
const U& tok,
const V& map, MapType&
value) {
188 if (!tok.isUninitialized())
189 value = map.find(tok.index())->
second->get(ptr.id(), ptr.key());
193 template <
typename MapType,
typename OutputType>
207 template <
typename MapType,
typename OutputType>
222 template <
typename OutputType>
223 template <
typename ObjType,
typename MapType>
229 bool overrideExistingValues) {
231 assignValue(ptr, val_map.second, vmaps, value);
232 if (overrideExistingValues || !obj.hasUserData(val_map.first)) {
233 obj.addUserData(val_map.first, value,
true);
236 <<
"Trying to add new UserData = " << val_map.first
237 <<
" failed because it already exists and you didnt specify to override it (set in the config "
238 "overrideExistingValues=cms.bool(True) )";
243 template <
typename ObjType,
typename MapType>
249 bool overrideExistingValues) {
251 assignValue(ptr, val_map.second, vmaps, value);
252 if (overrideExistingValues || !obj.hasUserFloat(val_map.first)) {
253 obj.addUserFloat(val_map.first, value,
true);
256 <<
"Trying to add new UserFloat = " << val_map.first
257 <<
" failed because it already exists and you didnt specify to override it (set in the config "
258 "overrideExistingValues=cms.bool(True) )";
263 template <
typename ObjType,
typename MapType>
269 bool overrideExistingValues) {
271 assignValue(ptr, val_map.second, vmaps, value);
272 if (overrideExistingValues || !obj.hasUserInt(val_map.first)) {
273 obj.addUserInt(val_map.first, value,
true);
276 <<
"Trying to add new UserInt = " << val_map.first
277 <<
" failed because it already exists and you didnt specify to override it (set in the config "
278 "overrideExistingValues=cms.bool(True) )";
289 bool overrideExistingValues) {
290 std::vector<std::pair<std::string, float>> ids;
291 for (
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr) {
293 assignValue(ptr, itr->second, vmaps, idVal);
294 ids.push_back({itr->first, idVal});
296 std::sort(ids.begin(), ids.end(), [](
auto& lhs,
auto& rhs) {
return lhs.first < rhs.first; });
307 bool overrideExistingValues) {
309 std::vector<std::pair<std::string, bool>> ids;
310 for (
auto itr = vmaps_token.begin(); itr != vmaps_token.end(); ++itr) {
312 assignValue(ptr, itr->second, vmaps, idVal);
313 ids.push_back({itr->first, idVal});
315 std::sort(ids.begin(), ids.end(), [](
auto& lhs,
auto& rhs) {
return lhs.first < rhs.first; });
Analysis-level Photon class.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void setElectronIDs(const std::vector< IdPair > &ids)
Store multiple electron ID values, discarding existing ones. The first one in the list becomes the 'd...
constexpr bool isUninitialized() const noexcept
bool exists(std::string const ¶meterName) const
checks if a parameter exists
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, bool overrideExistingValues)
EGXtraModFromVMObjFiller()=delete
U second(std::pair< T, U > const &p)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
const std::string & name() const
static void addValuesToObject(ObjType &obj, const edm::Ptr< reco::Candidate > &ptr, const std::unordered_map< std::string, edm::EDGetTokenT< edm::ValueMap< MapType >>> &vmaps_token, const std::unordered_map< unsigned, edm::Handle< edm::ValueMap< MapType >>> &vmaps, bool overrideExistingValues)
void setPhotonIDs(const std::vector< IdPair > &ids)
~EGXtraModFromVMObjFiller()=delete
std::vector< std::string > getParameterNames() const
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
T getParameter(std::string const &) const
Analysis-level electron class.
constexpr char Electron[]