artdaq  v3_01_00
HostMap.hh
1 #ifndef ARTDAQ_TRANSFERPLUGINS_DETAIL_HOSTMAP_HH
2 #define ARTDAQ_TRANSFERPLUGINS_DETAIL_HOSTMAP_HH
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include "fhiclcpp/ParameterSet.h"
8 #include "artdaq/TransferPlugins/TransferInterface.hh"
9 
10 namespace artdaq {
11 
13  {
14  std::string hostname;
15  int portOffset;
16  };
17  typedef std::map<int, DestinationInfo> hostMap_t;
18 
19  inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input)
20  {
21  std::vector<fhicl::ParameterSet> output;
22  for (auto& rank : input)
23  {
24  fhicl::ParameterSet rank_output;
25  rank_output.put<int>("rank", rank.first);
26  rank_output.put<std::string>("host", rank.second.hostname);
27  rank_output.put<int>("portOffset", rank.second.portOffset);
28  output.push_back(rank_output);
29  }
30  return output;
31  }
32 
33  inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t output = hostMap_t())
34  {
35  if (pset.has_key("host_map")) {
36  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
37  for (auto& ps : hosts)
38  {
39  auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT);
40  DestinationInfo info;
41  info.hostname = ps.get<std::string>("host", "localhost");
42  info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset;
43 
44  if (output.count(rank) && (output[rank].hostname != info.hostname || output[rank].portOffset != info.portOffset))
45  {
46  TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!";
47  }
48  output[rank] = info;
49  }
50  }
51  return output;
52  }
53 }
54 
55 #endif
Value to be returned upon receive timeout.