From 21d4e64c32a08fbed96919dd3cd5b8cca60e8032 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Mon, 23 Sep 2019 17:15:19 +0200 Subject: [PATCH 1/7] Remove old classes of CCDB (does not compile yet) --- CCDB/CMakeLists.txt | 91 +- CCDB/config/conditions-client.json | 34 - CCDB/config/conditions-server.json | 55 - CCDB/example/fill_local_ocdb.C | 15 - CCDB/include/CCDB/Backend.h | 54 - CCDB/include/CCDB/BackendOCDB.h | 46 - CCDB/include/CCDB/BackendRiak.h | 52 - CCDB/include/CCDB/Condition.h | 209 -- CCDB/include/CCDB/ConditionId.h | 186 -- CCDB/include/CCDB/ConditionMetaData.h | 111 - CCDB/include/CCDB/ConditionsMQClient.h | 50 - CCDB/include/CCDB/ConditionsMQServer.h | 56 - CCDB/include/CCDB/FileStorage.h | 159 -- CCDB/include/CCDB/GridStorage.h | 225 -- CCDB/include/CCDB/IdRunRange.h | 87 - CCDB/include/CCDB/LocalStorage.h | 140 -- CCDB/include/CCDB/Manager.h | 396 ---- CCDB/include/CCDB/ObjectHandler.h | 33 - CCDB/include/CCDB/Storage.h | 176 -- CCDB/include/CCDB/XmlHandler.h | 96 - CCDB/src/Backend.cxx | 36 - CCDB/src/BackendOCDB.cxx | 53 - CCDB/src/BackendRiak.cxx | 145 -- CCDB/src/CCDBLinkDef.h | 23 - CCDB/src/Condition.cxx | 114 - CCDB/src/ConditionId.cxx | 153 -- CCDB/src/ConditionMetaData.cxx | 121 -- CCDB/src/ConditionsMQClient.cxx | 120 -- CCDB/src/ConditionsMQServer.cxx | 190 -- CCDB/src/FileStorage.cxx | 755 ------- CCDB/src/GridStorage.cxx | 1460 ------------- CCDB/src/IdRunRange.cxx | 95 - CCDB/src/LocalStorage.cxx | 1184 ----------- CCDB/src/Manager.cxx | 1864 ----------------- CCDB/src/ObjectHandler.cxx | 59 - CCDB/src/Storage.cxx | 522 ----- CCDB/src/XmlHandler.cxx | 140 -- CCDB/src/request.proto | 13 - CCDB/src/runConditionsClient.cxx | 31 - CCDB/src/runConditionsServer.cxx | 35 - CCDB/test/TestClass.h | 20 - CCDB/test/testCcdbApi.cxx | 4 +- CCDB/test/testQueryServerStandalone.cxx | 69 - CCDB/test/testWriteReadAny.cxx | 49 - .../TPC/base/include/TPCBase/CDBInterface.h | 1 - .../EventVisualisationView/EventManager.h | 6 +- EventVisualisation/View/src/EventManager.cxx | 1 - 47 files changed, 21 insertions(+), 9513 deletions(-) delete mode 100644 CCDB/config/conditions-client.json delete mode 100644 CCDB/config/conditions-server.json delete mode 100644 CCDB/example/fill_local_ocdb.C delete mode 100644 CCDB/include/CCDB/Backend.h delete mode 100644 CCDB/include/CCDB/BackendOCDB.h delete mode 100644 CCDB/include/CCDB/BackendRiak.h delete mode 100644 CCDB/include/CCDB/Condition.h delete mode 100644 CCDB/include/CCDB/ConditionId.h delete mode 100644 CCDB/include/CCDB/ConditionMetaData.h delete mode 100644 CCDB/include/CCDB/ConditionsMQClient.h delete mode 100644 CCDB/include/CCDB/ConditionsMQServer.h delete mode 100644 CCDB/include/CCDB/FileStorage.h delete mode 100644 CCDB/include/CCDB/GridStorage.h delete mode 100644 CCDB/include/CCDB/IdRunRange.h delete mode 100644 CCDB/include/CCDB/LocalStorage.h delete mode 100644 CCDB/include/CCDB/Manager.h delete mode 100644 CCDB/include/CCDB/ObjectHandler.h delete mode 100644 CCDB/include/CCDB/Storage.h delete mode 100644 CCDB/include/CCDB/XmlHandler.h delete mode 100644 CCDB/src/Backend.cxx delete mode 100644 CCDB/src/BackendOCDB.cxx delete mode 100644 CCDB/src/BackendRiak.cxx delete mode 100644 CCDB/src/Condition.cxx delete mode 100644 CCDB/src/ConditionId.cxx delete mode 100644 CCDB/src/ConditionMetaData.cxx delete mode 100644 CCDB/src/ConditionsMQClient.cxx delete mode 100644 CCDB/src/ConditionsMQServer.cxx delete mode 100644 CCDB/src/FileStorage.cxx delete mode 100644 CCDB/src/GridStorage.cxx delete mode 100644 CCDB/src/IdRunRange.cxx delete mode 100644 CCDB/src/LocalStorage.cxx delete mode 100644 CCDB/src/Manager.cxx delete mode 100644 CCDB/src/ObjectHandler.cxx delete mode 100644 CCDB/src/Storage.cxx delete mode 100644 CCDB/src/XmlHandler.cxx delete mode 100644 CCDB/src/request.proto delete mode 100644 CCDB/src/runConditionsClient.cxx delete mode 100644 CCDB/src/runConditionsServer.cxx delete mode 100644 CCDB/test/TestClass.h delete mode 100644 CCDB/test/testQueryServerStandalone.cxx delete mode 100644 CCDB/test/testWriteReadAny.cxx diff --git a/CCDB/CMakeLists.txt b/CCDB/CMakeLists.txt index b1eee289d9d3b..a9ae493662f2b 100644 --- a/CCDB/CMakeLists.txt +++ b/CCDB/CMakeLists.txt @@ -9,86 +9,25 @@ # submit itself to any jurisdiction. o2_add_library(CCDB - SOURCES src/Backend.cxx - src/BackendOCDB.cxx - src/BackendRiak.cxx - src/Condition.cxx - src/ConditionId.cxx - src/ConditionMetaData.cxx - src/FileStorage.cxx - src/GridStorage.cxx - src/IdPath.cxx - src/IdRunRange.cxx - src/LocalStorage.cxx - src/Manager.cxx - src/ObjectHandler.cxx - src/Storage.cxx - src/XmlHandler.cxx - src/CcdbApi.cxx - src/ConditionsMQServer.cxx - src/ConditionsMQClient.cxx - src/BasicCCDBManager.cxx - src/CCDBTimeStampUtils.cxx - src/request.proto - PUBLIC_LINK_LIBRARIES FairMQ::FairMQ - protobuf::libprotobuf - ROOT::Hist - ROOT::XMLParser - O2::CommonUtils - FairRoot::ParMQ - O2::Device - CURL::libcurl - Boost::thread + SOURCES src/CcdbApi.cxx + src/BasicCCDBManager.cxx + src/CCDBTimeStampUtils.cxx + src/IdPath.cxx + PUBLIC_LINK_LIBRARIES CURL::libcurl + FairRoot::ParMQ + ROOT::Hist + O2::Device + O2::CommonUtils + FairMQ::FairMQ TARGETVARNAME targetName) -protobuf_generate(TARGET ${targetName}) - o2_target_root_dictionary(CCDB - HEADERS include/CCDB/Backend.h - include/CCDB/BackendOCDB.h - include/CCDB/BackendRiak.h - include/CCDB/Condition.h - include/CCDB/ConditionId.h - include/CCDB/ConditionMetaData.h - include/CCDB/FileStorage.h - include/CCDB/GridStorage.h - include/CCDB/IdPath.h - include/CCDB/IdRunRange.h - include/CCDB/LocalStorage.h - include/CCDB/Manager.h - include/CCDB/ObjectHandler.h - include/CCDB/Storage.h - include/CCDB/XmlHandler.h - include/CCDB/TObjectWrapper.h + HEADERS include/CCDB/CcdbApi.h - include/CCDB/BasicCCDBManager.h - include/CCDB/CCDBTimeStampUtils.h - test/TestClass.h) - -o2_add_executable(conditions-server - SOURCES src/runConditionsServer.cxx - COMPONENT_NAME ccdb - PUBLIC_LINK_LIBRARIES O2::CCDB) - -o2_add_executable(conditions-client - SOURCES src/runConditionsClient.cxx - COMPONENT_NAME ccdb - PUBLIC_LINK_LIBRARIES O2::CCDB) - -o2_add_executable(standalone-client - SOURCES test/testQueryServerStandalone.cxx - COMPONENT_NAME ccdb - PUBLIC_LINK_LIBRARIES O2::CCDB) - -o2_data_file(COPY config/conditions-server.json config/conditions-client.json - example/fill_local_ocdb.C - DESTINATION config) - -o2_add_test(WriteReadAny - SOURCES test/testWriteReadAny.cxx - COMPONENT_NAME ccdb - PUBLIC_LINK_LIBRARIES O2::CCDB - LABELS ccdb) + include/CCDB/TObjectWrapper.h + include/CCDB/IdPath.h + include/CCDB/BasicCCDBManager.h + include/CCDB/CCDBTimeStampUtils.h) o2_add_test(CcdbApi SOURCES test/testCcdbApi.cxx diff --git a/CCDB/config/conditions-client.json b/CCDB/config/conditions-client.json deleted file mode 100644 index c7a5942ce81aa..0000000000000 --- a/CCDB/config/conditions-client.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "fairMQOptions": - { - "devices": - [{ - "id": "parmq-client", - "channels": - [{ - "name": "data-put", - "sockets": - [{ - "type": "push", - "method": "connect", - "address": "tcp://localhost:25005", - "sndBufSize": "200", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - },{ - "name": "data-get", - "sockets": - [{ - "type": "req", - "method": "connect", - "address": "tcp://localhost:25006", - "sndBufSize": "1000", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - }] - }] - } -} - diff --git a/CCDB/config/conditions-server.json b/CCDB/config/conditions-server.json deleted file mode 100644 index a5a59680d5d18..0000000000000 --- a/CCDB/config/conditions-server.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "fairMQOptions": - { - "devices": - [{ - "id": "parmq-server", - "channels": - [{ - "name": "data-put", - "sockets": - [{ - "type": "pull", - "method": "bind", - "address": "tcp://*:25005", - "sndBufSize": "1000", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - },{ - "name": "data-get", - "sockets": - [{ - "type": "rep", - "method": "bind", - "address": "tcp://*:25006", - "sndBufSize": "1000", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - },{ - "name": "broker-put", - "sockets": - [{ - "type": "push", - "method": "connect", - "address": "tcp://127.0.0.1:5558", - "sndBufSize": "1000", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - },{ - "name": "broker-get", - "sockets": - [{ - "type": "req", - "method": "connect", - "address": "tcp://127.0.0.1:5559", - "sndBufSize": "1000", - "rcvBufSize": "1000", - "rateLogging": "0" - }] - }] - }] - } -} diff --git a/CCDB/example/fill_local_ocdb.C b/CCDB/example/fill_local_ocdb.C deleted file mode 100644 index 969952e0fc764..0000000000000 --- a/CCDB/example/fill_local_ocdb.C +++ /dev/null @@ -1,15 +0,0 @@ -void fill_local_ocdb() -{ - o2::ccdb::Manager* cdb = o2::ccdb::Manager::Instance(); - cdb->setDefaultStorage("local://O2CDB"); - TH1F* h = 0; - for (int run = 2000; run < 2100; run++) { - cdb->setRun(run); - h = new TH1F(Form("histo for %d run", run), "gauss", 100, -5, 5); - h->FillRandom("gaus", 1000); - o2::ccdb::ConditionId* id = new o2::ccdb::ConditionId("DET/Calib/Histo", run, run, 1, 0); - o2::ccdb::ConditionMetaData* md = new o2::ccdb::ConditionMetaData(); - cdb->putObject(h, *id, md); - h = 0; - } -} diff --git a/CCDB/include/CCDB/Backend.h b/CCDB/include/CCDB/Backend.h deleted file mode 100644 index d91b72afd3e0d..0000000000000 --- a/CCDB/include/CCDB/Backend.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file Backend.h -/// \brief Definition of the Backend class -/// \author Charis Kouzinopoulos - -#ifndef ALICE_O2_BACKEND_H_ -#define ALICE_O2_BACKEND_H_ - -#include -#include - -#if !(defined(__CLING__) || defined(__ROOTCLING__)) -#include -#endif - -// Google protocol buffers headers -#include - -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class Backend -{ - public: - virtual ~Backend() = default; - - /// Pack - virtual void Pack(const std::string& path, const std::string& key, std::string*& messageString) = 0; - - /// UnPack -#if !(defined(__CLING__) || defined(__ROOTCLING__)) - virtual Condition* UnPack(std::unique_ptr msg) = 0; -#endif - - /// Serializes a key (and optionally value) to an std::string using Protocol Buffers - void Serialize(std::string*& messageString, const std::string& key, const std::string& operationType, - const std::string& dataSource, const std::string& object = std::string()); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/BackendOCDB.h b/CCDB/include/CCDB/BackendOCDB.h deleted file mode 100644 index 9b115b25166d3..0000000000000 --- a/CCDB/include/CCDB/BackendOCDB.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file BackendOCDB.h -/// \brief Definition of the BackendOCDB class -/// \author Charis Kouzinopoulos - -#ifndef ALICE_O2_BACKENDOCDB_H_ -#define ALICE_O2_BACKENDOCDB_H_ - -#include "CCDB/Backend.h" - -#include -#include - -namespace o2 -{ -namespace ccdb -{ - -class BackendOCDB : public Backend -{ - - private: - public: - BackendOCDB(); - ~BackendOCDB() override = default; - - /// Prepares an object before transmission to CCDB server - void Pack(const std::string& path, const std::string& key, std::string*& messageString) override; - - /// Parses an incoming message from the CCDB server and prints the metadata of the included object -#if !(defined(__CLING__) || defined(__ROOTCLING__)) - Condition* UnPack(std::unique_ptr msg) override; -#endif -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/BackendRiak.h b/CCDB/include/CCDB/BackendRiak.h deleted file mode 100644 index be686add25047..0000000000000 --- a/CCDB/include/CCDB/BackendRiak.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file BackendRiak.h -/// \brief Definition of the BackendRiak class -/// \author Charis Kouzinopoulos - -#ifndef ALICE_O2_BACKENDRIAK_H_ -#define ALICE_O2_BACKENDRIAK_H_ - -#include "CCDB/Backend.h" - -namespace o2 -{ -namespace ccdb -{ - -class BackendRiak : public Backend -{ - - private: - /// Deserializes a message and stores the value to an std::string using Protocol Buffers - void Deserialize(const std::string& messageString, std::string& object); - - /// Compresses uncompressed_string to compressed_string using zlib - void Compress(const std::string& uncompressed_string, std::string& compressed_string); - - /// Decompresses compressed_string to uncompressed_string using zlib - void Decompress(std::string& uncompressed_string, const std::string& compressed_string); - - public: - BackendRiak(); - ~BackendRiak() override = default; - - /// Compresses and serializes an object prior to transmission to server - void Pack(const std::string& path, const std::string& key, std::string*& messageString) override; - - /// Deserializes and uncompresses an incoming message from the CCDB server -#if !(defined(__CLING__) || defined(__ROOTCLING__)) - Condition* UnPack(std::unique_ptr msg) override; -#endif -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/Condition.h b/CCDB/include/CCDB/Condition.h deleted file mode 100644 index 50b7fd726c37f..0000000000000 --- a/CCDB/include/CCDB/Condition.h +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file Condition.h -/// \brief Definition of the Condition class (CDB object) containing the condition and its metadata - -#ifndef ALICEO2_CDB_ENTRY_H_ -#define ALICEO2_CDB_ENTRY_H_ - -#include "CCDB/ConditionId.h" // for ConditionId -#include "CCDB/ConditionMetaData.h" // for ConditionMetaData -#include "CCDB/IdPath.h" // for IdPath -#include -#include "Rtypes.h" // for Int_t, kFALSE, Bool_t, etc -#include "TObject.h" // for TObject -#include "TString.h" // for TString - -namespace o2 -{ -namespace ccdb -{ -class IdRunRange; -} -} // namespace o2 - -namespace o2 -{ -namespace ccdb -{ - -/// Class containing the condition (a ROOT TObject) and the metadata identifying it (ConditionId) -/// An instance of this class is a CDB object and has a specified run-range validity, version -/// and subversion. These metadata are both building the file name of the CDB object and are -/// contained in the metadata. -class Condition : public TObject -{ - - public: - /// Default constructor - Condition(); - - /// Constructor - Condition(TObject* object, const ConditionId& id, ConditionMetaData* metaData, Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, ConditionMetaData* metaData, - Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, Int_t version, - ConditionMetaData* metaData, - Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion, - ConditionMetaData* metaData, Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, ConditionMetaData* metaData, - Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, - ConditionMetaData* metaData, - Bool_t owner = kFALSE); - - /// Constructor - Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion, - ConditionMetaData* metaData, Bool_t owner = kFALSE); - - /// Default destructor - ~Condition() override; - - /// Set the object identity from an ConditionId - void setId(const ConditionId& id) - { - mId = id; - }; - - /// ConditionId accessor - ConditionId& getId() - { - return mId; - }; - - /// ConditionId accessor - const ConditionId& getId() const - { - return mId; - }; - - /// Print the identifier fields - void printId() const; - - /// Setter of the TObject data member - void setObject(TObject* object) - { - mObject = object; - }; - - /// Getter of the TObject data member - TObject* getObject() - { - return mObject; - }; - - /// Getter of the TObject data member - const TObject* getObject() const - { - return mObject; - }; - - /// retrieve object as specified type - /// return false if failed/true otherwise - template - bool getObjectAs(T*& obj) - { - obj = nullptr; - // test if saved object was a wrapped object - if (auto wrapped = dynamic_cast*>(mObject)) { - obj = wrapped->getObj(); - return true; - } - return false; - } - - void setConditionMetaData(ConditionMetaData* metaData) - { - mConditionMetaData = metaData; - }; - - ConditionMetaData* getConditionMetaData() - { - return mConditionMetaData; - }; - - const ConditionMetaData* getConditionMetaData() const - { - return mConditionMetaData; - }; - - void printConditionMetaData() const - { - mConditionMetaData->printConditionMetaData(); - } - - /// Getter of the TObject data member - void setOwner(Bool_t owner) - { - mOwner = owner; - }; - - /// Getter of the TObject data member - Bool_t isOwner() const - { - return mOwner; - }; - - /// Setter of the version - void setVersion(Int_t version) - { - mId.setVersion(version); - } - - /// Setter of the subversion - void setSubVersion(Int_t subVersion) - { - mId.setSubVersion(subVersion); - } - - /// Getter of the last storage where the CDB object was before the current one - const TString getLastStorage() const - { - return mId.getLastStorage(); - }; - - /// Getter of the last storage where the CDB object was before the current one - void setLastStorage(TString lastStorage) - { - mId.setLastStorage(lastStorage); - }; - - /// Method to compare two CDB objects, used for sorting in ROOT ordered containers - Int_t Compare(const TObject* obj) const override; - - /// Define this class sortable (via the Compare method) for ROOT ordered containers - Bool_t IsSortable() const override; - - private: - Condition(const Condition& other); // no copy ctor - void operator=(const Condition& other); // no assignment op - - TObject* mObject; ///< The actual condition, a ROOT TObject - ConditionId mId; ///< The condition identifier - ConditionMetaData* mConditionMetaData; ///< metaData - Bool_t mOwner; ///< Ownership flag - - ClassDefOverride(Condition, 1); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/ConditionId.h b/CCDB/include/CCDB/ConditionId.h deleted file mode 100644 index dfb4b5b48cf3f..0000000000000 --- a/CCDB/include/CCDB/ConditionId.h +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_OBJECTID_H_ -#define ALICEO2_CDB_OBJECTID_H_ - -// Identity of an object stored into a database: // -// path, run validity range, version, subVersion // -#include // for TObject -#include "CCDB/IdPath.h" // for IdPath -#include "CCDB/IdRunRange.h" // for IdRunRange -#include "Rtypes.h" // for Int_t, Bool_t, ConditionId::Class, ClassDef, etc -#include "TString.h" // for TString - -namespace o2 -{ -namespace ccdb -{ - -class ConditionId : public TObject -{ - - public: - ConditionId(); - - ConditionId(const ConditionId& other); - - ConditionId(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - ConditionId(const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t verison = -1, Int_t subVersion = -1); - - static ConditionId* makeFromString(const TString& idString); - - ~ConditionId() override; - - const IdPath& getPath() const - { - return mPath; - } - - const TString& getPathString() const - { - return mPath.getPathString(); - } - - const TString getPathLevel(Int_t i) const - { - return mPath.getLevel(i); - } - - Bool_t isWildcard() const - { - return mPath.isWildcard(); - } - - void setPath(const char* path) - { - mPath.setPath(path); - } - - const IdRunRange& getIdRunRange() const - { - return mIdRunRange; - } - - IdRunRange& getIdRunRange() - { - return mIdRunRange; - } - - Int_t getFirstRun() const - { - return mIdRunRange.getFirstRun(); - } - - Int_t getLastRun() const - { - return mIdRunRange.getLastRun(); - } - - void setFirstRun(Int_t firstRun) - { - mIdRunRange.setFirstRun(firstRun); - } - - void setLastRun(Int_t lastRun) - { - mIdRunRange.setLastRun(lastRun); - } - - void setIdRunRange(Int_t firstRun, Int_t lastRun) - { - mIdRunRange.setIdRunRange(firstRun, lastRun); - } - - Bool_t isAnyRange() const - { - return mIdRunRange.isAnyRange(); - } - - Int_t getVersion() const - { - return mVersion; - } - - Int_t getSubVersion() const - { - return mSubVersion; - } - - void setVersion(Int_t version) - { - mVersion = version; - } - - void setSubVersion(Int_t subVersion) - { - mSubVersion = subVersion; - } - - const TString& getLastStorage() const - { - return mLastStorage; - } - - void setLastStorage(TString& lastStorage) - { - mLastStorage = lastStorage; - } - - Bool_t isValid() const; - - Bool_t isSpecified() const - { - return !(isWildcard() || isAnyRange()); - } - - Bool_t hasVersion() const - { - return mVersion >= 0; - } - - Bool_t hasSubVersion() const - { - return mSubVersion >= 0; - } - - Bool_t isSupersetOf(const ConditionId& other) const - { - return mPath.isSupersetOf(other.mPath) && mIdRunRange.isSupersetOf(other.mIdRunRange); - } - - virtual Bool_t isEqual(const TObject* obj) const; - - TString ToString() const; - - void print(Option_t* option = "") const; - - Int_t Compare(const TObject* obj) const override; - - Bool_t IsSortable() const override; - - const char* GetName() const override - { - return mPath.getPathString().Data(); - } - - private: - IdPath mPath; // path - IdRunRange mIdRunRange; // run range - Int_t mVersion; // version - Int_t mSubVersion; // subversion - TString mLastStorage; // previous storage place (new, grid, local, dump) - - ClassDefOverride(ConditionId, 1); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/ConditionMetaData.h b/CCDB/include/CCDB/ConditionMetaData.h deleted file mode 100644 index edc0e3b07a566..0000000000000 --- a/CCDB/include/CCDB/ConditionMetaData.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALI_META_DATA_H -#define ALI_META_DATA_H - -#include // for TMap -#include // for TObject -#include "Rtypes.h" // for UInt_t, ConditionMetaData::Class, Bool_t, etc -#include "TString.h" // for TString - -namespace o2 -{ -namespace ccdb -{ -// Set of data describing the object // -// but not used to identify the object // - -class ConditionMetaData : public TObject -{ - - public: - ConditionMetaData(); - - ConditionMetaData(const char* responsible, UInt_t beamPeriod = 0, const char* alirootVersion = "", - const char* comment = ""); - - ~ConditionMetaData() override; - - void setObjectClassName(const char* name) - { - mObjectClassName = name; - }; - - const char* getObjectClassName() const - { - return mObjectClassName.Data(); - }; - - void setResponsible(const char* yourName) - { - mResponsible = yourName; - }; - - const char* getResponsible() const - { - return mResponsible.Data(); - }; - - void setBeamPeriod(UInt_t period) - { - mBeamPeriod = period; - }; - - UInt_t getBeamPeriod() const - { - return mBeamPeriod; - }; - - void setAliRootVersion(const char* version) - { - mAliRootVersion = version; - }; - - const char* getAliRootVersion() const - { - return mAliRootVersion.Data(); - }; - - void setComment(const char* comment) - { - mComment = comment; - }; - - const char* getComment() const - { - return mComment.Data(); - }; - - void addDateToComment(); - - void setProperty(const char* property, TObject* object); - - TObject* getProperty(const char* property) const; - - Bool_t removeProperty(const char* property); - - void printConditionMetaData(); - - private: - TString mObjectClassName; // object's class name - TString mResponsible; // object's responsible person - UInt_t mBeamPeriod; // beam period - TString mAliRootVersion; // AliRoot version - TString mComment; // extra comments - // TList mCalibRuns; - - TMap mProperties; // list of object specific properties - - ClassDefOverride(ConditionMetaData, 1); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/ConditionsMQClient.h b/CCDB/include/CCDB/ConditionsMQClient.h deleted file mode 100644 index 8e1ca0524804f..0000000000000 --- a/CCDB/include/CCDB/ConditionsMQClient.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/** - * ConditionsMQClient.h - * - * @since 2016-01-11 - * @author R. Grosso, C. Kouzinopoulos from examples/MQ/7-parameters/FairMQExample7Client.h - */ - -#ifndef ALICEO2_CDB_CONDITIONSMQCLIENT_H_ -#define ALICEO2_CDB_CONDITIONSMQCLIENT_H_ - -#include - -#include - -namespace o2 -{ -namespace ccdb -{ - -class ConditionsMQClient : public FairMQDevice -{ - public: - ConditionsMQClient(); - ~ConditionsMQClient() override; - - protected: - void InitTask() override; - void Run() override; - - private: - int mRunId; - std::string mParameterName; - std::string mOperationType; - std::string mDataSource; - std::string mObjectPath; -}; -} // namespace ccdb -} // namespace o2 - -#endif /* ALICEO2_CDB_CONDITIONSMQCLIENT_H_ */ diff --git a/CCDB/include/CCDB/ConditionsMQServer.h b/CCDB/include/CCDB/ConditionsMQServer.h deleted file mode 100644 index 3cb1c4cffed31..0000000000000 --- a/CCDB/include/CCDB/ConditionsMQServer.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/** - * ConditionsMQServer.h - * - * @since 2016-01-11 - * @author R. Grosso, C. Kouzinopoulos from parmq/ParameterMQServer.h - */ - -#ifndef ALICEO2_CDB_CONDITIONSMQSERVER_H_ -#define ALICEO2_CDB_CONDITIONSMQSERVER_H_ - -#include - -#include "CCDB/Manager.h" -#include "ParameterMQServer.h" - -namespace o2 -{ -namespace ccdb -{ - -class ConditionsMQServer : public ParameterMQServer -{ - public: - ConditionsMQServer(); - - ~ConditionsMQServer() override; - - void Run() override; - - void InitTask() override; - - private: - Manager* mCdbManager; - - void getFromOCDB(std::string key); - - /// Parses a serialized message for a data source entry - void ParseDataSource(std::string& dataSource, const std::string& data); - - /// Deserializes a message and stores the value to an std::string using Protocol Buffers - void Deserialize(const std::string& messageString, std::string& key); -}; -} // namespace ccdb -} // namespace o2 - -#endif /* ALICEO2_CDB_CONDITIONSMQSERVER_H_ */ diff --git a/CCDB/include/CCDB/FileStorage.h b/CCDB/include/CCDB/FileStorage.h deleted file mode 100644 index 978d124a93d16..0000000000000 --- a/CCDB/include/CCDB/FileStorage.h +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_FILEDUMP_H_ -#define ALICEO2_CDB_FILEDUMP_H_ - -#include "CCDB/Manager.h" // for StorageFactory, StorageParameters -#include "Rtypes.h" // for Bool_t, Int_t, ClassDef, kFALSE, etc -#include "CCDB/Storage.h" // for Storage -#include "TString.h" // for TString - -class TFile; // lines 8-8 -class TList; - -class TObject; - -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class ConditionId; - -class IdRunRange; - -class FileStorage : public Storage -{ - friend class FileStorageFactory; - - public: - Bool_t isReadOnly() const override - { - return mReadOnly; - }; - - Bool_t hasSubVersion() const override - { - return kFALSE; - }; - - Bool_t hasConditionType(const char* path) const override; - - Bool_t idToFilename(const ConditionId& id, TString& filename) const override; - - void setRetry(Int_t /* nretry */, Int_t /* initsec */) override; - - protected: - Condition* getCondition(const ConditionId& query) override; - - ConditionId* getConditionId(const ConditionId& query) override; - - TList* getAllEntries(const ConditionId& query) override; - - Bool_t putCondition(Condition* entry, const char* mirrors = "") override; - - TList* getIdListFromFile(const char* fileName) override; - - private: - FileStorage(const FileStorage& source); - - FileStorage& operator=(const FileStorage& source); - - FileStorage(const char* dbFile, Bool_t readOnly); - - ~FileStorage() override; - - Bool_t keyNameToId(const char* keyname, IdRunRange& runRange, Int_t& version, Int_t& subVersion); - - Bool_t idToKeyName(const IdRunRange& runRange, Int_t version, Int_t subVersion, TString& keyname); - - Bool_t makeDir(const TString& dir); - - Bool_t prepareId(ConditionId& id); - - // Bool_t getId(const ConditionId& query, ConditionId& result); - ConditionId* getId(const ConditionId& query); - - void queryValidFiles() override; - - void getEntriesForLevel0(const ConditionId& query, TList* result); - - void getEntriesForLevel1(const ConditionId& query, TList* result); - - TFile* mFile; // FileStorage file - Bool_t mReadOnly; // ReadOnly flag - - ClassDefOverride(FileStorage, 0); -}; - -///////////////////////////////////////////////////////////////////// -// // -// class FileStorageFactory // -// // -///////////////////////////////////////////////////////////////////// - -class FileStorageFactory : public StorageFactory -{ - - public: - Bool_t validateStorageUri(const char* dbString) override; - - StorageParameters* createStorageParameter(const char* dbString) override; - - protected: - Storage* createStorage(const StorageParameters* param) override; - - ClassDefOverride(FileStorageFactory, 0); -}; - -///////////////////////////////////////////////////////////////////// -// // -// class FileStorageParameters // -// // -///////////////////////////////////////////////////////////////////// - -class FileStorageParameters : public StorageParameters -{ - - public: - FileStorageParameters(); - - FileStorageParameters(const char* dbPath, Bool_t readOnly = kFALSE); - - ~FileStorageParameters() override; - - const TString& getPathString() const - { - return mDBPath; - }; - - Bool_t isReadOnly() const - { - return mReadOnly; - }; - - StorageParameters* cloneParam() const override; - - virtual ULong_t getHash() const; - - virtual Bool_t isEqual(const TObject* obj) const; - - private: - TString mDBPath; // FileStorage file path name - Bool_t mReadOnly; // ReadOnly flag - - ClassDefOverride(FileStorageParameters, 0); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/GridStorage.h b/CCDB/include/CCDB/GridStorage.h deleted file mode 100644 index 4fa95ab51e948..0000000000000 --- a/CCDB/include/CCDB/GridStorage.h +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_GRID_H_ -#define ALICEO2_CDB_GRID_H_ - -#include "CCDB/Manager.h" // for StorageFactory, StorageParameters -#include "Rtypes.h" // for Bool_t, Long64_t, Long_t, Int_t, ClassDef, etc -#include "CCDB/Storage.h" // for Storage -#include "TString.h" // for TString - -class TFile; - -class TList; - -class TObjArray; - -class TObject; - -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class ConditionId; - -class ConditionMetaData; - -class GridStorage : public Storage -{ - friend class GridStorageFactory; - - public: - Bool_t isReadOnly() const override - { - return kFALSE; - } - - Bool_t hasSubVersion() const override - { - return kFALSE; - } - - Bool_t hasConditionType(const char* path) const override; - - Bool_t idToFilename(const ConditionId& id, TString& filename) const override; - - void setRetry(Int_t nretry, Int_t initsec) override; - - void setMirrorSEs(const char* mirrors) override - { - mMirrorSEs = mirrors; - } - - const char* getMirrorSEs() const override - { - return mMirrorSEs; - } - - protected: - Condition* getCondition(const ConditionId& queryId) override; - - ConditionId* getConditionId(const ConditionId& queryId) override; - - TList* getAllEntries(const ConditionId& queryId) override; - - Bool_t putCondition(Condition* entry, const char* mirrors = "") override; - - TList* getIdListFromFile(const char* fileName) override; - - private: - GridStorage(const char* gridUrl, const char* user, const char* dbFolder, const char* se, const char* cacheFolder, - Bool_t operateDisconnected, Long64_t cacheSize, Long_t cleanupInterval); - - ~GridStorage() override; - - GridStorage(const GridStorage& db); - - GridStorage& operator=(const GridStorage& db); - - Bool_t filenameToId(TString& filename, ConditionId& id); - - Bool_t prepareId(ConditionId& id); - - ConditionId* getId(const TObjArray& validFileIds, const ConditionId& query); - - Condition* getConditionFromFile(TString& filename, ConditionId* dataId); - - Bool_t putInCvmfs(TString& fullFilename, TFile* cdbFile) const; - - // TODO use AliEnTag classes! - Bool_t addTag(TString& foldername, const char* tagname); - - Bool_t tagFileId(TString& filename, const ConditionId* id); - - Bool_t tagFileConditionMetaData(TString& filename, const ConditionMetaData* md); - - void makeQueryFilter(Int_t firstRun, Int_t lastRun, const ConditionMetaData* md, TString& result) const; - - void queryValidFiles() override; - - TString mGridUrl; // GridStorage Url ("alien://aliendb4.cern.ch:9000") - TString mUser; // User - TString mDBFolder; // path of the DB folder - TString mSE; // Storage Element - TString mMirrorSEs; // Mirror Storage Elements - TString mCacheFolder; // local cache folder - Bool_t mOperateDisconnected; // Operate disconnected flag - Long64_t mCacheSize; // local cache size (in bytes) - Long_t mCleanupInterval; // local cache cleanup interval - - ClassDefOverride(GridStorage, 0); // access class to a DataBase in an AliEn storage -}; - -///////////////////////////////////////////////////////////////////// -// // -// class GridStorageFactory // -// // -///////////////////////////////////////////////////////////////////// - -class GridStorageFactory : public StorageFactory -{ - - public: - Bool_t validateStorageUri(const char* gridString) override; - - StorageParameters* createStorageParameter(const char* gridString) override; - - ~GridStorageFactory() - override = default; - - protected: - Storage* createStorage(const StorageParameters* param) override; - - ClassDefOverride(GridStorageFactory, 0); -}; - -///////////////////////////////////////////////////////////////////// -// // -// class GridStorageParameters // -// // -///////////////////////////////////////////////////////////////////// - -class GridStorageParameters : public StorageParameters -{ - - public: - GridStorageParameters(); - - GridStorageParameters(const char* gridUrl, const char* user, const char* dbFolder, const char* se, - const char* cacheFolder, - Bool_t operateDisconnected, Long64_t cacheSize, Long_t cleanupInterval); - - ~GridStorageParameters() override; - - const TString& GridUrl() const - { - return mGridUrl; - } - - const TString& getUser() const - { - return mUser; - } - - const TString& getDBFolder() const - { - return mDBFolder; - } - - const TString& getSE() const - { - return mSE; - } - - const TString& getCacheFolder() const - { - return mCacheFolder; - } - - Bool_t getOperateDisconnected() const - { - return mOperateDisconnected; - } - - Long64_t getCacheSize() const - { - return mCacheSize; - } - - Long_t getCleanupInterval() const - { - return mCleanupInterval; - } - - StorageParameters* cloneParam() const override; - - virtual ULong_t getHash() const; - - virtual Bool_t isEqual(const TObject* obj) const; - - private: - TString mGridUrl; // GridStorage url "Host:port" - TString mUser; // User - TString mDBFolder; // path of the DB folder - TString mSE; // Storage Element - TString mCacheFolder; // Cache folder - Bool_t mOperateDisconnected; // Operate disconnected flag - Long64_t mCacheSize; // local cache size (in bytes) - Long_t mCleanupInterval; // local cache cleanup interval - - ClassDefOverride(GridStorageParameters, 0); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/IdRunRange.h b/CCDB/include/CCDB/IdRunRange.h deleted file mode 100644 index 5725cb35bb6c8..0000000000000 --- a/CCDB/include/CCDB/IdRunRange.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_RUNRANGE_H_ -#define ALICEO2_CDB_RUNRANGE_H_ - -// defines the run validity range of the object: // -// [mFirstRun, mLastRun] // -#include // for TObject -#include "Rtypes.h" // for Int_t, Bool_t, IdRunRange::Class, ClassDef, etc - -namespace o2 -{ -namespace ccdb -{ -class IdRunRange : public TObject -{ - - public: - IdRunRange(); - - IdRunRange(Int_t firstRun, Int_t lastRun); - - ~IdRunRange() override; - - Int_t getFirstRun() const - { - return mFirstRun; - }; - - Int_t getLastRun() const - { - return mLastRun; - }; - - void setFirstRun(Int_t firstRun) - { - mFirstRun = firstRun; - }; - - void setLastRun(Int_t lastRun) - { - mLastRun = lastRun; - }; - - void setIdRunRange(Int_t firstRun, Int_t lastRun) - { - mFirstRun = firstRun; - mLastRun = lastRun; - }; - - Bool_t isValid() const; - - Bool_t isAnyRange() const - { - return mFirstRun < 0 && mLastRun < 0; - }; - - Bool_t isOverlappingWith(const IdRunRange& other) const; - - Bool_t isSupersetOf(const IdRunRange& other) const; - - virtual Bool_t isEqual(const TObject* obj) const; - - static Int_t Infinity() - { - return sInfinity; - } - - private: - Int_t mFirstRun; // first valid run - Int_t mLastRun; // last valid run - - static const Int_t sInfinity = 999999999; //! Flag for "infinity" - - ClassDefOverride(IdRunRange, 1); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/LocalStorage.h b/CCDB/include/CCDB/LocalStorage.h deleted file mode 100644 index 0db8af96e1b69..0000000000000 --- a/CCDB/include/CCDB/LocalStorage.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_LOCAL_H_ -#define ALICEO2_CDB_LOCAL_H_ - -// class LocalStorage // -// access class to a DataBase in a local storage // -#include "CCDB/Manager.h" // for StorageFactory, StorageParameters -#include "Rtypes.h" // for Bool_t, Int_t, ClassDef, LocalStorage::Class, etc -#include "CCDB/Storage.h" // for Storage -#include "TString.h" // for TString - -class TList; - -class TObject; - -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class ConditionId; - -class IdRunRange; - -class LocalStorage : public Storage -{ - friend class LocalStorageFactory; - - public: - Bool_t isReadOnly() const override - { - return kFALSE; - }; - - Bool_t hasSubVersion() const override - { - return kTRUE; - }; - - Bool_t hasConditionType(const char* path) const override; - - Bool_t idToFilename(const ConditionId& id, TString& filename) const override; - - void setRetry(Int_t /* nretry */, Int_t /* initsec */) override; - - protected: - Condition* getCondition(const ConditionId& queryId) override; - - ConditionId* getConditionId(const ConditionId& queryId) override; - - TList* getAllEntries(const ConditionId& queryId) override; - - Bool_t putCondition(Condition* entry, const char* mirrors = "") override; - - TList* getIdListFromFile(const char* fileName) override; - - private: - LocalStorage(const LocalStorage& source); - - LocalStorage& operator=(const LocalStorage& source); - - LocalStorage(const char* baseDir); - - ~LocalStorage() override; - - Bool_t filenameToId(const char* filename, IdRunRange& runRange, Int_t& version, Int_t& subVersion); - - Bool_t prepareId(ConditionId& id); - - // Bool_t getId(const ConditionId& query, ConditionId& result); - ConditionId* getId(const ConditionId& query); - - void queryValidFiles() override; - - void queryValidCVMFSFiles(TString& cvmfsOcdbTag); - - void getEntriesForLevel0(const char* level0, const ConditionId& query, TList* result); - - void getEntriesForLevel1(const char* level0, const char* Level1, const ConditionId& query, TList* result); - - TString mBaseDirectory; // path of the DB folder - - ClassDefOverride(LocalStorage, 0); // access class to a DataBase in a local storage -}; - -// class LocalStorageFactory -class LocalStorageFactory : public StorageFactory -{ - public: - Bool_t validateStorageUri(const char* dbString) override; - - StorageParameters* createStorageParameter(const char* dbString) override; - - protected: - Storage* createStorage(const StorageParameters* param) override; - - ClassDefOverride(LocalStorageFactory, 0); -}; - -// class LocalStorageParameters -class LocalStorageParameters : public StorageParameters -{ - public: - LocalStorageParameters(); - - LocalStorageParameters(const char* dbPath); - - LocalStorageParameters(const char* dbPath, const char* uri); - - ~LocalStorageParameters() override; - - const TString& getPathString() const - { - return mDBPath; - }; - - StorageParameters* cloneParam() const override; - - virtual ULong_t getHash() const; - - virtual Bool_t isEqual(const TObject* obj) const; - - private: - TString mDBPath; // path of the DB folder - ClassDefOverride(LocalStorageParameters, 0); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/Manager.h b/CCDB/include/CCDB/Manager.h deleted file mode 100644 index 58383f5b0597e..0000000000000 --- a/CCDB/include/CCDB/Manager.h +++ /dev/null @@ -1,396 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_MANAGER_H_ -#define ALICEO2_CDB_MANAGER_H_ - -#include // for TList -#include // for TMap -#include // for TObject -#include // for NULL -#include "Rtypes.h" // for Int_t, Bool_t, kFALSE, kTRUE, ClassDef, etc -#include "TString.h" // for TString -#include - -class TFile; - -/// @file Manager.h -/// @author Raffaele Grosso -/// @since 2014-12-02 -/// @brief Adapted to o2 from the original AliCDBManager.h in AliRoot -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class ConditionId; - -class ConditionMetaData; - -class IdPath; - -class IdRunRange; - -class Storage; - -class StorageFactory; - -class StorageParameters; - -/// @class Manager -/// Steer retrieval and upload of condition objects from/to -/// different storages (local, alien, file) - -class Manager : public TObject -{ - - public: - void registerFactory(StorageFactory* factory); - - Bool_t hasStorage(const char* dbString) const; - - StorageParameters* createStorageParameter(const char* dbString) const; - - Storage* getStorage(const char* dbString); - - TList* getActiveStorages(); - - const TMap* getStorageMap() const - { - return mStorageMap; - } - - const TList* getRetrievedIds() const - { - return mIds; - } - - void setDefaultStorage(const char* dbString); - - void setDefaultStorage(const StorageParameters* param); - - void setDefaultStorage(Storage* storage); - - void setDefaultStorageFromRun(Int_t run); - - Bool_t isDefaultStorageSet() const - { - return mDefaultStorage != nullptr; - } - - Storage* getDefaultStorage() const - { - return mDefaultStorage; - } - - void unsetDefaultStorage(); - - void setSpecificStorage(const char* calibType, const char* dbString, Int_t version = -1, Int_t subVersion = -1); - - Storage* getSpecificStorage(const char* calibType); - - void setdrainMode(const char* dbString); - - void setdrainMode(const StorageParameters* param); - - void setdrainMode(Storage* storage); - - void unsetdrainMode() - { - mdrainStorage = nullptr; - } - - Bool_t isdrainSet() const - { - return mdrainStorage != nullptr; - } - - Bool_t drain(Condition* entry); - - Bool_t setOcdbUploadMode(); - - void unsetOcdbUploadMode() - { - mOcdbUploadMode = kFALSE; - } - - Bool_t isOcdbUploadMode() const - { - return mOcdbUploadMode; - } - - Condition* getCondition(const ConditionId& query, Bool_t forceCaching = kFALSE); - - Condition* getCondition(const IdPath& path, Int_t runNumber = -1, Int_t version = -1, Int_t subVersion = -1); - - Condition* getCondition(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - Condition* getConditionFromSnapshot(const char* path); - - const char* getUri(const char* path); - - TList* getAllObjects(const ConditionId& query); - - TList* getAllObjects(const IdPath& path, Int_t runNumber = -1, Int_t version = -1, Int_t subVersion = -1); - - TList* getAllObjects(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - Bool_t putObject(TObject* object, const ConditionId& id, ConditionMetaData* metaData, const char* mirrors = ""); - - template - Bool_t putObjectAny(T* ptr, const ConditionId& id, ConditionMetaData* metaData, const char* mirrors = "") - { - TObjectWrapper local(ptr); - return putObject(&local, id, metaData, mirrors); - } - - Bool_t putCondition(Condition* entry, const char* mirrors = ""); - - void setCacheFlag(Bool_t cacheFlag) - { - mCache = cacheFlag; - } - - Bool_t getCacheFlag() const - { - return mCache; - } - - ULong64_t setLock(Bool_t lockFlag = kTRUE, ULong64_t key = 0); - - Bool_t getLock() const - { - return mLock; - } - - void setRawFlag(Bool_t rawFlag) - { - mRaw = rawFlag; - } - - Bool_t getRawFlag() const - { - return mRaw; - } - - void setRun(Int_t run); - - Int_t getRun() const - { - return mRun; - } - - void setMirrorSEs(const char* mirrors); - - const char* getMirrorSEs() const; - - void destroyActiveStorages(); - - void destroyActiveStorage(Storage* storage); - - void queryStorages(); - - void print(Option_t* option = "") const; - - static void destroy(); - - ~Manager() override; - - void clearCache(); - - void unloadFromCache(const char* path); - - const TMap* getConditionCache() const - { - return &mConditionCache; - } - - static Manager* Instance(TMap* entryCache = nullptr, Int_t run = -1); - - void init(); - - void initFromCache(TMap* entryCache, Int_t run); - - Bool_t initFromSnapshot(const char* snapshotFileName, Bool_t overwrite = kTRUE); - - Bool_t setSnapshotMode(const char* snapshotFileName = "OCDB.root"); - - void unsetSnapshotMode() - { - mSnapshotMode = kFALSE; - } - - void dumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const; - - void dumpToLightSnapshotFile(const char* lightSnapshotFileName) const; - - Int_t getStartRunLHCPeriod(); - - Int_t getEndRunLHCPeriod(); - - TString getLHCPeriod(); - - TString getCvmfsOcdbTag() const - { - return mCvmfsOcdb; - } - - Bool_t diffObjects(const char* cdbFile1, const char* cdbFile2) const; - - void extractBaseFolder(TString& url); // remove everything but the url from OCDB path - - protected: - static TString sOcdbFolderXmlFile; // alien path of the XML file for OCDB folder <--> Run range correspondance - - Manager(); - - Manager(const Manager& source); - - Manager& operator=(const Manager& source); - - static Manager* sInstance; // Manager instance - - Storage* getStorage(const StorageParameters* param); - - Storage* getActiveStorage(const StorageParameters* param); - - void putActiveStorage(StorageParameters* param, Storage* storage); - - void setSpecificStorage(const char* calibType, const StorageParameters* param, Int_t version = -1, - Int_t subVersion = -1); - - void alienToCvmfsUri(TString& uriString) const; - - void validateCvmfsCase() const; - - void getLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun); - - void getLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun); - - void cacheCondition(const char* path, Condition* entry); - - StorageParameters* selectSpecificStorage(const TString& path); - - ConditionId* getId(const ConditionId& query); - - ConditionId* getId(const IdPath& path, Int_t runNumber = -1, Int_t version = -1, Int_t subVersion = -1); - - ConditionId* getId(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - TList mFactories; //! list of registered storage factories - TMap mActiveStorages; //! list of active storages - TMap mSpecificStorages; //! list of detector-specific storages - TMap mConditionCache; //! cache of the retrieved objects - - TList* mIds; //! List of the retrieved object ConditionId's (to be streamed to file) - TMap* mStorageMap; //! list of storages (to be streamed to file) - - Storage* mDefaultStorage; //! pointer to default storage - Storage* mdrainStorage; //! pointer to drain storage - - StorageParameters* mOfficialStorageParameters; // Conditions data storage parameters - StorageParameters* mReferenceStorageParameters; // Reference data storage parameters - - Int_t mRun; //! The run number - Bool_t mCache; //! The cache flag - Bool_t mLock; //! Lock flag, if ON default storage and run number cannot be reset - - Bool_t mSnapshotMode; //! flag saying if we are in snapshot mode - TFile* mSnapshotFile; - Bool_t mOcdbUploadMode; //! flag for uploads to Official CDBs (upload to cvmfs must follow upload - // to AliEn) - - Bool_t mRaw; // flag to say whether we are in the raw case - TString mCvmfsOcdb; // set from $OCDB_PATH, points to a cvmfs AliRoot package - Int_t mStartRunLhcPeriod; // 1st run of the LHC period set - Int_t mEndRunLhcPeriod; // last run of the LHC period set - TString mLhcPeriod; // LHC period alien folder - - private: - ULong64_t mKey; //! Key for locking/unlocking - - ClassDefOverride(Manager, 0); -}; - -///////////////////////////////////////////////////////////////////// -// // -// class StorageFactory // -// // -///////////////////////////////////////////////////////////////////// - -class StorageParameters; - -class StorageFactory : public TObject -{ - friend class Manager; - - public: - ~StorageFactory() - override = default; - - virtual Bool_t validateStorageUri(const char* dbString) = 0; - - virtual StorageParameters* createStorageParameter(const char* dbString) = 0; - - protected: - virtual Storage* createStorage(const StorageParameters* param) = 0; - - ClassDefOverride(StorageFactory, 0); -}; - -///////////////////////////////////////////////////////////////////// -// // -// class StorageParameters // -// // -///////////////////////////////////////////////////////////////////// - -class StorageParameters : public TObject -{ - - public: - StorageParameters(); - - ~StorageParameters() override; - - const TString& getStorageType() const - { - return mType; - }; - - const TString& getUri() const - { - return mURI; - }; - - virtual StorageParameters* cloneParam() const = 0; - - protected: - void setType(const char* type) - { - mType = type; - }; - - void setUri(const char* uri) - { - mURI = uri; - }; - - private: - TString mType; //! CDB type - TString mURI; //! CDB URI - - ClassDefOverride(StorageParameters, 0); -}; - -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/ObjectHandler.h b/CCDB/include/CCDB/ObjectHandler.h deleted file mode 100644 index 61cdcb7965f75..0000000000000 --- a/CCDB/include/CCDB/ObjectHandler.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICE_O2_OBJECTHANDLER_H_ -#define ALICE_O2_OBJECTHANDLER_H_ - -#include -#include - -namespace o2 -{ -namespace ccdb -{ - -class ObjectHandler -{ - public: - ObjectHandler(); - virtual ~ObjectHandler(); - - /// Returns the binary payload of a ROOT file as an std::string - static void GetObject(const std::string& path, std::string& object); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/Storage.h b/CCDB/include/CCDB/Storage.h deleted file mode 100644 index bf4204b86cf9b..0000000000000 --- a/CCDB/include/CCDB/Storage.h +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICEO2_CDB_STORAGE_H_ -#define ALICEO2_CDB_STORAGE_H_ - -// interface to specific storage classes // -// ( GridStorage, LocalStorage, FileStorage) // -#include // for TList -#include // for TObjArray -#include "CCDB/IdPath.h" // for IdPath -#include "Rtypes.h" // for Int_t, Bool_t, Short_t, Storage::Class, etc -#include "TObject.h" // for TObject -#include "TString.h" // for TString - -class TFile; - -namespace o2 -{ -namespace ccdb -{ - -class Condition; - -class ConditionId; - -class ConditionMetaData; - -class IdRunRange; - -class IdPath; - -class Param; - -class Storage : public TObject -{ - - public: - Storage(); - - void setUri(const TString& uri) - { - mURI = uri; - } - - const TString& getUri() const - { - return mURI; - } - - const TString& getStorageType() const - { - return mType; - } - - const TString& getBaseFolder() const - { - return mBaseFolder; - } - - void readSelectionFromFile(const char* fileName); - - void addSelection(const ConditionId& selection); - - void addSelection(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion = -1); - - void addSelection(const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion = -1); - - void removeSelection(const ConditionId& selection); - - void removeSelection(const IdPath& path, const IdRunRange& runRange); - - void removeSelection(const IdPath& path, Int_t firstRun = -1, Int_t lastRun = -1); - - void removeSelection(int position); - - void removeAllSelections(); - - void printSelectionList(); - - Condition* getObject(const ConditionId& query); - - Condition* getObject(const IdPath& path, Int_t runNumber, Int_t version = -1, Int_t subVersion = -1); - - Condition* getObject(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - TList* getAllObjects(const ConditionId& query); - - TList* getAllObjects(const IdPath& path, Int_t runNumber, Int_t version = -1, Int_t subVersion = -1); - - TList* getAllObjects(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - ConditionId* getId(const ConditionId& query); - - ConditionId* getId(const IdPath& path, Int_t runNumber, Int_t version = -1, Int_t subVersion = -1); - - ConditionId* getId(const IdPath& path, const IdRunRange& runRange, Int_t version = -1, Int_t subVersion = -1); - - Bool_t putObject(TObject* object, ConditionId& id, ConditionMetaData* metaData, const char* mirrors = ""); - - Bool_t putObject(Condition* entry, const char* mirrors = ""); - - virtual void setMirrorSEs(const char* mirrors); - - virtual const char* getMirrorSEs() const; - - virtual Bool_t isReadOnly() const = 0; - - virtual Bool_t hasSubVersion() const = 0; - - virtual Bool_t hasConditionType(const char* path) const = 0; - - virtual Bool_t idToFilename(const ConditionId& id, TString& filename) const = 0; - - void - queryStorages(Int_t run, const char* pathFilter = "*", Int_t version = -1, ConditionMetaData* mdFilter = nullptr); - - void printrQueryStorages(); - - TObjArray* getQueryStoragesList() - { - return &mValidFileIds; - } - - virtual void setRetry(Int_t nretry, Int_t initsec) = 0; - - protected: - ~Storage() override; - - void getSelection(/*const*/ ConditionId* id); - - virtual Condition* getCondition(const ConditionId& query) = 0; - - virtual ConditionId* getConditionId(const ConditionId& query) = 0; - - virtual TList* getAllEntries(const ConditionId& query) = 0; - - virtual Bool_t putCondition(Condition* entry, const char* mirrors = "") = 0; - - virtual TList* getIdListFromFile(const char* fileName) = 0; - - virtual void queryValidFiles() = 0; - - void loadTreeFromFile(Condition* entry) const; - // void setTreeToFile( Condition* entry, TFile* file) const; - - TObjArray mValidFileIds; // list of ConditionId's of the files valid for a given run (cached as mRun) - Int_t mRun; // run number, used to manage list of valid files - IdPath mPathFilter; // path filter, used to manage list of valid files - Int_t mVersion; // version, used to manage list of valid files - ConditionMetaData* mConditionMetaDataFilter; // metadata, used to manage list of valid files - - TList mSelections; // list of selection criteria - TString mURI; // storage URI; - TString mType; //! LocalStorage, GridStorage: base folder name - Dump: file name - TString mBaseFolder; //! LocalStorage, GridStorage: base folder name - Dump: file name - Short_t mNretry; // Number of retries in opening the file - Short_t mInitRetrySeconds; // Seconds for first retry - - private: - Storage(const Storage& source); - - Storage& operator=(const Storage& source); - - ClassDefOverride(Storage, 0); -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/include/CCDB/XmlHandler.h b/CCDB/include/CCDB/XmlHandler.h deleted file mode 100644 index 023b340522d8a..0000000000000 --- a/CCDB/include/CCDB/XmlHandler.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef ALICE_O2_XML_HANDLER_H_ -#define ALICE_O2_XML_HANDLER_H_ -// The SAX XML file handler used by the OCDB Manager // -// get the OCDB Folder <-> Run Range correspondance // - -#include // for TObject -#include "Rtypes.h" // for Int_t, XmlHandler::Class, ClassDef, etc -#include "TString.h" // for TString - -class TList; - -#include // for NULL - -namespace o2 -{ -namespace ccdb -{ - -class IdRunRange; - -class XmlHandler : public TObject -{ - - public: - XmlHandler(); - - XmlHandler(Int_t run); - - XmlHandler(const XmlHandler& sh); - - ~XmlHandler() override; - - XmlHandler& operator=(const XmlHandler& sh); - - // functions to interface to TSAXHandler - void OnStartDocument(); - - void OnEndDocument(); - - void OnStartElement(const char* name, const TList* attributes); - - void OnEndElement(const char* name); - - void OnCharacters(const char* name); - - void OnComment(const char* name); - - void OnWarning(const char* name); - - void OnError(const char* name); - - void OnFatalError(const char* name); - - void OnCdataBlock(const char* name, Int_t len); - - Int_t getStartIdRunRange() const - { - return mStartIdRunRange; - } - - Int_t getEndIdRunRange() const - { - return mEndIdRunRange; - } - - TString getOcdbFolder() const - { - return mOCDBFolder; - } - - void setRun(Int_t run) - { - mRun = run; - } - - private: - Int_t mRun; // run for which the LHC Period Folder has to be found - Int_t mStartIdRunRange; // start run corresponding to the request - Int_t mEndIdRunRange; // end run corresponding to the request - TString mOCDBFolder; // OCDB folder corresponding to the request - - ClassDefOverride(XmlHandler, 0); // The XML file handler for the OCDB -}; -} // namespace ccdb -} // namespace o2 -#endif diff --git a/CCDB/src/Backend.cxx b/CCDB/src/Backend.cxx deleted file mode 100644 index b092f54358902..0000000000000 --- a/CCDB/src/Backend.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file Backend.cxx -/// \brief Implementation of the Backend class -/// \author Charis Kouzinopoulos - -#include "CCDB/Backend.h" -#include "request.pb.h" - -using namespace o2::ccdb; -using namespace std; - -void Backend::Serialize(std::string*& messageString, const std::string& key, const std::string& operationType, - const std::string& dataSource, const std::string& object /*= std::vector()*/) -{ - messaging::RequestMessage* requestMessage = new messaging::RequestMessage; - requestMessage->set_command(operationType); - requestMessage->set_datasource(dataSource); - requestMessage->set_key(key); - - if (object.length() > 0) { - requestMessage->set_value(object); - } - - requestMessage->SerializeToString(messageString); - - delete requestMessage; -} diff --git a/CCDB/src/BackendOCDB.cxx b/CCDB/src/BackendOCDB.cxx deleted file mode 100644 index b21f1fdad72c9..0000000000000 --- a/CCDB/src/BackendOCDB.cxx +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file BackendOCDB.cxx -/// \brief Implementation of the BackendOCDB class -/// \author Charis Kouzinopoulos - -#include "CCDB/BackendOCDB.h" -#include "CCDB/Condition.h" -#include "CCDB/ObjectHandler.h" - -#include "TMessage.h" - -#include - -#include -#include - -using namespace o2::ccdb; -using namespace std; - -// special class to expose protected TMessage constructor -class WrapTMessage : public TMessage -{ - public: - WrapTMessage(void* buf, Int_t len) : TMessage(buf, len) - { - ResetBit(kIsOwner); - } -}; - -BackendOCDB::BackendOCDB() = default; - -void BackendOCDB::Pack(const std::string& path, const std::string& key, std::string*& messageString) -{ - LOG(ERROR) << "The PUT operation is not supported for the OCDB backend yet"; -} - -Condition* BackendOCDB::UnPack(std::unique_ptr msg) -{ - WrapTMessage tmsg(msg->GetData(), msg->GetSize()); - Condition* aCondition = (Condition*)(tmsg.ReadObject(tmsg.GetClass())); - LOG(DEBUG) << "Received a condition from the server:"; - aCondition->printConditionMetaData(); - return aCondition; -} diff --git a/CCDB/src/BackendRiak.cxx b/CCDB/src/BackendRiak.cxx deleted file mode 100644 index 151925e26a722..0000000000000 --- a/CCDB/src/BackendRiak.cxx +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file BackendRiak.cxx -/// \brief Implementation of the BackendRiak class -/// \author Charis Kouzinopoulos - -#include "CCDB/BackendRiak.h" -#include "CCDB/ObjectHandler.h" -#include "request.pb.h" - -#include - -#include - -using namespace o2::ccdb; -using namespace std; - -BackendRiak::BackendRiak() = default; - -// Compression/decompression code taken from https://panthema.net/2007/0328-ZLibString.html - -void BackendRiak::Compress(const std::string& uncompressed_string, std::string& compressed_string) -{ - // z_stream is zlib's control structure - z_stream zs; - memset(&zs, 0, sizeof(zs)); - - if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK) { - LOG(ERROR) << "deflateInit failed while compressing"; - } - - zs.next_in = (Bytef*)uncompressed_string.data(); - zs.avail_in = uncompressed_string.size(); - - int ret; - char outbuffer[32768]; - std::string outstring; - - // Get the compressed bytes in blocks of 32768 bytes using repeated calls to deflate - do { - zs.next_out = reinterpret_cast(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = deflate(&zs, Z_FINISH); - - if (outstring.size() < zs.total_out) { - // append the block to the output string - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - } while (ret == Z_OK); - - deflateEnd(&zs); - - if (ret != Z_STREAM_END) { - LOG(ERROR) << "Exception during zlib compression: (" << ret << ") " << zs.msg; - } - - compressed_string.assign(outstring); -} - -void BackendRiak::Decompress(std::string& uncompressed_string, const std::string& compressed_string) -{ - // z_stream is zlib's control structure - z_stream zs; - memset(&zs, 0, sizeof(zs)); - - if (inflateInit(&zs) != Z_OK) { - LOG(ERROR) << "deflateInit failed while decompressing"; - } - - zs.next_in = (Bytef*)compressed_string.data(); - zs.avail_in = compressed_string.size(); - - int ret; - char outbuffer[32768]; - std::string outstring; - - // Get the decompressed bytes in blocks of 32768 bytes using repeated calls to inflate - do { - zs.next_out = reinterpret_cast(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = inflate(&zs, 0); - - if (outstring.size() < zs.total_out) { - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - } while (ret == Z_OK); - - inflateEnd(&zs); - - if (ret != Z_STREAM_END) { - LOG(ERROR) << "Exception during zlib compression: (" << ret << ") " << zs.msg; - } - - uncompressed_string.assign(outstring); -} - -void BackendRiak::Deserialize(const std::string& messageString, std::string& object) -{ - messaging::RequestMessage* requestMessage = new messaging::RequestMessage; - requestMessage->ParseFromString(messageString); - - object.assign(requestMessage->value()); - - delete requestMessage; -} - -void BackendRiak::Pack(const std::string& path, const std::string& key, std::string*& messageString) -{ - // Load the AliCDBEntry object from disk - std::string object; - ObjectHandler::GetObject(path, object); - - // Compress the object before storing to Riak - std::string compressed_object; - Compress(object, compressed_object); - - Serialize(messageString, key, "PUT", "Riak", compressed_object); -} - -Condition* BackendRiak::UnPack(std::unique_ptr msg) -{ - // FIXME: how to actually extract a condition or a binary blob here? - std::string brokerString(static_cast(msg->GetData()), msg->GetSize()); - - // Deserialize the received string - std::string compressedObject; - Deserialize(brokerString, compressedObject); - - // Decompress the compressed object - std::string object; - Decompress(object, compressedObject); - - // nullptr since no other possibility at moment - return nullptr; -} diff --git a/CCDB/src/CCDBLinkDef.h b/CCDB/src/CCDBLinkDef.h index a42fad5394d74..b24ca906e3aa4 100644 --- a/CCDB/src/CCDBLinkDef.h +++ b/CCDB/src/CCDBLinkDef.h @@ -15,29 +15,6 @@ #pragma link off all functions; #pragma link C++ class o2::ccdb::IdPath + ; -#pragma link C++ class o2::ccdb::IdRunRange + ; -#pragma link C++ class o2::ccdb::ConditionId + ; -#pragma link C++ class o2::ccdb::ConditionMetaData + ; -#pragma link C++ class o2::ccdb::Condition + ; -#pragma link C++ class o2::ccdb::Storage + ; -#pragma link C++ class o2::ccdb::StorageFactory + ; -#pragma link C++ class o2::ccdb::Manager + ; -#pragma link C++ class o2::ccdb::StorageParameters + ; -#pragma link C++ class o2::ccdb::LocalStorage + ; -#pragma link C++ class o2::ccdb::LocalStorageFactory + ; -#pragma link C++ class o2::ccdb::LocalStorageParameters + ; -#pragma link C++ class o2::ccdb::FileStorage + ; -#pragma link C++ class o2::ccdb::FileStorageFactory + ; -#pragma link C++ class o2::ccdb::FileStorageParameters + ; -#pragma link C++ class o2::ccdb::GridStorage + ; -#pragma link C++ class o2::ccdb::GridStorageFactory + ; -#pragma link C++ class o2::ccdb::GridStorageParameters + ; -#pragma link C++ class o2::ccdb::XmlHandler + ; #pragma link C++ class o2::ccdb::CcdbApi + ; #pragma link C++ class o2::ccdb::BasicCCDBManager + ; - -/// for the unit test -#pragma link C++ class TestClass + ; -#pragma link C++ class o2::TObjectWrapper < TestClass> + ; - #endif diff --git a/CCDB/src/Condition.cxx b/CCDB/src/Condition.cxx deleted file mode 100644 index 891eb9833176e..0000000000000 --- a/CCDB/src/Condition.cxx +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// \file Condition.h -/// \brief Implementation of the Condition class (CDB object) containing the condition and its metadata - -#include "CCDB/Condition.h" -#include // for LOG -#include // for NULL - -namespace o2 -{ -namespace ccdb -{ -class IdRunRange; -} -} // namespace o2 - -using namespace o2::ccdb; - -ClassImp(Condition); - -Condition::Condition() : mObject(nullptr), mId(), mConditionMetaData(nullptr), mOwner(kFALSE) -{ -} - -Condition::Condition(TObject* object, const ConditionId& id, ConditionMetaData* metaData, Bool_t owner) - : mObject(object), mId(id), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, ConditionMetaData* metaData, - Bool_t owner) - : mObject(object), mId(path, runRange, -1, -1), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, Int_t version, - ConditionMetaData* metaData, - Bool_t owner) - : mObject(object), mId(path, runRange, version, -1), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion, - ConditionMetaData* metaData, Bool_t owner) - : mObject(object), mId(path, runRange, version, subVersion), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, ConditionMetaData* metaData, - Bool_t owner) - : mObject(object), mId(path, firstRun, lastRun, -1, -1), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, - ConditionMetaData* metaData, - Bool_t owner) - : mObject(object), mId(path, firstRun, lastRun, version, -1), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::Condition(TObject* object, const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, - Int_t subVersion, - ConditionMetaData* metaData, Bool_t owner) - : mObject(object), mId(path, firstRun, lastRun, version, subVersion), mConditionMetaData(metaData), mOwner(owner) -{ - mConditionMetaData->setObjectClassName(mObject->ClassName()); -} - -Condition::~Condition() -{ - - if (mOwner) { - if (mObject) { - delete mObject; - } - - if (mConditionMetaData) { - delete mConditionMetaData; - } - } -} - -void Condition::printId() const -{ - - LOG(INFO) << mId.ToString().Data(); -} - -Int_t Condition::Compare(const TObject* obj) const -{ - Condition* o2 = (Condition*)obj; - return TString(this->getId().getPathString()).CompareTo((o2->getId().getPathString())); -} - -Bool_t Condition::IsSortable() const -{ - return kTRUE; -} diff --git a/CCDB/src/ConditionId.cxx b/CCDB/src/ConditionId.cxx deleted file mode 100644 index 9bd7f2c5707d2..0000000000000 --- a/CCDB/src/ConditionId.cxx +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "CCDB/ConditionId.h" -#include // for TObjArray -#include // for TObjString -#include -// using std::endl; -// using std::cout; -using namespace o2::ccdb; - -ClassImp(ConditionId); - -ConditionId::ConditionId() : mPath(), mIdRunRange(-1, -1), mVersion(-1), mSubVersion(-1), mLastStorage("new") -{ - // constructor -} - -ConditionId::ConditionId(const ConditionId& other) - : TObject(), - mPath(other.mPath), - mIdRunRange(other.mIdRunRange), - mVersion(other.mVersion), - mSubVersion(other.mSubVersion), - mLastStorage(other.mLastStorage) -{ - // constructor -} - -ConditionId::ConditionId(const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion) - : mPath(path), mIdRunRange(firstRun, lastRun), mVersion(version), mSubVersion(subVersion), mLastStorage("new") -{ - // constructor -} - -ConditionId::ConditionId(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) - : mPath(path), mIdRunRange(runRange), mVersion(version), mSubVersion(subVersion), mLastStorage("new") -{ - // constructor -} - -ConditionId* ConditionId::makeFromString(const TString& idString) -{ - // constructor from string - // string has the format as the output of ConditionId::ToString: - // path: "TRD/Calib/PIDLQ"; run range: [0,999999999]; version: v0_s0 - - ConditionId* id = new ConditionId("a/b/c", -1, -1, -1, -1); - - TObjArray* arr1 = idString.Tokenize(';'); - TIter iter1(arr1); - TObjString* objStr1 = nullptr; - while ((objStr1 = dynamic_cast(iter1.Next()))) { - TString buff(objStr1->GetName()); - - if (buff.Contains("path:")) { - TString path(buff(buff.First('\"') + 1, buff.Length() - buff.First('\"') - 2)); - id->setPath(path.Data()); - - } else if (buff.Contains("run range:")) { - TString firstRunStr(buff(buff.Index('[') + 1, buff.Index(',') - buff.Index('[') - 1)); - TString lastRunStr(buff(buff.Index(',') + 1, buff.Index(']') - buff.Index(',') - 1)); - id->setIdRunRange(firstRunStr.Atoi(), lastRunStr.Atoi()); - - } else if (buff.Contains("version:")) { - if (buff.Contains("_s")) { - TString versStr(buff(buff.Last('v') + 1, buff.Index('_') - buff.Last('v') - 1)); - TString subVersStr(buff(buff.Last('s') + 1, buff.Length() - buff.Last('s') - 1)); - id->setVersion(versStr.Atoi()); - id->setSubVersion(subVersStr.Atoi()); - } else { - TString versStr(buff(buff.Last('v') + 1, buff.Length() - buff.Last('v') - 1)); - id->setVersion(versStr.Atoi()); - } - } - } - - delete arr1; - - return id; -} - -ConditionId::~ConditionId() = default; - -Bool_t ConditionId::isValid() const -{ - // validity check - - if (!(mPath.isValid() && mIdRunRange.isValid())) { - return kFALSE; - } - - // FALSE if doesn't have version but has subVersion - return !(!hasVersion() && hasSubVersion()); -} - -Bool_t ConditionId::isEqual(const TObject* obj) const -{ - // check if this id is equal to other id (compares path, run range, versions) - - if (this == obj) { - return kTRUE; - } - - if (ConditionId::Class() != obj->IsA()) { - return kFALSE; - } - ConditionId* other = (ConditionId*)obj; - return mPath.getPathString() == other->getPathString() && mIdRunRange.isEqual(&other->getIdRunRange()) && - mVersion == other->getVersion() && mSubVersion == other->getSubVersion(); -} - -TString ConditionId::ToString() const -{ - // returns a string of ConditionId data - - TString result = Form(R"(path: "%s"; run range: [%d,%d])", getPathString().Data(), getFirstRun(), getLastRun()); - - if (getVersion() >= 0) { - result += Form("; version: v%d", getVersion()); - } - if (getSubVersion() >= 0) { - result += Form("_s%d", getSubVersion()); - } - return result; -} - -void ConditionId::print(Option_t* /*option*/) const -{ - // Prints ToString() - - std::cout << ToString().Data() << std::endl; -} - -Int_t ConditionId::Compare(const TObject* obj) const -{ - // - // compare according y - ConditionId* o2 = (ConditionId*)obj; - return TString(this->getPathString()).CompareTo((o2->getPathString())); -} - -Bool_t ConditionId::IsSortable() const -{ - return kTRUE; -} diff --git a/CCDB/src/ConditionMetaData.cxx b/CCDB/src/ConditionMetaData.cxx deleted file mode 100644 index 6893fb77be6d3..0000000000000 --- a/CCDB/src/ConditionMetaData.cxx +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// Set of data describing the object // -// but not used to identify the object // -#include "CCDB/ConditionMetaData.h" -#include // for TObjString -#include // for TTimeStamp - -using namespace o2::ccdb; - -ClassImp(ConditionMetaData); - -ConditionMetaData::ConditionMetaData() - : TObject(), mObjectClassName(""), mResponsible(""), mBeamPeriod(0), mAliRootVersion(""), mComment(""), mProperties() -{ - // default constructor - - mProperties.SetOwner(1); -} - -ConditionMetaData::ConditionMetaData(const char* responsible, UInt_t beamPeriod, const char* alirootVersion, - const char* comment) - : TObject(), - mObjectClassName(""), - mResponsible(responsible), - mBeamPeriod(beamPeriod), - mAliRootVersion(alirootVersion), - mComment(comment), - mProperties() -{ - // constructor - - mProperties.SetOwner(1); -} - -ConditionMetaData::~ConditionMetaData() = default; - -void ConditionMetaData::setProperty(const char* property, TObject* object) -{ - // add something to the list of properties - - mProperties.Add(new TObjString(property), object); -} - -TObject* ConditionMetaData::getProperty(const char* property) const -{ - // get a property specified by its name (property) - - return mProperties.GetValue(property); -} - -Bool_t ConditionMetaData::removeProperty(const char* property) -{ - // removes a property - - TObjString objStrProperty(property); - TObjString* aKey = (TObjString*)mProperties.Remove(&objStrProperty); - - if (aKey) { - delete aKey; - return kTRUE; - } else { - return kFALSE; - } -} - -void ConditionMetaData::addDateToComment() -{ - // add the date to the comment. - // This method is supposed to be useful if called at the time when the object - // is created, so that later it can more easily be tracked, in particular - // when the date of the file can be lost or when one is interested in the - // date of creation, irrespective of a later copy of it - - TTimeStamp ts(time(nullptr)); - TString comment(getComment()); - comment += Form("\tDate of production: %s\n", ts.AsString()); - comment.Remove(comment.Last('+')); - setComment(comment); -} - -void ConditionMetaData::printConditionMetaData() -{ - // print the object's metaData - - TString message; - if (mObjectClassName != "") { - message += TString::Format("\tObject's class name: %s\n", mObjectClassName.Data()); - } - if (mResponsible != "") { - message += TString::Format("\tResponsible: %s\n", mResponsible.Data()); - } - if (mBeamPeriod != 0) { - message += TString::Format("\tBeam period: %d\n", mBeamPeriod); - } - if (mAliRootVersion != "") { - message += TString::Format("\tAliRoot version: %s\n", mAliRootVersion.Data()); - } - if (mComment != "") { - message += TString::Format("\tComment: %s\n", mComment.Data()); - } - if (mProperties.GetEntries() > 0) { - message += "\tProperties key names:"; - - TIter iter(mProperties.GetTable()); - TPair* aPair; - while ((aPair = (TPair*)iter.Next())) { - message += TString::Format("\t\t%s\n", ((TObjString*)aPair->Key())->String().Data()); - } - } - message += '\n'; - Printf("**** Object's ConditionMetaData parameters **** \n%s", message.Data()); -} diff --git a/CCDB/src/ConditionsMQClient.cxx b/CCDB/src/ConditionsMQClient.cxx deleted file mode 100644 index b6927514bec53..0000000000000 --- a/CCDB/src/ConditionsMQClient.cxx +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/** - * @file ConditionsMQClient.cpp - * - * @since 2016-01-11 - * @author R. Grosso, C. Kouzinopoulos from examples/MQ/7-parameters/FairMQExample7Client.cxx - */ - -#include -#include - -#include "CCDB/BackendOCDB.h" -#include "CCDB/BackendRiak.h" -#include "CCDB/ConditionsMQClient.h" -#include "O2Device/Compatibility.h" - -#include -#include - -#include "boost/filesystem.hpp" - -using namespace o2::ccdb; -using namespace std; - -ConditionsMQClient::ConditionsMQClient() : mRunId(0), mParameterName() -{ -} - -ConditionsMQClient::~ConditionsMQClient() = default; - -void CustomCleanup(void* data, void* hint) -{ - delete static_cast(hint); -} - -void ConditionsMQClient::InitTask() -{ - mParameterName = GetConfig()->GetValue("parameter-name"); - mOperationType = GetConfig()->GetValue("operation-type"); - mDataSource = GetConfig()->GetValue("data-source"); - mObjectPath = GetConfig()->GetValue("object-path"); -} - -void ConditionsMQClient::Run() -{ - Backend* backend; - - while (compatibility::FairMQ13::IsRunning(this)) { - - boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); - boost::posix_time::ptime startTime = boost::posix_time::microsec_clock::local_time(); - - if (mDataSource == "OCDB") { - backend = new BackendOCDB(); - } else if (mDataSource == "Riak") { - backend = new BackendRiak(); - } else { - LOG(ERROR) << R"(")" << mDataSource << R"(" is not a valid Data Source)"; - return; - } - - boost::filesystem::path dataPath(mObjectPath); - boost::filesystem::recursive_directory_iterator endIterator; - - // Traverse the filesystem and retrieve the name of each root found - if (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) { - for (static boost::filesystem::recursive_directory_iterator directoryIterator(dataPath); - directoryIterator != endIterator; ++directoryIterator) { - if (boost::filesystem::is_regular_file(directoryIterator->status())) { - - // Retrieve the key from the filename by erasing the directory structure and trimming the file extension - std::string str = directoryIterator->path().string(); - str.erase(0, mObjectPath.length()); - std::size_t pos = str.rfind("."); - std::string key = str.substr(0, pos); - - if (mOperationType == "GET") { - std::string* messageString = new string(); - backend->Serialize(messageString, key, mOperationType, mDataSource); - - unique_ptr request(fTransportFactory->CreateMessage( - const_cast(messageString->c_str()), messageString->length(), CustomCleanup, messageString)); - unique_ptr reply(fTransportFactory->CreateMessage()); - - if (fChannels.at("data-get").at(0).Send(request) > 0) { - if (fChannels.at("data-get").at(0).Receive(reply) > 0) { - LOG(DEBUG) << "Received a condition with a size of " << reply->GetSize(); - backend->UnPack(std::move(reply)); - } - } - } else if (mOperationType == "PUT") { - std::string* messageString = new string(); - backend->Pack(directoryIterator->path().string(), key, messageString); - - unique_ptr request(fTransportFactory->CreateMessage( - const_cast(messageString->c_str()), messageString->length(), CustomCleanup, messageString)); - - if (fChannels.at("data-put").at(0).Send(request) > 0) { - LOG(DEBUG) << "Message sent" << endl; - } - } - } - } - } else { - LOG(ERROR) << "Path " << mObjectPath << " not existing or not a directory"; - } - - boost::posix_time::ptime endTime = boost::posix_time::microsec_clock::local_time(); - LOG(DEBUG) << " Time elapsed: " << (endTime - startTime).total_milliseconds() << "ms"; - } -} diff --git a/CCDB/src/ConditionsMQServer.cxx b/CCDB/src/ConditionsMQServer.cxx deleted file mode 100644 index 66f99f474ef99..0000000000000 --- a/CCDB/src/ConditionsMQServer.cxx +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/** - * @file ConditionsMQServer.cxx - * - * @since 2016-01-11 - * @author R. Grosso, C. Kouzinopoulos from parmq/ParameterMQServer.cxx - */ - -#include "TMessage.h" -#include "Rtypes.h" - -#include "CCDB/Condition.h" -#include "CCDB/ConditionsMQServer.h" -#include "CCDB/IdPath.h" -#include "O2Device/Compatibility.h" -#include -#include - -// Google protocol buffers headers -#include -#include "request.pb.h" - -#include - -using namespace o2::ccdb; -using std::cout; -using std::endl; -using std::string; - -ConditionsMQServer::ConditionsMQServer() : ParameterMQServer(), mCdbManager(o2::ccdb::Manager::Instance()) -{ -} - -void ConditionsMQServer::InitTask() -{ - ParameterMQServer::InitTask(); - // Set first input - if (GetFirstInputType() == "OCDB") { - mCdbManager->setDefaultStorage(GetFirstInputName().c_str()); - } - - // Set second input - if (GetSecondInputType() == "OCDB") { - mCdbManager->setDefaultStorage(GetSecondInputName().c_str()); - } - - // Set output - if (GetOutputName() != "") { - if (GetOutputType() == "OCDB") { - mCdbManager->setDefaultStorage(GetOutputName().c_str()); - } - } -} - -void free_tmessage(void* data, void* hint) -{ - delete static_cast(hint); -} - -void ConditionsMQServer::ParseDataSource(std::string& dataSource, const std::string& data) -{ - messaging::RequestMessage* msgReply = new messaging::RequestMessage; - msgReply->ParseFromString(data); - - LOG(DEBUG) << "Data source: " << msgReply->datasource(); - - dataSource = msgReply->datasource(); - - delete msgReply; -} - -void ConditionsMQServer::Deserialize(const std::string& messageString, std::string& object) -{ - messaging::RequestMessage* requestMessage = new messaging::RequestMessage; - requestMessage->ParseFromString(messageString); - - object.assign(requestMessage->key()); - - delete requestMessage; -} - -void ConditionsMQServer::Run() -{ - std::unique_ptr poller( - fTransportFactory->CreatePoller(fChannels, {"data-put", "data-get", "broker-get"})); - - while (compatibility::FairMQ13::IsRunning(this)) { - - poller->Poll(-1); - - if (poller->CheckInput("data-get", 0)) { - std::unique_ptr input(fTransportFactory->CreateMessage()); - - if (Receive(input, "data-get") > 0) { - std::string serialString(static_cast(input->GetData()), input->GetSize()); - - //LOG(DEBUG) << "Received a GET client message: " << serialString; - - std::string dataSource; - ParseDataSource(dataSource, serialString); - - if (dataSource == "OCDB") { - // Retrieve the key from the serialized message - std::string key; - Deserialize(serialString, key); - - getFromOCDB(key); - } else if (dataSource == "Riak") { - // No need to de-serialize, just forward message to the broker - fChannels.at("broker-get").at(0).Send(input); - } - } - } - - if (poller->CheckInput("data-put", 0)) { - std::unique_ptr input(fTransportFactory->CreateMessage()); - - if (Receive(input, "data-put") > 0) { - std::string serialString(static_cast(input->GetData()), input->GetSize()); - - // LOG(DEBUG) << "Received a PUT client message: " << serialString; - LOG(DEBUG) << "Message size: " << input->GetSize(); - - std::string dataSource; - ParseDataSource(dataSource, serialString); - - if (dataSource == "OCDB") { - LOG(ERROR) << "The GET operation is not supported for the OCDB data source yet"; - } else if (dataSource == "Riak") { - fChannels.at("broker-put").at(0).Send(input); - } - } - } - - if (poller->CheckInput("broker-get", 0)) { - std::unique_ptr input(fTransportFactory->CreateMessage()); - - if (Receive(input, "broker-get") > 0) { - LOG(DEBUG) << "Received object from broker with a size of: " << input->GetSize(); - - fChannels.at("data-get").at(0).Send(input); - } - } - } -} - -// Query OCDB for the condition -void ConditionsMQServer::getFromOCDB(std::string key) -{ - // Change key from i.e. "/DET/Calib/Histo/Run2008_2008_v1_s0" to (DET/Calib/Histo, 2008) - // FIXME: This will have to be changed in the future by adapting IdPath and getObject accordingly - std::size_t pos = key.rfind("/"); - std::string identifier = key.substr(0, pos); - key.erase(0, pos + 4); - std::size_t pos2 = key.find("_"); - int runId = atoi(key.substr(0, pos2).c_str()); - - Condition* aCondition = nullptr; - - mCdbManager->setRun(runId); - aCondition = mCdbManager->getCondition(IdPath(identifier), runId); - - if (aCondition) { - LOG(DEBUG) << "Sending following parameter to the client:"; - aCondition->printConditionMetaData(); - TMessage* tmsg = new TMessage(kMESS_OBJECT); - tmsg->WriteObject(aCondition); - - std::unique_ptr message( - fTransportFactory->CreateMessage(tmsg->Buffer(), tmsg->BufferSize(), free_tmessage, tmsg)); - - fChannels.at("data-get").at(0).Send(message); - } else { - LOG(ERROR) << R"(Could not get a condition for ")" << key << R"(" and run )" << runId << "!"; - } -} - -ConditionsMQServer::~ConditionsMQServer() -{ - delete mCdbManager; -} diff --git a/CCDB/src/FileStorage.cxx b/CCDB/src/FileStorage.cxx deleted file mode 100644 index 88ab981ce9b2d..0000000000000 --- a/CCDB/src/FileStorage.cxx +++ /dev/null @@ -1,755 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// access class to a DataBase in a dump storage (single file) // -#include "CCDB/FileStorage.h" -#include // for LOG -#include // for TFile -#include // for TKey -#include // for TObjString -#include // for TRegexp -#include // for TSystem, gSystem -#include "CCDB/Condition.h" // for Condition - -using namespace o2::ccdb; - -ClassImp(FileStorage); - -FileStorage::FileStorage(const char* dbFile, Bool_t readOnly) : mFile(nullptr), mReadOnly(readOnly) -{ - // constructor - - // opening file - mFile = TFile::Open(dbFile, mReadOnly ? "READ" : "UPDATE"); - if (!mFile) { - LOG(ERROR) << R"(Can't open file ")" << dbFile << R"(")"; - } else { - LOG(ERROR) << R"(File ")" << dbFile << R"(" opened)"; - if (mReadOnly) - LOG(DEBUG) << "in read-only mode"; - } - - mType = "dump"; - mBaseFolder = dbFile; -} - -FileStorage::~FileStorage() -{ - // destructor - - if (mFile) { - mFile->Close(); - delete mFile; - } -} - -Bool_t FileStorage::keyNameToId(const char* keyname, IdRunRange& runRange, Int_t& version, Int_t& subVersion) -{ - // build ConditionId from keyname numbers - - Ssiz_t mSize; - - // valid keyname: Run#firstRun_#lastRun_v#version_s#subVersion.root - TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+$"); - keyPattern.Index(keyname, &mSize); - if (!mSize) { - LOG(DEBUG) << R"(Bad keyname ")" << keyname << R"(".)"; - return kFALSE; - } - - TObjArray* strArray = (TObjArray*)TString(keyname).Tokenize("_"); - - TString firstRunString(((TObjString*)strArray->At(0))->GetString()); - runRange.setFirstRun(atoi(firstRunString.Data() + 3)); - runRange.setLastRun(atoi(((TObjString*)strArray->At(1))->GetString())); - - TString verString(((TObjString*)strArray->At(2))->GetString()); - version = atoi(verString.Data() + 1); - - TString subVerString(((TObjString*)strArray->At(3))->GetString()); - subVersion = atoi(subVerString.Data() + 1); - - delete strArray; - - return kTRUE; -} - -Bool_t FileStorage::idToKeyName(const IdRunRange& runRange, Int_t version, Int_t subVersion, TString& keyname) -{ - // build key name from ConditionId data (run range, version, subVersion) - - if (!runRange.isValid()) { - LOG(DEBUG) << "Invalid run range [" << runRange.getFirstRun() << "," << runRange.getLastRun() << "]."; - return kFALSE; - } - - if (version < 0) { - LOG(DEBUG) << R"(Invalid version ')" << version << R"('.)"; - return kFALSE; - } - - if (subVersion < 0) { - LOG(DEBUG) << R"(Invalid subversion ')" << subVersion << R"('.)"; - return kFALSE; - } - - keyname += "Run"; - keyname += runRange.getFirstRun(); - keyname += "_"; - keyname += runRange.getLastRun(); - keyname += "_v"; - keyname += version; - keyname += "_s"; - keyname += subVersion; - - return kTRUE; -} - -Bool_t FileStorage::makeDir(const TString& path) -{ - // descend into TDirectory, making TDirectories if they don't exist - TObjArray* strArray = (TObjArray*)path.Tokenize("/"); - - TIter iter(strArray); - TObjString* str; - - while ((str = (TObjString*)iter.Next())) { - - TString dirName(str->GetString()); - if (!dirName.Length()) { - continue; - } - - if (gDirectory->cd(dirName)) { - continue; - } - - TDirectory* aDir = gDirectory->mkdir(dirName, ""); - if (!aDir) { - LOG(ERROR) << R"(Can't create directory ")" << dirName.Data() << R"("!)"; - delete strArray; - - return kFALSE; - } - - aDir->cd(); - } - - delete strArray; - - return kTRUE; -} - -Bool_t FileStorage::prepareId(ConditionId& id) -{ - // prepare id (version, subVersion) of the object that will be stored (called by putCondition) - - IdRunRange aIdRunRange; // the runRange got from filename - IdRunRange lastIdRunRange(-1, -1); // highest runRange found - Int_t aVersion, aSubVersion; // the version subVersion got from filename - Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found - - TIter iter(gDirectory->GetListOfKeys()); - TKey* key; - - if (!id.hasVersion()) { // version not specified: look for highest version & subVersion - - while ((key = (TKey*)iter.Next())) { // loop on keys - - const char* keyName = key->GetName(); - - if (!keyNameToId(keyName, aIdRunRange, aVersion, aSubVersion)) { - LOG(DEBUG) << "Bad keyname <" << keyName << ">!I'll skip it."; - continue; - } - - if (!aIdRunRange.isOverlappingWith(id.getIdRunRange())) { - continue; - } - if (aVersion < lastVersion) { - continue; - } - if (aVersion > lastVersion) { - lastSubVersion = -1; - } - if (aSubVersion < lastSubVersion) { - continue; - } - lastVersion = aVersion; - lastSubVersion = aSubVersion; - lastIdRunRange = aIdRunRange; - } - - id.setVersion(lastVersion); - id.setSubVersion(lastSubVersion + 1); - - } else { // version specified, look for highest subVersion only - - while ((key = (TKey*)iter.Next())) { // loop on the keys - - const char* keyName = key->GetName(); - - if (!keyNameToId(keyName, aIdRunRange, aVersion, aSubVersion)) { - LOG(DEBUG) << "Bad keyname <" << keyName << ">!I'll skip it."; - continue; - } - - if (aIdRunRange.isOverlappingWith(id.getIdRunRange()) && aVersion == id.getVersion() && - aSubVersion > lastSubVersion) { - lastSubVersion = aSubVersion; - lastIdRunRange = aIdRunRange; - } - } - - id.setSubVersion(lastSubVersion + 1); - } - - TString lastStorage = id.getLastStorage(); - if (lastStorage.Contains(TString("grid"), TString::kIgnoreCase) && id.getSubVersion() > 0) { - LOG(ERROR) << "GridStorage to FileStorage Storage error! local object with version v" << id.getVersion() << "_s" - << id.getSubVersion() - 1 << " found:"; - LOG(ERROR) << "this object has been already transferred from GridStorage (check v" << id.getVersion() << "_s0)!"; - return kFALSE; - } - - if (lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.getSubVersion() > 0) { - LOG(DEBUG) << "A NEW object is being stored with version v" << id.getVersion() << "_s" << id.getSubVersion(); - LOG(DEBUG) << "and it will hide previously stored object with v" << id.getVersion() << "_s" - << id.getSubVersion() - 1 << "!"; - } - - if (!lastIdRunRange.isAnyRange() && !(lastIdRunRange.isEqual(&id.getIdRunRange()))) - LOG(WARNING) << "Run range modified w.r.t. previous version (Run" << lastIdRunRange.getFirstRun() << "_" - << lastIdRunRange.getLastRun() << "_v" << id.getVersion() << "_s" << id.getSubVersion() - 1 << ")"; - - return kTRUE; -} - -ConditionId* FileStorage::getId(const ConditionId& query) -{ - // look for filename matching query (called by getCondition) - - IdRunRange aIdRunRange; // the runRange got from filename - Int_t aVersion, aSubVersion; // the version and subVersion got from filename - - TIter iter(gDirectory->GetListOfKeys()); - TKey* key; - - ConditionId* result = new ConditionId(); - result->setPath(query.getPathString()); - - if (!query.hasVersion()) { // neither version and subversion specified -> look for highest version - // and subVersion - - while ((key = (TKey*)iter.Next())) { // loop on the keys - - if (!keyNameToId(key->GetName(), aIdRunRange, aVersion, aSubVersion)) { - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - if (result->getVersion() < aVersion) { - result->setVersion(aVersion); - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - - } else if (result->getVersion() == aVersion && result->getSubVersion() < aSubVersion) { - - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - } else if (result->getVersion() == aVersion && result->getSubVersion() == aSubVersion) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << ", version " << aVersion << "_" - << aSubVersion << "!"; - - delete result; - return nullptr; - } - } - - } else if (!query.hasSubVersion()) { // version specified but not subversion -> look for highest - // subVersion - - result->setVersion(query.getVersion()); - - while ((key = (TKey*)iter.Next())) { // loop on the keys - - if (!keyNameToId(key->GetName(), aIdRunRange, aVersion, aSubVersion)) { - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - if (query.getVersion() != aVersion) { - continue; - } - // aVersion is requested version! - - if (result->getSubVersion() == aSubVersion) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " << aVersion << "_" - << aSubVersion << "!"; - delete result; - return nullptr; - } - if (result->getSubVersion() < aSubVersion) { - - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - } - } - - } else { // both version and subversion specified - - while ((key = (TKey*)iter.Next())) { // loop on the keys - - if (!keyNameToId(key->GetName(), aIdRunRange, aVersion, aSubVersion)) { - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - if (query.getVersion() != aVersion || query.getSubVersion() != aSubVersion) { - continue; - } - // aVersion and aSubVersion are requested version and subVersion! - - if (result->getVersion() == aVersion && result->getSubVersion() == aSubVersion) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " << aVersion << "_" - << aSubVersion << "!"; - delete result; - return nullptr; - } - result->setVersion(aVersion); - result->setSubVersion(aSubVersion); - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - } - } - - return result; -} - -Condition* FileStorage::getCondition(const ConditionId& queryId) -{ - // get Condition from the database - - TDirectory::TContext context(gDirectory, mFile); - - if (!(mFile && mFile->IsOpen())) { - LOG(ERROR) << "FileStorage is not initialized properly"; - return nullptr; - } - - if (!gDirectory->cd(queryId.getPathString())) { - return nullptr; - } - - ConditionId* dataId = getConditionId(queryId); - - if (!dataId || !dataId->isSpecified()) { - if (dataId) { - delete dataId; - } - return nullptr; - } - - TString keyname; - if (!idToKeyName(dataId->getIdRunRange(), dataId->getVersion(), dataId->getSubVersion(), keyname)) { - LOG(DEBUG) << "Bad ID encountered! Subnormal error!"; - delete dataId; - return nullptr; - } - - // get the only Condition object from the file - // the object in the file is an Condition entry named keyname - // keyName = Run#firstRun_#lastRun_v#version_s#subVersion - - TObject* anObject = gDirectory->Get(keyname); - if (!anObject) { - LOG(DEBUG) << "Bad storage data: NULL entry object!"; - delete dataId; - return nullptr; - } - - if (Condition::Class() != anObject->IsA()) { - LOG(DEBUG) << "Bad storage data: Invalid entry object!"; - delete dataId; - return nullptr; - } - - ((Condition*)anObject)->setLastStorage("dump"); - - delete dataId; - return (Condition*)anObject; -} - -ConditionId* FileStorage::getConditionId(const ConditionId& queryId) -{ - // get Condition from the database - - TDirectory::TContext context(gDirectory, mFile); - - if (!(mFile && mFile->IsOpen())) { - LOG(ERROR) << "FileStorage is not initialized properly"; - return nullptr; - } - - if (!gDirectory->cd(queryId.getPathString())) { - return nullptr; - } - - ConditionId* dataId = nullptr; - - // look for a filename matching query requests (path, runRange, version, subVersion) - if (!queryId.hasVersion()) { - // if version is not specified, first check the selection criteria list - ConditionId selectedId(queryId); - getSelection(&selectedId); - dataId = getId(queryId); - } else { - dataId = getId(queryId); - } - - if (dataId && !dataId->isSpecified()) { - delete dataId; - return nullptr; - } - - return dataId; -} - -void FileStorage::getEntriesForLevel0(const ConditionId& queryId, TList* result) -{ - // multiple request ( Storage::GetAllObjects) - - TDirectory* saveDir = gDirectory; - - TIter iter(gDirectory->GetListOfKeys()); - TKey* key; - - while ((key = (TKey*)iter.Next())) { - - TString keyNameStr(key->GetName()); - if (queryId.getPath().doesLevel1Contain(keyNameStr)) { - gDirectory->cd(keyNameStr); - getEntriesForLevel1(queryId, result); - - saveDir->cd(); - } - } -} - -void FileStorage::getEntriesForLevel1(const ConditionId& queryId, TList* result) -{ - // multiple request ( Storage::GetAllObjects) - - TIter iter(gDirectory->GetListOfKeys()); - TKey* key; - - TDirectory* level0Dir = (TDirectory*)gDirectory->GetMother(); - - while ((key = (TKey*)iter.Next())) { - - TString keyNameStr(key->GetName()); - if (queryId.getPath().doesLevel2Contain(keyNameStr)) { - - IdPath aPath(level0Dir->GetName(), gDirectory->GetName(), keyNameStr); - ConditionId anId(aPath, queryId.getIdRunRange(), queryId.getVersion(), -1); - - Condition* anCondition = getCondition(anId); - if (anCondition) { - result->Add(anCondition); - } - } - } -} - -TList* FileStorage::getAllEntries(const ConditionId& queryId) -{ - // return list of CDB entries matching a generic request (Storage::GetAllObjects) - - TDirectory::TContext context(gDirectory, mFile); - - if (!(mFile && mFile->IsOpen())) { - LOG(ERROR) << "FileStorage is not initialized properly"; - return nullptr; - } - - TList* result = new TList(); - result->SetOwner(); - - TIter iter(gDirectory->GetListOfKeys()); - TKey* key; - - while ((key = (TKey*)iter.Next())) { - - TString keyNameStr(key->GetName()); - if (queryId.getPath().doesLevel0Contain(keyNameStr)) { - gDirectory->cd(keyNameStr); - getEntriesForLevel0(queryId, result); - - mFile->cd(); - } - } - - return result; -} - -Bool_t FileStorage::putCondition(Condition* entry, const char* mirrors) -{ - // put an Condition object into the database - - TDirectory::TContext context(gDirectory, mFile); - - if (!(mFile && mFile->IsOpen())) { - LOG(ERROR) << "FileStorage is not initialized properly"; - return kFALSE; - } - - if (mReadOnly) { - LOG(ERROR) << "FileStorage is read only!"; - return kFALSE; - } - - TString mirrorsString(mirrors); - if (!mirrorsString.IsNull()) - LOG(WARNING) << "LocalStorage storage cannot take mirror SEs into account. They will be ignored."; - - ConditionId& id = entry->getId(); - - if (!gDirectory->cd(id.getPathString())) { - if (!makeDir(id.getPathString())) { - LOG(ERROR) << R"(Can't open directory ")" << id.getPathString().Data() << R"("!)"; - return kFALSE; - } - } - - // set version and subVersion for the entry to be stored - if (!prepareId(id)) { - return kFALSE; - } - - // build keyname from entry's id - TString keyname; - if (!idToKeyName(id.getIdRunRange(), id.getVersion(), id.getSubVersion(), keyname)) { - LOG(ERROR) << "Invalid ID encountered! Subnormal error!"; - return kFALSE; - } - - // write object (key name: Run#firstRun_#lastRun_v#version_s#subVersion) - Bool_t result = gDirectory->WriteTObject(entry, keyname); - if (!result) { - LOG(ERROR) << R"(Can't write entry to file ")" << mFile->GetName() << R"(")"; - } - - if (result) { - LOG(INFO) << "CDB object stored into file " << mFile->GetName(); - LOG(INFO) << "TDirectory/key name: " << id.getPathString().Data() << "/" << keyname.Data(); - } - - return result; -} - -TList* FileStorage::getIdListFromFile(const char* fileName) -{ - - TString turl(fileName); - if (turl[0] != '/') { - turl.Prepend(TString(gSystem->WorkingDirectory()) + '/'); - } - TFile* file = TFile::Open(turl); - if (!file) { - LOG(ERROR) << "Can't open selection file <" << turl.Data() << ">!"; - return nullptr; - } - file->cd(); - - TList* list = new TList(); - list->SetOwner(); - int i = 0; - TString keycycle; - - ConditionId* id; - while (1) { - i++; - keycycle = " ConditionId;"; - keycycle += i; - - id = (ConditionId*)file->Get(keycycle); - if (!id) { - break; - } - list->AddFirst(id); - } - file->Close(); - delete file; - file = nullptr; - return list; -} - -Bool_t FileStorage::hasConditionType(const char* path) const -{ - // check for path in storage - - TDirectory::TContext context(gDirectory, mFile); - if (!(mFile && mFile->IsOpen())) { - LOG(ERROR) << "FileStorage is not initialized properly"; - return kFALSE; - } - - return gDirectory->cd(path); -} - -void FileStorage::queryValidFiles() -{ - // Query the CDB for files valid for Storage::mRun - // fills list mValidFileIds with ConditionId objects created from file name - - LOG(ERROR) << "Not yet (and maybe never) implemented"; -} - -Bool_t FileStorage::idToFilename(const ConditionId& /*id*/, TString& /*filename*/) const -{ - // build file name from ConditionId (path, run range, version) and mDBFolder - - LOG(ERROR) << "Not implemented"; - return kFALSE; -} - -void FileStorage::setRetry(Int_t /* nretry */, Int_t /* initsec */) -{ - // Function to set the exponential retry for putting entries in the OCDB - LOG(INFO) << "This function sets the exponential retry for putting entries in the OCDB - to be " - "used ONLY for GridStorage --> returning without doing anything"; - return; -} - -// FileStorage factory -ClassImp(FileStorageFactory); - -Bool_t FileStorageFactory::validateStorageUri(const char* dbString) -{ - // check if the string is valid dump URI - TRegexp dbPattern("^dump://.+$"); - return TString(dbString).Contains(dbPattern); -} - -StorageParameters* FileStorageFactory::createStorageParameter(const char* dbString) -{ - // create FileStorageParameters class from the URI string - - if (!validateStorageUri(dbString)) { - return nullptr; - } - - TString pathname(dbString + sizeof("dump://") - 1); - - Bool_t readOnly; - - if (pathname.Contains(TRegexp(";ReadOnly$"))) { - pathname.Resize(pathname.Length() - sizeof(";ReadOnly") + 1); - readOnly = kTRUE; - } else { - readOnly = kFALSE; - } - - gSystem->ExpandPathName(pathname); - - if (pathname[0] != '/') { - pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/'); - } - - return new FileStorageParameters(pathname, readOnly); -} - -Storage* FileStorageFactory::createStorage(const StorageParameters* param) -{ - // create FileStorage instance from parameters - if (FileStorageParameters::Class() == param->IsA()) { - const FileStorageParameters* dumpParam = (const FileStorageParameters*)param; - FileStorage* dumpStorage = new FileStorage(dumpParam->getPathString(), dumpParam->isReadOnly()); - return dumpStorage; - } - return nullptr; -} - -// FileStorage parameter class -ClassImp(FileStorageParameters); - -FileStorageParameters::FileStorageParameters() : StorageParameters(), mDBPath(), mReadOnly(kFALSE) -{ - // default constructor -} - -FileStorageParameters::FileStorageParameters(const char* dbPath, Bool_t readOnly) : mDBPath(dbPath), mReadOnly(readOnly) -{ - // constructor - TString uri; - uri += "dump://"; - uri += dbPath; - - if (mReadOnly) { - uri += ";ReadOnly"; - } - - setUri(uri); - setType("dump"); -} - -FileStorageParameters::~FileStorageParameters() = default; - -StorageParameters* FileStorageParameters::cloneParam() const -{ - // clone parameter - - return new FileStorageParameters(mDBPath, mReadOnly); -} - -ULong_t FileStorageParameters::getHash() const -{ - // return getHash function - - return mDBPath.Hash(); -} - -Bool_t FileStorageParameters::isEqual(const TObject* obj) const -{ - // check if this object is equal to StorageParameters obj - - if (this == obj) { - return kTRUE; - } - - if (FileStorageParameters::Class() != obj->IsA()) { - return kFALSE; - } - - FileStorageParameters* other = (FileStorageParameters*)obj; - - return mDBPath == other->mDBPath; -} diff --git a/CCDB/src/GridStorage.cxx b/CCDB/src/GridStorage.cxx deleted file mode 100644 index f3f865b450950..0000000000000 --- a/CCDB/src/GridStorage.cxx +++ /dev/null @@ -1,1460 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// access class to a DataBase in an AliEn storage // - -#include "CCDB/GridStorage.h" -#include // for LOG -#include // for TFile -#include // for gGrid, TGrid -#include // for TGridResult -#include // for TObjString -#include // for TROOT, gROOT -#include // for TRegexp -#include "CCDB/Condition.h" // for Condition -#include "TSystem.h" // for TSystem, gSystem - -using namespace o2::ccdb; - -ClassImp(GridStorage); - -GridStorage::GridStorage(const char* gridUrl, const char* user, const char* dbFolder, const char* se, - const char* cacheFolder, - Bool_t operateDisconnected, Long64_t cacheSize, Long_t cleanupInterval) - : Storage(), - mGridUrl(gridUrl), - mUser(user), - mDBFolder(dbFolder), - mSE(se), - mMirrorSEs(""), - mCacheFolder(cacheFolder), - mOperateDisconnected(operateDisconnected), - mCacheSize(cacheSize), - mCleanupInterval(cleanupInterval) -{ - // constructor // - // alalal - - // if the same GridStorage is alreay active, skip connection - if (!gGrid || mGridUrl != gGrid->GridUrl() || ((mUser != "") && (mUser != gGrid->GetUser()))) { - // connection to the GridStorage - LOG(INFO) << "Connection to the GridStorage..."; - if (gGrid) { - LOG(INFO) << "gGrid = " << gGrid << "; mGridUrl = " << mGridUrl.Data() - << "; gGrid->GridUrl() = " << gGrid->GridUrl(); - LOG(INFO) << "mUser = " << mUser.Data() << "; gGrid->getUser() = " << gGrid->GetUser(); - } - TGrid::Connect(mGridUrl.Data(), mUser.Data()); - } - - if (!gGrid) { - LOG(ERROR) << "Connection failed!"; - return; - } - - TString initDir(gGrid->Pwd(0)); - if (mDBFolder[0] != '/') { - mDBFolder.Prepend(initDir); - } - - // check DBFolder: trying to cd to DBFolder; if it does not exist, create it - if (!gGrid->Cd(mDBFolder.Data(), 0)) { - LOG(DEBUG) << "Creating new folder <" << mDBFolder.Data() << "> ..."; - TGridResult* res = gGrid->Command(Form("mkdir -p %s", mDBFolder.Data())); - TString result = res->GetKey(0, "__result__"); - if (result == "0") { - LOG(FATAL) << R"(Cannot create folder ")" << mDBFolder.Data() << R"("!)"; - return; - } - } else { - LOG(DEBUG) << "Folder <" << mDBFolder.Data() << "> found"; - } - - // removes any '/' at the end of path, then append one '/' - while (mDBFolder.EndsWith("/")) { - mDBFolder.Remove(mDBFolder.Last('/')); - } - mDBFolder += "/"; - - mType = "alien"; - mBaseFolder = mDBFolder; - - // Setting the cache - - // Check if local cache folder is already defined - TString origCache(TFile::GetCacheFileDir()); - if (mCacheFolder.Length() > 0) { - if (origCache.Length() == 0) { - LOG(INFO) << "Setting local cache to: " << mCacheFolder.Data(); - } else if (mCacheFolder != origCache) { - LOG(WARNING) << "LocalStorage cache folder was already defined, changing it to: " << mCacheFolder.Data(); - } - - // default settings are: operateDisconnected=kTRUE, forceCacheread = kFALSE - if (!TFile::SetCacheFileDir(mCacheFolder.Data(), mOperateDisconnected)) { - LOG(ERROR) << "Could not set cache folder " << mCacheFolder.Data() << " !"; - mCacheFolder = ""; - } else { - // reset mCacheFolder because the function may have - // slightly changed the folder name (e.g. '/' added) - mCacheFolder = TFile::GetCacheFileDir(); - } - - // default settings are: cacheSize=1GB, cleanupInterval = 0 - if (!TFile::ShrinkCacheFileDir(mCacheSize, mCleanupInterval)) { - LOG(ERROR) << "Could not set following values to ShrinkCacheFileDir: cacheSize = " << mCacheSize - << " cleanupInterval = " << mCleanupInterval << " !"; - } - } - - // return to the initial directory - gGrid->Cd(initDir.Data(), 0); - - mNretry = 3; // default - mInitRetrySeconds = 5; // default -} - -GridStorage::~GridStorage() -{ - // destructor - delete gGrid; - gGrid = nullptr; -} - -Bool_t GridStorage::filenameToId(TString& filename, ConditionId& id) -{ - // build ConditionId from full path filename (mDBFolder/path/Run#x_#y_v#z_s0.root) - - if (filename.Contains(mDBFolder)) { - filename = filename(mDBFolder.Length(), filename.Length() - mDBFolder.Length()); - } - - TString idPath = filename(0, filename.Last('/')); - id.setPath(idPath); - if (!id.isValid()) { - return kFALSE; - } - - filename = filename(idPath.Length() + 1, filename.Length() - idPath.Length()); - - Ssiz_t mSize; - // valid filename: Run#firstRun_#lastRun_v#version_s0.root - TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s0.root$"); - keyPattern.Index(filename, &mSize); - if (!mSize) { - - // TODO backward compatibility ... maybe remove later! - Ssiz_t oldmSize; - TRegexp oldKeyPattern("^Run[0-9]+_[0-9]+_v[0-9]+.root$"); - oldKeyPattern.Index(filename, &oldmSize); - if (!oldmSize) { - LOG(DEBUG) << "Bad filename <" << filename.Data() << ">."; - return kFALSE; - } else { - LOG(DEBUG) << "Old filename format <" << filename.Data() << ">."; - id.setSubVersion(-11); // TODO trick to ensure backward compatibility - } - - } else { - id.setSubVersion(-1); // TODO trick to ensure backward compatibility - } - - filename.Resize(filename.Length() - sizeof(".root") + 1); - - TObjArray* strArray = (TObjArray*)filename.Tokenize("_"); - - TString firstRunString(((TObjString*)strArray->At(0))->GetString()); - id.setFirstRun(atoi(firstRunString.Data() + 3)); - id.setLastRun(atoi(((TObjString*)strArray->At(1))->GetString())); - - TString verString(((TObjString*)strArray->At(2))->GetString()); - id.setVersion(atoi(verString.Data() + 1)); - - delete strArray; - - return kTRUE; -} - -Bool_t GridStorage::idToFilename(const ConditionId& id, TString& filename) const -{ - // build file name from ConditionId (path, run range, version) and mDBFolder - - if (!id.getIdRunRange().isValid()) { - LOG(DEBUG) << "Invalid run range [" << id.getFirstRun() << "," << id.getLastRun() << "]."; - return kFALSE; - } - - if (id.getVersion() < 0) { - LOG(DEBUG) << "Invalid version <" << id.getVersion() << ">."; - return kFALSE; - } - - filename = Form("Run%d_%d_v%d", id.getFirstRun(), id.getLastRun(), id.getVersion()); - - if (id.getSubVersion() != -11) { - filename += "_s0"; - } // TODO to ensure backward compatibility - filename += ".root"; - - filename.Prepend(mDBFolder + id.getPathString() + '/'); - - return kTRUE; -} - -void GridStorage::setRetry(Int_t nretry, Int_t initsec) -{ - - // Function to set the exponential retry for putting entries in the OCDB - - LOG(WARNING) << "WARNING!!! You are changing the exponential retry times and delay: this " - "function should be used by experts!"; - mNretry = nretry; - mInitRetrySeconds = initsec; - LOG(DEBUG) << "mNretry = " << mNretry << ", mInitRetrySeconds = " << mInitRetrySeconds; -} - -Bool_t GridStorage::prepareId(ConditionId& id) -{ - // prepare id (version) of the object that will be stored (called by putCondition) - - TString initDir(gGrid->Pwd(0)); - - TString dirName(mDBFolder); - - Bool_t dirExist = kFALSE; - - // go to the path; if directory does not exist, create it - for (int i = 0; i < 3; i++) { - // TString cmd("find -d "); - // cmd += Form("%s ",dirName); - // cmd += - // gGrid->Command(cmd.Data()); - dirName += Form("%s/", id.getPathLevel(i).Data()); - dirExist = gGrid->Cd(dirName, 0); - if (!dirExist) { - LOG(DEBUG) << "Creating new folder <" << dirName.Data() << "> ..."; - if (!gGrid->Mkdir(dirName, "", 0)) { - LOG(ERROR) << "Cannot create directory <" << dirName.Data() << "> !"; - gGrid->Cd(initDir.Data()); - return kFALSE; - } - - // if folders are new add tags to them - if (i == 1) { - - } else if (i == 2) { - LOG(DEBUG) << R"(Tagging level 2 folder with "CDB" and "CDB_MD" tag)"; - if (!addTag(dirName, "CDB")) { - LOG(ERROR) << "Could not tag folder " << dirName.Data() << " !"; - if (!gGrid->Rmdir(dirName.Data())) { - LOG(ERROR) << "Unexpected: could not remove " << dirName.Data() << " directory!"; - } - return 0; - } - if (!addTag(dirName, "CDB_MD")) { - LOG(ERROR) << "Could not tag folder " << dirName.Data() << " !"; - if (!gGrid->Rmdir(dirName.Data())) { - LOG(ERROR) << "Unexpected: could not remove " << dirName.Data() << " directory!"; - } - return 0; - } - } - } - } - gGrid->Cd(initDir, 0); - - TString filename; - ConditionId anId; // the id got from filename - IdRunRange lastIdRunRange(-1, -1); // highest runRange found - Int_t lastVersion = 0; // highest version found - - TGridResult* res = gGrid->Ls(dirName); - - // loop on the files in the directory, look for highest version - for (int i = 0; i < res->GetEntries(); i++) { - filename = res->GetFileNamePath(i); - if (!filenameToId(filename, anId)) { - continue; - } - if (anId.getIdRunRange().isOverlappingWith(id.getIdRunRange()) && anId.getVersion() > lastVersion) { - lastVersion = anId.getVersion(); - lastIdRunRange = anId.getIdRunRange(); - } - } - delete res; - - // GRP entries with explicitly set version escape default incremental versioning - if (id.getPathString().Contains("GRP") && id.hasVersion() && lastVersion != 0) { - LOG(DEBUG) << "Condition " << id.ToString().Data() << " won't be put in the destination OCDB"; - return kFALSE; - } - - id.setVersion(lastVersion + 1); - id.setSubVersion(0); - - TString lastStorage = id.getLastStorage(); - if (lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.getVersion() > 1) { - LOG(DEBUG) << "A NEW object is being stored with version " << id.getVersion(); - LOG(DEBUG) << "and it will hide previously stored object with version " << id.getVersion() - 1 << "!"; - } - - if (!lastIdRunRange.isAnyRange() && !(lastIdRunRange.isEqual(&id.getIdRunRange()))) - LOG(WARNING) << "Run range modified w.r.t. previous version (Run" << lastIdRunRange.getFirstRun() << "_" - << lastIdRunRange.getLastRun() << "_v" << id.getVersion() << ")"; - - return kTRUE; -} - -ConditionId* GridStorage::getId(const TObjArray& validFileIds, const ConditionId& query) -{ - // look for the ConditionId that matches query's requests (highest or exact version) - - if (validFileIds.GetEntriesFast() < 1) { - return nullptr; - } - - TIter iter(&validFileIds); - - ConditionId* anIdPtr = nullptr; - ConditionId* result = nullptr; - - while ((anIdPtr = dynamic_cast(iter.Next()))) { - if (anIdPtr->getPathString() != query.getPathString()) { - continue; - } - - // if(!CheckVersion(query, anIdPtr, result)) return NULL; - - if (!query.hasVersion()) { // look for highest version - if (result && result->getVersion() > anIdPtr->getVersion()) { - continue; - } - if (result && result->getVersion() == anIdPtr->getVersion()) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " - << anIdPtr->getVersion() << "!"; - return nullptr; - } - result = new ConditionId(*anIdPtr); - } else { // look for specified version - if (query.getVersion() != anIdPtr->getVersion()) { - continue; - } - if (result && result->getVersion() == anIdPtr->getVersion()) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " - << anIdPtr->getVersion() << "!"; - return nullptr; - } - result = new ConditionId(*anIdPtr); - } - } - - return result; -} - -ConditionId* GridStorage::getConditionId(const ConditionId& queryId) -{ - // get ConditionId from the database - // User must delete returned object - - ConditionId* dataId = nullptr; - - ConditionId selectedId(queryId); - if (!selectedId.hasVersion()) { - // if version is not specified, first check the selection criteria list - getSelection(&selectedId); - } - - TObjArray validFileIds; - validFileIds.SetOwner(1); - - // look for file matching query requests (path, runRange, version) - if (selectedId.getFirstRun() == mRun && mPathFilter.isSupersetOf(selectedId.getPathString()) && - mVersion == selectedId.getVersion() && !mConditionMetaDataFilter) { - // look into list of valid files previously loaded with Storage::FillValidFileIds() - LOG(DEBUG) << "List of files valid for run " << selectedId.getFirstRun() - << " was loaded. Looking there for fileids valid for path " << selectedId.getPathString().Data() << "!"; - dataId = getId(mValidFileIds, selectedId); - - } else { - // List of files valid for reqested run was not loaded. Looking directly into CDB - LOG(DEBUG) << "List of files valid for run " << selectedId.getFirstRun() << " and version " - << selectedId.getVersion() << " was not loaded. Looking directly into CDB for fileids valid for path " - << selectedId.getPathString().Data() << "!"; - - TString filter; - makeQueryFilter(selectedId.getFirstRun(), selectedId.getLastRun(), nullptr, filter); - - TString pattern = ".root"; - TString optionQuery = "-y -m"; - if (selectedId.getVersion() >= 0) { - pattern.Prepend(Form("_v%d_s0", selectedId.getVersion())); - optionQuery = ""; - } - - TString folderCopy(Form("%s%s/Run", mDBFolder.Data(), selectedId.getPathString().Data())); - - if (optionQuery.Contains("-y")) { - LOG(INFO) << "Only latest version will be returned"; - } - - LOG(DEBUG) << "** mDBFolder = " << folderCopy.Data() << ", pattern = " << pattern.Data() - << ", filter = " << filter.Data(); - TGridResult* res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data()); - if (res) { - for (int i = 0; i < res->GetEntries(); i++) { - ConditionId* validFileId = new ConditionId(); - TString filename = res->GetKey(i, "lfn"); - if (filename == "") { - continue; - } - if (filenameToId(filename, *validFileId)) { - validFileIds.AddLast(validFileId); - } - } - delete res; - } else { - return nullptr; // this should be only in case of file catalogue glitch - } - - dataId = getId(validFileIds, selectedId); - } - - return dataId; -} - -Condition* GridStorage::getCondition(const ConditionId& queryId) -{ - // get Condition from the database - - ConditionId* dataId = getConditionId(queryId); - - if (!dataId) { - LOG(FATAL) << "No valid CDB object found! request was: " << queryId.ToString().Data(); - return nullptr; - } - - TString filename; - if (!idToFilename(*dataId, filename)) { - LOG(DEBUG) << "Bad data ID encountered! Subnormal error!"; - delete dataId; - LOG(FATAL) << "No valid CDB object found! request was: " << queryId.ToString().Data(); - } - - Condition* anCondition = getConditionFromFile(filename, dataId); - - delete dataId; - if (!anCondition) - LOG(FATAL) << "No valid CDB object found! request was: " << queryId.ToString().Data(); - - return anCondition; -} - -Condition* GridStorage::getConditionFromFile(TString& filename, ConditionId* dataId) -{ - // Get AliCBCondition object from file "filename" - - LOG(DEBUG) << "Opening file: " << filename.Data(); - - filename.Prepend("/alien"); - - // if option="CACHEREAD" TFile will use the local caching facility! - TString option = "READ"; - if (mCacheFolder != "") { - - // Check if local cache folder was changed in the meanwhile - TString origCache(TFile::GetCacheFileDir()); - if (mCacheFolder != origCache) { - LOG(WARNING) << "LocalStorage cache folder has been overwritten!! mCacheFolder = " << mCacheFolder.Data() - << " origCache = " << origCache.Data(); - TFile::SetCacheFileDir(mCacheFolder.Data(), mOperateDisconnected); - TFile::ShrinkCacheFileDir(mCacheSize, mCleanupInterval); - } - - option.Prepend("CACHE"); - } - - LOG(DEBUG) << "Option: " << option.Data(); - - TFile* file = TFile::Open(filename, option); - if (!file) { - LOG(DEBUG) << "Can't open file <" << filename.Data() << ">!"; - return nullptr; - } - - // get the only Condition object from the file - // the object in the file is an Condition entry named " Condition" - - Condition* anCondition = dynamic_cast(file->Get(" Condition")); - - if (!anCondition) { - LOG(DEBUG) << "Bad storage data: file does not contain an Condition object!"; - file->Close(); - return nullptr; - } - - // The object's ConditionId is not reset during storage - // If object's ConditionId runRange or version do not match with filename, - // it means that someone renamed file by hand. In this case a warning msg is issued. - - if (anCondition) { - ConditionId entryId = anCondition->getId(); - Int_t tmpSubVersion = dataId->getSubVersion(); - dataId->setSubVersion(entryId.getSubVersion()); // otherwise filename and id may mismatch - if (!entryId.isEqual(dataId)) { - LOG(WARNING) << "Mismatch between file name and object's ConditionId!"; - LOG(WARNING) << "File name: " << dataId->ToString().Data(); - LOG(WARNING) << "Object's ConditionId: " << entryId.ToString().Data(); - } - dataId->setSubVersion(tmpSubVersion); - } - - anCondition->setLastStorage("grid"); - - // Check whether entry contains a TTree. In case load the tree in memory! - loadTreeFromFile(anCondition); - - // close file, return retieved entry - file->Close(); - delete file; - file = nullptr; - - return anCondition; -} - -TList* GridStorage::getAllEntries(const ConditionId& queryId) -{ - // return list of CDB entries matching a generic request (Storage::GetAllObjects) - - TList* result = new TList(); - result->SetOwner(); - - TObjArray validFileIds; - validFileIds.SetOwner(1); - - Bool_t alreadyLoaded = kFALSE; - - // look for file matching query requests (path, runRange) - if (queryId.getFirstRun() == mRun && mPathFilter.isSupersetOf(queryId.getPathString()) && mVersion < 0 && - !mConditionMetaDataFilter) { - // look into list of valid files previously loaded with Storage::FillValidFileIds() - LOG(DEBUG) << "List of files valid for run " << queryId.getFirstRun() << R"( and for path ")" - << queryId.getPathString().Data() << R"(" was loaded. Looking there!)"; - - alreadyLoaded = kTRUE; - - } else { - // List of files valid for reqested run was not loaded. Looking directly into CDB - LOG(DEBUG) << "List of files valid for run " << queryId.getFirstRun() << R"( and for path ")" - << queryId.getPathString().Data() << " was not loaded. Looking directly into CDB!"; - - TString filter; - makeQueryFilter(queryId.getFirstRun(), queryId.getLastRun(), nullptr, filter); - - TString path = queryId.getPathString(); - - TString pattern = "Run*.root"; - TString optionQuery = "-y"; - - TString addFolder = ""; - if (!path.Contains("*")) { - if (!path.BeginsWith("/")) { - addFolder += "/"; - } - addFolder += path; - } else { - if (path.BeginsWith("/")) { - path.Remove(0, 1); - } - if (path.EndsWith("/")) { - path.Remove(path.Length() - 1, 1); - } - TObjArray* tokenArr = path.Tokenize("/"); - if (tokenArr->GetEntries() != 3) { - LOG(ERROR) << "Not a 3 level path! Keeping old query..."; - pattern.Prepend(path + "/"); - } else { - TString str0 = ((TObjString*)tokenArr->At(0))->String(); - TString str1 = ((TObjString*)tokenArr->At(1))->String(); - TString str2 = ((TObjString*)tokenArr->At(2))->String(); - if (str0 != "*" && str1 != "*" && str2 == "*") { - // e.g. "ITS/Calib/*" - addFolder = "/" + str0 + "/" + str1; - } else if (str0 != "*" && str1 == "*" && str2 == "*") { - // e.g. "ITS/*/*" - addFolder = "/" + str0; - } else if (str0 == "*" && str1 == "*" && str2 == "*") { - // e.g. "*/*/*" - // do nothing: addFolder is already an empty string; - } else { - // e.g. "ITS/*/RecoParam" - pattern.Prepend(path + "/"); - } - } - delete tokenArr; - tokenArr = nullptr; - } - - TString folderCopy(Form("%s%s", mDBFolder.Data(), addFolder.Data())); - - LOG(DEBUG) << "mDBFolder = " << folderCopy.Data() << ", pattern = " << pattern.Data() - << ", filter = " << filter.Data(); - - TGridResult* res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data()); - - if (!res) { - LOG(ERROR) << "GridStorage query failed"; - return nullptr; - } - - for (int i = 0; i < res->GetEntries(); i++) { - ConditionId* validFileId = new ConditionId(); - TString filename = res->GetKey(i, "lfn"); - if (filename == "") { - continue; - } - if (filenameToId(filename, *validFileId)) { - validFileIds.AddLast(validFileId); - } - } - delete res; - } - - TIter* iter = nullptr; - if (alreadyLoaded) { - iter = new TIter(&mValidFileIds); - } else { - iter = new TIter(&validFileIds); - } - - TObjArray selectedIds; - selectedIds.SetOwner(1); - - // loop on list of valid Ids to select the right version to get. - // According to query and to the selection criteria list, version can be the highest or exact - IdPath pathCopy; - ConditionId* anIdPtr = nullptr; - ConditionId* dataId = nullptr; - IdPath queryPath = queryId.getPath(); - while ((anIdPtr = dynamic_cast(iter->Next()))) { - IdPath thisCDBPath = anIdPtr->getPath(); - if (!(queryPath.isSupersetOf(thisCDBPath)) || pathCopy.getPathString() == thisCDBPath.getPathString()) { - continue; - } - pathCopy = thisCDBPath; - - // check the selection criteria list for this query - ConditionId thisId(*anIdPtr); - thisId.setVersion(queryId.getVersion()); - if (!thisId.hasVersion()) { - getSelection(&thisId); - } - - if (alreadyLoaded) { - dataId = getId(mValidFileIds, thisId); - } else { - dataId = getId(validFileIds, thisId); - } - if (dataId) { - selectedIds.Add(dataId); - } - } - - delete iter; - iter = nullptr; - - // selectedIds contains the Ids of the files matching all requests of query! - // All the objects are now ready to be retrieved - iter = new TIter(&selectedIds); - while ((anIdPtr = dynamic_cast(iter->Next()))) { - TString filename; - if (!idToFilename(*anIdPtr, filename)) { - LOG(DEBUG) << "Bad data ID encountered! Subnormal error!"; - continue; - } - - Condition* anCondition = getConditionFromFile(filename, anIdPtr); - - if (anCondition) { - result->Add(anCondition); - } - } - delete iter; - iter = nullptr; - - return result; -} - -Bool_t GridStorage::putCondition(Condition* entry, const char* mirrors) -{ - // put an Condition object into the database - - ConditionId& id = entry->getId(); - - // set version for the entry to be stored - if (!prepareId(id)) { - return kFALSE; - } - - // build filename from entry's id - TString filename; - if (!idToFilename(id, filename)) { - LOG(ERROR) << "Bad ID encountered, cannot make a file name out of it!"; - return kFALSE; - } - - TString folderToTag = Form("%s%s", mDBFolder.Data(), id.getPathString().Data()); - - TDirectory* saveDir = gDirectory; - - TString fullFilename = Form("/alien%s", filename.Data()); - TString seMirrors(mirrors); - if (seMirrors.IsNull() || seMirrors.IsWhitespace()) { - seMirrors = getMirrorSEs(); - } - // specify SE to filename - // if a list of SEs was passed to this method or set via setMirrorSEs, set the first as SE for - // opening the file. - // The other SEs will be used in cascade in case of failure in opening the file. - // The remaining SEs will be used to create replicas. - TObjArray* arraySEs = seMirrors.Tokenize(','); - Int_t nSEs = arraySEs->GetEntries(); - Int_t remainingSEs = 1; - if (nSEs == 0) { - if (mSE != "default") { - fullFilename += Form("?se=%s", mSE.Data()); - } - } else { - remainingSEs = nSEs; - } - - // open file - TFile* file = nullptr; - TFile* reopenedFile = nullptr; - LOG(DEBUG) << "mNretry = " << mNretry << ", mInitRetrySeconds = " << mInitRetrySeconds; - TString targetSE(""); - - Bool_t result = kFALSE; - Bool_t reOpenResult = kFALSE; - Int_t reOpenAttempts = 0; - while (!reOpenResult && reOpenAttempts < 2) { // loop to check the file after closing it, to catch - // the unlikely but possible case when the file - // is cleaned up by alien just before closing as a consequence of a network disconnection while - // writing - - while (!file && remainingSEs > 0) { - if (nSEs != 0) { - TObjString* target = (TObjString*)arraySEs->At(nSEs - remainingSEs); - targetSE = target->String(); - if (!(targetSE.BeginsWith("ALICE::") && targetSE.CountChar(':') == 4)) { - LOG(ERROR) << R"(")" << targetSE.Data() << R"(" is an invalid storage element identifier.)"; - continue; - } - if (fullFilename.Contains('?')) { - fullFilename.Remove(fullFilename.Last('?')); - } - fullFilename += Form("?se=%s", targetSE.Data()); - } - Int_t remainingAttempts = mNretry; - Int_t nsleep = mInitRetrySeconds; // number of seconds between attempts. We let it increase exponentially - LOG(DEBUG) << "Uploading file into SE #" << nSEs - remainingSEs + 1 << ": " << targetSE.Data(); - while (remainingAttempts > 0) { - LOG(DEBUG) << "Uploading file into OCDB at " << targetSE.Data() << " - Attempt #" - << mNretry - remainingAttempts + 1; - remainingAttempts--; - file = TFile::Open(fullFilename, "CREATE"); - if (!file || !file->IsWritable()) { - if (file) { // file is not writable - file->Close(); - delete file; - file = nullptr; - } - TString message(TString::Format("Attempt %d failed.", mNretry - remainingAttempts)); - if (remainingAttempts > 0) { - message += " Sleeping for "; - message += nsleep; - message += " seconds"; - } else { - if (remainingSEs > 0) { - message += " Trying to upload at next SE"; - } - } - LOG(DEBUG) << message.Data(); - if (remainingAttempts > 0) { - sleep(nsleep); - } - } else { - remainingAttempts = 0; - } - nsleep *= mInitRetrySeconds; - } - remainingSEs--; - } - if (!file) { - LOG(ERROR) << "All " << mNretry << " attempts have failed on all " << nSEs << " SEs. Returning..."; - return kFALSE; - } - - file->cd(); - - // setTreeToFile(entry, file); - entry->setVersion(id.getVersion()); - - // write object (key name: " Condition") - result = (file->WriteTObject(entry, " Condition") != 0); - file->Close(); - if (!result) { - LOG(ERROR) << "Can't write entry to file <" << filename.Data() << ">!"; - } else { - LOG(DEBUG) << "Reopening file " << fullFilename.Data() << " for checking its correctness"; - reopenedFile = TFile::Open(fullFilename.Data(), "READ"); - if (!reopenedFile) { - reOpenResult = kFALSE; - LOG(INFO) << R"(The file ")" << fullFilename.Data() - << R"(" was closed successfully but cannot be reopened. Trying now to regenerate it (regeneration attempt number )" - << ++reOpenAttempts; - delete file; - file = nullptr; - LOG(DEBUG) << "Removing file " << filename.Data(); - if (!gGrid->Rm(filename.Data())) - LOG(ERROR) << "Can't delete file!"; - remainingSEs++; - } else { - reOpenResult = kTRUE; - if (!Manager::Instance()->isOcdbUploadMode()) { - reopenedFile->Close(); - delete reopenedFile; - reopenedFile = nullptr; - } - } - } - } - - if (saveDir) { - saveDir->cd(); - } else - gROOT->cd(); - delete file; - file = nullptr; - - if (result && reOpenResult) { - - if (!tagFileId(filename, &id)) { - LOG(INFO) << R"(CDB tagging failed. Deleting file ")" << filename.Data() << R"("!)"; - if (!gGrid->Rm(filename.Data())) - LOG(ERROR) << "Can't delete file!"; - return kFALSE; - } - - tagFileConditionMetaData(filename, entry->getConditionMetaData()); - } else { - LOG(ERROR) << "The file could not be opened or the object could not be written."; - if (!gGrid->Rm(filename.Data())) - LOG(ERROR) << "Can't delete file!"; - return kFALSE; - } - - LOG(INFO) << R"(CDB object stored into file ")" << filename.Data() << R"(" )"; - if (nSEs == 0) - LOG(INFO) << "Storage Element: " << mSE.Data(); - else - LOG(INFO) << "Storage Element: " << targetSE.Data(); - - // In case of other SEs specified by the user, mirror the file to the remaining SEs - for (Int_t i = 0; i < nSEs; i++) { - if (i == nSEs - remainingSEs - 1) { - continue; - } // skip mirroring to the SE where the file was saved - TString mirrorCmd("mirror "); - mirrorCmd += filename; - mirrorCmd += " "; - TObjString* target = (TObjString*)arraySEs->At(i); - TString mirrorSE(target->String()); - mirrorCmd += mirrorSE; - LOG(DEBUG) << R"(mirror command: ")" << mirrorCmd.Data() << R"(")"; - LOG(INFO) << "Mirroring to storage element: " << mirrorSE.Data(); - gGrid->Command(mirrorCmd.Data()); - } - arraySEs->Delete(); - arraySEs = nullptr; - - if (Manager::Instance()->isOcdbUploadMode()) { // if uploading to OCDBs, add to cvmfs too - if (!filename.BeginsWith("/alice/data") && !filename.BeginsWith("/alice/simulation/2008/v4-15-Release")) { - LOG(ERROR) << R"(Cannot upload to CVMFS OCDBs a non official CDB object: ")" << filename.Data() << R"("!)"; - } else { - if (!putInCvmfs(filename, reopenedFile)) - LOG(ERROR) << R"(Could not upload AliEn file ")" << filename.Data() << R"(" to CVMFS OCDB!)"; - } - reopenedFile->Close(); - delete reopenedFile; - reopenedFile = nullptr; - } - - return kTRUE; -} - -Bool_t GridStorage::putInCvmfs(TString& filename, TFile* cdbFile) const -{ - // Add the CDB object to cvmfs OCDB - - TString cvmfsFilename(filename); - // cvmfsFilename.Remove(TString::kTrailing, '/'); - TString basename = (cvmfsFilename(cvmfsFilename.Last('/') + 1, cvmfsFilename.Length())); - TString cvmfsDirname = cvmfsFilename.Remove(cvmfsFilename.Last('/'), cvmfsFilename.Length()); - TRegexp threeLevelsRE("[^/]+/[^/]+/[^/]+$"); - TString threeLevels = cvmfsDirname(threeLevelsRE); - - TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB"); - TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release"); - TString rawFolder = cvmfsDirname(re_RawFolder); - TString mcFolder = cvmfsDirname(re_MCFolder); - if (!rawFolder.IsNull()) { - cvmfsDirname.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration"); - } else if (!mcFolder.IsNull()) { - cvmfsDirname.Replace(0, 36, "/cvmfs/alice-ocdb.cern.ch/calibration/MC"); - } else { - LOG(ERROR) << "OCDB folder set for an invalid OCDB storage:\n " << cvmfsDirname.Data(); - return kFALSE; - } - // now cvmfsDirname is the full dirname in cvmfs - LOG(DEBUG) << R"(Publishing ")" << basename.Data() << R"(" in ")" << cvmfsDirname.Data() << R"(")"; - - // Tar the file with the right prefix path. Include the directory structure in the tarball - // to cover the case of a containing directory being new in cvmfs, plus a container directory - // to avoid clashing with stuff present in the local directory - TString firstLevel(threeLevels(0, threeLevels.First('/'))); - TString tempDir("tmpToCvmfsOcdbs"); - gSystem->Exec(Form("rm -r %s > /dev/null 2>&1", tempDir.Data())); // to be sure not to publish other stuff in cvmfs - Int_t result = gSystem->Exec(Form("mkdir -p %s/%s", tempDir.Data(), threeLevels.Data())); - if (result != 0) { - LOG(ERROR) << R"(Could not create the directory ")" << tempDir.Data() << "/" << threeLevels.Data() << R"(")"; - return kFALSE; - } - cdbFile->Cp(Form("%s/%s/%s", tempDir.Data(), threeLevels.Data(), basename.Data())); - TString tarFileName("cdbObjectToAdd.tar.gz"); - TString cvmfsBaseFolder(cvmfsDirname(0, cvmfsDirname.Last('/'))); - cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last('/')); - cvmfsBaseFolder = cvmfsBaseFolder(0, cvmfsBaseFolder.Last('/')); - // tarCommand should be e.g.: tar --transform - // 's,^,/cvmfs/alice-ocdb.cern.ch/calibration/data/2010/OCDB/,S' -cvzf objecttoadd.tar.gz basename - result = gSystem->Exec(Form("tar --transform 's,^%s,%s,S' -cvzf %s %s", tempDir.Data(), cvmfsBaseFolder.Data(), - tarFileName.Data(), tempDir.Data())); - if (result != 0) { - LOG(ERROR) << R"(Could not create the tarball for the object ")" << filename.Data() << R"(")"; - return kFALSE; - } - - // Copy the file to cvmfs (requires to have the executable in the path and access to the server) - result = gSystem->Exec(Form("ocdb-cvmfs %s", tarFileName.Data())); - if (result != 0) { - LOG(ERROR) << R"(Could not execute "ocdb-cvmfs )" << filename.Data() << R"(")"; - return kFALSE; - } - - // Remove the local file and the tar-file - gSystem->Exec(Form("rm -r %s", tempDir.Data())); - gSystem->Exec(Form("rm %s", tarFileName.Data())); - - return kTRUE; -} - -Bool_t GridStorage::addTag(TString& folderToTag, const char* tagname) -{ - // add "tagname" tag (CDB or CDB_MD) to folder where object will be stored - - Bool_t result = kTRUE; - LOG(DEBUG) << "adding " << tagname << R"( tag to folder ")" << folderToTag.Data() << R"(")"; - TString addTagCommand = Form("addTag %s %s", folderToTag.Data(), tagname); - TGridResult* gridres = gGrid->Command(addTagCommand.Data()); - const char* resCode = gridres->GetKey(0, "__result__"); // '1' if success - if (resCode[0] != '1') { - LOG(ERROR) << R"(Couldn't add ")" << tagname << R"(" tags to folder )" << folderToTag.Data() << "!"; - result = kFALSE; - } - delete gridres; - return result; -} - -Bool_t GridStorage::tagFileId(TString& filename, const ConditionId* id) -{ - // tag stored object in CDB table using object ConditionId's parameters - - TString dirname(filename); - Int_t dirNumber = gGrid->Mkdir(dirname.Remove(dirname.Last('/')), "-d"); - - TString addTagValue1 = Form("addTagValue %s CDB ", filename.Data()); - TString addTagValue2 = - Form("first_run=%d last_run=%d version=%d ", id->getFirstRun(), id->getLastRun(), id->getVersion()); - TString addTagValue3 = Form(R"(path_level_0="%s" path_level_1="%s" path_level_2="%s" )", - id->getPathLevel(0).Data(), id->getPathLevel(1).Data(), id->getPathLevel(2).Data()); - // TString addTagValue4 = Form("version_path=\"%s\" - // dir_number=%d",Form("%d_%s",id->getVersion(),filename.Data()),dirNumber); - TString addTagValue4 = Form(R"(version_path="%09d%s" dir_number=%d)", id->getVersion(), filename.Data(), dirNumber); - TString addTagValue = - Form("%s%s%s%s", addTagValue1.Data(), addTagValue2.Data(), addTagValue3.Data(), addTagValue4.Data()); - - Bool_t result = kFALSE; - LOG(DEBUG) << "Tagging file. Tag command: " << addTagValue.Data(); - TGridResult* res = gGrid->Command(addTagValue.Data()); - const char* resCode = res->GetKey(0, "__result__"); // '1' if success - if (resCode[0] != '1') { - LOG(ERROR) << "Couldn't add CDB tag value to file " << filename.Data() << " !"; - result = kFALSE; - } else { - LOG(DEBUG) << "Object successfully tagged."; - result = kTRUE; - } - delete res; - return result; -} - -Bool_t GridStorage::tagFileConditionMetaData(TString& filename, const ConditionMetaData* md) -{ - // tag stored object in CDB table using object ConditionId's parameters - - TString addTagValue1 = Form("addTagValue %s CDB_MD ", filename.Data()); - TString addTagValue2 = Form(R"(object_classname="%s" responsible="%s" beam_period=%d )", md->getObjectClassName(), - md->getResponsible(), md->getBeamPeriod()); - TString addTagValue3 = Form(R"(aliroot_version="%s" comment="%s")", md->getAliRootVersion(), md->getComment()); - TString addTagValue = Form("%s%s%s", addTagValue1.Data(), addTagValue2.Data(), addTagValue3.Data()); - - Bool_t result = kFALSE; - LOG(DEBUG) << "Tagging file. Tag command: " << addTagValue.Data(); - TGridResult* res = gGrid->Command(addTagValue.Data()); - const char* resCode = res->GetKey(0, "__result__"); // '1' if success - if (resCode[0] != '1') { - LOG(WARNING) << "Couldn't add CDB_MD tag value to file " << filename.Data() << " !"; - result = kFALSE; - } else { - LOG(DEBUG) << "Object successfully tagged."; - result = kTRUE; - } - return result; -} - -TList* GridStorage::getIdListFromFile(const char* fileName) -{ - - TString turl(fileName); - turl.Prepend("/alien" + mDBFolder); - turl += "?se="; - turl += mSE.Data(); - TFile* file = TFile::Open(turl); - if (!file) { - LOG(ERROR) << "Can't open selection file <" << turl.Data() << ">!"; - return nullptr; - } - - TList* list = new TList(); - list->SetOwner(); - int i = 0; - TString keycycle; - - ConditionId* id; - while (1) { - i++; - keycycle = " ConditionId;"; - keycycle += i; - - id = (ConditionId*)file->Get(keycycle); - if (!id) { - break; - } - list->AddFirst(id); - } - file->Close(); - delete file; - file = nullptr; - - return list; -} - -Bool_t GridStorage::hasConditionType(const char* path) const -{ - // check for path in storage's DBFolder - - TString initDir(gGrid->Pwd(0)); - TString dirName(mDBFolder); - dirName += path; // dirName = mDBFolder/path - Bool_t result = kFALSE; - if (gGrid->Cd(dirName, 0)) { - result = kTRUE; - } - gGrid->Cd(initDir.Data(), 0); - return result; -} - -void GridStorage::queryValidFiles() -{ - // Query the CDB for files valid for Storage::mRun - // Fills list mValidFileIds with ConditionId objects extracted from CDB files - // selected from AliEn metadata. - // If mVersion was not set, mValidFileIds is filled with highest versions. - - TString filter; - makeQueryFilter(mRun, mRun, mConditionMetaDataFilter, filter); - - TString path = mPathFilter.getPathString(); - - TString pattern = "Run*"; - TString optionQuery = "-y"; - if (mVersion >= 0) { - pattern += Form("_v%d_s0", mVersion); - optionQuery = ""; - } - pattern += ".root"; - LOG(DEBUG) << "pattern: " << pattern.Data(); - - TString addFolder = ""; - if (!path.Contains("*")) { - if (!path.BeginsWith("/")) { - addFolder += "/"; - } - addFolder += path; - } else { - if (path.BeginsWith("/")) { - path.Remove(0, 1); - } - if (path.EndsWith("/")) { - path.Remove(path.Length() - 1, 1); - } - TObjArray* tokenArr = path.Tokenize("/"); - if (tokenArr->GetEntries() != 3) { - LOG(ERROR) << "Not a 3 level path! Keeping old query..."; - pattern.Prepend(path + "/"); - } else { - TString str0 = ((TObjString*)tokenArr->At(0))->String(); - TString str1 = ((TObjString*)tokenArr->At(1))->String(); - TString str2 = ((TObjString*)tokenArr->At(2))->String(); - if (str0 != "*" && str1 != "*" && str2 == "*") { - // e.g. "ITS/Calib/*" - addFolder = "/" + str0 + "/" + str1; - } else if (str0 != "*" && str1 == "*" && str2 == "*") { - // e.g. "ITS/*/*" - addFolder = "/" + str0; - } else if (str0 == "*" && str1 == "*" && str2 == "*") { - // e.g. "*/*/*" - // do nothing: addFolder is already an empty string; - } else { - // e.g. "ITS/*/RecoParam" - pattern.Prepend(path + "/"); - } - } - delete tokenArr; - tokenArr = nullptr; - } - - TString folderCopy(Form("%s%s", mDBFolder.Data(), addFolder.Data())); - - LOG(DEBUG) << "mDBFolder = " << folderCopy.Data() << ", pattern = " << pattern.Data() - << ", filter = " << filter.Data(); - - if (optionQuery == "-y") { - LOG(INFO) << "Only latest version will be returned"; - } - - TGridResult* res = gGrid->Query(folderCopy, pattern, filter, optionQuery.Data()); - - if (!res) { - LOG(ERROR) << "GridStorage query failed"; - return; - } - - TIter next(res); - TMap* map; - while ((map = (TMap*)next())) { - TObjString* entry; - if ((entry = (TObjString*)((TMap*)map)->GetValue("lfn"))) { - TString& filename = entry->String(); - if (filename.IsNull()) { - continue; - } - LOG(DEBUG) << "Found valid file: " << filename.Data(); - ConditionId* validFileId = new ConditionId(); - Bool_t result = filenameToId(filename, *validFileId); - if (result) { - mValidFileIds.AddLast(validFileId); - } else { - delete validFileId; - } - } - } - delete res; -} - -void GridStorage::makeQueryFilter(Int_t firstRun, Int_t lastRun, const ConditionMetaData* md, TString& result) const -{ - // create filter for file query - - result = Form("CDB:first_run<=%d and CDB:last_run>=%d", firstRun, lastRun); - - // if(version >= 0) { - // result += Form(" and CDB:version=%d", version); - // } - // if(pathFilter.getLevel0() != "*") { - // result += Form(" and CDB:path_level_0=\"%s\"", pathFilter.getLevel0().Data()); - // } - // if(pathFilter.getLevel1() != "*") { - // result += Form(" and CDB:path_level_1=\"%s\"", pathFilter.getLevel1().Data()); - // } - // if(pathFilter.getLevel2() != "*") { - // result += Form(" and CDB:path_level_2=\"%s\"", pathFilter.getLevel2().Data()); - // } - - if (md) { - if (md->getObjectClassName()[0] != '\0') { - result += Form(R"( and CDB_MD:object_classname="%s")", md->getObjectClassName()); - } - if (md->getResponsible()[0] != '\0') { - result += Form(R"( and CDB_MD:responsible="%s")", md->getResponsible()); - } - if (md->getBeamPeriod() != 0) { - result += Form(" and CDB_MD:beam_period=%d", md->getBeamPeriod()); - } - if (md->getAliRootVersion()[0] != '\0') { - result += Form(R"( and CDB_MD:aliroot_version="%s")", md->getAliRootVersion()); - } - if (md->getComment()[0] != '\0') { - result += Form(R"( and CDB_MD:comment="%s")", md->getComment()); - } - } - LOG(DEBUG) << "filter: " << result.Data(); -} - -///////////////////////////////////////////////////////////////////////////////////////////////// -// // -// GridStorage factory // -// // -///////////////////////////////////////////////////////////////////////////////////////////////// - -ClassImp(GridStorageFactory); - -Bool_t GridStorageFactory::validateStorageUri(const char* gridString) -{ - // check if the string is valid GridStorage URI - - TRegexp gridPattern("^alien://.+$"); - - return TString(gridString).Contains(gridPattern); -} - -StorageParameters* GridStorageFactory::createStorageParameter(const char* gridString) -{ - // create GridStorageParameters class from the URI string - - if (!validateStorageUri(gridString)) { - return nullptr; - } - - TString buffer(gridString); - - TString gridUrl = "alien://"; - TString user = ""; - TString dbFolder = ""; - TString se = "default"; - TString cacheFolder = ""; - Bool_t operateDisconnected = kTRUE; - Long64_t cacheSize = (UInt_t)1024 * 1024 * 1024; // 1GB - Long_t cleanupInterval = 0; - - TObjArray* arr = buffer.Tokenize('?'); - TIter iter(arr); - TObjString* str = nullptr; - - while ((str = (TObjString*)iter.Next())) { - TString entry(str->String()); - Int_t indeq = entry.Index('='); - if (indeq == -1) { - if (entry.BeginsWith("alien://")) { // maybe it's a gridUrl! - gridUrl = entry; - continue; - } else { - LOG(ERROR) << "Invalid entry! " << entry.Data(); - continue; - } - } - - TString key = entry(0, indeq); - TString value = entry(indeq + 1, entry.Length() - indeq); - - if (key.Contains("grid", TString::kIgnoreCase)) { - gridUrl += value; - } else if (key.Contains("user", TString::kIgnoreCase)) { - user = value; - } else if (key.Contains("se", TString::kIgnoreCase)) { - se = value; - } else if (key.Contains("cacheF", TString::kIgnoreCase)) { - cacheFolder = value; - if (!cacheFolder.IsNull() && !cacheFolder.EndsWith("/")) { - cacheFolder += "/"; - } - } else if (key.Contains("folder", TString::kIgnoreCase)) { - dbFolder = value; - } else if (key.Contains("operateDisc", TString::kIgnoreCase)) { - if (value == "kTRUE") { - operateDisconnected = kTRUE; - } else if (value == "kFALSE") { - operateDisconnected = kFALSE; - } else if (value == "0" || value == "1") { - operateDisconnected = (Bool_t)value.Atoi(); - } else { - LOG(ERROR) << "Invalid entry! " << entry.Data(); - return nullptr; - } - } else if (key.Contains("cacheS", TString::kIgnoreCase)) { - if (value.IsDigit()) { - cacheSize = value.Atoi(); - } else { - LOG(ERROR) << "Invalid entry! " << entry.Data(); - return nullptr; - } - } else if (key.Contains("cleanupInt", TString::kIgnoreCase)) { - if (value.IsDigit()) { - cleanupInterval = value.Atoi(); - } else { - LOG(ERROR) << "Invalid entry! " << entry.Data(); - return nullptr; - } - } else { - LOG(ERROR) << "Invalid entry! " << entry.Data(); - return nullptr; - } - } - delete arr; - arr = nullptr; - - LOG(DEBUG) << "gridUrl: " << gridUrl.Data(); - LOG(DEBUG) << "user: " << user.Data(); - LOG(DEBUG) << "dbFolder: " << dbFolder.Data(); - LOG(DEBUG) << "s.e.: " << se.Data(); - LOG(DEBUG) << "local cache folder: " << cacheFolder.Data(); - LOG(DEBUG) << "local cache operate disconnected: " << operateDisconnected; - LOG(DEBUG) << "local cache size: " << cacheSize << ""; - LOG(DEBUG) << "local cache cleanup interval: " << cleanupInterval << ""; - - if (dbFolder == "") { - LOG(ERROR) << "Base folder must be specified!"; - return nullptr; - } - - return new GridStorageParameters(gridUrl.Data(), user.Data(), dbFolder.Data(), se.Data(), cacheFolder.Data(), - operateDisconnected, - cacheSize, cleanupInterval); -} - -Storage* GridStorageFactory::createStorage(const StorageParameters* param) -{ - // create GridStorage storage instance from parameters - GridStorage* grid = nullptr; - if (GridStorageParameters::Class() == param->IsA()) { - const GridStorageParameters* gridParam = (const GridStorageParameters*)param; - grid = new GridStorage(gridParam->GridUrl().Data(), gridParam->getUser().Data(), gridParam->getDBFolder().Data(), - gridParam->getSE().Data(), gridParam->getCacheFolder().Data(), - gridParam->getOperateDisconnected(), - gridParam->getCacheSize(), gridParam->getCleanupInterval()); - } - if (!gGrid && grid) { - delete grid; - grid = nullptr; - } - return grid; -} - -// GridStorage Parameter class -ClassImp(GridStorageParameters); - -GridStorageParameters::GridStorageParameters() - : StorageParameters(), - mGridUrl(), - mUser(), - mDBFolder(), - mSE(), - mCacheFolder(), - mOperateDisconnected(), - mCacheSize(), - mCleanupInterval() -{ - // default constructor -} - -GridStorageParameters::GridStorageParameters(const char* gridUrl, const char* user, const char* dbFolder, - const char* se, - const char* cacheFolder, Bool_t operateDisconnected, Long64_t cacheSize, - Long_t cleanupInterval) - : StorageParameters(), - mGridUrl(gridUrl), - mUser(user), - mDBFolder(dbFolder), - mSE(se), - mCacheFolder(cacheFolder), - mOperateDisconnected(operateDisconnected), - mCacheSize(cacheSize), - mCleanupInterval(cleanupInterval) -{ - // constructor - setType("alien"); - TString uri = Form( - "%s?User=%s?DBFolder=%s?SE=%s?CacheFolder=%s" - "?OperateDisconnected=%d?CacheSize=%lld?CleanupInterval=%ld", - mGridUrl.Data(), mUser.Data(), mDBFolder.Data(), mSE.Data(), mCacheFolder.Data(), - mOperateDisconnected, mCacheSize, mCleanupInterval); - setUri(uri.Data()); -} - -GridStorageParameters::~GridStorageParameters() = default; - -StorageParameters* GridStorageParameters::cloneParam() const -{ - // clone parameter - return new GridStorageParameters(mGridUrl.Data(), mUser.Data(), mDBFolder.Data(), mSE.Data(), mCacheFolder.Data(), - mOperateDisconnected, mCacheSize, mCleanupInterval); -} - -ULong_t GridStorageParameters::getHash() const -{ - // return getHash function - return mGridUrl.Hash() + mUser.Hash() + mDBFolder.Hash() + mSE.Hash() + mCacheFolder.Hash(); -} - -Bool_t GridStorageParameters::isEqual(const TObject* obj) const -{ - // check if this object is equal to StorageParameters obj - if (this == obj) { - return kTRUE; - } - if (GridStorageParameters::Class() != obj->IsA()) { - return kFALSE; - } - GridStorageParameters* other = (GridStorageParameters*)obj; - if (mGridUrl != other->mGridUrl) { - return kFALSE; - } - if (mUser != other->mUser) { - return kFALSE; - } - if (mDBFolder != other->mDBFolder) { - return kFALSE; - } - if (mSE != other->mSE) { - return kFALSE; - } - if (mCacheFolder != other->mCacheFolder) { - return kFALSE; - } - if (mOperateDisconnected != other->mOperateDisconnected) { - return kFALSE; - } - if (mCacheSize != other->mCacheSize) { - return kFALSE; - } - if (mCleanupInterval != other->mCleanupInterval) { - return kFALSE; - } - return kTRUE; -} diff --git a/CCDB/src/IdRunRange.cxx b/CCDB/src/IdRunRange.cxx deleted file mode 100644 index 3245181356cb7..0000000000000 --- a/CCDB/src/IdRunRange.cxx +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// defines the run validity range of the object: // -// [mFirstRun, mLastRun] // -#include "CCDB/IdRunRange.h" -#include // for LOG - -using namespace o2::ccdb; - -ClassImp(IdRunRange); - -IdRunRange::IdRunRange() : mFirstRun(-1), mLastRun(-1) -{ - // constructor -} - -IdRunRange::IdRunRange(Int_t firstRun, Int_t lastRun) : mFirstRun(firstRun), mLastRun(lastRun) -{ - // constructor -} - -IdRunRange::~IdRunRange() = default; - -Bool_t IdRunRange::isOverlappingWith(const IdRunRange& other) const -{ - // check if this runRange overlaps other runRange - - if (!(isValid() && other.isValid())) { - LOG(ERROR) << "Comparing invalid run ranges!"; - return kFALSE; - } - - if (isAnyRange() || other.isAnyRange()) { - LOG(ERROR) << "Comparing unspecified ranges!"; - return kFALSE; - } - - return ((mFirstRun < other.mFirstRun && other.mFirstRun <= mLastRun) || - (other.mFirstRun <= mFirstRun && mFirstRun <= other.mLastRun)); -} - -Bool_t IdRunRange::isSupersetOf(const IdRunRange& other) const -{ - // check if this runRange contains other runRange - - if (!(isValid() && other.isValid())) { - LOG(ERROR) << "Comparing invalid run ranges!"; - return kFALSE; - } - - if (isAnyRange()) { - return kTRUE; - } - - return mFirstRun <= other.mFirstRun && other.mFirstRun <= mLastRun && mFirstRun <= other.mLastRun && - other.mLastRun <= mLastRun; -} - -Bool_t IdRunRange::isEqual(const TObject* obj) const -{ - // check if this runRange is equal to other runRange - - if (this == obj) { - return kTRUE; - } - - if (IdRunRange::Class() != obj->IsA()) { - return kFALSE; - } - IdRunRange* other = (IdRunRange*)obj; - return mFirstRun == other->mFirstRun && mLastRun == other->mLastRun; -} - -Bool_t IdRunRange::isValid() const -{ - // validity check - - if (mFirstRun < 0 && mLastRun < 0) { - return kTRUE; - } - - if (mFirstRun >= 0 && mLastRun >= mFirstRun) { - return kTRUE; - } - - return kFALSE; -} diff --git a/CCDB/src/LocalStorage.cxx b/CCDB/src/LocalStorage.cxx deleted file mode 100644 index 6112cec87bf25..0000000000000 --- a/CCDB/src/LocalStorage.cxx +++ /dev/null @@ -1,1184 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// access class to a DataBase in a local storage // - -#include "CCDB/LocalStorage.h" -#include // for LOG -#include // for TFile -#include // for TObjString -#include // for TRegexp -#include // for TSystem, gSystem -#include "CCDB/Condition.h" // for Condition - -using namespace o2::ccdb; - -ClassImp(LocalStorage); - -LocalStorage::LocalStorage(const char* baseDir) : mBaseDirectory(baseDir) -{ - // constructor - - LOG(DEBUG) << "mBaseDirectory = " << mBaseDirectory.Data(); - - // check baseDire: trying to cd to baseDir; if it does not exist, create it - void* dir = gSystem->OpenDirectory(baseDir); - if (dir == nullptr) { - if (gSystem->mkdir(baseDir, kTRUE)) { - LOG(ERROR) << R"(Can't open directory ")" << baseDir << R"("!)"; //!!!!!!!! to be commented out for testing - } - - } else { - LOG(DEBUG) << R"(Folder ")" << mBaseDirectory.Data() << R"(" found)"; - gSystem->FreeDirectory(dir); - } - mType = "local"; - mBaseFolder = mBaseDirectory; -} - -LocalStorage::~LocalStorage() = default; - -Bool_t LocalStorage::filenameToId(const char* filename, IdRunRange& runRange, Int_t& version, Int_t& subVersion) -{ - // build ConditionId from filename numbers - - Ssiz_t mSize; - - // valid filename: Run#firstRun_#lastRun_v#version_s#subVersion.root - TRegexp keyPattern("^Run[0-9]+_[0-9]+_v[0-9]+_s[0-9]+.root$"); - keyPattern.Index(filename, &mSize); - if (!mSize) { - LOG(DEBUG) << "Bad filename <" << filename << ">."; - return kFALSE; - } - - TString idString(filename); - idString.Resize(idString.Length() - sizeof(".root") + 1); - - TObjArray* strArray = (TObjArray*)idString.Tokenize("_"); - - TString firstRunString(((TObjString*)strArray->At(0))->GetString()); - runRange.setFirstRun(atoi(firstRunString.Data() + 3)); - runRange.setLastRun(atoi(((TObjString*)strArray->At(1))->GetString())); - - TString verString(((TObjString*)strArray->At(2))->GetString()); - version = atoi(verString.Data() + 1); - - TString subVerString(((TObjString*)strArray->At(3))->GetString()); - subVersion = atoi(subVerString.Data() + 1); - - delete strArray; - - return kTRUE; -} - -Bool_t LocalStorage::idToFilename(const ConditionId& id, TString& filename) const -{ - // build file name from ConditionId data (run range, version, subVersion) - - LOG(DEBUG) << "mBaseDirectory = " << mBaseDirectory.Data(); - - if (!id.getIdRunRange().isValid()) { - LOG(DEBUG) << R"(Invalid run range ")" << id.getFirstRun() << "," << id.getLastRun() << R"(".)"; - return kFALSE; - } - - if (id.getVersion() < 0) { - LOG(DEBUG) << "Invalid version <" << id.getVersion() << ">."; - return kFALSE; - } - - if (id.getSubVersion() < 0) { - LOG(DEBUG) << "Invalid subversion <" << id.getSubVersion() << ">."; - return kFALSE; - } - - filename = Form("Run%d_%d_v%d_s%d.root", id.getFirstRun(), id.getLastRun(), id.getVersion(), id.getSubVersion()); - - filename.Prepend(mBaseDirectory + '/' + id.getPathString() + '/'); - - return kTRUE; -} - -Bool_t LocalStorage::prepareId(ConditionId& id) -{ - // prepare id (version, subVersion) of the object that will be stored (called by putCondition) - - TString dirName = Form("%s/%s", mBaseDirectory.Data(), id.getPathString().Data()); - - // go to the path; if directory does not exist, create it - void* dirPtr = gSystem->OpenDirectory(dirName); - if (!dirPtr) { - gSystem->mkdir(dirName, kTRUE); - dirPtr = gSystem->OpenDirectory(dirName); - - if (!dirPtr) { - LOG(ERROR) << R"(Can't create directory ")" << dirName.Data() << R"("!)"; - return kFALSE; - } - } - - const char* filename; - IdRunRange aIdRunRange; // the runRange got from filename - IdRunRange lastIdRunRange(-1, -1); // highest runRange found - Int_t aVersion, aSubVersion; // the version subVersion got from filename - Int_t lastVersion = 0, lastSubVersion = -1; // highest version and subVersion found - - if (!id.hasVersion()) { // version not specified: look for highest version & subVersion - - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files - - TString aString(filename); - if (aString == "." || aString == "..") { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - LOG(DEBUG) << "Bad filename <" << filename << ">! I'll skip it."; - continue; - } - - if (!aIdRunRange.isOverlappingWith(id.getIdRunRange())) { - continue; - } - if (aVersion < lastVersion) { - continue; - } - if (aVersion > lastVersion) { - lastSubVersion = -1; - } - if (aSubVersion < lastSubVersion) { - continue; - } - lastVersion = aVersion; - lastSubVersion = aSubVersion; - lastIdRunRange = aIdRunRange; - } - - id.setVersion(lastVersion); - id.setSubVersion(lastSubVersion + 1); - - } else { // version specified, look for highest subVersion only - - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on the files - - TString aString(filename); - if (aString == "." || aString == "..") { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - LOG(DEBUG) << "Bad filename <" << filename << ">!I'll skip it."; - continue; - } - - if (aIdRunRange.isOverlappingWith(id.getIdRunRange()) && aVersion == id.getVersion() && - aSubVersion > lastSubVersion) { - lastSubVersion = aSubVersion; - lastIdRunRange = aIdRunRange; - } - } - - id.setSubVersion(lastSubVersion + 1); - } - - gSystem->FreeDirectory(dirPtr); - - TString lastStorage = id.getLastStorage(); - if (lastStorage.Contains(TString("grid"), TString::kIgnoreCase) && id.getSubVersion() > 0) { - LOG(ERROR) << "GridStorage to LocalStorage Storage error! local object with version v" << id.getVersion() << "_s" - << id.getSubVersion() - 1 << " found:"; - LOG(ERROR) << "This object has been already transferred from GridStorage (check v" << id.getVersion() << "_s0)!"; - return kFALSE; - } - - if (lastStorage.Contains(TString("new"), TString::kIgnoreCase) && id.getSubVersion() > 0) { - LOG(DEBUG) << "A NEW object is being stored with version v" << id.getVersion() << "_s" << id.getSubVersion(); - LOG(DEBUG) << "and it will hide previously stored object with v" << id.getVersion() << "_s" - << id.getSubVersion() - 1 << "!"; - } - - if (!lastIdRunRange.isAnyRange() && !(lastIdRunRange.isEqual(&id.getIdRunRange()))) - LOG(WARNING) << "Run range modified w.r.t. previous version (Run" << lastIdRunRange.getFirstRun() << "_" - << lastIdRunRange.getLastRun() << "_v" << id.getVersion() << "_s" << id.getSubVersion() - 1; - - return kTRUE; -} - -ConditionId* LocalStorage::getId(const ConditionId& query) -{ - // look for filename matching query (called by getConditionId) - - // if querying for mRun and not specifying a version, look in the mValidFileIds list - if (!Manager::Instance()->getCvmfsOcdbTag().IsNull() && query.getFirstRun() == mRun && !query.hasVersion()) { - // if(query.getFirstRun() == mRun && !query.hasVersion()) { - // get id from mValidFileIds - TIter iter(&mValidFileIds); - - ConditionId* anIdPtr = nullptr; - ConditionId* result = nullptr; - - while ((anIdPtr = dynamic_cast(iter.Next()))) { - if (anIdPtr->getPathString() == query.getPathString()) { - result = new ConditionId(*anIdPtr); - break; - } - } - return result; - } - - // otherwise browse in the local filesystem CDB storage - TString dirName = Form("%s/%s", mBaseDirectory.Data(), query.getPathString().Data()); - - void* dirPtr = gSystem->OpenDirectory(dirName); - if (!dirPtr) { - LOG(DEBUG) << "Directory <" << (query.getPathString()).Data() << "> not found"; - LOG(DEBUG) << "in DB folder " << mBaseDirectory.Data(); - return nullptr; - } - - const char* filename; - ConditionId* result = new ConditionId(); - result->setPath(query.getPathString()); - - IdRunRange aIdRunRange; // the runRange got from filename - Int_t aVersion, aSubVersion; // the version and subVersion got from filename - - if (!query.hasVersion()) { // neither version and subversion specified -> look for highest version - // and subVersion - - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files - - TString aString(filename); - if (aString.BeginsWith('.')) { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - LOG(DEBUG) << "Filename " << filename << " matches\n"; - - if (result->getVersion() < aVersion) { - result->setVersion(aVersion); - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - - } else if (result->getVersion() == aVersion && result->getSubVersion() < aSubVersion) { - - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - } else if (result->getVersion() == aVersion && result->getSubVersion() == aSubVersion) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " << aVersion << "_" - << aSubVersion << "!"; - gSystem->FreeDirectory(dirPtr); - delete result; - return nullptr; - } - } - - } else if (!query.hasSubVersion()) { // version specified but not subversion -> look for highest - // subVersion - result->setVersion(query.getVersion()); - - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files - - TString aString(filename); - if (aString.BeginsWith('.')) { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - if (query.getVersion() != aVersion) { - continue; - } - // aVersion is requested version! - - if (result->getSubVersion() == aSubVersion) { - LOG(ERROR) << "More than one object valid for run " << query.getFirstRun() << " version " << aVersion << "_" - << aSubVersion << "!"; - gSystem->FreeDirectory(dirPtr); - delete result; - return nullptr; - } - if (result->getSubVersion() < aSubVersion) { - - result->setSubVersion(aSubVersion); - - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - } - } - - } else { // both version and subversion specified - - // ConditionId dataId(queryId.getPathString(), -1, -1, -1, -1); - // Bool_t result; - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files - - TString aString(filename); - if (aString.BeginsWith('.')) { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - LOG(DEBUG) << "Could not make id from file: " << filename; - continue; - } - // aIdRunRange, aVersion, aSubVersion filled from filename - - if (!aIdRunRange.isSupersetOf(query.getIdRunRange())) { - continue; - } - // aIdRunRange contains requested run! - - if (query.getVersion() != aVersion || query.getSubVersion() != aSubVersion) { - continue; - } - // aVersion and aSubVersion are requested version and subVersion! - - result->setVersion(aVersion); - result->setSubVersion(aSubVersion); - result->setFirstRun(aIdRunRange.getFirstRun()); - result->setLastRun(aIdRunRange.getLastRun()); - break; - } - } - - gSystem->FreeDirectory(dirPtr); - - return result; -} - -Condition* LocalStorage::getCondition(const ConditionId& queryId) -{ - // get Condition from the storage (the CDB file matching the query is - // selected by getConditionId and the contained id is passed here) - - ConditionId* dataId = getConditionId(queryId); - - TString errMessage(TString::Format("No valid CDB object found! request was: %s", queryId.ToString().Data())); - if (!dataId || !dataId->isSpecified()) { - LOG(ERROR) << "No file found matching this id!"; - throw std::runtime_error(errMessage.Data()); - return nullptr; - } - - TString filename; - if (!idToFilename(*dataId, filename)) { - LOG(ERROR) << "Bad data ID encountered!"; - delete dataId; - throw std::runtime_error(errMessage.Data()); - return nullptr; - } - - TFile file(filename, "READ"); // open file - if (!file.IsOpen()) { - LOG(ERROR) << "Can't open file <" << filename.Data() << ">!"; - delete dataId; - throw std::runtime_error(errMessage.Data()); - return nullptr; - } - - // get the only Condition object from the file - // the object in the file is an Condition entry named " Condition" - - Condition* anCondition = dynamic_cast(file.Get(" Condition")); - if (!anCondition) { - LOG(ERROR) << "Bad storage data: No Condition in file!"; - file.Close(); - delete dataId; - throw std::runtime_error(errMessage.Data()); - return nullptr; - } - - ConditionId& entryId = anCondition->getId(); - - // The object's ConditionId are not reset during storage - // If object's ConditionId runRange or version do not match with filename, - // it means that someone renamed file by hand. In this case a warning msg is issued. - - anCondition->setLastStorage("local"); - - if (!entryId.isEqual(dataId)) { - LOG(WARNING) << "Mismatch between file name and object's ConditionId!"; - LOG(WARNING) << "File name: " << dataId->ToString().Data(); - LOG(WARNING) << "Object's ConditionId: " << entryId.ToString().Data(); - } - - // Check whether entry contains a TTree. In case load the tree in memory! - loadTreeFromFile(anCondition); - - // close file, return retrieved entry - file.Close(); - delete dataId; - - return anCondition; -} - -ConditionId* LocalStorage::getConditionId(const ConditionId& queryId) -{ - // get ConditionId from the storage - // Via getId, select the CDB file matching the query and return - // the contained ConditionId - - ConditionId* dataId = nullptr; - - // look for a filename matching query requests (path, runRange, version, subVersion) - if (!queryId.hasVersion()) { - // if version is not specified, first check the selection criteria list - ConditionId selectedId(queryId); - getSelection(&selectedId); - dataId = getId(selectedId); - } else { - dataId = getId(queryId); - } - - if (dataId && !dataId->isSpecified()) { - delete dataId; - return nullptr; - } - - return dataId; -} - -void LocalStorage::getEntriesForLevel0(const char* level0, const ConditionId& queryId, TList* result) -{ - // multiple request ( Storage::GetAllObjects) - - TString level0Dir = Form("%s/%s", mBaseDirectory.Data(), level0); - - void* level0DirPtr = gSystem->OpenDirectory(level0Dir); - if (!level0DirPtr) { - LOG(DEBUG) << "Can't open level0 directory <" << level0Dir.Data() << ">!"; - return; - } - - const char* level1; - Long_t flag = 0; - while ((level1 = gSystem->GetDirEntry(level0DirPtr))) { - - TString level1Str(level1); - // skip directories starting with a dot (".svn" and similar in old svn working copies) - if (level1Str.BeginsWith('.')) { - continue; - } - - TString fullPath = Form("%s/%s", level0Dir.Data(), level1); - - Int_t res = gSystem->GetPathInfo(fullPath.Data(), nullptr, (Long64_t*)nullptr, &flag, nullptr); - - if (res) { - LOG(DEBUG) << "Error reading entry " << level1Str.Data() << " !"; - continue; - } - if (!(flag & 2)) { - continue; - } // bit 1 of flag = directory! - - if (queryId.getPath().doesLevel1Contain(level1)) { - getEntriesForLevel1(level0, level1, queryId, result); - } - } - - gSystem->FreeDirectory(level0DirPtr); -} - -void LocalStorage::getEntriesForLevel1(const char* level0, const char* level1, const ConditionId& queryId, - TList* result) -{ - // multiple request ( Storage::GetAllObjects) - - TString level1Dir = Form("%s/%s/%s", mBaseDirectory.Data(), level0, level1); - - void* level1DirPtr = gSystem->OpenDirectory(level1Dir); - if (!level1DirPtr) { - LOG(DEBUG) << "Can't open level1 directory <" << level1Dir.Data() << ">!"; - return; - } - - const char* level2; - Long_t flag = 0; - while ((level2 = gSystem->GetDirEntry(level1DirPtr))) { - - TString level2Str(level2); - // skip directories starting with a dot (".svn" and similar in old svn working copies) - if (level2Str.BeginsWith('.')) { - continue; - } - - TString fullPath = Form("%s/%s", level1Dir.Data(), level2); - - Int_t res = gSystem->GetPathInfo(fullPath.Data(), nullptr, (Long64_t*)nullptr, &flag, nullptr); - - if (res) { - LOG(DEBUG) << "Error reading entry " << level2Str.Data() << " !"; - continue; - } - if (!(flag & 2)) { - continue; - } // skip if not a directory - - if (queryId.getPath().doesLevel2Contain(level2)) { - - IdPath entryPath(level0, level1, level2); - - ConditionId entryId(entryPath, queryId.getIdRunRange(), queryId.getVersion(), queryId.getSubVersion()); - - // check filenames to see if any includes queryId.getIdRunRange() - void* level2DirPtr = gSystem->OpenDirectory(fullPath); - if (!level2DirPtr) { - LOG(DEBUG) << "Can't open level2 directory <" << fullPath.Data() << ">!"; - return; - } - const char* level3; - Long_t file_flag = 0; - while ((level3 = gSystem->GetDirEntry(level2DirPtr))) { - TString fileName(level3); - TString fullFileName = Form("%s/%s", fullPath.Data(), level3); - - Int_t file_res = gSystem->GetPathInfo(fullFileName.Data(), nullptr, (Long64_t*)nullptr, &file_flag, nullptr); - - if (file_res) { - LOG(DEBUG) << "Error reading entry " << level2Str.Data() << " !"; - continue; - } - if (file_flag) { - continue; - } // it is not a regular file! - - // skip if result already contains an entry for this path - Bool_t alreadyLoaded = kFALSE; - Int_t nEntries = result->GetEntries(); - for (int i = 0; i < nEntries; i++) { - Condition* lCondition = (Condition*)result->At(i); - ConditionId lId = lCondition->getId(); - TString lIdPath = lId.getPathString(); - if (lIdPath.EqualTo(entryPath.getPathString())) { - alreadyLoaded = kTRUE; - break; - } - } - if (alreadyLoaded) { - continue; - } - - // skip filenames not matching the regex below - TRegexp re("^Run[0-9]+_[0-9]+_"); - if (!fileName.Contains(re)) { - continue; - } - // Extract first- and last-run and version and subversion. - // This allows to avoid quering for a calibration path if we did not find a filename with - // run-range including the one specified in the query and - // with version, subversion matching the query - TString fn = fileName(3, fileName.Length() - 3); - TString firstRunStr = fn(0, fn.First('_')); - fn.Remove(0, firstRunStr.Length() + 1); - TString lastRunStr = fn(0, fn.First('_')); - fn.Remove(0, lastRunStr.Length() + 1); - TString versionStr = fn(1, fn.First('_') - 1); - fn.Remove(0, versionStr.Length() + 2); - TString subvStr = fn(1, fn.First('.') - 1); - Int_t firstRun = firstRunStr.Atoi(); - Int_t lastRun = lastRunStr.Atoi(); - IdRunRange rr(firstRun, lastRun); - Int_t version = versionStr.Atoi(); - Int_t subVersion = subvStr.Atoi(); - - Condition* anCondition = nullptr; - Bool_t versionOK = kTRUE, subVersionOK = kTRUE; - if (queryId.hasVersion() && version != queryId.getVersion()) { - versionOK = kFALSE; - } - if (queryId.hasSubVersion() && subVersion != queryId.getSubVersion()) { - subVersionOK = kFALSE; - } - if (rr.isSupersetOf(queryId.getIdRunRange()) && versionOK && subVersionOK) { - anCondition = getCondition(entryId); - result->Add(anCondition); - } - } - } - } - - gSystem->FreeDirectory(level1DirPtr); -} - -TList* LocalStorage::getAllEntries(const ConditionId& queryId) -{ - // return list of CDB entries matching a generic request (Storage::GetAllObjects) - - TList* result = new TList(); - result->SetOwner(); - - // if querying for mRun and not specifying a version, look in the mValidFileIds list - if (queryId.getFirstRun() == mRun && !queryId.hasVersion()) { - // get id from mValidFileIds - TIter* iter = new TIter(&mValidFileIds); - TObjArray selectedIds; - selectedIds.SetOwner(1); - - // loop on list of valid Ids to select the right version to get. - // According to query and to the selection criteria list, version can be the highest or exact - ConditionId* anIdPtr = nullptr; - ConditionId* dataId = nullptr; - IdPath queryPath = queryId.getPathString(); - while ((anIdPtr = dynamic_cast(iter->Next()))) { - IdPath thisCDBPath = anIdPtr->getPathString(); - if (!(queryPath.isSupersetOf(thisCDBPath))) { - continue; - } - - ConditionId thisId(*anIdPtr); - dataId = getId(thisId); - if (dataId) { - selectedIds.Add(dataId); - } - } - - delete iter; - iter = nullptr; - - // selectedIds contains the Ids of the files matching all requests of query! - // All the objects are now ready to be retrieved - iter = new TIter(&selectedIds); - while ((anIdPtr = dynamic_cast(iter->Next()))) { - Condition* anCondition = getCondition(*anIdPtr); - if (anCondition) { - result->Add(anCondition); - } - } - delete iter; - iter = nullptr; - return result; - } - - void* storageDirPtr = gSystem->OpenDirectory(mBaseDirectory); - if (!storageDirPtr) { - LOG(DEBUG) << "Can't open storage directory <" << mBaseDirectory.Data() << ">"; - return nullptr; - } - - const char* level0; - Long_t flag = 0; - while ((level0 = gSystem->GetDirEntry(storageDirPtr))) { - - TString level0Str(level0); - // skip directories starting with a dot (".svn" and similar in old svn working copies) - if (level0Str.BeginsWith('.')) { - continue; - } - - TString fullPath = Form("%s/%s", mBaseDirectory.Data(), level0); - - Int_t res = gSystem->GetPathInfo(fullPath.Data(), nullptr, (Long64_t*)nullptr, &flag, nullptr); - - if (res) { - LOG(DEBUG) << "Error reading entry " << level0Str.Data() << " !"; - continue; - } - - if (!(flag & 2)) { - continue; - } // bit 1 of flag = directory! - - if (queryId.getPath().doesLevel0Contain(level0)) { - getEntriesForLevel0(level0, queryId, result); - } - } - - gSystem->FreeDirectory(storageDirPtr); - - return result; -} - -Bool_t LocalStorage::putCondition(Condition* entry, const char* mirrors) -{ - // put an Condition object into the database - - ConditionId& id = entry->getId(); - - // set version and subVersion for the entry to be stored - if (!prepareId(id)) { - return kFALSE; - } - - // build filename from entry's id - TString filename = ""; - if (!idToFilename(id, filename)) { - - LOG(DEBUG) << "Bad ID encountered! Subnormal error!"; - return kFALSE; - } - - TString mirrorsString(mirrors); - if (!mirrorsString.IsNull()) - LOG(WARNING) << " LocalStorage storage cannot take mirror SEs into account. They will be ignored."; - - // open file - TFile file(filename, "CREATE"); - if (!file.IsOpen()) { - LOG(ERROR) << "Can't open file <" << filename.Data() << ">!"; - return kFALSE; - } - - // setTreeToFile(entry, &file); - - entry->setVersion(id.getVersion()); - entry->setSubVersion(id.getSubVersion()); - - // write object (key name: " Condition") - Bool_t result = file.WriteTObject(entry, " Condition"); - if (!result) - LOG(DEBUG) << "Can't write entry to file: " << filename.Data(); - - file.Close(); - if (result) { - if (!(id.getPathString().Contains("SHUTTLE/STATUS"))) - LOG(INFO) << R"(CDB object stored into file ")" << filename.Data() << R"(")"; - } - - return result; -} - -TList* LocalStorage::getIdListFromFile(const char* fileName) -{ - - TString fullFileName(fileName); - fullFileName.Prepend(mBaseDirectory + '/'); - TFile* file = TFile::Open(fullFileName); - if (!file) { - LOG(ERROR) << "Can't open selection file <" << fullFileName.Data() << ">!"; - return nullptr; - } - file->cd(); - - TList* list = new TList(); - list->SetOwner(); - int i = 0; - TString keycycle; - - ConditionId* id; - while (1) { - i++; - keycycle = " ConditionId;"; - keycycle += i; - - id = (ConditionId*)file->Get(keycycle); - if (!id) { - break; - } - list->AddFirst(id); - } - file->Close(); - delete file; - file = nullptr; - return list; -} - -Bool_t LocalStorage::hasConditionType(const char* path) const -{ - // check for path in storage's mBaseDirectory - - TString dirName = Form("%s/%s", mBaseDirectory.Data(), path); - Bool_t result = kFALSE; - - void* dirPtr = gSystem->OpenDirectory(dirName); - if (dirPtr) { - result = kTRUE; - } - gSystem->FreeDirectory(dirPtr); - - return result; -} - -void LocalStorage::queryValidFiles() -{ - // Query the CDB for files valid for Storage::mRun. - // Fills list mValidFileIds with ConditionId objects extracted from CDB files - // present in the local storage. - // If mVersion was not set, mValidFileIds is filled with highest versions. - // In the CVMFS case, the mValidFileIds is filled from the file containing - // the filepaths corresponding to the highest versions for the give OCDB tag - // by launching the script which extracts the last versions for the given run. - // - - if (mVersion != -1) - LOG(WARNING) << "Version parameter is not used by local storage query!"; - if (mConditionMetaDataFilter) { - LOG(WARNING) << "CDB meta data parameters are not used by local storage query!"; - delete mConditionMetaDataFilter; - mConditionMetaDataFilter = nullptr; - } - - // Check if in CVMFS case - TString cvmfsOcdbTag(gSystem->Getenv("OCDB_PATH")); - if (!cvmfsOcdbTag.IsNull()) { - queryValidCVMFSFiles(cvmfsOcdbTag); - return; - } - - void* storageDirPtr = gSystem->OpenDirectory(mBaseDirectory); - - const char* level0; - while ((level0 = gSystem->GetDirEntry(storageDirPtr))) { - - TString level0Str(level0); - if (level0Str.BeginsWith(".")) { - continue; - } - - if (mPathFilter.doesLevel0Contain(level0)) { - TString level0Dir = Form("%s/%s", mBaseDirectory.Data(), level0); - void* level0DirPtr = gSystem->OpenDirectory(level0Dir); - const char* level1; - while ((level1 = gSystem->GetDirEntry(level0DirPtr))) { - - TString level1Str(level1); - if (level1Str.BeginsWith(".")) { - continue; - } - - if (mPathFilter.doesLevel1Contain(level1)) { - TString level1Dir = Form("%s/%s/%s", mBaseDirectory.Data(), level0, level1); - - void* level1DirPtr = gSystem->OpenDirectory(level1Dir); - const char* level2; - while ((level2 = gSystem->GetDirEntry(level1DirPtr))) { - - TString level2Str(level2); - if (level2Str.BeginsWith(".")) { - continue; - } - - if (mPathFilter.doesLevel2Contain(level2)) { - TString dirName = Form("%s/%s/%s/%s", mBaseDirectory.Data(), level0, level1, level2); - - void* dirPtr = gSystem->OpenDirectory(dirName); - - const char* filename; - - IdRunRange aIdRunRange; // the runRange got from filename - IdRunRange hvIdRunRange; // the runRange of the highest version valid file - Int_t aVersion, aSubVersion; // the version and subVersion got from filename - Int_t highestV = -1, highestSubV = -1; // the highest version and subVersion for this calibration type - - while ((filename = gSystem->GetDirEntry(dirPtr))) { // loop on files - - TString aString(filename); - if (aString.BeginsWith(".")) { - continue; - } - - if (!filenameToId(filename, aIdRunRange, aVersion, aSubVersion)) { - continue; - } - - IdRunRange runrg(mRun, mRun); - if (!aIdRunRange.isSupersetOf(runrg)) { - continue; - } - - // check to keep the highest version/subversion (in case of more than one) - if (aVersion > highestV) { - highestV = aVersion; - highestSubV = aSubVersion; - hvIdRunRange = aIdRunRange; - } else if (aVersion == highestV) { - if (aSubVersion > highestSubV) { - highestSubV = aSubVersion; - hvIdRunRange = aIdRunRange; - } - } - } - if (highestV >= 0) { - IdPath validPath(level0, level1, level2); - ConditionId* validId = new ConditionId(validPath, hvIdRunRange, highestV, highestSubV); - mValidFileIds.AddLast(validId); - } - - gSystem->FreeDirectory(dirPtr); - } - } - gSystem->FreeDirectory(level1DirPtr); - } - } - gSystem->FreeDirectory(level0DirPtr); - } - } - gSystem->FreeDirectory(storageDirPtr); -} - -void LocalStorage::queryValidCVMFSFiles(TString& cvmfsOcdbTag) -{ - // Called in the CVMFS case to fill the mValidFileIds from the file containing - // the filepaths corresponding to the highest versions for the given OCDB tag - // by launching the script which extracts the last versions for the given run. - // - - TString command = cvmfsOcdbTag; - LOG(DEBUG) << R"(Getting valid files from CVMFS-OCDB tag ")" << cvmfsOcdbTag.Data() << R"(")"; - // CVMFS-OCDB tag. This is the file $OCDB_PATH/catalogue/20??.list.gz - // containing all CDB file paths (for the given AR tag) - cvmfsOcdbTag.Strip(TString::kTrailing, '/'); - cvmfsOcdbTag.Append("/"); - gSystem->ExpandPathName(cvmfsOcdbTag); - if (gSystem->AccessPathName(cvmfsOcdbTag)) - LOG(FATAL) << "cvmfs OCDB set to an invalid path: " << cvmfsOcdbTag.Data(); - - // The file containing the list of valid files for the current run has to be generated - // by running the (shell+awk) script on the CVMFS OCDB tag file. - - // the script in cvmfs to extract CDB filepaths for the given run has the following fullpath - // w.r.t. $OCDB_PATH: bin/OCDBperRun.sh - command = command.Strip(TString::kTrailing, '/'); - command.Append("/bin/getOCDBFilesPerRun.sh "); - command += cvmfsOcdbTag; - // from URI define the last two levels of the path of the cvmfs ocdb tag (e.g. data/2012.list.gz) - TString uri(getUri()); - uri.Remove(TString::kTrailing, '/'); - TObjArray* osArr = uri.Tokenize('/'); - TObjString* mcdata_os = dynamic_cast(osArr->At(osArr->GetEntries() - 3)); - TObjString* yeartype_os = nullptr; - TString mcdata = mcdata_os->GetString(); - if (mcdata == TString("data")) { - yeartype_os = dynamic_cast(osArr->At(osArr->GetEntries() - 2)); - } else { - mcdata_os = dynamic_cast(osArr->At(osArr->GetEntries() - 2)); - yeartype_os = dynamic_cast(osArr->At(osArr->GetEntries() - 1)); - } - mcdata = mcdata_os->GetString(); - TString yeartype = yeartype_os->GetString(); - command += mcdata; - command += '/'; - command += yeartype; - command += ".list.gz cvmfs "; - command += TString::Itoa(mRun, 10); - command += ' '; - command += TString::Itoa(mRun, 10); - command += " -y > "; - TString runValidFile(gSystem->WorkingDirectory()); - runValidFile += '/'; - runValidFile += mcdata; - runValidFile += '_'; - runValidFile += yeartype; - runValidFile += '_'; - runValidFile += TString::Itoa(mRun, 10); - command += runValidFile; - LOG(DEBUG) << R"(Running command: ")" << command.Data() << R"(")"; - Int_t result = gSystem->Exec(command.Data()); - if (result != 0) { - LOG(ERROR) << R"(Was not able to execute ")" << command.Data() << R"(")"; - } - - // We expect the file with valid paths for this run to be generated in the current directory - // and to be named as the CVMFS OCDB tag, without .gz, with '_runnumber' appended - // Fill mValidFileIds from file - std::ifstream file(runValidFile.Data()); - if (!file.is_open()) { - LOG(FATAL) << R"(Error opening file ")" << runValidFile.Data() << R"("!)"; - } - TString filepath; - while (filepath.ReadLine(file)) { - // skip line in case it is not a root file path - if (!filepath.EndsWith(".root")) { - continue; - } - // extract three-level path and basename - TObjArray* tokens = filepath.Tokenize('/'); - if (tokens->GetEntries() < 5) { - LOG(ERROR) << R"(")" << filepath.Data() << R"(" is not a valid cvmfs path for an OCDB object)"; - continue; - } - TObjString* baseNameOstr = (TObjString*)tokens->At(tokens->GetEntries() - 1); - TString baseName(baseNameOstr->String()); - TObjString* l0oStr = (TObjString*)tokens->At(tokens->GetEntries() - 4); - TObjString* l1oStr = (TObjString*)tokens->At(tokens->GetEntries() - 3); - TObjString* l2oStr = (TObjString*)tokens->At(tokens->GetEntries() - 2); - TString l0(l0oStr->String()); - TString l1(l1oStr->String()); - TString l2(l2oStr->String()); - TString threeLevels = l0 + '/' + l1 + '/' + l2; - - IdPath validPath(threeLevels); - // use basename and three-level path to create ConditionId - IdRunRange aIdRunRange; // the runRange got from filename - Int_t aVersion, aSubVersion; // the version and subVersion got from filename - if (!filenameToId(baseName, aIdRunRange, aVersion, aSubVersion)) - LOG(ERROR) << R"(Could not create a valid CDB id from path: ")" << filepath.Data() << R"(")"; - - IdRunRange runrg(mRun, mRun); - if (!aIdRunRange.isSupersetOf(runrg)) { - continue; - } // should never happen (would mean awk script wrong output) - // aIdRunRange contains requested run! - ConditionId* validId = new ConditionId(validPath, aIdRunRange, aVersion, aSubVersion); - mValidFileIds.AddLast(validId); - } - - file.close(); - return; -} - -///////////////////////////////////////////////////////////////////////////////////////////////// -// // -// LocalStorage factory // -// // -///////////////////////////////////////////////////////////////////////////////////////////////// - -ClassImp(LocalStorageFactory); - -Bool_t LocalStorageFactory::validateStorageUri(const char* dbString) -{ - // check if the string is valid local URI - - TRegexp dbPatternLocalStorage("^local://.+$"); - - return (TString(dbString).Contains(dbPatternLocalStorage) || TString(dbString).BeginsWith("snapshot://folder=")); -} - -StorageParameters* LocalStorageFactory::createStorageParameter(const char* dbString) -{ - // create LocalStorageParameters class from the URI string - - if (!validateStorageUri(dbString)) { - return nullptr; - } - - TString checkSS(dbString); - if (checkSS.BeginsWith("snapshot://")) { - TString snapshotPath("OCDB"); - snapshotPath.Prepend(TString(gSystem->WorkingDirectory()) + '/'); - checkSS.Remove(0, checkSS.First(':') + 3); - return new LocalStorageParameters(snapshotPath, checkSS); - } - - // if the string argument is not a snapshot URI, than it is a plain local URI - TString pathname(dbString + sizeof("local://") - 1); - - if (gSystem->ExpandPathName(pathname)) { - return nullptr; - } - - if (pathname[0] != '/') { - pathname.Prepend(TString(gSystem->WorkingDirectory()) + '/'); - } - // pathname.Prepend("local://"); - - return new LocalStorageParameters(pathname); -} - -Storage* LocalStorageFactory::createStorage(const StorageParameters* param) -{ - // create LocalStorage storage instance from parameters - - if (LocalStorageParameters::Class() == param->IsA()) { - - const LocalStorageParameters* localParam = (const LocalStorageParameters*)param; - - return new LocalStorage(localParam->getPathString()); - } - - return nullptr; -} - -void LocalStorage::setRetry(Int_t /* nretry */, Int_t /* initsec */) -{ - - // Function to set the exponential retry for putting entries in the OCDB - - LOG(INFO) << "This function sets the exponential retry for putting entries in the OCDB - to be " - "used ONLY for GridStorage --> returning without doing anything"; - return; -} - -///////////////////////////////////////////////////////////////////////////////////////////////// -// // -// LocalStorage Parameter class // // -// // -///////////////////////////////////////////////////////////////////////////////////////////////// - -ClassImp(LocalStorageParameters); - -LocalStorageParameters::LocalStorageParameters() : StorageParameters(), mDBPath() -{ - // default constructor -} - -LocalStorageParameters::LocalStorageParameters(const char* dbPath) : StorageParameters(), mDBPath(dbPath) -{ - // constructor - - setType("local"); - setUri(TString("local://") + dbPath); -} - -LocalStorageParameters::LocalStorageParameters(const char* dbPath, const char* uri) - : StorageParameters(), mDBPath(dbPath) -{ - // constructor - - setType("local"); - setUri(TString("alien://") + uri); -} - -LocalStorageParameters::~LocalStorageParameters() = default; - -StorageParameters* LocalStorageParameters::cloneParam() const -{ - // clone parameter - - return new LocalStorageParameters(mDBPath); -} - -ULong_t LocalStorageParameters::getHash() const -{ - // return getHash function - - return mDBPath.Hash(); -} - -Bool_t LocalStorageParameters::isEqual(const TObject* obj) const -{ - // check if this object is equal to StorageParameters obj - - if (this == obj) { - return kTRUE; - } - - if (LocalStorageParameters::Class() != obj->IsA()) { - return kFALSE; - } - - LocalStorageParameters* other = (LocalStorageParameters*)obj; - - return mDBPath == other->mDBPath; -} diff --git a/CCDB/src/Manager.cxx b/CCDB/src/Manager.cxx deleted file mode 100644 index 3026a86294147..0000000000000 --- a/CCDB/src/Manager.cxx +++ /dev/null @@ -1,1864 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "CCDB/Manager.h" -#include // for LOG -#include // for gGrid, TGrid -#include // for TKey -#include // for TMessage -#include // for TObjString -#include // for TRegexp -#include // for TSAXParser -#include // for TUUID -#include "CCDB/Condition.h" // for Condition -#include "CCDB/FileStorage.h" // for FileStorageFactory -#include "CCDB/GridStorage.h" // for GridStorageFactory -#include "CCDB/LocalStorage.h" // for LocalStorageFactory -#include "TFile.h" // for TFile -#include "TSystem.h" // for TSystem, gSystem -#include "CCDB/XmlHandler.h" // for XmlHandler - -using namespace o2::ccdb; - -ClassImp(StorageParameters); - -ClassImp(Manager); - -TString Manager::sOcdbFolderXmlFile("alien:///alice/data/OCDBFoldervsIdRunRange.xml"); -Manager* Manager::sInstance = nullptr; - -Manager* Manager::Instance(TMap* entryCache, Int_t run) -{ - // returns Manager instance (singleton) - - if (!sInstance) { - sInstance = new Manager(); - if (!entryCache) { - sInstance->init(); - } else { - sInstance->initFromCache(entryCache, run); - } - } - - return sInstance; -} - -void Manager::init() -{ - // factory registering - - registerFactory(new FileStorageFactory()); - registerFactory(new LocalStorageFactory()); - // GridStorageFactory is registered only if AliEn libraries are enabled in Root - if (!gSystem->Exec("root-config --has-alien 2>/dev/null |grep yes 2>&1 > /dev/null")) { // returns 0 if yes - LOG(INFO) << "AliEn classes enabled in Root. GridStorage factory registered."; - registerFactory(new GridStorageFactory()); - } -} - -void Manager::initFromCache(TMap* entryCache, Int_t run) -{ - // initialize manager from existing cache - // used on the slaves in case of parallel reconstruction - setRun(run); - - TIter iter(entryCache->GetTable()); - TPair* pair = nullptr; - - while ((pair = dynamic_cast(iter.Next()))) { - mConditionCache.Add(pair->Key(), pair->Value()); - } - // mCondition is the new owner of the cache - mConditionCache.SetOwnerKeyValue(kTRUE, kTRUE); - entryCache->SetOwnerKeyValue(kFALSE, kFALSE); - LOG(INFO) << mConditionCache.GetEntries() << " cache entries have been loaded"; -} - -void Manager::dumpToSnapshotFile(const char* snapshotFileName, Bool_t singleKeys) const -{ - // - // If singleKeys is true, dump the entries map and the ids list to the snapshot file - // (provided mostly for historical reasons, the file is then read with initFromSnapshot), - // otherwise write to file each Condition separately (the is the preferred way, the file - // is then read with setSnapshotMode). - - // open the file - TFile* f = TFile::Open(snapshotFileName, "RECREATE"); - if (!f || f->IsZombie()) { - LOG(ERROR) << "Cannot open file " << snapshotFileName; - return; - } - - LOG(INFO) << "Dumping entriesMap (entries'cache) with " << mConditionCache.GetEntries() << " entries!"; - LOG(INFO) << "Dumping entriesList with " << mIds->GetEntries() << "entries!"; - - f->cd(); - if (singleKeys) { - f->WriteObject(&mConditionCache, "CDBentriesMap"); - f->WriteObject(mIds, "CDBidsList"); - } else { - // We write the entries one by one named by their calibration path - TIter iter(mConditionCache.GetTable()); - TPair* pair = nullptr; - while ((pair = dynamic_cast(iter.Next()))) { - TObjString* os = dynamic_cast(pair->Key()); - if (!os) { - continue; - } - TString path = os->GetString(); - Condition* entry = dynamic_cast(pair->Value()); - if (!entry) { - continue; - } - path.ReplaceAll("/", "*"); - entry->Write(path.Data()); - } - } - f->Close(); - delete f; -} - -void Manager::dumpToLightSnapshotFile(const char* lightSnapshotFileName) const -{ - // The light snapshot does not contain the CDB objects (Entries) but - // only the information identifying them, that is the map of storages and - // the list of Ids, as in the UserInfo of AliESDs.root - - // open the file - TFile* f = TFile::Open(lightSnapshotFileName, "RECREATE"); - if (!f || f->IsZombie()) { - LOG(ERROR) << "Cannot open file " << lightSnapshotFileName; - return; - } - - LOG(INFO) << "Dumping map of storages with " << mStorageMap->GetEntries() << " entries!"; - LOG(INFO) << "Dumping entriesList with " << mIds->GetEntries() << " entries!"; - f->WriteObject(mStorageMap, "cdbStoragesMap"); - f->WriteObject(mIds, "CDBidsList"); - - f->Close(); - delete f; -} - -Bool_t Manager::initFromSnapshot(const char* snapshotFileName, Bool_t overwrite) -{ - // initialize manager from a CDB snapshot, that is add the entries - // to the entries map and the ids to the ids list taking them from - // the map and the list found in the input file - - // if the manager is locked it cannot initialize from a snapshot - if (mLock) { - LOG(ERROR) << "Being locked I cannot initialize from the snapshot!"; - return kFALSE; - } - - // open the file - TString snapshotFile(snapshotFileName); - if (snapshotFile.BeginsWith("alien://")) { - if (!gGrid) { - TGrid::Connect("alien://", ""); - if (!gGrid) { - LOG(ERROR) << "Connection to alien failed!"; - return kFALSE; - } - } - } - - TFile* f = TFile::Open(snapshotFileName); - if (!f || f->IsZombie()) { - LOG(ERROR) << "Cannot open file " << snapshotFileName; - return kFALSE; - } - - // retrieve entries' map from snapshot file - TMap* entriesMap = nullptr; - TIter next(f->GetListOfKeys()); - TKey* key; - while ((key = (TKey*)next())) { - if (strcmp(key->GetClassName(), "TMap") != 0) { - continue; - } - entriesMap = (TMap*)key->ReadObj(); - break; - } - if (!entriesMap || entriesMap->GetEntries() == 0) { - LOG(ERROR) << "Cannot get valid map of CDB entries from snapshot file"; - return kFALSE; - } - - // retrieve ids' list from snapshot file - TList* idsList = nullptr; - TIter nextKey(f->GetListOfKeys()); - TKey* keyN; - while ((keyN = (TKey*)nextKey())) { - if (strcmp(keyN->GetClassName(), "TList") != 0) { - continue; - } - idsList = (TList*)keyN->ReadObj(); - break; - } - if (!idsList || idsList->GetEntries() == 0) { - LOG(ERROR) << "Cannot get valid list of CDB entries from snapshot file"; - return kFALSE; - } - - // Add each (entry,id) from the snapshot to the memory: entry to the cache, id to the list of ids. - // If "overwrite" is false: add the entry to the cache and its id to the list of ids - // only if neither of them is already there. - // If "overwrite" is true: write the snapshot entry,id in any case. If something - // was already there for that calibration type, remove it and issue a warning - TIter iterObj(entriesMap->GetTable()); - TPair* pair = nullptr; - Int_t nAdded = 0; - while ((pair = dynamic_cast(iterObj.Next()))) { - TObjString* os = (TObjString*)pair->Key(); - TString path = os->GetString(); - TIter iterId(idsList); - ConditionId* id = nullptr; - ConditionId* correspondingId = nullptr; - while ((id = dynamic_cast(iterId.Next()))) { - TString idpath(id->getPathString()); - if (idpath == path) { - correspondingId = id; - break; - } - } - if (!correspondingId) { - LOG(ERROR) << R"(id for ")" << path.Data() - << R"(" not found in the snapshot (while entry was). This entry is skipped!)"; - break; - } - Bool_t cached = mConditionCache.Contains(path.Data()); - Bool_t registeredId = kFALSE; - TIter iter(mIds); - ConditionId* idT = nullptr; - while ((idT = dynamic_cast(iter.Next()))) { - if (idT->getPathString() == path) { - registeredId = kTRUE; - break; - } - } - - if (overwrite) { - if (cached || registeredId) { - LOG(WARNING) << R"(An entry was already cached for ")" << path.Data() - << R"(". Removing it before caching from snapshot)"; - unloadFromCache(path.Data()); - } - mConditionCache.Add(pair->Key(), pair->Value()); - mIds->Add(id); - nAdded++; - } else { - if (cached || registeredId) { - LOG(WARNING) << R"(An entry was already cached for ")" << path.Data() - << R"(". Not adding this object from snapshot)"; - } else { - mConditionCache.Add(pair->Key(), pair->Value()); - mIds->Add(id); - nAdded++; - } - } - } - - // mCondition is the new owner of the cache - mConditionCache.SetOwnerKeyValue(kTRUE, kTRUE); - entriesMap->SetOwnerKeyValue(kFALSE, kFALSE); - mIds->SetOwner(kTRUE); - idsList->SetOwner(kFALSE); - LOG(INFO) << nAdded << " new (entry,id) cached. Total number " << mConditionCache.GetEntries(); - - f->Close(); - delete f; - - return kTRUE; -} - -void Manager::destroy() -{ - // delete ALCDBManager instance and active storages - - if (sInstance) { - delete sInstance; - sInstance = nullptr; - } -} - -Manager::Manager() - : TObject(), - mFactories(), - mActiveStorages(), - mSpecificStorages(), - mConditionCache(), - mIds(nullptr), - mStorageMap(nullptr), - mDefaultStorage(nullptr), - mdrainStorage(nullptr), - mOfficialStorageParameters(nullptr), - mReferenceStorageParameters(nullptr), - mRun(-1), - mCache(kTRUE), - mLock(kFALSE), - mSnapshotMode(kFALSE), - mSnapshotFile(nullptr), - mOcdbUploadMode(kFALSE), - mRaw(kFALSE), - mCvmfsOcdb(""), - mStartRunLhcPeriod(-1), - mEndRunLhcPeriod(-1), - mLhcPeriod(""), - mKey(0) -{ - // default constuctor - mFactories.SetOwner(1); - mActiveStorages.SetOwner(1); - mSpecificStorages.SetOwner(1); - mConditionCache.SetName("CDBConditionCache"); - mConditionCache.SetOwnerKeyValue(kTRUE, kTRUE); - - mStorageMap = new TMap(); - mStorageMap->SetOwner(1); - mIds = new TList(); - mIds->SetOwner(1); -} - -Manager::~Manager() -{ - // destructor - clearCache(); - destroyActiveStorages(); - mFactories.Delete(); - mdrainStorage = nullptr; - mDefaultStorage = nullptr; - delete mStorageMap; - mStorageMap = nullptr; - delete mIds; - mIds = nullptr; - delete mOfficialStorageParameters; - delete mReferenceStorageParameters; - if (mSnapshotMode) { - mSnapshotFile->Close(); - mSnapshotFile = nullptr; - } -} - -void Manager::putActiveStorage(StorageParameters* param, Storage* storage) -{ - // put a storage object into the list of active storages - - mActiveStorages.Add(param, storage); - LOG(DEBUG) << "Active storages: " << mActiveStorages.GetEntries(); -} - -void Manager::registerFactory(StorageFactory* factory) -{ - // add a storage factory to the list of registerd factories - - if (!mFactories.Contains(factory)) { - mFactories.Add(factory); - } -} - -Bool_t Manager::hasStorage(const char* dbString) const -{ - // check if dbString is a URI valid for one of the registered factories - - TIter iter(&mFactories); - - StorageFactory* factory = nullptr; - while ((factory = (StorageFactory*)iter.Next())) { - - if (factory->validateStorageUri(dbString)) { - return kTRUE; - } - } - - return kFALSE; -} - -StorageParameters* Manager::createStorageParameter(const char* dbString) const -{ - // create StorageParameters object from URI string - - TString uriString(dbString); - - if (!mCvmfsOcdb.IsNull() && uriString.BeginsWith("alien://")) { - alienToCvmfsUri(uriString); - } - - TIter iter(&mFactories); - - StorageFactory* factory = nullptr; - while ((factory = (StorageFactory*)iter.Next())) { - StorageParameters* param = factory->createStorageParameter(uriString); - if (param) { - return param; - } - } - - return nullptr; -} - -void Manager::alienToCvmfsUri(TString& uriString) const -{ - // convert alien storage uri to local:///cvmfs storage uri (called when OCDB_PATH is set) - - TObjArray* arr = uriString.Tokenize('?'); - TIter iter(arr); - TObjString* str = nullptr; - TString entryKey = ""; - TString entryValue = ""; - TString newUriString = ""; - while ((str = (TObjString*)iter.Next())) { - TString entry(str->String()); - Int_t indeq = entry.Index('='); - entryKey = entry(0, indeq + 1); - entryValue = entry(indeq + 1, entry.Length() - indeq); - - if (entryKey.Contains("folder", TString::kIgnoreCase)) { - - TRegexp re_RawFolder("^/alice/data/20[0-9]+/OCDB"); - TRegexp re_MCFolder("^/alice/simulation/2008/v4-15-Release"); - TString rawFolder = entryValue(re_RawFolder); - TString mcFolder = entryValue(re_MCFolder); - if (!rawFolder.IsNull()) { - entryValue.Replace(0, 6, "/cvmfs/alice-ocdb.cern.ch/calibration"); - // entryValue.Replace(entryValue.Length()-4, entryValue.Length(), ""); - } else if (!mcFolder.IsNull()) { - entryValue.Replace(0, 36, "/cvmfs/alice-ocdb.cern.ch/calibration/MC"); - } else { - LOG(FATAL) << "Environment variable for cvmfs OCDB folder set for an invalid OCDB storage:\n " - << entryValue.Data(); - } - } else { - newUriString += entryKey; - } - newUriString += entryValue; - newUriString += '?'; - } - newUriString.Prepend("local://"); - newUriString.Remove(TString::kTrailing, '?'); - uriString = newUriString; -} - -Storage* Manager::getStorage(const char* dbString) -{ - // Get the CDB storage corresponding to the URI string passed as argument - // If "raw://" is passed, get the storage for the raw OCDB for the current run (mRun) - - TString uriString(dbString); - if (uriString.EqualTo("raw://")) { - if (!mLhcPeriod.IsNull() && !mLhcPeriod.IsWhitespace()) { - return getDefaultStorage(); - } else { - TString lhcPeriod(""); - Int_t startRun = -1, endRun = -1; - getLHCPeriodAgainstAlienFile(mRun, lhcPeriod, startRun, endRun); - return getStorage(lhcPeriod.Data()); - } - } - - StorageParameters* param = createStorageParameter(dbString); - if (!param) { - LOG(ERROR) << "Failed to activate requested storage! Check URI: " << dbString; - return nullptr; - } - - Storage* aStorage = getStorage(param); - - delete param; - return aStorage; -} - -Storage* Manager::getStorage(const StorageParameters* param) -{ - // get storage object from StorageParameters object - - // if the list of active storages already contains - // the requested storage, return it - Storage* aStorage = getActiveStorage(param); - if (aStorage) { - return aStorage; - } - - // if lock is ON, cannot activate more storages! - if (mLock) { - if (mDefaultStorage) { - LOG(FATAL) << "Lock is ON, and default storage is already set: cannot reset it or activate " - "more storages!"; - } - } - - // loop on the list of registered factories - TIter iter(&mFactories); - StorageFactory* factory = nullptr; - while ((factory = (StorageFactory*)iter.Next())) { - - // each factory tries to create its storage from the parameter - aStorage = factory->createStorage(param); - if (aStorage) { - putActiveStorage(param->cloneParam(), aStorage); - aStorage->setUri(param->getUri()); - if (mRun >= 0) { - if (aStorage->getStorageType() == "alien" || aStorage->getStorageType() == "local") { - aStorage->queryStorages(mRun); - } - } - return aStorage; - } - } - - LOG(ERROR) << "Failed to activate requested storage! Check URI: " << param->getUri().Data(); - - return nullptr; -} - -Storage* Manager::getActiveStorage(const StorageParameters* param) -{ - // get a storage object from the list of active storages - - return dynamic_cast(mActiveStorages.GetValue(param)); -} - -TList* Manager::getActiveStorages() -{ - // return list of active storages - // user has responsibility to delete returned object - - TList* result = new TList(); - - TIter iter(mActiveStorages.GetTable()); - TPair* aPair = nullptr; - while ((aPair = (TPair*)iter.Next())) { - result->Add(aPair->Value()); - } - - return result; -} - -void Manager::setdrainMode(const char* dbString) -{ - // set drain storage from URI string - - mdrainStorage = getStorage(dbString); -} - -void Manager::setdrainMode(const StorageParameters* param) -{ - // set drain storage from StorageParameters - - mdrainStorage = getStorage(param); -} - -void Manager::setdrainMode(Storage* storage) -{ - // set drain storage from another active storage - - mdrainStorage = storage; -} - -Bool_t Manager::drain(Condition* entry) -{ - // drain retrieved object to drain storage - - LOG(DEBUG) << "draining into drain storage..."; - return mdrainStorage->putObject(entry); -} - -Bool_t Manager::setOcdbUploadMode() -{ - // Set the framework in official upload mode. This tells the framework to upload - // objects to cvmfs after they have been uploaded to AliEn OCDBs. - // It return false if the executable to upload to cvmfs is not found. - - TString cvmfsUploadExecutable("$HOME/bin/ocdb-cvmfs"); - gSystem->ExpandPathName(cvmfsUploadExecutable); - if (gSystem->AccessPathName(cvmfsUploadExecutable)) { - return kFALSE; - } - mOcdbUploadMode = kTRUE; - return kTRUE; -} - -void Manager::setDefaultStorage(const char* storageUri) -{ - // sets default storage from URI string - - // if in the cvmfs case (triggered by environment variable) check for path validity - // and modify Uri if it is "raw://" - TString cvmfsOcdb(gSystem->Getenv("OCDB_PATH")); - if (!cvmfsOcdb.IsNull()) { - mCvmfsOcdb = cvmfsOcdb; - validateCvmfsCase(); - } - - // checking whether we are in the raw case - TString uriTemp(storageUri); - if (uriTemp == "raw://") { - mRaw = kTRUE; // read then by setRun to check if the method has to be called again with expanded uri - LOG(INFO) << "Setting the run-number will set the corresponding OCDB for raw data reconstruction."; - return; - } - - Storage* bckStorage = mDefaultStorage; - - mDefaultStorage = getStorage(storageUri); - - if (!mDefaultStorage) { - return; - } - - if (bckStorage && (mDefaultStorage != bckStorage)) { - LOG(WARNING) << "Existing default storage replaced: clearing cache!"; - clearCache(); - } - - if (mStorageMap->Contains("default")) { - delete mStorageMap->Remove(((TPair*)mStorageMap->FindObject("default"))->Key()); - } - mStorageMap->Add(new TObjString("default"), new TObjString(mDefaultStorage->getUri())); -} - -void Manager::setDefaultStorage(const StorageParameters* param) -{ - // set default storage from StorageParameters object - - Storage* bckStorage = mDefaultStorage; - - mDefaultStorage = getStorage(param); - - if (!mDefaultStorage) { - return; - } - - if (bckStorage && (mDefaultStorage != bckStorage)) { - LOG(WARNING) << "Existing default storage replaced: clearing cache!"; - clearCache(); - } - - if (mStorageMap->Contains("default")) { - delete mStorageMap->Remove(((TPair*)mStorageMap->FindObject("default"))->Key()); - } - mStorageMap->Add(new TObjString("default"), new TObjString(mDefaultStorage->getUri())); -} - -void Manager::setDefaultStorage(Storage* storage) -{ - // set default storage from another active storage - - // if lock is ON, cannot activate more storages! - if (mLock) { - if (mDefaultStorage) { - LOG(FATAL) << "Lock is ON, and default storage is already set: cannot reset it or activate " - "more storages!"; - } - } - - if (!storage) { - unsetDefaultStorage(); - return; - } - - Storage* bckStorage = mDefaultStorage; - - mDefaultStorage = storage; - - if (bckStorage && (mDefaultStorage != bckStorage)) { - LOG(WARNING) << "Existing default storage replaced: clearing cache!"; - clearCache(); - } - - if (mStorageMap->Contains("default")) { - delete mStorageMap->Remove(((TPair*)mStorageMap->FindObject("default"))->Key()); - } - mStorageMap->Add(new TObjString("default"), new TObjString(mDefaultStorage->getUri())); -} - -void Manager::validateCvmfsCase() const -{ - // The OCDB_PATH variable contains the path to the directory in /cvmfs/ which is - // an AliRoot tag based snapshot of the AliEn file catalogue (e.g. - // /cvmfs/alice.cern.ch/x86_64-2.6-gnu-4.1.2/Packages/OCDB/v5-05-76-AN). - // The directory has to contain: - // 1) /20??.list.gz gzipped text files listing the OCDB files (seen by that AliRoot tag) - // 2) bin/getOCDBFilesPerRun.sh (shell+awk) script extracting from 1) the list - // of valid files for the given run. - - if (!mCvmfsOcdb.BeginsWith("/cvmfs")) //!!!! to be commented out for testing - LOG(FATAL) << "OCDB_PATH set to an invalid path: " << mCvmfsOcdb.Data(); - - TString cvmfsUri(mCvmfsOcdb); - gSystem->ExpandPathName(cvmfsUri); - if (gSystem->AccessPathName(cvmfsUri)) - LOG(FATAL) << "OCDB_PATH set to an invalid path: " << cvmfsUri.Data(); - - // check that we find the two scripts we need - - LOG(DEBUG) << "OCDB_PATH envvar is set. Changing OCDB storage from alien:// to local:///cvmfs type."; - cvmfsUri = cvmfsUri.Strip(TString::kTrailing, '/'); - cvmfsUri.Append("/bin/getOCDBFilesPerRun.sh"); - if (gSystem->AccessPathName(cvmfsUri)) - LOG(FATAL) << "Cannot find valid script: " << cvmfsUri.Data(); -} - -void Manager::setDefaultStorageFromRun(Int_t run) -{ - // set default storage from the run number - to be used only with raw data - - // if lock is ON, cannot activate more storages! - if (mLock) { - if (mDefaultStorage) { - LOG(FATAL) << "Lock is ON, and default storage is already set: cannot activate default " - "storage from run number"; - } - } - - TString lhcPeriod(""); - Int_t startRun = 0, endRun = 0; - if (!mCvmfsOcdb.IsNull()) { // mRaw and cvmfs case: set LHC period from cvmfs file - getLHCPeriodAgainstCvmfsFile(run, lhcPeriod, startRun, endRun); - } else { // mRaw: set LHC period from AliEn XML file - getLHCPeriodAgainstAlienFile(run, lhcPeriod, startRun, endRun); - } - - mLhcPeriod = lhcPeriod; - mStartRunLhcPeriod = startRun; - mEndRunLhcPeriod = endRun; - - setDefaultStorage(mLhcPeriod.Data()); - if (!mDefaultStorage) - LOG(FATAL) << mLhcPeriod.Data() << " storage not there! Please check!"; -} - -void Manager::getLHCPeriodAgainstAlienFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) -{ - // set LHC period (year + first, last run) comparing run number and AliEn XML file - - // retrieve XML file from alien - if (!gGrid) { - TGrid::Connect("alien://", ""); - if (!gGrid) { - LOG(ERROR) << "Connection to alien failed!"; - return; - } - } - TUUID uuid; - TString rndname = "/tmp/"; - rndname += "OCDBFolderXML."; - rndname += uuid.AsString(); - rndname += ".xml"; - LOG(DEBUG) << "file to be copied = " << sOcdbFolderXmlFile.Data(); - if (!TFile::Cp(sOcdbFolderXmlFile.Data(), rndname.Data())) { - LOG(FATAL) << "Cannot make a local copy of OCDBFolder xml file in " << rndname.Data(); - } - XmlHandler* saxcdb = new XmlHandler(); - saxcdb->setRun(run); - TSAXParser* saxParser = new TSAXParser(); - saxParser->ConnectToHandler(" Handler", saxcdb); - saxParser->ParseFile(rndname.Data()); - LOG(INFO) << " LHC folder = " << saxcdb->getOcdbFolder().Data(); - LOG(INFO) << " LHC period start run = " << saxcdb->getStartIdRunRange(); - LOG(INFO) << " LHC period end run = " << saxcdb->getEndIdRunRange(); - lhcPeriod = saxcdb->getOcdbFolder(); - startRun = saxcdb->getStartIdRunRange(); - endRun = saxcdb->getEndIdRunRange(); -} - -void Manager::getLHCPeriodAgainstCvmfsFile(Int_t run, TString& lhcPeriod, Int_t& startRun, Int_t& endRun) -{ - // set LHC period (year + first, last run) comparing run number and CVMFS file - // We don't want to connect to AliEn just to set the uri from the runnumber - // for that we use the script getUriFromYear.sh in the cvmfs AliRoot package - - TString getYearScript(mCvmfsOcdb); - getYearScript = getYearScript.Strip(TString::kTrailing, '/'); - getYearScript.Append("/bin/getUriFromYear.sh"); - if (gSystem->AccessPathName(getYearScript)) - LOG(FATAL) << "Cannot find valid script: " << getYearScript.Data(); - TString inoutFile(gSystem->WorkingDirectory()); - inoutFile += "/uri_range_"; - inoutFile += TString::Itoa(run, 10); - TString command(getYearScript); - command += ' '; - command += TString::Itoa(run, 10); - command += Form(" > %s", inoutFile.Data()); - LOG(DEBUG) << R"(Running command: ")" << command.Data() << R"(")"; - Int_t result = gSystem->Exec(command.Data()); - if (result != 0) { - LOG(FATAL) << R"(Was not able to execute ")" << command.Data() << R"(")"; - } - - // now read the file with the uri and first and last run - std::ifstream file(inoutFile.Data()); - if (!file.is_open()) { - LOG(FATAL) << R"(Error opening file ")" << inoutFile.Data() << R"("!)"; - } - TString line; - TObjArray* oStringsArray = nullptr; - while (line.ReadLine(file)) { - oStringsArray = line.Tokenize(' '); - } - TObjString* oStrUri = dynamic_cast(oStringsArray->At(0)); - TObjString* oStrFirst = dynamic_cast(oStringsArray->At(1)); - TString firstRun = oStrFirst->GetString(); - TObjString* oStrLast = dynamic_cast(oStringsArray->At(2)); - TString lastRun = oStrLast->GetString(); - - lhcPeriod = oStrUri->GetString(); - startRun = firstRun.Atoi(); - endRun = lastRun.Atoi(); - - file.close(); -} - -void Manager::unsetDefaultStorage() -{ - // Unset default storage - - // if lock is ON, action is forbidden! - if (mLock) { - if (mDefaultStorage) { - LOG(FATAL) << "Lock is ON: cannot unset default storage!"; - } - } - - if (mDefaultStorage) { - LOG(WARNING) << "Clearing cache!"; - clearCache(); - } - - mRun = mStartRunLhcPeriod = mEndRunLhcPeriod = -1; - mRaw = kFALSE; - - mDefaultStorage = nullptr; -} - -void Manager::setSpecificStorage(const char* calibType, const char* dbString, Int_t version, Int_t subVersion) -{ - // sets storage specific for detector or calibration type (works with Manager::getObject(...)) - - StorageParameters* aPar = createStorageParameter(dbString); - if (!aPar) { - return; - } - setSpecificStorage(calibType, aPar, version, subVersion); - delete aPar; -} - -void Manager::setSpecificStorage(const char* calibType, const StorageParameters* param, Int_t version, Int_t subVersion) -{ - // sets storage specific for detector or calibration type (works with Manager::getObject(...)) - // Default storage should be defined prior to any specific storages, e.g.: - // Manager::instance()->setDefaultStorage("alien://"); - // Manager::instance()->setSpecificStorage("TPC/*","local://DB_TPC"); - // Manager::instance()->setSpecificStorage("*/Align/*","local://DB_TPCAlign"); - // calibType must be a valid CDB path! (3 level folder structure) - // Specific version/subversion is set in the uniqueid of the Param value stored in the - // specific storages map - - if (!mDefaultStorage && !mRaw) { - LOG(ERROR) << "Please activate a default storage first!"; - return; - } - - IdPath aPath(calibType); - if (!aPath.isValid()) { - LOG(ERROR) << "Not a valid path: " << calibType; - return; - } - - TObjString* objCalibType = new TObjString(aPath.getPathString()); - if (mSpecificStorages.Contains(objCalibType)) { - LOG(WARNING) << R"(Storage ")" << calibType << R"(" already activated! It will be replaced by the new one)"; - StorageParameters* checkPar = dynamic_cast(mSpecificStorages.GetValue(calibType)); - if (checkPar) { - delete checkPar; - } - delete mSpecificStorages.Remove(objCalibType); - } - Storage* aStorage = getStorage(param); - if (!aStorage) { - return; - } - - // Set the unique id of the AliCDBParam stored in the map to store specific version/subversion - UInt_t uId = ((subVersion + 1) << 16) + (version + 1); - StorageParameters* specificParam = param->cloneParam(); - specificParam->SetUniqueID(uId); - mSpecificStorages.Add(objCalibType, specificParam); - - if (mStorageMap->Contains(objCalibType)) { - delete mStorageMap->Remove(objCalibType); - } - mStorageMap->Add(objCalibType->Clone(), new TObjString(param->getUri())); -} - -Storage* Manager::getSpecificStorage(const char* calibType) -{ - // get storage specific for detector or calibration type - - IdPath calibPath(calibType); - if (!calibPath.isValid()) { - return nullptr; - } - - StorageParameters* checkPar = (StorageParameters*)mSpecificStorages.GetValue(calibPath.getPathString()); - if (!checkPar) { - LOG(ERROR) << calibType << " storage not found!"; - return nullptr; - } else { - return getStorage(checkPar); - } -} - -StorageParameters* Manager::selectSpecificStorage(const TString& path) -{ - // select storage valid for path from the list of specific storages - - IdPath aPath(path); - if (!aPath.isValid()) { - return nullptr; - } - - TIter iter(&mSpecificStorages); - TObjString* aCalibType = nullptr; - IdPath tmpPath("null/null/null"); - StorageParameters* aPar = nullptr; - while ((aCalibType = (TObjString*)iter.Next())) { - IdPath calibTypePath(aCalibType->GetName()); - if (calibTypePath.isSupersetOf(aPath)) { - if (calibTypePath.isSupersetOf(tmpPath)) { - continue; - } - aPar = (StorageParameters*)mSpecificStorages.GetValue(aCalibType); - tmpPath.setPath(calibTypePath.getPathString()); - } - } - return aPar; -} - -Condition* Manager::getCondition(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get an Condition object from the database - - if (runNumber < 0) { - // RunNumber is not specified. Try with mRun - if (mRun < 0) { - LOG(ERROR) << "Run number neither specified in query nor set in Manager! Use Manager::setRun."; - return nullptr; - } - runNumber = mRun; - } - - return getCondition(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -Condition* Manager::getCondition(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get an Condition object from the database! - - return getCondition(ConditionId(path, runRange, version, subVersion)); -} - -Condition* Manager::getCondition(const ConditionId& queryId, Bool_t forceCaching) -{ - // get an Condition object from the database - - // check if queryId's path and runRange are valid - // queryId is invalid also if version is not specified and subversion is! - if (!queryId.isValid()) { - LOG(ERROR) << "Invalid query: " << queryId.ToString().Data(); - return nullptr; - } - - // query is not specified if path contains wildcard or run range= [-1,-1] - if (!queryId.isSpecified()) { - LOG(ERROR) << "Unspecified query: " << queryId.ToString().Data(); - return nullptr; - } - - if (mLock && !(mRun >= queryId.getFirstRun() && mRun <= queryId.getLastRun())) - LOG(FATAL) << "Lock is ON: cannot use different run number than the internal one!"; - - if (mCache && !(mRun >= queryId.getFirstRun() && mRun <= queryId.getLastRun())) - LOG(WARNING) << "Run number explicitly set in query: CDB cache temporarily disabled!"; - - Condition* entry = nullptr; - - // first look into map of cached objects - if (mCache && queryId.getFirstRun() == mRun) { - entry = (Condition*)mConditionCache.GetValue(queryId.getPathString()); - } - if (entry) { - LOG(DEBUG) << "Object " << queryId.getPathString().Data() << " retrieved from cache !!"; - return entry; - } - - // if snapshot flag is set, try getting from the snapshot - // but in the case a specific storage is specified for this path - StorageParameters* aPar = selectSpecificStorage(queryId.getPathString()); - if (!aPar) { - if (mSnapshotMode && queryId.getFirstRun() == mRun) { - entry = getConditionFromSnapshot(queryId.getPathString()); - if (entry) { - LOG(INFO) << R"(Object ")" << queryId.getPathString().Data() << R"(" retrieved from the snapshot.)"; - if (queryId.getFirstRun() == mRun) { // no need to check mCache, mSnapshotMode not possible otherwise - cacheCondition(queryId.getPathString(), entry); - } - - if (!mIds->Contains(&entry->getId())) { - mIds->Add(entry->getId().Clone()); - } - - return entry; - } - } - } - - // Condition is not in cache (and, in case we are in snapshot mode, not in the snapshot either) - // => retrieve it from the storage and cache it!! - if (!mDefaultStorage) { - LOG(ERROR) << "No storage set!"; - return nullptr; - } - - Int_t version = -1, subVersion = -1; - Storage* aStorage = nullptr; - if (aPar) { - aStorage = getStorage(aPar); - TString str = aPar->getUri(); - UInt_t uId = aPar->GetUniqueID(); - version = Int_t(uId & 0xffff) - 1; - subVersion = Int_t(uId >> 16) - 1; - LOG(DEBUG) << "Looking into storage: " << str.Data(); - } else { - aStorage = getDefaultStorage(); - LOG(DEBUG) << "Looking into default storage"; - } - - ConditionId finalQueryId(queryId); - if (version >= 0) { - LOG(DEBUG) << "Specific version set to: " << version; - finalQueryId.setVersion(version); - } - if (subVersion >= 0) { - LOG(DEBUG) << "Specific subversion set to: " << subVersion; - finalQueryId.setSubVersion(subVersion); - } - entry = aStorage->getObject(finalQueryId); - - if (entry && mCache && (queryId.getFirstRun() == mRun || forceCaching)) { - cacheCondition(queryId.getPathString(), entry); - } - - if (entry && !mIds->Contains(&entry->getId())) { - mIds->Add(entry->getId().Clone()); - } - - return entry; -} - -Condition* Manager::getConditionFromSnapshot(const char* path) -{ - // get the entry from the open snapshot file - - TString sPath(path); - sPath.ReplaceAll("/", "*"); - if (!mSnapshotFile) { - LOG(ERROR) << "No snapshot file is open!"; - return nullptr; - } - Condition* entry = dynamic_cast(mSnapshotFile->Get(sPath.Data())); - if (!entry) { - LOG(DEBUG) << R"(Cannot get a CDB entry for ")" << path << R"(" from snapshot file)"; - return nullptr; - } - - return entry; -} - -Bool_t Manager::setSnapshotMode(const char* snapshotFileName) -{ - // set the manager in snapshot mode - - if (!mCache) { - LOG(ERROR) << "Cannot set the CDB manage in snapshot mode if the cache is not active!"; - return kFALSE; - } - - // open snapshot file - TString snapshotFile(snapshotFileName); - if (snapshotFile.BeginsWith("alien://")) { - if (!gGrid) { - TGrid::Connect("alien://", ""); - if (!gGrid) { - LOG(ERROR) << "Connection to alien failed!"; - return kFALSE; - } - } - } - - mSnapshotFile = TFile::Open(snapshotFileName); - if (!mSnapshotFile || mSnapshotFile->IsZombie()) { - LOG(ERROR) << "Cannot open file " << snapshotFileName; - return kFALSE; - } - - LOG(INFO) << "The CDB manager is set in snapshot mode!"; - mSnapshotMode = kTRUE; - return kTRUE; -} - -const char* Manager::getUri(const char* path) -{ - // return the URI of the storage where to look for path - - if (!isDefaultStorageSet()) { - return nullptr; - } - - StorageParameters* aPar = selectSpecificStorage(path); - - if (aPar) { - return aPar->getUri().Data(); - - } else { - return getDefaultStorage()->getUri().Data(); - } - - return nullptr; -} - -Int_t Manager::getStartRunLHCPeriod() -{ - // get the first run of validity - // for the current period - // if set - if (mStartRunLhcPeriod == -1) - LOG(WARNING) << "Run-range not yet set for the current LHC period."; - return mStartRunLhcPeriod; -} - -Int_t Manager::getEndRunLHCPeriod() -{ - // get the last run of validity - // for the current period - // if set - if (mEndRunLhcPeriod == -1) - LOG(WARNING) << "Run-range not yet set for the current LHC period."; - return mEndRunLhcPeriod; -} - -TString Manager::getLHCPeriod() -{ - // get the current LHC period string - // - if (mLhcPeriod.IsWhitespace() || mLhcPeriod.IsNull()) - LOG(WARNING) << "LHC period (OCDB folder) not yet set"; - return mLhcPeriod; -} - -ConditionId* Manager::getId(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get the ConditionId of the valid object from the database (does not retrieve the object) - // User must delete returned object! - - if (runNumber < 0) { - // RunNumber is not specified. Try with mRun - if (mRun < 0) { - LOG(ERROR) << "Run number neither specified in query nor set in Manager! Use Manager::setRun."; - return nullptr; - } - runNumber = mRun; - } - - return getId(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -ConditionId* Manager::getId(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get the ConditionId of the valid object from the database (does not retrieve the object) - // User must delete returned object! - - return getId(ConditionId(path, runRange, version, subVersion)); -} - -ConditionId* Manager::getId(const ConditionId& query) -{ - // get the ConditionId of the valid object from the database (does not retrieve the object) - // User must delete returned object! - - if (!mDefaultStorage) { - LOG(ERROR) << "No storage set!"; - return nullptr; - } - - // check if query's path and runRange are valid - // query is invalid also if version is not specified and subversion is! - if (!query.isValid()) { - LOG(ERROR) << "Invalid query: " << query.ToString().Data(); - return nullptr; - } - - // query is not specified if path contains wildcard or run range= [-1,-1] - if (!query.isSpecified()) { - LOG(ERROR) << "Unspecified query: " << query.ToString().Data(); - return nullptr; - } - - if (mCache && query.getFirstRun() != mRun) - LOG(WARNING) << "Run number explicitly set in query: CDB cache temporarily disabled!"; - - Condition* entry = nullptr; - - // first look into map of cached objects - if (mCache && query.getFirstRun() == mRun) { - entry = (Condition*)mConditionCache.GetValue(query.getPathString()); - } - - if (entry) { - LOG(DEBUG) << "Object " << query.getPathString().Data() << " retrieved from cache !!"; - return dynamic_cast(entry->getId().Clone()); - } - - // Condition is not in cache -> retrieve it from CDB and cache it!! - Storage* aStorage = nullptr; - StorageParameters* aPar = selectSpecificStorage(query.getPathString()); - - if (aPar) { - aStorage = getStorage(aPar); - TString str = aPar->getUri(); - LOG(DEBUG) << "Looking into storage: " << str.Data(); - - } else { - aStorage = getDefaultStorage(); - LOG(DEBUG) << "Looking into default storage"; - } - - return aStorage->getId(query); -} - -TList* Manager::getAllObjects(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get multiple Condition objects from the database - - if (runNumber < 0) { - // RunNumber is not specified. Try with mRun - if (mRun < 0) { - LOG(ERROR) << "Run number neither specified in query nor set in Manager! Use Manager::setRun."; - return nullptr; - } - runNumber = mRun; - } - - return getAllObjects(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -TList* Manager::getAllObjects(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get multiple Condition objects from the database - - return getAllObjects(ConditionId(path, runRange, version, subVersion)); -} - -TList* Manager::getAllObjects(const ConditionId& query) -{ - // get multiple Condition objects from the database - // Warning: this method works correctly only for queries of the type "Detector/*" - // and not for more specific queries e.g. "Detector/Calib/*" ! - // Warning #2: Entries are cached, but getAllObjects will keep on retrieving objects from OCDB! - // To get an object from cache use getObject() function - - if (!mDefaultStorage) { - LOG(ERROR) << "No storage set!"; - return nullptr; - } - - if (!query.isValid()) { - LOG(ERROR) << "Invalid query: " << query.ToString().Data(); - return nullptr; - } - - if ((mSpecificStorages.GetEntries() > 0) && query.getPathString().BeginsWith('*')) { - // if specific storages are active a query with "*" is ambiguous - LOG(ERROR) << "Query too generic in this context!"; - return nullptr; - } - - if (query.isAnyRange()) { - LOG(ERROR) << "Unspecified run or runrange: " << query.ToString().Data(); - return nullptr; - } - - if (mLock && query.getFirstRun() != mRun) - LOG(FATAL) << "Lock is ON: cannot use different run number than the internal one!"; - - StorageParameters* aPar = selectSpecificStorage(query.getPathString()); - - Storage* aStorage; - if (aPar) { - aStorage = getStorage(aPar); - LOG(DEBUG) << "Looking into storage: " << aPar->getUri().Data(); - - } else { - aStorage = getDefaultStorage(); - LOG(DEBUG) << "Looking into default storage: " << aStorage->getUri().Data(); - } - - TList* result = nullptr; - if (aStorage) { - result = aStorage->getAllObjects(query); - } - if (!result) { - return nullptr; - } - - // loop on result to check whether entries should be re-queried with specific storages - if (mSpecificStorages.GetEntries() > 0 && !(mSpecificStorages.GetEntries() == 1 && aPar)) { - LOG(INFO) << "Now look into all other specific storages..."; - - TIter iter(result); - Condition* chkCondition = nullptr; - - while ((chkCondition = dynamic_cast(iter.Next()))) { - ConditionId& chkId = chkCondition->getId(); - LOG(DEBUG) << "Checking id " << chkId.getPathString().Data() << " "; - StorageParameters* chkPar = selectSpecificStorage(chkId.getPathString()); - if (!chkPar || aPar == chkPar) { - continue; - } - Storage* chkStorage = getStorage(chkPar); - LOG(DEBUG) << "Found specific storage! " << chkPar->getUri().Data(); - - chkId.setIdRunRange(query.getFirstRun(), query.getLastRun()); - UInt_t uId = chkPar->GetUniqueID(); - Int_t version = -1, subVersion = -1; - version = Int_t(uId & 0xffff) - 1; - subVersion = Int_t(uId >> 16) - 1; - if (version != -1) { - chkId.setVersion(version); - } else { - chkId.setVersion(query.getVersion()); - } - if (subVersion != -1) { - chkId.setSubVersion(subVersion); - } else { - chkId.setSubVersion(query.getSubVersion()); - } - - Condition* newCondition = nullptr; - - if (chkStorage) { - newCondition = chkStorage->getObject(chkId); - } - if (!newCondition) { - continue; - } - - // object is found in specific storage: replace entry in the result list! - chkCondition->setOwner(1); - delete result->Remove(chkCondition); - result->AddFirst(newCondition); - } - - Int_t nEntries = result->GetEntries(); - LOG(INFO) << "After look into other specific storages, result list is:"; - for (int i = 0; i < nEntries; i++) { - Condition* entry = (Condition*)result->At(i); - LOG(INFO) << entry->getId().ToString().Data(); - } - } - - // caching entries - TIter iter(result); - Condition* entry = nullptr; - while ((entry = dynamic_cast(iter.Next()))) { - - if (!mIds->Contains(&entry->getId())) { - mIds->Add(entry->getId().Clone()); - } - if (mCache && (query.getFirstRun() == mRun)) { - cacheCondition(entry->getId().getPathString(), entry); - } - } - - return result; -} - -Bool_t Manager::putObject(TObject* object, const ConditionId& id, ConditionMetaData* metaData, const char* mirrors) -{ - // store an Condition object into the database - - if (object == nullptr) { - LOG(ERROR) << "Null Condition! No storage will be done!"; - return kFALSE; - } - - Condition anCondition(object, id, metaData); - return putCondition(&anCondition, mirrors); -} - -Bool_t Manager::putCondition(Condition* entry, const char* mirrors) -{ - // store an Condition object into the database - - if (!mDefaultStorage) { - LOG(ERROR) << "No storage set!"; - return kFALSE; - } - - if (!entry) { - LOG(ERROR) << "No entry!"; - return kFALSE; - } - - if (entry->getObject() == nullptr) { - LOG(ERROR) << "No valid object in CDB entry!"; - return kFALSE; - } - - if (!entry->getId().isValid()) { - LOG(ERROR) << "Invalid entry ID: " << entry->getId().ToString().Data(); - return kFALSE; - } - - if (!entry->getId().isSpecified()) { - LOG(ERROR) << "Unspecified entry ID: " << entry->getId().ToString().Data(); - return kFALSE; - } - - ConditionId id = entry->getId(); - StorageParameters* aPar = selectSpecificStorage(id.getPathString()); - - Storage* aStorage = nullptr; - - if (aPar) { - aStorage = getStorage(aPar); - } else { - aStorage = getDefaultStorage(); - } - - LOG(DEBUG) << "Storing object into storage: " << aStorage->getUri().Data(); - - TString strMirrors(mirrors); - Bool_t result = kFALSE; - if (!strMirrors.IsNull() && !strMirrors.IsWhitespace()) { - result = aStorage->putObject(entry, mirrors); - } else { - result = aStorage->putObject(entry, ""); - } - - if (mRun >= 0) { - queryStorages(); - } - - return result; -} - -void Manager::setMirrorSEs(const char* mirrors) -{ - // set mirror Storage Elements for the default storage, if it is of type "alien" - if (mDefaultStorage->getStorageType() != "alien") { - LOG(INFO) - << R"(The default storage is not of type "alien". Settings for Storage Elements are not taken into account!)"; - return; - } - mDefaultStorage->setMirrorSEs(mirrors); -} - -const char* Manager::getMirrorSEs() const -{ - // get mirror Storage Elements for the default storage, if it is of type "alien" - if (mDefaultStorage->getStorageType() != "alien") { - LOG(INFO) - << R"(The default storage is not of type "alien". Settings for Storage Elements are not taken into account!)"; - return ""; - } - return mDefaultStorage->getMirrorSEs(); -} - -void Manager::cacheCondition(const char* path, Condition* entry) -{ - // cache Condition. Cache is valid until run number is changed. - - Condition* chkCondition = dynamic_cast(mConditionCache.GetValue(path)); - - if (chkCondition) { - LOG(DEBUG) << "Object " << path << " already in cache !!"; - return; - } else { - LOG(DEBUG) << "Caching entry " << path; - } - - mConditionCache.Add(new TObjString(path), entry); - LOG(DEBUG) << "Cache entries: " << mConditionCache.GetEntries(); -} - -void Manager::print(Option_t* /*option*/) const -{ - // Print list of active storages and their URIs - - TString output = Form("Run number = %d; ", mRun); - output += "Cache is "; - if (!mCache) { - output += "NOT "; - } - output += Form("ACTIVE; Number of active storages: %d\n", mActiveStorages.GetEntries()); - - if (mDefaultStorage) { - output += Form("\t*** Default Storage URI: \"%s\"\n", mDefaultStorage->getUri().Data()); - } - if (mSpecificStorages.GetEntries() > 0) { - TIter iter(mSpecificStorages.GetTable()); - TPair* aPair = nullptr; - Int_t i = 1; - while ((aPair = (TPair*)iter.Next())) { - output += Form("\t*** Specific storage %d: Path \"%s\" -> URI \"%s\"\n", i++, - ((TObjString*)aPair->Key())->GetName(), ((StorageParameters*)aPair->Value())->getUri().Data()); - } - } - if (mdrainStorage) { - output += Form("*** drain Storage URI: %s\n", mdrainStorage->getUri().Data()); - } - LOG(INFO) << output.Data(); -} - -void Manager::setRun(Int_t run) -{ - // Sets current run number. - // When the run number changes the caching is cleared. - - if (mRun == run) { - return; - } - - if (mLock && mRun >= 0) { - LOG(FATAL) << "Lock is ON, cannot reset run number!"; - } - - mRun = run; - - if (mRaw) { - // here the LHCPeriod xml file is parsed; the string containing the correct period is returned; - // the default storage is set - if (mStartRunLhcPeriod <= run && mEndRunLhcPeriod >= run) { - LOG(INFO) << "LHCPeriod alien folder for current run already in memory"; - } else { - setDefaultStorageFromRun(mRun); - if (mConditionCache.GetEntries() != 0) { - clearCache(); - } - return; - } - } - clearCache(); - queryStorages(); -} - -void Manager::clearCache() -{ - // clear Condition cache - - LOG(DEBUG) << "Cache entries to be deleted: " << mConditionCache.GetEntries(); - - /* - // To clean entries one by one - TIter iter(mConditionCache.GetTable()); - TPair* pair=0; - while((pair= dynamic_cast (iter.Next()))){ - - TObjString* key = dynamic_cast (pair->Key()); - Condition* entry = dynamic_cast< Condition*> (pair->Value()); - LOG(DEBUG) << "Deleting entry: " << key->GetName(); - if (entry) delete entry; - delete mConditionCache.Remove(key); - } - */ - mConditionCache.DeleteAll(); - LOG(DEBUG) << "After deleting - Cache entries: " << mConditionCache.GetEntries(); -} - -void Manager::unloadFromCache(const char* path) -{ - // unload cached object - // that is remove the entry from the cache and the id from the list of ids - // - if (!mActiveStorages.GetEntries()) { - LOG(DEBUG) << R"(No active storages. Object ")" << path << R"(" is not unloaded from cache)"; - return; - } - - IdPath queryPath(path); - if (!queryPath.isValid()) { - return; - } - - if (!queryPath.isWildcard()) { // path is not wildcard, get it directly from the cache and unload it! - if (mConditionCache.Contains(path)) { - LOG(DEBUG) << R"(Unloading object ")" << path << R"(" from cache and from list of ids)"; - TObjString pathStr(path); - delete mConditionCache.Remove(&pathStr); - // we do not remove from the list of ConditionId's (it's not very coherent but we leave the - // id for the benefit of the userinfo) - /* - TIter iter(mIds); - ConditionId *id = 0; - while((id = dynamic_cast (iter.Next()))){ - if(queryPath.isSupersetOf(id->getPath())) - delete mIds->Remove(id); - }*/ - } else { - LOG(WARNING) << R"(Cache does not contain object ")" << path << R"("!)"; - } - LOG(DEBUG) << "Cache entries: " << mConditionCache.GetEntries(); - return; - } - - // path is wildcard: loop on the cache and unload all comprised objects! - TIter iter(mConditionCache.GetTable()); - TPair* pair = nullptr; - Int_t removed = 0; - - while ((pair = dynamic_cast(iter.Next()))) { - IdPath entryPath = pair->Key()->GetName(); - if (queryPath.isSupersetOf(entryPath)) { - LOG(DEBUG) << R"(Unloading object ")" << entryPath.getPathString().Data() - << R"(" from cache and from list of ids)"; - TObjString pathStr(entryPath.getPathString()); - delete mConditionCache.Remove(&pathStr); - removed++; - - // we do not remove from the list of ConditionId's (it's not very coherent but we leave the - // id for the benefit of the userinfo) - /* - TIter iterids(mIds); - ConditionId *anId = 0; - while((anId = dynamic_cast (iterids.Next()))){ - IdPath aPath = anId->getPath(); - TString aPathStr = aPath.getPath(); - if(queryPath.isSupersetOf(aPath)) { - delete mIds->Remove(anId); - } - }*/ - } - } - LOG(DEBUG) << "Cache entries and ids removed: " << removed << " Remaining: " << mConditionCache.GetEntries(); -} - -void Manager::destroyActiveStorages() -{ - // delete list of active storages - - mActiveStorages.DeleteAll(); - mSpecificStorages.DeleteAll(); -} - -void Manager::destroyActiveStorage(Storage* /*storage*/) -{ - // destroys active storage - - /* - TIter iter(mActiveStorages.GetTable()); - TPair* aPair; - while ((aPair = (TPair*) iter.Next())) { - if(storage == ( Storage*) aPair->Value()) - delete mActiveStorages.Remove(aPair->Key()); - storage->Delete(); storage=0x0; - } - */ -} - -void Manager::queryStorages() -{ - // query default and specific storages for files valid for mRun. Every storage loads the Ids into - // its list. - - if (mRun < 0) { - LOG(ERROR) << "Run number not yet set! Use Manager::setRun."; - return; - } - if (!mDefaultStorage) { - LOG(ERROR) << "Default storage is not set! Use Manager::setDefaultStorage"; - return; - } - if (mDefaultStorage->getStorageType() == "alien" || mDefaultStorage->getStorageType() == "local") { - mDefaultStorage->queryStorages(mRun); - //} else { - // LOG(DEBUG) << "Skipping query for valid files, it used only in grid..."; - } - - TIter iter(&mSpecificStorages); - TObjString* aCalibType = nullptr; - StorageParameters* aPar = nullptr; - while ((aCalibType = dynamic_cast(iter.Next()))) { - aPar = (StorageParameters*)mSpecificStorages.GetValue(aCalibType); - if (aPar) { - LOG(DEBUG) << "Querying specific storage " << aCalibType->GetName(); - Storage* aStorage = getStorage(aPar); - if (aStorage->getStorageType() == "alien" || aStorage->getStorageType() == "local") { - aStorage->queryStorages(mRun, aCalibType->GetName()); - } else { - LOG(DEBUG) << "Skipping query for valid files, it is used only in grid..."; - } - } - } -} - -Bool_t Manager::diffObjects(const char* cdbFile1, const char* cdbFile2) const -{ - // Compare byte-by-byte the objects contained in the CDB entry in two different files, - // whose name is passed as input - // Return value: - // kTRUE - in case the content of the OCDB object (persistent part) is exactly the same - // kFALSE - otherwise - - TString f1Str(cdbFile1); - TString f2Str(cdbFile2); - if (!gGrid && (f1Str.BeginsWith("alien://") || f2Str.BeginsWith("alien://"))) { - TGrid::Connect("alien://"); - } - - TFile* f1 = TFile::Open(cdbFile1); - if (!f1) { - Printf(R"(Cannot open file "%s")", cdbFile1); - return kFALSE; - } - TFile* f2 = TFile::Open(cdbFile2); - if (!f2) { - Printf(R"(Cannot open file "%s")", cdbFile2); - return kFALSE; - } - - Condition* entry1 = (Condition*)f1->Get(" Condition"); - if (!entry1) { - Printf(R"(Cannot get CDB entry from file "%s")", cdbFile1); - return kFALSE; - } - Condition* entry2 = (Condition*)f2->Get(" Condition"); - if (!entry2) { - Printf(R"(Cannot get CDB entry from file "%s")", cdbFile2); - return kFALSE; - } - - // stream the two objects in the buffer of two TMessages - TObject* object1 = entry1->getObject(); - TObject* object2 = entry2->getObject(); - TMessage* file1 = new TMessage(TBuffer::kWrite); - file1->WriteObject(object1); - Int_t size1 = file1->Length(); - TMessage* file2 = new TMessage(TBuffer::kWrite); - file2->WriteObject(object2); - Int_t size2 = file2->Length(); - if (size1 != size2) { - Printf("Problem 2: OCDB entry of different size (%d,%d)", size1, size2); - return kFALSE; - } - - // if the two buffers have the same size, check that they are the same byte-by-byte - Int_t countDiff = 0; - char* buf1 = file1->Buffer(); - char* buf2 = file2->Buffer(); - // for (Int_t i=0; iBuffer()[i]!=file2->Buffer()[i]) countDiff++; - for (Int_t i = 0; i < size1; i++) { - if (buf1[i] != buf2[i]) { - countDiff++; - } - } - - if (countDiff > 0) { - Printf("The CDB objects differ by %d bytes.", countDiff); - return kFALSE; - } - - Printf("The CDB objects are the same in the two files."); - return kTRUE; -} - -ULong64_t Manager::setLock(Bool_t lock, ULong64_t key) -{ - // To lock/unlock user must provide the key. A new key is provided after - // each successful lock. User should always backup the returned key and - // use it on next access. - if (mLock == lock) { - return 0; - } // nothing to be done - if (lock) { - // User wants to lock - check his identity - if (mKey) { - // Lock has a user - check his key - if (mKey != key) { - LOG(FATAL) << "Wrong key provided to lock CDB. Please remove CDB lock access from your code !"; - return 0; - } - } - // Provide new key - mKey = gSystem->Now(); - mLock = kTRUE; - return mKey; - } - // User wants to unlock - check the provided key - if (key != mKey) { - LOG(FATAL) << "Lock is ON: wrong key provided"; - return 0; - } - mLock = kFALSE; - return key; -} - -void Manager::extractBaseFolder(TString& url) -{ - // TBD RS - // remove everything but the url - - // Exact copy of the AliReconstuction::Rectify.... (to be removed) - // - // - TString sbs; - if (!(sbs = url(R"(\?User=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - if (!(sbs = url(R"(\?DBFolder=[^?]*)")).IsNull()) { - url.ReplaceAll("?DB", ""); - } - if (!(sbs = url(R"(\?SE=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - if (!(sbs = url(R"(\?CacheFolder=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - if (!(sbs = url(R"(\?OperateDisconnected=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - if (!(sbs = url(R"(\?CacheSize=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - if (!(sbs = url(R"(\?CleanupInterval=[^?]*)")).IsNull()) { - url.ReplaceAll(sbs, ""); - } - Bool_t slash = kFALSE, space = kFALSE; - while ((slash = url.EndsWith("/")) || (space = url.EndsWith(" "))) { - if (slash) { - url = url.Strip(TString::kTrailing, '/'); - } - if (space) { - url = url.Strip(TString::kTrailing, ' '); - } - } - // url.ToLower(); - // -} - -// interface to specific Parameter class // -// (GridStorageParam, LocalStorageParam, DumpParam) // - -StorageParameters::StorageParameters() : mType(), mURI() -{ - // constructor -} - -StorageParameters::~StorageParameters() = default; diff --git a/CCDB/src/ObjectHandler.cxx b/CCDB/src/ObjectHandler.cxx deleted file mode 100644 index 31b5b1074d0d1..0000000000000 --- a/CCDB/src/ObjectHandler.cxx +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "CCDB/ObjectHandler.h" - -#include "TBufferFile.h" -#include "TFile.h" - -#include - -#include - -using namespace o2::ccdb; - -ObjectHandler::ObjectHandler() = default; - -ObjectHandler::~ObjectHandler() = default; - -void ObjectHandler::GetObject(const std::string& path, std::string& object) -{ - TFile* file = new TFile(path.c_str()); - - // If file was not found or empty - if (file->IsZombie()) { - LOG(ERROR) << "The object was not found at " << path; - } - - // Get the AliCDBEntry from the root file - // we cast it directly to TObject (to avoid a link dependency on AliRoot here) - TObject* entry = file->Get("AliCDBEntry"); - - // Create an outcoming buffer - TBufferFile* buffer = new TBufferFile(TBuffer::kWrite); - - // Stream and serialize the AliCDBEntry object to the buffer - buffer->WriteObject((const TObject*)entry); - - // Obtain a pointer to the buffer - char* pointer = buffer->Buffer(); - - // Store the object to the referenced string - object.assign(pointer, buffer->Length()); - - // LOG(INFO) << "Object length: " << object.size(); - - // Release the open file - delete file; - - delete buffer; - - delete entry; -} diff --git a/CCDB/src/Storage.cxx b/CCDB/src/Storage.cxx deleted file mode 100644 index 7effe573478e9..0000000000000 --- a/CCDB/src/Storage.cxx +++ /dev/null @@ -1,522 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "CCDB/Storage.h" -#include // for LOG -#include // for TH1 -#include // for TKey -#include // for TNtuple -#include "CCDB/Condition.h" // for Condition -#include "CCDB/Manager.h" // for Manager - -using namespace o2::ccdb; - -ClassImp(Storage); - -Storage::Storage() - : mValidFileIds(), - mRun(-1), - mPathFilter(), - mVersion(-1), - mConditionMetaDataFilter(nullptr), - mSelections(), - mURI(), - mType(), - mBaseFolder(), - mNretry(0), - mInitRetrySeconds(0) -{ - // constructor - - mValidFileIds.SetOwner(1); - mSelections.SetOwner(1); -} - -Storage::~Storage() -{ - // destructor - - removeAllSelections(); - mValidFileIds.Clear(); - delete mConditionMetaDataFilter; -} - -void Storage::getSelection(/*const*/ ConditionId* id) -{ - // return required version and subversion from the list of selection criteria - - TIter iter(&mSelections); - ConditionId* aSelection; - - // loop on the list of selection criteria - while ((aSelection = (ConditionId*)iter.Next())) { - // check if selection element contains id's path and run (range) - if (aSelection->isSupersetOf(*id)) { - LOG(DEBUG) << "Using selection criterion: " << aSelection->ToString().Data() << " "; - // return required version and subversion - - id->setVersion(aSelection->getVersion()); - id->setSubVersion(aSelection->getSubVersion()); - return; - } - } - - // no valid element is found in the list of selection criteria -> return - LOG(DEBUG) << "Looking for objects with most recent version"; - return; -} - -void Storage::readSelectionFromFile(const char* fileName) -{ - // read selection criteria list from file - - removeAllSelections(); - - TList* list = getIdListFromFile(fileName); - if (!list) { - return; - } - - list->SetOwner(); - Int_t nId = list->GetEntries(); - ConditionId* id; - TKey* key; - - for (int i = nId - 1; i >= 0; i--) { - key = (TKey*)list->At(i); - id = (ConditionId*)key->ReadObj(); - if (id) { - addSelection(*id); - } - } - delete list; - LOG(INFO) << "Selection criteria list filled with " << mSelections.GetEntries() << " entries"; - printSelectionList(); -} - -void Storage::addSelection(const ConditionId& selection) -{ - // add a selection criterion - - IdPath path = selection.getPath(); - if (!path.isValid()) { - return; - } - - TIter iter(&mSelections); - const ConditionId* anId; - while ((anId = (ConditionId*)iter.Next())) { - if (selection.isSupersetOf(*anId)) { - LOG(WARNING) << "This selection is more general than a previous one and will hide it!"; - LOG(WARNING) << (anId->ToString()).Data(); - mSelections.AddBefore(anId, new ConditionId(selection)); - return; - } - } - mSelections.AddFirst(new ConditionId(selection)); -} - -void Storage::addSelection(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // add a selection criterion - - addSelection(ConditionId(path, runRange, version, subVersion)); -} - -void Storage::addSelection(const IdPath& path, Int_t firstRun, Int_t lastRun, Int_t version, Int_t subVersion) -{ - // add a selection criterion - - addSelection(ConditionId(path, firstRun, lastRun, version, subVersion)); -} - -void Storage::removeSelection(const ConditionId& selection) -{ - // remove a selection criterion - - TIter iter(&mSelections); - ConditionId* aSelection; - - while ((aSelection = (ConditionId*)iter.Next())) { - if (selection.isSupersetOf(*aSelection)) { - mSelections.Remove(aSelection); - } - } -} - -void Storage::removeSelection(const IdPath& path, const IdRunRange& runRange) -{ - // remove a selection criterion - - removeSelection(ConditionId(path, runRange, -1, -1)); -} - -void Storage::removeSelection(const IdPath& path, Int_t firstRun, Int_t lastRun) -{ - // remove a selection criterion - - removeSelection(ConditionId(path, firstRun, lastRun, -1, -1)); -} - -void Storage::removeSelection(int position) -{ - // remove a selection criterion from its position in the list - - delete mSelections.RemoveAt(position); -} - -void Storage::removeAllSelections() -{ - // remove all selection criteria - - mSelections.Clear(); -} - -void Storage::printSelectionList() -{ - // prints the list of selection criteria - - TIter iter(&mSelections); - ConditionId* aSelection; - - // loop on the list of selection criteria - int index = 0; - while ((aSelection = (ConditionId*)iter.Next())) { - LOG(INFO) << "index " << index++ << " -> selection: " << aSelection->ToString().Data(); - } -} - -Condition* Storage::getObject(const ConditionId& query) -{ - // get an Condition object from the database - - // check if query's path and runRange are valid - // query is invalid also if version is not specified and subversion is! - if (!query.isValid()) { - LOG(ERROR) << "Invalid query: " << query.ToString().Data(); - return nullptr; - } - - // query is not specified if path contains wildcard or runrange = [-1,-1] - if (!query.isSpecified()) { - LOG(ERROR) << "Unspecified query: " << query.ToString().Data(); - return nullptr; - } - - // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed! - Bool_t oldStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory(kFALSE); - - Condition* entry = getCondition(query); - - if (oldStatus != kFALSE) { - TH1::AddDirectory(kTRUE); - } - - // if drain storage is set, drain entry into drain storage - if (entry && (Manager::Instance())->isdrainSet()) { - Manager::Instance()->drain(entry); - } - - return entry; -} - -Condition* Storage::getObject(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get an Condition object from the database - - return getObject(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -Condition* Storage::getObject(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get an Condition object from the database - - return getObject(ConditionId(path, runRange, version, subVersion)); -} - -TList* Storage::getAllObjects(const ConditionId& query) -{ - // get multiple Condition objects from the database - - if (!query.isValid()) { - LOG(ERROR) << "Invalid query: " << query.ToString().Data(); - return nullptr; - } - - if (query.isAnyRange()) { - LOG(ERROR) << "Unspecified run or runrange: " << query.ToString().Data(); - return nullptr; - } - - // This is needed otherwise TH1 objects (histos, TTree's) are lost when file is closed! - Bool_t oldStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory(kFALSE); - - TList* result = getAllEntries(query); - - if (oldStatus != kFALSE) { - TH1::AddDirectory(kTRUE); - } - - Int_t nEntries = result->GetEntries(); - - LOG(INFO) << nEntries << " objects retrieved. Request was: " << query.ToString().Data(); - for (int i = 0; i < nEntries; i++) { - Condition* entry = (Condition*)result->At(i); - LOG(INFO) << entry->getId().ToString().Data(); - } - - // if drain storage is set, drain entries into drain storage - if ((Manager::Instance())->isdrainSet()) { - for (int i = 0; i < result->GetEntries(); i++) { - Condition* entry = (Condition*)result->At(i); - Manager::Instance()->drain(entry); - } - } - - return result; -} - -TList* Storage::getAllObjects(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get multiple Condition objects from the database - - return getAllObjects(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -TList* Storage::getAllObjects(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get multiple Condition objects from the database - - return getAllObjects(ConditionId(path, runRange, version, subVersion)); -} - -ConditionId* Storage::getId(const ConditionId& query) -{ - // get the ConditionId of the valid object from the database (does not open the file) - - // check if query's path and runRange are valid - // query is invalid also if version is not specified and subversion is! - if (!query.isValid()) { - LOG(ERROR) << "Invalid query: " << query.ToString().Data(); - return nullptr; - } - - // query is not specified if path contains wildcard or runrange = [-1,-1] - if (!query.isSpecified()) { - LOG(ERROR) << "Unspecified query: " << query.ToString().Data(); - return nullptr; - } - - ConditionId* id = getConditionId(query); - - return id; -} - -ConditionId* Storage::getId(const IdPath& path, Int_t runNumber, Int_t version, Int_t subVersion) -{ - // get the ConditionId of the valid object from the database (does not open the file) - - return getId(ConditionId(path, runNumber, runNumber, version, subVersion)); -} - -ConditionId* Storage::getId(const IdPath& path, const IdRunRange& runRange, Int_t version, Int_t subVersion) -{ - // get the ConditionId of the valid object from the database (does not open the file) - - return getId(ConditionId(path, runRange, version, subVersion)); -} - -Bool_t Storage::putObject(TObject* object, ConditionId& id, ConditionMetaData* metaData, const char* mirrors) -{ - // store an Condition object into the database - - if (object == nullptr) { - LOG(ERROR) << "Null Condition! No storage will be done!"; - return kFALSE; - } - - Condition anCondition(object, id, metaData); - - return putObject(&anCondition, mirrors); -} - -Bool_t Storage::putObject(Condition* entry, const char* mirrors) -{ - // store an Condition object into the database - - if (!entry) { - LOG(ERROR) << "No entry!"; - return kFALSE; - } - - if (entry->getObject() == nullptr) { - LOG(ERROR) << "No valid object in CDB entry!"; - return kFALSE; - } - - if (!entry->getId().isValid()) { - LOG(ERROR) << "Invalid entry ID: " << entry->getId().ToString().Data(); - return kFALSE; - } - - if (!entry->getId().isSpecified()) { - LOG(ERROR) << "Unspecified entry ID: " << entry->getId().ToString().Data(); - return kFALSE; - } - - TString strMirrors(mirrors); - if (!strMirrors.IsNull() && !strMirrors.IsWhitespace()) { - return putCondition(entry, mirrors); - } else { - return putCondition(entry); - } -} - -void Storage::queryStorages(Int_t run, const char* pathFilter, Int_t version, ConditionMetaData* md) -{ - // query CDB for files valid for given run, and fill list mValidFileIds - // Actual query is done in virtual function queryValidFiles() - // If version is not specified, the query will fill mValidFileIds - // with highest versions - - mRun = run; - - mPathFilter = pathFilter; - if (!mPathFilter.isValid()) { - LOG(ERROR) << "Filter not valid: " << pathFilter; - mPathFilter = "*"; - return; - } - - mVersion = version; - - LOG(INFO) << "Querying files valid for run " << mRun << R"( and path ")" << pathFilter << R"(" into CDB storage ")" - << mType.Data() << "://" << mBaseFolder.Data() << R"(")"; - - // In mValidFileIds, clear id for the same 3level path, if any - LOG(DEBUG) << R"(Clearing list of CDB ConditionId's previously loaded for path ")" << pathFilter << R"(")"; - IdPath filter(pathFilter); - for (Int_t i = mValidFileIds.GetEntries() - 1; i >= 0; --i) { - ConditionId* rmMe = dynamic_cast(mValidFileIds.At(i)); - IdPath rmPath = rmMe->getPathString(); - if (filter.isSupersetOf(rmPath)) { - LOG(DEBUG) << R"(Removing id ")" << rmPath.getPathString().Data() << R"(" matching: ")" << pathFilter << R"(")"; - delete mValidFileIds.RemoveAt(i); - } - } - - if (mConditionMetaDataFilter) { - delete mConditionMetaDataFilter; - mConditionMetaDataFilter = nullptr; - } - if (md) { - mConditionMetaDataFilter = dynamic_cast(md->Clone()); - } - - queryValidFiles(); - - LOG(INFO) << mValidFileIds.GetEntries() << " valid files found!"; -} - -void Storage::printrQueryStorages() -{ - // print parameters used to load list of CDB ConditionId's (mRun, mPathFilter, mVersion) - - ConditionId paramId(mPathFilter, mRun, mRun, mVersion); - LOG(INFO) << "**** queryStorages Parameters **** \n\t\"" << paramId.ToString().Data() << R"(")"; - - if (mConditionMetaDataFilter) { - mConditionMetaDataFilter->printConditionMetaData(); - } - - TString message = "**** ConditionId's of valid objects found *****\n"; - TIter iter(&mValidFileIds); - ConditionId* anId = nullptr; - - // loop on the list of selection criteria - while ((anId = dynamic_cast(iter.Next()))) { - message += Form("\t%s\n", anId->ToString().Data()); - } - message += Form("\n\tTotal: %d objects found\n", mValidFileIds.GetEntriesFast()); - LOG(INFO) << message.Data(); -} - -void Storage::setMirrorSEs(const char* mirrors) -{ - // if the current storage is not of "alien" type, just issue a warning - // GridStorage implements its own setMirrorSEs method, classes for other storage types do not - - TString storageType = getStorageType(); - if (storageType != "alien") { - LOG(WARNING) << R"(The current storage is of type ")" << storageType.Data() << R"(". Setting of SEs to ")" - << mirrors - << R"(" skipped!)"; - return; - } - LOG(ERROR) << "We should never get here!! GridStorage must have masked this virtual method!"; - return; -} - -const char* Storage::getMirrorSEs() const -{ - // if the current storage is not of "alien" type, just issue a warning - // GridStorage implements its own getMirrorSEs method, classes for other storage types do not - - TString storageType = getStorageType(); - if (storageType != "alien") { - LOG(WARNING) << R"(The current storage is of type ")" << storageType.Data() - << R"(" and cannot handle SEs. Returning empty string!)"; - return ""; - } - LOG(ERROR) << "We should never get here!! GridStorage must have masked this virtual method!"; - return ""; -} - -void Storage::loadTreeFromFile(Condition* entry) const -{ - // Checks whether entry contains a TTree and in case loads it into memory - - TObject* obj = (TObject*)entry->getObject(); - if (!obj) { - LOG(ERROR) << "Cannot retrieve the object:"; - entry->printConditionMetaData(); - return; - } - - if (!strcmp(obj->ClassName(), TTree::Class_Name())) { - - LOG(WARNING) << "Condition contains a TTree! Loading baskets..."; - - TTree* tree = dynamic_cast(obj); - - if (!tree) { - return; - } - - tree->LoadBaskets(); - tree->SetDirectory(nullptr); - } else if (!strcmp(obj->ClassName(), TNtuple::Class_Name())) { - - LOG(WARNING) << "Condition contains a TNtuple! Loading baskets..."; - - TNtuple* ntu = dynamic_cast(obj); - - if (!ntu) { - return; - } - - ntu->LoadBaskets(); - ntu->SetDirectory(nullptr); - } - - return; -} diff --git a/CCDB/src/XmlHandler.cxx b/CCDB/src/XmlHandler.cxx deleted file mode 100644 index 6d554a384aaae..0000000000000 --- a/CCDB/src/XmlHandler.cxx +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -// The SAX XML file handler used in the CDBManager // -#include "CCDB/XmlHandler.h" -#include // for LOG -#include // for TList -#include // for TXMLAttr - -using namespace o2::ccdb; -ClassImp(XmlHandler); - -XmlHandler::XmlHandler() : TObject(), mRun(-1), mStartIdRunRange(-1), mEndIdRunRange(-1), mOCDBFolder("") -{ - // - // XmlHandler default constructor - // -} - -XmlHandler::XmlHandler(Int_t run) : TObject(), mRun(run), mStartIdRunRange(-1), mEndIdRunRange(-1), mOCDBFolder("") -{ - // - // XmlHandler constructor with requested run - // -} - -XmlHandler::XmlHandler(const XmlHandler&) = default; - -XmlHandler& XmlHandler::operator=(const XmlHandler& sh) -{ - // - // Assignment operator - // - if (&sh == this) { - return *this; - } - - new (this) XmlHandler(sh); - return *this; -} - -XmlHandler::~XmlHandler() = default; - -void XmlHandler::OnStartDocument() -{ - // if something should happen right at the beginning of the - // XML document, this must happen here - LOG(INFO) << "Reading XML file for LHCPeriod <-> Run Range correspondence"; -} - -void XmlHandler::OnEndDocument() -{ - // if something should happen at the end of the XML document - // this must be done here -} - -void XmlHandler::OnStartElement(const char* name, const TList* attributes) -{ - // when a new XML element is found, it is processed here - - // set the current system if necessary - TString strName(name); - LOG(DEBUG) << "name = " << strName.Data(); - Int_t startRun = -1; - Int_t endRun = -1; - TXMLAttr* attr; - TIter next(attributes); - while ((attr = (TXMLAttr*)next())) { - TString attrName = attr->GetName(); - LOG(DEBUG) << "Name = " << attrName.Data(); - if (attrName == "StartIdRunRange") { - startRun = (Int_t)(((TString)(attr->GetValue())).Atoi()); - LOG(DEBUG) << "startRun = " << startRun; - } - if (attrName == "EndIdRunRange") { - endRun = (Int_t)(((TString)(attr->GetValue())).Atoi()); - LOG(DEBUG) << "endRun = " << endRun; - } - if (attrName == "OCDBFolder") { - if (mRun >= startRun && mRun <= endRun && startRun != -1 && endRun != -1) { - mOCDBFolder = (TString)(attr->GetValue()); - LOG(DEBUG) << "OCDBFolder = " << mOCDBFolder.Data(); - mStartIdRunRange = startRun; - mEndIdRunRange = endRun; - } - } - } - return; -} - -void XmlHandler::OnEndElement(const char* name) -{ - // do everything that needs to be done when an end tag of an element is found - TString strName(name); - LOG(DEBUG) << "name = " << strName.Data(); -} - -void XmlHandler::OnCharacters(const char* characters) -{ - // copy the text content of an XML element - // mContent = characters; - TString strCharacters(characters); - LOG(DEBUG) << "characters = " << strCharacters.Data(); -} - -void XmlHandler::OnComment(const char* /*text*/) -{ - // comments within the XML file are ignored -} - -void XmlHandler::OnWarning(const char* text) -{ - // process warnings here - LOG(INFO) << "Warning: " << text; -} - -void XmlHandler::OnError(const char* text) -{ - // process errors here - LOG(ERROR) << "Error: " << text; -} - -void XmlHandler::OnFatalError(const char* text) -{ - // process fatal errors here - LOG(FATAL) << "Fatal error: " << text; -} - -void XmlHandler::OnCdataBlock(const char* /*text*/, Int_t /*len*/) -{ - // process character data blocks here - // not implemented and should not be used here -} diff --git a/CCDB/src/request.proto b/CCDB/src/request.proto deleted file mode 100644 index b1af60c0acf63..0000000000000 --- a/CCDB/src/request.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto2"; - -package messaging; - -option java_package = "com.cern.messaging"; -option java_outer_classname = "Request"; - -message RequestMessage { - required string command = 1; - optional string datasource = 2; - optional string key = 3; - optional bytes value = 4; -} diff --git a/CCDB/src/runConditionsClient.cxx b/CCDB/src/runConditionsClient.cxx deleted file mode 100644 index 5eef2f7cb64f8..0000000000000 --- a/CCDB/src/runConditionsClient.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "runFairMQDevice.h" - -#include "CCDB/ConditionsMQClient.h" - -using namespace o2::ccdb; -using namespace std; - -namespace bpo = boost::program_options; - -void addCustomOptions(bpo::options_description& options) -{ - options.add_options()("parameter-name", bpo::value()->default_value("DET/Calib/Histo"), "Parameter Name")( - "operation-type", bpo::value()->default_value("GET"), "Operation Type")( - "data-source", bpo::value()->default_value("OCDB"), "Data Source")( - "object-path", bpo::value()->default_value("OCDB"), "Object Path"); -} - -FairMQDevice* getDevice(const FairMQProgOptions& config) -{ - return new ConditionsMQClient(); -} diff --git a/CCDB/src/runConditionsServer.cxx b/CCDB/src/runConditionsServer.cxx deleted file mode 100644 index 91a8811859500..0000000000000 --- a/CCDB/src/runConditionsServer.cxx +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "runFairMQDevice.h" - -#include "CCDB/ConditionsMQServer.h" - -using namespace o2::ccdb; -using namespace std; - -namespace bpo = boost::program_options; - -void addCustomOptions(bpo::options_description& options) -{ - options.add_options()("first-input-name", bpo::value()->default_value("first_input.root"), - "First input file name")("first-input-type", bpo::value()->default_value("ROOT"), - "First input file type (ROOT/ASCII)")( - "second-input-name", bpo::value()->default_value(""), "Second input file name")( - "second-input-type", bpo::value()->default_value("ROOT"), "Second input file type (ROOT/ASCII)")( - "output-name", bpo::value()->default_value(""), "Output file name")( - "output-type", bpo::value()->default_value("ROOT"), "Output file type")( - "channel-name", bpo::value()->default_value("ROOT"), "Output channel name"); -} - -FairMQDevice* getDevice(const FairMQProgOptions& config) -{ - return new ConditionsMQServer(); -} diff --git a/CCDB/test/TestClass.h b/CCDB/test/TestClass.h deleted file mode 100644 index f71a87b81dd4e..0000000000000 --- a/CCDB/test/TestClass.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#ifndef O2_CCDB_TESTCLASS -#define O2_CCDB_TESTCLASS - -// a private test class to be stored inside the CCDB; just used in a unit test -// the header is not public -struct TestClass { - double mD = 1.; -}; - -#endif diff --git a/CCDB/test/testCcdbApi.cxx b/CCDB/test/testCcdbApi.cxx index 7d409b9562981..4db55fbc47c07 100644 --- a/CCDB/test/testCcdbApi.cxx +++ b/CCDB/test/testCcdbApi.cxx @@ -19,7 +19,7 @@ #include "CCDB/CcdbApi.h" #include "CCDB/IdPath.h" // just as test object -#include "CCDB/Condition.h" // just as test object +#include "CommonUtils/RootChain.h" // just as test object #include "CCDB/CCDBTimeStampUtils.h" #include #include @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(store_retrieve_TMemFile_templated_test, *utf::precondition( BOOST_CHECK(path2 && path2->getPathString().CompareTo("HelloWorld") == 0); // try to query with different type and verify that we get nullptr - BOOST_CHECK(f.api.retrieveFromTFileAny(basePath + "CCDBPath", f.metadata) == nullptr); + BOOST_CHECK(f.api.retrieveFromTFileAny(basePath + "CCDBPath", f.metadata) == nullptr); //----------------------------------------------------------------------------------------------- // test if writing/reading complicated objects like TTree works (because of particular ownership) diff --git a/CCDB/test/testQueryServerStandalone.cxx b/CCDB/test/testQueryServerStandalone.cxx deleted file mode 100644 index 40ba2b0a9400f..0000000000000 --- a/CCDB/test/testQueryServerStandalone.cxx +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "TestClass.h" - -using namespace std; - -void CustomCleanup(void* data, void* hint) { delete static_cast(hint); } -void queryConditionServer(string transport, string address) -{ - auto factory = FairMQTransportFactory::CreateTransportFactory(transport); - auto channel = FairMQChannel{"data-get", "req", factory}; - channel.Connect(address); - channel.ValidateChannel(); - - auto backend = new o2::ccdb::BackendOCDB(); - - std::string* messageString = new string(); - std::string operationType("GET"); - // FIXME: how to setup the key? - // just a test key -- corresponding to example from unit test testWriteReadAny.cxx - std::string key("TestParam/Test/Test/Run1_1_v1_s0"); - std::string source("OCDB"); - backend->Serialize(messageString, key, operationType, source); - - std::cerr << messageString->c_str() << "\n"; - unique_ptr request(factory->CreateMessage(const_cast(messageString->c_str()), - messageString->length(), CustomCleanup, messageString)); - - unique_ptr reply(factory->CreateMessage()); - - channel.Send(request); - if (channel.Receive(reply) > 0) { - LOG(DEBUG) << "Received a condition with a size of " << reply->GetSize(); - auto condition = backend->UnPack(std::move(reply)); - LOG(DEBUG) << "TYPE " << condition->getObject()->IsA()->GetName() << "\n"; - - // retrieve concrete type - TestClass* c = nullptr; - condition->getObjectAs(c); - if (c) { - LOG(DEBUG) << "RECEIVED parameter value is " << c->mD << "\n"; - } - } -} - -int main() -{ - // assuming that conditions-server is running and listening on port 25006 - // see conditions-server.json - queryConditionServer("zeromq", "tcp://localhost:25006"); -} diff --git a/CCDB/test/testWriteReadAny.cxx b/CCDB/test/testWriteReadAny.cxx deleted file mode 100644 index 9d6abae0c3dbb..0000000000000 --- a/CCDB/test/testWriteReadAny.cxx +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#define BOOST_TEST_MODULE Test CCDB TestReadWriteAny -#define BOOST_TEST_MAIN -#define BOOST_TEST_DYN_LINK - -#include -#include -#include "CCDB/Condition.h" -#include "CCDB/Manager.h" -#include "TestClass.h" // local header - -namespace o2 -{ -namespace ccdb -{ -/// \brief Test writing/reading arbitrary (non TObject) classes A to CCDB -// a dictionary for TObjectWrapper must exist (next to the one for A) -BOOST_AUTO_TEST_CASE(ReadWriteTest1) -{ - auto cdb = o2::ccdb::Manager::Instance(); - cdb->setDefaultStorage("local://O2CDB"); - - TestClass parameter; - const double TESTVALUE = 20.; - parameter.mD = TESTVALUE; - - int run = 1; - auto id = new o2::ccdb::ConditionId("TestParam/Test/Test", run, run, 1, 0); - auto md = new o2::ccdb::ConditionMetaData(); - cdb->putObjectAny(¶meter, *id, md); - - auto condread = cdb->getCondition("TestParam/Test/Test", run); - - TestClass* readbackparameter = nullptr; - condread->getObjectAs(readbackparameter); - BOOST_CHECK(readbackparameter); - BOOST_CHECK_CLOSE(readbackparameter->mD, TESTVALUE, 1E-6); -} -} // namespace ccdb -} // namespace o2 diff --git a/Detectors/TPC/base/include/TPCBase/CDBInterface.h b/Detectors/TPC/base/include/TPCBase/CDBInterface.h index 5b6659f4cad98..71cb3d436370c 100644 --- a/Detectors/TPC/base/include/TPCBase/CDBInterface.h +++ b/Detectors/TPC/base/include/TPCBase/CDBInterface.h @@ -17,7 +17,6 @@ #include -#include #include #include #include diff --git a/EventVisualisation/View/include/EventVisualisationView/EventManager.h b/EventVisualisation/View/include/EventVisualisationView/EventManager.h index 2b98a54707b08..a8a30c7da73e9 100644 --- a/EventVisualisation/View/include/EventVisualisationView/EventManager.h +++ b/EventVisualisation/View/include/EventVisualisationView/EventManager.h @@ -17,7 +17,8 @@ #ifndef ALICE_O2_EVENTVISUALISATION_BASE_EVENTMANAGER_H #define ALICE_O2_EVENTVISUALISATION_BASE_EVENTMANAGER_H -#include "CCDB/Manager.h" +#include "CCDB/BasicCCDBManager.h" +#include "CCDB/CcdbApi.h" #include #include @@ -58,7 +59,7 @@ class EventManager : public TEveEventManager, public TQObject /// Sets the CDB path in CCDB Manager inline void setCdbPath(const TString& path) { - o2::ccdb::Manager::Instance()->setDefaultStorage(path.Data()); + ccdbApi.init(path.Data()); } Int_t getCurrentEvent() { return currentEvent; } @@ -81,6 +82,7 @@ class EventManager : public TEveEventManager, public TQObject private: static EventManager* instance; + static o2::ccdb::CcdbApi ccdbApi; EDataSource mCurrentDataSourceType = EDataSource::SourceOffline; DataSource* dataSource = nullptr; TString dataPath = ""; diff --git a/EventVisualisation/View/src/EventManager.cxx b/EventVisualisation/View/src/EventManager.cxx index 007bcaabacb84..09d080676f7f2 100644 --- a/EventVisualisation/View/src/EventManager.cxx +++ b/EventVisualisation/View/src/EventManager.cxx @@ -41,7 +41,6 @@ EventManager* EventManager::instance = nullptr; EventManager& EventManager::getInstance() { - if (instance == nullptr) instance = new EventManager(); return *instance; } From aa2898898166ccdc1c1e244da36af783f67c31c5 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 24 Sep 2019 11:07:39 +0200 Subject: [PATCH 2/7] fix for event visualization --- .../View/include/EventVisualisationView/EventManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EventVisualisation/View/include/EventVisualisationView/EventManager.h b/EventVisualisation/View/include/EventVisualisationView/EventManager.h index a8a30c7da73e9..a25737abc7a29 100644 --- a/EventVisualisation/View/include/EventVisualisationView/EventManager.h +++ b/EventVisualisation/View/include/EventVisualisationView/EventManager.h @@ -82,7 +82,7 @@ class EventManager : public TEveEventManager, public TQObject private: static EventManager* instance; - static o2::ccdb::CcdbApi ccdbApi; + o2::ccdb::CcdbApi ccdbApi; EDataSource mCurrentDataSourceType = EDataSource::SourceOffline; DataSource* dataSource = nullptr; TString dataPath = ""; From 68824a709bfacfd8bdee4c1334583cf5682ce569 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 24 Sep 2019 12:23:14 +0200 Subject: [PATCH 3/7] Changes for TPC (TestTPCCDBInterface disabled) --- Detectors/TPC/base/CMakeLists.txt | 12 ++++---- .../TPC/base/include/TPCBase/CDBInterface.h | 9 +++--- Detectors/TPC/base/src/TPCBaseLinkDef.h | 4 --- .../TPC/base/test/testTPCCDBInterface.cxx | 30 +++++++++++-------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Detectors/TPC/base/CMakeLists.txt b/Detectors/TPC/base/CMakeLists.txt index f79f79eea4c8e..ad39718c2dd34 100644 --- a/Detectors/TPC/base/CMakeLists.txt +++ b/Detectors/TPC/base/CMakeLists.txt @@ -88,11 +88,11 @@ o2_add_test(Parameters SOURCES test/testTPCParameters.cxx LABELS tpc) -o2_add_test(CCDBInterface - COMPONENT_NAME tpc - PUBLIC_LINK_LIBRARIES O2::TPCBase - SOURCES test/testTPCCDBInterface.cxx - ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage - LABELS tpc) +#o2_add_test(CCDBInterface +# COMPONENT_NAME tpc +# PUBLIC_LINK_LIBRARIES O2::TPCBase +# SOURCES test/testTPCCDBInterface.cxx +# ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage +# LABELS tpc) o2_data_file(COPY files DESTINATION Detectors/TPC) diff --git a/Detectors/TPC/base/include/TPCBase/CDBInterface.h b/Detectors/TPC/base/include/TPCBase/CDBInterface.h index 71cb3d436370c..3bd85ad8ae84e 100644 --- a/Detectors/TPC/base/include/TPCBase/CDBInterface.h +++ b/Detectors/TPC/base/include/TPCBase/CDBInterface.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include namespace o2 @@ -159,13 +159,12 @@ class CDBInterface T& getObjectFromCDB(const o2::ccdb::IdPath& path); }; +// TODO consider removing this as it does not bring much template inline T& CDBInterface::getObjectFromCDB(const o2::ccdb::IdPath& path) { - static auto cdb = o2::ccdb::Manager::Instance(); - auto condread = cdb->getCondition(path); - T* object{nullptr}; - condread->getObjectAs(object); + static auto cdb = o2::ccdb::BasicCCDBManager::instance(); + auto* object = cdb.get(path.getPathString().Data()); return *object; } diff --git a/Detectors/TPC/base/src/TPCBaseLinkDef.h b/Detectors/TPC/base/src/TPCBaseLinkDef.h index ce147fd3d044c..467b3e84c5ba9 100644 --- a/Detectors/TPC/base/src/TPCBaseLinkDef.h +++ b/Detectors/TPC/base/src/TPCBaseLinkDef.h @@ -57,10 +57,6 @@ #pragma link C++ function o2::tpc::painter::draw(o2::tpc::CalDet ); #pragma link C++ function o2::tpc::painter::draw(o2::tpc::CalDet ); -// for CDB -#pragma link C++ class o2::TObjectWrapper < o2::tpc::CalArray < float>> + ; -#pragma link C++ class o2::TObjectWrapper < o2::tpc::CalDet < float>> + ; - #pragma link C++ class o2::tpc::ParameterDetector; #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::tpc::ParameterDetector> + ; #pragma link C++ class o2::tpc::ParameterElectronics; diff --git a/Detectors/TPC/base/test/testTPCCDBInterface.cxx b/Detectors/TPC/base/test/testTPCCDBInterface.cxx index ecde739fff223..419c74a336a4b 100644 --- a/Detectors/TPC/base/test/testTPCCDBInterface.cxx +++ b/Detectors/TPC/base/test/testTPCCDBInterface.cxx @@ -20,7 +20,6 @@ #include "TFile.h" // o2 includes -#include "CCDB/Manager.h" #include "TPCBase/CDBInterface.h" #include "TPCBase/CDBInterface.h" #include "TPCBase/CalArray.h" @@ -36,18 +35,20 @@ namespace o2 { namespace tpc { -template -void writeObject(T& obj, const std::string_view type, const std::string_view name, const int run) -{ - auto cdb = o2::ccdb::Manager::Instance(); +//template +//void writeObject(T& obj, const std::string_view type, const std::string_view name, const int run) +//{ +// auto cdb = o2::ccdb::Manager::Instance(); +// +// auto id = new o2::ccdb::ConditionId( +// "TPC/" + type + +// "/" + name, +// run, run, 1, 0); +// auto md = new o2::ccdb::ConditionMetaData(); +// cdb->putObjectAny(&obj, *id, md); +//} - auto id = new o2::ccdb::ConditionId( - "TPC/" + type + - "/" + name, - run, run, 1, 0); - auto md = new o2::ccdb::ConditionMetaData(); - cdb->putObjectAny(&obj, *id, md); -} +const std::string ccdbUrl = "file:///tmp/CCDBSnapshot"; /// \brief write a CalPad object to the CCDB CalPad writeCalPadObject(const std::string_view name, const int run, const int dataOffset = 0) @@ -63,6 +64,11 @@ CalPad writeCalPadObject(const std::string_view name, const int run, const int d } } + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init(ccdbUrl); + std::map metadata; + ccdbApi.storeAsTFileAny(data, "Calib", metadata); + writeObject(data, "Calib", name, run); return data; From e5480292a369fa80fe1d29f07ab9883cd9ffbd41 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 24 Sep 2019 12:30:29 +0200 Subject: [PATCH 4/7] format --- CCDB/test/testCcdbApi.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCDB/test/testCcdbApi.cxx b/CCDB/test/testCcdbApi.cxx index 4db55fbc47c07..bc57aa9eeff6e 100644 --- a/CCDB/test/testCcdbApi.cxx +++ b/CCDB/test/testCcdbApi.cxx @@ -19,7 +19,7 @@ #include "CCDB/CcdbApi.h" #include "CCDB/IdPath.h" // just as test object -#include "CommonUtils/RootChain.h" // just as test object +#include "CommonUtils/RootChain.h" // just as test object #include "CCDB/CCDBTimeStampUtils.h" #include #include From fc5a08f1a678b4ff62c92c8bcb02470c49e7ddac Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 24 Sep 2019 14:48:27 +0200 Subject: [PATCH 5/7] missing file --- cmake/O2RootMacroExclusionList.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/O2RootMacroExclusionList.cmake b/cmake/O2RootMacroExclusionList.cmake index 0ce258a109d1e..381c37989d371 100644 --- a/cmake/O2RootMacroExclusionList.cmake +++ b/cmake/O2RootMacroExclusionList.cmake @@ -17,7 +17,6 @@ include(O2GetListOfMacros) # list(APPEND O2_ROOT_MACRO_EXCLUSION_LIST - CCDB/example/fill_local_ocdb.C DataFormats/simulation/test/checkStack.C Detectors/ITSMFT/ITS/macros/EVE/rootlogon.C Detectors/ITSMFT/ITS/macros/test/rootlogon.C From bb9edab5b5404f632371226336a865f51d7ac187 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 1 Oct 2019 15:23:04 +0200 Subject: [PATCH 6/7] add doxygen and trigger new build --- Detectors/TPC/base/include/TPCBase/CDBInterface.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Detectors/TPC/base/include/TPCBase/CDBInterface.h b/Detectors/TPC/base/include/TPCBase/CDBInterface.h index 3bd85ad8ae84e..988de5ccc5b4b 100644 --- a/Detectors/TPC/base/include/TPCBase/CDBInterface.h +++ b/Detectors/TPC/base/include/TPCBase/CDBInterface.h @@ -159,7 +159,12 @@ class CDBInterface T& getObjectFromCDB(const o2::ccdb::IdPath& path); }; -// TODO consider removing this as it does not bring much + +/// Get an object from the CCDB. +/// @tparam T +/// @param path +/// @return The object from the CCDB, ownership is transferred to the caller. +/// @todo Consider removing in favour of calling directly the manager::get method. template inline T& CDBInterface::getObjectFromCDB(const o2::ccdb::IdPath& path) { From 66e31bbcbd3cd26ff3e52a4143c8a46cbe3710a1 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Tue, 1 Oct 2019 15:58:17 +0200 Subject: [PATCH 7/7] format --- Detectors/TPC/base/include/TPCBase/CDBInterface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Detectors/TPC/base/include/TPCBase/CDBInterface.h b/Detectors/TPC/base/include/TPCBase/CDBInterface.h index 988de5ccc5b4b..20cbc51e5c32a 100644 --- a/Detectors/TPC/base/include/TPCBase/CDBInterface.h +++ b/Detectors/TPC/base/include/TPCBase/CDBInterface.h @@ -159,7 +159,6 @@ class CDBInterface T& getObjectFromCDB(const o2::ccdb::IdPath& path); }; - /// Get an object from the CCDB. /// @tparam T /// @param path