Version: SMASH-3.0
binaryoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022
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 <memory>
14 #include <string>
15 
16 #include "file.h"
17 #include "forwarddeclarations.h"
18 #include "numeric_cast.h"
19 #include "outputinterface.h"
20 #include "outputparameters.h"
21 
22 namespace smash {
23 
29  protected:
38  explicit BinaryOutputBase(const std::filesystem::path &path,
39  const std::string &mode, const std::string &name,
40  bool extended_format);
41 
46  void write(const char c);
47 
52  void write(const std::string &s);
53 
58  void write(const double x);
59 
64  void write(const FourVector &v);
65 
70  void write(const std::int32_t x) {
71  std::fwrite(&x, sizeof(x), 1, file_.get());
72  }
73 
78  void write(const std::uint32_t x) {
79  std::fwrite(&x, sizeof(x), 1, file_.get());
80  }
81 
86  void write(const std::uint16_t x) {
87  std::fwrite(&x, sizeof(x), 1, file_.get());
88  }
89 
94  void write(const size_t x) { write(smash::numeric_cast<uint32_t>(x)); }
95 
100  void write(const Particles &particles);
101 
106  void write(const ParticleList &particles);
107 
112  void write_particledata(const ParticleData &p);
113 
116 
117  private:
119  const uint16_t format_version_ = 8;
121  bool extended_;
122 };
123 
137  public:
145  BinaryOutputCollisions(const std::filesystem::path &path, std::string name,
146  const OutputParameters &out_par);
147 
155  void at_eventstart(const Particles &particles, const int event_number,
156  const EventInfo &event) override;
157 
165  void at_eventend(const Particles &particles, const int32_t event_number,
166  const EventInfo &event) override;
167 
174  void at_interaction(const Action &action, const double density) override;
175 
176  private:
179 };
180 
197  public:
205  BinaryOutputParticles(const std::filesystem::path &path, std::string name,
206  const OutputParameters &out_par);
207 
214  void at_eventstart(const Particles &particles, const int event_number,
215  const EventInfo &event) override;
216 
223  void at_eventend(const Particles &particles, const int event_number,
224  const EventInfo &event) override;
225 
233  void at_intermediate_time(const Particles &particles,
234  const std::unique_ptr<Clock> &clock,
235  const DensityParameters &dens_param,
236  const EventInfo &event) override;
237 
238  private:
241 };
242 
257  public:
265  BinaryOutputInitialConditions(const std::filesystem::path &path,
266  std::string name,
267  const OutputParameters &out_par);
268 
273  void at_eventstart(const Particles &, const int, const EventInfo &) override;
274 
281  void at_eventend(const Particles &particles, const int event_number,
282  const EventInfo &event) override;
283 
290  void at_interaction(const Action &action, const double) override;
291 };
292 
293 } // namespace smash
294 
295 #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:28
void write(const std::uint16_t x)
Write unsigned integer (16 bit) to binary output.
Definition: binaryoutput.h:86
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:121
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:119
RenamingFilePtr file_
Binary particles output file path.
Definition: binaryoutput.h:115
void write(const std::int32_t x)
Write integer (32 bit) to binary output.
Definition: binaryoutput.h:70
void write(const size_t x)
Write a std::size_t to binary output.
Definition: binaryoutput.h:94
void write(const std::uint32_t x)
Write unsigned integer (32 bit) to binary output.
Definition: binaryoutput.h:78
Saves SMASH collision history to binary file.
Definition: binaryoutput.h:136
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:178
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:256
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:196
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:240
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.