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