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 // vim: set sw=2 expandtab :
4 
5 //
6 // Helper class to put products directly into the {Run, SubRun, Event}
7 // Principal.
8 //
9 // NOTE that this should *not* be used to put products in the event that
10 // require parentage information to be filled in.
11 //
12 
24 
25 #include <memory>
26 #include <string>
27 
28 namespace art {
29 
30  inline RangeSet
32  {
33  return RangeSet::forRun(rp.runID());
34  }
35 
36  inline RangeSet
38  {
39  return RangeSet::forSubRun(srp.subRunID());
40  }
41 
42  template <typename T, typename P>
43  std::enable_if_t<!detail::range_sets_supported(P::branch_type)>
44  put_product_in_principal(std::unique_ptr<T>&& product,
45  P& principal,
46  std::string const& module_label,
47  std::string const& instance_name = {})
48  {
49  TypeID const typeID{typeid(T)};
50  if (product.get() == nullptr) {
52  << "put_product_in_principal: A null unique_ptr was passed to 'put'.\n"
53  << "The pointer is of type " << typeID << ".\n"
54  << "The specified product instance name was '" << instance_name
55  << "'.\n";
56  }
57 
58  auto const& process_name = principal.processConfiguration().processName();
59  auto const& product_name = canonicalProductName(
60  typeID.friendlyClassName(), module_label, instance_name, process_name);
61  ProductID const pid{product_name};
62  auto desc = principal.getProductDescription(pid);
63  if (!desc) {
65  "put_product_in_principal: error while trying to "
66  "retrieve product description:\n")
67  << "No product is registered for\n"
68  << " process name: '" << process_name << "'\n"
69  << " module label: '" << module_label << "'\n"
70  << " product friendly class name: '" << typeID.friendlyClassName()
71  << "'\n"
72  << " product instance name: '" << instance_name << "'\n"
73  << " branch type: '" << principal.branchType()
74  << "'\n";
75  }
76 
77  std::unique_ptr<EDProduct> wp = std::make_unique<Wrapper<T>>(move(product));
78  principal.put(
79  *desc,
80  std::make_unique<ProductProvenance const>(pid, productstatus::present()),
81  move(wp),
82  std::make_unique<RangeSet>());
83  }
84 
85  template <typename T, typename P>
86  std::enable_if_t<detail::range_sets_supported(P::branch_type)>
87  put_product_in_principal(std::unique_ptr<T>&& product,
88  P& principal,
89  std::string const& module_label,
90  std::string const& instance_name = {},
92  {
93  TypeID const typeID{typeid(T)};
94  if (product.get() == nullptr) {
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
99  << "'.\n";
100  }
101 
102  auto const& process_name = principal.processConfiguration().processName();
103  auto const& product_name = canonicalProductName(
104  typeID.friendlyClassName(), module_label, instance_name, process_name);
105  ProductID const pid{product_name};
106  auto desc = principal.getProductDescription(pid);
107  if (!desc) {
109  "put_product_in_principal: error while trying to "
110  "retrieve product description:\n")
111  << "No product is registered for\n"
112  << " process name: '" << process_name << "'\n"
113  << " module label: '" << module_label << "'\n"
114  << " product friendly class name: '" << typeID.friendlyClassName()
115  << "'\n"
116  << " product instance name: '" << instance_name << "'\n"
117  << " branch type: '" << principal.branchType()
118  << "'\n";
119  }
120 
121  // If the provided RangeSet is invalid, assign it a RangeSet
122  // corresponding to the full (Sub)Run.
123  if (!rs.is_valid()) {
124  rs = rangeSetFor(principal);
125  }
126  std::unique_ptr<EDProduct> wp = std::make_unique<Wrapper<T>>(move(product));
127  principal.put(
128  *desc,
129  std::make_unique<ProductProvenance const>(pid, productstatus::present()),
130  move(wp),
131  std::make_unique<RangeSet>(rs));
132  }
133 
134 } // namespace art
135 
136 #endif /* art_Framework_IO_Sources_put_product_in_principal_h */
137 
138 // Local Variables:
139 // mode: c++
140 // End:
RunID const & runID() const
Definition: Principal.cc:1052
std::string string
Definition: nybbler.cc:12
std::pair< float, std::string > P
bool is_valid() const
Definition: RangeSet.cc:117
RangeSet rangeSetFor(RunPrincipal const &rp)
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
def move(depos, offset)
Definition: depos.py:107
SubRunID subRunID() const
Definition: Principal.cc:1058
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
static RangeSet invalid()
Definition: RangeSet.cc:45
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10