CMS 3D CMS Logo

GetterOfProducts.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_GetterOfProducts_h
2 #define FWCore_Framework_GetterOfProducts_h
3 
112 
113 #include <functional>
114 #include <memory>
115 #include <string>
116 #include <vector>
117 
118 namespace edm {
119 
120  template <typename T>
122  public:
124 
125  template <typename U, typename M>
127  : matcher_(WillGetIfMatch<T>(match, module)),
128  tokens_(new std::vector<edm::EDGetTokenT<T>>),
130 
131  void operator()(edm::BranchDescription const& branchDescription) {
132  if (branchDescription.dropped())
133  return;
134  if (branchDescription.branchType() == branchType_ &&
135  branchDescription.unwrappedTypeID() == edm::TypeID(typeid(T))) {
136  auto const& token = matcher_(branchDescription);
137  if (not token.isUninitialized()) {
138  tokens_->push_back(token);
139  }
140  }
141  }
142 
143  void fillHandles(edm::Event const& event, std::vector<edm::Handle<T>>& handles) const {
144  handles.clear();
145  if (branchType_ == edm::InEvent) {
146  handles.reserve(tokens_->size());
148  for (auto const& token : *tokens_) {
149  if (auto handle = event.getHandle(token)) {
150  handles.push_back(handle);
151  }
152  }
153  }
154  }
155 
156  void fillHandles(edm::LuminosityBlock const& lumi, std::vector<edm::Handle<T>>& handles) const {
157  handles.clear();
158  if (branchType_ == edm::InLumi) {
159  handles.reserve(tokens_->size());
160  for (auto const& token : *tokens_) {
161  if (auto handle = lumi.getHandle(token)) {
162  handles.push_back(handle);
163  }
164  }
165  }
166  }
167 
168  void fillHandles(edm::Run const& run, std::vector<edm::Handle<T>>& handles) const {
169  handles.clear();
170  if (branchType_ == edm::InRun) {
171  handles.reserve(tokens_->size());
172  for (auto const& token : *tokens_) {
173  if (auto handle = run.getHandle(token)) {
174  handles.push_back(handle);
175  }
176  }
177  }
178  }
179 
180  std::vector<edm::EDGetTokenT<T>> const& tokens() const { return *tokens_; }
182 
183  private:
184  std::function<EDGetTokenT<T>(BranchDescription const&)> matcher_;
185  // A shared pointer is needed because objects of this type get assigned
186  // to std::function's and we want the copies in those to share the same vector.
187  std::shared_ptr<std::vector<edm::EDGetTokenT<T>>> tokens_;
189  };
190 } // namespace edm
191 #endif
std::vector< edm::EDGetTokenT< T > > const & tokens() const
void fillHandles(edm::LuminosityBlock const &lumi, std::vector< edm::Handle< T >> &handles) const
BranchType const & branchType() const
void fillHandles(edm::Event const &event, std::vector< edm::Handle< T >> &handles) const
std::shared_ptr< std::vector< edm::EDGetTokenT< T > > > tokens_
BranchType
Definition: BranchType.h:11
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
edm::BranchType branchType_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Run.h:343
TypeID unwrappedTypeID() const
GetterOfProducts(U const &match, M *module, edm::BranchType branchType=edm::InEvent)
std::function< EDGetTokenT< T >BranchDescription const &)> matcher_
edm::BranchType branchType() const
HLT enums.
long double T
void operator()(edm::BranchDescription const &branchDescription)
Definition: vlib.h:208
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
void fillHandles(edm::Run const &run, std::vector< edm::Handle< T >> &handles) const
Definition: event.py:1
Definition: Run.h:45
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)