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