LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Run.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_Run_h
2 #define art_Framework_Principal_Run_h
3 
4 // ======================================================================
5 //
6 // Run - This is the primary interface for accessing per run EDProducts
7 // and inserting new derived products.
8 //
9 // For its usage, see "art/Framework/Principal/DataViewImpl.h"
10 // ======================================================================
11 
21 
22 #include <memory>
23 #include <set>
24 #include <utility>
25 
26 namespace art {
27  class Consumer;
28 }
29 
30 class art::Run final : private art::DataViewImpl {
31 public:
32  using Base = DataViewImpl;
33 
34  explicit Run(RunPrincipal const& rp,
35  ModuleDescription const& md,
36  cet::exempt_ptr<Consumer> consumer,
37  RangeSet const& rsForPuttingProducts = RangeSet::invalid());
38 
39  // AUX functions.
40  RunID const&
41  id() const
42  {
43  return aux_.id();
44  }
46  run() const
47  {
48  return aux_.run();
49  }
50  Timestamp const&
51  beginTime() const
52  {
53  return aux_.beginTime();
54  }
55  Timestamp const&
56  endTime() const
57  {
58  return aux_.endTime();
59  }
60 
61  // Retrieve a product
62  using Base::get;
63  using Base::getByLabel;
64  using Base::getByToken;
65  using Base::getMany;
66  using Base::getManyByType;
69 
70  // Retrieve a view to a collection of products
71  using Base::getView;
72 
73  // Put a new product
74  template <typename PROD>
75  art::ProductID put(std::unique_ptr<PROD>&&);
76  template <typename PROD>
77  art::ProductID put(std::unique_ptr<PROD>&&, FullSemantic<Level::Run>);
78  template <typename PROD>
79  art::ProductID put(std::unique_ptr<PROD>&&, FragmentSemantic<Level::Run>);
80  template <typename PROD>
81  art::ProductID put(std::unique_ptr<PROD>&&,
83 
84  // Put a new product with an instance name
85  template <typename PROD>
86  art::ProductID put(std::unique_ptr<PROD>&&, std::string const& instanceName);
87  template <typename PROD>
88  art::ProductID put(std::unique_ptr<PROD>&&,
89  std::string const& instanceName,
91  template <typename PROD>
92  art::ProductID put(std::unique_ptr<PROD>&&,
93  std::string const& instanceName,
95  template <typename PROD>
96  art::ProductID put(std::unique_ptr<PROD>&&,
97  std::string const& instanceName,
99 
100  // Expert-level
101  using Base::processHistory;
103 
104  // Return true if this Run has been subjected to a process with the
105  // given processName, and false otherwise. If true is returned,
106  // then ps is filled with the ParameterSets (possibly more than one)
107  // used to configure the identified process(es). Equivalent
108  // ParameterSets are compressed out of the result.
109  bool getProcessParameterSet(std::string const& processName,
110  std::vector<fhicl::ParameterSet>& ps) const;
111 
112  EDProductGetter const* productGetter(ProductID const pid) const;
113 
114  // In principle, the principal (heh, heh) need not be a function
115  // argument since this class already keeps an internal reference to
116  // it. However, since the 'commit' function is public, requiring
117  // the principal as an argument prevents a commit from being called
118  // inappropriately.
119  void commit(RunPrincipal& rp,
120  bool const checkProducts,
121  std::set<TypeLabel> const& expectedProducts);
122 
123  void commit(RunPrincipal&);
124 
125  template <typename T>
127 
128 private:
130  template <typename PROD>
131  art::ProductID put_(std::unique_ptr<PROD>&& product,
132  std::string const& productInstanceName,
133  RangeSet const& rs);
134 
138 };
139 
140 //================================================================
141 // Implementation
142 
143 //----------------------------------------------------------------
144 // putting with no specified instance name
145 
146 template <typename PROD>
148 art::Run::put(std::unique_ptr<PROD>&& product)
149 {
150  return put<PROD>(std::move(product), std::string{});
151 }
152 
153 template <typename PROD>
155 art::Run::put(std::unique_ptr<PROD>&& product,
156  FullSemantic<Level::Run> const semantic)
157 {
158  return put<PROD>(std::move(product), std::string{}, semantic);
159 }
160 
161 template <typename PROD>
163 art::Run::put(std::unique_ptr<PROD>&& product,
164  FragmentSemantic<Level::Run> const semantic)
165 {
166  return put<PROD>(std::move(product), std::string{}, semantic);
167 }
168 
169 template <typename PROD>
171 art::Run::put(std::unique_ptr<PROD>&& product,
173 {
174  return put<PROD>(std::move(product), std::string{}, std::move(semantic));
175 }
176 
177 //----------------------------------------------------------------
178 // putting with specified instance name
179 
180 template <typename PROD>
182 art::Run::put(std::unique_ptr<PROD>&& product,
183  std::string const& productInstanceName)
184 {
186  return put_<PROD>(std::move(product), productInstanceName, productRangeSet_);
187 }
188 
189 template <typename PROD>
191 art::Run::put(std::unique_ptr<PROD>&& product,
192  std::string const& productInstanceName,
194 {
195  return put_<PROD>(
196  std::move(product), productInstanceName, RangeSet::forRun(id()));
197 }
198 
199 template <typename PROD>
201 art::Run::put(std::unique_ptr<PROD>&& product,
202  std::string const& productInstanceName,
204 {
205  static_assert(
207  "\n\n"
208  "art error: A Run product put with the semantic 'RunFragment'\n"
209  " must be able to be aggregated. Please add the appropriate\n"
210  " void aggregate(T const&)\n"
211  " function to your class, or contact artists@fnal.gov.\n");
212 
214  throw Exception{errors::ProductPutFailure, "Run::put"}
215  << "\nCannot put a product corresponding to a full Run using\n"
216  << "art::runFragment(). This can happen if you attempted to\n"
217  << "put a product at beginRun using art::runFragment().\n"
218  << "Please use either:\n"
219  << " art::fullRun(), or\n"
220  << " art::runFragment(art::RangeSet const&)\n"
221  << "or contact artists@fnal.gov for assistance.\n";
222  }
223  return put_<PROD>(std::move(product), productInstanceName, productRangeSet_);
224 }
225 
226 template <typename PROD>
228 art::Run::put(std::unique_ptr<PROD>&& product,
229  std::string const& productInstanceName,
231 {
232  static_assert(
234  "\n\n"
235  "art error: A Run product put with the semantic 'RunFragment'\n"
236  " must be able to be aggregated. Please add the appropriate\n"
237  " void aggregate(T const&)\n"
238  " function to your class, or contact artists@fnal.gov.\n");
239  if (semantic.rs.collapse().is_full_run()) {
240  throw Exception{errors::ProductPutFailure, "Run::put"}
241  << "\nCannot put a product corresponding to a full Run using\n"
242  << "art::runFragment(art::RangeSet&). Please use:\n"
243  << " art::fullRun()\n"
244  << "or contact artists@fnal.gov for assistance.\n";
245  }
246  return put_<PROD>(std::move(product), productInstanceName, semantic.rs);
247 }
248 
249 template <typename PROD>
251 art::Run::put_(std::unique_ptr<PROD>&& product,
252  std::string const& productInstanceName,
253  RangeSet const& rs)
254 {
255  TypeID const tid{typeid(PROD)};
256  if (product.get() == nullptr) {
257  throw Exception{errors::NullPointerError, "Run::put"}
258  << "\nA null unique_ptr was passed to 'put'.\n"
259  << "The pointer is of type " << tid << ".\n"
260  << "The specified productInstanceName was '" << productInstanceName
261  << "'.\n";
262  }
263 
264  if (!rs.is_valid()) {
265  throw Exception{errors::ProductPutFailure, "Run::put"}
266  << "\nCannot put a product with an invalid RangeSet.\n"
267  << "Please contact artists@fnal.gov.\n";
268  }
269 
270  auto const& pd = getProductDescription(tid, productInstanceName);
271  auto wp = std::make_unique<Wrapper<PROD>>(std::move(product));
272 
273  auto result = putProducts().emplace(
274  TypeLabel{
275  tid, productInstanceName, SupportsView<PROD>::value, false /*not used*/},
276  PMValue{std::move(wp), pd, rs});
277  if (!result.second) {
278  throw Exception{errors::ProductPutFailure, "Run::put"}
279  << "\nAttempt to put multiple products with the\n"
280  << "following description onto the Run.\n"
281  << "Products must be unique per Run.\n"
282  << "=================================\n"
283  << pd << "=================================\n";
284  }
285 
286  return pd.productID();
287 }
288 
289 #endif /* art_Framework_Principal_Run_h */
290 
291 // Local Variables:
292 // mode: c++
293 // End:
RunID const & id() const
Definition: RunAuxiliary.h:51
RangeSet & collapse()
Definition: RangeSet.cc:74
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:396
bool getProcessParameterSet(std::string const &processName, std::vector< fhicl::ParameterSet > &ps) const
Definition: Run.cc:28
ProcessHistory const & processHistory() const
Definition: DataViewImpl.cc:81
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:307
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:148
RunNumber_t run() const
Definition: Run.h:46
BranchDescription const & getProductDescription(TypeID const &type, std::string const &productInstanceName) const
Definition: Run.h:30
void commit(RunPrincipal &rp, bool const checkProducts, std::set< TypeLabel > const &expectedProducts)
Definition: Run.cc:36
art::ProductID put_(std::unique_ptr< PROD > &&product, std::string const &productInstanceName, RangeSet const &rs)
Put a new product with a &#39;product instance name&#39; and a &#39;range set&#39;.
Definition: Run.h:251
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
Timestamp const & endTime() const
Definition: Run.h:56
Timestamp const & endTime() const
Definition: RunAuxiliary.h:63
RunID const & id() const
Definition: Run.h:41
Run(RunPrincipal const &rp, ModuleDescription const &md, cet::exempt_ptr< Consumer > consumer, RangeSet const &rsForPuttingProducts=RangeSet::invalid())
Definition: Run.cc:11
bool is_full_run() const
Definition: RangeSet.cc:246
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
static RangeSet forRun(RunID)
Definition: RangeSet.cc:52
Principal const & principal_
Definition: Run.h:135
RunNumber_t run() const
Definition: RunAuxiliary.h:74
bool is_valid() const
Definition: RangeSet.cc:230
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EDProductGetter const * productGetter(ProductID const pid) const
Definition: Run.cc:22
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
static RangeSet invalid()
Definition: RangeSet.cc:46
TypeLabelMap & putProducts()
Definition: DataViewImpl.h:183
RunAuxiliary const & aux_
Definition: Run.h:136
HLT enums.
Timestamp const & beginTime() const
Definition: RunAuxiliary.h:57
bool removeCachedProduct(Handle< PROD > &h) const
Definition: DataViewImpl.h:551
Timestamp const & beginTime() const
Definition: Run.h:51
DataViewImpl(DataViewImpl const &)=delete
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119
RangeSet productRangeSet_
Definition: Run.h:137