Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetScapeXML.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetScapeXML.h
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 
16 #ifndef JETSCAPEXML_H
17 #define JETSCAPEXML_H
18 
19 #include <iostream>
20 #include <string>
21 #include <stdexcept>
22 #include <initializer_list>
23 
24 #include "tinyxml2.h"
25 
34 using std::string;
35 using std::runtime_error;
36 
37 namespace Jetscape {
38 
39 class JetScapeXML {
40 
41 public:
42  static JetScapeXML *Instance();
43 
44  // Master file: These functions are deprecated. Users should use the Main functions instead.
45  // These functions have been updated to use the 'main' instead of 'master' variables
46 
50  GetXMLElementMaster(std::initializer_list<const char *> &path);
51 
55 
56  void OpenXMLMasterFile();
57  void OpenXMLMasterFile(string m_name);
58 
59  // Main file:
60 
64  GetXMLElementMain(std::initializer_list<const char *> &path);
65 
68  bool IsMainFileOpen() const { return xml_main_file_open; }
69 
70  void OpenXMLMainFile();
71  void OpenXMLMainFile(string m_name);
72 
73  // User file
74 
78  GetXMLElementUser(std::initializer_list<const char *> &path);
79 
83 
84  void OpenXMLUserFile();
85  void OpenXMLUserFile(string m_name);
86 
87  // Helper functions for XML parsing/
88  // Look first in user XML file for a parameter, and if not found look in the main XML file.
89  tinyxml2::XMLElement *GetElement(std::initializer_list<const char *> path,
90  bool isRequired = true);
91  std::string GetElementText(std::initializer_list<const char *> path,
92  bool isRequired = true);
93  int GetElementInt(std::initializer_list<const char *> path,
94  bool isRequired = true);
95  double GetElementDouble(std::initializer_list<const char *> path,
96  bool isRequired = true);
97 
98 private:
100  xml_main_file_name = "";
101  xml_main_file_open = false;
102  xml_user_file_name = "";
103  xml_user_file_open = false;
104  };
106  static JetScapeXML *m_pInstance;
107 
108  // Main file
109 
111  xml_root_main; //use unique pointer here instead of raw pointer (check with tinyxml interface)
113 
116 
117  // User file
118 
120  xml_root_user; //use unique pointer here instead of raw pointer (check with tinyxml interface)
122 
125 };
126 
127 // Print the XML element path name
128 std::ostream &operator<<(std::ostream &os,
129  std::initializer_list<const char *> path);
130 
131 } // end namespace Jetscape
132 
133 #endif