lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Pds::Eb::EventBuilder Class Referenceabstract

Abstract event builder. More...

#include <EventBuilder.hh>

Inherited by Pds::Eb::EbAppBase.

Public Types

using time_point_t = std::chrono::time_point< fast_monotonic_clock >
 Time point of fast_monotonic_clock.
 
using ns_t = std::chrono::nanoseconds
 Alias for std::chrono::nanoseconds.
 

Public Member Functions

 EventBuilder (unsigned timeout, const unsigned &verbose)
 Set the event timeout to timeout milliseconds (0 means effectively no timeout) and keep verbose by reference; prints the timeout to stderr.
 
virtual ~EventBuilder ()
 Does nothing; empty body.
 
virtual void flush ()
 Hook called by expired() when nothing is pending; the default does nothing.
 
virtual void fixup (EbEvent *, unsigned srcId)=0
 Pure virtual: called once for each missing contributor srcId of an event that is being forced out (timed out or flushed by a newer complete event).
 
virtual void process (EbEvent *)=0
 Pure virtual: handle a completed or fixed-up event; called in pulse ID order just before the event is freed.
 
virtual uint64_t contract (const Pds::EbDgram *) const =0
 Pure virtual: return the bit list of contributors expected for the event that this contribution starts.
 
void expired ()
 Periodic timeout handler.
 
void process (const Pds::EbDgram *dgrams, const size_t bufSize, unsigned imm, const void *const end)
 Insert a batch of contributions starting at dgrams (entries bufSize bytes apart, ending at the EOL entry or after the maximum number of entries) into their events, with immediate data imm incremented per entry; end is only used to report a missing EOL.
 
void resetCounters ()
 Zero the pool counters, the timeout and fixup counts, the missing bit list, the occupancy counts, the event age, the processing time and the arrival times.
 
void clear ()
 Delete all pending events, discard the now-empty epochs, reset the counters and clear the epoch and event lookup tables.
 
void dump (unsigned detail) const
 Print the pending epochs (and their events, depending on detail) and the state of both object pools to stderr.
 
const uint64_t epochAllocCnt () const
 Return the number of allocations from the epoch pool (0 before initialize()).
 
const uint64_t epochFreeCnt () const
 Return the number of frees to the epoch pool (0 before initialize()).
 
const int64_t epochOccCnt () const
 Return the number of epochs in use (allocations minus frees), also caching it.
 
const uint64_t eventAllocCnt () const
 Return the number of allocations from the event pool (0 before initialize()).
 
const uint64_t eventFreeCnt () const
 Return the number of frees to the event pool (0 before initialize()).
 
const int64_t eventOccCnt () const
 Return the number of events in use (allocations minus frees), also caching it.
 
const uint64_t eventPoolDepth () const
 Return the number of objects in the event pool (0 before initialize()); returned by value.
 
const uint64_t timeoutCnt () const
 Return the number of incomplete events forced out because they were older than the timeout.
 
const uint64_t fixupCnt () const
 Return the number of incomplete events forced out before reaching the timeout.
 
const uint64_t missing () const
 Return the bit list of contributors still missing from the most recently fixed-up event.
 
const int64_t eventAge () const
 Return the most recently recorded event age in nanoseconds (updated while flushing and when an event is retired).
 
const int64_t ebTime () const
 Return the time spent in the most recent process(dgrams, ...) call, in nanoseconds.
 
const int64_t arrTime (unsigned src) const
 Return, for contributor src, the time in nanoseconds from the creation of the last event in its most recent batch to the start of processing that batch; 0 if src is out of range.
 

Protected Member Functions

int initialize (unsigned epochs, unsigned entries, unsigned sources, uint64_t duration)
 

Friends

class EbEvent
 

Detailed Description

Abstract event builder.

Contributions with the same pulse ID are collected into an EbEvent (events are grouped into epochs of a fixed duration), and events are passed to process(EbEvent*) in pulse ID order once their contract is met or they are forced out. Subclasses supply fixup(), process(EbEvent*) and contract().

Member Typedef Documentation

◆ ns_t

using Pds::Eb::EventBuilder::ns_t = std::chrono::nanoseconds

Alias for std::chrono::nanoseconds.

◆ time_point_t

Time point of fast_monotonic_clock.

Constructor & Destructor Documentation

◆ EventBuilder()

Pds::Eb::EventBuilder::EventBuilder ( unsigned  timeout,
const unsigned &  verbose 
)

Set the event timeout to timeout milliseconds (0 means effectively no timeout) and keep verbose by reference; prints the timeout to stderr.

The protected initialize() must be called before contributions are processed.

◆ ~EventBuilder()

virtual Pds::Eb::EventBuilder::~EventBuilder ( )
virtual

Does nothing; empty body.

Member Function Documentation

◆ arrTime()

const int64_t Pds::Eb::EventBuilder::arrTime ( unsigned  src) const
inline

Return, for contributor src, the time in nanoseconds from the creation of the last event in its most recent batch to the start of processing that batch; 0 if src is out of range.

◆ clear()

void Pds::Eb::EventBuilder::clear ( )

Delete all pending events, discard the now-empty epochs, reset the counters and clear the epoch and event lookup tables.

◆ contract()

virtual uint64_t Pds::Eb::EventBuilder::contract ( const Pds::EbDgram *  ) const
pure virtual

Pure virtual: return the bit list of contributors expected for the event that this contribution starts.

Implemented in Pds::Eb::EbAppBase.

◆ dump()

void Pds::Eb::EventBuilder::dump ( unsigned  detail) const

Print the pending epochs (and their events, depending on detail) and the state of both object pools to stderr.

◆ ebTime()

const int64_t Pds::Eb::EventBuilder::ebTime ( ) const
inline

Return the time spent in the most recent process(dgrams, ...) call, in nanoseconds.

◆ epochAllocCnt()

const uint64_t Pds::Eb::EventBuilder::epochAllocCnt ( ) const
inline

Return the number of allocations from the epoch pool (0 before initialize()).

◆ epochFreeCnt()

const uint64_t Pds::Eb::EventBuilder::epochFreeCnt ( ) const
inline

Return the number of frees to the epoch pool (0 before initialize()).

◆ epochOccCnt()

const int64_t Pds::Eb::EventBuilder::epochOccCnt ( ) const
inline

Return the number of epochs in use (allocations minus frees), also caching it.

◆ eventAge()

const int64_t Pds::Eb::EventBuilder::eventAge ( ) const
inline

Return the most recently recorded event age in nanoseconds (updated while flushing and when an event is retired).

◆ eventAllocCnt()

const uint64_t Pds::Eb::EventBuilder::eventAllocCnt ( ) const
inline

Return the number of allocations from the event pool (0 before initialize()).

◆ eventFreeCnt()

const uint64_t Pds::Eb::EventBuilder::eventFreeCnt ( ) const
inline

Return the number of frees to the event pool (0 before initialize()).

◆ eventOccCnt()

const int64_t Pds::Eb::EventBuilder::eventOccCnt ( ) const
inline

Return the number of events in use (allocations minus frees), also caching it.

◆ eventPoolDepth()

const uint64_t Pds::Eb::EventBuilder::eventPoolDepth ( ) const
inline

Return the number of objects in the event pool (0 before initialize()); returned by value.

◆ expired()

void Pds::Eb::EventBuilder::expired ( )

Periodic timeout handler.

If no event is pending, call flush(); otherwise flush pending events oldest first, fixing up incomplete events older than the timeout and stopping at the first incomplete event that may still complete.

◆ fixup()

virtual void Pds::Eb::EventBuilder::fixup ( EbEvent *  ,
unsigned  srcId 
)
pure virtual

Pure virtual: called once for each missing contributor srcId of an event that is being forced out (timed out or flushed by a newer complete event).

Implemented in Pds::Eb::EbAppBase.

◆ fixupCnt()

const uint64_t Pds::Eb::EventBuilder::fixupCnt ( ) const
inline

Return the number of incomplete events forced out before reaching the timeout.

◆ flush()

virtual void Pds::Eb::EventBuilder::flush ( )
inlinevirtual

Hook called by expired() when nothing is pending; the default does nothing.

◆ initialize()

int Pds::Eb::EventBuilder::initialize ( unsigned  epochs,
unsigned  entries,
unsigned  sources,
uint64_t  duration 
)
protected

◆ missing()

const uint64_t Pds::Eb::EventBuilder::missing ( ) const
inline

Return the bit list of contributors still missing from the most recently fixed-up event.

◆ process() [1/2]

void Pds::Eb::EventBuilder::process ( const Pds::EbDgram *  dgrams,
const size_t  bufSize,
unsigned  imm,
const void *const  end 
)

Insert a batch of contributions starting at dgrams (entries bufSize bytes apart, ending at the EOL entry or after the maximum number of entries) into their events, with immediate data imm incremented per entry; end is only used to report a missing EOL.

Completed events, and older events subject to the timeout rules, are then delivered; if none completed, a flush is tried at most every 100 ms. Also updates the arrival-time and processing-time metrics.

◆ process() [2/2]

virtual void Pds::Eb::EventBuilder::process ( EbEvent *  )
pure virtual

Pure virtual: handle a completed or fixed-up event; called in pulse ID order just before the event is freed.

◆ resetCounters()

void Pds::Eb::EventBuilder::resetCounters ( )

Zero the pool counters, the timeout and fixup counts, the missing bit list, the occupancy counts, the event age, the processing time and the arrival times.

◆ timeoutCnt()

const uint64_t Pds::Eb::EventBuilder::timeoutCnt ( ) const
inline

Return the number of incomplete events forced out because they were older than the timeout.

Friends And Related Symbol Documentation

◆ EbEvent

friend class EbEvent
friend

The documentation for this class was generated from the following file: