Belle II Software development
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 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()
Default constructor which will create an empty iov.

◆ 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 62 of file IntervalOfValidity.h.

62{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/2]

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 80 of file IntervalOfValidity.cc.

81{
82 auto experiment = (int) event.getExperiment();
83 auto run = (int) event.getRun();
84
85 // check for empty interval
86 if (empty()) return false;
87
88 // check lower bound
89 if (checkLowerBound(experiment, run) < 0) return false;
90 if (checkUpperBound(experiment, run) > 0) return false;
91 return true;
92}
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() [2/2]

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 86 of file IntervalOfValidity.h.

86{return overlap(iov) == iov;};
IntervalOfValidity overlap(const IntervalOfValidity &iov) const
Function that determines the overlap of the validity interval with another interval of validity.

◆ 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 55 of file IntervalOfValidity.h.

55{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 137 of file IntervalOfValidity.h.

138 {
139 return m_experimentHigh;
140 }

◆ 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 117 of file IntervalOfValidity.h.

118 {
119 return m_experimentLow;
120 }

◆ getRunHigh()

int getRunHigh ( ) const
inline

Getter for highest run number.

-1 means no bound.

Definition at line 145 of file IntervalOfValidity.h.

146 {
147 return m_runHigh;
148 }

◆ getRunLow()

int getRunLow ( ) const
inline

Getter for lowest run number.

-1 means no bound.

Definition at line 125 of file IntervalOfValidity.h.

126 {
127 return m_runLow;
128 }

◆ 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 76 of file IntervalOfValidity.h.

77 {
78 return !(*this == other);
79 }

◆ operator==()

bool operator== ( const IntervalOfValidity other) const
inline

Check whether two intervals of validity are identical.

Definition at line 67 of file IntervalOfValidity.h.

68 {
69 return (m_experimentLow == other.m_experimentLow) && (m_runLow == other.m_runLow) &&
70 (m_experimentHigh == other.m_experimentHigh) && (m_runHigh == other.m_runHigh);
71 }

◆ 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 94 of file IntervalOfValidity.cc.

95{
96 if (empty() || iov.empty()) return IntervalOfValidity();
97
98 IntervalOfValidity result(*this);
99 if (checkLowerBound(iov.m_experimentLow, iov.m_runLow) > 0) {
100 result.m_experimentLow = iov.m_experimentLow;
101 result.m_runLow = iov.m_runLow;
102 }
103 if (checkUpperBound(iov.m_experimentHigh, iov.m_runHigh) < 0) {
104 result.m_experimentHigh = iov.m_experimentHigh;
105 result.m_runHigh = iov.m_runHigh;
106 }
107
108 result.makeValid();
109 return result;
110}
A class that describes the interval of experiments/runs for which an object in the database is valid.

◆ 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 93 of file IntervalOfValidity.h.

93{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 112 of file IntervalOfValidity.cc.

113{
114 if (!overlaps(iov)) return true;
115
116 bool thisOlder = checkLowerBound(iov.m_experimentLow, iov.m_runLow) >= 0;
117 IntervalOfValidity& older = (thisOlder) ? *this : iov;
118 IntervalOfValidity& younger = (thisOlder) ? iov : *this;
119
120 if (trimOlder) {
121 // check for the case where trimming is not possible because the interval would be split
122 if (older.checkUpperBound(younger.m_experimentHigh, younger.m_runHigh) < 0) return false;
123
124 older.m_experimentHigh = younger.m_experimentLow;
125 older.m_runHigh = younger.m_runLow - 1;
126 if (older.m_runHigh < 0) {
127 older.m_experimentHigh--;
128 older.m_runHigh = -1;
129 }
130 older.makeValid();
131 } else {
132 younger.m_experimentLow = older.m_experimentHigh;
133 younger.m_runLow = older.m_runHigh + 1;
134 if (younger.m_runLow == 0) {
135 younger.m_experimentLow++;
136 }
137 younger.makeValid();
138 }
139
140 return true;
141}
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 Function 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 194 of file IntervalOfValidity.cc.

195 {
196 output << iov.m_experimentLow << "," << iov.m_runLow << "," << iov.m_experimentHigh << "," << iov.m_runHigh;
197
198 return output;
199 }

◆ 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 150 of file IntervalOfValidity.cc.

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

Member Data Documentation

◆ m_experimentHigh

int m_experimentHigh
private

Highest experiment number.

-1 means no bound.

Definition at line 176 of file IntervalOfValidity.h.

◆ m_experimentLow

int m_experimentLow
private

Lowest experiment number.

-1 means no bound.

Definition at line 168 of file IntervalOfValidity.h.

◆ m_runHigh

int m_runHigh
private

Highest run number.

-1 means no bound.

Definition at line 180 of file IntervalOfValidity.h.

◆ m_runLow

int m_runLow
private

Lowest run number.

-1 means no bound.

Definition at line 172 of file IntervalOfValidity.h.


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