Belle II Software development
MinMax.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <string>
12#include <utility> // std::pair
13#include <limits> // std::numeric_limits
14
15
16namespace Belle2 {
23 class MinMax {
24 protected:
25 std::pair<double, double> m_minMax;
26 public:
27
30 m_minMax({std::numeric_limits< double >::max(), -std::numeric_limits< double >::max()}) {}
31
33 void reset() { m_minMax = {std::numeric_limits< double >::max(), -std::numeric_limits< double >::max()}; }
34
36 bool checkAndReplaceIfMinMax(double newVal)
37 {
38 bool wasAdded = false;
39 if (newVal < m_minMax.first) { m_minMax.first = newVal; wasAdded = true; }
40 if (m_minMax.second < newVal) { m_minMax.second = newVal; wasAdded = true; }
41 return wasAdded;
42 }
43
44 double getMin() const { return m_minMax.first; }
46 double getMax() const { return m_minMax.second; }
48 std::string print() const
49 {
50 std::string min = m_minMax.first == std::numeric_limits< double >::max() ? "max<double>" : std::to_string(m_minMax.first);
51 std::string max = m_minMax.second == -std::numeric_limits< double >::max() ? "min<double>" : std::to_string(m_minMax.second);
52 return "min: " + min + ", max: " + max;
53 }
54 };
56}
57
small class for storing min and max.
Definition: MinMax.h:23
std::pair< double, double > m_minMax
.first is min, .second is .max.
Definition: MinMax.h:25
bool checkAndReplaceIfMinMax(double newVal)
checks value and replaces old ones if new one is better.
Definition: MinMax.h:36
double getMin() const
returns smallest value stored so far.
Definition: MinMax.h:44
std::string print() const
print function returning results for min and max as a string.
Definition: MinMax.h:48
void reset()
reset to start values.
Definition: MinMax.h:33
double getMax() const
returns biggest value stored so far.
Definition: MinMax.h:46
MinMax()
constructor, starts with max for min and min for max (will later be replaced by valid entries).
Definition: MinMax.h:29
Abstract base class for different kinds of events.