LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
detinfo::ElecClock Class Reference

Class representing the time measured by an electronics clock. More...

#include "ElecClock.h"

Public Member Functions

 ElecClock (double const time, double const frame_period, double const frequency)
 Constructor: sets all values. More...
 
constexpr ElecClock WithTime (double const time) const noexcept
 
constexpr ElecClock WithTick (int const tick, int const frame=0) const noexcept
 
constexpr ElecClock AdvanceTimeBy (double const time) const noexcept
 
constexpr ElecClock AdvanceTicksBy (int const ticks) const noexcept
 
constexpr double Time () const noexcept
 Current time (as stored) in microseconds. More...
 
constexpr double Time (int const sample, int const frame) const noexcept
 Returns the absolute time of the start of the specified sample. More...
 
constexpr double Time (double const time) const noexcept
 Returns the discretized value of the specified time. More...
 
constexpr double Time (int const ticks) const noexcept
 Returns the absolute start time of the specified tick. More...
 
constexpr double Frequency () const
 Frequency in MHz. More...
 
constexpr double FramePeriod () const noexcept
 A single frame period in microseconds. More...
 
constexpr int Ticks () const noexcept
 Current clock tick (that is, the number of tick Time() falls in). More...
 
constexpr int Ticks (double const time) const noexcept
 Returns the number of tick the specified time falls in. More...
 
constexpr int Ticks (int const sample, int const frame) const noexcept
 Returns the number of tick the specified sample falls in. More...
 
constexpr int Sample () const noexcept
 Returns number of the sample containing the clock current time. More...
 
constexpr int Sample (double const time) const noexcept
 Returns the number of the sample containing the specified time. More...
 
constexpr int Sample (int const tick) const noexcept
 Returns the number of the sample containing the specified tick. More...
 
constexpr int Frame () const noexcept
 Returns the number of the frame containing the clock current time. More...
 
constexpr int Frame (double const time) const noexcept
 Returns the number of the frame containing the specified time. More...
 
constexpr int Frame (int const tick) const noexcept
 Returns the number of the frame containing the specified tick. More...
 
constexpr unsigned int FrameTicks () const noexcept
 Number ticks in a frame. More...
 
constexpr double TickPeriod () const noexcept
 A single tick period in microseconds. More...
 
constexpr bool operator< (const ElecClock &rhs) const noexcept
 
constexpr bool operator> (const ElecClock &rhs) const noexcept
 
constexpr bool operator<= (const ElecClock &rhs) const noexcept
 
constexpr bool operator>= (const ElecClock &rhs) const noexcept
 

Private Member Functions

constexpr ElecClock (double const time, double const frame_period, double const frequency, std::nothrow_t) noexcept
 

Private Attributes

double fTime {}
 Time in microseconds. More...
 
double fFramePeriod {kTIME_MAX}
 Frame period in microseconds. More...
 
double fFrequency {1e9}
 Clock speed in MHz. More...
 

Detailed Description

Class representing the time measured by an electronics clock.

This class represents the status of a running electronics clock. As such, it has:

  • tick frequency: how many times the clock ticks in one second
  • frame period: the duration of a single frame; clock time is organised into two levels:
    • the time is split into frames
    • each frame is split in samples; the first one of a each frame is sample number 0
  • current time of the clock, with respect to the time (always "0") the clock was started at

Note that this object is actually able to manage any (continuous) value of time, and the concepts of frame and sample are not used to store the clock state, which is instead defined by its current time.

All these quantities are stored in real time units as opposed to clock tick counts. The nominal units for all times and frequencies are microseconds and megahertz, respectively, but ElecClock will give consistent results as long as the units of frame period and time are the same, and reciprocal to the frequency unit.

The clock can update its time directly (SetTime()) or through operators.

The clock started at time 0, with the sample 0 of the frame 0 (that is also tick 0). This implies that all times and ticks returned by the clock implicitly have the same reference as the input time specified by the constructors or by the last call to SetTime().

Some usage examples:

// get a clock with a period of 500 ns (2 MHz) and a frame of 1.6 ms
detinfo::ElecClock clock(0.0, 1600.0, 2.0);
std::cout << "New clock:"
<< "\n current time: " << clock.Time() // 0.0 us
<< "\n samples per frame: " << clock.FrameTicks() // 3200
<< std::endl;
clock.SetTime(1, 20); // sets the time to sample #20 of frame 1
std::cout << "Time set to sample #20 of frame #1:"
<< "\n current time: " << clock.Time() // 1610.0 us
<< "\n current tick: " << clock.Tick() // 3220
<< std::endl;
clock += 3.7; // add 3.7 us to the current time
std::cout << "Added 3.7 microseconds:"
<< "\n current time: " << clock.Time() // 1613.7 us
<< "\n current tick: " << clock.Tick() // 3227
<< "\n discrete time: " << clock.Time(Time()) // 1613.5 us
<< std::endl;
clock += 3; // add 3 more ticks (1.5 us) to the current time
std::cout << "Added 3 ticks:"
<< "\n current time: " << clock.Time() // 1615.2 us
<< "\n current tick: " << clock.Tick() // 3230
<< "\n discrete time: " << clock.Time(Time()) // 1615.0 us
<< std::endl;
Note
Most methods and operators have different behaviour according to whether their argument is of type double, in which case it is interpreted as a time, or int, where it is interpreted as a clock tick. Be especially careful when utilizing data types which are neither int not double, because a conversion to one of them will occur, and you need to be in control of which one.

Definition at line 91 of file ElecClock.h.

Constructor & Destructor Documentation

detinfo::ElecClock::ElecClock ( double const  time,
double const  frame_period,
double const  frequency 
)
inline

Constructor: sets all values.

Parameters
timestarting time of the clock [µs]
frame_periodperiod of the clock [µs]
frequencyclock frequency [MHz]

Definition at line 100 of file ElecClock.h.

References fFrequency.

101  : ElecClock{time, frame_period, frequency, std::nothrow}
102  {
103  if (fFrequency <= 0)
104  throw detinfo::DetectorClocksException("Only positive frequency allowed.");
105  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
ElecClock(double const time, double const frame_period, double const frequency)
Constructor: sets all values.
Definition: ElecClock.h:100
constexpr detinfo::ElecClock::ElecClock ( double const  time,
double const  frame_period,
double const  frequency,
std::nothrow_t   
)
inlineprivatenoexcept

Definition at line 320 of file ElecClock.h.

324  : fTime(time), fFramePeriod(frame_period), fFrequency(frequency)
325  {}
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fTime
Time in microseconds.
Definition: ElecClock.h:327
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328

Member Function Documentation

constexpr ElecClock detinfo::ElecClock::AdvanceTicksBy ( int const  ticks) const
inlinenoexcept

Definition at line 122 of file ElecClock.h.

References fFramePeriod, fFrequency, fTime, and Time().

123  {
124  return {fTime + Time(ticks), fFramePeriod, fFrequency, std::nothrow};
125  }
tick ticks
Alias for common language habits.
Definition: electronics.h:76
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
constexpr double Time() const noexcept
Current time (as stored) in microseconds.
Definition: ElecClock.h:132
double fTime
Time in microseconds.
Definition: ElecClock.h:327
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr ElecClock detinfo::ElecClock::AdvanceTimeBy ( double const  time) const
inlinenoexcept

Definition at line 117 of file ElecClock.h.

References fFramePeriod, fFrequency, and fTime.

118  {
119  return {fTime + time, fFramePeriod, fFrequency, std::nothrow};
120  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fTime
Time in microseconds.
Definition: ElecClock.h:327
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr int detinfo::ElecClock::Frame ( ) const
inlinenoexcept

Returns the number of the frame containing the clock current time.

See also
Frame(double)

The returned value is the number of the frame which the current clock time falls in.

Definition at line 269 of file ElecClock.h.

References Frame(), and fTime.

Referenced by opdet::ConstructFlash(), opdet::ConstructHit(), Frame(), Sample(), and Time().

269 { return Frame(fTime); }
constexpr int Frame() const noexcept
Returns the number of the frame containing the clock current time.
Definition: ElecClock.h:269
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr int detinfo::ElecClock::Frame ( double const  time) const
inlinenoexcept

Returns the number of the frame containing the specified time.

Parameters
timea clock time [µs]
Returns
number of the frame containing the specified time
See also
Sample(double)

The returned value is the number of the frame which the specified time falls in.

The result is not related to the current time of the clock.

Definition at line 282 of file ElecClock.h.

References fFramePeriod.

283  {
284  return static_cast<int>(time / fFramePeriod);
285  }
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr int detinfo::ElecClock::Frame ( int const  tick) const
inlinenoexcept

Returns the number of the frame containing the specified tick.

Parameters
ticka clock tick number
Returns
number of the frame containing the specified tick
See also
Frame(int)

The returned value is the number of the frame the specified tick belongs to.

The result is not related to the current time of the clock.

Definition at line 298 of file ElecClock.h.

References FrameTicks().

299  {
300  return (tick / static_cast<int>(FrameTicks()));
301  }
constexpr unsigned int FrameTicks() const noexcept
Number ticks in a frame.
Definition: ElecClock.h:304
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
constexpr double detinfo::ElecClock::FramePeriod ( ) const
inlinenoexcept

A single frame period in microseconds.

Definition at line 179 of file ElecClock.h.

References fFramePeriod.

179 { return fFramePeriod; }
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr unsigned int detinfo::ElecClock::FrameTicks ( ) const
inlinenoexcept

Number ticks in a frame.

Definition at line 304 of file ElecClock.h.

References fFramePeriod, and fFrequency.

Referenced by Frame(), Sample(), and Ticks().

305  {
306  return static_cast<unsigned int>(fFramePeriod * fFrequency);
307  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr double detinfo::ElecClock::Frequency ( ) const
inline
constexpr bool detinfo::ElecClock::operator< ( const ElecClock rhs) const
inlinenoexcept

Definition at line 314 of file ElecClock.h.

References fTime.

314 { return fTime < rhs.Time(); }
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr bool detinfo::ElecClock::operator<= ( const ElecClock rhs) const
inlinenoexcept

Definition at line 316 of file ElecClock.h.

References fTime.

316 { return fTime <= rhs.Time(); }
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr bool detinfo::ElecClock::operator> ( const ElecClock rhs) const
inlinenoexcept

Definition at line 315 of file ElecClock.h.

References fTime.

315 { return fTime > rhs.Time(); }
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr bool detinfo::ElecClock::operator>= ( const ElecClock rhs) const
inlinenoexcept

Definition at line 317 of file ElecClock.h.

References fTime.

317 { return fTime >= rhs.Time(); }
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr int detinfo::ElecClock::Sample ( ) const
inlinenoexcept

Returns number of the sample containing the clock current time.

See also
Sample(double)

The returned value is the number of the sample within a frame, which the current clock time falls in. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame().

Definition at line 224 of file ElecClock.h.

References fTime, and Sample().

Referenced by Sample(), and Time().

224 { return Sample(fTime); }
constexpr int Sample() const noexcept
Returns number of the sample containing the clock current time.
Definition: ElecClock.h:224
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr int detinfo::ElecClock::Sample ( double const  time) const
inlinenoexcept

Returns the number of the sample containing the specified time.

Parameters
timea clock time [µs]
Returns
number of the sample containing the specified time
See also
Frame(double)

The returned value is the number of the sample within a frame, which the specified time falls in. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame(double).

The result is not related to the current time of the clock.

Definition at line 239 of file ElecClock.h.

References fFramePeriod, fFrequency, and Frame().

240  {
241  return static_cast<int>((time - Frame(time) * fFramePeriod) * fFrequency);
242  }
constexpr int Frame() const noexcept
Returns the number of the frame containing the clock current time.
Definition: ElecClock.h:269
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr int detinfo::ElecClock::Sample ( int const  tick) const
inlinenoexcept

Returns the number of the sample containing the specified tick.

Parameters
ticka clock tick number
Returns
number of the sample containing the specified tick
See also
Frame(int)

The returned value is the number of the sample within a frame, of the specified tick. The number of the frame is not returned. To univocally define the sample, the number of the frame must also be obtained, e.g. via Frame(int).

The result is not related to the current time of the clock.

Definition at line 257 of file ElecClock.h.

References FrameTicks().

258  {
259  return (tick % static_cast<int>(FrameTicks()));
260  }
constexpr unsigned int FrameTicks() const noexcept
Number ticks in a frame.
Definition: ElecClock.h:304
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
constexpr int detinfo::ElecClock::Ticks ( ) const
inlinenoexcept

Current clock tick (that is, the number of tick Time() falls in).

Definition at line 182 of file ElecClock.h.

References fTime, and Ticks().

Referenced by detinfo::DetectorClocksData::ExternalTick2TDC(), detinfo::DetectorClocksData::OpticalTick2TDC(), Ticks(), and detinfo::trigger_offset().

182 { return Ticks(fTime); }
constexpr int Ticks() const noexcept
Current clock tick (that is, the number of tick Time() falls in).
Definition: ElecClock.h:182
double fTime
Time in microseconds.
Definition: ElecClock.h:327
constexpr int detinfo::ElecClock::Ticks ( double const  time) const
inlinenoexcept

Returns the number of tick the specified time falls in.

Parameters
timetime to be converted in ticks [µs]
Returns
the number of the tick containing the specified time

The tick number 0 starts at time 0.0 µs.

Note
The returned value (number of tick) can wrap if the real number of the tick is beyond the range of the returned data type (int).

Definition at line 194 of file ElecClock.h.

References fFrequency.

195  {
196  return static_cast<int>(time * fFrequency);
197  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
constexpr int detinfo::ElecClock::Ticks ( int const  sample,
int const  frame 
) const
inlinenoexcept

Returns the number of tick the specified sample falls in.

Parameters
samplenumber of sample in the specified frame
framenumber of frame the specified sample is in
Returns
the number of the tick containing the specified sample

The sample 0 of frame 0 is the tick number 0.

Note
The returned value (number of tick) can wrap if the real number of the tick is beyond the range of the returned data type (int).

Definition at line 210 of file ElecClock.h.

References FrameTicks().

211  {
212  return sample + frame * FrameTicks();
213  }
constexpr unsigned int FrameTicks() const noexcept
Number ticks in a frame.
Definition: ElecClock.h:304
constexpr double detinfo::ElecClock::Time ( ) const
inlinenoexcept
constexpr double detinfo::ElecClock::Time ( int const  sample,
int const  frame 
) const
inlinenoexcept

Returns the absolute time of the start of the specified sample.

Parameters
samplesample number within the specified frame
framenumber of the frame the specified sample is in
Returns
time [us] corresponding to the start of the specified sample

The sample number is not checked to be actually within the specified frame.

The returned time is not related to the current time of the clock.

Definition at line 145 of file ElecClock.h.

References fFramePeriod, and fFrequency.

146  {
147  return (sample / fFrequency + frame * fFramePeriod);
148  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr double detinfo::ElecClock::Time ( double const  time) const
inlinenoexcept

Returns the discretized value of the specified time.

Parameters
timea clock time [µs]
Returns
discretized time [µs] (as a floating point number)

The returned time is the start time of the sample time falls in.

It is not related to the current time of the clock.

Definition at line 159 of file ElecClock.h.

References Frame(), Sample(), and Time().

160  {
161  return Time(Sample(time), Frame(time));
162  }
constexpr int Frame() const noexcept
Returns the number of the frame containing the clock current time.
Definition: ElecClock.h:269
constexpr int Sample() const noexcept
Returns number of the sample containing the clock current time.
Definition: ElecClock.h:224
constexpr double Time() const noexcept
Current time (as stored) in microseconds.
Definition: ElecClock.h:132
constexpr double detinfo::ElecClock::Time ( int const  ticks) const
inlinenoexcept

Returns the absolute start time of the specified tick.

Parameters
ticksa clock time [µs]
Returns
discretized time [µs] (as a floating point number)

The returned time is the start time of the tick which time falls in.

It is not related to the current time of the clock.

Definition at line 173 of file ElecClock.h.

References fFrequency.

173 { return ticks / fFrequency; }
tick ticks
Alias for common language habits.
Definition: electronics.h:76
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
constexpr ElecClock detinfo::ElecClock::WithTick ( int const  tick,
int const  frame = 0 
) const
inlinenoexcept

Definition at line 112 of file ElecClock.h.

References fFramePeriod, fFrequency, and Time().

113  {
114  return {Time(tick, frame), fFramePeriod, fFrequency, std::nothrow};
115  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:73
constexpr double Time() const noexcept
Current time (as stored) in microseconds.
Definition: ElecClock.h:132
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328
constexpr ElecClock detinfo::ElecClock::WithTime ( double const  time) const
inlinenoexcept

Definition at line 107 of file ElecClock.h.

References fFramePeriod, and fFrequency.

108  {
109  return {time, fFramePeriod, fFrequency, std::nothrow};
110  }
double fFrequency
Clock speed in MHz.
Definition: ElecClock.h:329
double fFramePeriod
Frame period in microseconds.
Definition: ElecClock.h:328

Member Data Documentation

double detinfo::ElecClock::fFramePeriod {kTIME_MAX}
private

Frame period in microseconds.

Definition at line 328 of file ElecClock.h.

Referenced by AdvanceTicksBy(), AdvanceTimeBy(), Frame(), FramePeriod(), FrameTicks(), Sample(), Time(), WithTick(), and WithTime().

double detinfo::ElecClock::fFrequency {1e9}
private

Clock speed in MHz.

Definition at line 329 of file ElecClock.h.

Referenced by AdvanceTicksBy(), AdvanceTimeBy(), ElecClock(), FrameTicks(), Frequency(), Sample(), TickPeriod(), Ticks(), Time(), WithTick(), and WithTime().

double detinfo::ElecClock::fTime {}
private

Time in microseconds.

Definition at line 327 of file ElecClock.h.

Referenced by AdvanceTicksBy(), AdvanceTimeBy(), Frame(), operator<(), operator<=(), operator>(), operator>=(), Sample(), Ticks(), and Time().


The documentation for this class was generated from the following file: