Jpp  18.3.1
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 
7 #include "JIO/JStreamIO.hh"
9 #include "JIO/JByteArrayIO.hh"
10 #include "JDAQ/JDAQPreambleIO.hh"
13 #include "JLang/JObjectIterator.hh"
14 #include "JLang/JConversion.hh"
15 
16 
17 /**
18  * \author mdejong
19  */
20 
21 namespace JSUPPORT {}
22 namespace JPP { using namespace JSUPPORT; }
23 
24 namespace JSUPPORT {
25 
26  using JIO::JStreamReader;
33  using JLANG::JNullAccess;
34 
35 
36  /**
37  * DAQ object reading from binary file (i.e.\ .dat).
38  */
39  template<class T, bool = JLANG::JConversion<T,JDAQPreamble>::is_derived>
41 
42 
43  /**
44  * Template specialisation of JDAQFileReader for DAQ compatible data types.
45  *
46  * This class provides for an implementation of the JLANG::JAccessibleObjectIterator interface.\n
47  * The method JLANG::JAbstractObjectIterator::setObject is overwritten so that
48  * the desired object is read from the file which may contain also other objects.
49  */
50  template<class T>
51  class JDAQFileReader<T,true> :
53  public JStreamReader,
54  public JReaderObjectIterator<T>,
56  {
57  public:
58  /**
59  * Default constructor.
60  */
63  JStreamReader (static_cast<std::istream&> (*this)),
64  JReaderObjectIterator<T>(static_cast<JStreamReader&>(*this))
65  {}
66 
67 
68  /**
69  * Set object.
70  *
71  * \param object reference to object to be set
72  * \return true if set; else false
73  */
74  virtual bool setObject(T& object) override
75  {
76  using namespace std;
77  using namespace KM3NETDAQ;
78  using namespace JIO;
79 
80  for (JStreamReader& in = static_cast<JStreamReader&>(*this); in >> preamble; ) {
81 
82  if (preamble.getLength() < (int) getSizeof<JDAQPreamble>()) {
83 
84  this->setstate(ios::badbit);
85 
86  return false;
87 
88  } else if (preamble.getDataType() == getDataType<T>()) {
89 
90  buffer.resize(preamble.getLength());
91 
92  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), getSizeof<JDAQPreamble>());
93 
94  in.read(buffer.data() + getSizeof<JDAQPreamble>(),
95  preamble.getLength() - getSizeof<JDAQPreamble>());
96 
97  JByteArrayReader bin(buffer.data(), buffer.size());
98 
99  bin >> object;
100 
101  return (bool) in;
102 
103  } else {
104 
105  this->ignore((streamsize) (preamble.getLength() - getSizeof<JDAQPreamble>()));
106  }
107  }
108 
109  return false;
110  }
111 
112  private:
115  };
116 
117 
118  /**
119  * Template specialisation of JDAQFileReader for DAQ incompatible data types.
120  *
121  * This class provides for a null implementation of the JLANG::JAccessibleObjectIterator interface.
122  */
123  template<class T>
124  class JDAQFileReader<T,false> :
125  public JAccessibleObjectIterator<T>,
126  public JNullAccess,
127  public JNullIterator<T>
128  {};
129 }
130 
131 #endif
Object reading from binary file (i.e. .jpp).
virtual bool setObject(T &object) override
Set object.
Interface for null access.
Definition: JAccessible.hh:65
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
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).
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Accessible binary input stream.
size_t getSizeof< JDAQPreamble >()
Get size of type.
JReader object iterator.
JDAQFileReader()
Default constructor.