mupp 1.1.0
Loading...
Searching...
No Matches
PmuppScript Class Reference

Script interpreter for mupp batch processing. More...

#include <PmuppScript.h>

Inheritance diagram for PmuppScript:
Collaboration diagram for PmuppScript:

Public Slots

int executeScript ()
 Executes all script commands sequentially.
 

Signals

void finished ()
 Signal emitted when script execution completes.
 

Public Member Functions

 PmuppScript (QStringList script)
 Constructor. Initializes the script interpreter.
 
void setLoadPath (const QString cmd)
 Sets the load path for input data files.
 
QString getLoadPath ()
 Gets the current load path.
 
void setSavePath (const QString cmd)
 Sets the save path for output files.
 
QString getSavePath ()
 Gets the current save path.
 
int loadCollection (const QString str)
 Loads a data collection from file.
 
int select (const QString str)
 Selects a specific collection for plotting.
 
int selectAll ()
 Selects all loaded collections for plotting.
 
int addX (const QString str)
 Adds a parameter to the X-axis.
 
int addY (const QString str)
 Adds one or more parameters to the Y-axis.
 
int plot (const QString str)
 Creates a plot file by generating and executing a ROOT macro.
 
int macro (const QString str, const QString plotFln="")
 Generates a ROOT macro for plotting.
 
int var_cmd (const QString str, int script_idx=-1)
 Processes a variable definition command.
 

Private Member Functions

bool foundLabel (PmuppCollection *coll, const QString label)
 Checks if a parameter label exists in a collection.
 
bool foundVariable (const QString var)
 Checks if a variable is defined in the variable handler.
 
int getVarIndex (const QString var)
 Gets the index of a variable in the handler vector.
 
void minMax (QVector< double > dvec, double &min, double &max)
 Finds minimum and maximum values in a data vector.
 
QString getNicerLabel (const QString label)
 Converts parameter labels to prettier ROOT format.
 
int getCollectionIndex (const QString var_name)
 Gets the collection index associated with a variable.
 
QString getPythonBlock (int start_idx=-1)
 Returns the verbatim <python> ... </python> block of the script.
 

Private Attributes

std::unique_ptr< PmuppAdminfAdmin
 administration object for configuration
 
QStringList fScript
 list of script commands to execute
 
std::unique_ptr< PParamDataHandlerfParamDataHandler
 handler for parameter data collections
 
int fSelected
 selection state: -2=none, -1=all, >=0=specific index
 
PmuppPlotEntry fPlotEntry
 single plot configuration (for specific selection)
 
QVector< PmuppPlotEntryfPlotInfo
 vector of all plot configurations (for all selections)
 
bool fNorm
 normalization flag (true = normalize Y-data to max value)
 
QString fLoadPath
 directory path for loading input data files
 
QString fSavePath
 directory path for saving output files
 
QVector< PVarHandlerfVarHandler
 vector of variable expression handlers
 

Detailed Description

Script interpreter for mupp batch processing.

PmuppScript provides a command-line scripting interface for mupp, enabling automated batch processing of parameter data analysis and visualization. The class parses and executes script commands, managing data collections, plot configurations, variable definitions, and ROOT macro generation.

Script execution workflow:

  1. Initialize with script command list
  2. Execute commands sequentially via executeScript()
  3. Commands manipulate internal state (collections, plot config)
  4. Generate ROOT macros for plotting
  5. Optionally invoke ROOT in batch mode to create plot files

Command categories:

  • Path management: loadPath, savePath
  • Data loading: load
  • Collection selection: select, selectAll
  • Axis configuration: x (X-axis), y (Y-axis)
  • Variables: var, col
  • Normalization: norm
  • Output: plot, macro

Error handling: Methods return 0 on success, negative values on error. Specific error codes indicate different failure modes.

Definition at line 117 of file PmuppScript.h.

Constructor & Destructor Documentation

◆ PmuppScript()

PmuppScript::PmuppScript ( QStringList script)

Constructor. Initializes the script interpreter.

Constructor for the script interpreter.

Parameters
scriptlist of script commands to execute

Initializes the script execution environment with default settings:

  • Load path: current directory
  • Save path: current directory
  • Selection state: nothing selected
  • Normalization: disabled
  • Administration object for configuration access
Parameters
scriptlist of script commands to be executed

Definition at line 95 of file PmuppScript.cpp.

Member Function Documentation

◆ addX()

int PmuppScript::addX ( const QString str)

Adds a parameter to the X-axis.

Adds a parameter label to the X-axis.

Parameters
strx command string with parameter label
Returns
0 on success, negative value on error

Configures the X-axis (independent variable) for the plot. The label can be either:

  • A parameter name from the collection (e.g., "dataT", "dataB")
  • A defined variable expression

Behavior depends on selection state:

  • fSelected == -2: Error (no selection made)
  • fSelected == -1: Applies to all collections (creates fPlotInfo entries)
  • fSelected >= 0: Applies to specific collection (sets fPlotEntry)

Validation:

  • Checks if label exists in collection(s) or as a variable
  • Reports error if label not found
Parameters
strx command string (format: "x <label>")
Returns
0 on success
-1 wrong command syntax
-2 no collection selected
-3 selected collection not found
-4 label not found in collection or variables

Definition at line 420 of file PmuppScript.cpp.

◆ addY()

int PmuppScript::addY ( const QString str)

Adds one or more parameters to the Y-axis.

Adds one or more parameter labels to the Y-axis.

Parameters
stry command string with parameter label(s)
Returns
0 on success, negative value on error

Configures the Y-axis (dependent variable(s)) for the plot. Multiple Y-axis parameters can be specified in a single command, enabling multi-curve plots.

Each label can be either:

  • A parameter name from the collection
  • A defined variable expression

Behavior depends on selection state:

  • fSelected == -2: Error (no selection made)
  • fSelected == -1: Applies to all collections (updates fPlotInfo)
  • fSelected >= 0: Applies to specific collection (updates fPlotEntry, adds to fPlotInfo)

Validation:

  • Checks if each label exists in collection(s) or as a variable
  • Reports error on first missing label
Parameters
stry command string (format: "y <label1> [label2] [label3] ...")
Returns
0 on success
-1 wrong command syntax (< 2 tokens)
-2 no collection selected
-3 selected collection not found
-4 label not found in collection or variables

Definition at line 533 of file PmuppScript.cpp.

◆ executeScript

int PmuppScript::executeScript ( )
slot

Executes all script commands sequentially.

Processes each command in the script list, maintaining state and accumulating plot configurations. Emits finished() signal when complete or on error.

Returns
0 on success, negative or positive value on error

Processes each command in the script list, dispatching to appropriate handler methods based on command type. Maintains state throughout execution including:

  • Loaded data collections
  • Current selection
  • Plot configurations
  • Variable definitions

Command dispatch table:

Emits finished() signal upon completion or error.

Returns
0 on success, non-zero error code on failure

Definition at line 136 of file PmuppScript.cpp.

◆ finished

void PmuppScript::finished ( )
signal

Signal emitted when script execution completes.

◆ foundLabel()

bool PmuppScript::foundLabel ( PmuppCollection * coll,
const QString label )
private

Checks if a parameter label exists in a collection.

Parameters
collpointer to collection to search
labelparameter label to find
Returns
true if label found, false otherwise

Searches the first run of the collection for a parameter matching the given label. Assumes all runs in a collection have the same parameter structure.

Parameters
collpointer to collection to search
labelparameter label to find
Returns
true if label found in collection, false otherwise

Definition at line 1131 of file PmuppScript.cpp.

◆ foundVariable()

bool PmuppScript::foundVariable ( const QString var)
private

Checks if a variable is defined in the variable handler.

Parameters
varvariable name to search for
Returns
true if variable found, false otherwise

Searches the variable handler vector for a variable with the specified name. Used to validate variable references in x and y commands.

Parameters
varvariable name to search for
Returns
true if variable found, false otherwise

Definition at line 1156 of file PmuppScript.cpp.

◆ getCollectionIndex()

int PmuppScript::getCollectionIndex ( const QString var_name)
private

Gets the collection index associated with a variable.

Gets the collection index a variable is linked to.

Parameters
var_namevariable name
Returns
collection index, or -1 if not found

Scans the script for the 'col' command linking the given variable name to a collection and returns that collection index.

Parameters
var_namethe variable name to look up
Returns
the linked collection index, or -1 if not linked

Definition at line 1322 of file PmuppScript.cpp.

◆ getLoadPath()

QString PmuppScript::getLoadPath ( )
inline

Gets the current load path.

Returns
load path string

Definition at line 138 of file PmuppScript.h.

◆ getNicerLabel()

QString PmuppScript::getNicerLabel ( const QString label)
private

Converts parameter labels to prettier ROOT format.

Converts parameter labels to publication-quality ROOT format.

Parameters
labeloriginal parameter label
Returns
formatted label with ROOT markup (e.g., Greek letters)

Transforms standard parameter names into formatted labels suitable for publication plots, including:

  • Greek letters using ROOT markup (#sigma, #lambda, #alpha)
  • Subscripts and superscripts
  • Physical units
  • Normalization indicators (when fNorm is true)

Special case handling:

  • dataE → "E (keV)"
  • dataT → "T (K)"
  • dataB → "B (G)"
  • sigma → "#sigma (1/#mus)" or normalized version
  • lambda → "#lambda (1/#mus)" or normalized version
  • rate → "Rate (1/#mus)" or normalized version
  • alpha_LR → "#alpha_{LR}" or normalized version
  • alpha_TB → "#alpha_{TB}" or normalized version
  • others → "label/ max(label)" if normalized
Parameters
labeloriginal parameter label string
Returns
formatted label with ROOT markup

Definition at line 1243 of file PmuppScript.cpp.

◆ getPythonBlock()

QString PmuppScript::getPythonBlock ( int start_idx = -1)
private

Returns the verbatim <python> ... </python> block of the script.

Parameters
start_idxscan fScript from this index onwards (exclusive). Used so that multiple <python> blocks each pair with the preceding 'var' declaration. Defaults to -1 (start from the beginning).
Returns
the python block (including tags), or an empty string if none present

The script reader stores each python block as a single list entry. When a 'var X = python' declaration is being processed, the matching block is the first <python> ... </python> entry that comes after the declaration's position in the script. This pairs each declaration with the block that actually defines X (and XErr) and lets multiple python blocks coexist.

Parameters
start_idxposition of the calling 'var' command in fScript; the scan begins at start_idx+1. Pass -1 to scan from the beginning.
Returns
the python block (including the tags), or an empty string if none

Definition at line 1302 of file PmuppScript.cpp.

◆ getSavePath()

QString PmuppScript::getSavePath ( )
inline

Gets the current save path.

Returns
save path string

Definition at line 150 of file PmuppScript.h.

◆ getVarIndex()

int PmuppScript::getVarIndex ( const QString var)
private

Gets the index of a variable in the handler vector.

Parameters
varvariable name to search for
Returns
variable index, or -1 if not found

Searches for a variable by name and returns its position in the fVarHandler vector. Used during macro generation to retrieve variable values.

Parameters
varvariable name to search for
Returns
variable index (0-based), or -1 if not found

Definition at line 1181 of file PmuppScript.cpp.

◆ loadCollection()

int PmuppScript::loadCollection ( const QString str)

Loads a data collection from file.

Parameters
strload command string with filename
Returns
0 on success, positive value on error

Parses the load command to extract the filename, prepends the load path, and reads the parameter data file via the PParamDataHandler.

Processing steps:

  1. Removes "load " prefix from command string
  2. Trims whitespace from filename
  3. Prepends fLoadPath to create full file path
  4. Calls ReadParamFile() to load the data
Parameters
strload command string (format: "load filename.ext")
Returns
0 on success, 1 if file reading fails

Definition at line 301 of file PmuppScript.cpp.

◆ macro()

int PmuppScript::macro ( const QString str,
const QString plotFln = "" )

Generates a ROOT macro for plotting.

Generates a ROOT C++ macro for plotting.

Parameters
strmacro command string with macro filename
plotFlnoptional plot output filename (for SaveAs in macro)
Returns
0 on success, negative value on error

Creates a complete, standalone ROOT macro that can be executed independently. The macro includes:

Generated content:

  • Header with timestamp and filename
  • ROOT initialization and style settings
  • Data array declarations (xx, yy, error arrays)
  • Data population from collections/variables
  • TGraphAsymmErrors object creation
  • Canvas setup and configuration
  • Marker and color styling from configuration
  • Axis labels and ranges
  • Optional normalization
  • Optional SaveAs() call for plot output

Data handling:

  • Retrieves X/Y values from collections or variables
  • Handles asymmetric error bars (positive/negative)
  • Calculates axis ranges with 5% padding
  • Supports normalization to maximum Y value

Styling:

  • Uses marker and color definitions from PmuppAdmin
  • Falls back to default black circles if config exhausted
  • Applies ROOT formatting for Greek letters and subscripts
Parameters
strmacro command string (format: "macro filename.C")
plotFlnoptional output plot filename (adds SaveAs to macro)
Returns
0 on success
-1 wrong command syntax
-2 failed to open macro file for writing
-3 X or Y label data not found (internal error)

Definition at line 751 of file PmuppScript.cpp.

◆ minMax()

void PmuppScript::minMax ( QVector< double > dvec,
double & min,
double & max )
private

Finds minimum and maximum values in a data vector.

Parameters
dvecdata vector to analyze
minoutput parameter: minimum value
maxoutput parameter: maximum value

Scans through the data vector to determine the range. Used for automatic axis range calculation in plot generation.

Parameters
dvecdata vector to analyze
minoutput parameter: minimum value in vector
maxoutput parameter: maximum value in vector

Definition at line 1205 of file PmuppScript.cpp.

◆ plot()

int PmuppScript::plot ( const QString str)

Creates a plot file by generating and executing a ROOT macro.

Parameters
strplot command string with output filename
Returns
0 on success, negative value on error

This method performs the complete workflow for batch plot creation:

  1. Generates a temporary ROOT C++ macro (__out.C)
  2. Launches root.exe in batch mode to execute the macro
  3. Creates the output plot file (format determined by extension)
  4. Cleans up the temporary macro file

Supported output formats (via ROOT):

  • .pdf - PDF document
  • .png - PNG image
  • .eps - Encapsulated PostScript
  • .svg - Scalable Vector Graphics
  • .root - ROOT file

The method configures environment variables (LD_LIBRARY_PATH/ DYLD_LIBRARY_PATH) to ensure ROOT finds its libraries.

Parameters
strplot command string (format: "plot output_filename.ext")
Returns
0 on success
-1 wrong command syntax or macro generation failed
-2 failed to create QProcess
-3 failed to start root.exe

Definition at line 662 of file PmuppScript.cpp.

◆ select()

int PmuppScript::select ( const QString str)

Selects a specific collection for plotting.

Parameters
strselect command string with collection identifier
Returns
0 on success, negative value on error

Parses the select command to identify a collection by either:

  • Numeric index (0, 1, 2, ...)
  • Collection name string

The selected collection becomes the target for subsequent x and y commands. Sets fSelected to the collection index.

Parameters
strselect command string (format: "select <index|name>")
Returns
0 on success
-1 wrong command syntax
-2 collection index out of range
-3 collection name not found

Definition at line 336 of file PmuppScript.cpp.

◆ selectAll()

int PmuppScript::selectAll ( )

Selects all loaded collections for plotting.

Returns
0 on success, -1 if no collections available

Enables batch plotting mode where subsequent x and y commands apply to all collections. Sets fSelected to -1 (all-selected state).

This mode is useful for creating overlay plots showing multiple data sets with the same parameter axes.

Returns
0 on success, -1 if no collections are loaded

Definition at line 381 of file PmuppScript.cpp.

◆ setLoadPath()

void PmuppScript::setLoadPath ( const QString cmd)

Sets the load path for input data files.

Parameters
cmdloadPath command string with path specification

Parses the loadPath command string and extracts the directory path. Supports environment variable expansion: variables prefixed with '$' are replaced with their values from the system environment.

Path processing:

  1. Removes "loadPath " prefix from command
  2. Tokenizes path by '/' separator
  3. Expands environment variables ($VAR_NAME)
  4. Reconstructs full path with '/' separators

Example: "loadPath $HOME/data/musrfit/" → "/home/user/data/musrfit/"

Parameters
cmdloadPath command string including path specification

Definition at line 210 of file PmuppScript.cpp.

◆ setSavePath()

void PmuppScript::setSavePath ( const QString cmd)

Sets the save path for output files.

Parameters
cmdsavePath command string with path specification

Parses the savePath command string and extracts the directory path. Uses the same environment variable expansion mechanism as setLoadPath().

Path processing:

  1. Removes "savePath " prefix from command
  2. Tokenizes path by '/' separator
  3. Expands environment variables ($VAR_NAME)
  4. Reconstructs full path with '/' separators

Example: "savePath $HOME/plots/" → "/home/user/plots/"

Parameters
cmdsavePath command string including path specification

Definition at line 256 of file PmuppScript.cpp.

◆ var_cmd()

int PmuppScript::var_cmd ( const QString str,
int script_idx = -1 )

Processes a variable definition command.

Parameters
strvar command string with variable expression
script_idxposition of this command inside fScript; used to locate the matching <python> ... </python> block (the one following the declaration). Defaults to -1 (search from start).
Returns
0 on success, positive value on error

Variables enable defining derived quantities as mathematical expressions combining collection parameters. For example:

  • "var amplitude sigma+lambda"
  • "var asymmetry (forward-backward)/(forward+backward)"

Processing steps:

  1. Extracts variable name from command
  2. Checks if variable is linked to a collection (via col command)
  3. Locates optional error variable definition (varNameErr)
  4. Creates PVarHandler for expression parsing and evaluation
  5. Validates variable and stores handler if valid

Error handling:

  • Error variables (ending in "Err") are processed silently
  • Invalid expressions write errors to ~/.musrfit/mupp/mupp_err.log
  • Error log is displayed and deleted on failure

Integration with col command: The "col" command links variables to specific collections, enabling variable resolution during plot generation.

Parameters
strvar command string (format: "var <name> <expression>")
Returns
0 on success
0 if variable not linked to collection (ignored)
0 if error variable (processing deferred)
1 if variable expression is invalid

Definition at line 1030 of file PmuppScript.cpp.

Member Data Documentation

◆ fAdmin

std::unique_ptr<PmuppAdmin> PmuppScript::fAdmin
private

administration object for configuration

Definition at line 230 of file PmuppScript.h.

◆ fLoadPath

QString PmuppScript::fLoadPath
private

directory path for loading input data files

Definition at line 239 of file PmuppScript.h.

◆ fNorm

bool PmuppScript::fNorm
private

normalization flag (true = normalize Y-data to max value)

Definition at line 238 of file PmuppScript.h.

◆ fParamDataHandler

std::unique_ptr<PParamDataHandler> PmuppScript::fParamDataHandler
private

handler for parameter data collections

Definition at line 232 of file PmuppScript.h.

◆ fPlotEntry

PmuppPlotEntry PmuppScript::fPlotEntry
private

single plot configuration (for specific selection)

Definition at line 235 of file PmuppScript.h.

◆ fPlotInfo

QVector<PmuppPlotEntry> PmuppScript::fPlotInfo
private

vector of all plot configurations (for all selections)

Definition at line 236 of file PmuppScript.h.

◆ fSavePath

QString PmuppScript::fSavePath
private

directory path for saving output files

Definition at line 240 of file PmuppScript.h.

◆ fScript

QStringList PmuppScript::fScript
private

list of script commands to execute

Definition at line 231 of file PmuppScript.h.

◆ fSelected

int PmuppScript::fSelected
private

selection state: -2=none, -1=all, >=0=specific index

Definition at line 233 of file PmuppScript.h.

◆ fVarHandler

QVector<PVarHandler> PmuppScript::fVarHandler
private

vector of variable expression handlers

Definition at line 242 of file PmuppScript.h.


The documentation for this class was generated from the following files: