6 #ifndef HEPMC3_READERFACTORY_H
7 #define HEPMC3_READERFACTORY_H
22 std::shared_ptr<Reader> deduce_reader(
const std::string &filename)
25 if (filename.find(
"http://")!=std::string::npos) remote=
true;
26 if (filename.find(
"https://")!=std::string::npos) remote=
true;
27 if (filename.find(
"root://")!=std::string::npos) remote=
true;
28 if (filename.find(
"gsidcap://")!=std::string::npos) remote=
true;
30 std::vector<std::string> head;
34 if (stat (filename.c_str(), &buffer)!=0)
36 printf(
"Error in deduce_reader: file does not exist: %s\n",filename.c_str());
37 return std::shared_ptr<Reader> (
nullptr);
40 std::ifstream file(filename);
42 printf(
"Error in deduce_reader: could not open file for testing HepMC version: %s\n",filename.c_str());
43 return shared_ptr<Reader>(
nullptr);
48 while (std::getline(file, line)&&nonempty<3) {
49 if (line.empty())
continue;
55 #ifdef HEPMC3_READERROOTTREE_H
56 printf(
"Info in deduce_reader: Attempt ReaderRootTree for: %s\n",filename.c_str());
57 if( strncmp(head.at(0).c_str(),
"root",4) == 0||remote)
58 return std::shared_ptr<Reader>((Reader*) (
new ReaderRootTree(filename)));
60 printf(
"Info in deduce_reader: Will not attempt ReaderRootTree. include ReaderRootTree.h to enable ROOT support");
63 printf(
"Info in deduce_reader: file is on remote filesystem, but no root support is enabled: %s\n",filename.c_str());
64 return shared_ptr<Reader>(
nullptr);
67 printf(
"Info in deduce_reader: Attempt ReaderAscii for: %s\n",filename.c_str());
68 if( strncmp(head.at(0).c_str(),
"HepMC::Version",14) == 0 && strncmp(head.at(1).c_str(),
"HepMC::Asciiv3",14)==0 )
69 return std::shared_ptr<Reader>((Reader*) (
new ReaderAscii(filename)));
70 printf(
"Info in deduce_reader: Attempt ReaderAsciiHepMC2 for: %s\n",filename.c_str());
71 if( strncmp(head.at(0).c_str(),
"HepMC::Version",14) == 0 && strncmp(head.at(1).c_str(),
"HepMC::IO_GenEvent",18)==0 )
72 return std::shared_ptr<Reader>((Reader*) (
new ReaderAsciiHepMC2(filename)));
73 printf(
"Info in deduce_reader: Attempt ReaderLHEF for: %s\n",filename.c_str());
74 if( strncmp(head.at(0).c_str(),
"<LesHouchesEvents",17) == 0)
75 return std::shared_ptr<Reader>((Reader*) (
new ReaderLHEF(filename)));
76 printf(
"Info in deduce_reader: Attempt ReaderHEPEVT for: %s\n",filename.c_str());
77 std::stringstream st_e(head.at(0).c_str());
87 if (attr==
' ')
continue;
92 HEPEVT=
static_cast<bool>(st_e>>m_i>>m_p);
95 if (HEPEVT)
return std::shared_ptr<Reader>((Reader*) (
new ReaderHEPEVT(filename)));
96 printf(
"Info in deduce_reader: All attempts failed for: %s\n",filename.c_str());
97 return shared_ptr<Reader>(
nullptr);
Definition of class ReaderHEPEVT.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Fortran common block HEPEVT.
Definition of class ReaderLHEF.