ATLAS Offline Software
CrestApiFs.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
14 #ifndef CRESTAPI_CRESFSAPI_H
15 #define CRESTAPI_CRESFSAPI_H
16 
17 #include <string>
18 #include <map>
19 #include <list>
20 #include <iosfwd>
21 #include <cstdint>
22 #include "nlohmann/json.hpp"
23 #include <curl/curl.h>
24 #include <iostream>
25 #include <CrestApi/CrestModel.h>
26 #include <CrestApi/CrestApiBase.h>
27 
28 namespace Crest
29 {
30 
31  class CrestFsClient : public CrestApiBase
32  {
33  private:
34  std::string m_root_folder{};
35  std::string m_data_folder{};
36  std::map<std::string, nlohmann::json> m_data{};
37  bool m_isRewrite{};
38 
39  // parameters for CREST file storage:
40 
41  inline static const std::string s_FS_TAG_PATH = "/tags";
42  inline static const std::string s_FS_GLOBALTAG_PATH = "/globaltags";
43  inline static const std::string s_FS_DATA_PATH = "/data";
44 
45  inline static const std::string s_FS_TAG_FILE = "/tag.json";
46  inline static const std::string s_FS_IOV_FILE = "/iovs.json";
47  inline static const std::string s_FS_TAGMETAINFO_FILE = "/tagmetainfo.json";
48 
49  inline static const std::string s_FS_META_FILE = "/meta.json";
50  inline static const std::string s_FS_PALOAD_FILE = "/payload.json";
51 
52  inline static const std::string s_FS_GLOBALTAG_FILE = "/globaltag.json";
53  inline static const std::string s_FS_MAP_FILE = "/maps.json";
54 
55  inline static const std::string s_FS_PATH = "";
56 
57  inline static const int s_FS_PREFIX_LENGTH = 3;
58  std::string m_currentTag{};
59 
65  void checkFsException(const char *method_name);
66 
73  std::string getFileString(const std::string &path); // method to read file as a string
74 
81  void getFileList(const std::string &path);
82 
87  void flush();
88 
89  public:
90 
96  CrestFsClient(bool rewriteIfExists, const std::string &root_folder);
97 
99 
100  // Overrides
101 
102  // GlobaTag methods
103 
131  void createGlobalTag(GlobalTagDto &globalTag) override;
132 
140  GlobalTagDto findGlobalTag(const std::string &name) override;
141 
150  GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override;
151 
157  void removeGlobalTag(const std::string &name) override;
158 
159  // Tag methods
160 
189  void createTag(TagDto &tag) override;
190 
197  TagDto findTag(const std::string &name) override;
198 
208  TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override;
209 
215  void removeTag(const std::string &name) override;
216 
223  int getSize(const std::string &tagname) override;
224 
225  // TagMeta methods
226 
259  void createTagMeta(TagMetaDto &tag) override;
260 
265  void updateTagMeta(TagMetaDto &tag) override;
266 
272  TagMetaDto findTagMeta(const std::string &name) override;
273 
274  // Iovs
275 
289  IovSetDto selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) override;
290 
301  IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override;
302 
303  // GlobalTagMap methods
304 
326  void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override;
327 
335  GlobalTagMapSetDto findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) override;
336 
343  void removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) override;
344 
345 
346  // Payload methods
347 
372  void storeData(const std::string &tag,
373  const StoreSetDto &storeSetJson,
374  const std::string &payloadFormat="JSON",
375  const std::string &objectType="none",
376  const std::string &compressionType="none",
377  const std::string &version="1.0",
378  uint64_t endTime=-1) override;
379 
380  // Payload retrieval methods
381 
389  std::string getPayload(const std::string &hash) override;
390 
397  PayloadDto getPayloadMeta(const std::string &hash) override;
398 
403  std::string getCrestVersion() override;
404 
405 
406  private:
407  std::string getDateAndTime();
408 
416  std::string getFirstLetters(const std::string &str);
417 
418  // auxiliary methods to extract a single page of the data:
420  std::vector<std::string> getVectorPage(const std::vector<std::string>& data, int size, int page);
421 
422  // auxiliary method to get folder names:
423  std::vector<std::string> nameList(std::string & folder, bool ascending = true);
424 
425  // Auxiliary methods to build the path to the file.
426  std::string buildPath(const std::string &path, const std::string &file);
427 
428  // Auxiliary methods to sort the JSON array by the key value:
429  nlohmann::json sortJson(nlohmann::json js, const std::string & par, bool order);
431 
432  // auxiliary methods to check if the string corresponds to the mask:
433  bool isMatch(const std::string& word, long unsigned int n, const std::string& pattern, long unsigned int m);
434  bool isMatch(const std::string& word, const std::string& pattern);
435 
461  nlohmann::json findAllIovs(const std::string &tagname);
462 
474  void storePayloadDump(const std::string &tag,
475  uint64_t since,
476  const std::string &js,
477  const std::string &payloadFormat,
478  const std::string &objectType,
479  const std::string &compressionType,
480  const std::string &version,
481  const std::string &streamerInfo);
482  };
483 
484 } // namespace Crest
485 
486 #endif // CRESTAPI_CRESTCLIENT_H
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
Crest::CrestFsClient::s_FS_GLOBALTAG_PATH
static const std::string s_FS_GLOBALTAG_PATH
Definition: CrestApiFs.h:42
Crest::CrestFsClient::s_FS_TAG_PATH
static const std::string s_FS_TAG_PATH
Definition: CrestApiFs.h:41
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Crest::CrestFsClient::~CrestFsClient
~CrestFsClient()
CrestClient destructor.
Definition: CrestApiFs.cxx:56
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
Crest::CrestFsClient::updateTagMeta
void updateTagMeta(TagMetaDto &tag) override
This method updates a tag meta info on the file storage.
Definition: CrestApiFs.cxx:401
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
CrestApiBase.h
Header file for CREST C++ Client Library.
Crest::CrestFsClient::s_FS_DATA_PATH
static const std::string s_FS_DATA_PATH
Definition: CrestApiFs.h:43
Crest::CrestFsClient::createTagMeta
void createTagMeta(TagMetaDto &tag) override
This method creates a tag meta info on the file storage.
Definition: CrestApiFs.cxx:379
Crest::CrestFsClient::listGlobalTags
GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override
This method finds the global tags on the file storage.
Definition: CrestApiFs.cxx:166
Crest::CrestFsClient::m_data_folder
std::string m_data_folder
Definition: CrestApiFs.h:35
Crest::CrestFsClient::listTags
TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override
This method returns the tag list as TagSetDto.
Definition: CrestApiFs.cxx:295
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Crest::CrestFsClient::getFirstLetters
std::string getFirstLetters(const std::string &str)
This is an auxillary method extract first letters from the string (hash).
Definition: CrestApiFs.cxx:722
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Crest::CrestFsClient::sortIOVJson
nlohmann::json sortIOVJson(nlohmann::json js, bool order)
Definition: CrestApiFs.cxx:1036
CrestModel.h
Crest::CrestFsClient::getFileList
void getFileList(const std::string &path)
Auxiliary method to get a file list in the given directory.
Definition: CrestApiFs.cxx:88
Crest::CrestFsClient::getSize
int getSize(const std::string &tagname) override
This method gets the number of IOVs for the given tag.
Definition: CrestApiFs.cxx:644
Crest::CrestFsClient::s_FS_IOV_FILE
static const std::string s_FS_IOV_FILE
Definition: CrestApiFs.h:46
Crest::CrestFsClient::selectIovs
IovSetDto selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) override
This method selects IOVs for a given tagname from the file storage.
Definition: CrestApiFs.cxx:564
TagSetDto
Definition: CrestModel.h:126
Crest::CrestFsClient::findTagMeta
TagMetaDto findTagMeta(const std::string &name) override
This method gets a tag meta info by the tag name from the file storage.
Definition: CrestApiFs.cxx:406
Crest::CrestFsClient::flush
void flush()
Auxiliary method flush the data to the file system.
Definition: CrestApiFs.cxx:360
GlobalTagSetDto
Definition: CrestModel.h:81
Crest
Definition: CrestApi.h:30
makeDTCalibBlob_pickPhase.globalTag
globalTag
Definition: makeDTCalibBlob_pickPhase.py:398
Crest::CrestFsClient::findGlobalTagMap
GlobalTagMapSetDto findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) override
This method searches for tag mappings using the global tag name or tag name on the file storage.
Definition: CrestApiFs.cxx:528
Crest::CrestFsClient::createTag
void createTag(TagDto &tag) override
This method creates a tag on the file storage.
Definition: CrestApiFs.cxx:233
TagMetaDto
Definition: CrestModel.h:238
hotSpotInTAG.objectType
objectType
Definition: hotSpotInTAG.py:107
PayloadDto
Definition: CrestModel.h:345
Crest::CrestFsClient::s_FS_PATH
static const std::string s_FS_PATH
Definition: CrestApiFs.h:55
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
Crest::CrestFsClient::s_FS_META_FILE
static const std::string s_FS_META_FILE
Definition: CrestApiFs.h:49
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
Crest::CrestFsClient::s_FS_MAP_FILE
static const std::string s_FS_MAP_FILE
Definition: CrestApiFs.h:53
Crest::CrestFsClient::isMatch
bool isMatch(const std::string &word, long unsigned int n, const std::string &pattern, long unsigned int m)
Definition: CrestApiFs.cxx:1073
Crest::CrestFsClient::nameList
std::vector< std::string > nameList(std::string &folder, bool ascending=true)
Definition: CrestApiFs.cxx:977
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Crest::CrestFsClient::getFileString
std::string getFileString(const std::string &path)
Auxiliary method to get a file as a string.
Definition: CrestApiFs.cxx:60
Crest::CrestFsClient::m_root_folder
std::string m_root_folder
Definition: CrestApiFs.h:34
Crest::CrestFsClient::s_FS_TAG_FILE
static const std::string s_FS_TAG_FILE
Definition: CrestApiFs.h:45
GlobalTagDto
Definition: CrestModel.h:55
Crest::CrestFsClient::getDateAndTime
std::string getDateAndTime()
Definition: CrestApiFs.cxx:711
beamspotman.n
n
Definition: beamspotman.py:731
TagDto
The TagDto class It contains all fields of the TagDto class from the CREST API.
Definition: CrestModel.h:98
mc.order
order
Configure Herwig7.
Definition: mc.Herwig7_Dijet.py:12
Crest::CrestFsClient::CrestFsClient
CrestFsClient(bool rewriteIfExists, const std::string &root_folder)
CrestFsClient constructor.
Definition: CrestApiFs.cxx:35
Crest::CrestFsClient::s_FS_PALOAD_FILE
static const std::string s_FS_PALOAD_FILE
Definition: CrestApiFs.h:50
file
TFile * file
Definition: tile_monitor.h:29
Crest::CrestFsClient::s_FS_PREFIX_LENGTH
static const int s_FS_PREFIX_LENGTH
Definition: CrestApiFs.h:57
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Crest::CrestApiBase
Definition: CrestApiBase.h:32
Crest::CrestFsClient::createGlobalTagMap
void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override
This method creates a global tag map on the file storage.
Definition: CrestApiFs.cxx:431
Crest::CrestFsClient::checkFsException
void checkFsException(const char *method_name)
Auxiliary method to check if the CrestApi library initialized to work with the file system.
Definition: CrestApiFs.cxx:523
python.TriggerAPI.TriggerAPISession.ascending
ascending
Definition: TriggerAPISession.py:435
Crest::CrestFsClient::sortJson
nlohmann::json sortJson(nlohmann::json js, const std::string &par, bool order)
Definition: CrestApiFs.cxx:999
GlobalTagMapSetDto
Definition: CrestModel.h:160
Crest::CrestFsClient::getCrestVersion
std::string getCrestVersion() override
This method returns the full CREST Server version.
Definition: CrestApiFs.cxx:1111
Crest::CrestFsClient::findGlobalTag
GlobalTagDto findGlobalTag(const std::string &name) override
This method finds a global tag by name on the file storage.
Definition: CrestApiFs.cxx:138
Crest::CrestFsClient::findTag
TagDto findTag(const std::string &name) override
This method finds a tag by the name on the file storage.
Definition: CrestApiFs.cxx:267
Crest::CrestFsClient::createGlobalTag
void createGlobalTag(GlobalTagDto &globalTag) override
This method creates a global tag on the file storage.
Definition: CrestApiFs.cxx:106
Crest::CrestFsClient::s_FS_TAGMETAINFO_FILE
static const std::string s_FS_TAGMETAINFO_FILE
Definition: CrestApiFs.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
Crest::CrestFsClient::getVectorPage
std::vector< std::string > getVectorPage(const std::vector< std::string > &data, int size, int page)
Definition: CrestApiFs.cxx:949
Crest::CrestFsClient::removeGlobalTagMap
void removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) override
This method removes a global tag map from the file storage.
Definition: CrestApiFs.cxx:518
Crest::CrestFsClient::s_FS_GLOBALTAG_FILE
static const std::string s_FS_GLOBALTAG_FILE
Definition: CrestApiFs.h:52
Crest::CrestFsClient
Definition: CrestApiFs.h:32
Crest::CrestFsClient::selectGroups
IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override
This method returns IOV groups for a given tagname.
Definition: CrestApiFs.cxx:662
Crest::CrestFsClient::getPage
nlohmann::json getPage(nlohmann::json data, int size, int page)
Definition: CrestApiFs.cxx:921
MyPlots.page
page
Definition: MyPlots.py:234
get_generator_info.version
version
Definition: get_generator_info.py:33
Crest::CrestFsClient::m_data
std::map< std::string, nlohmann::json > m_data
Definition: CrestApiFs.h:36
Crest::CrestFsClient::removeGlobalTag
void removeGlobalTag(const std::string &name) override
This method removes a global tag.
Definition: CrestApiFs.cxx:161
Crest::CrestFsClient::m_currentTag
std::string m_currentTag
Definition: CrestApiFs.h:58
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
Crest::CrestFsClient::buildPath
std::string buildPath(const std::string &path, const std::string &file)
Definition: CrestApiFs.cxx:67
IovSetDto
Definition: CrestModel.h:287
Crest::CrestFsClient::storePayloadDump
void storePayloadDump(const std::string &tag, uint64_t since, const std::string &js, const std::string &payloadFormat, const std::string &objectType, const std::string &compressionType, const std::string &version, const std::string &streamerInfo)
This auxiliary method stores a single payload (with since time) on the file system.
Definition: CrestApiFs.cxx:728
tagname
Definition: tagname.h:29
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
str
Definition: BTagTrackIpAccessor.cxx:11
Crest::CrestFsClient::getPayloadMeta
PayloadDto getPayloadMeta(const std::string &hash) override
This method finds a payload meta info for the hash on the file storage.
Definition: CrestApiFs.cxx:883
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
StoreSetDto
Definition: CrestModel.h:331
Crest::CrestFsClient::getPayload
std::string getPayload(const std::string &hash) override
This method finds a payload resource associated to the hash on the file storage.
Definition: CrestApiFs.cxx:853
Crest::CrestFsClient::storeData
void storeData(const std::string &tag, const StoreSetDto &storeSetJson, const std::string &payloadFormat="JSON", const std::string &objectType="none", const std::string &compressionType="none", const std::string &version="1.0", uint64_t endTime=-1) override
This method stores several payloads in batch mode on the file storage.
Definition: CrestApiFs.cxx:669
Crest::CrestFsClient::m_isRewrite
bool m_isRewrite
Definition: CrestApiFs.h:37
Crest::CrestFsClient::removeTag
void removeTag(const std::string &name) override
This method removes a tag from the file storage.
Definition: CrestApiFs.cxx:290
GlobalTagMapDto
Definition: CrestModel.h:139
lumiFormat.endTime
endTime
Definition: lumiFormat.py:100
Crest::CrestFsClient::findAllIovs
nlohmann::json findAllIovs(const std::string &tagname)
This auxiliary method finds all iovs for a given tag name.
Definition: CrestApiFs.cxx:621