#ifndef OPATIO_H #define OPATIO_H #include #include #include #include #include #include #include #pragma pack(1) struct Header { char magic[4]; uint16_t version; uint32_t numTables; uint32_t headerSize; uint64_t indexOffset; char creationDate[16]; char sourceInfo[64]; char comment[128]; char reserved[26]; }; #pragma pack() struct TableIndex { double X; double Z; // double C; // For type 2 OPAL tables. When not set will be 0 // double O; // For type 2 OPAL tables. When not set will be 0 uint64_t byteStart; uint64_t byteEnd; char sha256[32]; }; struct OPATTable { uint32_t N_R; uint32_t N_T; std::vector logR; std::vector logT; std::vector> logKappa; }; class opatIOTest; // Friend for gtest class OpatIO { private: Header header; std::vector tableIndex; std::deque> tableQueue; std::map> tableIDToComposition; std::pair XZepsilon; int maxQDepth = 10; std::string filename; bool loaded = false; void readHeader(std::ifstream &file); void readTableIndex(std::ifstream &file); OPATTable getTableFromQueue(int tableID); void addTableToQueue(int tableID, OPATTable table); void removeTableFromQueue(); void flushQueue(); OPATTable getTable(int tableID); void printTable(OPATTable table, uint32_t truncateDigits=5); void XZLookupEpsilon(); void buildTableIDToComposition(); public: OpatIO(); OpatIO(std::string filename); ~OpatIO(); OPATTable getTable(double X, double Z); void setMaxQDepth(int depth); int getMaxQDepth(); void setFilename(std::string filename); void load(); void unload(); bool isLoaded(); void printHeader(); void printTableIndex(); void printTable(double X, double Z, uint32_t truncateDigits=5); std::vector getTableIndex(); Header getHeader(); std::vector getClosestXTables(double X, double ZExact, double C=0, double O=0, int numTables=1); std::vector getClosestZTables(double XExact, double Z, double C=0, double O=0, int numTables=1); std::vector getClosestTables(double X, double Z, double C=0, double O=0, int numTables=1); int lookupTableID(double X, double Z); int lookupClosestTableID(double X, double Z); uint16_t getOPATVersion(); }; #endif