/**************************************************************************** PAdmin.h Author: Andreas Suter e-mail: andreas.suter@psi.ch *****************************************************************************/ /*************************************************************************** * Copyright (C) 2010-2025 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef _PADMIN_H_ #define _PADMIN_H_ #include #include #include #include #include #include #include "PTheoTemplate.h" #include "PMusrfitFunc.h" #include "PInstrumentDef.h" class PAdmin; /** * @brief The PFuncXMLParser class parses the musrfit_funcs.xml file. * * This class reads and parses the XML file containing musrfit function definitions * and theory templates. The parsed data is stored in the PAdmin object which is * passed to the constructor. */ class PFuncXMLParser { public: /** * @brief Constructor. Parses the given XML file. * @param fln Path to the musrfit_funcs.xml file. * @param admin Pointer to the PAdmin object where parsed data will be stored. */ PFuncXMLParser(const QString &fln, PAdmin*); /** * @brief Destructor. */ virtual ~PFuncXMLParser() {} /** * @brief Checks if the XML parsing was successful. * @return true if parsing succeeded, false otherwise. */ virtual bool isValid() { return fValid; } private: /// @brief Enumeration of XML tag keywords for parsing state machine. enum EFuncKeyWords {eEmpty, eTemplateName, eTemplateTheo, eTemplateFunc, eName, eAbbrv, eNoOfParam, eParam, eParamName, eParamValue, eParamMap}; bool parse(QIODevice *device); bool startDocument(); bool startElement(); bool endElement(); bool characters(); bool endDocument(); QXmlStreamReader fXml; ///< xml stream reader object bool fValid; ///< flag showing if XML read has been successful EFuncKeyWords fKeyWord; ///< key word tag to know how to handle the content PAdmin *fAdmin; ///< a pointer to the main administration class object PTheoTemplate fTheoTemplate; ///< current theory template being parsed PMusrfitFunc fFunc; ///< current function being parsed PFuncParam fParam; ///< current function parameter being parsed }; /** * @brief The PInstrumentDefXMLParser class parses instrument definition XML files. * * This class reads and parses XML files containing instrument definitions for * various muon facilities (PSI, TRIUMF, ISIS, J-PARC). Each instrument includes * setup configurations for different measurement types (ZF, TF, LF). */ class PInstrumentDefXMLParser { public: /** * @brief Constructor. Parses the given instrument definition XML file. * @param fln Path to the instrument definition XML file. * @param admin Pointer to the PAdmin object where parsed data will be stored. */ PInstrumentDefXMLParser(const QString &fln, PAdmin*); /** * @brief Destructor. */ virtual ~PInstrumentDefXMLParser() {} /** * @brief Checks if the XML parsing was successful. * @return true if parsing succeeded, false otherwise. */ virtual bool isValid() { return fValid; } private: /// @brief Enumeration of XML tag keywords for parsing state machine. enum EKeyWords {eEmpty, eInstitute, eInstrument, eRunNameTemplate, eBeamline, eDataFileFormat, eTf, eZf, eLf, eNoOfDetectors, eFgbOffset, eLgb, eBkgRange, eLogicDetector}; bool parse(QIODevice *device); bool startDocument(); bool startElement(); bool endElement(); bool characters(); bool endDocument(); QXmlStreamReader fXml; ///< xml stream reader object bool fValid; ///< flag showing if XML read has been successful EKeyWords fKeyWord; ///< key word tag to know how to handle the content PAdmin *fAdmin; ///< a pointer to the main administration class object QString fInstituteName; ///< current institute name being parsed PInstrument *fInstrument; ///< current instrument object being built PSetup *fSetup; ///< current setup object being built }; /** * @brief The PMusrWizDefault class stores default settings for the musrWiz wizard. * * This class holds the default institute, instrument, and fit type that should * be pre-selected when the wizard starts. These defaults are loaded from the * musrWiz.xml configuration file. */ class PMusrWizDefault { public: /** * @brief Constructor. Initializes defaults to "UnDef". */ PMusrWizDefault(); /** * @brief Destructor. */ ~PMusrWizDefault() {} /** * @brief Returns the default institute name. * @return Default institute name. */ QString getInstitute() { return fInstitute; } /** * @brief Returns the default instrument name. * @return Default instrument name. */ QString getInstrument() { return fInstrument; } /** * @brief Returns the default fit type. * @return Default fit type string. */ QString getFitType() { return fFitType; } /** * @brief Sets the default institute name. * @param str Institute name to set. */ void setInstitute(QString str) { fInstitute = str; } /** * @brief Sets the default instrument name. * @param str Instrument name to set. */ void setInstrument(QString str) { fInstrument = str; } /** * @brief Sets the default fit type. * @param str Fit type to set. */ void setFitType(QString str) { fFitType = str; } private: QString fInstitute; ///< default institute name QString fInstrument; ///< default instrument name QString fFitType; ///< default fit type }; /** * @brief The PMusrWizDefaultXMLParser class parses the musrWiz.xml default settings file. * * This class reads the musrWiz.xml file which contains the default settings for * the wizard, including the default institute, instrument, and fit type. */ class PMusrWizDefaultXMLParser { public: /** * @brief Constructor. Parses the given musrWiz.xml file. * @param fln Path to the musrWiz.xml file. * @param admin Pointer to the PAdmin object where parsed defaults will be stored. */ PMusrWizDefaultXMLParser(const QString &fln, PAdmin*); /** * @brief Destructor. */ virtual ~PMusrWizDefaultXMLParser() {} /** * @brief Checks if the XML parsing was successful. * @return true if parsing succeeded, false otherwise. */ virtual bool isValid() { return fValid; } private: /// @brief Enumeration of XML tag keywords for parsing state machine. enum EKeyWords {eEmpty, eInstitute, eInstrument, eFitType}; bool parse(QIODevice *device); bool startDocument(); bool startElement(); bool endElement(); bool characters(); bool endDocument(); QXmlStreamReader fXml; ///< xml stream reader object bool fValid; ///< flag showing if XML read has been successful EKeyWords fKeyWord; ///< key word tag to know how to handle the content PAdmin *fAdmin; ///< a pointer to the main administration class object PMusrWizDefault fDefault; ///< default settings being parsed }; /** * @brief The PAdmin class is the main administration class for musrWiz. * * This class serves as the central repository for all configuration data needed * by the musrWiz application. It loads and manages: * - Default wizard settings from musrWiz.xml * - Musrfit function definitions and theory templates from musrfit_funcs.xml * - Instrument definitions from instrument_def_*.xml files * * The XML parser friend classes populate this class with data from the configuration files. */ class PAdmin : public QObject { public: /** * @brief Constructor. Loads all configuration files. * * Attempts to load configuration files first from the local directory, * then from $HOME/.musrfit/musrWiz/. If files don't exist, creates them * from built-in resources. */ PAdmin(); /** * @brief Destructor. */ ~PAdmin() {} /** * @brief Checks if the admin object was initialized successfully. * @return true if all required configuration files were loaded, false otherwise. */ bool IsValid() { return fValid; } /** * @brief Dumps debug information to stdout. * @param tag Debug tag: 0=instrument defs, 1=musrfit funcs, 2=both, -1=none. */ void dump(int tag); /** * @brief Returns the default institute name. * @return Default institute name from musrWiz.xml. */ QString getDefaultInstitute() { return fDefault.getInstitute(); } /** * @brief Returns the default instrument name. * @return Default instrument name from musrWiz.xml. */ QString getDefaultInstrument() { return fDefault.getInstrument(); } /** * @brief Returns the default fit type. * @return Default fit type string from musrWiz.xml. */ QString getDefaultFitType() { return fDefault.getFitType(); } /** * @brief Returns a list of all available institute names. * @return QStringList containing all institute names. */ QStringList getInstituteList(); /** * @brief Returns a list of instruments for a given institute. * @param institute Institute name to query. * @return QStringList containing all instrument names for the institute. */ QStringList getInstrumentList(QString institute); /** * @brief Returns a pointer to an instrument object. * @param institute Institute name. * @param instrument Instrument name. * @return Pointer to PInstrument, or nullptr if not found. */ PInstrument *getInstrument(QString institute, QString instrument); /** * @brief Returns the number of theory templates. * @return Number of theory templates. */ int getTheoTemplateSize() { return fTheoTemplate.size(); } /** * @brief Returns all theory templates. * @return QVector containing all PTheoTemplate objects. */ QVector getTheoTemplates() { return fTheoTemplate; } /** * @brief Returns a theory template by index. * @param idx Index of the template. * @return PTheoTemplate at the given index, or empty template if out of range. */ PTheoTemplate getTheoTemplate(int idx); /** * @brief Returns the number of musrfit functions. * @return Number of musrfit functions. */ int getMusrfitFuncSize() { return fMusrfitFunc.size(); } /** * @brief Returns all musrfit functions. * @return QVector containing all PMusrfitFunc objects. */ QVector getMusrfitFunc() { return fMusrfitFunc; } /** * @brief Returns a musrfit function by name or abbreviation. * @param name Function name or abbreviation. * @return PMusrfitFunc matching the name, or default func if not found. */ PMusrfitFunc getMusrfitFunc(QString name); protected: /** * @brief Adds an instrument to an institute. * @param institute Institute name. Creates the institute if it doesn't exist. * @param instrument Instrument object to add. * @return 0 on success. */ int addInstrument(QString institute, PInstrument instrument); private: friend class PFuncXMLParser; friend class PInstrumentDefXMLParser; friend class PMusrWizDefaultXMLParser; bool fValid; ///< flag indicating successful initialization PMusrWizDefault fDefault; ///< default wizard settings QVector fInstitute; ///< list of institutes with their instruments QVector fTheoTemplate; ///< list of theory templates QVector fMusrfitFunc; ///< list of musrfit functions /** * @brief Loads the musrWiz.xml default settings file. * @param fln Path to the file. * @return 0 on success, 1 on failure. */ int loadMusrWizDefault(QString fln); /** * @brief Loads the musrfit_funcs.xml file. * @param fln Path to the file. * @return 0 on success, 1 on failure. */ int loadMusrfitFunc(QString fln); /** * @brief Loads an instrument definition XML file. * @param path Directory path containing the file. * @param fln Filename of the instrument definition file. * @return 0 on success, 1 on failure. */ int loadInstrumentDef(QString path, QString fln); }; #endif // _PADMIN_H_