#ifndef __JSUPPORT__JDAQFILEREADER__ #define __JSUPPORT__JDAQFILEREADER__ #include #include #include "JIO/JBinaryFileReader.hh" #include "JIO/JByteArrayIO.hh" #include "JDAQ/JDAQPreambleIO.hh" #include "km3net-dataformat/online/JDAQDataTypes.hh" #include "JLang/JObjectIterator.hh" #include "JLang/JConversion.hh" /** * \author mdejong */ namespace JSUPPORT {} namespace JPP { using namespace JSUPPORT; } namespace JSUPPORT { using JIO::JBinaryFileReader; using KM3NETDAQ::JDAQPreamble; using JLANG::JAccessibleObjectIterator; using JLANG::JNullIterator; using JLANG::JNullAccess; /** * DAQ object reading from binary file (i.e.\ .dat). */ template::is_derived> class JDAQFileReader; /** * Template specialisation of JDAQFileReader for DAQ compatible data types. * * This class provides for an implementation of the JLANG::JAccessibleObjectIterator interface. * It overwrites the method setObject of the JLANG::JAbstractObjectIterator interface so that * the desired object is read from the file which may contain also other objects. */ template class JDAQFileReader : public JBinaryFileReader { public: /** * Set object. * * \param object reference to object to be set * \return true if set; else false */ virtual bool setObject(T& object) override { using namespace std; using namespace KM3NETDAQ; using namespace JIO; for (JStreamReader& in = static_cast(*this); in >> preamble; ) { if (preamble.getLength() < (int) getSizeof()) { this->setstate(ios::badbit); return false; } else if (preamble.getDataType() == getDataType()) { buffer.resize(preamble.getLength()); memcpy(buffer.data(), static_cast(&preamble), getSizeof()); in.read(buffer.data() + getSizeof(), preamble.getLength() - getSizeof()); JByteArrayReader bin(buffer.data(), buffer.size()); bin >> object; return (bool) in; } else { this->ignore((streamsize) (preamble.getLength() - getSizeof())); } } return false; } private: mutable JDAQPreamble preamble; mutable std::vector buffer; }; /** * Template specialisation of JDAQFileReader for DAQ incompatible data types. * * This class provides for a null implementation of the JLANG::JAccessibleObjectIterator interface. */ template class JDAQFileReader : public JAccessibleObjectIterator, public JNullAccess, public JNullIterator {}; } #endif