Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMC3Writer.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMC3Writer.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
12 
15  : WriterT(config.inputEvents, "HepMC3EventWriter", level), m_cfg(config) {
16  if (m_cfg.outputStem.empty()) {
17  throw std::invalid_argument("Missing output stem file name");
18  }
19 }
20 
23  const std::vector<HepMC3::GenEvent>& events) {
24  auto path = perEventFilepath(m_cfg.outputDir, m_cfg.outputStem + ".hepmc3",
25  ctx.eventNumber);
26 
27  ACTS_DEBUG("Attempting to write event to " << path);
28  HepMC3::WriterAscii writer(path);
29 
30  for (const auto& event : events) {
31  writer.write_event(event);
32  if (writer.failed()) {
33  return ActsExamples::ProcessCode::ABORT;
34  }
35  }
36 
37  writer.close();
39 }