![]() |
AliPhysics
068200c (068200c)
|
#include <AliYAMLConfiguration.h>
Public Member Functions | |
AliYAMLConfiguration (const std::string prefixString="AliEmcalCorrection", const std::string delimiterCharacter=":") | |
virtual | ~AliYAMLConfiguration () |
Setup the configurations at various points of the analysis. | |
bool | Initialize () |
bool | Reinitialize () |
Add a new particular configuration under a given name. | |
int | AddEmptyConfiguration (const std::string &configurationName) |
Add YAML configuration at configurationFilename to available configurations. More... | |
int | AddConfiguration (std::string configurationFilename, std::string configurationName="") |
int | AddConfiguration (const YAML::Node node, std::string configurationName="") |
Get a particular configuration by index or name. | |
bool | DoesConfigurationExist (const int i) const |
bool | DoesConfigurationExist (const std::string &name) const |
const std::pair< std::string, YAML::Node > & | GetConfiguration (const int i) const |
const std::pair< std::string, YAML::Node > & | GetConfiguration (const std::string &name) const |
std::pair< std::string, YAML::Node > & | GetConfiguration (const int i) |
std::pair< std::string, YAML::Node > & | GetConfiguration (const std::string &name) |
Translate between configuration name and index. | |
std::string | GetConfigurationNameFromIndex (const unsigned int i) const |
int | GetConfigurationIndexFromName (const std::string &name) const |
Remove a particular configuration by index or name. | |
bool | RemoveConfiguration (const unsigned int i) |
bool | RemoveConfiguration (const std::string &name) |
Get a property from the available configurations | |
template<typename T > | |
bool | GetProperty (std::vector< std::string > propertyPath, const std::string &propertyName, T &property, const bool requiredProperty) const |
template<typename T > | |
bool | GetProperty (const std::vector< std::string > propertyPath, T &property, const bool requiredProperty) const |
template<typename T > | |
bool | GetProperty (std::string propertyName, T &property, const bool requiredProperty=true) const |
Write a property to a particular configuration | |
template<typename T > | |
bool | WriteProperty (std::string propertyName, T &property, std::string configurationName="") |
Write a particular configuration at a given index or name to a file. | |
bool | WriteConfiguration (const std::string &filename, const unsigned int i) const |
bool | WriteConfiguration (const std::string &filename, const std::string &configurationName) const |
bool | CompareConfigurations (const int config1, const int config2) const |
bool | CompareConfigurations (const int config1, const std::string &config2) const |
bool | CompareConfigurations (const std::string &config1, const std::string &config2) const |
Protected Member Functions | |
bool | DoesFileExist (const std::string &filename) const |
void | SetupReadingConfigurationFilePath (std::string &filename, const std::string &fileIdentifier) const |
void | WriteConfigurationToFilePath (const std::string &localFilename, std::string filename) const |
void | PrintConfiguration (std::ostream &stream, const std::pair< std::string, YAML::Node > &configPair) const |
template<typename T > | |
unsigned int | GetConfigurationIndexFromName (const std::string &name, const std::vector< std::pair< std::string, T >> &configurations) const |
bool | IsSharedValue (std::string &value) const |
template<typename T > | |
auto | PrintRetrievedPropertyValueImpl (std::stringstream &tempMessage, const T &property, int) const -> decltype(tempMessage<< property, void()) |
template<typename T > | |
auto | PrintRetrievedPropertyValueImpl (std::stringstream &tempMessage, const std::vector< T > &property, int) const -> decltype(property.begin(), property.end(), tempMessage<< std::declval< T >(), void()) |
template<typename T > | |
void | PrintRetrievedPropertyValueImpl (std::stringstream &tempMessage, const T &property, long) const |
template<typename T > | |
void | PrintRetrievedPropertyValue (std::stringstream &tempMessage, const T &property) const |
template<typename T > | |
bool | GetPropertyFromNode (const YAML::Node &node, std::string propertyName, T &property) const |
template<typename T > | |
bool | GetProperty (YAML::Node &node, YAML::Node &sharedParametersNode, const std::string &configurationName, std::string propertyName, T &property) const |
template<typename T > | |
void | WriteValue (YAML::Node &node, std::string propertyName, T &proeprty) |
Protected Attributes | |
std::vector< std::pair < std::string, YAML::Node > > | fConfigurations |
! Contains all YAML configurations. The first element has the highest precedence. More... | |
std::vector< std::pair < std::string, std::string > > | fConfigurationsStrings |
Contains all YAML configurations as strings so that they can be streamed. More... | |
bool | fInitialized |
True if the configurations have been initialized. More... | |
std::string | fPrefixString |
Contains the prefix of any names base node names which should be removed. More... | |
std::string | fDelimiter |
Delimiter character to separate each level of the request. More... | |
Print a particular configuration at a given index or name to a file. | |
std::string | toString (const int index=-1) const |
std::ostream & | Print (std::ostream &in, const int index=-1) const |
std::ostream & | Print (std::ostream &in, const std::string &configurationName) const |
void | Print (Option_t *="") const |
std::ostream & | operator<< (std::ostream &in, const AliYAMLConfiguration &myTask) |
Definition at line 101 of file AliYAMLConfiguration.h.
AliYAMLConfiguration::AliYAMLConfiguration | ( | const std::string | prefixString = "AliEmcalCorrection" , |
const std::string | delimiterCharacter = ":" |
||
) |
Default constructor.
[in] | prefixString | Prefix to remove when gettnig a property. |
[in] | delimiterCharacter | Character that delimits between each part of the YAML path. |
Definition at line 27 of file AliYAMLConfiguration.cxx.
|
inlinevirtual |
Definition at line 104 of file AliYAMLConfiguration.h.
int AliYAMLConfiguration::AddConfiguration | ( | std::string | configurationFilename, |
std::string | configurationName = "" |
||
) |
Add YAML configuration at a given filename to the available configurations.
[in] | configurationFilename | Filename of the YAML configuration file to be added. |
[in] | configurationName | Name of the YAML node. The node will be stored under this name. |
Definition at line 59 of file AliYAMLConfiguration.cxx.
Referenced by AddEmptyConfiguration(), AliAnalysisTaskEmcalEmbeddingHelper::AutoConfigurePtHardBins(), AliEmcalCorrectionTask::CompareToStoredConfiguration(), AliEmcalCorrectionTask::InitializeConfiguration(), and AliAnalysisTaskEmcalEmbeddingHelper::InitializeYamlConfig().
int AliYAMLConfiguration::AddConfiguration | ( | const YAML::Node | node, |
std::string | configurationName = "" |
||
) |
Add a YAML node to the available configurations.
[in] | node | YAML node to be added. |
[in] | configurationName | Name of the YAML node. The node will be stored under this name. |
Definition at line 89 of file AliYAMLConfiguration.cxx.
int AliYAMLConfiguration::AddEmptyConfiguration | ( | const std::string & | configurationName | ) |
Add YAML configuration at configurationFilename to available configurations.
Create an empty YAML node and adds it to the available configurations.
[in] | configurationName | Name of the YAML node. The node will be stored under this name. |
Definition at line 44 of file AliYAMLConfiguration.cxx.
Referenced by AliAnalysisTaskEmcalEmbeddingHelper::AutoConfigurePtHardBins().
bool AliYAMLConfiguration::CompareConfigurations | ( | const int | configIndex1, |
const int | configIndex2 | ||
) | const |
Compare two configurations to see if they are identical.
[in] | configIndex1 | Index of the first configuration. |
[in] | configIndex2 | Index of the second configuration. |
Definition at line 183 of file AliYAMLConfiguration.cxx.
Referenced by AliEmcalCorrectionTask::CompareToStoredConfiguration().
|
inline |
Definition at line 181 of file AliYAMLConfiguration.h.
Referenced by CompareConfigurations().
|
inline |
Definition at line 182 of file AliYAMLConfiguration.h.
Referenced by CompareConfigurations().
|
inline |
Definition at line 126 of file AliYAMLConfiguration.h.
Referenced by CompareConfigurations(), AliEmcalCorrectionTask::DetermineComponentsToExecute(), AliEmcalCorrectionTask::GetPropertyNamesFromNode(), AliEmcalCorrectionTask::PrintConfiguration(), and WriteConfiguration().
|
inline |
Definition at line 127 of file AliYAMLConfiguration.h.
Referenced by DoesConfigurationExist().
|
inlineprotected |
Checks if a file exists. This is done inline to make it efficient. See: https://stackoverflow.com/a/19841704
filename | String containing the filename of the file to check. |
Definition at line 242 of file AliYAMLConfiguration.cxx.
Referenced by AddConfiguration().
|
inline |
Definition at line 128 of file AliYAMLConfiguration.h.
Referenced by CompareConfigurations(), AliEmcalCorrectionTask::DetermineComponentsToExecute(), AliEmcalCorrectionTask::GetPropertyNamesFromNode(), and AliEmcalCorrectionTask::PrintConfiguration().
|
inline |
Definition at line 129 of file AliYAMLConfiguration.h.
Referenced by GetConfiguration().
|
inline |
Definition at line 130 of file AliYAMLConfiguration.h.
|
inline |
Definition at line 131 of file AliYAMLConfiguration.h.
Referenced by GetConfiguration().
|
inline |
Definition at line 138 of file AliYAMLConfiguration.h.
Referenced by CompareConfigurations(), DoesConfigurationExist(), GetConfiguration(), GetConfigurationIndexFromName(), Print(), RemoveConfiguration(), WriteConfiguration(), and WriteProperty().
|
protected |
Get the index of the configuration given the configuration name. If the same name is used multiple times, then the first instance will be returned.
[in] | name | Name of the configuration. |
[in] | configurations | Configurations to search through (could contain YAML nodes, or the string copies). |
Definition at line 638 of file AliYAMLConfiguration.h.
|
inline |
Definition at line 137 of file AliYAMLConfiguration.h.
bool AliYAMLConfiguration::GetProperty | ( | std::vector< std::string > | propertyPath, |
const std::string & | propertyName, | ||
T & | property, | ||
const bool | requiredProperty | ||
) | const |
Helper function for main retrieval function. It automatically adds the property name to the end of the property path. By doing so, it allows the user to specify a general property path and then vary the property name between function calls.
[in] | propertyPath | Path to the property in the YAML file. |
[in] | propertyName | Name of the property to be retrieved. |
[out] | property | Contains the retrieved property. |
[in] | requiredProperty | True if the property is required |
Definition at line 345 of file AliYAMLConfiguration.h.
Referenced by AliEmcalCorrectionTask::AddContainer(), AliEmcalCorrectionTask::AddContainersToComponent(), AliAnalysisTaskEmcalEmbeddingHelper::AutoConfigurePtHardBins(), AliEmcalCorrectionTask::CreateInputObjects(), AliEmcalCorrectionTask::DetermineComponentsToExecute(), AliEmcalCorrectionComponent::GetProperty(), GetProperty(), AliEmcalCorrectionComponent::Initialize(), AliAnalysisTaskEmcalEmbeddingHelper::InitializeYamlConfig(), AliEmcalCorrectionTask::SetupCellsInfo(), and AliEmcalCorrectionTask::SetupContainer().
bool AliYAMLConfiguration::GetProperty | ( | const std::vector< std::string > | propertyPath, |
T & | property, | ||
const bool | requiredProperty | ||
) | const |
Helper function for main retrieval function. Each value in the property path will be joined together, separated by the delimiter set in the configuration class.
[in] | propertyPath | Path to the property in the YAML file. |
[out] | property | Contains the retrieved property. |
[in] | requiredProperty | True if the property is required |
Definition at line 362 of file AliYAMLConfiguration.h.
bool AliYAMLConfiguration::GetProperty | ( | std::string | propertyName, |
T & | property, | ||
const bool | requiredProperty = true |
||
) | const |
Main general function to get a property from a set of YAML configuration files. It first calls checks the user configuration, and then if the property is not found, it then checks the default configuration. If the property is required but it is not found, a fatal error is thrown.
[in] | propertyName | Name of the property to retrieve |
[out] | property | Contains the retrieved property |
[in] | requiredProperty | True if the property is required |
Definition at line 392 of file AliYAMLConfiguration.h.
|
protected |
Actually handles retrieving parameters from YAML nodes.
For propertyName = "hello:example_special:property", the retrieval procedure is as follows:
[in] | node | Main YAML node containing the properties |
[in] | sharedParametersNode | YAML node containing the shared parameters |
[in] | configurationName | Name of the configuration type. |
[in] | propertyName | Name of the property to retrieve |
[out] | property | Contains the retrieved property |
Definition at line 456 of file AliYAMLConfiguration.h.
|
protected |
Utility function to retrieve the property from a already selected YAML node.
[in] | node | YAML node from which the property should be retrieved |
[in] | propertyName | Name of the property to retrieve |
[out] | property | Contains the retrieved property |
Definition at line 323 of file AliYAMLConfiguration.h.
Referenced by AddConfiguration(), and GetProperty().
bool AliYAMLConfiguration::Initialize | ( | ) |
Initialize configurations.
This includes storing the contents of the YAML configurations into strings so that they can be streamed to the grid. (yaml-cpp objects do not work properly with ROOT streamers).
NOTE: fConfigurationInitialized is set to true if the function is successful.
Definition at line 340 of file AliYAMLConfiguration.cxx.
Referenced by AliEmcalCorrectionTask::InitializeConfiguration().
|
protected |
Check if value is a shared parameter, meaning we should look at another node. Also edits the input string to remove "sharedParameters:" if it exists, making it ready for use.
[in] | value | String containing the string value return by the parameter. |
Definition at line 400 of file AliYAMLConfiguration.cxx.
Referenced by GetProperty().
std::ostream & AliYAMLConfiguration::Print | ( | std::ostream & | in, |
const int | index = -1 |
||
) | const |
Print YAML configuration information on an output stream using the string representation provided by AliYAMLConfiguration::toString(). Used by operator<<.
If index = -1 (which is the default argument), then all configurations will be printed!
in | output stream stream |
index | Index of the configuration to print. |
Definition at line 474 of file AliYAMLConfiguration.cxx.
Referenced by CompareConfigurations(), operator<<(), and Print().
std::ostream & AliYAMLConfiguration::Print | ( | std::ostream & | in, |
const std::string & | configurationName | ||
) | const |
Print YAML configuration information on an output stream using the string representation provided by AliYAMLConfiguration::toString(). Used by operator<<
in | output stream stream. |
configurationName | Name of the configuration to print. |
Definition at line 487 of file AliYAMLConfiguration.cxx.
void AliYAMLConfiguration::Print | ( | Option_t * | opt = "" | ) | const |
Print basic YAML configuration information using the string representation provided by AliYAMLConfiguration::toString()
Definition at line 496 of file AliYAMLConfiguration.cxx.
|
protected |
Print a particular configuration.
[in] | index | Index of the YAML configuration. |
Definition at line 418 of file AliYAMLConfiguration.cxx.
Referenced by toString().
|
protected |
Wrapper function to resolve ambiguity in function overloading. By passing 0 as the last argument to the PrintRetrievedPropertyValueImpl(...) functions, it will first attempt to use the matching int function, and then fall back the to the long function. This is effectively a hack to help c++ properly resolve the function to call.
Inspired by: https://stackoverflow.com/a/38283990
[in] | property | Property to be printed |
[in,out] | tempMessage | Stringstream into which the property should be streamed |
Definition at line 307 of file AliYAMLConfiguration.h.
Referenced by GetProperty().
|
protected |
Prints the retrieved property value if the type implements operator<<(). For more on how this achieved, see: https://stackoverflow.com/a/22759368 and https://stackoverflow.com/a/11866675. NOTE: This function should not be called directly, but through PrintRetrievedPropertyValue(...)
NOTE: This function returns void!
[in] | property | Property to be printed |
[in,out] | tempMessage | Stringstream into which the property should be streamed |
Definition at line 255 of file AliYAMLConfiguration.h.
Referenced by PrintRetrievedPropertyValue().
|
protected |
Prints the retrieved values in a vector if the value is a vector (more specifically, if it implements begin() and end()) and if the type of the vector can be streamed in an ostream object. NOTE: This function should not be called directly, but through PrintRetrievedPropertyValue(...)
[in] | property | Property to be printed |
[in,out] | tempMessage | Stringstream into which the property should be streamed |
Definition at line 269 of file AliYAMLConfiguration.h.
|
protected |
Handles all other cases where the property is not covered by the other functions.
NOTE: This function should not be called directly, but through PrintRetrievedPropertyValue(...)
NOTE: Cannot use "..." as a function argument here as a fall back because it causes problems with ROOT dictionary generation...
[in] | property | Property to be printed |
[in,out] | tempMessage | Stringstream into which the property should be streamed |
Definition at line 289 of file AliYAMLConfiguration.h.
bool AliYAMLConfiguration::Reinitialize | ( | ) |
Reinitialize the configurations from the strings after streaming. This is required because the YAML node objects cannot be streamed.
This should be called immediately after the object is streamed on the grid. For example, at UserCreateOutputObjects().
Definition at line 366 of file AliYAMLConfiguration.cxx.
Referenced by AliEmcalCorrectionTask::CompareToStoredConfiguration(), and AliEmcalCorrectionTask::UserCreateOutputObjects().
bool AliYAMLConfiguration::RemoveConfiguration | ( | const unsigned int | i | ) |
Remove a configuration at a given index.
[in] | i | Index of the configuration to be rmeoved. |
Definition at line 118 of file AliYAMLConfiguration.cxx.
Referenced by AliEmcalCorrectionTask::CompareToStoredConfiguration().
|
inline |
Definition at line 145 of file AliYAMLConfiguration.h.
Referenced by RemoveConfiguration().
|
protected |
Handles setting up the configuration file to be opened, including in AliPhysics and on the grid. Cannot just use TFile::Open() because the YAML file is just text as opposed to a root file. In the case of a file on the grid, it is copied locally.
[in,out] | filename | Name of the file to be open |
[in] | fileIdentifier | Additional file identifier to add onto the file name |
Definition at line 256 of file AliYAMLConfiguration.cxx.
Referenced by AddConfiguration().
std::string AliYAMLConfiguration::toString | ( | const int | index = -1 | ) | const |
Prints information about the YAML configuration(s).
If index = -1 (which is the default argument), then all configurations will be printed!
index | Index of the YAML configuration to be printed. |
Definition at line 432 of file AliYAMLConfiguration.cxx.
Referenced by Print().
bool AliYAMLConfiguration::WriteConfiguration | ( | const std::string & | filename, |
const unsigned int | index | ||
) | const |
Write a YAML configuration node to file.
[in] | index | Index of the YAML configuration node. |
[in] | filename | Filename to write the node to. |
Definition at line 138 of file AliYAMLConfiguration.cxx.
Referenced by AliAnalysisTaskEmcalEmbeddingHelper::AutoConfigurePtHardBins(), WriteConfiguration(), and AliEmcalCorrectionTask::WriteConfigurationFile().
bool AliYAMLConfiguration::WriteConfiguration | ( | const std::string & | filename, |
const std::string & | configurationName | ||
) | const |
Write a YAML configuration node to file.
[in] | configurationName | Name of the YAML configuration node. |
[in] | filename | Filename to write the node to. |
Definition at line 170 of file AliYAMLConfiguration.cxx.
|
protected |
Write a selected YAML configuration to file. Practically, it copies a local file to the desired location] to ensure seamless access to AliEn.
[in] | filename | Filename to which the configuration should be written. |
[in] | localFilename | Filename where the configuration was written locally. |
Definition at line 299 of file AliYAMLConfiguration.cxx.
Referenced by WriteConfiguration().
bool AliYAMLConfiguration::WriteProperty | ( | std::string | propertyName, |
T & | property, | ||
std::string | configurationName = "" |
||
) |
Write a value to a YAML configuration. Note that the value is written to the YAML configuration, but then the YAML configuration needs to explicitly be written to file if the changes should be persistent.
[in] | propertyPath | Path to the property in the YAML file. |
[in] | property | Property to be written. |
[in] | configurationName | Name of the YAML configuration file to which the property should be written. |
Definition at line 564 of file AliYAMLConfiguration.h.
Referenced by AliAnalysisTaskEmcalEmbeddingHelper::AutoConfigurePtHardBins().
|
protected |
Determine where the value should be written and write it to the appropriate YAML node.
[in,out] | node | YAML node where the property should (eventually) be written. |
[in] | propertyName | Name of the property to be written. |
[in] | property | Property to be written to the YAML node. |
Definition at line 593 of file AliYAMLConfiguration.h.
Referenced by WriteProperty().
|
friend |
Implementation of the output stream operator for AliYAMLConfiguration. Printing basic YAML configuration information provided by the function toString(). Note that since this is friend, it is defined outside the namespace.
in | output stream |
myTask | Task which will be printed |
Definition at line 513 of file AliYAMLConfiguration.cxx.
|
protected |
! Contains all YAML configurations. The first element has the highest precedence.
Definition at line 230 of file AliYAMLConfiguration.h.
Referenced by AddConfiguration(), CompareConfigurations(), DoesConfigurationExist(), GetConfiguration(), GetConfigurationIndexFromName(), GetConfigurationNameFromIndex(), GetProperty(), Initialize(), Print(), Reinitialize(), RemoveConfiguration(), toString(), WriteConfiguration(), and WriteProperty().
|
protected |
Contains all YAML configurations as strings so that they can be streamed.
Definition at line 232 of file AliYAMLConfiguration.h.
Referenced by Initialize(), Reinitialize(), and toString().
|
protected |
Delimiter character to separate each level of the request.
Definition at line 236 of file AliYAMLConfiguration.h.
Referenced by GetProperty(), and toString().
|
protected |
True if the configurations have been initialized.
Definition at line 234 of file AliYAMLConfiguration.h.
Referenced by Initialize(), Reinitialize(), and toString().
|
protected |
Contains the prefix of any names base node names which should be removed.
Definition at line 235 of file AliYAMLConfiguration.h.
Referenced by GetProperty(), and toString().