9#include <framework/database/CentralMetadataProvider.h>
10#include <framework/logging/Logger.h>
12using json = nlohmann::json;
14namespace Belle2::Conditions {
20 const auto result =
get(
"/v2/globalTagStatus");
23 std::string invalidStates =
"";
24 for (
const auto& info : result) {
25 const std::string status = info.at(
"name");
26 if (not validStates.erase(status)) {
27 if (!invalidStates.empty()) invalidStates +=
", ";
28 invalidStates += status;
32 B2DEBUG(31,
"Conditions Database: unusable globaltag states: " << invalidStates);
33 for (
const auto& status : validStates) {
34 B2WARNING(
"Conditions Database: status marked as usable for global tags is not known to the database"
35 <<
LogVar(
"status", status));
42 std::stringstream stream;
46 stream.seekg(0, std::ios::beg);
47 return json::parse(stream);
53 const std::string url =
"/v2/globalTag/" + escaped;
55 const auto gtinfo =
get(url);
56 return gtinfo.at(
"globalTagStatus").at(
"name");
57 }
catch (std::runtime_error& e) {
58 B2ERROR(
"Conditions Database: Cannot download information on global tag. Usually this means it "
59 "doesn't exist and you misspelled the name"
61 }
catch (std::exception& e) {
62 B2ERROR(
"Conditions Database: Problem determining global tag status"
71 const std::string url =
"v2/iovPayloads/?gtName=" + escaped +
72 "&expNumber=" + std::to_string(exp) +
73 "&runNumber=" + std::to_string(run);
75 const auto payloads =
get(url);
76 if (!payloads.is_array())
throw std::runtime_error(
"expected array");
77 for (
const auto& info : payloads) {
78 if (!info.is_object())
throw std::runtime_error(
"excpected payload object");
79 const auto& payload = info.at(
"payload");
80 const auto& iov = info.at(
"payloadIov");
82 payload.at(
"basf2Module").at(
"name"),
84 payload.at(
"payloadUrl"),
85 payload.at(
"baseUrl"),
86 payload.at(
"checksum"),
87 iov.at(
"expStart"), iov.at(
"runStart"), iov.at(
"expEnd"), iov.at(
"runEnd"),
88 payload.at(
"revision")
91 }
catch (std::exception& e) {
92 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 joinWithSlash(const std::string &base, const std::string &second)
Join two strings and make sure that there is exactly one '/' between them.
std::string escapeString(const std::string &text)
Escape a string to make it safe to be used in web requests.
Class to store variables with their name which were sent to the logging service.