Mantid
|
The BinaryFile template is a helper function for loading simple binary files. More...
#include <BinaryFile.h>
Public Member Functions | |
BinaryFile () | |
Empty constructor. More... | |
BinaryFile (std::string filename) | |
Constructor - open a file. More... | |
void | close () |
Close the file. More... | |
size_t | getBufferSize (const size_t num_items) const |
Get a buffer size for loading blocks of data. More... | |
size_t | getNumElements () const |
Returns the # of elements in the file (cached result of getFileSize) More... | |
size_t | getOffset () const |
Returns the current offset into the file. More... | |
std::vector< T > | loadAll () |
Loads the entire contents of the file into a pointer to a std::vector. More... | |
std::vector< T > | loadAllIntoVector () |
Loads the entire contents of the file into a std::vector. More... | |
size_t | loadBlock (T *buffer, size_t block_size) |
Loads a single block from file and returns a pointer to a vector containing it. More... | |
size_t | loadBlockAt (T *buffer, size_t newOffset, size_t block_size) |
Loads a single block from file and returns a pointer to a vector containing it. More... | |
void | open (const std::string &filename) |
Open a file and keep a handle to the file. More... | |
~BinaryFile () | |
Destructor, close the file if needed. More... | |
Private Member Functions | |
size_t | getFileSize () |
Get the size of a file as a multiple of a particular data type. More... | |
Private Attributes | |
std::unique_ptr< std::ifstream > | handle |
File stream. More... | |
size_t | num_elements |
Number of elements of size T in the file. More... | |
size_t | obj_size |
Size of each object. More... | |
size_t | offset |
Offset into the file, if loading in blocks. More... | |
The BinaryFile template is a helper function for loading simple binary files.
NOTE: Data saving and loading is little-endian (on Win, Linux, and Intel Mac). Converting from a byte buffer loaded from disk to the T type is done with a reinterpret_cast<T>.
Definition at line 44 of file BinaryFile.h.
|
inline |
Empty constructor.
Definition at line 48 of file BinaryFile.h.
|
inline |
Constructor - open a file.
Definition at line 52 of file BinaryFile.h.
|
inline |
Destructor, close the file if needed.
Definition at line 55 of file BinaryFile.h.
|
inline |
Close the file.
Definition at line 82 of file BinaryFile.h.
|
inline |
Get a buffer size for loading blocks of data.
num_items |
Definition at line 96 of file BinaryFile.h.
References Mantid::Kernel::DEFAULT_BLOCK_SIZE.
|
inlineprivate |
Get the size of a file as a multiple of a particular data type.
runtime_error | if the file size is not compatible |
runtime_error | if the handle is not open. |
Definition at line 231 of file BinaryFile.h.
|
inline |
Returns the # of elements in the file (cached result of getFileSize)
Definition at line 86 of file BinaryFile.h.
Referenced by Mantid::DataHandling::DetermineChunking::exec(), Mantid::DataHandling::FilterEventsByLogValuePreNexus::loadPixelMap(), Mantid::DataHandling::LoadEventPreNexus2::loadPixelMap(), Mantid::DataHandling::FilterEventsByLogValuePreNexus::readPulseidFile(), and Mantid::DataHandling::LoadEventPreNexus2::readPulseidFile().
|
inline |
Returns the current offset into the file.
Definition at line 89 of file BinaryFile.h.
|
inline |
Loads the entire contents of the file into a pointer to a std::vector.
The file is closed once done.
Definition at line 109 of file BinaryFile.h.
Referenced by Mantid::DataHandling::FilterEventsByLogValuePreNexus::readPulseidFile(), Mantid::DataHandling::LoadEventPreNexus2::readPulseidFile(), and Mantid::DataHandling::LoadDspacemap::readVulcanBinaryFile().
|
inline |
Loads the entire contents of the file into a std::vector.
The file is closed once done.
Definition at line 145 of file BinaryFile.h.
Referenced by Mantid::DataHandling::LoadPreNexusMonitors::exec(), Mantid::DataHandling::FilterEventsByLogValuePreNexus::loadPixelMap(), and Mantid::DataHandling::LoadEventPreNexus2::loadPixelMap().
|
inline |
Loads a single block from file and returns a pointer to a vector containing it.
This can be called repeatedly to load an entire file.
block_size | how many elements to load in the block. If there are not enough elements, the vector returned is smaller than block_size |
buffer | array of block_size[] of T; must have been allocated before. |
Definition at line 186 of file BinaryFile.h.
|
inline |
Loads a single block from file and returns a pointer to a vector containing it.
This can be called repeatedly to load an entire file.
buffer | array of block_size[] of T; must have been allocated before. |
newOffset | offset (in # of elements) of where to start loading in the file. |
block_size | how many elements to load in the block. If there are not enough elements, the vector returned is smaller than block_size |
Definition at line 215 of file BinaryFile.h.
|
inline |
Open a file and keep a handle to the file.
filename | :: full path to open |
runtime_error | if the file size is not an even multiple of the type size |
invalid_argument | if the file does not exist |
Definition at line 64 of file BinaryFile.h.
References Mantid::DataHandling::exists().
|
private |
File stream.
Definition at line 259 of file BinaryFile.h.
|
private |
Number of elements of size T in the file.
Definition at line 263 of file BinaryFile.h.
|
private |
Size of each object.
Definition at line 261 of file BinaryFile.h.
|
private |
Offset into the file, if loading in blocks.
Definition at line 265 of file BinaryFile.h.