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 00010 namespace artdaq { 00011 00012 struct DestinationInfo 00013 { 00014 std::string hostname; 00015 int portOffset; 00016 }; 00017 typedef std::map<int, DestinationInfo> hostMap_t; 00018 00019 inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input) 00020 { 00021 std::vector<fhicl::ParameterSet> output; 00022 for (auto& rank : input) 00023 { 00024 fhicl::ParameterSet rank_output; 00025 rank_output.put<int>("rank", rank.first); 00026 rank_output.put<std::string>("host", rank.second.hostname); 00027 rank_output.put<int>("portOffset", rank.second.portOffset); 00028 output.push_back(rank_output); 00029 } 00030 return output; 00031 } 00032 00033 inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t output = hostMap_t()) 00034 { 00035 if (pset.has_key("host_map")) { 00036 auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map"); 00037 for (auto& ps : hosts) 00038 { 00039 auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT); 00040 DestinationInfo info; 00041 info.hostname = ps.get<std::string>("host", "localhost"); 00042 info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset; 00043 00044 if (output.count(rank) && (output[rank].hostname != info.hostname || output[rank].portOffset != info.portOffset)) 00045 { 00046 TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!"; 00047 } 00048 output[rank] = info; 00049 } 00050 } 00051 return output; 00052 } 00053 } 00054 00055 #endif