Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
Utopia::DataIO::DataManagerFactory< Model > Class Template Reference

Factory function which produces a Datamanager of type Default::DefaultDataManager<Model> from a config and argumets from which to construct writetasks. More...

#include <factory.hh>

Public Member Functions

template<typename... Args>
auto operator() (const Config &conf, const std::tuple< Args... > &args, const Default::DefaultDecidermap< Model > &deciderfactories=Default::default_deciders< Model >, const Default::DefaultTriggermap< Model > &triggerfactories=Default::default_triggers< Model >)
 Builds a new datamanager from a config file and a tuple of tuples of arguments.
 

Private Member Functions

template<typename ArgTpl >
std::pair< std::string, std::shared_ptr< Default::DefaultWriteTask< Model > > > _call_taskfactory (std::string typetag, ArgTpl &&arg_tpl)
 Function which calls the taskfactory with argument tuples, and takes care of using the correct type-tags.
 

Detailed Description

template<class Model>
class Utopia::DataIO::DataManagerFactory< Model >

Factory function which produces a Datamanager of type Default::DefaultDataManager<Model> from a config and argumets from which to construct writetasks.

Template Parameters
ModelModeltype to use.
ArgsTuple types <TypeTag, std::string, argstypes_for_task...>
Parameters
modelReference to the model the produced datamanagere shall belong to
w_argsTuples, have to contain [tagtype, name, argumnets...]
Returns
auto DefaultDatamanager with DefaultWriteTasks produced from model

Member Function Documentation

◆ _call_taskfactory()

template<class Model >
template<typename ArgTpl >
std::pair< std::string, std::shared_ptr< Default::DefaultWriteTask< Model > > > Utopia::DataIO::DataManagerFactory< Model >::_call_taskfactory ( std::string  typetag,
ArgTpl &&  arg_tpl 
)
inlineprivate

Function which calls the taskfactory with argument tuples, and takes care of using the correct type-tags.

Template Parameters
ArgTplautomatically determined
Parameters
typetagstring indicating which type tag to use
arg_tpltuple of arguments to invoke the taskfactory with
Returns
Default::DefaultWriteTask<Model> produced by invoking the TaskFactory with the passed argument tuple
615 {
616
617 if (typetag == "plain")
618 {
619 DataIO::TaskFactory< Model, TypeTag::plain > factory;
620
621 return std::apply(factory, std::forward< ArgTpl >(arg_tpl));
622 }
623 else if (typetag == "edge_property")
624 {
625 DataIO::TaskFactory< Model, TypeTag::edge_property > factory;
626
627 return std::apply(factory, std::forward< ArgTpl >(arg_tpl));
628 }
629 else if (typetag == "vertex_descriptor")
630 {
631 DataIO::TaskFactory< Model, TypeTag::vertex_descriptor > factory;
632
633 return std::apply(factory, std::forward< ArgTpl >(arg_tpl));
634 }
635 else if (typetag == "vertex_property")
636 {
637 DataIO::TaskFactory< Model, TypeTag::vertex_property > factory;
638
639 return std::apply(factory, std::forward< ArgTpl >(arg_tpl));
640 }
641 else
642 {
643 DataIO::TaskFactory< Model, TypeTag::edge_descriptor > factory;
644
645 return std::apply(factory, std::forward< ArgTpl >(arg_tpl));
646 }
647 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ operator()()

template<class Model >
template<typename... Args>
auto Utopia::DataIO::DataManagerFactory< Model >::operator() ( const Config conf,
const std::tuple< Args... > &  args,
const Default::DefaultDecidermap< Model > &  deciderfactories = Default::default_deciders<Model>,
const Default::DefaultTriggermap< Model > &  triggerfactories = Default::default_triggers<Model> 
)
inline

Builds a new datamanager from a config file and a tuple of tuples of arguments.

The latter are supplemented by the arguments given by the config, and then passed to the writetask factory, each. The result is then used for creating the datamanager. The arguments that need to be supplied in the code are

  • function which returns the data source, preferably by reference. Mind that you need to use decltype(auto) as return type if using a lambda.
  • the getter function which extracts data from the sources values, same thing as employed by dataset->write.
  • callable to write group attribute or tuple containing (name, data) or 'Nothing{}' if no attributes are desired
  • callable to write dataset attribute or tuple containing (name, data) or 'Nothing{}' if no attributes are desired
Template Parameters
Argsautomatically determined
Parameters
confconfig node giving the 'data_manager' configuration nodes
argstuple of argument tuples
Returns
auto DefaultDatamanager<Model> with the tasks built from config and arguments
681 {
682 // Get the global data manager logger
683 const auto _log = spdlog::get("data_mngr");
684
685 if constexpr (sizeof...(Args) == 0)
686 {
687 _log->info("Empty argument tuple for DataManager factory, "
688 "building default ...");
689 return Default::DefaultDataManager< Model >{};
690 }
691 else
692 {
693 // read the tasks from the config into a map
694 // has the consequence that the ordering need to match
695 std::map< std::string, Config > tasknodes;
696 for (auto&& node : conf["tasks"])
697 {
698 _log->info("Name of current task: {}",
699 node.first.as< std::string >());
700
701 tasknodes[node.first.as< std::string >()] = node.second;
702 }
703
704 // this transforms the tuple of argument tuples std::tuple< Args...
705 // >
706 std::unordered_map<
707 std::string,
708 std::shared_ptr< Default::DefaultWriteTask< Model > > >
709 tasks;
710
711 boost::hana::for_each(
712 args,
713 // function gets a tuple representing arguments for the
714 // writetask extracts config-supplied arguments from the
715 // respective config node if the latter is found, puts them in
716 // their correct place, then forwards the rest to the
717 // taksfactory. If no config node for a given taskname is found,
718 // exception is thrown
719 [&](const auto& arg_tpl) {
720 using std::get;
721 std::string name = "";
722 std::string name_in_tpl = get< 0 >(arg_tpl);
724
725 // find the current task in the config, if not found throw
726 if (tasknode_iter != tasknodes.end())
727 {
728 name = tasknode_iter->first;
729 }
730 else
731 {
732 // .. and throw if it is not
733 throw std::invalid_argument(
734 "A task with name '" + name_in_tpl +
735 "' was not found in the config!");
736 }
737
738 // read out the typetag from the config
739 std::string typetag = "";
740 if (not tasknode_iter->second["typetag"])
741 {
742 typetag = "plain";
743 }
744 else
745 {
746 get_as< std::string >("typetag", tasknode_iter->second);
747 }
748
749 // make a tuple of types from the argtuple except the first
750 // element which is the sentinel name
751 auto type_tuple = boost::hana::transform(
752 boost::hana::remove_at(arg_tpl,
753 boost::hana::size_t< 0 >{}),
754 [](auto&& t) {
755 return boost::hana::type_c<
756 std::decay_t< decltype(t) > >;
757 });
758
759 constexpr bool is_all_callable =
760 decltype(boost::hana::unpack(
762 boost::hana::template_<
763 _DMUtils::all_callable >))::type::value;
764
765 // all arguments are callables
766 if constexpr (is_all_callable)
767 {
768 _log->info("Building write task '{}' via factory ...",
769 name);
771 }
772 // not all-callable arguments
773 else
774 {
775
776 // extract arguments from the configfile
777 auto config_args = std::make_tuple(
778 // name
780 // basegroup_path
781 get_as< std::string >("basegroup_path",
782 tasknode_iter->second),
783 // dataset_descriptor
784 DatasetDescriptor{
785 get_as< std::string >("dataset_path",
786 tasknode_iter->second),
787 (tasknode_iter->second["capacity"]
788 ? get_as< std::vector< hsize_t > >(
789 "capacity", tasknode_iter->second)
790 : std::vector< hsize_t >{}),
791 (tasknode_iter->second["chunksize"]
793 "chunksize", tasknode_iter->second)
794 : std::vector< hsize_t >{}),
795 (tasknode_iter->second["compression"]
796 ? get_as< int >("compression",
797 tasknode_iter->second)
798 : 0) });
799
800 // remove the sentinel name and concat the tuples, which
801 // then is forwarded to args
802 auto full_arg_tpl = std::tuple_cat(
803 config_args,
804 boost::hana::remove_at(arg_tpl,
805 boost::hana::size_t< 0 >{}));
806
807 _log->info("Building write task '{}' via factory ...",
808 name);
809
810 tasks.emplace(_call_taskfactory(typetag, full_arg_tpl));
811 }
812 });
813
814 _log->info("Forwarding arguments to DataManager constructor ...");
815 // then produce default datamanager with all default deciders,
816 // triggers etc
817
818 return Default::DefaultDataManager< Model >(
819 conf,
820 tasks,
821 deciderfactories,
822 triggerfactories,
823 Default::DefaultExecutionProcess());
824 }
825 }
std::pair< std::string, std::shared_ptr< Default::DefaultWriteTask< Model > > > _call_taskfactory(std::string typetag, ArgTpl &&arg_tpl)
Function which calls the taskfactory with argument tuples, and takes care of using the correct type-t...
Definition factory.hh:614
Definition parallel.hh:235

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