Project
Loading...
Searching...
No Matches
Bracket.h
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
15
16#ifndef ALICEO2_BRACKET_H
17#define ALICEO2_BRACKET_H
18
19#include <GPUCommonRtypes.h>
20#ifndef GPUCA_ALIGPUCODE
21#include <string>
22#include <sstream>
23#endif
24
25namespace o2
26{
27namespace math_utils
28{
29namespace detail
30{
31
32template <typename T = float>
34{
35 public:
36 enum Relation : int { Below = -1,
37 Inside = 0,
38 Above = 1 };
39
40 Bracket(T minv, T maxv);
41 Bracket() = default;
42 Bracket(const Bracket<T>& src) = default;
43 Bracket(Bracket<T>&& src) = default;
44 Bracket& operator=(const Bracket<T>& src) = default;
46 ~Bracket() = default;
47
48 bool operator<(T other) const;
49 bool operator>(T other) const;
50
51 bool operator<(const Bracket<T>& other) const;
52 bool operator>(const Bracket<T>& other) const;
53 bool operator==(const Bracket<T>& other) const;
54 bool operator!=(const Bracket<T>& other) const;
55
56 void setMax(T v) noexcept;
57 void setMin(T v) noexcept;
58 void set(T minv, T maxv) noexcept;
59
62
63 T getMax() const;
64 T getMin() const;
65 T mean() const;
66 T delta() const;
67
69
70 void scale(T c);
71 bool isZeroLength() const;
72 bool isValid() const;
73 bool isInvalid() const;
74 void update(T v);
75 Relation isOutside(const Bracket<T>& t) const;
76 Relation isOutside(T t, T tErr) const;
78
79#ifndef GPUCA_ALIGPUCODE
80 std::string asString() const;
81#endif
82
83 private:
84 T mMin{};
85 T mMax{};
86
87 ClassDefNV(Bracket, 2);
88};
89
90template <typename T>
91Bracket<T>::Bracket(T minv, T maxv) : mMin(minv), mMax(maxv)
92{
93}
94
95template <typename T>
96inline bool Bracket<T>::operator<(T other) const
97{
98 return mMax < other;
99}
100
101template <typename T>
102inline bool Bracket<T>::operator>(T other) const
103{
104 return mMin > other;
105}
106
107template <typename T>
108inline bool Bracket<T>::operator<(const Bracket<T>& other) const
109{
110 return *this < other.mMin;
111}
112
113template <typename T>
114inline bool Bracket<T>::operator>(const Bracket<T>& other) const
115{
116 return *this > other.mMax;
117}
118
119template <typename T>
120inline bool Bracket<T>::operator==(const Bracket<T>& rhs) const
121{
122 return mMin == rhs.mMin && mMax == rhs.mMax;
123}
124
125template <typename T>
126inline bool Bracket<T>::operator!=(const Bracket<T>& rhs) const
127{
128 return !(*this == rhs);
129}
130
131template <typename T>
132inline void Bracket<T>::setMax(T v) noexcept
133{
134 mMax = v;
135}
136
137template <typename T>
138inline void Bracket<T>::setMin(T v) noexcept
139{
140 mMin = v;
141}
142
143template <typename T>
144inline void Bracket<T>::set(T minv, T maxv) noexcept
145{
146 this->setMin(minv);
147 this->setMax(maxv);
148}
149
150template <typename T>
152{
153 return mMax;
154}
155
156template <typename T>
158{
159 return mMin;
160}
161
162template <typename T>
163inline T Bracket<T>::getMax() const
164{
165 return mMax;
166}
167
168template <typename T>
169inline T Bracket<T>::getMin() const
170{
171 return mMin;
172}
173
174template <typename T>
175inline T Bracket<T>::mean() const
176{
177 return (mMin + mMax) / 2;
178}
179
180template <typename T>
181inline T Bracket<T>::delta() const
182{
183 return mMax - mMin;
184}
185
186template <typename T>
187inline bool Bracket<T>::isValid() const
188{
189 return mMax >= mMin;
190}
191
192template <typename T>
193inline bool Bracket<T>::isInvalid() const
194{
195 return mMin > mMax;
196}
197
198template <typename T>
199inline bool Bracket<T>::isZeroLength() const
200{
201 return mMin == mMax;
202}
203
204template <typename T>
206{
207 // update limits
208 if (v > mMax) {
209 mMax = v;
210 }
211 if (v < mMin) {
212 mMin = v;
213 }
214}
215
216template <typename T>
218{
219 mMin *= c;
220 mMax *= c;
221}
222
223template <typename T>
225{
226 return {getMin() > other.getMin() ? getMin() : other.getMin(), getMax() < other.getMax() ? getMax() : other.getMax()};
227}
228
229template <typename T>
231{
233 return t.mMax < mMin ? Below : (t.mMin > mMax ? Above : Inside);
234}
235
236template <typename T>
237inline typename Bracket<T>::Relation Bracket<T>::isOutside(T t, T tErr) const
238{
240 return t + tErr < mMin ? Below : (t - tErr > mMax ? Above : Inside);
241}
242
243template <typename T>
245{
247 return t < mMin ? Below : (t > mMax ? Above : Inside);
248}
249
250#ifndef GPUCA_ALIGPUCODE
251template <typename T>
252std::string Bracket<T>::asString() const
253{
254 std::stringstream tmp;
255 tmp << "[" << getMin() << ":" << getMax() << "]";
256 return tmp.str();
257}
258#endif
259
260} // namespace detail
261} // namespace math_utils
262} // namespace o2
263
264#endif
bool operator<(const Bracket< T > &other) const
Definition Bracket.h:108
bool operator<(T other) const
Definition Bracket.h:96
Bracket(const Bracket< T > &src)=default
Bracket getOverlap(const Bracket< T > &other) const
Definition Bracket.h:224
Relation isOutside(T t) const
Definition Bracket.h:244
void set(T minv, T maxv) noexcept
Definition Bracket.h:144
Relation isOutside(T t, T tErr) const
Definition Bracket.h:237
Bracket & operator=(Bracket< T > &&src)=default
bool operator!=(const Bracket< T > &other) const
Definition Bracket.h:126
Bracket & operator=(const Bracket< T > &src)=default
bool operator==(const Bracket< T > &other) const
Definition Bracket.h:120
Relation isOutside(const Bracket< T > &t) const
Definition Bracket.h:230
Bracket(Bracket< T > &&src)=default
std::string asString() const
Definition Bracket.h:252
bool operator>(T other) const
Definition Bracket.h:102
void setMax(T v) noexcept
Definition Bracket.h:132
bool operator>(const Bracket< T > &other) const
Definition Bracket.h:114
void setMin(T v) noexcept
Definition Bracket.h:138
GLenum src
Definition glcorearb.h:1767
const GLdouble * v
Definition glcorearb.h:832
D const SVectorGPU< T, D > & rhs
Definition SMatrixGPU.h:191
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
VectorOfTObjectPtrs other