Utopia 2
Framework for studying models of complex & adaptive systems.
|
Manage different tasks of writing out data from a source in a uniform yet flexible way. This is a class which, when being supplied with appropriate callables, manages their execution. More...
#include <data_manager.hh>
Public Types | |
using | Self = DataManager< Traits > |
Alias for own type. | |
using | Task = typename Traits::Task |
Task type, as defined in the traits. | |
using | Decider = typename Traits::Decider |
Decider type, as defined in the traits. | |
using | Trigger = typename Traits::Trigger |
Trigger type, as defined in the traits. | |
using | ExecutionProcess = typename Traits::ExecutionProcess |
Execution process type, as defined in the traits. | |
using | TaskMap = std::unordered_map< std::string, std::shared_ptr< Task > > |
Map of task names to shared pointers of Tasks; supporting polymorphism. | |
using | OrderedTaskMap = std::map< std::string, std::shared_ptr< Task > > |
Same as TaskMap, but using std::map such that ordering is preserved. | |
using | DeciderMap = std::unordered_map< std::string, std::shared_ptr< Decider > > |
Map of decider names to decider functions. | |
using | OrderedDeciderMap = std::map< std::string, std::shared_ptr< Decider > > |
Same as DeciderMap, but using std::map such that ordering is preserved. | |
using | TriggerMap = std::unordered_map< std::string, std::shared_ptr< Trigger > > |
Map of trigger names to trigger functions. | |
using | OrderedTriggerMap = std::map< std::string, std::shared_ptr< Trigger > > |
Same as TriggerMap, but using std::map such that ordering is preserved. | |
using | AssocsMap = std::unordered_map< std::string, std::vector< std::string > > |
Map of decider/task names to a collection of task names. | |
Public Member Functions | |
template<class Model , typename... Args> | |
void | operator() (Model &&model, Args &&... args) |
Invoke the execution process. | |
DeciderMap & | get_deciders () |
Get the container of decider objects. | |
TaskMap & | get_tasks () |
Get the container of task objects. | |
TriggerMap & | get_triggers () |
Get the container of trigger objects. | |
AssocsMap & | get_decider_task_map () |
Get the decider task map object. | |
AssocsMap & | get_trigger_task_map () |
Get the trigger task map object. | |
const std::shared_ptr< spdlog::logger > & | get_logger () const |
Get the logger used in this DataManager. | |
DataManager ()=default | |
Construct a new Data Manager object. | |
DataManager (const DataManager &other)=default | |
Construct a new Data Manager object. | |
DataManager (DataManager &&other)=default | |
Construct a new Data Manager object. | |
DataManager & | operator= (const DataManager &other)=default |
Copy assignment. | |
DataManager & | operator= (DataManager &&other)=default |
Move assignment. | |
virtual | ~DataManager ()=default |
Destroy the Data Manager object. | |
DataManager (const Config &cfg, TaskMap tasks, std::unordered_map< std::string, std::function< std::shared_ptr< Decider >() > > deciders, std::unordered_map< std::string, std::function< std::shared_ptr< Trigger >() > > triggers, ExecutionProcess execproc) | |
Construct DataManager using a config node. | |
DataManager (OrderedTaskMap tasks, OrderedDeciderMap deciders, OrderedTriggerMap triggers, ExecutionProcess execproc, std::map< std::string, std::string > decider_task_assocs={}, std::map< std::string, std::string > trigger_task_assocs={}) | |
Construct DataManager without config node from passed mappings only. If the last two arguments are not given, it is assumed that tasks, deciders, triggers are of equal length and are to be associated in a one-to-one way in the order given. This order dependencey is also the reason why we make use of 'OrderedTaskMap' (an std::map) here. | |
void | swap (DataManager &other) |
Exchange the state of the caller with the argument 'other'. | |
Protected Member Functions | |
template<typename ObjMap , typename KnownObjectsMap > | |
ObjMap | _setup_from_config (const Config &cfg, KnownObjectsMap &&known_objects) |
TaskMap | _filter_tasks_from_config (const Config &task_cfg, TaskMap &tasks) |
Check which tasks supplied to the datamanager are active and shall be retained, using the config node provided. | |
template<typename DTMap > | |
AssocsMap | _associate_from_config (const Config &task_cfg, DTMap &&dt_map, std::string lookup_key) |
Given a configuration, builds an association map. | |
Protected Attributes | |
std::shared_ptr< spdlog::logger > | _log |
Used to inform about progress of DataManager operations. | |
TaskMap | _tasks |
Stores (name, task) pairs in an unordered map. | |
DeciderMap | _deciders |
Stores (name, deciderfunction) pairs in an unordered map. | |
TriggerMap | _triggers |
Stores (name, triggerfunction) pairs in an unordered map. | |
AssocsMap | _decider_task_map |
Mapping from deciders names to containers of names of tasks that use those deciders. | |
AssocsMap | _trigger_task_map |
Mapping from trigger names to containers of names of tasks that use those triggers. | |
ExecutionProcess | _execution_process |
Callable which tells how to utilize triggers, deciders, tasks to write data. | |
Manage different tasks of writing out data from a source in a uniform yet flexible way. This is a class which, when being supplied with appropriate callables, manages their execution.
The entire process of writing data from a source to a location consists of deciding when to write, deciding when to switch location (making sure the respective location exists) and then actually writing data. The DataManager handles multiple independent instances of this process. In that sence, it works like an STL stream.
if
clause context. This is called a "decider". How this works is user defined. All deciders have to have the same call signature. All deciders need to have a common base type.if
clause context. This is called a "trigger". How this works is user defined. All trigges need to have a common base type.The actual execution of all data writing processes is handled by one and only one callable, the so-called "execution process". This has to at least be able to receive a reference to a DataManager instance, a reference to an object being a source of data (the model), and optionally an arbitrary number of additional arguments.
The details of all these callables/classes are implementation defined and up to the user.
Traits | A ::DataManagerTraits-like type. Supplies all customaizable types for the DataManager, i.e. the decider, trigger, task, and execution process. |
using Utopia::DataIO::DataManager< Traits >::AssocsMap = std::unordered_map< std::string, std::vector< std::string > > |
Map of decider/task names to a collection of task names.
using Utopia::DataIO::DataManager< Traits >::Decider = typename Traits::Decider |
Decider type, as defined in the traits.
using Utopia::DataIO::DataManager< Traits >::DeciderMap = std::unordered_map< std::string, std::shared_ptr< Decider > > |
Map of decider names to decider functions.
using Utopia::DataIO::DataManager< Traits >::ExecutionProcess = typename Traits::ExecutionProcess |
Execution process type, as defined in the traits.
using Utopia::DataIO::DataManager< Traits >::OrderedDeciderMap = std::map< std::string, std::shared_ptr< Decider > > |
Same as DeciderMap, but using std::map such that ordering is preserved.
using Utopia::DataIO::DataManager< Traits >::OrderedTaskMap = std::map< std::string, std::shared_ptr< Task > > |
Same as TaskMap, but using std::map such that ordering is preserved.
using Utopia::DataIO::DataManager< Traits >::OrderedTriggerMap = std::map< std::string, std::shared_ptr< Trigger > > |
Same as TriggerMap, but using std::map such that ordering is preserved.
using Utopia::DataIO::DataManager< Traits >::Self = DataManager< Traits > |
Alias for own type.
using Utopia::DataIO::DataManager< Traits >::Task = typename Traits::Task |
Task type, as defined in the traits.
using Utopia::DataIO::DataManager< Traits >::TaskMap = std::unordered_map< std::string, std::shared_ptr< Task > > |
Map of task names to shared pointers of Tasks; supporting polymorphism.
using Utopia::DataIO::DataManager< Traits >::Trigger = typename Traits::Trigger |
Trigger type, as defined in the traits.
using Utopia::DataIO::DataManager< Traits >::TriggerMap = std::unordered_map< std::string, std::shared_ptr< Trigger > > |
Map of trigger names to trigger functions.
|
default |
Construct a new Data Manager object.
|
default |
Construct a new Data Manager object.
other | Object to copy state from |
|
default |
Construct a new Data Manager object.
other | Object to move state from |
|
virtualdefault |
Destroy the Data Manager object.
|
inline |
Construct DataManager using a config node.
Arguments are an unordered_map that assigns names to shared_ptrs of tasks, and two other unordered_maps that assign names to factory functions for producing shared_ptrs to Deciders and triggers. This factory function approach enables us to use dynamic polymorphism on the deciders and triggers. This ability is not useful for tasks however, because they are designed to receive their functionality from the outside via passing them function objects on construction. Hence it is forgone here.
cfg | Configuration node that contains datamanager config options |
tasks | unordered_map containing name->shared_ptr_to_task mapping |
deciders | map associating names to factory functions producing shared_ptr_to_deciders |
triggers | map associating names to factory functions producing shared_ptr_to_triggers |
execproc | Function object that determines the execution process of the datamanager, i.e., how the deciders, triggers and tasks work together to produce the output data |
|
inline |
Construct DataManager without config node from passed mappings only. If the last two arguments are not given, it is assumed that tasks, deciders, triggers are of equal length and are to be associated in a one-to-one way in the order given. This order dependencey is also the reason why we make use of 'OrderedTaskMap' (an std::map) here.
tasks | map that assigns names to shared_ptrs to tasks |
deciders | map that assigns names to shared_ptrs to deciders |
triggers | map that assigns names to shared_ptrs to triggers |
execproc | Function object that determines the execution process of the datamanager, i.e., how the deciders, triggers and tasks work together to produce the the output data |
decider_task_assocs | Map that assigns each task a decider function by name: taskname->decidername |
trigger_task_assocs | Map that assigns each task a trigger function by name: taskname->triggername |
|
inlineprotected |
Given a configuration, builds an association map.
DTMap | automatically determined |
task_cfg | The mapping to iterate as given by the config. It holds the tasks and names the decider and trigger and the task is associated to and tells if it is active or not. |
dt_map | Map that holds names->decider/trigger mapping. Used to check if the names in the config indeed match some known decider/trigger. |
lookup_key | Key which names the mapping used for association, i.e., "decider" or "trigger". |
|
inlineprotected |
Check which tasks supplied to the datamanager are active and shall be retained, using the config node provided.
task_cfg | config node defining tasks |
tasks | unordered map naming pointers to tasks |
|
inlineprotected |
|
inline |
|
inline |
|
inline |
Get the logger used in this DataManager.
|
inline |
|
inline |
|
inline |
|
inline |
Invoke the execution process.
Args | Parameter pack types |
model | The model reference to pass on to the execution process |
args | The parameter pack to pass on to the execution process |
|
default |
|
default |
|
inline |
Exchange the state of the caller with the argument 'other'.
other |
|
protected |
Mapping from deciders names to containers of names of tasks that use those deciders.
|
protected |
Stores (name, deciderfunction) pairs in an unordered map.
|
protected |
Callable which tells how to utilize triggers, deciders, tasks to write data.
|
protected |
Used to inform about progress of DataManager operations.
|
protected |
Stores (name, task) pairs in an unordered map.
|
protected |
Mapping from trigger names to containers of names of tasks that use those triggers.
|
protected |
Stores (name, triggerfunction) pairs in an unordered map.