Belle II Software  release-05-02-19
IntervalOfValidity.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <iosfwd>
14 #include <Rtypes.h>
15 
16 namespace Belle2 {
21  class EventMetaData;
22 
27  class IntervalOfValidity final {
28  public:
30  IntervalOfValidity(): IntervalOfValidity(-1, -1, -1, -1) {}
31 
39  IntervalOfValidity(int experimentLow, int runLow, int experimentHigh , int runHigh);
40 
44  ~IntervalOfValidity() = default;
45 
51  bool contains(const EventMetaData& event) const;
52 
57  bool empty() const {return ((m_experimentLow < 0) && (m_experimentHigh < 0));};
58 
64  static IntervalOfValidity always() {return IntervalOfValidity(0, 0, -1, -1);};
65 
69  bool operator==(const IntervalOfValidity& other) const
70  {
71  return (m_experimentLow == other.m_experimentLow) && (m_runLow == other.m_runLow) &&
72  (m_experimentHigh == other.m_experimentHigh) && (m_runHigh == other.m_runHigh);
73  }
74 
78  bool operator!=(const IntervalOfValidity& other) const
79  {
80  return !(*this == other);
81  }
82 
88  bool contains(const IntervalOfValidity& iov) const {return overlap(iov) == iov;};
89 
95  bool overlaps(const IntervalOfValidity& iov) const {return !overlap(iov).empty();};
96 
103 
110  bool trimOverlap(IntervalOfValidity& iov, bool trimOlder = true);
111 
119  int getExperimentLow() const
120  {
121  return m_experimentLow;
122  }
123 
127  int getRunLow() const
128  {
129  return m_runLow;
130  }
131 
139  int getExperimentHigh() const
140  {
141  return m_experimentHigh;
142  }
143 
147  int getRunHigh() const
148  {
149  return m_runHigh;
150  }
151 
157  friend std::istream& operator>> (std::istream& input, IntervalOfValidity& iov);
158 
164  friend std::ostream& operator<< (std::ostream& output, const IntervalOfValidity& iov);
165 
166  private:
167 
170  int m_experimentLow;
171 
174  int m_runLow;
175 
179 
183 
192  int checkLowerBound(int experiment, int run) const;
193 
202  int checkUpperBound(int experiment, int run) const;
203 
207  void makeValid();
208 
210  };
212 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::IntervalOfValidity::overlaps
bool overlaps(const IntervalOfValidity &iov) const
Function that checks the validity interval overlaps with another interval of validity.
Definition: IntervalOfValidity.h:103
Belle2::IntervalOfValidity::always
static IntervalOfValidity always()
Function that returns an interval of validity that is always valid, c.f.
Definition: IntervalOfValidity.h:72
Belle2::IntervalOfValidity::checkUpperBound
int checkUpperBound(int experiment, int run) const
Helper function to check whether a given experiment/run number is above or below the upper bound of t...
Definition: IntervalOfValidity.cc:56
Belle2::IntervalOfValidity::checkLowerBound
int checkLowerBound(int experiment, int run) const
Helper function to check whether a given experiment/run number is above or below the lower bound of t...
Definition: IntervalOfValidity.cc:42
Belle2::IntervalOfValidity::m_experimentLow
int m_experimentLow
Lowest experiment number.
Definition: IntervalOfValidity.h:178
Belle2::IntervalOfValidity::IntervalOfValidity
IntervalOfValidity()
Default constructor which will create an empty iov.
Definition: IntervalOfValidity.h:38
Belle2::IntervalOfValidity::operator>>
friend std::istream & operator>>(std::istream &input, IntervalOfValidity &iov)
Input stream operator for reading IoV data from a text file.
Definition: IntervalOfValidity.cc:152
Belle2::IntervalOfValidity::~IntervalOfValidity
~IntervalOfValidity()=default
Destructor.
Belle2::IntervalOfValidity::m_experimentHigh
int m_experimentHigh
Highest experiment number.
Definition: IntervalOfValidity.h:186
Belle2::IntervalOfValidity::overlap
IntervalOfValidity overlap(const IntervalOfValidity &iov) const
Function that determines the overlap of the validity interval with another interval of validity.
Definition: IntervalOfValidity.cc:96
Belle2::IntervalOfValidity::operator==
bool operator==(const IntervalOfValidity &other) const
Check whether two intervals of validity are identical.
Definition: IntervalOfValidity.h:77
Belle2::IntervalOfValidity::m_runLow
int m_runLow
Lowest run number.
Definition: IntervalOfValidity.h:182
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::IntervalOfValidity::contains
bool contains(const EventMetaData &event) const
Function that checks whether the event is inside the validity interval.
Definition: IntervalOfValidity.cc:82
Belle2::IntervalOfValidity::getRunLow
int getRunLow() const
Getter for lowest run number.
Definition: IntervalOfValidity.h:135
Belle2::IntervalOfValidity::m_runHigh
int m_runHigh
Highest run number.
Definition: IntervalOfValidity.h:190
Belle2::IntervalOfValidity::ClassDefNV
ClassDefNV(IntervalOfValidity, 2)
describes the interval of experiments/runs for which an object in the database is valid.
Belle2::IntervalOfValidity::trimOverlap
bool trimOverlap(IntervalOfValidity &iov, bool trimOlder=true)
Remove the overlap between two intervals of validity by shortening one of them.
Definition: IntervalOfValidity.cc:114
Belle2::IntervalOfValidity::operator!=
bool operator!=(const IntervalOfValidity &other) const
Check whether two intervals of validity are different.
Definition: IntervalOfValidity.h:86
Belle2::IntervalOfValidity::getExperimentHigh
int getExperimentHigh() const
Getter for highest experiment number.
Definition: IntervalOfValidity.h:147
Belle2::IntervalOfValidity::operator<<
friend std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Output stream operator for writing IoV data to a text file.
Definition: IntervalOfValidity.cc:196
Belle2::IntervalOfValidity::empty
bool empty() const
Function that checks whether the validity interval is empty.
Definition: IntervalOfValidity.h:65
Belle2::IntervalOfValidity::getRunHigh
int getRunHigh() const
Getter for highest run number.
Definition: IntervalOfValidity.h:155
Belle2::IntervalOfValidity::makeValid
void makeValid()
Helper function to set the interval to empty if the upper bound is below the lower one.
Definition: IntervalOfValidity.cc:70
Belle2::IntervalOfValidity::getExperimentLow
int getExperimentLow() const
Getter for lowest experiment number.
Definition: IntervalOfValidity.h:127