Jpp  15.0.1-rc.1-highQE
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 time.
75  *
76  * \return time [s]
77  */
79  {
80  return (UTC_seconds & getMask());
81  }
82 
83 
84  /**
85  * Get time.
86  *
87  * \return time [16 ns]
88  */
90  {
92  }
93 
94 
95  /**
96  * Get time (limited to 16 ns cycles).
97  *
98  * \return time [ns]
99  */
100  double getTimeNanoSecond() const
101  {
102  return getUTCseconds() * 1.0e9 + getUTC16nanosecondcycles() * getTick();
103  }
104 
105 
106  /**
107  * Set time.
108  *
109  * \param utc_ns time [ns]
110  */
111  void setTimeNanoSecond(const double utc_ns)
112  {
113  UTC_seconds = (unsigned int) ( utc_ns / 1.0e9);
114  UTC_16nanosecondcycles = (unsigned int) ((utc_ns - UTC_seconds*1.0e9) / getTick());
115  }
116 
117 
118  /**
119  * Get minimum possible value.
120  *
121  * \return minimum possible value
122  */
124  {
125  return JDAQUTCExtended(0,0);
126  }
127 
128 
129  /**
130  * Get maximum possible value.
131  *
132  * \return maximum possible value
133  */
135  {
136  return JDAQUTCExtended(std::numeric_limits<JUINT32_t>::max(),
137  std::numeric_limits<JUINT32_t>::max());
138  }
139 
140 
141  /**
142  * Get mask for seconds data.
143  *
144  * \return mask
145  */
146  static JUINT32_t getMask()
147  {
148  return 0x7FFFFFFF;
149  }
150 
151 
152  /**
153  * Get number of nano-seconds per tick.
154  *
155  * \return time [ns]
156  */
157  static double getTick()
158  {
159  return 16.0;
160  }
161 
162 
163  /**
164  * Read UTC time.
165  *
166  * \param in intput stream
167  * \param utc UTC extended time
168  * \return intput stream
169  */
170  friend inline std::istream& operator>>(std::istream& in, JDAQUTCExtended& utc)
171  {
172  in >> utc.UTC_seconds;
173  in.get();
174  in >> utc.UTC_16nanosecondcycles;
175 
176  return in;
177  }
178 
179 
180  /**
181  * Write UTC time.
182  *
183  * \param out output stream
184  * \param utc UTC extended time
185  * \return output stream
186  */
187  friend inline std::ostream& operator<<(std::ostream& out, const JDAQUTCExtended& utc)
188  {
189  using namespace std;
190 
191  const char c = out.fill();
192 
193  out << setw(10) << utc.getUTCseconds();
194  out << ':';
195  out << setw(10) << setfill('0') << utc.getUTC16nanosecondcycles() << setfill(c);
196 
197  return out;
198  }
199 
200 
202 
203 
204  protected:
207  };
208 
209 
210  /**
211  * Less than operator for UTC times.
212  *
213  * \param first UTC time
214  * \param second UTC time
215  * \result true if first UTC time earlier than second UTC time; else false
216  */
217  inline bool operator<(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
218  {
219  if (first.getUTCseconds() == second.getUTCseconds())
220  return first.getUTC16nanosecondcycles() < second.getUTC16nanosecondcycles();
221  else
222  return first.getUTCseconds() < second.getUTCseconds();
223  }
224 
225 
226  /**
227  * Equal operator for UTC times.
228  *
229  * \param first UTC time
230  * \param second UTC time
231  * \result true if first UTC time equal second UTC time; else false
232  */
233  inline bool operator==(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
234  {
235  return (first.getUTCseconds() == second.getUTCseconds() &&
237  }
238 
239 
240  /**
241  * Not equal operator for UTC times.
242  *
243  * \param first UTC time
244  * \param second UTC time
245  * \result true if first UTC time not equal second UTC time; else false
246  */
247  inline bool operator!=(const JDAQUTCExtended& first, const JDAQUTCExtended& second)
248  {
249  return !(first == second);
250  }
251 }
252 
253 #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.
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
friend JWriter & operator<<(JWriter &, const JDAQUTCExtended &)
Write UTC to output.
JUINT32_t getUTC16nanosecondcycles() const
Get 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 time.
static JUINT32_t getMask()
Get mask for seconds data.
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
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
friend std::ostream & operator<<(std::ostream &out, const JDAQUTCExtended &utc)
Write UTC time.
double getTimeNanoSecond() const
Get time (limited to 16 ns cycles).