Version: SMASH-1.8
binaryoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_BINARYOUTPUT_H_
11 #define SRC_INCLUDE_BINARYOUTPUT_H_
12 
13 #include <string>
14 
15 #include <boost/numeric/conversion/cast.hpp>
16 
17 #include "file.h"
18 #include "forwarddeclarations.h"
19 #include "outputinterface.h"
20 #include "outputparameters.h"
21 
22 namespace smash {
23 
29  protected:
38  explicit BinaryOutputBase(const bf::path &path, const std::string &mode,
39  const std::string &name, bool extended_format);
40 
45  void write(const char c);
46 
51  void write(const std::string &s);
52 
57  void write(const double x);
58 
63  void write(const FourVector &v);
64 
69  void write(const std::int32_t x) {
70  std::fwrite(&x, sizeof(x), 1, file_.get());
71  }
72 
77  void write(const std::uint32_t x) {
78  std::fwrite(&x, sizeof(x), 1, file_.get());
79  }
80 
85  void write(const std::uint16_t x) {
86  std::fwrite(&x, sizeof(x), 1, file_.get());
87  }
88 
93  void write(const size_t x) { write(boost::numeric_cast<uint32_t>(x)); }
94 
99  void write(const Particles &particles);
100 
105  void write(const ParticleList &particles);
106 
111  void write_particledata(const ParticleData &p);
112 
115 
116  private:
118  const uint16_t format_version_ = 7;
120  bool extended_;
121 };
122 
136  public:
144  BinaryOutputCollisions(const bf::path &path, std::string name,
145  const OutputParameters &out_par);
146 
153  void at_eventstart(const Particles &particles,
154  const int event_number) override;
155 
165  void at_eventend(const Particles &particles, const int32_t event_number,
166  double impact_parameter, bool empty_event) override;
167 
174  void at_interaction(const Action &action, const double density) override;
175 
176  private:
179 };
180 
197  public:
205  BinaryOutputParticles(const bf::path &path, std::string name,
206  const OutputParameters &out_par);
207 
213  void at_eventstart(const Particles &particles,
214  const int event_number) override;
215 
224  void at_eventend(const Particles &particles, const int event_number,
225  double impact_parameter, bool empty_event) override;
226 
233  void at_intermediate_time(const Particles &particles,
234  const std::unique_ptr<Clock> &clock,
235  const DensityParameters &dens_param) override;
236 
237  private:
240 };
241 
256  public:
264  BinaryOutputInitialConditions(const bf::path &path, std::string name,
265  const OutputParameters &out_par);
266 
271  void at_eventstart(const Particles &, const int) override;
272 
281  void at_eventend(const Particles &particles, const int event_number,
282  double impact_parameter, bool empty_event) override;
283 
290  void at_interaction(const Action &action, const double) override;
291 };
292 
293 } // namespace smash
294 
295 #endif // SRC_INCLUDE_BINARYOUTPUT_H_
smash
Definition: action.h:24
outputparameters.h
smash::BinaryOutputBase::extended_
bool extended_
Option for extended output.
Definition: binaryoutput.h:120
smash::BinaryOutputCollisions::at_eventstart
void at_eventstart(const Particles &particles, const int event_number) override
Writes the initial particle information list of an event to the binary output.
Definition: binaryoutput.cc:207
smash::DensityParameters
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:107
smash::BinaryOutputParticles::only_final_
OutputOnlyFinal only_final_
Whether final- or initial-state particles should be written.
Definition: binaryoutput.h:239
OutputOnlyFinal
OutputOnlyFinal
Whether and when only final state particles should be printed.
Definition: forwarddeclarations.h:200
smash::ParticleData
Definition: particledata.h:52
smash::BinaryOutputParticles::at_eventend
void at_eventend(const Particles &particles, const int event_number, double impact_parameter, bool empty_event) override
Writes the final particle information of an event to the binary output.
Definition: binaryoutput.cc:274
smash::BinaryOutputBase::write
void write(const std::uint16_t x)
Write unsigned integer (16 bit) to binary output.
Definition: binaryoutput.h:85
smash::BinaryOutputBase::write
void write(const size_t x)
Write a std::size_t to binary output.
Definition: binaryoutput.h:93
smash::BinaryOutputInitialConditions::at_eventend
void at_eventend(const Particles &particles, const int event_number, double impact_parameter, bool empty_event) override
Writes the final particle information of an event to the binary output.
Definition: binaryoutput.cc:316
smash::BinaryOutputBase::BinaryOutputBase
BinaryOutputBase(const bf::path &path, const std::string &mode, const std::string &name, bool extended_format)
Create binary output base.
Definition: binaryoutput.cc:135
smash::RenamingFilePtr::get
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
smash::BinaryOutputBase::write
void write(const std::uint32_t x)
Write unsigned integer (32 bit) to binary output.
Definition: binaryoutput.h:77
smash::BinaryOutputParticles
Writes the particle list at specific times to the binary file.
Definition: binaryoutput.h:196
forwarddeclarations.h
outputinterface.h
smash::OutputParameters
Helper structure for Experiment to hold output options and parameters.
Definition: outputparameters.h:25
smash::BinaryOutputBase::file_
RenamingFilePtr file_
Binary particles output file path.
Definition: binaryoutput.h:114
smash::BinaryOutputBase::write_particledata
void write_particledata(const ParticleData &p)
Write particle data to binary output.
Definition: binaryoutput.cc:178
smash::OutputInterface
Abstraction of generic output.
Definition: outputinterface.h:35
smash::BinaryOutputBase::write
void write(const char c)
Write byte to binary output.
Definition: binaryoutput.cc:148
smash::BinaryOutputBase::format_version_
const uint16_t format_version_
Binary file format version number.
Definition: binaryoutput.h:118
smash::BinaryOutputInitialConditions::at_interaction
void at_interaction(const Action &action, const double) override
Writes particles that are removed when crossing the hypersurface to the output.
Definition: binaryoutput.cc:341
smash::BinaryOutputCollisions::at_interaction
void at_interaction(const Action &action, const double density) override
Writes an interaction block, including information about the incoming and outgoing particles,...
Definition: binaryoutput.cc:240
smash::BinaryOutputCollisions::print_start_end_
bool print_start_end_
Write initial and final particles additonally to collisions?
Definition: binaryoutput.h:178
smash::Particles
Definition: particles.h:33
smash::Action
Definition: action.h:35
smash::RenamingFilePtr
A RAII type to replace std::FILE *.
Definition: file.h:73
smash::BinaryOutputBase::write
void write(const std::int32_t x)
Write integer (32 bit) to binary output.
Definition: binaryoutput.h:69
smash::BinaryOutputCollisions
Saves SMASH collision history to binary file.
Definition: binaryoutput.h:135
smash::FourVector
Definition: fourvector.h:33
smash::pdg::p
constexpr int p
Proton.
Definition: pdgcode_constants.h:28
file.h
smash::BinaryOutputInitialConditions::BinaryOutputInitialConditions
BinaryOutputInitialConditions(const bf::path &path, std::string name, const OutputParameters &out_par)
Create binary initial conditions particle output.
Definition: binaryoutput.cc:308
smash::BinaryOutputParticles::BinaryOutputParticles
BinaryOutputParticles(const bf::path &path, std::string name, const OutputParameters &out_par)
Create binary particle output.
Definition: binaryoutput.cc:257
smash::BinaryOutputCollisions::at_eventend
void at_eventend(const Particles &particles, const int32_t event_number, double impact_parameter, bool empty_event) override
Writes the final particle information list of an event to the binary output.
Definition: binaryoutput.cc:217
smash::BinaryOutputParticles::at_eventstart
void at_eventstart(const Particles &particles, const int event_number) override
Writes the initial particle information of an event to the binary output.
Definition: binaryoutput.cc:264
smash::BinaryOutputInitialConditions::at_eventstart
void at_eventstart(const Particles &, const int) override
Writes the initial particle information of an event to the binary output.
Definition: binaryoutput.cc:313
smash::BinaryOutputCollisions::BinaryOutputCollisions
BinaryOutputCollisions(const bf::path &path, std::string name, const OutputParameters &out_par)
Create binary particle output.
Definition: binaryoutput.cc:199
smash::BinaryOutputInitialConditions
Writes the particles when crossing the hypersurface to the binary file.
Definition: binaryoutput.h:255
smash::BinaryOutputBase
Definition: binaryoutput.h:28
smash::BinaryOutputParticles::at_intermediate_time
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param) override
Writes particles at each time interval; fixed by option OUTPUT_INTERVAL.
Definition: binaryoutput.cc:297