Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JDAQClock.hh
Go to the documentation of this file.
1#ifndef __JDAQCLOCK__
2#define __JDAQCLOCK__
3
4#include <istream>
5#include <ostream>
6#include <exception>
7#include <cmath>
8
10
11
12/**
13 * \author mdejong
14 */
15
16namespace KM3NETDAQ {
17
18 namespace {
19 static double FRAME_TIME_NS = 100000000.0; //!< Frame time [ns]
20 static double RESET_TIME_NS = FRAME_TIME_NS; //!< TDC dynamic range [ns]
21 }
22
23
24 /**
25 * Auxiliary class to set DAQ system clock parameters.
26 */
27 class JDAQClock {
28 public:
29 /**
30 * Clock types.
31 */
32 enum JDAQClock_t { KM3NET = 1, PPM_DU = 3, ANTARES = 101 };
33
34
35 /**
36 * Constructor.
37 *
38 * \param clock clock type
39 */
41 {
42 this->clock = clock;
43
44 set();
45 }
46
47
48 /**
49 * Get clock type.
50 *
51 * \return clock type
52 */
54 {
55 return clock;
56 }
57
58
59 /**
60 * Set clock type.
61 *
62 * \param clock clock type
63 */
64 void set(const JDAQClock_t clock)
65 {
66 this->clock = clock;
67
68 set();
69 }
70
71
72 /**
73 * Set DAQ clock parameters.
74 */
75 void set()
76 {
77 switch (this->clock) {
78
79 case KM3NET:
80 FRAME_TIME_NS = 100000000.0;
81 RESET_TIME_NS = FRAME_TIME_NS;
82 break;
83
84 case PPM_DU:
85 FRAME_TIME_NS = (1<<27);
86 RESET_TIME_NS = FRAME_TIME_NS;
87 break;
88
89 case ANTARES:
90 FRAME_TIME_NS = 13107200.0 * 8;
91 RESET_TIME_NS = 419430400.0;
92 break;
93
94 default:
95 throw JDAQException("Undefined clock.");
96 }
97 }
98
99
100 /**
101 * Read clock from input.
102 *
103 * \param in input stream
104 * \param clock JClock
105 * \return input stream
106 */
107 friend inline std::istream& operator>>(std::istream& in, JDAQClock& clock)
108 {
109 using namespace std;
110
111 int clk;
112
113 in >> clk;
114
115 try {
116 clock.set((JDAQClock_t) clk);
117 }
118 catch(const std::exception& error) {
119 in.setstate(ios_base::badbit);
120 }
121
122 return in;
123 }
124
125
126 /**
127 * Write clock to output.
128 *
129 * \param out output stream
130 * \param clock JClock
131 * \return output stream
132 */
133 friend inline std::ostream& operator<<(std::ostream& out, const JDAQClock& clock)
134 {
135 return out << clock.clock;
136 }
137
138
139 protected:
141 };
142
143
144 /**
145 * Equal operator for JDAQClock.
146 *
147 * \param first JDAQClock
148 * \param second JDAQClock
149 * \return true if both clock types are equal; else false
150 */
151 inline bool operator==(const JDAQClock& first, const JDAQClock& second)
152 {
153 return first.get() == second.get();
154 }
155
156
157 /**
158 * Get frame time duration.
159 *
160 * \return frame time [ns]
161 */
162 inline double getFrameTime()
163 {
164 return FRAME_TIME_NS;
165 }
166
167
168 /**
169 * Get TDC dynamic range.
170 *
171 * \return TDC dynamic range [ns]
172 */
173 inline double getRTS()
174 {
175 return RESET_TIME_NS;
176 }
177
178
179 /**
180 * Get start time of frame in ns since start of run for a given frame index.
181 *
182 * \param frame_index frame index
183 * \return time [ns]
184 */
185 inline double getTimeOfFrame(const int frame_index)
186 {
187 if (frame_index != 0)
188 return (double) (frame_index - 1) * FRAME_TIME_NS;
189 else
190 return 0;
191 }
192
193
194 /**
195 * Get start time of frame in ns since start of run for a given frame index.
196 *
197 * \param frame_index frame index
198 * \return time [ns]
199 */
200 inline double getTimeOfFrame(const unsigned int frame_index)
201 {
202 if (frame_index != 0)
203 return (double) (frame_index - 1) * FRAME_TIME_NS;
204 else
205 return 0;
206 }
207
208
209 /**
210 * Get time of last RTS in ns since start of run for a given time.
211 *
212 * \param t_ns time [ns]
213 * \return time [ns]
214 */
215 inline double getTimeOfRTS(const double t_ns)
216 {
217 return std::floor(t_ns/RESET_TIME_NS) * RESET_TIME_NS;
218 }
219
220
221 /**
222 * Get time of last RTS in ns since start of run for a given frame index.
223 *
224 * \param frame_index frame index
225 * \return time [ns]
226 */
227 inline double getTimeOfRTS(const int frame_index)
228 {
229 return std::floor(getTimeOfFrame(frame_index)/RESET_TIME_NS) * RESET_TIME_NS;
230 }
231
232
233 /**
234 * Get time of last RTS in ns since start of run for a given frame index.
235 *
236 * \param frame_index frame index
237 * \return time [ns]
238 */
239 inline double getTimeOfRTS(const unsigned int frame_index)
240 {
241 return std::floor(getTimeOfFrame(frame_index)/RESET_TIME_NS) * RESET_TIME_NS;
242 }
243
244
245 /**
246 * Get frame index for a given time in ns.
247 *
248 * \param t_ns time [ns]
249 * \return frame index
250 */
251 inline int getFrameIndex(const double t_ns)
252 {
253 return (int) (t_ns / FRAME_TIME_NS) + 1;
254 }
255
256
257 /**
258 * Get time in ns since last RTS for a given frame index.
259 *
260 * \param frame_index frame index
261 * \return time [ns]
262 */
263 inline double getTimeSinceRTS(const int frame_index)
264 {
265 return std::fmod(getTimeOfFrame(frame_index), RESET_TIME_NS);
266 }
267
268
269 /**
270 * Get time in ns since last RTS for a given frame index.
271 *
272 * \param frame_index frame index
273 * \return time [ns]
274 */
275 inline double getTimeSinceRTS(const unsigned int frame_index)
276 {
277 return std::fmod(getTimeOfFrame(frame_index), RESET_TIME_NS);
278 }
279
280
281 /**
282 * Get time in ns since last RTS for a given time in ns.
283 *
284 * \param t_ns time [ns]
285 * \return time [ns]
286 */
287 inline double getTimeSinceRTS(const double& t_ns)
288 {
289 return std::fmod(t_ns, RESET_TIME_NS);
290 }
291}
292
293namespace ANTARES {
294 /**
295 * Set clock.
296 */
297 inline void setClock()
298 {
300 }
301
303 using KM3NETDAQ::getRTS;
308}
309
310namespace KM3NET {
311 /**
312 * Set clock.
313 */
314 inline void setClock()
315 {
317 }
318
320 using KM3NETDAQ::getRTS;
325}
326
327#endif
Auxiliary class to set DAQ system clock parameters.
Definition JDAQClock.hh:27
friend std::ostream & operator<<(std::ostream &out, const JDAQClock &clock)
Write clock to output.
Definition JDAQClock.hh:133
friend std::istream & operator>>(std::istream &in, JDAQClock &clock)
Read clock from input.
Definition JDAQClock.hh:107
JDAQClock(const JDAQClock_t clock=KM3NET)
Constructor.
Definition JDAQClock.hh:40
JDAQClock_t get() const
Get clock type.
Definition JDAQClock.hh:53
JDAQClock_t
Clock types.
Definition JDAQClock.hh:32
void set()
Set DAQ clock parameters.
Definition JDAQClock.hh:75
void set(const JDAQClock_t clock)
Set clock type.
Definition JDAQClock.hh:64
General exception.
Name space for Antares.
Definition Jpp.hh:21
void setClock()
Set clock.
Definition JDAQClock.hh:297
bool operator==(const Head &first, const Head &second)
Equal operator.
Definition JHead.hh:1801
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
int getFrameIndex(const double t_ns)
Get frame index for a given time in ns.
Definition JDAQClock.hh:251
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
double getTimeOfFrame(const int frame_index)
Get start time of frame in ns since start of run for a given frame index.
Definition JDAQClock.hh:185
double getTimeSinceRTS(const int frame_index)
Get time in ns since last RTS for a given frame index.
Definition JDAQClock.hh:263
double getRTS()
Get TDC dynamic range.
Definition JDAQClock.hh:173
double getTimeOfRTS(const JDAQChronometer &chronometer)
Get time of last RTS in ns since start of run for a given chronometer.
Name space for KM3NeT.
Definition Jpp.hh:16