lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Drp::PgpReader Class Reference

Reads DMA buffers from the PGP driver in bulk and assembles them into PGPEvents (one buffer per lane). More...

#include <DrpBase.hh>

Inherited by Drp::Pgp, Drp::Pgp, Drp::Pgp, Drp::Pgp, and Drp::Pgp.

Public Member Functions

 PgpReader (const Parameters &para, MemPool &pool, unsigned maxRetCnt, unsigned dmaFreeCnt)
 Size the bulk-read arrays for maxRetCnt buffers and the free-index batch for dmaFreeCnt buffers (aborting if the pool has fewer DMA buffers than dmaFreeCnt), set up poll() on the device file descriptor and reset the pool counters.
 
virtual ~PgpReader ()
 Call flush().
 
int32_t read ()
 Read up to maxRetCnt DMA buffers.
 
void flush ()
 Return the DMA indices queued for freeing, return every DMA buffer that can still be read without counting it, and free all pebble buffers in use.
 
const Pds::TimingHeader * handle (Detector *det, unsigned current)
 Process DMA buffer current of the last read() for detector det: record it in the PGPEvent chosen by its event counter and, once all lanes have arrived, check the event (counter jumps, common readout group, readout groups of SlowUpdates) and allocate a transition buffer (non-L1Accept) and a pebble buffer index.
 
void freeDma (PGPEvent *event)
 Queue the DMA buffers of all lanes of event for return to the driver (returned in batches of dmaFreeCnt) and clear the lane mask of the event.
 
virtual void handleBrokenEvent (const PGPEvent &event)
 Hook called for events that are dropped; the default does nothing.
 
virtual void resetEventCounter ()
 Reset the last completed event counter to 0; handle() calls this at BeginRun.
 
uint64_t dmaBytes () const
 Return the total number of DMA bytes handled.
 
uint64_t dmaSize () const
 Return the size of the last DMA buffer handled.
 
int64_t latency () const
 Return the last measured TimingHeader latency in microseconds, updated about every 92857 pulse IDs (10 Hz per the code comment).
 
uint64_t nDmaErrors () const
 Return the number of DMA buffers that reported an error.
 
uint64_t nNoComRoG () const
 Return the number of events dropped because the common readout group was missing.
 
uint64_t nMissingRoGs () const
 Return the number of SlowUpdates dropped because readout groups in Parameters::rogMask were missing.
 
uint64_t nTmgHdrError () const
 Return the number of timing headers with the error bit set.
 
uint64_t nPgpJumps () const
 Return the number of event counter jumps detected.
 
uint64_t nNoTrDgrams () const
 Return the number of events dropped because no transition buffer was available.
 
int64_t nPgpInUser () const
 Return dmaGetRxBuffinUserCount() for the device of the pool.
 
int64_t nPgpInHw () const
 Return dmaGetRxBuffinHwCount() for the device of the pool.
 
int64_t nPgpInPreHw () const
 Return dmaGetRxBuffinPreHwQCount() for the device of the pool.
 
int64_t nPgpInRx () const
 Return dmaGetRxBuffinSwQCount() for the device of the pool.
 
std::chrono::nanoseconds age (const XtcData::TimeStamp &time) const
 Return the latency of timestamp time (Pds::Eb::latency()) in nanoseconds.
 

Protected Attributes

const Parameters & m_para
 
MemPool & m_pool
 
pollfd m_pfd
 
Pds::fast_monotonic_clock::time_point m_t0
 
int m_tmo
 
unsigned m_us
 
std::vector< int32_t > dmaRet
 
std::vector< uint32_t > dmaIndex
 
std::vector< uint32_t > dest
 
std::vector< uint32_t > dmaFlags
 
std::vector< uint32_t > dmaErrors
 
uint32_t m_lastComplete
 
XtcData::TransitionId::Value m_lastTid
 
uint32_t m_lastData [6]
 
std::vector< uint32_t > m_dmaIndices
 
unsigned m_count
 
uint64_t m_dmaBytes
 
uint64_t m_dmaSize
 
uint64_t m_latPid
 
int64_t m_latency
 
uint64_t m_nDmaErrors
 
uint64_t m_nNoComRoG
 
uint64_t m_nMissingRoGs
 
uint64_t m_nTmgHdrError
 
uint64_t m_nPgpJumps
 
uint64_t m_nNoTrDgrams
 
std::mutex m_lock
 
bool m_dmaOverrun
 

Detailed Description

Reads DMA buffers from the PGP driver in bulk and assembles them into PGPEvents (one buffer per lane).

It checks event counters, readout groups and buffer sanity, and allocates pebble and transition buffers for complete events.

Constructor & Destructor Documentation

◆ PgpReader()

Drp::PgpReader::PgpReader ( const Parameters &  para,
MemPool &  pool,
unsigned  maxRetCnt,
unsigned  dmaFreeCnt 
)

Size the bulk-read arrays for maxRetCnt buffers and the free-index batch for dmaFreeCnt buffers (aborting if the pool has fewer DMA buffers than dmaFreeCnt), set up poll() on the device file descriptor and reset the pool counters.

◆ ~PgpReader()

virtual Drp::PgpReader::~PgpReader ( )
virtual

Call flush().

Member Function Documentation

◆ age()

std::chrono::nanoseconds Drp::PgpReader::age ( const XtcData::TimeStamp &  time) const

Return the latency of timestamp time (Pds::Eb::latency()) in nanoseconds.

◆ dmaBytes()

uint64_t Drp::PgpReader::dmaBytes ( ) const
inline

Return the total number of DMA bytes handled.

◆ dmaSize()

uint64_t Drp::PgpReader::dmaSize ( ) const
inline

Return the size of the last DMA buffer handled.

◆ flush()

void Drp::PgpReader::flush ( )

Return the DMA indices queued for freeing, return every DMA buffer that can still be read without counting it, and free all pebble buffers in use.

◆ freeDma()

void Drp::PgpReader::freeDma ( PGPEvent *  event)

Queue the DMA buffers of all lanes of event for return to the driver (returned in batches of dmaFreeCnt) and clear the lane mask of the event.

Thread-safe.

◆ handle()

const Pds::TimingHeader * Drp::PgpReader::handle ( Detector *  det,
unsigned  current 
)

Process DMA buffer current of the last read() for detector det: record it in the PGPEvent chosen by its event counter and, once all lanes have arrived, check the event (counter jumps, common readout group, readout groups of SlowUpdates) and allocate a transition buffer (non-L1Accept) and a pebble buffer index.

Returns the TimingHeader of a complete, accepted event, otherwise nullptr; aborts on a DMA overflow or a header with zero pulse ID, timestamp or env.

◆ handleBrokenEvent()

virtual void Drp::PgpReader::handleBrokenEvent ( const PGPEvent &  event)
inlinevirtual

Hook called for events that are dropped; the default does nothing.

Reimplemented in Drp::Pgp.

◆ latency()

int64_t Drp::PgpReader::latency ( ) const
inline

Return the last measured TimingHeader latency in microseconds, updated about every 92857 pulse IDs (10 Hz per the code comment).

◆ nDmaErrors()

uint64_t Drp::PgpReader::nDmaErrors ( ) const
inline

Return the number of DMA buffers that reported an error.

◆ nMissingRoGs()

uint64_t Drp::PgpReader::nMissingRoGs ( ) const
inline

Return the number of SlowUpdates dropped because readout groups in Parameters::rogMask were missing.

◆ nNoComRoG()

uint64_t Drp::PgpReader::nNoComRoG ( ) const
inline

Return the number of events dropped because the common readout group was missing.

◆ nNoTrDgrams()

uint64_t Drp::PgpReader::nNoTrDgrams ( ) const
inline

Return the number of events dropped because no transition buffer was available.

◆ nPgpInHw()

int64_t Drp::PgpReader::nPgpInHw ( ) const
inline

Return dmaGetRxBuffinHwCount() for the device of the pool.

◆ nPgpInPreHw()

int64_t Drp::PgpReader::nPgpInPreHw ( ) const
inline

Return dmaGetRxBuffinPreHwQCount() for the device of the pool.

◆ nPgpInRx()

int64_t Drp::PgpReader::nPgpInRx ( ) const
inline

Return dmaGetRxBuffinSwQCount() for the device of the pool.

◆ nPgpInUser()

int64_t Drp::PgpReader::nPgpInUser ( ) const
inline

Return dmaGetRxBuffinUserCount() for the device of the pool.

◆ nPgpJumps()

uint64_t Drp::PgpReader::nPgpJumps ( ) const
inline

Return the number of event counter jumps detected.

◆ nTmgHdrError()

uint64_t Drp::PgpReader::nTmgHdrError ( ) const
inline

Return the number of timing headers with the error bit set.

◆ read()

int32_t Drp::PgpReader::read ( )

Read up to maxRetCnt DMA buffers.

If the poll timeout is non-zero (100 ms initially, later 1 ms), first wait in poll(); after a successful read the timeout becomes 0 (pure polling) when buffers arrive faster than one per millisecond, else 1 ms. After an empty read, sleep with exponential back-off up to 1024 us. Returns the readDma() result.

◆ resetEventCounter()

virtual void Drp::PgpReader::resetEventCounter ( )
inlinevirtual

Reset the last completed event counter to 0; handle() calls this at BeginRun.

Reimplemented in Drp::Pgp.

Member Data Documentation

◆ dest

std::vector<uint32_t> Drp::PgpReader::dest
protected

◆ dmaErrors

std::vector<uint32_t> Drp::PgpReader::dmaErrors
protected

◆ dmaFlags

std::vector<uint32_t> Drp::PgpReader::dmaFlags
protected

◆ dmaIndex

std::vector<uint32_t> Drp::PgpReader::dmaIndex
protected

◆ dmaRet

std::vector<int32_t> Drp::PgpReader::dmaRet
protected

◆ m_count

unsigned Drp::PgpReader::m_count
protected

◆ m_dmaBytes

uint64_t Drp::PgpReader::m_dmaBytes
protected

◆ m_dmaIndices

std::vector<uint32_t> Drp::PgpReader::m_dmaIndices
protected

◆ m_dmaOverrun

bool Drp::PgpReader::m_dmaOverrun
protected

◆ m_dmaSize

uint64_t Drp::PgpReader::m_dmaSize
protected

◆ m_lastComplete

uint32_t Drp::PgpReader::m_lastComplete
protected

◆ m_lastData

uint32_t Drp::PgpReader::m_lastData[6]
protected

◆ m_lastTid

XtcData::TransitionId::Value Drp::PgpReader::m_lastTid
protected

◆ m_latency

int64_t Drp::PgpReader::m_latency
protected

◆ m_latPid

uint64_t Drp::PgpReader::m_latPid
protected

◆ m_lock

std::mutex Drp::PgpReader::m_lock
protected

◆ m_nDmaErrors

uint64_t Drp::PgpReader::m_nDmaErrors
protected

◆ m_nMissingRoGs

uint64_t Drp::PgpReader::m_nMissingRoGs
protected

◆ m_nNoComRoG

uint64_t Drp::PgpReader::m_nNoComRoG
protected

◆ m_nNoTrDgrams

uint64_t Drp::PgpReader::m_nNoTrDgrams
protected

◆ m_nPgpJumps

uint64_t Drp::PgpReader::m_nPgpJumps
protected

◆ m_nTmgHdrError

uint64_t Drp::PgpReader::m_nTmgHdrError
protected

◆ m_para

const Parameters& Drp::PgpReader::m_para
protected

◆ m_pfd

pollfd Drp::PgpReader::m_pfd
protected

◆ m_pool

MemPool& Drp::PgpReader::m_pool
protected

◆ m_t0

Pds::fast_monotonic_clock::time_point Drp::PgpReader::m_t0
protected

◆ m_tmo

int Drp::PgpReader::m_tmo
protected

◆ m_us

unsigned Drp::PgpReader::m_us
protected

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