Skip to content

Commit 6de104d

Browse files
author
Michal Tichák
committed
fixup! tests
1 parent 8eabefb commit 6de104d

File tree

2 files changed

+79
-35
lines changed

2 files changed

+79
-35
lines changed

Framework/src/MonitorObjectCollection.cxx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
3333
throw std::runtime_error("The other object is not a MonitorObjectCollection");
3434
}
3535

36+
bool reportedMismatchingRunNumbers = false;
3637
auto otherIterator = otherCollection->MakeIterator();
3738
while (auto otherObject = otherIterator->Next()) {
3839
auto otherObjectName = otherObject->GetName();
@@ -51,13 +52,26 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
5152
<< otherMO->getActivity().mId << ") "
5253
<< "is higher than the one of the target object '"
5354
<< targetMO->GetName() << "' (" << targetMO->getActivity().mId
54-
<< "). I am switching these objects, but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
55+
<< "). Replacing the merged object with input, "
56+
<< "but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
5557
<< "QC objects from other setups are reaching this one."
5658
<< ENDM;
5759
otherMO->Copy(*targetMO);
5860
continue;
5961
}
6062

63+
if (!reportedMismatchingRunNumbers && otherMO->getActivity().mId < targetMO->getActivity().mId) {
64+
ILOG(Error, Ops) << "The run number of the input object '" << otherMO->GetName() << "' ("
65+
<< otherMO->getActivity().mId << ") "
66+
<< "does not match the run number of the target object '"
67+
<< targetMO->GetName() << "' (" << targetMO->getActivity().mId
68+
<< "). Ignoring this object nad trying to continue, but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
69+
<< "QC objects from other setups are reaching this one. Will not report more mismatches in this collection."
70+
<< ENDM;
71+
reportedMismatchingRunNumbers = true;
72+
continue;
73+
}
74+
6175
// That might be another collection or a concrete object to be merged, we walk on the collection recursively.
6276
algorithm::merge(targetMO->getObject(), otherMO->getObject());
6377
if (otherMO->getValidity().isValid()) {

Framework/test/testMonitorObjectCollection.cxx

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <Mergers/MergerAlgorithm.h>
2626

2727
#include <catch_amalgamated.hpp>
28-
#include <iostream>
2928

3029
using namespace o2::mergers;
3130

@@ -99,42 +98,73 @@ TEST_CASE("monitor_object_collection_merge")
9998

10099
TEST_CASE("monitor_object_collection_merge_different_id")
101100
{
102-
103-
auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* {
101+
const auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* {
104102
return dynamic_cast<TH1I*>(dynamic_cast<MonitorObject*>(collection->At(0))->getObject());
105103
};
106104

107-
const size_t bins = 10;
108-
const size_t min = 0;
109-
const size_t max = 10;
110-
111-
// Setting up the target. Histo 1D
112-
auto target = std::make_unique<MonitorObjectCollection>();
113-
114-
auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
115-
targetTH1I->Fill(5);
116-
targetTH1I->Print();
117-
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
118-
targetMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", gInvalidValidityInterval });
119-
targetMoTH1I->setIsOwner(true);
120-
target->Add(targetMoTH1I);
121-
122-
// Setting up the other. Histo 1D + Histo 2D
123-
auto other = std::make_unique<MonitorObjectCollection>();
124-
other->SetOwner(true);
125-
126-
auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
127-
otherTH1I->Fill(2);
128-
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
129-
otherMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
130-
otherMoTH1I->setIsOwner(true);
131-
other->Add(otherMoTH1I);
132-
133-
std::cout << toHisto(target)->GetTitle() << "\n";
134-
std::cout << toHisto(other)->GetTitle() << "\n";
135-
CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
136-
std::cout << toHisto(target)->GetTitle() << "\n";
137-
std::cout << toHisto(other)->GetTitle() << "\n";
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+
}
138168
}
139169

140170
TEST_CASE("monitor_object_collection_post_deserialization")

0 commit comments

Comments
 (0)