JANA2
C++ framework for multi-threaded data processing
|
Public Member Functions | |
JParameterManager () | |
Default constructor. | |
JParameterManager (const JParameterManager &) | |
Copy constructor. More... | |
~JParameterManager () override | |
Destructor. More... | |
void | SetLogger (JLogger logger) |
bool | Exists (std::string name) |
Test whether a parameter of some name exists. More... | |
JParameter * | FindParameter (std::string) |
Retrieves a JParameter object of some name. More... | |
void | PrintParameters () |
void | PrintParameters (int verbosity, int strictness) |
Prints parameters to stdout. More... | |
std::map< std::string, JParameter * > | GetAllParameters () |
Access entire map of parameters. More... | |
template<typename T > | |
JParameter * | GetParameter (std::string name, T &val) |
Retrieves a JParameter and stores its value. More... | |
template<typename T > | |
T | GetParameterValue (std::string name) |
Retrieves a parameter value. More... | |
template<typename T > | |
JParameter * | SetParameter (std::string name, T val) |
Sets a configuration parameter. More... | |
template<typename T > | |
JParameter * | SetDefaultParameter (std::string name, T &val, std::string description="") |
Retrieve a configuration parameter, if necessary creating it with the provided default value. More... | |
template<typename T > | |
T | RegisterParameter (std::string name, const T default_val, std::string description="") |
Retrieve a configuration parameter, if necessary creating it with the provided default value. More... | |
void | FilterParameters (std::map< std::string, std::string > &parms, std::string filter="") |
Copy a list of all parameters into the supplied map, replacing its current contents. More... | |
void | ReadConfigFile (std::string name) |
Load parameters from a configuration file. More... | |
void | WriteConfigFile (std::string name) |
Write parameters out to an ASCII configuration file. More... | |
JLogger | GetLogger (const std::string &prefix) |
template<> | |
void | Parse (const std::string &value, std::string &out) |
Specialization for string. More... | |
template<> | |
void | Parse (const std::string &value, bool &val) |
Specialization for bool. | |
template<typename T , size_t N> | |
void | Parse (const std::string &value, std::array< T, N > &val) |
template<> | |
void | Parse (const std::string &in, JLogger::Level &out) |
Specialization for JLogger::Level enum. | |
template<> | |
std::string | Stringify (const float &value) |
template<> | |
std::string | Stringify (const double &value) |
template<> | |
std::string | Stringify (const long double &value) |
template<> | |
std::string | Stringify (const std::string &value) |
template<> | |
std::string | Stringify (const JInspector::Format &value) |
template<> | |
void | Parse (const std::string &value, JInspector::Format &val) |
Public Member Functions inherited from JService | |
virtual | ~JService ()=default |
acquire_services is a callback which allows the user to configure a JService which relies on other JServices. More... | |
void | DoInit (JServiceLocator *) |
virtual void | Init () |
virtual void | acquire_services (JServiceLocator *) |
Public Member Functions inherited from jana::components::JComponent | |
void | SetLevel (JEventLevel level) |
void | SetCallbackStyle (CallbackStyle style) |
void | SetPrefix (std::string prefix) |
void | SetTypeName (std::string type_name) |
For convenience, we provide a NAME_OF_THIS macro so that the user doesn't have to store the type name as a string, because that could get out of sync if automatic refactoring tools are used. | |
JApplication * | GetApplication () const |
JLogger & | GetLogger () |
std::string | GetPrefix () const |
JEventLevel | GetLevel () const |
std::string | GetLoggerName () const |
std::string | GetPluginName () const |
void | SetLoggerName (std::string logger_name) |
void | SetPluginName (std::string plugin_name) |
std::string | GetTypeName () const |
virtual void | Summarize (JComponentSummary &) const |
CallbackStyle | GetCallbackStyle () const |
Status | GetStatus () const |
void | SetApplication (JApplication *app) |
void | SetLogger (JLogger logger) |
template<typename F > | |
void | CallWithJExceptionWrapper (std::string func_name, F func) |
void | RegisterParameter (ParameterBase *parameter) |
void | RegisterService (ServiceBase *service) |
void | ConfigureAllParameters (std::map< std::string, std::string > fields) |
Static Public Member Functions | |
template<typename T > | |
static void | Parse (const std::string &value, T &out) |
Basic implementation of Parse for C++14 and earlier. | |
template<typename T > | |
static void | Parse (const std::string &value, std::vector< T > &out) |
Specialization for std::vector<std::string> | |
template<typename T , size_t arrSize> | |
static void | Parse (const std::string &value, std::array< T, arrSize > &out) |
template<typename T > | |
static std::string | Stringify (const T &value) |
Basic implementation of Parse for C++14 and earlier. | |
template<typename T > | |
static std::string | Stringify (const std::vector< T > &values) |
template<typename T , size_t N> | |
static std::string | Stringify (const std::array< T, N > &values) |
template<typename T > | |
static bool | Equals (const T &lhs, const T &rhs) |
static std::string | ToLower (const std::string &name) |
Converts a parameter name to all lowercase. More... | |
Additional Inherited Members | |
Public Types inherited from jana::components::JComponent | |
enum class | Status { Uninitialized , Initialized , Opened , Closed , Finalized } |
enum class | CallbackStyle { LegacyMode , ExpertMode , DeclarativeMode } |
Protected Attributes inherited from jana::components::JComponent | |
std::vector< ParameterBase * > | m_parameters |
std::vector< ServiceBase * > | m_services |
JEventLevel | m_level = JEventLevel::PhysicsEvent |
CallbackStyle | m_callback_style = CallbackStyle::LegacyMode |
std::string | m_prefix |
std::string | m_plugin_name |
std::string | m_logger_name |
std::string | m_type_name |
Status | m_status = Status::Uninitialized |
std::mutex | m_mutex |
JApplication * | m_app = nullptr |
JLogger | m_logger |
JParameterManager::JParameterManager | ( | const JParameterManager & | other | ) |
Copy constructor.
Does a deep copy of the JParameter objects to avoid double frees.
|
override |
Destructor.
Destroys all contained JParameter objects.
bool JParameterManager::Exists | ( | std::string | name | ) |
Test whether a parameter of some name exists.
[in] | name | the parameter name |
void JParameterManager::FilterParameters | ( | std::map< std::string, std::string > & | parms, |
std::string | filter = "" |
||
) |
Copy a list of all parameters into the supplied map, replacing its current contents.
[in] | filter | Empty by default. If the filter string is non-empty, it is used to filter out all parameters whose key does not start with the filter string. Furthermore, the filter string is removed from the keys. |
[out] | parms | A map of {key: string, parameter: string}. The contents of this map are replaced on each call. Parameter values are returned as strings rather than as JParameter objects, which means we don't have to worry about ownership. Returned parameters are marked as used. |
JParameter * JParameterManager::FindParameter | ( | std::string | name | ) |
Retrieves a JParameter object of some name.
[in] | name | the parameter name |
std::map< std::string, JParameter * > JParameterManager::GetAllParameters | ( | ) |
Access entire map of parameters.
Use this to do things like writing all parameters out to a non-standard format. This creates a copy of the map. Any modifications you make to the map itself won't propagate back to the JParameterManager. However, any modifications you make to the enclosed JParameters will. Prefer using SetParameter, SetDefaultParameter, FindParameter, or FilterParameters instead.
JParameter * JParameterManager::GetParameter | ( | std::string | name, |
T & | val | ||
) |
Retrieves a JParameter and stores its value.
[in] | name | The name of the parameter to retrieve |
[out] | val | Reference to where the parameter value should be stored |
T JParameterManager::GetParameterValue | ( | std::string | name | ) |
Retrieves a parameter value.
[in] | name | The name of the parameter to retrieve |
JException | in case the parameter is not found |
|
inline |
Specialization for string.
The stream operator is not only redundant here, but it also splits the string (see Issue #191)
void JParameterManager::PrintParameters | ( | int | verbosity, |
int | strictness | ||
) |
Prints parameters to stdout.
[in] | int | verbosity 0: Don't show parameters table 1: Show parameters with user-provided values only 2: Show parameters with default values, except those marked "advanced" 3: Show parameters with default values, including those marked "advanced" |
[in] | int | strictness 0: Ignore unused parameters 1: Warn on unused parameters 2: Throw on unused parameters |
void JParameterManager::ReadConfigFile | ( | std::string | filename | ) |
Load parameters from a configuration file.
filename | Path to the configuration file |
The file should have the form:
key1 value1 key2 value2 ...
There should be a space between the key and the value. The key may contain no spaces. The value is taken as the rest of the line up to, but not including the newline. A key may be specified with no value and the value will be set to "1". A "#" charater will discard the remaining characters in a line up to the next newline. Lines starting with "#" are ignored completely. Lines with no characters (except for the newline) are ignored.
|
inline |
Retrieve a configuration parameter, if necessary creating it with the provided default value.
[in] | name | The parameter name. Must not contain spaces. |
[in,out] | default_val | Value to set the desired default value to (returned if no value yet set for parameter). |
[in] | description | Optional description, e.g. units, set or range of valid values, etc. |
This is a convenience method that wraps SetDefaultParameter. The difference is that this has the default passed by value (not by reference) and the value of the parameter is returned by value. This allows a slightly different form for declaring configuration parameters with a default value. e.g. auto thresh = jpp->RegisterParameter("SystemA:threshold", 1.3, "threshold in MeV");
References SetDefaultParameter().
JParameter * JParameterManager::SetDefaultParameter | ( | std::string | name, |
T & | val, | ||
std::string | description = "" |
||
) |
Retrieve a configuration parameter, if necessary creating it with the provided default value.
[in] | name | The parameter name. Must not contain spaces. |
[in,out] | val | Reference to a variable which has been set to the desired default value. |
[in] | description | Optional description, e.g. units, set or range of valid values, etc. |
Upon entry, the value in "val" should be set to the desired default value. It will be overwritten if a value for the parameter already exists because it was given by the user either on the command line or in a configuration file. If the parameter does not already exist, it is created and its value set to that of "val". Upon exit, "val" will always contain the value that should be used for event processing.
If a parameter with the given name already exists, it will be checked to see if the parameter already has a default value assigned (this is kept separate from the actual value of the parameter used and is maintained purely for bookkeeping purposes). If it does not have a default value, then the value of "val" upon entry is saved as the default. If it does have a default, then the value of the default is compared to the value of "val" upon entry. If the two do not match, then a warning message is printed to indicate to the user that two different default values are being set for this parameter.
Parameters specified on the command line using the "-Pkey=value" syntax will not have a default value at the time the parameter is created.
References Parse(), Stringify(), and ToLower().
Referenced by RegisterParameter().
JParameter * JParameterManager::SetParameter | ( | std::string | name, |
T | val | ||
) |
Sets a configuration parameter.
[in] | name | The parameter name |
[in] | val | The parameter value. This may be typed, or it may be a string. |
References Stringify(), and ToLower().
|
static |
Converts a parameter name to all lowercase.
When accessing the m_parameters map, strings are always converted to lower case. This makes configuration parameters case-insensitive in effect, while still preserving the user's choice of case in the parameter name.
Referenced by GetParameter(), GetParameterValue(), SetDefaultParameter(), and SetParameter().
void JParameterManager::WriteConfigFile | ( | std::string | filename | ) |
Write parameters out to an ASCII configuration file.
[in] | filename | Path to the configuration file |
The file is written in a format compatible with reading in via ReadConfigFile().