LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
4 // ======================================================================
5 //
6 // SubRun: 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/DataViewImpl.h"
10 //
11 // ======================================================================
12 
24 
25 #include <memory>
26 #include <set>
27 #include <utility>
28 
29 namespace art {
30  class Consumer;
31 }
32 
33 class art::SubRun final : private art::DataViewImpl {
34 public:
35  using Base = DataViewImpl;
36 
37  SubRun(SubRunPrincipal const& srp,
38  ModuleDescription const& md,
39  cet::exempt_ptr<Consumer> consumer,
40  RangeSet const& rsForPuttingProducts = RangeSet::invalid());
41 
43  subRun() const
44  {
45  return aux_.subRun();
46  }
48  run() const
49  {
50  return aux_.run();
51  }
52  SubRunID
53  id() const
54  {
55  return aux_.id();
56  }
57 
58  Timestamp const&
59  beginTime() const
60  {
61  return aux_.beginTime();
62  }
63  Timestamp const&
64  endTime() const
65  {
66  return aux_.endTime();
67  }
68 
69  // Retrieve a product
70  using Base::get;
71  using Base::getByLabel;
72  using Base::getByToken;
73  using Base::getMany;
74  using Base::getManyByType;
77 
78  // Retrieve a view to a collection of products
79  using Base::getView;
80 
81  Run const& getRun() const;
82 
83  // Put a new product
84  template <typename PROD>
85  ProductID put(std::unique_ptr<PROD>&&);
86  template <typename PROD>
87  ProductID put(std::unique_ptr<PROD>&&, FullSemantic<Level::SubRun>);
88  template <typename PROD>
89  ProductID put(std::unique_ptr<PROD>&&, FragmentSemantic<Level::SubRun>);
90  template <typename PROD>
91  ProductID put(std::unique_ptr<PROD>&&, RangedFragmentSemantic<Level::SubRun>);
92 
93  // Put a new product with an instance name
94  template <typename PROD>
95  ProductID put(std::unique_ptr<PROD>&&, std::string const& instanceName);
96  template <typename PROD>
97  ProductID put(std::unique_ptr<PROD>&&,
98  std::string const& instanceName,
100  template <typename PROD>
101  ProductID put(std::unique_ptr<PROD>&&,
102  std::string const& instanceName,
104  template <typename PROD>
105  ProductID put(std::unique_ptr<PROD>&&,
106  std::string const& instanceName,
108 
109  // Expert-level
110  using Base::processHistory;
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(SubRunPrincipal& srp,
121  bool const checkProducts,
122  std::set<TypeLabel> const& expectedProducts);
123 
124  void commit(SubRunPrincipal&);
125 
126  template <typename T>
128 
129 private:
131  template <typename PROD>
132  art::ProductID put_(std::unique_ptr<PROD>&& product,
133  std::string const& productInstanceName,
134  RangeSet const& rs);
135 
138  std::unique_ptr<Run const> const run_;
140 };
141 
142 //================================================================
143 // Implementation
144 
145 //----------------------------------------------------------------
146 // putting with no specified instance name
147 
148 template <typename PROD>
150 art::SubRun::put(std::unique_ptr<PROD>&& product)
151 {
152  return put<PROD>(std::move(product), std::string{});
153 }
154 
155 template <typename PROD>
157 art::SubRun::put(std::unique_ptr<PROD>&& product,
158  FullSemantic<Level::SubRun> const semantic)
159 {
160  return put<PROD>(std::move(product), std::string{}, semantic);
161 }
162 
163 template <typename PROD>
165 art::SubRun::put(std::unique_ptr<PROD>&& product,
166  FragmentSemantic<Level::SubRun> const semantic)
167 {
168  return put<PROD>(std::move(product), std::string{}, semantic);
169 }
170 
171 template <typename PROD>
173 art::SubRun::put(std::unique_ptr<PROD>&& product,
175 {
176  return put<PROD>(std::move(product), std::string{}, std::move(semantic));
177 }
178 
179 //----------------------------------------------------------------
180 // putting with specified instance name
181 
182 template <typename PROD>
184 art::SubRun::put(std::unique_ptr<PROD>&& product,
185  std::string const& productInstanceName)
186 {
188  return put_<PROD>(std::move(product), productInstanceName, productRangeSet_);
189 }
190 
191 template <typename PROD>
193 art::SubRun::put(std::unique_ptr<PROD>&& product,
194  std::string const& productInstanceName,
196 {
197  return put_<PROD>(
198  std::move(product), productInstanceName, RangeSet::forSubRun(id()));
199 }
200 
201 template <typename PROD>
203 art::SubRun::put(std::unique_ptr<PROD>&& product,
204  std::string const& productInstanceName,
206 {
207  static_assert(
209  "\n\n"
210  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
211  " must be able to be aggregated. Please add the appropriate\n"
212  " void aggregate(T const&)\n"
213  " function to your class, or contact artists@fnal.gov.\n");
214 
216  throw art::Exception(art::errors::ProductPutFailure, "SubRun::put")
217  << "\nCannot put a product corresponding to a full SubRun using\n"
218  << "art::subRunFragment(). This can happen if you attempted to\n"
219  << "put a product at beginSubRun using art::subRunFragment().\n"
220  << "Please use either:\n"
221  << " art::fullSubRun(), or\n"
222  << " art::subRunFragment(art::RangeSet const&)\n"
223  << "or contact artists@fnal.gov for assistance.\n";
224  }
225  return put_<PROD>(std::move(product), productInstanceName, productRangeSet_);
226 }
227 
228 template <typename PROD>
230 art::SubRun::put(std::unique_ptr<PROD>&& product,
231  std::string const& productInstanceName,
233 {
234  static_assert(
236  "\n\n"
237  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
238  " must be able to be aggregated. Please add the appropriate\n"
239  " void aggregate(T const&)\n"
240  " function to your class, or contact artists@fnal.gov.\n");
241  if (semantic.rs.collapse().is_full_subRun()) {
242  throw Exception{errors::ProductPutFailure, "Run::put"}
243  << "\nCannot put a product corresponding to a full SubRun using\n"
244  << "art::subRunFragment(art::RangeSet&). Please use:\n"
245  << " art::fullSubRun()\n"
246  << "or contact artists@fnal.gov for assistance.\n";
247  }
248  return put_<PROD>(std::move(product), productInstanceName, semantic.rs);
249 }
250 
251 template <typename PROD>
253 art::SubRun::put_(std::unique_ptr<PROD>&& product,
254  std::string const& productInstanceName,
255  RangeSet const& rs)
256 {
257  TypeID const tid{typeid(PROD)};
258  if (product.get() == nullptr) {
259  throw art::Exception{art::errors::NullPointerError, "SubRun::put"}
260  << "\nA null unique_ptr was passed to 'put'.\n"
261  << "The pointer is of type " << tid << ".\n"
262  << "The specified productInstanceName was '" << productInstanceName
263  << "'.\n";
264  }
265 
266  if (!rs.is_valid()) {
267  throw art::Exception{art::errors::ProductPutFailure, "SubRun::put"}
268  << "\nCannot put a product with an invalid RangeSet.\n"
269  << "Please contact artists@fnal.gov.\n";
270  }
271 
272  auto const& pd = getProductDescription(tid, productInstanceName);
273  auto wp = std::make_unique<Wrapper<PROD>>(std::move(product));
274 
275  auto result = putProducts().emplace(
276  TypeLabel{
277  tid, productInstanceName, SupportsView<PROD>::value, false /*not used*/},
278  PMValue{std::move(wp), pd, rs});
279  if (!result.second) {
280  throw art::Exception{art::errors::ProductPutFailure, "SubRun::put"}
281  << "\nAttempt to put multiple products with the\n"
282  << "following description onto the SubRun.\n"
283  << "Products must be unique per SubRun.\n"
284  << "=================================\n"
285  << pd << "=================================\n";
286  }
287 
288  return pd.productID();
289 }
290 
291 #endif /* art_Framework_Principal_SubRun_h */
292 
293 // Local Variables:
294 // mode: c++
295 // End:
Timestamp const & endTime() const
Definition: SubRun.h:64
RangeSet & collapse()
Definition: RangeSet.cc:74
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:396
SubRunNumber_t subRun() const
Definition: SubRun.h:43
ProcessHistory const & processHistory() const
Definition: DataViewImpl.cc:81
SubRunID const & id() const
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:307
Timestamp const & endTime() const
std::unique_ptr< Run const > const run_
Definition: SubRun.h:138
Timestamp const & beginTime() const
Definition: SubRun.h:59
BranchDescription const & getProductDescription(TypeID const &type, std::string const &productInstanceName) const
Definition: Run.h:30
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: SubRun.h:253
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
Principal const & principal_
Definition: SubRun.h:136
SubRun(SubRunPrincipal const &srp, ModuleDescription const &md, cet::exempt_ptr< Consumer > consumer, RangeSet const &rsForPuttingProducts=RangeSet::invalid())
Definition: SubRun.cc:20
RangeSet productRangeSet_
Definition: SubRun.h:139
Run const & getRun() const
Definition: SubRun.cc:32
Timestamp const & beginTime() const
SubRunAuxiliary const & aux_
Definition: SubRun.h:137
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
SubRunNumber_t subRun() const
EDProductGetter const * productGetter(ProductID const pid) const
Definition: SubRun.cc:42
bool is_valid() const
Definition: RangeSet.cc:230
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool is_full_subRun() const
Definition: RangeSet.cc:253
void commit(SubRunPrincipal &srp, bool const checkProducts, std::set< TypeLabel > const &expectedProducts)
Definition: SubRun.cc:48
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:58
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
ProductID put(std::unique_ptr< PROD > &&)
SubRunID id() const
Definition: SubRun.h:53
static RangeSet invalid()
Definition: RangeSet.cc:46
TypeLabelMap & putProducts()
Definition: DataViewImpl.h:183
HLT enums.
bool removeCachedProduct(Handle< PROD > &h) const
Definition: DataViewImpl.h:551
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
RunNumber_t run() const
Definition: SubRun.h:48
RunNumber_t run() const
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119