diff --git a/Database/CrestApi/CMakeLists.txt b/Database/CrestApi/CMakeLists.txt deleted file mode 100644 index 80da0f5c43cff31b70a88c95e786c0537b70de1e..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ - -# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration - -# Set the name of the package. -atlas_subdir( CrestApi ) - -# External dependencies. -find_package(nlohmann_json) -find_package(CURL) -find_package(Boost COMPONENTS system thread filesystem unit_test_framework regex timer) - -set(SOURCES src/CrestApi.cxx src/CrestRequest.cxx src/CrestApiFs.cxx src/CrestModel.cxx src/CrestContainer.cxx src/CrestApiBase.cxx) - -# Component(s) in the package. -atlas_add_library( CrestApiLib - ${SOURCES} - PUBLIC_HEADERS CrestApi - LINK_LIBRARIES nlohmann_json::nlohmann_json - PRIVATE_INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${CURL_LIBRARIES} ${Boost_LIBRARIES} ) - -# CrestApi package test for the file storage methods (CrestApiFs.cxx). -atlas_add_test( CrestApiFs_test - SOURCES test/CrestApiFs_test.cxx - LINK_LIBRARIES CrestApiLib nlohmann_json::nlohmann_json CxxUtils - INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} - LINK_LIBRARIES ${CURL_LIBRARIES} ${Boost_LIBRARIES} stdc++ - POST_EXEC_SCRIPT nopost.sh ) - -# CrestApi package test for the server methods (CrestApi.cxx). -atlas_add_test( CrestApi_test - SOURCES test/CrestApi_test.cxx - LINK_LIBRARIES CrestApiLib nlohmann_json::nlohmann_json CxxUtils - INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} - LINK_LIBRARIES ${CURL_LIBRARIES} ${Boost_LIBRARIES} stdc++ - POST_EXEC_SCRIPT nopost.sh ) diff --git a/Database/CrestApi/CrestApi/ATLAS_CHECK_THREAD_SAFETY b/Database/CrestApi/CrestApi/ATLAS_CHECK_THREAD_SAFETY deleted file mode 100644 index 46f6639dac0800bee9f7a57c1b739154780d227b..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/ATLAS_CHECK_THREAD_SAFETY +++ /dev/null @@ -1 +0,0 @@ -Database/CrestApi diff --git a/Database/CrestApi/CrestApi/CrestApi.h b/Database/CrestApi/CrestApi/CrestApi.h deleted file mode 100644 index a53dde4cd61b2b2829debd5b0b9933b8a7cf0605..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestApi.h +++ /dev/null @@ -1,480 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -/*! - \file - \brief Header file for CREST C++ Client Library - - This file contains the CrestClient class. - (See CrestClientExt.h for CrestClient class extention with additional methods.) - Here is the method description. - */ - -#ifndef CRESTAPI_CRESAPI_H -#define CRESTAPI_CRESAPI_H - -#include <string> -#include <map> -#include <list> -#include <iosfwd> -#include <cstdint> -#include "nlohmann/json.hpp" -#include <curl/curl.h> -#include <iostream> -#include <CrestApi/CrestModel.h> -#include <CrestApi/CrestApiBase.h> -#include <CrestApi/CrestRequest.h> - -namespace Crest -{ - - class CrestClient : public CrestApiBase - { - private: - std::string makeUrl(const std::string &address) const; - - std::string m_PATH = DEFAULT_CREST_API_VERSION; - - inline static const std::string s_TAG_PATH = "/tags"; - inline static const std::string s_ADMIN_PATH = "/admin"; - inline static const std::string s_IOV_PATH = "/iovs"; - - inline static const std::string s_IOV_SIZE_PATH = "/size"; - - inline static const std::string s_GLOBALTAG_PATH = "/globaltags"; - inline static const std::string s_GLOBALTAG_MAP_PATH = "/globaltagmaps"; - inline static const std::string s_PAYLOAD_PATH = "/payloads"; - inline static const std::string s_MONITORING_PAYLOAD_PATH = "/monitoring/payloads"; - inline static const std::string s_META_PATH = "/meta"; - inline static const std::string s_DATA_PATH = "/data"; - - inline static const std::string s_FOLDER_PATH = "/folders"; - inline static const std::string s_RUNINFO_PATH = "/runinfo"; - inline static const std::string s_RUNINFO_LIST_PATH = "/list"; - - inline static const std::string s_METHOD_IOVS = "IOVS"; - inline static const std::string s_METHOD_GROUPS = "GROUPS"; - - // CREST Server data paths: - inline static const std::string s_MGMT_PATH = "/mgmt"; - inline static const std::string s_MGMT_INFO_PATH = "/info"; - inline static const std::string s_CREST_CLIENT_VERSION = "5.0"; - inline static const std::string s_MGMT_INFO_PATH_2 = "/actuator/info"; - - // ... other constants - - std::string m_host; - std::string m_port; - std::string m_prefix = "http://"; - - Crest::CrestRequest m_request = Crest::CrestRequest(); - -/** - * This is an auxiliary method to read the CREST Server properties. - * @return JSON with CREST server properties. - * - * <pre> - * - * Example: - * { - * "build":{ - * "artifact":"crestdb", - * "name":"crestdb", - * "time":"2023-12-02T15:21:57.045Z", - * "version":"4.2.1", - * "group":"hep.crest" - * } - * } - * </pre> - */ - nlohmann::json getMgmtInfo(); - - -/** - * This method returns the full CREST Server version. - * @return CREST server version. - */ - std::string getCrestVersion() override; - -/** - * This is an auxiliary method to extract a major version number from - * full version string. - * @return major version number. - */ - int getMajorVersion(std::string &str); - -/** - * Auxiliary method to convert string in to JSON object. - * @param str - string (std::string) - * @param method - method name, which calls this method. This parameter is used to throw an error exception. - * @return - JSON object as nlohmann::json - * - */ - nlohmann::json getJson(const std::string &str, const char *method) const; - -/** - * This method removes all XML/HTML tags from a string. - * (It is an auxiliary method to clear the CREST Server response.) - * @param xmlBuffer - the text (a std::string ) to be cleared. - */ - std::string parseXMLOutput(const std::string_view xmlBuffer) const; - -/** - * This method removes all end of line and carriage return symbols from a string. - * (It is an auxiliary method to clear the CREST Server response.) - * @param str - the text (a std::string ) to be cleared. - */ - std::string removeCR(const std::string &str) const; - -/** - * This checks the hash of payload from IOV (hash) with - * the hash calculated for the payload in the std::string (str) - * (It is an auxiliary method to check the payload.) - * @param hash - the hash from an IOV. - * @param str - the payload in std::string. - */ - void checkHash(const std::string &hash, const std::string &str, const char* method_name); - - - public: - -/** - * CrestClient constructor. - * @param host - host name of the CREST Server. - * @param port - port of the CREST Server. - * @param check_version - the parameter to switch CREST version checking, if this parameter is true, - * the CREST version test will be executed. - */ - CrestClient(const std::string &host, const std::string &port, bool checkVersion = false); - -/** - * CrestClient constructor. - * @param url - URL address of the CREST Server (with port). - * @param check_version - the parameter to switch CREST version checking, if this parameter is true, - * the CREST version test will be executed. <br> - * - * Example: - * <br> - * <pre> - * std::string url = "http://mvg-test-pc-03.cern.ch:8090"; - * CrestClient myCrestClient = CrestClient(url); - * </pre> - */ - CrestClient(std::string_view url, bool checkVersion = false); - - ~CrestClient(); - - inline static const bool s_CREST_CLIENT_CHECK = false; - -/** - * This method is a CREST version test. It checks if the major CREST server - * is equal to the major CrestApi vesrion. - * If the versions are different an error is thrown. - * \exception std::runtime_error - error, if the versions are different. - */ - void checkCrestVersion(); - - // Overrides - - // GlobaTag methods - -/** - * This method creates a global tag on CREST server. - * @param globalTag - global tag as GlobalTagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"validity", 0}, - * {"description", "test"}, - * {"release", "1"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"snapshotTime", "2018-12-18T11:32:57.952+0000"}, - * {"scenario", "test"}, - * {"workflow", "M"}, - * {"type", "t"}, - * }; - * - * GlobalTagDto dto = GlobalTagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createGlobalTag(dto); - * </pre> - */ - void createGlobalTag(GlobalTagDto &globalTag) override; - -/** - * This method finds a global tag by name on the CREST server. Only one global tag should be returned. - * (This method is an analogue of the find_global_tag method in Python) - * @param name - global tag name, - * @return global tag as GlobalTagDto. - */ - GlobalTagDto findGlobalTag(const std::string &name) override; - -/** - * This method finds the global tags on the CREST server. - * @param name - global tag name pattern, "%" can be used for any symbols, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC), - * @return global tag list as GlobalTagSetDto. - */ - GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override; - -/** - * This method removes a global tag on the CREST server. - * (This method is an analogue of the remove_global_tag method in Python) - * @param name - global tag name - */ - void removeGlobalTag(const std::string &name) override; - - // Tag methods - -/** - * This method creates a tag on the CREST server. - * @param tag - tag as TagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"timeType", "time"}, - * {"description", "test"}, - * {"synchronization", "none"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"modificationTime", "2018-12-18T11:32:57.952+0000"}, - * {"payloadSpec", "JSON"}, - * {"lastValidatedTime", 0.}, - * {"endOfValidity", 0.}, - * }; - * - * TagDto dto = TagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTag(dto); - * - * </pre> - */ - void createTag(TagDto &tag) override; - -/** - * This method finds a tag by the name on the CREST server. - * (This method is an analogue of the find_tag method in Python) - * @param name - tag name - * @return tag as TagDto object. - */ - TagDto findTag(const std::string &name) override; - - /** - * This method returns the tag list as TagSetDto from the CREST server. - * (This method is an analogue of the list_tags method in Python) - * @param name - tag name pattern, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC). - * @return tag list as TagSetDto object. - */ - TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override; - -/** - * This method removes a tag from the CREST server. - * (This method is an analogue of the remove_tag method in Python) - * @param tagName - tag name - */ - void removeTag(const std::string &name) override; - -/** - * This method gets the number of IOVs for the given tag. - * (This method is an analogue of the get_size method in Python) - * @param tagname - tag name. - * @return IOV number. - */ - int getSize(const std::string& tagname) override; - - // TagMeta methods - -/** - * This method creates a tag meta info on the CREST server. - * @param tag - tag meta info as TagMetaDto. - * - * <pre> - * Example: - * - * nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}}; - * - * nlohmann::json chanList = nlohmann::json::array({channel}); - * - * nlohmann::json tagInfo = - * { - * {"channel_list", chanList}, - * {"node_description", "description of the node"}, - * {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}}; - * - * nlohmann::json js = - * { - * {"tagName", tagname}, - * {"description", "none"}, - * {"chansize", 1}, - * {"colsize", 6}, - * {"tagInfo", tagInfo.dump()}, - * {"insertionTime", "2020-12-04"}}; - * - * TagMetaDto dto = TagMetaDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTagMeta(dto); - * </pre> - */ - void createTagMeta(TagMetaDto &tag) override; - -/** - * This method updates a tag meta info on the CREST server. - * @param tag - tag meta info as TagMetaDto. - */ - void updateTagMeta(TagMetaDto &tag) override; - -/** - * This method reads a tag meta info by the tag name from the CREST server. - * @param name - tag name - * @return tag meta info as a TagMetaDto. - */ - TagMetaDto findTagMeta(const std::string &name) override; - - // GlobalTagMap methods - -/** - * This method creates a global tag map on the CREST server. - * @param globalTagMap - the global tag map as GlobalTagMapDto. - * - * <pre> - * Example: - * - * nlohmann::json js = - * { - * {"globalTagName", globaltag}, - * {"record", "testing2"}, - * {"label", "test2"}, - * {"tagName", tagname} - * }; - * - * GlobalTagMapDto globalTagMap = GlobalTagMapDto(); - * globalTagMap = globalTagMap.from_json(js); - * - * myCrestClient.createGlobalTagMap(globalTagMap); - * </pre> - */ - void createGlobalTagMap(GlobalTagMapDto& globalTagMap) override; - -/** - * This method searches for tag mappings using the global tag name or tag name - * on the CREST server. - * (This method is an analogue of the find_global_tag_map method in Python) - * @param name - name of a global tag or a tag - * @param xCrestMapMode - search mode (Trace or BackTrace). If it is set as "Trace" the global tag name will be used for searching, otherwise - the tag name. - * @return global tag map list as GlobalTagMapSetDto. - */ - GlobalTagMapSetDto findGlobalTagMap(const std::string& name, const std::string& xCrestMapMode) override; - -/** - * This method removes a global tag map on the CREST server. - * @param name - the global tag name, - * @param label - label, - * @param tagname - tag name. - */ - void removeGlobalTagMap(const std::string& name, const std::string& record, const std::string& label, const std::string& tagname) override; - - // Iovs - -/** - * This method selects IOVs for a given tagname on the CREST server. - * The result is an IOV list. - * (This method is an analogue of the select_iovs method in Python) - * @param name - tag name, - * @param since - since time (the beginning of the time interval), - * @param until - until time (end of the time interval), - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV list as IovSetDto. - */ - 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 returns IOV groups for a given tagname on CREST server. - * The result is an IOV list. - * (This method is an analogue of the select_groups method in Python) - * @param name - tag name, - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV groups as IovSetDto. - */ - IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override; - - // Payload methods - -/** - * This method stores several payloads in batch mode on the CREST server. - * (This method is an analogue of the store_data method in Python) - * @param tag - tag name. - * @param storeSetJson - iov and payload data as a JSON object. - * @param payloadFormat - payload format [FILE | JSON]. - * @param objectType - object type. - * @param compressionType - compression type. - * @param version - version. - * @param endTime - end time, if endtime = 0, the server does not use this parameter in the internal check. - * - * <pre> - * Example how to use these parameters: - * - * std::string tag = "test_MvG3a"; - * uint64_t endtime = 200; - * std::string objectType = "test"; - * std::string compressionType = "none"; - * std::string version = "1.0"; - * std::string payloadFormat = "JSON"; - * std::string jsonString = R"({"size": 1, "datatype": "data", "format": "StoreSetDto", "resources": [{"since": 1000,"data": "Sample data","streamerInfo": "Info123"}]})"; - * StoreSetDto storeSetJson = StoreSetDto::from_json(jsonString); - * </pre> - */ - 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; - - // Payload retrieval methods - -/** - * This method finds a payload resource associated to the hash on the CREST server. - * The payload returns as a string. - * (This method is an analogue of the get_payload method in Python) - * @param hash - hash. - * @return payload as a std::string - */ - std::string getPayload(const std::string &hash) override; - -/** - * This method finds a payload meta info for the hash on the CREST server. - * (This method is an analogue of the get_payload_meta method in Python) - * @param hash - hash. - * @return payload meta info as PayloadDto. - */ - PayloadDto getPayloadMeta(const std::string &hash) override; - }; - -} // namespace Crest - -#endif // CRESTAPI_CRESTCLIENT_H diff --git a/Database/CrestApi/CrestApi/CrestApiBase.h b/Database/CrestApi/CrestApi/CrestApiBase.h deleted file mode 100644 index 5531929a7325de7e62d700fcc35e276ecdd091cd..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestApiBase.h +++ /dev/null @@ -1,370 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -/*! - \file - \brief Header file for CREST C++ Client Library - - This file contains the CrestClient class. - (See CrestClientExt.h for CrestClient class extention with additional methods.) - Here is the method description. - */ - -#ifndef CRESTAPI_CRESAPIBASE_H -#define CRESTAPI_CRESAPIBASE_H - -#include <string> -#include <map> -#include <list> -#include <iosfwd> -#include <cstdint> -#include "nlohmann/json.hpp" -#include <curl/curl.h> -#include <iostream> -#include <CrestApi/CrestModel.h> - -#define DEFAULT_CREST_API_VERSION "/api-v5.0" - -namespace Crest -{ - -class CrestApiBase { - -private: - - inline static const std::string s_CREST_CLIENT_VERSION = "5.0"; - -protected: - -/** - * This method method calculates the hash for string. - * @param str - string. - * @return hash for a given string. - */ - std::string getHash(std::string_view str); - -/** - * This method method calculates the hash for a file. - * @param file - path to the file with the file name.. - * @return hash for a given file. - */ - std::string getHashForFile(const std::string &file); - -/** - * This method returns the full CrestApi version. - * @return CrestApi library version. - */ - const std::string& getClientVersion(); - - -public: - virtual ~CrestApiBase() = default; - // GlobaTag methods - -/** - * This method creates a global tag. - * @param globalTag - global tag as GlobalTagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"validity", 0}, - * {"description", "test"}, - * {"release", "1"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"snapshotTime", "2018-12-18T11:32:57.952+0000"}, - * {"scenario", "test"}, - * {"workflow", "M"}, - * {"type", "t"}, - * }; - * - * GlobalTagDto dto = GlobalTagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createGlobalTag(dto); - * </pre> - */ - virtual void createGlobalTag(GlobalTagDto& globalTag) = 0; - - -/** - * This method finds a global tag by name. Only one global tag should be returned. - * (This method is an analogue of the find_global_tag method in Python) - * @param name - global tag name, - * @return global tag as GlobalTagDto. - */ - virtual GlobalTagDto findGlobalTag(const std::string& name) = 0; - -/** - * This method finds the global tags. - * @param name - global tag name pattern, "%" can be used for any symbols, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC), - * @return global tag list as GlobalTagSetDto. - */ - virtual GlobalTagSetDto listGlobalTags(const std::string& name, int size, int page, const std::string& sort) = 0; - -/** - * This method removes a global tag. - * (This method is an analogue of the remove_global_tag method in Python) - * @param name - global tag name - */ - virtual void removeGlobalTag(const std::string& name) = 0; - - // Tag methods - -/** - * This method creates a tag. - * @param tag - tag as TagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"timeType", "time"}, - * {"description", "test"}, - * {"synchronization", "none"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"modificationTime", "2018-12-18T11:32:57.952+0000"}, - * {"payloadSpec", "JSON"}, - * {"lastValidatedTime", 0.}, - * {"endOfValidity", 0.}, - * }; - * - * TagDto dto = TagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTag(dto); - * - * </pre> - */ - virtual void createTag(TagDto& tag) = 0; - -/** - * This method finds a tag by the name. - * (This method is an analogue of the find_tag method in Python) - * @param name - tag name - * @return tag as TagDto object. - */ - virtual TagDto findTag(const std::string& name) = 0; - - /** - * This method returns the tag list as TagSetDto. - * (This method is an analogue of the list_tags method in Python) - * @param name - tag name pattern, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC). - * @return tag list as TagSetDto object. - */ - virtual TagSetDto listTags(const std::string& name, int size, int page, const std::string& sort) = 0; - -/** - * This method removes a tag. - * (This method is an analogue of the remove_tag method in Python) - * @param tagName - tag name - */ - virtual void removeTag(const std::string& name) = 0; - -/** - * This method gets the number of IOVs for the given tag. - * (This method is an analogue of the get_size method in Python) - * @param tagname - tag name. - * @return IOV number. - */ - virtual int getSize(const std::string& tagname) = 0; - - // Tag Meta Info methods - -/** - * This method creates a tag meta info. - * @param tag - tag meta info as TagMetaDto. - * - * <pre> - * Example: - * - * nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}}; - * - * nlohmann::json chanList = nlohmann::json::array({channel}); - * - * nlohmann::json tagInfo = - * { - * {"channel_list", chanList}, - * {"node_description", "description of the node"}, - * {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}}; - * - * nlohmann::json js = - * { - * {"tagName", tagname}, - * {"description", "none"}, - * {"chansize", 1}, - * {"colsize", 6}, - * {"tagInfo", tagInfo.dump()}, - * {"insertionTime", "2020-12-04"}}; - * - * TagMetaDto dto = TagMetaDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTagMeta(dto); - * </pre> - */ - virtual void createTagMeta(TagMetaDto& tag) = 0; - -/** - * This method updates a tag meta info. - * @param tag - tag meta info as TagMetaDto. - */ - virtual void updateTagMeta(TagMetaDto& tag) = 0; - -/** - * This method gets a tag meta info by the tag name. - * @param name - tag name - * @return tag meta info as a TagMetaDto. - */ - virtual TagMetaDto findTagMeta(const std::string& name) = 0; - - - // IOV methods - -/** - * This method selects IOVs for a given tagname. The result is an IOV list. - * (This method is an analogue of the select_iovs method in Python) - * @param name - tag name, - * @param since - since time (the beginning of the time interval), - * @param until - until time (end of the time interval), - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV list as IovSetDto. - */ - virtual IovSetDto selectIovs(const std::string& name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string& sort) = 0; - -/** - * This method returns IOV groups for a given tagname. The result is an IOV list. - * (This method is an analogue of the select_groups method in Python) - * @param name - tag name, - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV groups as IovSetDto. - */ - virtual IovSetDto selectGroups(const std::string& name, long snapshot, int size, int page, const std::string& sort) = 0; - - // GlobalTagMap methods - -/** - * This method creates a global tag map. - * @param globalTagMap - the global tag map as GlobalTagMapDto. - * - * <pre> - * Example: - * - * nlohmann::json js = - * { - * {"globalTagName", globaltag}, - * {"record", "testing2"}, - * {"label", "test2"}, - * {"tagName", tagname} - * }; - * - * GlobalTagMapDto globalTagMap = GlobalTagMapDto(); - * globalTagMap = globalTagMap.from_json(js); - * - * myCrestClient.createGlobalTagMap(globalTagMap); - * </pre> - */ - virtual void createGlobalTagMap(GlobalTagMapDto& globalTagMap) = 0; - -/** - * This method searches for tag mappings using the global tag name or tag name . - * (This method is an analogue of the find_global_tag_map method in Python) - * @param name - name of a global tag or a tag - * @param xCrestMapMode - search mode (Trace or BackTrace). If it is set as "Trace" the global tag name will be used for searching, otherwise - the tag name. - * @return global tag map list as GlobalTagMapSetDto. - */ - virtual GlobalTagMapSetDto findGlobalTagMap(const std::string& name, const std::string& xCrestMapMode) = 0; - -/** - * This method removes a global tag map. - * @param name - the global tag name, - * @param label - label, - * @param tagname - tag name. - */ - virtual void removeGlobalTagMap(const std::string& name, const std::string& record, const std::string& label, const std::string& tagname) = 0; - - // Payload methods - -/** - * This method stores several payloads in batch mode. - * (This method is an analogue of the store_data method in Python) - * @param tag - tag name. - * @param storeSetJson - iov and payload data as a JSON object. - * @param payloadFormat - payload format [FILE | JSON]. - * @param objectType - object type. - * @param compressionType - compression type. - * @param version - version. - * @param endTime - end time, if endtime = 0, the server does not use this parameter in the internal check. - * - * <pre> - * Example how to use these parameters: - * - * std::string tag = "test_MvG3a"; - * uint64_t endtime = 200; - * std::string objectType = "test"; - * std::string compressionType = "none"; - * std::string version = "1.0"; - * std::string payloadFormat = "JSON"; - * std::string jsonString = R"({"size": 1, "datatype": "data", "format": "StoreSetDto", "resources": [{"since": 1000,"data": "Sample data","streamerInfo": "Info123"}]})"; - * StoreSetDto storeSetJson = StoreSetDto::from_json(jsonString); - * </pre> - */ - virtual void storeData(const std::string& tag, - const StoreSetDto& storeSetJson, - const std::string& payloadFormat, - const std::string& objectType, - const std::string& compressionType, - const std::string& version, - uint64_t endTime) = 0; - - - // Payload retrieval methods - -/** - * This method finds a payload resource associated to the hash. The payload returns as a string. - * (This method is an analogue of the get_payload method in Python) - * @param hash - hash. - * @return payload as a std::string - */ - virtual std::string getPayload(const std::string& hash) = 0; - -/** - * This method finds a payload meta info for the hash. - * (This method is an analogue of the get_payload_meta method in Python) - * @param hash - hash. - * @return payload meta info as PayloadDto. - */ - virtual PayloadDto getPayloadMeta(const std::string& hash) = 0; - -/** - * This method returns the full CREST Server version. - * @return CREST server version. - */ - virtual std::string getCrestVersion() = 0; - - -}; - -} // namespace Crest - -#endif // CRESTAPI_CRESTCLIENT_H diff --git a/Database/CrestApi/CrestApi/CrestApiExt.h b/Database/CrestApi/CrestApi/CrestApiExt.h deleted file mode 100644 index 76bb20446fded01c211bbd9cce9203a63343d223..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestApiExt.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - - -/*! - \file - \brief Header file for CREST C++ Client Library (CrestClientExt) - - This file contains the CrestClientExt class. - This is a CrestClient class version with additional methods based on - Boost Parameter Library. - */ - -#include <CrestApi/CrestApi.h> -#include <boost/parameter/name.hpp> -#include <boost/parameter/preprocessor.hpp> - - -BOOST_PARAMETER_NAME(page) -BOOST_PARAMETER_NAME(size) -BOOST_PARAMETER_NAME(tagname) -BOOST_PARAMETER_NAME(sort) -BOOST_PARAMETER_NAME(dateformat) -BOOST_PARAMETER_NAME(name) - -namespace Crest { - class CrestClientExt: public CrestClient { - public: - CrestClientExt(const std::string& _host, const std::string& _port, bool _check_version = s_CREST_CLIENT_CHECK) : CrestClient(_host, _port, _check_version) {} - CrestClientExt(const std::string& url, bool check_version = s_CREST_CLIENT_CHECK) : CrestClient(url, check_version) {} - -// ~CrestClientExt(); - -/** - * This method returns the global tag list. It has boost parameters, all of them are optional. - * @param _name - global tag name pattern, optional parameter, - * @param _size - page size, a number of tags per a page, optional parameter, default value is 1000, - * @param _page - page number optional parameter, default value is 0, - * @param _sort - sorting order, default value is "name:ASC". - * If you dont use the optional parameter names, you have to use the same parameter order. - * Example: <br> - * <pre> - * nlohmann::json list1 = myCrestClient.listGlobalTagsParams(); - * nlohmann::json list2 = myCrestClient.listGlobalTagsParams("",3,5); - * nlohmann::json list2 = myCrestClient.listGlobalTagsParams(_page=3,_size=5); - * </pre> - * - * nlohmann::json listGlobalTagsParams(std::string _name, int _size, int _page); - */ - BOOST_PARAMETER_MEMBER_FUNCTION( - (GlobalTagSetDto), - listGlobalTagsParams, - tag, - (required - ) - (optional - (name, (std::string), "") - (size, (int), 1000) - (page, (int), 0) - (sort, (std::string), "name:ASC") - ) - ) { - return listGlobalTags(name, size, page, sort); - } - -/** - * This method returns the tag list. It has boost parameters, all of them are optional. - * (This method is an analogue of the list_tags method in Python) - * @param _name - tag name pattern, optional parameter, - * @param _size - page size, a number of tags per a page, optional parameter, default value is 1000, - * @param _page - page number optional parameter, default value is 0, - * @param _sort - sorting order, default value is "name:ASC". - * If you dont use the optional parameter names, you have to use the same parameter order. - * Example: <br> - * <pre> - * nlohmann::json list1 = myCrestClient.listTagsParams(); - * nlohmann::json list2 = myCrestClient.listTagsParams("",3,5); - * nlohmann::json list2 = myCrestClient.listTagsParams(_page=3,_size=5); - * </pre> - * - * nlohmann::json listTagsParams(std::string _name, int _size, int _page); - */ - BOOST_PARAMETER_MEMBER_FUNCTION( - (TagSetDto), - listTagsParams, - tag, - (required - ) - (optional - (name, (std::string), "") - (size, (int), 1000) - (page, (int), 0) - (sort, (std::string), "name:ASC") - ) - ) { - return listTags(name, size, page, sort); - } - - }; // CrestClientExt (end) - -} // namespace Crest diff --git a/Database/CrestApi/CrestApi/CrestApiFs.h b/Database/CrestApi/CrestApi/CrestApiFs.h deleted file mode 100644 index 44bdc2c713ad4b9fefe605b21dc30135e4eff319..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestApiFs.h +++ /dev/null @@ -1,486 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -/*! - \file - \brief Header file for CREST C++ Client Library - - This file contains the CrestClient class. - (See CrestClientExt.h for CrestClient class extention with additional methods.) - Here is the method description. - */ - -#ifndef CRESTAPI_CRESFSAPI_H -#define CRESTAPI_CRESFSAPI_H - -#include <string> -#include <map> -#include <list> -#include <iosfwd> -#include <cstdint> -#include "nlohmann/json.hpp" -#include <curl/curl.h> -#include <iostream> -#include <CrestApi/CrestModel.h> -#include <CrestApi/CrestApiBase.h> - -namespace Crest -{ - - class CrestFsClient : public CrestApiBase - { - private: - std::string m_root_folder{}; - std::string m_data_folder{}; - std::map<std::string, nlohmann::json> m_data{}; - bool m_isRewrite{}; - - // parameters for CREST file storage: - - inline static const std::string s_FS_TAG_PATH = "/tags"; - inline static const std::string s_FS_GLOBALTAG_PATH = "/globaltags"; - inline static const std::string s_FS_DATA_PATH = "/data"; - - inline static const std::string s_FS_TAG_FILE = "/tag.json"; - inline static const std::string s_FS_IOV_FILE = "/iovs.json"; - inline static const std::string s_FS_TAGMETAINFO_FILE = "/tagmetainfo.json"; - - inline static const std::string s_FS_META_FILE = "/meta.json"; - inline static const std::string s_FS_PALOAD_FILE = "/payload.json"; - - inline static const std::string s_FS_GLOBALTAG_FILE = "/globaltag.json"; - inline static const std::string s_FS_MAP_FILE = "/maps.json"; - - inline static const std::string s_FS_PATH = ""; - - inline static const int s_FS_PREFIX_LENGTH = 3; - std::string m_currentTag{}; - -/** - * Auxiliary method to check if the CrestApi library initialized to work with the file system. - * It was used to throw an exception if the library method not implemented for file system. - * @param method_name - method name. - */ - void checkFsException(const char *method_name); - -/** - * Auxiliary method to get a file as a string. - * (The old method name - get_file_string) - * @param path - path to the file. - * - */ - std::string getFileString(const std::string &path); // method to read file as a string - -/** - * Auxiliary method to get a file list in the given directory. - * (The old method name - get_file_list) - * @param path - path to the directory. - * - */ - void getFileList(const std::string &path); - -/** - * Auxiliary method flush the data to the file system. - * - */ - void flush(); - - public: - -/** - * CrestFsClient constructor. - * @param rewriteIfExist - this parameter sets if the data can be rewritten. - * @param root_folder - the folder where the data have to be stored. - */ - CrestFsClient(bool rewriteIfExists, const std::string &root_folder); - - ~CrestFsClient(); - - // Overrides - - // GlobaTag methods - -/** - * This method creates a global tag on the file storage. - * @param globalTag - global tag as GlobalTagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"validity", 0}, - * {"description", "test"}, - * {"release", "1"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"snapshotTime", "2018-12-18T11:32:57.952+0000"}, - * {"scenario", "test"}, - * {"workflow", "M"}, - * {"type", "t"}, - * }; - * - * GlobalTagDto dto = GlobalTagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createGlobalTag(dto); - * </pre> - */ - void createGlobalTag(GlobalTagDto &globalTag) override; - -/** - * This method finds a global tag by name on the file storage. - * Only one global tag should be returned. - * (This method is an analogue of the find_global_tag method in Python) - * @param name - global tag name, - * @return global tag as GlobalTagDto. - */ - GlobalTagDto findGlobalTag(const std::string &name) override; - -/** - * This method finds the global tags on the file storage. - * @param name - global tag name pattern, "%" can be used for any symbols, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC), - * @return global tag list as GlobalTagSetDto. - */ - GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override; - -/** - * This method removes a global tag. - * (This method is an analogue of the remove_global_tag method in Python) - * @param name - global tag name - */ - void removeGlobalTag(const std::string &name) override; - - // Tag methods - -/** - * This method creates a tag on the file storage. - * @param tag - tag as TagDto. - * - * <pre> - * - * Example: - * - * nlohmann::json js = - * { - * {"name", tagname}, - * {"timeType", "time"}, - * {"description", "test"}, - * {"synchronization", "none"}, - * {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - * {"modificationTime", "2018-12-18T11:32:57.952+0000"}, - * {"payloadSpec", "JSON"}, - * {"lastValidatedTime", 0.}, - * {"endOfValidity", 0.}, - * }; - * - * TagDto dto = TagDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTag(dto); - * - * </pre> - */ - void createTag(TagDto &tag) override; - -/** - * This method finds a tag by the name on the file storage. - * (This method is an analogue of the find_tag method in Python) - * @param name - tag name - * @return tag as TagDto object. - */ - TagDto findTag(const std::string &name) override; - - /** - * This method returns the tag list as TagSetDto. - * (This method is an analogue of the list_tags method in Python) - * @param name - tag name pattern, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (name:ASC or name:DESC). - * @return tag list as TagSetDto object. - */ - TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override; - -/** - * This method removes a tag from the file storage. - * (This method is an analogue of the remove_tag method in Python) - * @param tagName - tag name - */ - void removeTag(const std::string &name) override; - -/** - * This method gets the number of IOVs for the given tag. - * (This method is an analogue of the get_size method in Python) - * @param tagname - tag name. - * @return IOV number. - */ - int getSize(const std::string &tagname) override; - - // TagMeta methods - -/** - * This method creates a tag meta info on the file storage. - * @param tag - tag meta info as TagMetaDto. - * - * <pre> - * Example: - * - * nlohmann::json channel = {{"0", "ATLAS_PREFERRED"}}; - * - * nlohmann::json chanList = nlohmann::json::array({channel}); - * - * nlohmann::json tagInfo = - * { - * {"channel_list", chanList}, - * {"node_description", "description of the node"}, - * {"payload_spec", "stave:Int32, eta:Int32, mag:Float, base:Float, free:Float"}}; - * - * nlohmann::json js = - * { - * {"tagName", tagname}, - * {"description", "none"}, - * {"chansize", 1}, - * {"colsize", 6}, - * {"tagInfo", tagInfo.dump()}, - * {"insertionTime", "2020-12-04"}}; - * - * TagMetaDto dto = TagMetaDto(); - * dto = dto.from_json(js); - * - * myCrestClient.createTagMeta(dto); - * </pre> - */ - void createTagMeta(TagMetaDto &tag) override; - -/** - * This method updates a tag meta info on the file storage. - * @param tag - tag meta info as TagMetaDto. - */ - void updateTagMeta(TagMetaDto &tag) override; - -/** - * This method gets a tag meta info by the tag name from the file storage. - * @param name - tag name - * @return tag meta info as a TagMetaDto. - */ - TagMetaDto findTagMeta(const std::string &name) override; - - // Iovs - -/** - * This method selects IOVs for a given tagname from the file storage. - * The result is an IOV list. - * (This method is an analogue of the select_iovs method in Python) - * @param name - tag name, - * @param since - since time (the beginning of the time interval), - * @param until - until time (end of the time interval), - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV list as IovSetDto. - */ - 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 returns IOV groups for a given tagname. The result is an IOV list. - * (This method is an analogue of the select_groups method in Python) - * @param name - tag name, - * @param snapshot - snapshot, - * @param size - page size, - * @param page - page number, - * @param sort - sorting order (id.since:ASC or id.since:DESC) - * @return an IOV groups as IovSetDto. - */ - IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override; - - // GlobalTagMap methods - -/** - * This method creates a global tag map on the file storage. - * @param globalTagMap - the global tag map as GlobalTagMapDto. - * - * <pre> - * Example: - * - * nlohmann::json js = - * { - * {"globalTagName", globaltag}, - * {"record", "testing2"}, - * {"label", "test2"}, - * {"tagName", tagname} - * }; - * - * GlobalTagMapDto globalTagMap = GlobalTagMapDto(); - * globalTagMap = globalTagMap.from_json(js); - * - * myCrestClient.createGlobalTagMap(globalTagMap); - * </pre> - */ - void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override; - -/** - * This method searches for tag mappings using the global tag name or tag name - * on the file storage. (This method is an analogue of the find_global_tag_map method in Python) - * @param name - name of a global tag or a tag - * @param xCrestMapMode - search mode (Trace or BackTrace). If it is set as "Trace" the global tag name will be used for searching, otherwise - the tag name. - * @return global tag map list as GlobalTagMapSetDto. - */ - GlobalTagMapSetDto findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) override; - -/** - * This method removes a global tag map from the file storage. - * @param name - the global tag name, - * @param label - label, - * @param tagname - tag name. - */ - void removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) override; - - - // Payload methods - -/** - * This method stores several payloads in batch mode on the file storage. - * (This method is an analogue of the store_data method in Python) - * @param tag - tag name. - * @param storeSetJson - iov and payload data as a JSON object. - * @param payloadFormat - payload format [FILE | JSON]. - * @param objectType - object type. - * @param compressionType - compression type. - * @param version - version. - * @param endTime - end time, if endtime = 0, the server does not use this parameter in the internal check. - * - * <pre> - * Example how to use these parameters: - * - * std::string tag = "test_MvG3a"; - * uint64_t endtime = 200; - * std::string objectType = "test"; - * std::string compressionType = "none"; - * std::string version = "1.0"; - * std::string payloadFormat = "JSON"; - * std::string jsonString = R"({"size": 1, "datatype": "data", "format": "StoreSetDto", "resources": [{"since": 1000,"data": "Sample data","streamerInfo": "Info123"}]})"; - * StoreSetDto storeSetJson = StoreSetDto::from_json(jsonString); - * </pre> - */ - 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; - - // Payload retrieval methods - -/** - * This method finds a payload resource associated to the hash - * on the file storage. The payload returns as a string. - * (This method is an analogue of the get_payload method in Python) - * @param hash - hash. - * @return payload as a std::string - */ - std::string getPayload(const std::string &hash) override; - -/** - * This method finds a payload meta info for the hash on the file storage. - * (This method is an analogue of the get_payload_meta method in Python) - * @param hash - hash. - * @return payload meta info as PayloadDto. - */ - PayloadDto getPayloadMeta(const std::string &hash) override; - -/** - * This method returns the full CREST Server version. - * @return CREST server version. - */ - std::string getCrestVersion() override; - - - private: - std::string getDateAndTime(); - -/** - * This is an auxillary method extract first letters from the string (hash). - * The letter number is in the s_FS_PREFIX_LENGTH variable. - * This method is used to create a catalogue sub directory in the file storage. - * @param str - string to extract first letters. - * @return - string with first letters - */ - std::string getFirstLetters(const std::string &str); - - // auxiliary methods to extract a single page of the data: - nlohmann::json getPage(nlohmann::json data, int size, int page); - std::vector<std::string> getVectorPage(const std::vector<std::string>& data, int size, int page); - - // auxiliary method to get folder names: - std::vector<std::string> nameList(std::string & folder, bool ascending = true); - - // Auxiliary methods to build the path to the file. - std::string buildPath(const std::string &path, const std::string &file); - - // Auxiliary methods to sort the JSON array by the key value: - nlohmann::json sortJson(nlohmann::json js, const std::string & par, bool order); - nlohmann::json sortIOVJson(nlohmann::json js, bool order); - - // auxiliary methods to check if the string corresponds to the mask: - bool isMatch(const std::string& word, long unsigned int n, const std::string& pattern, long unsigned int m); - bool isMatch(const std::string& word, const std::string& pattern); - -/** - * This auxiliary method finds all iovs for a given tag name. The result is a JSON object. - * @param tagname - tag name. - * @return JSON array with the IOV list. Example: <br> - * - * <pre> - * IOV list = - * [ - * { - * "tagName": "CaloOflHadDMCorr2-R123-FTFP-BERT-IOVDEP-01", - * "since": 0, - * "insertionTime": "2023-09-13T12:53:46+0000", - * "payloadHash": "ba26ca6b4e17b0c33b008045c5e703bdf049a1546e731ec7c3d2d39789b1ce1f" - * }, - * ... - * ] - * </pre> - * <b>IOV JSON parameters:</b> - * <pre> - * tagName string tag name - * since number since time parameter - * insertionTime string($date-time) insertion time - * payloadHash string payload hash - * </pre> - */ - nlohmann::json findAllIovs(const std::string &tagname); - -/** - * This auxiliary method stores a single payload (with since time) on the file system. - * @param tag - tag name. - * @param since - since parameter, - * @param js - a string with a payload or file (the path and the file name) with payload. - * @param payloadFormat - payload format [FILE | JSON]. - * @param objectType - object type. - * @param compressionType - compression type. - * @param version - version. - * @param endTime - end time, if endtime = 0, the server does not use this parameter in the internal check. - */ - 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); - }; - -} // namespace Crest - -#endif // CRESTAPI_CRESTCLIENT_H diff --git a/Database/CrestApi/CrestApi/CrestCondException.h b/Database/CrestApi/CrestApi/CrestCondException.h deleted file mode 100644 index 46858cb58f20b783eeb9e3f815583183a7536f9b..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestCondException.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -#ifndef CREST_COND_EXCEPTION_H -#define CREST_COND_EXCEPTION_H -#include <iostream> -#include <stdexcept> - -namespace Crest { - const unsigned int UNKNOWN_TYPE = -1; - const unsigned int COMMON_TYPE = 0; - const unsigned int FINALIZE_STRUCTURE_TYPE = 1; - const unsigned int EXISTS_TYPE = 2; - class CrestBaseException : public std::exception { - protected: - std::string m_text; - uint32_t m_type; - CrestBaseException():m_text(""),m_type(UNKNOWN_TYPE){;} - public: - char const* what() const throw() { return m_text.c_str(); } - uint32_t getType() {return m_type;} - }; - - class FinStructureException : public CrestBaseException { - public: - FinStructureException(){ m_text="Error: Can not change structure because data already exists.";m_type=FINALIZE_STRUCTURE_TYPE;} - }; - class ColumnExistException : public CrestBaseException { - public: - ColumnExistException(const char* name){ m_text="Error: The column with name '"+std::string(name)+ "' already exists.";m_type=EXISTS_TYPE;} - }; - class CommonCrestException: public CrestBaseException { - public: - CommonCrestException(const char* text){m_text="Error: "+std::string(text); m_type=COMMON_TYPE;} - }; - -} - -#endif diff --git a/Database/CrestApi/CrestApi/CrestContainer.h b/Database/CrestApi/CrestApi/CrestContainer.h deleted file mode 100644 index 18eeea0e620d155ccfc35bf0a71bb0b678b5b71f..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestContainer.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -/*! - \file - \brief Header file for CrestContainer class. - - This file contains the CrestContainer class. Main goal of this class is store/load data for CREST. It will support (serealization and deserialization) different format of CREST payload. It is common class for prepare data for put/load payload to/from CREST server. - */ - - -#ifndef CREST_COND_CONTAINER_H -#define CREST_COND_CONTAINER_H -#include <vector> -#include <string> -#include <iostream> -#include <sstream> -#include <utility> -#include <map> -#include "nlohmann/json.hpp" - -namespace Crest { - enum class TypeId { - Bool, UChar, Int16, UInt16, - Int32, UInt32, UInt63, Int64, - Float, Double, String255, String4k, - String64k, String16M, String128M, Blob64k, Blob16M, Blob128M, TypeIdCount - }; - const static std::map<TypeId, std::string> s_typeToString = { - { TypeId::Bool, "Bool" }, - { TypeId::UChar, "UChar" }, - { TypeId::Int16, "Int16" }, - { TypeId::UInt16, "UInt16" }, - { TypeId::Int32, "Int32" }, - { TypeId::UInt32, "UInt32" }, - { TypeId::UInt63, "UInt63" }, - { TypeId::Int64, "Int64" }, - { TypeId::Float, "Float" }, - { TypeId::Double, "Double" }, - { TypeId::String255, "String255" }, - { TypeId::String4k, "String4k" }, - { TypeId::String64k, "String64k" }, - { TypeId::String16M, "String16M" }, - { TypeId::String128M,"String128M"}, - { TypeId::Blob64k, "Blob64k" }, - { TypeId::Blob16M, "Blob16M" }, - { TypeId::Blob128M, "Blob128M" } - }; - - enum class ModeId{ - Standard, DCS, DCS_FULL - }; - class CrestContainer{ - private: - std::vector<std::pair<std::string,TypeId>> m_payload_spec; - nlohmann::json m_payload={}; - nlohmann::json m_row={}; - nlohmann::json m_iov_data={}; - nlohmann::json m_vector_data=nlohmann::json::array(); - nlohmann::json m_full_data={}; - ModeId m_modeId; - bool m_isVectorPayload=false; - - void validatePayloadSize(const nlohmann::json &data) const; - nlohmann::json createRowArray(const nlohmann::json& data_row) const; - const nlohmann::json& getRow(); - - public: - CrestContainer(); - ~CrestContainer(); - /** - * @brief It adds a column to the payload specification. - * @param name The name of the column. - * @param type The type of the column. - * - * This method adds a column to the payload specification. filling the vector m_payload_spec. - * The methods with a different signature are just overloads to make it easier to use. - */ - void addColumn(const std::string& name, TypeId type); - void addColumn(const std::string& name, const char* type); - void addColumn(const std::string& name, uint32_t type); - - /** - * @brief It sets the mode of the container. - */ - bool isVectorPayload(); - void setVectorPayload(bool isVectorPayload); - - Crest::TypeId stringToTypeId(const std::string& type) const; - Crest::TypeId intToTypeId(int value) const; - - /** - * @brief It adds row data to vector. - * - * This method should use for Vector type of data. It should call after all data of row is added. - */ - void putRow2Vector(); - - /** - * @brief It adds a null value to the payload. - * @param name The name of the column. - * - * This method adds a null to the payload. It fills the json object m_row. - */ - void addNullRecord(const char* name); - - /** - * @brief It adds a record to the payload. - * @param name The name of the column. - * @param number The number of parameters. - * @param ... The values of the record. - * - * This method adds a record to the payload. It fills the json object m_row. - */ - void addRecord(const char* name,int number, ...); - /** - * @brief It associate the payload row to a channel_id. - * @param channel_id The channel_id to associate the payload row. - * - * The method adds the current payload row to the json object m_payload. The row is associated with the channel_id. - */ - void addData(const char* channel_id); - /** - * @brief It associate the payload row to a channel_id. - * @param channel_id The channel_id to associate the payload row. - * @param data The data to be associated with the channel_id. - * - * The method adds the payload row to the json object m_payload. The row is associated with the channel_id. - * The data is the data to be associated with the channel_id, and they belong to a previously filled payload row. - */ - void addExternalData(const char* channel_id, const nlohmann::json& data); - /** - * @brief It adds an IOV to the json object m_iov_data. - * @param since The since value of the IOV. - * - * The data is a json object containing all channels stored before, and kept in m_payload. - */ - void addIov(const uint64_t since); - - const std::vector<std::pair<std::string,TypeId>>& getMPayloadSpec(); - - template<typename T> T getRecord(const std::string& name) - { - for (const auto& column : m_payload_spec) { - if (column.first == name) { - try { - return m_row.at(name).get<T>(); - } catch (nlohmann::json::exception& e) { - throw std::runtime_error("JSON exception for key: " + name); - } - } - } - throw std::runtime_error("Column name not found or type mismatch."); - } - - const nlohmann::json& getPayload(); - const nlohmann::json& getIovData(); - - const nlohmann::json& getPayloadChannel(const char* channel_id); - - - void setIovData(const nlohmann::json& j); - void setPayload(const nlohmann::json& j); - // return the payload spec as a copy - nlohmann::json getPayloadSpec(); - void setPayloadSpec(const nlohmann::json& j); - - /** - * @brief It encodes the input string to base64. - */ - static std::string base64_encode(const uint8_t* bytes_to_encode, unsigned int in_len); - /** - * @brief It decodes the input string from base64. - */ - static std::vector<unsigned char> base64_decode(const std::string& encodedData); - /** - * @brief It returns the index of the column with the given name. - * @param name The name of the column. - * It checks the payload spec array to get the index back. - */ - int getColumnIndex(const std::string& name); - /** - * @brief It reinitializes the containers. - */ - void flush(); - void clear(); - void selectIov(const uint64_t since); - std::vector<std::string> channelIds(); - /** - * @brief It returns the json representation of the container. - */ - std::string getJsonPayload(); - /** - * @brief It returns the json representation of the container. - */ - std::string getJsonIovData(); - /** - * @brief It creates a file with the json representation of the container. - */ - void dump_json_to_file(const nlohmann::json& j, const std::string& filename); - /** - * @brief It reads a json file and returns the json object. - */ - nlohmann::json read_json_from_file(const std::string& filename, const std::string& spec_filename); - /** - * @brief It reads a json object to fill the containers. - */ - void from_json(const uint64_t since, const nlohmann::json& j); - - void parseOldFormat(std::string& colName, TypeId& typespec,const nlohmann::json & j); - }; -} -#endif diff --git a/Database/CrestApi/CrestApi/CrestException.h b/Database/CrestApi/CrestApi/CrestException.h deleted file mode 100644 index f3b12fc98d1c2d07fa25621369fb131822c7aeba..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestException.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -namespace Crest -{ - - class CrestException : public std::runtime_error - { - public: - CrestException(const std::string& what = "") : std::runtime_error(what) {} - }; - - - class CrestConflictException : public CrestException - { - public: - CrestConflictException(const std::string& what = "") : CrestException(what) {} - }; - -} diff --git a/Database/CrestApi/CrestApi/CrestModel.h b/Database/CrestApi/CrestApi/CrestModel.h deleted file mode 100644 index 00a2457baf3547631287bbfcd8ad376816553d77..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestModel.h +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 2019-2025 CERN for the benefit of the ATLAS collaboration - */ - -#ifndef CREST_DTOS_HPP -#define CREST_DTOS_HPP - -#include <string> -#include <vector> -#include <optional> -#include "nlohmann/json.hpp" -#include <CrestApi/CrestException.h> - -#include <optional> - -using json = nlohmann::json; - -class RespPage -{ -public: - int size{}; - int64_t totalElements{}; - int totalPages{}; - int number{}; - - json to_json() const; - static RespPage from_json(const json &j); -}; - -class GenericMap -{ -public: - std::map<std::string, std::string> additionalProperties; - - json to_json() const; - - static GenericMap from_json(const json &j); -}; - -class CrestBaseResponse -{ -private: -public: - virtual ~CrestBaseResponse() = default; - std::optional<std::string> datatype; - std::optional<RespPage> page; - std::optional<GenericMap> filter; - json to_json() const; - void load_from_json(const json &j); - virtual const char* getFormat() const =0; - virtual int64_t getSize() const =0; -}; - -class GlobalTagDto -{ -public: - std::string name; - int64_t validity{}; - std::string description; - std::string release; - std::optional<std::string> insertionTime; - std::string snapshotTime; - std::string scenario; - std::string workflow; - std::string type; - int64_t snapshotTimeMilli{}; - int64_t insertionTimeMilli{}; - - // Ctor - GlobalTagDto(const char* _name, const char* _description, const char* _release, const char* _workflow); - - // Default Ctor - GlobalTagDto(); - - json to_json() const ; - - static GlobalTagDto from_json(const json &j); -}; - -class GlobalTagSetDto : public CrestBaseResponse -{ -public: - std::vector<GlobalTagDto> resources; - const char* getFormat() const {return "GlobalTagSetDto";} - int64_t getSize() const{return resources.size();} - - json to_json() const; - - static GlobalTagSetDto from_json(const json &j); -}; - -/** - * @brief The TagDto class - * It contains all fields of the TagDto class from the CREST API. - * When using this to create a new Tag you don't need to set insertion and modification times. - */ -class TagDto -{ -public: - std::string name; - std::string timeType; - std::string objectType; - std::string synchronization; - std::string description; - uint64_t lastValidatedTime{}; - uint64_t endOfValidity{}; - std::optional<std::string> insertionTime; - std::optional<std::string> modificationTime; - // Ctor - TagDto(std::string _name, std::string _timeType, std::string _description): name(_name), timeType(_timeType), - objectType(""), - synchronization("none"), - description(_description), - lastValidatedTime(0), endOfValidity(0){ - - } - // Default Ctor - TagDto(): name(""), timeType(""), objectType(""), synchronization("none"), description(""), lastValidatedTime(0), endOfValidity(0) { - - } - json to_json() const; - static TagDto from_json(const json &j); -}; - -class TagSetDto : public CrestBaseResponse -{ -public: - std::vector<TagDto> resources; - const char* getFormat() const {return "TagSetDto";} - int64_t getSize() const{return resources.size();} - - json to_json() const; - - static TagSetDto from_json(const json &j); -}; - - -class GlobalTagMapDto -{ -public: - std::string tagName; - std::string globalTagName; - std::string record; - std::string label; - // Ctor - GlobalTagMapDto(const std::string& tagName, const std::string& globalTagName, const std::string& record): - tagName(tagName), globalTagName(globalTagName), record(record), label("none"){ - - } - // Default Ctor - GlobalTagMapDto(): tagName(""), globalTagName(""), record("none"), label("none"){ - - } - - json to_json() const; - static GlobalTagMapDto from_json(const json &j); -}; - -class GlobalTagMapSetDto : public CrestBaseResponse -{ -public: - std::vector<GlobalTagMapDto> resources; - const char* getFormat() const {return "GlobalTagMapSetDto";} - int64_t getSize() const{return resources.size();} - - json to_json() const; - static GlobalTagMapSetDto from_json(const json &j); - - static GlobalTagMapSetDto from_fs_json(const json &j); -}; - -class ChannelSetDto{ -private: - std::vector< std::pair<std::string,std::string> > m_channels; -public: - ChannelSetDto& operator=(const ChannelSetDto&) = default; - ChannelSetDto& operator=(ChannelSetDto&&) = default; - - ChannelSetDto(){} - ChannelSetDto(ChannelSetDto const& copy):m_channels(copy.getChannels()){} - void add(const std::string& id,const std::string& name); - const std::vector< std::pair<std::string,std::string> >& getChannels() const {return m_channels;} - size_t getSize() const {return m_channels.size();} - json to_json() const; - static ChannelSetDto from_json(const json &j); -}; - -class PayloadSpecDto{ -private: - std::vector< std::pair<std::string,std::string> > m_row; -public: - PayloadSpecDto& operator=(const PayloadSpecDto&) = default; - PayloadSpecDto& operator=(PayloadSpecDto&&) = default; - PayloadSpecDto(){} - PayloadSpecDto(PayloadSpecDto const& copy):m_row(copy.getColumns()){} - const std::vector< std::pair<std::string,std::string> >& getColumns() const {return m_row;} - size_t getSize() const {return m_row.size();} - void add(const std::string& name,const std::string& type); - json to_json() const; - static PayloadSpecDto from_json(const json &j); -}; - -class TagInfoDto{ -private: - std::string m_node_description; - PayloadSpecDto m_payload_spec; - ChannelSetDto m_channel_list; -public: - TagInfoDto(const std::string& description):m_node_description(description){ - } - TagInfoDto(const std::string& description,PayloadSpecDto& payload_spec,ChannelSetDto& channel_list): - m_node_description(description),m_payload_spec(payload_spec),m_channel_list(channel_list){ - } - void setPayloadSpec(PayloadSpecDto& spec){ - m_payload_spec=spec; - } - void setChannel(ChannelSetDto& ch){ - m_channel_list=ch; - } - const PayloadSpecDto& getPayloadSpec() - { - return m_payload_spec; - } - const ChannelSetDto& getChannels() - { - return m_channel_list; - } - const std::string& getFolderDescription(){ return m_node_description;} - size_t getChannelSize() const {return m_channel_list.getSize();} - size_t getColumnSize() const {return m_payload_spec.getSize();} - json to_json() const; - static TagInfoDto from_json(const json &j); - -}; - - -class TagMetaDto -{ -public: - std::string tagName; - std::string description; - std::optional<std::string> insertionTime; - TagInfoDto tagInfo; - // Ctor - TagMetaDto(const std::string& tagName, const std::string& description, const TagInfoDto& info): - tagName(tagName), description(description), tagInfo(info){ - } - // Default Ctor - TagMetaDto(): tagName(""), description(""), tagInfo(""){ - } - - json to_json() const; - static TagMetaDto from_json(const json &j); -}; - -class TagMetaSetDto : public CrestBaseResponse -{ -public: - std::vector<TagMetaDto> resources; - const char* getFormat() const {return "TagMetaSetDto";} - int64_t getSize() const{return resources.size();} - - json to_json() const; - static TagMetaSetDto from_json(const json &j); -}; - -class IovDto -{ -public: - std::string tagName; - uint64_t since{}; - std::optional<std::string> insertionTime; - std::string payloadHash; - // Ctor - IovDto(const std::string& tagName, uint64_t since, const std::string& payloadHash): - tagName(tagName), since(since), payloadHash(payloadHash) { - } - // Default Ctor - IovDto(): tagName(""), since(0), payloadHash("") { - } - - json to_json() const; - static IovDto from_json(const json &j); -}; - -class IovSetDto : public CrestBaseResponse -{ -public: - std::vector<IovDto> resources; - const char* getFormat() const {return "IovSetDto";} - int64_t getSize() const{return resources.size();} - std::vector<uint64_t> getListSince(); - json to_json() const; - - static IovSetDto from_json(const json &j); - - static IovSetDto from_fs_json(const json &j); -}; - -class StoreDto -{ - std::optional<std::string> m_app_name; - std::optional<std::string> m_app_version; -public: - uint64_t since{}; - std::string hash; - std::string data; - std::optional<std::string> insertionTime; - StoreDto(uint64_t l_since, const std::string& l_data): - since(l_since), hash(""), data(l_data){ - - } - // Ctor - StoreDto(uint64_t since, const std::string& hash, const std::string& data): - since(since), hash(hash), data(data){ - - } - // Default Ctor - StoreDto(): since(0), hash(""), data(""){ - } - - void setAppVersion (const char* str){m_app_version=str;} - void setAppName (const char* str){m_app_name=str;} - json getStreamerInfo() const; - json to_json() const; - - static StoreDto from_json(const json &j); -}; - -class StoreSetDto : public CrestBaseResponse -{ -public: - std::vector<StoreDto> resources; - const char* getFormat() const {return "StoreSetDto";} - int64_t getSize() const{return resources.size();} - - void push_back(const StoreDto & dto); - void clear(); - json to_json() const; - - static StoreSetDto from_json(const json &j); -}; - -class PayloadDto -{ -public: - std::string hash; - std::string version; - std::string objectType; - std::string objectName; - std::string compressionType; - std::string checkSum; - int size{}; - std::optional<std::string> insertionTime; - - // Function to serialize the object to JSON - - json to_json() const; - - // Function to deserialize the object from JSON - - static PayloadDto from_json(const json &j); -}; - -class PayloadSetDto : public CrestBaseResponse -{ -public: - std::vector<PayloadDto> resources; - const char* getFormat() const {return "PayloadSetDto";} - int64_t getSize() const{return resources.size();} - - // Function to serialize the object to JSON - - json to_json() const; - - // Function to deserialize the object from JSON - - static PayloadSetDto from_json(const json &j); -}; - -#endif // CREST_DTOS_HPP diff --git a/Database/CrestApi/CrestApi/CrestRequest.h b/Database/CrestApi/CrestApi/CrestRequest.h deleted file mode 100644 index 3b6cc6fed0656d8ce5d4101c4c223e81004f8796..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/CrestRequest.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - Copyright (C) 2019-2024 CERN for the benefit of the ATLAS collaboration - */ - -#ifndef CRESTAPI_REQUEST_H -#define CRESTAPI_REQUEST_H - -#include <string> -#include <map> -#include <iosfwd> -#include <cstdint> -#include "nlohmann/json.hpp" -#include <iostream> -#include <curl/curl.h> - -namespace Crest -{ - - // The action to be performed - enum class Action - { - GET = 0, - POST = 1, - PUT = 2, - DELETE = 3 - }; - - class urlParameters - { - private: - std::string m_str{}; - - public: - void add(const std::string &key, const std::string &value) - { - if (m_str.empty()) - { - m_str = key; - m_str += '='; - m_str += value; - } - else - { - m_str += '&'; - m_str += key; - m_str += '='; - m_str += value; - } - } - - const std::string &getParams() const - { - return m_str; - } - - void reset() - { - m_str.clear(); - } - }; - - class CrestRequest - { - - private: - std::string m_prefix = "http://"; - std::string m_host; - std::string m_port; - std::string make_url(const std::string &address) const; - - char* m_CREST_PROXY = NULL; - const char* m_CREST_PROXY_VAR = "SOCKS_PROXY"; - - // Auxiliary method to make request to the CREST Server. This method is used by other methods realizing the - // requests with the concrete kinds of data (iovs|payloads|tags…). - // They are used to clean the response from the CREST Server from the additional information and to check the - // response code. - bool isJson(const std::string& str); - nlohmann::json getJson(const std::string& str, const char* method); - nlohmann::json getJson(const std::string& str); - int checkErrors(const nlohmann::json& js, const char* method); - std::string parseXMLOutput(const std::string_view xmlBuffer); - std::string removeCR(const std::string& str); - - void getProxyPath(); - - public: - CrestRequest(); - ~CrestRequest(); - - void setHost(const std::string& host); - void setPort(const std::string& port); - void setPrefix(const std::string& prefix); - - /** - * General auxiliary method to make request to the CREST Server. This method is used by other methods realizing the - * requests with the concrete kinds of data (iovs|payloads|tags…). - * - * @param current_path - URL request path - * @param action - Action (GET|POST|DELETE) - * @param js - a JSON object which has to be send or changed with this request. If this argument has to be void it has - * to be set as nullptr. - * - */ - std::string performRequest(const std::string ¤t_path, Action action, nlohmann::json &js, const std::string& header_params = ""); - - /** - * General auxillary method to make request to the CREST Server. This method is used by other methods realizing the - * requests with the concrete kinds of data (iovs|payloads|tags…). - * - * @param current_path - URL request path - * @param action - Action (GET|POST|DELETE) - * @param js - a JSON object which has to be send or changed with this request. If this argument has to be void it has - * to be set as nullptr. - * @param method_name - the name of method which called this method. This parameter is used in the error messages. - * - */ - std::string performRequest(const std::string ¤t_path, Action action, nlohmann::json &js, - const char *method_name, const std::string& header_params = ""); - - - std::vector<char> getPayloadRequest(const std::string ¤t_path); - - - std::string uploadPayload(const std::string ¤t_path, - const std::string& tag, uint64_t endtime, const nlohmann::json& js, - const std::string& objectType, const std::string& compressionType, const std::string& version, - const std::vector<std::string>& files); - - void checkResult(CURLcode res, long response_code, const std::string& st, const char* method_name); - }; -} - -#endif // CRESTAPI_REQUEST_H diff --git a/Database/CrestApi/CrestApi/picosha2.h b/Database/CrestApi/CrestApi/picosha2.h deleted file mode 100644 index 97cfb00ccfe2a04c8c5d73de02d9d07f635db787..0000000000000000000000000000000000000000 --- a/Database/CrestApi/CrestApi/picosha2.h +++ /dev/null @@ -1,387 +0,0 @@ -/* - The MIT License (MIT) - - Copyright (C) 2017 okdshin - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ -#ifndef PICOSHA2_H -#define PICOSHA2_H -// picosha2:20140213 - -#ifndef PICOSHA2_BUFFER_SIZE_FOR_INPUT_ITERATOR -#define PICOSHA2_BUFFER_SIZE_FOR_INPUT_ITERATOR \ - 1048576 //=1024*1024: default is 1MB memory -#endif - -#include <algorithm> -#include <cassert> -#include <iterator> -#include <sstream> -#include <vector> -#include <fstream> -namespace picosha2 { - typedef unsigned long word_t; - typedef unsigned char byte_t; - - static const size_t k_digest_size = 32; - - namespace detail { - inline byte_t mask_8bit(byte_t x) {return x & 0xff;} - - inline word_t mask_32bit(word_t x) {return x & 0xffffffff;} - - const word_t add_constant[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, - 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, - 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, - 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, - 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, - 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - }; - - const word_t initial_message_digest[8] = { - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, - 0xa54ff53a, 0x510e527f, 0x9b05688c, - 0x1f83d9ab, 0x5be0cd19 - }; - - inline word_t ch(word_t x, word_t y, word_t z) {return (x & y) ^ ((~x) & z);} - - inline word_t maj(word_t x, word_t y, word_t z) { - return (x & y) ^ (x & z) ^ (y & z); - } - - inline word_t rotr(word_t x, std::size_t n) { - assert(n < 32); - return mask_32bit((x >> n) | (x << (32 - n))); - } - - inline word_t bsig0(word_t x) {return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);} - - inline word_t bsig1(word_t x) {return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);} - - inline word_t shr(word_t x, std::size_t n) { - assert(n < 32); - return x >> n; - } - - inline word_t ssig0(word_t x) {return rotr(x, 7) ^ rotr(x, 18) ^ shr(x, 3);} - - inline word_t ssig1(word_t x) {return rotr(x, 17) ^ rotr(x, 19) ^ shr(x, 10);} - - template <typename RaIter1, typename RaIter2> - void hash256_block(RaIter1 message_digest, RaIter2 first, RaIter2 last) { - assert(first + 64 == last); - static_cast<void>(last); // for avoiding unused-variable warning - word_t w[64]; - std::fill(w, w + 64, 0); - for (std::size_t i = 0; i < 16; ++i) { - w[i] = (static_cast<word_t>(mask_8bit(*(first + i * 4))) << 24) | - (static_cast<word_t>(mask_8bit(*(first + i * 4 + 1))) << 16) | - (static_cast<word_t>(mask_8bit(*(first + i * 4 + 2))) << 8) | - (static_cast<word_t>(mask_8bit(*(first + i * 4 + 3)))); - } - for (std::size_t i = 16; i < 64; ++i) { - w[i] = mask_32bit(ssig1(w[i - 2]) + w[i - 7] + ssig0(w[i - 15]) + - w[i - 16]); - } - - word_t a = *message_digest; - word_t b = *(message_digest + 1); - word_t c = *(message_digest + 2); - word_t d = *(message_digest + 3); - word_t e = *(message_digest + 4); - word_t f = *(message_digest + 5); - word_t g = *(message_digest + 6); - word_t h = *(message_digest + 7); - - for (std::size_t i = 0; i < 64; ++i) { - word_t temp1 = h + bsig1(e) + ch(e, f, g) + add_constant[i] + w[i]; - word_t temp2 = bsig0(a) + maj(a, b, c); - h = g; - g = f; - f = e; - e = mask_32bit(d + temp1); - d = c; - c = b; - b = a; - a = mask_32bit(temp1 + temp2); - } - *message_digest += a; - *(message_digest + 1) += b; - *(message_digest + 2) += c; - *(message_digest + 3) += d; - *(message_digest + 4) += e; - *(message_digest + 5) += f; - *(message_digest + 6) += g; - *(message_digest + 7) += h; - for (std::size_t i = 0; i < 8; ++i) { - *(message_digest + i) = mask_32bit(*(message_digest + i)); - } - } - } // namespace detail - - template <typename InIter> - void output_hex(InIter first, InIter last, std::ostream& os) { - os.setf(std::ios::hex, std::ios::basefield); - while (first != last) { - os.width(2); - os.fill('0'); - os << static_cast<unsigned int>(*first); - ++first; - } - os.setf(std::ios::dec, std::ios::basefield); - } - - template <typename InIter> - void bytes_to_hex_string(InIter first, InIter last, std::string& hex_str) { - std::ostringstream oss; - output_hex(first, last, oss); - hex_str.assign(oss.str()); - } - - template <typename InContainer> - void bytes_to_hex_string(const InContainer& bytes, std::string& hex_str) { - bytes_to_hex_string(bytes.begin(), bytes.end(), hex_str); - } - - template <typename InIter> - std::string bytes_to_hex_string(InIter first, InIter last) { - std::string hex_str; - bytes_to_hex_string(first, last, hex_str); - return hex_str; - } - - template <typename InContainer> - std::string bytes_to_hex_string(const InContainer& bytes) { - std::string hex_str; - bytes_to_hex_string(bytes, hex_str); - return hex_str; - } - - class hash256_one_by_one { - public: - hash256_one_by_one() {init();} - - void init() { - m_buffer_.clear(); - std::fill(m_data_length_digits_, m_data_length_digits_ + 4, 0); - std::copy(detail::initial_message_digest, - detail::initial_message_digest + 8, m_h_); - } - - template <typename RaIter> - void process(RaIter first, RaIter last) { - add_to_data_length(static_cast<word_t>(std::distance(first, last))); - std::copy(first, last, std::back_inserter(m_buffer_)); - std::size_t i = 0; - for (; i + 64 <= m_buffer_.size(); i += 64) { - detail::hash256_block(m_h_, m_buffer_.begin() + i, - m_buffer_.begin() + i + 64); - } - m_buffer_.erase(m_buffer_.begin(), m_buffer_.begin() + i); - } - - void finish() { - byte_t temp[64]; - - std::fill(temp, temp + 64, 0); - std::size_t remains = m_buffer_.size(); - std::copy(m_buffer_.begin(), m_buffer_.end(), temp); - temp[remains] = 0x80; - - if (remains > 55) { - std::fill(temp + remains + 1, temp + 64, 0); - detail::hash256_block(m_h_, temp, temp + 64); - std::fill(temp, temp + 64 - 4, 0); - } else { - std::fill(temp + remains + 1, temp + 64 - 4, 0); - } - - write_data_bit_length(&(temp[56])); - detail::hash256_block(m_h_, temp, temp + 64); - } - - template <typename OutIter> - void get_hash_bytes(OutIter first, OutIter last) const { - for (const word_t* iter = m_h_; iter != m_h_ + 8; ++iter) { - for (std::size_t i = 0; i < 4 && first != last; ++i) { - *(first++) = detail::mask_8bit( - static_cast<byte_t>((*iter >> (24 - 8 * i)))); - } - } - } - - private: - void add_to_data_length(word_t n) { - word_t carry = 0; - - m_data_length_digits_[0] += n; - for (std::size_t i = 0; i < 4; ++i) { - m_data_length_digits_[i] += carry; - if (m_data_length_digits_[i] >= 65536u) { - carry = m_data_length_digits_[i] >> 16; - m_data_length_digits_[i] &= 65535u; - } else { - break; - } - } - } - - void write_data_bit_length(byte_t* begin) { - word_t data_bit_length_digits[4]; - - std::copy(m_data_length_digits_, m_data_length_digits_ + 4, - data_bit_length_digits); - - // convert byte length to bit length (multiply 8 or shift 3 times left) - word_t carry = 0; - for (std::size_t i = 0; i < 4; ++i) { - word_t before_val = data_bit_length_digits[i]; - data_bit_length_digits[i] <<= 3; - data_bit_length_digits[i] |= carry; - data_bit_length_digits[i] &= 65535u; - carry = (before_val >> (16 - 3)) & 65535u; - } - - // write data_bit_length - for (int i = 3; i >= 0; --i) { - (*begin++) = static_cast<byte_t>(data_bit_length_digits[i] >> 8); - (*begin++) = static_cast<byte_t>(data_bit_length_digits[i]); - } - } - - std::vector<byte_t> m_buffer_; - word_t m_data_length_digits_[4]; // as 64bit integer (16bit x 4 integer) - word_t m_h_[8]; - }; - - inline void get_hash_hex_string(const hash256_one_by_one& hasher, - std::string& hex_str) { - byte_t hash[k_digest_size]; - - hasher.get_hash_bytes(hash, hash + k_digest_size); - return bytes_to_hex_string(hash, hash + k_digest_size, hex_str); - } - - inline std::string get_hash_hex_string(const hash256_one_by_one& hasher) { - std::string hex_str; - get_hash_hex_string(hasher, hex_str); - return hex_str; - } - - namespace impl { - template <typename RaIter, typename OutIter> - void hash256_impl(RaIter first, RaIter last, OutIter first2, OutIter last2, int, - std::random_access_iterator_tag) { - hash256_one_by_one hasher; - - // hasher.init(); - hasher.process(first, last); - hasher.finish(); - hasher.get_hash_bytes(first2, last2); - } - - template <typename InputIter, typename OutIter> - void hash256_impl(InputIter first, InputIter last, OutIter first2, - OutIter last2, int buffer_size, std::input_iterator_tag) { - std::vector<byte_t> buffer(buffer_size); - hash256_one_by_one hasher; - // hasher.init(); - while (first != last) { - int size = buffer_size; - for (int i = 0; i != buffer_size; ++i, ++first) { - if (first == last) { - size = i; - break; - } - buffer[i] = *first; - } - hasher.process(buffer.begin(), buffer.begin() + size); - } - hasher.finish(); - hasher.get_hash_bytes(first2, last2); - } - } - - template <typename InIter, typename OutIter> - void hash256(InIter first, InIter last, OutIter first2, OutIter last2, - int buffer_size = PICOSHA2_BUFFER_SIZE_FOR_INPUT_ITERATOR) { - picosha2::impl::hash256_impl( - first, last, first2, last2, buffer_size, - typename std::iterator_traits<InIter>::iterator_category()); - } - - template <typename InIter, typename OutContainer> - void hash256(InIter first, InIter last, OutContainer& dst) { - hash256(first, last, dst.begin(), dst.end()); - } - - template <typename InContainer, typename OutIter> - void hash256(const InContainer& src, OutIter first, OutIter last) { - hash256(src.begin(), src.end(), first, last); - } - - template <typename InContainer, typename OutContainer> - void hash256(const InContainer& src, OutContainer& dst) { - hash256(src.begin(), src.end(), dst.begin(), dst.end()); - } - - template <typename InIter> - void hash256_hex_string(InIter first, InIter last, std::string& hex_str) { - byte_t hashed[k_digest_size]; - - hash256(first, last, hashed, hashed + k_digest_size); - std::ostringstream oss; - output_hex(hashed, hashed + k_digest_size, oss); - hex_str.assign(oss.str()); - } - - template <typename InIter> - std::string hash256_hex_string(InIter first, InIter last) { - std::string hex_str; - hash256_hex_string(first, last, hex_str); - return hex_str; - } - - inline void hash256_hex_string(const std::string& src, std::string& hex_str) { - hash256_hex_string(src.begin(), src.end(), hex_str); - } - - template <typename InContainer> - void hash256_hex_string(const InContainer& src, std::string& hex_str) { - hash256_hex_string(src.begin(), src.end(), hex_str); - } - - template <typename InContainer> - std::string hash256_hex_string(const InContainer& src) { - return hash256_hex_string(src.begin(), src.end()); - } - - template<typename OutIter>void hash256(std::ifstream& f, OutIter first, OutIter last) { - hash256(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>(), first, last); - } -}// namespace picosha2 -#endif // PICOSHA2_H diff --git a/Database/CrestApi/README.md b/Database/CrestApi/README.md deleted file mode 100644 index 9205b1fb7e494f2222790b04e9a73e514446b1ef..0000000000000000000000000000000000000000 --- a/Database/CrestApi/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# CREST Client C++ Library. -This library implements the client API to interact with the CREST Server. - -## Project structure -CrestApi project structure: - -| Directory | Description | -|------------|------------------------------------------------------------| -| CrestApi | Contains the header files for the library (CrestApi.h). | -| data | Contains the data files used in the CrestApi examples. | -| doc | Contains examples for the library. | -| scripts | Contains the bash scripts used to create objects in the CREST Server. | -| src | Contains the library source code (CrestApi.cxx). | -| test | Contains the ATLAS test (test.cxx). *(To be written later)*| -| CMakeList.txt | CMake file for the package CrestApi. | - -## Installation -We provide this code as a standalone library. -It requires: -* the `nlhomann` JSON library (this is delivered within this package) -* the `CURL` library -* the `BOOST` library - -### Standalone (lxplus) -* Create a build directory -```shell -mkdir build -``` -* Create Makefiles -```shell -cd ./build -cmake .. -``` -* Compile library and examples -```shell -make -``` -## Testing -The simple examples are in the `doc` directory. The executables will be created in the `build` directory. - -* `crest_example_server`: this file utilizes a *CREST* server, so you need to provide a *URL* as argument. In general you can use `http://crest-undertow-api.web.cern.ch` - -* `crest_example_fs` : this file utilizes the file system. - - diff --git a/Database/CrestApi/README.txt b/Database/CrestApi/README.txt deleted file mode 100644 index a9d403ca758d5e52f6eda9408d5bb02c2484713b..0000000000000000000000000000000000000000 --- a/Database/CrestApi/README.txt +++ /dev/null @@ -1,28 +0,0 @@ -This is CREST Client C++ Library. -This library realises the client API to the CREST Server. - -============================================================= - -EXAMPLES - -The simple examples are in the crest_example.cxx. This file is in -the /doc folder. - -WARNING! The examples uses the test versions of the CREST servers. -If they do not respond please edit their network addresses in the -crest_example.cxx and recompile it. - - -============================================================== - -CrestApi project structure: - -CrestApi - this directory conrains the header files for the library (CrestApi.h). -data - this directory contains the data files used in the CrestApi examples. -doc - this directory contains examples for the library -scripts - this directory contains the bash scripts used to create some objects in the CREST Server. -src - this directory contains the library source code (CrestApi.cxx). -test - this directory contains the ATLAS test (test.cxx) It has to be written later. - -CMakeList.txt - CMake file for the package CrestApi. - diff --git a/Database/CrestApi/data/data.txt b/Database/CrestApi/data/data.txt deleted file mode 100644 index a58f8dcf54cca96e5dca63124b869aaf9325ea47..0000000000000000000000000000000000000000 --- a/Database/CrestApi/data/data.txt +++ /dev/null @@ -1 +0,0 @@ -{"data_array":{"0":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000000]"],"100":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000001]"],"101":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000002]"],"200":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000003]"],"201":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000004]"],"202":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000005]"],"203":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000006]"],"204":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000007]"],"205":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000008]"],"206":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000009]"],"207":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000A]"],"208":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000B]"],"209":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000C]"],"210":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000D]"],"211":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000E]"],"212":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000000F]"],"213":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000010]"],"214":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000011]"],"215":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000012]"],"216":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000013]"],"217":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000014]"],"218":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000015]"],"219":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000016]"],"220":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000017]"],"221":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000018]"],"222":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000019]"],"223":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001A]"],"224":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001B]"],"225":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001C]"],"226":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001D]"],"227":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001E]"],"228":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-0000001F]"],"229":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000020]"],"230":["[DB=165A62FE-FB86-DC11-9876-001320DCF58D][CNT=CollectionTreeAlignableTransform][CLID=E779C6B5-3F2A-473E-B35E-6CCB345E0665][TECH=00000202][OID=00000003-00000021]"]},"folder_payloadspec":[{"PoolRef":"String4k"}],"iov":0,"iov_obj":[0,0],"name":"IndetAlign-IndetAlign_cscalign_00","node_description":"<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1170039409\" /></addrHeader><typeName>AlignableTransformContainer</typeName>"} \ No newline at end of file diff --git a/Database/CrestApi/data/layout.json b/Database/CrestApi/data/layout.json deleted file mode 100644 index 17481bdc191f58c3c617ebff0292051654298a64..0000000000000000000000000000000000000000 --- a/Database/CrestApi/data/layout.json +++ /dev/null @@ -1 +0,0 @@ - {"name":"test_MvG4","timeType":"time","synchronization":"none","description":"none","lastValidatedTime":"0","endOfValidity":"0","insertionTime":"2018-12-06T11:18:35.641+0000","modificationTime":"2018-12-06T11:18:35.641+0000","payloadSpec":"stave: Int32, eta: Int32, mag: Float, base: Float, free: Float"} \ No newline at end of file diff --git a/Database/CrestApi/data/test-01.txt b/Database/CrestApi/data/test-01.txt deleted file mode 100644 index f079749c42ffdcc5f52ed2d3a6f15b09307e975e..0000000000000000000000000000000000000000 --- a/Database/CrestApi/data/test-01.txt +++ /dev/null @@ -1 +0,0 @@ -test1 \ No newline at end of file diff --git a/Database/CrestApi/data/test-02.txt b/Database/CrestApi/data/test-02.txt deleted file mode 100644 index d606037cb232bfda7788a8322492312d55b2ae9d..0000000000000000000000000000000000000000 --- a/Database/CrestApi/data/test-02.txt +++ /dev/null @@ -1 +0,0 @@ -test2 \ No newline at end of file diff --git a/Database/CrestApi/data/test-03.txt b/Database/CrestApi/data/test-03.txt deleted file mode 100644 index 8f06323f5b2b653a49b09ae45089210423464ab2..0000000000000000000000000000000000000000 --- a/Database/CrestApi/data/test-03.txt +++ /dev/null @@ -1,3 +0,0 @@ -test1 -test2 -test3 \ No newline at end of file diff --git a/Database/CrestApi/scripts/111-create-global-tag.sh b/Database/CrestApi/scripts/111-create-global-tag.sh deleted file mode 100644 index 96eb0c001806337d90d0ece48c5aef2d3c2c39d0..0000000000000000000000000000000000000000 --- a/Database/CrestApi/scripts/111-create-global-tag.sh +++ /dev/null @@ -1 +0,0 @@ -curl --header "Content-Type: application/json" --request POST --data '{"name":"MVG_TEST","validity":0,"description":"test","release":"1","insertionTime":"2018-12-18T11:32:58.081+0000","snapshotTime":"2018-12-18T11:32:57.952+0000","scenario":"test","workflow":"M","type":"t","snapshotTimeMilli":null,"insertionTimeMilli":null}' http://mvg-test-pc-03.cern.ch:8090/crestapi/globaltags \ No newline at end of file diff --git a/Database/CrestApi/scripts/777-create-my-tag.sh b/Database/CrestApi/scripts/777-create-my-tag.sh deleted file mode 100644 index 94e45d969d852a0ca5c8ff1708e3f936ce2ff178..0000000000000000000000000000000000000000 --- a/Database/CrestApi/scripts/777-create-my-tag.sh +++ /dev/null @@ -1 +0,0 @@ -curl --header "Content-Type: application/json" --request POST --data '{"name":"test_MvG2","timeType":"time","synchronization":"none","description":"none","lastValidatedTime":0,"endOfValidity":0,"insertionTime":"2018-12-06T11:18:35.641+0000","modificationTime":"2018-12-06T11:18:35.641+0000","payloadSpec":"stave: Int32, eta: Int32, mag: Float, base: Float, free: Float"}]' http://mvg-test-pc-03.cern.ch:8090/crestapi/tags \ No newline at end of file diff --git a/Database/CrestApi/scripts/888-create-my-tag.sh b/Database/CrestApi/scripts/888-create-my-tag.sh deleted file mode 100644 index 438d4ec701e0f5d4de0f29c7d81c0f6dbe3c9c15..0000000000000000000000000000000000000000 --- a/Database/CrestApi/scripts/888-create-my-tag.sh +++ /dev/null @@ -1 +0,0 @@ -curl --header "Content-Type: application/json" --request POST --data '{"name":"test_MvG3","timeType":"time","synchronization":"none","description":"none","lastValidatedTime":0,"endOfValidity":0,"insertionTime":"2018-12-06T11:18:35.641+0000","modificationTime":"2018-12-06T11:18:35.641+0000","payloadSpec":"stave: Int32, eta: Int32, mag: Float, base: Float, free: Float"}]' http://mvg-test-pc-03.cern.ch:8090/crestapi/tags \ No newline at end of file diff --git a/Database/CrestApi/scripts/999-create-my-tag.sh b/Database/CrestApi/scripts/999-create-my-tag.sh deleted file mode 100644 index 7865baebec1bd2250c724e330f6f9ffeb1985e9c..0000000000000000000000000000000000000000 --- a/Database/CrestApi/scripts/999-create-my-tag.sh +++ /dev/null @@ -1 +0,0 @@ -curl --header "Content-Type: application/json" --request POST --data '{"name":"test_MvG4","timeType":"time","synchronization":"none","description":"none","lastValidatedTime":0,"endOfValidity":0,"insertionTime":"2018-12-06T11:18:35.641+0000","modificationTime":"2018-12-06T11:18:35.641+0000","payloadSpec":"stave: Int32, eta: Int32, mag: Float, base: Float, free: Float"}]' http://mvg-test-pc-03.cern.ch:8090/crestapi/tags \ No newline at end of file diff --git a/Database/CrestApi/src/CrestApi.cxx b/Database/CrestApi/src/CrestApi.cxx deleted file mode 100644 index 91e45d5d5162b3b8bf67ad7b3ee70c6d466a1f73..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestApi.cxx +++ /dev/null @@ -1,805 +0,0 @@ -/* - Copyright (C) 2020-2024 CERN for the benefit of the ATLAS collaboration -*/ - -#include <CrestApi/CrestApi.h> -#include <CrestApi/CrestRequest.h> -#include <CrestApi/CrestModel.h> - -#include <boost/uuid/uuid.hpp> // uuid class -#include <boost/uuid/uuid_generators.hpp> // generators -#include <boost/uuid/uuid_io.hpp> -#include <boost/asio.hpp> - -#include <fstream> -#include <filesystem> -#include <iostream> -#include <sstream> - -#include <CrestApi/picosha2.h> - -#include <cstdio> -#include <ctime> -#include <cstdlib> - -namespace Crest -{ - - /** - * CrestClient constructor for Internet mode. If CrestClient is created with this method the data will be sent to the - * CREST Server. - * @param _host - host name of the CREST Server. - * @param _port - port of the CREST Server. - * @param check_version - the parameter to switch CREST version checking, if this parameter is true, - * the CREST version test will be executed. - */ - CrestClient::CrestClient(const std::string &_host, const std::string &_port, bool check_version) : m_host(_host), m_port(_port) - { - if (check_version == true) - { - checkCrestVersion(); - } - m_request.setHost(m_host); - m_request.setPort(m_port); - m_request.setPrefix(m_prefix); - } - - /** - * CrestClient constructor for Internet mode. If CrestClient is created with this method the data will be sent to the - * CREST Server. - * @param url - URL address of the CREST Server (with port). - * @param check_version - the parameter to switch CREST version checking, if this parameter is true, - * the CREST version test will be executed. - * <br> <br> - * Example: - * <br> - * <pre> - * std::string url = "http://mvg-test-pc-03.cern.ch:8090"; - * CrestClient myCrestClient = CrestClient(url); - * </pre> - */ - CrestClient::CrestClient(std::string_view url, bool check_version) - { - size_t found = url.find_first_of(':'); - size_t n = url.size(); - - std::string_view url_new = url.substr(found + 3); // url_new is the url excluding the http part - m_prefix = url.substr(0,found + 3); // URL prefix "http://" or "https://" - - size_t found1 = url_new.find_first_of(':'); - size_t found2 = url_new.find_first_of('/'); - - std::string_view host; - std::string_view port; - std::string_view resources; - if (found1 != std::string::npos && found2 != std::string::npos) { - host = url_new.substr(0, found1); - port = url_new.substr(found1 + 1, found2 - found1 - 1); - } else if (found1 != std::string::npos) { - host = url_new.substr(0, found1); - port = url_new.substr(found1 + 1); - } else if (found2 != std::string::npos) { - if (m_prefix == "https://") { - port = "443"; - } - else port = "80"; - host = url_new.substr(0, found2); - } else { - if (m_prefix == "https://") { - port = "443"; - } - else port = "80"; - host = url_new; - } - - if (found2 < n - 1) - { - resources = url_new.substr(found2, n - 1); - m_PATH = resources; - } - - m_port = std::string(port); - m_host = std::string(host); - m_request.setHost(m_host); - m_request.setPort(m_port); - m_request.setPrefix(m_prefix); - - if (check_version == true) - { - checkCrestVersion(); - } - std::cout << "CrestClient::CrestClient: host = " << m_host << ", port = " << m_port << ", path = " << m_PATH << std::endl; - } - - /** - * CrestClient destructor. - */ - CrestClient::~CrestClient() {} - - - // The auxillary method to remove XML/HTML tags from a std::string - std::string CrestClient::parseXMLOutput(const std::string_view xmlBuffer) const - { - bool copy = true; - - std::string plainString = ""; - - // remove all xml tags - for (long unsigned int i = 0; i < xmlBuffer.length(); i++) - { - char convertc = xmlBuffer[i]; - - if (convertc == '<') - copy = false; - else if (convertc == '>') - { - copy = true; - continue; - } - - if (copy) - plainString += convertc; - } - - return plainString; - } - - - // The auxillary method to remove carridge returns from a std::string - std::string CrestClient::removeCR(const std::string &str) const - { - std::string str2 = str; - std::replace(str2.begin(), str2.end(), '\n', '|'); - char needle = '\r'; - size_t pos; - while ((pos = str2.find(needle)) != str2.npos) - { - str2.erase(pos, 1); - } - return str2; - } - - - /** - * CrestClient::getJson method is used to convert the string to the json object. - * @param str - string to be converted to the json object. - * @param method - name of the method which calls this method. - * @return json object. - */ - nlohmann::json CrestClient::getJson(const std::string &str, const char *method) const - { - nlohmann::json js = nullptr; - try - { - js = nlohmann::json::parse(str); - } - catch (nlohmann::json::parse_error &e) - { - if (method == nullptr || *method == '\0') - { - // method name is undefined - - std::string wh = e.what(); - throw CrestException("ERROR in JSON conversion: " + wh + " | In string: " + str); - } - else - { - std::string str2 = parseXMLOutput(str); // to remove HTML tags use this function - std::string str3 = removeCR(str2); // to remove carridge return - throw CrestException("ERROR in " + std::string(method) + " | CREST Server response : " + str3); - } - } - catch (const std::exception &e) - { - throw CrestException("ERROR in CrestClient::" + (std::string)method + ": " + e.what()); - } - return js; - } - - nlohmann::json CrestClient::getMgmtInfo() - { - const char *method_name = "getMgmtInfo"; - - std::string current_path = s_MGMT_PATH + s_MGMT_INFO_PATH; - std::string retv; - nlohmann::json js = nullptr; - - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - - nlohmann::json respond = getJson(retv, method_name); - - return respond; - } - - std::string CrestClient::getCrestVersion() - { - - std::string version = ""; - nlohmann::json buildInfo; - nlohmann::json info = getMgmtInfo(); - // The CREST Server response has the following structure: - // { "build": { "artifact": "crestdb", "name": "crest", "version": "4.0", "group": "hep.crest"} } - try - { - buildInfo = info["build"]; - version = buildInfo["version"]; - } - catch (const std::exception &e) - { - throw CrestException("ERROR in CrestClient::getCrestVersion: " + to_string(info) + " does not contain version info."); - } - return version; - } - - - int CrestClient::getMajorVersion(std::string &str) - { - int v = -1; - int n = str.find('.'); - - if (n < 1) - { - throw CrestException("ERROR in CrestClient::getMajorVersion: string \"" + str + "\" does not contain major version."); - } - - std::string vers = str.substr(0, n); - - try - { - v = std::stoi(str); - } - catch (const std::exception &e) - { - throw CrestException("ERROR in CrestClient::getMajorVersion: string \"" + str + "\" does not contain major version."); - } - - return v; - } - - void CrestClient::checkCrestVersion() - { - std::string client = getClientVersion(); - std::string server = getCrestVersion(); - - int clientVersion = getMajorVersion(client); - int serverVersion = getMajorVersion(server); - - if (clientVersion != serverVersion) - { - throw CrestException("ERROR in CrestClient::checkCrestVersion: CrestApi version \"" + client + "\" does not correspond to the server version \"" + server + "\"."); - } - } - - std::string CrestClient::makeUrl(const std::string &address) const - { - std::string str = m_prefix; - str += m_host; - str += ':'; - str += m_port; - str += address; - return str; - } - //============================================================================================================== - // GlobalTag methods: - void CrestClient::createGlobalTag(GlobalTagDto &dto) - { - const char *method_name = "CrestClient::createGlobalTag"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_PATH; - std::string retv; - nlohmann::json js = dto.to_json(); - retv = m_request.performRequest(current_path, Action::POST, js, method_name); - } - - GlobalTagDto CrestClient::findGlobalTag(const std::string &name) - { - const char *method_name = "CrestClient::findGlobalTag"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_PATH; - current_path += '/'; - current_path += name; - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - GlobalTagSetDto dto = GlobalTagSetDto::from_json(response); - std::vector<GlobalTagDto> v = dto.resources; - // Only one element is expected: - return v[0]; - } - - GlobalTagSetDto CrestClient::listGlobalTags(const std::string &name, int size, int page, const std::string &sort) - { - const char *method_name = "CrestClient::listGlobalTags"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_PATH; - current_path += '?'; - if (name != "") - { - current_path += "name="; - current_path += name; - current_path += '&'; - } - if (size != -1) - { - current_path += "size="; - current_path += std::to_string(size); - current_path += '&'; - } - if (page != -1) - { - current_path += "page="; - current_path += std::to_string(page); - current_path += '&'; - } - if (sort != "") - { - current_path += "sort="; - current_path += sort; - current_path += '&'; - } - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - GlobalTagSetDto dto = GlobalTagSetDto::from_json(response); - - return dto; - } - - // The method to remove a global tag: - void CrestClient::removeGlobalTag(const std::string &name) - { - const char *method_name = "CrestClient::removeGlobalTag"; - - std::string current_path = m_PATH; - current_path += s_ADMIN_PATH; - current_path += s_GLOBALTAG_PATH; - current_path += '/'; - current_path += name; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::DELETE, js, method_name); - } - - //============================================================================================================== - // Tag methods: - void CrestClient::createTag(TagDto &dto) - { - const char *method_name = "CrestClient::createTag"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - std::string retv; - nlohmann::json js = dto.to_json(); - retv = m_request.performRequest(current_path, Action::POST, js, method_name); - } - - // The method to find a tag: - TagDto CrestClient::findTag(const std::string &name) - { - const char *method_name = "CrestClient::findTag"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - current_path += '/'; - current_path += name; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - TagSetDto dto = TagSetDto::from_json(response); - - std::vector<TagDto> v = dto.resources; - // Only one element is expected: - return v[0]; - } - - TagSetDto CrestClient::listTags(const std::string &name, int size, int page, const std::string &sort) - { - const char *method_name = "CrestClient::listTags"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - current_path += '?'; - if (name != "") - { - current_path += "name="; - current_path += name; - current_path += '&'; - } - if (size != -1) - { - current_path += "size="; - current_path += std::to_string(size); - current_path += '&'; - } - if (page != -1) - { - current_path += "page="; - current_path += std::to_string(page); - current_path += '&'; - } - if (sort != "") - { - current_path += "sort="; - current_path += sort; - current_path += '&'; - } - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - TagSetDto dto = TagSetDto::from_json(response); - - return dto; - } - - // The method to remove a tag: - void CrestClient::removeTag(const std::string &name) - { - const char *method_name = "CrestClient::removeTag"; - - std::string current_path = m_PATH; - current_path += s_ADMIN_PATH; - current_path += s_TAG_PATH; - current_path += '/'; - current_path += name; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::DELETE, js, method_name); - } - - //============================================================================================================== - // TagMeta methods: - void CrestClient::createTagMeta(TagMetaDto &dto) - { - const char *method_name = "CrestClient::createTagMeta"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - current_path += '/'; - current_path += dto.tagName; - current_path += s_META_PATH; - - std::string retv; - nlohmann::json js = dto.to_json(); - retv = m_request.performRequest(current_path, Action::POST, js, method_name); - } - - void CrestClient::updateTagMeta(TagMetaDto &dto) - { - const char *method_name = "CrestClient::updateTagMeta"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - current_path += '/'; - current_path += dto.tagName; - current_path += s_META_PATH; - - std::string retv; - nlohmann::json js = dto.to_json(); - retv = m_request.performRequest(current_path, Action::PUT, js, method_name); - } - - TagMetaDto CrestClient::findTagMeta(const std::string &name) - { - const char *method_name = "CrestClient::findTagMeta"; - - std::string current_path = m_PATH; - current_path += s_TAG_PATH; - current_path += '/'; - current_path += name; - current_path += s_META_PATH; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - TagMetaSetDto dto = TagMetaSetDto::from_json(response); - std::vector<TagMetaDto> v = dto.resources; - // Only one element is expected: - return v[0]; - } - - - int CrestClient::getSize(const std::string &tagname) - { - const char *method_name = "CrestClient::getSize"; - - std::string current_path = m_PATH; - current_path += s_IOV_PATH; - current_path += s_IOV_SIZE_PATH; - current_path += "?tagname="; - current_path += tagname; - - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json respond = getJson(retv, method_name); - - auto res = respond.find("resources"); - nlohmann::json r; - - if (res != respond.end()) - { - r = respond["resources"][0]; - } - - int result = 0; - if (r.find("niovs") != r.end()) - { - result = r["niovs"]; - } - else - { - throw CrestException("ERROR in CrestClient::getSize CREST Server JSON response has no \"size\" key."); - } - - return result; - } - - //============================================================================================================== - // GlobalTagMaps methods: - void CrestClient::createGlobalTagMap(GlobalTagMapDto &dto) - { - const char *method_name = "CrestClient::createGlobalTagMap"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_MAP_PATH; - std::string retv; - nlohmann::json js = dto.to_json(); - retv = m_request.performRequest(current_path, Action::POST, js, method_name); - } - - GlobalTagMapSetDto CrestClient::findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) - { - const char *method_name = "CrestClient::findGlobalTagMap"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_MAP_PATH; - current_path += '/'; - current_path += name; - std::string headers_params = ""; - - if (xCrestMapMode != "") - { - headers_params += "X-Crest-MapMode: "; - headers_params += xCrestMapMode; - } - else - { - headers_params += "X-Crest-MapMode: "; - headers_params += "Trace"; - } - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name, headers_params); - nlohmann::json response = getJson(retv, method_name); - GlobalTagMapSetDto dto = GlobalTagMapSetDto::from_json(response); - - return dto; - } - - void CrestClient::removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) - { - const char *method_name = "CrestClient::removeGlobalTagMap"; - - std::string current_path = m_PATH; - current_path += s_GLOBALTAG_MAP_PATH; - current_path += '/'; - current_path += name; - current_path += '?'; - if (tagname != "") - { - current_path += "tagname="; - current_path += tagname; - current_path += '&'; - } - if (record != "") - { - current_path += "record="; - current_path += record; - current_path += '&'; - } - if (label != "") - { - current_path += "label="; - current_path += label; - current_path += '&'; - } - - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::DELETE, js, method_name); - } - - //============================================================================================================== - // Iovs methods: - IovSetDto CrestClient::selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) - { - const char *method_name = "CrestClient::selectIovs"; - - std::string current_path = m_PATH; - current_path += s_IOV_PATH; - - current_path += "?method="; - current_path += s_METHOD_IOVS; - current_path += "&tagname="; - - current_path += name; - current_path += "&since="; - current_path += std::to_string(since); - current_path += "&until="; - if (until == static_cast<uint64_t>(-1)) - { - current_path += "INF"; - } - else - { - current_path += std::to_string(until); - } - current_path += "&snapshot="; - current_path += std::to_string(snapshot); - // - current_path += "&size="; - current_path += std::to_string(size); - current_path += "&page="; - current_path += std::to_string(page); - current_path += "&sort="; - current_path += sort; - // - - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - IovSetDto dto = IovSetDto::from_json(response); - - return dto; - } - - IovSetDto CrestClient::selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) - { - const char *method_name = "CrestClient::selectGroups"; - - std::string current_path = m_PATH; - current_path += s_IOV_PATH; - - current_path += "?method="; - current_path += s_METHOD_GROUPS; - current_path += "&tagname="; - - current_path += name; - current_path += "&snapshot="; - current_path += std::to_string(snapshot); - - // - current_path += "&size="; - current_path += std::to_string(size); - current_path += "&page="; - current_path += std::to_string(page); - current_path += "&sort="; - current_path += sort; - // - - std::string retv; - - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - IovSetDto dto = IovSetDto::from_json(response); - - return dto; - } - - //============================================================================================================== - // Payload methods: - void CrestClient::storeData(const std::string &tag, - const StoreSetDto &storeSetJson, - const std::string &payloadFormat, - const std::string &objectType, - const std::string &compressionType, - const std::string &version, - uint64_t endTime) - { - - std::string current_path = m_PATH; - current_path += s_PAYLOAD_PATH; - std::vector<std::string> files; - std::string retv; - nlohmann::json js = storeSetJson.to_json(); - if (payloadFormat == "JSON") - { - retv = m_request.uploadPayload(current_path, tag, endTime, js, objectType, compressionType, version, files); - } - else - { - // Assumes the data content in the JSON is just a file path. - nlohmann::json resources = nullptr; - - auto subjectIdIter1 = js.find("resources"); - if (subjectIdIter1 != js.end()) - { - resources = js["resources"]; - } - int partN = resources.size(); - for (int i = 0; i < partN; i++) - { - nlohmann::json element = resources[i]; - std::string file_param; - - auto subjectIdIter1 = element.find("data"); - if (subjectIdIter1 != element.end()) - { - file_param = element["data"]; - } - // - int found_dots = file_param.find_first_of(':'); - int word_size = file_param.size(); - std::string data_file = file_param.substr(found_dots + 3, word_size); - files.push_back(data_file); - } - retv = m_request.uploadPayload(current_path, tag, endTime, js, objectType, compressionType, version, files); - } - } - - std::string CrestClient::getPayload(const std::string &hash) - { - const char *method_name = "CrestClient::getPayload"; - - std::string current_path = m_PATH; - current_path += s_PAYLOAD_PATH; - current_path += "/data?format=BLOB&hash="; - current_path += hash; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - checkHash(hash, retv, method_name); - return retv; - } - - PayloadDto CrestClient::getPayloadMeta(const std::string &hash) - { - const char *method_name = "CrestClient::getPayloadMeta"; - - std::string current_path = m_PATH; - current_path += s_PAYLOAD_PATH; - current_path += '/'; - current_path += hash; - current_path += "?format=META"; - std::string retv; - nlohmann::json js = nullptr; - retv = m_request.performRequest(current_path, Action::GET, js, method_name); - nlohmann::json response = getJson(retv, method_name); - - PayloadSetDto dto = PayloadSetDto::from_json(response); - std::vector<PayloadDto> v = dto.resources; - // Only one element is expected: - return v[0]; - } - - void CrestClient::checkHash(const std::string &hash, const std::string &str, const char* method_name) - { - std::string calculatedHash = getHash(str); - if (hash != calculatedHash) { - throw CrestException("ERROR in " + (std::string)method_name + ": payload is corrupted."); - } - return; - } - -} // namespace Crest - diff --git a/Database/CrestApi/src/CrestApiBase.cxx b/Database/CrestApi/src/CrestApiBase.cxx deleted file mode 100644 index 14a7e473f154cacf6a431246d2e158d85fe0e9ec..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestApiBase.cxx +++ /dev/null @@ -1,43 +0,0 @@ -#include <CrestApi/picosha2.h> -#include <iostream> -#include <CrestApi/CrestApiBase.h> - -namespace Crest -{ - - std::string CrestApiBase::getHashForFile(const std::string &file) - { - std::ifstream ifs(file); - if (!ifs) - { - throw CrestException( - "ERROR in CrestFsClient::getHashForFile cannot open file \"" + file + "\"."); - } - - picosha2::hash256_one_by_one hasher; - std::vector<char> buffer(1024 * 1024); // use 1M memory - while (ifs.read(buffer.data(), static_cast<std::streamsize>(buffer.size()))) - { - std::cout << "#" << std::flush; - hasher.process(buffer.begin(), buffer.end()); - } - // process remains - hasher.process(buffer.begin(), buffer.begin() + static_cast<int>(ifs.gcount())); - hasher.finish(); - - std::string hash = picosha2::get_hash_hex_string(hasher); - return hash; - } - - std::string CrestApiBase::getHash(std::string_view str) - { - std::string hash_hex_str = picosha2::hash256_hex_string(str.begin(), str.end()); - return hash_hex_str; - } - - const std::string& CrestApiBase::getClientVersion() - { - return s_CREST_CLIENT_VERSION; - } - -} // namespace Crest diff --git a/Database/CrestApi/src/CrestApiFs.cxx b/Database/CrestApi/src/CrestApiFs.cxx deleted file mode 100644 index 30b4256d80e4cb23910dbc7dcc896da08e3387e5..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestApiFs.cxx +++ /dev/null @@ -1,1117 +0,0 @@ -/* - Copyright (C) 2020-2025 CERN for the benefit of the ATLAS collaboration -*/ - -#include <CrestApi/CrestApiFs.h> -#include <CrestApi/CrestRequest.h> -#include <CrestApi/CrestModel.h> - -#include <boost/uuid/uuid.hpp> // uuid class -#include <boost/uuid/uuid_generators.hpp> // generators -#include <boost/uuid/uuid_io.hpp> -#include <boost/asio.hpp> - -#include <fstream> -#include <filesystem> -#include <iostream> - -#include <CrestApi/picosha2.h> - -#include <cstdio> -#include <ctime> -#include <cstdlib> - -#include <algorithm> - -namespace Crest -{ - - /** - * CrestFsClient constructor for Internet mode. If CrestClient is created with this method the data will be sent to the - * CREST Server. - * @param rewriteIfExists - Boolean flag to reinitialize the file system. - * @param root_folder - root directory of the CREST storage. - */ - CrestFsClient::CrestFsClient(bool rewriteIfExists, const std::string &root_folder) - : m_root_folder(root_folder), m_isRewrite(rewriteIfExists) - { - if (m_root_folder == "") { - m_root_folder = std::filesystem::current_path(); - m_root_folder += "/crest"; - } - if (!std::filesystem::exists(std::filesystem::path(m_root_folder))) - { - std::filesystem::create_directory(std::filesystem::path(m_root_folder)); - } - m_data_folder = m_root_folder + "/data"; - if (!std::filesystem::exists(std::filesystem::path(m_data_folder))) - { - std::filesystem::create_directory(std::filesystem::path(m_data_folder)); - } - } - - /** - * CrestClient destructor. - */ - CrestFsClient::~CrestFsClient() {} - - // UTILITIES Methods - - std::string CrestFsClient::getFileString(const std::string& path) { - std::ifstream ifs(path); - std::stringstream buf; - buf << ifs.rdbuf(); - return buf.str(); - } - - std::string CrestFsClient::buildPath(const std::string &path, const std::string &name) - { - std::string p = m_root_folder; - if (!std::filesystem::exists(std::filesystem::path(m_root_folder))) - { - std::filesystem::create_directory(std::filesystem::path(m_root_folder)); - } - p += path; - if (!std::filesystem::exists(std::filesystem::path(p))) - { - std::filesystem::create_directory(std::filesystem::path(p)); - } - p += '/'; - p += name; - if (!std::filesystem::exists(std::filesystem::path(p))) - { - std::filesystem::create_directory(std::filesystem::path(p)); - } - return p; - } - - void CrestFsClient::getFileList(const std::string &path) - { - std::filesystem::path p(path); - for (auto i = std::filesystem::directory_iterator(p); i != std::filesystem::directory_iterator(); i++) - { - std::string file = i->path().filename().string(); - if (file != "data") - { - std::cout << file << std::endl; - } - else{ - continue; - } - } - } - - // Global tag methods: - - void CrestFsClient::createGlobalTag(GlobalTagDto &globalTag) - { - std::string name = ""; - if (globalTag.name != "") - { - name = globalTag.name; - } - else - { - throw CrestException("ERROR in CrestFsClient::createGlobalTag: global tag name is not set."); - } - - std::string workDir = buildPath(s_FS_GLOBALTAG_PATH, name); - std::string globalTagFile = workDir + s_FS_GLOBALTAG_FILE; - - if (m_isRewrite) - { - if (std::filesystem::exists(std::filesystem::path(globalTagFile))) - { - std::filesystem::remove(std::filesystem::path(globalTagFile)); - } - - std::ofstream outFile; - - outFile.open(globalTagFile.c_str()); - outFile << globalTag.to_json(); - outFile.close(); - } - - return; - } - - GlobalTagDto CrestFsClient::findGlobalTag(const std::string &name) - { - nlohmann::json js = nullptr; - GlobalTagDto dto; - - std::string workDir = buildPath(s_FS_GLOBALTAG_PATH, name); - std::string file_path = workDir + s_FS_GLOBALTAG_FILE; - - try - { - std::string tag = getFileString(file_path); - js = nlohmann::json::parse(tag); - dto = GlobalTagDto::from_json(js); - } - catch (...) - { - throw CrestException( - "ERROR in CrestFsClient::findGlobalTag: cannot get the global tag " + name + " form the file storage."); - } - - return dto; - } - - void CrestFsClient::removeGlobalTag(const std::string &) - { - checkFsException("CrestFsClient::removeGlobalTag"); - } - - GlobalTagSetDto CrestFsClient::listGlobalTags(const std::string &name, int size, int page, const std::string &sort) - { - - std::string folder = m_root_folder + s_FS_GLOBALTAG_PATH; - - GlobalTagSetDto tagSet; - - bool ascending = true; - if (sort == "name:ASC") - { - ascending = true; - } - else if (sort == "name:DESC") - { - ascending = false; - } - else - { - throw CrestException( - "ERROR in CrestFsClient::listTags: wrong sort parameter." + sort); - } - - try - { - std::vector<std::string> taglist = nameList(folder, ascending); - std::vector<std::string> clearedTaglist; - - for (const std::string& tag : taglist) - { - std::string file_name = folder + "/" + tag + "/" + s_FS_GLOBALTAG_FILE; - - if (std::filesystem::exists(file_name)) - { - if (name != "") - { - if (isMatch(tag, name)) - { - clearedTaglist.push_back(tag); - } - } - else - { - clearedTaglist.push_back(tag); - } - } - } - - taglist = getVectorPage(clearedTaglist, size, page); - for (const std::string& tag : taglist) - { - std::string file_name = folder + "/" + tag + "/" + s_FS_GLOBALTAG_FILE; - GlobalTagDto dto = findGlobalTag(tag); - tagSet.resources.push_back(dto); - } - tagSet.datatype = ""; - } - catch (const std::exception &e) - { - throw CrestException( - "ERROR in CrestFsClient::listGlobalTags: cannot get the tag list."); - } - - return tagSet; - } - - // Tag methods: - - void CrestFsClient::createTag(TagDto &tag) - { - std::string name = tag.name; - std::string workDir = buildPath(s_FS_TAG_PATH, name); - - if (name.compare(m_currentTag) != 0 && m_isRewrite) - { - flush(); - } - m_currentTag = name; - std::string tagFile = workDir + s_FS_TAG_FILE; - std::string iovFile = workDir + s_FS_IOV_FILE; - - if (m_isRewrite) - { - if (std::filesystem::exists(std::filesystem::path(tagFile))) - { - std::filesystem::remove(std::filesystem::path(tagFile)); - } - if (std::filesystem::exists(std::filesystem::path(iovFile))) - { - std::filesystem::remove(std::filesystem::path(iovFile)); - } - std::ofstream outFile; - outFile.open(tagFile.c_str()); - outFile << tag.to_json(); - outFile.close(); - } - if (m_data.find(name) == m_data.end()) - { - m_data.insert(std::pair<std::string, nlohmann::json>(name, nlohmann::json(nlohmann::json::value_t::array))); - } - } - - TagDto CrestFsClient::findTag(const std::string &name) - { - nlohmann::json js = nullptr; - TagDto dto; - - std::string workDir = buildPath(s_FS_TAG_PATH, name); - std::string file_path = workDir + s_FS_TAG_FILE; - - try - { - std::string tag = getFileString(file_path); - js = nlohmann::json::parse(tag); - dto = TagDto::from_json(js); - } - catch (...) - { - throw CrestException( - "ERROR in CrestFsClient::findTag: cannot get the tag " + name + " form the file storage."); - } - - return dto; - } - - void CrestFsClient::removeTag(const std::string &) - { - checkFsException("CrestFsClient::removeTag"); - } - - TagSetDto CrestFsClient::listTags(const std::string &name, int size, int page, const std::string &sort) - { - - std::string folder = m_root_folder + s_FS_TAG_PATH; - - TagSetDto tagSet; - - bool ascending = true; - if (sort == "name:ASC") - { - ascending = true; - } - else if (sort == "name:DESC") - { - ascending = false; - } - else - { - throw CrestException( - "ERROR in CrestFsClient::listTags: wrong sort parameter." + sort); - } - - try - { - std::vector<std::string> taglist = nameList(folder, ascending); - std::vector<std::string> clearedTaglist; - - for (const std::string& tag : taglist) - { - std::string file_name = folder + "/" + tag + "/" + s_FS_TAG_FILE; - - if (std::filesystem::exists(file_name)) - { - if (name != "") - { - if (isMatch(tag, name)) - { - clearedTaglist.push_back(tag); - } - } - else - { - clearedTaglist.push_back(tag); - } - } - } - - taglist = getVectorPage(clearedTaglist, size, page); - for (const std::string& tag : taglist) - { - std::string file_name = folder + "/" + tag + "/" + s_FS_TAG_FILE; - TagDto dto = findTag(tag); - tagSet.resources.push_back(dto); - } - tagSet.datatype = ""; - } - catch (const std::exception &e) - { - throw CrestException( - "ERROR in CrestFsClient::listTags: cannot get the tag list."); - } - - return tagSet; - } - - void CrestFsClient::flush() - { - - for (auto &item : m_data) - { - nlohmann::json iov = item.second; - std::string name = item.first; - std::string workDir = m_root_folder + s_FS_TAG_PATH + '/' + name; - std::ofstream outFile; - std::string tagFile = workDir + s_FS_IOV_FILE; - outFile.open(tagFile.c_str()); - outFile << iov; - outFile.close(); - } - - m_data.clear(); - } - - // TagMeta methods - void CrestFsClient::createTagMeta(TagMetaDto &tag) - { - std::string name = tag.tagName; - - std::string workDir = buildPath(s_FS_TAG_PATH, name); - std::string tagMetaFile = workDir + s_FS_TAGMETAINFO_FILE; - - if (m_isRewrite) - { - if (std::filesystem::exists(std::filesystem::path(tagMetaFile))) - { - std::filesystem::remove(std::filesystem::path(tagMetaFile)); - } - - std::ofstream outFile; - - outFile.open(tagMetaFile.c_str()); - outFile << tag.to_json(); - outFile.close(); - } - } - - void CrestFsClient::updateTagMeta(TagMetaDto &) - { - checkFsException("CrestFsClient::updateTagMeta"); - } - - TagMetaDto CrestFsClient::findTagMeta(const std::string &name) - { - nlohmann::json js = nullptr; - TagMetaDto dto; - - std::string workDir = buildPath(s_FS_TAG_PATH, name); - std::string file_path = workDir + s_FS_TAGMETAINFO_FILE; - - try - { - std::string tag = getFileString(file_path); - js = nlohmann::json::parse(tag); - dto = TagMetaDto::from_json(js); - } - catch (...) - { - throw CrestException( - "ERROR in CrestFsClient::findTagMeta: cannot get the tag " + name + " form the file storage."); - } - - return dto; - } - - // GlobalTagMap methods - - void CrestFsClient::createGlobalTagMap(GlobalTagMapDto &globalTagMap) - { - nlohmann::json js = globalTagMap.to_json(); - - // global tag name: - std::string name = ""; - try - { - name = static_cast<std::string>(js["globalTagName"]); - } - catch (...) - { - throw CrestException("ERROR in CrestClient::createGlobalTagMap: cannot get the global tag name from JSON."); - } - - // tag name: - std::string tagname = ""; - try - { - tagname = static_cast<std::string>(js["tagName"]); - } - catch (...) - { - throw CrestException("ERROR in CrestClient::createGlobalTagMap: cannot get the tag name from JSON."); - } - - std::string workDir = buildPath(s_FS_GLOBALTAG_PATH, name); - std::string catalogFile = workDir + s_FS_MAP_FILE; - - if (std::filesystem::exists(std::filesystem::path(catalogFile))) - { - // cathalogue file exists: - - std::string array_lst = getFileString(catalogFile); - - nlohmann::json cathalogue; - try - { - cathalogue = nlohmann::json::parse(array_lst); - } - catch (...) - { - throw CrestException("ERROR in CrestFsClient::createGlobalTagMap: global tag map file corrupted."); - } - - if (std::filesystem::exists(std::filesystem::path(catalogFile))) - { - // the file storage contains the record of the global tag map: - int m = cathalogue.size(); - for (int i = 0; i < m; i++) - { - const std::string &tn = cathalogue[i]["tagName"]; - if (tn == tagname) - { - cathalogue.erase(i); - } - } - } - else - { - // the file storage does not contain the record of the global tag map: - } - std::filesystem::remove(std::filesystem::path(catalogFile)); - cathalogue.push_back(js); - std::ofstream outFile; - - outFile.open(catalogFile.c_str()); - outFile << cathalogue; - outFile.close(); - } - else - { - // cathalogue file does not exist (creation): - - nlohmann::json cathalogue = nlohmann::json::array(); - cathalogue.push_back(js); - - std::ofstream outFile; - - outFile.open(catalogFile.c_str()); - outFile << cathalogue; - outFile.close(); - } - - return; - } - - void CrestFsClient::removeGlobalTagMap(const std::string &, const std::string &, const std::string &, const std::string &) - { - checkFsException("CrestFsClient::removeGlobalTagMap"); - } - - void CrestFsClient::checkFsException(const char *method_name) - { - throw CrestException("ERROR in " + std::string(method_name) + " This methods is unsupported for FILESYSTEM mode"); - } - - GlobalTagMapSetDto CrestFsClient::findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) - { - - nlohmann::json js = nullptr; - - if (xCrestMapMode != "Trace") - { - throw CrestException( - "ERROR in CrestFsClient::getGlobalTagMap: not supported value for the parameter xCrestMapMode = " + xCrestMapMode); - } - - std::string workDir = m_root_folder + s_FS_GLOBALTAG_PATH; - workDir += '/'; - workDir += name; - workDir += s_FS_MAP_FILE; - - try - { - std::string tag = getFileString(workDir); - js = nlohmann::json::parse(tag); - } - catch (...) - { - throw CrestException( - "ERROR in CrestFsClient::getGlobalTagMap: cannot get the global tag map " + name + - " form the file storage."); - } - - GlobalTagMapSetDto dto; - dto = GlobalTagMapSetDto::from_fs_json(js); - return dto; - } - - // Iovs methods - - IovSetDto CrestFsClient::selectIovs(const std::string &name, uint64_t since, uint64_t until, long , int size, int page, const std::string &sort) - { - IovSetDto dto; - - nlohmann::json js = nlohmann::json::array(); - - try - { - nlohmann::json iovList = findAllIovs(name); - int niovs = iovList.size(); - - for (int i = 0; i < niovs; i++) - { - if (iovList[i].find("since") != iovList[i].end()) - { - uint64_t currentS = iovList[i]["since"]; - - if (until != static_cast<uint64_t>(-1)) - { - if (currentS >= since && currentS <= until) - { - js.push_back(iovList[i]); - } - } - else - { // until == -1, Infinity - if (currentS >= since) - { - js.push_back(iovList[i]); - } - } // until == -1 - } - } // for - } - catch (...) - { - throw CrestException("ERROR in CrestClient::selectIovsFS : cannot get the iov list form file storage"); - } - - bool ascending = true; - if (sort == "id.since:ASC") - ascending = true; - else if (sort == "id.since:DESC") - ascending = false; - else - { - throw CrestException( - "ERROR in CrestFsClient::selectIovs: wrong sort parameter." + sort); - } - - nlohmann::json sorted = sortIOVJson(std::move(js), ascending); - nlohmann::json ext = getPage(std::move(sorted), size, page); - dto = IovSetDto::from_fs_json(ext); - - return dto; - } - - nlohmann::json CrestFsClient::findAllIovs(const std::string &tagname) - { - nlohmann::json js = nullptr; - std::string file_path = m_root_folder; - file_path += '/'; - file_path += s_FS_TAG_PATH; - file_path += '/'; - file_path += tagname; - file_path += s_FS_IOV_FILE; - - try - { - std::string tag = getFileString(file_path); - js = nlohmann::json::parse(tag); - } - catch (const std::exception &e) - { - throw CrestException("ERROR in CrestFsClient::findAllIovs : cannot get the iov information form file storage "); - } - - return js; - } - - int CrestFsClient::getSize(const std::string &tagname) - { - int res = 0; - - try - { - nlohmann::json iovs = findAllIovs(tagname); - int length = iovs.size(); - return length; - } - catch (...) - { - return res; - } - - return res; - } - - IovSetDto CrestFsClient::selectGroups(const std::string &, long , int , int , const std::string &) - { - checkFsException("CrestFsClient::selectGroups"); - return IovSetDto(); - } - - // Payload methods - void CrestFsClient::storeData(const std::string &tag, - const StoreSetDto &storeSetJson, - const std::string &payloadFormat, - const std::string &objectType, - const std::string &compressionType, - const std::string &version, - uint64_t) - { - std::string name = tag; - - std::string workDir = buildPath(s_FS_TAG_PATH, name); - std::string tagFile = workDir + s_FS_TAG_FILE; - std::string iovFile = workDir + s_FS_IOV_FILE; - - nlohmann::json js_data = storeSetJson.to_json(); - - nlohmann::json res; - auto it = js_data.find("resources"); - if (it != js_data.end()) - { - res = js_data["resources"]; - } - - try - { - for (auto &kvp : res) - { - std::string payload = kvp.value("data", ""); - int since = kvp.value("since", 0); - std::string streamer = kvp.value("streamerInfo", ""); - // Register everything on the file system. - storePayloadDump(tag, since, payload, payloadFormat, - objectType, compressionType, version, streamer); - } - } // end of try - catch (...) - { - throw CrestException("ERROR in CrestFsClient::storeData cannot store the data in a file"); - } // end of catch - flush(); - } - - std::string CrestFsClient::getDateAndTime() - { - time_t now = time(0); - struct tm tstruct; - char buf[80]; - - localtime_r(&now, &tstruct); - strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct); - return buf; - } - - std::string CrestFsClient::getFirstLetters(const std::string &str) - { - std::string result = str.substr(0, s_FS_PREFIX_LENGTH); - return result; - } - - void CrestFsClient::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) - { - - std::ofstream outFile; - - std::string hashCode; - std::string payloadLocalFile; - - // payload file: - if (payloadFormat == "JSON") - { - hashCode = getHash(js); - } - else - { - - int found_dots = js.find_first_of(':'); - int word_size = js.size(); - payloadLocalFile = js.substr(found_dots + 3, word_size); - - hashCode = getHashForFile(payloadLocalFile); - } - - std::string workDir = m_data_folder; - workDir += '/'; - workDir += getFirstLetters(hashCode); - if (!std::filesystem::exists(std::filesystem::path(workDir))) - { - std::filesystem::create_directory(std::filesystem::path(workDir)); - } - workDir += '/'; - workDir += hashCode; - if (!std::filesystem::exists(std::filesystem::path(workDir))) - { - std::filesystem::create_directory(std::filesystem::path(workDir)); - } - std::string tagFile = workDir + "/payload.json"; - - if (payloadFormat == "JSON") - { - outFile.open(tagFile); - outFile << js; - outFile.close(); - } - else - { - try - { - std::filesystem::copy_file(payloadLocalFile, tagFile); - } - catch (std::filesystem::filesystem_error &e) - { - throw CrestException("ERROR in CrestFsClient::storePayloadDump cannot not save payload file: " + tagFile + e.what()); - } - } - - // Define the meta info for the payload: - nlohmann::json jsn = - { - {"hash", hashCode}, - {"checkSum", "SHA-256"}, - {"objectType", objectType}, - {"version", version}, - {"size", js.size()}, - {"streamerInfo", streamerInfo}, - {"compressionType", compressionType}, - {"insertionTime", getDateAndTime()}}; - - // payload meta info file: - std::string metaFile = workDir + "/meta.json"; - - outFile.open(metaFile); - outFile << jsn.dump(); - outFile.close(); - - // check if data exists - - if (m_data.find(tag) == m_data.end()) - { - try - { - nlohmann::json jsi = findAllIovs(tag); - m_data.insert(std::pair<std::string, nlohmann::json>(tag, jsi)); - } - catch (...) - { - try - { // tag exists, but there are no IOVs - nlohmann::json tagJS = findTag(tag).to_json(); - nlohmann::json jsFree = nlohmann::json::array({}); - m_data.insert(std::pair<std::string, nlohmann::json>(tag, jsFree)); - } - catch (...) - { - throw CrestException( - "ERROR in CrestFsClient::storePayloadDump cannot get data for tag \"" + tag + "\" from file storage."); - } - } - } - - std::map<std::string, nlohmann::json>::iterator it = m_data.find(tag); - if (it != m_data.end()) - { - std::string link = std::move(hashCode); - nlohmann::json iovs = it->second; - nlohmann::json obj(nlohmann::json::value_t::object); - obj["tagName"] = tag; - obj["since"] = since; - obj["insertionTime"] = getDateAndTime(); - obj["payloadHash"] = link; - iovs.push_back(obj); - m_data[it->first] = std::move(iovs); - } - } - - - // Payload methods - - std::string CrestFsClient::getPayload(const std::string &hash) - { - std::string workDir = m_data_folder; - workDir += '/'; - workDir += getFirstLetters(hash); - workDir += '/'; - workDir += hash; - std::string filePath = workDir + "/payload.json"; - std::string res = ""; - - try - { - if (std::filesystem::exists(filePath)) - { - res = getFileString(filePath); - } - else - { - throw CrestException("payload with hash " + hash + " does not exist."); - } - } - catch (const std::exception &e) - { - std::string message = e.what(); - throw CrestException("ERROR in CrestFsClient::getPayload cannot get the payload form file storage, " + message); - } - - return res; - } - - PayloadDto CrestFsClient::getPayloadMeta(const std::string &hash) - { - nlohmann::json js = nullptr; - PayloadDto dto; - - std::string workDir = m_data_folder; - workDir += '/'; - workDir += getFirstLetters(hash); - workDir += '/'; - workDir += hash; - - std::string filePath = std::move(workDir); - filePath += "/meta.json"; - - std::string res = ""; - - try - { - if (std::filesystem::exists(filePath)) - { - res = getFileString(filePath); - js = nlohmann::json::parse(res); - dto = PayloadDto::from_json(js); - } - else - { - throw CrestException("payload meta info with hash " + hash + " does not exist."); - } - } - catch (const std::exception &e) - { - std::string message = e.what(); - throw CrestException("ERROR in CrestClient::getPayloadMeta cannot get the payload meta info form file storage, " + message); - } - - return dto; - } - - nlohmann::json CrestFsClient::getPage(nlohmann::json data, int size, int page) - { - nlohmann::json js = nlohmann::json::array(); - int dataSize = data.size(); - - if (dataSize == 0) - return js; // the data is absent - - // index interval to load the data from JSON array: - int kmin = size * page; - int kmax = size * (page + 1); - - // check if the interval is correct: - if (kmin > dataSize - 1) - return js; // out of range - - if (kmax > dataSize - 1) - { // this step is not full - kmax = dataSize; - } - - for (int i = kmin; i < kmax; i++) - { - js.push_back(data[i]); - } - return js; - } - - std::vector<std::string> CrestFsClient::getVectorPage(const std::vector<std::string>& data, int size, int page) - { - std::vector<std::string> res; - int dataSize = data.size(); - - if (dataSize == 0) - return res; // the data is absent - - // index interval to load the data from JSON array: - int kmin = size * page; - int kmax = size * (page + 1); - - // check if the interval is correct: - if (kmin > dataSize - 1) - return res; // out of range - - if (kmax > dataSize - 1) - { // this step is not full - kmax = dataSize; - } - - for (int i = kmin; i < kmax; i++) - { - res.push_back(data[i]); - } - return res; - } - - std::vector<std::string> CrestFsClient::nameList(std::string &folder, bool ascending) - { - std::vector<std::string> tag_list; - std::filesystem::path p(folder); - - for (auto i = std::filesystem::directory_iterator(p); i != std::filesystem::directory_iterator(); i++) - { - std::string file = i->path().filename().string(); - tag_list.push_back(file); - } - - std::sort(tag_list.begin(), tag_list.end()); - - if (ascending == false) - { - std::reverse(tag_list.begin(), tag_list.end()); - } - - return tag_list; - } - - // method to sort JSON array by the key (par) value - nlohmann::json CrestFsClient::sortJson(nlohmann::json js, const std::string &par, bool order) - { - nlohmann::json respond = nlohmann::json::array(); - std::vector<std::string> parlist; - std::map<std::string, nlohmann::json> m; - - int size = js.size(); - for (int i = 0; i < size; i++) - { - nlohmann::json elem = js[i]; - - auto res = elem.find(par); - - if (res != elem.end()) - { - std::string par_val = elem[par]; - parlist.push_back(par_val); - m[par_val] = std::move(elem); - } - } - - std::sort(parlist.begin(), parlist.end()); - - if (order == false) - { - std::reverse(parlist.begin(), parlist.end()); - } - - for (std::string item : parlist) - { - respond.push_back(m[item]); - } - - return respond; - } - - // method to sort JSON array with IOVs by the since value - nlohmann::json CrestFsClient::sortIOVJson(nlohmann::json js, bool order) - { - std::string par = "since"; - nlohmann::json respond = nlohmann::json::array(); - std::vector<double> parlist; - std::map<double, nlohmann::json> m; - - int size = js.size(); - for (int i = 0; i < size; i++) - { - nlohmann::json elem = js[i]; - - auto res = elem.find(par); - - if (res != elem.end()) - { - double par_val = elem[par]; - parlist.push_back(par_val); - m[par_val] = std::move(elem); - } - } - - std::sort(parlist.begin(), parlist.end()); - - if (order == false) - { - std::reverse(parlist.begin(), parlist.end()); - } - - for (double item : parlist) - { - respond.push_back(m[item]); - } - - return respond; - } - - bool CrestFsClient::isMatch(const std::string& word, long unsigned int n, const std::string& pattern, long unsigned int m) - { - if (m == pattern.size()) - { - return n == word.size(); - } - - if (n == word.size()) - { - for (long unsigned int i = m; i < pattern.size(); i++) - { - if (pattern[i] != '%') - { - return false; - } - } - - return true; - } - - if (pattern[m] == '?' || pattern[m] == word[n]) - { - return isMatch(word, n + 1, pattern, m + 1); - } - - if (pattern[m] == '%') - { - return isMatch(word, n + 1, pattern, m) || isMatch(word, n, pattern, m + 1); - } - - return false; - } - - bool CrestFsClient::isMatch(const std::string& word, const std::string& pattern) - { - return isMatch(word, 0, pattern, 0); - } - - std::string CrestFsClient::getCrestVersion() - { - throw CrestException( - "ERROR in CrestFsClient::getCrestVersion: cannot get the CREST server version for file storage."); - } - -} // namespace Crest - diff --git a/Database/CrestApi/src/CrestContainer.cxx b/Database/CrestApi/src/CrestContainer.cxx deleted file mode 100644 index 606521666b7122445b0455f558c96643874a3a4c..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestContainer.cxx +++ /dev/null @@ -1,650 +0,0 @@ -/* - Copyright (C) 2020-2024 CERN for the benefit of the ATLAS collaboration -*/ - -#include "CrestApi/CrestContainer.h" -#include "CrestApi/CrestCondException.h" -#include <stdarg.h> -#include <boost/archive/iterators/base64_from_binary.hpp> -#include <boost/archive/iterators/binary_from_base64.hpp> -#include <boost/archive/iterators/transform_width.hpp> -#include <boost/algorithm/string.hpp> -#include <fstream> -#include <iomanip> - -using json = nlohmann::json; - -Crest::CrestContainer::CrestContainer() : m_modeId(ModeId::Standard) { ; } -Crest::CrestContainer::~CrestContainer() -{ - flush(); -} - -bool Crest::CrestContainer::isVectorPayload() -{ - return m_isVectorPayload; -} -void Crest::CrestContainer::setVectorPayload(bool isVectorPayload) -{ - m_isVectorPayload = isVectorPayload; -} - -Crest::TypeId Crest::CrestContainer::stringToTypeId(const std::string &type) const -{ - for(auto& t: s_typeToString){ - if(t.second.compare(type)==0) - return t.first; - } - throw CommonCrestException("The type of parameter is not defined."); -} - -// Function to convert an integer to a TypeId -Crest::TypeId Crest::CrestContainer::intToTypeId(int value) const -{ - if (value < 0 || value >= static_cast<int>(Crest::TypeId::TypeIdCount)) { - throw std::out_of_range("Invalid integer value for TypeId"); - } - return static_cast<Crest::TypeId>(value); -} - -std::string Crest::CrestContainer::base64_encode(const uint8_t *data, unsigned int len) -{ - using namespace boost::archive::iterators; - typedef base64_from_binary<transform_width<const char *, 6, 8>> base64_encoder; - - std::string encodedData; - std::copy(base64_encoder(data), base64_encoder(data + len), std::back_inserter(encodedData)); - - size_t numPaddingChars = (3 - len % 3) % 3; - encodedData.append(numPaddingChars, '='); - - return encodedData; -} - -// Decode base64 data to binary -std::vector<unsigned char> Crest::CrestContainer::base64_decode(const std::string &encodedData) -{ - using namespace boost::archive::iterators; - typedef transform_width<binary_from_base64<std::string::const_iterator>, 8, 6> base64_decoder; - - std::string encodedDataNoPadding = encodedData; - boost::algorithm::erase_all(encodedDataNoPadding, "="); - - std::vector<unsigned char> decodedData; - std::copy(base64_decoder(encodedDataNoPadding.begin()), base64_decoder(encodedDataNoPadding.end()), std::back_inserter(decodedData)); - - return decodedData; -} - -void Crest::CrestContainer::addColumn(const std::string &name, TypeId type) -{ - m_payload_spec.emplace_back(name, type); -} - -void Crest::CrestContainer::addColumn(const std::string &name, const char *type) -{ - addColumn(name, stringToTypeId(type)); -} - -void Crest::CrestContainer::addColumn(const std::string &name, uint32_t type) -{ - addColumn(name, static_cast<TypeId>(type)); -} - -void Crest::CrestContainer::addNullRecord(const char *name) -{ - auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(), - [&name](const auto &column) - { return column.first == name; }); - - if (it != m_payload_spec.end()) - { - m_row[name] = nlohmann::json::value_t::null; - } -} - -void Crest::CrestContainer::addRecord(const char *name, int number, ...) -{ - - va_list ap; - va_start(ap, number); - - for (auto &column : m_payload_spec) - { - if (column.first != name) - { - continue; - } - - switch (column.second) - { - case TypeId::Bool: - m_row[name] = va_arg(ap, int); - break; - case TypeId::UChar: - m_row[name] = static_cast<unsigned char>(va_arg(ap, int)); - break; - case TypeId::Int16: - case TypeId::Int32: - m_row[name] = va_arg(ap, int); - break; - case TypeId::UInt16: - case TypeId::UInt32: - m_row[name] = va_arg(ap, unsigned int); - break; - case TypeId::UInt63: - m_row[name] = va_arg(ap, uint64_t); - break; - case TypeId::Int64: - m_row[name] = va_arg(ap, int64_t); - break; - case TypeId::Float: - case TypeId::Double: - m_row[name] = va_arg(ap, double); - break; - case TypeId::String255: - case TypeId::String4k: - case TypeId::String64k: - case TypeId::String16M: - case TypeId::Blob64k: - case TypeId::Blob16M: - m_row[name] = std::string(va_arg(ap, const char *)); - break; - default: - throw CommonCrestException("Unsupported column type."); - } - } - va_end(ap); -} - -void Crest::CrestContainer::addData(const char *channel_id) -{ - addExternalData(channel_id, getRow()); -} - -void Crest::CrestContainer::addExternalData(const char *channel_id, const nlohmann::json &data) -{ - - validatePayloadSize(data); - nlohmann::json arr_data = m_isVectorPayload ? nlohmann::json::array() : nlohmann::json(); - - for (const auto &data_row : data)//m_vector_data) - { - auto row_arr_data = createRowArray(data_row); - - if (m_isVectorPayload) - { - arr_data.push_back(row_arr_data); - } - else - { - arr_data = row_arr_data; - } - } - m_payload[channel_id] = arr_data; - m_vector_data.clear(); - m_row.clear(); -} - -void Crest::CrestContainer::validatePayloadSize(const nlohmann::json &data) const -{ - if (!data.is_array()) - throw CommonCrestException("The format of data is wrong. It should be the vector (size 1 for non vector payload)"); - if (!m_isVectorPayload && m_vector_data.size() > 1) - { - throw CommonCrestException("The payload is not a vector, but the size seems to be larger than 1...."); - } -} - -nlohmann::json Crest::CrestContainer::createRowArray(const nlohmann::json &data_row) const -{ - nlohmann::json row_arr_data = nlohmann::json::array(); - for (const auto &column : m_payload_spec) - { - if (data_row.find(column.first) == data_row.end()) - { - std::string msg = "The data does not contain the column: " + column.first; - throw CommonCrestException(msg.c_str()); - } - row_arr_data.push_back(data_row[column.first]); - } - return row_arr_data; -} - -void Crest::CrestContainer::addIov(const uint64_t since) -{ - m_iov_data["since"] = since; - m_iov_data["data"] = m_payload; - m_full_data[std::to_string(since)]=m_payload; - m_payload.clear(); -} - -void Crest::CrestContainer::selectIov(const uint64_t since){ - m_iov_data["since"]=since; - m_iov_data["data"]=m_full_data[std::to_string(since)]; -} - -std::vector<std::string> Crest::CrestContainer::channelIds(){ - std::vector<std::string> chs; - for (auto& x : m_iov_data["data"].items()){ - chs.push_back(x.key()); - } - return chs; -} -const std::vector<std::pair<std::string, Crest::TypeId>> &Crest::CrestContainer::getMPayloadSpec() -{ - return m_payload_spec; -} - -const nlohmann::json &Crest::CrestContainer::getPayloadChannel(const char *channel_id) -{ - if (m_payload.empty()) - { - m_payload = m_iov_data["data"]; - } - auto it = m_payload.find(channel_id); - if (it == m_payload.end()) - { - std::string msg = "Channel id " + std::string(channel_id) + " is not found."; - throw CommonCrestException(msg.c_str()); - } - if (m_row.empty()) - { - for (const auto &column : m_payload_spec) - { - int index = getColumnIndex(column.first); - if (index == -1) - { - throw std::runtime_error("Column name not found."); - } - m_row[column.first] = it.value()[index]; - } - } - return it.value(); -} - -int Crest::CrestContainer::getColumnIndex(const std::string &name) -{ - auto it = std::find_if(m_payload_spec.begin(), m_payload_spec.end(), - [&name](const auto &column) - { return column.first == name; }); - - if (it != m_payload_spec.end()) - { - return std::distance(m_payload_spec.begin(), it); - } - else - { - throw CommonCrestException("The column name is not found."); - } -} - -void Crest::CrestContainer::putRow2Vector() -{ - if (m_isVectorPayload) - { - m_vector_data.push_back(m_row); - m_row.clear(); - } - else - { - std::string msg = "The payload is not a vector."; - throw CommonCrestException(msg.c_str()); - } -} - -const nlohmann::json &Crest::CrestContainer::getRow() -{ - if (m_isVectorPayload) - return m_vector_data; - m_vector_data.push_back(m_row); - return m_vector_data; -} - -const nlohmann::json &Crest::CrestContainer::getPayload() -{ - if (m_payload.empty() && m_iov_data.empty()) - { - std::string msg = "The payload is empty."; - throw CommonCrestException(msg.c_str()); - } - if (m_payload.empty()) - { - m_payload = m_iov_data["data"]; - } - return m_payload; -} - -const nlohmann::json &Crest::CrestContainer::getIovData() -{ - if (m_iov_data.empty()) - { - std::string msg = "The iov data is empty."; - throw CommonCrestException(msg.c_str()); - } - return m_iov_data; -} - -void Crest::CrestContainer::setIovData(const nlohmann::json &j) -{ - m_iov_data = j; -} - -void Crest::CrestContainer::setPayload(const nlohmann::json &j) -{ - m_payload = j; -} - -std::string Crest::CrestContainer::getJsonPayload() -{ - return getPayload().dump(); -} - -std::string Crest::CrestContainer::getJsonIovData() -{ - return m_iov_data.dump(); -} - -json Crest::CrestContainer::getPayloadSpec() -{ - json pspec_data=json::array(); - for (auto &column : m_payload_spec) - { - json j={}; - std::map<TypeId, std::string>::const_iterator pos = Crest::s_typeToString.find(column.second); - if (pos == Crest::s_typeToString.end()) { - throw CommonCrestException("Type do not exist in the map."); - } else { - j[column.first] = pos->second; - } - pspec_data.push_back(j); - } - return pspec_data; -} - -void Crest::CrestContainer::setPayloadSpec(const nlohmann::json &j) -{ - if (j.is_array()) - { - for (const auto &column : j) - { - for (const auto &[name, type] : column.items()) - { - addColumn(name, static_cast<TypeId>(std::stoi(type.get<std::string>()))); - } - } - } - else - { - for (const auto &[name, type] : j.items()) - { - addColumn(name, static_cast<TypeId>(type.get<int>())); - } - } -} - -void Crest::CrestContainer::flush() -{ - m_iov_data.clear(); - m_row.clear(); - m_vector_data.clear(); - m_full_data={}; -} - -void Crest::CrestContainer::clear(){ - m_payload.clear(); - m_iov_data.clear(); - m_row.clear(); - m_vector_data.clear(); - m_full_data={}; -} - -// Function to dump JSON object into a file -void Crest::CrestContainer::dump_json_to_file(const nlohmann::json &j, const std::string &filename) -{ - std::ofstream file(filename); - if (file.is_open()) - { - file << std::setprecision(6) << j.dump(4); - file.close(); - } - else - { - std::cerr << "CondContainer::dump_json_to_file: Error opening file: " << filename << std::endl; - } -} - -// Function to read file and create JSON object -nlohmann::json Crest::CrestContainer::read_json_from_file(const std::string &filename, const std::string &spec_filename) -{ - - std::ifstream specfile(spec_filename); - nlohmann::json jspec; - if (specfile.is_open()) - { - specfile >> jspec; - specfile.close(); - } - else - { - std::cerr << "CondContainer::read_json_from_file: Error opening file: " << spec_filename << std::endl; - } - // Set the payload spec - setPayloadSpec(jspec); - // Read data file - std::ifstream file(filename); - nlohmann::json j; - if (file.is_open()) - { - file >> j; - file.close(); - } - else - { - std::cerr << "CondContainer::read_json_from_file: Error opening file: " << filename << std::endl; - } - return j; -} - -void Crest::CrestContainer::parseOldFormat(std::string& colName, TypeId& typespec,const nlohmann::json & thisVal){ - try{ - if (thisVal.is_null()){ - m_row[colName] ="NULL"; - return; - } - std::string strVal = to_string(thisVal); - if(strVal.size()>2&& strVal[0]=='"'&& strVal[strVal.size()-1]=='"') - strVal=strVal.substr(1,strVal.size()-2); - if((strVal.compare("NULL")==0||strVal.compare("null")==0)&& - (typespec==TypeId::Bool || typespec==TypeId::Int16 || typespec==TypeId::UInt16 - || typespec==TypeId::Int32 || typespec==TypeId::UInt32 - || typespec==TypeId::Int64 || typespec==TypeId::UInt63 - || typespec==TypeId::Float || typespec==TypeId::Double)){ - m_row[colName] ="NULL"; - return; - } - switch (typespec) { - case TypeId::Bool: - { - const bool newVal=(strVal == "true"); - m_row[colName] = newVal; - break; - } - case TypeId::UChar: - { - m_row[colName]=std::stoul(strVal); - break; - } - case TypeId::Int16: - { - m_row[colName]=std::stol(strVal); - break; - } - case TypeId::UInt16: - { - m_row[colName]=std::stoul(strVal); - break; - } - case TypeId::Int32: - { - m_row[colName]=std::stoi(strVal); - break; - } - case TypeId::UInt32: - { - m_row[colName]=std::stoull(strVal); - break; - } - case TypeId::UInt63: - { - m_row[colName]=std::stoull(strVal); - break; - } - case TypeId::Int64: - { - m_row[colName]=std::stoll(strVal); - break; - } - case TypeId::Float: - { - m_row[colName]=std::stof(strVal); - break; - } - case TypeId::Double: - { - m_row[colName]=std::stod(strVal); - break; - } - case TypeId::String255: - case TypeId::String4k: - case TypeId::String64k: - case TypeId::String16M: - case TypeId::String128M: - { - m_row[colName]=thisVal.get<std::string>(); - break; - } - case TypeId::Blob128M: - case TypeId::Blob16M: - case TypeId::Blob64k: - { - m_row[colName]=thisVal.get<std::string>(); - break; - } - default: - { - throw std::runtime_error("UNTREATED TYPE!"); - break; - } - } - - } - catch(json::exception& e){ - std::cerr << e.what() << std::endl; - throw std::runtime_error(e.what()); - } -} -void Crest::CrestContainer::from_json(const uint64_t since,const nlohmann::json &j_in) -{ - nlohmann::json j = j_in; - if (j.is_string()){ - std::istringstream ss(to_string(j)); - std::string st; - ss >> std::quoted(st); - j = json::parse(st); - } - if(m_modeId!=ModeId::Standard) - throw CommonCrestException("Unsupported type of payload."); - // Accessing the "data" object - if (j.contains("data") && j["data"].is_object()) - { - const auto &data = j["data"]; - - // Loop over each channel in the data - for (const auto &channel : data.items()) - { - std::string channelKey = channel.key(); - const auto &data_ch = channel.value(); - nlohmann::json vecJson(json::value_t::array); - if(m_isVectorPayload) - vecJson=data_ch; - else - vecJson.push_back(data_ch); - - for (const auto &values : vecJson) - { - // TODO: this will not work for vector payloads - // Check if the number of values in the array matches the expected number of columns - if (values.is_array() && values.size() == m_payload_spec.size()) - { - for (size_t i = 0; i < values.size(); ++i) - { - const auto &spec = m_payload_spec[i]; - std::string colName = spec.first; - TypeId colType = spec.second; - if(values[i].is_string() &&( colType==TypeId::Bool || colType==TypeId::Int16 || colType==TypeId::UInt16 - || colType==TypeId::Int32 || colType==TypeId::UInt32 || colType==TypeId::Int64 || colType==TypeId::UInt63 || colType==TypeId::Float || colType==TypeId::Double)) - { - parseOldFormat(colName,colType,values[i]); - continue; - } - switch (colType) - { - case TypeId::Bool: - m_row[colName] = values[i].get<bool>(); - break; - case TypeId::UChar: - m_row[colName] = values[i].get<unsigned char>(); - break; - case TypeId::Int16: - case TypeId::Int32: - m_row[colName] = values[i].get<int>(); - break; - case TypeId::UInt16: - case TypeId::UInt32: - m_row[colName] = values[i].get<unsigned int>(); - break; - case TypeId::UInt63: - m_row[colName] = values[i].get<uint64_t>(); - break; - case TypeId::Int64: - m_row[colName] = values[i].get<int64_t>(); - break; - case TypeId::Float: - case TypeId::Double: - m_row[colName] = values[i].get<double>(); - break; - case TypeId::String255: - case TypeId::String4k: - case TypeId::String64k: - case TypeId::String16M: - case TypeId::String128M: - m_row[colName] = values[i].get<std::string>(); - break; - case TypeId::Blob128M: - case TypeId::Blob64k: - case TypeId::Blob16M: - m_row[colName] = values[i].get<std::string>(); - break; - default: - throw CommonCrestException("Unsupported column type."); - } - } - } - else - { - std::cerr << "CrestContainer::from_json: Mismatch in number of values for channel " << channelKey << std::endl; - } - if(m_isVectorPayload) - putRow2Vector(); - } - addData(channelKey.c_str()); - } - } - else - { - std::cerr << "CrestContainer::from_json: JSON does not contain a 'data' object or it is not a JSON object." << std::endl; - std::cerr << "CrestContainer::from_json json:"<<j<<std::endl; - } - addIov(since); -} diff --git a/Database/CrestApi/src/CrestModel.cxx b/Database/CrestApi/src/CrestModel.cxx deleted file mode 100644 index 76e3cfbbeb960a320732f2a70459a75fc9208999..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestModel.cxx +++ /dev/null @@ -1,663 +0,0 @@ -/* - Copyright (C) 2020-2025 CERN for the benefit of the ATLAS collaboration -*/ - -#include <CrestApi/CrestModel.h> -#include <iostream> -#include <sstream> -#include <string> -#include <iomanip> -#include "boost/regex.hpp" - -json RespPage::to_json() const -{ - return { - {"size", size}, - {"totalElements", totalElements}, - {"totalPages", totalPages}, - {"number", number}}; -} -RespPage RespPage::from_json(const json &j) -{ - RespPage respPage; - respPage.size = j.value("size", 0); - respPage.totalElements = j.value("totalElements", 0); - respPage.totalPages = j.value("totalPages", 0); - respPage.number = j.value("number", 0); - return respPage; -} -json GenericMap::to_json() const -{ - json additionalPropertiesJson; - for (const auto &entry : additionalProperties) - { - additionalPropertiesJson[entry.first] = entry.second; - } - - return { - additionalPropertiesJson}; -} - -GenericMap GenericMap::from_json(const json &j) -{ - GenericMap genericMap; - - json additionalPropertiesJson = j.value("additionalProperties", json::object()); - for (auto it = additionalPropertiesJson.begin(); it != additionalPropertiesJson.end(); ++it) - { - genericMap.additionalProperties[it.key()] = it.value(); - } - - return genericMap; -} - -json CrestBaseResponse::to_json() const -{ - json result = {}; - if (datatype.has_value()) - result["datatype"] = datatype.value(); - result["format"] = getFormat(); - result["size"] = getSize(); - - // Check if the 'page' optional contains a value - if (page.has_value()) - { - // Check if the value of 'page' is not null - if (!page.value().to_json().is_null()) - { - result["page"] = page.value().to_json(); - } - } - - // Check if the 'filter' optional contains a value - if (filter.has_value()) - { - // Check if the value of 'filter' is not null - if (!filter.value().to_json().is_null()) - { - result["filter"] = filter.value().to_json(); - } - } - - return result; -} - -void CrestBaseResponse::load_from_json(const json &j) -{ - if (j.contains("datatype")) - datatype = j.value("datatype", ""); - // Check for the presence of "page" key and create an optional - if (j.contains("page")) - { - if (!j["page"].is_null()) - { - page = std::make_optional((RespPage::from_json(j["page"]))); - } - } - - // Check for the presence of "filter" key and create an optional - filter = j.contains("filter") ? std::make_optional(GenericMap::from_json(j["filter"])) : std::nullopt; -} -json GlobalTagSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((GlobalTagDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} - -GlobalTagSetDto GlobalTagSetDto::from_json(const json &j) -{ - GlobalTagSetDto globalTagSet; - globalTagSet.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - globalTagSet.resources.push_back(GlobalTagDto::from_json(*it)); - } - - return globalTagSet; -} - -GlobalTagDto::GlobalTagDto() : name(""), validity(0), description(""), release(""), - snapshotTime(""), scenario(""), workflow(""), type("T"), - snapshotTimeMilli(0), insertionTimeMilli(0) -{ -} - -GlobalTagDto::GlobalTagDto(const char *l_name, const char *l_description, const char *l_release, const char *l_workflow) : name(l_name), validity(0), description(l_description), release(l_release), - snapshotTime(""), scenario(""), workflow(l_workflow), type("T"), - snapshotTimeMilli(0), insertionTimeMilli(0) -{ -} - -json GlobalTagDto::to_json() const -{ - json js = {}; - js["name"] = name; - js["validity"] = validity; - js["description"] = description; - js["release"] = release; - if (insertionTime.has_value()) - js["insertionTime"] = insertionTime.value(); - js["snapshotTime"] = snapshotTime; - js["scenario"] = scenario; - js["workflow"] = workflow; - js["type"] = type; - js["snapshotTimeMilli"] = snapshotTimeMilli; - js["insertionTimeMilli"] = insertionTimeMilli; - return js; -} -GlobalTagDto GlobalTagDto::from_json(const json &j) -{ - GlobalTagDto globalTag; - globalTag.name = j.value("name", ""); - globalTag.validity = j.value<uint64_t>("validity", 0); - globalTag.description = j.value("description", ""); - globalTag.release = j.value("release", ""); - if (j.contains(std::string{"insertionTime"})) - globalTag.insertionTime = j.value("insertionTime", ""); - globalTag.snapshotTime = j.value("snapshotTime", ""); - globalTag.scenario = j.value("scenario", ""); - globalTag.workflow = j.value("workflow", ""); - globalTag.type = j.value("type", ""); - globalTag.snapshotTimeMilli = j.value("snapshotTimeMilli", 0); - globalTag.insertionTimeMilli = j.value("insertionTimeMilli", 0); - return globalTag; -} -json TagDto::to_json() const -{ - json js = {}; - js["name"] = name; - js["timeType"] = timeType; - js["payloadSpec"] = objectType; - js["synchronization"] = synchronization; - if (insertionTime.has_value()) - js["insertionTime"] = insertionTime.value(); - js["description"] = description; - js["lastValidatedTime"] = lastValidatedTime; - js["endOfValidity"] = endOfValidity; - if (modificationTime.has_value()) - js["modificationTime"] = modificationTime.value(); - return js; -} -TagDto TagDto::from_json(const json &j) -{ - TagDto tag; - auto it = j.find("name"); - if (it != j.end()) - { - tag.name = j["name"]; - } - else - { - throw Crest::CrestException("ERROR in TagDto.from_json: JSON contains no tag name."); - } - - tag.timeType = j.value("timeType", ""); - tag.objectType = j.value("payloadSpec", ""); - tag.synchronization = j.value("synchronization", "none"); - tag.description = j.value("description", ""); - tag.lastValidatedTime = j.value<uint64_t>("lastValidatedTime", 0); - tag.endOfValidity = j.value<uint64_t>("endOfValidity", 0); - if (j.contains(std::string{"insertionTime"})) - tag.insertionTime = j.value("insertionTime", ""); - tag.modificationTime = j.value("modificationTime", ""); - return tag; -} -json TagSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((TagDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} -TagSetDto TagSetDto::from_json(const json &j) -{ - TagSetDto tagSet; - tagSet.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - tagSet.resources.push_back(TagDto::from_json(*it)); - } - - return tagSet; -} -json GlobalTagMapDto::to_json() const -{ - return { - {"tagName", tagName}, - {"globalTagName", globalTagName}, - {"record", record}, - {"label", label}}; -} -GlobalTagMapDto GlobalTagMapDto::from_json(const json &j) -{ - GlobalTagMapDto tagmap; - tagmap.tagName = j.value("tagName", ""); - tagmap.globalTagName = j.value("globalTagName", ""); - tagmap.record = j.value("record", "none"); - tagmap.label = j.value("label", "none"); - return tagmap; -} - -json GlobalTagMapSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((GlobalTagMapDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} -GlobalTagMapSetDto GlobalTagMapSetDto::from_json(const json &j) -{ - GlobalTagMapSetDto tagMapSet; - tagMapSet.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - tagMapSet.resources.push_back(GlobalTagMapDto::from_json(*it)); - } - - return tagMapSet; -} - -GlobalTagMapSetDto GlobalTagMapSetDto::from_fs_json(const json &j) -{ - GlobalTagMapSetDto tagMapSet; - tagMapSet.load_from_json(j); - // int n = j.size(); - - for (auto it = j.begin(); it != j.end(); ++it) - { - tagMapSet.resources.push_back(GlobalTagMapDto::from_json(*it)); - } - - tagMapSet.datatype = "maps"; - - return tagMapSet; -} - -void ChannelSetDto::add(const std::string& id, const std::string& name) -{ - m_channels.push_back(std::pair<std::string, std::string>(id, name)); -} -ChannelSetDto ChannelSetDto::from_json(const json &j) -{ - ChannelSetDto chDto; - for (unsigned int i = 0; i < j.size(); i++) - { - auto itemZero = j[i].begin(); - chDto.add(itemZero.key(), itemZero.value()); - } - return chDto; -} -json ChannelSetDto::to_json() const -{ - json chJson = json::array(); - for (auto &ch : m_channels) - { - json obj = {}; - obj[ch.first] = ch.second; - chJson.push_back(obj); - } - return chJson; -} -void PayloadSpecDto::add(const std::string& name, const std::string& type) -{ - m_row.push_back(std::pair<std::string, std::string>(name, type)); -} -PayloadSpecDto PayloadSpecDto::from_json(const json &j) -{ - PayloadSpecDto chDto; - //old format - if(!j.is_object()&&!j.is_array()){ - std::string regex=R"delim(([^\s,:]*):\s?([^\s,]*),?)delim"; - boost::regex expression(regex); - boost::smatch what; - std::string input=j.dump(); - input=boost::regex_replace(input,boost::regex("\""),""); - bool match=boost::regex_search(input, what, expression); - while (match){ - std::string n(what[1]); - std::string t(what[2]); - chDto.add(boost::regex_replace(n, boost::regex("(^[ ]+)|([ ]+$)"),""),boost::regex_replace(t, boost::regex("(^[ ]+)|([ ]+$)"),"")); - input = what.suffix(); - match=boost::regex_search(input, what, expression); - } - return chDto; - } - for (unsigned int i = 0; i < j.size(); i++) - { - const auto itemZero = j[i].begin(); - chDto.add(itemZero.key(), itemZero.value()); - - } - return chDto; -} -json PayloadSpecDto::to_json() const -{ - json chJson = json::array(); - for (auto &ch : m_row) - { - json obj = {}; - obj[ch.first] = ch.second; - chJson.push_back(obj); - } - return chJson; -} -json TagInfoDto::to_json() const -{ - json tagInfo = {}; - tagInfo["node_description"] = m_node_description; - tagInfo["payload_spec"] = m_payload_spec.to_json(); - tagInfo["channel_list"] = m_channel_list.to_json(); - return tagInfo; -} -TagInfoDto TagInfoDto::from_json(const json &j) -{ - std::string node_description = j.value("node_description", ""); - json jsonSpec = j.value("payload_spec", json::array()); - if (jsonSpec.is_string()) - jsonSpec = json::parse(to_string(jsonSpec)); - PayloadSpecDto payload_spec = PayloadSpecDto::from_json(jsonSpec); - json jsonCh = j.value("channel_list", json::array()); - if (jsonCh.is_string()) - jsonCh = json::parse(to_string(jsonCh)); - ChannelSetDto channel_list = ChannelSetDto::from_json(jsonCh); - TagInfoDto dto(node_description, payload_spec, channel_list); - return dto; -} - -json TagMetaDto::to_json() const -{ - json tagMeta = {}; - tagMeta["tagName"] = tagName; - tagMeta["description"] = description; - tagMeta["chansize"] = tagInfo.getChannelSize(); - tagMeta["colsize"] = tagInfo.getColumnSize(); - tagMeta["tagInfo"] = tagInfo.to_json().dump(); - if (insertionTime.has_value()) - tagMeta["insertionTime"] = insertionTime.value(); - return tagMeta; -} -TagMetaDto TagMetaDto::from_json(const json &j) -{ - TagMetaDto tag; - tag.tagName = j.value("tagName", ""); - json infoJs = j["tagInfo"]; - if (infoJs.is_string()) - { - std::istringstream ss(to_string(infoJs)); - std::string st; - ss >> std::quoted(st); - infoJs = json::parse(st); - } - tag.tagInfo = TagInfoDto::from_json(infoJs); - - tag.description = j.value("description", ""); - if (j.contains(std::string{"insertionTime"})) - tag.insertionTime = j.value("insertionTime", ""); - return tag; -} - -json TagMetaSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((TagMetaDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} -TagMetaSetDto TagMetaSetDto::from_json(const json &j) -{ - TagMetaSetDto tagSet; - tagSet.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - tagSet.resources.push_back(TagMetaDto::from_json(*it)); - } - - return tagSet; -} - -json IovDto::to_json() const -{ - json iov = {}; - iov["tagName"] = tagName; - iov["since"] = since; - if (insertionTime.has_value()) - iov["insertionTime"] = insertionTime.value(); - iov["payloadHash"] = payloadHash; - return iov; -} - -IovDto IovDto::from_json(const json &j) -{ - IovDto iov; - iov.tagName = j.value("tagName", ""); - iov.since = j.value<uint64_t>("since", 0); - - if (j.contains("insertionTime")) - { - if (!j["insertionTime"].is_null()) - { - iov.insertionTime = j["insertionTime"]; - } - else - { - iov.insertionTime = ""; - } - } - else - { - iov.insertionTime = ""; - } - - if (j.contains("payloadHash")) - { - if (!j["payloadHash"].is_null()) - { - iov.payloadHash = j["payloadHash"]; - } - else - { - iov.payloadHash = ""; - } - } - else - { - iov.payloadHash = ""; - } - - return iov; -} - -json IovSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((IovDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} - -std::vector<uint64_t> IovSetDto::getListSince(){ - std::vector<uint64_t> v; - for (IovDto item_iov: resources){ - uint64_t since = item_iov.since; - v.emplace_back(since); - } - return v; -} - -IovSetDto IovSetDto::from_json(const json &j) -{ - IovSetDto iovSet; - iovSet.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - iovSet.resources.push_back(IovDto::from_json(*it)); - } - - return iovSet; -} - -IovSetDto IovSetDto::from_fs_json(const json &j) -{ - IovSetDto iovSet; - iovSet.load_from_json(j); - - for (auto it = j.begin(); it != j.end(); ++it) - { - iovSet.resources.push_back(IovDto::from_json(*it)); - } - - iovSet.datatype = "iovs"; - - return iovSet; -} - -json StoreDto::to_json() const -{ - json dto = {}; - dto["hash"] = hash; - dto["since"] = since; - dto["data"] = data; - dto["streamerInfo"] = getStreamerInfo().dump(); - return dto; -} -json StoreDto::getStreamerInfo() const -{ - json js = {}; - if (m_app_version.has_value()) - js["app_version"] = m_app_version.value(); - if (m_app_name.has_value()) - js["app_name"] = m_app_name.value(); - return js; -} - -StoreDto StoreDto::from_json(const json &j) -{ - StoreDto storeDto; - storeDto.hash = j.value("hash", ""); - storeDto.since = j.value("since", 0.0); - storeDto.data = j.value("data", ""); - //do we need get streamerInfo? - return storeDto; -} - -json StoreSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((StoreDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} -void StoreSetDto::push_back(const StoreDto & dto) -{ - resources.push_back(dto); -} -void StoreSetDto::clear() -{ - resources.clear(); -} - -StoreSetDto StoreSetDto::from_json(const json &j) -{ - StoreSetDto storeSetDto; - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - storeSetDto.push_back(StoreDto::from_json(*it)); - } - - return storeSetDto; -} - -// Function to serialize the object to JSON - -json PayloadDto::to_json() const -{ - json payloadDto = {}; - payloadDto["hash"] = hash; - payloadDto["version"] = version; - payloadDto["objectType"] = objectType; - payloadDto["objectName"] = objectName; - payloadDto["compressionType"] = compressionType; - payloadDto["checkSum"] = checkSum; - payloadDto["size"] = size; - if (insertionTime.has_value()) - payloadDto["insertionTime"] = insertionTime.value(); - return payloadDto; -} - -// Function to deserialize the object from JSON - -PayloadDto PayloadDto::from_json(const json &j) -{ - PayloadDto payloadDto; - payloadDto.hash = j.value("hash", ""); - payloadDto.version = j.value("version", ""); - payloadDto.objectType = j.value("objectType", ""); - payloadDto.objectName = j.value("objectName", ""); - payloadDto.compressionType = j.value("compressionType", ""); - payloadDto.checkSum = j.value("checkSum", ""); - payloadDto.size = j.value("size", 0); - if (j.contains(std::string{"insertionTime"})) - payloadDto.insertionTime = j.value("insertionTime", ""); - return payloadDto; -} - -// Function to serialize the object to JSON - -json PayloadSetDto::to_json() const -{ - json baseJson = CrestBaseResponse::to_json(); - json jsonResources = json::array(); - for (const auto &resource : resources) - { - jsonResources.push_back(((PayloadDto)resource).to_json()); - } - baseJson["resources"] = std::move(jsonResources); - return baseJson; -} - -// Function to deserialize the object from JSON - -PayloadSetDto PayloadSetDto::from_json(const json &j) -{ - PayloadSetDto payloadSetDto; - payloadSetDto.load_from_json(j); - json jsonResources = j.value("resources", json::array()); - for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) - { - payloadSetDto.resources.push_back(PayloadDto::from_json(*it)); - } - - return payloadSetDto; -} diff --git a/Database/CrestApi/src/CrestRequest.cxx b/Database/CrestApi/src/CrestRequest.cxx deleted file mode 100644 index 4073192a26f995e6b741c41d651a8d6aab3c0ee9..0000000000000000000000000000000000000000 --- a/Database/CrestApi/src/CrestRequest.cxx +++ /dev/null @@ -1,545 +0,0 @@ -/* - Copyright (C) 2020-2024 CERN for the benefit of the ATLAS collaboration -*/ - -#include <CrestApi/CrestRequest.h> -#include <iostream> -#include "nlohmann/json.hpp" - -#include <boost/uuid/uuid.hpp> // uuid class -#include <boost/uuid/uuid_generators.hpp> // generators -#include <boost/uuid/uuid_io.hpp> -#include <boost/asio.hpp> -#include <fstream> - -#include <string> -#include <map> -#include <CrestApi/CrestException.h> - -namespace Crest -{ - - CrestRequest::CrestRequest() - { - curl_global_init(CURL_GLOBAL_ALL); - m_CREST_PROXY = std::getenv(m_CREST_PROXY_VAR); - } - - CrestRequest::~CrestRequest() - { - curl_global_cleanup(); - } - - void CrestRequest::setHost(const std::string &host) - { - m_host = host; - } - - void CrestRequest::setPort(const std::string &port) - { - m_port = port; - } - - void CrestRequest::setPrefix(const std::string &prefix) - { - m_prefix = prefix; - } - - std::string CrestRequest::make_url(const std::string &address) const - { - std::string str = m_prefix; - str += m_host; - str += ':'; - str += m_port; - str += address; - return str; - } - - size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::vector<char> *output) - { - size_t total_size = size * nmemb; - output->insert(output->end(), reinterpret_cast<char *>(contents), reinterpret_cast<char *>(contents) + total_size); - return total_size; - } - - size_t curlWrite_CallbackFunc_StdString(void *contents, size_t size, size_t nmemb, std::string *s) - { - size_t newLength = size * nmemb; - - try - { - s->append((char *)contents, newLength); - } - catch (std::bad_alloc &e) - { - std::cout << "Not enough memory to allocate "<<newLength<<" bytes "<< std::endl; - return 0; - } - return newLength; - } - - // Callback function to provide data for the request - size_t ReadCallback(void *contents, size_t size, size_t nmemb, std::string *input) - { - size_t totalSize = size * nmemb; - if (!input->empty()) - { - // Copy data from the input string to the buffer - size_t toCopy = std::min(totalSize, input->size()); - std::memcpy(contents, input->c_str(), toCopy); - input->erase(0, toCopy); - return toCopy; - } - return 0; - } - - std::string CrestRequest::performRequest(const std::string ¤t_path, Action action, nlohmann::json &js, - const char *method_name, const std::string& header_params) - { - CURL *curl; - CURLcode res; - - /* Enable tracing of ascii data */ - // sanitise the current path - std::string sanitisedPath(current_path); - auto caretPosition = sanitisedPath.find('^'); - if (caretPosition != std::string::npos) - sanitisedPath.replace(caretPosition, 1, "%5E"); - /* get a curl handle */ - curl = curl_easy_init(); - std::string stt; - struct curl_slist *headers = NULL; - if (curl) - { - std::string url = make_url(sanitisedPath); - std::string s; - std::cout << "cURL request to " << url << std::endl; - - if (m_CREST_PROXY) - { - // Set the proxy type (replace with your proxy type details) - curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - - // Set the proxy address and port (replace with your SOCKS proxy details) - curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY); - } - - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - if (js.is_null()) - { - if (action == Action::DELETE) - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - if (header_params != "") - { - headers = curl_slist_append(headers, header_params.c_str()); - } - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - } - else - { - stt = js.dump(); - - if (action == Action::PUT) - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - headers = curl_slist_append(headers, "Accept: */*"); - headers = curl_slist_append(headers, "Content-Type: application/json"); - - if (header_params != "") - { - headers = curl_slist_append(headers, header_params.c_str()); - } - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(curl, CURLOPT_POST, 1L); - - /* set where to read from (on Windows you need to use READFUNCTION too) */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, stt.c_str()); - } - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWrite_CallbackFunc_StdString); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); - - /* Perform the request, res will get the return code */ - res = curl_easy_perform(curl); - - // data to check the errors in the server response: - long response_code; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); - - /* always cleanup */ - curl_easy_cleanup(curl); - curl_slist_free_all(headers); - - curl_global_cleanup(); - - // error checking in the server response: - checkResult(res, response_code, s, method_name); - - return s; - } - - throw CrestException(std::string("ERROR in ") + std::string(method_name) + " | CURL not init"); - } - - std::vector<char> CrestRequest::getPayloadRequest(const std::string ¤t_path) - { - // Initialize libcurl - CURL *curl; - CURLcode res; - - curl_global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - - if (curl) - { - std::string url = make_url(current_path); - std::string response; - - std::string content_type = "application/octet-stream"; - - if (m_CREST_PROXY) - { - // Set the proxy type (replace with your proxy type details) - curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - - // Set the proxy address and port (replace with your SOCKS proxy details) - curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY); - } - else - { - // The environment variable does not exist - std::cerr << "SOCKS_PROXY environment variable not found." << std::endl; - } - // - - // First set the URL that is about to receive the GET. This URL can - // just as well be a https: - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - - // Set the write callback function to handle the response - std::vector<char> response_data; - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_data); - // Perform the request - res = curl_easy_perform(curl); - - // data to check the errors in the server response: - long response_code; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); - - curl_easy_cleanup(curl); - - // error checking in the server response: - const char *method_name = "CrestRequest::getPayloadRequest"; - checkResult(res, response_code, response, method_name); - - return response_data; - } - throw CrestException(std::string("ERROR in ") + "getPayloadRequest CURL not init"); - } - - - std::string CrestRequest::uploadPayload(const std::string ¤t_path, const std::string &tag, uint64_t endtime, const nlohmann::json &js, - const std::string& objectType, const std::string& compressionType, const std::string& version, - const std::vector<std::string> &files) - { - - CURL *curl; - - curl_global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - - struct curl_slist *headers = NULL; - - if (curl) - { - std::string url = make_url(current_path); - std::string response; - - std::string content_type = "application/octet-stream"; - - if (m_CREST_PROXY) - { - // Set the proxy type (replace with your proxy type details) - curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - - // Set the proxy address and port (replace with your SOCKS proxy details) - curl_easy_setopt(curl, CURLOPT_PROXY, m_CREST_PROXY); - } - - // - - // First set the URL that is about to receive our POST. This URL can - // just as well be a https: - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - std::string js_str = js.dump(); - - // Enable verbose mode - // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - - std::string format = "X-Crest-PayloadFormat: "; - if (files.size() > 0) - { - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); - format += "FILE"; - content_type = "application/form-data"; - } - else - { - curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - format += "JSON"; - } - headers = curl_slist_append(headers, format.c_str()); - headers = curl_slist_append(headers, "Accept: application/json"); - headers = curl_slist_append(headers, "Content-Type: multipart/form-data"); - - // Create the form for new version -#if LIBCURL_VERSION_MAJOR < 8 - struct curl_httppost *formpost = NULL; - struct curl_httppost *lastptr = NULL; - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "tag", CURLFORM_COPYCONTENTS, tag.c_str(), CURLFORM_END); - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "endtime", CURLFORM_COPYCONTENTS, std::to_string(endtime).c_str(), CURLFORM_END); - // Set the read callback function - // Add the "storeset" field with the JSON data directly - curl_formadd(&formpost, &lastptr, - CURLFORM_COPYNAME, "storeset", - CURLFORM_BUFFER, "json_data", - CURLFORM_BUFFERPTR, js_str.c_str(), - CURLFORM_BUFFERLENGTH, js_str.size(), - CURLFORM_CONTENTTYPE, content_type.c_str(), - CURLFORM_END); - - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "version", CURLFORM_COPYCONTENTS, version.c_str(), CURLFORM_END); - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "objectType", CURLFORM_COPYCONTENTS, objectType.c_str(), CURLFORM_END); - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "compressionType", CURLFORM_COPYCONTENTS, compressionType.c_str(), CURLFORM_END); - - for (auto &file : files) - { - curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "files", CURLFORM_FILE, file.c_str(), CURLFORM_END); - } - curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); - -#else - - curl_mime *mime = curl_mime_init(curl); - { - curl_mimepart *part = curl_mime_addpart(mime); - curl_mime_name(part, "tag"); - curl_mime_data(part, tag.c_str(), tag.size()); - - part = curl_mime_addpart(mime); - std::string endtime_s = std::to_string(endtime); - curl_mime_name(part, "endtime"); - curl_mime_data(part, endtime_s.c_str(), endtime_s.size()); - - part = curl_mime_addpart(mime); - curl_mime_name(part, "version"); - curl_mime_data(part, version.c_str(), version.size()); - - part = curl_mime_addpart(mime); - curl_mime_name(part, "objectType"); - curl_mime_data(part, objectType.c_str(), objectType.size()); - - part = curl_mime_addpart(mime); - curl_mime_name(part, "compressionType"); - curl_mime_data(part, compressionType.c_str(), compressionType.size()); - - part = curl_mime_addpart(mime); - curl_mime_name(part, "storeset"); - curl_mime_type(part, content_type.c_str()); - curl_mime_data(part, js.dump().c_str(), js.dump().size()); - - for (auto &file : files) - { - curl_mimepart *part = curl_mime_addpart(mime); - curl_mime_name(part, "files"); - curl_mime_filedata(part, file.c_str()); - } - } - curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); -#endif - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWrite_CallbackFunc_StdString); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); - - // Perform the request - CURLcode res = curl_easy_perform(curl); - - // data to check the errors in the server response: - long response_code; - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); - const char *method_name = "CrestRequest::uploadPayload"; - - /* always cleanup */ - curl_easy_cleanup(curl); -#if LIBCURL_VERSION_MAJOR < 8 - curl_formfree(formpost); -#else - curl_mime_free(mime); -#endif - curl_slist_free_all(headers); - curl_global_cleanup(); - - // error checking in the server response: - checkResult(res, response_code, response, method_name); - - return response; - } - std::string mes = "ERROR in CrestRequest::uploadPayload"; - throw CrestException(mes + " | CURL not init"); - } - // end of REQUEST METHODS - - // The auxillary method to remove XML/HTML tags from a std::string - - std::string CrestRequest::parseXMLOutput(std::string_view xmlBuffer) - { - bool copy = true; - - std::string plainString = ""; - - // remove all xml tags - for (long unsigned int i = 0; i < xmlBuffer.length(); i++) - { - char convertc = xmlBuffer[i]; - - if (convertc == '<') - copy = false; - else if (convertc == '>') - { - copy = true; - continue; - } - - if (copy) - plainString += convertc; - } - - return plainString; - } - - std::string CrestRequest::removeCR(const std::string &str) - { - std::string str2 = str; - std::replace(str2.begin(), str2.end(), '\n', '|'); - char needle = '\r'; - size_t pos; - while ((pos = str2.find(needle)) != str2.npos) - { - str2.erase(pos, 1); - } - return str2; - } - - bool CrestRequest::isJson(const std::string &str) - { - try - { - nlohmann::json js = nlohmann::json::parse(str); - return true; - } - catch (nlohmann::json::parse_error &e) - { - return false; - } - } - - void CrestRequest::checkResult(CURLcode res, const long response_code, const std::string &st, - const char *method_name) - { - // Bad HTTP response: - - if (res != CURLE_OK) - { - std::string mes = "ERROR in "; - mes += method_name; - mes += " | "; - throw CrestException(mes + std::to_string(response_code)); - } - - // Errors, decoded from JSON CREST Server messages: - - if (isJson(st)) - { - nlohmann::json respond = getJson(st); - checkErrors(respond, method_name); - } - - // HTTP response code error interval: - - if (response_code >= 400 || response_code == 303) - { - std::string s = parseXMLOutput(st); // to remove HTML tags - s = removeCR(s); // to remove end lines and carridge returns - std::string mes = "ERROR in "; - mes += method_name; - mes += " | "; - throw CrestException(mes + "CREST Server response : " + s); - } - } - - nlohmann::json CrestRequest::getJson(const std::string &str, const char *method) - { - try - { - nlohmann::json js = nlohmann::json::parse(str); - return js; - } - catch (nlohmann::json::parse_error &e) - { - if (method == nullptr || *method == '\0') - { - // method name is undefined - - std::string wh = e.what(); - throw CrestException("ERROR in JSON conversion: " + wh + " | In string: " + str); - } - else - { - std::string str2 = parseXMLOutput(str); // to remove HTML tags use this function - std::string str3 = removeCR(str2); // to remove carridge return - throw CrestException("ERROR in " + std::string(method) + " | CREST Server response : " + str3); - } - } - } - - nlohmann::json CrestRequest::getJson(const std::string &str) - { - return getJson(str, ""); - } - - int CrestRequest::checkErrors(const nlohmann::json &js, const char *method) - { - int result = 0; - auto res = js.find("type"); - - // Old format parsing: - - if (res != js.end()) - { - std::string type = js.value("type", " unknown type "); - if (type == "error" || type == "info") - { - std::string message = js.value("message", " unknown message "); - throw CrestException("ERROR in " + std::string(method) + " | CREST response: " + message); - } - } - - // New format parsing: - - auto r1 = js.find("error"); - auto r2 = js.find("message"); - - if (r1 != js.end()) - { - std::string error = js.value("error", " unknown error "); - if (r2 != js.end()) - { - std::string message = js.value("message", ""); - throw CrestException("ERROR in " + std::string(method) + " | CREST response: " + (message.empty() ?error : message)); - } - } - return result; - } - -} diff --git a/Database/CrestApi/test/CrestApiFs_test.cxx b/Database/CrestApi/test/CrestApiFs_test.cxx deleted file mode 100644 index 34bcbc5e2cd063bd15a4ff23a296eb87afd06bfb..0000000000000000000000000000000000000000 --- a/Database/CrestApi/test/CrestApiFs_test.cxx +++ /dev/null @@ -1,261 +0,0 @@ - -/** - * @file CrestApi/test/CrestApiFs_test.cxx - * @brief Some tests for file storage methods. - */ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MAIN -#define BOOST_TEST_MODULE TEST_CRESTAPI - -#include <boost/test/unit_test.hpp> - -#include "../CrestApi/CrestApiFs.h" -#include <string> -#include <unistd.h> -#include <sys/stat.h> - -#include "CxxUtils/checker_macros.h" -ATLAS_NO_CHECK_FILE_THREAD_SAFETY; - -using namespace Crest; - -BOOST_AUTO_TEST_SUITE(CrestApiFsTest) - - std::string workdir = "./crest"; - int dirstat = mkdir (workdir.c_str(), S_IRWXU); - CrestFsClient myCrestClient = CrestFsClient(true, workdir); - std::string tagname = "test_ctest_tag_01"; - std::string global_tag = "TEST_GLOBAL_TAG_01"; - - - BOOST_AUTO_TEST_CASE(tag_test){ - std::cout << "\n====== CrestApi Test for the file storage methods =====\n\n"; - - - std::cout << std::endl << "1) Tag test" << std::endl; - - nlohmann::json js = - { - {"description", "none"}, - {"endOfValidity", 0}, - {"insertionTime", "2018-12-06T11:18:35.641+0000"}, - {"lastValidatedTime", 0}, - {"modificationTime", "2018-12-06T11:18:35.641+0000"}, - {"name", tagname}, - {"payloadSpec", "Json2Cool"}, - {"synchronization", "none"}, - {"timeType", "time"} - }; - - std::cout << "tag (" << tagname << ") =" << std::endl - << js.dump(4) << std::endl; - - TagDto dto = TagDto(); - dto = dto.from_json(js); - - try - { - myCrestClient.createTag(dto); - std::cout << "Tag " << tagname - << " created in the directory " << workdir - << "." << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the tag " << tagname - << " in the directory" << workdir << std::endl; - std::cout << e.what() << std::endl; - } - - TagDto dto2; - - std::cout << "Reading the file from the file storage..." << std::endl; - - try - { - dto2 = myCrestClient.findTag(tagname); - std::cout << std::endl - << "tag (" << tagname << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the tag " << tagname - << " from the directory" << workdir << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - js.erase("modificationTime"); - js2.erase("modificationTime"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - - bool res = patch.empty(); - if (res) { - std::cout << "Tag test passed successfully." << std::endl; - } - else { - std::cout << "Tag test failed." << std::endl; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(tag_meta_test){ - - std::cout << std::endl << "2) Tag meta info test" << std::endl; - - PayloadSpecDto spec; - spec.add("ModuleId","UInt32"); - spec.add("ErrorCode","UInt32"); - spec.add("json","Blob64k"); - - std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>"; - TagInfoDto taginfo(description); - taginfo.setPayloadSpec(spec); - - ChannelSetDto chanset; - chanset.add("583008256",""); - chanset.add("583204864",""); - - taginfo.setChannel(chanset); - - std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}"; - TagMetaDto dto(tagname,tag_description,taginfo); - nlohmann::json js = dto.to_json(); - - try - { - myCrestClient.createTagMeta(dto); - std::cout << "Tag meta info for tag " << tagname - << " created in the directory " << workdir - << "." << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the tag meta info for tag " << tagname - << " in the directory" << workdir << std::endl; - std::cout << e.what() << std::endl; - } - - TagMetaDto dto2; - - std::cout << "Reading the tag meta from the file storage..." << std::endl; - - try - { - dto2 = myCrestClient.findTagMeta(tagname); - std::cout << std::endl - << "tag meta (" << tagname << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the tag meta " << tagname - << " from the directory" << workdir << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - - bool res = patch.empty(); - if (res) { - std::cout << "Tag meta info test passed successfully." << std::endl; - } - else { - std::cout << "Tag meta info test failed." << std::endl; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(global_tag_test){ - - std::cout << std::endl << "3) Global Tag test" << std::endl; - - nlohmann::json js = - { - {"name", global_tag}, - {"validity", 0.0}, - {"description", "test"}, - {"release", "1"}, - {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - {"snapshotTime", "2018-12-18T11:32:58+0000"}, - {"scenario", "test"}, - {"workflow", "M"}, - {"type", "t"}, - }; - - std::cout << "global tag (" << global_tag << ") =" << std::endl - << js.dump(4) << std::endl; - - GlobalTagDto dto = GlobalTagDto(); - dto = dto.from_json(js); - - try - { - myCrestClient.createGlobalTag(dto); - std::cout << "Global tag " << global_tag - << " created on the CREST server. " << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the global tag " << global_tag - << " on CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - GlobalTagDto dto2; - - std::cout << "Reading the global tag from the CREST server..." << std::endl; - - try - { - dto2 = myCrestClient.findGlobalTag(global_tag); - std::cout << std::endl - << "global tag (" << global_tag << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the global tag " << global_tag - << " from the CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - js.erase("modificationTime"); - js2.erase("modificationTime"); - js2.erase("insertionTimeMilli"); - js2.erase("snapshotTimeMilli"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - std::cout << "global tag patch = " << std:: endl - << patch.dump(4) << std::endl; - - bool res = patch.empty(); - if (res) { - std::cout << "The global tag test passed successfully." << std::endl; - } - else { - std::cout << "The global tag test failed." << std::endl; - } - - BOOST_TEST(res); - } - - -BOOST_AUTO_TEST_SUITE_END() - diff --git a/Database/CrestApi/test/CrestApi_test.cxx b/Database/CrestApi/test/CrestApi_test.cxx deleted file mode 100644 index 8b53cf4ad47344c52db1261b58206b9dbfa32912..0000000000000000000000000000000000000000 --- a/Database/CrestApi/test/CrestApi_test.cxx +++ /dev/null @@ -1,290 +0,0 @@ - -/** - * @file CrestApi/test/CrestApi_test.cxx - * @brief Some tests for server methods. - */ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MAIN -#define BOOST_TEST_MODULE TEST_CRESTAPI - -#include <boost/test/unit_test.hpp> - -#include "../CrestApi/CrestApi.h" -#include <string> - -using namespace Crest; - -BOOST_AUTO_TEST_SUITE(CrestApiTest) - - const std::string crest_server = "http://crest-04.cern.ch"; - const std::string tagname = "test_ctest_tag_01"; - const std::string global_tag = "TEST_GLOBAL_TAG_01"; - - - BOOST_AUTO_TEST_CASE(tag_test){ - CrestClient myCrestClient = CrestClient(crest_server,false); - std::cout << "\n====== CrestApi Test for the server methods =====\n"; - std::cout << "CREST server: " << crest_server << "\n\n"; - - - std::cout << std::endl << "1) Tag test" << std::endl; - - nlohmann::json js = - { - {"description", "none"}, - {"endOfValidity", 0}, - {"insertionTime", "2018-12-06T11:18:35.641+0000"}, - {"lastValidatedTime", 0}, - {"modificationTime", "2018-12-06T11:18:35.641+0000"}, - {"name", tagname}, - {"payloadSpec", "Json2Cool"}, - {"synchronization", "none"}, - {"timeType", "time"} - }; - - std::cout << "tag (" << tagname << ") =" << std::endl - << js.dump(4) << std::endl; - - TagDto dto = TagDto(); - dto = dto.from_json(js); - - try - { - myCrestClient.createTag(dto); - std::cout << "Tag " << tagname - << " created on the CREST server. " << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the tag " << tagname - << " on CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - TagDto dto2; - - std::cout << "Reading the file from the CREST server..." << std::endl; - - try - { - dto2 = myCrestClient.findTag(tagname); - std::cout << std::endl - << "tag (" << tagname << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the tag " << tagname - << " from the CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - js.erase("modificationTime"); - js2.erase("modificationTime"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - - bool res = patch.empty(); - if (res) { - std::cout << "Tag test passed successfully." << std::endl; - } - else { - std::cout << "Tag test failed." << std::endl; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(tag_meta_test){ - CrestClient myCrestClient = CrestClient(crest_server,false); - std::cout << std::endl << "2) Tag meta info test" << std::endl; - - PayloadSpecDto spec; - spec.add("ModuleId","UInt32"); - spec.add("ErrorCode","UInt32"); - spec.add("json","Blob64k"); - - std::string description = "<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>"; - TagInfoDto taginfo(description); - taginfo.setPayloadSpec(spec); - - ChannelSetDto chanset; - chanset.add("583008256",""); - chanset.add("583204864",""); - - taginfo.setChannel(chanset); - - std::string tag_description = "{\"dbname\":\"OFLP200\",\"nodeFullpath\":\"/TRIGGER/L1Calo/V1/Calibration/JfexModuleSettings\",\"schemaName\":\"COOLOFL_TRIGGER\"}"; - TagMetaDto dto(tagname,tag_description,taginfo); - nlohmann::json js = dto.to_json(); - - try - { - myCrestClient.createTagMeta(dto); - std::cout << "Tag meta info for tag " << tagname - << " created on the CREST server." - << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the tag meta info for tag " << tagname - << " on the CREST server" << std::endl; - std::cout << e.what() << std::endl; - } - - TagMetaDto dto2; - - std::cout << "Reading the tag meta from the CREST server..." << std::endl; - - try - { - dto2 = myCrestClient.findTagMeta(tagname); - std::cout << std::endl - << "tag meta (" << tagname << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the tag meta " << tagname - << " from the CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - - bool res = patch.empty(); - if (res) { - std::cout << "Tag meta info test passed successfully." << std::endl; - } - else { - std::cout << "Tag meta info test failed." << std::endl; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(global_tag_test){ - CrestClient myCrestClient = CrestClient(crest_server,false); - std::cout << std::endl << "3) Global Tag test" << std::endl; - - nlohmann::json js = - { - {"name", global_tag}, - {"validity", 0.0}, - {"description", "test"}, - {"release", "1"}, - {"insertionTime", "2018-12-18T11:32:58.081+0000"}, - {"snapshotTime", "2018-12-18T11:32:58+0000"}, - {"scenario", "test"}, - {"workflow", "M"}, - {"type", "t"}, - }; - - std::cout << "global tag (" << global_tag << ") =" << std::endl - << js.dump(4) << std::endl; - - GlobalTagDto dto = GlobalTagDto(); - dto = dto.from_json(js); - - try - { - myCrestClient.createGlobalTag(dto); - std::cout << "Global tag " << global_tag - << " created on the CREST server. " << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot create the global tag " << global_tag - << " on CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - GlobalTagDto dto2; - - std::cout << "Reading the global tag from the CREST server..." << std::endl; - - try - { - dto2 = myCrestClient.findGlobalTag(global_tag); - std::cout << std::endl - << "global tag (" << global_tag << ") = " << std::endl - << dto2.to_json().dump(4) << std::endl; - } - catch (const std::exception &e) - { - std::cout << "Error: Cannot get the global tag " << global_tag - << " from the CREST server." << std::endl; - std::cout << e.what() << std::endl; - } - - // create the patch - nlohmann::json js2 = dto2.to_json(); - js.erase("insertionTime"); - js2.erase("insertionTime"); - js.erase("modificationTime"); - js2.erase("modificationTime"); - js2.erase("insertionTimeMilli"); - js2.erase("snapshotTimeMilli"); - nlohmann::json patch = nlohmann::json::diff(js, js2); - std::cout << "global tag patch = " << std:: endl - << patch.dump(4) << std::endl; - - bool res = patch.empty(); - if (res) { - std::cout << "The global tag test passed successfully." << std::endl; - } - else { - std::cout << "The global tag test failed." << std::endl; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(global_tag_removing_test){ - CrestClient myCrestClient = CrestClient(crest_server,false); - std::cout << std::endl << "4) Global tag removing test" << std::endl; - bool res = true; - - try{ - myCrestClient.removeGlobalTag(global_tag); - std::cout << "The global tag " << global_tag << " was removed from CREST server." << std::endl; - } - catch (const CrestException& e) { - std::cout << "The global tag " << global_tag << " was not removed from server." << std::endl; - res = false; - } - - BOOST_TEST(res); - } - - - BOOST_AUTO_TEST_CASE(tag_removing_test){ - CrestClient myCrestClient = CrestClient(crest_server,false); - std::cout << std::endl << "5) Tag removing test" << std::endl; - bool res = true; - - try{ - myCrestClient.removeTag(tagname); - std::cout << "The tag " << tagname << " was removed from CREST server." << std::endl; - } - catch (const CrestException& e) { - std::cout << "Tag " << tagname << " was not removed from server." << std::endl; - res = false; - } - - BOOST_TEST(res); - } - -BOOST_AUTO_TEST_SUITE_END() - diff --git a/Database/CrestApi/test/json_parse.cxx b/Database/CrestApi/test/json_parse.cxx deleted file mode 100644 index 04ef4df11da06e33dc0dbc9818e67da34fad0eae..0000000000000000000000000000000000000000 --- a/Database/CrestApi/test/json_parse.cxx +++ /dev/null @@ -1,31 +0,0 @@ -#include <iostream> -#include <nlohmann/json.hpp> - -using json = nlohmann::json; - -#include <iomanip> - -int main() { - std::string jsonString = R"({ - "data": { - "0": [ - "[{\"stationEta\": -2, \"stationPhi\": 1, \"stationName\": 56, \"multiLayer\": 1, \"gasGap\": 1, \"pcbPos\": 6, \"indiv\": 0.0, \"extra\": 0.0, \"total\": 0.0, \"position\": \"right\", \"litmeasb\": 6}, {\"stationEta\": -2, \"stationPhi\": 1, \"stationName\": 56, \"multiLayer\": 1, \"gasGap\": 1, \"pcbPos\": 6, \"indiv\": 0.0, \"extra\": 0.0, \"total\": 0.0, \"position\": \"left\", \"litmeasb\": 6}, {\"stationEta\": -2, \"stationPhi\": 1, \"stationName\": 56, \"multiLayer\": 1, \"gasGap\": 1, \"pcbPos\": 7, \"indiv\": 0.0, \"extra\": 0.0, \"total\": 0.0, \"position\": \"right\", \"litmeasb\": 7}, {\"stationEta\": -2, \"stationPhi\": 1, \"stationName\": 56, \"multiLayer\": 1, \"gasGap\": 1, \"pcbPos\": 7, \"indiv\": 0.0, \"extra\": 0.0, \"total\": 0.0, \"position\": \"left\", \"litmeasb\": 7}]" - ] - } - })"; - - try { - json parsedJson = json::parse(jsonString); - - // Access the inner string and parse it as JSON - std::string innerString = parsedJson["data"]["0"][0]; - json innerJson = json::parse(innerString); - - // Print the parsed inner JSON - std::cout << "Parsed Inner JSON:\n" << std::setw(4) << innerJson << std::endl; - } catch (const std::exception& e) { - std::cerr << "Error parsing JSON: " << e.what() << std::endl; - } - - return 0; -} diff --git a/Database/CrestApi/test/test-json.cxx b/Database/CrestApi/test/test-json.cxx deleted file mode 100644 index e3093cafdf3202d495f1753f2eb9888399acbd12..0000000000000000000000000000000000000000 --- a/Database/CrestApi/test/test-json.cxx +++ /dev/null @@ -1,143 +0,0 @@ -#include <iostream> -#include <nlohmann/json.hpp> - -using json = nlohmann::json; - -#include <iomanip> - -int main() -{ - // create the different JSON values with default values - json j_null(json::value_t::null); - json j_boolean(json::value_t::boolean); - json j_number_integer(json::value_t::number_integer); - json j_number_float(json::value_t::number_float); - json j_object(json::value_t::object); - json j_array(json::value_t::array); - json j_string(json::value_t::string); - - // serialize the JSON values - std::cout << j_null << '\n'; - std::cout << j_boolean << '\n'; - std::cout << j_number_integer << '\n'; - std::cout << j_number_float << '\n'; - std::cout << j_object << '\n'; - std::cout << j_array << '\n'; - std::cout << j_string << '\n'; - - // create object from string literal - json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; - - // or even nicer with a raw string literal - auto j2 = R"( - { - "happy": true, - "pi": 3.141 - } - )"_json; - - float pi = j2["pi"]; - std::cout << pi << '\n'; - - //float rnd = random()/1000.; - double rnd = 3.015999999999; - std::cout << rnd << '\n'; - - // Create a pointer to the double - unsigned char* bytePtr = reinterpret_cast<unsigned char*>(&rnd); - - // Print the binary representation - std::cout << "Binary representation of double: "; - for (int i = sizeof(rnd) - 1; i >= 0; --i) { - std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(bytePtr[i]); - } - std::cout << std::endl; - - j2["pi"] = rnd; - std::cout << j2 << '\n'; - double rnd_json = j2["pi"]; - std::cout << "Binary representation of double read from json: "; - unsigned char* bytePtr2 = reinterpret_cast<unsigned char*>(&rnd_json); - for (int i = sizeof(rnd_json) - 1; i >= 0; --i) { - std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(bytePtr2[i]); - } - std::cout << std::endl; - auto j3 = R"( - { - "happy": true, - "pi": 3.015999999999 - } - )"_json; - double rnd_json_2 = j3["pi"]; - std::cout << "Binary representation of double read from json: "; - unsigned char* bytePtr3 = reinterpret_cast<unsigned char*>(&rnd_json_2); - for (int i = sizeof(rnd_json_2) - 1; i >= 0; --i) { - std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(bytePtr3[i]); - } - std::cout << std::endl; - - // Fill a json object with data - json j4; - j4["a_char"] = new char('c'); - j4["a_string"] = "string"; - j4["a_bool"] = true; - j4["a_int"] = 42; - j4["a_float"] = 3.141; - j4["a_null"] = nullptr; - j4["an_unsigned_int"] = 42u; - j4["an_unsigned_long"] = 42ul; - j4["an_unsigned_long_long"] = 42ull; - - std::cout << j4 << '\n'; - - // Read back data using iterators - for (json::iterator it = j4.begin(); it != j4.end(); ++it) { - std::cout << it.key() << " : " << it.value() << "\n"; - if (it.key() == "a_char") { - std::cout << "a_char is a char: " << it.value().is_string() << "\n"; - std::string a_str = it.value().get<std::string>(); - char a_char = a_str[0]; - std::cout << "a_char: " << a_char << "\n"; - } - if (it.key() == "a_string") { - std::cout << "a_string is a string: " << it.value().is_string() << "\n"; - std::string a_string = it.value().get<std::string>(); - std::cout << "a_string: " << a_string << "\n"; - } - if (it.key() == "a_bool") { - std::cout << "a_bool is a bool: " << it.value().is_boolean() << "\n"; - bool a_bool = it.value().get<bool>(); - std::cout << "a_bool: " << a_bool << "\n"; - } - if (it.key() == "a_int") { - std::cout << "a_int is an int: " << it.value().is_number_integer() << "\n"; - int a_int = it.value().get<int>(); - std::cout << "a_int: " << a_int << "\n"; - } - if (it.key() == "a_float") { - std::cout << "a_float is a float: " << it.value().is_number_float() << "\n"; - float a_float = it.value().get<float>(); - std::cout << "a_float: " << a_float << "\n"; - } - if (it.key() == "a_unsigned_int") { - std::cout << "a_unsigned_int is an unsigned int: " << it.value().is_number_unsigned() << "\n"; - unsigned int a_unsigned_int = it.value().get<unsigned int>(); - std::cout << "a_unsigned_int: " << a_unsigned_int << "\n"; - } - if (it.key() == "a_unsigned_long") { - std::cout << "a_unsigned_long is an unsigned long: " << it.value().is_number_unsigned() << "\n"; - unsigned long a_unsigned_long = it.value().get<unsigned long>(); - std::cout << "a_unsigned_long: " << a_unsigned_long << "\n"; - } - if (it.key() == "a_unsigned_long_long") { - std::cout << "a_unsigned_long_long is an unsigned long long: " << it.value().is_number_unsigned() << "\n"; - unsigned long long a_unsigned_long_long = it.value().get<unsigned long long>(); - std::cout << "a_unsigned_long_long: " << a_unsigned_long_long << "\n"; - } - if (it.key() == "a_null") { - std::cout << "a_null is null: " << it.value().is_null() << "\n"; - } - - } - -} diff --git a/Database/IOVDbSvc/CMakeLists.txt b/Database/IOVDbSvc/CMakeLists.txt index 2b57abbd5fbaab38ceca4c1ccd741a071947b23f..2ea3e4ee568bd62794b931aaa7fcf3dd2e3447ba 100644 --- a/Database/IOVDbSvc/CMakeLists.txt +++ b/Database/IOVDbSvc/CMakeLists.txt @@ -9,25 +9,28 @@ find_package( CORAL COMPONENTS CoralBase RelationalAccess ) find_package( ROOT COMPONENTS Core ) find_package( Boost COMPONENTS unit_test_framework regex timer program_options thread) find_package( nlohmann_json ) +find_package( CrestApi COMPONENTS CrestApi) # Component(s) in the package: atlas_add_library( IOVDbSvcLib IOVDbSvc/*.h INTERFACE PUBLIC_HEADERS IOVDbSvc - INCLUDE_DIRS ${COOL_INCLUDE_DIRS} - LINK_LIBRARIES ${COOL_LIBRARIES} GaudiKernel ) + INCLUDE_DIRS ${COOL_INCLUDE_DIRS} + LINK_LIBRARIES ${COOL_LIBRARIES} GaudiKernel) + atlas_add_component( IOVDbSvc src/*.h src/*.cxx src/components/*.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} CxxUtils + ${Boost_INCLUDE_DIRS} ${CrestApi_INCLUDE_DIRS} CxxUtils LINK_LIBRARIES ${ROOT_LIBRARIES} ${CORAL_LIBRARIES} ${COOL_LIBRARIES} ${Boost_LIBRARIES} nlohmann_json::nlohmann_json GaudiKernel AthenaBaseComps AthenaKernel StoreGateLib FileCatalog AthenaPoolUtilities CoraCool IOVDbDataModel EventInfoUtils GeoModelInterfaces IOVDbMetaDataToolsLib EventInfoMgtLib PoolSvcLib IOVDbSvcLib - CrestApiLib CxxUtils DBLock SGTools ) + CxxUtils DBLock SGTools CrestApi::CrestApiLib ) + # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8}) @@ -60,7 +63,7 @@ atlas_add_test( IOVDbConn_test SOURCES test/IOVDbConn_test.cxx src/IOVDbConn.cxx INCLUDE_DIRS ${COOL_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} LINK_LIBRARIES ${COOL_LIBRARIES} ${Boost_LIBRARIES} ${ROOT_LIBRARIES} - GaudiKernel CxxUtils TestTools CoraCool CrestApiLib + GaudiKernel CxxUtils TestTools CoraCool CrestApi::CrestApiLib POST_EXEC_SCRIPT "nopost.sh" ) atlas_add_test( IOVDbStringFunctions_test @@ -92,7 +95,7 @@ atlas_add_test( IOVDbCoolFunctions_test src/IOVDbConn.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} LINK_LIBRARIES ${Boost_LIBRARIES} ${COOL_LIBRARIES} ${CORAL_LIBRARIES} - GaudiKernel AthenaKernel CoraCool CrestApiLib + GaudiKernel AthenaKernel CoraCool CrestApi::CrestApiLib POST_EXEC_SCRIPT "nopost.sh" ) atlas_add_test( ReadFromFileMetaData_test @@ -112,13 +115,13 @@ atlas_add_test( IOVDbFolder_test src/ReadFromFileMetaData.cxx src/IOVDbCoolFunctions.cxx src/TagFunctions.cxx src/Cool2Json.cxx src/Base64Codec.cxx src/Json2Cool.cxx src/BasicFolder.cxx src/CrestFunctions.cxx src/IOVDbJsonStringFunctions.cxx - INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} - ${ROOT_INCLUDE_DIRS} + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} + ${ROOT_INCLUDE_DIRS} ${CrestApi_INCLUDE_DIRS} LINK_LIBRARIES ${Boost_LIBRARIES} ${COOL_LIBRARIES} ${CORAL_LIBRARIES} ${ROOT_LIBRARIES} nlohmann_json::nlohmann_json GaudiKernel AthenaKernel AthenaBaseComps StoreGateLib SGTools CxxUtils TestTools CoraCool AthenaPoolUtilities GeoModelInterfaces - IOVDbMetaDataToolsLib IOVDbDataModel EventInfoMgtLib CrestApiLib + IOVDbMetaDataToolsLib IOVDbDataModel EventInfoMgtLib CrestApi::CrestApiLib POST_EXEC_SCRIPT "nopost.sh" ) atlas_add_test( IovStore_test @@ -140,7 +143,7 @@ atlas_add_test( TagFunctions_test atlas_add_test( BasicFolder_test SOURCES test/BasicFolder_test.cxx src/BasicFolder.cxx src/IOVDbJsonStringFunctions.cxx src/FolderTypes.cxx src/IOVDbStringFunctions.cxx src/Base64Codec.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} CoralUtilities - LINK_LIBRARIES ${Boost_LIBRARIES} ${COOL_LIBRARIES} ${CORAL_LIBRARIES} AthenaPoolUtilities CrestApiLib + LINK_LIBRARIES ${Boost_LIBRARIES} ${COOL_LIBRARIES} ${CORAL_LIBRARIES} AthenaPoolUtilities CrestApi::CrestApiLib POST_EXEC_SCRIPT "nopost.sh" ) atlas_add_test( Json2Cool_test @@ -178,11 +181,12 @@ atlas_add_executable( cool_crest_compare src/FolderTypes.cxx src/IOVDbStringFunctions.cxx src/IOVDbParser.cxx src/IOVDbConn.cxx src/IovStore.cxx src/ReadFromFileMetaData.cxx src/IOVDbCoolFunctions.cxx src/TagFunctions.cxx src/Cool2Json.cxx src/Base64Codec.cxx src/Json2Cool.cxx src/BasicFolder.cxx src/CrestFunctions.cxx src/IOVDbJsonStringFunctions.cxx #src/*.cxx - INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} CoralUtilities + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${COOL_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} CoralUtilities ${CrestApi_INCLUDE_DIRS} LINK_LIBRARIES ${Boost_LIBRARIES} ${COOL_LIBRARIES} ${CORAL_LIBRARIES} ${ROOT_LIBRARIES} nlohmann_json::nlohmann_json GaudiKernel AthenaKernel AthenaBaseComps StoreGateLib SGTools CxxUtils TestTools CoraCool AthenaPoolUtilities GeoModelInterfaces - IOVDbMetaDataToolsLib IOVDbDataModel EventInfoMgtLib CrestApiLib + IOVDbMetaDataToolsLib IOVDbDataModel EventInfoMgtLib CrestApi::CrestApiLib ) endif() + diff --git a/Database/IOVDbSvc/src/CrestFunctions.cxx b/Database/IOVDbSvc/src/CrestFunctions.cxx index ffc1706c693f5dd6eb373f794e39c32369efb76c..7ffe769c2d6b7206b7f10195d164d6fb12c9009b 100644 --- a/Database/IOVDbSvc/src/CrestFunctions.cxx +++ b/Database/IOVDbSvc/src/CrestFunctions.cxx @@ -19,16 +19,18 @@ namespace IOVDbNamespace{ + using namespace Crest; + CrestFunctions::CrestFunctions(const std::string & crest_path){ setURLBase(crest_path); const std::string prefix1 = "http://"; const std::string prefix2 = "https://"; if (crest_path.starts_with(prefix1) || crest_path.starts_with(prefix2)){ - m_crestCl = std::unique_ptr<Crest::CrestClient>(new Crest::CrestClient(getURLBase())); + m_crestCl = std::unique_ptr<Crest::CrestApi>(new Crest::CrestApi(getURLBase())); } else{ - m_crestCl = std::unique_ptr<Crest::CrestFsClient>(new Crest::CrestFsClient(true,getURLBase())); + m_crestCl = std::unique_ptr<Crest::CrestApiFs>(new Crest::CrestApiFs(true,getURLBase())); } } @@ -71,7 +73,7 @@ namespace IOVDbNamespace{ try{ IovSetDto dto = m_crestCl->selectIovs(tag, 0, -1, 0, 10000, 0, "id.since:ASC"); - nlohmann::json iov_data = dto.to_json(); + nlohmann::json iov_data = dto.toJson(); nlohmann::json iov_list = getResources(iov_data); reply = iov_list.dump(); } catch (std::exception & e){ @@ -118,23 +120,24 @@ namespace IOVDbNamespace{ } - std::string + std::string CrestFunctions::folderDescriptionForTag(const std::string & tag){ - + std::string jsonReply = ""; - + TagMetaDto dto = m_crestCl->findTagMeta(tag); - jsonReply = dto.tagInfo.getFolderDescription(); + TagInfoDto tag_info_dto = dto.getTagInfoDto(); + jsonReply = tag_info_dto.getFolderDescription(); return jsonReply; } - + std::map<std::string, std::string> CrestFunctions::getGlobalTagMap(const std::string& globaltag){ std::map<std::string, std::string> tagmap; try{ GlobalTagMapSetDto dto = m_crestCl->findGlobalTagMap(globaltag,"Trace"); - nlohmann::json globaltag_map_data = dto.to_json(); + nlohmann::json globaltag_map_data = dto.toJson(); nlohmann::json j = getResources(globaltag_map_data); int n = j.size(); for (int i = 0; i < n; i++ ){ @@ -153,15 +156,10 @@ namespace IOVDbNamespace{ nlohmann::json CrestFunctions::getTagInfo(const std::string & tag){ try{ - TagMetaDto dto = m_crestCl->findTagMeta(tag); - nlohmann::json meta_info = dto.to_json(); - - if (meta_info.contains("tagInfo")){ - std::string metainf = meta_info["tagInfo"]; - nlohmann::json js = nlohmann::json::parse(metainf); - return js; - } - + TagMetaDto dto = m_crestCl->findTagMeta(tag); + TagInfoDto tag_info_dto = dto.getTagInfoDto(); + nlohmann::json tag_info = tag_info_dto.toJson(); + return tag_info; } catch (std::exception & e){ std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get a tag meta info " << tag << std::endl; } @@ -172,7 +170,7 @@ namespace IOVDbNamespace{ CrestFunctions::getTagProperties(const std::string & tag){ try{ TagDto dto = m_crestCl->findTag(tag); - return dto.to_json(); + return dto.toJson(); } catch (std::exception & e){ std::cerr<<__FILE__<<":"<<__LINE__<< ": " << e.what() << " Cannot get a tag Properties of " << tag << std::endl; } @@ -228,9 +226,9 @@ namespace IOVDbNamespace{ std::vector<uint64_t> v; try{ IovSetDto dto = m_crestCl->selectGroups(tag, 0, 10000, 0, "id.since:ASC"); - const std::vector<IovDto> & res = dto.resources; + const std::vector<IovDto> & res = dto.getResources(); for (const IovDto & item_iov: res){ - v.emplace_back(item_iov.since); + v.emplace_back(item_iov.getSince()); } } catch (std::exception & e){ std::cerr<<__FILE__<<":"<<__LINE__<< ": "<<e.what()<<" while trying to find the IOVs"<<std::endl; @@ -305,10 +303,10 @@ namespace IOVDbNamespace{ dto = m_crestCl->selectIovs(tag, s_time, u_time, 0, 10000, 0, "id.since:ASC"); } } - std::vector<IovDto> res = dto.resources; + std::vector<IovDto> res = dto.getResources(); std::map<uint64_t, std::string> hashmap; for (const IovDto & item: res) { - hashmap[item.since] = item.payloadHash; + hashmap[item.getSince()] = item.getPayloadHash(); } for (auto& t : hashmap){ iovHashPairs.emplace_back(std::to_string(t.first),t.second); diff --git a/Database/IOVDbSvc/src/IOVDbFolder.cxx b/Database/IOVDbSvc/src/IOVDbFolder.cxx index a4299e5554ce3857216f97903d92ba6ed30a1e1c..9ccc4abd59345a78b4488ce7c0511deb66078cbf 100644 --- a/Database/IOVDbSvc/src/IOVDbFolder.cxx +++ b/Database/IOVDbSvc/src/IOVDbFolder.cxx @@ -61,6 +61,8 @@ #include "IOVDbJsonStringFunctions.h" using namespace IOVDbNamespace; +using namespace cool; +using namespace Crest; namespace{ const std::string fileSuffix{".json"}; @@ -962,11 +964,11 @@ IOVDbFolder::preLoadFolder(ITagInfoMgr *tagInfoMgr , const unsigned int cacheRun crest_work_dir += "/crest_data"; bool crest_rewrite = true; - Crest::CrestFsClient crestFSClient = Crest::CrestFsClient(crest_rewrite, crest_work_dir); + Crest::CrestApiFs crestFSClient = Crest::CrestApiFs(crest_rewrite, crest_work_dir); try{ TagMetaDto dto = TagMetaDto(); - dto = dto.from_json(tag_meta); + dto = dto.fromJson(tag_meta); crestFSClient.createTagMeta(dto); ATH_MSG_INFO("Tag meta info for " << m_crestTag << " saved to disk."); @@ -1405,7 +1407,7 @@ std::vector<BasicFolder> IOVDbFolder::fetchCrestObjects(cool::ValidityKey since std::string crest_work_dir=std::filesystem::current_path(); crest_work_dir += "/crest_data"; bool crest_rewrite = true; - Crest::CrestFsClient crestFSClient = Crest::CrestFsClient(crest_rewrite, crest_work_dir); + Crest::CrestApiFs crestFSClient = Crest::CrestApiFs(crest_rewrite, crest_work_dir); nlohmann::json js = { @@ -1418,7 +1420,7 @@ std::vector<BasicFolder> IOVDbFolder::fetchCrestObjects(cool::ValidityKey since {"timeType", "time"}}; TagDto dto = TagDto(); - dto = dto.from_json(js); + dto = dto.fromJson(js); try{ crestFSClient.createTag(dto); @@ -1449,7 +1451,7 @@ std::vector<BasicFolder> IOVDbFolder::fetchCrestObjects(cool::ValidityKey since {"resources", jResources} }; - StoreSetDto storeSetDto = StoreSetDto::from_json(jsStoreSet); + StoreSetDto storeSetDto = StoreSetDto::fromJson(jsStoreSet); try{ crestFSClient.storeData(m_crestTag, storeSetDto, "JSON", "test", "test", "1", endtime); diff --git a/Projects/AthAnalysis/package_filters.txt b/Projects/AthAnalysis/package_filters.txt index eec3907ae59cf483afb2c66882bbe7cebd36ef1f..e85593e132ed628f1079b264f5e0dd0d7ccf888f 100644 --- a/Projects/AthAnalysis/package_filters.txt +++ b/Projects/AthAnalysis/package_filters.txt @@ -200,7 +200,6 @@ - Database/AthenaPOOL/AthenaPoolExample.* - Database/AthenaPOOL/.*Tools + Database/AthenaPOOL/.* -+ Database/CrestApi + Database/DBLock + Database/IOVDb.* + Database/PersistentDataModel.* diff --git a/Projects/AthGeneration/package_filters.txt b/Projects/AthGeneration/package_filters.txt index e2eece7450dcf2d81b203edb843bd4b0ff711053..02ccfd4332dfb9dc22a649a9adff297c682905cf 100644 --- a/Projects/AthGeneration/package_filters.txt +++ b/Projects/AthGeneration/package_filters.txt @@ -80,7 +80,6 @@ + Database/ConnectionManagement/DBReplicaSvc + Database/CoraCool + Database/DBLock -+ Database/CrestApi + Database/IOVDbAthenaPool + Database/IOVDbDataModel + Database/IOVDbMetaDataTools diff --git a/Projects/AthSimulation/package_filters.txt b/Projects/AthSimulation/package_filters.txt index 1df868c5b1148f0c16101dc05e3a84f81e8c3897..a49be2d7315a8a9bc4e8ee8d15c0d9ee1c087133 100644 --- a/Projects/AthSimulation/package_filters.txt +++ b/Projects/AthSimulation/package_filters.txt @@ -90,7 +90,6 @@ + Database/ConnectionManagement/DBReplicaSvc + Database/CoraCool + Database/DBLock -+ Database/CrestApi + Database/IOVDbAthenaPool + Database/IOVDbDataModel + Database/IOVDbMetaDataTools