1 #ifndef RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h
2 #define RecoEgamma_EgammaTools_EGExtraInfoModifierFromValueMaps_h
13 #include <unordered_map>
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>;
106 std::unordered_map<unsigned, edm::Handle<edm::ValueMap<MapType>>>
ele_vmaps;
108 std::unordered_map<unsigned, edm::Handle<edm::ValueMap<MapType>>>
pho_vmaps;
114 template <
typename MapType,
typename OutputType>
119 constexpr
char photonSrc[] =
"photonSrc";
121 conf.
exists(
"overrideExistingValues") ? conf.
getParameter<
bool>(
"overrideExistingValues") :
false;
122 if (conf.
exists(
"electron_config")) {
137 if (conf.
exists(
"photon_config")) {
153 template <
typename MapType,
typename OutputType>
160 ele_idx = pho_idx = 0;
162 if (!e_conf.tok_electron_src.isUninitialized()) {
163 auto eles = evt.
getHandle(e_conf.tok_electron_src);
165 eles_by_oop.resize(eles->size());
166 std::copy(eles->ptrs().begin(), eles->ptrs().end(), eles_by_oop.begin());
169 for (
auto const&
itr : e_conf.tok_valuemaps) {
173 if (!ph_conf.tok_photon_src.isUninitialized()) {
174 auto phos = evt.
getHandle(ph_conf.tok_photon_src);
176 phos_by_oop.resize(phos->size());
177 std::copy(phos->ptrs().begin(), phos->ptrs().end(), phos_by_oop.begin());
180 for (
auto const&
itr : ph_conf.tok_valuemaps) {
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())
193 template <
typename MapType,
typename OutputType>
199 if (!e_conf.tok_electron_src.isUninitialized())
200 ptr = eles_by_oop.at(ele_idx);
203 ele, ptr, e_conf.tok_valuemaps, ele_vmaps, overrideExistingValues_);
207 template <
typename MapType,
typename OutputType>
213 if (!ph_conf.tok_photon_src.isUninitialized())
214 ptr = phos_by_oop.at(pho_idx);
217 pho, ptr, ph_conf.tok_valuemaps, pho_vmaps, overrideExistingValues_);
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; });
297 obj.setElectronIDs(ids);
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; });
316 obj.setPhotonIDs(ids);