LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ElecClock.h
Go to the documentation of this file.
1 
14 #ifndef ElecClock_H
15 #define ElecClock_H
16 
17 #include "ClockConstants.h"
19 
20 namespace detinfo {
91  class ElecClock{
92 
93  public:
94 
106 
114  ElecClock(double time, double frame_period, double frequency)
115  : fTime(time),
116  fFramePeriod(frame_period),
117  fFrequency(frequency)
118  {
119  if( fFrequency <= 0 ) throw detinfo::DetectorClocksException("Negative frequency is prohibited!");
120  }
121 
122  protected:
123 
124  //-- Attribute variables --//
125 
126  double fTime;
127  double fFramePeriod;
128  double fFrequency;
129 
130  public:
131 
132  //-- Setters --//
133 
138  void SetTime(double time) { fTime = time; }
139 
148  void SetTime(int sample,
149  int frame)
150  { fTime = Time(sample, frame); }
151 
160  void SetTime(unsigned int sample,
161  unsigned int frame)
162  { SetTime(int(sample),int(frame)); }
163 
171  void SetTime(int ticks)
172  { fTime = Time(ticks,0); }
173 
181  void SetTime(unsigned int ticks)
182  { SetTime(int(ticks)); }
183 
184  //-- Getters --//
185 
191  double Time() const { return fTime; }
192 
204  double Time(int sample, int frame) const { return (sample / fFrequency + frame * fFramePeriod); }
205 
215  double Time(double time) const { return Time(Sample(time),Frame(time)); }
216 
226  double Time(int ticks) const {return ticks/fFrequency; }
227 
229  double Frequency() const { return fFrequency; }
230 
232  double FramePeriod() const { return fFramePeriod; }
233 
235  int Ticks() const { return Ticks(fTime); }
236 
247  int Ticks(double time) const { return (int)(time * fFrequency); }
248 
260  int Ticks(int sample, int frame) const { return sample + frame * FrameTicks(); }
261 
271  int Sample() const { return Sample(fTime); }
272 
286  int Sample(double time) const { return (int)((time - Frame(time) * fFramePeriod) * fFrequency); }
287 
301  int Sample(int tick) const { return (tick % (int)(FrameTicks())); }
302 
310  int Frame() const { return Frame(fTime); }
311 
323  int Frame(double time) const { return (int)(time / fFramePeriod); }
324 
336  int Frame(int tick) const { return (tick / (int)(FrameTicks())); }
337 
339  unsigned int FrameTicks() const { return (int)(fFramePeriod * fFrequency);}
340 
342  double TickPeriod() const { return 1./fFrequency; }
343 
344 
345  //-- operators --//
346 
349 
351  ElecClock& operator++() { fTime += 1./fFrequency; return *this;}
352 
354  ElecClock operator++(int) {ElecClock tmp(*this); operator++(); return tmp;}
355 
357  ElecClock& operator--() { fTime -= 1./fFrequency; return *this;}
358 
360  ElecClock operator--(int) {ElecClock tmp(*this); operator--(); return tmp;}
361 
363  ElecClock& operator+=(const double &rhs) { fTime += rhs; return *this;}
365  ElecClock& operator-=(const double &rhs) { fTime -= rhs; return *this;}
366 
368  ElecClock& operator+=(const float &rhs) { fTime += (double)rhs; return *this;}
370  ElecClock& operator-=(const float &rhs) { fTime -= (double)rhs; return *this;}
371 
373  ElecClock& operator+=(const int &rhs) { fTime += Time(rhs); return *this;}
375  ElecClock& operator-=(const int &rhs) { fTime -= Time(rhs); return *this;}
376 
378  ElecClock& operator+=(const unsigned int &rhs) { fTime += Time((int)rhs); return *this;}
380  ElecClock& operator-=(const unsigned int &rhs) { fTime -= Time((int)rhs); return *this;}
381 
383  ElecClock& operator+=(const ElecClock& rhs) { fTime += rhs.Time(); return *this;}
384 
386  ElecClock& operator-=(const ElecClock& rhs) { fTime -= rhs.Time(); return *this;}
387 
390  inline ElecClock operator+(const ElecClock& rhs)
391  { return ElecClock(fTime + rhs.Time(),fFramePeriod,fFrequency); }
392 
395  inline ElecClock operator-(const ElecClock& rhs)
396  { return ElecClock(fTime - rhs.Time(),fFramePeriod,fFrequency); }
397 
399 
401  inline bool operator< (const ElecClock& rhs) const { return fTime < rhs.Time(); }
403  inline bool operator> (const ElecClock& rhs) const { return fTime > rhs.Time(); }
405  inline bool operator<= (const ElecClock& rhs) const { return fTime <= rhs.Time(); }
407  inline bool operator>= (const ElecClock& rhs) const { return fTime >= rhs.Time(); }
408 
409  }; // class ElecClock
410 
411 }
412 #endif
413  // end of doxygen group
414 
int Ticks(int sample, int frame) const
Returns the number of tick the specified sample falls in.
Definition: ElecClock.h:260
int Frame(double time) const
Returns the number of the frame containing the specified time.
Definition: ElecClock.h:323
bool operator<=(const ElecClock &rhs) const
Compares the current time of this clock with the one of rhs.
Definition: ElecClock.h:405
double Time(int ticks) const
Returns the absolute start time of the specified tick.
Definition: ElecClock.h:226
ElecClock & operator-=(const unsigned int &rhs)
Decreases the current clock time by the specified number of ticks.
Definition: ElecClock.h:380
double Time(double time) const
Returns the discretized value of the specified time.
Definition: ElecClock.h:215
int Sample(int tick) const
Returns the number of the sample containing the specified tick.
Definition: ElecClock.h:301
void SetTime(double time)
Directly sets the current time on the clock.
Definition: ElecClock.h:138
void SetTime(unsigned int sample, unsigned int frame)
Sets the current time on the clock from frame and sample number.
Definition: ElecClock.h:160
double Time(int sample, int frame) const
Returns the absolute time of the start of the specified sample.
Definition: ElecClock.h:204
void SetTime(unsigned int ticks)
Sets the current time on the clock from tick number.
Definition: ElecClock.h:181
bool operator<(const ElecClock &rhs) const
Compares the current time of this clock with the one of rhs.
Definition: ElecClock.h:401
ElecClock & operator-=(const float &rhs)
Decreases the current clock time by the specified time in microseconds.
Definition: ElecClock.h:370
int Ticks() const
Current clock tick (that is, the number of tick Time() falls in).
Definition: ElecClock.h:235
Float_t tmp
Definition: plot.C:37
Class def header for exception classes in DetectorClocks data provider.
ElecClock & operator+=(const unsigned int &rhs)
Increases the current clock time by the specified number of ticks.
Definition: ElecClock.h:378
void SetTime(int sample, int frame)
Sets the current time on the clock from frame and sample number.
Definition: ElecClock.h:148
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:128
int Frame(int tick) const
Returns the number of the frame containing the specified tick.
Definition: ElecClock.h:336
void SetTime(int ticks)
Sets the current time on the clock from tick number.
Definition: ElecClock.h:171
int Frame() const
Returns the number of the frame containing the clock current time.
Definition: ElecClock.h:310
ElecClock operator-(const ElecClock &rhs)
Definition: ElecClock.h:395
ElecClock operator++(int)
Increases the current clock time by a full tick time.
Definition: ElecClock.h:354
int Sample(double time) const
Returns the number of the sample containing the specified time.
Definition: ElecClock.h:286
ElecClock(double time, double frame_period, double frequency)
Constructor: sets all values.
Definition: ElecClock.h:114
General LArSoft Utilities.
ElecClock operator--(int)
Decreases the current clock time by a full tick time.
Definition: ElecClock.h:360
ElecClock & operator--()
Decreases the current clock time by a full tick time.
Definition: ElecClock.h:357
double fTime
Time in microseconds.
Definition: ElecClock.h:126
bool operator>(const ElecClock &rhs) const
Compares the current time of this clock with the one of rhs.
Definition: ElecClock.h:403
double FramePeriod() const
A single frame period in microseconds.
Definition: ElecClock.h:232
ElecClock & operator++()
Increases the current clock time by a full tick time.
Definition: ElecClock.h:351
ElecClock operator+(const ElecClock &rhs)
Definition: ElecClock.h:390
double TickPeriod() const
A single tick period in microseconds.
Definition: ElecClock.h:342
ElecClock & operator-=(const int &rhs)
Decreases the current clock time by the specified number of ticks.
Definition: ElecClock.h:375
ElecClock & operator+=(const float &rhs)
Increases the current clock time by the specified time in microseconds.
Definition: ElecClock.h:368
unsigned int FrameTicks() const
Number ticks in a frame.
Definition: ElecClock.h:339
ElecClock & operator-=(const double &rhs)
Decreases the current clock time by the specified time in microseconds.
Definition: ElecClock.h:365
ElecClock & operator+=(const ElecClock &rhs)
Increases the current clock time by the current time of another clock.
Definition: ElecClock.h:383
ElecClock & operator+=(const double &rhs)
Increases the current clock time by the specified time in microseconds.
Definition: ElecClock.h:363
double Time() const
Current time (as stored) in microseconds.
Definition: ElecClock.h:191
Class representing the time measured by an electronics clock.
Definition: ElecClock.h:91
bool operator>=(const ElecClock &rhs) const
Compares the current time of this clock with the one of rhs.
Definition: ElecClock.h:407
int Sample() const
Returns number of the sample containing the clock current time.
Definition: ElecClock.h:271
ElecClock()
Default constructor.
Definition: ElecClock.h:105
ElecClock & operator+=(const int &rhs)
Increases the current clock time by the specified number of ticks.
Definition: ElecClock.h:373
double Frequency() const
Frequency in MHz.
Definition: ElecClock.h:229
int Ticks(double time) const
Returns the number of tick the specified time falls in.
Definition: ElecClock.h:247
const double kTIME_MAX
Maximum time in microseconds.
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:127
ElecClock & operator-=(const ElecClock &rhs)
Decreases the current clock time by the current time of another clock.
Definition: ElecClock.h:386