1 #include <daq/rfarm/event/hltsocket/HLTFile.h>
2 #include <framework/logging/Logger.h>
6 bool HLTFile::open(
const std::string& fileName,
bool raw,
const char* mode)
13 m_rfile = std::fopen(fileName.c_str(), mode);
15 B2ERROR(
"File opening failed! " << strerror(errno));
19 m_sfile.reset(
new SeqFile(fileName, mode));
20 if (m_sfile->status() <= 0) {
21 B2ERROR(
"File opening failed! " << strerror(errno));
36 int HLTFile::put(
char* data,
int len)
39 B2ERROR(
"Trying to write to a closed file");
41 const int bcount = m_sfile->write(data);
43 B2ERROR(
"Error in sending the data: " << strerror(errno));
46 B2ASSERT(
"Written buffer size != buffer size in data!", bcount == len);
50 int HLTFile::put_wordbuf(
int* data,
int len)
53 B2ERROR(
"Trying to write to a closed file!");
57 const int gcount = data[0];
58 B2ASSERT(
"The first entry in the data must be the buffer size!", gcount == len);
60 int bcount = std::fwrite(data,
sizeof(
char), len *
sizeof(
int), m_rfile);
62 B2ERROR(
"Error in writing the data: " << strerror(errno));
65 bcount = ((bcount - 1) /
sizeof(
int) + 1);
67 B2ASSERT(
"Written buffer size != buffer size in data!" << bcount <<
" " << len, bcount == len);
73 int HLTFile::get(
char* data,
int len)
75 const int bcount = m_sfile->read(data, len);
77 B2ERROR(
"Error in getting the data: " << strerror(errno));
83 int HLTFile::get_wordbuf(
int* wrdbuf,
int len)
86 B2ERROR(
"Trying to read from a closed file!");
89 int br = std::fread(wrdbuf,
sizeof(
int), 1, m_rfile);
91 if (std::feof(m_rfile)) {
94 B2ERROR(
"Error in getting the size: " << strerror(errno));
98 const int gcount = (wrdbuf[0] - 1);
100 B2ERROR(
"buffer too small! " << gcount <<
" < " << len);
104 const int bcount = std::fread(&wrdbuf[1],
sizeof(
int), gcount, m_rfile);
106 if (std::feof(m_rfile)) {
109 B2ERROR(
"Error in getting the data: " << strerror(errno));
113 B2ASSERT(
"Read buffer size != buffer size in data: " << bcount <<
" != " << gcount, bcount == gcount);