Event.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_Event_h
2 #define art_Framework_Principal_Event_h
3 
4 // ======================================================================
5 //
6 // Event - This is the primary interface for accessing EDProducts from a
7 // single collision and inserting new derived products.
8 //
9 // For its usage, see "art/Framework/Principal/DataViewImpl.h"
10 //
11 // ======================================================================
12 
28 #include "cetlib/HorizontalRule.h"
30 #include "fhiclcpp/ParameterSet.h"
31 
32 #include <cstdlib>
33 #include <memory>
34 #include <set>
35 #include <vector>
36 
37 namespace art {
38  class BranchDescription;
39  class ProdToProdMapBuilder; // fwd declaration to avoid circularity
40 }
41 
42 class art::Event final : private art::DataViewImpl {
43 public:
44  using Base = DataViewImpl;
45  explicit Event(EventPrincipal const& ep,
46  ModuleDescription const& md,
48  RangeSet const& rs);
49 
50  explicit Event(EventPrincipal const& ep,
51  ModuleDescription const& md,
52  cet::exempt_ptr<Consumer> consumer);
53 
54  // AUX functions.
55  EventID
56  id() const
57  {
58  return aux_.id();
59  }
60  Timestamp
61  time() const
62  {
63  return aux_.time();
64  }
65 
67  event() const
68  {
69  return aux_.event();
70  }
72  subRun() const
73  {
74  return aux_.subRun();
75  }
77  run() const
78  {
79  return id().run();
80  }
81 
82  bool
83  isRealData() const
84  {
85  return aux_.isRealData();
86  }
89  {
90  return aux_.experimentType();
91  }
92 
93  SubRun const& getSubRun() const;
94  Run const& getRun() const;
95 
96  History const& history() const;
97  ProcessHistoryID const& processHistoryID() const;
98 
99  // Put a new product.
100  template <typename PROD>
101  ProductID
102  put(std::unique_ptr<PROD>&& product)
103  {
104  return put<PROD>(std::move(product), std::string());
105  }
106 
107  // Put a new product with a 'product instance name'
108  template <typename PROD>
109  ProductID put(std::unique_ptr<PROD>&& product,
110  std::string const& productInstanceName);
111 
112  // Retrieve a product
113  using Base::get;
114  using Base::getByLabel;
115  using Base::getByToken;
116  using Base::getMany;
117  using Base::getManyByType;
119  using Base::getValidHandle;
120 
121  // Retrieve a view to a collection of products
122  using Base::getView;
123 
124  // Expert-level
125  using Base::processHistory;
127  using Base::size;
128 
129  // Return true if this Event has been subjected to a process with
130  // the given processName, and false otherwise.
131  // If true is returned, then ps is filled with the ParameterSet
132  // used to configure the identified process.
133  bool getProcessParameterSet(std::string const& processName,
134  fhicl::ParameterSet& ps) const;
135 
136  EDProductGetter const* productGetter(ProductID const) const;
137 
138  // In principle, the principal (heh, heh) need not be a function
139  // argument since this class already keeps an internal reference to
140  // it. However, since the 'commit' function is public, requiring
141  // the principal as an argument prevents a commit from being called
142  // inappropriately.
143  void commit(EventPrincipal&,
144  bool checkPutProducts,
145  std::set<TypeLabel> const& expectedProducts);
146 
147  template <typename T>
149 
150 private:
152  std::unique_ptr<SubRun const> const subRun_;
154 }; // Event
155 
156 // ----------------------------------------------------------------------
157 
158 template <typename PROD>
160 art::Event::put(std::unique_ptr<PROD>&& product,
161  std::string const& productInstanceName)
162 {
163  TypeID const tid{typeid(PROD)};
164  if (product.get() == nullptr) {
166  << "Event::put: A null unique_ptr was passed to 'put'.\n"
167  << "The pointer is of type " << tid << ".\n"
168  << "The specified productInstanceName was '" << productInstanceName
169  << "'.\n";
170  }
171 
172  auto const& pd = getProductDescription(tid, productInstanceName);
173  auto wp = std::make_unique<Wrapper<PROD>>(std::move(product));
174 
175  auto result = putProducts().emplace(
176  TypeLabel{
177  tid, productInstanceName, SupportsView<PROD>::value, false /*not used*/},
178  DataViewImpl::PMValue{std::move(wp), pd, RangeSet::invalid()});
179  if (!result.second) {
180  cet::HorizontalRule rule{30};
182  << "Event::put: Attempt to put multiple products with the\n"
183  << " following description onto the Event.\n"
184  << " Products must be unique per Event.\n"
185  << rule('=') << '\n'
186  << pd << rule('=') << '\n';
187  }
188 
189  return pd.productID();
190 } // put<>()
191 
192 // ----------------------------------------------------------------------
193 #endif /* art_Framework_Principal_Event_h */
194 
195 // Local Variables:
196 // mode: c++
197 // End:
EDProductGetter const * productGetter(ProductID const) const
bool isRealData() const
bool getProcessParameterSet(std::string const &processName, fhicl::ParameterSet &ps) const
SubRunNumber_t subRun() const
Definition: Event.h:72
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:396
Timestamp const & time() const
ProcessHistory const & processHistory() const
Run const & getRun() const
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:307
bool isRealData() const
Definition: Event.h:83
RunNumber_t run() const
Definition: EventID.h:98
Definition: Run.h:31
EventAuxiliary::ExperimentType experimentType() const
Definition: Event.h:88
SubRun const & getSubRun() const
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:474
void getMany(SelectorBase const &, std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:421
static RangeSet invalid()
History const & history() const
EventPrincipal const & eventPrincipal_
Definition: Event.h:153
EventAuxiliary const & aux_
Definition: Event.h:151
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
EventNumber_t event() const
Definition: Event.h:67
SubRunNumber_t subRun() const
EventNumber_t event() const
std::unique_ptr< SubRun const > const subRun_
Definition: Event.h:152
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
TypeLabelMap & putProducts()
Definition: DataViewImpl.h:183
ProcessHistoryID const & processHistoryID() const
Timestamp time() const
Definition: Event.h:61
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
void commit(EventPrincipal &, bool checkPutProducts, std::set< TypeLabel > const &expectedProducts)
BranchDescription const & getProductDescription(TypeID const &type, std::string const &productInstanceName) const
bool removeCachedProduct(Handle< PROD > &h) const
Definition: DataViewImpl.h:551
DataViewImpl(DataViewImpl const &)=delete
ExperimentType experimentType() const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
void checkPutProducts(bool checkProducts, std::set< TypeLabel > const &expectedProducts, TypeLabelMap const &putProducts)
RunNumber_t run() const
Definition: Event.h:77
Event(EventPrincipal const &ep, ModuleDescription const &md, cet::exempt_ptr< Consumer > consumer, RangeSet const &rs)
size_t size() const
EventID id() const
Definition: Event.h:56
EventID const & id() const
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119