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+
99170TEST_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