FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
DataReader.h
Go to the documentation of this file.
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2017.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Authors:
11  Ron Fox
12  Giordano Cerriza
13  FRIB
14  Michigan State University
15  East Lansing, MI 48824-1321
16 */
17 
21 #ifndef DATAREADER_H
22 #define DATAREADER_H
23 
24 #include <cstddef>
25 
26 namespace frib {
27  namespace analysis {
60  class CDataReader {
61  private:
62  std::size_t m_nBytes; // bytes in the buffer.
63  void* m_pBuffer; // buffer itself.
64  std::size_t m_nBufferSize; // Size of the buffer.
65  bool m_eof;
66 
67  int m_nFd; // Data source.
68 
69  // State of the last 'read':
70 
71  bool m_fReleased; // A new read is allowed.
72  std::size_t m_nUserBytes; // Bytes we gave to the user.
73  std::size_t m_nUserItems; // items we gave to the user.
74 
75  public: // Exported data types:
76 
77  // What a read returns:
78 
79  typedef struct _Result {
80  std::size_t s_nbytes;
81  std::size_t s_nItems;
82  const void* s_pData;
83  } Result, *pResult;
84  public:
85  CDataReader(const char* pFilename, std::size_t bufferSize);
86  CDataReader(int fd, std::size_t bufferSize);
87  virtual ~CDataReader();
88 
89  private:
90  CDataReader(const CDataReader& rhs);
91  CDataReader& operator=(const CDataReader& rhs);
92  int operator==(const CDataReader& rhs);
93  int operator!=(const CDataReader& rhs);
94  public:
95  Result getBlock(std::size_t maxbytes);
96  void done();
97  private:
98  void allocateBuffer();
99  void fillBuffer();
100  void probeData(std::size_t maxBytes);
101  };
102  }
103 }
104 
105 
106 #endif
Definition: DataReader.h:60
Definition: DataReader.h:79
virtual ~CDataReader()
Definition: DataReader.cpp:79
void done()
Definition: DataReader.cpp:115
Result getBlock(std::size_t maxbytes)
Definition: DataReader.cpp:91
Definition: AbstractApplication.cpp:30