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