MaCh3  2.5.1
Reference Guide
NuDockFactory.cpp
Go to the documentation of this file.
1 
6 #include "NuDockFactory.h"
7 
9 const std::unordered_map<std::string, std::string> NuDockOscNameMap = {
10  {"Theta12", "sin2th_12"},
11  {"Theta13", "sin2th_13"},
12  {"Theta23", "sin2th_23"},
13  {"DeltaCP", "delta_cp"},
14  {"Deltam2_21", "delm2_12"},
15  {"Deltam2_32", "delm2_23"},
16 };
17 
19 const std::unordered_map<std::string, std::string> NuDockOscNameMap_r = {
20  {"sin2th_12", "Theta12"},
21  {"sin2th_13", "Theta13"},
22  {"sin2th_23", "Theta23"},
23  {"delta_cp", "DeltaCP"},
24  {"delm2_12", "Deltam2_21"},
25  {"delm2_23", "Deltam2_32"},
26 };
27 
29 const std::unordered_map<std::string, CommunicationType> CommunicationTypeMap = {
30  {"LOCALHOST", CommunicationType::LOCALHOST},
31  {"UNIX_DOMAIN_SOCKET", CommunicationType::UNIX_DOMAIN_SOCKET},
32  {"TCP", CommunicationType::TCP}
33 };
34 
36 const std::unordered_map<std::string, VerbosityLevel> VerbosityLevelMap = {
37  {"DEBUG", VerbosityLevel::DEBUG},
38  {"INFO", VerbosityLevel::INFO},
39  {"WARNING", VerbosityLevel::WARNING},
40  {"ERROR", VerbosityLevel::ERROR}
41 };
42 
44  std::unique_ptr<NuDock> &nudock_ptr) {
45  // Here man can be either the sample manager or the fit manager, as long as it
46  // has the NuDock config
47  if (nudock_ptr) {
48  MACH3LOG_INFO("NuDock object has already been created so I am not "
49  "re-initialising the object");
50  return;
51  }
52  std::string nudock_conf_name = "NuDock";
53  if (!man->raw()["NuDock"]) {
54  if (!man->raw()["NuDockClient"]) {
56  "No NuDock configuration found in the provided manager object");
57  throw MaCh3Exception(__FILE__, __LINE__);
58  } else {
59  MACH3LOG_INFO("Setting up NuDock client.");
60  nudock_conf_name = "NuDockClient";
61  }
62  } else {
63  MACH3LOG_INFO("Setting up NuDock server.");
64  }
65 
66  bool useDebug = GetFromManager(man->raw()[nudock_conf_name]["Debug"], false);
67  std::string schemaLocation = GetFromManager<std::string>(
68  man->raw()[nudock_conf_name]["SchemaLocation"], "");
69  std::string commTypeStr = GetFromManager<std::string>(
70  man->raw()[nudock_conf_name]["CommunicationType"], "LOCALHOST");
71  int port = GetFromManager<int>(man->raw()[nudock_conf_name]["Port"], 1234);
72  std::string verbosity =
73  GetFromManager<std::string>(man->raw()[nudock_conf_name]["NuDockVerbosity"], "INFO");
74 
75  CommunicationType commType;
76  if (CommunicationTypeMap.find(commTypeStr) != CommunicationTypeMap.end()) {
77  commType = CommunicationTypeMap.at(commTypeStr);
78  } else {
80  "Unsupported communication type for NuDock: {}. Supported types "
81  "are LOCALHOST, UNIX_DOMAIN_SOCKET, and TCP.",
82  commTypeStr);
83  throw MaCh3Exception(__FILE__, __LINE__);
84  }
85 
86  VerbosityLevel verbLevel;
87  if (VerbosityLevelMap.find(verbosity) != VerbosityLevelMap.end()) {
88  verbLevel = VerbosityLevelMap.at(verbosity);
89  } else {
91  "Unsupported verbosity level for NuDock: {}. Supported levels are "
92  "DEBUG, INFO, WARN, and ERROR.",
93  verbosity);
94  throw MaCh3Exception(__FILE__, __LINE__);
95  }
96 
97  nudock_ptr =
98  std::make_unique<NuDock>(useDebug, schemaLocation, commType, port, verbLevel);
99  MACH3LOG_INFO("NuDock object created with communication type: {} on port: {}", commTypeStr, port);
100  MACH3LOG_INFO("NuDock schema location: {}", schemaLocation);
101  MACH3LOG_INFO("NuDock debug mode: {}", useDebug);
102  MACH3LOG_INFO("NuDock verbosity level: {}", verbosity);
103 }
104 
105 void FormatOscParsForNuDock(const std::string &param_name, double &param_value) {
106  if (param_name == "Theta12" || param_name == "Theta13" || param_name == "Theta23") {
107  param_value = std::asin(std::sqrt(param_value));
108  }
109 }
110 
111 void FormatOscParsForMaCh3(const std::string &param_name, double &param_value) {
112  if (param_name == "Theta12" || param_name == "Theta13" || param_name == "Theta23") {
113  param_value = std::sin(param_value) * std::sin(param_value);
114  }
115 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
const std::unordered_map< std::string, std::string > NuDockOscNameMap_r
Mapping from MaCh3 oscillation parameter names to NuDock names.
const std::unordered_map< std::string, std::string > NuDockOscNameMap
Mapping from NuDock oscillation parameter names to MaCh3 names.
const std::unordered_map< std::string, CommunicationType > CommunicationTypeMap
Lookup table mapping strings to NuDock CommunicationType enum values.
void FormatOscParsForMaCh3(const std::string &param_name, double &param_value)
Convert an oscillation parameter value from NuDock convention to MaCh3 convention.
void FormatOscParsForNuDock(const std::string &param_name, double &param_value)
Convert an oscillation parameter value from MaCh3 convention to NuDock convention.
void InitialiseNuDockObj(Manager *man, std::unique_ptr< NuDock > &nudock_ptr)
Initialise a NuDock communication object from a manager configuration.
const std::unordered_map< std::string, VerbosityLevel > VerbosityLevelMap
Lookup table mapping strings to NuDock VerbosityLevel enum values.
Factory utilities for creating and configuring NuDock communication objects.
Type GetFromManager(const YAML::Node &node, const Type defval, const std::string File="", const int Line=1)
Get content of config file if node is not found take default value specified.
Definition: YamlHelper.h:329
Custom exception class used throughout MaCh3.
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
YAML::Node const & raw() const
Return config.
Definition: Manager.h:47