1#ifndef UTOPIA_DATAIO_DATA_MANAGER_DEFAULTS_HH
2#define UTOPIA_DATAIO_DATA_MANAGER_DEFAULTS_HH
4#include <boost/hana/ext/std/tuple.hpp>
5#include <boost/hana/fold.hpp>
6#include <boost/hana/zip.hpp>
7#include <unordered_map>
9#include "../cfg_utils.hh"
34 std::function< std::shared_ptr< HDFGroup >(std::shared_ptr< HDFGroup >&&) >;
37template <
typename Model >
39 std::function<
void(std::shared_ptr< HDFDataset >&,
Model&) >;
42template <
typename Model >
44 std::shared_ptr< HDFGroup >&,
Model&) >;
47template <
typename Model >
49 std::function<
void(std::shared_ptr< HDFGroup >&,
Model&) >;
52template <
typename Model >
54 std::function<
void(std::shared_ptr< HDFDataset >&,
Model&) >;
64template <
typename Model >
94 template <
class Datamanager,
class Model >
102 if (
taskpair.second->base_group ==
nullptr)
105 taskpair.second->build_basegroup(
m.get_hdfgrp());
108 for (
auto& [name,
trigger] :
dm.get_triggers())
112 for (
auto&
taskname :
dm.get_trigger_task_map()[name])
119 task->active_dataset =
121 task->base_group,
m);
123 if (
task->write_attribute_basegroup)
125 task->write_attribute_basegroup(
126 task->base_group,
m);
132 for (
auto& [name,
decider] :
dm.get_deciders())
136 for (
auto&
taskname :
dm.get_decider_task_map()[name])
140 task->write_data(
task->active_dataset,
142 if (
task->write_attribute_active_dataset)
144 task->write_attribute_active_dataset(
145 task->active_dataset,
m);
165template<
typename Model>
186template <
typename Model >
237 fmt::format(
"Array of unexpected length {}! "
238 "Expected array of length 2 or 3 [start, stop, step] "
239 "with step optional (default 1).",
244 std::array< std::size_t, 3 >
interval;
264template <
typename Model >
274 return (
m.get_time() ==
time);
303template <
typename Model >
353 return boost::hana::fold(
376 for (
auto it = cfg.begin();
it != cfg.end(); ++
it, ++
conf_it)
403template <
typename Model >
406 std::function< std::shared_ptr< Decider< Model > >() > >;
419template <
typename Model >
421 { std::string(
"always"),
422 []() {
return std::make_shared< AlwaysDecider< Model > >(); } },
423 { std::string(
"once"),
424 []() {
return std::make_shared< OnceDecider< Model > >(); } },
425 { std::string(
"interval"),
426 []() {
return std::make_shared< IntervalDecider< Model > >(); } }
438template <
typename Model >
441template <
typename Model >
444template <
typename Model >
447template <
typename Model >
453template <
typename Model >
460template <
typename Model >
For access to a dict-like structure with a bad key.
Definition exceptions.hh:67
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
OutputIt copy(const Utopia::ExecPolicy policy, InputIt first, InputIt last, OutputIt d_first)
Copy the input range to a new range.
Definition parallel.hh:324
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
static DefaultDecidermap< Model > default_deciders
Map that names the deciders supplied by default such that they can be addressed in a config file.
Definition defaults.hh:420
std::function< void(std::shared_ptr< HDFDataset > &, Model &) > DefaultAttributeWriterDataset
Type of the default attribute writer for datasets.
Definition defaults.hh:54
std::function< std::shared_ptr< HDFGroup >(std::shared_ptr< HDFGroup > &&) > DefaultBaseGroupBuilder
Type of the default group builder.
Definition defaults.hh:34
std::unordered_map< std::string, std::function< std::shared_ptr< Decider< Model > >() > > DefaultDecidermap
Definition defaults.hh:406
std::function< std::shared_ptr< HDFDataset >(std::shared_ptr< HDFGroup > &, Model &) > DefaultBuilder
Type of the default dataset builder.
Definition defaults.hh:44
std::function< void(std::shared_ptr< HDFGroup > &, Model &) > DefaultAttributeWriterGroup
Type of the default attribute writer for groups.
Definition defaults.hh:49
DefaultDecidermap< Model > DefaultTriggermap
Definition defaults.hh:454
std::function< void(std::shared_ptr< HDFDataset > &, Model &) > DefaultDataWriter
Type of the default data writer.
Definition defaults.hh:39
static DefaultTriggermap< Model > default_triggers
Default trigger factories. Equal to deciders because while the task they fullfill is different,...
Definition defaults.hh:461
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Decider which always returns true.
Definition defaults.hh:305
virtual ~AlwaysDecider()=default
virtual void set_from_cfg(const Config &) override
Definition defaults.hh:317
virtual bool operator()(Model &) override
Definition defaults.hh:310
AlwaysDecider(AlwaysDecider &&)=default
AlwaysDecider & operator=(AlwaysDecider &&)=default
AlwaysDecider(const AlwaysDecider &)=default
AlwaysDecider & operator=(const AlwaysDecider &)=default
Combines a number of deciders; returns true if any of them is true.
Definition defaults.hh:338
std::tuple< Deciders... > held_deciders
Tuple of associated decider objects.
Definition defaults.hh:343
CompositeDecider()=default
virtual void set_from_cfg(const Config &cfg) override
Set the decider up from a given config node.
Definition defaults.hh:367
virtual ~CompositeDecider()=default
CompositeDecider & operator=(const CompositeDecider &)=default
CompositeDecider & operator=(CompositeDecider &&)=default
virtual bool operator()(Model &m) override
Evaluates the composite deciders; returns true if any is true.
Definition defaults.hh:351
CompositeDecider(const CompositeDecider &)=default
Common interface for all deciders (and triggers, for that matter). Every decider/Trigger must inherit...
Definition defaults.hh:166
virtual void set_from_cfg(const Config &)=0
virtual bool operator()(Model &)=0
Decider & operator=(const Decider &)=default
Decider(const Decider &)=default
Decider & operator=(Decider &&)=default
Decider(Decider &&)=default
virtual ~Decider()=default
Functor representing what is considered the most widely used execution process for writing data.
Definition defaults.hh:84
void operator()(Datamanager &dm, Model &m)
Call operator for executing the execution process.
Definition defaults.hh:96
A decider that returns true when within certain time intervals.
Definition defaults.hh:188
IntervalDecider(const IntervalDecider &)=default
IntervalDecider & operator=(IntervalDecider &&)=default
IntervalDecider & operator=(const IntervalDecider &)=default
virtual bool operator()(Model &m) override
Definition defaults.hh:197
IntervalDecider(IntervalDecider &&)=default
virtual ~IntervalDecider()=default
IntervalDecider()=default
virtual void set_from_cfg(const Config &cfg) override
Set the decider up from a given config node.
Definition defaults.hh:224
std::list< std::array< std::size_t, 3 > > intervals
The sequence of intervals within to return true.
Definition defaults.hh:194
Decider which only returns true at a certain time.
Definition defaults.hh:266
OnceDecider & operator=(const OnceDecider &)=default
virtual void set_from_cfg(const Config &cfg) override
Set the decider up from a given config node.
Definition defaults.hh:283
std::size_t time
Definition defaults.hh:269
virtual bool operator()(Model &m) override
Definition defaults.hh:272
OnceDecider(const OnceDecider &)=default
OnceDecider(OnceDecider &&)=default
OnceDecider()=default
Construct a OnceDecider that evaluates to true at time zero.
OnceDecider & operator=(OnceDecider &&)=default
virtual ~OnceDecider()=default
Encapsulate a task for writing data to a destination. Containes a callable 'writer' responisible for ...
Definition write_task.hh:50