docs(opatIO): wrote and built doxygen docs

This commit is contained in:
2025-02-16 12:29:51 -05:00
parent 5ce365d545
commit 0d5406aeee
44 changed files with 711 additions and 243 deletions

View File

@@ -9,93 +9,264 @@
#include <map>
#include <utility>
/**
* @brief Structure to hold the header information of an OPAT file.
*/
#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];
char magic[4]; ///< Magic number to identify the file type
uint16_t version; ///< Version of the OPAT file format
uint32_t numTables; ///< Number of tables in the file
uint32_t headerSize; ///< Size of the header
uint64_t indexOffset; ///< Offset to the index section
char creationDate[16]; ///< Creation date of the file
char sourceInfo[64]; ///< Source information
char comment[128]; ///< Comment section
char reserved[26]; ///< Reserved for future use
};
#pragma pack()
/**
* @brief Structure to hold the index information of a table in an OPAT file.
*/
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];
double X; ///< X composition value
double Z; ///< Z composition value
uint64_t byteStart; ///< Byte start position of the table
uint64_t byteEnd; ///< Byte end position of the table
char sha256[32]; ///< SHA-256 hash of the table data
};
/**
* @brief Structure to hold the data of an OPAT table.
*/
struct OPATTable {
uint32_t N_R;
uint32_t N_T;
std::vector<double> logR;
std::vector<double> logT;
std::vector<std::vector<double>> logKappa;
uint32_t N_R; ///< Number of R values
uint32_t N_T; ///< Number of T values
std::vector<double> logR; ///< Logarithm of R values
std::vector<double> logT; ///< Logarithm of T values
std::vector<std::vector<double>> logKappa; ///< Logarithm of Kappa values
};
class opatIOTest; // Friend for gtest
/**
* @brief Class to manage the input/output operations for OPAT files.
*/
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;
Header header; ///< Header information of the OPAT file
std::vector<TableIndex> tableIndex; ///< Index information of the tables
std::deque<std::pair<int, OPATTable>> tableQueue; ///< Queue to manage table caching
std::map<int, std::pair<double, double>> tableIDToComposition; ///< Map to store table ID to composition mapping
std::pair<double, double> XZepsilon; ///< Epsilon values for X and Z
int maxQDepth = 10; ///< Maximum depth of the table queue
std::string filename; ///< Filename of the OPAT file
bool loaded = false; ///< Flag to indicate if the file is loaded
/**
* @brief Read the header from the file.
* @param file The input file stream.
*/
void readHeader(std::ifstream &file);
/**
* @brief Read the table index from the file.
* @param file The input file stream.
*/
void readTableIndex(std::ifstream &file);
/**
* @brief Get a table from the queue.
* @param tableID The ID of the table.
* @return The OPAT table.
*/
OPATTable getTableFromQueue(int tableID);
/**
* @brief Add a table to the queue.
* @param tableID The ID of the table.
* @param table The OPAT table.
*/
void addTableToQueue(int tableID, OPATTable table);
/**
* @brief Remove a table from the queue.
*/
void removeTableFromQueue();
/**
* @brief Flush the table queue.
*/
void flushQueue();
/**
* @brief Get a table by its ID.
* @param tableID The ID of the table.
* @return The OPAT table.
*/
OPATTable getTable(int tableID);
/**
* @brief Print a table.
* @param table The OPAT table.
* @param truncateDigits Number of digits to truncate.
*/
void printTable(OPATTable table, uint32_t truncateDigits=5);
/**
* @brief Lookup epsilon values for X and Z.
*/
void XZLookupEpsilon();
/**
* @brief Build the table ID to composition mapping.
*/
void buildTableIDToComposition();
public:
/**
* @brief Default constructor.
*/
OpatIO();
/**
* @brief Constructor with filename.
* @param filename The name of the OPAT file.
*/
OpatIO(std::string filename);
/**
* @brief Destructor.
*/
~OpatIO();
/**
* @brief Get a table by X and Z values.
* @param X The X composition value.
* @param Z The Z composition value.
* @return The OPAT table.
*/
OPATTable getTable(double X, double Z);
/**
* @brief Set the maximum depth of the table queue.
* @param depth The maximum depth.
*/
void setMaxQDepth(int depth);
/**
* @brief Get the maximum depth of the table queue.
* @return The maximum depth.
*/
int getMaxQDepth();
/**
* @brief Set the filename of the OPAT file.
* @param filename The name of the file.
*/
void setFilename(std::string filename);
/**
* @brief Load the OPAT file.
*/
void load();
/**
* @brief Unload the OPAT file.
*/
void unload();
/**
* @brief Check if the file is loaded.
* @return True if the file is loaded, false otherwise.
*/
bool isLoaded();
/**
* @brief Print the header information.
*/
void printHeader();
/**
* @brief Print the table index.
*/
void printTableIndex();
/**
* @brief Print a table by X and Z values.
* @param X The X composition value.
* @param Z The Z composition value.
* @param truncateDigits Number of digits to truncate.
*/
void printTable(double X, double Z, uint32_t truncateDigits=5);
/**
* @brief Get the table index.
* @return A vector of TableIndex structures.
*/
std::vector<TableIndex> getTableIndex();
/**
* @brief Get the header information.
* @return The Header structure.
*/
Header getHeader();
/**
* @brief Get the closest tables by X value.
* @param X The X composition value.
* @param ZExact The exact Z composition value.
* @param C The C composition value (default is 0).
* @param O The O composition value (default is 0).
* @param numTables The number of closest tables to retrieve (default is 1).
* @return A vector of OPAT tables.
*/
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);
/**
* @brief Get the closest tables by Z value.
* @param XExact The exact X composition value.
* @param Z The Z composition value.
* @param C The C composition value (default is 0).
* @param O The O composition value (default is 0).
* @param numTables The number of closest tables to retrieve (default is 1).
* @return A vector of OPAT tables.
*/
std::vector<OPATTable> getClosestZTables(double XExact, double Z, double C=0, double O=0, int numTables=1);
/**
* @brief Get the closest tables by X and Z values.
* @param X The X composition value.
* @param Z The Z composition value.
* @param C The C composition value (default is 0).
* @param O The O composition value (default is 0).
* @param numTables The number of closest tables to retrieve (default is 1).
* @return A vector of OPAT tables.
*/
std::vector<OPATTable> getClosestTables(double X, double Z, double C=0, double O=0, int numTables=1);
/**
* @brief Lookup the table ID by X and Z values.
* @param X The X composition value.
* @param Z The Z composition value.
* @return The table ID.
*/
int lookupTableID(double X, double Z);
/**
* @brief Lookup the closest table ID by X and Z values.
* @param X The X composition value.
* @param Z The Z composition value.
* @return The closest table ID.
*/
int lookupClosestTableID(double X, double Z);
/**
* @brief Get the version of the OPAT file format.
* @return The version of the OPAT file format.
*/
uint16_t getOPATVersion();
};
#endif