1616#define ALICEO2_BRACKET_H
1717
1818#include < GPUCommonRtypes.h>
19+ #ifndef GPUCA_ALIGPUCODE
20+ #include < fmt/format.h>
21+ #include < string>
22+ #endif
1923
2024namespace o2
2125{
@@ -60,18 +64,20 @@ class Bracket
6064 T mean () const ;
6165 T delta () const ;
6266
63- void scale (T c)
64- {
65- mMin *= c;
66- mMax *= c;
67- }
67+ Bracket getOverlap (const Bracket<T>& other) const ;
6868
69+ void scale (T c);
70+ bool isZeroLength () const ;
6971 bool isValid () const ;
7072 bool isInvalid () const ;
7173 void update (T v);
7274 Relation isOutside (const Bracket<T>& t) const ;
7375 Relation isOutside (T t, T tErr) const ;
7476
77+ #ifndef GPUCA_ALIGPUCODE
78+ std::string asString () const ;
79+ #endif
80+
7581 private:
7682 T mMin {};
7783 T mMax {};
@@ -168,21 +174,31 @@ inline T Bracket<T>::mean() const
168174{
169175 return (mMin + mMax ) / 2 ;
170176}
177+
171178template <typename T>
172179inline T Bracket<T>::delta() const
173180{
174181 return mMax - mMin ;
175182}
183+
176184template <typename T>
177185inline bool Bracket<T>::isValid() const
178186{
179187 return mMax >= mMin ;
180188}
189+
181190template <typename T>
182191inline bool Bracket<T>::isInvalid() const
183192{
184193 return mMin > mMax ;
185194}
195+
196+ template <typename T>
197+ inline bool Bracket<T>::isZeroLength() const
198+ {
199+ return mMin == mMax ;
200+ }
201+
186202template <typename T>
187203inline void Bracket<T>::update(T v)
188204{
@@ -195,19 +211,41 @@ inline void Bracket<T>::update(T v)
195211 }
196212}
197213
214+ template <typename T>
215+ inline void Bracket<T>::scale(T c)
216+ {
217+ mMin *= c;
218+ mMax *= c;
219+ }
220+
221+ template <typename T>
222+ inline Bracket<T> Bracket<T>::getOverlap(const Bracket<T>& other) const
223+ {
224+ return {getMin () > other.getMin () ? getMin () : other.getMin (), getMax () < other.getMax () ? getMax () : other.getMax ()};
225+ }
226+
198227template <typename T>
199228inline typename Bracket<T>::Relation Bracket<T>::isOutside(const Bracket<T>& t) const
200229{
201230 // /< check if provided bracket is outside of this bracket
202231 return t.mMax < mMin ? Below : (t.mMin > mMax ? Above : Inside);
203232}
233+
204234template <typename T>
205235inline typename Bracket<T>::Relation Bracket<T>::isOutside(T t, T tErr) const
206236{
207237 // /< check if the provided value t with error tErr is outside of the bracket
208238 return t + tErr < mMin ? Below : (t - tErr > mMax ? Above : Inside);
209239}
210240
241+ #ifndef GPUCA_ALIGPUCODE
242+ template <typename T>
243+ std::string Bracket<T>::asString() const
244+ {
245+ return fmt::format (" [{}:{}]" , getMin (), getMax ());
246+ }
247+ #endif
248+
211249} // namespace detail
212250} // namespace math_utils
213251} // namespace o2
0 commit comments