99 lines
2.5 KiB
C++
99 lines
2.5 KiB
C++
#ifndef OPATIO_H
|
|
#define OPATIO_H
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <map>
|
|
#include <utility>
|
|
|
|
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];
|
|
};
|
|
|
|
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<double> logR;
|
|
std::vector<double> logT;
|
|
std::vector<std::vector<double>> logKappa;
|
|
};
|
|
|
|
class opatIOTest; // Friend for gtest
|
|
|
|
class OpatIO {
|
|
private:
|
|
Header header;
|
|
std::vector<TableIndex> tableIndex;
|
|
std::deque<std::pair<int, OPATTable>> tableQueue;
|
|
std::map<int, std::pair<double, double>> tableIDToComposition;
|
|
std::pair<double, double> 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<TableIndex> getTableIndex();
|
|
Header getHeader();
|
|
|
|
std::vector<OPATTable> getClosestXTables(double X, double ZExact, double C=0, double O=0, int numTables=1);
|
|
std::vector<OPATTable> getClosestZTables(double XExact, double Z, double C=0, double O=0, int numTables=1);
|
|
std::vector<OPATTable> 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 |