Version: SMASH-3.1
hepmcoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2020-2023
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/hepmcoutput.h"
11 
12 #include "HepMC3/Print.h"
13 #include "HepMC3/WriterAscii.h"
14 
15 #ifdef SMASH_USE_HEPMC_ROOTIO
16 #include "HepMC3/WriterRootTree.h"
17 #endif
18 
19 namespace smash {
20 // clang-format off
249 // clang-format on
250 HepMcOutput::HepMcOutput(const std::filesystem::path &path, std::string name,
251  const bool full_event, std::string HepMC3_output_type)
252  : HepMcInterface(name, full_event),
253  filename_(path / (name + "." + HepMC3_output_type)) {
255  filename_unfinished_ += +".unfinished";
256 #ifdef SMASH_USE_HEPMC_ROOTIO
257  if (HepMC3_output_type == "asciiv3") {
258 #endif
259  output_file_ = std::make_unique<HepMC3::WriterAscii>(
260  filename_unfinished_.string(), event_.run_info());
262 #ifdef SMASH_USE_HEPMC_ROOTIO
263  } else {
264  output_file_ = std::make_unique<HepMC3::WriterRootTree>(
265  filename_unfinished_.string(), event_.run_info());
267  }
268 #endif
269 }
271  logg[LOutput].debug() << "Renaming file " << filename_unfinished_ << " to "
272  << filename_ << std::endl;
273  output_file_->close();
274  std::filesystem::rename(filename_unfinished_, filename_);
275 }
276 
277 void HepMcOutput::at_eventend(const Particles &particles,
278  const int32_t event_number,
279  const EventInfo &event) {
280  HepMcInterface::at_eventend(particles, event_number, event);
281  logg[LOutput].debug() << "Writing event " << event_number << " with "
282  << event_.particles().size() << " particles and "
283  << event_.vertices().size() << " vertices to output "
284  << std::endl;
285  output_file_->write_event(event_);
286 }
287 
288 } // namespace smash
Base class for output handlers that need the HepMC3 structure.
void at_eventend(const Particles &particles, const int32_t event_number, const EventInfo &event) override
Add the final particles information of an event to the central vertex.
HepMC3::GenEvent event_
The event.
void at_eventend(const Particles &particles, const int32_t event_number, const EventInfo &event) override
Add the final particles information of an event to the central vertex.
Definition: hepmcoutput.cc:277
const std::filesystem::path filename_
Filename of output.
Definition: hepmcoutput.h:66
HepMcOutput(const std::filesystem::path &path, std::string name, const bool full_event, std::string HepMC3_output_type)
Create HepMC particle output.
Definition: hepmcoutput.cc:250
~HepMcOutput()
Destructor renames file.
Definition: hepmcoutput.cc:270
std::filesystem::path filename_unfinished_
Filename of output as long as simulation is still running.
Definition: hepmcoutput.h:68
type_of_HepMC3_output output_type_
HepMC3 output type.
Definition: hepmcoutput.h:74
std::unique_ptr< HepMC3::Writer > output_file_
Pointers to the base class of HepMC3 output files.
Definition: hepmcoutput.h:70
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
Definition: action.h:24
static constexpr int LOutput
Structure to contain custom data for output.