Project
Loading...
Searching...
No Matches
BasicCCDBManager.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12//
13// Created by Sandro Wenzel on 2019-08-14.
14//
18#include <boost/lexical_cast.hpp>
19#include <fairlogger/Logger.h>
20#include <string>
21
22namespace o2
23{
24namespace ccdb
25{
26
27void CCDBManagerInstance::setURL(std::string const& url)
28{
29 mCCDBAccessor.init(url);
30}
31
32void CCDBManagerInstance::reportFatal(std::string_view err)
33{
34 LOG(fatal) << err;
35}
36
37std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(const std::map<std::string, std::string>& headers)
38{
39 if (headers.size() != 0) {
40 std::string report{};
41 auto strt = headers.find("STF");
42 auto stop = headers.find("ETF");
43 long valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
44 long valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
45 if (valStrt < 0 || valStop < 0) {
46 report += "Missing STF/EFT -> use SOX/EOX;";
47 strt = headers.find("SOX");
48 valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
49 if (valStrt < 1) {
50 report += fmt::format(" Missing/invalid SOX -> use SOR");
51 strt = headers.find("SOR");
52 valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
53 }
54 stop = headers.find("EOX");
55 valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
56 if (valStop < 1) {
57 report += fmt::format(" | Missing/invalid EOX -> use EOR");
58 stop = headers.find("EOR");
59 valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
60 }
61 if (!report.empty()) {
62 LOGP(warn, "{}", report);
63 }
64 }
65 return std::make_pair(valStrt, valStop);
66 }
67 return std::make_pair(-1L, -1L);
68}
69
70std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(o2::ccdb::CcdbApi const& api, int runnumber, bool fatal)
71{
72 auto headers = api.retrieveHeaders("RCT/Info/RunInformation", std::map<std::string, std::string>(), runnumber);
73 auto response = getRunDuration(headers);
74 if ((response.first <= 0 || response.second < response.first) && fatal) {
75 LOG(fatal) << "Empty, missing or invalid response from query to RCT/Info/RunInformation for run " << runnumber;
76 }
77 return response;
78}
79
80std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(int runnumber, bool fatal)
81{
82 mQueries++;
83 if (!isCachingEnabled()) {
84 return CCDBManagerInstance::getRunDuration(mCCDBAccessor, runnumber, fatal);
85 }
86 auto& cached = mCache["RCT-Run-Info HeaderOnly"];
87 std::pair<int64_t, int64_t> rd;
88 cached.queries++;
89 if (cached.startvalidity != runnumber) { // need to fetch
90 rd = CCDBManagerInstance::getRunDuration(mCCDBAccessor, runnumber, fatal);
91 cached.objPtr = std::make_shared<std::pair<int64_t, int64_t>>(rd);
92 cached.startvalidity = runnumber;
93 cached.endvalidity = runnumber + 1;
94 cached.minSize = cached.maxSize = 0;
95 cached.fetches++;
96 } else {
97 rd = *reinterpret_cast<std::pair<int64_t, int64_t>*>(cached.objPtr.get());
98 }
99 return rd;
100}
101
103{
104 std::string res = fmt::format("{} queries, {} bytes", mQueries, fmt::group_digits(mFetchedSize));
105 if (mCachingEnabled) {
106 res += fmt::format(" for {} objects", mCache.size());
107 }
108 res += fmt::format(", {} good fetches (and {} failed ones", mFetches, mFailures);
109 if (mCachingEnabled && mFailures) {
110 int nfailObj = 0;
111 for (const auto& obj : mCache) {
112 if (obj.second.failures) {
113 nfailObj++;
114 }
115 }
116 res += fmt::format(" for {} objects", nfailObj);
117 }
118 res += fmt::format(") in {} ms, instance: {}", fmt::group_digits(mTimerMS), mCCDBAccessor.getUniqueAgentID());
119 return res;
120}
121
123{
124 LOG(info) << "CCDBManager summary: " << getSummaryString();
125 if (longrep && mCachingEnabled) {
126 LOGP(info, "CCDB cache miss/hit/failures");
127 for (const auto& obj : mCache) {
128 LOGP(info, " {}: {}/{}/{} ({}-{} bytes)", obj.first, obj.second.fetches, obj.second.queries - obj.second.fetches - obj.second.failures, obj.second.failures, obj.second.minSize, obj.second.maxSize);
129 }
130 }
131}
132
134{
135 report(true);
136}
137
138} // namespace ccdb
139} // namespace o2
std::string url
uint32_t res
Definition RawData.h:0
void report(bool longrep=false)
bool isCachingEnabled() const
check if caching is enabled
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
void setURL(const std::string &url)
set a URL to query from
const std::string getUniqueAgentID() const
Definition CcdbApi.h:71
void init(std::string const &hosts)
Definition CcdbApi.cxx:160
std::map< std::string, std::string > retrieveHeaders(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1) const
Definition CcdbApi.cxx:1445
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::random_device rd