Skip to content

Commit

Permalink
add separate method to extract run-duration from RCT info headers
Browse files Browse the repository at this point in the history
  • Loading branch information
shahor02 committed Oct 11, 2024
1 parent 3fba187 commit e9e205d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CCDB/include/CCDB/BasicCCDBManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class CCDBManagerInstance
/// On error it fatals (if fatal == true) or else returns the pair -1, -1.
std::pair<int64_t, int64_t> getRunDuration(int runnumber, bool fatal = true);
static std::pair<int64_t, int64_t> getRunDuration(o2::ccdb::CcdbApi const& api, int runnumber, bool fatal = true);

static std::pair<int64_t, int64_t> getRunDuration(const MD& headers);
std::string getSummaryString() const;

size_t getFetchedSize() const { return mFetchedSize; }
Expand Down
45 changes: 24 additions & 21 deletions CCDB/src/BasicCCDBManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,47 @@ void CCDBManagerInstance::reportFatal(std::string_view err)
LOG(fatal) << err;
}

std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(o2::ccdb::CcdbApi const& api, int runnumber, bool fatal)
std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(const std::map<std::string, std::string>& headers)
{
auto response = api.retrieveHeaders("RCT/Info/RunInformation", std::map<std::string, std::string>(), runnumber);
if (response.size() != 0) {
if (headers.size() != 0) {
std::string report{};
auto strt = response.find("STF");
auto stop = response.find("ETF");
long valStrt = (strt == response.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
long valStop = (stop == response.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
auto strt = headers.find("STF");
auto stop = headers.find("ETF");
long valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
long valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
if (valStrt < 0 || valStop < 0) {
report += "Missing STF/EFT -> use SOX/EOX;";
strt = response.find("SOX");
valStrt = (strt == response.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
strt = headers.find("SOX");
valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
if (valStrt < 1) {
report += fmt::format(" Missing/invalid SOX -> use SOR");
strt = response.find("SOR");
valStrt = (strt == response.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
strt = headers.find("SOR");
valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
}
stop = response.find("EOX");
valStop = (stop == response.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
stop = headers.find("EOX");
valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
if (valStop < 1) {
report += fmt::format(" | Missing/invalid EOX -> use EOR");
stop = response.find("EOR");
valStop = (stop == response.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
stop = headers.find("EOR");
valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
}
if (!report.empty()) {
LOGP(warn, "{}", report);
}
}
if (valStrt > 0 && valStop >= valStrt) {
return std::make_pair(valStrt, valStop);
}
return std::make_pair(valStrt, valStop);
}
// failure
if (fatal) {
return std::make_pair(-1L, -1L);
}

std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(o2::ccdb::CcdbApi const& api, int runnumber, bool fatal)
{
auto headers = api.retrieveHeaders("RCT/Info/RunInformation", std::map<std::string, std::string>(), runnumber);
auto response = getRunDuration(headers);
if ((response.first <= 0 || response.second < response.first) && fatal) {
LOG(fatal) << "Empty, missing or invalid response from query to RCT/Info/RunInformation for run " << runnumber;
}
return std::make_pair(-1L, -1L);
return response;
}

std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(int runnumber, bool fatal)
Expand Down

0 comments on commit e9e205d

Please sign in to comment.