Belle II Software  release-08-01-10
PXDLocalDAQFile Class Reference

A class to manage I/O for a chain of blocked files. More...

#include <PXDLocalDAQFile.h>

Collaboration diagram for PXDLocalDAQFile:

Public Member Functions

 PXDLocalDAQFile (const std::string &filename)
 Constructor.
 
 ~PXDLocalDAQFile ()
 Destructor.
 
 PXDLocalDAQFile (const PXDLocalDAQFile &)=delete
 No copying.
 
PXDLocalDAQFileoperator= (const PXDLocalDAQFile &)=delete
 No assignment.
 
int status () const
 Returns status after constructor call. More...
 
int read (char *buf, int max)
 Read a record from a file. More...
 
int read_data (char *data, size_t len)
 Read a record from a file. More...
 

Private Member Functions

void openFile (std::string filename)
 actually open the file
 

Private Attributes

std::string m_filename
 Name of the opened file.
 
int m_fd { -1}
 file descriptor.
 
bool m_compressed {false}
 is file bzip2 compressed?
 
std::unique_ptr< std::ios > m_stream
 pointer to the filtering input or output stream
 

Detailed Description

A class to manage I/O for a chain of blocked files.

Definition at line 22 of file PXDLocalDAQFile.h.

Member Function Documentation

◆ read()

int read ( char *  buf,
int  max 
)

Read a record from a file.

Returns the data size read.

Definition at line 76 of file PXDLocalDAQFile.cc.

77 {
78  // cast stream object
79  auto in = dynamic_cast<std::istream*>(m_stream.get());
80  if (!in) {
81  B2FATAL("PXDLocalDAQFile::read() cannot get input file");
82  }
83  //trigger eof if there's nothing left int the file. Could throw an error on decompress failure
84  try {
85  in->peek();
86  } catch (ios_base::failure& e) {
87  B2ERROR("PXDLocalDAQFile::read() cannot read file: " << e.what());
88  return -1;
89  }
90  // return -1 if eof
91  if (in->eof()) {
92  B2DEBUG(29, "PXDLocalDAQFile::read() eof");
93  return -1;
94  }
95 
96  // read from file
97  try {
98  in->read(buf, size);
99  } catch (ios_base::failure& e) {
100  B2ERROR("PXDLocalDAQFile::read() " << e.what() << ": could only read " << in->gcount() << " bytes, expected " << size);
101  return -1;
102  }
103 
104  return in->gcount();
105 }
std::unique_ptr< std::ios > m_stream
pointer to the filtering input or output stream

◆ read_data()

int read_data ( char *  data,
size_t  len 
)

Read a record from a file.

Returns the data size if successfully read, otherwise 0.

Definition at line 107 of file PXDLocalDAQFile.cc.

◆ status()

int status ( ) const

Returns status after constructor call.

If success, fd is returned. If not, -1

Definition at line 71 of file PXDLocalDAQFile.cc.


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