24 if (filename.find(
"http://")!=std::string::npos) remote=
true;
25 if (filename.find(
"https://")!=std::string::npos) remote=
true;
26 if (filename.find(
"root://")!=std::string::npos) remote=
true;
27 if (filename.find(
"gsidcap://")!=std::string::npos) remote=
true;
29 std::vector<std::string> head;
33 if (stat (filename.c_str(), &buffer)!=0)
35 printf(
"Error in deduce_reader: file does not exist: %s\n",filename.c_str());
36 return std::shared_ptr<Reader> (
nullptr);
39 std::ifstream file(filename);
41 printf(
"Error in deduce_reader: could not open file for testing HepMC version: %s\n",filename.c_str());
42 return shared_ptr<Reader>(
nullptr);
47 while (std::getline(file, line)&&nonempty<3) {
48 if (line.empty())
continue;
57#ifdef HEPMC3_READERROOTTREE_H
58 printf(
"Info in deduce_reader: Attempt ReaderRootTree for: %s\n",filename.c_str());
59 if( strncmp(head.at(0).c_str(),
"root",4) == 0||remote)
62 printf(
"Info in deduce_reader: Will not attempt ReaderRootTree. include ReaderRootTree.h to enable ROOT support");
65 printf(
"Info in deduce_reader: file is on remote filesystem, but no root support is enabled: %s\n",filename.c_str());
66 return shared_ptr<Reader>(
nullptr);
69 printf(
"Info in deduce_reader: Attempt ReaderAscii for: %s\n",filename.c_str());
70 if( strncmp(head.at(0).c_str(),
"HepMC::Version",14) == 0 && strncmp(head.at(1).c_str(),
"HepMC::Asciiv3",14)==0 )
72 printf(
"Info in deduce_reader: Attempt ReaderAsciiHepMC2 for: %s\n",filename.c_str());
73 if( strncmp(head.at(0).c_str(),
"HepMC::Version",14) == 0 && strncmp(head.at(1).c_str(),
"HepMC::IO_GenEvent",18)==0 )
75 printf(
"Info in deduce_reader: Attempt ReaderLHEF for: %s\n",filename.c_str());
76 if( strncmp(head.at(0).c_str(),
"<LesHouchesEvents",17) == 0)
78 printf(
"Info in deduce_reader: Attempt ReaderHEPEVT for: %s\n",filename.c_str());
79 std::stringstream st_e(head.at(0).c_str());
89 if (attr==
' ')
continue;
94 HEPEVT=
static_cast<bool>(st_e>>m_i>>m_p);
98 printf(
"Info in deduce_reader: All attempts failed for: %s\n",filename.c_str());
99 return shared_ptr<Reader>(
nullptr);