59#include <unordered_map>
151 std::unordered_map<FloatIndexVector, CardCatalogEntry>
tableIndex;
262 std::unique_ptr<double[]>
data;
272 [[nodiscard]] std::pair<double, double>
size()
const {
return std::make_pair(
N_R,
N_C); }
313 double operator()(uint32_t row, uint32_t column, uint64_t zdepth)
const;
343 [[nodiscard]]
double getData(uint32_t row, uint32_t column, uint64_t zdepth)
const;
379 [[nodiscard]]
const double*
getRawData()
const;
394 [[nodiscard]] std::string
ascii()
const;
428 [[nodiscard]]
const OPATTable&
get(
const std::string& tag)
const;
469 [[nodiscard]] std::vector<std::string>
getKeys()
const;
486 double min = std::numeric_limits<double>::max();
487 double max = std::numeric_limits<double>::min();
505 std::unordered_map<FloatIndexVector, DataCard>
cards;
538 [[nodiscard]]
const DataCard&
get(
const std::vector<double>& index)
const {
584 [[nodiscard]] std::vector<Bounds>
getBounds()
const;
603OPAT
readOPAT(
const std::string& filename);
645CardCatalogEntry
readCardCatalogEntry(std::ifstream &file, uint64_t offset, uint16_t numIndex, uint8_t hashPrecision);
688std::unordered_map<FloatIndexVector, DataCard>
readDataCards(std::ifstream &file,
const Header &header,
const CardCatalog &cardCatalog);
707DataCard
readDataCard(std::ifstream &file,
const CardCatalogEntry &entry);
749TableIndex
readTableIndex(std::ifstream &file,
const CardCatalogEntry &entry,
const CardHeader &header);
771OPATTable
readOPATTable(std::ifstream &file,
const CardCatalogEntry &cardEntry,
const TableIndexEntry &tableEntry);
790bool hasMagic(
const std::string& filename);
827 static_assert(std::is_trivially_copyable_v<T>,
"swap_bytes only supports trivial types.");
829 auto src =
reinterpret_cast<uint8_t*
>(&value);
830 auto* dest =
reinterpret_cast<uint8_t*
>(&result);
831 for (
size_t i = 0; i <
sizeof(T); i++) {
832 dest[i] = src[
sizeof(T) - 1 - i];
Definition indexVector.h:38
Header file defining the FloatIndexVector class for handling floating-point index vectors.
TableIndex readTableIndex(std::ifstream &file, const CardCatalogEntry &entry, const CardHeader &header)
Reads the TableIndex from a DataCard.
Definition opatIO.cpp:209
bool hasMagic(const std::string &filename)
Checks if a file has the correct magic number for an OPAT file.
Definition opatIO.cpp:46
CardHeader readDataCardHeader(std::ifstream &file, const CardCatalogEntry &entry)
Reads the header of a DataCard from the file.
Definition opatIO.cpp:192
OPATTable readOPATTable(std::ifstream &file, const CardCatalogEntry &cardEntry, const TableIndexEntry &tableEntry)
Reads an OPATTable from the file.
Definition opatIO.cpp:231
CardCatalogEntry readCardCatalogEntry(std::ifstream &file, uint64_t offset, uint16_t numIndex, uint8_t hashPrecision)
Reads a CardCatalogEntry from the file.
Definition opatIO.cpp:127
bool is_big_endian()
Determines if the system is big-endian.
Definition opatIO.cpp:40
CardCatalog readCardCatalog(std::ifstream &file, const Header &header)
Reads the CardCatalog from the file.
Definition opatIO.cpp:149
T swap_bytes(T value)
Swaps the byte order of a value.
Definition opatIO.h:826
DataCard readDataCard(std::ifstream &file, const CardCatalogEntry &entry)
Reads a single DataCard from the file.
Definition opatIO.cpp:173
OPAT readOPAT(const std::string &filename)
Reads an OPAT file and returns its contents as an OPAT structure.
Definition opatIO.cpp:76
Header readHeader(std::ifstream &file)
Reads the header of an OPAT file.
Definition opatIO.cpp:109
std::unordered_map< FloatIndexVector, DataCard > readDataCards(std::ifstream &file, const Header &header, const CardCatalog &cardCatalog)
Reads all DataCards from the file.
Definition opatIO.cpp:163
Structure to hold the minimum and maximum values for a dimension.
Definition opatIO.h:485
friend std::ostream & operator<<(std::ostream &os, const Bounds &bounds)
Stream insertion operator for printing the Bounds.
Definition opatIO.cpp:584
double max
The maximum value.
Definition opatIO.h:487
double min
The minimum value.
Definition opatIO.h:486
Structure to hold the index information of a table in an OPAT file.
Definition opatIO.h:130
friend std::ostream & operator<<(std::ostream &os, const CardCatalogEntry &entry)
Stream insertion operator for printing the catalog entry.
Definition opatIO.cpp:526
char sha256[32]
SHA-256 hash of the table data for integrity verification.
Definition opatIO.h:134
uint64_t byteStart
Byte start position of the table in the file.
Definition opatIO.h:132
uint64_t byteEnd
Byte end position of the table in the file.
Definition opatIO.h:133
FloatIndexVector index
Index vector for the associated table.
Definition opatIO.h:131
Structure to hold the catalog of tables in a DataCard.
Definition opatIO.h:150
friend std::ostream & operator<<(std::ostream &os, const CardCatalog &catalog)
Stream insertion operator for printing the card catalog.
Definition opatIO.cpp:541
std::unordered_map< FloatIndexVector, CardCatalogEntry > tableIndex
Map of index vectors to catalog entries.
Definition opatIO.h:151
Structure to hold a DataCard, which contains multiple tables.
Definition opatIO.h:409
CardHeader header
Header of the DataCard.
Definition opatIO.h:410
std::unordered_map< std::string, OPATTable > tableData
Map of table tags to their data.
Definition opatIO.h:412
TableIndex tableIndex
Index of tables within the DataCard.
Definition opatIO.h:411
std::vector< std::string > getKeys() const
Retrieves a list of all table tags (keys) present in this DataCard.
Definition opatIO.cpp:302
const OPATTable & operator[](const std::string &tag) const
Accesses a table from the DataCard by tag.
Definition opatIO.cpp:292
friend std::ostream & operator<<(std::ostream &os, const DataCard &card)
Stream insertion operator for printing the DataCard.
Definition opatIO.cpp:569
const OPATTable & get(const std::string &tag) const
Retrieves a table from the DataCard by tag.
Definition opatIO.cpp:284
Structure to hold the entire OPAT file.
Definition opatIO.h:502
Header header
Header of the OPAT file.
Definition opatIO.h:503
std::unordered_map< FloatIndexVector, DataCard > cards
Map of index vectors to DataCards.
Definition opatIO.h:505
const DataCard & get(const std::vector< double > &index) const
Retrieves a DataCard from the OPAT structure by a standard vector of doubles. This is a convenience o...
Definition opatIO.h:538
CardCatalog cardCatalog
Catalog of DataCards in the file.
Definition opatIO.h:504
const DataCard & operator[](const std::vector< double > &index) const
Accesses a DataCard from the OPAT structure by a standard vector of doubles. This is a convenience ov...
Definition opatIO.h:565
std::vector< Bounds > getBounds() const
Calculates and returns the bounds (min and max values) for each dimension of the index vectors in the...
Definition opatIO.cpp:59
friend std::ostream & operator<<(std::ostream &os, const OPAT &opat)
Stream insertion operator for printing the OPAT structure.
Definition opatIO.cpp:574
const DataCard & get(const FloatIndexVector &index) const
Retrieves a DataCard from the OPAT structure by index.
Definition opatIO.cpp:271
const DataCard & operator[](const FloatIndexVector &index) const
Accesses a DataCard from the OPAT structure by index.
Definition opatIO.cpp:280
Structure to hold the data of an OPAT table.
Definition opatIO.h:259
const double * getRawData() const
Retrieves the raw data of the table.
Definition opatIO.cpp:451
void print() const
Prints the table to the standard output.
Definition opatIO.cpp:502
uint32_t N_R
Number of rows in the table.
Definition opatIO.h:264
friend std::ostream & operator<<(std::ostream &os, const OPATTable &table)
Definition opatIO.cpp:564
std::pair< double, double > size() const
Returns the size of the table as a pair of rows and columns.
Definition opatIO.h:272
OPATTable slice(const Slice &rowSlice, const Slice &colSlice) const
Extracts a slice of the table.
Definition opatIO.cpp:461
std::string ascii() const
Converts the table to an ASCII representation.
Definition opatIO.cpp:491
OPATTable getColumn(uint32_t column) const
Extracts a single column from the table.
Definition opatIO.cpp:386
OPATTable getRowValues() const
Retrieves all row values of the table.
Definition opatIO.cpp:407
std::unique_ptr< double[]> columnValues
Array of column values.
Definition opatIO.h:261
OPATTable getColumnValues() const
Retrieves all column values of the table.
Definition opatIO.cpp:429
const double & operator()() const
Accesses the first value in the table's data array.
Definition opatIO.cpp:332
std::unique_ptr< double[]> rowValues
Array of row values.
Definition opatIO.h:260
uint32_t N_C
Number of columns in the table.
Definition opatIO.h:265
uint64_t m_vsize
Vector size of each cell.
Definition opatIO.h:266
std::unique_ptr< double[]> data
Array of table data.
Definition opatIO.h:262
OPATTable getRow(uint32_t row) const
Extracts a single row from the table.
Definition opatIO.cpp:370
OPATTable getData(uint32_t row, uint32_t column) const
Retrieves a table value by row and column.
Definition opatIO.cpp:349
int vsize() const
Retrieves the vector size of each cell in the table.
Definition opatIO.h:281
Structure to represent a slice of data.
Definition opatIO.h:239
uint32_t start
Start index of the slice.
Definition opatIO.h:240
uint32_t end
End index of the slice.
Definition opatIO.h:241
friend std::ostream & operator<<(std::ostream &os, const Slice &slice)
Stream insertion operator for printing the slice.
Definition opatIO.cpp:579
Structure to hold the index information of a table within a DataCard.
Definition opatIO.h:168
char columnName[8]
Name of the columns (optional).
Definition opatIO.h:174
friend std::ostream & operator<<(std::ostream &os, const TableIndexEntry &entry)
Stream insertion operator for printing the table index entry.
Definition opatIO.cpp:546
uint64_t byteStart
Byte start position of the table in the card.
Definition opatIO.h:170
char reserved[12]
Reserved for future use.
Definition opatIO.h:177
uint16_t numColumns
Number of columns in the table.
Definition opatIO.h:172
uint64_t size
Vector size of each cell.
Definition opatIO.h:176
char tag[8]
Tag identifying the table.
Definition opatIO.h:169
uint16_t numRows
Number of rows in the table.
Definition opatIO.h:173
char rowName[8]
Name of the rows (optional).
Definition opatIO.h:175
uint64_t byteEnd
Byte end position of the table in the card.
Definition opatIO.h:171
Structure to hold the index of tables within a DataCard.
Definition opatIO.h:194
std::unordered_map< std::string, TableIndexEntry > tableIndex
Map of table tags to index entries.
Definition opatIO.h:195
const TableIndexEntry & get(const std::string &tag) const
Retrieves a TableIndexEntry by tag.
Definition opatIO.cpp:311
friend std::ostream & operator<<(std::ostream &os, const TableIndex &index)
Stream insertion operator for printing the table index.
Definition opatIO.cpp:557
const TableIndexEntry & operator[](const std::string &tag) const
Accesses a TableIndexEntry by tag.
Definition opatIO.cpp:319