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