Skip to content

Commit c0ec83f

Browse files
justonedev1Michal Tichák
andauthored
switch MOs in MonitorObjectCollection when run number is higher on new (#2443)
Co-authored-by: Michal Tichák <michal.tichak@cern.ch>
1 parent 13084fd commit c0ec83f

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

Framework/src/MonitorObjectCollection.cxx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,32 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
4646
if (!otherMO || !targetMO) {
4747
throw std::runtime_error("The target object or the other object could not be casted to MonitorObject.");
4848
}
49-
if (!reportedMismatchingRunNumbers && targetMO->getActivity().mId != otherMO->getActivity().mId) {
49+
50+
if (otherMO->getActivity().mId > targetMO->getActivity().mId) {
51+
ILOG(Error, Ops) << "The run number of the input object '" << otherMO->GetName() << "' ("
52+
<< otherMO->getActivity().mId << ") "
53+
<< "is higher than the one of the target object '"
54+
<< targetMO->GetName() << "' (" << targetMO->getActivity().mId
55+
<< "). Replacing the merged object with input, "
56+
<< "but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
57+
<< "QC objects from other setups are reaching this one."
58+
<< ENDM;
59+
otherMO->Copy(*targetMO);
60+
continue;
61+
}
62+
63+
if (!reportedMismatchingRunNumbers && otherMO->getActivity().mId < targetMO->getActivity().mId) {
5064
ILOG(Error, Ops) << "The run number of the input object '" << otherMO->GetName() << "' ("
5165
<< otherMO->getActivity().mId << ") "
5266
<< "does not match the run number of the target object '"
5367
<< targetMO->GetName() << "' (" << targetMO->getActivity().mId
54-
<< "). Trying to continue, but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
68+
<< "). Ignoring this object and trying to continue, but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
5569
<< "QC objects from other setups are reaching this one. Will not report more mismatches in this collection."
5670
<< ENDM;
5771
reportedMismatchingRunNumbers = true;
72+
continue;
5873
}
74+
5975
// That might be another collection or a concrete object to be merged, we walk on the collection recursively.
6076
algorithm::merge(targetMO->getObject(), otherMO->getObject());
6177
if (otherMO->getValidity().isValid()) {

Framework/test/testMonitorObjectCollection.cxx

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include "QualityControl/MonitorObjectCollection.h"
1818
#include "QualityControl/MonitorObject.h"
19-
#include "QualityControl/QcInfoLogger.h"
2019

20+
#include <TH1.h>
2121
#include <TH1I.h>
2222
#include <TH2I.h>
2323
#include <TH2I.h>
@@ -96,6 +96,77 @@ TEST_CASE("monitor_object_collection_merge")
9696
delete target;
9797
}
9898

99+
TEST_CASE("monitor_object_collection_merge_different_id")
100+
{
101+
const auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* {
102+
return dynamic_cast<TH1I*>(dynamic_cast<MonitorObject*>(collection->At(0))->getObject());
103+
};
104+
105+
constexpr size_t bins = 10;
106+
constexpr size_t min = 0;
107+
constexpr size_t max = 10;
108+
109+
SECTION("other has higher run number than target")
110+
{
111+
auto target = std::make_unique<MonitorObjectCollection>();
112+
113+
auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
114+
targetTH1I->Fill(5);
115+
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
116+
targetMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", { 10, 20 } });
117+
targetMoTH1I->setIsOwner(true);
118+
target->Add(targetMoTH1I);
119+
120+
auto other = std::make_unique<MonitorObjectCollection>();
121+
other->SetOwner(true);
122+
123+
auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
124+
otherTH1I->Fill(2);
125+
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
126+
otherMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
127+
otherMoTH1I->setIsOwner(true);
128+
other->Add(otherMoTH1I);
129+
130+
CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
131+
auto* h1orig = toHisto(target);
132+
auto* h1other = toHisto(other);
133+
REQUIRE(h1orig->GetAt(3) == 1);
134+
for (size_t i = 0; i != h1orig->GetSize(); ++i) {
135+
REQUIRE(h1orig->GetAt(i) == h1other->GetAt(i));
136+
}
137+
}
138+
139+
SECTION("other has lower run number than target")
140+
{
141+
auto target = std::make_unique<MonitorObjectCollection>();
142+
143+
auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
144+
targetTH1I->Fill(5);
145+
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
146+
targetMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 10, 20 } });
147+
targetMoTH1I->setIsOwner(true);
148+
target->Add(targetMoTH1I);
149+
150+
auto other = std::make_unique<MonitorObjectCollection>();
151+
other->SetOwner(true);
152+
153+
auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
154+
otherTH1I->Fill(2);
155+
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
156+
otherMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
157+
otherMoTH1I->setIsOwner(true);
158+
other->Add(otherMoTH1I);
159+
160+
CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
161+
auto* h1orig = toHisto(target);
162+
auto* h1other = toHisto(other);
163+
REQUIRE(h1orig->At(h1orig->FindBin(5)) == 1);
164+
REQUIRE(h1other->At(h1other->FindBin(5)) == 0);
165+
REQUIRE(h1orig->At(h1orig->FindBin(2)) == 0);
166+
REQUIRE(h1other->At(h1other->FindBin(2)) == 1);
167+
}
168+
}
169+
99170
TEST_CASE("monitor_object_collection_post_deserialization")
100171
{
101172
const size_t bins = 10;
@@ -171,4 +242,4 @@ TEST_CASE("monitor_object_collection_clone_mw")
171242
delete mwMOC2;
172243
}
173244

174-
} // namespace o2::quality_control::core
245+
} // namespace o2::quality_control::core

0 commit comments

Comments
 (0)