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

Implementation of NuDock factory utilities for object creation and oscillation parameter format conversion. More...

#include "NuDockFactory.h"
Include dependency graph for NuDockFactory.cpp:

Go to the source code of this file.

Functions

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
 Mapping from NuDock oscillation parameter names to MaCh3 names. More...
 
const std::unordered_map< std::string, std::string > NuDockOscNameMap_r
 Mapping from MaCh3 oscillation parameter names to NuDock names. More...
 
const std::unordered_map< std::string, CommunicationType > CommunicationTypeMap
 Lookup table mapping strings to NuDock CommunicationType enum values. More...
 
const std::unordered_map< std::string, VerbosityLevel > VerbosityLevelMap
 Lookup table mapping strings to NuDock VerbosityLevel enum values. More...
 

Detailed Description

Implementation of NuDock factory utilities for object creation and oscillation parameter format conversion.

Author
Hank Hua

Definition in file NuDockFactory.cpp.

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()

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

◆ CommunicationTypeMap

const std::unordered_map<std::string, CommunicationType> CommunicationTypeMap
Initial value:
= {
{"LOCALHOST", CommunicationType::LOCALHOST},
{"UNIX_DOMAIN_SOCKET", CommunicationType::UNIX_DOMAIN_SOCKET},
{"TCP", CommunicationType::TCP}
}

Lookup table mapping strings to NuDock CommunicationType enum values.

Definition at line 29 of file NuDockFactory.cpp.

◆ NuDockOscNameMap

const std::unordered_map<std::string, std::string> NuDockOscNameMap
Initial value:
= {
{"Theta12", "sin2th_12"},
{"Theta13", "sin2th_13"},
{"Theta23", "sin2th_23"},
{"DeltaCP", "delta_cp"},
{"Deltam2_21", "delm2_12"},
{"Deltam2_32", "delm2_23"},
}

Mapping from NuDock oscillation parameter names to MaCh3 names.

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
Initial value:
= {
{"sin2th_12", "Theta12"},
{"sin2th_13", "Theta13"},
{"sin2th_23", "Theta23"},
{"delta_cp", "DeltaCP"},
{"delm2_12", "Deltam2_21"},
{"delm2_23", "Deltam2_32"},
}

Mapping from MaCh3 oscillation parameter names to NuDock names.

Map from MaCh3 oscillation parameter names to NuDock names.

Definition at line 19 of file NuDockFactory.cpp.

◆ VerbosityLevelMap

const std::unordered_map<std::string, VerbosityLevel> VerbosityLevelMap
Initial value:
= {
{"DEBUG", VerbosityLevel::DEBUG},
{"INFO", VerbosityLevel::INFO},
{"WARNING", VerbosityLevel::WARNING},
{"ERROR", VerbosityLevel::ERROR}
}

Lookup table mapping strings to NuDock VerbosityLevel enum values.

Definition at line 36 of file NuDockFactory.cpp.