Version: SMASH-3.0
hepmcoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2020-2022
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
240 // clang-format on
241 HepMcOutput::HepMcOutput(const std::filesystem::path &path, std::string name,
242  const bool full_event, std::string HepMC3_output_type)
243  : HepMcInterface(name, full_event),
244  filename_(path / (name + "." + HepMC3_output_type)) {
246  filename_unfinished_ += +".unfinished";
247 #ifdef SMASH_USE_HEPMC_ROOTIO
248  if (HepMC3_output_type == "asciiv3") {
249 #endif
250  output_file_ = std::make_unique<HepMC3::WriterAscii>(
251  filename_unfinished_.string(), event_.run_info());
253 #ifdef SMASH_USE_HEPMC_ROOTIO
254  } else {
255  output_file_ = std::make_unique<HepMC3::WriterRootTree>(
256  filename_unfinished_.string(), event_.run_info());
258  }
259 #endif
260 }
262  logg[LOutput].debug() << "Renaming file " << filename_unfinished_ << " to "
263  << filename_ << std::endl;
264  output_file_->close();
265  std::filesystem::rename(filename_unfinished_, filename_);
266 }
267 
268 void HepMcOutput::at_eventend(const Particles &particles,
269  const int32_t event_number,
270  const EventInfo &event) {
271  HepMcInterface::at_eventend(particles, event_number, event);
272  logg[LOutput].debug() << "Writing event " << event_number << " with "
273  << event_.particles().size() << " particles and "
274  << event_.vertices().size() << " vertices to output "
275  << std::endl;
276  output_file_->write_event(event_);
277 }
278 
279 } // 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:268
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:241
~HepMcOutput()
Destructor renames file.
Definition: hepmcoutput.cc:261
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.