artdaq  v3_02_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 #include "fhiclcpp/types/Sequence.h"
10 #include "fhiclcpp/types/Table.h"
11 #include "fhiclcpp/types/Atom.h"
12 
13 namespace artdaq {
14 
15  struct HostMap
16  {
17  struct HostConfig
18  {
19  fhicl::Atom<int> rank{ fhicl::Name{"rank"}, fhicl::Comment{"Rank index"} };
20  fhicl::Atom<std::string> host{ fhicl::Name{"host"}, fhicl::Comment{"Hostname for artdaq application with this rank"} };
21  fhicl::Atom<int> portOffset{ fhicl::Name{"portOffset"},fhicl::Comment{"DEPRECATED: Port offset of this artdaq application"}, 5500 };
22  };
23  struct Config
24  {
25  fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") };
26  };
27  };
28 
30  {
31  std::string hostname;
32  int portOffset;
33  };
34  typedef std::map<int, DestinationInfo> hostMap_t;
35 
36  inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input)
37  {
38  std::vector<fhicl::ParameterSet> output;
39  for (auto& rank : input)
40  {
41  fhicl::ParameterSet rank_output;
42  rank_output.put<int>("rank", rank.first);
43  rank_output.put<std::string>("host", rank.second.hostname);
44  rank_output.put<int>("portOffset", rank.second.portOffset);
45  output.push_back(rank_output);
46  }
47  return output;
48  }
49 
50  inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t output = hostMap_t())
51  {
52  if (pset.has_key("host_map")) {
53  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
54  for (auto& ps : hosts)
55  {
56  auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT);
57  DestinationInfo info;
58  info.hostname = ps.get<std::string>("host", "localhost");
59  info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset;
60 
61  if (output.count(rank) && (output[rank].hostname != info.hostname || output[rank].portOffset != info.portOffset))
62  {
63  TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!";
64  }
65  output[rank] = info;
66  }
67  }
68  return output;
69  }
70 }
71 
72 #endif
Value to be returned upon receive timeout.