Belle II Software light-2406-ragdoll
PayloadProvider.h
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#pragma once
9
10#include <framework/database/PayloadMetadata.h>
11#include <framework/database/Downloader.h>
12#include <framework/utilities/FileSystem.h>
13
14#include <vector>
15#include <string>
16#include <unordered_map>
17
18namespace Belle2::Conditions {
21 public:
22
26 std::string base;
29 };
30
32 enum class EDirectoryLayout {
35 c_flat,
40 };
41
64 explicit PayloadProvider(const std::vector<std::string>& locations, const std::string& cachedir = "", int timeout = 60);
65
73 bool find(PayloadMetadata& meta);
74 private:
77 bool getLocalFile(const PayloadLocation& loc, PayloadMetadata& meta) const;
80 bool getRemoteFile(const PayloadLocation& loc, PayloadMetadata& meta);
85 bool getTemporaryFile(const std::string& url, PayloadMetadata& meta, bool silentOnMissing);
87 std::string getFilename(EDirectoryLayout structure, const PayloadMetadata& payload) const;
91 std::vector<PayloadLocation> m_locations;
97 std::unordered_map<std::string, std::unique_ptr<FileSystem::TemporaryFile>> m_temporaryFiles;
100 };
101} // Belle2::Conditions namespace
Simple class to encapsulate libcurl as used by the ConditionsDatabase.
Definition: Downloader.h:22
static Downloader & getDefaultInstance()
Return the default instance.
Definition: Downloader.cc:134
Class to find payload files in a list of locations.
bool getTemporaryFile(const std::string &url, PayloadMetadata &meta, bool silentOnMissing)
Try to download url into a temporary file, if successful set the filename member of the metadata and ...
PayloadLocation m_cacheDir
Location of the cache directory where/how we want to store downloaded payloads.
bool getLocalFile(const PayloadLocation &loc, PayloadMetadata &meta) const
Look for a payload in the local directory location, set the filename member of the metadata instance ...
std::vector< PayloadLocation > m_locations
List of configured lookup locations: The first one will always be the cache directory and the last on...
std::unordered_map< std::string, std::unique_ptr< FileSystem::TemporaryFile > > m_temporaryFiles
Map of all active temporary files we downloaded and keep around until they can be closed.
int m_timeout
Timeout to wait for a write look when trying to download payloads.
EDirectoryLayout
Enumeration of different directory layouts.
@ c_flat
Flat directory containing the payloads in the form dbstore_{NAME}_rev_{REVISION}.root
@ c_hashed
Hashed directory structure containing the payloads in the form AB/{NAME}_r{REVISION}....
std::string getFilename(EDirectoryLayout structure, const PayloadMetadata &payload) const
Return the filename of a payload to look for given a directory structure and some metadata.
Downloader & m_downloader
Instance to the database file downloading instance.
bool find(PayloadMetadata &meta)
Try to find a payload, return true on success, false if it cannot be found.
bool getRemoteFile(const PayloadLocation &loc, PayloadMetadata &meta)
Look for a payload on a remote server and download if possible, set the filename member of the metada...
Simple struct to group all information necessary for a single payload.
Simple struct to represent a lookup location.
bool isRemote
Is this a remote location where we want to download the files?