diff --git a/Kernel/LHCbAlgs/src/TrajPoca.cpp b/Kernel/LHCbAlgs/src/TrajPoca.cpp index 6f2f8b31819d067ebe6203920c01a2652e6d2b3e..20f67d5f3088d874ba579c8bb76903bd971144c0 100644 --- a/Kernel/LHCbAlgs/src/TrajPoca.cpp +++ b/Kernel/LHCbAlgs/src/TrajPoca.cpp @@ -36,10 +36,10 @@ TrajPoca::TrajPoca( const std::string& type, //============================================================================= StatusCode TrajPoca::minimize( const LHCb::Trajectory& traj1, double& mu1, - bool restrictRange1, + RestrictRange restrictRange1, const LHCb::Trajectory& traj2, double& mu2, - bool restrictRange2, + RestrictRange restrictRange2, Gaudi::XYZVector& distance, double precision ) const { @@ -148,7 +148,7 @@ StatusCode TrajPoca::minimize( const LHCb::Trajectory& traj1, //============================================================================= StatusCode TrajPoca::minimize( const LHCb::Trajectory& traj, double& mu, - bool restrictRange, + RestrictRange restrictRange, const Gaudi::XYZPoint& pt, Gaudi::XYZVector& distance, double /*precision*/ ) const @@ -163,8 +163,8 @@ StatusCode TrajPoca::minimize( const LHCb::Trajectory& traj, //============================================================================= // //============================================================================= -bool TrajPoca::stepTowardPoca( const LHCb::Trajectory& traj1, double& mu1, bool restrictRange1, - const LHCb::Trajectory& traj2, double& mu2, bool restrictRange2, +bool TrajPoca::stepTowardPoca( const LHCb::Trajectory& traj1, double& mu1, RestrictRange restrictRange1, + const LHCb::Trajectory& traj2, double& mu2, RestrictRange restrictRange2, double tolerance, cache_t& cache ) const { // a bunch of ugly, unitialized member variables @@ -246,8 +246,8 @@ bool TrajPoca::stepTowardPoca( const LHCb::Trajectory& traj1, double& mu1, bool // these do not make any sense here. either we need to merge them with the lines above that restrict to the validity of the // expansion, or we need to move them out of here entirely. - if (UNLIKELY(restrictRange1)) restrictToRange(mu1, traj1); - if (UNLIKELY(restrictRange2)) restrictToRange(mu2, traj2); + if (UNLIKELY(bool(restrictRange1))) restrictToRange(mu1, traj1); + if (UNLIKELY(bool(restrictRange2))) restrictToRange(mu2, traj2); // another check for parallel trajectories if (UNLIKELY(std::min(std::abs(mu1), std::abs(mu2)) > m_maxDist)) { diff --git a/Kernel/LHCbAlgs/src/TrajPoca.h b/Kernel/LHCbAlgs/src/TrajPoca.h index f7ad76afc3451121df20ceae833c8ee62a4de74e..54c71fe1efa8ce3eae3ec79840488e3ccf0b5abd 100644 --- a/Kernel/LHCbAlgs/src/TrajPoca.h +++ b/Kernel/LHCbAlgs/src/TrajPoca.h @@ -36,8 +36,8 @@ public: /// trajectories is at its minimum. The precision parameter is the desired /// numerical accuracy of mu1 and mu2. If the restrictrange flag is true, mu /// is restricted to the range of the trajectory. - StatusCode minimize( const LHCb::Trajectory& traj1, double& mu1, bool restrictRange1, - const LHCb::Trajectory& traj2, double& mu2, bool restrictRange2, + StatusCode minimize( const LHCb::Trajectory& traj1, double& mu1, RestrictRange range1, + const LHCb::Trajectory& traj2, double& mu2, RestrictRange range2, Gaudi::XYZVector& distance, double precision ) const override; @@ -47,7 +47,7 @@ public: /// restricted to the range of the trajectory. StatusCode minimize( const LHCb::Trajectory& traj, double& mu, - bool restrictRange, + RestrictRange restrictRange, const Gaudi::XYZPoint& pt, Gaudi::XYZVector& distance, double precision ) const override; @@ -59,8 +59,8 @@ private: }; - bool stepTowardPoca( const LHCb::Trajectory& traj1, double& mu1, bool restrictRange1, - const LHCb::Trajectory& traj2, double& mu2, bool restrictRange2, + bool stepTowardPoca( const LHCb::Trajectory& traj1, double& mu1, RestrictRange range1, + const LHCb::Trajectory& traj2, double& mu2, RestrictRange range2, double precision, cache_t& cache ) const; inline bool restrictToRange(double& l, const LHCb::Trajectory& t) const diff --git a/Kernel/LHCbKernel/Kernel/ITrajPoca.h b/Kernel/LHCbKernel/Kernel/ITrajPoca.h index 313c6db4b1f82f2914c232178fde1de7a570a714..d87c20d7a81ada8568e25b4a94322be9a96e2fc0 100644 --- a/Kernel/LHCbKernel/Kernel/ITrajPoca.h +++ b/Kernel/LHCbKernel/Kernel/ITrajPoca.h @@ -8,6 +8,7 @@ #include "GaudiKernel/Vector3DTypes.h" #include "Trajectory.h" +#include "TaggedBool.h" /** @class ITrajPoca ITrajPoca.h @@ -21,18 +22,18 @@ struct ITrajPoca : extend_interfaces { - DeclareInterfaceID(ITrajPoca, 2, 0 ); + DeclareInterfaceID(ITrajPoca, 3, 0 ); + + using RestrictRange = xplicit::tagged_bool; /// Find points along trajectories at which the distance between the /// trajectories is at its minimum. The precision parameter is the desired /// numerical accuracy of mu1 and mu2. If the restrictrange flag is true, mu /// is restricted to the range of the trajectory. - virtual StatusCode minimize( const LHCb::Trajectory& traj1, - double& mu1, - bool restrictRange1, - const LHCb::Trajectory& traj2, - double& mu2, - bool restrictRange2, + virtual StatusCode minimize( const LHCb::Trajectory& traj1, double& mu1, + RestrictRange restrictRange1, + const LHCb::Trajectory& traj2, double& mu2, + RestrictRange restrictRange2, Gaudi::XYZVector& distance, double precision ) const = 0 ; @@ -40,9 +41,8 @@ struct ITrajPoca : extend_interfaces { /// is minimum. The precision parameter is the desired numerical accuracy of /// the expansion parameter mu. If the restrictrange flag is true, mu is /// restricted to the range of the trajectory. - virtual StatusCode minimize( const LHCb::Trajectory& traj, - double& mu, - bool restrictRange, + virtual StatusCode minimize( const LHCb::Trajectory& traj, double& mu, + RestrictRange restrictRange, const Gaudi::XYZPoint& pt, Gaudi::XYZVector& distance, double precision ) const = 0; @@ -50,25 +50,22 @@ struct ITrajPoca : extend_interfaces { /// Find points along trajectories at which the distance between the /// trajectories is at its minimum. The precision parameter is the desired /// numerical accuracy of the expansion parameters mu1 and mu2. - StatusCode minimize( const LHCb::Trajectory& traj1, - double& mu1, - const LHCb::Trajectory& traj2, - double& mu2, - Gaudi::XYZVector& distance, - double precision ) const { - return minimize( traj1, mu1, false, traj2, mu2, false,distance, precision); + StatusCode minimize( const LHCb::Trajectory& traj1, double& mu1, + const LHCb::Trajectory& traj2, double& mu2, + Gaudi::XYZVector& distance, double precision ) const { + return minimize( traj1, mu1, RestrictRange{false}, + traj2, mu2, RestrictRange{false}, + distance, precision ); } /// Find point along trajectory at which the distance to point 'p' /// is minimum. The precision parameter is the desired /// numerical accuracy of the expansion parameter mu. - StatusCode minimize( const LHCb::Trajectory& traj, - double& mu, + StatusCode minimize( const LHCb::Trajectory& traj, double& mu, const Gaudi::XYZPoint& pt, - Gaudi::XYZVector& distance, - double precision ) const { - return minimize( traj, mu, false, pt, distance, precision); + Gaudi::XYZVector& distance, double precision ) const { + return minimize( traj, mu, RestrictRange{false}, pt, distance, precision ); } }; #endif // KERNEL_ITRAJPOCA_H diff --git a/Kernel/LHCbKernel/Kernel/TaggedBool.h b/Kernel/LHCbKernel/Kernel/TaggedBool.h new file mode 100644 index 0000000000000000000000000000000000000000..70b9abdd346cd1cc8b9821f85828410e5a20dbf7 --- /dev/null +++ b/Kernel/LHCbKernel/Kernel/TaggedBool.h @@ -0,0 +1,48 @@ +// Copyright (C) 2016 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// copied from https://github.com/akrzemi1/explicit/tree/master/include/ak_toolkit +// last commit: bd572fe05a700cc6766b3d09f8916c9975ccbb45 + +#ifndef AK_TOOLKIT_EXPLICIT_TAGGED_BOOL_HEADER_GUARD_ +#define AK_TOOLKIT_EXPLICIT_TAGGED_BOOL_HEADER_GUARD_ + +namespace xplicit { +namespace tagged_bool_ns { // artificial namespace to prevent ADL into namespace xplicit + +template +class tagged_bool +{ + bool value; + + template friend class tagged_bool; + +public: + + constexpr explicit tagged_bool (bool v) : value {v} {} + + constexpr explicit tagged_bool (int) = delete; + constexpr explicit tagged_bool (double) = delete; + constexpr explicit tagged_bool (void*) = delete; + + template + constexpr explicit tagged_bool (tagged_bool b) : value {b.value} {} + + constexpr explicit operator bool() const { return value; } + constexpr tagged_bool operator!() const { return tagged_bool{!value}; } + + friend constexpr bool operator==(tagged_bool l, tagged_bool r) { return l.value == r.value; } + friend constexpr bool operator!=(tagged_bool l, tagged_bool r) { return l.value != r.value; } +}; + +} + +using tagged_bool_ns::tagged_bool; // with this tagged_bool is in namespace xplicit but with disabled ADL + +} + +#endif +