MaCh3  2.5.1
Reference Guide
Functions | Variables
NuDockFactory.h File Reference

Factory utilities for creating and configuring NuDock communication objects. More...

#include <Manager/Manager.h>
#include "nudock.hpp"
Include dependency graph for NuDockFactory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ void InitialiseNuDockObj (Manager *man, std::unique_ptr< NuDock > &nudock_ptr)
 Initialise a NuDock communication object from a manager configuration. More...
 
void FormatOscParsForNuDock (const std::string &param_name, double &param_value)
 Convert an oscillation parameter value from MaCh3 convention to NuDock convention. More...
 
void FormatOscParsForMaCh3 (const std::string &param_name, double &param_value)
 Convert an oscillation parameter value from NuDock convention to MaCh3 convention. More...
 

Variables

const std::unordered_map< std::string, std::string > NuDockOscNameMap
 Map from NuDock oscillation parameter names to MaCh3 names. More...
 
const std::unordered_map< std::string, std::string > NuDockOscNameMap_r
 Map from MaCh3 oscillation parameter names to NuDock names. More...
 

Detailed Description

Factory utilities for creating and configuring NuDock communication objects.

Provides helper functions to initialise NuDock instances from MaCh3 configuration, as well as conversion utilities between MaCh3 and NuDock oscillation parameter conventions.

Author
Hank Hua

Definition in file NuDockFactory.h.

Function Documentation

◆ FormatOscParsForMaCh3()

void FormatOscParsForMaCh3 ( const std::string &  param_name,
double &  param_value 
)

Convert an oscillation parameter value from NuDock convention to MaCh3 convention.

Parameters
param_nameThe NuDock-side parameter name (e.g. "Theta12").
[in,out]param_valueThe parameter value to convert in-place.

Definition at line 111 of file NuDockFactory.cpp.

111  {
112  if (param_name == "Theta12" || param_name == "Theta13" || param_name == "Theta23") {
113  param_value = std::sin(param_value) * std::sin(param_value);
114  }
115 }

◆ FormatOscParsForNuDock()

void FormatOscParsForNuDock ( const std::string &  param_name,
double &  param_value 
)

Convert an oscillation parameter value from MaCh3 convention to NuDock convention.

Parameters
param_nameThe MaCh3-side parameter name (e.g. "Theta12").
[in,out]param_valueThe parameter value to convert in-place.

Definition at line 105 of file NuDockFactory.cpp.

105  {
106  if (param_name == "Theta12" || param_name == "Theta13" || param_name == "Theta23") {
107  param_value = std::asin(std::sqrt(param_value));
108  }
109 }

◆ InitialiseNuDockObj()

_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ void InitialiseNuDockObj ( Manager man,
std::unique_ptr< NuDock > &  nudock_ptr 
)

Initialise a NuDock communication object from a manager configuration.

Parameters
manPointer to the MaCh3 manager holding the NuDock YAML config block.
[in,out]nudock_ptrUnique pointer that will own the newly created NuDock object.
Exceptions
MaCh3Exceptionif no NuDock configuration is found, or if an unsupported communication type / verbosity level is specified.

Definition at line 43 of file NuDockFactory.cpp.

44  {
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 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
const std::unordered_map< std::string, CommunicationType > CommunicationTypeMap
Lookup table mapping strings to NuDock CommunicationType enum values.
const std::unordered_map< std::string, VerbosityLevel > VerbosityLevelMap
Lookup table mapping strings to NuDock VerbosityLevel enum values.
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.
YAML::Node const & raw() const
Return config.
Definition: Manager.h:47

Variable Documentation

◆ NuDockOscNameMap

const std::unordered_map<std::string, std::string> NuDockOscNameMap
extern

Map from NuDock oscillation parameter names to MaCh3 names.

Keys are NuDock-style names (e.g. "Theta12"), values are MaCh3-style names (e.g. "sin2th_12").

Map from NuDock oscillation parameter names to MaCh3 names.

Definition at line 9 of file NuDockFactory.cpp.

◆ NuDockOscNameMap_r

const std::unordered_map<std::string, std::string> NuDockOscNameMap_r
extern

Map from MaCh3 oscillation parameter names to NuDock names.

Keys are MaCh3-style names (e.g. "sin2th_12"), values are NuDock-style names (e.g. "Theta12").

Map from MaCh3 oscillation parameter names to NuDock names.

Definition at line 19 of file NuDockFactory.cpp.