![]() |
|
|||
File indexing completed on 2025-02-22 10:31:24
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers. 0003 // See the top-level COPYRIGHT file for details. 0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0005 //---------------------------------------------------------------------------// 0006 //! \file celeritas/io/EventReader.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <memory> 0011 #include <string> 0012 #include <vector> 0013 0014 #include "corecel/Config.hh" 0015 0016 #include "corecel/Assert.hh" 0017 #include "corecel/Macros.hh" 0018 #include "corecel/Types.hh" 0019 0020 #include "EventIOInterface.hh" 0021 0022 namespace HepMC3 0023 { 0024 class Reader; 0025 } 0026 0027 namespace celeritas 0028 { 0029 //---------------------------------------------------------------------------// 0030 class ParticleParams; 0031 struct Primary; 0032 0033 //---------------------------------------------------------------------------// 0034 /*! 0035 * Read a HepMC3 event record file and create primary particles. 0036 * 0037 * Each \c operator() call returns a vector of primaries from a single event 0038 * until all events have been read. Supported formats are Asciiv3, IO_GenEvent, 0039 * HEPEVT, and LHEF. 0040 * 0041 * \todo Define ImportPrimary with double precision. 0042 */ 0043 class EventReader : public EventReaderInterface 0044 { 0045 public: 0046 //!@{ 0047 //! \name Type aliases 0048 using SPConstParticles = std::shared_ptr<ParticleParams const>; 0049 using result_type = std::vector<Primary>; 0050 //!@} 0051 0052 public: 0053 // Construct from a filename 0054 EventReader(std::string const& filename, SPConstParticles particles); 0055 0056 //! Prevent copying and moving 0057 CELER_DELETE_COPY_MOVE(EventReader); 0058 0059 // Read a single event from the event record 0060 result_type operator()() final; 0061 0062 //! Get total number of events 0063 size_type num_events() const final { return num_events_; } 0064 0065 private: 0066 using SPReader = std::shared_ptr<HepMC3::Reader>; 0067 0068 // Shared standard model particle data 0069 SPConstParticles particles_; 0070 0071 // HepMC3 event record reader 0072 SPReader reader_; 0073 0074 // Number of events read 0075 size_type event_count_{0}; 0076 0077 // Total number of events in file 0078 size_type num_events_; 0079 }; 0080 0081 //---------------------------------------------------------------------------// 0082 // Set verbosity from the environment (HEPMC3_VERBOSE) 0083 void set_hepmc3_verbosity_from_env(); 0084 0085 //---------------------------------------------------------------------------// 0086 // Wrapper function for HepMC3::deduce_reader to avoid duplicate symbols 0087 std::shared_ptr<HepMC3::Reader> open_hepmc3(std::string const& filename); 0088 0089 //---------------------------------------------------------------------------// 0090 // INLINE DEFINITIONS 0091 //---------------------------------------------------------------------------// 0092 #if !CELERITAS_USE_HEPMC3 0093 inline EventReader::EventReader(std::string const&, SPConstParticles) 0094 { 0095 CELER_DISCARD(particles_); 0096 CELER_DISCARD(reader_); 0097 CELER_DISCARD(event_count_); 0098 CELER_DISCARD(num_events_); 0099 CELER_NOT_CONFIGURED("HepMC3"); 0100 } 0101 0102 inline auto EventReader::operator()() -> result_type 0103 { 0104 CELER_ASSERT_UNREACHABLE(); 0105 } 0106 0107 inline void set_hepmc3_verbosity_from_env() {} 0108 #endif 0109 0110 //---------------------------------------------------------------------------// 0111 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |