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//
16#include <boost/lexical_cast.hpp>
17#include <fairlogger/Logger.h>
18#include <string>
19
20namespace o2
21{
22namespace ccdb
23{
24
25void CCDBManagerInstance::setURL(std::string const& url)
26{
27 mCCDBAccessor.init(url);
28}
29
30void CCDBManagerInstance::reportFatal(std::string_view err)
31{
32 LOG(fatal) << err;
33}
34
35std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(const std::map<std::string, std::string>& headers)
36{
37 if (headers.size() != 0) {
38 std::string report{};
39 auto strt = headers.find("STF");
40 auto stop = headers.find("ETF");
41 long valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
42 long valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
43 if (valStrt < 0 || valStop < 0) {
44 report += "Missing STF/EFT -> use SOX/EOX;";
45 strt = headers.find("SOX");
46 valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
47 if (valStrt < 1) {
48 report += fmt::format(" Missing/invalid SOX -> use SOR");
49 strt = headers.find("SOR");
50 valStrt = (strt == headers.end()) ? -1L : boost::lexical_cast<int64_t>(strt->second);
51 }
52 stop = headers.find("EOX");
53 valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
54 if (valStop < 1) {
55 report += fmt::format(" | Missing/invalid EOX -> use EOR");
56 stop = headers.find("EOR");
57 valStop = (stop == headers.end()) ? -1L : boost::lexical_cast<int64_t>(stop->second);
58 }
59 if (!report.empty()) {
60 LOGP(warn, "{}", report);
61 }
62 }
63 return std::make_pair(valStrt, valStop);
64 }
65 return std::make_pair(-1L, -1L);
66}
67
68std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(o2::ccdb::CcdbApi const& api, int runnumber, bool fatal)
69{
70 auto headers = api.retrieveHeaders("RCT/Info/RunInformation", std::map<std::string, std::string>(), runnumber);
71 auto response = getRunDuration(headers);
72 if ((response.first <= 0 || response.second < response.first) && fatal) {
73 LOG(fatal) << "Empty, missing or invalid response from query to RCT/Info/RunInformation for run " << runnumber;
74 }
75 return response;
76}
77
78std::pair<int64_t, int64_t> CCDBManagerInstance::getRunDuration(int runnumber, bool fatal)
79{
80 mQueries++;
81 if (!isCachingEnabled()) {
82 return CCDBManagerInstance::getRunDuration(mCCDBAccessor, runnumber, fatal);
83 }
84 auto& cached = mCache["RCT-Run-Info HeaderOnly"];
85 std::pair<int64_t, int64_t> rd;
86 cached.queries++;
87 if (cached.startvalidity != runnumber) { // need to fetch
88 rd = CCDBManagerInstance::getRunDuration(mCCDBAccessor, runnumber, fatal);
89 cached.objPtr = std::make_shared<std::pair<int64_t, int64_t>>(rd);
90 cached.startvalidity = runnumber;
91 cached.endvalidity = runnumber + 1;
92 cached.minSize = cached.maxSize = 0;
93 cached.fetches++;
94 } else {
95 rd = *reinterpret_cast<std::pair<int64_t, int64_t>*>(cached.objPtr.get());
96 }
97 return rd;
98}
99
101{
102 std::string res = fmt::format("{} queries, {} bytes", mQueries, fmt::group_digits(mFetchedSize));
103 if (mCachingEnabled) {
104 res += fmt::format(" for {} objects", mCache.size());
105 }
106 res += fmt::format(", {} good fetches (and {} failed ones", mFetches, mFailures);
107 if (mCachingEnabled && mFailures) {
108 int nfailObj = 0;
109 for (const auto& obj : mCache) {
110 if (obj.second.failures) {
111 nfailObj++;
112 }
113 }
114 res += fmt::format(" for {} objects", nfailObj);
115 }
116 res += fmt::format(") in {} ms, instance: {}", fmt::group_digits(mTimerMS), mCCDBAccessor.getUniqueAgentID());
117 return res;
118}
119
121{
122 LOG(info) << "CCDBManager summary: " << getSummaryString();
123 if (longrep && mCachingEnabled) {
124 LOGP(info, "CCDB cache miss/hit/failures");
125 for (const auto& obj : mCache) {
126 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);
127 }
128 }
129}
130
132{
133 report(true);
134}
135
136} // namespace ccdb
137} // namespace o2
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:165
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:1416
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