artdaq  v3_06_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  {
20  struct HostConfig
21  {
23  fhicl::Atom<int> rank{ fhicl::Name{"rank"}, fhicl::Comment{"Rank index"} };
25  fhicl::Atom<std::string> host{ fhicl::Name{"host"}, fhicl::Comment{"Hostname for artdaq application with this rank"} };
26  };
30  struct Config
31  {
35  fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") };
36  };
37  };
38 
39  typedef std::map<int, std::string> hostMap_t;
40 
46  inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, std::string> input)
47  {
48  std::vector<fhicl::ParameterSet> output;
49  for (auto& rank : input)
50  {
51  fhicl::ParameterSet rank_output;
52  rank_output.put<int>("rank", rank.first);
53  rank_output.put<std::string>("host", rank.second);
54  output.push_back(rank_output);
55  }
56  return output;
57  }
58 
66  inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, hostMap_t map = hostMap_t())
67  {
68  if (pset.has_key("host_map")) {
69  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
70  for (auto& ps : hosts)
71  {
72  auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT);
73  auto hostname = ps.get<std::string>("host", "localhost");
74 
75  if (map.count(rank) && (map[rank] != hostname ))
76  {
77  TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!";
78  }
79  map[rank] = hostname;
80  }
81  }
82  return map;
83  }
84 }
85 
86 #endif
fhicl::Sequence< fhicl::Table< HostConfig > > host_map
List of artdaq applications by rank and location. See artdaq::HostMap::HostConfig ...
Definition: HostMap.hh:35
fhicl::Atom< int > rank
&quot;rank&quot;: Rank index
Definition: HostMap.hh:23
hostMap_t MakeHostMap(fhicl::ParameterSet pset, hostMap_t map=hostMap_t())
Make a hostMap_t from a HostMap::Config ParameterSet
Definition: HostMap.hh:66
std::vector< fhicl::ParameterSet > MakeHostMapPset(std::map< int, std::string > input)
Create a list of HostMap::HostConfig ParameterSets from a hostMap_t map
Definition: HostMap.hh:46
Template for the host_map configuration parameter.
Definition: HostMap.hh:30
fhicl::Atom< std::string > host
&quot;host&quot;: Hostname for artdaq application with this rank
Definition: HostMap.hh:25
Entries in the host_map should have these parameters. May be used for parameter validation ...
Definition: HostMap.hh:20
Value to be returned upon receive timeout.
std::map< int, std::string > hostMap_t
The host_map is a map associating ranks with artdaq::DestinationInfo objects.
Definition: HostMap.hh:39