LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SourceHelper.cc
Go to the documentation of this file.
2 
10 
11 #include <utility>
12 
13 using namespace std;
14 
16 
17 void
19 {
20  if (!presentProducts_) {
21  throw Exception(
23  "Error while attempting to create principal from SourceHelper.\n")
24  << "Principals cannot be created until product registration is "
25  "complete.\n"
26  "This can happen if you are attempting to create a Principal\n"
27  "outside of your 'readNext' function, or if you are using a\n"
28  "different SourceHelper object than the one provided by art.\n"
29  "Please contact artists@fnal.gov for guidance.";
30  }
31 }
32 
35  ProcessHistoryID const& processHistoryID,
36  BranchType const bt,
37  ProcessConfiguration const& pc) const
38 {
39  // If no products are present for this branch type, we do not
40  // update the process history.
41  if (presentProducts_->descriptions(bt).empty()) {
42  return processHistoryID;
43  }
44 
45  art::ProcessHistory processHistory{};
46  if (processHistoryID.isValid()) {
47  bool const found =
48  ProcessHistoryRegistry::get(processHistoryID, processHistory);
49  if (!found) {
50  throw Exception(
52  "Error while attempting to create principal from SourceHelper.\n")
53  << "The provided process-history ID\n"
54  << " " << processHistory << '\n'
55  << "does not correspond to a known process history.\n"
56  "Please contact artists@fnal.gov for guidance.";
57  }
58  }
59  processHistory.push_back(pc);
60  auto const phid = processHistory.id();
61  art::ProcessHistoryRegistry::emplace(phid, processHistory);
62  return phid;
63 }
64 
65 void
67  cet::exempt_ptr<ProductTables const> presentProducts)
68 {
69  presentProducts_ = presentProducts;
70 }
71 
72 template <typename T>
73 T*
74 art::SourceHelper::makePrincipal_(typename T::Auxiliary aux) const
75 {
77  constexpr auto branch_type = T::branch_type;
78  aux.setProcessHistoryID(updatedProcessHistoryID_(
79  aux.processHistoryID(), branch_type, md_.processConfiguration()));
80  auto principal =
81  new T{aux, md_.processConfiguration(), &presentProducts_->get(branch_type)};
82  if (aux.processHistoryID().isValid()) {
83  principal->markProcessHistoryAsModified();
84  }
85  return principal;
86 }
87 
90 {
91  return makePrincipal_<RunPrincipal>(std::move(runAux));
92 }
93 
96  Timestamp const& startTime) const
97 {
98  return makeRunPrincipal(
100 }
101 
104  Timestamp const& startTime) const
105 {
106  return makeRunPrincipal(RunID{r}, startTime);
107 }
108 
111 {
112  return makePrincipal_<SubRunPrincipal>(std::move(subRunAux));
113 }
114 
117  Timestamp const& startTime) const
118 {
119  return makeSubRunPrincipal(
120  SubRunAuxiliary{sr, startTime, Timestamp::invalidTimestamp()});
121 }
122 
125  SubRunNumber_t const sr,
126  Timestamp const& startTime) const
127 {
128  return makeSubRunPrincipal(SubRunID{r, sr}, startTime);
129 }
130 
133 {
134  return makePrincipal_<EventPrincipal>(std::move(eventAux));
135 }
136 
139  EventID const& e,
140  Timestamp const& startTime,
141  bool const isRealData,
142  EventAuxiliary::ExperimentType const eType) const
143 {
144  return makeEventPrincipal(EventAuxiliary{e, startTime, isRealData, eType});
145 }
146 
149  RunNumber_t const r,
150  SubRunNumber_t const sr,
151  EventNumber_t const e,
152  Timestamp const& startTime,
153  bool const isRealData,
154  EventAuxiliary::ExperimentType const eType) const
155 {
156  return makeEventPrincipal(EventID{r, sr, e}, startTime, isRealData, eType);
157 }
TRandom r
Definition: spectrum.C:23
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary subRunAux) const
cet::exempt_ptr< ProductTables const > presentProducts_
Definition: SourceHelper.h:88
void setPresentProducts(cet::exempt_ptr< ProductTables const > presentProducts)
Definition: SourceHelper.cc:66
EventPrincipal * makeEventPrincipal(EventAuxiliary eventAux) const
STL namespace.
static collection_type const & get()
SourceHelper(ModuleDescription const &md)
Definition: SourceHelper.cc:15
ProcessHistoryID updatedProcessHistoryID_(ProcessHistoryID const &, BranchType, ProcessConfiguration const &) const
Definition: SourceHelper.cc:34
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
T * makePrincipal_(typename T::Auxiliary aux) const
Definition: SourceHelper.cc:74
bool isValid() const
Definition: Hash.h:122
ProcessConfiguration const & processConfiguration() const
void throwIfProductsNotRegistered_() const
Definition: SourceHelper.cc:18
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
RunPrincipal * makeRunPrincipal(RunAuxiliary runAux) const
Definition: SourceHelper.cc:89
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
ModuleDescription md_
Definition: SourceHelper.h:89
BranchType
Definition: BranchType.h:20
Float_t e
Definition: plot.C:35
static auto emplace(value_type const &value)
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120