9#include <boost/python/def.hpp>
10#include <boost/python/overloads.hpp>
11#include <boost/python/docstring_options.hpp>
12#include <boost/python/list.hpp>
13#include <boost/python/dict.hpp>
14#include <boost/python/extract.hpp>
15#include <boost/python/return_value_policy.hpp>
16#include <boost/python/manage_new_object.hpp>
17#include <boost/python/raw_function.hpp>
18#include <boost/algorithm/string.hpp>
20#include <framework/database/Database.h>
22#include <framework/dataobjects/EventMetaData.h>
23#include <framework/logging/Logger.h>
24#include <framework/database/DBStore.h>
26#include <framework/database/PayloadProvider.h>
27#include <framework/database/MetadataProvider.h>
28#include <framework/database/LocalMetadataProvider.h>
29#include <framework/database/CentralMetadataProvider.h>
30#include <framework/database/HSFCentralMetadataProvider.h>
31#include <framework/database/Configuration.h>
53 conf.setInitialized(
false);
75 std::vector<DBQuery> query{
DBQuery{name,
true}};
77 entry.
updatePayload(query[0].revision, query[0].iov, query[0].filename, query[0].checksum, query[0].globaltag, event);
87 const size_t testingPayloads = std::count_if(query.begin(), query.end(), [
this, &event](
auto & payload) {
89 payload.filename =
"";
92 for (auto& tmp : m_testingPayloads) {
93 if (tmp.get(event, payload)) return true;
98 if (testingPayloads == query.size())
return true;
101 m_metadataProvider->getPayloads(event.getExperiment(), event.getRun(), query);
102 }
catch (std::exception&) {
104 B2WARNING(
"Conditions data: Problem with payload metadata provider, trying to fall back to next provider..."
105 <<
LogVar(
"provider", m_currentProvider));
106 nextMetadataProvider();
107 return getData(event, query);
110 const size_t payloadsLocated = std::count_if(query.begin(), query.end(), [
this](
auto & payload) {
112 if (!payload.filename.empty()) return true;
116 if (payload.revision == 0) return not payload.required;
118 if (not m_payloadProvider->find(payload)) {
122 auto loglevel = payload.required ? LogConfig::c_Error : LogConfig::c_Warning;
123 B2LOG(loglevel, 0,
"Conditions data: Could not find file for payload"
124 << LogVar(
"name", payload.name) << LogVar(
"revision", payload.revision)
125 << LogVar(
"checksum", payload.checksum) << LogVar(
"globaltag", payload.globaltag));
126 return not payload.required;
131 return payloadsLocated == query.size();
136 return std::all_of(query.begin(), query.end(), [
this](
const auto &
import) {
137 return storeData(import.name, import.object, import.iov);
162 B2FATAL(
"Conditions data: No more metadata providers available");
170 boost::algorithm::to_lower(protocol);
171 if (protocol ==
"file") {
173 }
else if (protocol ==
"http" or protocol ==
"https") {
176 B2FATAL(
"Conditions data: Unknown metadata protocol, only supported protocols for payload metadata are file, http, https"
177 <<
LogVar(
"protocol", protocol));
191 }
catch (std::exception& e) {
192 B2WARNING(
"Conditions data: Metadata provider not usable, trying next one ..."
198 B2WARNING(
"Conditions data: One (or more) globaltag is not available in the current metadata proivder, trying next one ...");
212 conf.setInitialized(
true);
217 [](
const auto & tag) {
218 return boost::algorithm::trim_copy(tag);
221 std::set<std::string> seen;
223 [&seen](
const auto & tag) {
224 return not seen.insert(tag).second;
247 B2INFO(
"Conditions data: configured globaltag is " <<
m_globalTags[0]);
249 B2INFO(
"Conditions data: configured globaltags (highest priority first) are " << boost::algorithm::join(
m_globalTags,
", "));
254 conf.getPayloadLocations(),
255 conf.getDownloadCacheDirectory(),
256 conf.getDownloadLockTimeout()
259 m_payloadCreation = std::make_unique<Conditions::TestingPayloadStorage>(conf.getNewPayloadLocation());
262 for (
const auto& path : conf.getTestingPayloadLocations()) {
263 B2INFO(
"Conditions data: configured to use testing payloads" <<
LogVar(
"location", path));
268 B2WARNING(R
"(Conditions data: configured to look for temporary testing payloads from one or more local folders.
270 This will lead to non-reproducible results and is strictly only for testing purposes.
271 It is NOT ALLOWED for official productions or data analysis and any results obtained like this WILL NOT BE PUBLISHED.
281 namespace py = boost::python;
287 py::docstring_options options(
true,
true,
false);
static Configuration & getInstance()
Get a reference to the instance which will be used when the Database is initialized.
static void exposePythonAPI()
expose this class to python
ScopeGuard ensureSession()
Make sure there's an active session and return a ScopeGuard object that closes the session on destruc...
static Downloader & getDefaultInstance()
Return the default instance.
Class to hold one entry from the ConditionsDB in the DBStore.
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
TObject * releaseObject()
Return the pointer to the current object and release ownership: The caller is responsible to clean up...
std::string m_currentProvider
Name of the currently used metadata provider.
std::unique_ptr< Conditions::MetadataProvider > m_metadataProvider
Currently active metadata provider.
EDatabaseState m_configState
Current configuration state of the database.
EDatabaseState
State of the database.
@ c_PreInit
Before any initialization.
@ c_InitGlobaltagList
Globaltag list has been finalized metadata providers not and globaltags are not checked for usability...
@ c_Ready
Everything is ready.
Conditions::PayloadMetadata DBQuery
Struct for bulk read queries.
std::unique_ptr< Conditions::PayloadProvider > m_payloadProvider
The active payload provider.
std::set< std::string > m_usableTagStates
Set of usable globaltag states to be handed to the metadata providers.
std::unique_ptr< Conditions::TestingPayloadStorage > m_payloadCreation
testing payload storage to create new payloads
std::vector< std::string > m_globalTags
List of globaltags to be used.
std::vector< Conditions::TestingPayloadStorage > m_testingPayloads
optional list of testing payload storages to look for existing payloads
std::vector< std::string > m_metadataConfigurations
List of available metadata providers (which haven't been tried yet)
Database()=default
Hidden constructor, as it is a singleton.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Simple ScopeGuard to execute a function at the end of the object lifetime.
Class to store variables with their name which were sent to the logging service.
void reset(bool keepEntries=false)
Invalidate all payloads.
std::string getGlobalTags()
Return the global tags used by the database.
void initialize(const EDatabaseState target=c_Ready)
Initialize the database connection settings on first use.
~Database()
Hidden destructor, as it is a singleton.
std::pair< TObject *, IntervalOfValidity > getData(const EventMetaData &event, const std::string &name)
Request an object from the database.
static Database & Instance()
Instance of a singleton Database.
static DBStore & Instance()
Instance of a singleton DBStore.
static void exposePythonAPI()
Exposes setGlobalTag function of the Database class to Python.
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
void nextMetadataProvider()
Enable the next metadataprovider in the list.
static void reset(bool keepConfig=false)
Reset the database instance.
ScopeGuard createScopedUpdateSession()
Make sure we have efficient http pipelinging during initialize/beginRun but don't keep session alive ...
void updatePayload(unsigned int revision, const IntervalOfValidity &iov, const std::string &filename, const std::string &checksum, const std::string &globaltag, const EventMetaData &event)
Update the payload information for this entry and if appropriate open the new file and extract the ob...
Abstract base class for different kinds of events.