File indexing completed on 2025-09-16 08:52:22
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011
0012 #include "corecel/Config.hh"
0013
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Macros.hh"
0016 #include "celeritas/Types.hh"
0017
0018 #include "EventIOInterface.hh"
0019
0020 namespace HepMC3
0021 {
0022 class Writer;
0023 }
0024
0025 namespace celeritas
0026 {
0027
0028 class ParticleParams;
0029
0030
0031
0032
0033
0034 class EventWriter : public EventWriterInterface
0035 {
0036 public:
0037
0038
0039 using SPConstParticles = std::shared_ptr<ParticleParams const>;
0040
0041
0042
0043 enum class Format
0044 {
0045 hepevt,
0046 hepmc2,
0047 hepmc3,
0048 size_
0049 };
0050
0051 public:
0052
0053 EventWriter(std::string const& filename, SPConstParticles params);
0054
0055
0056 EventWriter(std::string const& filename,
0057 SPConstParticles params,
0058 Format fmt);
0059
0060
0061 CELER_DELETE_COPY_MOVE(EventWriter);
0062
0063 ~EventWriter() override = default;
0064
0065
0066 void operator()(VecPrimary const& primaries) final;
0067
0068 private:
0069
0070 SPConstParticles particles_;
0071
0072 Format fmt_;
0073
0074
0075 std::shared_ptr<HepMC3::Writer> writer_;
0076
0077
0078 EventId::size_type event_count_{0};
0079
0080 bool warned_mismatched_events_{false};
0081 };
0082
0083
0084
0085
0086 char const* to_cstring(EventWriter::Format);
0087
0088
0089
0090
0091 #if !CELERITAS_USE_HEPMC3
0092 inline EventWriter::EventWriter(std::string const& s, SPConstParticles p)
0093 : EventWriter{s, p, Format::size_}
0094 {
0095 }
0096 inline EventWriter::EventWriter(std::string const&, SPConstParticles, Format)
0097 {
0098 CELER_DISCARD(particles_);
0099 CELER_DISCARD(fmt_);
0100 CELER_DISCARD(writer_);
0101 CELER_DISCARD(event_count_);
0102 CELER_DISCARD(warned_mismatched_events_);
0103 CELER_NOT_CONFIGURED("HepMC3");
0104 }
0105
0106 inline void EventWriter::operator()(argument_type)
0107 {
0108 CELER_ASSERT_UNREACHABLE();
0109 }
0110 #endif
0111
0112
0113 }