LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DetectorClocksStandardTriggerLoader.h
Go to the documentation of this file.
1 
22 #ifndef LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
23 #define LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
24 
25 // LArSoft libraries
27 #include "lardataobj/RawData/TriggerData.h" // raw::Trigger
28 
29 // framework libraries
31 #include "cetlib_except/exception.h"
32 
33 // C++ standard libraries
34 #include <vector>
35 
36 
37 namespace detinfo {
38 
49  { detClocks.SetTriggerTime(trigger.TriggerTime(), trigger.BeamGateTime()); }
50 
51 
71  template <typename Event>
73  (detinfo::DetectorClocksStandard& detClocks, Event const& event)
74  {
75  //
76  // fetch the trigger data product
77  //
78  using TriggerHandle_t
79  = typename Event::template HandleT<std::vector<raw::Trigger>>;
80 
81  art::InputTag const triggerTag = detClocks.TrigModuleName();
82  TriggerHandle_t triggerHandle;
83  if (!event.template getByLabel(triggerTag, triggerHandle)) return false;
84 
85  //
86  // check that we do have a trigger
87  // (we have already checked whether the handle is valid above)
88  //
89 
90  auto const& triggers = *triggerHandle;
91  if (triggers.empty()) return false;
92 
93  //
94  // select which trigger to set (i.e., the only one!)
95  //
96  if (triggers.size() != 1) {
97  throw cet::exception("setDetectorClocksStandardTrigger")
98  << "Found " << triggers.size()
99  << " trigger objects in '" << triggerTag.encode()
100  << "' (only one trigger per event is supported)\n";
101  }
102 
103  //
104  // set the timings from the first and only trigger into the service
105  //
107  (detClocks, triggers.front());
108 
109  // all done
110  return true;
111 
112  } // setDetectorClocksStandardTriggersFromEvent()
113 
114 
133  template <typename Event>
135  (detinfo::DetectorClocksStandard& detClocks, Event const& event)
136  {
137  //
138  // try to read the trigger from the event
139  //
140  if (setDetectorClocksStandardTriggersFromEvent(detClocks, event))
141  return true;
142 
143  //
144  // if there was no trigger candidate, set it default
145  //
146  detClocks.SetDefaultTriggerTime();
147  return false;
148 
149  } // setDetectorClocksStandardTrigger
150 
151 } // namespace detinfo
152 
153 
154 #endif // LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
bool setDetectorClocksStandardTrigger(detinfo::DetectorClocksStandard &detClocks, Event const &event)
Loads DetectorClocksStandard trigger times.
void setDetectorClocksStandardTriggersFromRawTrigger(detinfo::DetectorClocksStandard &detClocks, raw::Trigger const &trigger)
Loads DetectorClocksStandard trigger times from a raw::Trigger.
std::string TrigModuleName() const
Returns the input tag of the trigger data product.
virtual void SetTriggerTime(double trig_time, double beam_time)
Setter for trigger times.
double TriggerTime() const
Trigger time w.r.t. electronics clock T0 in us.
Definition: TriggerData.h:51
std::string encode() const
Definition: InputTag.cc:36
double BeamGateTime() const
BeamGate time w.r.t. electronics clock T0 in us.
Definition: TriggerData.h:53
General LArSoft Utilities.
void SetDefaultTriggerTime()
Sets trigger and beam gate time from default configuration values.
bool setDetectorClocksStandardTriggersFromEvent(detinfo::DetectorClocksStandard &detClocks, Event const &event)
Loads DetectorClocksStandard trigger times from a raw::Trigger.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.