LDMX Software
|
Reading a raw data file. More...
#include <Reader.h>
Public Member Functions | |
Reader () | |
default constructor | |
void | open (const std::string &file_name) |
Open a file with this reader. | |
Reader (const std::string &file_name) | |
Constructor that also opens the input file. | |
~Reader ()=default | |
destructor, close the input file stream | |
void | seek (int off, std::ios_base::seekdir dir=std::ios::beg) |
Go ("seek") a specific position in the file. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
void | seek (int off, std::ios_base::seekdir dir=std::ios::beg) |
Seek by number of words. | |
int | tell () |
Tell us where the reader is. | |
template<typename WordType > | |
int | tell () |
Tell by number of words. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Reader & | read (WordType *w, std::size_t count) |
Read the next 'count' words into the input handle. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Reader & | operator>> (WordType &w) |
Stream the next word into the input handle. | |
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true> | |
Reader & | operator>> (ObjectType &o) |
Stream into a class object. | |
template<typename ContentType > | |
Reader & | read (std::vector< ContentType > &vec, std::size_t count) |
Read the next 'count' objects into the input vector. | |
bool | operator! () const |
Check if reader is in a fail state. | |
operator bool () const | |
Check if reader is in good/bad state. | |
bool | eof () |
check if file is done | |
Private Attributes | |
std::ifstream | file_ |
file stream we are reading from | |
std::size_t | file_size_ |
file size in bytes | |
Reading a raw data file.
We wrap a basic std::ifstream in order to make the retrieving of specific-width words easier for ourselves.
|
inline |
default constructor
We make sure that our input file stream will not skip white space.
Definition at line 26 of file Reader.h.
References file_.
|
inline |
Constructor that also opens the input file.
[in] | file_name | full path to the file we are going to open |
Definition at line 47 of file Reader.h.
References open().
|
inline |
check if file is done
Just calls the underlying ifstream eof.
Definition at line 214 of file Reader.h.
References file_, and file_size_.
Referenced by hcal::HcalRawDecoder::produce(), and packing::SingleSubsystemUnpacker::produce().
|
inline |
Open a file with this reader.
We open the file as an input, binary file.
[in] | file_name | full path to the file we are going to open |
Definition at line 35 of file Reader.h.
References file_, and file_size_.
Referenced by packing::FiberTrackerRawDecoder::configure(), packing::WRRawDecoder::configure(), hcal::HcalRawDecoder::configure(), packing::SingleSubsystemUnpacker::configure(), packing::rawdatafile::File::File(), and Reader().
|
inline |
Check if reader is in good/bad state.
Following the C++ reference, we pass-along the check on if our ifstream is in a fail state.
Defining this operator allows us to do the following.
Reader r('dummy.raw') if (r) { std::cout << "dummy.raw was opened good" << std::endl; }
Definition at line 205 of file Reader.h.
References file_.
|
inline |
|
inline |
Stream into a class object.
We assume that the class we are streaming to has a specific method defined.
Reader& read(Reader&)
This can be satisfied by the classes that we own and operate.
in] ObjectType class type to read
[in] | o | instance of object to read into |
Definition at line 152 of file Reader.h.
References read().
|
inline |
Stream the next word into the input handle.
This implementation of the stream operator is only available to handles of integral types. Helps for shorthand of only grabbing a single word from the reader.
in] WordType integral-type word to read out
[in] | w | reference to word to read into |
Definition at line 133 of file Reader.h.
References read().
|
inline |
Read the next 'count' objects into the input vector.
This is common enough, I wanted to specialize the read function.
The std::vector::resize is helpful for avoiding additional copies while the vector is being expanded. After allocating the space for each entry in the vector, we call the stream operator from *this into each entry in order, leaving early if a failure occurs.
in] ContentType type of object inside the vector
[in] | vec | object vector to read into |
[in] | count | number of objects to read |
Definition at line 172 of file Reader.h.
|
inline |
Read the next 'count' words into the input handle.
This implementation of read is only available to pointers to integral types. We assume that whatever space pointed to by w already has the space reserved necessary for the input words.
in] WordType integral-type word to read out
[in] | w | pointer to WordType array to write data to |
[in] | count | number of words to read |
Definition at line 113 of file Reader.h.
Referenced by packing::FiberTrackerField::FiberTrackerField(), operator>>(), operator>>(), packing::SingleSubsystemUnpacker::produce(), packing::rawdatafile::EventPacket::read(), packing::rawdatafile::SubsystemPacket::read(), and read().
|
inline |
Go ("seek") a specific position in the file.
This non-template version of seek uses the default meaning of the "off" parameter in which it counts bytes.
[in] | off | number of bytes to move relative to dir |
[in] | dir | location flag for the file, default is beginning |
Definition at line 61 of file Reader.h.
References file_.
Referenced by packing::rawdatafile::File::File(), and seek().
|
inline |
Seek by number of words.
This template version of seek uses the input word type to move around by the count of the input words rather than the count of bytes.
in] WordType Integral-type to count by
[in] | off | number of words to move relative to dir |
[in] | dir | location flag for the file, default is beginning |
Definition at line 78 of file Reader.h.
References seek().
|
inline |
|
inline |
|
private |
file stream we are reading from
Definition at line 218 of file Reader.h.
Referenced by eof(), open(), operator bool(), operator!(), read(), Reader(), seek(), and tell().
|
private |