Version: SMASH-3.4
oscaroutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020,2022,2024-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_OSCAROUTPUT_H_
11 #define SRC_INCLUDE_SMASH_OSCAROUTPUT_H_
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "file.h"
18 #include "forwarddeclarations.h"
19 #include "outputinterface.h"
20 #include "outputparameters.h"
21 #include "smash/outputformatter.h"
22 
23 namespace smash {
24 
25 /**
26  * \addtogroup output
27  * @{
28  */
29 
30 /// Selector for the output format of OscarOutput
35  ASCII
36 };
37 
38 /**
39  * \brief Flags for the \p Contents template parameter of OscarOutput.
40  *
41  * Flags can be combined with binary OR operators to some arbitrary int. That's
42  * why the values of the enumerators are written out (in hexadecimal), to ensure
43  * every flag occupies a single bit.
44  */
46  /// store interaction information (write_interaction)
48  /// store the state after N timesteps (after_Nth_timestep)
49  OscarTimesteps = 0x002,
50  /// store the state at the start of each event (at_eventstart)
52  /// store the state at the end of each event (at_eventend)
54  /// store the state at the end of each event if it is not empty (at_eventend)
56  /// store the particles that are removed on the hypersurface
57  OscarParticlesIC = 0x020
58 };
59 
60 /**
61  * \tparam Format Determines the variant of OSCAR formatting that is used. See
62  * OscarOutputFormat.
63  * \tparam Contents Determines what information will be written to file. This
64  * integer is a bitflag that can be constructed from ORing
65  * enumerators from OscarOutputContents together.
66  */
67 template <OscarOutputFormat Format, int Contents>
68 class OscarOutput : public OutputInterface {
69  public:
70  /**
71  * Create oscar output.
72  *
73  * \param[in] path Output path.
74  * \param[in] name Name of the ouput.
75  * \param[in] quantities List of quantities present in the output file.
76  */
77  OscarOutput(const std::filesystem::path &path, const std::string &name,
78  const std::vector<std::string> quantities = {});
79 
80  /**
81  * Writes the initial particle information of an event to the oscar output.
82  * \param[in] particles Current list of all particles.
83  * \param[in] event_label Numbers of event and ensemble.
84  * \param[in] event Event info, see \ref event_info
85  */
86  void at_eventstart(const Particles &particles, const EventLabel &event_label,
87  const EventInfo &event) override;
88 
89  /**
90  * Writes the final particle information of an event to the oscar output.
91  * \param[in] particles Current list of particles.
92  * \param[in] event_label Numbers of event and ensemble.
93  * \param[in] event Event info, see \ref event_info
94  */
95  void at_eventend(const Particles &particles, const EventLabel &event_label,
96  const EventInfo &event) override;
97 
98  /**
99  * Writes a interaction prefix line and a line for every incoming and
100  * outgoing particle to the oscar output.
101  * \param[in] action Action that holds the information of the interaction.
102  * \param[in] density Density at the interaction point.
103  */
104  void at_interaction(const Action &action, const double density) override;
105 
106  /**
107  * Writes a prefix line then write out all current particles.
108  *
109  * \param[in] particles Current list of particles.
110  * \param[in] clock Unused, needed since inherited.
111  * \param[in] dens_param Unused, needed since inherited.
112  * \param[in] event_label Numbers of event and ensemble.
113  * \param[in] event Event info, see \ref event_info
114  */
115  void at_intermediate_time(const Particles &particles,
116  const std::unique_ptr<Clock> &clock,
117  const DensityParameters &dens_param,
118  const EventLabel &event_label,
119  const EventInfo &event) override;
120 
121  private:
122  /**
123  * Write single particle information line to output.
124  * \param[in] data Data of particle.
125  */
126  void write_particledata(const ParticleData &data);
127 
128  /**
129  * Write a ToASCII::type buffer to the output.
130  * \param[in] buffer Buffer containing the ASCII-formatted data to be written
131  */
132  void write(const ToASCII::type &buffer);
133 
134  /**
135  * Write the particle information of a list of particles to the output.
136  * One line per particle.
137  * \param[in] particles List of particles to be written
138  */
139  void write(const Particles &particles);
140 
141  /// Full filepath of the output file.
143 
144  /// Formatter of the output
146 };
147 
148 /**
149  * \return A new OscarOutput object using information from \p config to
150  * select the correct implementation.
151  *
152  * \param[in] format The output format as string, e.g. \c "Oscar2013"
153  * \param[in] content The output content as string, e.g. \c "Particles"
154  * \param[in] path The path to the output directory where the file(s) will be
155  * placed.
156  * \param[in] out_par A structure containing parameters of the output, in
157  * particular if it is extended or not, if printing only final
158  * particles in event, etc.
159  */
160 std::unique_ptr<OutputInterface> create_oscar_output(
161  const std::string &format, const std::string &content,
162  const std::filesystem::path &path, const OutputParameters &out_par);
163 
164 // @}
165 
166 } // namespace smash
167 
168 #endif // SRC_INCLUDE_SMASH_OSCAROUTPUT_H_
Action is the base class for a generic process that takes a number of incoming particles and transfor...
Definition: action.h:35
A class to pre-calculate and store parameters relevant for density calculation.
Definition: density.h:92
A general-purpose formatter for output, supporting both ASCII and binary formats.
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
Definition: particledata.h:59
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
FormattingHelper< T > format(const T &value, const char *unit, int width=-1, int precision=-1)
Acts as a stream modifier for std::ostream to output an object with an optional suffix string and wit...
Definition: logging.h:217
OscarOutputContents
Flags for the Contents template parameter of OscarOutput.
Definition: oscaroutput.h:45
void at_intermediate_time(const Particles &particles, const std::unique_ptr< Clock > &clock, const DensityParameters &dens_param, const EventLabel &event_label, const EventInfo &event) override
Writes a prefix line then write out all current particles.
Definition: oscaroutput.cc:254
void write_particledata(const ParticleData &data)
Write single particle information line to output.
Definition: oscaroutput.cc:871
OscarOutputFormat
Selector for the output format of OscarOutput.
Definition: oscaroutput.h:31
OscarOutput(const std::filesystem::path &path, const std::string &name, const std::vector< std::string > quantities={})
Create oscar output.
std::unique_ptr< OutputInterface > create_oscar_output(const std::string &format, const std::string &content, const std::filesystem::path &path, const OutputParameters &out_par)
Definition: oscaroutput.cc:926
OutputFormatter< ToASCII > formatter_
Formatter of the output.
Definition: oscaroutput.h:145
RenamingFilePtr file_
Full filepath of the output file.
Definition: oscaroutput.h:142
void write(const ToASCII::type &buffer)
Write a ToASCII::type buffer to the output.
Definition: oscaroutput.cc:878
void at_eventend(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Writes the final particle information of an event to the oscar output.
Definition: oscaroutput.cc:170
void at_eventstart(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Writes the initial particle information of an event to the oscar output.
Definition: oscaroutput.cc:136
void at_interaction(const Action &action, const double density) override
Writes a interaction prefix line and a line for every incoming and outgoing particle to the oscar out...
Definition: oscaroutput.cc:215
@ OscarParticlesAtEventend
store the state at the end of each event (at_eventend)
Definition: oscaroutput.h:53
@ OscarParticlesAtEventendIfNotEmpty
store the state at the end of each event if it is not empty (at_eventend)
Definition: oscaroutput.h:55
@ OscarAtEventstart
store the state at the start of each event (at_eventstart)
Definition: oscaroutput.h:51
@ OscarInteractions
store interaction information (write_interaction)
Definition: oscaroutput.h:47
@ OscarParticlesIC
store the particles that are removed on the hypersurface
Definition: oscaroutput.h:57
@ OscarTimesteps
store the state after N timesteps (after_Nth_timestep)
Definition: oscaroutput.h:49
@ OscarFormat1999
Definition: oscaroutput.h:34
@ OscarFormat2013Extended
Definition: oscaroutput.h:33
@ ASCII
Definition: oscaroutput.h:35
@ OscarFormat2013
Definition: oscaroutput.h:32
Definition: action.h:24
Structure to contain custom data for output.
Structure to contain information about the event and ensemble numbers.
Helper structure for Experiment to hold output options and parameters.
std::string type
Return type of this converter.