30 static_assert(!is_tick_v<electronics_time>);
31 static_assert( is_tick_v<electronics_tick>);
32 static_assert( is_tick_v<electronics_tick_d>);
33 static_assert( is_tick_v<electronics_time_ticks>);
34 static_assert( is_tick_v<electronics_time_ticks_d>);
35 static_assert(!is_tick_v<TPCelectronics_time>);
36 static_assert( is_tick_v<TPCelectronics_tick>);
37 static_assert( is_tick_v<TPCelectronics_tick_d>);
38 static_assert( is_tick_v<TPCelectronics_time_ticks>);
39 static_assert( is_tick_v<TPCelectronics_time_ticks_d>);
40 static_assert(!is_tick_v<trigger_time>);
41 static_assert( is_tick_v<trigger_tick>);
42 static_assert( is_tick_v<trigger_tick_d>);
43 static_assert( is_tick_v<trigger_time_ticks>);
44 static_assert( is_tick_v<trigger_time_ticks_d>);
45 static_assert(!is_tick_v<simulation_time>);
46 static_assert(!is_tick_v<optical_time>);
47 static_assert( is_tick_v<optical_tick>);
48 static_assert( is_tick_v<optical_tick_d>);
49 static_assert( is_tick_v<optical_time_ticks>);
50 static_assert( is_tick_v<optical_time_ticks_d>);
68 close_in_value(
double const a,
double const b)
70 return std::abs(a - b) < std::numeric_limits<double>::epsilon();
92 if (
time.value() == expectedTime) {
93 mf::LogVerbatim(
"DetectorTimingsStandard_test") <<
"DetectorTimings::TriggerTime() => " <<
time;
98 <<
"Trigger time expected to be " << expectedTime <<
" us in electronics time, but got " 99 <<
time <<
" instead";
120 if (close_in_value(
time.value(), expectedTime)) {
122 <<
"DetectorTimings::BeamGateTime() => " <<
time;
127 <<
"Beam gate time expected to be " << expectedTime <<
" us in electronics time, but got " 128 <<
time <<
" instead";
152 microsecond const expectedStartTime{expectedStartTime_us};
159 if (startTime == expectedStartTime) {
161 <<
"DetectorTimings::startTime<simulation_time>() => " << startTime;
166 <<
"Simulation time expected to start at " << expectedStartTime
167 <<
" in electronics time, but got " << startTime <<
" instead";
175 if (elecStartTime == -expectedStartTime) {
177 <<
"DetectorTimings::startTime<electronics_time, simulation_time>() => " << elecStartTime;
182 <<
"Electronics time expected to start at " << (-expectedStartTime)
183 <<
" in simulation time, but got " << elecStartTime <<
" instead";
191 double const inputTime_ns = 100.0;
201 if (
time.value() == expectedTime) {
203 <<
"DetectorTimings::toElectronicsTime<simulation_time>(" << inputTime <<
") => " <<
time;
208 <<
"A simulation time of " << inputTime <<
" is expected to be " << expectedTime
209 <<
" us in electronics time, but got " <<
time <<
" instead";
218 if (simulTime.value() == inputTime_ns) {
220 <<
"DetectorTimings::toTimeScale<electronics_time>(" << expectedTime <<
") => " << simulTime;
225 <<
"An electronics time of " << expectedTime <<
" us is expected to be " << inputTime
226 <<
" in simulation time, but got " << simulTime <<
" instead";
233 if (cmp.equal(TPCtick.value(), expectedTPCtick)) {
235 <<
"DetectorTimings::toTick<TPCelectronics_tick_d>(" << inputTime <<
") => " << TPCtick;
240 <<
"A simulation time of " << inputTime <<
" is expected to be at " << expectedTPCtick
241 <<
" TPC electronics tick, but got " << TPCtick <<
" instead";
255 if (simulTick == expectedSimulTick) {
257 <<
"DetectorTimings::toTimeScale<simulation_time>(" << trigTime <<
" + " << tickOffset
258 <<
" = " << tick <<
") => " << simulTick;
263 <<
"An offset of " << tickOffset <<
" on trigger time (" << trigTime <<
") is expected to be " 264 << expectedSimulTick <<
" in simulation time, but got " << simulTick <<
" instead";
291 if (startTime.value() == expectedStartTime) {
293 <<
"DetectorTimings::startTime<trigger_time>() => " << startTime;
298 <<
"Trigger time expected to start at " << expectedStartTime
299 <<
" us in electronics time, but got " << startTime <<
" instead";
307 if (elecStartTime.value() == -expectedStartTime) {
309 <<
"DetectorTimings::startTime<electronics_time, trigger_time>() => " << elecStartTime;
314 <<
"Electronics time expected to start at " << (-expectedStartTime)
315 <<
" us in trigger time, but got " << elecStartTime <<
" instead";
323 double const inputTime_us = 100.0;
333 if (
time.value() == expectedTime) {
335 <<
"DetectorTimings::toElectronicsTime<trigger_time>(" << inputTime <<
") => " <<
time;
340 <<
"A trigger time of " << inputTime <<
" is expected to be " << expectedTime
341 <<
" us in electronics time, but got " <<
time <<
" instead";
350 if (trigTime.value() == inputTime_us) {
352 <<
"DetectorTimings::toTriggerTime<electronics_time>(" << expectedTime <<
") => " << trigTime;
357 <<
"An electronics time of " << expectedTime <<
" us is expected to be " << inputTime
358 <<
" in trigger time, but got " << trigTime <<
" instead";
384 if (frequency.value() == expectedFrequency) {
386 <<
"DetectorTimings::OpticalClockFrequency() => " << frequency;
391 <<
"Optical clock frequency expected to be " << expectedFrequency <<
" MHz, but got " 392 << frequency <<
" instead";
401 if (period.value() == expectedPeriod) {
403 <<
"DetectorTimings::OpticalClockPeriod() => " << period;
408 <<
"Optical clock period expected to be " << expectedPeriod <<
" us, but got " << period
412 if (
std::abs(period.quantity() * frequency - 1.0) > 1
e-4) {
415 <<
"Optical clock period (" << period <<
") and frequency (" << frequency
416 <<
" should have been one the inverse of the other! (their product is " 417 << (period.quantity() * frequency) <<
")";
427 auto const expectedStartTime = 0_us;
433 if (startTime == expectedStartTime) {
435 <<
"DetectorTimings::startTime<optical_time>() => " << startTime;
440 <<
"Start of optical time scale is expected to be " << expectedStartTime
441 <<
" in electronics time, but got " << startTime <<
" instead";
451 if (trigStartTime == expectedTrigStartTime) {
453 <<
"DetectorTimings::startTime<optical_time, trigger_time>() => " << trigStartTime;
458 <<
"Start of optical time scale is expected to be " << expectedTrigStartTime
459 <<
" in trigger time, but got " << trigStartTime <<
" instead";
465 double const inputTick_count = 900.5;
478 if (
time.value() == expectedTime_us) {
480 <<
"DetectorTimings::toElectronicsTime<optical_tick_d>(" << inputTick_d <<
") => " <<
time;
485 <<
"Optical tick #" << inputTick_count <<
" is expected to be " << expectedTime_us
486 <<
" us in electronics time, but got " <<
time <<
" instead";
493 if (
tick == inputTick_d) {
495 <<
"DetectorTimings::toTick<optical_tick_d, " 503 <<
" is expected to be optical tick " << inputTick_d <<
", but got " <<
tick <<
" instead";
509 double const expectedTrigTime_truncated_us =
513 auto const inputTick = optical_tick::castFrom(inputTick_count);
520 if (trigTime.value() == expectedTrigTime_truncated_us) {
522 <<
"DetectorTimings::toTriggerTime<optical_tick>(" << inputTick <<
") => " << trigTime;
527 <<
"Optical tick " << inputTick <<
" is expected to be " << expectedTrigTime_truncated_us
528 <<
" us in trigger time, but got " << trigTime <<
" instead";
537 if (trigTick == inputTick) {
539 <<
"DetectorTimings::toTick<optical_tick, trigger_time>(" << expectedTrigTime_us <<
") => " 545 <<
"Trigger time " << expectedTrigTime_us <<
" us is expected to be optical tick " 546 << inputTick <<
", but got " << trigTick <<
" instead";
559 if (elecTick == expectedElecTick) {
561 <<
"DetectorTimings::toTick<electronics_tick>(" << inputTick <<
") => " 567 <<
"Optical tick #" << inputTick_count <<
" is expected to be " 568 << expectedElecTick <<
" (electronics tick), but got " 569 << elecTick <<
" instead";
582 if (tickFromElecTick == expectedOptTick) {
584 <<
"DetectorTimings::toTick<optical_tick, " 586 <<
">(" << elecTick <<
") => " << tickFromElecTick;
593 <<
" is expected to be optical tick " << expectedOptTick
594 <<
", but got " << tickFromElecTick <<
" instead";
601 double const inputInterval_us = 200.008;
615 <<
"DetectorTimings::toTicks<optical_time_ticks_d>(" << inputInterval <<
") => " <<
ticks_d;
620 <<
"Time interval " << inputInterval <<
" is expected to last " << expectedTicksD
621 <<
" optical ticks, but got " <<
ticks_d <<
" instead";
625 int const expectedTicks =
static_cast<int>(expectedTicksD);
632 <<
"DetectorTimings::toTicks<optical_time_ticks>(" << inputInterval <<
") => " <<
ticks;
637 <<
"Time interval " << inputInterval <<
" is expected to last " << expectedTicks
638 <<
" optical integer ticks, but got " <<
ticks <<
" instead";
677 std::cerr <<
"FHiCL configuration file path required as first argument!" <<
std::endl;
719 <<
"Electronics clock: " << timings.ClockPeriodFor<
electronics_time>() <<
", " 729 if (nErrors > 0) {
mf::LogError(
"clocks_test") << nErrors <<
" errors detected!"; }
731 return (nErrors > 0U)? 1: 0;
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
DetectorClocksData DataForJob() const override
Returns a complete detinfo::DetectorClocksData object.
unsigned int testOpticalClockTimings(detinfo::DetectorTimings const &timings)
electronics_time BeamGateTime() const
Dimensioned variables representing frequency quantities.
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
megahertz OpticalClockFrequency() const
Returns the frequency of the optical clock tick.
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Provides simple real number checks.
Ticks toTicks(time_interval time) const
Returns the number of ticks corresponding to a time interval.
trigger_time toTriggerTime(FromTime time) const
Converts a time point into trigger time scale.
detinfo::DetectorClocksData const & clockData() const
Returns the detector clocks data.
double TPCG4Time2Tick(double const g4time) const
Given G4 time returns electronics clock count [tdc].
Class holding a configuration for a test environment.
tick_d ticks_d
Alias for common language habits.
A collection of traits for a time scale.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
constexpr value_t value() const
Returns the value of the quantity.
unsigned int testBeamGateTime(detinfo::DetectorTimings const &timings)
Functions to help debugging by instrumenting code.
tick ticks
Alias for common language habits.
Class for approximate comparisons.
timescale_traits< OpticalTimeCategory >::tick_interval_d_t optical_time_ticks_d
constexpr double TickPeriod() const noexcept
A single tick period in microseconds.
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
timescale_traits< TPCelectronicsTimeCategory >::tick_d_t TPCelectronics_tick_d
A point on the TPC electronics time scale expressed in its ticks (real).
Interface to detinfo::DetectorClocks.
Helper functions for support of DetectorClocksService in LArSoft tests.
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
int main(int argc, char const **argv)
Runs the test.
detinfo::DetectorClocksWithUnits const & detClocksUnits() const
Returns a DetectorClocksWithUnits object.
timescale_traits< ElectronicsTimeCategory >::tick_interval_t electronics_time_ticks
An interval on the electronics time scale expressed in its ticks.
electronics_time toElectronicsTime(FromTime time) const
Converts a time point into electronics time scale.
time_interval_for< TimeScale > ClockPeriodFor() const
Returns the period of the clock for the specified time scale.
double BeamGateTime() const
Beam gate electronics clock time in [us].
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
A value measured in the specified unit.
simulation_time toSimulationTime(FromTime time) const
Converts a time point into simulation time scale.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
ElecClock const & OpticalClock() const noexcept
Borrow a const Optical clock with time set to Trigger time [us].
timescale_traits< OpticalTimeCategory >::time_point_t optical_time
A point in time on the optical detector electronics time scale.
unsigned int testSimulationTimes(detinfo::DetectorTimings const &timings)
An interval (duration, length, distance) between two quantity points.
unsigned int testTriggerTime(detinfo::DetectorTimings const &timings)
electronics_time TriggerTime() const
Literal constants for time quantities.
double TriggerTime() const
Trigger electronics clock time in [us].
Class used for the conversion of times between different formats and references.
A test environment with some support for service providers.
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
testing::TesterEnvironment< testing::BasicEnvironmentConfiguration > TestEnvironment
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
TargetTime toTimeScale(FromTime time) const
Returns a time point in a different time scale.
double G4ToElecTime(double const g4_time) const
TargetTick toTick(FromTime time) const
Returns a time point as a tick on a different time scale.
Dimensioned variables representing space or time quantities.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
unsigned int testTriggerTimes(detinfo::DetectorTimings const &timings)
constexpr double Frequency() const
Frequency in MHz.
timescale_traits< OpticalTimeCategory >::tick_d_t optical_tick_d
auto OpticalClockPeriod() const
Returns the duration of the optical clock period and tick.
microsecond TriggerTime() const
Equivalent to detinfo::DetectorClocksData::TriggerTime().
void SetServiceParameterSetPath(std::string service_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
void SetMainTesterParameterSetPath(std::string path)
Sets the FHiCL path for the configuration of the main test algorithm.
Namespace including different time scales as defined in LArSoft.
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.
QTextStream & endl(QTextStream &s)
constexpr TimeScale startTime() const
Returns the start time of the specified time scale.