LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DetectorClocksStandardTriggerLoader.h
Go to the documentation of this file.
1 
22 #ifndef LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
23 #define LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
24 
25 // LArSoft libraries
26 #include "lardataobj/RawData/TriggerData.h" // raw::Trigger
27 
28 // framework libraries
30 #include "cetlib_except/exception.h"
31 
32 // C++ standard libraries
33 #include <optional>
34 #include <vector>
35 
36 namespace detinfo {
37 
56  template <typename Event>
57  std::optional<std::pair<double, double>> trigger_times_for_event(art::InputTag const& triggerTag,
58  Event const& event)
59  {
60  // try to read the trigger from the event
61  // fetch the trigger data product
62  using TriggerHandle_t = typename Event::template HandleT<std::vector<raw::Trigger>>;
63 
64  TriggerHandle_t triggerHandle;
65  if (!event.template getByLabel(triggerTag, triggerHandle)) { return std::nullopt; }
66 
67  // check that we do have a trigger
68  // (we have already checked whether the handle is valid above)
69  auto const& triggers = *triggerHandle;
70  if (triggers.empty()) { return std::nullopt; }
71 
72  // select which trigger to set (i.e., the only one!)
73  if (triggers.size() != 1) {
74  throw cet::exception("setDetectorClocksStandardTrigger")
75  << "Found " << triggers.size() << " trigger objects in '" << triggerTag.encode()
76  << "' (only one trigger per event is supported)\n";
77  }
78 
79  auto const& trigger = triggers.front();
80  return std::make_optional(std::make_pair(trigger.TriggerTime(), trigger.BeamGateTime()));
81  }
82 
103  template <typename Event>
104  std::optional<double> g4ref_time_for_event(art::InputTag const& triggerTag, Event const& event)
105  {
106  // fetch the trigger data product
107  using TriggerHandle_t = typename Event::template HandleT<std::vector<raw::Trigger>>;
108 
109  TriggerHandle_t triggerHandle;
110  if (!event.template getByLabel(triggerTag, triggerHandle)) return std::nullopt;
111 
112  // check that we do have a trigger
113  // (we have already checked whether the handle is valid above)
114  auto const& triggers = *triggerHandle;
115  if (triggers.empty()) return std::nullopt;
116 
117  // select which trigger to set (i.e., the only one!)
118  if (triggers.size() != 1) {
119  throw cet::exception("setDetectorClocksStandardTrigger")
120  << "Found " << triggers.size() << " trigger objects in '" << triggerTag.encode()
121  << "' (only one trigger per event is supported)\n";
122  }
123 
124  return std::make_optional(triggers.front().TriggerTime());
125  }
126 
127 } // namespace detinfo
128 
129 #endif // LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
std::optional< double > g4ref_time_for_event(art::InputTag const &triggerTag, Event const &event)
Loads DetectorClocksStandard G4Ref correction times.
std::string encode() const
Definition: InputTag.cc:97
General LArSoft Utilities.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::optional< std::pair< double, double > > trigger_times_for_event(art::InputTag const &triggerTag, Event const &event)
Loads DetectorClocksStandard trigger times.
Event finding and building.