artdaq  v3_02_01
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"} };
27  fhicl::Atom<int> portOffset{ fhicl::Name{"portOffset"},fhicl::Comment{"DEPRECATED: Port offset of this artdaq application"}, 5500 };
28  };
32  struct Config
33  {
37  fhicl::Sequence<fhicl::Table<HostConfig>> host_map{ fhicl::Name("host_map"), fhicl::Comment("List of artdaq applications by rank and location") };
38  };
39  };
40 
45  {
46  std::string hostname;
47  int portOffset;
48  };
49  typedef std::map<int, DestinationInfo> hostMap_t;
50 
56  inline std::vector<fhicl::ParameterSet> MakeHostMapPset(std::map<int, DestinationInfo> input)
57  {
58  std::vector<fhicl::ParameterSet> output;
59  for (auto& rank : input)
60  {
61  fhicl::ParameterSet rank_output;
62  rank_output.put<int>("rank", rank.first);
63  rank_output.put<std::string>("host", rank.second.hostname);
64  rank_output.put<int>("portOffset", rank.second.portOffset);
65  output.push_back(rank_output);
66  }
67  return output;
68  }
69 
77  inline hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset = 0, hostMap_t map = hostMap_t())
78  {
79  if (pset.has_key("host_map")) {
80  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
81  for (auto& ps : hosts)
82  {
83  auto rank = ps.get<int>("rank", TransferInterface::RECV_TIMEOUT);
84  DestinationInfo info;
85  info.hostname = ps.get<std::string>("host", "localhost");
86  info.portOffset = ps.get<int>("portOffset", 5500) + masterPortOffset;
87 
88  if (map.count(rank) && (map[rank].hostname != info.hostname || map[rank].portOffset != info.portOffset))
89  {
90  TLOG(TLVL_ERROR) << "Inconsistent host maps supplied! Check configuration! There may be TCPSocket-related failures!";
91  }
92  map[rank] = info;
93  }
94  }
95  return map;
96  }
97 }
98 
99 #endif
fhicl::Sequence< fhicl::Table< HostConfig > > host_map
List of artdaq applications by rank and location. See artdaq::HostMap::HostConfig ...
Definition: HostMap.hh:37
int portOffset
DEPRECATED: Port offset of this artdaq application.
Definition: HostMap.hh:47
fhicl::Atom< int > rank
&quot;rank&quot;: Rank index
Definition: HostMap.hh:23
std::string hostname
Hostname of the application.
Definition: HostMap.hh:46
std::vector< fhicl::ParameterSet > MakeHostMapPset(std::map< int, DestinationInfo > input)
Create a list of HostMap::HostConfig ParameterSets from a hostMap_t map
Definition: HostMap.hh:56
Template for the host_map configuration parameter.
Definition: HostMap.hh:32
std::map< int, DestinationInfo > hostMap_t
The host_map is a map associating ranks with artdaq::DestinationInfo objects.
Definition: HostMap.hh:49
hostMap_t MakeHostMap(fhicl::ParameterSet pset, int masterPortOffset=0, hostMap_t map=hostMap_t())
Make a hostMap_t from a HostMap::Config ParameterSet
Definition: HostMap.hh:77
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.
Entry in the host map
Definition: HostMap.hh:44
fhicl::Atom< int > portOffset
&quot;portOffset&quot; (Default: 5500): DEPRECATED : Port offset of this artdaq application ...
Definition: HostMap.hh:27