#ifndef __JSUPPORT__JFILESCANNER__ #define __JSUPPORT__JFILESCANNER__ #include #include "JLang/JObjectReader.hh" #include "JLang/JException.hh" #include "Jeep/JPrint.hh" #include "JROOT/JRootFileReader.hh" #include "JSupport/JDAQFileReader.hh" #include "JSupport/JMonteCarloFileReader.hh" #include "JSupport/JFilenameSupportkit.hh" /** * \author mdejong */ namespace JSUPPORT {} namespace JPP { using namespace JSUPPORT; } namespace JSUPPORT { using JLANG::JAccessibleObjectReader; using JLANG::JProtocolException; using JLANG::JFileOpenException; /** * Object reading from file. * * This class implements the method open of the JLANG::JAccessible interface. * The file format is derived from the file name extension. */ template class JFileScanner : public JAccessibleObjectReader { public: typedef typename JAccessibleObjectReader::helper_type helper_type; /** * Default constructor. */ JFileScanner() {} /** * Constructor. * * \param file_name file name */ JFileScanner(const char* file_name) { open(file_name); } /** * Destructor. */ ~JFileScanner() { if (this->is_open()) { this->close(); } } /** * Open file. * * \param file_name file name */ virtual void open(const char* file_name) override { using namespace std; using namespace JPP; JAccessible::Throw(true); if (getProtocol(file_name) == ROOT_FILE_FORMAT) this->reset(new JRootFileReader()); else if (getFilenameExtension(file_name) == ROOT_FILE_FORMAT) this->reset(new JRootFileReader()); else if (getFilenameExtension(file_name) == DAQ_FILE_FORMAT) this->reset(new JDAQFileReader()); else if (getFilenameExtension(file_name) == MONTE_CARLO_FILE_FORMAT) this->reset(new JMonteCarloASCIIFileReader()); else if (getFilenameExtension(file_name) == GZIP_FILE_FORMAT) this->reset(new JMonteCarloGZFileReader()); else this->Throw(JProtocolException(MAKE_STRING("Protocol not defined: " << file_name))); if (this->is_valid()) { this->get()->open(file_name); if (!this->get()->is_open()) { if (getFilenameExtension(file_name) != ROOT_FILE_FORMAT) { JAccessible::Throw(JFileOpenException("File not opened.")); } } } } }; } #endif