FRIBParallelanalysis
1.0
FrameworkforMPIParalleldataanalysisatFRIB
|
#include <DataReader.h>
Classes | |
struct | _Result |
Public Types | |
typedef struct frib::analysis::CDataReader::_Result | Result |
typedef struct frib::analysis::CDataReader::_Result * | pResult |
Public Member Functions | |
CDataReader (const char *pFilename, std::size_t bufferSize) | |
CDataReader (int fd, std::size_t bufferSize) | |
virtual | ~CDataReader () |
Result | getBlock (std::size_t maxbytes) |
void | done () |
This is a buffered data reader that is reading a set of items that are ring item like. For the purposes of this class, we only need to know that each item starts with an std::unit32_t which represents its self inclusive size.
Formally we have an internal buffer into which we gulp pretty big chunks of the data source. A client then asks us for a chunk of data giving us a maximum size. We return a pointer to the block of data and an actual size, as well as a number of items. Prior to the next request for data, the caller must indicate that it is done with the current block. Thus this is inherently not thread-safe though it can be used to feed data to e.g. a Dealer in an MPI environment.
Typical use case:
* CDataReader reader("somefile"); * auto got = reader.getBlock(maxbytes); * size_t nbytes = got.s_nbytes; // 0 if no more data. * size_t nItems = got.s_nItems; // 0 if no more data. * const void* p = got.s_pData; // data, nullptr if no more data. * ... // do something with the data. * reader.done(); // now can get more data. *
frib::analysis::CDataReader::CDataReader | ( | int | fd, |
std::size_t | bufferSize | ||
) |
constructor Already have a file descriptor open:
fd | - a file descriptor open on the data source. |
|
virtual |
destructor
void frib::analysis::CDataReader::done | ( | ) |
done Indicate the client is done with the last chunk of data:
CDataReader::Result frib::analysis::CDataReader::getBlock | ( | std::size_t | maxbytes | ) |
getBlock