9#include <framework/database/IntervalOfValidity.h>
10#include <framework/dataobjects/EventMetaData.h>
11#include <framework/logging/Logger.h>
18 int runHigh) : m_experimentLow(experimentLow), m_runLow(runLow), m_experimentHigh(experimentHigh), m_runHigh(runHigh)
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.");
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.");
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.");
43 if (
empty())
return false;
57 if (
empty())
return false;
83 auto run = (int) event.
getRun();
86 if (
empty())
return false;
100 result.m_experimentLow = iov.m_experimentLow;
101 result.m_runLow = iov.m_runLow;
104 result.m_experimentHigh = iov.m_experimentHigh;
105 result.m_runHigh = iov.m_runHigh;
116 bool thisOlder =
checkLowerBound(iov.m_experimentLow, iov.m_runLow) >= 0;
154 throw std::runtime_error(
"cannot read from stream");
159 while (input.good()) {
160 auto c = input.peek();
162 if (((c ==
' ') || (c ==
'\n') || (c ==
'\t'))) {
164 if (index == 0 && str[0].empty()) {
173 if (index == 4)
break;
180 throw std::invalid_argument(
"IoV needs to be four values (firstExp,firstRun,finalExp,finalRun)");
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");
196 output << iov.m_experimentLow <<
"," << iov.m_runLow <<
"," << iov.m_experimentHigh <<
"," << iov.m_runHigh;
A class that describes the interval of experiments/runs for which an object in the database is valid.
bool trimOverlap(IntervalOfValidity &iov, bool trimOlder=true)
Remove the overlap between two intervals of validity by shortening one of them.
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...
bool empty() const
Function that checks whether the validity interval is empty.
void makeValid()
Helper function to set the interval to empty if the upper bound is below the lower one.
int m_runLow
Lowest run number.
bool contains(const EventMetaData &event) const
Function that checks whether the event is inside the validity interval.
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...
bool overlaps(const IntervalOfValidity &iov) const
Function that checks the validity interval overlaps with another interval of validity.
int m_experimentLow
Lowest experiment number.
IntervalOfValidity overlap(const IntervalOfValidity &iov) const
Function that determines the overlap of the validity interval with another interval of validity.
int m_experimentHigh
Highest experiment number.
IntervalOfValidity()
Default constructor which will create an empty iov.
int m_runHigh
Highest run number.
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
std::istream & operator>>(std::istream &input, IntervalOfValidity &iov)
Abstract base class for different kinds of events.