LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SubRun.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_SubRun_h
2 #define art_Framework_Principal_SubRun_h
3 // vim: set sw=2 expandtab :
4 
5 //
6 // This is the primary interface for accessing per subRun
7 // EDProducts and inserting new derived per subRun EDProducts.
8 //
9 // For its usage, see "art/Framework/Principal/ProductRetriever.h"
10 //
11 
17 
18 #include <cassert>
19 #include <memory>
20 #include <optional>
21 
22 #define PUT_DEPRECATION_MSG \
23  "\n\n" \
24  "art warning: The SubRun::put(...) function without a product semantic is " \
25  "deprecated.\n" \
26  " Please adjust your usage to include the correct semantic " \
27  "(e.g.):\n\n" \
28  " subrun.put(std::move(product), art::fullSubRun());\n" \
29  " subrun.put(std::move(product), instanceName, " \
30  "art::subRunFragment());\n\n" \
31  " Generally, SubRun::put calls made in beginSubRun should " \
32  "include art::fullSubRun();\n" \
33  " SubRun::put calls made in endSubRun should use " \
34  "art::subRunFragment().\n" \
35  " Contact artists@fnal.gov for assistance or details.\n\n"
36 
37 namespace art {
38 
39  class SubRun final : private ProductRetriever {
40  public:
41  ~SubRun();
42 
43  explicit SubRun(SubRunPrincipal const& srp,
44  ModuleContext const& mc,
45  std::optional<ProductInserter> inserter = std::nullopt,
46  RangeSet const& rs = RangeSet::invalid());
47 
48  SubRun(SubRun const&) = delete;
49  SubRun(SubRun&&) = delete;
50  SubRun& operator=(SubRun const&) = delete;
51  SubRun& operator=(SubRun&&) = delete;
52 
53  SubRunID id() const;
54  RunNumber_t run() const;
55  SubRunNumber_t subRun() const;
56  Timestamp const& beginTime() const;
57  Timestamp const& endTime() const;
58  ProcessHistory const& processHistory() const;
59 
67 
68  Run const& getRun() const;
72 
75 
76  // Obsolete interface (will be deprecated)
79 
80  // Product insertion - subrun
81  template <typename PROD>
82  [[deprecated(PUT_DEPRECATION_MSG)]] PutHandle<PROD> put(
83  std::unique_ptr<PROD>&& edp,
84  std::string const& instance = {});
85  template <typename PROD>
86  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
88  template <typename PROD>
89  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
91  template <typename PROD>
92  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
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  template <typename PROD>
103  PutHandle<PROD> put(std::unique_ptr<PROD>&& edp,
104  std::string const& instance,
106 
107  private:
108  void commitProducts();
109 
110  // Give access to commitProducts(...).
111  friend class detail::Analyzer;
112  friend class detail::Filter;
113  friend class detail::Producer;
114  friend class ProducingService;
115 
116  std::optional<ProductInserter> inserter_;
118  Run const run_;
119  // The RangeSet to be used by any products put by the user.
120  // Cannot be const because we call collapse() on it.
122  };
123 
124  template <typename PROD>
126  SubRun::put(std::unique_ptr<PROD>&& edp, std::string const& instance)
127  {
128  assert(inserter_);
129  // Should be protected when a SubRun is shared among threads.
130  return inserter_->put(std::move(edp), instance, rangeSet_.collapse());
131  }
132 
133  template <typename PROD>
135  SubRun::put(std::unique_ptr<PROD>&& edp,
136  FullSemantic<Level::SubRun> const semantic)
137  {
138  return put(std::move(edp), "", semantic);
139  }
140 
141  template <typename PROD>
143  SubRun::put(std::unique_ptr<PROD>&& edp,
144  FragmentSemantic<Level::SubRun> const semantic)
145  {
146  return put(std::move(edp), "", semantic);
147  }
148 
149  template <typename PROD>
151  SubRun::put(std::unique_ptr<PROD>&& edp,
153  {
154  return put(std::move(edp), "", std::move(semantic));
155  }
156 
157  template <typename PROD>
159  SubRun::put(std::unique_ptr<PROD>&& edp,
160  std::string const& instance,
162  {
163  assert(inserter_);
164  return inserter_->put(std::move(edp), instance, RangeSet::forSubRun(id()));
165  }
166 
167  template <typename PROD>
169  SubRun::put(std::unique_ptr<PROD>&& edp,
170  std::string const& instance,
172  {
173  static_assert(
175  "\n\n"
176  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
177  " must be able to be aggregated. Please add the appropriate\n"
178  " void aggregate(T const&)\n"
179  " function to your class, or contact artists@fnal.gov.\n");
180  assert(inserter_);
182  throw Exception(errors::ProductPutFailure, "SubRun::put")
183  << "\nCannot put a product corresponding to a full SubRun using\n"
184  << "art::subRunFragment(). This can happen if you attempted to\n"
185  << "put a product at beginSubRun using art::subRunFragment().\n"
186  << "Please use either:\n"
187  << " art::fullSubRun(), or\n"
188  << " art::subRunFragment(art::RangeSet const&)\n"
189  << "or contact artists@fnal.gov for assistance.\n";
190  }
191  return inserter_->put(std::move(edp), instance, rangeSet_);
192  }
193 
194  template <typename PROD>
196  SubRun::put(std::unique_ptr<PROD>&& edp,
197  std::string const& instance,
199  {
200  static_assert(
202  "\n\n"
203  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
204  " must be able to be aggregated. Please add the appropriate\n"
205  " void aggregate(T const&)\n"
206  " function to your class, or contact artists@fnal.gov.\n");
207  assert(inserter_);
208  if (semantic.rs.collapse().is_full_subRun()) {
209  throw Exception{errors::ProductPutFailure, "SubRun::put"}
210  << "\nCannot put a product corresponding to a full SubRun using\n"
211  << "art::subRunFragment(art::RangeSet&). Please use:\n"
212  << " art::fullSubRun()\n"
213  << "or contact artists@fnal.gov for assistance.\n";
214  }
215  if (!semantic.rs.is_valid()) {
216  throw Exception{errors::ProductPutFailure, "SubRun::put"}
217  << "\nCannot put a product with an invalid RangeSet.\n"
218  << "Please contact artists@fnal.gov.\n";
219  }
220  return inserter_->put(std::move(edp), instance, semantic.rs);
221  }
222 
223 } // namespace art
224 
225 #undef PUT_DEPRECATION_MSG
226 
227 #endif /* art_Framework_Principal_SubRun_h */
228 
229 // Local Variables:
230 // mode: c++
231 // End:
bool get(SelectorBase const &, Handle< PROD > &result) const
SubRun(SubRunPrincipal const &srp, ModuleContext const &mc, std::optional< ProductInserter > inserter=std::nullopt, RangeSet const &rs=RangeSet::invalid())
Definition: SubRun.cc:13
ProductID getProductID(std::string const &instance_name="") const
std::optional< fhicl::ParameterSet const > getProcessParameterSet(std::string const &process) const
SubRunPrincipal const & subRunPrincipal_
Definition: SubRun.h:117
const std::string instance
RangeSet rangeSet_
Definition: SubRun.h:121
RangeSet & collapse()
Definition: RangeSet.cc:262
Definition: Run.h:37
ProcessHistory const & processHistory() const
Definition: SubRun.cc:55
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
EDProductGetter const * productGetter(ProductID const pid) const
Run const & getRun() const
Definition: SubRun.cc:61
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: SubRun.h:126
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
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
Run const run_
Definition: SubRun.h:118
SubRunNumber_t subRun() const
Definition: SubRun.cc:37
#define PUT_DEPRECATION_MSG
Definition: SubRun.h:22
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Timestamp const & endTime() const
Definition: SubRun.cc:49
void commitProducts()
Definition: SubRun.cc:67
SubRunID id() const
Definition: SubRun.cc:25
static RangeSet invalid()
Definition: RangeSet.cc:45
cet::exempt_ptr< BranchDescription const > getProductDescription(ProductID) const
Definition: MVAAlg.h:12
bool is_full_subRun() const
Definition: RangeSet.cc:130
Timestamp const & beginTime() const
Definition: SubRun.cc:43
PROD const & getProduct(InputTag const &tag) const
RunNumber_t run() const
Definition: SubRun.cc:31
std::optional< ProductInserter > inserter_
Definition: SubRun.h:116
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
std::optional< Provenance const > getProductProvenance(ProductID) const
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120
SubRun & operator=(SubRun const &)=delete