feat(opatIO): added min viable version of opatIO

opatIO can now read tables properly and retreive them in a useful manner. Future aditions will be the ability to lookup "closest" tables and a pretty printer for tables.
This commit is contained in:
2025-02-15 07:27:47 -05:00
parent eda61c6889
commit 3fc2651730
4 changed files with 169 additions and 117 deletions

View File

@@ -5,7 +5,9 @@
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <utility>
struct Header {
char magic[4];
@@ -37,11 +39,15 @@ struct OPATTable {
std::vector<std::vector<double>> logKappa;
};
class opatIOTest; // Friend for gtest
class OpatIO {
private:
Header header;
std::vector<TableIndex> tableIndex;
std::queue<OPATTable> tableQueue;
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;
@@ -49,26 +55,21 @@ private:
void readHeader(std::ifstream &file);
void readTableIndex(std::ifstream &file);
bool isTableInQueue(double X, double Z);
OPATTable getTableFromQueue(double X, double Z);
void addTableToQueue(OPATTable table);
OPATTable getTableFromQueue(int tableID);
void addTableToQueue(int tableID, OPATTable table);
void removeTableFromQueue();
void flushQueue();
uint16_t getOPATVersion();
uint16_t getTableID(double X, double Z);
uint64_t getTableByteStart(uint16_t tableID);
uint64_t getTableByteEnd(uint16_t tableID);
OPATTable getTable(int tableID);
void XZLookupEpsilon();
void buildTableIDToComposition();
public:
OpatIO();
OpatIO(std::string filename);
~OpatIO();
OPATTable getTable(double X, double, double C=0, double O=0);
OPATTable getTable(uint16_t tableID);
OPATTable getTable(double X, double Z);
void setMaxQDepth(int depth);
int getMaxQDepth();
void setFilename(std::string filename);
@@ -87,6 +88,10 @@ public:
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();
};