#ifndef __JSUPPORT__JTRIGGERPARAMETERSSUPPORTKIT__ #define __JSUPPORT__JTRIGGERPARAMETERSSUPPORTKIT__ #include "JTrigger/JTriggerParameters.hh" #include "JLang/JAbstractObjectIterator.hh" #include "JLang/JException.hh" #include "JSupport/JMultipleFileScanner.hh" /** * \author mdejong */ namespace JSUPPORT {} namespace JPP { using namespace JSUPPORT; } namespace JSUPPORT { using JTRIGGER::JTriggerParameters; using JLANG::JRewindableAbstractObjectIterator; using JLANG::JException; using JLANG::JNullPointerException; /** * Template specialisation of JMultipleFileScanner for trigger parameters. * * This class re-implements the methods rewind and setObject of the JLANG::JRewindableAbstractObjectIterator interface * so that all trigger parameter objects in the complete file list are read and checked for consistency. */ template<> class JMultipleFileScanner : public virtual JMultipleFileScanner<>, public JRewindableAbstractObjectIterator { public: /** * Default constructor. */ JMultipleFileScanner() : JMultipleFileScanner<>(), JRewindableAbstractObjectIterator(), do_next(true) {} /** * Copy constructor. * The file list is copied. * * \param file_list JMultipleFileScanner */ JMultipleFileScanner(const JMultipleFileScanner_t& file_list) : JMultipleFileScanner<>(), JRewindableAbstractObjectIterator(), do_next(true) { configure(file_list, JLimit()); } /** * Rewind. */ virtual void rewind() override { do_next = true; } /** * Set object. * * \param object reference to object to be set * \return true if set; else false */ virtual bool setObject(JTriggerParameters& object) override { if (do_next) { using namespace JLANG; object = JTriggerParameters(); do_next = false; unsigned int count = 0; JFileScanner scanner; for (const_iterator i = this->begin(); i != this->end(); ++i) { scanner.open(i->c_str()); if (scanner.hasNext()) { const JTriggerParameters* __p = scanner.next(); if (count == 0) object = *__p; else if (!object.equals(*__p)) throw JException("JMultipleFileScanner::setObject(): inconsistent trigger parameters."); ++count; } scanner.close(); } return count != 0; } else { return false; } } /** * Get trigger parameters. * * \return trigger parameters */ const JTriggerParameters& getTriggerParameters() { const JTriggerParameters* p = NULL; if (!this->hasNext() || (p = this->next()) == NULL) { throw JNullPointerException("JMultipleFileScanner::getTriggerParameters(): Missing trigger parameters."); } rewind(); return *p; } private: bool do_next; }; /** * Get trigger parameters. * * \param file_list file list * \return trigger parameters */ inline JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t& file_list) { return JMultipleFileScanner(file_list).getTriggerParameters(); } } #endif