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);
115 TH3I*
target =
new TH3I(
"obj1",
"obj1",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
117 TH3I*
other =
new TH3I(
"obj2",
"obj2",
bins,
min,
max,
bins,
min,
max,
bins,
min,
max);
118 other->Fill(2, 2, 2);
119 other->Fill(2, 2, 2);
129 const size_t dim = 5;
134 THnI*
target =
new THnI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
136 THnI*
other =
new THnI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
137 other->FillBin(2, 1);
138 other->FillBin(2, 1);
148 const size_t dim = 5;
153 Double_t
entry[dim] = {5, 5, 5, 5, 5};
155 THnSparseI*
target =
new THnSparseI(
"obj1",
"obj1", dim, binsDims, mins, maxs);
157 THnSparseI*
other =
new THnSparseI(
"obj2",
"obj2", dim, binsDims, mins, maxs);
176 auto createTree = [&](std::string
name) -> TTree* {
177 TTree*
tree =
new TTree();
179 tree->Branch(
"b1", &branch1,
"a/I:b/L:c/F:d/D");
180 tree->Branch(
"b2", &branch2);
184 TTree*
target = createTree(
"obj1");
185 TTree*
other = createTree(
"obj2");
202 constexpr Int_t points = 5;
203 Double_t
x1[] = {0, 1, 2, 3, 4};
204 Double_t
y1[] = {0, 1, 2, 3, 4};
205 Double_t x2[] = {5, 6, 7, 8, 9};
206 Double_t y2[] = {5, 6, 7, 8, 9};
209 TGraph*
other =
new TGraph(points, x2, y2);
221 other->Fill(5, 5, 1);
227 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(2)), 2, 0.001);
228 BOOST_CHECK_CLOSE(
target->GetBinContent(
target->FindBin(5)), 5, 0.001);
258 TObjArray*
target =
new TObjArray();
261 TH1I* targetTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
266 target->Add(targetCustom);
269 TList*
other =
new TList();
270 other->SetOwner(
true);
272 TH1I* otherTH1I =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
275 other->Add(otherTH1I);
278 otherTH2I->Fill(5, 5);
279 other->Add(otherTH2I);
282 other->Add(otherCustom);
291 BOOST_REQUIRE_EQUAL(
target->GetEntries(), 3);
293 TH1I* resultTH1I =
dynamic_cast<TH1I*
>(
target->FindObject(
"histo 1d"));
294 BOOST_REQUIRE(resultTH1I !=
nullptr);
298 TH2I* resultTH2I =
dynamic_cast<TH2I*
>(
target->FindObject(
"histo 2d"));
299 BOOST_REQUIRE(resultTH2I !=
nullptr);
303 BOOST_REQUIRE(resultCustom !=
nullptr);
309TCanvas*
createCanvas(std::string
name, std::string title, std::vector<std::shared_ptr<TH1I>>& histograms)
311 auto canvas =
new TCanvas(
name.c_str(), title.c_str(), 100, 100);
312 canvas->Divide(histograms.size(), 1);
313 for (
size_t i = 1;
const auto& hist : histograms) {
323 auto collectFromTPad = [](TPad* pad, std::vector<TObject*>&
objects,
const auto& collectFromTPad) {
327 auto* primitives = pad->GetListOfPrimitives();
328 for (
int i = 0;
i < primitives->GetSize(); ++
i) {
329 auto* primitive = primitives->At(
i);
330 if (
auto* primitivePad =
dynamic_cast<TPad*
>(primitive)) {
331 collectFromTPad(primitivePad,
objects, collectFromTPad);
338 std::vector<TObject*> collectedObjects;
339 collectFromTPad(canvas, collectedObjects, collectFromTPad);
341 return collectedObjects;
348 std::vector<std::shared_ptr<TH1I>> histsC1{
349 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
350 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
357 std::vector<std::shared_ptr<TH1I>> histsC2{
358 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
359 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
367 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
368 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
375 for (
const auto&
object : targetObjects) {
376 auto th =
static_cast<TH1*
>(
object);
377 if (std::string(th->GetName()) ==
"th1") {
380 if (std::string(th->GetName()) ==
"th2") {
388 std::vector<std::shared_ptr<TH1I>> histsC1{
389 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
390 std::make_shared<TH1I>(
"th2",
"obj2",
bins,
min,
max),
393 std::vector<std::shared_ptr<TH1I>> histsC2{
394 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
397 auto targetCanvas =
createCanvas(
"c1",
"test title 1", histsC1);
398 auto otherCanvas =
createCanvas(
"c2",
"test title 2", histsC2);
400 BOOST_CHECK_THROW(
algorithm::merge(targetCanvas, otherCanvas), std::runtime_error);
405 std::vector<std::shared_ptr<TH1I>> histsC1{
406 std::make_shared<TH1I>(
"th1",
"obj1",
bins,
min,
max),
409 std::vector<std::shared_ptr<TH1I>> histsC2{
410 std::make_shared<TH1I>(
"th2",
"obj2",
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);
422 TObjArray*
main =
new TObjArray();
423 main->SetOwner(
false);
425 TH1I* histo1D =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
433 auto* collectionInside =
new TList();
434 collectionInside->SetOwner(
true);
436 TH1I* histo1DinsideCollection =
new TH1I(
"histo 1d",
"histo 1d",
bins,
min,
max);
437 histo1DinsideCollection->Fill(2);
438 collectionInside->Add(histo1DinsideCollection);
440 TH2I* histo2DinsideCollection =
new TH2I(
"histo 2d",
"histo 2d",
bins,
min,
max,
bins,
min,
max);
441 histo2DinsideCollection->Fill(5, 5);
442 collectionInside->Add(histo2DinsideCollection);
444 main->Add(collectionInside);
453 target->SetBit(TH1::kIsAverage);
457 other->SetBit(TH1::kIsAverage);
461 BOOST_CHECK_CLOSE(
target->GetBinContent(
other->FindBin(5)), 1.0, 0.001);
467BOOST_AUTO_TEST_SUITE(VectorOfHistos)
471 return {histo->GetArray(),
static_cast<uint
>(histo->GetSize())};
474template <
typename T, std::
size_t N>
482 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
506 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());
507 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());
508 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());
509 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());
516 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());
517 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());
518 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());
519 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());
524 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
544 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());
545 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());
546 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());
553 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());
554 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());
555 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());
560 auto target1_1 = std::make_shared<TH1F>(
"histo 1-1",
"histo 1-1",
bins,
min,
max);
580 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());
581 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());
582 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());
592 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());
593 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());
594 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());
597BOOST_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())