![]() |
MaCh3 2.2.1
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. | |
#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. | |
template<typename T , typename... Args> | |
bool | CheckNodeExistsHelper (const T &node, const std::string &key, Args... args) |
KS: Recursive function to traverse YAML nodes. | |
template<typename... Args> | |
bool | CheckNodeExists (const YAML::Node &node, Args... args) |
KS: Wrapper function to call the recursive helper. | |
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. | |
template<typename T , typename... Args> | |
T | FindFromManager (const YAML::Node &node, Args... args) |
Wrapper function to call the recursive helper. | |
YAML::Node | STRINGtoYAML (const std::string &yaml_string) |
Function to convert a YAML string to a YAML node. | |
std::string | YAMLtoSTRING (const YAML::Node &node) |
KS: Convert a YAML node to a string representation. | |
std::string | TMacroToString (const TMacro ¯o) |
KS: Convert a ROOT TMacro object to a string representation. | |
YAML::Node | TMacroToYAML (const TMacro ¯o) |
KS: Convert a ROOT TMacro object to a YAML node. | |
TMacro | YAMLtoTMacro (const YAML::Node &yaml_node, const std::string &name) |
Convert a YAML node to a ROOT TMacro object. | |
bool | compareYAMLNodes (const YAML::Node &node1, const YAML::Node &node2) |
Compare if yaml nodes are identical. | |
template<typename TValue > | |
void | OverrideConfig (YAML::Node node, std::string const &key, TValue val) |
Overrides the configuration settings based on provided arguments. | |
template<typename... Args> | |
void | OverrideConfig (YAML::Node node, std::string const &key, Args... args) |
Overrides the configuration settings based on provided arguments. | |
std::string | DemangleTypeName (const std::string &mangledName) |
Function to demangle type names. | |
template<typename Type > | |
Type | Get (const YAML::Node &node, const std::string File, const int Line) |
Get content of config file. | |
template<typename Type > | |
Type | GetFromManager (const YAML::Node &node, Type defval, const std::string File="", const int Line=1) |
Get content of config file if node is not found take default value specified. | |
YAML::Node | LoadYamlConfig (const std::string &filename, const std::string &File, const int Line) |
Open YAML file. | |
const YAML::Node & | Cnode (const YAML::Node &n) |
KS: Convenience wrapper to return a YAML node as-is. | |
YAML::Node | MergeNodes (YAML::Node a, YAML::Node b) |
KS: Recursively merges two YAML nodes. | |
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. | |
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. | |
Utility functions for handling YAML nodes.
Definition in file YamlHelper.h.
#define Get2DBounds | ( | filename | ) | Parse2DBounds((filename), __FILE__, __LINE__) |
Definition at line 562 of file YamlHelper.h.
#define GetBounds | ( | filename | ) | ParseBounds((filename), __FILE__, __LINE__) |
Definition at line 561 of file YamlHelper.h.
#define M3OpenConfig | ( | filename | ) | LoadYamlConfig((filename), __FILE__, __LINE__) |
Macro to simplify calling LoadYaml with file and line info.
Definition at line 560 of file YamlHelper.h.
bool CheckNodeExists | ( | const YAML::Node & | node, |
Args... | args | ||
) |
KS: Wrapper function to call the recursive helper.
Definition at line 54 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 33 of file YamlHelper.h.
bool CheckNodeExistsHelper | ( | const T & | node, |
const std::string & | key, | ||
Args... | args | ||
) |
KS: Recursive function to traverse YAML nodes.
Definition at line 42 of file YamlHelper.h.
|
inline |
KS: Convenience wrapper to return a YAML node as-is.
n | Input YAML node. |
Definition at line 389 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. |
Definition at line 179 of file YamlHelper.h.
|
inline |
Function to demangle type names.
Definition at line 252 of file YamlHelper.h.
T FindFromManager | ( | const YAML::Node & | node, |
Args... | args | ||
) |
Wrapper function to call the recursive helper.
Definition at line 83 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 63 of file YamlHelper.h.
T FindFromManagerHelper | ( | const YAML::Node & | node, |
const std::string & | key, | ||
Args... | args | ||
) |
Recursive function to traverse YAML nodes.
Definition at line 71 of file YamlHelper.h.
Type Get | ( | const YAML::Node & | node, |
const std::string | File, | ||
const int | Line | ||
) |
Get content of config file.
node | Yaml node |
Definition at line 265 of file YamlHelper.h.
Type GetFromManager | ( | const YAML::Node & | node, |
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 |
Definition at line 298 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 325 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 405 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 |
args | The arguments to override the configuration. The last argument will be used as the value |
Definition at line 245 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 |
Definition at line 226 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 538 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 454 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 91 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 117 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 146 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 106 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 161 of file YamlHelper.h.