Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Utopia::DataIO::DataManager< Traits > Class Template Reference

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. More...
 
using Task = typename Traits::Task
 Task type, as defined in the traits. More...
 
using Decider = typename Traits::Decider
 Decider type, as defined in the traits. More...
 
using Trigger = typename Traits::Trigger
 Trigger type, as defined in the traits. More...
 
using ExecutionProcess = typename Traits::ExecutionProcess
 Execution process type, as defined in the traits. More...
 
using TaskMap = std::unordered_map< std::string, std::shared_ptr< Task > >
 Map of task names to shared pointers of Tasks; supporting polymorphism. More...
 
using OrderedTaskMap = std::map< std::string, std::shared_ptr< Task > >
 Same as TaskMap, but using std::map such that ordering is preserved. More...
 
using DeciderMap = std::unordered_map< std::string, std::shared_ptr< Decider > >
 Map of decider names to decider functions. More...
 
using OrderedDeciderMap = std::map< std::string, std::shared_ptr< Decider > >
 Same as DeciderMap, but using std::map such that ordering is preserved. More...
 
using TriggerMap = std::unordered_map< std::string, std::shared_ptr< Trigger > >
 Map of trigger names to trigger functions. More...
 
using OrderedTriggerMap = std::map< std::string, std::shared_ptr< Trigger > >
 Same as TriggerMap, but using std::map such that ordering is preserved. More...
 
using AssocsMap = std::unordered_map< std::string, std::vector< std::string > >
 Map of decider/task names to a collection of task names. More...
 

Public Member Functions

template<class Model , typename... Args>
void operator() (Model &&model, Args &&... args)
 Invoke the execution process. More...
 
DeciderMapget_deciders ()
 Get the container of decider objects. More...
 
TaskMapget_tasks ()
 Get the container of task objects. More...
 
TriggerMapget_triggers ()
 Get the container of trigger objects. More...
 
AssocsMapget_decider_task_map ()
 Get the decider task map object. More...
 
AssocsMapget_trigger_task_map ()
 Get the trigger task map object. More...
 
const std::shared_ptr< spdlog::logger > & get_logger () const
 Get the logger used in this DataManager. More...
 
 DataManager ()=default
 Construct a new Data Manager object. More...
 
 DataManager (const DataManager &other)=default
 Construct a new Data Manager object. More...
 
 DataManager (DataManager &&other)=default
 Construct a new Data Manager object. More...
 
DataManageroperator= (const DataManager &other)=default
 Copy assignment. More...
 
DataManageroperator= (DataManager &&other)=default
 Move assignment. More...
 
virtual ~DataManager ()=default
 Destroy the Data Manager object. More...
 
 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. More...
 
 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. More...
 
void swap (DataManager &other)
 Exchange the state of the caller with the argument 'other'. More...
 

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. More...
 
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. More...
 

Protected Attributes

std::shared_ptr< spdlog::logger > _log
 Used to inform about progress of DataManager operations. More...
 
TaskMap _tasks
 Stores (name, task) pairs in an unordered map. More...
 
DeciderMap _deciders
 Stores (name, deciderfunction) pairs in an unordered map. More...
 
TriggerMap _triggers
 Stores (name, triggerfunction) pairs in an unordered map. More...
 
AssocsMap _decider_task_map
 Mapping from deciders names to containers of names of tasks that use those deciders. More...
 
AssocsMap _trigger_task_map
 Mapping from trigger names to containers of names of tasks that use those triggers. More...
 
ExecutionProcess _execution_process
 Callable which tells how to utilize triggers, deciders, tasks to write data. More...
 

Detailed Description

template<class Traits>
class Utopia::DataIO::DataManager< Traits >

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.

Idea

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.

Implementation

Template Parameters
TraitsA ::DataManagerTraits-like type. Supplies all customaizable types for the DataManager, i.e. the decider, trigger, task, and execution process.

Member Typedef Documentation

◆ AssocsMap

template<class Traits >
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.

◆ Decider

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::Decider = typename Traits::Decider

Decider type, as defined in the traits.

◆ DeciderMap

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::DeciderMap = std::unordered_map< std::string, std::shared_ptr< Decider > >

Map of decider names to decider functions.

◆ ExecutionProcess

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::ExecutionProcess = typename Traits::ExecutionProcess

Execution process type, as defined in the traits.

◆ OrderedDeciderMap

template<class 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.

◆ OrderedTaskMap

template<class Traits >
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.

◆ OrderedTriggerMap

template<class Traits >
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.

◆ Self

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::Self = DataManager< Traits >

Alias for own type.

◆ Task

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::Task = typename Traits::Task

Task type, as defined in the traits.

◆ TaskMap

template<class 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.

◆ Trigger

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::Trigger = typename Traits::Trigger

Trigger type, as defined in the traits.

◆ TriggerMap

template<class Traits >
using Utopia::DataIO::DataManager< Traits >::TriggerMap = std::unordered_map< std::string, std::shared_ptr< Trigger > >

Map of trigger names to trigger functions.

Constructor & Destructor Documentation

◆ DataManager() [1/5]

template<class Traits >
Utopia::DataIO::DataManager< Traits >::DataManager ( )
default

Construct a new Data Manager object.

◆ DataManager() [2/5]

template<class Traits >
Utopia::DataIO::DataManager< Traits >::DataManager ( const DataManager< Traits > &  other)
default

Construct a new Data Manager object.

Parameters
otherObject to copy state from

◆ DataManager() [3/5]

template<class Traits >
Utopia::DataIO::DataManager< Traits >::DataManager ( DataManager< Traits > &&  other)
default

Construct a new Data Manager object.

Parameters
otherObject to move state from

◆ ~DataManager()

template<class Traits >
virtual Utopia::DataIO::DataManager< Traits >::~DataManager ( )
virtualdefault

Destroy the Data Manager object.

◆ DataManager() [4/5]

template<class Traits >
Utopia::DataIO::DataManager< Traits >::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 
)
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.

Parameters
cfgConfiguration node that contains datamanager config options
tasksunordered_map containing name->shared_ptr_to_task mapping
decidersmap associating names to factory functions producing shared_ptr_to_deciders
triggersmap associating names to factory functions producing shared_ptr_to_triggers
execprocFunction object that determines the execution process of the datamanager, i.e., how the deciders, triggers and tasks work together to produce the output data

◆ DataManager() [5/5]

template<class Traits >
Utopia::DataIO::DataManager< Traits >::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 = {} 
)
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.

Parameters
tasksmap that assigns names to shared_ptrs to tasks
decidersmap that assigns names to shared_ptrs to deciders
triggersmap that assigns names to shared_ptrs to triggers
execprocFunction 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_assocsMap that assigns each task a decider function by name: taskname->decidername
trigger_task_assocsMap that assigns each task a trigger function by name: taskname->triggername

Member Function Documentation

◆ _associate_from_config()

template<class Traits >
template<typename DTMap >
AssocsMap Utopia::DataIO::DataManager< Traits >::_associate_from_config ( const Config task_cfg,
DTMap &&  dt_map,
std::string  lookup_key 
)
inlineprotected

Given a configuration, builds an association map.

Template Parameters
DTMapautomatically determined
Parameters
task_cfgThe 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_mapMap that holds names->decider/trigger mapping. Used to check if the names in the config indeed match some known decider/trigger.
lookup_keyKey which names the mapping used for association, i.e., "decider" or "trigger".
Returns
AssocsMap Map that associates the given deciders/triggers with a vector of names that name tasks.

◆ _filter_tasks_from_config()

template<class Traits >
TaskMap Utopia::DataIO::DataManager< Traits >::_filter_tasks_from_config ( const Config task_cfg,
TaskMap tasks 
)
inlineprotected

Check which tasks supplied to the datamanager are active and shall be retained, using the config node provided.

Parameters
task_cfgconfig node defining tasks
tasksunordered map naming pointers to tasks
Returns
TaskMap 'tasks' map filtered by activity

◆ _setup_from_config()

template<class Traits >
template<typename ObjMap , typename KnownObjectsMap >
ObjMap Utopia::DataIO::DataManager< Traits >::_setup_from_config ( const Config cfg,
KnownObjectsMap &&  known_objects 
)
inlineprotected

◆ get_decider_task_map()

template<class Traits >
AssocsMap& Utopia::DataIO::DataManager< Traits >::get_decider_task_map ( )
inline

Get the decider task map object.

Returns
const AssocsMap&

◆ get_deciders()

template<class Traits >
DeciderMap& Utopia::DataIO::DataManager< Traits >::get_deciders ( )
inline

Get the container of decider objects.

Returns
const DeciderMap&

◆ get_logger()

template<class Traits >
const std::shared_ptr< spdlog::logger >& Utopia::DataIO::DataManager< Traits >::get_logger ( ) const
inline

Get the logger used in this DataManager.

Returns
const std::shared_ptr<spdlog::logger>&

◆ get_tasks()

template<class Traits >
TaskMap& Utopia::DataIO::DataManager< Traits >::get_tasks ( )
inline

Get the container of task objects.

Returns
const TaskMap&

◆ get_trigger_task_map()

template<class Traits >
AssocsMap& Utopia::DataIO::DataManager< Traits >::get_trigger_task_map ( )
inline

Get the trigger task map object.

Returns
const AssocsMap&

◆ get_triggers()

template<class Traits >
TriggerMap& Utopia::DataIO::DataManager< Traits >::get_triggers ( )
inline

Get the container of trigger objects.

Returns
const TriggerMap&

◆ operator()()

template<class Traits >
template<class Model , typename... Args>
void Utopia::DataIO::DataManager< Traits >::operator() ( Model &&  model,
Args &&...  args 
)
inline

Invoke the execution process.

Template Parameters
ArgsParameter pack types
Parameters
modelThe model reference to pass on to the execution process
argsThe parameter pack to pass on to the execution process

◆ operator=() [1/2]

template<class Traits >
DataManager& Utopia::DataIO::DataManager< Traits >::operator= ( const DataManager< Traits > &  other)
default

Copy assignment.

Parameters
other
Returns
DataManager& reference to object to assign the state from.

◆ operator=() [2/2]

template<class Traits >
DataManager& Utopia::DataIO::DataManager< Traits >::operator= ( DataManager< Traits > &&  other)
default

Move assignment.

Parameters
other
Returns
DataManager& reference to object to assign the state from.

◆ swap()

template<class Traits >
void Utopia::DataIO::DataManager< Traits >::swap ( DataManager< Traits > &  other)
inline

Exchange the state of the caller with the argument 'other'.

Parameters
other

Member Data Documentation

◆ _decider_task_map

template<class Traits >
AssocsMap Utopia::DataIO::DataManager< Traits >::_decider_task_map
protected

Mapping from deciders names to containers of names of tasks that use those deciders.

◆ _deciders

template<class Traits >
DeciderMap Utopia::DataIO::DataManager< Traits >::_deciders
protected

Stores (name, deciderfunction) pairs in an unordered map.

◆ _execution_process

template<class Traits >
ExecutionProcess Utopia::DataIO::DataManager< Traits >::_execution_process
protected

Callable which tells how to utilize triggers, deciders, tasks to write data.

◆ _log

template<class Traits >
std::shared_ptr< spdlog::logger > Utopia::DataIO::DataManager< Traits >::_log
protected

Used to inform about progress of DataManager operations.

◆ _tasks

template<class Traits >
TaskMap Utopia::DataIO::DataManager< Traits >::_tasks
protected

Stores (name, task) pairs in an unordered map.

◆ _trigger_task_map

template<class Traits >
AssocsMap Utopia::DataIO::DataManager< Traits >::_trigger_task_map
protected

Mapping from trigger names to containers of names of tasks that use those triggers.

◆ _triggers

template<class Traits >
TriggerMap Utopia::DataIO::DataManager< Traits >::_triggers
protected

Stores (name, triggerfunction) pairs in an unordered map.


The documentation for this class was generated from the following file: