Skip to content

Commit 3ce20f6

Browse files
author
Michal Tichák
committed
QC-1086 added cycles to MOs and QOs
1 parent 2af8981 commit 3ce20f6

17 files changed

+150
-27
lines changed

Framework/include/QualityControl/CcdbDatabase.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ class CcdbDatabase : public DatabaseInterface
7676
const std::string& createdNotAfter = "", const std::string& createdNotBefore = "") override;
7777

7878
// retrieval - MO - deprecated
79-
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName, long timestamp = Timestamp::Current, const core::Activity& activity = {}) override;
79+
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName,
80+
long timestamp = Timestamp::Current,
81+
const core::Activity& activity = {},
82+
const std::map<std::string, std::string>& metadata = {}) override;
8083
// retrieval - QO - deprecated
81-
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current, const core::Activity& activity = {}) override;
84+
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current,
85+
const core::Activity& activity = {},
86+
const std::map<std::string, std::string>& metadata = {}) override;
8287

8388
// retrieval - general
8489
std::string retrieveJson(std::string path, long timestamp, const std::map<std::string, std::string>& metadata) override;
@@ -91,10 +96,10 @@ class CcdbDatabase : public DatabaseInterface
9196
static long getCurrentTimestamp();
9297
static long getFutureTimestamp(int secondsInFuture);
9398
/**
94-
* Return the listing of folder and/or objects in the subpath.
95-
* @param subpath The folder we want to list the children of.
96-
* @return The listing of folder and/or objects at the subpath.
97-
*/
99+
* Return the listing of folder and/or objects in the subpath.
100+
* @param subpath The folder we want to list the children of.
101+
* @return The listing of folder and/or objects at the subpath.
102+
*/
98103
std::vector<std::string> getListing(const std::string& subpath = "");
99104

100105
/**

Framework/include/QualityControl/DatabaseInterface.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class DatabaseInterface
135135
* @param activity Activity of the object
136136
* @deprecated
137137
*/
138-
virtual std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName, long timestamp = Timestamp::Current, const core::Activity& activity = {}) = 0;
138+
virtual std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName,
139+
long timestamp = Timestamp::Current, const core::Activity& activity = {},
140+
const std::map<std::string, std::string>& metadata = {}) = 0;
139141
/**
140142
* \brief Look up a quality object and return it.
141143
* Look up a quality object and return it if found or nullptr if not.
@@ -144,7 +146,9 @@ class DatabaseInterface
144146
* @param activity Activity of the object
145147
* @deprecated
146148
*/
147-
virtual std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current, const core::Activity& activity = {}) = 0;
149+
virtual std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current,
150+
const core::Activity& activity = {},
151+
const std::map<std::string, std::string>& metadata = {}) = 0;
148152

149153
/**
150154
* \brief Look up an object and return it.

Framework/include/QualityControl/DummyDatabase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class DummyDatabase : public DatabaseInterface
3535
std::string const& detectorName, std::string const& taskName, long from = -1, long to = -1) override;
3636
// MonitorObject
3737
void storeMO(std::shared_ptr<const o2::quality_control::core::MonitorObject> q) override;
38-
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string taskName, std::string objectName, long timestamp = -1, const core::Activity& activity = {}) override;
38+
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string taskName, std::string objectName, long timestamp = -1, const core::Activity& activity = {}, const std::map<std::string, std::string>& metadata = {}) override;
3939
// QualityObject
4040
void storeQO(std::shared_ptr<const o2::quality_control::core::QualityObject> q) override;
41-
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string checkerName, long timestamp = -1, const core::Activity& activity = {}) override;
41+
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string checkerName, long timestamp = -1, const core::Activity& activity = {}, const std::map<std::string, std::string>& metadata = {}) override;
4242

4343
// General
4444
void* retrieveAny(std::type_info const& tinfo, std::string const& path,

Framework/include/QualityControl/MonitorObject.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define QC_CORE_MONITOROBJECT_H
1919

2020
// std
21+
#include <optional>
2122
#include <string>
2223
#include <map>
2324
// ROOT
@@ -113,6 +114,8 @@ class MonitorObject : public TObject
113114
const std::map<std::string, std::string>& getMetadataMap() const;
114115
/// \brief Update the value of metadata or add it if it does not exist yet.
115116
void addOrUpdateMetadata(std::string key, std::string value);
117+
/// \brief Get metadata value of given key, returns std::nullopt if none exists;
118+
std::optional<std::string> getMetadata(const std::string& key);
116119

117120
void Draw(Option_t* option) override;
118121
TObject* DrawClone(Option_t* option) const override;
@@ -146,7 +149,7 @@ class MonitorObject : public TObject
146149
void releaseObject();
147150
void cloneAndSetObject(const MonitorObject&);
148151

149-
ClassDefOverride(MonitorObject, 13);
152+
ClassDefOverride(MonitorObject, 14);
150153
};
151154

152155
} // namespace o2::quality_control::core

Framework/include/QualityControl/MonitorObjectCollection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ class MonitorObjectCollection : public TObjArray, public mergers::MergeInterface
4040
void setTaskName(const std::string&);
4141
const std::string& getTaskName() const;
4242

43+
void addOrUpdateMetadata(std::string key, std::string value);
44+
4345
MergeInterface* cloneMovingWindow() const override;
4446

4547
private:
4648
std::string mDetector = "TST";
4749
std::string mTaskName = "Test";
4850

49-
ClassDefOverride(MonitorObjectCollection, 2);
51+
ClassDefOverride(MonitorObjectCollection, 3);
5052
};
5153

5254
} // namespace o2::quality_control::core
5355

54-
#endif //QUALITYCONTROL_MONITOROBJECTCOLLECTION_H
56+
#endif // QUALITYCONTROL_MONITOROBJECTCOLLECTION_H

Framework/include/QualityControl/ObjectMetadataKeys.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ constexpr auto created = "Created";
2828
constexpr auto md5sum = "Content-MD5";
2929
constexpr auto objectType = "ObjectType";
3030
constexpr auto lastModified = "lastModified";
31+
constexpr auto cycle = "Cycle";
32+
3133
// General QC framework
3234
constexpr auto qcVersion = "qc_version";
3335
constexpr auto qcDetectorCode = "qc_detector_name";
@@ -36,6 +38,7 @@ constexpr auto qcTaskClass = "qc_task_class";
3638
constexpr auto qcQuality = "qc_quality";
3739
constexpr auto qcCheckName = "qc_check_name";
3840
constexpr auto qcAdjustableEOV = "adjustableEOV"; // this is a keyword for the CCDB
41+
3942
// QC Activity
4043
constexpr auto runType = "RunType";
4144
constexpr auto runNumber = "RunNumber";

Framework/include/QualityControl/Triggers.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <functional>
2222
#include <iosfwd>
2323
#include <utility>
24+
#include <map>
2425
#include "QualityControl/Activity.h"
2526

2627
namespace o2::quality_control::postprocessing
@@ -48,12 +49,12 @@ struct Trigger {
4849

4950
/// \brief Constructor. Timestamp is generated from the time of construction.
5051
Trigger(TriggerType triggerType, bool last = false, core::Activity activity = {})
51-
: triggerType(triggerType), last(last), activity(std::move(activity)), timestamp(msSinceEpoch()){};
52+
: triggerType(triggerType), last(last), activity(std::move(activity)), timestamp(msSinceEpoch()) {};
5253
/// \brief Constructor.
5354
Trigger(TriggerType triggerType, bool last, core::Activity activity, uint64_t timestamp, std::string config = {})
54-
: triggerType(triggerType), last(last), activity(std::move(activity)), timestamp(timestamp), config(std::move(config)){};
55+
: triggerType(triggerType), last(last), activity(std::move(activity)), timestamp(timestamp), config(std::move(config)) {};
5556
/// \brief Constructor.
56-
Trigger(TriggerType triggerType, bool last, uint64_t timestamp) : triggerType(triggerType), last(last), activity(), timestamp(timestamp){};
57+
Trigger(TriggerType triggerType, bool last, uint64_t timestamp) : triggerType(triggerType), last(last), activity(), timestamp(timestamp) {};
5758

5859
operator bool() const { return triggerType != TriggerType::No && triggerType != TriggerType::INVALID; }
5960
friend std::ostream& operator<<(std::ostream& out, const Trigger& t);
@@ -69,6 +70,7 @@ struct Trigger {
6970
core::Activity activity; // if tracking an object, it contains also its validity start and end
7071
uint64_t timestamp; // if tracking an object, it is the validity start (validFrom)
7172
std::string config{};
73+
std::map<std::string, std::string> metadata{}; // metadata to search in database
7274
};
7375

7476
using TriggerFcn = std::function<Trigger()>;

Framework/src/CcdbDatabase.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ TObject* CcdbDatabase::retrieveTObject(std::string path, std::map<std::string, s
283283
auto* object = ccdbApi->retrieveFromTFileAny<TObject>(path, metadata, timestamp, headers);
284284
if (object == nullptr) {
285285
ILOG(Warning, Support) << "We could NOT retrieve the object " << path << " with timestamp " << timestamp << "." << ENDM;
286+
for (auto [metaKey, metaVal] : metadata) {
287+
ILOG(Debug, Support) << "and with metadata: [" << metaKey << ", " << metaVal << "]" << ENDM;
288+
}
286289
return nullptr;
287290
}
288291
ILOG(Debug, Support) << "Retrieved object " << path << " with timestamp " << timestamp << ENDM;
@@ -307,11 +310,14 @@ void* CcdbDatabase::retrieveAny(const type_info& tinfo, const string& path, cons
307310
return object;
308311
}
309312

310-
std::shared_ptr<o2::quality_control::core::MonitorObject> CcdbDatabase::retrieveMO(std::string objectPath, std::string objectName, long timestamp, const core::Activity& activity)
313+
std::shared_ptr<o2::quality_control::core::MonitorObject> CcdbDatabase::retrieveMO(std::string objectPath, std::string objectName,
314+
long timestamp, const core::Activity& activity,
315+
const std::map<std::string, std::string>& metadataToRetrieve)
311316
{
312317
string fullPath = activity.mProvenance + "/" + objectPath + "/" + objectName;
313318
map<string, string> headers;
314319
map<string, string> metadata = activity_helpers::asDatabaseMetadata(activity, false);
320+
metadata.insert(metadataToRetrieve.begin(), metadataToRetrieve.end());
315321
TObject* obj = retrieveTObject(fullPath, metadata, timestamp, &headers);
316322

317323
// no object found
@@ -348,10 +354,13 @@ std::shared_ptr<o2::quality_control::core::MonitorObject> CcdbDatabase::retrieve
348354
return mo;
349355
}
350356

351-
std::shared_ptr<o2::quality_control::core::QualityObject> CcdbDatabase::retrieveQO(std::string qoPath, long timestamp, const core::Activity& activity)
357+
std::shared_ptr<o2::quality_control::core::QualityObject> CcdbDatabase::retrieveQO(std::string qoPath, long timestamp,
358+
const core::Activity& activity,
359+
const std::map<std::string, std::string>& metadataToRetrieve)
352360
{
353361
map<string, string> headers;
354362
map<string, string> metadata = activity_helpers::asDatabaseMetadata(activity, false);
363+
metadata.insert(metadataToRetrieve.begin(), metadataToRetrieve.end());
355364
auto fullPath = activity.mProvenance + "/" + qoPath;
356365
TObject* obj = retrieveTObject(fullPath, metadata, timestamp, &headers);
357366
if (obj == nullptr) {

Framework/src/Check.cxx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <memory>
1515
#include <algorithm>
16+
#include <string>
1617
#include <utility>
1718
#include <ranges>
1819
// O2
@@ -24,6 +25,7 @@
2425
#include "QualityControl/CommonSpec.h"
2526
#include "QualityControl/InputUtils.h"
2627
#include "QualityControl/MonitorObject.h"
28+
#include "QualityControl/ObjectMetadataKeys.h"
2729
#include "QualityControl/RootClassFactory.h"
2830
#include "QualityControl/QcInfoLogger.h"
2931
#include "QualityControl/Quality.h"
@@ -163,7 +165,14 @@ QualityObjectsType Check::check(std::map<std::string, std::shared_ptr<MonitorObj
163165
}));
164166
ILOG(Debug, Devel) << "Check '" << mCheckConfig.name << "', quality '" << quality << "'" << ENDM;
165167
std::vector<std::string> monitorObjectsNames;
166-
std::ranges::copy(moMapToCheck | std::views::keys, std::back_inserter(monitorObjectsNames));
168+
// std::ranges::copy(moMapToCheck | std::views::keys, std::back_inserter(monitorObjectsNames));
169+
unsigned long maxCycle{};
170+
for (const auto& [moName, mo] : moMapToCheck) {
171+
monitorObjectsNames.emplace_back(moName);
172+
if (const auto cycle = mo->getMetadata(repository::metadata_keys::cycle)) {
173+
maxCycle = std::max(std::stoul(cycle.value()), maxCycle);
174+
}
175+
}
167176
// todo: take metadata from somewhere
168177
qualityObjects.emplace_back(std::make_shared<QualityObject>(
169178
quality,
@@ -172,7 +181,11 @@ QualityObjectsType Check::check(std::map<std::string, std::shared_ptr<MonitorObj
172181
UpdatePolicyTypeUtils::ToString(mCheckConfig.policyType),
173182
stringifyInput(mCheckConfig.inputSpecs),
174183
monitorObjectsNames));
184+
175185
qualityObjects.back()->setActivity(commonActivity);
186+
if (maxCycle > 0) {
187+
qualityObjects.back()->addMetadata(repository::metadata_keys::cycle, std::to_string(maxCycle));
188+
}
176189
beautify(moMapToCheck, quality);
177190
}
178191

Framework/src/DummyDatabase.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void DummyDatabase::storeMO(std::shared_ptr<const o2::quality_control::core::Mon
3838
{
3939
}
4040

41-
std::shared_ptr<o2::quality_control::core::MonitorObject> DummyDatabase::retrieveMO(std::string, std::string, long, const core::Activity& activity)
41+
std::shared_ptr<o2::quality_control::core::MonitorObject> DummyDatabase::retrieveMO(std::string, std::string, long, const core::Activity& activity, const std::map<std::string, std::string>&)
4242
{
4343
return {};
4444
}
@@ -47,7 +47,7 @@ void DummyDatabase::storeQO(std::shared_ptr<const o2::quality_control::core::Qua
4747
{
4848
}
4949

50-
std::shared_ptr<o2::quality_control::core::QualityObject> DummyDatabase::retrieveQO(std::string, long, const core::Activity& activity)
50+
std::shared_ptr<o2::quality_control::core::QualityObject> DummyDatabase::retrieveQO(std::string, long, const core::Activity& activity, const std::map<std::string, std::string>& metadata)
5151
{
5252
return {};
5353
}

0 commit comments

Comments
 (0)