musredit 1.0.0
Loading...
Searching...
No Matches
PFitOutputHandler Class Reference

Dialog for executing and monitoring musrfit fitting processes. More...

#include <PFitOutputHandler.h>

Inheritance diagram for PFitOutputHandler:
Collaboration diagram for PFitOutputHandler:

Public Member Functions

 PFitOutputHandler (QString workingDirectory, QVector< QString > &cmd)
 Constructs the fit output handler dialog and starts the musrfit process.
 
virtual ~PFitOutputHandler ()
 Destructor - ensures the musrfit process is terminated.
 

Private Slots

virtual void readFromStdOut ()
 Slot to read and display standard output from musrfit.
 
virtual void readFromStdErr ()
 Slot to read and display standard error from musrfit.
 
virtual void quitButtonPressed ()
 Slot called when the Quit/Done button is pressed.
 
virtual void processDone (int exitCode, QProcess::ExitStatus exitStatus)
 Slot called when the musrfit process finishes.
 

Private Attributes

Process Management

Members for managing the musrfit process.

qint64 fProcPID
 Process ID of the running musrfit process.
 
std::unique_ptr< QProcess > fProc
 QProcess object managing the musrfit execution.
 
UI Components

Dialog user interface elements.

std::unique_ptr< QVBoxLayout > fVbox
 Vertical layout manager for dialog widgets.
 
std::unique_ptr< QPlainTextEdit > fOutput
 Read-only text widget displaying musrfit output (max 1000 lines).
 
std::unique_ptr< QPushButton > fQuitButton
 Button showing "Fitting..." during fit, "Done" after completion.
 

Detailed Description

Dialog for executing and monitoring musrfit fitting processes.

This class provides a dialog that executes musrfit as a child process and displays its output in real-time. It allows users to monitor the fitting progress, including MINUIT2 iterations, chi-square values, warnings, and error messages.

Features:
  • Executes musrfit as a child process via QProcess
  • Captures both stdout and stderr output in real-time
  • Displays output in a scrollable, read-only text widget (limited to 1000 lines)
  • Button shows "Fitting..." during execution, changes to "Done" when complete
  • Allows interrupting a running fit by pressing the button
  • Proper process cleanup on dialog close or destruction
Usage:
QVector<QString> cmd;
cmd << "/path/to/musrfit" << "file.msr";
PFitOutputHandler dialog("/path/to/working/dir", cmd);
dialog.exec();
PFitOutputHandler(QString workingDirectory, QVector< QString > &cmd)
Constructs the fit output handler dialog and starts the musrfit process.
Platform Notes:
  • On macOS: Sets DYLD_LIBRARY_PATH for ROOT library access
  • On Linux: Sets LD_LIBRARY_PATH for ROOT library access
Output Files:
The working directory parameter determines where musrfit saves its output files, including the .mlog fit log file.
See also
PDumpOutputHandler For similar handling of dump_header output

Definition at line 97 of file PFitOutputHandler.h.

Constructor & Destructor Documentation

◆ PFitOutputHandler()

PFitOutputHandler::PFitOutputHandler ( QString workingDirectory,
QVector< QString > & cmd )

Constructs the fit output handler dialog and starts the musrfit process.

Initializes the dialog UI and starts the musrfit fitting process. The constructor performs the following steps:

  1. Creates the dialog layout with a plain text output area (max 1000 lines) and button
  2. Configures the process environment with appropriate library paths
  3. Sets the working directory for output files (mlog, etc.)
  4. Extracts the program and arguments from the command vector
  5. Connects process signals for output capture and completion notification
  6. Starts the musrfit process
Environment Configuration:
  • On macOS: Sets DYLD_LIBRARY_PATH to include $ROOTSYS/lib
  • On Linux: Sets LD_LIBRARY_PATH to include $ROOTSYS/lib
Parameters
workingDirectoryDirectory where musrfit will run and save output files (mlog files, MINUIT2 output, etc.).
cmdCommand vector where cmd[0] is the musrfit executable path and subsequent elements are command-line arguments (msr filename, options).
Note
If the command vector is empty, the constructor returns immediately without creating the UI. If the process fails to start, an error dialog is displayed.

Definition at line 76 of file PFitOutputHandler.cpp.

◆ ~PFitOutputHandler()

PFitOutputHandler::~PFitOutputHandler ( )
virtual

Destructor - ensures the musrfit process is terminated.

Performs cleanup by ensuring the musrfit child process is properly terminated. The termination sequence is:

  1. Attempt graceful termination with QProcess::terminate() (SIGTERM)
  2. Wait for process to finish
  3. If still running, use QProcess::kill() (SIGKILL)
  4. As a last resort, use system kill -9 command with stored PID

This multi-stage approach ensures the process doesn't become orphaned, even if musrfit doesn't respond to normal termination signals (e.g., if stuck in a long calculation).

Definition at line 144 of file PFitOutputHandler.cpp.

Member Function Documentation

◆ processDone

void PFitOutputHandler::processDone ( int exitCode,
QProcess::ExitStatus exitStatus )
privatevirtualslot

Slot called when the musrfit process finishes.

Slot called when the musrfit process finishes execution.

Parameters
exitCodeThe exit code returned by musrfit.
exitStatusThe exit status (normal or crash).

This slot is connected to QProcess::finished signal and is called when musrfit terminates, whether normally or due to a crash. It updates the button text from "Fitting..." to "Done" to indicate the fit has completed.

If the process crashed (exitStatus == QProcess::CrashExit), a debug message is logged with the exit code for diagnostic purposes.

Parameters
exitCodeThe exit code returned by musrfit (0 typically indicates success).
exitStatusThe exit status: QProcess::NormalExit for normal termination, QProcess::CrashExit if the process crashed.

Definition at line 215 of file PFitOutputHandler.cpp.

◆ quitButtonPressed

void PFitOutputHandler::quitButtonPressed ( )
privatevirtualslot

Slot called when the Quit/Done button is pressed.

Handles user request to close the dialog. The behavior depends on whether the fit is still running:

  • If running: Attempts to terminate musrfit gracefully using QProcess::terminate(). If graceful termination fails within the timeout period, forcefully kills the process using QProcess::kill().
  • If finished: Simply closes the dialog.

After ensuring the process is stopped (or was already stopped), accepts the dialog (closes it with QDialog::Accepted result).

Definition at line 237 of file PFitOutputHandler.cpp.

◆ readFromStdErr

void PFitOutputHandler::readFromStdErr ( )
privatevirtualslot

Slot to read and display standard error from musrfit.

Slot to capture and display standard error from musrfit.

Reads all available data from the musrfit process's standard error stream and appends it to the text display widget. This slot is connected to the QProcess::readyReadStandardError signal and may be called multiple times as error output arrives in chunks.

Error output typically includes warnings about parameter bounds, convergence issues, file access problems, and other diagnostic messages.

Definition at line 193 of file PFitOutputHandler.cpp.

◆ readFromStdOut

void PFitOutputHandler::readFromStdOut ( )
privatevirtualslot

Slot to read and display standard output from musrfit.

Slot to capture and display standard output from musrfit.

Reads all available data from the musrfit process's standard output stream and appends it to the text display widget. This slot is connected to the QProcess::readyReadStandardOutput signal and may be called multiple times as output arrives in chunks during the fitting process.

The output typically includes MINUIT2 iteration progress, parameter values, and chi-square information.

Definition at line 174 of file PFitOutputHandler.cpp.

Member Data Documentation

◆ fOutput

std::unique_ptr<QPlainTextEdit> PFitOutputHandler::fOutput
private

Read-only text widget displaying musrfit output (max 1000 lines).

Definition at line 142 of file PFitOutputHandler.h.

◆ fProc

std::unique_ptr<QProcess> PFitOutputHandler::fProc
private

QProcess object managing the musrfit execution.

Definition at line 134 of file PFitOutputHandler.h.

◆ fProcPID

qint64 PFitOutputHandler::fProcPID
private

Process ID of the running musrfit process.

Definition at line 133 of file PFitOutputHandler.h.

◆ fQuitButton

std::unique_ptr<QPushButton> PFitOutputHandler::fQuitButton
private

Button showing "Fitting..." during fit, "Done" after completion.

Definition at line 143 of file PFitOutputHandler.h.

◆ fVbox

std::unique_ptr<QVBoxLayout> PFitOutputHandler::fVbox
private

Vertical layout manager for dialog widgets.

Definition at line 141 of file PFitOutputHandler.h.


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