artdaq_core
v3_04_02
|
The SharedMemoryFragmentManager is a SharedMemoryManager that deals with Fragment transfers using a SharedMemoryManager. More...
#include <artdaq-core/Core/SharedMemoryFragmentManager.hh>
Public Member Functions | |
SharedMemoryFragmentManager (uint32_t shm_key, size_t buffer_count, size_t max_buffer_size, size_t buffer_timeout_us=100 *1000000) | |
SharedMemoryFragmentManager Constructor. More... | |
virtual | ~SharedMemoryFragmentManager ()=default |
SharedMemoryFragmentManager destructor. | |
int | WriteFragment (Fragment &&fragment, bool overwrite, size_t timeout_us) |
Write a Fragment to the Shared Memory. More... | |
int | ReadFragment (Fragment &fragment) |
Read a Fragment from the Shared Memory. More... | |
int | ReadFragmentHeader (detail::RawFragmentHeader &header) |
Read a Fragment Header from the Shared Memory. More... | |
int | ReadFragmentData (RawDataType *destination, size_t words) |
Read Fragment Data from the Shared Memory. More... | |
bool | ReadyForWrite (bool overwrite) override |
Check if a buffer is ready for writing, and if so, reserves it for use. More... | |
![]() | |
SharedMemoryManager (uint32_t shm_key, size_t buffer_count=0, size_t buffer_size=0, uint64_t buffer_timeout_us=100 *1000000, bool destructive_read_mode=true) | |
SharedMemoryManager Constructor. More... | |
virtual | ~SharedMemoryManager () noexcept |
SharedMemoryManager Destructor. | |
void | Attach () |
Reconnect to the shared memory segment. | |
int | GetBufferForReading () |
Finds a buffer that is ready to be read, and reserves it for the calling manager. More... | |
int | GetBufferForWriting (bool overwrite) |
Finds a buffer that is ready to be written to, and reserves it for the calling manager. More... | |
bool | ReadyForRead () |
Whether any buffer is ready for read. More... | |
size_t | ReadReadyCount () |
Count the number of buffers that are ready for reading. More... | |
size_t | WriteReadyCount (bool overwrite) |
Count the number of buffers that are ready for writing. More... | |
std::deque< int > | GetBuffersOwnedByManager (bool locked=true) |
Get the list of all buffers currently owned by this manager instance. More... | |
size_t | BufferDataSize (int buffer) |
Get the current size of the buffer's data. More... | |
size_t | BufferSize () |
Get the size of of a single buffer. | |
void | ResetReadPos (int buffer) |
Set the read position of the given buffer to the beginning of the buffer. More... | |
void | ResetWritePos (int buffer) |
Set the write position of the given buffer to the beginning of the buffer. More... | |
void | IncrementReadPos (int buffer, size_t read) |
Increment the read position for a given buffer. More... | |
bool | IncrementWritePos (int buffer, size_t written) |
Increment the write position for a given buffer. More... | |
bool | MoreDataInBuffer (int buffer) |
Determine if more data is available to be read, based on the read position and data size. More... | |
bool | CheckBuffer (int buffer, BufferSemaphoreFlags flags) |
Check both semaphore conditions (Mode flag and manager ID) for a given buffer. More... | |
void | MarkBufferFull (int buffer, int destination=-1) |
Release a buffer from a writer, marking it Full and ready for a reader. More... | |
void | MarkBufferEmpty (int buffer, bool force=false) |
Release a buffer from a reader, marking it Empty and ready to accept more data. More... | |
bool | ResetBuffer (int buffer) |
Resets the buffer from Reading to Full. This operation will only have an effect if performed by the owning manager or if the buffer has timed out. More... | |
void | GetNewId () |
Assign a new ID to the current SharedMemoryManager, if one has not yet been assigned. | |
uint16_t | GetAttachedCount () const |
Get the number of attached SharedMemoryManagers. More... | |
void | ResetAttachedCount () const |
Reset the attached manager count to 0. | |
int | GetMyId () const |
Get the ID number of the current SharedMemoryManager. More... | |
int | GetRank () const |
Get the rank of the owner of the Shared Memory (artdaq assigns rank to each artdaq process for data flow) More... | |
void | SetRank (int rank) |
Set the rank stored in the Shared Memory, if the current instance is the owner of the shared memory. More... | |
bool | IsValid () const |
Is the shared memory pointer valid? More... | |
bool | IsEndOfData () const |
Determine whether the Shared Memory is marked for destruction (End of Data) | |
size_t | size () const |
Get the number of buffers in the shared memory segment. More... | |
size_t | Write (int buffer, void *data, size_t size) |
Write size bytes of data from the given pointer to a buffer. More... | |
bool | Read (int buffer, void *data, size_t size) |
Read size bytes of data from buffer into the given pointer. More... | |
virtual std::string | toString () |
Write information about the SharedMemory to a string. More... | |
uint32_t | GetKey () const |
Get the key of the shared memory attached to this SharedMemoryManager. More... | |
void * | GetReadPos (int buffer) |
Get a pointer to the current read position of the buffer. More... | |
void * | GetWritePos (int buffer) |
Get a pointer to the current write position of the buffer. More... | |
void * | GetBufferStart (int buffer) |
Get a pointer to the start position of the buffer. More... | |
void | Detach (bool throwException=false, std::string category="", std::string message="", bool force=false) |
Detach from the Shared Memory segment, optionally throwing a cet::exception with the specified properties. More... | |
uint64_t | GetBufferTimeout () const |
Gets the configured timeout for buffers to be declared "stale". More... | |
size_t | GetBufferCount () const |
Gets the number of buffers which have been processed through the Shared Memory. More... | |
size_t | GetLastSeenBufferID () const |
Gets the highest buffer number either written or read by this SharedMemoryManager. More... | |
size_t | GetLowestSeqIDRead () const |
Gets the lowest sequence ID that has been read by any reader, as reported by the readers. | |
void | SetMinWriteSize (size_t size) |
Sets the threshold after which a buffer should be considered "non-empty" (in case of default headers) More... | |
std::list< std::pair< int, BufferSemaphoreFlags > > | GetBufferReport () |
Get a report on the status of each buffer. More... | |
Additional Inherited Members | |
![]() | |
enum | BufferSemaphoreFlags { BufferSemaphoreFlags::Empty, BufferSemaphoreFlags::Writing, BufferSemaphoreFlags::Full, BufferSemaphoreFlags::Reading } |
The BufferSemaphoreFlags enumeration represents the different possible "states" of a given shared memory buffer. More... | |
![]() | |
static std::string | FlagToString (BufferSemaphoreFlags flag) |
Convert a BufferSemaphoreFlags variable to its string represenatation. More... | |
The SharedMemoryFragmentManager is a SharedMemoryManager that deals with Fragment transfers using a SharedMemoryManager.
Definition at line 11 of file SharedMemoryFragmentManager.hh.
artdaq::SharedMemoryFragmentManager::SharedMemoryFragmentManager | ( | uint32_t | shm_key, |
size_t | buffer_count, | ||
size_t | max_buffer_size, | ||
size_t | buffer_timeout_us = 100 * 1000000 |
||
) |
SharedMemoryFragmentManager Constructor.
shm_key | The key to use when attaching/creating the shared memory segment |
buffer_count | The number of buffers in the shared memory |
max_buffer_size | The size of each buffer |
buffer_timeout_us | The maximum amount of time a buffer may be locked before being returned to its previous state. This timer is reset upon any operation by the owning SharedMemoryManager. |
Definition at line 7 of file SharedMemoryFragmentManager.cc.
int artdaq::SharedMemoryFragmentManager::ReadFragment | ( | Fragment & | fragment | ) |
Read a Fragment from the Shared Memory.
fragment | Output Fragment object |
Definition at line 70 of file SharedMemoryFragmentManager.cc.
int artdaq::SharedMemoryFragmentManager::ReadFragmentData | ( | RawDataType * | destination, |
size_t | words | ||
) |
Read Fragment Data from the Shared Memory.
destination | Destination for data |
words | RawDataType Word count to read |
Definition at line 111 of file SharedMemoryFragmentManager.cc.
int artdaq::SharedMemoryFragmentManager::ReadFragmentHeader | ( | detail::RawFragmentHeader & | header | ) |
Read a Fragment Header from the Shared Memory.
header | Output Fragment Header |
Definition at line 84 of file SharedMemoryFragmentManager.cc.
|
overridevirtual |
Check if a buffer is ready for writing, and if so, reserves it for use.
overwrite | Whether to overwrite Full buffers (non-reliable mode) |
Reimplemented from artdaq::SharedMemoryManager.
Definition at line 14 of file SharedMemoryFragmentManager.cc.
int artdaq::SharedMemoryFragmentManager::WriteFragment | ( | Fragment && | fragment, |
bool | overwrite, | ||
size_t | timeout_us | ||
) |
Write a Fragment to the Shared Memory.
fragment | Fragment to write |
overwrite | Whether to set the overwrite flag |
timeout_us | Time to wait for shared memory to be free (0: No timeout) (Timeout does not apply if overwrite == false) |
Definition at line 23 of file SharedMemoryFragmentManager.cc.