CbmRoot
Loading...
Searching...
No Matches
_GTestCbmDigiTimeslice.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5#include "CbmDigiTimeslice.h"
6#include "CbmStsDigi.h"
7
8#include <boost/archive/binary_iarchive.hpp>
9#include <boost/archive/binary_oarchive.hpp>
10
11#include <array>
12#include <random>
13
14#include "compareStsDigi.h"
15#include "gtest/gtest-spi.h"
16#include "gtest/gtest.h"
17
18TEST(_GTestCbmDigiTimeslice, CheckSerialization)
19{
20
21 // Limits for STS digi member values
22 int32_t maxUnit = (1 << 6) - 1; // 6 bits for address - unit
23 int32_t maxLadd = (1 << 5) - 1; // 5 bits for address - ladder
24 int32_t maxHlad = (1 << 1) - 1; // 1 bit for address - halfladder
25 int32_t maxModu = (1 << 5) - 1; // 5 bits for address - module
26 uint16_t maxChan = (1 << 11) - 1; // 11 bits for channel number
27 int32_t maxTime = (1 << 30) - 1; // 31 bits for time
28 uint16_t maxChrg = (1 << 5) - 1; // 5 bits for ADC
29
30 // Random generator
31 std::random_device rd;
32 std::mt19937 gen(rd());
33 std::uniform_int_distribution<uint64_t> rTsIndex(0); // Timeslice index
34 std::uniform_int_distribution<uint64_t> rTsPos(0); // Timeslice offset
35 std::uniform_int_distribution<uint32_t> rTsNumMs(0); // Number of microslices
36 std::uniform_int_distribution<uint32_t> rTsNumCp(0); // Number of components
37 std::uniform_int_distribution<int32_t> rNumDigis(1, 10); // Number of digis
38 std::uniform_int_distribution<int32_t> rUnit(0, maxUnit); // Digi address: unit
39 std::uniform_int_distribution<int32_t> rLadd(0, maxLadd); // Digi address: ladder
40 std::uniform_int_distribution<int32_t> rHlad(0, maxHlad); // Digi address: halfladder
41 std::uniform_int_distribution<int32_t> rModu(0, maxModu); // Digi address: module
42 std::uniform_int_distribution<uint16_t> rChan(0, maxChan); // Digi channel
43 std::uniform_int_distribution<int32_t> rTime(0, maxTime); // Digi time
44 std::uniform_int_distribution<uint16_t> rChrg(0, maxChrg); // Digi charge
45
46 // Create DigiTimeslice
47 CbmDigiTimeslice tsWrite;
48 uint64_t tsIndex = rTsIndex(gen);
49 uint64_t tsPos = rTsPos(gen);
50 uint32_t tsNumMs = rTsNumMs(gen);
51 uint32_t tsNumCp = rTsNumCp(gen);
52 tsWrite.fDesc.index = tsIndex;
53 tsWrite.fDesc.ts_pos = tsPos;
54 tsWrite.fDesc.num_core_microslices = tsNumMs;
55 tsWrite.fDesc.num_components = tsNumCp;
56
57 // Create a number of STS digis and add them to the event
58 int32_t numDigis = rNumDigis(gen);
59 numDigis = 1;
60 std::vector<int32_t> vAddr(numDigis);
61 std::vector<uint16_t> vChan(numDigis);
62 std::vector<int32_t> vTime(numDigis);
63 std::vector<uint16_t> vChrg(numDigis);
64 for (int32_t iDigi = 0; iDigi < numDigis; iDigi++) {
65 int32_t unit = rUnit(gen);
66 int32_t ladd = rLadd(gen);
67 int32_t hlad = rHlad(gen);
68 int32_t modu = rModu(gen);
69 int32_t addr = CbmStsAddress::GetAddress(unit, ladd, hlad, modu, 0, 0);
70 uint16_t chan = rChan(gen);
71 int32_t time = rTime(gen);
72 uint16_t chrg = rChrg(gen);
73 vAddr[iDigi] = addr;
74 vChan[iDigi] = chan;
75 vTime[iDigi] = time;
76 vChrg[iDigi] = chrg;
77 tsWrite.fData.fSts.fDigis.emplace_back(addr, chan, time, chrg);
78 }
79
80 // Serialize timeslice to string
81 std::stringstream s;
82 boost::archive::binary_oarchive outArchive(s);
83 outArchive << tsWrite;
84
85 // Deserialize event from string
86 CbmDigiTimeslice tsRead;
87 boost::archive::binary_iarchive inArchive(s);
88 inArchive >> tsRead;
89
90 // Compare output and input
91 EXPECT_EQ(tsRead.fDesc.index, tsIndex);
92 EXPECT_EQ(tsRead.fDesc.ts_pos, tsPos);
93 EXPECT_EQ(tsRead.fDesc.num_core_microslices, tsNumMs);
94 EXPECT_EQ(tsRead.fDesc.num_components, tsNumCp);
95 for (int32_t iDigi = 0; iDigi < numDigis; iDigi++) {
96 compareStsDigiDataMembers(tsRead.fData.fSts.fDigis[iDigi], vAddr[iDigi], vChrg[iDigi], vChan[iDigi],
97 ECbmModuleId::kSts, vTime[iDigi]);
98 }
99}
@ kSts
Silicon Tracking System.
TEST(_GTestCbmDigiTimeslice, CheckSerialization)
CbmStsDigiData fSts
STS data.
Definition CbmDigiData.h:36
Collection of digis from all detector systems within one timeslice.
CbmDigiData fData
Timeslice data.
fles::TimesliceDescriptor fDesc
Timeslice descriptor (metadata)
std::vector< CbmStsDigi > fDigis
Data vector.
void compareStsDigiDataMembers(CbmStsDigi &test, int32_t address, uint16_t charge, uint16_t channel, ECbmModuleId systemid, int64_t time)
int32_t GetAddress(uint32_t unit=0, uint32_t ladder=0, uint32_t halfladder=0, uint32_t module=0, uint32_t sensor=0, uint32_t side=0, uint32_t version=kCurrentVersion)
Construct address.