FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
Classes | Public Types | Public Member Functions | List of all members
frib::analysis::CDataReader Class Reference

#include <DataReader.h>

Classes

struct  _Result
 

Public Types

typedef struct frib::analysis::CDataReader::_Result Result
 
typedef struct frib::analysis::CDataReader::_ResultpResult
 

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 ()
 

Detailed Description

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.
* 
Note
this works best (in terms of minmal data movement), if the size of the reader's buffer is closely matched to the maxsize's that are passed to getBlock().

Constructor & Destructor Documentation

◆ CDataReader()

frib::analysis::CDataReader::CDataReader ( int  fd,
std::size_t  bufferSize 
)

constructor Already have a file descriptor open:

Parameters
fd- a file descriptor open on the data source.
Note
fd will be closed on destruction.

◆ ~CDataReader()

frib::analysis::CDataReader::~CDataReader ( )
virtual

destructor

Member Function Documentation

◆ done()

void frib::analysis::CDataReader::done ( )

done Indicate the client is done with the last chunk of data:

  • Ensure this is a valid call (m_fReleased is false).
  • Slide any data in the buffer to the front.
  • Fill any remaining space

◆ getBlock()

CDataReader::Result frib::analysis::CDataReader::getBlock ( std::size_t  maxbytes)

getBlock

  • Ensure this is legal (m_fReleased is true). -probeData to figure out how much data to actually give.
  • Build up the Result value from the state data probeData created and return.

The documentation for this class was generated from the following files: