00001 #ifndef ARTDAQ_TRANSFERPLUGINS_DETAIL_HOSTMAP_HH 00002 #define ARTDAQ_TRANSFERPLUGINS_DETAIL_HOSTMAP_HH 00003 00004 #include <string> 00005 #include <vector> 00006 #include <map> 00007 #include "fhiclcpp/ParameterSet.h" 00008 #include "artdaq/TransferPlugins/TransferInterface.hh" 00009 #include "fhiclcpp/types/Sequence.h" 00010 #include "fhiclcpp/types/Table.h" 00011 #include "fhiclcpp/types/Atom.h" 00012 00013 namespace artdaq { 00014 00015 struct HostMap 00016 { 00020 struct HostConfig 00021 { 00023 fhicl::Atom<int> rank{ fhicl::Name{"rank"}, fhicl::Comment{"Rank index"} }; 00025 fhicl::Atom<std::string> host{ fhicl::Name{"host"}, fhicl::Comment{"Hostname for artdaq application with this rank"} }; 00026 }; 00030 struct Config 00031 { 00035 fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") }; 00036 }; 00037 }; 00038 00039 typedef std::map<int, std::string> hostMap_t; 00040 00046 inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, std::string> input) 00047 { 00048 std::vector<fhicl::ParameterSet> output; 00049 for (auto& rank : input) 00050 { 00051 fhicl::ParameterSet rank_output; 00052 rank_output.put<int>("rank", rank.first); 00053 rank_output.put<std::string>("host", rank.second); 00054 output.push_back(rank_output); 00055 } 00056 return output; 00057 } 00058 00066 inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, hostMap_t map = hostMap_t()) 00067 { 00068 if (pset.has_key("host_map")) { 00069 auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map"); 00070 for (auto& ps : hosts) 00071 { 00072 auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT); 00073 auto hostname = ps.get<std::string>("host", "localhost"); 00074 00075 if (map.count(rank) && (map[rank] != hostname )) 00076 { 00077 TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!"; 00078 } 00079 map[rank] = hostname; 00080 } 00081 } 00082 return map; 00083 } 00084 } 00085 00086 #endif