File indexing completed on 2025-01-18 10:01:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef HEPMC3_READERFACTORY_H
0012 #define HEPMC3_READERFACTORY_H
0013
0014
0015 #include "HepMC3/ReaderFactory_fwd.h"
0016 #include "HepMC3/CompressedIO.h"
0017
0018 namespace HepMC3 {
0019
0020
0021
0022
0023
0024
0025
0026 inline std::shared_ptr<Reader> deduce_reader(const std::string &filename)
0027 {
0028 InputInfo input(filename);
0029 if (input.m_init && !input.m_error && input.m_reader) return input.m_reader;
0030 if (input.m_root || input.m_remote) {
0031 HEPMC3_DEBUG(10, "deduce_reader: Attempt ReaderRootTree for " << filename);
0032 return std::make_shared<ReaderPlugin>(filename, libHepMC3rootIO, std::string("newReaderRootTreefile"));
0033 }
0034 if (input.m_protobuf) {
0035 HEPMC3_DEBUG(10, "deduce_reader: Attempt ProtobufIO for " << filename);
0036 return std::make_shared<ReaderPlugin>(filename, libHepMC3protobufIO, std::string("newReaderprotobuffile"));
0037 }
0038 #if HEPMC3_USE_COMPRESSION
0039 HEPMC3_DEBUG(10, "Attempt ReaderGZ for " << filename);
0040 char buf[6];
0041 snprintf(buf, 6, "%s", input.m_head.at(0).c_str());
0042 Compression det = detect_compression_type(buf, buf + 6);
0043 if ( det != Compression::plaintext ) {
0044 HEPMC3_DEBUG(10, "Detected supported compression: " << det);
0045 return deduce_reader(std::shared_ptr< std::istream >(new ifstream(filename.c_str())));
0046 }
0047 #endif
0048 std::string f = filename;
0049 return input.native_reader(f);
0050 }
0051 }
0052 #endif