9#include <pxd/unpacking/PXDLocalDAQFile.h>
10#include <framework/logging/Logger.h>
16#include <boost/iostreams/device/file_descriptor.hpp>
17#include <boost/iostreams/filter/bzip2.hpp>
18#include <boost/iostreams/filtering_stream.hpp>
19#include <boost/format.hpp>
23namespace io = boost::iostreams;
28 if (filename.empty()) {
29 B2ERROR(
"PXDLocalDAQFile: Empty filename given");
33 m_compressed = filename.size() > 4 && filename.compare(filename.size() - 4, 4,
".bz2") == 0;
38 B2WARNING(
"PXDLocalDAQFile: error opening '" << filename <<
"': " << strerror(errno)
39 <<
", trying again with '.bz2'");
45 B2ERROR(
"PXDLocalDAQFile: error opening '" << filename <<
"': " << strerror(errno));
47 B2INFO(
"PXDLocalDAQFile: " <<
m_filename <<
" opened (fd=" <<
m_fd <<
")");
56 m_fd = open(filename.c_str(), O_RDONLY);
57 auto*
filter =
new io::filtering_istream();
59 filter->push(io::file_descriptor_source(
m_fd, io::close_handle));
60 filter->exceptions(ios_base::badbit | ios_base::failbit);
67 B2INFO(
"Closing PXDLocalDAQFile ");
79 auto in =
dynamic_cast<std::istream*
>(
m_stream.get());
81 B2FATAL(
"PXDLocalDAQFile::read() cannot get input file");
86 }
catch (ios_base::failure& e) {
87 B2ERROR(
"PXDLocalDAQFile::read() cannot read file: " << e.what());
92 B2DEBUG(29,
"PXDLocalDAQFile::read() eof");
99 }
catch (ios_base::failure& e) {
100 B2ERROR(
"PXDLocalDAQFile::read() " << e.what() <<
": could only read " << in->gcount() <<
" bytes, expected " << size);
109 size_t l =
read(data, len);
110 if (l != len)
return 0;
~PXDLocalDAQFile()
Destructor.
int read_data(char *data, size_t len)
Read a record from a file.
void openFile(std::string filename)
actually open the file
std::unique_ptr< std::ios > m_stream
pointer to the filtering input or output stream
bool m_compressed
is file bzip2 compressed?
int status() const
Returns status after constructor call.
std::string m_filename
Name of the opened file.
PXDLocalDAQFile(const std::string &filename)
Constructor.
int read(char *buf, int max)
Read a record from a file.
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double > > &runs, double cut, std::map< ExpRun, std::pair< double, double > > &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Abstract base class for different kinds of events.