Skip to content

Commit 41431f7

Browse files
authored
[WIP] CCDB api import from QC (O2-347) (#1321)
* CCDB api import from QC (O2-347) * formatting * copyright and some other warnings fixes
1 parent e2f7af7 commit 41431f7

6 files changed

Lines changed: 784 additions & 1 deletion

File tree

CCDB/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(SRCS
2121
src/ObjectHandler.cxx
2222
src/Storage.cxx
2323
src/XmlHandler.cxx
24+
src/CcdbApi.cxx
2425
)
2526

2627
set(HEADERS
@@ -91,7 +92,8 @@ install(
9192

9293
set(TEST_SRCS
9394
test/testWriteReadAny.cxx
94-
)
95+
test/testCcdbApi.cxx
96+
)
9597

9698
O2_GENERATE_TESTS(
9799
BUCKET_NAME ${BUCKET_NAME}

CCDB/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## CCDB API
2+
3+
The CCDB API class (`CcdbApi`) is implemented using libcurl and gives
4+
access to the CCDB via its REST api.
5+
6+
Usage :
7+
```
8+
// init
9+
CcdbApi api;
10+
map<string, string> metadata; // can be empty
11+
api.init("http://ccdb-test.cern.ch:8080");
12+
// store
13+
auto h1 = new TH1F("object1", "object1", 100, 0, 99);
14+
api.store(h1, "Test/Detector", metadata);
15+
// retrieve
16+
auto h1back = api.retrieve("Test/Detector", metadata);
17+
18+
```
19+
120
## Conditions MQ
221

322
Conditions MQ is a client/server CCDB implementation for O2. Currently the implementation supports two backends, an OCDB and a Riak one.

CCDB/include/CCDB/CcdbApi.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
///
12+
/// \file CcdbApi.h
13+
/// \author Barthelemy von Haller
14+
///
15+
16+
#ifndef PROJECT_CCDBAPI_H
17+
#define PROJECT_CCDBAPI_H
18+
19+
#include <string>
20+
#include <memory>
21+
#include <iostream>
22+
#include <map>
23+
#include <curl/curl.h>
24+
#include <TObject.h>
25+
26+
namespace o2
27+
{
28+
namespace ccdb
29+
{
30+
31+
/**
32+
* Interface to the CCDB.
33+
* It uses Curl to talk to the REST api.
34+
*
35+
* @todo use smart pointers ?
36+
* @todo handle errors and exceptions
37+
* @todo extend code coverage
38+
*/
39+
class CcdbApi //: public DatabaseInterface
40+
{
41+
public:
42+
/// \brief Default constructor
43+
CcdbApi();
44+
/// \brief Default destructor
45+
virtual ~CcdbApi();
46+
47+
/**
48+
* Initialize connection to CCDB
49+
*
50+
* @param host The URL to the CCDB (e.g. "ccdb-test.cern.ch:8080")
51+
*/
52+
void init(std::string host);
53+
54+
/**
55+
* Stores an object in the CCDB
56+
*
57+
* @param rootObject Shared pointer to the object to store.
58+
* @param path The path where the object is going to be stored.
59+
* @param metadata Key-values representing the metadata for this object.
60+
* @param startValidityTimestamp Start of validity. If omitted, current timestamp is used.
61+
* @param endValidityTimestamp End of validity. If omitted, current timestamp + 1 year is used.
62+
*/
63+
void store(TObject* rootObject, std::string path, std::map<std::string, std::string> metadata,
64+
long startValidityTimestamp = -1, long endValidityTimestamp = -1);
65+
66+
/**
67+
* Retrieve object at the given path for the given timestamp.
68+
*
69+
* @param path The path where the object is to be found.
70+
* @param metadata Key-values representing the metadata to filter out objects.
71+
* @param timestamp Timestamp of the object to retrieve. If omitted, current timestamp is used.
72+
* @return the object, or nullptr if none were found.
73+
*/
74+
TObject* retrieve(std::string path, std::map<std::string, std::string> metadata,
75+
long timestamp = -1);
76+
77+
// std::vector<std::string> getListOfTasksWithPublications();
78+
// std::vector<std::string> getPublishedObjectNames(std::string taskName);
79+
80+
/**
81+
* Delete all versions of the object at this path.
82+
*
83+
* @todo Raise an exception if no such object exist.
84+
* @param path
85+
*/
86+
void truncate(std::string path);
87+
88+
/**
89+
* Delete the matching version of this object.
90+
*
91+
* @todo Raise an exception if no such object exist.
92+
* @param path Path to the object to delete
93+
* @param timestamp Timestamp of the object to delete.
94+
*/
95+
void deleteObject(std::string path, long timestamp = -1);
96+
97+
/**
98+
* Return the listing of objects, and in some cases subfolders, matching this path.
99+
* The path can contain sql patterns (correctly encoded) or regexps.
100+
*
101+
* In the case where there is no pattern, the list of subfolders is returned along with all the objects at
102+
* this path. It does not work recursively and objects from the subfolders are not returned.
103+
*
104+
* In the case where there is a pattern, subfolders are not returned and any object matching the pattern will
105+
* be returned, including those in subfolders if they match.
106+
*
107+
* Example : Task/Detector will return objects and subfolders in /Task/Detector but not the object(s) in
108+
* /Task/Detector/Sub.
109+
* Example : Task/Detector/.* will return any object below Detector recursively.
110+
* Example : Te*e* will return any object matching this pattern, including Test/detector and TestSecond/A/B.
111+
*
112+
* @todo accept should use an enum class.
113+
* @param path The path to the folder we want to list the children of (default : top dir).
114+
* @param latestOnly In case there are several versions of the same object, list only the latest one.
115+
* @param returnFormat The format of the returned string -> one of "text/plain (default)", "application/json", "text/xml"
116+
* @return The listing of folder and/or objects in the format requested
117+
*/
118+
std::string list(std::string path = "", bool latestOnly = false, std::string returnFormat = "text/plain");
119+
120+
private:
121+
/**
122+
* Get the current timestamp.
123+
*
124+
* @return the current timestamp as a long
125+
*/
126+
long getCurrentTimestamp();
127+
/**
128+
* Transform and return a string representation of the given timestamp.
129+
*
130+
* @param timestamp
131+
* @return a string representation of the given timestamp.
132+
*/
133+
std::string getTimestampString(long timestamp);
134+
/**
135+
* Compute and return a timestamp X seconds in the future.
136+
*
137+
* @param secondsInFuture The number of seconds in the future.
138+
* @return the future timestamp
139+
*/
140+
long getFutureTimestamp(int secondsInFuture);
141+
142+
/**
143+
* Build the full url to store an object.
144+
*
145+
* @param path The path where the object is going to be stored.
146+
* @param metadata Key-values representing the metadata for this object.
147+
* @param startValidityTimestamp Start of validity. If omitted or negative, the current timestamp is used.
148+
* @param endValidityTimestamp End of validity. If omitted or negative, current timestamp + 1 year is used.
149+
* @return The full url to store an object (url / startValidity / endValidity / [metadata &]* )
150+
*/
151+
std::string getFullUrlForStorage(const std::string& path, const std::map<std::string, std::string>& metadata,
152+
long startValidityTimestamp = -1, long endValidityTimestamp = -1);
153+
154+
/**
155+
* Build the full url to store an object.
156+
* @param path The path where the object is going to be found.
157+
* @param metadata Key-values representing the metadata for this object.
158+
* @param timestamp When the object we retrieve must be valid. If omitted or negative, the current timestamp is used.
159+
* @return The full url to store an object (url / startValidity / endValidity / [metadata &]* )
160+
*/
161+
std::string getFullUrlForRetrieval(const std::string& path, const std::map<std::string, std::string>& metadata,
162+
long timestamp = -1);
163+
164+
/**
165+
* Initialization of CURL
166+
*/
167+
void curlInit();
168+
169+
/// Base URL of the CCDB (with port)
170+
std::string mUrl;
171+
};
172+
} // namespace ccdb
173+
} // namespace o2
174+
175+
#endif //PROJECT_CCDBAPI_H

0 commit comments

Comments
 (0)