15 #ifndef SBNOBJ_ICARUS_PMT_TRIGGER_DATA_TRIGGERGATEDATA_H
16 #define SBNOBJ_ICARUS_PMT_TRIGGER_DATA_TRIGGERGATEDATA_H
24 #include <type_traits>
28 namespace icarus::trigger {
42 <
typename ClockTick =
unsigned int,
typename OpeningCount =
unsigned int>
45 static constexpr ClockTick
MinTick
46 = std::numeric_limits<ClockTick>::min();
52 ClockTick
tick { std::numeric_limits<ClockTick>::lowest() };
66 return (event == other.
event)
67 && (tick == other.
tick) && (opening == other.
opening);
73 return (event != other.
event)
74 || (tick != other.
tick) || (opening != other.
opening);
85 template <
typename Tick,
typename TickInterval>
89 template <
typename TK,
typename TI>
90 std::ostream& operator<< (std::ostream&, TriggerGateData<TK, TI>
const&);
92 template <
typename TK,
typename TI>
93 std::ostream&
operator<<
131 template <
typename Tick,
typename TickInterval>
156 = std::numeric_limits<ClockTick_t>::min();
160 = std::numeric_limits<ClockTick_t>::max();
274 {
return openAt(tick, -count); }
392 template <
typename Op>
421 friend std::ostream& operator<< <ClockTick_t, ClockTicks_t>
423 friend std::ostream& operator<< <ClockTick_t, ClockTicks_t>
424 (std::ostream&,
Status const&);
437 {
return status.
tick; }
438 template <
typename A,
typename B>
470 template <
typename Op>
504 #include "sbnobj/ICARUS/PMT/Trigger/Data/TriggerGateData.tcc"
510 #endif // SBNOBJ_ICARUS_PMT_TRIGGER_DATA_TRIGGERGATEDATA_H
Set the level, overriding the previous level.
typename GateEvolution_t::iterator status_iterator
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
triggergatedata_t & Sum(triggergatedata_t const &other)
Combines with a gate, keeping the sum of openings of the two.
typename GateEvolution_t::const_iterator status_const_iterator
triggergatedata_t & Min(triggergatedata_t const &other)
Combines with a gate, keeping the minimum opening among the two.
static constexpr ClockTick_t MaxTick
An unbearably large tick number.
status_const_iterator findMaxOpenStatus(ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns an iterator to the maximum open status (.
bool operator()(A &&a, B &&b) const
status_const_iterator findStatus(Op op, ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns an iterator to the first status for which op(status) is true.
static constexpr ClockTick_t MinTick
An unbearably small tick number.
void closeAllAt(ClockTick_t tick)
Completely close this gate at the specified time.
static triggergatedata_t SymmetricCombination(Op &&op, triggergatedata_t const &a, triggergatedata_t const &b, ClockTicks_t aDelay=ClockTicks_t{}, ClockTicks_t bDelay=ClockTicks_t{})
Returns a gate combination of the openings of two other gates.
ClockTick tick
When the status starts being valid.
static Status const NewGateStatus
A new gate starts with this status: opening level set to 0.
void closeAt(ClockTick_t tick, OpeningDiff_t count)
Close this gate at the specified time (decrease the opening by count).
Relative shift, adding an offset to the previous level.
bool operator==(TriggerGateStatus const &other) const
Comparison: are all fields matching?
bool operator==(TriggerGateData const &) const
bool operator!=(TriggerGateStatus const &other) const
Comparison: is any field not matching?
void compact()
Maintenance operation: removes unconsequential stati.
TriggerGateData(GateEvolution_t &&gateLevel)
Protected constructor: set the data directly.
void openBetween(ClockTick_t start, ClockTick_t end, OpeningDiff_t count=1)
Open this gate at specified start tick, and close it at end tick.
triggergatedata_t & Mul(triggergatedata_t const &other)
Combines with a gate, keeping the product of openings of the two.
triggergatedata_t & Max(triggergatedata_t const &other)
Combines with a gate, keeping the maximum opening among the two.
void clear()
Sets the gate levels in the state at construction.
auto end(FixedBins< T, C > const &) noexcept
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
status_const_iterator findOpenStatus(OpeningCount_t minOpening=1U, ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns an iterator to the first open status (.
details::TriggerGateStatus< ClockTick_t, OpeningCount_t > Status
OpeningCount_t openingCount(ClockTick_t tick) const
Returns the opening count of the gate at the specified tick.
TriggerGateEventType event
The event which yielded this status.
constexpr TriggerGateStatus()=default
OpeningCount opening
The total opening of the gate.
ClockTick_t lastTick() const
Returns the number of ticks this gate covers.
Comparison by tick number.
unsigned int OpeningCount_t
Type of count of number of open channels.
ClockTick_t findOpen(OpeningCount_t minOpening=1U, ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns the tick at which the gate opened.
Unknown state. This can't be good.
static constexpr ClockTick MinTick
status_iterator findLastStatusForTickOrThrow(ClockTick_t tick)
void openAt(ClockTick_t tick, OpeningDiff_t count)
Open this gate at the specified time (increase the opening by count).
TriggerGateData()
Constructor: a closed gate for the channel in waveform.
static constexpr ClockTick_t tickOf(ClockTick_t tick)
TriggerGateData< Tick, TickInterval > triggergatedata_t
This type.
bool operator!=(TriggerGateData const &) const
bool isOpen(ClockTick_t tick) const
Returns whether the gate is open at all at the specified tick.
std::optional< status_const_iterator > findLastStatusFor(ClockTick_t tick) const
Returns a const-iterator to the status current at tick, or no value.
void closeAt(ClockTick_t tick)
Close this gate at the specified time.
ClockTick_t findMaxOpen(ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns the tick at which the gate has the maximum opening.
Logical multi-level gate.
GateEvolution_t fGateLevel
Evolution of the gate in time.
void setOpeningAt(ClockTick_t tick, OpeningCount_t openingCount)
Changes the opening to match openingCount at the specified time.
static GateEvolution_t startingGateLevel()
Helper returning the starting state of the levels at construction time.
TriggerGateEventType
Type of events that can happen at a certain tick of a trigger gate.
void openAt(ClockTick_t tick)
Open this gate at the specified time (increase the opening by 1).
std::size_t count(Cont const &cont)
std::make_signed_t< OpeningCount_t > OpeningDiff_t
Type representing a variation of open channels.
TickInterval ClockTicks_t
Type of a time interval, measured in ticks.
void openFor(ClockTick_t tick, ClockTicks_t length, OpeningDiff_t count=1)
Open this gate at the specified time, and close it length ticks later.
Tick ClockTick_t
Type of a point in time, measured in ticks.
bool alwaysClosed() const
Returns whether this gate never opened.
std::vector< Status > GateEvolution_t
Type to describe the time evolution of the gate.
ClockTick_t findClose(OpeningCount_t minOpening=1U, ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns the tick at which the gate closed.
std::pair< OpeningCount_t, OpeningCount_t > openingRange(ClockTick_t start, ClockTick_t end) const
Returns the range of trigger opening values in the specified range.
status_const_iterator findCloseStatus(OpeningCount_t minOpening=1U, ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns an iterator to the first close status (.
static constexpr ClockTick_t tickOf(Status const &status)