10 #ifndef LARDATAALG_UTILITIES_INTERVALS_H
11 #define LARDATAALG_UTILITIES_INTERVALS_H
18 #include <type_traits>
20 namespace util::quantities {
32 template <
typename Cat,
typename =
void>
35 template <
typename Cat>
41 template <
typename Cat>
54 static std::string
name() =
delete;
62 template <
typename IV>
66 template <
typename IV>
72 template <
typename PT>
76 template <
typename PT>
113 template <
typename Q,
typename Cat = NoCategory>
121 template <
typename OC,
typename Type =
void>
124 <category_base_t::template category_compatible_with<OC>(),
Type>
142 template <
typename R>
149 using unit_t =
typename quantity_t::unit_t;
155 template <
typename OQ,
typename OI>
179 template <
typename... Args>
194 <
typename IV,
typename std::enable_if_t<is_interval_v<IV>>* =
nullptr>
212 using quantity_t::unit;
213 using quantity_t::unitName;
214 using quantity_t::unitSymbol;
215 using quantity_t::baseUnit;
228 template <
typename OU>
230 {
return quantity_t::template sameBaseUnitAs<OU>(); }
233 template <
typename OU>
235 {
return quantity_t::template sameUnitAs<OU>(); }
285 template <
typename OQ,
typename OC>
286 constexpr enable_if_compatible_t<Interval<OQ, OC>,
value_t>
291 template <
typename R>
296 template <
typename OQ,
typename OC>
297 enable_if_compatible_t<Interval<OQ, OC>,
interval_t&>
302 template <
typename R>
304 { quantity_t::operator-= (other);
return *
this; }
307 template <
typename OQ,
typename OC>
308 enable_if_compatible_t<Interval<OQ, OC>,
interval_t&>
313 template <
typename T>
315 { quantity_t::operator*= (factor);
return *
this; }
318 template <
typename T>
320 { quantity_t::operator/= (factor);
return *
this; }
353 template <
typename OQ,
typename OC>
354 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
358 template <
typename OQ,
typename OC>
359 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
363 template <
typename OQ,
typename OC>
364 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
368 template <
typename OQ,
typename OC>
369 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
373 template <
typename OQ,
typename OC>
374 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
375 operator<=(Interval<OQ, OC>
const other)
const
378 template <
typename OQ,
typename OC>
379 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
380 operator<(Interval<OQ, OC>
const other)
const
388 template <
typename IV>
399 template <
typename U>
406 template <
typename... Args>
424 template <
typename Q,
typename Cat,
typename... Args>
425 constexpr
bool operator==
427 {
return a.quantity() == b; }
429 template <
typename Q,
typename Cat,
typename... Args>
430 constexpr
bool operator==
434 template <
typename Q,
typename Cat,
typename... Args>
435 constexpr
bool operator!=
437 {
return a.quantity() != b; }
439 template <
typename Q,
typename Cat,
typename... Args>
440 constexpr
bool operator!=
444 template <
typename Q,
typename Cat,
typename... Args>
445 constexpr
bool operator<=
447 {
return a.quantity() <= b; }
449 template <
typename Q,
typename Cat,
typename... Args>
450 constexpr
bool operator<=
454 template <
typename Q,
typename Cat,
typename... Args>
455 constexpr
bool operator<
457 {
return a.quantity() < b; }
459 template <
typename Q,
typename Cat,
typename... Args>
460 constexpr
bool operator<
464 template <
typename Q,
typename Cat,
typename... Args>
465 constexpr
bool operator>=
467 {
return a.quantity() >= b; }
469 template <
typename Q,
typename Cat,
typename... Args>
470 constexpr
bool operator>=
474 template <
typename Q,
typename Cat,
typename... Args>
475 constexpr
bool operator>
477 {
return a.quantity() > b; }
479 template <
typename Q,
typename Cat,
typename... Args>
480 constexpr
bool operator>
503 template <
typename Q,
typename Cat,
typename T>
504 constexpr std::enable_if_t<std::is_arithmetic_v<T>, Interval<Q, Cat>>
507 template <
typename Q,
typename Cat,
typename T>
508 constexpr std::enable_if_t<std::is_arithmetic_v<T>, Interval<Q, Cat>>
513 template <
typename AQ,
typename AC,
typename BQ,
typename BC>
514 constexpr
auto operator* (Interval<AQ, AC>
const, Interval<BQ, BC>
const)
519 template <
typename Q,
typename Cat,
typename T>
520 constexpr std::enable_if_t<std::is_arithmetic_v<T>, Interval<Q, Cat>>
530 template <
typename IV,
typename R,
typename T =
typename IV::value_t>
536 template <
typename Q,
typename Cat>
564 typename IV = Interval<Q, Cat>
573 template <
typename OC,
typename Type =
void>
576 <category_base_t::template category_compatible_with<OC>(),
Type>
598 template <
typename R>
605 using unit_t =
typename quantity_t::unit_t;
611 template <
typename OQ,
typename OI>
620 explicit Point() =
default;
635 template <
typename... Args>
649 <
typename PT,
typename std::enable_if_t<is_point_v<PT>>* =
nullptr>
694 template <
typename R>
700 template <
typename OQ,
typename OC>
701 constexpr enable_if_compatible_t<Interval<OQ, OC>,
point_t>
706 template <
typename R>
711 template <
typename OQ,
typename OC>
712 constexpr enable_if_compatible_t<Interval<OQ, OC>,
point_t>
717 template <
typename R>
722 template <
typename OQ,
typename OC>
723 enable_if_compatible_t<Interval<OQ, OC>,
point_t&>
operator+=
728 template <
typename R>
730 { quantity_t::operator-= (other);
return *
this; }
733 template <
typename OQ,
typename OC>
734 enable_if_compatible_t<Interval<OQ, OC>,
point_t&>
operator-=
768 template <
typename OQ,
typename OI>
772 template <
typename OQ,
typename OI>
773 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
777 template <
typename OQ,
typename OI>
778 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
782 template <
typename OQ,
typename OI>
783 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
787 template <
typename OQ,
typename OI>
788 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
789 operator<=(other_point_t<OQ, OI>
const other)
const
792 template <
typename OQ,
typename OI>
793 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
794 operator<(other_point_t<OQ, OI>
const other)
const
806 using quantity_t::unit;
807 using quantity_t::baseUnit;
808 using quantity_t::unitName;
809 using quantity_t::unitSymbol;
815 template <
typename PT>
816 constexpr std::enable_if_t<is_point_v<PT>, PT>
convertInto()
const {
return PT(*
this); }
826 template <
typename U>
833 template <
typename... Args>
852 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
853 constexpr
bool operator==
855 {
return a.quantity() == b; }
857 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
858 constexpr
bool operator==
862 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
863 constexpr
bool operator!=
865 {
return a.quantity() != b; }
867 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
868 constexpr
bool operator!=
872 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
873 constexpr
bool operator<=
875 {
return a.quantity() <= b; }
877 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
878 constexpr
bool operator<=
882 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
883 constexpr
bool operator<
885 {
return a.quantity() < b; }
887 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
888 constexpr
bool operator<
892 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
893 constexpr
bool operator>=
895 {
return a.quantity() >= b; }
897 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
898 constexpr
bool operator>=
902 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
903 constexpr
bool operator>
905 {
return a.quantity() > b; }
907 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
908 constexpr
bool operator>
928 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
929 constexpr Point<Q, Cat, IV>
operator+
930 (Interval<OQ, OC>
const delta, Point<Q, Cat, IV>
const p)
933 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
934 constexpr Point<Q, Cat, IV>
operator-
935 (Interval<OQ, OC>
const delta, Point<Q, Cat, IV>
const p)
940 <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OCat>
942 typename Point<Q, Cat, IV>
943 ::template enable_if_compatible_t<Point<OQ, OCat, IV>, IV>
953 template <
typename PT,
typename R,
typename T =
typename PT::value_t>
959 template <
typename Q,
typename Cat,
typename IV>
971 static std::string
name() {
return "generic"; }
991 template <
typename IV>
992 IV
makeInterval(std::string_view
s,
bool unitOptional =
false);
994 template <
typename IV>
995 IV
makeInterval(std::string
const&
s,
bool unitOptional =
false);
997 template <
typename IV>
1017 template <
typename PT>
1018 PT
makePoint(std::string_view
s,
bool unitOptional =
false);
1020 template <
typename PT>
1021 PT
makePoint(std::string
const&
s,
bool unitOptional =
false);
1023 template <
typename PT>
1024 PT
makePoint(
char const*
s,
bool unitOptional =
false);
1037 namespace util::quantities::concepts::details {
1040 template <
typename,
typename = std::
void_t<>>
1043 template <
typename Obj>
1048 template <
typename Obj>
1052 template <
typename,
typename = std::
void_t<>>
1055 template <
typename Cat>
1057 : std::true_type {};
1059 template <
typename Cat>
1068 template <
typename OC>
1070 {
return util::is_any_of_v<OC, NoCategory, category_t>; }
1076 template <
typename Cat,
typename >
1079 template <
typename Cat>
1081 {
using type =
typename Cat::category_t; };
1085 template <
typename Cat>
1098 template <
typename OC>
1099 static constexpr
bool same_category_as();
1101 template <
typename OC>
1102 static constexpr
bool same_category_as(OC
const&);
1107 template <
typename OC>
1108 static constexpr
bool category_compatible_with();
1110 template <
typename OC>
1111 static constexpr
bool category_compatible_with(OC
const&);
1116 static constexpr
bool hasCategoryName();
1119 static std::string categoryName();
1127 template <
typename Cat>
1132 template <
typename Cat>
1133 template <
typename OC>
1135 return details::has_category_v<OC>
1136 && std::is_same_v<typename OC::category_t, category_t>;
1139 template <
typename Cat>
1140 template <
typename OC>
1142 {
return same_category_as<OC>(); }
1146 template <
typename Cat>
1147 template <
typename OC>
1149 {
return traits_t::template compatible_with<category_of<OC>>(); }
1152 template <
typename Cat>
1153 template <
typename OC>
1155 {
return category_compatible_with<OC>(); }
1158 template <
typename Cat>
1164 template <
typename Cat>
1177 namespace util::quantities::concepts {
1183 template <
typename... Args>
1189 struct is_point:
public std::false_type {};
1191 template <
typename... Args>
1203 template <
typename IV>
1205 (std::string_view
s,
bool unitOptional )
1207 using quantity_t =
typename IV::quantity_t;
1208 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1213 template <
typename IV>
1215 (std::string
const& s,
bool unitOptional )
1217 using quantity_t =
typename IV::quantity_t;
1218 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1223 template <
typename IV>
1225 (
char const* s,
bool unitOptional )
1227 using quantity_t =
typename IV::quantity_t;
1228 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1233 template <
typename PT>
1235 (std::string_view s,
bool unitOptional )
1237 using quantity_t =
typename PT::quantity_t;
1238 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1243 template <
typename PT>
1245 (std::string
const& s,
bool unitOptional )
1247 using quantity_t =
typename PT::quantity_t;
1248 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1253 template <
typename PT>
1255 (
char const* s,
bool unitOptional )
1257 using quantity_t =
typename PT::quantity_t;
1258 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1269 template <
typename Q,
typename Cat>
1270 struct hash<util::quantities::concepts::Interval<Q, Cat>> {
1271 constexpr
auto operator()
1273 noexcept(noexcept(std::hash(key.quantity())))
1274 {
return std::hash(key.quantity()); }
1277 template <
typename Q,
typename Cat,
typename IV>
1279 constexpr
auto operator()
1281 noexcept(noexcept(std::hash(key.quantity())))
1282 {
return std::hash(key.quantity()); }
1289 template <
typename Q,
typename Cat>
1290 class numeric_limits<util::quantities::concepts::Interval<Q, Cat>>
1292 <util::quantities::concepts::Interval<Q, Cat>>
1295 template <
typename Q,
typename Cat>
1296 class numeric_limits<util::quantities::concepts::Interval<Q, Cat>
const>
1298 <util::quantities::concepts::Interval<Q, Cat> const>
1301 template <
typename Q,
typename Cat>
1302 class numeric_limits<util::quantities::concepts::Interval<Q, Cat> volatile>
1304 <util::quantities::concepts::Interval<Q, Cat> volatile>
1307 template <
typename Q,
typename Cat>
1308 class numeric_limits
1309 <util::quantities::concepts::Interval<Q, Cat>
const volatile>
1311 <util::quantities::concepts::Interval<Q, Cat> const volatile>
1315 template <
typename Q,
typename Cat,
typename IV>
1318 <util::quantities::concepts::Point<Q, Cat, IV>>
1321 template <
typename Q,
typename Cat,
typename IV>
1324 <util::quantities::concepts::Point<Q, Cat, IV> const>
1327 template <
typename Q,
typename Cat,
typename IV>
1330 <util::quantities::concepts::Point<Q, Cat, IV> volatile>
1333 template <
typename Q,
typename Cat,
typename IV>
1334 class numeric_limits
1337 <util::quantities::concepts::Point<Q, Cat, IV> const volatile>
1348 #endif // LARDATAALG_UTILITIES_INTERVALS_H
constexpr interval_t operator+() const
Returns an interval with same value.
typename category_base_t::category_t category_t
Quantity the interval is based on.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Interval< Q, Cat > interval_t
This type.
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator==(Interval< OQ, OC > const other) const
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
constexpr Interval(IV iv)
Constructor: converts from another interval.
category_traits< category_t > traits_t
Traits of this category.
static constexpr bool sameBaseUnitAs()
Returns whether objects of type OU have the same base unit as this.
value_t
the JSON type enumeration
Interval()=default
Constructor: value is left uninitialized.
constexpr enable_if_compatible_t< Interval< OQ, OC >, value_t > operator/(Interval< OQ, OC > const denom) const
Division by an interval, returns a pure number.
constexpr interval_t operator-(interval_t const other) const
Q quantity_t
Quantity the interval is based on.
constexpr Interval(value_t v)
Constructor: takes a value in the intended representation.
interval_t & operator*=(T factor)
Scale this interval by a factor.
static interval_t castFrom(U value)
Returns a new interval initialized with the specified value.
typename T::interval_t interval_of
Type of interval contained in specified type T.
constexpr bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
interval_t & operator/=(T factor)
Scale the interval dividing it by a quotient.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator>=(other_point_t< OQ, OI > const other) const
PT makePoint(std::string_view s, bool unitOptional=false)
Returns a point of the specified type parsed from a string.
Trait: true_type if IV is a Interval specialization.
constexpr bool operator>=(Interval< Q, Cat > const a, Quantity< Args...> const b) noexcept
constexpr Point(Quantity< Args...> const q)
Constructor: converts from a quantity.
typename category_of_type< Cat >::type category_of
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator>=(Interval< OQ, OC > const other) const
std::string to_string(Interval< Q, Cat > const &iv)
typename quantity_t::baseunit_t baseunit_t
Description of the unscaled unit.
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
typename category_base_t::traits_t traits_t
Traits of the category.
typename category_base_t::category_t category_t
The category this point belongs to.
constexpr bool is_interval_v
Trait: true if IV is a Interval specialization.
An object belonging to a category Cat.
static point_t castFrom(U value)
Returns a new point initialized with the specified value.
static constexpr bool sameUnitAs()
Returns whether objects of type OU have same unit and scale as this.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
constexpr point_t operator-() const
Returns a parity-changed point.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
A value measured in the specified unit.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator>(other_point_t< OQ, OI > const other) const
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
typename std::enable_if< B, T >::type enable_if_t
bool operator!=(base_iterator< ValueL > const &a, base_iterator< ValueR > const &b)
typename quantity_t::baseunit_t baseunit_t
Description of the unscaled unit.
Point< rescale< typename PT::quantity_t, R, T >, typename PT::category_t > rescale_point
Type of a point like PT, but with a different unit scale R.
String & operator+=(String &s, VectorDumper< Vector > const &manip)
Appends a string rendering of a vector to the specified string.
constexpr interval_t operator+(interval_t const other) const
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Cat category_t
The categories the traits are about.
constexpr IV convertInto() const
Convert this interval into the specified one.
An interval (duration, length, distance) between two quantity points.
interval_t & operator-=(scaled_quantity_t< R > const other)
Subtract a quantity (possibly converted) from this one.
static std::string name()=delete
Returns the name of this category. Optional.
IV interval_t
The interval type corresponding to the unit of this point.
constexpr std::enable_if_t< is_point_v< PT >, PT > convertInto() const
Convert this interval into the specified one.
static constexpr bool compatible_with()
Returns whether the category OC is "compatible" with this one.
Interval< rescale< typename IV::quantity_t, R, T >, typename IV::category_t > rescale_interval
Type of an interval like IV, but with a different unit scale R.
constexpr bool has_category_v
Trait: true_type if PT is a Point specialization.
constexpr Interval(Quantity< Args...> const &q)
Constructor: converts from a quantity.
Numeric variable proxies with embedded unit of measurement.
constexpr bool operator>(Interval< Q, Cat > const a, Quantity< Args...> const b) noexcept
std::ostream & operator<<(std::ostream &out, Interval< Args...> const iv)
constexpr Point(PT const p)
Constructor: converts from another point.
static std::string name()
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator!=(other_point_t< OQ, OI > const other) const
Cat category_t
The category of this object.
An non-mandatory base class for interval and point categories.
then echo File list $list not found else cat $list while read file do echo $file sed s
typename make_void< Ts...>::type void_t
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator>(Interval< OQ, OC > const other) const
constexpr interval_t abs() const
Returns an interval with the absolute value of this one.
typename quantity_t::value_t value_t
Type of the stored value.
constexpr std::enable_if_t< std::is_arithmetic_v< T >, Interval< Q, Cat > > operator*(Interval< Q, Cat > const iv, T const factor)
Multiplication with a scalar.
typename quantity_t::value_t value_t
Type of the stored value.
constexpr interval_t operator-() const
Returns an interval with same value but the sign flipped.
Limits of a quantity are the same as the underlying type.
IV makeInterval(std::string_view s, bool unitOptional=false)
Returns an interval of the specified type parsed from a string.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator==(other_point_t< OQ, OI > const other) const
constexpr bool is_interval_or_point_v
Trait: true if PT is a specialization of Interval or Point.
typename category_base_t::traits_t traits_t
Traits of the category.
constexpr point_t operator+() const
Returns a point with same value.
constexpr bool is_point_v
Trait: true if PT is a Point specialization.
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
constexpr Point(value_t v)
Constructor: takes a value in the intended representation.
typename quantity_t::unit_t unit_t
Description of the scaled unit.
constexpr bool operator<=(Interval< Q, Cat > const a, Quantity< Args...> const b) noexcept
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator!=(Interval< OQ, OC > const other) const
interval_t & operator+=(scaled_quantity_t< R > const other)
Add a quantity (possibly converted) to this one.
typename quantity_t::unit_t unit_t
Description of the scaled unit.
std::disjunction< is_interval< T >, is_point< T >> is_interval_or_point
Trait: true_type if PT is a specialization of Interval or Point.