Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQUTCExtended.hh
Go to the documentation of this file.
1 #ifndef __JDAQUTCEXTENDED__
2 #define __JDAQUTCEXTENDED__
3 
4 /**
5  * \author rbruijn
6  */
7 
8 #include <cstdint>
9 #include <istream>
10 #include <ostream>
11 #include <iomanip>
12 #include <limits>
13 
15 
16 
17 namespace KM3NETDAQ {
18 
19  /**
20  * Data structure for UTC time.
21  */
23  {
24  public:
25 
26  friend size_t getSizeof<JDAQUTCExtended>();
28  friend JWriter& operator<<(JWriter&, const JDAQUTCExtended&);
29 
30 
31  /**
32  * Default constructor.
33  */
35  UTC_seconds(0),
37  {}
38 
39 
40  /**
41  * Constructor.
42  *
43  * \param seconds seconds [s]
44  * \param cycles cycles [16 ns]
45  */
46  JDAQUTCExtended(const uint32_t seconds,
47  const uint32_t cycles):
48  UTC_seconds(seconds),
50  {}
51 
52 
53  /**
54  * Constructor.
55  *
56  * \param nanoseconds time [ns]
57  */
58  JDAQUTCExtended(const double nanoseconds)
59  {
60  setTimeNanoSecond(nanoseconds);
61  }
62 
63 
64  /**
65  * Virtual destructor.
66  */
67  virtual ~JDAQUTCExtended()
68  {}
69 
70 
71  /**
72  * Get White Rabbit status.
73  *
74  * \return true if okay; else false
75  */
76  bool getWRStatus() const
77  {
78  return (UTC_seconds & ~getMask()) != 0;
79  }
80 
81 
82  /**
83  * Get major time.
84  *
85  * \return time [s]
86  */
87  uint32_t getUTCseconds() const
88  {
89  return (UTC_seconds & getMask());
90  }
91 
92 
93  /**
94  * Get minor time.
95  *
96  * \return time [16 ns]
97  */
98  uint32_t getUTC16nanosecondcycles() const
99  {
100  return UTC_16nanosecondcycles;
101  }
102 
103 
104  /**
105  * Get time (limited to 16 ns cycles).
106  *
107  * \return time [ns]
108  */
109  double getTimeNanoSecond() const
110  {
111  return getUTCseconds() * 1.0e9 + getUTC16nanosecondcycles() * getTick();
112  }
113 
114 
115  /**
116  * Set time.
117  *
118  * \param utc_ns time [ns]
119  */
120  void setTimeNanoSecond(const double utc_ns)
121  {
122  UTC_seconds = (uint32_t) ( utc_ns * 1.0e-9);
123  UTC_16nanosecondcycles = (uint32_t) ((utc_ns - UTC_seconds*1.0e9) / getTick());
124  }
125 
126 
127  /**
128  * Add time.
129  *
130  * \param t_ns time [ns]
131  */
132  void addTimeNanoSecond(const double t_ns)
133  {
134  const double x_ns = (double) getUTC16nanosecondcycles() * (double) getTick() + t_ns;
135  const uint32_t t_s = (uint32_t) (x_ns * 1.0e-9);
136 
137  UTC_seconds += t_s;
138  UTC_16nanosecondcycles = (uint32_t) ((x_ns - t_s*1.0e9) / getTick());
139  }
140 
141 
142  /**
143  * Get minimum possible value.
144  *
145  * \return minimum possible value
146  */
148  {
149  return JDAQUTCExtended(0,0);
150  }
151 
152 
153  /**
154  * Get maximum possible value.
155  *
156  * \return maximum possible value
157  */
159  {
160  return JDAQUTCExtended(std::numeric_limits<uint32_t>::max(),
161  std::numeric_limits<uint32_t>::max());
162  }
163 
164 
165  /**
166  * Get mask for seconds data.
167  *
168  * \return mask
169  */
170  static uint32_t getMask()
171  {
172  return 0x7FFFFFFF;
173  }
174 
175 
176  /**
177  * Get number of nano-seconds per tick.
178  *
179  * \return time [ns]
180  */
181  static double getTick()
182  {
183  return 16.0;
184  }
185 
186 
187  /**
188  * Read UTC time.
189  *
190  * \param in intput stream
191  * \param utc UTC extended time
192  * \return intput stream
193  */
194  friend inline std::istream& operator>>(std::istream& in, JDAQUTCExtended& utc)
195  {
196  in >> utc.UTC_seconds;
197  in.get();
198  in >> utc.UTC_16nanosecondcycles;
199 
200  return in;
201  }
202 
203 
204  /**
205  * Write UTC time.
206  *
207  * \param out output stream
208  * \param utc UTC extended time
209  * \return output stream
210  */
211  friend inline std::ostream& operator<<(std::ostream& out, const JDAQUTCExtended& utc)
212  {
213  using namespace std;
214 
215  const char c = out.fill();
216 
217  out << setw(10) << utc.getUTCseconds();
218  out << ':';
219  out << setw(10) << setfill('0') << utc.getUTC16nanosecondcycles() << setfill(c);
220 
221  return out;
222  }
223 
224 
226 
227 
228  protected:
229  uint32_t UTC_seconds;
231  };
232 
233 
234  /**
235  * Less than operator for UTC times.
236  *
237  * \param first UTC time
238  * \param second UTC time
239  * \result true if first UTC time earlier than second UTC time; else false
240  */
241  inline bool operator<(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
242  {
243  if (first.getUTCseconds() == second.getUTCseconds())
244  return first.getUTC16nanosecondcycles() < second.getUTC16nanosecondcycles();
245  else
246  return first.getUTCseconds() < second.getUTCseconds();
247  }
248 
249 
250  /**
251  * Greater than operator for UTC times.
252  *
253  * \param first UTC time
254  * \param second UTC time
255  * \result true if first UTC time later than second UTC time; else false
256  */
257  inline bool operator>(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
258  {
259  return (second < first);
260  }
261 
262 
263  /**
264  * Less than or equal operator for UTC times.
265  *
266  * \param first UTC time
267  * \param second UTC time
268  * \result true if first UTC time earlier than second UTC time; else false
269  */
270  inline bool operator<=(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
271  {
272  return !(second < first);
273  }
274 
275 
276  /**
277  * Greater than or equal operator for UTC times.
278  *
279  * \param first UTC time
280  * \param second UTC time
281  * \result true if first UTC time earlier than second UTC time; else false
282  */
283  inline bool operator>=(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
284  {
285  return !(first < second);
286  }
287 
288 
289  /**
290  * Equal operator for UTC times.
291  *
292  * \param first UTC time
293  * \param second UTC time
294  * \result true if first UTC time equal second UTC time; else false
295  */
296  inline bool operator==(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
297  {
298  return (first.getUTCseconds() == second.getUTCseconds() &&
300  }
301 
302 
303  /**
304  * Not equal operator for UTC times.
305  *
306  * \param first UTC time
307  * \param second UTC time
308  * \result true if first UTC time not equal second UTC time; else false
309  */
310  inline bool operator!=(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
311  {
312  return !(first == second);
313  }
314 
315 
316  /**
317  * Get time difference between two UTC times.
318  *
319  * \param first UTC time
320  * \param second UTC time
321  * \result time difference [s]
322  */
323  inline double getTimeDifference(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
324  {
325  const double utc_s = ((double) second.getUTCseconds() - (double) first.getUTCseconds());
326  const double utc_ns = ((double) second.getUTC16nanosecondcycles() - (double) first.getUTC16nanosecondcycles()) * JDAQUTCExtended::getTick();
327 
328  return utc_s + utc_ns*1.0e-9;
329  }
330 }
331 
332 #endif
size_t getSizeof< JDAQUTCExtended >()
Get size of type.
static JDAQUTCExtended max()
Get maximum possible value.
uint32_t getUTC16nanosecondcycles() const
Get minor time.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Interface for binary output.
friend std::istream & operator>>(std::istream &in, JDAQUTCExtended &utc)
Read UTC time.
static JDAQUTCExtended min()
Get minimum possible value.
static double getTick()
Get number of nano-seconds per tick.
bool getWRStatus() const
Get White Rabbit status.
friend JReader & operator>>(JReader &, JDAQUTCExtended &)
Read UTC from input.
JDAQUTCExtended(const double nanoseconds)
Constructor.
Data structure for UTC time.
ClassDef(JDAQUTCExtended, 1)
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
uint32_t getUTCseconds() const
Get major time.
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
friend JWriter & operator<<(JWriter &, const JDAQUTCExtended &)
Write UTC to output.
void setTimeNanoSecond(const double utc_ns)
Set time.
JDAQUTCExtended(const uint32_t seconds, const uint32_t cycles)
Constructor.
Interface for binary input.
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
void addTimeNanoSecond(const double t_ns)
Add time.
bool operator>(const JDAQUTCExtended &first, const JDAQUTCExtended &second)
Greater than operator for UTC times.
static uint32_t getMask()
Get mask for seconds data.
bool operator>=(const JDAQUTCExtended &first, const JDAQUTCExtended &second)
Greater than or equal operator for UTC times.
JDAQUTCExtended()
Default constructor.
virtual ~JDAQUTCExtended()
Virtual destructor.
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:174
bool operator<=(const JDAQUTCExtended &first, const JDAQUTCExtended &second)
Less than or equal operator for UTC times.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
friend std::ostream & operator<<(std::ostream &out, const JDAQUTCExtended &utc)
Write UTC time.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).