Belle II Software development
RunInfoBuffer Class Reference

Public Types

enum  State {
  NOTREADY = 0 ,
  READY = 1 ,
  RUNNING = 2 ,
  PAUSING = 3 ,
  PAUSED = 4 ,
  RESUMING = 5
}
 
enum  EFlag {
  NOERRO ,
  PROCESS_DOWN = 0x01 ,
  SOCKET_BIND = 0x02 ,
  SOCKET_IN = 0x04 ,
  SOCKET_OUT = 0x08 ,
  EVENTFORMAT = 0x10 ,
  CPRFIFO_EMPTY = 0x20 ,
  CPRFIFO_FULL = 0x40 ,
  CPRFIFO_LEF_FULL = 0x80
}
 

Public Member Functions

size_t size ()
 
bool open (const std::string &nodename, int nodeid=0, bool recreate=false)
 
bool init ()
 
bool close ()
 
bool unlink ()
 
bool lock ()
 
bool unlock ()
 
bool wait ()
 
bool wait (int time)
 
bool notify ()
 
void clear ()
 
const std::string getName () const
 
const std::string getPath () const
 
bool isAvailable () const
 
ronode_infoget ()
 
unsigned int getNodeId () const
 
unsigned int getState () const
 
unsigned int getErrorFlag () const
 
unsigned int getExpNumber () const
 
unsigned int getRunNumber () const
 
unsigned int getSubNumber () const
 
int getInputPort () const
 
int getInputAddress () const
 
unsigned int getInputCount () const
 
unsigned long long getInputNBytes () const
 
int getOutputPort () const
 
int getOutputAddress () const
 
unsigned int getOutputCount () const
 
unsigned long long getOutputNBytes () const
 
void setNodeId (unsigned int id)
 
void setState (State state)
 
void setErrorFlag (EFlag eflag)
 
void setExpNumber (unsigned int expno)
 
void setRunNumber (unsigned int runno)
 
void setSubNumber (unsigned int subno)
 
void setInputPort (int port)
 
void setInputAddress (int addr)
 
void setInputCount (unsigned int count)
 
void setInputNBytes (unsigned long long nbyte)
 
void addInputCount (unsigned int count)
 
void addInputNBytes (unsigned long long nbyte)
 
void setOutputPort (int port)
 
void setOutputAddress (int addr)
 
void setOutputCount (unsigned int count)
 
void setOutputNBytes (unsigned long long nbyte)
 
void addOutputCount (unsigned int count)
 
void addOutputNBytes (unsigned long long nbyte)
 
event_headergetEventHeader ()
 
void copyEventHeader (int *buf)
 
bool isNotReady ()
 
bool isReady ()
 
bool isRunning ()
 
bool isPausing ()
 
bool isPaused ()
 
bool isResuming ()
 
bool waitRunning (int timeout)
 
bool waitReady (int timeout)
 
bool reportRunning ()
 
bool reportError (EFlag eflag)
 
bool reportReady ()
 
bool reportNotReady ()
 

Private Attributes

std::string m_nodename
 
std::string m_path
 
SharedMemory m_memory
 
ronode_infom_info
 
MMutex m_mutex
 
MCond m_cond
 

Detailed Description

Definition at line 22 of file RunInfoBuffer.h.

Member Enumeration Documentation

◆ EFlag

enum EFlag

Definition at line 35 of file RunInfoBuffer.h.

35 {
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 };

◆ State

enum State

Definition at line 25 of file RunInfoBuffer.h.

25 {
26 NOTREADY = 0,
27 READY = 1,
28 RUNNING = 2,
29 PAUSING = 3,
30 PAUSED = 4,
31 RESUMING = 5
32 };

Constructor & Destructor Documentation

◆ RunInfoBuffer()

RunInfoBuffer ( )
inline

Definition at line 48 of file RunInfoBuffer.h.

49 {
50 m_info = NULL;
51 }

◆ ~RunInfoBuffer()

~RunInfoBuffer ( )
inline

Definition at line 52 of file RunInfoBuffer.h.

52{}

Member Function Documentation

◆ addInputCount()

void addInputCount ( unsigned int  count)
inline

Definition at line 97 of file RunInfoBuffer.h.

97{ m_info->io[0].count += count; }

◆ addInputNBytes()

void addInputNBytes ( unsigned long long  nbyte)
inline

Definition at line 98 of file RunInfoBuffer.h.

98{ m_info->io[0].nbyte += nbyte; }

◆ addOutputCount()

void addOutputCount ( unsigned int  count)
inline

Definition at line 103 of file RunInfoBuffer.h.

103{ m_info->io[1].count += count; }

◆ addOutputNBytes()

void addOutputNBytes ( unsigned long long  nbyte)
inline

Definition at line 104 of file RunInfoBuffer.h.

104{ m_info->io[1].nbyte += nbyte; }

◆ clear()

void clear ( )

Definition at line 59 of file RunInfoBuffer.cc.

60{
61 if (m_info == NULL) return;
62 MLockGuard lockGuard(m_mutex);
63 memset(m_info, 0, sizeof(ronode_info));
64}
Lock Guard for a Mutex instance.
Definition: LockGuard.h:47

◆ close()

bool close ( )

Definition at line 66 of file RunInfoBuffer.cc.

67{
68 m_memory.close();
69 return true;
70}

◆ copyEventHeader()

void copyEventHeader ( int *  buf)

Definition at line 173 of file RunInfoBuffer.cc.

174{
175 if (m_info == NULL) return;
176 memcpy(&(m_info->header), buf, sizeof(event_header));
177}

◆ get()

ronode_info * get ( )
inline

Definition at line 72 of file RunInfoBuffer.h.

72{ return m_info; }

◆ getErrorFlag()

unsigned int getErrorFlag ( ) const
inline

Definition at line 75 of file RunInfoBuffer.h.

75{ return m_info->eflag; }

◆ getEventHeader()

event_header & getEventHeader ( )
inline

Definition at line 105 of file RunInfoBuffer.h.

105{ return m_info->header; }

◆ getExpNumber()

unsigned int getExpNumber ( ) const
inline

Definition at line 76 of file RunInfoBuffer.h.

76{ return m_info->expno; }

◆ getInputAddress()

int getInputAddress ( ) const
inline

Definition at line 80 of file RunInfoBuffer.h.

80{ return m_info->io[0].addr; }

◆ getInputCount()

unsigned int getInputCount ( ) const
inline

Definition at line 81 of file RunInfoBuffer.h.

81{ return m_info->io[0].count; }

◆ getInputNBytes()

unsigned long long getInputNBytes ( ) const
inline

Definition at line 82 of file RunInfoBuffer.h.

82{ return m_info->io[0].nbyte; }

◆ getInputPort()

int getInputPort ( ) const
inline

Definition at line 79 of file RunInfoBuffer.h.

79{ return m_info->io[0].port; }

◆ getName()

const std::string getName ( ) const
inline

Definition at line 69 of file RunInfoBuffer.h.

69{ return m_nodename; }

◆ getNodeId()

unsigned int getNodeId ( ) const
inline

Definition at line 73 of file RunInfoBuffer.h.

73{ return m_info->nodeid; }

◆ getOutputAddress()

int getOutputAddress ( ) const
inline

Definition at line 84 of file RunInfoBuffer.h.

84{ return m_info->io[1].addr; }

◆ getOutputCount()

unsigned int getOutputCount ( ) const
inline

Definition at line 85 of file RunInfoBuffer.h.

85{ return m_info->io[1].count; }

◆ getOutputNBytes()

unsigned long long getOutputNBytes ( ) const
inline

Definition at line 86 of file RunInfoBuffer.h.

86{ return m_info->io[1].nbyte; }

◆ getOutputPort()

int getOutputPort ( ) const
inline

Definition at line 83 of file RunInfoBuffer.h.

83{ return m_info->io[1].port; }

◆ getPath()

const std::string getPath ( ) const
inline

Definition at line 70 of file RunInfoBuffer.h.

70{ return m_path; }

◆ getRunNumber()

unsigned int getRunNumber ( ) const
inline

Definition at line 77 of file RunInfoBuffer.h.

77{ return m_info->runno; }

◆ getState()

unsigned int getState ( ) const
inline

Definition at line 74 of file RunInfoBuffer.h.

74{ return m_info->state; }

◆ getSubNumber()

unsigned int getSubNumber ( ) const
inline

Definition at line 78 of file RunInfoBuffer.h.

78{ return m_info->subno; }

◆ init()

bool init ( )

Definition at line 49 of file RunInfoBuffer.cc.

50{
51 if (m_info == NULL) return false;
52 m_mutex.init();
53 m_cond.init();
54 memset(m_info, 0, sizeof(ronode_info));
55 LogFile::debug("Initialized %s", m_path.c_str());
56 return true;
57}

◆ isAvailable()

bool isAvailable ( ) const
inline

Definition at line 71 of file RunInfoBuffer.h.

71{ return m_info != NULL; }

◆ isNotReady()

bool isNotReady ( )
inline

Definition at line 107 of file RunInfoBuffer.h.

107{ return (m_info) && m_info->state == NOTREADY; }

◆ isPaused()

bool isPaused ( )
inline

Definition at line 111 of file RunInfoBuffer.h.

111{ return (m_info) && m_info->state == PAUSED; }

◆ isPausing()

bool isPausing ( )
inline

Definition at line 110 of file RunInfoBuffer.h.

110{ return (m_info) && m_info->state == PAUSING; }

◆ isReady()

bool isReady ( )
inline

Definition at line 108 of file RunInfoBuffer.h.

108{ return (m_info) && m_info->state == READY; }

◆ isResuming()

bool isResuming ( )
inline

Definition at line 112 of file RunInfoBuffer.h.

112{ return (m_info) && m_info->state == RESUMING; }

◆ isRunning()

bool isRunning ( )
inline

Definition at line 109 of file RunInfoBuffer.h.

109{ return (m_info) && m_info->state == RUNNING; }

◆ lock()

bool lock ( )

Definition at line 79 of file RunInfoBuffer.cc.

80{
81 if (m_info == NULL) return false;
82 return m_mutex.lock();
83}

◆ notify()

bool notify ( )

Definition at line 103 of file RunInfoBuffer.cc.

104{
105 if (m_info == NULL) return false;
106 return m_cond.broadcast();
107}

◆ open()

bool open ( const std::string &  nodename,
int  nodeid = 0,
bool  recreate = false 
)

Definition at line 24 of file RunInfoBuffer.cc.

26{
27 m_nodename = nodename;
28 std::string username = getenv("USER");
29 m_path = "/run_info_" + username + "_" + nodename;
30 if (!m_memory.open(m_path, size())) {
31 perror("shm_open");
32 LogFile::fatal("Failed to open %s", m_path.c_str());
33 return false;
34 }
35 char* buf = (char*)m_memory.map(0, size());
36 if (buf == NULL) {
37 return false;
38 }
39 m_mutex = MMutex(buf);
40 buf += m_mutex.size();
41 m_cond = MCond(buf);
42 buf += m_cond.size();
43 m_info = (ronode_info*)buf;
44 if (recreate) init();
45 if (nodeid > 0) setNodeId(nodeid);
46 return true;
47}

◆ reportError()

bool reportError ( EFlag  eflag)

Definition at line 146 of file RunInfoBuffer.cc.

147{
148 if (m_info == NULL) return false;
149 MLockGuard lockGuard(m_mutex);
150 setErrorFlag(eflag);
151 notify();
152 return true;
153}

◆ reportNotReady()

bool reportNotReady ( )

Definition at line 164 of file RunInfoBuffer.cc.

165{
166 if (m_info == NULL) return false;
167 MLockGuard lockGuard(m_mutex);
168 setState(RunInfoBuffer::NOTREADY);
169 notify();
170 return true;
171}

◆ reportReady()

bool reportReady ( )

Definition at line 155 of file RunInfoBuffer.cc.

156{
157 if (m_info == NULL) return false;
158 MLockGuard lockGuard(m_mutex);
159 setState(RunInfoBuffer::READY);
160 notify();
161 return true;
162}

◆ reportRunning()

bool reportRunning ( )

Definition at line 137 of file RunInfoBuffer.cc.

138{
139 if (m_info == NULL) return false;
140 MLockGuard lockGuard(m_mutex);
141 setState(RunInfoBuffer::RUNNING);
142 notify();
143 return true;
144}

◆ setErrorFlag()

void setErrorFlag ( EFlag  eflag)
inline

Definition at line 89 of file RunInfoBuffer.h.

89{ m_info->eflag = (unsigned int)eflag; }

◆ setExpNumber()

void setExpNumber ( unsigned int  expno)
inline

Definition at line 90 of file RunInfoBuffer.h.

90{ m_info->expno = expno; }

◆ setInputAddress()

void setInputAddress ( int  addr)
inline

Definition at line 94 of file RunInfoBuffer.h.

94{ m_info->io[0].addr = addr; }

◆ setInputCount()

void setInputCount ( unsigned int  count)
inline

Definition at line 95 of file RunInfoBuffer.h.

95{ m_info->io[0].count = count; }

◆ setInputNBytes()

void setInputNBytes ( unsigned long long  nbyte)
inline

Definition at line 96 of file RunInfoBuffer.h.

96{ m_info->io[0].nbyte = nbyte; }

◆ setInputPort()

void setInputPort ( int  port)
inline

Definition at line 93 of file RunInfoBuffer.h.

93{ m_info->io[0].port = port; }

◆ setNodeId()

void setNodeId ( unsigned int  id)
inline

Definition at line 87 of file RunInfoBuffer.h.

87{ m_info->nodeid = id; }

◆ setOutputAddress()

void setOutputAddress ( int  addr)
inline

Definition at line 100 of file RunInfoBuffer.h.

100{ m_info->io[1].addr = addr; }

◆ setOutputCount()

void setOutputCount ( unsigned int  count)
inline

Definition at line 101 of file RunInfoBuffer.h.

101{ m_info->io[1].count = count; }

◆ setOutputNBytes()

void setOutputNBytes ( unsigned long long  nbyte)
inline

Definition at line 102 of file RunInfoBuffer.h.

102{ m_info->io[1].nbyte = nbyte; }

◆ setOutputPort()

void setOutputPort ( int  port)
inline

Definition at line 99 of file RunInfoBuffer.h.

99{ m_info->io[1].port = port; }

◆ setRunNumber()

void setRunNumber ( unsigned int  runno)
inline

Definition at line 91 of file RunInfoBuffer.h.

91{ m_info->runno = runno; }

◆ setState()

void setState ( State  state)
inline

Definition at line 88 of file RunInfoBuffer.h.

88{ m_info->state = (unsigned int)state; }

◆ setSubNumber()

void setSubNumber ( unsigned int  subno)
inline

Definition at line 92 of file RunInfoBuffer.h.

92{ m_info->subno = subno; }

◆ size()

size_t size ( )

Definition at line 18 of file RunInfoBuffer.cc.

19{
20 return m_mutex.size() + m_cond.size() +
21 sizeof(ronode_info);
22}

◆ unlink()

bool unlink ( )

Definition at line 72 of file RunInfoBuffer.cc.

73{
74 m_memory.unlink();
75 m_memory.close();
76 return true;
77}

◆ unlock()

bool unlock ( )

Definition at line 85 of file RunInfoBuffer.cc.

86{
87 if (m_info == NULL) return false;
88 return m_mutex.unlock();
89}

◆ wait() [1/2]

bool wait ( )

Definition at line 91 of file RunInfoBuffer.cc.

92{
93 if (m_info == NULL) return false;
94 return m_cond.wait(m_mutex);
95}

◆ wait() [2/2]

bool wait ( int  time)

Definition at line 97 of file RunInfoBuffer.cc.

98{
99 if (m_info == NULL) return false;
100 return m_cond.wait(m_mutex, time, 0);
101}

◆ waitReady()

bool waitReady ( int  timeout)

Definition at line 121 of file RunInfoBuffer.cc.

122{
123 if (m_info == NULL) return false;
124 MLockGuard lockGuard(m_mutex);
125 if (getState() != RunInfoBuffer::READY &&
126 getState() != RunInfoBuffer::RUNNING) {
127 if (!wait(timeout)) {
128 if (getState() != RunInfoBuffer::READY &&
129 getState() != RunInfoBuffer::RUNNING) {
130 return false;
131 }
132 }
133 }
134 return true;
135}

◆ waitRunning()

bool waitRunning ( int  timeout)

Definition at line 109 of file RunInfoBuffer.cc.

110{
111 if (m_info == NULL) return false;
112 MLockGuard lockGuard(m_mutex);
113 if (getState() != RunInfoBuffer::RUNNING) {
114 if (!wait(timeout)) {
115 return false;
116 }
117 }
118 return true;
119}

Member Data Documentation

◆ m_cond

MCond m_cond
private

Definition at line 127 of file RunInfoBuffer.h.

◆ m_info

ronode_info* m_info
private

Definition at line 125 of file RunInfoBuffer.h.

◆ m_memory

SharedMemory m_memory
private

Definition at line 124 of file RunInfoBuffer.h.

◆ m_mutex

MMutex m_mutex
private

Definition at line 126 of file RunInfoBuffer.h.

◆ m_nodename

std::string m_nodename
private

Definition at line 122 of file RunInfoBuffer.h.

◆ m_path

std::string m_path
private

Definition at line 123 of file RunInfoBuffer.h.


The documentation for this class was generated from the following files: