CbmRoot
Loading...
Searching...
No Matches
_GTestCbmDigiEvent.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 "CbmDigiEvent.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(_GTestCbmDigiEvent, 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<int32_t> rEvtNumber(1, 1000); // Event number
34 std::uniform_real_distribution<double> rEvtTime(0., 1.e10); // Event time
35 std::uniform_int_distribution<int32_t> rNumDigis(1, 10); // Number of digis
36 std::uniform_int_distribution<int32_t> rUnit(0, maxUnit); // Digi address: unit
37 std::uniform_int_distribution<int32_t> rLadd(0, maxLadd); // Digi address: ladder
38 std::uniform_int_distribution<int32_t> rHlad(0, maxHlad); // Digi address: halfladder
39 std::uniform_int_distribution<int32_t> rModu(0, maxModu); // Digi address: module
40 std::uniform_int_distribution<uint16_t> rChan(0, maxChan); // Digi channel
41 std::uniform_int_distribution<int32_t> rTime(0, maxTime); // Digi time
42 std::uniform_int_distribution<uint16_t> rChrg(0, maxChrg); // Digi charge
43
44 // Create DigiEvent
45 CbmDigiEvent eventOut;
46 int32_t evtNumber = rEvtNumber(gen);
47 double evtTime = rEvtTime(gen);
48 eventOut.fNumber = evtNumber;
49 eventOut.fTime = evtTime;
50
51 // Create a number of STS digis and add them to the event
52 int32_t numDigis = rNumDigis(gen);
53 std::vector<int32_t> vAddr(numDigis);
54 std::vector<uint16_t> vChan(numDigis);
55 std::vector<int32_t> vTime(numDigis);
56 std::vector<uint16_t> vChrg(numDigis);
57 for (int32_t iDigi = 0; iDigi < numDigis; iDigi++) {
58 int32_t unit = rUnit(gen);
59 int32_t ladd = rLadd(gen);
60 int32_t hlad = rHlad(gen);
61 int32_t modu = rModu(gen);
62 int32_t addr = CbmStsAddress::GetAddress(unit, ladd, hlad, modu, 0, 0);
63 uint16_t chan = rChan(gen);
64 int32_t time = rTime(gen);
65 uint16_t chrg = rChrg(gen);
66 vAddr[iDigi] = addr;
67 vChan[iDigi] = chan;
68 vTime[iDigi] = time;
69 vChrg[iDigi] = chrg;
70 eventOut.fData.fSts.fDigis.emplace_back(addr, chan, time, chrg);
71 }
72
73 // Serialize event to string
74 std::stringstream s;
75 boost::archive::binary_oarchive outArchive(s);
76 outArchive << eventOut;
77
78 // Deserialize event from string
79 CbmDigiEvent eventIn;
80 boost::archive::binary_iarchive inArchive(s);
81 inArchive >> eventIn;
82
83 // Compare output and input
84 EXPECT_EQ(eventIn.fNumber, evtNumber);
85 EXPECT_FLOAT_EQ(eventIn.fTime, evtTime);
86 EXPECT_EQ(eventIn.fData.fSts.fDigis.size(), numDigis);
87 for (int32_t iDigi = 0; iDigi < numDigis; iDigi++) {
88 compareStsDigiDataMembers(eventIn.fData.fSts.fDigis[iDigi], vAddr[iDigi], vChrg[iDigi], vChan[iDigi],
89 ECbmModuleId::kSts, vTime[iDigi]);
90 }
91}
@ kSts
Silicon Tracking System.
TEST(_GTestCbmDigiEvent, CheckSerialization)
CbmStsDigiData fSts
STS data.
Definition CbmDigiData.h:36
Collection of digis from all detector systems within one event.
double fTime
Event trigger time [ns].
CbmDigiData fData
Event data.
uint64_t fNumber
Event identifier.
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.