Skip to content

Commit 01ca0f2

Browse files
authored
Adapt get ccdb object names (#377)
* Adapt the code to get objects from the CCDB to the new format returned by it * QC-322 remove excessive output * QC-323
1 parent 2d565d0 commit 01ca0f2

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

Framework/src/CcdbDatabase.cxx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <unordered_set>
3434

3535
#include <boost/algorithm/string.hpp>
36+
#include <boost/property_tree/json_parser.hpp>
37+
#include <boost/property_tree/ptree.hpp>
38+
#include <boost/foreach.hpp>
3639

3740
using namespace std::chrono;
3841
using namespace AliceO2::Common;
@@ -184,6 +187,9 @@ std::shared_ptr<core::MonitorObject> CcdbDatabase::retrieveMO(std::string taskNa
184187
map<string, string> metadata;
185188
TObject* obj = retrieveTObject(path, metadata, when, &headers);
186189
Version objectVersion(headers["qc_version"]); // retrieve headers to determine the version of the QC framework
190+
// ILOG(Debug) << "Version of object is " << objectVersion << ENDM;
191+
// ILOG(Debug) << "objectVersion == Version(\"0.0.0\") : " << (objectVersion == Version("0.0.0")) << ENDM;
192+
// ILOG(Debug) << "objectVersion < Version(\"0.25\") : " << (objectVersion < Version("0.25")) << ENDM
187193

188194
std::shared_ptr<MonitorObject> mo;
189195
if (objectVersion == Version("0.0.0") || objectVersion < Version("0.25")) {
@@ -315,21 +321,18 @@ std::vector<std::string> CcdbDatabase::getListing(std::string subpath)
315321
std::vector<std::string> CcdbDatabase::getPublishedObjectNames(std::string taskName)
316322
{
317323
std::vector<string> result;
318-
319324
string listing = ccdbApi.list(taskName + "/.*", true, "Application/JSON");
320325

321-
// Split the string we received, by line. Also trim it and remove empty lines. Select the lines starting with "path".
322-
std::stringstream ss(listing);
323-
std::string line;
324-
std::string taskNameEscaped = boost::replace_all_copy(taskName, "/", "\\/");
325-
while (std::getline(ss, line, '\n')) {
326-
ltrim(line);
327-
rtrim(line);
328-
if (line.length() > 0 && line.find("\"path\"") == 0) {
329-
unsigned long objNameStart = 9 + taskNameEscaped.length();
330-
string path = line.substr(objNameStart, line.length() - 2 /*final 2 char*/ - objNameStart);
331-
result.push_back(path);
332-
}
326+
boost::property_tree::ptree pt;
327+
stringstream ss;
328+
ss << listing;
329+
boost::property_tree::read_json(ss, pt);
330+
331+
BOOST_FOREACH (boost::property_tree::ptree::value_type& v, pt.get_child("objects")) {
332+
assert(v.first.empty()); // array elements have no names
333+
string data = v.second.get_child("path").data();
334+
string path = data.substr(taskName.size());
335+
result.push_back(path);
333336
}
334337

335338
return result;

Framework/test/testDbFactory.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
///
1515

1616
#include "QualityControl/DatabaseFactory.h"
17+
#include "QualityControl/QcInfoLogger.h"
1718

1819
#ifdef _WITH_MYSQL
19-
2020
#include "QualityControl/MySqlDatabase.h"
21-
2221
#endif
22+
2323
#define BOOST_TEST_MODULE DbFactory test
2424
#define BOOST_TEST_MAIN
2525
#define BOOST_TEST_DYN_LINK
@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(db_ccdb_listing)
9999
// }
100100
BOOST_CHECK(std::find(objectNames.begin(), objectNames.end(), "/object1") != objectNames.end());
101101
BOOST_CHECK(std::find(objectNames.begin(), objectNames.end(), "/object2") != objectNames.end());
102-
BOOST_CHECK(std::find(objectNames.begin(), objectNames.end(), "/path\\/to\\/object3") != objectNames.end());
102+
BOOST_CHECK(std::find(objectNames.begin(), objectNames.end(), "/path/to/object3") != objectNames.end());
103103

104104
// store list of streamer infos
105105
// ccdb->storeStreamerInfosToFile("streamerinfos.root");

0 commit comments

Comments
 (0)