Jpp  18.2.1
the software that should make you happy
 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 
10 
11 
12 /**
13  * \author mdejong
14  */
15 
16 namespace KM3NETDAQ {
17 
18  /**
19  * DAQ preamble.
20  *
21  * The data type is determined by the return value of method getDataType().\n
22  * This method should be overloaded so that each data type is uniquely mapped to an integer value.
23  *
24  * The size and type information of this object can be used for RTTI.
25  */
26  class JDAQPreamble :
27  public JDAQAbstractPreamble,
28  public TObject
29  {
30  protected:
31 
32  /**
33  * Constructor.
34  *
35  * \param type data type of derived class
36  */
37  template<class T>
40  {}
41 
42  public:
43 
44  friend size_t getSizeof<JDAQPreamble>();
46  friend JWriter& operator<<(JWriter&, const JDAQPreamble&);
47 
48  /**
49  * Default constructor.
50  */
53  {}
54 
55 
56  /**
57  * Virtual destructor.
58  */
59  virtual ~JDAQPreamble()
60  {}
61 
62 
63  /**
64  * Get DAQ preamble.
65  *
66  * This method should be used for binary I/O to get the actual data for the given object.\n
67  * To this end, the following method should be overloaded for the corresponding data type.
68  * <pre>
69  * size_t getSizeof(const T&);
70  * </pre>
71  *
72  * \param object object
73  * \return preamble
74  */
75  template<class T>
76  static JDAQPreamble getDAQPreamble(const T& object)
77  {
78  static JDAQPreamble preamble;
79 
80  preamble.length = getSizeof(object);
81  preamble.type = KM3NETDAQ::getDataType<T>();
82 
83  return preamble;
84  }
85 
86 
87  /**
88  * Print DAQ preamble.
89  *
90  * \param out output stream
91  * \param preamble JDAQPreamble
92  * \return output stream
93  */
94  friend inline std::ostream& operator<<(std::ostream& out, const JDAQPreamble& preamble)
95  {
96  using namespace std;
97 
98  out << setw(8) << preamble.length;
99  out << ' ';
100  out << setw(6) << preamble.type;
101 
102  return out;
103  }
104 
105 
107  };
108 }
109 
110 #endif
Interface for binary output.
Auxiliary class for a DAQ type holder.
friend size_t getSizeof()
Definition of method to get size of data type.
Definition: JRoot.hh:19
ClassDef(JDAQPreamble, 1)
JDAQPreamble(const JDAQType< T > &type)
Constructor.
Definition: JDAQPreamble.hh:38
static JDAQPreamble getDAQPreamble(const T &object)
Get DAQ preamble.
Definition: JDAQPreamble.hh:76
do set_variable OUTPUT_DIRECTORY $WORKDIR T
virtual ~JDAQPreamble()
Virtual destructor.
Definition: JDAQPreamble.hh:59
Interface for binary input.
Simple data structure for the DAQ preamble required for a correct calculation of the object size for ...
JDAQPreamble()
Default constructor.
Definition: JDAQPreamble.hh:51
friend JReader & operator>>(JReader &, JDAQPreamble &)
Read DAQ preamble from input.
size_t getSizeof< JDAQPreamble >()
Get size of type.
friend JWriter & operator<<(JWriter &, const JDAQPreamble &)
Write DAQ preamble to output.
friend std::ostream & operator<<(std::ostream &out, const JDAQPreamble &preamble)
Print DAQ preamble.
Definition: JDAQPreamble.hh:94