diff --git a/src/musredit_qt6/mupp/PmuppScript.cpp b/src/musredit_qt6/mupp/PmuppScript.cpp index 66459ed3d..f3693d2ad 100644 --- a/src/musredit_qt6/mupp/PmuppScript.cpp +++ b/src/musredit_qt6/mupp/PmuppScript.cpp @@ -27,6 +27,44 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +/** + * @file PmuppScript.cpp + * + * @brief Implementation of the mupp scripting interface for batch processing. + * + * This file implements the non-interactive scripting system for mupp, enabling + * automated batch processing of parameter data analysis and plotting tasks. + * + * Key functionality implemented: + * - Script command parsing and execution + * - Path management with environment variable expansion + * - Data collection loading and selection + * - X-Y axis parameter configuration + * - Variable expression evaluation and storage + * - ROOT macro generation with full plot specification + * - Batch mode plot creation via ROOT subprocess + * - Label formatting for publication-quality plots + * + * Script command processing: + * The executeScript() method processes commands sequentially, maintaining + * state throughout execution. Each command type (loadPath, load, select, + * x, y, var, norm, plot, macro) has a dedicated handler method. + * + * ROOT macro generation: + * The macro() method creates complete ROOT C++ macros including: + * - Data array definitions + * - TGraphAsymmErrors objects for error bars + * - Canvas and styling setup + * - Axis labels and ranges + * - Marker and color configuration + * - Optional normalization + * + * Variable system: + * Variables are mathematical expressions combining collection parameters. + * The var_cmd() method integrates with PVarHandler for expression parsing + * and evaluation, enabling derived quantity calculations. + */ + #include #include @@ -43,8 +81,16 @@ //-------------------------------------------------------------------------- /** - * @brief PmuppScript::PmuppScript. Ctor - * @param script source + * @brief Constructor for the script interpreter. + * + * 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 + * + * @param script list of script commands to be executed */ PmuppScript::PmuppScript(QStringList script) : fScript(script) @@ -59,8 +105,33 @@ PmuppScript::PmuppScript(QStringList script) : //-------------------------------------------------------------------------- /** - * @brief PmuppScript::executeScript. Handles the script commands. - * @return 0 on success. + * @brief Executes all script commands sequentially. + * + * 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: + * - "loadPath" → setLoadPath() + * - "savePath" → setSavePath() + * - "load " → loadCollection() + * - "selectAll" → selectAll() + * - "select " → select() + * - "x" → addX() + * - "y" → addY() + * - "norm" → sets fNorm flag + * - "plot" → plot() + * - "macro" → macro() + * - "var" → var_cmd() + * - "col" → (handled internally by var) + * + * Emits finished() signal upon completion or error. + * + * @return 0 on success, non-zero error code on failure */ int PmuppScript::executeScript() { @@ -117,9 +188,22 @@ int PmuppScript::executeScript() //-------------------------------------------------------------------------- /** - * @brief PmuppScript::setLoadPath. Sets the load path (where to look for input - * data. - * @param cmd set load path command string. + * @brief Sets the load path for input data files. + * + * 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/" + * + * @param cmd loadPath command string including path specification */ void PmuppScript::setLoadPath(const QString cmd) { @@ -151,9 +235,21 @@ void PmuppScript::setLoadPath(const QString cmd) //-------------------------------------------------------------------------- /** - * @brief PmuppScript::setSavePath. Sets the save path (where to save the output - * files. - * @param cmd save path command string. + * @brief Sets the save path for output files. + * + * 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/" + * + * @param cmd savePath command string including path specification */ void PmuppScript::setSavePath(const QString cmd) { @@ -185,9 +281,20 @@ void PmuppScript::setSavePath(const QString cmd) //-------------------------------------------------------------------------- /** - * @brief PmuppScript::loadCollection. Load collection command - * @param str load collection command string - * @return 0 on success. + * @brief Loads a data collection from file. + * + * 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 + * + * @param str load command string (format: "load filename.ext") + * + * @return 0 on success, 1 if file reading fails */ int PmuppScript::loadCollection(const QString str) { @@ -208,9 +315,21 @@ int PmuppScript::loadCollection(const QString str) //-------------------------------------------------------------------------- /** - * @brief PmuppScript::select. Select collection command. - * @param str selection command string + * @brief Selects a specific collection for plotting. + * + * 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. + * + * @param str select command string (format: "select ") + * * @return 0 on success + * @return -1 wrong command syntax + * @return -2 collection index out of range + * @return -3 collection name not found */ int PmuppScript::select(const QString str) { @@ -247,8 +366,15 @@ int PmuppScript::select(const QString str) //-------------------------------------------------------------------------- /** - * @brief PmuppScript::selectAll. Select all collections - * @return 0 on success + * @brief Selects all loaded collections for plotting. + * + * 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. + * + * @return 0 on success, -1 if no collections are loaded */ int PmuppScript::selectAll() { @@ -265,9 +391,29 @@ int PmuppScript::selectAll() //-------------------------------------------------------------------------- /** - * @brief PmuppScript::addX. Add label to x-axis - * @param str label string + * @brief Adds a parameter label to the X-axis. + * + * 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 + * + * @param str x command string (format: "x