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"} }; 00027 fhicl::Atom<int> portOffset{ fhicl::Name{"portOffset"},fhicl::Comment{"DEPRECATED: Port offset of this artdaq application"}, 5500 }; 00028 }; 00032 struct Config 00033 { 00037 fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") }; 00038 }; 00039 }; 00040 00044 struct DestinationInfo 00045 { 00046 std::string hostname; 00047 int portOffset; 00048 }; 00049 typedef std::map<int, DestinationInfo> hostMap_t; 00050 00056 inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input) 00057 { 00058 std::vector<fhicl::ParameterSet> output; 00059 for (auto& rank : input) 00060 { 00061 fhicl::ParameterSet rank_output; 00062 rank_output.put<int>("rank", rank.first); 00063 rank_output.put<std::string>("host", rank.second.hostname); 00064 rank_output.put<int>("portOffset", rank.second.portOffset); 00065 output.push_back(rank_output); 00066 } 00067 return output; 00068 } 00069 00077 inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t map = hostMap_t()) 00078 { 00079 if (pset.has_key("host_map")) { 00080 auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map"); 00081 for (auto& ps : hosts) 00082 { 00083 auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT); 00084 DestinationInfo info; 00085 info.hostname = ps.get<std::string>("host", "localhost"); 00086 info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset; 00087 00088 if (map.count(rank) && (map[rank].hostname != info.hostname || map[rank].portOffset != info.portOffset)) 00089 { 00090 TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!"; 00091 } 00092 map[rank] = info; 00093 } 00094 } 00095 return map; 00096 } 00097 } 00098 00099 #endif