CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Event.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Event_h
2 #define FWCore_Framework_Event_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Framework
7 // Class : Event
8 //
17 /*----------------------------------------------------------------------
18 ----------------------------------------------------------------------*/
19 
25 
30 
34 
35 #include "boost/shared_ptr.hpp"
36 
37 #include <memory>
38 #include <string>
39 #include <set>
40 #include <typeinfo>
41 #include <vector>
42 
43 namespace edm {
44 
45  class ConstBranchDescription;
47  class TriggerResults;
48  class TriggerNames;
49 
50  class Event : public EventBase {
51  public:
52  Event(EventPrincipal& ep, ModuleDescription const& md);
53  virtual ~Event();
54 
55  // AUX functions are defined in EventBase
56  EventAuxiliary const& eventAuxiliary() const {return aux_;}
57 
58  LuminosityBlock const&
60  return *luminosityBlock_;
61  }
62 
63  Run const&
64  getRun() const;
65 
67  run() const {return id().run();}
68 
69  template<typename PROD>
70  bool
71  get(ProductID const& oid, Handle<PROD>& result) const;
72 
73  // Template member overload to deal with Views.
74  template<typename ELEMENT>
75  bool
76  get(ProductID const& oid, Handle<View<ELEMENT> >& result) const ;
77 
79 
80  ProcessHistoryID const& processHistoryID() const;
81 
83  template<typename PROD>
85  put(std::auto_ptr<PROD> product) {return put<PROD>(product, std::string());}
86 
88  template<typename PROD>
90  put(std::auto_ptr<PROD> product, std::string const& productInstanceName);
91 
95  template<typename PROD>
97  getRefBeforePut() {return getRefBeforePut<PROD>(std::string());}
98 
99  template<typename PROD>
101  getRefBeforePut(std::string const& productInstanceName);
102 
103  template<typename PROD>
104  bool
105  get(SelectorBase const& sel, Handle<PROD>& result) const;
106 
107  template<typename PROD>
108  bool
109  getByLabel(InputTag const& tag, Handle<PROD>& result) const;
110 
111  template<typename PROD>
112  bool
113  getByLabel(std::string const& label, Handle<PROD>& result) const;
114 
115  template<typename PROD>
116  bool
117  getByLabel(std::string const& label, std::string const& productInstanceName, Handle<PROD>& result) const;
118 
119  template<typename PROD>
120  void
121  getMany(SelectorBase const& sel, std::vector<Handle<PROD> >& results) const;
122 
123  template<typename PROD>
124  bool
125  getByType(Handle<PROD>& result) const;
126 
127  template<typename PROD>
128  void
129  getManyByType(std::vector<Handle<PROD> >& results) const;
130 
131  // Template member overload to deal with Views.
132  template<typename ELEMENT>
133  bool
134  getByLabel(std::string const& label,
135  Handle<View<ELEMENT> >& result) const;
136 
137  template<typename ELEMENT>
138  bool
139  getByLabel(std::string const& label,
140  std::string const& productInstanceName,
141  Handle<View<ELEMENT> >& result) const;
142 
143  template<typename ELEMENT>
144  bool
145  getByLabel(InputTag const& tag, Handle<View<ELEMENT> >& result) const;
146 
147  template<typename ELEMENT>
148  void
150  Handle<View<ELEMENT> >& result) const;
151 
152  Provenance
153  getProvenance(BranchID const& theID) const;
154 
155  Provenance
156  getProvenance(ProductID const& theID) const;
157 
158  void
159  getAllProvenance(std::vector<Provenance const*>& provenances) const;
160 
161  // Return true if this Event has been subjected to a process with
162  // the given processName, and false otherwise.
163  // If true is returned, then ps is filled with the ParameterSet
164  // used to configure the identified process.
165  bool
166  getProcessParameterSet(std::string const& processName, ParameterSet& ps) const;
167 
168  virtual ProcessHistory const&
169  processHistory() const;
170 
171  size_t size() const;
172 
174  virtual TriggerResultsByName triggerResultsByName(std::string const& process) const;
175 
176  typedef std::vector<std::pair<WrapperOwningHolder, ConstBranchDescription const*> > ProductPtrVec;
177 
178  private:
179  EventPrincipal const&
180  eventPrincipal() const;
181 
183  eventPrincipal();
184 
185  ProductID
186  makeProductID(ConstBranchDescription const& desc) const;
187 
188  //override used by EventBase class
189  virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType, std::type_info const& iProductType, InputTag const& iTag) const;
190 
191  // commit_() is called to complete the transaction represented by
192  // this PrincipalGetAdapter. The friendships required seems gross, but any
193  // alternative is not great either. Putting it into the
194  // public interface is asking for trouble
196  friend class DaqSource;
197  friend class InputSource;
198  friend class RawInputSource;
199  friend class EDFilter;
200  friend class EDProducer;
201 
202  void commit_(std::vector<BranchID>* previousParentage= 0, ParentageID* previousParentageId = 0);
203  void commit_aux(ProductPtrVec& products, bool record_parents, std::vector<BranchID>* previousParentage = 0, ParentageID* previousParentageId = 0);
204 
206  getByProductID_(ProductID const& oid) const;
207 
209  ProductPtrVec const& putProducts() const {return putProducts_;}
210 
213 
215 
216  // putProducts_ and putProductsWithoutParents_ are the holding
217  // pens for EDProducts inserted into this PrincipalGetAdapter. Pointers
218  // in these collections own the products to which they point.
219  //
220  ProductPtrVec putProducts_; // keep parentage info for these
221  ProductPtrVec putProductsWithoutParents_; // ... but not for these
222 
224  boost::shared_ptr<LuminosityBlock const> const luminosityBlock_;
225 
226  // gotBranchIDs_ must be mutable because it records all 'gets',
227  // which do not logically modify the PrincipalGetAdapter. gotBranchIDs_ is
228  // merely a cache reflecting what has been retreived from the
229  // Principal class.
230  typedef std::set<BranchID> BranchIDSet;
232  void addToGotBranchIDs(Provenance const& prov) const;
233 
234  // We own the retrieved Views, and have to destroy them.
235  mutable std::vector<boost::shared_ptr<ViewBase> > gotViews_;
236  };
237 
238  // The following functions objects are used by Event::put, under the
239  // control of a metafunction if, to put the given pair into the
240  // right collection.
241  template<typename PROD>
244  void do_it(ptrvec_t& /*ignored*/,
245  ptrvec_t& used,
246  WrapperOwningHolder const& edp,
247  ConstBranchDescription const* desc) const {
248  used.push_back(std::make_pair(edp, desc));
249  }
250  };
251 
252  template<typename PROD>
255 
256  void do_it(ptrvec_t& used,
257  ptrvec_t& /*ignored*/,
258  WrapperOwningHolder const& edp,
259  ConstBranchDescription const* desc) const {
260  used.push_back(std::make_pair(edp, desc));
261  }
262  };
263 
264 
265  template<typename PROD>
266  bool
267  Event::get(ProductID const& oid, Handle<PROD>& result) const {
268  result.clear();
269  BasicHandle bh = this->getByProductID_(oid);
270  convert_handle(bh, result); // throws on conversion error
271  if(bh.failedToGet()) {
272  return false;
273  }
275  return true;
276  }
277 
278  template<typename ELEMENT>
279  bool
281  result.clear();
282  BasicHandle bh = this->getByProductID_(oid);
283 
284  if(bh.failedToGet()) {
285  boost::shared_ptr<cms::Exception> whyFailed(new edm::Exception(edm::errors::ProductNotFound));
286  *whyFailed
287  << "get View by ID failed: no product with ID = " << oid <<"\n";
288  Handle<View<ELEMENT> > temp(whyFailed);
289  result.swap(temp);
290  return false;
291  }
292 
293  fillView_(bh, result);
294  return true;
295  }
296 
297  template<typename PROD>
299  Event::put(std::auto_ptr<PROD> product, std::string const& productInstanceName) {
300  if(product.get() == 0) { // null pointer is illegal
301  TypeID typeID(typeid(PROD));
302  principal_get_adapter_detail::throwOnPutOfNullProduct("Event", typeID, productInstanceName);
303  }
304 
305  // The following will call post_insert if T has such a function,
306  // and do nothing if T has no such function.
309  DoNotPostInsert<PROD> >::type maybe_inserter;
310  maybe_inserter(product.get());
311 
312  ConstBranchDescription const& desc =
313  provRecorder_.getBranchDescription(TypeID(*product), productInstanceName);
314 
316 
319  RecordInParentfull<PROD> >::type parentage_recorder;
320  parentage_recorder.do_it(putProducts(),
322  edp,
323  &desc);
324 
325  // putProducts().push_back(std::make_pair(edp, &desc));
326 
327  // product.release(); // The object has been copied into the Wrapper.
328  // The old copy must be deleted, so we cannot release ownership.
329 
330  return(OrphanHandle<PROD>(static_cast<Wrapper<PROD> const*>(edp.wrapper())->product(), makeProductID(desc)));
331  }
332 
333  template<typename PROD>
335  Event::getRefBeforePut(std::string const& productInstanceName) {
336  PROD* p = 0;
337  ConstBranchDescription const& desc =
338  provRecorder_.getBranchDescription(TypeID(*p), productInstanceName);
339 
340  //should keep track of what Ref's have been requested and make sure they are 'put'
342  }
343 
344  template<typename PROD>
345  bool
347  bool ok = provRecorder_.get(sel, result);
348  if(ok) {
349  addToGotBranchIDs(*result.provenance());
350  }
351  return ok;
352  }
353 
354  template<typename PROD>
355  bool
357  bool ok = provRecorder_.getByLabel(tag, result);
358  if(ok) {
359  addToGotBranchIDs(*result.provenance());
360  }
361  return ok;
362  }
363 
364  template<typename PROD>
365  bool
366  Event::getByLabel(std::string const& label, Handle<PROD>& result) const {
367  bool ok = provRecorder_.getByLabel(label, result);
368  if(ok) {
369  addToGotBranchIDs(*result.provenance());
370  }
371  return ok;
372  }
373 
374  template<typename PROD>
375  bool
376  Event::getByLabel(std::string const& label,
377  std::string const& productInstanceName,
378  Handle<PROD>& result) const {
379  bool ok = provRecorder_.getByLabel(label, productInstanceName, result);
380  if(ok) {
381  addToGotBranchIDs(*result.provenance());
382  }
383  return ok;
384  }
385 
386  template<typename PROD>
387  void
388  Event::getMany(SelectorBase const& sel, std::vector<Handle<PROD> >& results) const {
390  for(typename std::vector<Handle<PROD> >::const_iterator it = results.begin(), itEnd = results.end();
391  it != itEnd; ++it) {
392  addToGotBranchIDs(*it->provenance());
393  }
394  }
395 
396  template<typename PROD>
397  bool
399  bool ok = provRecorder_.getByType(result);
400  if(ok) {
401  addToGotBranchIDs(*result.provenance());
402  }
403  return ok;
404  }
405 
406  template<typename PROD>
407  void
408  Event::getManyByType(std::vector<Handle<PROD> >& results) const {
410  for(typename std::vector<Handle<PROD> >::const_iterator it = results.begin(), itEnd = results.end();
411  it != itEnd; ++it) {
412  addToGotBranchIDs(*it->provenance());
413  }
414  }
415 
416  template<typename ELEMENT>
417  bool
418  Event::getByLabel(std::string const& moduleLabel, Handle<View<ELEMENT> >& result) const {
419  return getByLabel(moduleLabel, std::string(), result);
420  }
421 
422  template<typename ELEMENT>
423  bool
424  Event::getByLabel(std::string const& moduleLabel,
425  std::string const& productInstanceName,
426  Handle<View<ELEMENT> >& result) const {
427  result.clear();
428 
429  TypeID typeID(typeid(ELEMENT));
430 
431  BasicHandle bh;
432  int nFound = provRecorder_.getMatchingSequenceByLabel_(typeID,
433  moduleLabel,
434  productInstanceName,
435  bh);
436 
437  if(nFound == 0) {
438  boost::shared_ptr<cms::Exception> whyFailed(new edm::Exception(edm::errors::ProductNotFound));
439  *whyFailed
440  << "getByLabel: Found zero products matching all criteria\n"
441  << "Looking for sequence of type: " << typeID << "\n"
442  << "Looking for module label: " << moduleLabel << "\n"
443  << "Looking for productInstanceName: " << productInstanceName << "\n";
444  Handle<View<ELEMENT> > temp(whyFailed);
445  result.swap(temp);
446  return false;
447  }
448  if(nFound > 1) {
450  e << "getByLabel: Found more than one product matching all criteria\n"
451  << "Looking for sequence of type: " << typeID << "\n"
452  << "Looking for module label: " << moduleLabel << "\n"
453  << "Looking for productInstanceName: " << productInstanceName << "\n";
454  e.raise();
455  }
456 
457  fillView_(bh, result);
458  return true;
459  }
460 
461  template<typename ELEMENT>
462  bool
464  result.clear();
465  if(tag.process().empty()) {
466  return getByLabel(tag.label(), tag.instance(), result);
467  } else {
468  TypeID typeID(typeid(ELEMENT));
469 
470  BasicHandle bh;
471  int nFound = provRecorder_.getMatchingSequenceByLabel_(typeID,
472  tag.label(),
473  tag.instance(),
474  tag.process(),
475  bh);
476 
477  if(nFound == 0) {
478  boost::shared_ptr<cms::Exception> whyFailed(new edm::Exception(edm::errors::ProductNotFound));
479  *whyFailed
480  << "getByLabel: Found zero products matching all criteria\n"
481  << "Looking for sequence of type: " << typeID << "\n"
482  << "Looking for module label: " << tag.label() << "\n"
483  << "Looking for productInstanceName: " << tag.instance() << "\n"
484  << "Looking for processName: "<<tag.process() <<"\n";
485  Handle<View<ELEMENT> > temp(whyFailed);
486  result.swap(temp);
487  return false;
488  }
489  if(nFound > 1) {
491  e << "getByLabel: Found more than one product matching all criteria\n"
492  << "Looking for sequence of type: " << typeID << "\n"
493  << "Looking for module label: " << tag.label() << "\n"
494  << "Looking for productInstanceName: " << tag.instance() << "\n"
495  << "Looking for processName: "<<tag.process() <<"\n";
496  e.raise();
497  }
498 
499  fillView_(bh, result);
500  return true;
501  }
502  return false;
503  }
504 
505  template<typename ELEMENT>
506  void
508  std::vector<void const*> pointersToElements;
509  // the following is a shared pointer.
510  // It is not initialized here
511  helper_vector_ptr helpers;
512  // the following must initialize the
513  // shared pointer and fill the helper vector
514  bh.interface()->fillView(bh.wrapper(), bh.id(), pointersToElements, helpers);
515 
516  boost::shared_ptr<View<ELEMENT> >
517  newview(new View<ELEMENT>(pointersToElements, helpers));
518 
520  gotViews_.push_back(newview);
521  Handle<View<ELEMENT> > h(&*newview, bh.provenance());
522  result.swap(h);
523  }
524 }
525 #endif
RunNumber_t run() const
Definition: EventID.h:42
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:408
ProductID id() const
Definition: BasicHandle.h:114
bool getProcessParameterSet(std::string const &processName, ParameterSet &ps) const
Definition: Event.cc:75
type
Definition: HCALResponse.h:22
virtual ~Event()
Definition: Event.cc:23
void commit_aux(ProductPtrVec &products, bool record_parents, std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:109
virtual TriggerResultsByName triggerResultsByName(std::string const &process) const
Definition: Event.cc:209
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Event.cc:70
bool getByLabel(std::string const &label, Handle< PROD > &result) const
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:199
boost::shared_ptr< reftobase::RefVectorHolderBase > helper_vector_ptr
Definition: EDProductfwd.h:46
boost::shared_ptr< LuminosityBlock const > const luminosityBlock_
Definition: Event.h:224
size_t size() const
Definition: Event.cc:185
Definition: Hash.h:41
BranchIDSet gotBranchIDs_
Definition: Event.h:231
int getMatchingSequenceByLabel_(TypeID const &typeID, std::string const &label, std::string const &productInstanceName, BasicHandle &result) const
void raise()
Definition: Exception.h:103
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
Run const & getRun() const
Definition: Event.cc:45
void do_it(ptrvec_t &used, ptrvec_t &, WrapperOwningHolder const &edp, ConstBranchDescription const *desc) const
Definition: Event.h:256
void getManyByType(std::vector< Handle< PROD > > &results) const
void do_it(ptrvec_t &, ptrvec_t &used, WrapperOwningHolder const &edp, ConstBranchDescription const *desc) const
Definition: Event.h:244
WrapperInterfaceBase const * interface() const
Definition: BasicHandle.h:98
std::vector< EventSelectionID > EventSelectionIDVector
ProductPtrVec const & putProducts() const
Definition: Event.h:209
void const * wrapper() const
Definition: BasicHandle.h:102
EDProductGetter const * prodGetter() const
Provenance const * provenance() const
Definition: BasicHandle.h:110
PrincipalGetAdapter provRecorder_
Definition: Event.h:214
ESProducts< T, S > products(const T &i1, const S &i2)
Definition: ESProducts.h:189
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
void fillView(void const *me, ProductID const &id, std::vector< void const * > &view, helper_vector_ptr &helpers) const
void getMany(SelectorBase const &sel, std::vector< Handle< PROD > > &results) const
Definition: Event.h:388
tuple result
Definition: query.py:137
RunNumber_t run() const
Definition: Event.h:67
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:267
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:59
ProductPtrVec putProducts_
Definition: Event.h:220
void addToGotBranchIDs(Provenance const &prov) const
Definition: Event.cc:175
void getMany(SelectorBase const &, std::vector< Handle< PROD > > &results) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
RefProd< PROD > getRefBeforePut()
Definition: Event.h:97
ProductPtrVec & putProductsWithoutParents()
Definition: Event.h:211
virtual ProcessHistory const & processHistory() const
Definition: Event.cc:180
Event::ProductPtrVec ptrvec_t
Definition: Event.h:243
virtual BasicHandle getByLabelImpl(std::type_info const &iWrapperType, std::type_info const &iProductType, InputTag const &iTag) const
Definition: Event.cc:190
EventAuxiliary const & eventAuxiliary() const
Definition: Event.h:56
ProductID makeProductID(ConstBranchDescription const &desc) const
Definition: Event.cc:40
EventAuxiliary const & aux_
Definition: Event.h:223
bool failedToGet() const
Definition: BasicHandle.h:94
ProductPtrVec putProductsWithoutParents_
Definition: Event.h:221
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool get(SelectorBase const &, Handle< PROD > &result) const
void convert_handle(BasicHandle const &bh, Handle< T > &result)
Definition: ConvertHandle.h:19
std::vector< boost::shared_ptr< ViewBase > > gotViews_
Definition: Event.h:235
string const
Definition: compareJSON.py:14
ProcessHistoryID const & processHistoryID() const
Definition: Event.cc:55
Event(EventPrincipal &ep, ModuleDescription const &md)
Definition: Event.cc:15
ProductPtrVec & putProducts()
Definition: Event.h:208
std::string const & label() const
Definition: InputTag.h:25
EventSelectionIDVector const & eventSelectionIDs() const
Definition: Event.cc:50
std::string const & process() const
Definition: InputTag.h:29
void commit_(std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:103
edm::EventID id() const
Definition: EventBase.h:56
#define PROD(A, B)
unsigned int RunNumber_t
Definition: EventRange.h:32
BasicHandle getByProductID_(ProductID const &oid) const
Definition: Event.cc:98
void const * wrapper() const
Definition: WrapperHolder.h:76
void throwOnPutOfNullProduct(char const *principalType, TypeID const &productType, std::string const &productInstanceName)
ConstBranchDescription const & getBranchDescription(TypeID const &type, std::string const &productInstanceName) const
tuple process
Definition: LaserDQM_cfg.py:3
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:60
ProductPtrVec const & putProductsWithoutParents() const
Definition: Event.h:212
EventPrincipal const & eventPrincipal() const
Definition: Event.cc:35
Event::ProductPtrVec ptrvec_t
Definition: Event.h:254
std::vector< std::pair< WrapperOwningHolder, ConstBranchDescription const * > > ProductPtrVec
Definition: Event.h:176
std::string const & instance() const
Definition: InputTag.h:26
std::set< BranchID > BranchIDSet
Definition: Event.h:230
void fillView_(BasicHandle &bh, Handle< View< ELEMENT > > &result) const
Definition: Event.h:507
Definition: Run.h:33
Provenance const * provenance() const
Definition: HandleBase.h:84
bool getByType(Handle< PROD > &result) const