|
mupp 1.1.0
|
The PVarHandler class handles variable parsing, evaluation, and data management. More...
#include <PVarHandler.h>

Public Member Functions | |
| PVarHandler () | |
| Default constructor. | |
| PVarHandler (PmuppCollection *coll, std::string parse_str, std::string var_name="", const std::vector< PmuppCollection * > &allColl=std::vector< PmuppCollection * >()) | |
| Constructor that parses and evaluates a variable expression. | |
| bool | isValid () |
| Checks if the parsing and evaluation were successful. | |
| QString | getCollName () |
| Gets the collection name. | |
| QString | getVarName () |
| Gets the variable name. | |
| std::vector< double > | getValues () |
| Gets the computed values for the variable. | |
| std::vector< double > | getErrors () |
| Gets the computed errors for the variable. | |
Private Member Functions | |
| void | injectPredefVariables () |
| Injects predefined variables from the collection into the AST. | |
| void | evaluatePython () |
| Evaluates the variable using an embedded Python3 interpreter (TPython). | |
| std::string | getVarName (int idx) |
| Gets the variable name at a specific parameter index. | |
| std::vector< double > | getData (int idx) |
| Gets the data values for a specific parameter across all runs. | |
| std::vector< double > | getDataErr (int idx) |
| Gets the error values for a specific parameter across all runs. | |
Private Attributes | |
| PmuppCollection * | fColl |
| pointer to collection containing run data needed for parsing and evaluation | |
| std::vector< PmuppCollection * > | fAllColl |
| all loaded collections (handler-index order); Python path only, exposed as coll[]/collErr[] | |
| std::string | fParseStr |
| the variable input string to be parsed | |
| std::string | fVarName |
| name of the variable to extract from evaluation results | |
| mupp::prog::PVarHandler | fVar |
| variable handler storing the computed values and errors | |
| bool | fIsValid |
| flag indicating whether parsing and evaluation succeeded | |
| mupp::ast::statement_list | fAst |
| Abstract Syntax Tree generated from parsing. | |
The PVarHandler class handles variable parsing, evaluation, and data management.
This class provides the main interface for parsing variable definition strings, evaluating expressions using the Boost.Spirit parser framework, and managing the resulting computed values and errors. It integrates with PmuppCollection to access run data and inject predefined variables for use in expressions.
The variable syntax supports:
Example usage:
Definition at line 69 of file PVarHandler.h.
| PVarHandler::PVarHandler | ( | ) |
Default constructor.
Default constructor creating an invalid handler.
Creates an invalid PVarHandler instance with null pointers and empty strings.
Initializes all members to default/null values, resulting in an invalid handler that will return false from isValid().
Definition at line 286 of file PVarHandler.cpp.
| PVarHandler::PVarHandler | ( | PmuppCollection * | coll, |
| std::string | parse_str, | ||
| std::string | var_name = "", | ||
| const std::vector< PmuppCollection * > & | allColl = std::vector<PmuppCollection*>() ) |
Constructor that parses and evaluates a variable expression.
Parses the provided expression string, performs semantic analysis, injects predefined variables from the collection, evaluates the expression, and stores the results.
| coll | pointer to the PmuppCollection containing run data and parameters |
| parse_str | the variable definition string to parse (e.g., "var x = $T1 + 1.0") |
| var_name | optional variable name to extract from the evaluation results; if empty, only parsing/checking is performed |
| allColl | optional list of all loaded collections (in handler-index order). Only used by the Python path, where it is exposed inside the <python> block as coll[]/collErr[] (see evaluatePython()). If empty, only the bound collection 'coll' is injected (bare names and par[]/parErr[]). |
Performs the complete variable processing pipeline:
If parsing, semantic analysis, or evaluation fails, fIsValid is set to false and error messages are logged to ~/.musrfit/mupp/mupp_err.log.
| coll | pointer to the collection containing run data |
| parse_str | the variable definition string to parse |
| var_name | optional variable name to extract; if empty, only validation is performed |
| allColl | optional list of all loaded collections (Python path only) |
Definition at line 312 of file PVarHandler.cpp.
|
private |
Evaluates the variable using an embedded Python3 interpreter (TPython).
Evaluates a <python> ... </python> variable block via ROOT's TPython.
Used when the input string contains a <python> ... </python> block. The bound collection's parameters are injected into the interpreter as bare-name lists (one value per run) plus par[]/parErr[] dictionaries as a fallback for names that are not valid Python identifiers (e.g. the keyword 'lambda'). In addition, every loaded collection passed via fAllColl is exposed through the coll[]/collErr[] dictionaries, addressable both by integer index (matching the script 'col <idx>') and by collection name; index and name keys reference the same per-parameter dict. This lets a single <python> block compute (and combine) variables for several collections. The user script must assign the requested variable and its error counterpart (<name>Err). Both value and error arrays are read back and stored in fVar.
If mupp was built without TPython support, the handler is marked invalid.
See the declaration in PVarHandler.h for the data contract. On any failure a message is written to ~/.musrfit/mupp/mupp_err.log and fIsValid stays false.
Definition at line 368 of file PVarHandler.cpp.
|
inline |
Gets the collection name.
Definition at line 107 of file PVarHandler.h.
|
private |
Gets the data values for a specific parameter across all runs.
| idx | the parameter index in the collection |
Collects the value of the specified parameter from every run in the collection, returning them as a vector.
| idx | the parameter index (0-based) |
Definition at line 607 of file PVarHandler.cpp.
|
private |
Gets the error values for a specific parameter across all runs.
Computes the geometric mean of positive and negative errors for each run.
| idx | the parameter index in the collection |
Collects the error of the specified parameter from every run in the collection. The error is computed as the geometric mean of the positive and negative errors: sqrt(abs(posErr * negErr)).
| idx | the parameter index (0-based) |
Definition at line 635 of file PVarHandler.cpp.
| std::vector< double > PVarHandler::getErrors | ( | ) |
Gets the computed errors for the variable.
Gets the computed error values for the variable.
Returns the vector of error values computed during expression evaluation. Each element corresponds to a different run in the collection.
Definition at line 536 of file PVarHandler.cpp.
| std::vector< double > PVarHandler::getValues | ( | ) |
Gets the computed values for the variable.
Returns the vector of values computed during expression evaluation. Each element corresponds to a different run in the collection.
Definition at line 518 of file PVarHandler.cpp.
|
inline |
Gets the variable name.
Definition at line 113 of file PVarHandler.h.
|
private |
Gets the variable name at a specific parameter index.
| idx | the parameter index in the collection |
Retrieves the parameter name from the collection's first run at the specified index.
| idx | the parameter index (0-based) |
Definition at line 586 of file PVarHandler.cpp.
|
private |
Injects predefined variables from the collection into the AST.
Extracts all parameter names from the collection's first run and creates variable declarations for both the parameter names and their corresponding error variables (suffixed with 'Err'). These declarations are prepended to the AST before evaluation.
For each parameter in the collection's first run, creates variable declarations for both the parameter name and its corresponding error variable (with 'Err' suffix). These declarations are prepended to the AST so they are processed before user-defined variables, making all collection parameters available for use in expressions.
Definition at line 555 of file PVarHandler.cpp.
|
inline |
Checks if the parsing and evaluation were successful.
Definition at line 101 of file PVarHandler.h.
|
private |
all loaded collections (handler-index order); Python path only, exposed as coll[]/collErr[]
Definition at line 129 of file PVarHandler.h.
|
private |
Abstract Syntax Tree generated from parsing.
Definition at line 135 of file PVarHandler.h.
|
private |
pointer to collection containing run data needed for parsing and evaluation
Definition at line 128 of file PVarHandler.h.
|
private |
flag indicating whether parsing and evaluation succeeded
Definition at line 134 of file PVarHandler.h.
|
private |
the variable input string to be parsed
Definition at line 130 of file PVarHandler.h.
|
private |
variable handler storing the computed values and errors
Definition at line 132 of file PVarHandler.h.
|
private |
name of the variable to extract from evaluation results
Definition at line 131 of file PVarHandler.h.