Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:57

0001 /*******************************************************************************
0002  * Copyright (c) The JETSCAPE Collaboration, 2018
0003  *
0004  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
0005  * 
0006  * For the list of contributors see AUTHORS.
0007  *
0008  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
0009  *
0010  * or via email to bugs.jetscape@gmail.com
0011  *
0012  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
0013  * See COPYING for details.
0014  ******************************************************************************/
0015 
0016 #ifndef JETSCAPEXML_H
0017 #define JETSCAPEXML_H
0018 
0019 #include <iostream>
0020 #include <string>
0021 #include <stdexcept>
0022 #include <initializer_list>
0023 
0024 #include "tinyxml2.h"
0025 
0026 /**
0027  * @class JetScapeXML
0028  * @brief JetScape XML init reader class (meant as singleton)
0029  *
0030  * This class contains the machinery to load two XML configuration files: a Main file, and a User file.
0031  *
0032  */
0033 
0034 using std::string;
0035 using std::runtime_error;
0036 
0037 namespace Jetscape {
0038 
0039 class JetScapeXML {
0040 
0041 public:
0042   static JetScapeXML *Instance();
0043 
0044   // Master file: These functions are deprecated. Users should use the Main functions instead.
0045   // These functions have been updated to use the 'main' instead of 'master' variables
0046 
0047   tinyxml2::XMLElement *GetXMLRootMaster() { return xml_root_main; }
0048   tinyxml2::XMLDocument &GetXMLDocumentMaster() { return xml_doc_main; }
0049   tinyxml2::XMLElement *
0050   GetXMLElementMaster(std::initializer_list<const char *> &path);
0051 
0052   void SetXMLMasterFileName(string m_name) { xml_main_file_name = m_name; }
0053   std::string GetXMLMasterFileName() { return xml_main_file_name; }
0054   bool IsMasterFileOpen() { return xml_main_file_open; }
0055 
0056   void OpenXMLMasterFile();
0057   void OpenXMLMasterFile(string m_name);
0058 
0059   // Main file:
0060 
0061   tinyxml2::XMLElement *GetXMLRootMain() const { return xml_root_main; }
0062   tinyxml2::XMLDocument &GetXMLDocumentMain() { return xml_doc_main; }
0063   tinyxml2::XMLElement *
0064   GetXMLElementMain(std::initializer_list<const char *> &path);
0065 
0066   void SetXMLMainFileName(string m_name) { xml_main_file_name = m_name; }
0067   std::string GetXMLMainFileName() const { return xml_main_file_name; }
0068   bool IsMainFileOpen() const { return xml_main_file_open; }
0069 
0070   void OpenXMLMainFile();
0071   void OpenXMLMainFile(string m_name);
0072 
0073   // User file
0074 
0075   tinyxml2::XMLElement *GetXMLRootUser() { return xml_root_user; }
0076   tinyxml2::XMLDocument &GetXMLDocumentUser() { return xml_doc_user; }
0077   tinyxml2::XMLElement *
0078   GetXMLElementUser(std::initializer_list<const char *> &path);
0079 
0080   void SetXMLUserFileName(string m_name) { xml_user_file_name = m_name; }
0081   std::string GetXMLUserFileName() { return xml_user_file_name; }
0082   bool IsUserFileOpen() { return xml_user_file_open; }
0083 
0084   void OpenXMLUserFile();
0085   void OpenXMLUserFile(string m_name);
0086 
0087   // Helper functions for XML parsing/
0088   // Look first in user XML file for a parameter, and if not found look in the main XML file.
0089   tinyxml2::XMLElement *GetElement(std::initializer_list<const char *> path,
0090                                    bool isRequired = true);
0091   std::string GetElementText(std::initializer_list<const char *> path,
0092                              bool isRequired = true);
0093   int GetElementInt(std::initializer_list<const char *> path,
0094                     bool isRequired = true);
0095   double GetElementDouble(std::initializer_list<const char *> path,
0096                           bool isRequired = true);
0097 
0098 private:
0099   JetScapeXML() {
0100     xml_main_file_name = "";
0101     xml_main_file_open = false;
0102     xml_user_file_name = "";
0103     xml_user_file_open = false;
0104   };
0105   JetScapeXML(JetScapeXML const &){};
0106   static JetScapeXML *m_pInstance;
0107 
0108   // Main file
0109 
0110   tinyxml2::XMLElement *
0111       xml_root_main; //use unique pointer here instead of raw pointer (check with tinyxml interface)
0112   tinyxml2::XMLDocument xml_doc_main;
0113 
0114   std::string xml_main_file_name;
0115   bool xml_main_file_open;
0116 
0117   // User file
0118 
0119   tinyxml2::XMLElement *
0120       xml_root_user; //use unique pointer here instead of raw pointer (check with tinyxml interface)
0121   tinyxml2::XMLDocument xml_doc_user;
0122 
0123   std::string xml_user_file_name;
0124   bool xml_user_file_open;
0125 };
0126 
0127 // Print the XML element path name
0128 std::ostream &operator<<(std::ostream &os,
0129                          std::initializer_list<const char *> path);
0130 
0131 } // end namespace Jetscape
0132 
0133 #endif