Project
Loading...
Searching...
No Matches
testDigitIOV0.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 - V0
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 "TestFileV0.h"
32#include "DigitD0.h"
33#include "IO.h"
34
35using namespace o2::mch;
36using namespace o2::mch::io;
37
38void bin2cpp(const char* filename = "digits.v3.in")
39{
40 // filename must point to a V0 format
41 std::ifstream in(filename);
42 int ndig;
43 int pos{8};
44 int event{0};
45 in.seekg(8);
46 while ((ndig = o2::mch::io::impl::advance(in, digitFileFormats[0].digitSize, "digits")) >= 0) {
47 int next = in.tellg();
48 if (ndig < 40 || ndig == 96) {
49 std::cout << fmt::format("Event {:4d} {} ndigits between {} and {}\n", event, ndig, pos, next);
50 }
51 pos = next;
52 event++;
53 }
54 struct a {
55 int start, end;
56 };
57 std::array<a, 2> positions = {a{17707576, 17708160}, a{38707380, 38708064}};
58 std::vector<uint8_t> bytes;
59 int i{1};
60 for (auto p : positions) {
61 in.seekg(p.start);
62 int n = p.end - p.start;
63 bytes.resize(n);
64 in.read(reinterpret_cast<char*>(&bytes[0]), n);
65 if (in.tellg() != p.end) {
66 std::cout << "lost in file!\n";
67 exit(1);
68 }
69 for (auto b : bytes) {
70 std::cout << fmt::format("0x{:02X},", b);
71 if (i % 16 == 0) {
72 std::cout << "\n";
73 }
74 i++;
75 }
76 }
77 std::cout << "i=" << i << "\n";
78}
79
80BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
82{
83 bin2cpp();
84}
85struct V0File {
87 {
88 std::ostringstream buffer;
89 for (auto b : v0_buffer) {
90 buffer << b;
91 }
92 std::istringstream in(buffer.str());
93 DigitSampler r(in);
94 r.read(digits[0], rofs[0]);
95 r.read(digits[1], rofs[1]);
96 }
97 std::array<std::vector<o2::mch::Digit>, 2> digits;
98 std::array<std::vector<o2::mch::ROFRecord>, 2> rofs;
99};
100
101BOOST_AUTO_TEST_CASE(CheckStructOffsets)
102{
103 BOOST_CHECK_EQUAL(offsetof(o2::mch::io::impl::DigitD0, tfTime), 0);
104 BOOST_CHECK_EQUAL(offsetof(o2::mch::io::impl::DigitD0, nofSamples), 4);
106 BOOST_CHECK_EQUAL(offsetof(o2::mch::io::impl::DigitD0, padID), 12);
109}
110
111BOOST_FIXTURE_TEST_SUITE(SpotCheckV0, V0File)
112
113BOOST_AUTO_TEST_CASE(SpotCheckSizesV0)
114{
115 BOOST_CHECK_EQUAL(digits[0].size(), 29);
116 BOOST_CHECK_EQUAL(digits[1].size(), 34);
117
118 BOOST_CHECK_EQUAL(rofs[0].size(), 1);
119 BOOST_CHECK_EQUAL(rofs[1].size(), 1);
120
121 BOOST_CHECK_EQUAL(digits[0][20].getDetID(), 712);
122 BOOST_CHECK_EQUAL(digits[1][31].getDetID(), 1024);
123}
124
125BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
126BOOST_AUTO_TEST_CASE(SpotCheckDumpV0)
127{
128 DigitSink w(std::cout);
129 w.write(digits[0], rofs[0]);
130 w.write(digits[1], rofs[1]);
131}
132
133BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
134BOOST_AUTO_TEST_CASE(SpotCheckDetIDV0)
135{
136 BOOST_CHECK_EQUAL(digits[0][20].getDetID(), 712);
137 BOOST_CHECK_EQUAL(digits[1][31].getDetID(), 1024);
138}
139
140BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
141BOOST_AUTO_TEST_CASE(SpotCheckPadIDV0)
142{
143 BOOST_CHECK_EQUAL(digits[0][20].getPadID(), 1661387464);
144 BOOST_CHECK_EQUAL(digits[1][31].getPadID(), 268444672);
145}
146
147BOOST_TEST_DECORATOR(*boost::unit_test::disabled())
148BOOST_AUTO_TEST_CASE(SpotCheckADCV0)
149{
150 BOOST_CHECK_EQUAL(digits[0][20].getADC(), 1063648290);
151 BOOST_CHECK_EQUAL(digits[1][31].getADC(), 1065400059);
152}
153
154BOOST_AUTO_TEST_SUITE_END()
int32_t i
Definition of the MCH ROFrame record.
uint16_t pos
Definition RawData.h:3
std::array< uint8_t, 1276 > v0_buffer
struct _cl_event * event
Definition glcorearb.h:2982
GLdouble n
Definition glcorearb.h:1982
GLuint buffer
Definition glcorearb.h:655
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean r
Definition glcorearb.h:1233
GLuint start
Definition glcorearb.h:469
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
int advance(std::istream &in, size_t itemByteSize, const char *itemName)
Definition IO.cxx:35
std::array< DigitFileFormat, 5 > digitFileFormats
BOOST_AUTO_TEST_CASE(FlatHisto)
std::string filename()
std::array< std::vector< o2::mch::ROFRecord >, 2 > rofs
std::array< std::vector< o2::mch::Digit >, 2 > digits
void bin2cpp(const char *filename="digits.v3.in")
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< Digit > digits
ArrayADC adc