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>
32#include <TObjString.h>
48constexpr size_t min = 0;
49constexpr size_t max = 10;
61 TH1I*
other =
nullptr;
69 TObjString*
target =
new TObjString(
"foo");
70 TObjString*
other =
new TObjString(
"bar");
79 TH1I*
object =
new TH1I(
"obj1",
"obj1",
bins,
min,
max);
131 TH3I*
target =
new TH3I(
"obj1",
"obj1",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
133 TH3I*
other =
new TH3I(
"obj2",
"obj2",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
134 other->Fill(2, 2, 2);
135 other->Fill(2, 2, 2);
145 const size_t dim = 5;
150 THnI*
target =
new THnI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
152 THnI*
other =
new THnI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
153 other->FillBin(2, 1);
154 other->FillBin(2, 1);
164 const size_t dim = 5;
169 Double_t
entry[dim] = {5, 5, 5, 5, 5};
171 THnSparseI*
target =
new THnSparseI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
173 THnSparseI*
other =
new THnSparseI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
192 auto createTree = [&](std::string
name) -> TTree* {
193 TTree*
tree =
new TTree();
195 tree->Branch(
"b1", &branch1,
"a/I:b/L:c/F:d/D");
196 tree->Branch(
"b2", &branch2);
200 TTree*
target = createTree(
"obj1");
201 TTree*
other = createTree(
"obj2");
218 constexpr Int_t points = 5;
219 Double_t
x1[] = {0, 1, 2, 3, 4};
220 Double_t
y1[] = {0, 1, 2, 3, 4};
221 Double_t x2[] = {5, 6, 7, 8, 9};
222 Double_t y2[] = {5, 6, 7, 8, 9};
225 TGraph*
other =
new TGraph(points, x2, y2);
237 other->Fill(5, 5, 1);
243 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(2)), 2, 0.001);
244 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(5)), 5, 0.001);
274 TObjArray*
target =
new TObjArray();
277 TH1I* targetTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
282 target->Add(targetCustom);
285 TList*
other =
new TList();
286 other->SetOwner(
true);
288 TH1I* otherTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
291 other->Add(otherTH1I);
294 otherTH2I->Fill(5, 5);
295 other->Add(otherTH2I);
298 other->Add(otherCustom);
307 BOOST_REQUIRE_EQUAL(
target->GetEntries(), 3);
309 TH1I* resultTH1I =
dynamic_cast<TH1I*
>(
target->FindObject(
"histo 1d"));
310 BOOST_REQUIRE(resultTH1I !=
nullptr);
314 TH2I* resultTH2I =
dynamic_cast<TH2I*
>(
target->FindObject(
"histo 2d"));
315 BOOST_REQUIRE(resultTH2I !=
nullptr);
319 BOOST_REQUIRE(resultCustom !=
nullptr);
325TCanvas*
createCanvas(std::string
name, std::string title, std::vector<std::shared_ptr<TH1I>>& histograms)
327 auto canvas =
new TCanvas(
name.c_str(), title.c_str(), 100, 100);
328 canvas->Divide(histograms.size(), 1);
329 for (
size_t i = 1;
const auto& hist : histograms) {
339 auto collectFromTPad = [](TPad* pad, std::vector<TObject*>&
objects,
const auto& collectFromTPad) {
343 auto* primitives = pad->GetListOfPrimitives();
344 for (
int i = 0;
i < primitives->GetSize(); ++
i) {
345 auto* primitive = primitives->At(
i);
346 if (
auto* primitivePad =
dynamic_cast<TPad*
>(primitive)) {
347 collectFromTPad(primitivePad,
objects, collectFromTPad);
354 std::vector<TObject*> collectedObjects;
355 collectFromTPad(canvas, collectedObjects, collectFromTPad);
357 return collectedObjects;
364 std::vector<std::shared_ptr<TH1I>> histsC1{
365 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
366 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
373 std::vector<std::shared_ptr<TH1I>> histsC2{
374 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
375 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
383 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
384 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
391 for (
const auto&
object : targetObjects) {
392 auto th =
static_cast<TH1*
>(
object);
393 if (std::string(th->GetName()) ==
"th1") {
396 if (std::string(th->GetName()) ==
"th2") {
404 std::vector<std::shared_ptr<TH1I>> histsC1{
405 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
406 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
409 std::vector<std::shared_ptr<TH1I>> histsC2{
410 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
413 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
414 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
416 BOOST_CHECK_THROW(
algorithm::merge(targetCanvas, otherCanvas), std::runtime_error);
421 std::vector<std::shared_ptr<TH1I>> histsC1{
422 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
425 std::vector<std::shared_ptr<TH1I>> histsC2{
426 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
429 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
430 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
432 BOOST_CHECK_THROW(
algorithm::merge(targetCanvas, otherCanvas), std::runtime_error);
438 TObjArray*
main =
new TObjArray();
439 main->SetOwner(
false);
441 TH1I* histo1D =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
449 auto* collectionInside =
new TList();
450 collectionInside->SetOwner(
true);
452 TH1I* histo1DinsideCollection =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
453 histo1DinsideCollection->Fill(2);
454 collectionInside->Add(histo1DinsideCollection);
456 TH2I* histo2DinsideCollection =
new TH2I(
"histo 2d",
"histo 2d",
bins,
min,
max,
bins,
min,
max);
457 histo2DinsideCollection->Fill(5, 5);
458 collectionInside->Add(histo2DinsideCollection);
460 main->Add(collectionInside);
469 target->SetBit(TH1::kIsAverage);
473 other->SetBit(TH1::kIsAverage);
477 BOOST_CHECK_CLOSE(
target->GetBinContent(
other->FindBin(5)), 1.0, 0.001);
483BOOST_AUTO_TEST_SUITE(VectorOfHistos)
487 return {histo->GetArray(),
static_cast<uint
>(histo->GetSize())};
490template <
typename T, std::
size_t N>
498 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
522 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());
523 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());
524 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());
525 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());
532 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());
533 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());
534 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());
535 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 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
560 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());
561 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());
562 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());
569 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());
570 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());
571 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());
576 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
596 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());
597 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());
598 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());
608 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());
609 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());
610 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());
613BOOST_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)
std::vector< TObjectPtr > VectorOfTObjectPtrs
Defining DataPointCompositeObject explicitly as copiable.
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())