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 
helper::NamedUserDataLoader< pat::helper::AddUserInt > userInts_
T getParameter(std::string const &) const
Analysis-level Photon class.
Definition: Photon.h:46
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
pat::PATObjectUserDataEmbedder< pat::Electron > PATElectronUserDataEmbedder
Definition: helper.py:1
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
pat::PATObjectUserDataEmbedder< pat::Tau > PATTauUserDataEmbedder
ParameterWildcardBase * addWildcard(U const &pattern)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
pat::PATObjectUserDataEmbedder< pat::Photon > PATPhotonUserDataEmbedder
helper::NamedUserDataLoader< pat::helper::AddUserFloat > userFloats_
helper::NamedUserDataLoader< pat::helper::AddUserCand > userCands_
Definition: HeavyIon.h:7
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:168
char const * label
pat::PATObjectUserDataEmbedder< pat::Jet > PATJetUserDataEmbedder
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
NamedUserDataLoader(const edm::ParameterSet &iConfig, const std::string &main, edm::ConsumesCollector &&cc)
edm::ValueMap< value_type > product_type
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< std::pair< std::string, edm::EDGetTokenT< typename A::product_type > > > labelsAndTokens_
Analysis-level tau class.
Definition: Tau.h:53
edm::EDGetTokenT< edm::View< T > > src_
PATObjectUserDataEmbedder(const edm::ParameterSet &iConfig)
pat::PATObjectUserDataEmbedder< pat::Muon > PATMuonUserDataEmbedder
Analysis-level electron class.
Definition: Electron.h:51
Analysis-level calorimeter jet class.
Definition: Jet.h:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
Definition: main.py:1
helper::NamedUserDataLoader< pat::helper::AddUserIntFromBool > userIntFromBools_
void addData(const edm::Event &iEvent, const std::vector< edm::Ptr< T >> &ptrs, std::vector< T > &out) const
long double T
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
def move(src, dest)
Definition: eostools.py:511
void addData(ObjectType &obj, const std::string &key, const value_type &val)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)