CMS 3D CMS Logo

LuminosityBlock.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_LuminosityBlock_h
2 #define FWCore_Framework_LuminosityBlock_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Framework
7 // Class : LuminosityBlock
8 //
17 /*----------------------------------------------------------------------
18 
19 ----------------------------------------------------------------------*/
20 
31 
32 #include <memory>
33 #include <string>
34 #include <typeinfo>
35 #include <vector>
36 
37 namespace edm {
38  class ModuleCallingContext;
39  class ProducerBase;
41 
42  namespace stream {
43  template <typename T>
44  class ProducingModuleAdaptorBase;
45  }
46 
48  public:
50  ModuleDescription const& md,
51  ModuleCallingContext const*,
52  bool isAtEnd);
53  ~LuminosityBlock() override;
54 
55  // AUX functions are defined in LuminosityBlockBase
56  LuminosityBlockAuxiliary const& luminosityBlockAuxiliary() const override { return aux_; }
57 
61 
68  typedef unsigned long CacheIdentifier_t;
69  CacheIdentifier_t cacheIdentifier() const;
70 
71  //Used in conjunction with EDGetToken
72  void setConsumer(EDConsumerBase const* iConsumer);
73 
74  void setSharedResourcesAcquirer(SharedResourcesAcquirer* iResourceAcquirer);
75 
76  void setProducer(ProducerBase const* iProducer);
77 
78  template <typename PROD>
79  bool getByLabel(std::string const& label, Handle<PROD>& result) const;
80 
81  template <typename PROD>
82  bool getByLabel(std::string const& label, std::string const& productInstanceName, Handle<PROD>& result) const;
83 
85  template <typename PROD>
86  bool getByLabel(InputTag const& tag, Handle<PROD>& result) const;
87 
88  template <typename PROD>
89  bool getByToken(EDGetToken token, Handle<PROD>& result) const;
90 
91  template <typename PROD>
92  bool getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const;
93 
94  template <typename PROD>
95  Handle<PROD> getHandle(EDGetTokenT<PROD> token) const;
96 
97  template <typename PROD>
98  PROD const& get(EDGetTokenT<PROD> token) const noexcept(false);
99 
100  template <typename PROD>
101  void getManyByType(std::vector<Handle<PROD>>& results) const;
102 
103  Run const& getRun() const { return *run_; }
104 
106  template <typename PROD>
107  void put(std::unique_ptr<PROD> product) {
108  put<PROD>(std::move(product), std::string());
109  }
110 
112  template <typename PROD>
113  void put(std::unique_ptr<PROD> product, std::string const& productInstanceName);
114 
115  template <typename PROD>
116  void put(EDPutToken token, std::unique_ptr<PROD> product);
117 
118  template <typename PROD>
119  void put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product);
120 
122  template <typename PROD, typename... Args>
123  void emplace(EDPutTokenT<PROD> token, Args&&... args);
124 
125  template <typename PROD, typename... Args>
126  void emplace(EDPutToken token, Args&&... args);
127 
128  Provenance getProvenance(BranchID const& theID) const;
129 
130  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
131 
132  ProcessHistoryID const& processHistoryID() const;
133 
134  ProcessHistory const& processHistory() const;
135 
136  ModuleCallingContext const* moduleCallingContext() const { return moduleCallingContext_; }
137 
138  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const {
139  provRecorder_.labelsForToken(iToken, oLabels);
140  }
141 
142  private:
143  LuminosityBlockPrincipal const& luminosityBlockPrincipal() const;
144 
145  // Override version from LuminosityBlockBase class
146  BasicHandle getByLabelImpl(std::type_info const& iWrapperType,
147  std::type_info const& iProductType,
148  InputTag const& iTag) const override;
149 
150  template <typename PROD>
151  void putImpl(EDPutToken::value_type token, std::unique_ptr<PROD> product);
152 
153  template <typename PROD, typename... Args>
154  void emplaceImpl(EDPutToken::value_type token, Args&&... args);
155 
156  typedef std::vector<edm::propagate_const<std::unique_ptr<WrapperBase>>> ProductPtrVec;
157  ProductPtrVec& putProducts() { return putProducts_; }
158  ProductPtrVec const& putProducts() const { return putProducts_; }
159 
160  // commit_() is called to complete the transaction represented by
161  // this PrincipalGetAdapter. The friendships required seems gross, but any
162  // alternative is not great either. Putting it into the
163  // public interface is asking for trouble
164  friend class RawInputSource;
165  friend class ProducerBase;
166  template <typename T>
168 
169  void commit_(std::vector<edm::ProductResolverIndex> const& iShouldPut);
170 
172  ProductPtrVec putProducts_;
174  std::shared_ptr<Run const> const run_;
176 
177  static const std::string emptyString_;
178  };
179 
180  template <typename PROD>
181  void LuminosityBlock::putImpl(EDPutToken::value_type index, std::unique_ptr<PROD> product) {
182  // The following will call post_insert if T has such a function,
183  // and do nothing if T has no such function.
185  maybe_inserter(product.get());
186 
187  assert(index < putProducts().size());
188 
189  std::unique_ptr<Wrapper<PROD>> wp(new Wrapper<PROD>(std::move(product)));
190  putProducts()[index] = std::move(wp);
191  }
192 
193  template <typename PROD>
194  void LuminosityBlock::put(std::unique_ptr<PROD> product, std::string const& productInstanceName) {
195  if (UNLIKELY(product.get() == nullptr)) { // null pointer is illegal
196  TypeID typeID(typeid(PROD));
197  principal_get_adapter_detail::throwOnPutOfNullProduct("LuminosityBlock", typeID, productInstanceName);
198  }
199  auto index = provRecorder_.getPutTokenIndex(TypeID(*product), productInstanceName);
200  putImpl(index, std::move(product));
201  }
202 
203  template <typename PROD>
204  void LuminosityBlock::put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product) {
205  if (UNLIKELY(product.get() == 0)) { // null pointer is illegal
206  TypeID typeID(typeid(PROD));
208  "LuminosityBlock", typeID, provRecorder_.productInstanceLabel(token));
209  }
210  if (UNLIKELY(token.isUninitialized())) {
212  }
213  putImpl(token.index(), std::move(product));
214  }
215 
216  template <typename PROD>
217  void LuminosityBlock::put(EDPutToken token, std::unique_ptr<PROD> product) {
218  if (UNLIKELY(product.get() == 0)) { // null pointer is illegal
219  TypeID typeID(typeid(PROD));
221  "LuminosityBlock", typeID, provRecorder_.productInstanceLabel(token));
222  }
223  if (UNLIKELY(token.isUninitialized())) {
225  }
226  if (UNLIKELY(provRecorder_.getTypeIDForPutTokenIndex(token.index()) != TypeID{typeid(PROD)})) {
228  provRecorder_.getTypeIDForPutTokenIndex(token.index()));
229  }
230 
231  putImpl(token.index(), std::move(product));
232  }
233 
234  template <typename PROD, typename... Args>
236  if (UNLIKELY(token.isUninitialized())) {
237  principal_get_adapter_detail::throwOnPutOfUninitializedToken("LuminosityBlock", typeid(PROD));
238  }
239  emplaceImpl<PROD>(token.index(), std::forward<Args>(args)...);
240  }
241 
242  template <typename PROD, typename... Args>
243  void LuminosityBlock::emplace(EDPutToken token, Args&&... args) {
244  if (UNLIKELY(token.isUninitialized())) {
245  principal_get_adapter_detail::throwOnPutOfUninitializedToken("LuminosityBlock", typeid(PROD));
246  }
247  if (UNLIKELY(provRecorder_.getTypeIDForPutTokenIndex(token.index()) != TypeID{typeid(PROD)})) {
249  provRecorder_.getTypeIDForPutTokenIndex(token.index()));
250  }
251 
252  emplaceImpl(token.index(), std::forward<Args>(args)...);
253  }
254 
255  template <typename PROD, typename... Args>
257  assert(index < putProducts().size());
258 
259  std::unique_ptr<Wrapper<PROD>> wp(new Wrapper<PROD>(WrapperBase::Emplace{}, std::forward<Args>(args)...));
260 
261  // The following will call post_insert if T has such a function,
262  // and do nothing if T has no such function.
264  maybe_inserter(&(wp->bareProduct()));
265 
266  putProducts()[index] = std::move(wp);
267  }
268 
269  template <typename PROD>
271  return getByLabel(label, emptyString_, result);
272  }
273 
274  template <typename PROD>
276  std::string const& productInstanceName,
277  Handle<PROD>& result) const {
278  if (!provRecorder_.checkIfComplete<PROD>()) {
279  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), label, productInstanceName);
280  }
281  result.clear();
282  BasicHandle bh = provRecorder_.getByLabel_(
283  TypeID(typeid(PROD)), label, productInstanceName, emptyString_, moduleCallingContext_);
284  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
285  if (result.failedToGet()) {
286  return false;
287  }
288  return true;
289  }
290 
292  template <typename PROD>
294  if (!provRecorder_.checkIfComplete<PROD>()) {
295  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), tag.label(), tag.instance());
296  }
297  result.clear();
298  BasicHandle bh = provRecorder_.getByLabel_(TypeID(typeid(PROD)), tag, moduleCallingContext_);
299  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
300  if (result.failedToGet()) {
301  return false;
302  }
303  return true;
304  }
305 
306  template <typename PROD>
308  if (!provRecorder_.checkIfComplete<PROD>()) {
309  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
310  }
311  result.clear();
312  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
313  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
314  if (result.failedToGet()) {
315  return false;
316  }
317  return true;
318  }
319 
320  template <typename PROD>
322  if (!provRecorder_.checkIfComplete<PROD>()) {
323  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
324  }
325  result.clear();
326  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
327  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
328  if (result.failedToGet()) {
329  return false;
330  }
331  return true;
332  }
333 
334  template <typename PROD>
336  if
337  UNLIKELY(!provRecorder_.checkIfComplete<PROD>()) {
338  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
339  }
340  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
341  return convert_handle<PROD>(std::move(bh));
342  }
343 
344  template <typename PROD>
345  PROD const& LuminosityBlock::get(EDGetTokenT<PROD> token) const noexcept(false) {
346  if
347  UNLIKELY(!provRecorder_.checkIfComplete<PROD>()) {
348  principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
349  }
350  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
351  return *convert_handle<PROD>(std::move(bh));
352  }
353 
354  template <typename PROD>
355  void LuminosityBlock::getManyByType(std::vector<Handle<PROD>>& results) const {
356  if (!provRecorder_.checkIfComplete<PROD>()) {
358  }
359  return provRecorder_.getManyByType(results, moduleCallingContext_);
360  }
361 
362  // Free functions to retrieve a collection from the LuminosityBlock.
363  // Will throw an exception if the collection is not available.
364 
365  template <typename T>
366  T const& get(LuminosityBlock const& event, InputTag const& tag) {
368  event.getByLabel(tag, handle);
369  // throw if the handle is not valid
370  return *handle.product();
371  }
372 
373  template <typename T>
374  T const& get(LuminosityBlock const& event, EDGetToken const& token) {
376  event.getByToken(token, handle);
377  // throw if the handle is not valid
378  return *handle.product();
379  }
380 
381  template <typename T>
382  T const& get(LuminosityBlock const& event, EDGetTokenT<T> const& token) {
384  event.getByToken(token, handle);
385  // throw if the handle is not valid
386  return *handle.product();
387  }
388 
389 } // namespace edm
390 
391 #endif // FWCore_Framework_LuminosityBlock_h
size
Write out results.
value_type index() const
Definition: EDPutToken.h:77
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
ProductPtrVec putProducts_
PROD const & get(EDGetTokenT< PROD > token) const (false)
std::shared_ptr< Run const > const run_
static const std::string emptyString_
ModuleCallingContext const * moduleCallingContext() const
bool getByLabel(std::string const &label, Handle< PROD > &result) const
void emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
value_type index() const
Definition: EDPutToken.h:50
ProductPtrVec const & putProducts() const
void put(edm::Event &evt, double value, const char *instanceName)
void putImpl(EDPutToken::value_type token, std::unique_ptr< PROD > product)
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const override
char const * label
unsigned long CacheIdentifier_t
bool isUninitialized() const
Definition: EDPutToken.h:51
LuminosityBlockAuxiliary const & aux_
void put(std::unique_ptr< PROD > product)
Put a new product.
unsigned int value_type
Definition: EDPutToken.h:42
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
ProductPtrVec & putProducts()
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void emplaceImpl(EDPutToken::value_type token, Args &&...args)
bool failedToGet() const
Definition: HandleBase.h:78
#define noexcept
void getManyByType(std::vector< Handle< PROD >> &results) const
std::vector< edm::propagate_const< std::unique_ptr< WrapperBase > > > ProductPtrVec
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
T const * product() const
Definition: Handle.h:74
ModuleCallingContext const * moduleCallingContext_
bool isUninitialized() const
Definition: EDPutToken.h:78
std::string const & label() const
Definition: InputTag.h:36
PrincipalGetAdapter provRecorder_
HLT enums.
#define PROD(A, B)
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
#define UNLIKELY(x)
Definition: Likely.h:21
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
long double T
std::string const & instance() const
Definition: InputTag.h:37
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
Run const & getRun() const