Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQPreamble.hh
Go to the documentation of this file.
1 #ifndef __JDAQPREAMBLE__
2 #define __JDAQPREAMBLE__
3 
4 #include <ostream>
5 #include <iomanip>
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JDAQ/JDAQRoot.hh"
9 #include "JDAQ/JDAQDataTypes.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace KM3NETDAQ {
18 
19  using JIO::JReader;
20  using JIO::JWriter;
21 
22 
23  /**
24  * DAQ preamble.
25  *
26  * Note that for I/O, the data member length is read whereas
27  * the return value of the virtual method getSize() is written.
28  *
29  * Any derived class should provide for an implementation of
30  * method getSize() so that the actual size of the object is written.
31  *
32  * The data type is determined by the return value of method getDataType().
33  * This method should be overloaded so that each data type is
34  * uniquely mapped to an integer value.
35  *
36  * The size and type information of the (abstract) object can be used for RTTI.
37  */
38 
39  class JDAQPreamble :
40  public JDAQAbstractPreamble,
41  public TObject
42  {
43  protected:
44 
45  /**
46  * Constructor.
47  *
48  * \param type data type of derived class
49  */
50  template<class T>
53  {}
54 
55 
56  public:
57  /**
58  * Default constructor.
59  */
62 
63  {}
64 
65 
66  /**
67  * Virtual destructor.
68  */
69  virtual ~JDAQPreamble()
70  {}
71 
72 
73  /**
74  * Read DAQ preamble from input.
75  *
76  * \param in JReader
77  * \param preamble JDAQPreamble
78  * \return JReader
79  */
80  friend inline JReader& operator>>(JReader& in, JDAQPreamble& preamble)
81  {
82  in >> preamble.length;
83  in >> preamble.type;
84 
85  return in;
86  }
87 
88 
89  /**
90  * Write DAQ preamble to output.
91  *
92  * \param out JWriter
93  * \param preamble JDAQPreamble
94  * \return JWriter
95  */
96  friend inline JWriter& operator<<(JWriter& out, const JDAQPreamble& preamble)
97  {
98  out << preamble.getSize();
99  out << preamble.type;
100 
101  return out;
102  }
103 
104 
105  /**
106  * Get size of object.
107  *
108  * \return number of bytes
109  */
110  static int sizeOf()
111  {
113  }
114 
115 
116  /**
117  * Get size of object.
118  *
119  * \return number of bytes
120  */
121  virtual int getSize() const
122  {
123  return JDAQPreamble::sizeOf();
124  }
125 
126 
128 
129 
130  protected:
131  /**
132  * Set length.
133  */
134  void setLength()
135  {
136  length = getSize();
137  }
138  };
139 
140 
141  /**
142  * Print DAQ preamble.
143  *
144  * \param out output stream
145  * \param preamble JDAQPreamble
146  * \return output stream
147  */
148  inline std::ostream& operator<<(std::ostream& out, const JDAQPreamble& preamble)
149  {
150  using namespace std;
151 
152  out << setw(8) << preamble.getSize();
153  out << ' ';
154  out << setw(6) << preamble.getDataType();
155 
156  return out;
157  }
158 }
159 
160 #endif
Interface for binary output.
Auxiliary class for a DAQ type holder.
int getDataType() const
Get data type.
Definition: JRoot.hh:19
friend JWriter & operator<<(JWriter &out, const JDAQPreamble &preamble)
Write DAQ preamble to output.
Definition: JDAQPreamble.hh:96
void setLength()
Set length.
ClassDef(JDAQPreamble, 1)
virtual int getSize() const
Get size of object.
virtual ~JDAQPreamble()
Virtual destructor.
Definition: JDAQPreamble.hh:69
Interface for binary input.
Simple datastructure for the DAQ preamble without ROOT functionality.
JDAQPreamble()
Default constructor.
Definition: JDAQPreamble.hh:60
static int sizeOf()
Get size of object.
JDAQPreamble(JDAQType< T > type)
Constructor.
Definition: JDAQPreamble.hh:51
friend JReader & operator>>(JReader &in, JDAQPreamble &preamble)
Read DAQ preamble from input.
Definition: JDAQPreamble.hh:80
std::ostream & operator<<(std::ostream &out, const JDAQChronometer &chronometer)
Print DAQ chronometer.
static int sizeOf()
Get size of object.