CMS 3D CMS Logo

Run.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Run_h
2 #define FWCore_Framework_Run_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Framework
7 // Class : Run
8 //
16 /*----------------------------------------------------------------------
17 
18 ----------------------------------------------------------------------*/
19 
29 
30 #include <memory>
31 #include <string>
32 #include <typeinfo>
33 #include <vector>
34 
35 namespace edm {
36  class ModuleCallingContext;
37  class ProducerBase;
39 
40  namespace stream {
41  template <typename T>
42  class ProducingModuleAdaptorBase;
43  }
44 
45  class Run : public RunBase {
46  public:
47  Run(RunPrincipal const& rp, ModuleDescription const& md, ModuleCallingContext const*, bool isAtEnd);
48  ~Run() override;
49 
50  //Used in conjunction with EDGetToken
51  void setConsumer(EDConsumerBase const* iConsumer) { provRecorder_.setConsumer(iConsumer); }
52 
54  provRecorder_.setSharedResourcesAcquirer(iResourceAcquirer);
55  }
56 
57  void setProducer(ProducerBase const* iProducer);
58 
60  // AUX functions are defined in RunBase
61  RunAuxiliary const& runAuxiliary() const override { return aux_; }
62  // AUX functions.
63  // RunID const& id() const {return aux_.id();}
64  // RunNumber_t run() const {return aux_.run();}
65  // Timestamp const& beginTime() const {return aux_.beginTime();}
66  // Timestamp const& endTime() const {return aux_.endTime();}
67 
70  RunIndex index() const;
71 
78  typedef unsigned long CacheIdentifier_t;
79  CacheIdentifier_t cacheIdentifier() const;
80 
81  template <typename PROD>
82  bool getByLabel(std::string const& label, Handle<PROD>& result) const;
83 
84  template <typename PROD>
85  bool getByLabel(std::string const& label, std::string const& productInstanceName, Handle<PROD>& result) const;
86 
88  template <typename PROD>
89  bool getByLabel(InputTag const& tag, Handle<PROD>& result) const;
90 
91  template <typename PROD>
92  bool getByToken(EDGetToken token, Handle<PROD>& result) const;
93 
94  template <typename PROD>
95  bool getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const;
96 
97  template <typename PROD>
98  Handle<PROD> getHandle(EDGetTokenT<PROD> token) const;
99 
100  template <typename PROD>
101  PROD const& get(EDGetTokenT<PROD> token) const noexcept(false);
102 
103  template <typename PROD>
104  void getManyByType(std::vector<Handle<PROD>>& results) const;
105 
107  template <typename PROD>
108  void put(std::unique_ptr<PROD> product) {
109  put<PROD>(std::move(product), std::string());
110  }
111 
113  template <typename PROD>
114  void put(std::unique_ptr<PROD> product, std::string const& productInstanceName);
115 
116  template <typename PROD>
117  void put(EDPutToken token, std::unique_ptr<PROD> product);
118 
119  template <typename PROD>
120  void put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product);
121 
123  template <typename PROD, typename... Args>
124  void emplace(EDPutTokenT<PROD> token, Args&&... args);
125 
126  template <typename PROD, typename... Args>
127  void emplace(EDPutToken token, Args&&... args);
128 
129  Provenance getProvenance(BranchID const& theID) const;
130 
131  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
132 
133  // Return true if this Run has been subjected to a process with
134  // the given processName, and false otherwise.
135  // If true is returned, then ps is filled with the ParameterSets
136  // (possibly more than one) used to configure the identified
137  // process(es). Equivalent ParameterSets are compressed out of the
138  // result.
139  // This function is not yet implemented in full.
140  //bool
141  //getProcessParameterSet(std::string const& processName, std::vector<ParameterSet>& ps) const;
142 
143  ProcessHistoryID const& processHistoryID() const;
144 
145  ProcessHistory const& processHistory() const;
146 
147  ModuleCallingContext const* moduleCallingContext() const { return moduleCallingContext_; }
148 
149  void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const {
150  provRecorder_.labelsForToken(iToken, oLabels);
151  }
152 
153  private:
154  RunPrincipal const& runPrincipal() const;
155 
156  // Override version from RunBase class
157  BasicHandle getByLabelImpl(std::type_info const& iWrapperType,
158  std::type_info const& iProductType,
159  InputTag const& iTag) const override;
160 
161  template <typename PROD>
162  void putImpl(EDPutToken::value_type token, std::unique_ptr<PROD> product);
163 
164  template <typename PROD, typename... Args>
165  void emplaceImpl(EDPutToken::value_type token, Args&&... args);
166 
167  typedef std::vector<edm::propagate_const<std::unique_ptr<WrapperBase>>> ProductPtrVec;
168  ProductPtrVec& putProducts() { return putProducts_; }
169  ProductPtrVec const& putProducts() const { return putProducts_; }
170 
171  // commit_() is called to complete the transaction represented by
172  // this PrincipalGetAdapter. The friendships required seems gross, but any
173  // alternative is not great either. Putting it into the
174  // public interface is asking for trouble
175  friend class RawInputSource;
176  friend class ProducerBase;
177  template <typename T>
179 
180  void commit_(std::vector<edm::ProductResolverIndex> const& iShouldPut);
181 
183  ProductPtrVec putProducts_;
187  sharedResourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
188 
189  static const std::string emptyString_;
190  };
191 
192  template <typename PROD>
193  void Run::putImpl(EDPutToken::value_type index, std::unique_ptr<PROD> product) {
194  // The following will call post_insert if T has such a function,
195  // and do nothing if T has no such function.
197  maybe_inserter(product.get());
198 
199  assert(index < putProducts().size());
200 
201  std::unique_ptr<Wrapper<PROD>> wp(new Wrapper<PROD>(std::move(product)));
202  putProducts()[index] = std::move(wp);
203  }
204 
205  template <typename PROD>
206  void Run::put(std::unique_ptr<PROD> product, std::string const& productInstanceName) {
207  if (UNLIKELY(product.get() == nullptr)) { // null pointer is illegal
208  TypeID typeID(typeid(PROD));
209  principal_get_adapter_detail::throwOnPutOfNullProduct("Run", typeID, productInstanceName);
210  }
211  auto index = provRecorder_.getPutTokenIndex(TypeID(*product), productInstanceName);
212  putImpl(index, std::move(product));
213  }
214 
215  template <typename PROD>
216  void Run::put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product) {
217  if (UNLIKELY(product.get() == 0)) { // null pointer is illegal
218  TypeID typeID(typeid(PROD));
219  principal_get_adapter_detail::throwOnPutOfNullProduct("Run", typeID, provRecorder_.productInstanceLabel(token));
220  }
221  if (UNLIKELY(token.isUninitialized())) {
223  }
224  putImpl(token.index(), std::move(product));
225  }
226 
227  template <typename PROD>
228  void Run::put(EDPutToken token, std::unique_ptr<PROD> product) {
229  if (UNLIKELY(product.get() == 0)) { // null pointer is illegal
230  TypeID typeID(typeid(PROD));
231  principal_get_adapter_detail::throwOnPutOfNullProduct("Run", typeID, provRecorder_.productInstanceLabel(token));
232  }
233  if (UNLIKELY(token.isUninitialized())) {
235  }
236  if (UNLIKELY(provRecorder_.getTypeIDForPutTokenIndex(token.index()) != TypeID{typeid(PROD)})) {
238  provRecorder_.getTypeIDForPutTokenIndex(token.index()));
239  }
240 
241  putImpl(token.index(), std::move(product));
242  }
243 
244  template <typename PROD, typename... Args>
245  void Run::emplace(EDPutTokenT<PROD> token, Args&&... args) {
246  if (UNLIKELY(token.isUninitialized())) {
248  }
249  emplaceImpl<PROD>(token.index(), std::forward<Args>(args)...);
250  }
251 
252  template <typename PROD, typename... Args>
253  void Run::emplace(EDPutToken token, Args&&... args) {
254  if (UNLIKELY(token.isUninitialized())) {
256  }
257  if (UNLIKELY(provRecorder_.getTypeIDForPutTokenIndex(token.index()) != TypeID{typeid(PROD)})) {
259  provRecorder_.getTypeIDForPutTokenIndex(token.index()));
260  }
261 
262  emplaceImpl(token.index(), std::forward<Args>(args)...);
263  }
264 
265  template <typename PROD, typename... Args>
267  assert(index < putProducts().size());
268 
269  std::unique_ptr<Wrapper<PROD>> wp(new Wrapper<PROD>(WrapperBase::Emplace{}, std::forward<Args>(args)...));
270 
271  // The following will call post_insert if T has such a function,
272  // and do nothing if T has no such function.
274  maybe_inserter(&(wp->bareProduct()));
275 
276  putProducts()[index] = std::move(wp);
277  }
278 
279  template <typename PROD>
281  return getByLabel(label, emptyString_, result);
282  }
283 
284  template <typename PROD>
285  bool Run::getByLabel(std::string const& label, std::string const& productInstanceName, Handle<PROD>& result) const {
286  if (!provRecorder_.checkIfComplete<PROD>()) {
287  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), label, productInstanceName);
288  }
289  result.clear();
290  BasicHandle bh = provRecorder_.getByLabel_(
291  TypeID(typeid(PROD)), label, productInstanceName, emptyString_, moduleCallingContext_);
292  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
293  if (result.failedToGet()) {
294  return false;
295  }
296  return true;
297  }
298 
300  template <typename PROD>
302  if (!provRecorder_.checkIfComplete<PROD>()) {
303  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), tag.label(), tag.instance());
304  }
305  result.clear();
306  BasicHandle bh = provRecorder_.getByLabel_(TypeID(typeid(PROD)), tag, moduleCallingContext_);
307  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
308  if (result.failedToGet()) {
309  return false;
310  }
311  return true;
312  }
313 
314  template <typename PROD>
316  if (!provRecorder_.checkIfComplete<PROD>()) {
317  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), token);
318  }
319  result.clear();
320  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
321  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
322  if (result.failedToGet()) {
323  return false;
324  }
325  return true;
326  }
327 
328  template <typename PROD>
330  if (!provRecorder_.checkIfComplete<PROD>()) {
331  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), token);
332  }
333  result.clear();
334  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
335  result = convert_handle<PROD>(std::move(bh)); // throws on conversion error
336  if (result.failedToGet()) {
337  return false;
338  }
339  return true;
340  }
341 
342  template <typename PROD>
344  if (!provRecorder_.checkIfComplete<PROD>()) {
345  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), token);
346  }
347  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
348  return convert_handle<PROD>(std::move(bh));
349  }
350 
351  template <typename PROD>
352  PROD const& Run::get(EDGetTokenT<PROD> token) const noexcept(false) {
353  if (!provRecorder_.checkIfComplete<PROD>()) {
354  principal_get_adapter_detail::throwOnPrematureRead("Run", TypeID(typeid(PROD)), token);
355  }
356  BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)), PRODUCT_TYPE, token, moduleCallingContext_);
357  return *convert_handle<PROD>(std::move(bh));
358  }
359 
360  template <typename PROD>
361  void Run::getManyByType(std::vector<Handle<PROD>>& results) const {
362  if (!provRecorder_.checkIfComplete<PROD>()) {
364  }
365  return provRecorder_.getManyByType(results, moduleCallingContext_);
366  }
367 
368  // Free functions to retrieve a collection from the Run.
369  // Will throw an exception if the collection is not available.
370 
371  template <typename T>
372  T const& get(Run const& event, InputTag const& tag) {
374  event.getByLabel(tag, handle);
375  // throw if the handle is not valid
376  return *handle.product();
377  }
378 
379  template <typename T>
380  T const& get(Run const& event, EDGetToken const& token) {
382  event.getByToken(token, handle);
383  // throw if the handle is not valid
384  return *handle.product();
385  }
386 
387  template <typename T>
388  T const& get(Run const& event, EDGetTokenT<T> const& token) {
390  event.getByToken(token, handle);
391  // throw if the handle is not valid
392  return *handle.product();
393  }
394 
395 } // namespace edm
396 
397 #endif // FWCore_Framework_Run_h
size
Write out results.
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
static const std::string emptyString_
Definition: Run.h:189
value_type index() const
Definition: EDPutToken.h:77
PROD const & get(EDGetTokenT< PROD > token) const (false)
Definition: Run.h:352
ProductPtrVec putProducts_
Definition: Run.h:183
ProductPtrVec const & putProducts() const
Definition: Run.h:169
RunAuxiliary const & aux_
Definition: Run.h:184
std::vector< edm::propagate_const< std::unique_ptr< WrapperBase > > > ProductPtrVec
Definition: Run.h:167
void throwOnPutOfUninitializedToken(char const *principalType, std::type_info const &productType)
PrincipalGetAdapter Base
Definition: Run.h:59
void emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Run.h:245
value_type index() const
Definition: EDPutToken.h:50
void put(edm::Event &evt, double value, const char *instanceName)
unsigned long CacheIdentifier_t
Definition: Run.h:78
char const * label
bool isUninitialized() const
Definition: EDPutToken.h:51
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:315
unsigned int value_type
Definition: EDPutToken.h:42
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Run.h:343
void throwOnPutOfWrongType(std::type_info const &wrongType, TypeID const &rightType)
void putImpl(EDPutToken::value_type token, std::unique_ptr< PROD > product)
Definition: Run.h:193
RunAuxiliary const & runAuxiliary() const override
Definition: Run.h:61
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 setSharedResourcesAcquirer(SharedResourcesAcquirer *iResourceAcquirer)
Definition: Run.h:53
bool failedToGet() const
Definition: HandleBase.h:78
#define noexcept
SharedResourcesAcquirer * sharedResourcesAcquirer_
Definition: Run.h:187
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: Run.h:361
T const * product() const
Definition: Handle.h:74
ProductPtrVec & putProducts()
Definition: Run.h:168
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:108
bool isUninitialized() const
Definition: EDPutToken.h:78
std::string const & label() const
Definition: InputTag.h:36
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: Run.h:149
HLT enums.
#define PROD(A, B)
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:147
void throwOnPrematureRead(char const *principalType, TypeID const &productType, std::string const &moduleLabel, std::string const &productInstanceName)
ModuleCallingContext const * moduleCallingContext_
Definition: Run.h:185
void emplaceImpl(EDPutToken::value_type token, Args &&...args)
Definition: Run.h:266
#define UNLIKELY(x)
Definition: Likely.h:21
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
long double T
void setConsumer(EDConsumerBase const *iConsumer)
Definition: Run.h:51
std::string const & instance() const
Definition: InputTag.h:37
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
PrincipalGetAdapter provRecorder_
Definition: Run.h:182