CMS 3D CMS Logo

PATObjectUserDataEmbedder.cc
Go to the documentation of this file.
6 
9 
15 
16 namespace pat {
17 
18  namespace helper {
19 
21  typedef bool value_type;
23  template <typename ObjectType>
24  void addData(ObjectType &obj, const std::string &key, const value_type &val) {
25  obj.addUserInt(key, val);
26  }
27  };
28 
29  template <typename A>
31  public:
33  if (iConfig.existsAs<edm::ParameterSet>(main)) {
34  edm::ParameterSet const &srcPSet = iConfig.getParameter<edm::ParameterSet>(main);
35  for (const std::string &label : srcPSet.getParameterNamesForType<edm::InputTag>()) {
36  labelsAndTokens_.emplace_back(
37  label, cc.consumes<typename A::product_type>(srcPSet.getParameter<edm::InputTag>(label)));
38  }
39  }
40  }
41  template <typename T>
42  void addData(const edm::Event &iEvent, const std::vector<edm::Ptr<T>> &ptrs, std::vector<T> &out) const {
43  A adder;
44  unsigned int n = ptrs.size();
46  for (const auto &pair : labelsAndTokens_) {
47  iEvent.getByToken(pair.second, handle);
48  for (unsigned int i = 0; i < n; ++i) {
49  adder.addData(out[i], pair.first, (*handle)[ptrs[i]]);
50  }
51  }
52  }
53 
54  private:
55  std::vector<std::pair<std::string, edm::EDGetTokenT<typename A::product_type>>> labelsAndTokens_;
56  }; // class NamedUserDataLoader
57  } // namespace helper
58 
59  template <typename T>
61  public:
63  : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
64  userFloats_(iConfig, "userFloats", consumesCollector()),
65  userInts_(iConfig, "userInts", consumesCollector()),
66  userIntFromBools_(iConfig, "userIntFromBools", consumesCollector()),
67  userCands_(iConfig, "userCands", consumesCollector()) {
68  produces<std::vector<T>>();
69  }
70 
72 
73  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
74 
75  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
77  desc.add<edm::InputTag>("src");
78  for (const std::string &what : {"userFloats", "userInts", "userIntFromBools", "userCands"}) {
80  descNested.addWildcard<edm::InputTag>("*");
81  desc.add<edm::ParameterSetDescription>(what, descNested);
82  }
83  if (typeid(T) == typeid(pat::Muon))
84  descriptions.add("muonsWithUserData", desc);
85  else if (typeid(T) == typeid(pat::Electron))
86  descriptions.add("electronsWithUserData", desc);
87  else if (typeid(T) == typeid(pat::Photon))
88  descriptions.add("photonsWithUserData", desc);
89  else if (typeid(T) == typeid(pat::Tau))
90  descriptions.add("tausWithUserData", desc);
91  else if (typeid(T) == typeid(pat::Jet))
92  descriptions.add("jetsWithUserData", desc);
93  }
94 
95  private:
96  // configurables
102  };
103 
104 } // namespace pat
105 
106 template <typename T>
109  iEvent.getByToken(src_, src);
110 
111  std::unique_ptr<std::vector<T>> out(new std::vector<T>());
112  out->reserve(src->size());
113 
114  std::vector<edm::Ptr<T>> ptrs;
115  ptrs.reserve(src->size());
116  for (unsigned int i = 0, n = src->size(); i < n; ++i) {
117  // copy by value, save the ptr
118  out->push_back((*src)[i]);
119  ptrs.push_back(src->ptrAt(i));
120  }
121  userFloats_.addData(iEvent, ptrs, *out);
122  userInts_.addData(iEvent, ptrs, *out);
123  userIntFromBools_.addData(iEvent, ptrs, *out);
124  userCands_.addData(iEvent, ptrs, *out);
125 
126  iEvent.put(std::move(out));
127 }
128 
134 
pat::helper::NamedUserDataLoader
Definition: PATObjectUserDataEmbedder.cc:30
PATUserDataMerger.h
mps_fire.i
i
Definition: mps_fire.py:428
pat::PATObjectUserDataEmbedder::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATObjectUserDataEmbedder.cc:107
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::PATObjectUserDataEmbedder::~PATObjectUserDataEmbedder
~PATObjectUserDataEmbedder() override
Definition: PATObjectUserDataEmbedder.cc:71
sistrip::View
View
Definition: ConstantsForView.h:26
PATPhotonUserDataEmbedder
pat::PATObjectUserDataEmbedder< pat::Photon > PATPhotonUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:131
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
PATTauUserDataEmbedder
pat::PATObjectUserDataEmbedder< pat::Tau > PATTauUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:132
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
Photon.h
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
pat::PATObjectUserDataEmbedder::PATObjectUserDataEmbedder
PATObjectUserDataEmbedder(const edm::ParameterSet &iConfig)
Definition: PATObjectUserDataEmbedder.cc:62
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
edm::Handle
Definition: AssociativeIterator.h:50
Tau.h
edm::ParameterSetDescription::addWildcard
ParameterWildcardBase * addWildcard(U const &pattern)
Definition: ParameterSetDescription.h:199
MakerMacros.h
pat::PATObjectUserDataEmbedder::src_
edm::EDGetTokenT< edm::View< T > > src_
Definition: PATObjectUserDataEmbedder.cc:97
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
pat::PATObjectUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:60
pat::helper::AddUserIntFromBool::product_type
edm::ValueMap< value_type > product_type
Definition: PATObjectUserDataEmbedder.cc:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::helper::NamedUserDataLoader::labelsAndTokens_
std::vector< std::pair< std::string, edm::EDGetTokenT< typename A::product_type > > > labelsAndTokens_
Definition: PATObjectUserDataEmbedder.cc:55
pat::helper::NamedUserDataLoader::NamedUserDataLoader
NamedUserDataLoader(const edm::ParameterSet &iConfig, const std::string &main, edm::ConsumesCollector &&cc)
Definition: PATObjectUserDataEmbedder.cc:32
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
pat::PATObjectUserDataEmbedder::userInts_
helper::NamedUserDataLoader< pat::helper::AddUserInt > userInts_
Definition: PATObjectUserDataEmbedder.cc:99
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::helper::NamedUserDataLoader::addData
void addData(const edm::Event &iEvent, const std::vector< edm::Ptr< T >> &ptrs, std::vector< T > &out) const
Definition: PATObjectUserDataEmbedder.cc:42
PATJetUserDataEmbedder
pat::PATObjectUserDataEmbedder< pat::Jet > PATJetUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:133
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
ecaldqm::binning::ObjectType
ObjectType
Definition: MESetBinningUtils.h:17
UserData.h
pat::PATObjectUserDataEmbedder::userCands_
helper::NamedUserDataLoader< pat::helper::AddUserCand > userCands_
Definition: PATObjectUserDataEmbedder.cc:101
helper
Definition: helper.py:1
A
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
iEvent
int iEvent
Definition: GenABIO.cc:224
dumpRecoGeometry_cfg.Muon
Muon
Definition: dumpRecoGeometry_cfg.py:190
PATMuonUserDataEmbedder
pat::PATObjectUserDataEmbedder< pat::Muon > PATMuonUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:130
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
cc
Jet.h
main
Definition: main.py:1
InputTag.h
pat::helper::AddUserIntFromBool::value_type
bool value_type
Definition: PATObjectUserDataEmbedder.cc:21
edm::Ptr
Definition: AssociationVector.h:31
pat::helper::AddUserIntFromBool::addData
void addData(ObjectType &obj, const std::string &key, const value_type &val)
Definition: PATObjectUserDataEmbedder.cc:24
pat::PATObjectUserDataEmbedder::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATObjectUserDataEmbedder.cc:75
pat::PATObjectUserDataEmbedder::userIntFromBools_
helper::NamedUserDataLoader< pat::helper::AddUserIntFromBool > userIntFromBools_
Definition: PATObjectUserDataEmbedder.cc:100
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap
Definition: ValueMap.h:107
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
View.h
pat::PATObjectUserDataEmbedder::userFloats_
helper::NamedUserDataLoader< pat::helper::AddUserFloat > userFloats_
Definition: PATObjectUserDataEmbedder.cc:98
ParameterSet.h
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::InputTag
Definition: InputTag.h:15
PATElectronUserDataEmbedder
pat::PATObjectUserDataEmbedder< pat::Electron > PATElectronUserDataEmbedder
Definition: PATObjectUserDataEmbedder.cc:129
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
label
const char * label
Definition: PFTauDecayModeTools.cc:11
magneticFieldFilterJSON.main
def main(argv=None)
Definition: magneticFieldFilterJSON.py:22
pat::helper::AddUserIntFromBool
Definition: PATObjectUserDataEmbedder.cc:20