LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 // vim: set sw=2 expandtab :
4 
5 //
6 // 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/ProductRetriever.h"
10 //
11 
16 
17 #include <cassert>
18 #include <optional>
19 
20 #define PUT_DEPRECATION_MSG \
21  "\n\n" \
22  "art warning: The Run::put(...) function without a product semantic is " \
23  "deprecated.\n" \
24  " Please adjust your usage to include the correct semantic " \
25  "(e.g.):\n\n" \
26  " run.put(std::move(product), art::fullRun());\n" \
27  " run.put(std::move(product), instanceName, " \
28  "art::runFragment());\n\n" \
29  " Generally, Run::put calls made in beginRun should include " \
30  "art::fullRun();\n" \
31  " Run::put calls made in endRun should use " \
32  "art::runFragment().\n" \
33  " Contact artists@fnal.gov for assistance or details.\n\n"
34 
35 namespace art {
36 
37  class Run final : private ProductRetriever {
38  public:
39  ~Run();
40 
41  explicit Run(RunPrincipal const& srp,
42  ModuleContext const& mc,
43  std::optional<ProductInserter> inserter = std::nullopt,
44  RangeSet const& rs = RangeSet::invalid());
45 
46  Run(Run const&) = delete;
47  Run(Run&&) = delete;
48  Run& operator=(Run const&) = delete;
49  Run& operator=(Run&&) = delete;
50 
51  RunID id() const;
52  RunNumber_t run() const;
53  Timestamp const& beginTime() const;
54  Timestamp const& endTime() const;
55  ProcessHistory const& processHistory() const;
56 
64 
68 
71 
72  // Obsolete interface (will be deprecated)
75 
76  // Product insertion
77  template <typename PROD>
78  [[deprecated(PUT_DEPRECATION_MSG)]] PutHandle<PROD> put(
79  std::unique_ptr<PROD>&& edp,
80  std::string const& instance = {});
81  template <typename PROD>
82  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
83  FullSemantic<Level::Run> semantic);
84  template <typename PROD>
85  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
87  template <typename PROD>
88  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
90  template <typename PROD>
91  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
92  std::string const& instance,
94  template <typename PROD>
95  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
96  std::string const& instance,
98  template <typename PROD>
99  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
100  std::string const& instance,
102 
103  private:
104  void commitProducts();
105 
106  // Give access to commitProducts(...).
107  friend class detail::Analyzer;
108  friend class detail::Filter;
109  friend class detail::Producer;
110  friend class ProducingService;
111 
112  std::optional<ProductInserter> inserter_;
114  // The RangeSet to be used by any products put by the user.
115  // Cannot be const because we call collapse() on it.
117  };
118 
119  template <typename PROD>
121  Run::put(std::unique_ptr<PROD>&& edp, std::string const& instance)
122  {
123  // Should be protected when a Run is shared among threads.
124  assert(inserter_);
125  return inserter_->put(std::move(edp), instance, rangeSet_.collapse());
126  }
127 
128  template <typename PROD>
130  Run::put(std::unique_ptr<PROD>&& edp, FullSemantic<Level::Run> const semantic)
131  {
132  return put(std::move(edp), "", semantic);
133  }
134 
135  template <typename PROD>
137  Run::put(std::unique_ptr<PROD>&& edp,
138  FragmentSemantic<Level::Run> const semantic)
139  {
140  return put(std::move(edp), "", semantic);
141  }
142 
143  template <typename PROD>
145  Run::put(std::unique_ptr<PROD>&& edp,
147  {
148  return put(std::move(edp), "", std::move(semantic));
149  }
150 
151  template <typename PROD>
153  Run::put(std::unique_ptr<PROD>&& edp,
154  std::string const& instance,
156  {
157  assert(inserter_);
158  return inserter_->put(std::move(edp), instance, RangeSet::forRun(id()));
159  }
160 
161  template <typename PROD>
163  Run::put(std::unique_ptr<PROD>&& edp,
164  std::string const& instance,
166  {
167  static_assert(
169  "\n\n"
170  "art error: A Run product put with the semantic 'RunFragment'\n"
171  " must be able to be aggregated. Please add the appropriate\n"
172  " void aggregate(T const&)\n"
173  " function to your class, or contact artists@fnal.gov.\n");
174  assert(inserter_);
175  if (rangeSet_.collapse().is_full_run()) {
176  throw Exception{errors::ProductPutFailure, "Run::put"}
177  << "\nCannot put a product corresponding to a full Run using\n"
178  << "art::runFragment(). This can happen if you attempted to\n"
179  << "put a product at beginRun using art::runFragment().\n"
180  << "Please use either:\n"
181  << " art::fullRun(), or\n"
182  << " art::runFragment(art::RangeSet const&)\n"
183  << "or contact artists@fnal.gov for assistance.\n";
184  }
185  return inserter_->put(std::move(edp), instance, rangeSet_);
186  }
187 
188  template <typename PROD>
190  Run::put(std::unique_ptr<PROD>&& edp,
191  std::string const& instance,
193  {
194  static_assert(
196  "\n\n"
197  "art error: A Run product put with the semantic 'RunFragment'\n"
198  " must be able to be aggregated. Please add the appropriate\n"
199  " void aggregate(T const&)\n"
200  " function to your class, or contact artists@fnal.gov.\n");
201  assert(inserter_);
202  if (semantic.rs.collapse().is_full_run()) {
203  throw Exception{errors::ProductPutFailure, "Run::put"}
204  << "\nCannot put a product corresponding to a full Run using\n"
205  << "art::runFragment(art::RangeSet&). Please use:\n"
206  << " art::fullRun()\n"
207  << "or contact artists@fnal.gov for assistance.\n";
208  }
209  if (!semantic.rs.is_valid()) {
210  throw Exception{errors::ProductPutFailure, "Run::put"}
211  << "\nCannot put a product with an invalid RangeSet.\n"
212  << "Please contact artists@fnal.gov.\n";
213  }
214  return inserter_->put(std::move(edp), instance, semantic.rs);
215  }
216 
217 } // namespace art
218 
219 #undef PUT_DEPRECATION_MSG
220 
221 #endif /* art_Framework_Principal_Run_h */
222 
223 // Local Variables:
224 // mode: c++
225 // End:
bool get(SelectorBase const &, Handle< PROD > &result) const
#define PUT_DEPRECATION_MSG
Definition: Run.h:20
Timestamp const & endTime() const
Definition: Run.cc:39
RunID id() const
Definition: Run.cc:21
ProductID getProductID(std::string const &instance_name="") const
std::optional< fhicl::ParameterSet const > getProcessParameterSet(std::string const &process) const
Run & operator=(Run const &)=delete
const std::string instance
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
RangeSet rangeSet_
Definition: Run.h:116
RunNumber_t run() const
Definition: Run.cc:27
RangeSet & collapse()
Definition: RangeSet.cc:262
Definition: Run.h:37
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
EDProductGetter const * productGetter(ProductID const pid) const
bool is_full_run() const
Definition: RangeSet.cc:123
std::vector< InputTag > getInputTags(SelectorBase const &selector=MatchAllSelector{}) const
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
ProcessHistory const & processHistory() const
Definition: Run.cc:45
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Handle< PROD > getHandle(SelectorBase const &) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::optional< ProductInserter > inserter_
Definition: Run.h:112
static RangeSet invalid()
Definition: RangeSet.cc:45
cet::exempt_ptr< BranchDescription const > getProductDescription(ProductID) const
void commitProducts()
Definition: Run.cc:51
Definition: MVAAlg.h:12
Timestamp const & beginTime() const
Definition: Run.cc:33
RunPrincipal const & runPrincipal_
Definition: Run.h:113
PROD const & getProduct(InputTag const &tag) const
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
std::optional< Provenance const > getProductProvenance(ProductID) const
Run(RunPrincipal const &srp, ModuleContext const &mc, std::optional< ProductInserter > inserter=std::nullopt, RangeSet const &rs=RangeSet::invalid())
Definition: Run.cc:10
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120