ATLAS Offline Software
CrestApi.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_CRESAPI_H
15 #define CRESTAPI_CRESAPI_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 #include <CrestApi/CrestRequest.h>
28 
29 namespace Crest
30 {
31 
32  class CrestClient : public CrestApiBase
33  {
34  private:
35  std::string makeUrl(const std::string &address) const;
36 
38 
39  inline static const std::string s_TAG_PATH = "/tags";
40  inline static const std::string s_ADMIN_PATH = "/admin";
41  inline static const std::string s_IOV_PATH = "/iovs";
42 
43  inline static const std::string s_IOV_SIZE_PATH = "/size";
44 
45  inline static const std::string s_GLOBALTAG_PATH = "/globaltags";
46  inline static const std::string s_GLOBALTAG_MAP_PATH = "/globaltagmaps";
47  inline static const std::string s_PAYLOAD_PATH = "/payloads";
48  inline static const std::string s_MONITORING_PAYLOAD_PATH = "/monitoring/payloads";
49  inline static const std::string s_META_PATH = "/meta";
50  inline static const std::string s_DATA_PATH = "/data";
51 
52  inline static const std::string s_FOLDER_PATH = "/folders";
53  inline static const std::string s_RUNINFO_PATH = "/runinfo";
54  inline static const std::string s_RUNINFO_LIST_PATH = "/list";
55 
56  inline static const std::string s_METHOD_IOVS = "IOVS";
57  inline static const std::string s_METHOD_GROUPS = "GROUPS";
58 
59  // CREST Server data paths:
60  inline static const std::string s_MGMT_PATH = "/mgmt";
61  inline static const std::string s_MGMT_INFO_PATH = "/info";
62  inline static const std::string s_CREST_CLIENT_VERSION = "5.0";
63  inline static const std::string s_MGMT_INFO_PATH_2 = "/actuator/info";
64 
65  // ... other constants
66 
67  std::string m_host;
68  std::string m_port;
69  std::string m_prefix = "http://";
70 
72 
92 
93 
98  std::string getCrestVersion() override;
99 
105  int getMajorVersion(std::string &str);
106 
114  nlohmann::json getJson(const std::string &str, const char *method) const;
115 
121  std::string parseXMLOutput(const std::string_view xmlBuffer) const;
122 
128  std::string removeCR(const std::string &str) const;
129 
137  void checkHash(const std::string &hash, const std::string &str, const char* method_name);
138 
139 
140  public:
141 
149  CrestClient(const std::string &host, const std::string &port, bool checkVersion = false);
150 
164  CrestClient(std::string_view url, bool checkVersion = false);
165 
166  ~CrestClient();
167 
168  inline static const bool s_CREST_CLIENT_CHECK = false;
169 
176  void checkCrestVersion();
177 
178  // Overrides
179 
180  // GlobaTag methods
181 
209  void createGlobalTag(GlobalTagDto &globalTag) override;
210 
217  GlobalTagDto findGlobalTag(const std::string &name) override;
218 
227  GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override;
228 
234  void removeGlobalTag(const std::string &name) override;
235 
236  // Tag methods
237 
266  void createTag(TagDto &tag) override;
267 
274  TagDto findTag(const std::string &name) override;
275 
285  TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override;
286 
292  void removeTag(const std::string &name) override;
293 
300  int getSize(const std::string& tagname) override;
301 
302  // TagMeta methods
303 
336  void createTagMeta(TagMetaDto &tag) override;
337 
342  void updateTagMeta(TagMetaDto &tag) override;
343 
349  TagMetaDto findTagMeta(const std::string &name) override;
350 
351  // GlobalTagMap methods
352 
374  void createGlobalTagMap(GlobalTagMapDto& globalTagMap) override;
375 
384  GlobalTagMapSetDto findGlobalTagMap(const std::string& name, const std::string& xCrestMapMode) override;
385 
392  void removeGlobalTagMap(const std::string& name, const std::string& record, const std::string& label, const std::string& tagname) override;
393 
394  // Iovs
395 
409  IovSetDto selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) override;
410 
422  IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override;
423 
424  // Payload methods
425 
450  void storeData(const std::string &tag,
451  const StoreSetDto &storeSetJson,
452  const std::string &payloadFormat="JSON",
453  const std::string &objectType="none",
454  const std::string &compressionType="none",
455  const std::string &version="1.0",
456  uint64_t endTime=-1) override;
457 
458  // Payload retrieval methods
459 
467  std::string getPayload(const std::string &hash) override;
468 
475  PayloadDto getPayloadMeta(const std::string &hash) override;
476  };
477 
478 } // namespace Crest
479 
480 #endif // CRESTAPI_CRESTCLIENT_H
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
Crest::CrestClient::s_TAG_PATH
static const std::string s_TAG_PATH
Definition: CrestApi.h:39
Crest::CrestClient::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 CREST server.
Definition: CrestApi.cxx:565
Crest::CrestClient::getJson
nlohmann::json getJson(const std::string &str, const char *method) const
Auxiliary method to convert string in to JSON object.
Definition: CrestApi.cxx:169
Crest::CrestClient::removeGlobalTag
void removeGlobalTag(const std::string &name) override
This method removes a global tag on the CREST server.
Definition: CrestApi.cxx:358
Crest::CrestClient::s_MGMT_INFO_PATH
static const std::string s_MGMT_INFO_PATH
Definition: CrestApi.h:61
Crest::CrestClient::getSize
int getSize(const std::string &tagname) override
This method gets the number of IOVs for the given tag.
Definition: CrestApi.cxx:515
CrestApiBase.h
Header file for CREST C++ Client Library.
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Crest::CrestClient::s_ADMIN_PATH
static const std::string s_ADMIN_PATH
Definition: CrestApi.h:40
Crest::CrestClient::makeUrl
std::string makeUrl(const std::string &address) const
Definition: CrestApi.cxx:273
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Crest::CrestClient::listTags
TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override
This method returns the tag list as TagSetDto from the CREST server.
Definition: CrestApi.cxx:405
Crest::CrestClient::removeTag
void removeTag(const std::string &name) override
This method removes a tag from the CREST server.
Definition: CrestApi.cxx:448
Crest::CrestClient::s_IOV_PATH
static const std::string s_IOV_PATH
Definition: CrestApi.h:41
CrestModel.h
Crest::CrestClient::s_METHOD_IOVS
static const std::string s_METHOD_IOVS
Definition: CrestApi.h:56
Crest::CrestClient::s_GLOBALTAG_MAP_PATH
static const std::string s_GLOBALTAG_MAP_PATH
Definition: CrestApi.h:46
TagSetDto
Definition: CrestModel.h:126
Crest::CrestClient::m_host
std::string m_host
Definition: CrestApi.h:67
Crest::CrestClient::m_PATH
std::string m_PATH
Definition: CrestApi.h:37
Crest::CrestClient::findGlobalTag
GlobalTagDto findGlobalTag(const std::string &name) override
This method finds a global tag by name on the CREST server.
Definition: CrestApi.cxx:295
GlobalTagSetDto
Definition: CrestModel.h:81
Crest
Definition: CrestApi.h:30
Crest::CrestClient::s_RUNINFO_PATH
static const std::string s_RUNINFO_PATH
Definition: CrestApi.h:53
Crest::CrestClient::~CrestClient
~CrestClient()
CrestClient destructor.
Definition: CrestApi.cxx:117
makeDTCalibBlob_pickPhase.globalTag
globalTag
Definition: makeDTCalibBlob_pickPhase.py:398
physics_parameters.url
string url
Definition: physics_parameters.py:27
Crest::CrestClient::s_MONITORING_PAYLOAD_PATH
static const std::string s_MONITORING_PAYLOAD_PATH
Definition: CrestApi.h:48
TagMetaDto
Definition: CrestModel.h:238
DEFAULT_CREST_API_VERSION
#define DEFAULT_CREST_API_VERSION
Definition: CrestApiBase.h:27
hotSpotInTAG.objectType
objectType
Definition: hotSpotInTAG.py:107
Crest::CrestClient::findTag
TagDto findTag(const std::string &name) override
This method finds a tag by the name on the CREST server.
Definition: CrestApi.cxx:386
PayloadDto
Definition: CrestModel.h:345
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
Crest::CrestClient::s_CREST_CLIENT_CHECK
static const bool s_CREST_CLIENT_CHECK
Definition: CrestApi.h:168
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Crest::CrestClient::createTagMeta
void createTagMeta(TagMetaDto &tag) override
This method creates a tag meta info on the CREST server.
Definition: CrestApi.cxx:464
Crest::CrestClient::s_GLOBALTAG_PATH
static const std::string s_GLOBALTAG_PATH
Definition: CrestApi.h:45
Crest::CrestClient::s_MGMT_INFO_PATH_2
static const std::string s_MGMT_INFO_PATH_2
Definition: CrestApi.h:63
Crest::CrestClient::s_META_PATH
static const std::string s_META_PATH
Definition: CrestApi.h:49
Crest::CrestClient::updateTagMeta
void updateTagMeta(TagMetaDto &tag) override
This method updates a tag meta info on the CREST server.
Definition: CrestApi.cxx:479
Crest::CrestClient::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 on the CREST server.
Definition: CrestApi.cxx:629
Crest::CrestClient::s_METHOD_GROUPS
static const std::string s_METHOD_GROUPS
Definition: CrestApi.h:57
GlobalTagDto
Definition: CrestModel.h:55
CrestRequest.h
Crest::CrestClient::s_MGMT_PATH
static const std::string s_MGMT_PATH
Definition: CrestApi.h:60
Crest::CrestClient::getCrestVersion
std::string getCrestVersion() override
This method returns the full CREST Server version.
Definition: CrestApi.cxx:214
TagDto
The TagDto class It contains all fields of the TagDto class from the CREST API.
Definition: CrestModel.h:98
Crest::CrestClient::createTag
void createTag(TagDto &tag) override
This method creates a tag on the CREST server.
Definition: CrestApi.cxx:374
Crest::CrestClient::getPayloadMeta
PayloadDto getPayloadMeta(const std::string &hash) override
This method finds a payload meta info for the hash on the CREST server.
Definition: CrestApi.cxx:775
Crest::CrestClient::CrestClient
CrestClient(const std::string &host, const std::string &port, bool checkVersion=false)
CrestClient constructor.
Definition: CrestApi.cxx:36
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
Crest::CrestApiBase
Definition: CrestApiBase.h:32
Crest::CrestClient::findTagMeta
TagMetaDto findTagMeta(const std::string &name) override
This method reads a tag meta info by the tag name from the CREST server.
Definition: CrestApi.cxx:494
Crest::CrestClient::s_DATA_PATH
static const std::string s_DATA_PATH
Definition: CrestApi.h:50
Crest::CrestClient::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 CREST server.
Definition: CrestApi.cxx:711
GlobalTagMapSetDto
Definition: CrestModel.h:160
Crest::CrestClient::s_CREST_CLIENT_VERSION
static const std::string s_CREST_CLIENT_VERSION
Definition: CrestApi.h:62
Crest::CrestClient::createGlobalTagMap
void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override
This method creates a global tag map on the CREST server.
Definition: CrestApi.cxx:554
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Crest::CrestClient::s_PAYLOAD_PATH
static const std::string s_PAYLOAD_PATH
Definition: CrestApi.h:47
Crest::CrestClient::checkCrestVersion
void checkCrestVersion()
This method is a CREST version test.
Definition: CrestApi.cxx:259
Crest::CrestClient::getMgmtInfo
nlohmann::json getMgmtInfo()
This is an auxiliary method to read the CREST Server properties.
Definition: CrestApi.cxx:199
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
Crest::CrestClient::m_prefix
std::string m_prefix
Definition: CrestApi.h:69
Crest::CrestRequest
Definition: CrestRequest.h:63
Crest::CrestClient::getPayload
std::string getPayload(const std::string &hash) override
This method finds a payload resource associated to the hash on the CREST server.
Definition: CrestApi.cxx:760
MyPlots.page
page
Definition: MyPlots.py:234
get_generator_info.version
version
Definition: get_generator_info.py:33
Crest::CrestClient::listGlobalTags
GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override
This method finds the global tags on the CREST server.
Definition: CrestApi.cxx:315
Crest::CrestClient::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 on the CREST server.
Definition: CrestApi.cxx:594
Crest::CrestClient::m_port
std::string m_port
Definition: CrestApi.h:68
Crest::CrestClient::m_request
Crest::CrestRequest m_request
Definition: CrestApi.h:71
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
Crest::CrestClient::parseXMLOutput
std::string parseXMLOutput(const std::string_view xmlBuffer) const
This method removes all XML/HTML tags from a string.
Definition: CrestApi.cxx:121
IovSetDto
Definition: CrestModel.h:287
Crest::CrestClient::createGlobalTag
void createGlobalTag(GlobalTagDto &globalTag) override
This method creates a global tag on CREST server.
Definition: CrestApi.cxx:284
Crest::CrestClient
Definition: CrestApi.h:33
Crest::CrestClient::getMajorVersion
int getMajorVersion(std::string &str)
This is an auxiliary method to extract a major version number from full version string.
Definition: CrestApi.cxx:235
tagname
Definition: tagname.h:29
Crest::CrestClient::checkHash
void checkHash(const std::string &hash, const std::string &str, const char *method_name)
This checks the hash of payload from IOV (hash) with the hash calculated for the payload in the std::...
Definition: CrestApi.cxx:795
str
Definition: BTagTrackIpAccessor.cxx:11
Crest::CrestClient::removeCR
std::string removeCR(const std::string &str) const
This method removes all end of line and carriage return symbols from a string.
Definition: CrestApi.cxx:149
Crest::CrestClient::s_FOLDER_PATH
static const std::string s_FOLDER_PATH
Definition: CrestApi.h:52
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
StoreSetDto
Definition: CrestModel.h:331
Crest::CrestClient::s_RUNINFO_LIST_PATH
static const std::string s_RUNINFO_LIST_PATH
Definition: CrestApi.h:54
Crest::CrestClient::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 on CREST server.
Definition: CrestApi.cxx:674
GlobalTagMapDto
Definition: CrestModel.h:139
lumiFormat.endTime
endTime
Definition: lumiFormat.py:100
Crest::CrestClient::s_IOV_SIZE_PATH
static const std::string s_IOV_SIZE_PATH
Definition: CrestApi.h:43