1 #ifndef _ots_BufferImplementation_h_
2 #define _ots_BufferImplementation_h_
4 #include "otsdaq/DataManager/CircularBufferBase.h"
5 #include "otsdaq/Macros/CoutMacros.h"
6 #include "otsdaq/Macros/StringMacros.h"
7 #include "otsdaq/MessageFacility/MessageFacility.h"
17 template<
class D,
class H>
22 ConsumerStruct() : priority_(CircularBufferBase::LowConsumerPriority), readPointer_(0), subBuffersStatus_(
nullptr) {}
24 CircularBufferBase::ConsumerPriority priority_;
26 std::atomic_bool* subBuffersStatus_;
30 BufferImplementation(
const std::string& producerName =
"",
unsigned int numberOfSubBuffers = 100);
37 void resetConsumerList(
void);
38 void registerConsumer(
const std::string& name, CircularBufferBase::ConsumerPriority priority);
40 int attachToEmptySubBuffer(D*& data, H*& header);
41 int setWrittenSubBuffer(
void);
42 int write(
const D& buffer,
const H& header = H());
43 int read(D& buffer,
const std::string& consumer);
44 int read(D& buffer, H& header,
const std::string& consumer);
45 int read(D*& buffer, H*& header,
const std::string& consumer);
46 int setReadSubBuffer(
const std::string& consumer);
51 bool isEmpty(
void)
const;
52 unsigned int bufferSize(
void)
const {
return numberOfSubBuffers_; }
53 unsigned int numberOfWrittenBuffers(
void)
const;
55 const std::map<std::string, ConsumerStruct>& getConsumers(
void)
const {
return consumers_; };
57 void dumpStatus(std::ostream* out = (std::ostream*)&(std::cout))
const;
60 const std::string mfSubject_;
66 ErrorBufferLocked = -2,
67 ErrorBufferNotAvailable = -3,
68 ErrorReadBufferOutOfSync = -4
71 const std::string producerName_;
72 unsigned int numberOfSubBuffers_;
73 std::map<std::string, ConsumerStruct> consumers_;
75 std::atomic_bool* subBuffersStatus_;
76 std::vector<H> headers_;
77 std::vector<D> subBuffers_;
78 const bool bufferFree_;
80 unsigned int nextWritePointer(
void);
81 unsigned int nextReadPointer(
const std::string& consumer);
82 int getFreeBufferIndex(
void);
83 unsigned int getReadPointer(
const std::string& consumer);
84 void setWritten(
unsigned int subBuffer);
85 void setFree(
unsigned int subBuffer,
const std::string& consumer);
86 std::atomic_bool& isFree(
unsigned int subBuffer)
const;
87 std::atomic_bool& isFree(
unsigned int subBuffer,
const std::string& consumer)
const;
89 H& getHeader(
unsigned int subBuffer);
90 D& getSubBuffer(
unsigned int subBuffer);
91 void writeSubBuffer(
unsigned int subBuffer,
const D& buffer,
const H& header);
93 #include "otsdaq/DataManager/BufferImplementation.icc"