Project
Loading...
Searching...
No Matches
testDigitIO.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#include <boost/test/tools/old/interface.hpp>
13#include <sstream>
14#include "DigitFileFormat.h"
15#define BOOST_TEST_MODULE Test MCHWorkflow DigitsIO
16#define BOOST_TEST_MAIN
17#define BOOST_TEST_DYN_LINK
18
19#include <boost/test/unit_test.hpp>
20#include <boost/test/data/test_case.hpp>
21#include "DigitIO.h"
22#include <algorithm>
23#include <fmt/format.h>
24#include <fstream>
27#include <cassert>
28#include <array>
29#include <stdexcept>
30#include "DigitSamplerImpl.h"
31#include "IO.h"
32
33using namespace o2::mch;
34using namespace o2::mch::io;
35
37 uint8_t digitVersion,
38 uint8_t digitSize,
39 uint8_t rofVersion,
40 uint8_t rofSize,
41 bool run2ids,
42 bool hasRof)
43{
45 df.fileVersion = fileVersion;
46 df.digitVersion = digitVersion;
47 df.digitSize = digitSize;
48 df.rofVersion = rofVersion;
49 df.rofSize = rofSize;
50 df.run2ids = run2ids;
51 df.hasRof = hasRof;
52 return df;
53}
54
55BOOST_AUTO_TEST_CASE(DigitFileFormatV0Value)
56{
57 DigitFileFormat v0 = createFormat(0, 0, 20, 0, 0, true, false);
59}
60
61BOOST_AUTO_TEST_CASE(DigitFileFormatV1Value)
62{
63 DigitFileFormat v1 = createFormat(1, 0, 20, 1, 16, false, true);
65}
66
67BOOST_AUTO_TEST_CASE(DigitFileFormatV2Value)
68{
69 DigitFileFormat v2 = createFormat(2, 0, 19, 1, 14, false, false);
71}
72
73BOOST_AUTO_TEST_CASE(DigitFileFormatV3Value)
74{
75 DigitFileFormat v3 = createFormat(3, 0, 19, 1, 14, false, true);
77}
78
79BOOST_AUTO_TEST_CASE(DigitFileFormatV4Value)
80{
81 DigitFileFormat v4 = createFormat(4, 0, 19, 2, 18, false, true);
82 BOOST_CHECK_EQUAL(isValid(v4), true);
83}
84
85BOOST_DATA_TEST_CASE(WriteMustReturnFalseIfDigitVectorIsEmpty, digitFileFormats, digitFileFormat)
86{
87 std::ostringstream str;
88 std::vector<ROFRecord> rofs;
89 std::vector<Digit> digits;
90
91 rofs.push_back({});
92
93 DigitSink dwText(str);
94 bool ok = dwText.write(digits, rofs);
95
96 BOOST_CHECK_EQUAL(ok, false);
97
98 DigitSink dwBinary(str, digitFileFormat);
99 ok = dwBinary.write(digits, rofs);
100
101 BOOST_CHECK_EQUAL(ok, false);
102}
103
104BOOST_DATA_TEST_CASE(BinaryWriteMustReturnFalseIfRofVectorIsEmpty, digitFileFormats, digitFileFormat)
105{
106 if (not digitFileFormat.hasRof) {
107 return;
108 }
109 std::ostringstream str;
110 std::vector<ROFRecord> rofs;
111 std::vector<Digit> digits;
112
113 digits.push_back({});
114
115 DigitSink dwBinary(str, digitFileFormat);
116 bool ok = dwBinary.write(digits, rofs);
117
118 BOOST_CHECK_EQUAL(ok, false);
119}
120
126
127BOOST_DATA_TEST_CASE(ReaderMustIdentifyFileFormat, digitFileFormats, digitFileFormat)
128{
129 std::stringstream buffer;
130 buffer.write(reinterpret_cast<const char*>(&digitFileFormat), sizeof(uint64_t));
131 buffer.clear();
132 buffer.seekg(0);
134 BOOST_CHECK_EQUAL(dr.fileFormat(), digitFileFormat);
135}
136
137BOOST_DATA_TEST_CASE(BinaryWriterMustTagCorrectly, digitFileFormats, digitFileFormat)
138{
139 std::stringstream buffer;
140 DigitSink dw(buffer, digitFileFormat);
142 BOOST_CHECK_EQUAL(dr.fileFormat(), digitFileFormat);
143}
144
145std::vector<o2::mch::Digit> createDummyFixedDigits(int n)
146{
147 assert(n < 100);
148 std::vector<Digit> digits;
149 int dummyADC{40};
150 int32_t dummyTime{1000};
151 uint16_t dummySamples{10};
152 for (int i = 0; i < n; i++) {
153 auto& d = digits.emplace_back(100, i, dummyADC + i, dummyTime + i * 100, dummySamples + i * 10);
154 if (i == 7 || i == 23) {
155 d.setSaturated(true);
156 }
157 }
158 return digits;
159}
160
161struct TF {
162 std::vector<Digit> digits;
163 std::vector<ROFRecord> rofs;
164};
165
166TF createDummyData(int ndigits, int nrofs, uint32_t firstOrbit)
167{
168 if (nrofs >= ndigits) {
169 throw std::invalid_argument("cannot have more rofs than digits!");
170 }
171 TF tf;
173 int step = ndigits / nrofs;
174 for (int i = 0; i < nrofs; i++) {
175 o2::InteractionRecord ir(0, firstOrbit + i);
176 tf.rofs.emplace_back(ir, step * i, i == nrofs - 1 ? ndigits - step * i : step);
177 };
178 return tf;
179}
180
187constexpr int NROF_1 = 1;
188constexpr int NROF_2 = 1;
189constexpr int NROF_3 = 1;
190constexpr int NROF_4 = 3;
191constexpr int NROFS = NROF_1 + NROF_2 + NROF_3 + NROF_4;
192
193std::vector<TF> testData{
194 createDummyData(3, NROF_1, 0),
195 createDummyData(5, NROF_2, 10),
196 createDummyData(13, NROF_3, 20),
197 createDummyData(26, NROF_4, 20),
198};
199
200void writeTestData(std::ostream& out, DigitFileFormat dff)
201{
202 auto tfs = testData;
203 DigitSink dw(out, dff);
204 for (auto tf : tfs) {
205 dw.write(tf.digits, tf.rofs);
206 }
207}
208
209BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
210BOOST_DATA_TEST_CASE(TestDataDump, digitFileFormats, digitFileFormat)
211{
212 auto tfs = testData;
213 DigitSink dw(std::cout);
214 for (auto tf : tfs) {
215 dw.write(tf.digits, tf.rofs);
216 }
217 BOOST_CHECK_EQUAL(tfs.size(), testData.size());
218}
219
220BOOST_DATA_TEST_CASE(TestDataIsOfExpectedFormat, digitFileFormats, digitFileFormat)
221{
222 std::stringstream buffer;
223 writeTestData(buffer, digitFileFormat);
225
226 BOOST_CHECK_EQUAL(dr.fileFormat(), digitFileFormat);
227}
228
229BOOST_DATA_TEST_CASE(TestDataHasExpectedNofROFs, digitFileFormats, digitFileFormat)
230{
231 std::stringstream buffer;
232 writeTestData(buffer, digitFileFormat);
234
236}
237
238BOOST_DATA_TEST_CASE(TestDataHasExpectedNofTFs, digitFileFormats, digitFileFormat)
239{
240 std::stringstream buffer;
241 writeTestData(buffer, digitFileFormat);
243
244 if (not digitFileFormat.hasRof) {
246 } else {
248 }
249}
250
251BOOST_DATA_TEST_CASE(TestDataHasExpectedNumberOfDigitsWhenReading, digitFileFormats, digitFileFormat)
252{
253 std::stringstream buffer;
254 writeTestData(buffer, digitFileFormat);
256
257 std::vector<Digit> digits;
258 std::vector<ROFRecord> rofs;
259 int ndigits{0};
260 while (dr.read(digits, rofs)) {
261 ndigits += digits.size();
262 }
263 BOOST_CHECK_EQUAL(ndigits, 47);
264}
265
266BOOST_DATA_TEST_CASE(TestDataHasExpectedNumberOfDigitsWhenCounting, digitFileFormats, digitFileFormat)
267{
268 std::stringstream buffer;
269 writeTestData(buffer, digitFileFormat);
271
273}
274
275BOOST_DATA_TEST_CASE(CheckReader, digitFileFormats, digitFileFormat)
276{
277 std::stringstream buffer;
278 writeTestData(buffer, digitFileFormat);
280
281 std::vector<Digit> digits;
282 std::vector<ROFRecord> rofs;
283
284 std::array<int, 3> digits_per_tf = {3, 5, 13};
285 for (int itf = 0; itf < 3; ++itf) {
286 dr.read(digits, rofs);
287 BOOST_CHECK_EQUAL(digits.size(), digits_per_tf[itf]);
288 BOOST_CHECK_EQUAL(rofs.size(), 1);
289 BOOST_CHECK_EQUAL(rofs[0].getFirstIdx(), 0);
290 BOOST_CHECK_EQUAL(rofs[0].getLastIdx(), digits_per_tf[itf] - 1);
291 }
292 dr.read(digits, rofs);
293 int ndigits_4th_tf = not digitFileFormat.hasRof ? 8 : 26;
294 BOOST_CHECK_EQUAL(digits.size(), ndigits_4th_tf);
295 if (not digitFileFormat.hasRof) {
296 BOOST_CHECK_EQUAL(rofs.size(), 1);
297 BOOST_CHECK_EQUAL(rofs[0].getFirstIdx(), 0);
298 BOOST_CHECK_EQUAL(rofs[0].getLastIdx(), 7);
299 BOOST_CHECK_EQUAL(digits[7].getADC(), 47);
300 BOOST_CHECK_EQUAL(digits[7].isSaturated(), true);
301 } else {
302 BOOST_CHECK_EQUAL(rofs.size(), 3);
303 BOOST_CHECK_EQUAL(rofs[0].getFirstIdx(), 0);
304 BOOST_CHECK_EQUAL(rofs[0].getLastIdx(), 7);
305 BOOST_CHECK_EQUAL(rofs[1].getFirstIdx(), 8);
306 BOOST_CHECK_EQUAL(rofs[1].getLastIdx(), 15);
307 BOOST_CHECK_EQUAL(rofs[2].getFirstIdx(), 16);
308 BOOST_CHECK_EQUAL(rofs[2].getLastIdx(), 25);
309 BOOST_CHECK_EQUAL(digits[23].getADC(), 63);
310 BOOST_CHECK_EQUAL(digits[23].isSaturated(), true);
311 }
312}
unsigned short int uint16_t
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
Definition of the MCH ROFrame record.
uint32_t dummyTime
Definition testDigit.cxx:24
unsigned long dummyADC
Definition testDigit.cxx:23
DigitFileFormat fileFormat() const
bool read(std::vector< Digit > &digits, std::vector< ROFRecord > &rofs)
bool write(gsl::span< const Digit > digits, gsl::span< const ROFRecord > rofs={})
GLdouble n
Definition glcorearb.h:1982
GLuint buffer
Definition glcorearb.h:655
GLfloat v0
Definition glcorearb.h:811
GLfloat GLfloat v1
Definition glcorearb.h:812
GLfloat GLfloat GLfloat GLfloat v3
Definition glcorearb.h:814
GLfloat GLfloat GLfloat v2
Definition glcorearb.h:813
bool isValid(DigitFileFormat dff)
constexpr uint64_t TAG_DIGITS
std::array< DigitFileFormat, 5 > digitFileFormats
BOOST_AUTO_TEST_CASE(FlatHisto)
std::unique_ptr< GPUReconstructionTimeframe > tf
std::vector< ROFRecord > rofs
std::vector< Digit > digits
constexpr int NROF_4
std::vector< TF > testData
constexpr int NROF_2
constexpr int NROFS
constexpr int NROF_3
void writeTestData(std::ostream &out, DigitFileFormat dff)
BOOST_DATA_TEST_CASE(WriteMustReturnFalseIfDigitVectorIsEmpty, digitFileFormats, digitFileFormat)
TF createDummyData(int ndigits, int nrofs, uint32_t firstOrbit)
constexpr int NROF_1
std::vector< o2::mch::Digit > createDummyFixedDigits(int n)
DigitFileFormat createFormat(uint8_t fileVersion, uint8_t digitVersion, uint8_t digitSize, uint8_t rofVersion, uint8_t rofSize, bool run2ids, bool hasRof)
o2::InteractionRecord ir(0, 0)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< Digit > digits
const std::string str