Project
Loading...
Searching...
No Matches
testTimeStamp.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test TimeStamp class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
16#include <chrono>
17#include "Headers/TimeStamp.h"
18
19namespace o2
20{
21namespace header
22{
23
25{
26 // 32 bit number for the tick if the clock precision
27 // is on the orbit level
28 BOOST_CHECK(sizeof(LHCOrbitClock::rep) == 4);
29
30 float orbitPeriod = LHCOrbitClock::period::num;
31 orbitPeriod /= LHCOrbitClock::period::den;
32 BOOST_CHECK(orbitPeriod > 0.000085 && orbitPeriod < 0.000091);
33
34 // 64 bit number for the tick if the clock precision
35 // is on the bunch level
36 BOOST_CHECK(sizeof(LHCBunchClock::rep) == 8);
37
38 float bunchPeriod = LHCBunchClock::period::num;
39 bunchPeriod /= LHCBunchClock::period::den;
40 BOOST_CHECK(bunchPeriod > 0.0000000249 && bunchPeriod < 0.0000000251);
41
42 // duration comparison
43 LHCOrbitClock::duration fourOrbits(4);
44 BOOST_CHECK(fourOrbits == std::chrono::nanoseconds(4 * lhc_clock_parameter::gOrbitTimeNanoSec));
45}
46
47BOOST_AUTO_TEST_CASE(TimeStamp_test)
48{
49 // check the TimeStamp member layout with respect to manually
50 // assembled 64 bit field
51 // 'AC' (accelerator) specifies the LHCClock
52 // 40404040 orbits are almost 1h
53 // together with 1512 bunches we pass 1h
54 // TODO: extend from fixed values to random values
55 uint64_t bunches = 1512;
56 uint64_t orbits = 40404040;
57 uint64_t ts64 = String2<uint16_t>("AC") | bunches << 16 | orbits << 32;
58 TimeStamp timestamp("AC", orbits, bunches);
59
60 // using the type cast operator
61 BOOST_CHECK(ts64 == timestamp);
62
63 // checking cast to LHCClock
64 auto timeInLHCOrbitClock = timestamp.get<LHCOrbitClock>();
65 auto timeInLHCBunchClock = timestamp.get<LHCBunchClock>();
66 BOOST_CHECK(timeInLHCOrbitClock.count() == orbits);
67 BOOST_CHECK(timeInLHCOrbitClock == LHCOrbitClock::duration(orbits));
68
69 // time in LHCOrbitClock cuts off the bunches
70 BOOST_CHECK(timeInLHCOrbitClock <= timeInLHCBunchClock);
71
72 // get explicitely the time ignoring bunch counter and cast to seconds
73 // that must be less then 1h
74 auto timeInSeconds = std::chrono::duration_cast<std::chrono::seconds>(timestamp.get<LHCOrbitClock>());
75 BOOST_CHECK(timeInSeconds < std::chrono::hours(1));
76
77 // directly retrieving time in hours takes both orbits and bunches for
78 // internal calculation before casting to hours
79 auto timeInHours = timestamp.get<std::chrono::hours>();
80 BOOST_CHECK(timeInHours.count() == 1);
81
82 // setting timestamp with a value in unit mico seconds
83 uint64_t tenSeconds = 10000000;
84 timestamp = String2<uint16_t>("US") | tenSeconds << 32;
85
86 // check conversion of the us value to LHCClock
87 auto timeInOrbitPrecision = timestamp.get<LHCOrbitClock>();
88 auto timeInBunchPrecision = timestamp.get<LHCBunchClock>();
89 uint64_t expectedOrbits = tenSeconds * 1000 / (lhc_clock_parameter::gNumberOfBunches * lhc_clock_parameter::gBunchSpacingNanoSec);
90 BOOST_CHECK(timeInOrbitPrecision.count() == expectedOrbits);
91
92 // conversion in orbit precision ignores bunches
93 BOOST_CHECK(timeInOrbitPrecision <= timeInBunchPrecision);
94}
95} // namespace header
96} // namespace o2
std::vector< std::string > header
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
A std chrono implementation of LHC clock and timestamp.
std::chrono::duration< rep, period > duration
Definition TimeStamp.h:93
typename lhc_clock_parameter::Property< Precision >::rep rep
Definition TimeStamp.h:91
BOOST_AUTO_TEST_CASE(Descriptor_test)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK(tree)