32 _chTimeCorrections.fill(0);
42 throw std::runtime_error(
"Ch number is bigger than 4095!" );
44 _chTimeCorrections[ch] = correction;
46 if( correction > _maxCorrection )
47 _maxCorrection = correction;
48 if( correction < _minCorrection )
49 _minCorrection = correction;
51 _correctionWidth = _maxCorrection-_minCorrection;
60 return ch < 4095 ? _chTimeCorrections[ch] : 0;
66 virtual void process( std::vector<DetectorEvent> &input, std::vector<DetectorEvent> &output ) {
73 auto proci = _ctxh->processInstance();
78 for(
auto &det : input ) {
80 if( det.time < _tsPrev ) {
81 _ctxh->logWarning( fmt::format(
"TimeOrder error: {} -> {}, {} s.",
82 _tsPrev, det.time, (det.time-_tsPrev)*1e-8 ) );
84 while( _queue.size() ) {
85 output.push_back( std::move( _queue.front() ) );
94 while( _queue.size() && _queue.front().time + _correctionWidth < det.time ) {
95 output.emplace_back( std::move( _queue.front() ) );
99 const bool sortingNeeded = ( _queue.size() && _queue.back().time > det.time );
100 _queue.emplace_back( std::move(det) );
111 std::array<int64_t,4096> _chTimeCorrections;
113 int64_t _maxCorrection{0};
114 int64_t _minCorrection{0};
115 int64_t _correctionWidth{0};
121 std::deque<DetectorEvent> _queue;
Handle to context used by specific class.
Definition: ContextBase.hpp:188
Abstract baseclass for all stages which transforms detector events to detector events.
Definition: StageDetectorEventToDetectorEvent.hpp:23
Adjusts individual channel timing and merges channels back in time order.
Definition: TimeAdjuster.hpp:26
void setCorrection(uint16_t ch, int64_t correction)
Registers timestamp correction for a channel.
Definition: TimeAdjuster.hpp:40
int64_t getCorrection(uint16_t ch) const noexcept
Returns correction of the timestamp registered to a channel.
Definition: TimeAdjuster.hpp:59
virtual void process(std::vector< DetectorEvent > &input, std::vector< DetectorEvent > &output)
Consumes detector events and returns different detector events.
Definition: TimeAdjuster.hpp:66
Definition: mainpage.dox:6
static ContextBase & getActive() noexcept
Returns active Context.
Definition: ContextBase.hpp:80
Functor to compare DetectorEvent instances based on time field (as std::less<>).
Definition: DetectorEvent.hpp:69