-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataFile.h
38 lines (29 loc) · 1 KB
/
DataFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Interface for reading a data file for parallelization test
// Much simplified version of CodaFile
#ifndef PPODD_DATAFILE
#define PPODD_DATAFILE
#include <cstdint>
#include <cstdio>
#include <string>
#include <memory>
using evbuf_t = uint32_t;
using evbuf_ptr_t = std::unique_ptr<evbuf_t[]>;
static constexpr size_t MAX_EVTSIZE = 4*1024*1024;
class DataFile {
public:
explicit DataFile( std::string filename = std::string() );
~DataFile();
bool IsOpen() { return (filep != nullptr); }
int Open( const std::string& filename = std::string() );
int ReadEvent();
int Close();
[[nodiscard]] evbuf_t* GetEvBufPtr() const { return buffer.get(); }
[[nodiscard]] evbuf_ptr_t& GetEvBuffer() { return buffer; }
[[nodiscard]] evbuf_t GetEvSize() const { return buffer[0]; }
[[nodiscard]] size_t GetEvWords() const { return GetEvSize()/sizeof(evbuf_t); }
private:
std::string filename;
FILE* filep;
evbuf_ptr_t buffer; // Buffer for current event
};
#endif