Skip to content

Commit 196fa28

Browse files
author
Michal Tichák
committed
fixup! QC-1086 added cycles to MOs and QOs
1 parent 3ce20f6 commit 196fa28

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

Framework/include/QualityControl/ObjectMetadataKeys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ 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";
3231

3332
// General QC framework
3433
constexpr auto qcVersion = "qc_version";
@@ -38,6 +37,7 @@ constexpr auto qcTaskClass = "qc_task_class";
3837
constexpr auto qcQuality = "qc_quality";
3938
constexpr auto qcCheckName = "qc_check_name";
4039
constexpr auto qcAdjustableEOV = "adjustableEOV"; // this is a keyword for the CCDB
40+
constexpr auto cycle = "CycleNumber";
4141

4242
// QC Activity
4343
constexpr auto runType = "RunType";

Framework/src/CcdbDatabase.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,8 +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+
ILOG(Debug, Support) << "and with metadata:" << ENDM;
286287
for (auto [metaKey, metaVal] : metadata) {
287-
ILOG(Debug, Support) << "and with metadata: [" << metaKey << ", " << metaVal << "]" << ENDM;
288+
ILOG(Debug, Support) << metaKey << ", " << metaVal << ENDM;
288289
}
289290
return nullptr;
290291
}

Framework/src/Check.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <memory>
1515
#include <algorithm>
16+
#include <stdexcept>
1617
#include <string>
1718
#include <utility>
1819
#include <ranges>
@@ -165,12 +166,18 @@ QualityObjectsType Check::check(std::map<std::string, std::shared_ptr<MonitorObj
165166
}));
166167
ILOG(Debug, Devel) << "Check '" << mCheckConfig.name << "', quality '" << quality << "'" << ENDM;
167168
std::vector<std::string> monitorObjectsNames;
168-
// std::ranges::copy(moMapToCheck | std::views::keys, std::back_inserter(monitorObjectsNames));
169169
unsigned long maxCycle{};
170170
for (const auto& [moName, mo] : moMapToCheck) {
171171
monitorObjectsNames.emplace_back(moName);
172172
if (const auto cycle = mo->getMetadata(repository::metadata_keys::cycle)) {
173-
maxCycle = std::max(std::stoul(cycle.value()), maxCycle);
173+
const auto& cycleStr = cycle.value();
174+
unsigned long cycleVal{};
175+
if (const auto fromCharsRed = std::from_chars(cycleStr.c_str(), cycleStr.c_str() + cycleStr.size(), cycleVal); fromCharsRed.ec == std::errc()) {
176+
maxCycle = std::max(cycleVal, maxCycle);
177+
} else {
178+
ILOG(Warning, Support) << "metadata " << repository::metadata_keys::cycle << " with value " << cycleStr << " couldn't be parsed for a reason: "
179+
<< std::make_error_code(fromCharsRed.ec).message() << ENDM;
180+
}
174181
}
175182
}
176183
// todo: take metadata from somewhere

Framework/src/MonitorObjectCollection.cxx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,48 @@
2121

2222
#include <Mergers/MergerAlgorithm.h>
2323
#include <TNamed.h>
24+
#include <optional>
2425
#include <string>
26+
#include <charconv>
2527

2628
using namespace o2::mergers;
2729

2830
namespace o2::quality_control::core
2931
{
3032

31-
void mergeCycles(MonitorObject*& otherMO, MonitorObject*& targetMO)
33+
std::optional<unsigned long> parseCycle(const std::string& cycleStr)
34+
{
35+
unsigned long cycleVal{};
36+
if (auto parse_res = std::from_chars(cycleStr.c_str(), cycleStr.c_str() + cycleStr.size(), cycleVal); parse_res.ec != std::errc{}) {
37+
ILOG(Warning, Support) << "failed to decypher " << repository::metadata_keys::cycle << " metadata with value " << cycleStr
38+
<< ", with std::errc " << std::make_error_code(parse_res.ec).message() << ENDM;
39+
return std::nullopt;
40+
}
41+
return cycleVal;
42+
}
43+
44+
void mergeCycles(MonitorObject* targetMO, MonitorObject* otherMO)
3245
{
3346
const auto otherCycle = otherMO->getMetadata(repository::metadata_keys::cycle);
3447
const auto targetCycle = targetMO->getMetadata(repository::metadata_keys::cycle);
3548
if (otherCycle.has_value() && targetCycle.has_value()) {
36-
// TODO: would it be worth it for metadata to store other types than std::string?
37-
targetMO->addOrUpdateMetadata(repository::metadata_keys::cycle, std::to_string(std::max(std::stoul(otherCycle.value()), std::stoul(targetCycle.value()))));
49+
const auto targetCycleParsed = parseCycle(targetCycle.value());
50+
const auto otherCycleParsed = parseCycle(otherCycle.value());
51+
52+
if (targetCycleParsed && otherCycleParsed) {
53+
targetMO->addOrUpdateMetadata(repository::metadata_keys::cycle, std::to_string(std::max(targetCycleParsed.value(), otherCycleParsed.value())));
54+
return;
55+
}
56+
57+
if (targetCycleParsed.value()) {
58+
targetMO->addOrUpdateMetadata(repository::metadata_keys::cycle, std::to_string(targetCycleParsed.value()));
59+
return;
60+
}
61+
62+
if (otherCycleParsed.value()) {
63+
otherMO->addOrUpdateMetadata(repository::metadata_keys::cycle, std::to_string(otherCycleParsed.value()));
64+
return;
65+
}
3866
}
3967
}
4068

@@ -72,7 +100,7 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
72100
continue;
73101
}
74102

75-
mergeCycles(otherMO, targetMO);
103+
mergeCycles(targetMO, otherMO);
76104

77105
if (!reportedMismatchingRunNumbers && otherMO->getActivity().mId < targetMO->getActivity().mId) {
78106
ILOG(Error, Ops) << "The run number of the input object '" << otherMO->GetName() << "' ("

Framework/src/SliceTrendingTask.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void SliceTrendingTask::initialize(Trigger t, framework::ServiceRegistryRef serv
6363
ILOG(Info, Support) << "Trying to retrieve an existing TTree for this task to continue the trend." << ENDM;
6464
auto& qcdb = services.get<repository::DatabaseInterface>();
6565
auto path = RepoPathUtils::getMoPath(mConfig.detectorName, PostProcessingInterface::getName(), "", "", false);
66-
auto mo = qcdb.retrieveMO(path, PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest, {}, t.metadata);
66+
auto mo = qcdb.retrieveMO(path, PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest);
6767
if (mo && mo->getObject()) {
6868
auto tree = dynamic_cast<TTree*>(mo->getObject());
6969
if (tree) {

0 commit comments

Comments
 (0)