Jpp
JDAQFileReader.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JDAQFILEREADER__
2 #define __JSUPPORT__JDAQFILEREADER__
3 
4 #include <vector>
5 #include <string.h>
6 
8 #include "JIO/JByteArrayIO.hh"
9 #include "JDAQ/JDAQDataTypes.hh"
10 #include "JDAQ/JDAQPreamble.hh"
11 #include "JLang/JObjectIterator.hh"
12 #include "JLang/JConversion.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JSUPPORT {}
20 namespace JPP { using namespace JSUPPORT; }
21 
22 namespace JSUPPORT {
23 
28  using JLANG::JNullAccess;
29 
30 
31  /**
32  * DAQ object reading from binary file (i.e. .dat).
33  */
34  template<class T, bool = JLANG::JConversion<T,JDAQPreamble>::is_derived>
36 
37 
38  /**
39  * Template specialisation of JDAQFileReader for DAQ compatible data types.
40  *
41  * This class provides for an implementation of the JLANG::JAccessibleObjectIterator interface.
42  * It overwrites the method setObject of the JLANG::JAbstractObjectIterator interface so that
43  * the desired object is read from the file which may contain also other objects.
44  */
45  template<class T>
46  class JDAQFileReader<T,true> :
47  public JBinaryFileReader<T>
48  {
49  public:
50  /**
51  * Set object.
52  *
53  * \param object reference to object to be set
54  * \return true if set; else false
55  */
56  virtual bool setObject(T& object)
57  {
58  using namespace std;
59  using namespace KM3NETDAQ;
60  using namespace JIO;
61 
62  for (JStreamReader& in = static_cast<JStreamReader&>(*this); in >> preamble; ) {
63 
64  if (preamble.getLength() < JDAQPreamble::sizeOf()) {
65 
66  this->setstate(ios::badbit);
67 
68  return false;
69 
70  } else if (preamble.getDataType() == getDataType<T>()) {
71 
72  buffer.resize(preamble.getLength());
73 
74  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), JDAQPreamble::sizeOf());
75 
76  in.read(buffer.data() + JDAQPreamble::sizeOf(),
77  preamble.getLength() - JDAQPreamble::sizeOf());
78 
79  JByteArrayReader bin(buffer.data(), buffer.size());
80 
81  bin >> object;
82 
83  return (bool) in;
84 
85  } else {
86 
87  this->ignore((streamsize) (preamble.getLength() - JDAQPreamble::sizeOf()));
88  }
89  }
90 
91  return false;
92  }
93 
94  private:
97  };
98 
99 
100  /**
101  * Template specialisation of JDAQFileReader for DAQ incompatible data types.
102  *
103  * This class provides for a null implementation of the JLANG::JAccessibleObjectIterator interface.
104  */
105  template<class T>
106  class JDAQFileReader<T,false> :
107  public JAccessibleObjectIterator<T>,
108  public JNullAccess,
109  public JNullIterator<T>
110  {};
111 }
112 
113 #endif
JSUPPORT::JDAQFileReader< T, true >::setObject
virtual bool setObject(T &object)
Set object.
Definition: JDAQFileReader.hh:56
JSUPPORT::JDAQFileReader< T, true >::buffer
std::vector< char > buffer
Definition: JDAQFileReader.hh:96
JObjectIterator.hh
JIO::JBinaryFileReader
Object reading from binary file.
Definition: JBinaryFileReader.hh:32
std::vector< char >
KM3NETDAQ::JDAQPreamble::sizeOf
static int sizeOf()
Get size of object.
Definition: JDAQPreamble.hh:110
JSUPPORT::JDAQFileReader< T, true >::preamble
JDAQPreamble preamble
Definition: JDAQFileReader.hh:95
JSUPPORT::JDAQFileReader
DAQ object reading from binary file (i.e.
Definition: JDAQFileReader.hh:35
JIO::JByteArrayReader
Byte array binary input.
Definition: JByteArrayIO.hh:25
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JAccessibleObjectIterator
Interface for object iteration with named access.
Definition: JObjectIterator.hh:372
JDAQDataTypes.hh
JBinaryFileReader.hh
JIO::JStreamReader
Binary input based on std::istream.
Definition: JStreamIO.hh:24
JByteArrayIO.hh
JConversion.hh
std
Definition: jaanetDictionary.h:36
JSUPPORT
Support classes and methods for experiment specific I/O.
Definition: JDataWriter.cc:38
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JIO
Auxiliary classes and methods for binary I/O.
Definition: JBinaryFileReader.hh:17
JLANG::JNullAccess
Interface for null access.
Definition: JAccessible.hh:65
JDAQPreamble.hh
KM3NETDAQ::JDAQPreamble
DAQ preamble.
Definition: JDAQPreamble.hh:39
JLANG::JNullIterator
Implementation for null iteration.
Definition: JObjectIterator.hh:325