Version: SMASH-3.1
binaryoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022-2024
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_BINARYOUTPUT_H_
11 #define SRC_INCLUDE_SMASH_BINARYOUTPUT_H_
12 
13 #include <cstdint>
14 #include <memory>
15 #include <string>
16 
17 #include "file.h"
18 #include "forwarddeclarations.h"
19 #include "numeric_cast.h"
20 #include "outputinterface.h"
21 #include "outputparameters.h"
22 
23 namespace smash {
24 
30  protected:
39  explicit BinaryOutputBase(const std::filesystem::path &path,
40  const std::string &mode, const std::string &name,
41  bool extended_format);
42 
47  void write(const char c);
48 
53  void write(const std::string &s);
54 
59  void write(const double x);
60 
65  void write(const FourVector &v);
66 
71  void write(const std::int32_t x) {
72  std::fwrite(&x, sizeof(x), 1, file_.get());
73  }
74 
79  void write(const std::uint32_t x) {
80  std::fwrite(&x, sizeof(x), 1, file_.get());
81  }
82 
87  void write(const std::uint16_t x) {
88  std::fwrite(&x, sizeof(x), 1, file_.get());
89  }
90 
95  void write(const size_t x) { write(smash::numeric_cast<uint32_t>(x)); }
96 
101  void write(const Particles &particles);
102 
107  void write(const ParticleList &particles);
108 
113  void write_particledata(const ParticleData &p);
114 
117 
118  private:
120  const uint16_t format_version_ = 9;
122  bool extended_;
123 };
124 
138  public:
146  BinaryOutputCollisions(const std::filesystem::path &path, std::string name,
147  const OutputParameters &out_par);
148 
156  void at_eventstart(const Particles &particles, const int event_number,
157  const EventInfo &event) override;
158 
166  void at_eventend(const Particles &particles, const int32_t event_number,
167  const EventInfo &event) override;
168 
175  void at_interaction(const Action &action, const double density) override;
176 
177  private:
180 };
181 
198  public:
206  BinaryOutputParticles(const std::filesystem::path &path, std::string name,
207  const OutputParameters &out_par);
208 
215  void at_eventstart(const Particles &particles, const int event_number,
216  const EventInfo &event) override;
217 
224  void at_eventend(const Particles &particles, const int event_number,
225  const EventInfo &event) override;
226 
234  void at_intermediate_time(const Particles &particles,
235  const std::unique_ptr<Clock> &clock,
236  const DensityParameters &dens_param,
237  const EventInfo &event) override;
238 
239  private:
242 };
243 
258  public:
266  BinaryOutputInitialConditions(const std::filesystem::path &path,
267  std::string name,
268  const OutputParameters &out_par);
269 
274  void at_eventstart(const Particles &, const int, const EventInfo &) override;
275 
282  void at_eventend(const Particles &particles, const int event_number,
283  const EventInfo &event) override;
284 
291  void at_interaction(const Action &action, const double) override;
292 };
293 
294 } // namespace smash
295 
296 #endif // SRC_INCLUDE_SMASH_BINARYOUTPUT_H_
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
Base class for SMASH binary output.
Definition: binaryoutput.h:29
void write(const std::uint16_t x)
Write unsigned integer (16 bit) to binary output.
Definition: binaryoutput.h:87
BinaryOutputBase(const std::filesystem::path &path, const std::string &mode, const std::string &name, bool extended_format)
Create binary output base.
bool extended_
Option for extended output.
Definition: binaryoutput.h:122
void write(const char c)
Write byte to binary output.
void write_particledata(const ParticleData &p)
Write particle data to binary output.
const uint16_t format_version_
Binary file format version number.
Definition: binaryoutput.h:120
RenamingFilePtr file_
Binary particles output file path.
Definition: binaryoutput.h:116
void write(const std::int32_t x)
Write integer (32 bit) to binary output.
Definition: binaryoutput.h:71
void write(const size_t x)
Write a std::size_t to binary output.
Definition: binaryoutput.h:95
void write(const std::uint32_t x)
Write unsigned integer (32 bit) to binary output.
Definition: binaryoutput.h:79
Saves SMASH collision history to binary file.
Definition: binaryoutput.h:137
void at_interaction(const Action &action, const double density) override
Writes an interaction block, including information about the incoming and outgoing particles,...
void at_eventstart(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the initial particle information list of an event to the binary output.
bool print_start_end_
Write initial and final particles additonally to collisions?
Definition: binaryoutput.h:179
void at_eventend(const Particles &particles, const int32_t event_number, const EventInfo &event) override
Writes the final particle information list of an event to the binary output.
BinaryOutputCollisions(const std::filesystem::path &path, std::string name, const OutputParameters &out_par)
Create binary particle output.
Writes the particles when crossing the hypersurface to the binary file.
Definition: binaryoutput.h:257
void at_eventstart(const Particles &, const int, const EventInfo &) override
Writes the initial particle information of an event to the binary output.
void at_interaction(const Action &action, const double) override
Writes particles that are removed when crossing the hypersurface to the output.
void at_eventend(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the final particle information of an event to the binary output.
BinaryOutputInitialConditions(const std::filesystem::path &path, std::string name, const OutputParameters &out_par)
Create binary initial conditions particle output.
Writes the particle list at specific times to the binary file.
Definition: binaryoutput.h:197
void at_eventstart(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the initial particle information of an event to the binary output.
OutputOnlyFinal only_final_
Whether final- or initial-state particles should be written.
Definition: binaryoutput.h:241
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &event) override
Writes particles at each time interval; fixed by option OUTPUT_INTERVAL.
BinaryOutputParticles(const std::filesystem::path &path, std::string name, const OutputParameters &out_par)
Create binary particle output.
void at_eventend(const Particles &particles, const int event_number, const EventInfo &event) override
Writes the final particle information of an event to the binary output.
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:108
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Definition: fourvector.h:33
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:58
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
A RAII type to replace std::FILE *.
Definition: file.h:72
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27
OutputOnlyFinal
Whether and when only final state particles should be printed.
constexpr int p
Proton.
Definition: action.h:24
Structure to contain custom data for output.
Helper structure for Experiment to hold output options and parameters.