Jpp  19.0.0
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 "JIO/JBinaryFileReader.hh"
11 #include "JDAQ/JDAQPreambleIO.hh"
14 #include "JLang/JObjectIterator.hh"
15 #include "JLang/JConversion.hh"
16 
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace JSUPPORT {}
23 namespace JPP { using namespace JSUPPORT; }
24 
25 namespace JSUPPORT {
26 
27  using JIO::JStreamReader;
34  using JLANG::JNullAccess;
35 
36 
37  /**
38  * DAQ object reading from binary file (i.e.\ .dat).
39  */
40  template<class T, bool = JLANG::JConversion<T,JDAQPreamble>::is_derived>
42 
43 
44  /**
45  * Template specialisation of JDAQFileReader for DAQ compatible data types.
46  *
47  * This class provides for an implementation of the JLANG::JAccessibleObjectIterator interface.\n
48  * The method JLANG::JAbstractObjectIterator::setObject is overwritten so that
49  * the desired object is read from the file which may contain also other objects.
50  */
51  template<class T>
52  class JDAQFileReader<T,true> :
54  public JStreamReader,
55  public JReaderObjectIterator<T>,
57  {
58  public:
59  /**
60  * Default constructor.
61  */
64  JStreamReader (static_cast<std::istream&> (*this)),
65  JReaderObjectIterator<T>(static_cast<JStreamReader&>(*this))
66  {}
67 
68 
69  /**
70  * Set object.
71  *
72  * \param object reference to object to be set
73  * \return true if set; else false
74  */
75  virtual bool setObject(T& object) override
76  {
77  using namespace std;
78  using namespace KM3NETDAQ;
79  using namespace JIO;
80 
81  for (JStreamReader& in = static_cast<JStreamReader&>(*this); in >> preamble; ) {
82 
83  if (preamble.getLength() < (int) getSizeof<JDAQPreamble>()) {
84 
85  this->setstate(ios::badbit);
86 
87  return false;
88 
89  } else if (preamble.getDataType() == getDataType<T>()) {
90 
91  buffer.resize(preamble.getLength());
92 
93  memcpy(buffer.data(), static_cast<JDAQAbstractPreamble*>(&preamble), getSizeof<JDAQPreamble>());
94 
95  in.read(buffer.data() + getSizeof<JDAQPreamble>(),
96  preamble.getLength() - getSizeof<JDAQPreamble>());
97 
98  JByteArrayReader bin(buffer.data(), buffer.size());
99 
100  bin >> object;
101 
102  return (bool) in;
103 
104  } else {
105 
106  this->ignore((streamsize) (preamble.getLength() - getSizeof<JDAQPreamble>()));
107  }
108  }
109 
110  return false;
111  }
112 
113  private:
116  };
117 
118 
119  /**
120  * Template specialisation of JDAQFileReader for DAQ incompatible data types.
121  *
122  * This class provides for a null implementation of the JLANG::JAccessibleObjectIterator interface.
123  */
124  template<class T>
125  class JDAQFileReader<T,false> :
126  public JAccessibleObjectIterator<T>,
127  public JNullAccess,
128  public JNullIterator<T>
129  {};
130 }
131 
132 #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 The output file must have the wildcard in the e g root fi 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.