Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetScapeWriterStream.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetScapeWriterStream.cc
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 // jetscape writer ascii class
16 
17 #include "JetScapeWriterStream.h"
18 #include "JetScapeLogger.h"
19 #include "JetScapeXML.h"
20 
21 namespace Jetscape {
22 
23 // Register the modules with the base class
24 template <>
25 RegisterJetScapeModule<JetScapeWriterStream<ofstream>>
26  JetScapeWriterStream<ofstream>::reg("JetScapeWriterAscii");
27 template <>
28 RegisterJetScapeModule<JetScapeWriterStream<ogzstream>>
29  JetScapeWriterStream<ogzstream>::regGZ("JetScapeWriterAsciiGZ");
30 
31 template <class T>
33  SetOutputFileName(m_file_name_out);
34 }
35 
37  VERBOSE(8);
38  if (GetActive())
39  Close();
40 }
41 
42 template <class T> void JetScapeWriterStream<T>::WriteHeaderToFile() {
43  VERBOSE(3) << "Run JetScapeWriterStream<T>: Write header of event # "
44  << GetCurrentEvent() << " ...";
45  Write(to_string(GetCurrentEvent()) + " Event");
46 
47  std::ostringstream oss;
48  oss.str("");
49  oss << GetId() << "sigmaGen " << GetHeader().GetSigmaGen();
50  WriteComment(oss.str());
51  oss.str("");
52  oss << GetId() << "sigmaErr " << GetHeader().GetSigmaErr();
53  WriteComment(oss.str());
54  oss.str("");
55  oss << GetId() << "weight " << GetHeader().GetEventWeight();
56  WriteComment(oss.str());
57 
58  if (GetHeader().GetNpart() > -1) {
59  oss.str("");
60  oss << GetId() << "Npart " << GetHeader().GetNpart();
61  WriteComment(oss.str());
62  }
63  if (GetHeader().GetNcoll() > -1) {
64  oss.str("");
65  oss << GetId() << "Ncoll " << GetHeader().GetNcoll();
66  WriteComment(oss.str());
67  }
68  if (GetHeader().GetTotalEntropy() > -1) {
69  oss.str("");
70  oss << GetId() << "TotalEntropy " << GetHeader().GetTotalEntropy();
71  WriteComment(oss.str());
72  }
73 
74  if (GetHeader().GetEventPlaneAngle() > -999) {
75  oss.str("");
76  oss << GetId() << "EventPlaneAngle " << GetHeader().GetEventPlaneAngle();
77  WriteComment(oss.str());
78  }
79 }
80 
81 template <class T> void JetScapeWriterStream<T>::WriteEvent() {
82  // JSINFO<<"Run JetScapeWriterStream<T>: Write event # "<<GetCurrentEvent()<<" ...";
83  // do nothing, the modules handle this
84 }
85 
86 template <class T> void JetScapeWriterStream<T>::Write(weak_ptr<Parton> p) {
87  auto pp = p.lock();
88  if (pp) {
89  output_file << *pp << endl;
90  }
91 }
92 
93 template <class T> void JetScapeWriterStream<T>::Write(weak_ptr<Vertex> v) {
94  auto vv = v.lock();
95  if (vv) {
96  output_file << *vv << endl;
97  }
98 }
99 
100 template <class T> void JetScapeWriterStream<T>::Init() {
101  if (GetActive()) {
102  JSINFO << "JetScape Stream Writer initialized with output file = "
103  << GetOutputFileName();
104  output_file.open(GetOutputFileName().c_str());
105 
106  //Write Init Informations, like XML and ... to file ...
107  //WriteInitFileXMLMain();
108  //WriteInitFileXMLUser();
109  }
110 }
111 
112 template <class T> void JetScapeWriterStream<T>::Exec() {
113  // JSINFO<<"Run JetScapeWriterStream<T>: Write event # "<<GetCurrentEvent()<<" ...";
114 
115  // if (GetActive())
116  // WriteEvent();
117 }
118 
120  JSDEBUG << "Write XML Main to output file. XML file = "
122  tinyxml2::XMLPrinter printer;
124  WriteComment("Init XML Main file used : " +
125  JetScapeXML::Instance()->GetXMLMainFileName());
126  output_file << printer.CStr();
127 }
128 
130  JSDEBUG << "Write XML User to output file. XML file = "
132  tinyxml2::XMLPrinter printer;
134  WriteComment("Init XML User file used : " +
135  JetScapeXML::Instance()->GetXMLUserFileName());
136  output_file << printer.CStr();
137 }
138 
139 template <class T>
140 void JetScapeWriterStream<T>::Write(weak_ptr<PartonShower> ps) {
141  auto pShower = ps.lock();
142  if (!pShower)
143  return;
144 
145  WriteComment(
146  "Parton Shower in JetScape format to be used later by GTL graph:");
147 
148  // write vertices
149  PartonShower::node_iterator nIt, nEnd;
150 
151  for (nIt = pShower->nodes_begin(), nEnd = pShower->nodes_end(); nIt != nEnd;
152  ++nIt) {
153  WriteWhiteSpace("[" + to_string(nIt->id()) + "] V");
154  Write(pShower->GetVertex(*nIt));
155  }
156 
157  PartonShower::edge_iterator eIt, eEnd;
158  for (eIt = pShower->edges_begin(), eEnd = pShower->edges_end(); eIt != eEnd;
159  ++eIt) {
160  WriteWhiteSpace("[" + to_string(eIt->source().id()) + "]=>[" +
161  to_string(eIt->target().id()) + "] P");
162  Write(pShower->GetParton(*eIt));
163  }
164 }
165 
166 template <class T> void JetScapeWriterStream<T>::Write(weak_ptr<Hadron> h) {
167  auto hh = h.lock();
168  if (hh) {
169  output_file << *hh << endl;
170  }
171 }
172 
173 template class JetScapeWriterStream<ofstream>;
174 
175 #ifdef USE_GZIP
176 template class JetScapeWriterStream<ogzstream>;
177 #endif
178 
179 } // end namespace Jetscape