Project
Loading...
Searching...
No Matches
testDigitizationContext.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test DigitizationContext class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15
16#include <boost/test/unit_test.hpp>
18#include <vector>
19
20namespace o2
21{
22
23// build a context whose collisions sit at the given orbits (one collision each, source 0)
24steer::DigitizationContext makeContext(std::vector<long> const& orbits)
25{
27 auto& records = ctx.getEventRecords();
28 auto& parts = ctx.getEventParts();
29 int entry = 0;
30 for (auto o : orbits) {
32 parts.push_back({steer::EventPart(0, entry++)});
33 }
34 ctx.setNCollisions(records.size());
35 ctx.setMaxNumberParts(1);
36 return ctx;
37}
38
39// The timeframe index structure must have one entry per timeframe asked for, and entry i must
40// describe exactly the collisions falling into orbits [start + i*orbitsPerTF, start + (i+1)*orbitsPerTF).
41BOOST_AUTO_TEST_CASE(TimeframeIndicesAreSlotAligned)
42{
43 long const orbitsPerTF = 6;
44 long const start = 0;
45 long const nTF = 5; // orbits 0..29
46
47 // timeframe 1 (orbits 6..11) and timeframe 4 (orbits 24..29) hold no collision
48 std::vector<long> orbits{0, 3, 5, 12, 14, 17, 18, 21};
49 auto ctx = makeContext(orbits);
50
51 auto indices = ctx.calcTimeframeIndices(start, orbitsPerTF, 0., nTF);
52 BOOST_CHECK_EQUAL(indices.size(), (size_t)nTF);
53
54 for (int tf = 0; tf < nTF; ++tf) {
55 auto first = std::get<0>(indices[tf]);
56 auto last = std::get<1>(indices[tf]);
57 long const lo = start + tf * orbitsPerTF;
58 long const hi = lo + orbitsPerTF;
59 // count what should be in this timeframe
60 int expected = 0;
61 for (auto o : orbits) {
62 if (o >= lo && o < hi) {
63 expected++;
64 }
65 }
66 BOOST_CHECK_EQUAL(last - first + 1, expected);
67 for (int i = first; i <= last; ++i) {
68 BOOST_CHECK(orbits[i] >= lo);
69 BOOST_CHECK(orbits[i] < hi);
70 }
71 }
72}
73
74// A timeframe without collisions must survive extraction as a valid, empty context
75BOOST_AUTO_TEST_CASE(EmptyTimeframeExtracts)
76{
77 long const orbitsPerTF = 6;
78 long const nTF = 3;
79 auto ctx = makeContext({0, 2, 13}); // timeframe 1 (orbits 6..11) is empty
80 auto indices = ctx.calcTimeframeIndices(0, orbitsPerTF, 0., nTF);
81 BOOST_CHECK_EQUAL(indices.size(), (size_t)nTF);
82
83 auto tf0 = ctx.extractSingleTimeframe(0, indices, {});
84 auto tf1 = ctx.extractSingleTimeframe(1, indices, {});
85 auto tf2 = ctx.extractSingleTimeframe(2, indices, {});
86 BOOST_CHECK_EQUAL(tf0.getEventRecords().size(), (size_t)2);
87 BOOST_CHECK_EQUAL(tf1.getEventRecords().size(), (size_t)0);
88 BOOST_CHECK_EQUAL(tf2.getEventRecords().size(), (size_t)1);
89 BOOST_CHECK_EQUAL(tf2.getEventRecords()[0].orbit, 13);
90}
91
92// The trailing timeframes of the requested range must be present even when the last collision
93// falls well before the end of the range
94BOOST_AUTO_TEST_CASE(TrailingTimeframesArePresent)
95{
96 long const orbitsPerTF = 6;
97 long const nTF = 9; // this is what an 8-timeframe anchored MC job with orbitsEarly asks for
98 auto ctx = makeContext({1, 2, 7});
99 auto indices = ctx.calcTimeframeIndices(0, orbitsPerTF, 0., nTF);
100 BOOST_CHECK_EQUAL(indices.size(), (size_t)nTF);
101 for (int tf = 2; tf < nTF; ++tf) {
102 BOOST_CHECK(std::get<0>(indices[tf]) > std::get<1>(indices[tf])); // empty, but present
103 }
104}
105
106// applyMaxCollisionFilter must not shift timeframes when one of them is empty
107BOOST_AUTO_TEST_CASE(MaxCollisionFilterKeepsSlots)
108{
109 long const orbitsPerTF = 6;
110 long const nTF = 4;
111 // tf0: orbits 0,1,2 tf1: empty tf2: orbits 12,13 tf3: orbit 19
112 auto ctx = makeContext({0, 1, 2, 12, 13, 19});
113 auto indices = ctx.calcTimeframeIndices(0, orbitsPerTF, 0., nTF);
114 ctx.applyMaxCollisionFilter(indices, 0, orbitsPerTF, 2, 0.); // keep at most 2 per timeframe
115
116 BOOST_CHECK_EQUAL(indices.size(), (size_t)nTF);
117 BOOST_CHECK_EQUAL(std::get<1>(indices[0]) - std::get<0>(indices[0]) + 1, 2); // capped
118 BOOST_CHECK(std::get<0>(indices[1]) > std::get<1>(indices[1])); // still empty
119 BOOST_CHECK_EQUAL(std::get<1>(indices[2]) - std::get<0>(indices[2]) + 1, 2);
120 BOOST_CHECK_EQUAL(std::get<1>(indices[3]) - std::get<0>(indices[3]) + 1, 1);
121
122 auto tf2 = ctx.extractSingleTimeframe(2, indices, {});
123 BOOST_CHECK_EQUAL(tf2.getEventRecords().size(), (size_t)2);
124 BOOST_CHECK_EQUAL(tf2.getEventRecords()[0].orbit, 12);
125}
126
127} // namespace o2
std::vector< o2::soa::IndexRecord > records
int32_t i
GLuint entry
Definition glcorearb.h:5735
GLsizei GLenum const void * indices
Definition glcorearb.h:400
GLuint start
Definition glcorearb.h:469
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
steer::DigitizationContext makeContext(std::vector< long > const &orbits)
std::unique_ptr< GPUReconstructionTimeframe > tf
std::map< std::string, ID > expected
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())