|
25 | 25 | #include <Mergers/MergerAlgorithm.h> |
26 | 26 |
|
27 | 27 | #include <catch_amalgamated.hpp> |
28 | | -#include <iostream> |
29 | 28 |
|
30 | 29 | using namespace o2::mergers; |
31 | 30 |
|
@@ -99,42 +98,73 @@ TEST_CASE("monitor_object_collection_merge") |
99 | 98 |
|
100 | 99 | TEST_CASE("monitor_object_collection_merge_different_id") |
101 | 100 | { |
102 | | - |
103 | | - auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* { |
| 101 | + const auto toHisto = [](std::unique_ptr<MonitorObjectCollection>& collection) -> TH1I* { |
104 | 102 | return dynamic_cast<TH1I*>(dynamic_cast<MonitorObject*>(collection->At(0))->getObject()); |
105 | 103 | }; |
106 | 104 |
|
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 | + } |
138 | 168 | } |
139 | 169 |
|
140 | 170 | TEST_CASE("monitor_object_collection_post_deserialization") |
|
0 commit comments