artdaq  v3_11_02
HostMap.hh
1 #ifndef ARTDAQ_DAQDATA_HOSTMAP_HH
2 #define ARTDAQ_DAQDATA_HOSTMAP_HH
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include "fhiclcpp/ParameterSet.h"
8 #include "fhiclcpp/types/Atom.h"
9 #include "fhiclcpp/types/Sequence.h"
10 #include "fhiclcpp/types/Table.h"
11 
12 #include "artdaq/DAQdata/Globals.hh"
13 
14 namespace artdaq {
15 
16 struct HostMap
17 {
21  struct HostConfig
22  {
24  fhicl::Atom<int> rank{fhicl::Name{"rank"}, fhicl::Comment{"Rank index"}};
26  fhicl::Atom<std::string> host{fhicl::Name{"host"}, fhicl::Comment{"Hostname for artdaq application with this rank"}};
27  };
31  struct Config
32  {
36  fhicl::Sequence<fhicl::Table<HostConfig>> host_map{fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location")};
37  };
38 };
39 
40 typedef std::map<int, std::string> hostMap_t;
41 
47 inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, std::string> input)
48 {
49  std::vector<fhicl::ParameterSet> output;
50  for (auto& rank : input)
51  {
52  fhicl::ParameterSet rank_output;
53  rank_output.put<int>("rank", rank.first);
54  rank_output.put<std::string>("host", rank.second);
55  output.push_back(rank_output);
56  }
57  return output;
58 }
59 
66 inline hostMap_t MakeHostMap(fhicl::ParameterSet const& pset, hostMap_t map = hostMap_t())
67 {
68  if (pset.has_key("host_map"))
69  {
70  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
71  for (auto& ps : hosts)
72  {
73  auto rank = ps.get<int>("rank");
74  auto hostname = ps.get<std::string>("host");
75 
76  if (map.count(rank) && (map[rank] != hostname))
77  {
78  TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!";
79  }
80  map[rank] = hostname;
81  }
82  }
83  return map;
84 }
85 } // namespace artdaq
86 
87 #endif // ARTDAQ_DAQDATA_HOSTMAP_HH
fhicl::Sequence< fhicl::Table< HostConfig > > host_map
List of artdaq applications by rank and location. See artdaq::HostMap::HostConfig ...
Definition: HostMap.hh:36
fhicl::Atom< int > rank
&quot;rank&quot;: Rank index
Definition: HostMap.hh:24
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:47
Template for the host_map configuration parameter.
Definition: HostMap.hh:31
fhicl::Atom< std::string > host
&quot;host&quot;: Hostname for artdaq application with this rank
Definition: HostMap.hh:26
Entries in the host_map should have these parameters. May be used for parameter validation ...
Definition: HostMap.hh:21
std::map< int, std::string > hostMap_t
The host_map is a map associating ranks with artdaq::DestinationInfo objects.
Definition: HostMap.hh:40
hostMap_t MakeHostMap(fhicl::ParameterSet const &pset, hostMap_t map=hostMap_t())
Make a hostMap_t from a HostMap::Config ParameterSet
Definition: HostMap.hh:66