1+ // Copyright 2019-2026 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+ #ifndef O2_TRACKINGITS_TIMEESTBC_H_
13+ #define O2_TRACKINGITS_TIMEESTBC_H_
14+
15+ #include < limits>
16+ #include < cstdint>
17+ #include " CommonDataFormat/TimeStamp.h"
18+ #include " GPUCommonRtypes.h"
19+ #include " GPUCommonDef.h"
20+ #include " GPUCommonMath.h"
21+
22+ namespace o2 ::its
23+ {
24+ // Time estimates are given in BC
25+ // error needs to cover maximum 1 orbit
26+ // this is an symmetric time error [t0-tE, t0+tE)
27+ using TimeStampType = uint32_t ;
28+ using TimeStampErrorType = uint16_t ;
29+ class TimeEstBC : public o2 ::dataformats::TimeStampWithError<TimeStampType, TimeStampErrorType>
30+ {
31+ public:
32+ using Base = o2::dataformats::TimeStampWithError<TimeStampType, TimeStampErrorType>;
33+ GPUhdDefault () TimeEstBC() = default ;
34+ GPUhdi () TimeEstBC(TimeStampType t, TimeStampErrorType e) : Base(t, e) {}
35+
36+ // check if timestamps overlap within their interval
37+ GPUhdi () bool isCompatible (const TimeEstBC& o) const noexcept
38+ {
39+ return !(upper () <= o.lower () || o.upper () <= lower ());
40+ }
41+
42+ GPUhdi () TimeEstBC& operator +=(const TimeEstBC& o) noexcept
43+ {
44+ add (o);
45+ return *this ;
46+ }
47+
48+ GPUhdi () TimeEstBC operator +(const TimeEstBC& o) const noexcept
49+ {
50+ TimeEstBC res = *this ;
51+ res += o;
52+ return res;
53+ }
54+
55+ private:
56+ // add the other timestmap to this one
57+ // this assumes already that both overlap
58+ GPUhdi () void add (const TimeEstBC& o) noexcept
59+ {
60+ const TimeStampType lo = o2::gpu::CAMath::Max (lower (), o.lower ());
61+ const TimeStampType hi = o2::gpu::CAMath::Min (upper (), o.upper ());
62+ const TimeStampType half = (hi - lo) / 2u ;
63+ this ->setTimeStamp (lo + half);
64+ this ->setTimeStampError (static_cast <TimeStampErrorType>(half));
65+ }
66+
67+ GPUhdi () TimeStampType upper () const noexcept
68+ {
69+ TimeStampType t = this ->getTimeStamp ();
70+ TimeStampType e = this ->getTimeStampError ();
71+ constexpr TimeStampType max = std::numeric_limits<TimeStampType>::max ();
72+ return (t > (max - e)) ? max : t + e;
73+ }
74+
75+ GPUhdi () TimeStampType lower () const noexcept
76+ {
77+ TimeStampType t = this ->getTimeStamp ();
78+ TimeStampType e = this ->getTimeStampError ();
79+ return (t > e) ? (t - e) : 0u ;
80+ }
81+
82+ ClassDefNV (TimeEstBC, 1 );
83+ };
84+ } // namespace o2::its
85+
86+ #endif
0 commit comments