![]() |
Project
|
#include <CcdbApi.h>
Classes | |
struct | RequestContext |
Public Types | |
typedef struct o2::ccdb::CcdbApi::RequestContext | RequestContext |
Public Member Functions | |
CcdbApi () | |
Default constructor. | |
virtual | ~CcdbApi () |
Default destructor. | |
CcdbApi (const CcdbApi &)=delete | |
void | operator= (const CcdbApi &)=delete |
const std::string | getUniqueAgentID () const |
void | init (std::string const &hosts) |
std::string const & | getURL () const |
bool | isSnapshotMode () const |
int | storeAsTFile (const TObject *rootObject, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const |
template<typename T > | |
int | storeAsTFileAny (const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const |
int | storeAsTFileAny (const TObject *rootobj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const |
template<typename T > | |
std::enable_if<!std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type | retrieveFromTFileAny (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const |
template<typename T > | |
std::enable_if< std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type | retrieveFromTFileAny (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const |
void | truncate (std::string const &path) const |
void | deleteObject (std::string const &path, long timestamp=-1) const |
int | updateMetadata (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp, std::string const &id="", long newEOV=0) |
std::string | list (std::string const &path="", bool latestOnly=false, std::string const &returnFormat="text/plain", long createdNotAfter=-1, long createdNotBefore=-1) const |
void | snapshot (std::string const &ccdbrootpath, std::string const &localDir, long timestamp) const |
bool | isHostReachable () const |
std::vector< std::string > | parseSubFolders (std::string const &reply) const |
std::vector< std::string > | getAllFolders (std::string const &top) const |
bool | retrieveBlob (std::string const &path, std::string const &targetdir, std::map< std::string, std::string > const &metadata, long timestamp, bool preservePathStructure=true, std::string const &localFileName="snapshot.root", std::string const &createdNotAfter="", std::string const &createdNotBefore="") const |
std::map< std::string, std::string > | retrieveHeaders (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1) const |
TObject * | retrieve (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp) const |
TObject * | retrieveFromTFile (std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp, std::map< std::string, std::string > *headers, std::string const &etag, const std::string &createdNotAfter, const std::string &createdNotBefore) const |
void | loadFileToMemory (std::vector< char > &dest, std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp, std::map< std::string, std::string > *headers, std::string const &etag, const std::string &createdNotAfter, const std::string &createdNotBefore, bool considerSnapshot=true) const |
void | saveSnapshot (RequestContext &requestContext) const |
void | scheduleDownload (RequestContext &requestContext, size_t *requestCounter) const |
void | getFromSnapshot (bool createSnapshot, std::string const &path, long timestamp, std::map< std::string, std::string > &headers, std::string &snapshotpath, o2::pmr::vector< char > &dest, int &fromSnapshot, std::string const &etag) const |
void | releaseNamedSemaphore (boost::interprocess::named_semaphore *sem, std::string const &path) const |
boost::interprocess::named_semaphore * | createNamedSemaphore (std::string const &path) const |
void | loadFileToMemory (o2::pmr::vector< char > &dest, const std::string &path, std::map< std::string, std::string > *localHeaders=nullptr) const |
void | loadFileToMemory (o2::pmr::vector< char > &dest, std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp, std::map< std::string, std::string > *headers, std::string const &etag, const std::string &createdNotAfter, const std::string &createdNotBefore, bool considerSnapshot=true) const |
bool | loadLocalContentToMemory (o2::pmr::vector< char > &dest, std::string &url) const |
void | navigateSourcesAndLoadFile (RequestContext &requestContext, int &fromSnapshot, size_t *requestCounter) const |
void | vectoredLoadFileToMemory (std::vector< RequestContext > &requestContext) const |
int | storeAsBinaryFile (const char *buffer, size_t size, const std::string &fileName, const std::string &objectType, const std::string &path, const std::map< std::string, std::string > &metadata, long startValidityTimestamp, long endValidityTimestamp, std::vector< char >::size_type maxSize=0) const |
int | storeAsTFile_impl (const void *obj1, std::type_info const &info, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const |
void * | retrieveFromTFile (std::type_info const &, std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const |
void | runDownloaderLoop (bool noWait) |
void | setCurlRetriesParameters (int numberRetries, int delay=100000) |
Static Public Member Functions | |
static bool | checkAlienToken () |
template<typename T > | |
static std::unique_ptr< std::vector< char > > | createObjectImage (const T *obj, CcdbObjectInfo *info=nullptr) |
static std::unique_ptr< std::vector< char > > | createObjectImage (const TObject *obj, CcdbObjectInfo *info=nullptr) |
static std::unique_ptr< std::vector< char > > | createObjectImage (const void *obj, std::type_info const &tinfo, CcdbObjectInfo *info=nullptr) |
static void * | extractFromTFile (TFile &file, TClass const *cl, const char *what=CCDBOBJECT_ENTRY) |
static bool | getCCDBEntryHeaders (std::string const &url, std::string const &etag, std::vector< std::string > &headers, const std::string &agentID="") |
static void | parseCCDBHeaders (std::vector< std::string > const &headers, std::vector< std::string > &pfns, std::string &etag) |
static CCDBQuery * | retrieveQueryInfo (TFile &) |
static std::map< std::string, std::string > * | retrieveMetaInfo (TFile &) |
static std::string | generateFileName (const std::string &inp) |
static void | curlSetSSLOptions (CURL *curl) |
static std::string | determineSemaphoreName (std::string const &basedir, std::string const &objectpath) |
static bool | removeSemaphore (std::string const &name, bool remove=false) |
static void | removeLeakingSemaphores (std::string const &basedir, bool remove=false) |
static void | appendFlatHeader (o2::pmr::vector< char > &dest, const std::map< std::string, std::string > &headers) |
static bool | isMemoryFileInvalid (const o2::pmr::vector< char > &v) |
template<typename T > | |
static T * | extractFromMemoryBlob (o2::pmr::vector< char > &blob) |
Static Public Attributes | |
static constexpr const char * | CCDBQUERY_ENTRY = "ccdb_query" |
static constexpr const char * | CCDBMETA_ENTRY = "ccdb_meta" |
static constexpr const char * | CCDBOBJECT_ENTRY = "ccdb_object" |
Interface to the CCDB. It uses Curl to talk to the REST api.
use smart pointers ?
handle errors and exceptions
extend code coverage
o2::ccdb::CcdbApi::CcdbApi | ( | ) |
Default constructor.
Definition at line 95 of file CcdbApi.cxx.
|
virtual |
Default destructor.
Definition at line 111 of file CcdbApi.cxx.
|
delete |
|
static |
Definition at line 1906 of file CcdbApi.cxx.
|
static |
Definition at line 128 of file CcdbApi.cxx.
boost::interprocess::named_semaphore * o2::ccdb::CcdbApi::createNamedSemaphore | ( | std::string const & | path | ) | const |
Definition at line 1744 of file CcdbApi.cxx.
|
inlinestatic |
Create a binary image of the arbitrary type object, if CcdbObjectInfo pointer is provided, register there
the assigned object class name and the filename
obj | Raw pointer to the object to store. |
info | optinal info where assigned object name and filename will be filled |
|
static |
Create a binary image of the TObject, if CcdbObjectInfo pointer is provided, register there
the assigned object class name and the filename
obj | Raw pointer to the object to store. |
info | optinal info where assigned object name and filename will be filled |
Definition at line 321 of file CcdbApi.cxx.
|
static |
Create a binary image of the object, if CcdbObjectInfo pointer is provided, register there
the assigned object class name and the filename
obj | Raw pointer to the object to store. |
tinfo | object type info |
info | optinal info where assigned object name and filename will be filled |
Definition at line 307 of file CcdbApi.cxx.
|
static |
Set curl SSL options. The client still will be able to connect to non-ssl endpoints
curl | curl handler |
Definition at line 612 of file CcdbApi.cxx.
Delete the matching version of this object.
path | Path to the object to delete |
timestamp | Timestamp of the object to delete. |
Definition at line 1243 of file CcdbApi.cxx.
|
static |
Definition at line 1737 of file CcdbApi.cxx.
|
inlinestatic |
|
static |
A helper function to extract an object from an existing in-memory TFile
file | a TFile instance |
cl | The TClass object describing the serialized type |
Definition at line 877 of file CcdbApi.cxx.
|
static |
Generates a file-name where the object will be stored (usually, from the provided class name)
Definition at line 798 of file CcdbApi.cxx.
std::vector< std::string > o2::ccdb::CcdbApi::getAllFolders | ( | std::string const & | top | ) | const |
Function returning the complete list of (recursive) paths below a given top path
top | The top folder from which to search |
Definition at line 1582 of file CcdbApi.cxx.
|
static |
Get headers associated to a given CCDBEntry on the server.
url | the url which refers to the objects |
etag | of the previous reply |
headers | the headers found in the request. Will be emptied when we return false. |
Definition at line 1496 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::getFromSnapshot | ( | bool | createSnapshot, |
std::string const & | path, | ||
long | timestamp, | ||
std::map< std::string, std::string > & | headers, | ||
std::string & | snapshotpath, | ||
o2::pmr::vector< char > & | dest, | ||
int & | fromSnapshot, | ||
std::string const & | etag | ||
) | const |
Definition at line 1822 of file CcdbApi.cxx.
|
inline |
|
inline |
void o2::ccdb::CcdbApi::init | ( | std::string const & | hosts | ) |
Initialize connection to CCDB
hosts | The URLs to the CCDB (e.g. "ccdb-test.cern.ch:8080" or to a local snapshot "file:///tmp/CCDBSnapshot"), separated with "," or ";" ("https://localhost:8080,https://ccdb-test.cern.ch:8080") |
Definition at line 165 of file CcdbApi.cxx.
bool o2::ccdb::CcdbApi::isHostReachable | ( | ) | const |
Check whether the url is reachable.
url | The url to test. |
Definition at line 1301 of file CcdbApi.cxx.
|
inlinestatic |
|
inline |
std::string o2::ccdb::CcdbApi::list | ( | std::string const & | path = "" , |
bool | latestOnly = false , |
||
std::string const & | returnFormat = "text/plain" , |
||
long | createdNotAfter = -1 , |
||
long | createdNotBefore = -1 |
||
) | const |
Return the listing of objects, and in some cases subfolders, matching this path. The path can contain sql patterns (correctly encoded) or regexps.
In the case where there is no pattern, the list of subfolders is returned along with all the objects at this path. It does not work recursively and objects from the subfolders are not returned.
In the case where there is a pattern, subfolders are not returned and any object matching the pattern will be returned, including those in subfolders if they match.
Example : Task/Detector will return objects and subfolders in /Task/Detector but not the object(s) in /Task/Detector/Sub. Example : Task/Detector/.* will return any object below Detector recursively. Example : Te*e* will return any object matching this pattern, including Test/detector and TestSecond/A/B.
path | The path to the folder we want to list the children of (default : top dir). |
latestOnly | In case there are several versions of the same object, list only the latest one. |
returnFormat | The format of the returned string -> one of "text/plain (default)", "application/json", "text/xml" |
Definition at line 1191 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::loadFileToMemory | ( | o2::pmr::vector< char > & | dest, |
const std::string & | path, | ||
std::map< std::string, std::string > * | localHeaders = nullptr |
||
) | const |
Definition at line 1987 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::loadFileToMemory | ( | o2::pmr::vector< char > & | dest, |
std::string const & | path, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp, | ||
std::map< std::string, std::string > * | headers, | ||
std::string const & | etag, | ||
const std::string & | createdNotAfter, | ||
const std::string & | createdNotBefore, | ||
bool | considerSnapshot = true |
||
) | const |
Definition at line 1888 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::loadFileToMemory | ( | std::vector< char > & | dest, |
std::string const & | path, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp, | ||
std::map< std::string, std::string > * | headers, | ||
std::string const & | etag, | ||
const std::string & | createdNotAfter, | ||
const std::string & | createdNotBefore, | ||
bool | considerSnapshot = true |
||
) | const |
Definition at line 1873 of file CcdbApi.cxx.
bool o2::ccdb::CcdbApi::loadLocalContentToMemory | ( | o2::pmr::vector< char > & | dest, |
std::string & | url | ||
) | const |
Definition at line 1971 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::navigateSourcesAndLoadFile | ( | RequestContext & | requestContext, |
int & | fromSnapshot, | ||
size_t * | requestCounter | ||
) | const |
Retrieves files either as snapshot or schedules them to be downloaded via CCDBDownloader.
requestContext | Structure giving details about the transfer. |
fromSnapshot | After navigateSourcesAndLoadFile returns signals whether file was retrieved from snapshot. |
requestCounter | Pointer to the variable storing the number of requests to be done. |
Definition at line 1925 of file CcdbApi.cxx.
|
static |
Extract the possible locations for a file and check whether or not the current cached object is still valid.
headers | the headers to be parsed |
pfns | the vector of pfns to be filled. |
etag | the etag to be updated with the new value |
Definition at line 1531 of file CcdbApi.cxx.
std::vector< std::string > o2::ccdb::CcdbApi::parseSubFolders | ( | std::string const & | reply | ) | const |
Helper function to extract the list of sub-folders from a list reply into a vector container. Can be used to achieve full recursive traversal/listing of the CCDB.
reply | The reply that we got from a GET/browse sort of request. |
Definition at line 1324 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::releaseNamedSemaphore | ( | boost::interprocess::named_semaphore * | sem, |
std::string const & | path | ||
) | const |
Definition at line 1756 of file CcdbApi.cxx.
|
static |
Definition at line 1790 of file CcdbApi.cxx.
|
static |
Definition at line 1767 of file CcdbApi.cxx.
TObject * o2::ccdb::CcdbApi::retrieve | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp | ||
) | const |
Definition at line 770 of file CcdbApi.cxx.
bool o2::ccdb::CcdbApi::retrieveBlob | ( | std::string const & | path, |
std::string const & | targetdir, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp, | ||
bool | preservePathStructure = true , |
||
std::string const & | localFileName = "snapshot.root" , |
||
std::string const & | createdNotAfter = "" , |
||
std::string const & | createdNotBefore = "" |
||
) | const |
Simple function to retrieve the blob corresponding to some path and timestamp. Saves the blob locally to a binary file with the following properties: a) The base destination directory is given by "targetdir" (will be created if not present) b) If preservePathStructure == true; Additional sub-folders corresponding to "path" will be created inside "targetdir". c) The filename on disc will be determined by localFileName, or in case localFilename="" from the filename returned by CCDB meta data.
Definition at line 815 of file CcdbApi.cxx.
TObject * o2::ccdb::CcdbApi::retrieveFromTFile | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp, | ||
std::map< std::string, std::string > * | headers, | ||
std::string const & | etag, | ||
const std::string & | createdNotAfter, | ||
const std::string & | createdNotBefore | ||
) | const |
Definition at line 808 of file CcdbApi.cxx.
void * o2::ccdb::CcdbApi::retrieveFromTFile | ( | std::type_info const & | tinfo, |
std::string const & | path, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp = -1 , |
||
std::map< std::string, std::string > * | headers = nullptr , |
||
std::string const & | etag = "" , |
||
const std::string & | createdNotAfter = "" , |
||
const std::string & | createdNotBefore = "" |
||
) | const |
A generic helper implementation to query obj whose type is given by a std::type_info
Definition at line 1113 of file CcdbApi.cxx.
std::enable_if< std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type o2::ccdb::CcdbApi::retrieveFromTFileAny | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp = -1 , |
||
std::map< std::string, std::string > * | headers = nullptr , |
||
std::string const & | etag = "" , |
||
const std::string & | createdNotAfter = "" , |
||
const std::string & | createdNotBefore = "" |
||
) | const |
Retrieve object at the given path for the given timestamp.
path | The path where the object is to be found. |
metadata | Key-values representing the metadata to filter out objects. |
timestamp | Timestamp of the object to retrieve. If omitted, current timestamp is used. |
headers | Map to be populated with the headers we received, if it is not null. |
optional | etag from previous call |
optional | createdNotAfter upper time limit for the object creation timestamp (TimeMachine mode) |
optional | createdNotBefore lower time limit for the object creation timestamp (TimeMachine mode) |
std::enable_if< std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type o2::ccdb::CcdbApi::retrieveFromTFileAny | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp = -1 , |
||
std::map< std::string, std::string > * | headers = nullptr , |
||
std::string const & | etag = "" , |
||
const std::string & | createdNotAfter = "" , |
||
const std::string & | createdNotBefore = "" |
||
) | const |
std::map< std::string, std::string > o2::ccdb::CcdbApi::retrieveHeaders | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp = -1 |
||
) | const |
Retrieve the headers of a CCDB entry, if it exists.
path | The path where the object is to be found. |
metadata | Key-values representing the metadata to filter out objects. |
timestamp | Timestamp of the object to retrieve. If omitted, current timestamp is used. |
Definition at line 1416 of file CcdbApi.cxx.
|
static |
Extracts meta-information associated to the CCDB blob sitting in given TFile.
Definition at line 1553 of file CcdbApi.cxx.
|
static |
Extracts meta-information of the query from a TFile containing the CCDB blob.
Definition at line 1544 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::runDownloaderLoop | ( | bool | noWait | ) |
Run the uvLoop belonging to mDownloader once.
noWait | Using this flag will cause the loop to run only if sockets have pendind data. |
Definition at line 267 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::saveSnapshot | ( | RequestContext & | requestContext | ) | const |
Definition at line 1847 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::scheduleDownload | ( | RequestContext & | requestContext, |
size_t * | requestCounter | ||
) | const |
Definition at line 1674 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::snapshot | ( | std::string const & | ccdbrootpath, |
std::string const & | localDir, | ||
long | timestamp | ||
) | const |
Make a local snapshot of all valid objects, given a timestamp, of the CCDB under a given local path. This is doing a recursive list and fetching the files locally.
Definition at line 867 of file CcdbApi.cxx.
int o2::ccdb::CcdbApi::storeAsBinaryFile | ( | const char * | buffer, |
size_t | size, | ||
const std::string & | fileName, | ||
const std::string & | objectType, | ||
const std::string & | path, | ||
const std::map< std::string, std::string > & | metadata, | ||
long | startValidityTimestamp, | ||
long | endValidityTimestamp, | ||
std::vector< char >::size_type | maxSize = 0 |
||
) | const |
A generic method to store a binary buffer (e.g. an image of the TMemFile)
Definition at line 351 of file CcdbApi.cxx.
int o2::ccdb::CcdbApi::storeAsTFile | ( | const TObject * | rootObject, |
std::string const & | path, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | startValidityTimestamp = -1 , |
||
long | endValidityTimestamp = -1 , |
||
std::vector< char >::size_type | maxSize = 0 |
||
) | const |
Store into the CCDB a TFile containing the ROOT object.
rootObject | Raw pointer to the object to store. |
path | The path where the object is going to be stored. |
metadata | Key-values representing the metadata for this object. |
startValidityTimestamp | Start of validity. If omitted, current timestamp is used. |
endValidityTimestamp | End of validity. If omitted, current timestamp + 1 day is used. |
Definition at line 466 of file CcdbApi.cxx.
int o2::ccdb::CcdbApi::storeAsTFile_impl | ( | const void * | obj1, |
std::type_info const & | info, | ||
std::string const & | path, | ||
std::map< std::string, std::string > const & | metadata, | ||
long | startValidityTimestamp = -1 , |
||
long | endValidityTimestamp = -1 , |
||
std::vector< char >::size_type | maxSize = 0 |
||
) | const |
A generic helper implementation to store an obj whose type is given by a std::type_info
Definition at line 335 of file CcdbApi.cxx.
|
inline |
Store into the CCDB a TFile containing an object of type T (which needs to have a ROOT dictionary)
obj | Raw pointer to the object to store. |
path | The path where the object is going to be stored. |
metadata | Key-values representing the metadata for this object. |
startValidityTimestamp | Start of validity. If omitted, current timestamp is used. |
endValidityTimestamp | End of validity. If omitted, current timestamp + 1 day is used. |
void o2::ccdb::CcdbApi::truncate | ( | std::string const & | path | ) | const |
Delete all versions of the object at this path.
path |
Definition at line 1270 of file CcdbApi.cxx.
int o2::ccdb::CcdbApi::updateMetadata | ( | std::string const & | path, |
std::map< std::string, std::string > const & | metadata, | ||
long | timestamp, | ||
std::string const & | id = "" , |
||
long | newEOV = 0 |
||
) |
Update the metadata of the object defined by the provided timestamp, and id if provided.
path | Path to the object to update |
metadata | The metadata to update |
timestamp | The timestamp to select the object |
id | The id, if any, to select the object |
Definition at line 1599 of file CcdbApi.cxx.
void o2::ccdb::CcdbApi::vectoredLoadFileToMemory | ( | std::vector< RequestContext > & | requestContext | ) | const |
Retrieves files described via RequestContexts into memory. Downloads are performed in parallel via CCDBDownloader.
requestContext | Structure giving details about the transfer. |
Definition at line 1941 of file CcdbApi.cxx.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |