Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:19

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 // Jetscape final state {hadrons,kartons} writer ascii class
0017 // Based on JetScapeWriterStream.
0018 // author: Raymond Ehlers <raymond.ehlers@cern.ch>, ORNL
0019 
0020 #ifndef JETSCAPEWRITERSTREAM_H
0021 #define JETSCAPEWRITERSTREAM_H
0022 
0023 #include <fstream>
0024 #include <string>
0025 
0026 #ifdef USE_GZIP
0027 #include "gzstream.h"
0028 #endif
0029 
0030 #include "JetScapeWriter.h"
0031 
0032 using std::ofstream;
0033 
0034 namespace Jetscape {
0035 
0036 template <class T>
0037 class JetScapeWriterFinalStateStream : public JetScapeWriter {
0038 
0039 public:
0040   JetScapeWriterFinalStateStream<T>(){};
0041   JetScapeWriterFinalStateStream<T>(string m_file_name_out);
0042   virtual ~JetScapeWriterFinalStateStream<T>();
0043 
0044   void Init();
0045   void Exec();
0046 
0047   virtual std::string GetName() { throw std::runtime_error("Don't use the base class"); }
0048   bool GetStatus() { return output_file.good(); }
0049   // Close is utilized to add the xsec and error.
0050   void Close();
0051 
0052   void Write(weak_ptr<PartonShower> ps);
0053   void Write(weak_ptr<Hadron> h);
0054   // We aren't interested in the individual partons or vertices, so skip them.
0055 
0056   void WriteHeaderToFile() { };
0057   void WriteEvent();
0058 
0059   void Write(string s) { output_file << s << endl; }
0060   // Intentionally make these no-ops since we want to fully control our output from this
0061   // class. Tasks will often directly call these functions, so we need to prevent them from doing so.
0062   void WriteComment(string s) { }
0063   void WriteWhiteSpace(string s) { }
0064 
0065 protected:
0066   T output_file; //!< Output file
0067   std::vector<std::shared_ptr<JetScapeParticleBase>> particles;
0068 };
0069 
0070 template <class T>
0071 class JetScapeWriterFinalStatePartonsStream : public JetScapeWriterFinalStateStream<T> {
0072   std::string GetName() { return "partons"; }
0073   // Don't collect the hadrons by making it a no-op
0074   void Write(weak_ptr<Hadron> h) { }
0075 protected:
0076   // Allows the registration of the module so that it is available to be used by the Jetscape framework.
0077   static RegisterJetScapeModule<JetScapeWriterFinalStatePartonsStream<ofstream>> regParton;
0078   static RegisterJetScapeModule<JetScapeWriterFinalStatePartonsStream<ogzstream>> regPartonGZ;
0079 };
0080 
0081 template <class T>
0082 class JetScapeWriterFinalStateHadronsStream : public JetScapeWriterFinalStateStream<T> {
0083   std::string GetName() { return "hadrons"; }
0084   // Don't collect the hadrons by making it a no-op
0085   void Write(weak_ptr<PartonShower> ps) { }
0086 protected:
0087   // Allows the registration of the module so that it is available to be used by the Jetscape framework.
0088   static RegisterJetScapeModule<JetScapeWriterFinalStateHadronsStream<ofstream>> regHadron;
0089   static RegisterJetScapeModule<JetScapeWriterFinalStateHadronsStream<ogzstream>> regHadronGZ;
0090 };
0091 
0092 typedef JetScapeWriterFinalStatePartonsStream<ofstream> JetScapeWriterFinalStatePartonsAscii;
0093 typedef JetScapeWriterFinalStateHadronsStream<ofstream> JetScapeWriterFinalStateHadronsAscii;
0094 #ifdef USE_GZIP
0095 typedef JetScapeWriterFinalStatePartonsStream<ogzstream> JetScapeWriterFinalStatePartonsAsciiGZ;
0096 typedef JetScapeWriterFinalStateHadronsStream<ogzstream> JetScapeWriterFinalStateHadronsAsciiGZ;
0097 #endif
0098 
0099 } // end namespace Jetscape
0100 
0101 #endif // JETSCAPEWRITERSTREAM_H