Belle II Software development
SharedEventBuffer.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#ifndef Belle2_SharedEventBuffer_h
9#define Belle2_SharedEventBuffer_h
10
11#include "daq/slc/system/SharedMemory.h"
12#include "daq/slc/system/MMutex.h"
13#include "daq/slc/system/MCond.h"
14
15namespace Belle2 {
22
23 public:
24 struct Header {
25 unsigned int expno;
26 unsigned int runno;
27 unsigned int subno;
28 unsigned int count_in;
29 unsigned int count_out;
30 unsigned long long nword_in;
31 unsigned long long nword_out;
32 unsigned short nwriter;
33 unsigned short nreader;
34 };
35
36 public:
38 {
39 m_buf = NULL;
40 m_nword = 0;
41 }
43 {
44 if (m_buf != NULL) m_memory.close();
45 }
46
47 public:
48 size_t size() throw();
49 bool open(const std::string& nodename,
50 size_t nword, bool recreate = false);
51 bool init();
52 bool close();
53 bool unlink();
54 bool lock() throw();
55 bool unlock() throw();
56 bool wait() throw();
57 bool wait(int time) throw();
58 bool notify() throw();
59 void clear();
60 bool isOpened() { return m_memory.isOpened(); }
61
62 public:
63 const std::string getPath() const throw() { return m_path; }
64 Header* getHeader() throw() { return m_header; }
65 int* getBuffer() throw() { return m_buf; }
66 bool isWritable(int nword) throw();
67 bool isReadable(int nword) throw();
68 unsigned int write(const int* buf, unsigned int nword,
69 bool fouce, unsigned int serial = 0)
70 {
71 return write(buf, nword, fouce, serial, false);
72 }
73 unsigned int write(const int* buf, unsigned int nword,
74 bool fouce, unsigned int serial, bool unlocked);
75 unsigned int read(int* buf, bool fouce, bool unlocked, Header* hdr = NULL);
76
77 private:
78 std::string m_path;
79 SharedMemory m_memory;
80 MMutex m_mutex;
81 MCond m_cond;
82 Header* m_header;
83 int* m_buf;
84 unsigned int m_nword;
85
86 };
87
89}
90
91#endif
Abstract base class for different kinds of events.
STL namespace.