18 #include "smash/config.h"
24 const OutputParameters ¶meters);
27 const std::vector<std::string> &quantities) {
28 std::string filename = content;
29 if (content ==
"Particles" || content ==
"Collisions") {
30 std::transform(filename.begin(), filename.end(), filename.begin(),
31 [](
unsigned char c) { return std::tolower(c); });
32 }
else if (content ==
"Photons" || content ==
"Dileptons") {
34 }
else if (content ==
"Initial_Conditions") {
35 filename =
"SMASH_IC";
37 throw std::invalid_argument(
38 "Unknown content to get the binary output filename.");
41 filename +=
"_oscar2013";
43 filename +=
"_oscar2013_extended";
45 filename +=
"_custom";
47 return filename +
".bin";
203 const std::string &mode,
204 const std::string &name,
205 const std::vector<std::string> &quantities)
207 if (quantities.empty()) {
208 throw std::invalid_argument(
209 "Empty quantities list passed to 'BinaryOutputBase' constructor.");
211 std::fwrite(
"SMSH", 4, 1,
file_.
get());
213 std::uint16_t format_variant{};
221 write(format_variant);
222 write(SMASH_VERSION);
227 std::fwrite(&c,
sizeof(
char), 1,
file_.
get());
230 std::fwrite(chunk.data(),
sizeof(
char), chunk.size(),
file_.
get());
234 const auto size = smash::numeric_cast<uint32_t>(s.size());
235 std::fwrite(&size,
sizeof(std::uint32_t), 1,
file_.
get());
236 std::fwrite(s.c_str(), s.size(), 1,
file_.
get());
240 std::fwrite(&x,
sizeof(x), 1,
file_.
get());
248 write_in_chunk<ToBinary>(
254 write_in_chunk<ToBinary>(
264 const std::filesystem::path &path, std::string name,
265 const OutputParameters &out_par,
const std::vector<std::string> &quantities)
268 print_start_end_(out_par.coll_printstartend) {}
273 const char pchar =
'p';
275 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
286 const char pchar =
'p';
288 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
296 const char fchar =
'f';
297 std::fwrite(&fchar,
sizeof(
char), 1,
file_.
get());
301 const char empty =
event.empty_event;
309 const double density) {
310 const char ichar =
'i';
311 std::fwrite(&ichar,
sizeof(
char), 1,
file_.
get());
314 std::fwrite(&density,
sizeof(
double), 1,
file_.
get());
316 std::fwrite(&weight,
sizeof(
double), 1,
file_.
get());
318 std::fwrite(&partial_weight,
sizeof(
double), 1,
file_.
get());
319 const auto type =
static_cast<uint32_t
>(action.
get_type());
320 std::fwrite(&type,
sizeof(uint32_t), 1,
file_.
get());
326 const std::filesystem::path &path, std::string name,
327 const OutputParameters &out_par,
const std::vector<std::string> &quantities)
330 only_final_(out_par.part_only_final) {}
335 const char pchar =
'p';
337 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
348 const char pchar =
'p';
350 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
358 const char fchar =
'f';
359 std::fwrite(&fchar,
sizeof(
char), 1,
file_.
get());
363 const char empty =
event.empty_event;
371 const std::unique_ptr<Clock> &,
375 const char pchar =
'p';
377 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
386 const std::filesystem::path &path, std::string name,
387 const std::vector<std::string> &quantities)
399 const char fchar =
'f';
400 std::fwrite(&fchar,
sizeof(
char), 1,
file_.
get());
404 const char empty =
event.empty_event;
415 const char pchar =
'p';
416 std::fwrite(&pchar,
sizeof(
char), 1,
file_.
get());
423 const std::string &
format,
425 const bool is_extended = std::invoke([&content, ¶meters]() {
426 if (content ==
"Particles")
428 else if (content ==
"Collisions")
430 else if (content ==
"Dileptons")
432 else if (content ==
"Photons")
434 else if (content ==
"Initial_Conditions")
439 const auto default_quantities =
442 if (
format ==
"Oscar2013_bin") {
443 return default_quantities;
444 }
else if (
format ==
"Binary") {
445 if (content ==
"Particles" || content ==
"Collisions" ||
446 content ==
"Dileptons" || content ==
"Photons" ||
447 content ==
"Initial_Conditions") {
448 auto list_of_quantities = parameters.
quantities.at(content);
449 if (list_of_quantities.empty()) {
450 return default_quantities;
452 return list_of_quantities;
458 throw std::invalid_argument(
459 "Unknown content to get the list of quantities for binary output.");
462 throw std::invalid_argument(
463 "Unknown format to get the list of quantities for binary output.");
468 const std::string &
format,
const std::string &content,
470 const auto quantities =
472 if (content ==
"Particles") {
473 return std::make_unique<BinaryOutputParticles>(path, content, out_par,
475 }
else if (content ==
"Collisions" || content ==
"Dileptons" ||
476 content ==
"Photons") {
477 return std::make_unique<BinaryOutputCollisions>(path, content, out_par,
479 }
else if (content ==
"Initial_Conditions") {
480 return std::make_unique<BinaryOutputInitialConditions>(path, content,
483 throw std::invalid_argument(
"Binary output not available for '" + content +
Action is the base class for a generic process that takes a number of incoming particles and transfor...
virtual ProcessType get_type() const
Get the process type.
virtual double get_total_weight() const =0
Return the total weight value, which is mainly used for the weight output entry.
const ParticleList & incoming_particles() const
Get the list of particles that go into the action.
virtual double get_partial_weight() const =0
Return the specific weight for the chosen outgoing channel, which is mainly used for the partial weig...
const ParticleList & outgoing_particles() const
Get the list of particles that resulted from the action.
Base class for SMASH binary output.
void write(const ToBinary::type &chunk)
Write several bytes to the binary output.
void write_particledata(const ParticleData &p)
Write particle data to binary output.
const uint16_t format_version_
Binary file format version number.
const uint16_t format_custom_
Format variant number associated to the custom quantities case.
OutputFormatter< ToBinary > formatter_
The output formatter.
RenamingFilePtr file_
Binary particles output file path.
BinaryOutputBase(const std::filesystem::path &path, const std::string &mode, const std::string &name, const std::vector< std::string > &quantities)
Create binary output base.
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 EventLabel &event_label, const EventInfo &event) override
Writes the initial particle information list of an event to the binary output.
void at_eventend(const Particles &particles, const EventLabel &event_label, 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, const std::vector< std::string > &quantities)
Create binary particle output.
bool print_start_end_
Write initial and final particles additonally to collisions?
void at_eventend(const Particles &particles, const EventLabel &event_label, 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 std::vector< std::string > &quantities)
Create binary initial conditions particle output.
void at_interaction(const Action &action, const double) override
Writes particles that are removed when crossing the hypersurface to the output.
void at_eventstart(const Particles &, const EventLabel &, const EventInfo &) override
Writes the initial particle information of an event to the binary output.
void at_eventstart(const Particles &particles, const EventLabel &event_label, const EventInfo &event) override
Writes the initial particle information of an event to the binary output.
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 particles at each time interval; fixed by option OUTPUT_INTERVAL.
OutputOnlyFinal only_final_
Whether final- or initial-state particles should be written.
BinaryOutputParticles(const std::filesystem::path &path, std::string name, const OutputParameters &out_par, const std::vector< std::string > &quantities)
Create binary particle output.
void at_eventend(const Particles &particles, const EventLabel &event_label, 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.
The FourVector class holds relevant values in Minkowski spacetime with (+, −, −, −) metric signature.
Abstraction of generic output.
ParticleData contains the dynamic information of a certain particle.
The Particles class abstracts the storage and manipulation of particles.
FILE * get()
Get the underlying FILE* pointer.
std::vector< char > type
Return type of this converter.
@ IfNotEmpty
Print only final-state particles, and those only if the event is not empty.
@ No
Print initial, intermediate and final-state particles.
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...
std::unique_ptr< OutputInterface > create_binary_output(const std::string &format, const std::string &content, const std::filesystem::path &path, const OutputParameters &out_par)
Create a binary output object.
@ FluidizationNoRemoval
See here for a short description.
@ Fluidization
See here for a short description.
static auto get_list_of_binary_quantities(const std::string &content, const std::string &format, const OutputParameters ¶meters)
static auto get_binary_filename(const std::string &content, const std::vector< std::string > &quantities)
Structure to contain custom data for output.
bool empty_event
True if no collisions happened.
double impact_parameter
Impact parameter for collider modus, otherwise dummy.
Structure to contain information about the event and ensemble numbers.
int32_t ensemble_number
The number of the ensemble.
int32_t event_number
The number of the event.
static const std::vector< std::string > oscar2013
Quantities output in OSCAR2013 format.
static const std::vector< std::string > oscar2013extended
Quantities output in Extended OSCAR2013 format.
Helper structure for Experiment to hold output options and parameters.
bool dil_extended
Extended format for dilepton output.
bool coll_extended
Extended format for collisions output.
bool part_extended
Extended format for particles output.
bool photons_extended
Extended format for photon output.
std::map< std::string, std::vector< std::string > > quantities
Map of quantities to be printed in the output.
bool ic_extended
Extended initial conditions output.