1 #include "daq/slc/readout/RunInfoBuffer.h"
3 #include <daq/slc/system/LogFile.h>
4 #include <daq/slc/system/LockGuard.h>
11 size_t RunInfoBuffer::size()
13 return m_mutex.size() + m_cond.size() +
17 bool RunInfoBuffer::open(
const std::string& nodename,
18 int nodeid,
bool recreate)
20 m_nodename = nodename;
21 std::string username = getenv(
"USER");
22 m_path =
"/run_info_" + username +
"_" + nodename;
23 if (!m_memory.open(m_path, size())) {
25 LogFile::fatal(
"Failed to open %s", m_path.c_str());
28 char* buf = (
char*)m_memory.map(0, size());
33 buf += m_mutex.size();
38 if (nodeid > 0) setNodeId(nodeid);
42 bool RunInfoBuffer::init()
44 if (m_info == NULL)
return false;
48 LogFile::debug(
"Initialized %s", m_path.c_str());
52 void RunInfoBuffer::clear()
54 if (m_info == NULL)
return;
59 bool RunInfoBuffer::close()
65 bool RunInfoBuffer::unlink()
72 bool RunInfoBuffer::lock()
74 if (m_info == NULL)
return false;
75 return m_mutex.lock();
78 bool RunInfoBuffer::unlock()
80 if (m_info == NULL)
return false;
81 return m_mutex.unlock();
84 bool RunInfoBuffer::wait()
86 if (m_info == NULL)
return false;
87 return m_cond.wait(m_mutex);
90 bool RunInfoBuffer::wait(
int time)
92 if (m_info == NULL)
return false;
93 return m_cond.wait(m_mutex, time, 0);
96 bool RunInfoBuffer::notify()
98 if (m_info == NULL)
return false;
99 return m_cond.broadcast();
102 bool RunInfoBuffer::waitRunning(
int timeout)
104 if (m_info == NULL)
return false;
106 if (getState() != RunInfoBuffer::RUNNING) {
107 if (!wait(timeout)) {
114 bool RunInfoBuffer::waitReady(
int timeout)
116 if (m_info == NULL)
return false;
118 if (getState() != RunInfoBuffer::READY &&
119 getState() != RunInfoBuffer::RUNNING) {
120 if (!wait(timeout)) {
121 if (getState() != RunInfoBuffer::READY &&
122 getState() != RunInfoBuffer::RUNNING) {
130 bool RunInfoBuffer::reportRunning()
132 if (m_info == NULL)
return false;
134 setState(RunInfoBuffer::RUNNING);
139 bool RunInfoBuffer::reportError(EFlag eflag)
141 if (m_info == NULL)
return false;
148 bool RunInfoBuffer::reportReady()
150 if (m_info == NULL)
return false;
152 setState(RunInfoBuffer::READY);
157 bool RunInfoBuffer::reportNotReady()
159 if (m_info == NULL)
return false;
161 setState(RunInfoBuffer::NOTREADY);
166 void RunInfoBuffer::copyEventHeader(
int* buf)
168 if (m_info == NULL)
return;