otsdaq-mu2e-stm  5.02.01
master_config.hh
1 #ifndef MASTER_CONFIG_HH_
2 #define MASTER_CONFIG_HH_
3 
4 // Environment variable code
5 #include "Mu2e-STMDAQ/utils/EnvVars.hh"
6 // Include config file
7 #include "Mu2e-STMDAQ/config/config.hh"
8 
9 // Master configurable variables
10 struct master_info{
11 
12  // Server host
13  const std::string host;
14  // Ch0 (HPGe) server host name
15  const std::string ch0_host;
16  // Ch1 (LaBr) server host name
17  const std::string ch1_host;
18  // The channel number
19  const int ch_num;
20  // The channel name
21  const std::string ch_name;
22  // Numa node
23  const int numa_sock;
24 
25  // Use software simulation as data source
26  const bool use_sw_sim;
27 
28  static int compute_ch_num(const std::string& host,
29  const std::string& ch0_host,
30  const std::string& ch1_host)
31  {
32  if (host == ch0_host) return 0;
33  if (host == ch1_host) return 1;
34  throw std::runtime_error(
35  "master_info: HOSTNAME '" + host +
36  "' does not match stm.ch0_host ('" + ch0_host +
37  "') or stm.ch1_host ('" + ch1_host + "')"
38  );
39  }
40 
41  static std::string compute_ch_name(int ch_num)
42  {
43  return (ch_num == 0) ? "HPGe" : "Labr";
44  }
45 
46  static int get_daq_socket(int ch_num) {
47  return (ch_num == 0) ? 1 : 0;
48  }
49 
50  // Constructor
51  master_info(Config& cfg, const std::shared_ptr<AsyncLogger> logger) :
52  host(EnvVars::expand("${HOSTNAME}")), // Server host name
53  ch0_host(cfg.getValue<std::string>("stm.ch0_host")), // Channel 0 host name
54  ch1_host(cfg.getValue<std::string>("stm.ch1_host")), // Channel 1 host name
55  ch_num(compute_ch_num(host, ch0_host, ch1_host)), // Channel number
56  ch_name(compute_ch_name(ch_num)), // Channel name
57  numa_sock(get_daq_socket(ch_num)),
58  use_sw_sim(cfg.getValue<int>("stm.use_sw_sim")) // Use software simulation
59  {
60 
61  // Notify user
62  if (logger){
63  logger->log("Config:master_info: HOST = " +
64  host + ", NUMA socket = " +
65  std::to_string(numa_sock),1);
66  logger->log("Config:master_info: Channel = " +
67  std::to_string(ch_num) +
68  " (" + ch_name + ")",1);
69  if (ch_num != 0 && ch_num != 1){
70  logger->log("Config:master_info: Error in config file --> stm.channel must be equal to 0 (HPGe) or 1 (LaBr)",0);
71  }
72  std::string option;
73  if (use_sw_sim){
74  option = "SOFTWARE SIMULATION";
75  }
76  else{
77  option = "HARDWARE/FIRMWARE";
78  }
79  logger->log("Config:master_info: Using " +
80  option + " as data input.",1);
81  }
82 
83  }
84 
85 };
86 
87 #endif
Definition: config.hh:19