Version: SMASH-2.2
hepmcoutput.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-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 
160 HepMcOutput::HepMcOutput(const bf::path &path, std::string name,
161  const bool full_event, std::string HepMC3_output_type)
162  : HepMcInterface(name, full_event),
163  filename_(path / (name + "." + HepMC3_output_type)) {
165  filename_unfinished_ += +".unfinished";
166 #ifdef SMASH_USE_HEPMC_ROOTIO
167  if (HepMC3_output_type == "asciiv3") {
168 #endif
169  output_file_ = make_unique<HepMC3::WriterAscii>(
170  filename_unfinished_.string(), event_.run_info());
172 #ifdef SMASH_USE_HEPMC_ROOTIO
173  } else {
174  output_file_ = make_unique<HepMC3::WriterRootTree>(
175  filename_unfinished_.string(), event_.run_info());
177  }
178 #endif
179 }
181  logg[LOutput].debug() << "Renaming file " << filename_unfinished_ << " to "
182  << filename_ << std::endl;
183  output_file_->close();
184  bf::rename(filename_unfinished_, filename_);
185 }
186 
187 void HepMcOutput::at_eventend(const Particles &particles,
188  const int32_t event_number,
189  const EventInfo &event) {
190  HepMcInterface::at_eventend(particles, event_number, event);
191  logg[LOutput].debug() << "Writing event " << event_number << " with "
192  << event_.particles().size() << " particles and "
193  << event_.vertices().size() << " vertices to output "
194  << std::endl;
195  output_file_->write_event(event_);
196 }
197 
198 } // 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:187
const bf::path filename_
Filename of output.
Definition: hepmcoutput.h:65
bf::path filename_unfinished_
Filename of output as long as simulation is still running.
Definition: hepmcoutput.h:67
~HepMcOutput()
Destructor renames file.
Definition: hepmcoutput.cc:180
HepMcOutput(const bf::path &path, std::string name, const bool full_event, std::string HepMC3_output_type)
Create HepMC particle output.
Definition: hepmcoutput.cc:160
type_of_HepMC3_output output_type_
HepMC3 output type.
Definition: hepmcoutput.h:73
std::unique_ptr< HepMC3::Writer > output_file_
Pointers to the base class of HepMC3 output files.
Definition: hepmcoutput.h:69
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.