Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/JDAQPreambleIO.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) override
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() < (int) getSizeof<JDAQPreamble>()) {
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), getSizeof<JDAQPreamble>());
75 
76  in.read(buffer.data() + getSizeof<JDAQPreamble>(),
77  preamble.getLength() - getSizeof<JDAQPreamble>());
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() - getSizeof<JDAQPreamble>()));
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
Object reading from binary file.
virtual bool setObject(T &object) override
Set object.
Interface for null access.
Definition: JAccessible.hh:65
Binary input based on std::istream.
Definition: JStreamIO.hh:24
Byte array binary input.
Definition: JByteArrayIO.hh:25
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Implementation for null iteration.
Simple data structure for the DAQ preamble required for a correct calculation of the object size for ...
Interface for object iteration with named access.
DAQ object reading from binary file (i.e. .dat).
size_t getSizeof< JDAQPreamble >()
Get size of type.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41