Belle II Software development
HLTFile Class Reference

Public Member Functions

bool open (const std::string &fileName, bool raw, const char *mode)
 
int put_wordbuf (int *data, int len)
 
int put (char *data, int len)
 
int get_wordbuf (int *data, int len)
 
int get (char *data, int len)
 

Private Attributes

std::unique_ptr< SeqFilem_sfile
 
FILE * m_rfile = nullptr
 

Detailed Description

Definition at line 18 of file HLTFile.h.

Constructor & Destructor Documentation

◆ ~HLTFile()

~HLTFile ( )
virtual

Definition at line 36 of file HLTFile.cc.

37{
38 if (m_rfile) {
39 fclose(m_rfile);
40 }
41}

Member Function Documentation

◆ get()

int get ( char *  data,
int  len 
)

Definition at line 80 of file HLTFile.cc.

81{
82 const int bcount = m_sfile->read(data, len);
83 if (bcount <= 0) {
84 B2ERROR("Error in getting the data: " << strerror(errno));
85 return bcount;
86 }
87 return bcount;
88}

◆ get_wordbuf()

int get_wordbuf ( int *  data,
int  len 
)

Definition at line 90 of file HLTFile.cc.

91{
92 if (not m_rfile) {
93 B2ERROR("Trying to read from a closed file!");
94 return -1;
95 }
96 int br = std::fread(wrdbuf, sizeof(int), 1, m_rfile);
97 if (br <= 0) {
98 if (std::feof(m_rfile)) {
99 return 0;
100 }
101 B2ERROR("Error in getting the size: " << strerror(errno));
102 return br;
103 }
104
105 const int gcount = (wrdbuf[0] - 1);
106 if (gcount > len) {
107 B2ERROR("buffer too small! " << gcount << " < " << len);
108 return -1;
109 }
110 // ATTENTION: the send size is size / 4
111 const int bcount = std::fread(&wrdbuf[1], sizeof(int), gcount, m_rfile);
112 if (bcount <= 0) {
113 if (std::feof(m_rfile)) {
114 return 0;
115 }
116 B2ERROR("Error in getting the data: " << strerror(errno));
117 return bcount;
118 }
119
120 B2ASSERT("Read buffer size != buffer size in data: " << bcount << " != " << gcount, bcount == gcount);
121 return (wrdbuf[0]);
122}

◆ open()

bool open ( const std::string &  fileName,
bool  raw,
const char *  mode 
)

Definition at line 13 of file HLTFile.cc.

14{
15 if (m_rfile) {
16 fclose(m_rfile);
17 }
18
19 if (raw) {
20 m_rfile = std::fopen(fileName.c_str(), mode);
21 if (!m_rfile) {
22 B2ERROR("File opening failed! " << strerror(errno));
23 return false;
24 }
25 } else {
26 m_sfile.reset(new SeqFile(fileName, mode));
27 if (m_sfile->status() <= 0) {
28 B2ERROR("File opening failed! " << strerror(errno));
29 return false;
30 }
31 }
32
33 return true;
34}
A class to manage I/O for a chain of blocked files.
Definition: SeqFile.h:22

◆ put()

int put ( char *  data,
int  len 
)

Definition at line 43 of file HLTFile.cc.

44{
45 if (not m_sfile) {
46 B2ERROR("Trying to write to a closed file");
47 }
48 const int bcount = m_sfile->write(data);
49 if (bcount <= 0) {
50 B2ERROR("Error in sending the data: " << strerror(errno));
51 return bcount;
52 }
53 B2ASSERT("Written buffer size != buffer size in data!", bcount == len);
54 return bcount;
55}

◆ put_wordbuf()

int put_wordbuf ( int *  data,
int  len 
)

Definition at line 57 of file HLTFile.cc.

58{
59 if (not m_rfile) {
60 B2ERROR("Trying to write to a closed file!");
61 return -1;
62 }
63
64 const int gcount = data[0];
65 B2ASSERT("The first entry in the data must be the buffer size!", gcount == len);
66
67 int bcount = std::fwrite(data, sizeof(char), len * sizeof(int), m_rfile);
68 if (bcount <= 0) {
69 B2ERROR("Error in writing the data: " << strerror(errno));
70 return bcount;
71 }
72 bcount = ((bcount - 1) / sizeof(int) + 1);
73
74 B2ASSERT("Written buffer size != buffer size in data!" << bcount << " " << len, bcount == len);
75
76 // ATTENTION: the returned size is size / 4
77 return bcount;
78}

Member Data Documentation

◆ m_rfile

FILE* m_rfile = nullptr
private

Definition at line 30 of file HLTFile.h.

◆ m_sfile

std::unique_ptr<SeqFile> m_sfile
private

Definition at line 29 of file HLTFile.h.


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