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  ProcessConfiguration const& pc) const
36 {
37  art::ProcessHistory processHistory{};
38  // If no products are present for this branch type, we do not
39  // register the process history.
40  if (presentProducts_->descriptions(bt).empty()) {
41  return processHistory.id();
42  }
43 
44  processHistory.push_back(pc);
45  auto const phid = processHistory.id();
46  art::ProcessHistoryRegistry::emplace(phid, processHistory);
47  return phid;
48 }
49 
50 std::unique_ptr<art::History>
52  std::unique_ptr<History>&& history) const
53 {
54  // If no event products are present, we do not register the process
55  // history, and we return the already-provided history.
56  if (presentProducts_->descriptions(InEvent).empty()) {
57  return std::move(history);
58  }
59 
60  // To append to the processing history, we must first retrieve the
61  // ProcessHistory object corresponding to history's process history
62  // ID, if the ID is valid.
63  art::ProcessHistory processHistory;
64  auto const phid = history->processHistoryID();
65  if (phid.isValid()) {
66  bool const success = ProcessHistoryRegistry::get(phid, processHistory);
67  if (!success) {
68  throw Exception{
70  "Error while attempting to create event principal from SourceHelper.\n"}
71  << "There is no processing history corresponding to the valid id: "
72  << phid << '\n'
73  << "Please contact artists@fnal.gov for guidance.";
74  }
75  }
76 
77  processHistory.push_back(pc);
78  auto const new_phid = processHistory.id();
79  art::ProcessHistoryRegistry::emplace(new_phid, processHistory);
80  history->setProcessHistoryID(new_phid);
81  return std::move(history);
82 }
83 
84 void
87 {
88  presentProducts_ = presentProducts;
89 }
90 
93 {
95  runAux.processHistoryID() =
97  auto principal = new RunPrincipal{
99  if (runAux.processHistoryID().isValid()) {
100  principal->markProcessHistoryAsModified();
101  }
102  return principal;
103 }
104 
107  Timestamp const& startTime) const
108 {
109  RunAuxiliary const runAux{r, startTime, Timestamp::invalidTimestamp()};
110  return makeRunPrincipal(runAux);
111 }
112 
115  Timestamp const& startTime) const
116 {
117  return makeRunPrincipal(RunID{r}, startTime);
118 }
119 
122 {
125  subRunAux.setProcessHistoryID(phid);
126  auto principal = new SubRunPrincipal{
127  subRunAux, md_.processConfiguration(), &presentProducts_->get(InSubRun)};
128  if (subRunAux.processHistoryID().isValid()) {
129  principal->markProcessHistoryAsModified();
130  }
131  return principal;
132 }
133 
136  Timestamp const& startTime) const
137 {
138  SubRunAuxiliary const subRunAux{sr, startTime, Timestamp::invalidTimestamp()};
139  return makeSubRunPrincipal(subRunAux);
140 }
141 
144  SubRunNumber_t const sr,
145  Timestamp const& startTime) const
146 {
147  return makeSubRunPrincipal(SubRunID{r, sr}, startTime);
148 }
149 
152  std::unique_ptr<History>&& history) const
153 {
154  if (history.get() == nullptr) {
155  throw Exception{
157  "Error while attempting to create principal from SourceHelper.\n"}
158  << "The provided 'unique_ptr<History>' object is null, which is not "
159  "allowed\n"
160  "for this makeEventPrincipal function overload. Please choose a "
161  "different\n"
162  "function to use, or provided a non-null History unique pointer. "
163  "Contact\n"
164  "artists@fnal.gov for further guidance.";
165  }
167  auto new_history = history_(md_.processConfiguration(), std::move(history));
168  auto const processHistoryID = new_history->processHistoryID();
169  auto principal = new EventPrincipal{eventAux,
171  &presentProducts_->get(InEvent),
172  std::move(new_history)};
173  if (processHistoryID.isValid()) {
174  principal->markProcessHistoryAsModified();
175  }
176  return principal;
177 }
178 
181  EventID const& e,
182  Timestamp const& startTime,
183  bool const isRealData,
184  EventAuxiliary::ExperimentType const eType) const
185 {
186  EventAuxiliary const eventAux{e, startTime, isRealData, eType};
187  return makeEventPrincipal(eventAux, std::make_unique<History>());
188 }
189 
192  RunNumber_t const r,
193  SubRunNumber_t const sr,
194  EventNumber_t const e,
195  Timestamp const& startTime,
196  bool const isRealData,
197  EventAuxiliary::ExperimentType const eType) const
198 {
199  return makeEventPrincipal(EventID{r, sr, e}, startTime, isRealData, eType);
200 }
std::unique_ptr< History > history_(ProcessConfiguration const &, std::unique_ptr< History > &&) const
Definition: SourceHelper.cc:51
cet::exempt_ptr< ProductTables const > presentProducts_
Definition: SourceHelper.h:94
void setPresentProducts(cet::exempt_ptr< ProductTables const > presentProducts)
Definition: SourceHelper.cc:85
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary const &subRunAux) const
STL namespace.
void setProcessHistoryID(ProcessHistoryID const &phid) const
RunPrincipal * makeRunPrincipal(RunAuxiliary const &runAux) const
Definition: SourceHelper.cc:92
ProcessHistoryID id() const
const double e
static collection_type const & get()
bt
Definition: tracks.py:83
SourceHelper(ModuleDescription const &md)
Definition: SourceHelper.cc:15
def move(depos, offset)
Definition: depos.py:107
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
bool isValid() const
Definition: Hash.h:123
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
ProcessHistoryID & processHistoryID() const noexcept
Definition: RunAuxiliary.cc:67
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
ModuleDescription md_
Definition: SourceHelper.h:95
BranchType
Definition: BranchType.h:20
ProcessHistoryID const & processHistoryID() const noexcept
EventPrincipal * makeEventPrincipal(EventAuxiliary const &eventAux, std::unique_ptr< History > &&history) const
static constexpr double sr
Definition: Units.h:166
void push_back(const_reference t)
static auto emplace(value_type const &value)
ProcessHistoryID processHistoryID_(BranchType, ProcessConfiguration const &) const
Definition: SourceHelper.cc:34
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120