artdaq  v3_09_00
artdaq::FragmentBuffer Class Reference

FragmentBuffer is a FragmentGenerator-derived abstract class that defines the interface for a FragmentGenerator designed as a state machine with start, stop, etc., transition commands. More...

#include <artdaq/DAQrate/FragmentBuffer.hh>

Classes

struct  Config
 Configuration of the FragmentBuffer. May be used for parameter validation More...
 

Public Types

using Parameters = fhicl::WrappedTable< Config >
 Used for ParameterSet validation (if desired)
 

Public Member Functions

 FragmentBuffer (const fhicl::ParameterSet &ps)
 FragmentBuffer Constructor. More...
 
virtual ~FragmentBuffer ()
 FragmentBuffer Destructor. More...
 
void AddFragmentsToBuffer (FragmentPtrs frags)
 
void Stop ()
 
void Reset (bool stop)
 
void applyRequestsIgnoredMode (artdaq::FragmentPtrs &frags)
 Create fragments using data buffer for request mode Ignored. Precondition: dataBufferMutex_ and request_mutex_ are locked More...
 
void applyRequestsSingleMode (artdaq::FragmentPtrs &frags)
 Create fragments using data buffer for request mode Single. Precondition: dataBufferMutex_ and request_mutex_ are locked More...
 
void applyRequestsBufferMode (artdaq::FragmentPtrs &frags)
 Create fragments using data buffer for request mode Buffer. Precondition: dataBufferMutex_ and request_mutex_ are locked More...
 
void applyRequestsWindowMode (artdaq::FragmentPtrs &frags)
 Create fragments using data buffer for request mode Window. Precondition: dataBufferMutex_ and request_mutex_ are locked More...
 
void applyRequestsSequenceIDMode (artdaq::FragmentPtrs &frags)
 Create fragments using data buffer for request mode SequenceID. Precondition: dataBufferMutex_ and request_mutex_ are locked More...
 
void applyRequestsWindowMode_CheckAndFillDataBuffer (artdaq::FragmentPtrs &frags, artdaq::Fragment::fragment_id_t id, artdaq::Fragment::sequence_id_t seq, artdaq::Fragment::timestamp_t ts)
 
bool applyRequests (FragmentPtrs &frags)
 See if any requests have been received, and add the corresponding data Fragment objects to the output list. More...
 
bool sendEmptyFragment (FragmentPtrs &frags, size_t sequenceId, Fragment::fragment_id_t fragmentId, std::string desc)
 Send an EmptyFragmentType Fragment. More...
 
void sendEmptyFragments (FragmentPtrs &frags, std::map< Fragment::sequence_id_t, Fragment::timestamp_t > &requests)
 This function is for Buffered and Single request modes, as they can only respond to one data request at a time If the request message seqID > ev_counter, simply send empties until they're equal. More...
 
void checkSentWindows (Fragment::sequence_id_t seq)
 Check the windows_sent_ooo_ map for sequence IDs that may be removed. More...
 
bool waitForDataBufferReady (Fragment::fragment_id_t id)
 Wait for the data buffer to drain (dataBufferIsTooLarge returns false), periodically reporting status. More...
 
bool dataBufferIsTooLarge (Fragment::fragment_id_t id)
 Test the configured constraints on the data buffer. More...
 
void getDataBufferStats (Fragment::fragment_id_t id)
 Calculate the size of the dataBuffer and report appropriate metrics. More...
 
void getDataBuffersStats ()
 Calculate the size of all dataBuffers and report appropriate metrics.
 
void checkDataBuffer (Fragment::fragment_id_t id)
 Perform data buffer pruning operations for the given buffer. If the RequestMode is Single, removes all but the latest Fragment from the data buffer. More...
 
void checkDataBuffers ()
 Perform data buffer pruning operations for all buffers.
 
std::map
< Fragment::sequence_id_t,
std::chrono::steady_clock::time_point > 
GetSentWindowList (Fragment::fragment_id_t id)
 Get the map of Window-mode requests fulfilled by this Fragment Geneerator for the given Fragment ID. More...
 
std::vector
< Fragment::fragment_id_t > 
fragmentIDs ()
 Get the list of Fragment IDs handled by this FragmentBuffer. More...
 
RequestMode request_mode () const
 Get the current request mode of the FragmentBuffer More...
 
void SetRequestBuffer (std::shared_ptr< RequestBuffer > buffer)
 Set the pointer to the RequestBuffer used to retrieve requests. More...
 
artdaq::Fragment::sequence_id_t GetNextSequenceID () const
 Get the next sequence ID expected by this FragmentBuffer. This is used to track sent windows and missed requests. More...
 

Protected Member Functions

artdaq::Fragment::fragment_id_t fragment_id () const
 Get the Fragment ID of this Fragment generator. More...
 
bool check_stop ()
 Routine used by applyRequests to make sure that all outstanding requests have been fulfilled before returning. More...
 
std::string printMode_ ()
 Return the string representation of the current RequestMode. More...
 
size_t dataBufferFragmentCount_ ()
 Get the total number of Fragments in all data buffers. More...
 

Detailed Description

FragmentBuffer is a FragmentGenerator-derived abstract class that defines the interface for a FragmentGenerator designed as a state machine with start, stop, etc., transition commands.

Users of classes derived from FragmentBuffer will call these transitions via the publically defined StartCmd(), StopCmd(), etc.; these public functions contain functionality considered properly universal to all FragmentBuffer-derived classes, including calls to private virtual functions meant to be overridden in derived classes. The same applies to this class's implementation of the FragmentGenerator::getNext() pure virtual function, which is declared final (i.e., non-overridable in derived classes) and which itself calls a pure virtual getNext_() function to be implemented in derived classes.

State-machine related interface functions will be called only from a single thread. getNext() will be called only from a single thread. The thread from which state-machine interfaces functions are called may be a different thread from the one that calls getNext().

John F., 3/24/14

After some discussion with Kurt, FragmentBuffer has been updated such that it now contains a member vector fragment_ids_ ; if "fragment_id" is set in the FHiCL document controlling a class derived from FragmentBuffer, fragment_ids_ will be booked as a length-1 vector, and the value in this vector will be returned by fragment_id(). fragment_id() will throw an exception if the length of the vector isn't 1. If "fragment_ids" is set in the FHiCL document, then fragment_ids_ is filled with the values in the list which "fragment_ids" refers to, otherwise it is set to the empty vector (this is what should happen if the user sets the "fragment_id" variable in the FHiCL document, otherwise exceptions will end up thrown due to the logical conflict). If neither "fragment_id" nor "fragment_ids" is set in the FHiCL document, writers of classes derived from this one will be expected to override the virtual fragmentIDs() function with their own code (the CompositeDriver class is an example of this)

Definition at line 82 of file FragmentBuffer.hh.

Constructor & Destructor Documentation

artdaq::FragmentBuffer::FragmentBuffer ( const fhicl::ParameterSet &  ps)
explicit

FragmentBuffer Constructor.

Parameters
psParameterSet used to configure FragmentBuffer. See artdaq::FragmentBuffer::Config.

Definition at line 46 of file FragmentBuffer.cc.

artdaq::FragmentBuffer::~FragmentBuffer ( )
virtual

FragmentBuffer Destructor.

Joins all threads before returning

Definition at line 115 of file FragmentBuffer.cc.

Member Function Documentation

bool artdaq::FragmentBuffer::applyRequests ( FragmentPtrs &  frags)

See if any requests have been received, and add the corresponding data Fragment objects to the output list.

Parameters
[out]fragslist of FragmentPtr objects ready for transmission
Returns
True if not stopped

Definition at line 725 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsBufferMode ( artdaq::FragmentPtrs &  frags)

Create fragments using data buffer for request mode Buffer. Precondition: dataBufferMutex_ and request_mutex_ are locked

Parameters
fragsOuput fragments

Definition at line 470 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsIgnoredMode ( artdaq::FragmentPtrs &  frags)

Create fragments using data buffer for request mode Ignored. Precondition: dataBufferMutex_ and request_mutex_ are locked

Parameters
fragsOuput fragments

Definition at line 411 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsSequenceIDMode ( artdaq::FragmentPtrs &  frags)

Create fragments using data buffer for request mode SequenceID. Precondition: dataBufferMutex_ and request_mutex_ are locked

Parameters
fragsOuput fragments

Definition at line 667 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsSingleMode ( artdaq::FragmentPtrs &  frags)

Create fragments using data buffer for request mode Single. Precondition: dataBufferMutex_ and request_mutex_ are locked

Parameters
fragsOuput fragments

Definition at line 427 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsWindowMode ( artdaq::FragmentPtrs &  frags)

Create fragments using data buffer for request mode Window. Precondition: dataBufferMutex_ and request_mutex_ are locked

Parameters
fragsOuput fragments

Definition at line 620 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::applyRequestsWindowMode_CheckAndFillDataBuffer ( artdaq::FragmentPtrs &  frags,
artdaq::Fragment::fragment_id_t  id,
artdaq::Fragment::sequence_id_t  seq,
artdaq::Fragment::timestamp_t  ts 
)

Copy data from the relevant data buffer that matches the given timestamp.

Parameters
fragsOutput Fragments
idFragment ID of buffer to search
seqSequence ID of output Fragment
tsTimestamp of output Fragment (used to determine window limits)

Definition at line 522 of file FragmentBuffer.cc.

bool artdaq::FragmentBuffer::check_stop ( )
protected

Routine used by applyRequests to make sure that all outstanding requests have been fulfilled before returning.

Returns
The logical AND of should_stop, mode is not Ignored, and requests list size equal to 0

Definition at line 210 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::checkDataBuffer ( Fragment::fragment_id_t  id)

Perform data buffer pruning operations for the given buffer. If the RequestMode is Single, removes all but the latest Fragment from the data buffer.

Parameters
idFragment ID of buffer In Window and Buffer RequestModes, this function discards the oldest Fragment objects until the data buffer is below its size constraints, then also checks for stale Fragments, based on the timestamp of the most recent Fragment.

Definition at line 361 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::checkSentWindows ( Fragment::sequence_id_t  seq)

Check the windows_sent_ooo_ map for sequence IDs that may be removed.

Parameters
seqSequence ID of current window

Definition at line 834 of file FragmentBuffer.cc.

size_t artdaq::FragmentBuffer::dataBufferFragmentCount_ ( )
protected

Get the total number of Fragments in all data buffers.

Returns
Number of Fragments in all data buffers

Definition at line 245 of file FragmentBuffer.cc.

bool artdaq::FragmentBuffer::dataBufferIsTooLarge ( Fragment::fragment_id_t  id)

Test the configured constraints on the data buffer.

Parameters
idFragment ID of data buffer
Returns
Whether the data buffer is full

Definition at line 322 of file FragmentBuffer.cc.

artdaq::Fragment::fragment_id_t artdaq::FragmentBuffer::fragment_id ( ) const
inlineprotected

Get the Fragment ID of this Fragment generator.

Exceptions
cet::exception("FragmentID")if there is more that one Fragment ID configured for this Fragment Generator
Returns
Fragment ID for the Fragment Generator

Definition at line 361 of file FragmentBuffer.hh.

std::vector<Fragment::fragment_id_t> artdaq::FragmentBuffer::fragmentIDs ( )
inline

Get the list of Fragment IDs handled by this FragmentBuffer.

Returns
A std::vector<Fragment::fragment_id_t> containing the Fragment IDs handled by this FragmentBuffer

Definition at line 301 of file FragmentBuffer.hh.

void artdaq::FragmentBuffer::getDataBufferStats ( Fragment::fragment_id_t  id)

Calculate the size of the dataBuffer and report appropriate metrics.

Parameters
idFragment ID of buffer

Definition at line 335 of file FragmentBuffer.cc.

artdaq::Fragment::sequence_id_t artdaq::FragmentBuffer::GetNextSequenceID ( ) const
inline

Get the next sequence ID expected by this FragmentBuffer. This is used to track sent windows and missed requests.

Returns
The next sequence ID expected by this FragmentBuffer

Definition at line 345 of file FragmentBuffer.hh.

std::map<Fragment::sequence_id_t, std::chrono::steady_clock::time_point> artdaq::FragmentBuffer::GetSentWindowList ( Fragment::fragment_id_t  id)
inline

Get the map of Window-mode requests fulfilled by this Fragment Geneerator for the given Fragment ID.

Parameters
idFragment ID of buffer
Returns
Map of sequence_id and time_point for sent Window-mode requests

This function is used in FragmentBuffer_t to verify correct functioning of Window mode

Definition at line 287 of file FragmentBuffer.hh.

std::string artdaq::FragmentBuffer::printMode_ ( )
protected

Return the string representation of the current RequestMode.

Returns
The string representation of the current RequestMode

Definition at line 226 of file FragmentBuffer.cc.

RequestMode artdaq::FragmentBuffer::request_mode ( ) const
inline

Get the current request mode of the FragmentBuffer

Returns
Current RequestMode of the CFG

Definition at line 317 of file FragmentBuffer.hh.

bool artdaq::FragmentBuffer::sendEmptyFragment ( FragmentPtrs &  frags,
size_t  sequenceId,
Fragment::fragment_id_t  fragmentId,
std::string  desc 
)

Send an EmptyFragmentType Fragment.

Parameters
[out]fragsOutput list to append EmptyFragmentType to
sequenceIdSequence ID of Empty Fragment
fragmentIdFragment ID of Empty Fragment
descMessage to log with reasoning for sending Empty Fragment
Returns
True if no exceptions

Definition at line 807 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::sendEmptyFragments ( FragmentPtrs &  frags,
std::map< Fragment::sequence_id_t, Fragment::timestamp_t > &  requests 
)

This function is for Buffered and Single request modes, as they can only respond to one data request at a time If the request message seqID > ev_counter, simply send empties until they're equal.

Parameters
[out]fragsOutput list to append EmptyFragmentType to
requestsList of requests to process

Definition at line 818 of file FragmentBuffer.cc.

void artdaq::FragmentBuffer::SetRequestBuffer ( std::shared_ptr< RequestBuffer buffer)
inline

Set the pointer to the RequestBuffer used to retrieve requests.

Parameters
bufferPointer to the RequestBuffer

Definition at line 339 of file FragmentBuffer.hh.

bool artdaq::FragmentBuffer::waitForDataBufferReady ( Fragment::fragment_id_t  id)

Wait for the data buffer to drain (dataBufferIsTooLarge returns false), periodically reporting status.

Parameters
idFragment ID of data buffer
Returns
True if wait ended without something else disrupting the run

Definition at line 253 of file FragmentBuffer.cc.


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