#ifndef __JDAQPREAMBLE__ #define __JDAQPREAMBLE__ #include #include #include "JIO/JSerialisable.hh" #include "JDAQ/JDAQRoot.hh" #include "JDAQ/JDAQDataTypes.hh" #include "JDAQ/JDAQAbstractPreamble.hh" namespace KM3NETDAQ { namespace { using JIO::JReader; using JIO::JWriter; } /** * DAQ preamble. * * Note that for I/O, the data member length is read whereas * the return value of the virtual method getSize() is written. * * Any derived class should provide for an implementation of * method getSize() so that the actual size of the object is written. * * The data type is determined by the return value of method getDataType(). * This method should be overloaded so that each data type is * uniquely mapped to an integer value. * * The size and type information of the (abstract) object can be used for RTTI. */ class JDAQPreamble : public JDAQAbstractPreamble, public TObject { protected: /** * Constructor. * * \param type data type of derived class */ template JDAQPreamble(JLANG::JType type) : JDAQAbstractPreamble(type) {} public: /** * Default constructor. */ JDAQPreamble() : JDAQAbstractPreamble() {} /** * Virtual destructor. */ virtual ~JDAQPreamble() {} /** * Read DAQ preamble from input. * * \param in JReader * \param preamble JDAQPreamble * \return JReader */ friend inline JReader& operator>>(JReader& in, JDAQPreamble& preamble) { in >> preamble.length; in >> preamble.type; return in; } /** * Write DAQ preamble to output. * * \param out JWriter * \param preamble JDAQPreamble * \return JWriter */ friend inline JWriter& operator<<(JWriter& out, const JDAQPreamble& preamble) { out << preamble.getSize(); out << preamble.type; return out; } /** * Get size of object. * * \return number of bytes */ static int sizeOf() { return JDAQAbstractPreamble::sizeOf(); } /** * Get size of object. * * \return number of bytes */ virtual int getSize() const { return JDAQPreamble::sizeOf(); } ClassDef(JDAQPreamble,1); protected: /** * Set length. */ void setLength() { length = getSize(); } }; /** * Print DAQ preamble. * * \param out output stream * \param preamble JDAQPreamble * \return output stream */ inline std::ostream& operator<<(std::ostream& out, const JDAQPreamble& preamble) { using namespace std; out << setw(8) << preamble.getSize(); out << ' '; out << setw(6) << preamble.getDataType(); return out; } } #endif