put_product_in_principal.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Sources_put_product_in_principal_h
2 #define art_Framework_IO_Sources_put_product_in_principal_h
3 
4 ////////////////////////////////////////////////////////////////////////
5 // Helper class to put products directly into the {Run, SubRun, Event}
6 // Principal.
7 //
8 // NOTE that this should *not* be used to put products in the event that
9 // require parentage information to be filled in.
10 //
11 // 2011/03/15 CG,
12 ////////////////////////////////////////////////////////////////////////
13 
24 
25 #include <memory>
26 #include <string>
27 
28 namespace art {
29  template <typename T, typename P>
30  std::enable_if_t<P::branch_type == InEvent || P::branch_type == InResults>
31  put_product_in_principal(std::unique_ptr<T>&& product,
32  P& principal,
33  std::string const& module_label,
34  std::string const& instance_name = {});
35 
36  template <typename T, typename P>
37  std::enable_if_t<P::branch_type == InSubRun || P::branch_type == InRun>
38  put_product_in_principal(std::unique_ptr<T>&& product,
39  P& principal,
40  std::string const& module_label,
41  std::string const& instance_name = {},
42  RangeSet&& = RangeSet::invalid());
43 
44  inline RangeSet
46  {
47  return RangeSet::forRun(rp.id());
48  }
49 
50  inline RangeSet
52  {
53  return RangeSet::forSubRun(srp.id());
54  }
55 }
56 
57 template <typename T, typename P>
58 std::enable_if_t<P::branch_type == art::InEvent ||
59  P::branch_type == art::InResults>
60 art::put_product_in_principal(std::unique_ptr<T>&& product,
61  P& principal,
62  std::string const& module_label,
63  std::string const& instance_name)
64 {
65  if (product.get() == nullptr) {
66  TypeID const typeID{typeid(T)};
68  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
69  << "The pointer is of type " << typeID << ".\n"
70  << "The specified product instance name was '" << instance_name << "'.\n";
71  }
72 
73  BranchDescription const& desc =
74  get_ProductDescription<T>(principal, module_label, instance_name);
75 
76  std::unique_ptr<EDProduct> wp =
77  std::make_unique<Wrapper<T>>(std::move(product));
78  principal.put(std::move(wp),
79  desc,
80  std::make_unique<ProductProvenance const>(
82 }
83 
84 template <typename T, typename P>
85 std::enable_if_t<P::branch_type == art::InSubRun ||
86  P::branch_type == art::InRun>
87 art::put_product_in_principal(std::unique_ptr<T>&& product,
88  P& principal,
89  std::string const& module_label,
90  std::string const& instance_name,
91  RangeSet&& rs)
92 {
93  if (product.get() == nullptr) {
94  TypeID const typeID{typeid(T)};
96  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
97  << "The pointer is of type " << typeID << ".\n"
98  << "The specified product instance name was '" << instance_name << "'.\n";
99  }
100 
101  BranchDescription const& desc =
102  get_ProductDescription<T>(principal, module_label, instance_name);
103 
104  // If the provided RangeSet is invalid, assign it a RangeSet
105  // corresponding to the full (Sub)Run.
106  if (!rs.is_valid())
107  rs = rangeSetFor(principal);
108 
109  std::unique_ptr<EDProduct> wp =
110  std::make_unique<Wrapper<T>>(std::move(product));
111  principal.put(std::move(wp),
112  desc,
113  std::make_unique<ProductProvenance const>(
115  std::move(rs));
116 }
117 
118 #endif /* art_Framework_IO_Sources_put_product_in_principal_h */
119 
120 // Local Variables:
121 // mode: c++
122 // End:
static RangeSet forSubRun(SubRunID)
std::enable_if_t< P::branch_type==InEvent||P::branch_type==InResults > put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
RangeSet rangeSetFor(RunPrincipal const &rp)
static RangeSet forRun(RunID)
#define P(a, b, c, d, e, x)
static RangeSet invalid()
SubRunID id() const
ProductID productID() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)
RunID const & id() const
Definition: RunPrincipal.h:48
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
double T
Definition: Xdiff_gwt.C:5
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10