20#define BOOST_TEST_MODULE Test Utilities MergerAlgorithm
21#define BOOST_TEST_MAIN
22#define BOOST_TEST_DYN_LINK
24#include <boost/test/unit_test.hpp>
33#include <TObjString.h>
50constexpr size_t min = 0;
51constexpr size_t max = 10;
63 TH1I*
other =
nullptr;
71 TObjString*
target =
new TObjString(
"foo");
72 TObjString*
other =
new TObjString(
"bar");
81 TH1I*
object =
new TH1I(
"obj1",
"obj1",
bins,
min,
max);
133 TH3I*
target =
new TH3I(
"obj1",
"obj1",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
135 TH3I*
other =
new TH3I(
"obj2",
"obj2",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
136 other->Fill(2, 2, 2);
137 other->Fill(2, 2, 2);
147 const size_t dim = 5;
152 THnI*
target =
new THnI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
154 THnI*
other =
new THnI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
155 other->FillBin(2, 1);
156 other->FillBin(2, 1);
166 const size_t dim = 5;
171 Double_t
entry[dim] = {5, 5, 5, 5, 5};
173 THnSparseI*
target =
new THnSparseI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
175 THnSparseI*
other =
new THnSparseI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
194 auto createTree = [&](std::string
name) -> TTree* {
195 TTree*
tree =
new TTree();
197 tree->Branch(
"b1", &branch1,
"a/I:b/L:c/F:d/D");
198 tree->Branch(
"b2", &branch2);
202 TTree*
target = createTree(
"obj1");
203 TTree*
other = createTree(
"obj2");
220 constexpr Int_t points = 5;
221 Double_t
x1[] = {0, 1, 2, 3, 4};
222 Double_t
y1[] = {0, 1, 2, 3, 4};
223 Double_t x2[] = {5, 6, 7, 8, 9};
224 Double_t y2[] = {5, 6, 7, 8, 9};
227 TGraph*
other =
new TGraph(points, x2, y2);
239 other->Fill(5, 5, 1);
245 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(2)), 2, 0.001);
246 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(5)), 5, 0.001);
276 TObjArray*
target =
new TObjArray();
279 TH1I* targetTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
284 target->Add(targetCustom);
287 TList*
other =
new TList();
288 other->SetOwner(
true);
290 TH1I* otherTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
293 other->Add(otherTH1I);
296 otherTH2I->Fill(5, 5);
297 other->Add(otherTH2I);
300 other->Add(otherCustom);
309 BOOST_REQUIRE_EQUAL(
target->GetEntries(), 3);
311 TH1I* resultTH1I =
dynamic_cast<TH1I*
>(
target->FindObject(
"histo 1d"));
312 BOOST_REQUIRE(resultTH1I !=
nullptr);
316 TH2I* resultTH2I =
dynamic_cast<TH2I*
>(
target->FindObject(
"histo 2d"));
317 BOOST_REQUIRE(resultTH2I !=
nullptr);
321 BOOST_REQUIRE(resultCustom !=
nullptr);
327TCanvas*
createCanvas(std::string
name, std::string title, std::vector<std::shared_ptr<TH1I>>& histograms)
329 auto canvas =
new TCanvas(
name.c_str(), title.c_str(), 100, 100);
330 canvas->Divide(histograms.size(), 1);
331 for (
size_t i = 1;
const auto& hist : histograms) {
336 TPaveText* pt =
new TPaveText(.05, .1, .95, .8);
347 auto collectFromTPad = [](TPad* pad, std::vector<TObject*>&
objects,
const auto& collectFromTPad) {
351 auto* primitives = pad->GetListOfPrimitives();
352 for (
int i = 0;
i < primitives->GetSize(); ++
i) {
353 auto* primitive = primitives->At(
i);
354 if (
auto* primitivePad =
dynamic_cast<TPad*
>(primitive)) {
355 collectFromTPad(primitivePad,
objects, collectFromTPad);
362 std::vector<TObject*> collectedObjects;
363 collectFromTPad(canvas, collectedObjects, collectFromTPad);
365 return collectedObjects;
372 std::vector<std::shared_ptr<TH1I>> histsC1{
373 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
374 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
381 std::vector<std::shared_ptr<TH1I>> histsC2{
382 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
383 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
391 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
392 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
399 for (
const auto&
object : targetObjects) {
400 auto th =
static_cast<TH1*
>(
object);
401 if (std::string(th->GetName()) ==
"th1") {
404 if (std::string(th->GetName()) ==
"th2") {
412 std::vector<std::shared_ptr<TH1I>> histsC1{
413 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
414 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
417 std::vector<std::shared_ptr<TH1I>> histsC2{
418 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
421 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
422 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
424 BOOST_CHECK_THROW(
algorithm::merge(targetCanvas, otherCanvas), std::runtime_error);
429 std::vector<std::shared_ptr<TH1I>> histsC1{
430 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
433 std::vector<std::shared_ptr<TH1I>> histsC2{
434 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
437 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
438 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
440 BOOST_CHECK_THROW(
algorithm::merge(targetCanvas, otherCanvas), std::runtime_error);
446 TObjArray*
main =
new TObjArray();
447 main->SetOwner(
false);
449 TH1I* histo1D =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
457 auto* collectionInside =
new TList();
458 collectionInside->SetOwner(
true);
460 TH1I* histo1DinsideCollection =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
461 histo1DinsideCollection->Fill(2);
462 collectionInside->Add(histo1DinsideCollection);
464 TH2I* histo2DinsideCollection =
new TH2I(
"histo 2d",
"histo 2d",
bins,
min,
max,
bins,
min,
max);
465 histo2DinsideCollection->Fill(5, 5);
466 collectionInside->Add(histo2DinsideCollection);
468 main->Add(collectionInside);
477 target->SetBit(TH1::kIsAverage);
481 other->SetBit(TH1::kIsAverage);
485 BOOST_CHECK_CLOSE(
target->GetBinContent(
other->FindBin(5)), 1.0, 0.001);
491BOOST_AUTO_TEST_SUITE(VectorOfHistos)
495 return {histo->GetArray(),
static_cast<uint
>(histo->GetSize())};
498template <
typename T, std::
size_t N>
506 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
530 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
531 BOOST_TEST(
to_span(
target1_2) ==
to_array({0., 0., 0., 0., 0., 0., 4., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
532 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
533 BOOST_TEST(
to_span(
other1_2) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
540 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 3., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
541 BOOST_TEST(
to_span(
target1_2) ==
to_array({0., 0., 0., 0., 0., 0., 6., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
542 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
543 BOOST_TEST(
to_span(
other1_2) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
548 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
568 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
569 BOOST_TEST(
to_span(
target1_2) ==
to_array({0., 0., 0., 0., 0., 0., 4., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
570 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
577 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 3., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
578 BOOST_TEST(
to_span(
target1_2) ==
to_array({0., 0., 0., 0., 0., 0., 4., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
579 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
584 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
604 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
605 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
606 BOOST_TEST(
to_span(
other1_2) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
616 BOOST_TEST(
to_span(target1_1) ==
to_array({0., 0., 0., 0., 0., 0., 3., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
617 BOOST_TEST(
to_span(
other1_1) ==
to_array({0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
618 BOOST_TEST(
to_span(
other1_2) ==
to_array({0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0.}), boost::test_tools::per_element());
621BOOST_AUTO_TEST_SUITE_END()
std::vector< std::string > objects
An example of overriding O2 Mergers merging interface, v0.1.
An example of a custom TObject inheriting MergeInterface.
Algorithms for merging objects.
Definition of ObjectStore for Mergers, v0.1.
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLuint GLfloat GLfloat GLfloat x1
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
void merge(TObject *const target, TObject *const other)
A function which merges TObjects.
void deleteTCollections(TObject *obj)
bool isMergeable(TObject *obj)
std::vector< TObjectPtr > VectorOfTObjectPtrs
gsl::span< T, N > to_array(T(&&arr)[N])
gsl::span< float > to_span(std::shared_ptr< TH1F > &histo)
BOOST_AUTO_TEST_CASE(MergerEmptyObjects)
auto collectUnderlyingObjects(TCanvas *canvas) -> std::vector< TObject * >
VectorOfTObjectPtrs target
TCanvas * createCanvas(std::string name, std::string title, std::vector< std::shared_ptr< TH1I > > &histograms)
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
VectorOfTObjectPtrs other
BOOST_TEST(target.size()==2)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())