9#include "fire/exception/Exception.h"
10#include "fire/io/Access.h"
11#include "fire/io/AbstractData.h"
12#include "fire/io/Writer.h"
14#include "fire/io/h5/Reader.h"
16#include "fire/io/root/Reader.h"
37template <
typename DataType>
39 :
BaseData(path), owner_{handle == nullptr} {
45 save_type_ = { boost::core::demangle(
typeid(DataType).name()), class_version<DataType> };
89template <
typename DataType,
typename Enable =
void>
137 }
catch (
const HighFive::DataSetException& e) {
139 const auto& [diskt, diskv] = f.type(this->
path_);
141 ss <<
"Data at " << this->
path_ <<
" could not be loaded into "
142 << memt <<
" (version " << memv <<
") from the type it was written as "
143 << diskt <<
" (version " << diskv <<
")\n"
144 " Check that your implementation of attach can handle any "
145 "previous versions of your class you are trying to read.\n"
146 " H5 Error:\n" << e.what();
155 void load(root::Reader& f)
final override {
187 template <
typename MemberType>
192 "its use in the serialization of variable length types.\n"
193 " Please give your member a more detailed name corresponding to "
194 "your class",
false);
198 if (sl == SaveLoad::LoadOnly)
load =
true;
199 else if (sl == SaveLoad::SaveOnly) {
save =
true; input_file =
nullptr; }
218 template <
typename MemberType>
220 attach(old_name,m,SaveLoad::LoadOnly);
221 attach(new_name,m,SaveLoad::SaveOnly);
247template <
typename AtomicType>
248class Data<AtomicType,
std::enable_if_t<is_atomic_v<AtomicType>>>
318template <
typename ContentType>
333 size_{path +
"/" +
constants::SIZE_NAME, input_file},
334 data_{path +
"/data", input_file} {}
348 this->
handle_->resize(size_.get());
349 for (
std::size_t i_vec{0}; i_vec < size_.get(); i_vec++) {
351 (*(this->
handle_))[i_vec] = data_.get();
375 size_.update(this->
handle_->size());
378 data_.update(this->
handle_->at(i_vec));
408template <
typename KeyType,
typename ValType>
423 size_{path +
"/" +
constants::SIZE_NAME, input_file},
424 keys_{path +
"/keys", input_file},
425 vals_{path +
"/vals", input_file} {}
439 for (
std::size_t i_map{0}; i_map < size_.get(); i_map++) {
442 this->
handle_->emplace(keys_.get(), vals_.get());
466 size_.update(this->
handle_->size());
468 for (
auto const& [key,val] : *(this->
handle_)) {
#define fire_class_version(VERS)
define the version number for a class
Definition: ClassVersion.h:83
Definitions for names of structures required by serialization methods.
Standard base exception class with some useful output information.
Definition: Exception.h:18
Type-specific base class to hold common data methods.
Definition: AbstractData.h:96
std::pair< std::string, int > save_type_
type this data that is being used to write
Definition: AbstractData.h:234
std::optional< std::pair< std::string, int > > load_type_
type this data is loading from
Definition: AbstractData.h:232
AbstractData(const std::string &path, Reader *input_file=nullptr, DataType *handle=nullptr)
Define the dataset path and provide an optional handle.
Definition: Data.h:38
bool owner_
we own the object in memory
Definition: AbstractData.h:239
DataType * handle_
handle on current object in memory
Definition: AbstractData.h:237
Empty data base allowing recursion.
Definition: AbstractData.h:30
std::string path_
path of data set
Definition: AbstractData.h:82
Data(const std::string &path, Reader *input_file=nullptr, AtomicType *handle=nullptr)
We don't do any more initialization except which is handled by the AbstractData.
Definition: Data.h:258
void structure(Writer &f) final override
do NOT persist any structure for atomic types
Definition: Data.h:301
void load(h5::Reader &f) final override
Down to a type that h5::Reader can handle.
Definition: Data.h:269
void save(Writer &f) final override
Down to a type that io::Writer can handle.
Definition: Data.h:291
Data< KeyType > keys_
the data set holding the content of all the keys
Definition: Data.h:487
void structure(Writer &f) final override
pure virtual method for saving structure
Definition: Data.h:476
void load(h5::Reader &f) final override
Load a map from the input file.
Definition: Data.h:437
Data< ValType > vals_
the data set holding the content of all the vals
Definition: Data.h:489
Data< std::size_t > size_
the data set of sizes of the vectors
Definition: Data.h:485
Data(const std::string &path, Reader *input_file=nullptr, std::map< KeyType, ValType > *handle=nullptr)
We create three child data sets, one for the successive sizes of the maps and two to hold all the key...
Definition: Data.h:420
void save(Writer &f) final override
Save a vector to the output file.
Definition: Data.h:465
void structure(Writer &f) final override
pure virtual method for saving structure
Definition: Data.h:383
Data< std::size_t > size_
the data set of sizes of the vectors
Definition: Data.h:391
void save(Writer &f) final override
Save a vector to the output file.
Definition: Data.h:374
Data< ContentType > data_
the data set holding the content of all the vectors
Definition: Data.h:393
void load(h5::Reader &f) final override
Load a vector from the input file.
Definition: Data.h:346
Data(const std::string &path, Reader *input_file=nullptr, std::vector< ContentType > *handle=nullptr)
We create two child data sets, one to hold the successive sizes of the vectors and one to hold all of...
Definition: Data.h:330
General data set.
Definition: Data.h:90
void save(Writer &f) final override
pure virtual method for saving data
Definition: Data.h:166
Reader * input_file_
pointer to the input file (if there is one)
Definition: Data.h:236
void attach(const std::string &name, MemberType &m, SaveLoad sl=SaveLoad::Both)
Attach a member object from the our data handle.
Definition: Data.h:188
std::vector< std::tuple< bool, bool, std::unique_ptr< BaseData > > > members_
list of members in this dataset
Definition: Data.h:234
void load(h5::Reader &f) final override
Loading this dataset from the file involves simply loading all of the members of the data type.
Definition: Data.h:135
SaveLoad
Flag how a member variable should be accessed by serialization.
Definition: Data.h:98
@ LoadOnly
only load the member (read in)
Definition: Data.h:100
@ SaveOnly
only save the member (write out)
Definition: Data.h:101
@ Both
load and save the member
Definition: Data.h:99
Data(const std::string &path, Reader *input_file=nullptr, DataType *handle=nullptr)
Attach ourselves to the input type after construction.
Definition: Data.h:116
void rename(const std::string &old_name, const std::string &new_name, MemberType &m)
Rename a member variable.
Definition: Data.h:219
void structure(Writer &f) final override
pure virtual method for saving structure
Definition: Data.h:170
Prototype for reading files within fire.
Definition: Reader.h:29
virtual std::pair< std::string, int > type(const std::string &path)=0
Get the type of the input object.
Write the fire DataSets into a deterministic structure in the output HDF5 data file.
Definition: Writer.h:19
Reading a file generated by fire.
Definition: Reader.h:22
Reading ROOT files into our data structures.
Definition: Reader.h:29
Geant4 does a GLOBAL definition of the keyword TRUE.
Definition: AbstractData.h:11
static void connect(T &t, D &d)
Connect the input types by attaching t to do.
Definition: Access.h:33
Structure constants vital to serialization method.
Definition: Constants.h:16
static const std::string SIZE_NAME
the name of the size dataset for variable types
Definition: Constants.h:30