|
musrfit 1.10.0
|
Class for parsing and evaluating mathematical functions from msr-file FUNCTIONS blocks. More...
#include <PFunction.h>

Classes | |
| class | EvalVisitor |
| Visitor class for evaluating the AST. More... | |
Public Member Functions | |
| PFunction (const musrfit::ast::assignment &assignment) | |
| Constructor that parses and prepares a function for evaluation. | |
| virtual | ~PFunction () |
| Destructor that cleans up resources. | |
| virtual Bool_t | IsValid () |
| Checks if the function was successfully parsed and initialized. | |
| virtual Int_t | GetFuncNo () |
| Returns the function number extracted from the function label. | |
| virtual Bool_t | CheckMapAndParamRange (UInt_t mapSize, UInt_t paramSize) |
| Validates that all parameter and map references are within valid ranges. | |
| virtual Double_t | Eval (std::vector< Double_t > param, PMetaData metaData) |
| Evaluates the function with given parameters and metadata. | |
| virtual void | SetMap (std::vector< Int_t > map) |
| Sets the map vector for parameter indirection. | |
| virtual TString * | GetFuncString () |
| Returns the human-readable string representation of the function. | |
Protected Member Functions | |
| virtual Bool_t | FindAndCheckMapAndParamRange (const musrfit::ast::operand &operand, UInt_t mapSize, UInt_t paramSize) |
| Recursively validates parameter and map references in the AST. | |
| virtual TString | GenerateString (const musrfit::ast::expression &expr) |
| Generates a human-readable string representation of the AST. | |
| virtual TString | GenerateStringOperand (const musrfit::ast::operand &operand) |
| Generates a string representation of an operand. | |
Private Attributes | |
| musrfit::ast::expression | fAst |
| Abstract syntax tree for the expression. | |
| std::vector< Double_t > | fParam |
| Current fit parameter values for evaluation. | |
| std::vector< Int_t > | fMap |
| Map vector for indirect parameter references. | |
| Bool_t | fValid |
| Validity flag: true if function parsed and initialized successfully. | |
| Int_t | fFuncNo |
| Function number extracted from label (x in FUNx) | |
| TString | fFuncString |
| Formatted, human-readable function representation. | |
| PMetaData | fMetaData |
| Metadata from experimental data (field, energy, temperature, etc.) | |
Class for parsing and evaluating mathematical functions from msr-file FUNCTIONS blocks.
This class handles the complete lifecycle of a function definition:
Functions can reference:
Example function definition:
Definition at line 69 of file PFunction.h.
| PFunction::PFunction | ( | const musrfit::ast::assignment & | assignment | ) |
Constructor that parses and prepares a function for evaluation.
Constructor that initializes the function from a parsed AST.
| assignment | Abstract syntax tree (AST) from parsing a function expression |
This constructor stores the AST generated by the Boost.Spirit X3 parser, extracts the function number, and prepares the function for evaluation. The X3 AST is directly suitable for evaluation using the visitor pattern, eliminating the need for conversion to an intermediate tree structure.
| assignment | AST from parsing a function expression (FUN# = expression) |
Definition at line 55 of file PFunction.cpp.
References fAst, fFuncNo, fFuncString, fValid, and GenerateString().
Referenced by FindAndCheckMapAndParamRange(), and GenerateStringOperand().
|
virtual |
Destructor that cleans up resources.
Destructor that releases resources.
Cleans up parameter and map vectors.
Definition at line 74 of file PFunction.cpp.
|
virtual |
Validates that all parameter and map references are within valid ranges.
| mapSize | Number of available map entries |
| paramSize | Number of available fit parameters |
Recursively traverses the AST to find all parameter (PAR#) and map (MAP#) references and checks that they are within the specified bounds.
| mapSize | Number of available map entries |
| paramSize | Number of available fit parameters |
Definition at line 91 of file PFunction.cpp.
References fAst, and FindAndCheckMapAndParamRange().
|
virtual |
Evaluates the function with given parameters and metadata.
| param | Vector of fit parameter values |
| metaData | Metadata containing field, energy, temperature, etc. |
Uses the visitor pattern to traverse the AST and compute the numeric result. The evaluation applies operators with proper precedence as encoded in the AST.
| param | Vector of fit parameter values |
| metaData | Metadata containing field, energy, temperature, etc. |
Definition at line 193 of file PFunction.cpp.
|
protectedvirtual |
Recursively validates parameter and map references in the AST.
Recursively validates parameter and map references in an operand.
| operand | Current operand being checked |
| mapSize | Number of available map entries |
| paramSize | Number of available fit parameters |
Helper visitor for CheckMapAndParamRange that handles different operand types.
| operand | Current operand being checked |
| mapSize | Number of available map entries |
| paramSize | Number of available fit parameters |
Definition at line 121 of file PFunction.cpp.
References FindAndCheckMapAndParamRange(), and PFunction().
Referenced by CheckMapAndParamRange(), and FindAndCheckMapAndParamRange().
|
protectedvirtual |
Generates a human-readable string representation of the AST.
Generates a human-readable string representation of an expression.
| expr | Expression AST to convert to string |
| expr | Expression AST to convert |
Definition at line 238 of file PFunction.cpp.
References GenerateString(), and GenerateStringOperand().
Referenced by GenerateString(), GenerateStringOperand(), and PFunction().
|
protectedvirtual |
Generates a string representation of an operand.
| operand | Operand AST to convert to string |
| operand | Operand AST to convert |
Definition at line 318 of file PFunction.cpp.
References GenerateString(), GenerateStringOperand(), and PFunction().
Referenced by GenerateString(), and GenerateStringOperand().
|
inlinevirtual |
Returns the function number extracted from the function label.
Definition at line 99 of file PFunction.h.
References fFuncNo.
|
inlinevirtual |
Returns the human-readable string representation of the function.
Definition at line 138 of file PFunction.h.
References fFuncString.
|
inlinevirtual |
Checks if the function was successfully parsed and initialized.
Definition at line 91 of file PFunction.h.
References fValid.
|
inlinevirtual |
Sets the map vector for parameter indirection.
Maps allow indirect parameter references. MAP# references fMap[#-1], which then indexes into the parameter vector.
| map | Vector of parameter indices (1-based) |
Definition at line 130 of file PFunction.h.
References fMap.
|
private |
Abstract syntax tree for the expression.
Definition at line 202 of file PFunction.h.
Referenced by CheckMapAndParamRange(), Eval(), and PFunction().
|
private |
Function number extracted from label (x in FUNx)
Definition at line 207 of file PFunction.h.
Referenced by GetFuncNo(), and PFunction().
|
private |
Formatted, human-readable function representation.
Definition at line 208 of file PFunction.h.
Referenced by GetFuncString(), and PFunction().
|
private |
Map vector for indirect parameter references.
Definition at line 204 of file PFunction.h.
Referenced by Eval(), SetMap(), and ~PFunction().
|
private |
Metadata from experimental data (field, energy, temperature, etc.)
Definition at line 209 of file PFunction.h.
Referenced by Eval().
|
private |
Current fit parameter values for evaluation.
Definition at line 203 of file PFunction.h.
Referenced by Eval(), and ~PFunction().
|
private |
Validity flag: true if function parsed and initialized successfully.
Definition at line 206 of file PFunction.h.
Referenced by Eval(), IsValid(), and PFunction().