Belle II Software  release-05-02-19
RunInfoBuffer.h
1 #ifndef _Belle2_RunInfoBuffer_h
2 #define _Belle2_RunInfoBuffer_h
3 
4 #include "daq/slc/system/SharedMemory.h"
5 #include "daq/slc/system/MMutex.h"
6 #include "daq/slc/system/MCond.h"
7 #include "daq/slc/readout/ronode_info.h"
8 
9 namespace Belle2 {
15  class RunInfoBuffer {
16 
17  public:
18  enum State {
19  NOTREADY = 0,
20  READY = 1,
21  RUNNING = 2,
22  PAUSING = 3,
23  PAUSED = 4,
24  RESUMING = 5
25  };
26 
27  public:
28  enum EFlag {
29  NOERRO,
30  PROCESS_DOWN = 0x01,
31  SOCKET_BIND = 0x02,
32  SOCKET_IN = 0x04,
33  SOCKET_OUT = 0x08,
34  EVENTFORMAT = 0x10,
35  CPRFIFO_EMPTY = 0x20,
36  CPRFIFO_FULL = 0x40,
37  CPRFIFO_LEF_FULL = 0x80
38  };
39 
40  public:
42  {
43  m_info = NULL;
44  }
45  ~RunInfoBuffer() {}
46 
47  public:
48  size_t size() ;
49  bool open(const std::string& nodename,
50  int nodeid = 0, bool recreate = false);
51  bool init();
52  bool close();
53  bool unlink();
54  bool lock() ;
55  bool unlock() ;
56  bool wait() ;
57  bool wait(int time) ;
58  bool notify() ;
59  void clear();
60 
61  public:
62  const std::string getName() const { return m_nodename; }
63  const std::string getPath() const { return m_path; }
64  bool isAvailable() const { return m_info != NULL; }
65  ronode_info* get() { return m_info; }
66  unsigned int getNodeId() const { return m_info->nodeid; }
67  unsigned int getState() const { return m_info->state; }
68  unsigned int getErrorFlag() const { return m_info->eflag; }
69  unsigned int getExpNumber() const { return m_info->expno; }
70  unsigned int getRunNumber() const { return m_info->runno; }
71  unsigned int getSubNumber() const { return m_info->subno; }
72  int getInputPort() const { return m_info->io[0].port; }
73  int getInputAddress() const { return m_info->io[0].addr; }
74  unsigned int getInputCount() const { return m_info->io[0].count; }
75  unsigned long long getInputNBytes() const { return m_info->io[0].nbyte; }
76  int getOutputPort() const { return m_info->io[1].port; }
77  int getOutputAddress() const { return m_info->io[1].addr; }
78  unsigned int getOutputCount() const { return m_info->io[1].count; }
79  unsigned long long getOutputNBytes() const { return m_info->io[1].nbyte; }
80  void setNodeId(unsigned int id) { m_info->nodeid = id; }
81  void setState(State state) { m_info->state = (unsigned int)state; }
82  void setErrorFlag(EFlag eflag) { m_info->eflag = (unsigned int)eflag; }
83  void setExpNumber(unsigned int expno) { m_info->expno = expno; }
84  void setRunNumber(unsigned int runno) { m_info->runno = runno; }
85  void setSubNumber(unsigned int subno) { m_info->subno = subno; }
86  void setInputPort(int port) { m_info->io[0].port = port; }
87  void setInputAddress(int addr) { m_info->io[0].addr = addr; }
88  void setInputCount(unsigned int count) { m_info->io[0].count = count; }
89  void setInputNBytes(unsigned long long nbyte) { m_info->io[0].nbyte = nbyte; }
90  void addInputCount(unsigned int count) { m_info->io[0].count += count; }
91  void addInputNBytes(unsigned long long nbyte) { m_info->io[0].nbyte += nbyte; }
92  void setOutputPort(int port) { m_info->io[1].port = port; }
93  void setOutputAddress(int addr) { m_info->io[1].addr = addr; }
94  void setOutputCount(unsigned int count) { m_info->io[1].count = count; }
95  void setOutputNBytes(unsigned long long nbyte) { m_info->io[1].nbyte = nbyte; }
96  void addOutputCount(unsigned int count) { m_info->io[1].count += count; }
97  void addOutputNBytes(unsigned long long nbyte) { m_info->io[1].nbyte += nbyte; }
98  event_header& getEventHeader() { return m_info->header; }
99  void copyEventHeader(int* buf);
100  bool isNotReady() { return (m_info) && m_info->state == NOTREADY; }
101  bool isReady() { return (m_info) && m_info->state == READY; }
102  bool isRunning() { return (m_info) && m_info->state == RUNNING; }
103  bool isPausing() { return (m_info) && m_info->state == PAUSING; }
104  bool isPaused() { return (m_info) && m_info->state == PAUSED; }
105  bool isResuming() { return (m_info) && m_info->state == RESUMING; }
106 
107  bool waitRunning(int timeout);
108  bool waitReady(int timeout);
109  bool reportRunning();
110  bool reportError(EFlag eflag);
111  bool reportReady();
112  bool reportNotReady();
113 
114  private:
115  std::string m_nodename;
116  std::string m_path;
117  SharedMemory m_memory;
118  ronode_info* m_info;
119  MMutex m_mutex;
120  MCond m_cond;
121 
122  };
123 
125 }
126 
127 #endif
Belle2::event_header
Definition: ronode_info.h:12
Belle2::RunInfoBuffer
Definition: RunInfoBuffer.h:15
Belle2::MMutex
Definition: MMutex.h:19
Belle2::MCond
Definition: MCond.h:14
Belle2::SharedMemory
Definition: SharedMemory.h:12
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ronode_info
Definition: ronode_info.h:23