Belle II Software development
LocalMetadataProvider.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/database/LocalMetadataProvider.h>
10
11#include <framework/logging/Logger.h>
12
13namespace Belle2::Conditions {
14
15 LocalMetadataProvider::LocalMetadataProvider(std::string filename, const std::set<std::string>& usableTagStates):
16 MetadataProvider(usableTagStates), m_filename{std::move(filename)}, m_connection{m_filename},
17 m_globaltagStatus{m_connection, "SELECT globalTagStatus FROM globaltags WHERE globalTagName=:globaltag", true},
18 m_selectPayloads{m_connection, R"SQL(
19 SELECT
20 payloadName, globalTagName, payloadUrl, baseUrl, checksum,
21 firstExp, firstRun, finalExp, finalRun, revision
22 FROM iov_payloads
23 WHERE globalTagName=:globaltag AND
24 ((firstExp==:exp AND firstRun<=:run) OR firstExp<:exp) AND
25 (finalExp<0 OR (finalRun<0 AND finalExp>=:exp) OR finalExp>:exp OR (finalExp==:exp AND finalRun>=:run));
26 )SQL", true}
27 {
29 }
30
31 std::string LocalMetadataProvider::getGlobaltagStatus(const std::string& globaltag)
32 {
33 try {
34 if (m_globaltagStatus.execute(globaltag).step()) {
35 return m_globaltagStatus.getRow();
36 }
37 B2ERROR("Local Database: Global tag does not exist"
38 << LogVar("database", m_filename) << LogVar("globaltag", globaltag));
39 } catch (std::exception& e) {
40 B2ERROR("Local Database: Error checking globaltag"
41 << LogVar("database", m_filename) << LogVar("globaltag", globaltag) << LogVar("error", e.what()));
42 }
43 return "";
44 }
45
46 bool LocalMetadataProvider::updatePayloads(const std::string& globaltag, int exp, int run)
47 {
48 try {
49 for (auto&& row : m_selectPayloads.execute(globaltag, exp, run)) {
50 addPayload(std::move(row), "Local Database");
51 }
52 } catch (std::exception& e) {
53 B2ERROR("Local Database: Error obtaining payloads"
54 << LogVar("database", m_filename) << LogVar("globaltag", globaltag) << LogVar("error", e.what()));
55 return false;
56 }
57 return true;
58 }
59} // Belle2::Conditions namespace
LocalMetadataProvider(std::string filename, const std::set< std::string > &usableTagStates)
Construct with the name of the sqlite file.
bool updatePayloads(const std::string &globaltag, int exp, int run) override
Update the list of existing payloads from a given globaltag, exp and run combination.
sqlite::ObjectStatement< PayloadMetadata, std::string, std::string, std::string, std::string, std::string, int, int, int, int, int > m_selectPayloads
SQLite statement to return all payloads for a given globaltag, exp, run.
std::string getGlobaltagStatus(const std::string &globaltag) override
Return the status of the given globaltag.
sqlite::SimpleStatement< std::string > m_globaltagStatus
SQLite statement to return the status of a global tag.
std::string m_filename
Filename for the sqlite database file.
Base class for a payload metadata provider.
void printInfoMessage(const std::string &provider)
Print an INFO message about the used metadata provider.
void addPayload(PayloadMetadata &&payload, const std::string &messagePrefix="")
Add a payload information to the internal list.
Class to store variables with their name which were sent to the logging service.
STL namespace.