|
Mantid
|
The BinaryFile template is a helper function for loading simple binary files. More...
#include <BinaryFile.h>
Public Member Functions | |
| BinaryFile () | |
| Empty constructor. | |
| BinaryFile (std::filesystem::path const &filepath) | |
| Constructor - open a file. | |
| void | close () |
| Close the file. | |
| size_t | getBufferSize (const size_t num_items) const |
| Get a buffer size for loading blocks of data. | |
| size_t | getNumElements () const |
| Returns the # of elements in the file (cached result of getFileSize) | |
| size_t | getOffset () const |
| Returns the current offset into the file. | |
| std::vector< T > | loadAll () |
| Loads the entire contents of the file into a pointer to a std::vector. | |
| std::vector< T > | loadAllIntoVector () |
| Loads the entire contents of the file into a std::vector. | |
| size_t | loadBlock (T *buffer, size_t block_size) |
| Loads a single block from file and returns a pointer to a vector containing it. | |
| 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. | |
| void | open (std::filesystem::path const &filepath) |
| Open a file and keep a handle to the file. | |
| ~BinaryFile () | |
| Destructor, close the file if needed. | |
Private Member Functions | |
| size_t | getFileSize () |
| Get the size of a file as a multiple of a particular data type. | |
Private Attributes | |
| std::unique_ptr< std::ifstream > | handle |
| File stream. | |
| size_t | num_elements |
| Number of elements of size T in the file. | |
| size_t | obj_size |
| Size of each object. | |
| size_t | offset |
| Offset into the file, if loading in blocks. | |
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 43 of file BinaryFile.h.
|
inline |
Empty constructor.
Definition at line 47 of file BinaryFile.h.
|
inline |
Constructor - open a file.
Definition at line 51 of file BinaryFile.h.
|
inline |
Destructor, close the file if needed.
Definition at line 54 of file BinaryFile.h.
|
inline |
Close the file.
Definition at line 79 of file BinaryFile.h.
|
inline |
Get a buffer size for loading blocks of data.
| num_items |
Definition at line 93 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 228 of file BinaryFile.h.
|
inline |
Returns the # of elements in the file (cached result of getFileSize)
Definition at line 83 of file BinaryFile.h.
Referenced by Mantid::DataHandling::DetermineChunking::exec(), Mantid::DataHandling::LoadEventPreNexus2::loadPixelMap(), and Mantid::DataHandling::LoadEventPreNexus2::readPulseidFile().
|
inline |
Returns the current offset into the file.
Definition at line 86 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 106 of file BinaryFile.h.
Referenced by Mantid::DataHandling::LoadEventPreNexus2::readPulseidFile().
|
inline |
Loads the entire contents of the file into a std::vector.
The file is closed once done.
Definition at line 142 of file BinaryFile.h.
Referenced by Mantid::DataHandling::LoadPreNexusMonitors::exec(), 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 183 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 212 of file BinaryFile.h.
|
inline |
Open a file and keep a handle to the file.
| filepath | :: 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 63 of file BinaryFile.h.
|
private |
File stream.
Definition at line 256 of file BinaryFile.h.
|
private |
Number of elements of size T in the file.
Definition at line 260 of file BinaryFile.h.
|
private |
Size of each object.
Definition at line 258 of file BinaryFile.h.
|
private |
Offset into the file, if loading in blocks.
Definition at line 262 of file BinaryFile.h.