Belle II Software  release-05-02-19
SharedEventBuffer.h
1 #ifndef Belle2_SharedEventBuffer_h
2 #define Belle2_SharedEventBuffer_h
3 
4 #include "daq/slc/system/SharedMemory.h"
5 #include "daq/slc/system/MMutex.h"
6 #include "daq/slc/system/MCond.h"
7 
8 namespace Belle2 {
15 
16  public:
17  struct Header {
18  unsigned int expno;
19  unsigned int runno;
20  unsigned int subno;
21  unsigned int count_in;
22  unsigned int count_out;
23  unsigned long long nword_in;
24  unsigned long long nword_out;
25  unsigned short nwriter;
26  unsigned short nreader;
27  };
28 
29  public:
31  {
32  m_buf = NULL;
33  m_nword = 0;
34  }
36  {
37  if (m_buf != NULL) m_memory.close();
38  }
39 
40  public:
41  size_t size() throw();
42  bool open(const std::string& nodename,
43  size_t nword, bool recreate = false);
44  bool init();
45  bool close();
46  bool unlink();
47  bool lock() throw();
48  bool unlock() throw();
49  bool wait() throw();
50  bool wait(int time) throw();
51  bool notify() throw();
52  void clear();
53  bool isOpened() { return m_memory.isOpened(); }
54 
55  public:
56  const std::string getPath() const throw() { return m_path; }
57  Header* getHeader() throw() { return m_header; }
58  int* getBuffer() throw() { return m_buf; }
59  bool isWritable(int nword) throw();
60  bool isReadable(int nword) throw();
61  unsigned int write(const int* buf, unsigned int nword,
62  bool fouce, unsigned int serial = 0)
63  {
64  return write(buf, nword, fouce, serial, false);
65  }
66  unsigned int write(const int* buf, unsigned int nword,
67  bool fouce, unsigned int serial, bool unlocked);
68  unsigned int read(int* buf, bool fouce, bool unlocked, Header* hdr = NULL);
69 
70  private:
71  std::string m_path;
72  SharedMemory m_memory;
73  MMutex m_mutex;
74  MCond m_cond;
75  Header* m_header;
76  int* m_buf;
77  unsigned int m_nword;
78 
79  };
80 
82 }
83 
84 #endif
Belle2::SharedEventBuffer
Definition: SharedEventBuffer.h:14
Belle2::SharedEventBuffer::Header
Definition: SharedEventBuffer.h:17
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19