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 { 00017 struct HostConfig 00018 { 00019 fhicl::Atom<int> rank{ fhicl::Name{"rank"}, fhicl::Comment{"Rank index"} }; 00020 fhicl::Atom<std::string> host{ fhicl::Name{"host"}, fhicl::Comment{"Hostname for artdaq application with this rank"} }; 00021 fhicl::Atom<int> portOffset{ fhicl::Name{"portOffset"},fhicl::Comment{"DEPRECATED: Port offset of this artdaq application"}, 5500 }; 00022 }; 00023 struct Config 00024 { 00025 fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") }; 00026 }; 00027 }; 00028 00029 struct DestinationInfo 00030 { 00031 std::string hostname; 00032 int portOffset; 00033 }; 00034 typedef std::map<int, DestinationInfo> hostMap_t; 00035 00036 inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input) 00037 { 00038 std::vector<fhicl::ParameterSet> output; 00039 for (auto& rank : input) 00040 { 00041 fhicl::ParameterSet rank_output; 00042 rank_output.put<int>("rank", rank.first); 00043 rank_output.put<std::string>("host", rank.second.hostname); 00044 rank_output.put<int>("portOffset", rank.second.portOffset); 00045 output.push_back(rank_output); 00046 } 00047 return output; 00048 } 00049 00050 inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t output = hostMap_t()) 00051 { 00052 if (pset.has_key("host_map")) { 00053 auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map"); 00054 for (auto& ps : hosts) 00055 { 00056 auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT); 00057 DestinationInfo info; 00058 info.hostname = ps.get<std::string>("host", "localhost"); 00059 info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset; 00060 00061 if (output.count(rank) && (output[rank].hostname != info.hostname || output[rank].portOffset != info.portOffset)) 00062 { 00063 TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!"; 00064 } 00065 output[rank] = info; 00066 } 00067 } 00068 return output; 00069 } 00070 } 00071 00072 #endif