Belle II Software prerelease-11-00-00a
IntervalOfValidity Class Referencefinal

A class that describes the interval of experiments/runs for which an object in the database is valid. More...

#include <IntervalOfValidity.h>

Public Member Functions

 IntervalOfValidity ()
 Default constructor which will create an empty iov.
 
 IntervalOfValidity (int experimentLow, int runLow, int experimentHigh, int runHigh)
 Construct a new iov.
 
 ~IntervalOfValidity ()=default
 Destructor.
 
bool contains (const int experiment, const int run) const
 Function that checks whether the (experiment, run) is inside the validity interval.
 
bool contains (const EventMetaData &event) const
 Function that checks whether the event is inside the validity interval.
 
bool empty () const
 Function that checks whether the validity interval is empty.
 
bool operator== (const IntervalOfValidity &other) const
 Check whether two intervals of validity are identical.
 
bool operator!= (const IntervalOfValidity &other) const
 Check whether two intervals of validity are different.
 
bool contains (const IntervalOfValidity &iov) const
 Function that checks the validity interval contains another interval of validity.
 
bool overlaps (const IntervalOfValidity &iov) const
 Function that checks the validity interval overlaps with another interval of validity.
 
IntervalOfValidity overlap (const IntervalOfValidity &iov) const
 Function that determines the overlap of the validity interval with another interval of validity.
 
bool trimOverlap (IntervalOfValidity &iov, bool trimOlder=true)
 Remove the overlap between two intervals of validity by shortening one of them.
 
int getExperimentLow () const
 Getter for lowest experiment number.
 
int getRunLow () const
 Getter for lowest run number.
 
int getExperimentHigh () const
 Getter for highest experiment number.
 
int getRunHigh () const
 Getter for highest run number.
 

Static Public Member Functions

static IntervalOfValidity always ()
 Function that returns an interval of validity that is always valid, c.f.
 

Private Member Functions

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 the interval of validity.
 
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 the interval of validity.
 
void makeValid ()
 Helper function to set the interval to empty if the upper bound is below the lower one.
 
 ClassDefNV (IntervalOfValidity, 2)
 describes the interval of experiments/runs for which an object in the database is valid.
 

Private Attributes

int m_experimentLow
 Lowest experiment number.
 
int m_runLow
 Lowest run number.
 
int m_experimentHigh
 Highest experiment number.
 
int m_runHigh
 Highest run number.
 

Friends

std::istream & operator>> (std::istream &input, IntervalOfValidity &iov)
 Input stream operator for reading IoV data from a text file.
 
std::ostream & operator<< (std::ostream &output, const IntervalOfValidity &iov)
 Output stream operator for writing IoV data to a text file.
 

Detailed Description

A class that describes the interval of experiments/runs for which an object in the database is valid.

Definition at line 25 of file IntervalOfValidity.h.

Constructor & Destructor Documentation

◆ IntervalOfValidity() [1/2]

IntervalOfValidity ( )
inline

Default constructor which will create an empty iov.

Definition at line 28 of file IntervalOfValidity.h.

28: IntervalOfValidity(-1, -1, -1, -1) {}

◆ IntervalOfValidity() [2/2]

IntervalOfValidity ( int experimentLow,
int runLow,
int experimentHigh,
int runHigh )

Construct a new iov.

Parameters
experimentLowlowest experiment number of the validity range, -1 means no bound
runLowlowest run number in the experiment with number experimentLow of the validity range, -1 means no bound
experimentHighhighest experiment number of the validity range, -1 means no bound
runHighhighest run number in the experiment with number experimentHigh of the validity range, -1 means no bound

Definition at line 17 of file IntervalOfValidity.cc.

18 : m_experimentLow(experimentLow), m_runLow(runLow), m_experimentHigh(experimentHigh), m_runHigh(runHigh)
19{
20 // consistency checks
21 if ((experimentLow < 0) && (runLow >= 0)) {
22 B2ERROR("A run number of " << runLow << " is given for an undefined low experiment number. Setting run to undefined, too.");
23 m_runLow = -1;
24 }
25 if ((experimentHigh < 0) && (runHigh >= 0)) {
26 B2ERROR("A run number of " << runHigh << " is given for an undefined high experiment number. Setting run to undefined, too.");
27 m_runHigh = -1;
28 }
29 if ((experimentLow >= 0) && (experimentHigh >= 0)) {
30 if ((experimentLow > experimentHigh) || ((experimentLow == experimentHigh) && (runHigh >= 0) && (runLow > runHigh))) {
31 B2ERROR("The given lower and higher experiment/run numbers of " << experimentLow << "/" << runLow << " and " << experimentHigh <<
32 "/" << runHigh << ", respectively, are in the wrong order, Swapping them.");
34 std::swap(m_runLow, m_runHigh);
35 }
36 }
37}
int m_runLow
Lowest run number.
int m_experimentLow
Lowest experiment number.
int m_experimentHigh
Highest experiment number.
int m_runHigh
Highest run number.

Member Function Documentation

◆ always()

static IntervalOfValidity always ( )
inlinestatic

Function that returns an interval of validity that is always valid, c.f.

the default constructor which is never valid (a zero interval)

Returns
an interval of validity that is always valid

Definition at line 70 of file IntervalOfValidity.h.

70{return IntervalOfValidity(0, 0, -1, -1);};

◆ checkLowerBound()

int checkLowerBound ( int experiment,
int run ) const
private

Helper function to check whether a given experiment/run number is above or below the lower bound of the interval of validity.

Parameters
experimentthe experiment number
runthe run number
Returns
0 if the given experiment/run number is equal to the lower bound, -1 if it is below the lower bound, 1 if it is above the lower bound.

Definition at line 40 of file IntervalOfValidity.cc.

41{
42 // check for empty interval
43 if (empty()) return false;
44
45 if ((m_experimentLow == experiment) && (m_runLow == run)) return 0;
46 if (m_experimentLow < 0) return 1;
47 if (experiment < m_experimentLow) return -1;
48 if (experiment == m_experimentLow) {
49 if (run < m_runLow) return -1;
50 }
51 return 1;
52}
bool empty() const
Function that checks whether the validity interval is empty.

◆ checkUpperBound()

int checkUpperBound ( int experiment,
int run ) const
private

Helper function to check whether a given experiment/run number is above or below the upper bound of the interval of validity.

Parameters
experimentthe experiment number
runthe run number
Returns
0 if the given experiment/run number is equal to the upper bound, -1 if it is below the upper bound, 1 if it is above the upper bound.

Definition at line 54 of file IntervalOfValidity.cc.

55{
56 // check for empty interval
57 if (empty()) return false;
58
59 if ((m_experimentHigh == experiment) && (m_runHigh == run)) return 0;
60 if (m_experimentHigh < 0) return -1;
61 if ((experiment < 0) || (experiment > m_experimentHigh)) return 1;
62 if (experiment == m_experimentHigh) {
63 if ((m_runHigh >= 0) && ((run > m_runHigh) || (run < 0))) return 1;
64 }
65 return -1;
66}

◆ contains() [1/3]

bool contains ( const EventMetaData & event) const

Function that checks whether the event is inside the validity interval.

Parameters
eventevent meta data to be checked, if the run number 0 it's checked whether the whole experiment is inside the validity interval
Returns
true if the given event is inside the validity interval.

Definition at line 90 of file IntervalOfValidity.cc.

91{
92 auto experiment = (int) event.getExperiment();
93 auto run = (int) event.getRun();
94 return contains(experiment, run);
95}
bool contains(const int experiment, const int run) const
Function that checks whether the (experiment, run) is inside the validity interval.

◆ contains() [2/3]

bool contains ( const int experiment,
const int run ) const

Function that checks whether the (experiment, run) is inside the validity interval.

Parameters
experimentexperiment number to be checked
runrun number to be checked; if the run number 0 it's checked whether the whole experiment is inside the validity interval
Returns
true if the given (experiment, run) is inside the validity interval.

Definition at line 79 of file IntervalOfValidity.cc.

80{
81 // check for empty interval
82 if (empty()) return false;
83
84 // check lower bound
85 if (checkLowerBound(experiment, run) < 0) return false;
86 if (checkUpperBound(experiment, run) > 0) return false;
87 return true;
88}
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...
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...

◆ contains() [3/3]

bool contains ( const IntervalOfValidity & iov) const
inline

Function that checks the validity interval contains another interval of validity.

Parameters
iovthe other validity interval
Returns
true if the given other interval of validity is inside the validity interval.

Definition at line 94 of file IntervalOfValidity.h.

94{return overlap(iov) == iov;};

◆ empty()

bool empty ( ) const
inline

Function that checks whether the validity interval is empty.

Returns
true if the validity interval is empty.

Definition at line 63 of file IntervalOfValidity.h.

63{return ((m_experimentLow < 0) && (m_experimentHigh < 0));};

◆ getExperimentHigh()

int getExperimentHigh ( ) const
inline

Getter for highest experiment number.

-1 means no bound (unless it is a special case described below).

If both m_experimentHigh and m_experimentLow are equal to -1, interval is empty (doesn't match any experiments/runs).

Definition at line 145 of file IntervalOfValidity.h.

146 {
147 return m_experimentHigh;
148 }

◆ getExperimentLow()

int getExperimentLow ( ) const
inline

Getter for lowest experiment number.

-1 means no bound (unless it is a special case described below).

If both m_experimentHigh and m_experimentLow are equal to -1, interval is empty (doesn't match any experiments/runs).

Definition at line 125 of file IntervalOfValidity.h.

126 {
127 return m_experimentLow;
128 }

◆ getRunHigh()

int getRunHigh ( ) const
inline

Getter for highest run number.

-1 means no bound.

Definition at line 153 of file IntervalOfValidity.h.

154 {
155 return m_runHigh;
156 }

◆ getRunLow()

int getRunLow ( ) const
inline

Getter for lowest run number.

-1 means no bound.

Definition at line 133 of file IntervalOfValidity.h.

134 {
135 return m_runLow;
136 }

◆ makeValid()

void makeValid ( )
private

Helper function to set the interval to empty if the upper bound is below the lower one.

Definition at line 68 of file IntervalOfValidity.cc.

69{
70 if (m_experimentLow < 0) m_runLow = -1;
71 if (m_experimentHigh < 0) m_runHigh = -1;
72 if ((m_experimentLow >= 0) && (m_experimentHigh >= 0)) {
75 }
76 }
77}

◆ operator!=()

bool operator!= ( const IntervalOfValidity & other) const
inline

Check whether two intervals of validity are different.

Definition at line 84 of file IntervalOfValidity.h.

85 {
86 return !(*this == other);
87 }

◆ operator==()

bool operator== ( const IntervalOfValidity & other) const
inline

Check whether two intervals of validity are identical.

Definition at line 75 of file IntervalOfValidity.h.

76 {
77 return (m_experimentLow == other.m_experimentLow) && (m_runLow == other.m_runLow) &&
78 (m_experimentHigh == other.m_experimentHigh) && (m_runHigh == other.m_runHigh);
79 }

◆ overlap()

IntervalOfValidity overlap ( const IntervalOfValidity & iov) const

Function that determines the overlap of the validity interval with another interval of validity.

Parameters
iovthe other validity interval
Returns
the interval that is common to both intervals of validity.

Definition at line 97 of file IntervalOfValidity.cc.

98{
99 if (empty() || iov.empty()) return IntervalOfValidity();
100
101 IntervalOfValidity result(*this);
102 if (checkLowerBound(iov.m_experimentLow, iov.m_runLow) > 0) {
103 result.m_experimentLow = iov.m_experimentLow;
104 result.m_runLow = iov.m_runLow;
105 }
106 if (checkUpperBound(iov.m_experimentHigh, iov.m_runHigh) < 0) {
107 result.m_experimentHigh = iov.m_experimentHigh;
108 result.m_runHigh = iov.m_runHigh;
109 }
110
111 result.makeValid();
112 return result;
113}
IntervalOfValidity()
Default constructor which will create an empty iov.

◆ overlaps()

bool overlaps ( const IntervalOfValidity & iov) const
inline

Function that checks the validity interval overlaps with another interval of validity.

Parameters
iovthe other validity interval
Returns
true if both intervals of validity have a common range.

Definition at line 101 of file IntervalOfValidity.h.

101{return !overlap(iov).empty();};

◆ trimOverlap()

bool trimOverlap ( IntervalOfValidity & iov,
bool trimOlder = true )

Remove the overlap between two intervals of validity by shortening one of them.

This does not work if an interval would be cut into two.

Parameters
iovthe other validity interval
trimOlderflag to determine which validity interval should be trimmed based on the comparison of the lower range bound
Returns
true if the overlap could be removed.

Definition at line 115 of file IntervalOfValidity.cc.

116{
117 if (!overlaps(iov)) return true;
118
119 bool thisOlder = checkLowerBound(iov.m_experimentLow, iov.m_runLow) >= 0;
120 IntervalOfValidity& older = (thisOlder) ? *this : iov;
121 IntervalOfValidity& younger = (thisOlder) ? iov : *this;
122
123 if (trimOlder) {
124 // check for the case where trimming is not possible because the interval would be split
125 if (older.checkUpperBound(younger.m_experimentHigh, younger.m_runHigh) < 0) return false;
126
127 older.m_experimentHigh = younger.m_experimentLow;
128 older.m_runHigh = younger.m_runLow - 1;
129 if (older.m_runHigh < 0) {
130 older.m_experimentHigh--;
131 older.m_runHigh = -1;
132 }
133 older.makeValid();
134 } else {
135 younger.m_experimentLow = older.m_experimentHigh;
136 younger.m_runLow = older.m_runHigh + 1;
137 if (younger.m_runLow == 0) {
138 younger.m_experimentLow++;
139 }
140 younger.makeValid();
141 }
142
143 return true;
144}
void makeValid()
Helper function to set the interval to empty if the upper bound is below the lower one.
bool overlaps(const IntervalOfValidity &iov) const
Function that checks the validity interval overlaps with another interval of validity.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & output,
const IntervalOfValidity & iov )
friend

Output stream operator for writing IoV data to a text file.

Parameters
outputThe output stream.
iovThe IntervalOfValidity object.

Definition at line 197 of file IntervalOfValidity.cc.

198 {
199 output << iov.m_experimentLow << "," << iov.m_runLow << "," << iov.m_experimentHigh << "," << iov.m_runHigh;
200
201 return output;
202 }

◆ operator>>

std::istream & operator>> ( std::istream & input,
IntervalOfValidity & iov )
friend

Input stream operator for reading IoV data from a text file.

Parameters
inputThe input stream.
iovThe InervalOfValidity object.

Definition at line 153 of file IntervalOfValidity.cc.

154 {
155 iov = IntervalOfValidity();
156 if (!input.good()) {
157 throw std::runtime_error("cannot read from stream");
158 }
159
160 std::string str[4];
161 int index = 0;
162 while (input.good()) {
163 auto c = input.peek();
164 if (c == EOF) break;
165 if (((c == ' ') || (c == '\n') || (c == '\t'))) {
166 //ignore whitespace in the beginning
167 if (index == 0 && str[0].empty()) {
168 input.get();
169 continue;
170 }
171 //and stop parsing otherwise
172 break;
173 }
174 if (c == ',') {
175 index++;
176 if (index == 4) break;
177 } else {
178 str[index] += c;
179 }
180 input.get();
181 }
182 if (index != 3) {
183 throw std::invalid_argument("IoV needs to be four values (firstExp,firstRun,finalExp,finalRun)");
184 }
185 try {
186 iov.m_experimentLow = stoi(str[0]);
187 iov.m_runLow = stoi(str[1]);
188 iov.m_experimentHigh = stoi(str[2]);
189 iov.m_runHigh = stoi(str[3]);
190 } catch (std::invalid_argument& e) {
191 throw std::invalid_argument("experiment and run numbers must be integers");
192 }
193
194 return input;
195 }

Member Data Documentation

◆ m_experimentHigh

int m_experimentHigh
private

Highest experiment number.

-1 means no bound.

Definition at line 184 of file IntervalOfValidity.h.

◆ m_experimentLow

int m_experimentLow
private

Lowest experiment number.

-1 means no bound.

Definition at line 176 of file IntervalOfValidity.h.

◆ m_runHigh

int m_runHigh
private

Highest run number.

-1 means no bound.

Definition at line 188 of file IntervalOfValidity.h.

◆ m_runLow

int m_runLow
private

Lowest run number.

-1 means no bound.

Definition at line 180 of file IntervalOfValidity.h.


The documentation for this class was generated from the following files: