Skip to content

Commit b4ddc75

Browse files
kouzinopoulosMohammadAlTurany
authored andcommitted
Plugin infrustructure for the CCDB client
1 parent b6df8cc commit b4ddc75

14 files changed

Lines changed: 393 additions & 264 deletions

CCDB/CMakeLists.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS src/request.proto)
66
include_directories(${CMAKE_BINARY_DIR}/CCDB)
77

88
set(SRCS
9-
src/Manager.cxx
9+
src/Backend.cxx
10+
src/BackendOCDB.cxx
11+
src/BackendRiak.cxx
1012
src/Condition.cxx
11-
src/GridStorage.cxx
12-
src/LocalStorage.cxx
13-
src/FileStorage.cxx
14-
src/ConditionMetaData.cxx
1513
src/ConditionId.cxx
14+
src/ConditionMetaData.cxx
15+
src/FileStorage.cxx
16+
src/GridStorage.cxx
1617
src/IdPath.cxx
1718
src/IdRunRange.cxx
19+
src/LocalStorage.cxx
20+
src/Manager.cxx
21+
src/ObjectHandler.cxx
1822
src/Storage.cxx
1923
src/XmlHandler.cxx
20-
src/ObjectHandler.cxx
2124
)
2225

2326
set(HEADERS
27+
include/${MODULE_NAME}/Backend.h
28+
include/${MODULE_NAME}/BackendOCDB.h
29+
include/${MODULE_NAME}/BackendRiak.h
2430
include/${MODULE_NAME}/Condition.h
2531
include/${MODULE_NAME}/ConditionId.h
2632
include/${MODULE_NAME}/ConditionMetaData.h
@@ -30,9 +36,9 @@ set(HEADERS
3036
include/${MODULE_NAME}/IdRunRange.h
3137
include/${MODULE_NAME}/LocalStorage.h
3238
include/${MODULE_NAME}/Manager.h
39+
include/${MODULE_NAME}/ObjectHandler.h
3340
include/${MODULE_NAME}/Storage.h
3441
include/${MODULE_NAME}/XmlHandler.h
35-
include/${MODULE_NAME}/ObjectHandler.h
3642
)
3743

3844
Set(NO_DICT_SRCS

CCDB/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ conditions-server --id parmq-server --mq-config <installation directory>/bin/con
2323
* In a separate shell run the client example:
2424

2525
```bash
26-
conditions-client --id parmq-client --mq-config <installation directory>/bin/config/conditions-client.json --data-source OCDB
26+
conditions-client --id parmq-client --mq-config <installation directory>/bin/config/conditions-client.json --data-source OCDB --object-path <installation directory>/bin/config/O2CDB
2727
```
2828

2929
### Riak backend

CCDB/include/CCDB/Backend.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// \file Backend.h
2+
/// \brief Definition of the Backend class
3+
/// \author Charis Kouzinopoulos <charalampos.kouzinopoulos@cern.ch>
4+
5+
#ifndef ALICE_O2_BACKEND_H_
6+
#define ALICE_O2_BACKEND_H_
7+
8+
#include <string>
9+
#include <vector>
10+
11+
#include "FairMQDevice.h"
12+
13+
// Google protocol buffers headers
14+
#include <google/protobuf/stubs/common.h>
15+
#include "request.pb.h"
16+
17+
using namespace std;
18+
19+
namespace AliceO2 {
20+
namespace CDB {
21+
22+
class Backend {
23+
public:
24+
virtual ~Backend(){};
25+
26+
/// Pack
27+
virtual void Pack(const std::string& path, const std::string& key, std::string*& messageString) = 0;
28+
29+
/// UnPack
30+
virtual void UnPack(std::unique_ptr<FairMQMessage> msg) = 0;
31+
32+
/// Serializes a key (and optionally value) to an std::string using Protocol Buffers
33+
void Serialize(std::string*& messageString, const std::string& key, const std::string& operationType,
34+
const std::string& dataSource, const std::string& object = std::string());
35+
};
36+
}
37+
}
38+
#endif

CCDB/include/CCDB/BackendOCDB.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// \file BackendOCDB.h
2+
/// \brief Definition of the BackendOCDB class
3+
/// \author Charis Kouzinopoulos <charalampos.kouzinopoulos@cern.ch>
4+
5+
#ifndef ALICE_O2_BACKENDOCDB_H_
6+
#define ALICE_O2_BACKENDOCDB_H_
7+
8+
#include "CCDB/Backend.h"
9+
10+
#include <iostream>
11+
#include <memory>
12+
13+
using namespace std;
14+
15+
namespace AliceO2 {
16+
namespace CDB {
17+
18+
class BackendOCDB : public Backend {
19+
20+
private:
21+
public:
22+
BackendOCDB();
23+
virtual ~BackendOCDB(){};
24+
25+
/// Prepares an object before transmission to CCDB server
26+
void Pack(const std::string& path, const std::string& key, std::string*& messageString);
27+
28+
/// Parses an incoming message from the CCDB server and prints the metadata of the included object
29+
void UnPack(std::unique_ptr<FairMQMessage> msg);
30+
};
31+
}
32+
}
33+
#endif

CCDB/include/CCDB/BackendRiak.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// \file BackendRiak.h
2+
/// \brief Definition of the BackendRiak class
3+
/// \author Charis Kouzinopoulos <charalampos.kouzinopoulos@cern.ch>
4+
5+
#ifndef ALICE_O2_BACKENDRIAK_H_
6+
#define ALICE_O2_BACKENDRIAK_H_
7+
8+
#include "CCDB/Backend.h"
9+
10+
using namespace std;
11+
12+
namespace AliceO2 {
13+
namespace CDB {
14+
15+
class BackendRiak : public Backend {
16+
17+
private:
18+
/// Deserializes a message and stores the value to an std::string using Protocol Buffers
19+
void Deserialize(const std::string& messageString, std::string& object);
20+
21+
/// Compresses uncompressed_string to compressed_string using zlib
22+
void Compress(const std::string& uncompressed_string, std::string& compressed_string);
23+
24+
/// Decompresses compressed_string to uncompressed_string using zlib
25+
void Decompress(std::string& uncompressed_string, const std::string& compressed_string);
26+
27+
public:
28+
BackendRiak();
29+
virtual ~BackendRiak(){};
30+
31+
/// Compresses and serializes an object prior to transmission to server
32+
void Pack(const std::string& path, const std::string& key, std::string*& messageString);
33+
34+
/// Deserializes and uncompresses an incoming message from the CCDB server
35+
void UnPack(std::unique_ptr<FairMQMessage> msg);
36+
};
37+
}
38+
}
39+
#endif

CCDB/include/CCDB/ConditionsMQClient.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ class ConditionsMQClient : public FairMQDevice {
4545
std::string fDataSource;
4646
std::string fObjectPath;
4747

48-
/// Serializes a key (and optionally value) to an std::string using Protocol Buffers
49-
void Serialize(std::string*& messageString, const std::string& key, const std::string& object = std::string());
50-
51-
/// Deserializes a message and stores the value to an std::string using Protocol Buffers
52-
void Deserialize(const std::string& messageString, std::string& object);
53-
54-
/// Run loop when an OCDB backend is chosen
55-
void RunOCDB();
56-
57-
/// Run loop when a Riak backend is chosen
58-
void RunRiak();
5948
};
6049
}
6150
}

CCDB/include/CCDB/ConditionsMQServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class ConditionsMQServer : public ParameterMQServer {
3636
private:
3737
Manager* fCdbManager;
3838

39-
void getFromOCDB(std::string key, int runId);
39+
void getFromOCDB(std::string key);
4040

4141
/// Parses a serialized message for a data source entry
4242
void ParseDataSource(std::string& dataSource, const std::string& data);
4343

44-
/// Parses a serialized message for a key entry
45-
void ParseKey(std::string& key, int& runId, const std::string& data);
44+
/// Deserializes a message and stores the value to an std::string using Protocol Buffers
45+
void Deserialize(const std::string& messageString, std::string& key);
4646
};
4747
}
4848
}

CCDB/include/CCDB/ObjectHandler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class ObjectHandler {
1717
/// Returns the binary payload of a ROOT file as an std::string
1818
void GetObject(const std::string& path, std::string& object);
1919

20-
/// Compresses uncompressed_string in to compressed_string using zlib
21-
void Compress(const std::string& uncompressed_string, std::string& compressed_string);
22-
void Decompress(std::string& uncompressed_string, const std::string& compressed_string);
2320
};
2421
}
2522
}

CCDB/src/Backend.cxx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// \file Backend.cxx
2+
/// \brief Implementation of the Backend class
3+
/// \author Charis Kouzinopoulos <charalampos.kouzinopoulos@cern.ch>
4+
5+
#include "CCDB/Backend.h"
6+
7+
using namespace AliceO2::CDB;
8+
using namespace std;
9+
10+
void Backend::Serialize(std::string*& messageString, const std::string& key, const std::string& operationType,
11+
const std::string& dataSource, const std::string& object /*= std::vector<char>()*/)
12+
{
13+
messaging::RequestMessage* requestMessage = new messaging::RequestMessage;
14+
requestMessage->set_command(operationType);
15+
requestMessage->set_datasource(dataSource);
16+
requestMessage->set_key(key);
17+
18+
if (object.length() > 0) {
19+
requestMessage->set_value(object);
20+
}
21+
22+
requestMessage->SerializeToString(messageString);
23+
24+
delete requestMessage;
25+
}

CCDB/src/BackendOCDB.cxx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/// \file BackendOCDB.cxx
2+
/// \brief Implementation of the BackendOCDB class
3+
/// \author Charis Kouzinopoulos <charalampos.kouzinopoulos@cern.ch>
4+
5+
#include "CCDB/BackendOCDB.h"
6+
#include "CCDB/Condition.h"
7+
#include "CCDB/ObjectHandler.h"
8+
9+
#include "TBufferFile.h"
10+
#include "TFile.h"
11+
#include "TMessage.h"
12+
#include "Rtypes.h"
13+
14+
#include <zlib.h>
15+
16+
#include "FairMQLogger.h"
17+
18+
using namespace AliceO2::CDB;
19+
using namespace std;
20+
21+
// special class to expose protected TMessage constructor
22+
class WrapTMessage : public TMessage {
23+
public:
24+
WrapTMessage(void* buf, Int_t len) : TMessage(buf, len) { ResetBit(kIsOwner); }
25+
};
26+
27+
BackendOCDB::BackendOCDB() {}
28+
29+
void BackendOCDB::Pack(const std::string& path, const std::string& key, std::string*& messageString)
30+
{
31+
LOG(ERROR) << "The PUT operation is not supported for the OCDB backend yet";
32+
}
33+
34+
void BackendOCDB::UnPack(std::unique_ptr<FairMQMessage> msg)
35+
{
36+
WrapTMessage tmsg(msg->GetData(), msg->GetSize());
37+
Condition* aCondition = (Condition*)(tmsg.ReadObject(tmsg.GetClass()));
38+
LOG(DEBUG) << "Received a condition from the server:";
39+
aCondition->printConditionMetaData();
40+
}

0 commit comments

Comments
 (0)