![]() |
MaCh3
2.4.2
Reference Guide
|
Utility functions for handling YAML nodes. More...
#include <iostream>#include <fstream>#include <string>#include <cxxabi.h>#include <regex>#include "Manager/MaCh3Exception.h"#include "Manager/Core.h"#include "TMacro.h"#include "TList.h"#include "TObjString.h"#include "yaml-cpp/yaml.h"Go to the source code of this file.
Macros | |
| #define | M3OpenConfig(filename) LoadYamlConfig((filename), __FILE__, __LINE__) |
| Macro to simplify calling LoadYaml with file and line info. More... | |
| #define | GetBounds(filename) ParseBounds((filename), __FILE__, __LINE__) |
| #define | Get2DBounds(filename) Parse2DBounds((filename), __FILE__, __LINE__) |
Functions | |
| template<typename T > | |
| bool | CheckNodeExistsHelper (const T &node) |
| Use this like this CheckNodeExists(config, "LikelihoodOptions", "TestStatistic"); KS: Base case for recursion. More... | |
| template<typename T , typename... Args> | |
| bool | CheckNodeExistsHelper (const T &node, const std::string &key, Args... args) |
| KS: Recursive function to traverse YAML nodes. More... | |
| template<typename... Args> | |
| bool | CheckNodeExists (const YAML::Node &node, Args... args) |
| KS: Wrapper function to call the recursive helper. More... | |
| template<typename T > | |
| T | FindFromManagerHelper (const YAML::Node &node) |
| template<typename T , typename... Args> | |
| T | FindFromManagerHelper (const YAML::Node &node, const std::string &key, Args... args) |
| Recursive function to traverse YAML nodes. More... | |
| template<typename T , typename... Args> | |
| T | FindFromManager (const YAML::Node &node, Args... args) |
| Wrapper function to call the recursive helper. More... | |
| YAML::Node | STRINGtoYAML (const std::string &yaml_string) |
| Function to convert a YAML string to a YAML node. More... | |
| std::string | YAMLtoSTRING (const YAML::Node &node) |
| KS: Convert a YAML node to a string representation. More... | |
| std::string | TMacroToString (const TMacro ¯o) |
| KS: Convert a ROOT TMacro object to a string representation. More... | |
| YAML::Node | TMacroToYAML (const TMacro ¯o) |
| KS: Convert a ROOT TMacro object to a YAML node. More... | |
| TMacro | YAMLtoTMacro (const YAML::Node &yaml_node, const std::string &name) |
| Convert a YAML node to a ROOT TMacro object. More... | |
| bool | compareYAMLNodes (const YAML::Node &node1, const YAML::Node &node2, bool Mute=false) |
| Compare if yaml nodes are identical. More... | |
| template<typename TValue > | |
| void | OverrideConfig (YAML::Node node, std::string const &key, TValue val) |
| Overrides the configuration settings based on provided arguments. More... | |
| template<typename... Args> | |
| void | OverrideConfig (YAML::Node node, std::string const &key, Args... args) |
| Overrides the configuration settings based on provided arguments. More... | |
| std::string | DemangleTypeName (const std::string &mangledName) |
| Function to demangle type names. More... | |
| template<typename Type > | |
| Type | Get (const YAML::Node &node, const std::string File, const int Line) |
| Get content of config file. More... | |
| template<typename Type > | |
| 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. More... | |
| YAML::Node | LoadYamlConfig (const std::string &filename, const std::string &File, const int Line) |
| Open YAML file. More... | |
| const YAML::Node & | Cnode (const YAML::Node &n) |
| KS: Convenience wrapper to return a YAML node as-is. More... | |
| YAML::Node | MergeNodes (const YAML::Node &a, const YAML::Node &b) |
| KS: Recursively merges two YAML nodes. More... | |
| std::vector< double > | ParseBounds (const YAML::Node &node, const std::string &File, const int Line) |
| KS: Get bounds from YAML for example for selection cuts. More... | |
| std::vector< std::vector< double > > | Parse2DBounds (const YAML::Node &node, const std::string &File, const int Line) |
| KS: Get 2D bounds from YAML for example for selection cuts. More... | |
Utility functions for handling YAML nodes.
MaCh3 uses YAML in a specific way within its configuration system. These helper functions act as a safety layer on top of yaml-cpp, adding MaCh3-specific validation, consistency checks, and enhanced error reporting.
Definition in file YamlHelper.h.
| #define Get2DBounds | ( | filename | ) | Parse2DBounds((filename), __FILE__, __LINE__) |
Definition at line 591 of file YamlHelper.h.
| #define GetBounds | ( | filename | ) | ParseBounds((filename), __FILE__, __LINE__) |
Definition at line 590 of file YamlHelper.h.
| #define M3OpenConfig | ( | filename | ) | LoadYamlConfig((filename), __FILE__, __LINE__) |
Macro to simplify calling LoadYaml with file and line info.
Definition at line 589 of file YamlHelper.h.
| bool CheckNodeExists | ( | const YAML::Node & | node, |
| Args... | args | ||
| ) |
KS: Wrapper function to call the recursive helper.
Definition at line 60 of file YamlHelper.h.
| bool CheckNodeExistsHelper | ( | const T & | node | ) |
Use this like this CheckNodeExists(config, "LikelihoodOptions", "TestStatistic"); KS: Base case for recursion.
Definition at line 39 of file YamlHelper.h.
| bool CheckNodeExistsHelper | ( | const T & | node, |
| const std::string & | key, | ||
| Args... | args | ||
| ) |
|
inline |
KS: Convenience wrapper to return a YAML node as-is.
| n | Input YAML node. |
Definition at line 418 of file YamlHelper.h.
|
inline |
Compare if yaml nodes are identical.
| node1 | The first YAML node to compare. |
| node2 | The second YAML node to compare. |
| Mute | allow to mute warning messages |
Definition at line 186 of file YamlHelper.h.
|
inline |
Function to demangle type names.
Definition at line 276 of file YamlHelper.h.
| T FindFromManager | ( | const YAML::Node & | node, |
| Args... | args | ||
| ) |
Wrapper function to call the recursive helper.
Definition at line 89 of file YamlHelper.h.
| T FindFromManagerHelper | ( | const YAML::Node & | node | ) |
Use this like this FindFromManager<std::string>(config, "LikelihoodOptions", "TestStatistic"); Base case for recursion
Definition at line 69 of file YamlHelper.h.
| T FindFromManagerHelper | ( | const YAML::Node & | node, |
| const std::string & | key, | ||
| Args... | args | ||
| ) |
| Type Get | ( | const YAML::Node & | node, |
| const std::string | File, | ||
| const int | Line | ||
| ) |
Get content of config file.
| node | Yaml node |
| File | name of file in which function is being called to make better error message |
| Line | File line in which function is being called to make better error message |
Definition at line 291 of file YamlHelper.h.
| 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.
| node | Yaml node |
| defval | Default value which will be used in case node doesn't exist |
| File | name of file in which function is being called to make better error message |
| Line | File line in which function is being called to make better error message |
Definition at line 329 of file YamlHelper.h.
|
inline |
Open YAML file.
| filename | name of filename to open |
| File | name of file where function is called |
| Line | number where function is called |
Definition at line 356 of file YamlHelper.h.
|
inline |
KS: Recursively merges two YAML nodes.
If both nodes are maps, their keys are merged. Scalar or null values in b will override those in a. If b is null, a is returned unchanged.
| a | The base YAML node. |
| b | The YAML node to merge into a. |
Definition at line 434 of file YamlHelper.h.
| void OverrideConfig | ( | YAML::Node | node, |
| std::string const & | key, | ||
| Args... | args | ||
| ) |
Overrides the configuration settings based on provided arguments.
This function allows you to set configuration options in a nested YAML node.
| node | YAML node that will be modified |
| key | The key in the YAML node to override |
| args | The arguments to override the configuration. The last argument will be used as the value |
Definition at line 269 of file YamlHelper.h.
| void OverrideConfig | ( | YAML::Node | node, |
| std::string const & | key, | ||
| TValue | val | ||
| ) |
Overrides the configuration settings based on provided arguments.
| node | YAML node that will be modified |
| key | The key in the YAML node to override |
| val | The value to assign to the key |
Definition at line 249 of file YamlHelper.h.
|
inline |
KS: Get 2D bounds from YAML for example for selection cuts.
Parses a YAML node representing 2D selection bounds. Each element in the node must be a sequence of 1 or 2 scalar values. If a single value is given, it is interpreted as the center of a bin and expanded to [value - 0.5, value + 0.5]. If two values are given, they are used as-is. If an element is empty or null, default bounds are used.
This function is useful for interpreting kinematic or classification bounds specified in YAML configuration files.
Example YAML input:
Resulting vector:
| node | The YAML node containing a sequence of bounds (each being a 1- or 2-element sequence). |
| File | The name of the file calling this function (for error reporting). |
| Line | The line number in the file calling this function (for error reporting). |
Definition at line 567 of file YamlHelper.h.
|
inline |
KS: Get bounds from YAML for example for selection cuts.
This function expects a YAML node of exactly two elements. If any of the elements is an empty string or null, it is replaced with a default kinematic bound. If the element is a non-empty string and cannot be converted to a double, an exception is thrown.
| node | The YAML node containing the bounds. |
| File | The name of the file calling this function (for error context). |
| Line | The line number in the file calling this function. |
Definition at line 483 of file YamlHelper.h.
|
inline |
Function to convert a YAML string to a YAML node.
| yaml_string | String which will be converted to yaml node |
Definition at line 97 of file YamlHelper.h.
|
inline |
KS: Convert a ROOT TMacro object to a string representation.
| macro | The ROOT TMacro object to convert. |
Definition at line 123 of file YamlHelper.h.
|
inline |
KS: Convert a ROOT TMacro object to a YAML node.
| macro | The ROOT TMacro object to convert. |
Definition at line 152 of file YamlHelper.h.
|
inline |
KS: Convert a YAML node to a string representation.
| node | The YAML node to convert to a string. |
Definition at line 112 of file YamlHelper.h.
|
inline |
Convert a YAML node to a ROOT TMacro object.
| yaml_node | The YAML node to convert to a TMacro. |
| name | Name of TMacro that will be saved |
Definition at line 167 of file YamlHelper.h.