Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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"
15#include "JLang/JConversion.hh"
16
17
18/**
19 * \author mdejong
20 */
21
22namespace JSUPPORT {}
23namespace JPP { using namespace JSUPPORT; }
24
25namespace JSUPPORT {
26
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> :
127 public JNullAccess,
128 public JNullIterator<T>
129 {};
130}
131
132#endif
Object reading from binary file (i.e. .jpp).
Byte array binary input.
Binary input based on std::istream.
Definition JStreamIO.hh:26
Interface for object iteration with named access.
Interface for null access.
virtual bool setObject(T &object) override
Set object.
DAQ object reading from binary file (i.e. .dat).
Simple data structure for the DAQ preamble required for a correct calculation of the object size for ...
Auxiliary classes and methods for binary I/O.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
int getDataType()
Template definition for method returning data type.
size_t getSizeof< JDAQPreamble >()
Get size of type.
Implementation for null iteration.