Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetScapeModuleBase.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetScapeModuleBase.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 JETSCAPEMODULEBASE_H
17 #define JETSCAPEMODULEBASE_H
18 
19 #include <string>
20 #include <memory>
21 #include <random>
22 #include <map>
23 
24 #include "JetScapeTask.h"
25 #include "JetScapeXML.h"
26 #include "sigslot.h"
27 
28 namespace Jetscape {
29 
30 class JetScapeWriter;
31 
33  : public JetScapeTask,
34  public sigslot::has_slots<sigslot::multi_threaded_local> {
35 
36 public:
40 
43  JetScapeModuleBase(string m_name);
44 
47  virtual ~JetScapeModuleBase();
48 
49  //virtual shared_ptr<JetScapeModuleBase> Clone() const {return nullptr;}
52  virtual void Init();
53 
56  virtual void Exec(){};
57 
60  virtual void Clear(){};
61 
64  void SetXMLMainFileName(string m_name) { xml_main_file_name = m_name; }
65 
69 
72  void SetXMLUserFileName(string m_name) { xml_user_file_name = m_name; }
73 
77 
80  static int GetCurrentEvent() { return current_event; }
81 
84  static void IncrementCurrentEvent() { current_event++; }
85 
89 
92  tinyxml2::XMLElement *GetXMLElement(std::initializer_list<const char *> path,
93  bool isRequired = true) {
94  return JetScapeXML::Instance()->GetElement(path, isRequired);
95  }
96  std::string GetXMLElementText(std::initializer_list<const char *> path,
97  bool isRequired = true) {
98  return JetScapeXML::Instance()->GetElementText(path, isRequired);
99  }
100  int GetXMLElementInt(std::initializer_list<const char *> path,
101  bool isRequired = true) {
102  return JetScapeXML::Instance()->GetElementInt(path, isRequired);
103  }
104  double GetXMLElementDouble(std::initializer_list<const char *> path,
105  bool isRequired = true) {
106  return JetScapeXML::Instance()->GetElementDouble(path, isRequired);
107  }
108 
109 private:
112  static int current_event;
114 };
115 
129 
130 template <typename T> shared_ptr<JetScapeModuleBase> createT() {
131  return std::make_shared<T>();
132 }
133 
134 // Factory to create and keep track of new modules
136 public:
138 
139  typedef std::map<std::string, shared_ptr<JetScapeModuleBase> (*)()> map_type;
140 
142  static shared_ptr<JetScapeModuleBase> createInstance(std::string const &s) {
143  map_type::iterator it = getMap()->find(s);
144  if (it == getMap()->end()) {
145  return 0;
146  }
147  return it->second();
148  }
149 
150 protected:
152  static map_type *getMap() {
153  // We never delete the map (until program termination) because we cannot guarantee correct destruction order
154  if (!moduleMap) {
155  moduleMap = new map_type;
156  }
157  return moduleMap;
158  }
159 
160 private:
163 };
164 
169 template <typename T>
171 public:
174  //std::cout << "Registering " << s << " to the map" << std::endl;
175  getMap()->insert(std::make_pair(s, &createT<T>));
176  }
177 };
178 
179 } // end namespace Jetscape
180 
181 #endif