Skip to content

Commit ee7b2a0

Browse files
authored
Merge pull request #96 from PetrilloAtWork/feature/gp_adderTrigger
Additions to sbn::ExtraTriggerInfo data product to store ICARUS adder information
2 parents a3411b6 + 988e319 commit ee7b2a0

11 files changed

Lines changed: 169 additions & 52 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ cet_cmake_env()
2828
cet_set_compiler_flags(DIAGS CAUTIOUS
2929
WERROR
3030
NO_UNDEFINED
31-
EXTRA_FLAGS -pedantic
32-
EXTRA_CXX_FLAGS -Wno-unused-local-typedefs
31+
EXTRA_FLAGS -pedantic -Wno-unused-local-typedefs
3332
)
3433

3534
cet_report_compiler_flags(REPORT_THRESHOLD VERBOSE)

sbnobj/Common/Reco/classes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@
2929
#include "sbnobj/Common/Reco/CNNScore.h"
3030
#include "sbnobj/Common/Reco/TPCPMTBarycenterMatch.h"
3131

32-
3332
#include <utility>
3433
#include <vector>

sbnobj/Common/Trigger/ExtraTriggerInfo.cxx

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
// -----------------------------------------------------------------------------
1818
namespace {
1919

20+
// ---------------------------------------------------------------------------
21+
template <typename Stream, char CharOn = 'x', char CharOff = '-'>
22+
class ByteDumper {
23+
static constexpr char symbols[2] = { CharOff, CharOn };
24+
25+
Stream& out;
26+
27+
public:
28+
ByteDumper(Stream& out): out{ out } {}
29+
30+
void operator() (std::uint8_t bits, std::size_t nBits = 8) const
31+
{
32+
std::uint8_t mask = 1 << (nBits - 1); // default: 0x80
33+
do { out << symbols[(bits & mask)? 1: 0]; } while (mask >>= 1);
34+
}
35+
36+
}; // ByteDumper
37+
38+
2039
// ---------------------------------------------------------------------------
2140
template <typename T = std::uint64_t>
2241
struct TimestampDumper { T timestamp; };
@@ -71,6 +90,31 @@ namespace {
7190
}
7291

7392

93+
// ---------------------------------------------------------------------------
94+
template <typename T>
95+
struct BitDumper { T bits; unsigned int n; };
96+
97+
template <typename T>
98+
BitDumper<T> dumpBits
99+
(T bits, unsigned int n = sizeof(T) * 8) { return { bits, n }; }
100+
101+
template <typename T>
102+
std::ostream& operator<< (std::ostream& out, BitDumper<T> wrapper) {
103+
static auto const bitMask = [](unsigned int n)
104+
{ return (n == sizeof(T)*8)? ~T{0}: T((1 << n) - 1); };
105+
106+
ByteDumper const dumpByte{ out };
107+
unsigned int bitsLeft = wrapper.n;
108+
while (bitsLeft > 0) { // goes 8 by 8 (fewer on the first iteration)
109+
unsigned int const maskBits = (bitsLeft - 1) % 8 + 1;
110+
bitsLeft -= maskBits;
111+
dumpByte((wrapper.bits >> bitsLeft) & bitMask(maskBits), maskBits);
112+
} // while
113+
114+
return out;
115+
} // operator<< (LVDSmaskDumper)
116+
117+
74118
// ---------------------------------------------------------------------------
75119

76120
struct LVDSmaskDumper { std::uint64_t bits; };
@@ -80,32 +124,22 @@ namespace {
80124
std::ostream& operator<< (std::ostream& out, LVDSmaskDumper wrapper) {
81125
std::uint64_t const bits { wrapper.bits };
82126

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-
};
89127
auto boardBits = [](std::uint64_t bits, short int board) -> std::uint8_t
90128
{ return static_cast<std::uint8_t>((bits >> (board * 8)) & 0xFF); };
91129

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));
130+
// positions 3 and 7 are empty
131+
out
132+
<< dumpBits(boardBits(bits, 6)) << ' '
133+
<< dumpBits(boardBits(bits, 5)) << ' '
134+
<< dumpBits(boardBits(bits, 4)) << ' '
135+
<< ' '
136+
<< dumpBits(boardBits(bits, 2)) << ' '
137+
<< dumpBits(boardBits(bits, 1)) << ' '
138+
<< dumpBits(boardBits(bits, 0))
139+
;
105140

106141
return out;
107-
} // operator<< (LVDSmaskDumper)
108-
142+
} // operator<< (LVDSmaskDumper)
109143

110144
} // local namespace
111145

@@ -173,34 +207,41 @@ std::ostream& sbn::operator<< (std::ostream& out, ExtraTriggerInfo const& info)
173207
for (std::string const& bitName: names(info.triggerLocation()))
174208
out << " " << bitName;
175209
}
176-
out << "\nWest cryostat: "
177-
<< info.cryostats[ExtraTriggerInfo::WestCryostat].triggerCount
210+
out << "\nEast cryostat: "
211+
<< info.cryostats[ExtraTriggerInfo::EastCryostat].triggerCount
178212
<< " triggers";
179-
if (auto const& cryo = info.cryostats[ExtraTriggerInfo::WestCryostat];
213+
if (auto const& cryo = info.cryostats[ExtraTriggerInfo::EastCryostat];
180214
cryo.hasLVDS()
181215
) {
182216
out
183-
<< "\n west wall: "
184-
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
185217
<< "\n east wall: "
186218
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::EastPMTwall])
219+
<< ", sectors: "
220+
<< dumpBits(cryo.SectorStatus[ExtraTriggerInfo::EastPMTwall], 6)
221+
<< "\n west wall: "
222+
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
223+
<< ", sectors: "
224+
<< dumpBits(cryo.SectorStatus[ExtraTriggerInfo::WestPMTwall], 6)
187225
;
188226
}
189227

190-
out << "\nEast cryostat: "
191-
<< info.cryostats[ExtraTriggerInfo::EastCryostat].triggerCount
228+
out << "\nWest cryostat: "
229+
<< info.cryostats[ExtraTriggerInfo::WestCryostat].triggerCount
192230
<< " triggers";
193-
if (auto const& cryo = info.cryostats[ExtraTriggerInfo::EastCryostat];
231+
if (auto const& cryo = info.cryostats[ExtraTriggerInfo::WestCryostat];
194232
cryo.hasLVDS()
195233
) {
196234
out
197-
<< "\n west wall: "
198-
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
199235
<< "\n east wall: "
200236
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::EastPMTwall])
237+
<< ", sectors: "
238+
<< dumpBits(cryo.SectorStatus[ExtraTriggerInfo::EastPMTwall], 6)
239+
<< "\n west wall: "
240+
<< dumpLVDSmask(cryo.LVDSstatus[ExtraTriggerInfo::WestPMTwall])
241+
<< ", sectors: "
242+
<< dumpBits(cryo.SectorStatus[ExtraTriggerInfo::WestPMTwall], 6)
201243
;
202244
}
203-
204245

205246
return out;
206247
} // sbn::operator<< (ExtraTriggerInfo)

sbnobj/Common/Trigger/ExtraTriggerInfo.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,26 @@ struct sbn::ExtraTriggerInfo {
220220
*/
221221
std::array<std::uint64_t, MaxWalls> LVDSstatus { 0U, 0U };
222222

223+
/**
224+
* @brief Light level of detector blocks/slices.
225+
*
226+
* There is one status per PMT wall (index mnemonic constants: `EastPMTwall`
227+
* and `WestPMTwall`).
228+
*
229+
*
230+
* ICARUS
231+
* -------
232+
*
233+
* Analog adder boards serving 15 contiguous channels are discriminated,
234+
* and their status at trigger time is reflected here.
235+
*
236+
* Each entry describes a PMT wall, that is 6 bits, starting from the most
237+
* upstream (south) as the least significant bit.
238+
*
239+
* The remaining 10 bits are reserved for future use.
240+
*/
241+
std::array<std::uint16_t, MaxWalls> SectorStatus { 0U, 0U };
242+
223243
/// Returns whether there is some recorded LVDS activity.
224244
constexpr bool hasLVDS() const;
225245

@@ -248,6 +268,22 @@ struct sbn::ExtraTriggerInfo {
248268
{ return { triggerLocationBits }; }
249269

250270

271+
// the following methods are meant to ease cryostat information in Python.
272+
/// Returns information about the specified `cryostat` (e.g. `EastCryostat`).
273+
/// @throws std::out_of_range if invalid `cryostat`
274+
CryostatInfo const& cryostatInfo(std::size_t cryostat) const
275+
{ return cryostats.at(cryostat); }
276+
277+
/// Returns LVDS states on a PMT `wall` of the specified `cryostat`.
278+
/// @throws std::out_of_range if invalid `cryostat` or `wall`
279+
std::uint64_t LVDSinfo(std::size_t cryostat, std::size_t wall) const
280+
{ return cryostatInfo(cryostat).LVDSstatus.at(wall); }
281+
282+
/// Returns sector states on a PMT `wall` of the specified `cryostat`.
283+
/// @throws std::out_of_range if invalid `cryostat` or `wall`
284+
std::uint16_t SectorInfo(std::size_t cryostat, std::size_t wall) const
285+
{ return cryostatInfo(cryostat).SectorStatus.at(wall); }
286+
251287
/// @}
252288
// --- END ---- Trigger topology ---------------------------------------------
253289

sbnobj/Common/Trigger/classes_def.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<enum name="sbn::bits::triggerSource" ClassVersion="10" />
2828
<enum name="sbn::bits::triggerLocation" ClassVersion="10" />
2929
<enum name="sbn::bits::triggerType" ClassVersion="10" />
30-
<class name="sbn::ExtraTriggerInfo::CryostatInfo" ClassVersion="10" >
30+
<class name="sbn::ExtraTriggerInfo::CryostatInfo" ClassVersion="11" >
31+
<version ClassVersion="11" checksum="3455337645"/>
3132
<version ClassVersion="10" checksum="313789291"/>
3233
</class>
3334

sbnobj/ICARUS/PMT/Trigger/Data/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
cet_make(
22
LIBRARIES
3+
lardataalg::UtilitiesHeaders
34
lardataobj::RawData
45
larcorealg::CoreUtils
5-
lardataalg::DetectorInfo
66
cetlib_except::cetlib_except
77
NO_DICTIONARY
88
)

sbnobj/ICARUS/PMT/Trigger/Data/OpticalTriggerGate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "sbnobj/ICARUS/PMT/Trigger/Data/ReadoutTriggerGate.h"
1616

1717
// LArSoft libraries
18-
#include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // detinfo::timescales
1918
#include "lardataalg/Utilities/quantities/electronics.h" // tick
2019
#include "lardataobj/RawData/OpDetWaveform.h"
2120

@@ -40,7 +39,6 @@ namespace icarus::trigger {
4039
/// Type of trigger gate data serialized into _art_ data products.
4140
using OpticalTriggerGateData_t = icarus::trigger::ReadoutTriggerGate
4241
<TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t>
43-
// <detinfo::timescales::optical_tick, detinfo::timescales::optical_time_ticks, raw::Channel_t>
4442
;
4543

4644
} // namespace icarus::trigger

sbnobj/ICARUS/PMT/Trigger/Data/ReadoutTriggerGate.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,24 @@ template <typename Tick, typename TickInterval, typename ChannelIDType>
198198
*/
199199
ChannelID_t channel() const;
200200

201-
202201
/// Associates the specified channel to this readout gate.
203202
This_t& addChannel(ChannelID_t const channel);
204203

205204
/// Associates the specified channels to this readout gate.
206205
This_t& addChannels(std::initializer_list<ChannelID_t> channels)
207206
{ associateChannels(channels); return *this; }
208207

208+
/// Removes the specified channel from this readout gate.
209+
/// Nothing happens if not present.
210+
This_t& removeChannel(ChannelID_t const channel);
211+
212+
/// Removes the specified channels from this readout gate.
213+
/// Nothing happens for the channels that are not present.
214+
This_t& removeChannels(std::initializer_list<ChannelID_t> channels);
215+
216+
/// Removes all channel numbers from this gate.
217+
This_t& resetChannels();
218+
209219
// --- END Access to channel information -------------------------------------
210220

211221

sbnobj/ICARUS/PMT/Trigger/Data/ReadoutTriggerGate.tcc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ auto icarus::trigger::ReadoutTriggerGate<Tick, TickInterval, ChannelIDType>::add
7676
} // icarus::trigger::ReadoutTriggerGate<>::addChannel()
7777

7878

79+
//------------------------------------------------------------------------------
80+
template <typename Tick, typename TickInterval, typename ChannelIDType>
81+
auto icarus::trigger::ReadoutTriggerGate<Tick, TickInterval, ChannelIDType>::removeChannel
82+
(ChannelID_t const channel) -> This_t&
83+
{
84+
auto const iNearest
85+
= std::lower_bound(fChannels.begin(), fChannels.end(), channel);
86+
if ((iNearest != fChannels.end()) && (*iNearest == channel))
87+
fChannels.erase(iNearest);
88+
return *this;
89+
} // icarus::trigger::ReadoutTriggerGate<>::removeChannel()
90+
91+
92+
//------------------------------------------------------------------------------
93+
template <typename Tick, typename TickInterval, typename ChannelIDType>
94+
auto icarus::trigger::ReadoutTriggerGate<Tick, TickInterval, ChannelIDType>::removeChannels
95+
(std::initializer_list<ChannelID_t> channels) -> This_t&
96+
{
97+
// we don't require `channels` to be sorted, so we need to look yo every time.
98+
for (ChannelID_t const channel: channels) removeChannel(channel);
99+
return *this;
100+
} // icarus::trigger::ReadoutTriggerGate<>::removeChannels()
101+
102+
103+
//------------------------------------------------------------------------------
104+
template <typename Tick, typename TickInterval, typename ChannelIDType>
105+
auto icarus::trigger::ReadoutTriggerGate<Tick, TickInterval, ChannelIDType>::resetChannels
106+
() -> This_t&
107+
{
108+
fChannels.clear();
109+
return *this;
110+
} // icarus::trigger::ReadoutTriggerGate<>::resetChannels()
111+
112+
79113
//------------------------------------------------------------------------------
80114
template <typename Tick, typename TickInterval, typename ChannelIDType>
81115
void

sbnobj/ICARUS/PMT/Trigger/Data/TriggerGateData.tcc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#ifndef SBNOBJ_ICARUS_PMT_TRIGGER_DATA_TRIGGERGATEDATA_TCC
1010
#define SBNOBJ_ICARUS_PMT_TRIGGER_DATA_TRIGGERGATEDATA_TCC
1111

12-
// LArSoft libraries
13-
#include "larcorealg/CoreUtils/StdUtils.h" // util::to_string()
14-
1512
// C/C++ standard libraries
1613
#include <ostream>
1714
#include <stdexcept> // std::runtime_error
@@ -269,17 +266,18 @@ void icarus::trigger::TriggerGateData<TK, TI>::openBetween
269266
// (4) update all the following stati;
270267
// the "Shift" action stops when a set happens, and stacks with other shifts
271268
//
269+
using std::to_string;
272270
while (++iStatus != send) {
273271
switch (iStatus->event) {
274272
case EventType::Shift: // change the resulting opening
275273
if ((count < 0) && (iStatus->opening < OpeningCount_t(-count))) {
276274
throw std::runtime_error(
277275
"icarus::trigger::TriggerGateData::openBetween(): "
278-
"asked to close " + util::to_string(-count)
276+
"asked to close " + to_string(-count)
279277
+ " gate counts starting at "
280-
+ util::to_string(start) + " but at time "
281-
+ util::to_string(iStatus->tick) + " only "
282-
+ util::to_string(iStatus->opening) + " are still open"
278+
+ to_string(start) + " but at time "
279+
+ to_string(iStatus->tick) + " only "
280+
+ to_string(iStatus->opening) + " are still open"
283281
);
284282
}
285283
iStatus->opening += count;
@@ -639,10 +637,11 @@ auto icarus::trigger::TriggerGateData<TK, TI>::findLastStatusForTickOrThrow
639637
auto const iStatus = findLastStatusFor(tick); // status may be before the tick
640638
if (iStatus) return iStatus.value();
641639
// this should be not even possible
640+
using std::to_string;
642641
throw std::runtime_error(
643-
"icarus::trigger::TriggerGateData: requested time " + util::to_string(tick)
642+
"icarus::trigger::TriggerGateData: requested time " + to_string(tick)
644643
+ " is before the gate channel was created (at "
645-
+ util::to_string(fGateLevel.front().tick)
644+
+ to_string(fGateLevel.front().tick)
646645
+ ")"
647646
);
648647
} // icarus::trigger::TriggerGateData<>::findLastStatusForTickOrThrow()
@@ -656,10 +655,11 @@ auto icarus::trigger::TriggerGateData<TK, TI>::findLastStatusForTickOrThrow
656655
auto const iStatus = findLastStatusFor(tick); // status may be before the tick
657656
if (iStatus) return iStatus.value();
658657
// this should be not even possible
658+
using std::to_string;
659659
throw std::runtime_error(
660-
"icarus::trigger::TriggerGateData: requested time " + util::to_string(tick)
660+
"icarus::trigger::TriggerGateData: requested time " + to_string(tick)
661661
+ " is before the gate channel was created (at "
662-
+ util::to_string(fGateLevel.front().tick)
662+
+ to_string(fGateLevel.front().tick)
663663
+ ")"
664664
);
665665
} // icarus::trigger::TriggerGateData<>::findLastStatusForTickOrThrow() const

0 commit comments

Comments
 (0)