Jpp  18.1.0
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> // only in C++0x, will give uint32_t
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  typedef unsigned int JUINT32_t; // preferably uint32_t
27 
28  friend size_t getSizeof<JDAQUTCExtended>();
30  friend JWriter& operator<<(JWriter&, const JDAQUTCExtended&);
31 
32 
33  /**
34  * Default constructor.
35  */
37  UTC_seconds(0),
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param seconds seconds [s]
46  * \param cycles cycles [16 ns]
47  */
48  JDAQUTCExtended(const JUINT32_t seconds,
49  const JUINT32_t cycles):
50  UTC_seconds(seconds),
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param nanoseconds time [ns]
59  */
60  JDAQUTCExtended(const double nanoseconds)
61  {
62  setTimeNanoSecond(nanoseconds);
63  }
64 
65 
66  /**
67  * Virtual destructor.
68  */
69  virtual ~JDAQUTCExtended()
70  {}
71 
72 
73  /**
74  * Get White Rabbit status.
75  *
76  * \return true if okay; else false
77  */
78  bool getWRStatus() const
79  {
80  return (UTC_seconds & ~getMask()) != 0;
81  }
82 
83 
84  /**
85  * Get major time.
86  *
87  * \return time [s]
88  */
90  {
91  return (UTC_seconds & getMask());
92  }
93 
94 
95  /**
96  * Get minor time.
97  *
98  * \return time [16 ns]
99  */
101  {
102  return UTC_16nanosecondcycles;
103  }
104 
105 
106  /**
107  * Get time (limited to 16 ns cycles).
108  *
109  * \return time [ns]
110  */
111  double getTimeNanoSecond() const
112  {
113  return getUTCseconds() * 1.0e9 + getUTC16nanosecondcycles() * getTick();
114  }
115 
116 
117  /**
118  * Set time.
119  *
120  * \param utc_ns time [ns]
121  */
122  void setTimeNanoSecond(const double utc_ns)
123  {
124  UTC_seconds = (unsigned int) ( utc_ns / 1.0e9);
125  UTC_16nanosecondcycles = (unsigned int) ((utc_ns - UTC_seconds*1.0e9) / getTick());
126  }
127 
128 
129  /**
130  * Get minimum possible value.
131  *
132  * \return minimum possible value
133  */
135  {
136  return JDAQUTCExtended(0,0);
137  }
138 
139 
140  /**
141  * Get maximum possible value.
142  *
143  * \return maximum possible value
144  */
146  {
147  return JDAQUTCExtended(std::numeric_limits<JUINT32_t>::max(),
148  std::numeric_limits<JUINT32_t>::max());
149  }
150 
151 
152  /**
153  * Get mask for seconds data.
154  *
155  * \return mask
156  */
157  static JUINT32_t getMask()
158  {
159  return 0x7FFFFFFF;
160  }
161 
162 
163  /**
164  * Get number of nano-seconds per tick.
165  *
166  * \return time [ns]
167  */
168  static double getTick()
169  {
170  return 16.0;
171  }
172 
173 
174  /**
175  * Read UTC time.
176  *
177  * \param in intput stream
178  * \param utc UTC extended time
179  * \return intput stream
180  */
181  friend inline std::istream& operator>>(std::istream& in, JDAQUTCExtended& utc)
182  {
183  in >> utc.UTC_seconds;
184  in.get();
185  in >> utc.UTC_16nanosecondcycles;
186 
187  return in;
188  }
189 
190 
191  /**
192  * Write UTC time.
193  *
194  * \param out output stream
195  * \param utc UTC extended time
196  * \return output stream
197  */
198  friend inline std::ostream& operator<<(std::ostream& out, const JDAQUTCExtended& utc)
199  {
200  using namespace std;
201 
202  const char c = out.fill();
203 
204  out << setw(10) << utc.getUTCseconds();
205  out << ':';
206  out << setw(10) << setfill('0') << utc.getUTC16nanosecondcycles() << setfill(c);
207 
208  return out;
209  }
210 
211 
213 
214 
215  protected:
218  };
219 
220 
221  /**
222  * Less than operator for UTC times.
223  *
224  * \param first UTC time
225  * \param second UTC time
226  * \result true if first UTC time earlier than second UTC time; else false
227  */
228  inline bool operator<(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
229  {
230  if (first.getUTCseconds() == second.getUTCseconds())
231  return first.getUTC16nanosecondcycles() < second.getUTC16nanosecondcycles();
232  else
233  return first.getUTCseconds() < second.getUTCseconds();
234  }
235 
236 
237  /**
238  * Greater than operator for UTC times.
239  *
240  * \param first UTC time
241  * \param second UTC time
242  * \result true if first UTC time later than second UTC time; else false
243  */
244  inline bool operator>(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
245  {
246  return (second < first);
247  }
248 
249 
250  /**
251  * Less than or equal operator for UTC times.
252  *
253  * \param first UTC time
254  * \param second UTC time
255  * \result true if first UTC time earlier 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  * Greater 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 !(first < second);
273  }
274 
275 
276  /**
277  * Equal operator for UTC times.
278  *
279  * \param first UTC time
280  * \param second UTC time
281  * \result true if first UTC time equal second UTC time; else false
282  */
283  inline bool operator==(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
284  {
285  return (first.getUTCseconds() == second.getUTCseconds() &&
287  }
288 
289 
290  /**
291  * Not equal operator for UTC times.
292  *
293  * \param first UTC time
294  * \param second UTC time
295  * \result true if first UTC time not equal second UTC time; else false
296  */
297  inline bool operator!=(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
298  {
299  return !(first == second);
300  }
301 
302 
303  /**
304  * Get time difference between two UTC times.
305  *
306  * \param first UTC time
307  * \param second UTC time
308  * \result time difference [s]
309  */
310  inline double getTimeDifference(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
311  {
312  const double utc_s = ((double) second.getUTCseconds() - (double) first.getUTCseconds());
313  const double utc_ns = ((double) second.getUTC16nanosecondcycles() - (double) first.getUTC16nanosecondcycles()) * JDAQUTCExtended::getTick();
314 
315  return utc_s + utc_ns*1.0e-9;
316  }
317 }
318 
319 #endif
size_t getSizeof< JDAQUTCExtended >()
Get size of type.
static JDAQUTCExtended max()
Get maximum possible value.
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
double getTimeDifference(const JDAQChronometer &first, const JDAQChronometer &second)
Get time difference between two chronometers.
friend JWriter & operator<<(JWriter &, const JDAQUTCExtended &)
Write UTC to output.
JUINT32_t getUTC16nanosecondcycles() const
Get minor time.
JDAQUTCExtended(const JUINT32_t seconds, const JUINT32_t cycles)
Constructor.
void setTimeNanoSecond(const double utc_ns)
Set time.
Interface for binary input.
JUINT32_t getUTCseconds() const
Get major time.
$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 &))'
static JUINT32_t getMask()
Get mask for seconds data.
bool operator>(const JDAQUTCExtended &first, const JDAQUTCExtended &second)
Greater than operator for UTC times.
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:46
friend std::ostream & operator<<(std::ostream &out, const JDAQUTCExtended &utc)
Write UTC time.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).