Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQModuleIdentifier.hh
Go to the documentation of this file.
1 #ifndef __JDAQMODULEIDENTIFIER__
2 #define __JDAQMODULEIDENTIFIER__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JDAQ/JDAQRoot.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace KM3NETDAQ {
16 
17  using JIO::JReader;
18  using JIO::JWriter;
19 
20 
21  /**
22  * Module identifier.
23  */
25  {
26  public:
27  /**
28  * Default constructor.
29  */
31  id(-1)
32  {}
33 
34 
35  /**
36  * Constructor.
37  *
38  * \param __id module identifier
39  */
40  JDAQModuleIdentifier(const int __id) :
41  id(__id)
42  {}
43 
44 
45  /**
46  * Get Module identifier.
47  *
48  * \return Module identifier
49  */
51  {
52  return *this;
53  }
54 
55 
56  /**
57  * Set Module identifier.
58  *
59  * \param module Module identifier
60  */
62  {
63  *this = module;
64  }
65 
66 
67  /**
68  * Get module identifier.
69  *
70  * \return module identifier
71  */
72  int getModuleID() const
73  {
74  return id;
75  }
76 
77 
78  /**
79  * Read DAQ ModuleIdentifier from input.
80  *
81  * \param in input stream
82  * \param module module identifier
83  * \return input stream
84  */
85  friend inline std::istream& operator>>(std::istream& in, JDAQModuleIdentifier& module)
86  {
87  in >> module.id;
88 
89  return in;
90  }
91 
92 
93  /**
94  * Write DAQ ModuleIdentifier to output.
95  *
96  * \param out output stream
97  * \param module module identifier
98  * \return output stream
99  */
100  friend inline std::ostream& operator<<(std::ostream& out, const JDAQModuleIdentifier& module)
101  {
102  out << module.id;
103 
104  return out;
105  }
106 
107 
108  /**
109  * Read module identifier from input.
110  *
111  * \param in reader
112  * \param module module identifier
113  * \return rader
114  */
115  friend inline JReader& operator>>(JReader& in, JDAQModuleIdentifier& module)
116  {
117  in >> module.id;
118 
119  return in;
120  }
121 
122 
123  /**
124  * Write module identifier to output.
125  *
126  * \param out writer
127  * \param module module identifier
128  * \return writer
129  */
130  friend inline JWriter& operator<<(JWriter& out, const JDAQModuleIdentifier& module)
131  {
132  out << module.id;
133 
134  return out;
135  }
136 
137 
138  /**
139  * Get size of object.
140  *
141  * \return number of bytes
142  */
143  static int sizeOf()
144  {
145  return sizeof(int);
146  }
147 
148 
150 
151 
152  protected:
153  int id;
154  };
155 
156 
157  /**
158  * Equal operator.
159  *
160  * \param first first module identifier
161  * \param second second module identifier
162  * \return true if identifiers are equal; else false
163  */
164  inline bool operator==(const JDAQModuleIdentifier& first, const JDAQModuleIdentifier& second)
165  {
166  return first.getModuleID() == second.getModuleID();
167  }
168 
169 
170  /**
171  * Not equal operator.
172  *
173  * \param first first module identifier
174  * \param second second module identifier
175  * \return true if identifiers are different; else false
176  */
177  inline bool operator!=(const JDAQModuleIdentifier& first, const JDAQModuleIdentifier& second)
178  {
179  return first.getModuleID() != second.getModuleID();
180  }
181 
182 
183  /**
184  * Equal operator.
185  *
186  * \param module module identifier
187  * \param id identifier
188  * \return true if identifiers are equal; else false
189  */
190  inline bool operator==(const JDAQModuleIdentifier& module, const int id)
191  {
192  return module.getModuleID() == id;
193  }
194 
195 
196  /**
197  * Not equal operator.
198  *
199  * \param module module identifier
200  * \param id identifier
201  * \return true if identifiers are different; else false
202  */
203  inline bool operator!=(const JDAQModuleIdentifier& module, const int id)
204  {
205  return module.getModuleID() != id;
206  }
207 
208 
209  /**
210  * Less than operator.
211  *
212  * \param first first module identifier
213  * \param second second module identifier
214  * \return true if first identifier less than second eidentifier; else false
215  */
216  inline bool operator<(const JDAQModuleIdentifier& first, const JDAQModuleIdentifier& second)
217  {
218  return first.getModuleID() < second.getModuleID();
219  }
220 
221 
222  /**
223  * Less than operator.
224  *
225  * \param module module identifier
226  * \param id identifier
227  * \return true if module identifier less than identifier; else false
228  */
229  inline bool operator<(const JDAQModuleIdentifier& module, const int id)
230  {
231  return module.getModuleID() < id;
232  }
233 
234 
235  /**
236  * Auxiliary class to compare modules.
237  */
239  /*
240  * Default constructor.
241  */
243  {}
244 
245 
246  /**
247  * Compare modules.
248  *
249  * \param first first module
250  * \param second second module
251  * \return true if first module identifier less than that of second; else false
252  */
253  bool operator()(const JDAQModuleIdentifier& first, const JDAQModuleIdentifier& second) const
254  {
255  return first.getModuleID() < second.getModuleID();
256  }
257  };
258 }
259 
260 #endif
JDAQModuleIdentifier(const int __id)
Constructor.
bool operator()(const JDAQModuleIdentifier &first, const JDAQModuleIdentifier &second) const
Compare modules.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Interface for binary output.
int getModuleID() const
Get module identifier.
JDAQModuleIdentifier()
Default constructor.
friend JWriter & operator<<(JWriter &out, const JDAQModuleIdentifier &module)
Write module identifier to output.
Interface for binary input.
Auxiliary class to compare modules.
friend std::istream & operator>>(std::istream &in, JDAQModuleIdentifier &module)
Read DAQ ModuleIdentifier from input.
void setModuleIdentifier(const JDAQModuleIdentifier &module)
Set Module identifier.
static int sizeOf()
Get size of object.
friend JReader & operator>>(JReader &in, JDAQModuleIdentifier &module)
Read module identifier from input.
friend std::ostream & operator<<(std::ostream &out, const JDAQModuleIdentifier &module)
Write DAQ ModuleIdentifier to output.
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
bool operator<(const JDAQHit &first, const JDAQHit &second)
Less than operator for DAQ hits.
Definition: JDAQHit.hh:178
ClassDefNV(JDAQModuleIdentifier, 1)