File indexing completed on 2025-01-18 10:01:14
0001
0002
0003
0004
0005
0006 #ifndef HEPMC3_READERGZ_H
0007 #define HEPMC3_READERGZ_H
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <set>
0018 #include <string>
0019 #include <fstream>
0020 #include <istream>
0021 #include <iterator>
0022 #include "HepMC3/Reader.h"
0023 #include "HepMC3/GenEvent.h"
0024 #include "HepMC3/CompressedIO.h"
0025 namespace HepMC3 {
0026
0027 template <class T> class ReaderGZ : public Reader {
0028 public:
0029
0030
0031 ReaderGZ(const std::string& filename) {
0032 m_zstr = std::shared_ptr< std::istream >(new ifstream(filename.c_str()));
0033 m_reader = std::make_shared<T>(*(m_zstr.get()));
0034 }
0035
0036 ReaderGZ(std::istream & is) {
0037 m_zstr = std::shared_ptr< std::istream >(new istream(is));
0038 m_reader = std::make_shared<T>(*(m_zstr.get()));
0039 }
0040
0041 ReaderGZ(std::shared_ptr<std::istream> s_stream) {
0042 m_zstr = s_stream;
0043 m_reader = std::make_shared<T>(*(m_zstr.get()));
0044 }
0045
0046
0047 ~ReaderGZ() { close(); }
0048
0049
0050 bool skip(const int i) override { if (m_reader) return m_reader->skip(i); return false; }
0051
0052
0053
0054
0055 bool read_event(GenEvent& evt) override { if (m_reader) return m_reader->read_event(evt); return false; }
0056
0057
0058
0059 bool failed() override { if (m_reader) return m_reader->failed(); return false; }
0060
0061
0062
0063 void close() override {
0064 if (m_reader) return m_reader->close();
0065 if(dynamic_pointer_cast<ifstream>(m_zstr)) dynamic_pointer_cast<ifstream>(m_zstr)->close();
0066 }
0067
0068
0069 void set_run_info(std::shared_ptr<GenRunInfo> run) override { if (m_reader) m_reader->set_run_info(run); }
0070
0071
0072 std::shared_ptr<GenRunInfo> run_info() const override { return m_reader?m_reader->run_info():nullptr; }
0073
0074
0075 std::shared_ptr<Reader> writer() { return m_reader;}
0076
0077 private:
0078
0079 std::shared_ptr< std::istream > m_zstr = nullptr;
0080 std::shared_ptr<Reader> m_reader = nullptr;
0081
0082 };
0083
0084 }
0085 #endif