Version: SMASH-3.0
smash::BinaryOutputBase Class Reference

#include <binaryoutput.h>

Base class for SMASH binary output.

Definition at line 28 of file binaryoutput.h.

Inheritance diagram for smash::BinaryOutputBase:
smash::OutputInterface smash::BinaryOutputCollisions smash::BinaryOutputInitialConditions smash::BinaryOutputParticles

Protected Member Functions

 BinaryOutputBase (const std::filesystem::path &path, const std::string &mode, const std::string &name, bool extended_format)
 Create binary output base. More...
 
void write (const char c)
 Write byte to binary output. More...
 
void write (const std::string &s)
 Write string to binary output. More...
 
void write (const double x)
 Write double to binary output. More...
 
void write (const FourVector &v)
 Write four-vector to binary output. More...
 
void write (const std::int32_t x)
 Write integer (32 bit) to binary output. More...
 
void write (const std::uint32_t x)
 Write unsigned integer (32 bit) to binary output. More...
 
void write (const std::uint16_t x)
 Write unsigned integer (16 bit) to binary output. More...
 
void write (const size_t x)
 Write a std::size_t to binary output. More...
 
void write (const Particles &particles)
 Write particle data of each particle in particles to binary output. More...
 
void write (const ParticleList &particles)
 Write each particle data entry to binary output. More...
 
void write_particledata (const ParticleData &p)
 Write particle data to binary output. More...
 

Protected Attributes

RenamingFilePtr file_
 Binary particles output file path. More...
 
- Protected Attributes inherited from smash::OutputInterface
const bool is_dilepton_output_
 Is this the dilepton output? More...
 
const bool is_photon_output_
 Is this the photon output? More...
 
const bool is_IC_output_
 Is this the IC output? More...
 

Private Attributes

const uint16_t format_version_ = 8
 Binary file format version number. More...
 
bool extended_
 Option for extended output. More...
 

Additional Inherited Members

- Public Member Functions inherited from smash::OutputInterface
 OutputInterface (std::string name)
 Construct output interface. More...
 
virtual ~OutputInterface ()=default
 
virtual void at_eventstart (const Particles &particles, const int event_number, const EventInfo &info)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const std::vector< Particles > &ensembles, int event_number)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, RectangularLattice< DensityOnLattice > lattice)
 Output launched at event start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventstart (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type, RectangularLattice< EnergyMomentumTensor > lattice)
 Output launched atevent start after initialization, when particles are generated but not yet propagated. More...
 
virtual void at_eventend (const int event_number, const ThermodynamicQuantity tq, const DensityType dens_type)
 Output launched at event end. More...
 
virtual void at_eventend (const ThermodynamicQuantity tq)
 Output launched at event end. More...
 
virtual void at_eventend (const Particles &particles, const int event_number, const EventInfo &info)
 Output launched at event end. More...
 
virtual void at_eventend (const std::vector< Particles > &ensembles, const int event_number)
 Output launched at event end. More...
 
virtual void at_interaction (const Action &action, const double density)
 Called whenever an action modified one or more particles. More...
 
virtual void at_intermediate_time (const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventInfo &info)
 Output launched after every N'th timestep. More...
 
virtual void at_intermediate_time (const std::vector< Particles > &ensembles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param)
 Output launched after every N'th timestep. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< DensityOnLattice > &lattice)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_output (const ThermodynamicQuantity tq, const DensityType dt, RectangularLattice< EnergyMomentumTensor > &lattice)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &lattice, const double current_time)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (RectangularLattice< DensityOnLattice > &lattice, const double current_time, const std::vector< Particles > &ensembles, const DensityParameters &dens_param)
 Output to write thermodynamics from the lattice. More...
 
virtual void thermodynamics_lattice_output (const ThermodynamicQuantity tq, RectangularLattice< EnergyMomentumTensor > &lattice, const double current_time)
 Output to write energy-momentum tensor and related quantities from the lattice. More...
 
virtual void thermodynamics_output (const GrandCanThermalizer &gct)
 Output to write energy-momentum tensor and related quantities from the thermalizer class. More...
 
virtual void fields_output (const std::string name1, const std::string name2, RectangularLattice< std::pair< ThreeVector, ThreeVector >> &lat)
 Write fields in vtk output. More...
 
bool is_dilepton_output () const
 Get, whether this is the dilepton output? More...
 
bool is_photon_output () const
 Get, whether this is the photon output? More...
 
bool is_IC_output () const
 Get, whether this is the IC output? More...
 
const char * to_string (const ThermodynamicQuantity tq)
 Convert thermodynamic quantities to strings. More...
 
const char * to_string (const DensityType dens_type)
 Convert density types to strings. More...
 

Constructor & Destructor Documentation

◆ BinaryOutputBase()

smash::BinaryOutputBase::BinaryOutputBase ( const std::filesystem::path &  path,
const std::string &  mode,
const std::string &  name,
bool  extended_format 
)
explicitprotected

Create binary output base.

Parameters
[in]pathOutput path.
[in]modeIs used to determine the file access mode.
[in]nameName of the output.
[in]extended_formatIs the written output extended.

Definition at line 135 of file binaryoutput.cc.

139  : OutputInterface(name), file_{path, mode}, extended_(extended_format) {
140  std::fwrite("SMSH", 4, 1, file_.get()); // magic number
141  write(format_version_); // file format version number
142  std::uint16_t format_variant = static_cast<uint16_t>(extended_);
143  write(format_variant);
144  write(SMASH_VERSION);
145 }
bool extended_
Option for extended output.
Definition: binaryoutput.h:121
void write(const char c)
Write byte 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
OutputInterface(std::string name)
Construct output interface.
FILE * get()
Get the underlying FILE* pointer.
Definition: file.cc:27

Member Function Documentation

◆ write() [1/10]

void smash::BinaryOutputBase::write ( const char  c)
protected

Write byte to binary output.

Parameters
[in]cValue to be written.

Definition at line 148 of file binaryoutput.cc.

148  {
149  std::fwrite(&c, sizeof(char), 1, file_.get());
150 }

◆ write() [2/10]

void smash::BinaryOutputBase::write ( const std::string &  s)
protected

Write string to binary output.

Parameters
[in]sString to be written.

Definition at line 152 of file binaryoutput.cc.

152  {
153  const auto size = smash::numeric_cast<uint32_t>(s.size());
154  std::fwrite(&size, sizeof(std::uint32_t), 1, file_.get());
155  std::fwrite(s.c_str(), s.size(), 1, file_.get());
156 }

◆ write() [3/10]

void smash::BinaryOutputBase::write ( const double  x)
protected

Write double to binary output.

Parameters
[in]xValue to be written.

Definition at line 158 of file binaryoutput.cc.

158  {
159  std::fwrite(&x, sizeof(x), 1, file_.get());
160 }

◆ write() [4/10]

void smash::BinaryOutputBase::write ( const FourVector v)
protected

Write four-vector to binary output.

Parameters
[in]vFour-vector to be written.

Definition at line 162 of file binaryoutput.cc.

162  {
163  std::fwrite(v.begin(), sizeof(*v.begin()), 4, file_.get());
164 }

◆ write() [5/10]

void smash::BinaryOutputBase::write ( const std::int32_t  x)
inlineprotected

Write integer (32 bit) to binary output.

Parameters
[in]xValue to be written.

Definition at line 70 of file binaryoutput.h.

70  {
71  std::fwrite(&x, sizeof(x), 1, file_.get());
72  }

◆ write() [6/10]

void smash::BinaryOutputBase::write ( const std::uint32_t  x)
inlineprotected

Write unsigned integer (32 bit) to binary output.

Parameters
[in]xValue to be written.

Definition at line 78 of file binaryoutput.h.

78  {
79  std::fwrite(&x, sizeof(x), 1, file_.get());
80  }

◆ write() [7/10]

void smash::BinaryOutputBase::write ( const std::uint16_t  x)
inlineprotected

Write unsigned integer (16 bit) to binary output.

Parameters
[in]xValue to be written.

Definition at line 86 of file binaryoutput.h.

86  {
87  std::fwrite(&x, sizeof(x), 1, file_.get());
88  }

◆ write() [8/10]

void smash::BinaryOutputBase::write ( const size_t  x)
inlineprotected

Write a std::size_t to binary output.

Parameters
[in]xValue to be written.

Definition at line 94 of file binaryoutput.h.

94 { write(smash::numeric_cast<uint32_t>(x)); }

◆ write() [9/10]

void smash::BinaryOutputBase::write ( const Particles particles)
protected

Write particle data of each particle in particles to binary output.

Parameters
[in]particlesList of particles, whose data is to be written.

Definition at line 166 of file binaryoutput.cc.

166  {
167  for (const auto &p : particles) {
169  }
170 }
void write_particledata(const ParticleData &p)
Write particle data to binary output.
constexpr int p
Proton.

◆ write() [10/10]

void smash::BinaryOutputBase::write ( const ParticleList &  particles)
protected

Write each particle data entry to binary output.

Parameters
[in]particlesList of particles, whose data is to be written.

Definition at line 172 of file binaryoutput.cc.

172  {
173  for (const auto &p : particles) {
175  }
176 }

◆ write_particledata()

void smash::BinaryOutputBase::write_particledata ( const ParticleData p)
protected

Write particle data to binary output.

Parameters
[in]pParticle data to be written.

Definition at line 178 of file binaryoutput.cc.

178  {
179  write(p.position());
180  double mass = p.effective_mass();
181  std::fwrite(&mass, sizeof(mass), 1, file_.get());
182  write(p.momentum());
183  write(p.pdgcode().get_decimal());
184  write(p.id());
185  write(p.type().charge());
186  if (extended_) {
187  const auto history = p.get_history();
188  write(history.collisions_per_particle);
189  write(p.formation_time());
190  write(p.xsec_scaling_factor());
191  write(history.id_process);
192  write(static_cast<int32_t>(history.process_type));
193  write(history.time_last_collision);
194  write(history.p1.get_decimal());
195  write(history.p2.get_decimal());
196  write(p.type().baryon_number());
197  }
198 }

Member Data Documentation

◆ file_

RenamingFilePtr smash::BinaryOutputBase::file_
protected

Binary particles output file path.

Definition at line 115 of file binaryoutput.h.

◆ format_version_

const uint16_t smash::BinaryOutputBase::format_version_ = 8
private

Binary file format version number.

Definition at line 119 of file binaryoutput.h.

◆ extended_

bool smash::BinaryOutputBase::extended_
private

Option for extended output.

Definition at line 121 of file binaryoutput.h.


The documentation for this class was generated from the following files: