All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtraTriggerInfo.cxx
Go to the documentation of this file.
1 /**
2  * @file sbnobj/Common/Trigger/ExtraTriggerInfo.cxx
3  * @brief Data product holding additional trigger information.
4  * @authors Gianluca Petrillo (petrillo@slac.stanford.edu),
5  * Jacob Zettlemoyer (jzettle@fnal.gov>)
6  * @date June 18, 2021
7  * @see sbnobj/Common/Trigger/ExtraTriggerInfo.h
8  */
9 
11 
12 // C/C++ standard library
13 #include <ostream>
14 #include <iomanip> // std::setfill(), std::setw()
15 
16 
17 // -----------------------------------------------------------------------------
18 namespace {
19 
20  // ---------------------------------------------------------------------------
21  template <typename T = std::uint64_t>
22  struct TimestampDumper { T timestamp; };
23 
24  template <typename T>
25  TimestampDumper<T> dumpTimestamp(T timestamp)
26  { return { timestamp }; }
27 
28  template <typename T>
29  std::ostream& operator<< (std::ostream& out, TimestampDumper<T> wrapper) {
30  T const timestamp = wrapper.timestamp;
32  out << (timestamp / 1'000'000'000) << "."
33  << std::setfill('0') << std::setw(9) << (timestamp % 1'000'000'000)
34  << " s";
35  }
36  else out << "<n/a>";
37  return out;
38  } // operator<< (TimestampDumper)
39 
40 
41  // ---------------------------------------------------------------------------
42  struct TriggerIDdumper { unsigned int ID; };
43 
44  TriggerIDdumper dumpTriggerID(unsigned int ID) { return { ID }; }
45 
46  std::ostream& operator<< (std::ostream& out, TriggerIDdumper wrapper) {
47  unsigned int const ID = wrapper.ID;
48  if (sbn::ExtraTriggerInfo::isValidID(ID)) out << ID;
49  else out << "<n/a>";
50  return out;
51  } // operator<< (TriggerIDdumper)
52 
53 
54  // ---------------------------------------------------------------------------
55  struct TriggerCountDumper { unsigned int count; };
56 
57  TriggerCountDumper dumpTriggerCount(unsigned int count) { return { count }; }
58 
59  std::ostream& operator<< (std::ostream& out, TriggerCountDumper wrapper) {
60  unsigned int const count = wrapper.count;
61  if (sbn::ExtraTriggerInfo::isValidCount(count)) out << count;
62  else out << "<n/a>";
63  return out;
64  } // operator<< (TriggerCountDumper)
65 
66 
67  // ---------------------------------------------------------------------------
68  long long int timestampDiff(std::uint64_t timestamp, std::uint64_t ref) {
69  return static_cast<long long int>
70  ((timestamp > ref)? (timestamp - ref): (ref - timestamp));
71  }
72 
73 
74  // ---------------------------------------------------------------------------
75 
76  struct LVDSmaskDumper { std::uint64_t bits; };
77 
78  LVDSmaskDumper dumpLVDSmask(std::uint64_t bits) { return { bits }; }
79 
80  std::ostream& operator<< (std::ostream& out, LVDSmaskDumper wrapper) {
81  std::uint64_t const bits { wrapper.bits };
82 
83  auto dumpBoard = [&out](std::uint8_t bits)
84  {
85  static constexpr char symbols[2] = { '-', 'x' };
86  std::uint8_t mask = 0x80;
87  do { out << symbols[(bits & mask)? 1: 0]; } while (mask >>= 1);
88  };
89  auto boardBits = [](std::uint64_t bits, short int board) -> std::uint8_t
90  { return static_cast<std::uint8_t>((bits >> (board * 8)) & 0xFF); };
91 
92  // positions 3 and 7 are empty
93  dumpBoard(boardBits(bits, 6));
94  out << ' ';
95  dumpBoard(boardBits(bits, 5));
96  out << ' ';
97  dumpBoard(boardBits(bits, 4));
98  out << ' ';
99  out << ' ';
100  dumpBoard(boardBits(bits, 2));
101  out << ' ';
102  dumpBoard(boardBits(bits, 1));
103  out << ' ';
104  dumpBoard(boardBits(bits, 0));
105 
106  return out;
107  } // operator<< (LVDSmaskDumper)
108 
109 
110 } // local namespace
111 
112 
113 // -----------------------------------------------------------------------------
114 std::ostream& sbn::operator<< (std::ostream& out, ExtraTriggerInfo const& info)
115 {
116  if (!info.isValid()) {
117  out << "<invalid>";
118  return out;
119  }
120 
121  // quite a load:
122  out
123  << "trigger ID=" << dumpTriggerID(info.triggerID)
124  << " (type " << name(info.triggerType) << ")"
125  << " from source " << name(info.sourceType)
126  << " at " << dumpTimestamp(info.triggerTimestamp)
127  << " on beam gate ID=" << dumpTriggerID(info.gateID)
128  << " at " << dumpTimestamp(info.beamGateTimestamp)
129  << " (diff: "
130  << timestampDiff(info.beamGateTimestamp, info.triggerTimestamp) << " ns)"
131  << "\n"
132  << "enable gate opened at " << dumpTimestamp(info.enableGateTimestamp)
133  << " (" << timestampDiff(info.beamGateTimestamp, info.enableGateTimestamp)
134  << " ns before the gate)"
135  << "\n"
136  << "counts from this source: trigger="
137  << dumpTriggerCount(info.triggerCount)
138  << " beam=" << dumpTriggerCount(info.gateCount)
139  << "\n"
140  << "previous trigger from this source at "
141  << dumpTimestamp(info.previousTriggerTimestamp)
142  << ", triggers since: "
143  << dumpTriggerCount(info.anyTriggerCountFromPreviousTrigger)
144  << ", gates since: "
145  << dumpTriggerCount(info.anyGateCountFromPreviousTrigger)
146  << " ("
147  << dumpTriggerCount(info.gateCountFromPreviousTrigger)
148  << " from this same source)"
149  << "\n"
150  << "most recent trigger was from source "
151  << name(info.anyPreviousTriggerSourceType) << " at "
152  << dumpTimestamp(info.anyPreviousTriggerTimestamp)
153  ;
156  {
157  out
158  << " ("
159  << dumpTimestamp(info.triggerTimestamp - info.anyPreviousTriggerTimestamp)
160  << " earlier)";
161  }
162  out
163  << ", and "
164  << dumpTriggerCount(info.anyGateCountFromAnyPreviousTrigger)
165  << " gates from any source have opened since"
166  ;
167  if (info.WRtimeToTriggerTime != ExtraTriggerInfo::UnknownCorrection) {
168  out << "\nCorrection applied to the timestamps: "
169  << dumpTimestamp(info.WRtimeToTriggerTime);
170  }
171  if (info.triggerLocationBits != 0) {
172  out << "\nLocation(s) of trigger:";
173  for (std::string const& bitName: names(info.triggerLocation()))
174  out << " " << bitName;
175  }
176  out << "\nWest cryostat: "
177  << info.cryostats[ExtraTriggerInfo::WestCryostat].triggerCount
178  << " triggers";
179  if (auto const& cryo = info.cryostats[ExtraTriggerInfo::WestCryostat];
180  cryo.hasLVDS()
181  ) {
182  out
183  << "\n west wall: "
184  << dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
185  << "\n east wall: "
186  << dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::EastPMTwall])
187  ;
188  }
189 
190  out << "\nEast cryostat: "
191  << info.cryostats[ExtraTriggerInfo::EastCryostat].triggerCount
192  << " triggers";
193  if (auto const& cryo = info.cryostats[ExtraTriggerInfo::EastCryostat];
194  cryo.hasLVDS()
195  ) {
196  out
197  << "\n west wall: "
198  << dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
199  << "\n east wall: "
200  << dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::EastPMTwall])
201  ;
202  }
203 
204 
205  return out;
206 } // sbn::operator<< (ExtraTriggerInfo)
207 
208 
209 // -----------------------------------------------------------------------------
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common symbols
unsigned int gateID
Incremental counter of gates from any source opened from start of the run.
unsigned int anyTriggerCountFromPreviousTrigger
std::ostream & operator<<(std::ostream &out, sbn::PMTconfiguration const &config)
Prints the configuration into a stream with default verbosity.
unsigned int gateCount
Incremental counter of gates from this source opened from start of the run.
sbn::bits::triggerLocationMask triggerLocation() const
Returns the location of the trigger.
static constexpr bool isValidID(unsigned int ID) noexcept
Returns whether the specified ID is valid (i.e. is not NoID).
std::string bitName(triggerSource bit)
Returns a mnemonic short name of the beam type.
Definition: BeamBits.h:267
std::uint64_t beamGateTimestamp
Absolute timestamp of the opening of this beam gate [ns].
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
Additional information on trigger.
sbn::triggerSource anyPreviousTriggerSourceType
Type of the previous trigger.
unsigned int triggerCount
Incremental counter of triggers from this source from start of the run.
unsigned int triggerLocationBits
Bits for the trigger location (.
std::array< CryostatInfo, MaxCryostats > cryostats
Status of each LVDS channel in each PMT wall at trigger time.
std::uint64_t enableGateTimestamp
Absolute timestamp of the opening of the enable gate [ns].
sbn::triggerSource sourceType
Type of this gate (sbn::triggerSource::NBits marks this object invalid).
unsigned int anyGateCountFromPreviousTrigger
constexpr bool isValid() const noexcept
Returns whether this object contains any valid information.
static const std::vector< std::string > names
sbn::triggerType triggerType
Type of this trigger (see sbn::triggerType).
static constexpr bool isValidTimestamp(std::uint64_t ts) noexcept
Returns whether the timestamp ts is valid (i.e. is not NoTimestamp).
std::uint64_t anyPreviousTriggerTimestamp
Absolute timestamp of the previous trigger from any source [ns].
unsigned int anyGateCountFromAnyPreviousTrigger
then echo fcl name
Data product holding additional trigger information.
unsigned int gateCountFromPreviousTrigger
std::size_t count(Cont const &cont)
std::uint64_t previousTriggerTimestamp
Absolute timestamp of the previous trigger from this same source [ns].
std::uint64_t triggerTimestamp
Absolute timestamp of this trigger [ns].
unsigned int triggerID
The identifier of this trigger (usually matching the event number).
static constexpr bool isValidCount(unsigned int count) noexcept
Returns whether the count is valid (i.e. is not 0).
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
Definition: CheatTrack.h:153
std::int64_t WRtimeToTriggerTime
Correction added to the White Rabbit time to get the trigger time.