Skip to content

Commit

Permalink
fixup! tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Tichák committed Oct 8, 2024
1 parent 8eabefb commit 6de104d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 35 deletions.
16 changes: 15 additions & 1 deletion Framework/src/MonitorObjectCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void MonitorObjectCollection::merge(mergers::MergeInterface* const other)
throw std::runtime_error("The other object is not a MonitorObjectCollection");
}

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

if (!reportedMismatchingRunNumbers && otherMO->getActivity().mId < targetMO->getActivity().mId) {
ILOG(Error, Ops) << "The run number of the input object '" << otherMO->GetName() << "' ("
<< otherMO->getActivity().mId << ") "
<< "does not match the run number of the target object '"
<< targetMO->GetName() << "' (" << targetMO->getActivity().mId
<< "). Ignoring this object nad trying to continue, but THIS SHOULD BE IMMEDIATELY ADDRESSED IN PRODUCTION. "
<< "QC objects from other setups are reaching this one. Will not report more mismatches in this collection."
<< ENDM;
reportedMismatchingRunNumbers = true;
continue;
}

// That might be another collection or a concrete object to be merged, we walk on the collection recursively.
algorithm::merge(targetMO->getObject(), otherMO->getObject());
if (otherMO->getValidity().isValid()) {
Expand Down
98 changes: 64 additions & 34 deletions Framework/test/testMonitorObjectCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <Mergers/MergerAlgorithm.h>

#include <catch_amalgamated.hpp>
#include <iostream>

using namespace o2::mergers;

Expand Down Expand Up @@ -99,42 +98,73 @@ TEST_CASE("monitor_object_collection_merge")

TEST_CASE("monitor_object_collection_merge_different_id")
{

auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* {
const auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* {
return dynamic_cast<TH1I*>(dynamic_cast<MonitorObject*>(collection->At(0))->getObject());
};

const size_t bins = 10;
const size_t min = 0;
const size_t max = 10;

// Setting up the target. Histo 1D
auto target = std::make_unique<MonitorObjectCollection>();

auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
targetTH1I->Fill(5);
targetTH1I->Print();
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
targetMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", gInvalidValidityInterval });
targetMoTH1I->setIsOwner(true);
target->Add(targetMoTH1I);

// Setting up the other. Histo 1D + Histo 2D
auto other = std::make_unique<MonitorObjectCollection>();
other->SetOwner(true);

auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
otherTH1I->Fill(2);
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
otherMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
otherMoTH1I->setIsOwner(true);
other->Add(otherMoTH1I);

std::cout << toHisto(target)->GetTitle() << "\n";
std::cout << toHisto(other)->GetTitle() << "\n";
CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
std::cout << toHisto(target)->GetTitle() << "\n";
std::cout << toHisto(other)->GetTitle() << "\n";
constexpr size_t bins = 10;
constexpr size_t min = 0;
constexpr size_t max = 10;

SECTION("other has higher run number than target")
{
auto target = std::make_unique<MonitorObjectCollection>();

auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
targetTH1I->Fill(5);
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
targetMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", { 10, 20 } });
targetMoTH1I->setIsOwner(true);
target->Add(targetMoTH1I);

auto other = std::make_unique<MonitorObjectCollection>();
other->SetOwner(true);

auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
otherTH1I->Fill(2);
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
otherMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
otherMoTH1I->setIsOwner(true);
other->Add(otherMoTH1I);

CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
auto* h1orig = toHisto(target);
auto* h1other = toHisto(other);
REQUIRE(h1orig->GetAt(3) == 1);
for (size_t i = 0; i != h1orig->GetSize(); ++i) {
REQUIRE(h1orig->GetAt(i) == h1other->GetAt(i));
}
}

SECTION("other has lower run number than target")
{
auto target = std::make_unique<MonitorObjectCollection>();

auto* targetTH1I = new TH1I("histo 1d", "original", bins, min, max);
targetTH1I->Fill(5);
auto* targetMoTH1I = new MonitorObject(targetTH1I, "histo 1d", "class", "DET");
targetMoTH1I->setActivity({ 1234, "PHYSICS", "LHC32x", "apass2", "qc_async", { 10, 20 } });
targetMoTH1I->setIsOwner(true);
target->Add(targetMoTH1I);

auto other = std::make_unique<MonitorObjectCollection>();
other->SetOwner(true);

auto* otherTH1I = new TH1I("histo 1d", "input", bins, min, max);
otherTH1I->Fill(2);
auto* otherMoTH1I = new MonitorObject(otherTH1I, "histo 1d", "class", "DET");
otherMoTH1I->setActivity({ 123, "PHYSICS", "LHC32x", "apass2", "qc_async", { 43, 60 } });
otherMoTH1I->setIsOwner(true);
other->Add(otherMoTH1I);

CHECK_NOTHROW(algorithm::merge(target.get(), other.get()));
auto* h1orig = toHisto(target);
auto* h1other = toHisto(other);
REQUIRE(h1orig->At(h1orig->FindBin(5)) == 1);
REQUIRE(h1other->At(h1other->FindBin(5)) == 0);
REQUIRE(h1orig->At(h1orig->FindBin(2)) == 0);
REQUIRE(h1other->At(h1other->FindBin(2)) == 1);
}
}

TEST_CASE("monitor_object_collection_post_deserialization")
Expand Down

0 comments on commit 6de104d

Please sign in to comment.