Skip to content

Commit d758a79

Browse files
authored
[QC-491] PP Task to transform Quality Objects into TRFCollections (#623)
* Allow to retrieve all timestamps of a QC object in CCDB * default value for metadata in Qualities * [QC-491] PP Task to transform Quality Objects into TRFCollections
1 parent 33314dc commit d758a79

15 files changed

Lines changed: 568 additions & 106 deletions

Framework/include/QualityControl/CcdbDatabase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class CcdbDatabase : public DatabaseInterface
8686
*/
8787
std::vector<std::string> getListing(std::string subpath = "");
8888

89+
/**
90+
* \brief Returns a vector of all 'valid from' timestamps for an object.
91+
* \path Path on an object.
92+
* \return A vector of all 'valid from' timestamps for an object in non-descending order.
93+
*/
94+
std::vector<uint64_t> getTimestampsForObject(std::string path);
95+
8996
private:
9097
/**
9198
* \brief Load StreamerInfos from a ROOT file.

Framework/include/QualityControl/Quality.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ class Quality
8989
const std::map<std::string, std::string>& getMetadataMap() const;
9090
/// \brief Overwrite the existing metadata.
9191
void overwriteMetadata(std::map<std::string, std::string> pairs);
92-
/// \brief Get a metadata
92+
/// \brief Get metadata
9393
/// \return the value corresponding to the key if it was found.
9494
/// \throw ObjectNotFoundError in case the key is not found.
95-
const std::string getMetadata(std::string key);
95+
std::string getMetadata(std::string key);
96+
/// \brief Get metadata
97+
/// \return the value corresponding to the key if it was found, default value otherwise
98+
std::string getMetadata(std::string key, std::string defaultValue);
9699

97100
private:
98101
unsigned int mLevel; /// 0 is no quality, 1 is best quality, then it only goes downhill...

Framework/include/QualityControl/QualityObject.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ class QualityObject : public TObject
9898
/// \brief Get a metadata
9999
/// \return the value corresponding to the key if it was found.
100100
/// \throw ObjectNotFoundError in case the key is not found.
101-
const std::string getMetadata(std::string key);
101+
std::string getMetadata(std::string key);
102+
/// \brief Get a metadata
103+
/// \return the value corresponding to the key if it was found, default value otherwise
104+
std::string getMetadata(std::string key, std::string defaultValue);
102105

103106
/// \brief Build the path to this object.
104107
/// Build the path to this object as it will appear in the GUI.

Framework/src/CcdbDatabase.cxx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,29 @@ std::vector<std::string> CcdbDatabase::getListing(std::string subpath)
361361
return result;
362362
}
363363

364+
std::vector<uint64_t> CcdbDatabase::getTimestampsForObject(std::string path)
365+
{
366+
std::stringstream listingAsStringStream{ getListingAsString(path, "application/json") };
367+
// std::cout << "listingAsString: " << listingAsStringStream.str() << std::endl;
368+
369+
boost::property_tree::ptree listingAsTree;
370+
boost::property_tree::read_json(listingAsStringStream, listingAsTree);
371+
372+
std::vector<uint64_t> timestamps;
373+
const auto& objects = listingAsTree.get_child("objects");
374+
timestamps.reserve(objects.size());
375+
376+
// As for today, we receive objects in the order of the newest to the oldest.
377+
// We prefer the other order here.
378+
for (auto rit = objects.rbegin(); rit != objects.rend(); ++rit) {
379+
timestamps.emplace_back(rit->second.get<uint64_t>("Valid-From"));
380+
}
381+
382+
// we make sure it is sorted. If it is already, it shouldn't cost much.
383+
std::sort(timestamps.begin(), timestamps.end());
384+
return timestamps;
385+
}
386+
364387
std::vector<std::string> CcdbDatabase::getPublishedObjectNames(std::string taskName)
365388
{
366389
std::vector<string> result;

Framework/src/Quality.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
#include <iostream>
1919
#include <Common/Exceptions.h>
2020

21-
ClassImp(o2::quality_control::core::Quality)
21+
ClassImp(o2::quality_control::core::Quality) //
2222

23-
// clang-format off
24-
namespace o2::quality_control::core
23+
namespace o2::quality_control::core
2524
{
26-
// clang-format on
2725

2826
// could be changed if needed but I don't see why we would need more than 10 levels
2927
const unsigned int Quality::NullLevel = 10;
@@ -75,7 +73,7 @@ namespace o2::quality_control::core
7573
addMetadata(pairs);
7674
}
7775

78-
const std::string Quality::getMetadata(std::string key)
76+
std::string Quality::getMetadata(std::string key)
7977
{
8078
if (mUserMetadata.count(key) == 0) {
8179
std::cerr << "Could not get the metadata with key \"" << key << "\"" << std::endl;
@@ -84,4 +82,9 @@ namespace o2::quality_control::core
8482
return mUserMetadata.at(key);
8583
}
8684

85+
std::string Quality::getMetadata(std::string key, std::string defaultValue)
86+
{
87+
return mUserMetadata.count(key) > 0 ? mUserMetadata.at(key) : defaultValue;
88+
}
89+
8790
} // namespace o2::quality_control::core

Framework/src/QualityObject.cxx

Lines changed: 100 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -37,118 +37,123 @@ QualityObject::QualityObject(
3737
mQuality.overwriteMetadata(metadata);
3838
}
3939

40-
QualityObject::~QualityObject() = default;
40+
QualityObject::~QualityObject() = default;
4141

42-
const std::string anonChecker = "anonymousChecker";
43-
QualityObject::QualityObject()
44-
: QualityObject(Quality(), anonChecker)
45-
{
46-
}
42+
const std::string anonChecker = "anonymousChecker";
43+
QualityObject::QualityObject()
44+
: QualityObject(Quality(), anonChecker)
45+
{
46+
}
4747

48-
const char* QualityObject::GetName() const
49-
{
50-
std::string name = getName();
51-
return strdup(name.c_str());
52-
}
48+
const char* QualityObject::GetName() const
49+
{
50+
std::string name = getName();
51+
return strdup(name.c_str());
52+
}
5353

54-
std::string QualityObject::getName() const
55-
{
56-
if (mPolicyName == "OnEachSeparately") {
57-
if (mMonitorObjectsNames.size() != 1) {
58-
BOOST_THROW_EXCEPTION(FatalException() << errinfo_details("QualityObject::getName: "
59-
"The vector of monitorObjectsNames must contain a single object"));
60-
}
61-
return mCheckName + "/" + mMonitorObjectsNames[0];
54+
std::string QualityObject::getName() const
55+
{
56+
if (mPolicyName == "OnEachSeparately") {
57+
if (mMonitorObjectsNames.size() != 1) {
58+
BOOST_THROW_EXCEPTION(FatalException() << errinfo_details("QualityObject::getName: "
59+
"The vector of monitorObjectsNames must contain a single object"));
6260
}
63-
return mCheckName;
61+
return mCheckName + "/" + mMonitorObjectsNames[0];
6462
}
63+
return mCheckName;
64+
}
6565

66-
void QualityObject::updateQuality(Quality quality)
67-
{
68-
//TODO: Update timestamp
69-
mQuality = quality;
70-
}
71-
Quality QualityObject::getQuality() const
72-
{
73-
return mQuality;
74-
}
66+
void QualityObject::updateQuality(Quality quality)
67+
{
68+
//TODO: Update timestamp
69+
mQuality = quality;
70+
}
71+
Quality QualityObject::getQuality() const
72+
{
73+
return mQuality;
74+
}
7575

76-
void QualityObject::addMetadata(std::string key, std::string value)
77-
{
78-
mQuality.addMetadata(key, value);
79-
}
76+
void QualityObject::addMetadata(std::string key, std::string value)
77+
{
78+
mQuality.addMetadata(key, value);
79+
}
8080

81-
void QualityObject::addMetadata(std::map<std::string, std::string> pairs)
82-
{
83-
mQuality.addMetadata(pairs);
84-
}
81+
void QualityObject::addMetadata(std::map<std::string, std::string> pairs)
82+
{
83+
mQuality.addMetadata(pairs);
84+
}
8585

86-
const std::map<std::string, std::string>& QualityObject::getMetadataMap() const
87-
{
88-
return mQuality.getMetadataMap();
89-
}
86+
const std::map<std::string, std::string>& QualityObject::getMetadataMap() const
87+
{
88+
return mQuality.getMetadataMap();
89+
}
9090

91-
void QualityObject::updateMetadata(std::string key, std::string value)
92-
{
93-
mQuality.updateMetadata(key, value);
94-
}
91+
void QualityObject::updateMetadata(std::string key, std::string value)
92+
{
93+
mQuality.updateMetadata(key, value);
94+
}
9595

96-
const std::string QualityObject::getMetadata(std::string key)
97-
{
98-
return mQuality.getMetadata(key);
99-
}
96+
std::string QualityObject::getMetadata(std::string key)
97+
{
98+
return mQuality.getMetadata(key);
99+
}
100100

101-
std::string QualityObject::getPath() const
102-
{
103-
std::string path;
104-
try {
105-
path = RepoPathUtils::getQoPath(this);
106-
} catch (FatalException& fe) {
107-
fe << errinfo_details("Only one MO should be assigned to one QO With the policy OnEachSeparatety"); // update error info
108-
throw;
109-
}
110-
return path;
111-
}
101+
std::string QualityObject::getMetadata(std::string key, std::string defaultValue)
102+
{
103+
return mQuality.getMetadata(key, defaultValue);
104+
}
112105

113-
const std::string& QualityObject::getDetectorName() const
114-
{
115-
return mDetectorName;
116-
}
106+
std::string QualityObject::getPath() const
107+
{
108+
std::string path;
109+
try {
110+
path = RepoPathUtils::getQoPath(this);
111+
} catch (FatalException& fe) {
112+
fe << errinfo_details("Only one MO should be assigned to one QO With the policy OnEachSeparatety"); // update error info
113+
throw;
114+
}
115+
return path;
116+
}
117117

118-
void QualityObject::setDetectorName(const std::string& detectorName)
119-
{
120-
QualityObject::mDetectorName = detectorName;
121-
}
118+
const std::string& QualityObject::getDetectorName() const
119+
{
120+
return mDetectorName;
121+
}
122122

123-
void QualityObject::setQuality(const Quality& quality)
124-
{
125-
updateQuality(quality);
126-
}
127-
const std::string& QualityObject::getCheckName() const
128-
{
129-
return mCheckName;
130-
}
123+
void QualityObject::setDetectorName(const std::string& detectorName)
124+
{
125+
QualityObject::mDetectorName = detectorName;
126+
}
131127

132-
const std::string& QualityObject::getPolicyName() const
133-
{
134-
return mPolicyName;
135-
}
128+
void QualityObject::setQuality(const Quality& quality)
129+
{
130+
updateQuality(quality);
131+
}
132+
const std::string& QualityObject::getCheckName() const
133+
{
134+
return mCheckName;
135+
}
136136

137-
const std::vector<std::string> QualityObject::getMonitorObjectsNames() const
138-
{
139-
return mMonitorObjectsNames;
140-
}
137+
const std::string& QualityObject::getPolicyName() const
138+
{
139+
return mPolicyName;
140+
}
141141

142-
std::ostream& operator<<(std::ostream& out, const QualityObject& q) // output
143-
{
144-
out << "QualityObject: " << q.getName() << ":\n"
145-
<< " - checkName : " << q.getCheckName() << "\n"
146-
<< " - detectorName : " << q.getDetectorName() << "\n"
147-
<< " - monitorObjectsNames : ";
148-
for (auto item : q.getMonitorObjectsNames()) {
149-
out << item << ", ";
150-
}
151-
return out;
152-
}
142+
const std::vector<std::string> QualityObject::getMonitorObjectsNames() const
143+
{
144+
return mMonitorObjectsNames;
145+
}
146+
147+
std::ostream& operator<<(std::ostream& out, const QualityObject& q) // output
148+
{
149+
out << "QualityObject: " << q.getName() << ":\n"
150+
<< " - checkName : " << q.getCheckName() << "\n"
151+
<< " - detectorName : " << q.getDetectorName() << "\n"
152+
<< " - monitorObjectsNames : ";
153+
for (auto item : q.getMonitorObjectsNames()) {
154+
out << item << ", ";
155+
}
156+
return out;
157+
}
153158

154159
} // namespace o2::quality_control::core

Modules/Common/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ configure_file("include/Common/Version.h.in"
1010
add_library(O2QcCommon)
1111

1212
target_sources(O2QcCommon
13-
PRIVATE src/NonEmpty.cxx
13+
PRIVATE src/TRFCollectionTask.cxx
14+
src/TRFCollectionTaskConfig.cxx
15+
src/NonEmpty.cxx
1416
src/MeanIsAbove.cxx
1517
src/TH1Reductor.cxx
1618
src/TH2Reductor.cxx
@@ -24,7 +26,7 @@ target_include_directories(
2426
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2527
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
2628

27-
target_link_libraries(O2QcCommon PUBLIC O2QualityControl PRIVATE ROOT::Graf)
29+
target_link_libraries(O2QcCommon PUBLIC O2QualityControl O2::DataFormatsQualityControl PRIVATE ROOT::Graf)
2830

2931
install(TARGETS O2QcCommon
3032
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -33,6 +35,7 @@ install(TARGETS O2QcCommon
3335

3436
add_root_dictionary(O2QcCommon
3537
HEADERS include/Common/NonEmpty.h
38+
include/Common/TRFCollectionTask.h
3639
include/Common/MeanIsAbove.h
3740
include/Common/TH1Reductor.h
3841
include/Common/TH2Reductor.h
@@ -42,6 +45,9 @@ add_root_dictionary(O2QcCommon
4245
LINKDEF include/Common/LinkDef.h
4346
BASENAME O2QcCommon)
4447

48+
install(FILES etc/trfcollection-example.json
49+
DESTINATION Modules/Common)
50+
4551
# ---- Tests ----
4652

4753
set(TEST_SRCS test/testMeanIsAbove.cxx test/testNonEmpty.cxx test/testCommonReductors.cxx)

0 commit comments

Comments
 (0)