artdaq_core  v3_06_00
SharedMemoryEventReceiver.hh
1 #ifndef artdaq_core_Core_SharedMemoryEventReceiver_hh
2 #define artdaq_core_Core_SharedMemoryEventReceiver_hh 1
3 
4 #include <set>
5 
6 #include "artdaq-core/Core/SharedMemoryManager.hh"
7 #include "artdaq-core/Data/Fragment.hh"
8 #include "artdaq-core/Data/RawEvent.hh"
9 
10 namespace artdaq {
15 {
16 public:
22  SharedMemoryEventReceiver(uint32_t shm_key, uint32_t broadcast_shm_key);
26  virtual ~SharedMemoryEventReceiver() = default;
27 
34  bool ReadyForRead(bool broadcast = false, size_t timeout_us = 1000000);
35 
42 
48  std::set<Fragment::type_t> GetFragmentTypes(bool& err);
49 
56  std::unique_ptr<Fragments> GetFragmentsByType(bool& err, Fragment::type_t type);
57 
62  std::string toString();
63 
67  void ReleaseBuffer();
68 
73  int GetRank() { return data_.GetRank(); }
74 
79  int GetMyId() { return data_.GetMyId(); }
80 
85  bool IsEndOfData() { return data_.IsEndOfData(); }
86 
91  int ReadReadyCount() { return data_.ReadReadyCount() + broadcasts_.ReadReadyCount(); }
92 
97  size_t size() { return data_.size(); }
98 
99 private:
102  SharedMemoryEventReceiver& operator=(SharedMemoryEventReceiver const&) = delete;
104 
105  std::string printBuffers_(SharedMemoryManager* data_source);
106 
107  int current_read_buffer_;
108  bool initialized_;
109  detail::RawEventHeader* current_header_;
110  SharedMemoryManager* current_data_source_;
111  SharedMemoryManager data_;
112  SharedMemoryManager broadcasts_;
113 };
114 } // namespace artdaq
115 
116 #endif /* artdaq_core_Core_SharedMemoryEventReceiver_hh */
void ReleaseBuffer()
Release the buffer currently being read to the Empty state.
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
Definition: Fragment.hh:137
SharedMemoryEventReceiver can receive events (as written by SharedMemoryEventManager) from Shared Mem...
int GetMyId()
Returns the ID of the reading process.
The SharedMemoryManager creates a Shared Memory area which is divided into a number of fixed-size buf...
int GetRank()
Returns the Rank of the writing process.
size_t ReadReadyCount()
Count the number of buffers that are ready for reading.
size_t size()
Get the size of the data buffer.
int GetRank() const
Get the rank of the owner of the Shared Memory (artdaq assigns rank to each artdaq process for data f...
SharedMemoryEventReceiver(uint32_t shm_key, uint32_t broadcast_shm_key)
Connect to a Shared Memory segment using the given parameters.
size_t size() const
Get the number of buffers in the shared memory segment.
bool IsEndOfData() const
Determine whether the Shared Memory is marked for destruction (End of Data)
The header information used to identify key properties of the RawEvent object.
Definition: RawEvent.hh:28
std::set< Fragment::type_t > GetFragmentTypes(bool &err)
Get a set of Fragment Types present in the event.
int ReadReadyCount()
Get the count of available buffers, both broadcasts and data.
virtual ~SharedMemoryEventReceiver()=default
SharedMemoryEventReceiver Destructor.
bool ReadyForRead(bool broadcast=false, size_t timeout_us=1000000)
Determine whether an event is available for reading.
std::string toString()
Write out information about the Shared Memory to a string.
detail::RawEventHeader * ReadHeader(bool &err)
Get the Event header.
bool IsEndOfData()
Determine if the end of data has been reached (from data shared memory segment)
int GetMyId() const
Get the ID number of the current SharedMemoryManager.
std::unique_ptr< Fragments > GetFragmentsByType(bool &err, Fragment::type_t type)
Get a pointer to the Fragments of a given type in the event.