 |
Belle II Software
release-05-01-25
|
11 #include <framework/database/CentralMetadataProvider.h>
12 #include <framework/logging/Logger.h>
14 using json = nlohmann::json;
16 namespace Belle2::Conditions {
22 const auto result =
get(
"/v2/globalTagStatus");
25 std::string invalidStates =
"";
26 for (
const auto& info : result) {
27 const std::string status = info.at(
"name");
28 if (not validStates.erase(status)) {
29 if (!invalidStates.empty()) invalidStates +=
", ";
30 invalidStates += status;
33 B2INFO(
"Conditions Database: found working server" <<
LogVar(
"url",
m_baseUrl));
34 B2DEBUG(31,
"Conditions Database: unusable globaltag states: " << invalidStates);
35 for (
const auto& status : validStates) {
36 B2WARNING(
"Conditions Database: status marked as usable for global tags is not known to the database"
37 <<
LogVar(
"status", status));
44 std::stringstream stream;
48 stream.seekg(0, std::ios::beg);
49 return json::parse(stream);
55 const std::string url =
"/v2/globalTag/" + escaped;
57 const auto gtinfo =
get(url);
58 return gtinfo.at(
"globalTagStatus").at(
"name");
59 }
catch (std::runtime_error& e) {
60 B2ERROR(
"Conditions Database: Cannot download information on global tag. Usually this means it "
61 "doesn't exist and you misspelled the name"
63 }
catch (std::exception& e) {
64 B2ERROR(
"Conditions Database: Problem determining global tag status"
73 const std::string url =
"v2/iovPayloads/?gtName=" + escaped +
74 "&expNumber=" + std::to_string(exp) +
75 "&runNumber=" + std::to_string(run);
77 const auto payloads =
get(url);
78 if (!payloads.is_array())
throw std::runtime_error(
"expected array");
79 for (
const auto& info : payloads) {
80 if (!info.is_object())
throw std::runtime_error(
"excpected payload object");
81 const auto& payload = info.at(
"payload");
82 const auto& iov = info.at(
"payloadIov");
84 payload.at(
"basf2Module").at(
"name"),
86 payload.at(
"payloadUrl"),
87 payload.at(
"baseUrl"),
88 payload.at(
"checksum"),
89 iov.at(
"expStart"), iov.at(
"runStart"), iov.at(
"expEnd"), iov.at(
"runEnd"),
90 payload.at(
"revision")
93 }
catch (std::exception& e) {
94 B2ERROR(
"Conditions Database: Problem parsing payload information."
bool download(const std::string &url, std::ostream &stream, bool silentOnMissing=false)
get an url and save the content to stream This function raises exceptions when there are any problems
std::string escapeString(const std::string &text)
Escape a string to make it safe to be used in web requests.
std::string joinWithSlash(const std::string &base, const std::string &second)
Join two strings and make sure that there is exactly one '/' between them.
Class to store variables with their name which were sent to the logging service.