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