9#include <framework/database/MetadataProvider.h>
10#include <framework/logging/Logger.h>
12#include <boost/algorithm/string.hpp>
14namespace Belle2::Conditions {
18 const size_t validTags = std::count_if(
m_tags.begin(),
m_tags.end(), [
this](
const auto & name) {
20 auto status = getGlobaltagStatus(name);
22 if (status.empty()) return false;
24 if (m_usableTagStates.count(status) == 0) {
25 B2ERROR(
"The globaltag has a status which is not permitted for use. This is for your own protection"
26 << LogVar(
"globaltag", name)
27 << LogVar(
"status", status)
28 << LogVar(
"allowed states", boost::algorithm::join(m_usableTagStates,
", ")));
33 return validTags == tags.size();
36 bool MetadataProvider::getPayloads(
int exp,
int run, std::vector<PayloadMetadata>& info)
38 if (info.empty())
return true;
39 for (
const auto& tag : m_tags) {
42 std::tie(present, m_payloads) = m_cache[tag].get(exp, run);
44 if (!present && !updatePayloads(tag, exp, run)) {
47 throw std::runtime_error(
"Problem updating metadata");
50 const auto& existing = *m_payloads;
55 const size_t found = std::count_if(info.begin(), info.end(), [&existing](
auto & payload) {
57 if (payload.revision > 0 or !payload.filename.empty()) return true;
59 if (auto&& it = existing.find(payload.name); it != existing.end()) {
60 payload.update(it->second);
61 B2DEBUG(35,
"Found requested payload metadata"
62 << LogVar(
"globaltag", payload.globaltag)
63 << LogVar(
"name", payload.name)
64 << LogVar(
"revision", payload.revision)
65 << LogVar(
"checksum", payload.checksum));
72 if (found == info.size())
break;
77 const int missing = std::count_if(info.begin(), info.end(), [
this, exp, run](
const auto & p) {
78 if (p.revision == 0 and p.filename.empty() and p.required) {
79 B2ERROR(
"Cannot find payload in any of the configured global tags"
80 << LogVar(
"name", p.name)
81 << LogVar(
"globaltags", boost::algorithm::join(m_tags,
", "))
82 << LogVar(
"experiment", exp) << LogVar(
"run", run));
91 void MetadataProvider::addPayload(
PayloadMetadata&& payload,
const std::string& messagePrefix)
93 const auto [it, inserted] = m_payloads->emplace(payload.name, payload);
95 auto& existing = it->second;
96 if (existing.revision < payload.revision) {
97 std::swap(existing, payload);
99 B2DEBUG(36, messagePrefix << (messagePrefix.empty() ?
"" :
": ") <<
"Found duplicate payload. Discarding one of them"
100 <<
LogVar(
"globaltag", existing.globaltag)
101 <<
LogVar(
"name", existing.name)
102 <<
LogVar(
"revision", existing.revision)
103 <<
LogVar(
"checksum", existing.checksum)
104 <<
LogVar(
"discarded revision", payload.revision));
106 B2DEBUG(37, messagePrefix << (messagePrefix.empty() ?
"" :
": ") <<
"Found payload"
107 <<
LogVar(
"globaltag", payload.globaltag)
108 <<
LogVar(
"name", payload.name)
109 <<
LogVar(
"revision", payload.revision)
110 <<
LogVar(
"checksum", payload.checksum));
114 void MetadataProvider::printInfoMessage(
const std::string& provider =
"")
116 B2INFO(
"Conditions Database: found working metadata provider"
117 <<
LogVar(
"provider", provider));
120 std::string NullMetadataProvider::getGlobaltagStatus([[maybe_unused]]
const std::string& name)
122 if (!m_errorShown) B2ERROR(
"No Metadata provider configured, globaltags cannot be used");
Class to store variables with their name which were sent to the logging service.