5#include "Rivet/Config/RivetCommon.hh"
6#include "Rivet/Projection.hh"
34 Cmp(
const T& t1,
const T& t2)
35 : _value(CmpState::UNDEF), _objects(&t1, &t2) { }
40 : _value(x._value), _objects(nullptr, nullptr) { }
44 const Cmp<T>& operator=(
const Cmp<U>& x) {
54 operator CmpState()
const {
61 const Cmp<T>&
operator||(
const Cmp<U>& c)
const {
63 if (_value == CmpState::EQ) _value = c;
70 void _compare()
const {
71 if (_value == CmpState::UNDEF) {
73 if ( l(*_objects.first, *_objects.second) ) _value = CmpState::NEQ;
74 else if ( l(*_objects.second, *_objects.first) ) _value = CmpState::NEQ;
75 else _value = CmpState::EQ;
80 mutable CmpState _value;
83 const pair<const T*, const T*> _objects;
103 class Cmp<Projection> final {
109 Cmp(
const Projection& p1,
const Projection& p2)
110 : _value(CmpState::UNDEF), _objects(&p1, &p2)
114 template <
typename U>
116 : _value(x), _objects(nullptr, nullptr)
120 template <
typename U>
121 const Cmp<Projection>& operator=(
const Cmp<U>& x) {
130 operator CmpState()
const {
136 template <
typename U>
137 const Cmp<Projection>&
operator||(
const Cmp<U>& c)
const {
139 if (_value == CmpState::EQ) _value = c;
146 void _compare()
const {
147 if (_value == CmpState::UNDEF) {
148 const std::type_info& id1 =
typeid(*_objects.first);
149 const std::type_info& id2 =
typeid(*_objects.second);
150 if (id1.before(id2)) _value = CmpState::NEQ;
151 else if (id2.before(id1)) _value = CmpState::NEQ;
153 CmpState cmps = _objects.first->compare(*_objects.second);
154 if (cmps == CmpState::EQ) _value = CmpState::EQ;
155 else _value = CmpState::NEQ;
163 mutable CmpState _value;
166 const pair<const Projection*, const Projection*> _objects;
187 class Cmp<double> final {
193 Cmp(
const double p1,
const double p2)
194 : _value(CmpState::UNDEF), _numA(p1), _numB(p2)
198 template <
typename U>
200 : _value(x), _numA(0.0), _numB(0.0)
204 template <
typename U>
205 const Cmp<double>& operator=(
const Cmp<U>& x) {
214 operator CmpState()
const {
220 template <
typename U>
221 const Cmp<double>&
operator||(
const Cmp<U>& c)
const {
223 if (_value == CmpState::EQ) _value = c;
230 void _compare()
const {
231 if (_value == CmpState::UNDEF) {
232 if (
fuzzyEquals(_numA,_numB)) _value = CmpState::EQ;
233 else _value = CmpState::NEQ;
240 mutable CmpState _value;
243 const double _numA, _numB;
254 template <
typename T>
255 inline Cmp<T>
cmp(
const T& t1,
const T& t2) {
256 return Cmp<T>(t1, t2);
266 return Cmp<Projection>(p1, p2);
const PROJ & getProjection(const std::string &name) const
Definition ProjectionApplier.hh:62
Base class for all Rivet projections.
Definition Projection.hh:29
Definition MC_CENT_PPB_Projections.hh:10
Cmp< Projection > PCmp
Typedef for Cmp<Projection>
Definition Cmp.hh:261
Cmp< Projection > pcmp(const Projection &p1, const Projection &p2)
Global helper function for easy creation of Cmp<Projection> objects.
Definition Cmp.hh:265
std::enable_if< std::is_arithmetic< N1 >::value &&std::is_arithmetic< N2 >::value &&(std::is_floating_point< N1 >::value||std::is_floating_point< N2 >::value), bool >::type fuzzyEquals(N1 a, N2 b, double tolerance=1e-5)
Compare two numbers for equality with a degree of fuzziness.
Definition MathUtils.hh:57
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition Cmp.hh:255
Cut operator||(const Cut &aptr, const Cut &bptr)