8#include <daq/rfarm/event/hltsocket/HLTFile.h>
9#include <framework/logging/Logger.h>
13bool HLTFile::open(
const std::string& fileName,
bool raw,
const char* mode)
20 m_rfile = std::fopen(fileName.c_str(), mode);
22 B2ERROR(
"File opening failed! " << strerror(errno));
26 m_sfile.reset(
new SeqFile(fileName, mode));
27 if (m_sfile->status() <= 0) {
28 B2ERROR(
"File opening failed! " << strerror(errno));
43int HLTFile::put(
char* data,
int len)
46 B2ERROR(
"Trying to write to a closed file");
48 const int bcount = m_sfile->write(data);
50 B2ERROR(
"Error in sending the data: " << strerror(errno));
53 B2ASSERT(
"Written buffer size != buffer size in data!", bcount == len);
57int HLTFile::put_wordbuf(
int* data,
int len)
60 B2ERROR(
"Trying to write to a closed file!");
64 const int gcount = data[0];
65 B2ASSERT(
"The first entry in the data must be the buffer size!", gcount == len);
67 int bcount = std::fwrite(data,
sizeof(
char), len *
sizeof(
int), m_rfile);
69 B2ERROR(
"Error in writing the data: " << strerror(errno));
72 bcount = ((bcount - 1) /
sizeof(
int) + 1);
74 B2ASSERT(
"Written buffer size != buffer size in data!" << bcount <<
" " << len, bcount == len);
80int HLTFile::get(
char* data,
int len)
82 const int bcount = m_sfile->read(data, len);
84 B2ERROR(
"Error in getting the data: " << strerror(errno));
90int HLTFile::get_wordbuf(
int* wrdbuf,
int len)
93 B2ERROR(
"Trying to read from a closed file!");
96 int br = std::fread(wrdbuf,
sizeof(
int), 1, m_rfile);
98 if (std::feof(m_rfile)) {
101 B2ERROR(
"Error in getting the size: " << strerror(errno));
105 const int gcount = (wrdbuf[0] - 1);
107 B2ERROR(
"buffer too small! " << gcount <<
" < " << len);
111 const int bcount = std::fread(&wrdbuf[1],
sizeof(
int), gcount, m_rfile);
113 if (std::feof(m_rfile)) {
116 B2ERROR(
"Error in getting the data: " << strerror(errno));
120 B2ASSERT(
"Read buffer size != buffer size in data: " << bcount <<
" != " << gcount, bcount == gcount);
A class to manage I/O for a chain of blocked files.
Abstract base class for different kinds of events.