Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pierre-Alain Loizeau
cbmroot
Commits
854e0124
Commit
854e0124
authored
Oct 26, 2021
by
Volker Friese
Browse files
Introduce unit tests for CbmDigiEvent and CbmDigiTimeslice. Refs
#2261
.
parent
c2c404b4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
284 additions
and
7 deletions
+284
-7
core/data/base/CbmDigiData.h
core/data/base/CbmDigiData.h
+1
-0
core/data/test/CMakeLists.txt
core/data/test/CMakeLists.txt
+8
-7
core/data/test/global/CMakeLists.txt
core/data/test/global/CMakeLists.txt
+69
-0
core/data/test/global/_GTestCbmDigiEvent.cxx
core/data/test/global/_GTestCbmDigiEvent.cxx
+91
-0
core/data/test/global/_GTestCbmDigiTimeslice.cxx
core/data/test/global/_GTestCbmDigiTimeslice.cxx
+99
-0
core/data/test/sts/_GTestCbmStsDigi.cxx
core/data/test/sts/_GTestCbmStsDigi.cxx
+16
-0
No files found.
core/data/base/CbmDigiData.h
View file @
854e0124
...
...
@@ -9,6 +9,7 @@
#include "CbmStsDigi.h"
#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include <vector>
...
...
core/data/test/CMakeLists.txt
View file @
854e0124
...
...
@@ -20,17 +20,22 @@ EndMacro(CreateGTestExeAndAddTest)
FIND_PACKAGE
(
Threads REQUIRED
)
add_subdirectory
(
global
)
add_subdirectory
(
psd
)
add_subdirectory
(
trd
)
Set
(
INCLUDE_DIRECTORIES
${
CBMBASE_DIR
}
${
CBMDATA_DIR
}
${
CBMDATA_DIR
}
/base
${
CBMDATA_DIR
}
/global
${
CBMDATA_DIR
}
/sts
${
CBMDATA_DIR
}
/tof
${
CBMDATA_DIR
}
/rich
${
CBMDATA_DIR
}
/much
${
CBMDATA_DIR
}
/test/sts
${
CBMDATA_DIR
}
/test/global
${
CMAKE_SOURCE_DIR
}
/external/ipc/ipc/lib/fles_ipc
${
BASE_INCLUDE_DIRECTORIES
}
${
GTEST_INCLUDE_DIR
}
)
...
...
@@ -55,6 +60,7 @@ Set(DEPENDENCIES
GeoBase
MbsAPI
${
CMAKE_THREAD_LIBS_INIT
}
boost_serialization
)
set
(
SPECIAL_DEPENDENCIES
...
...
@@ -77,6 +83,8 @@ if (CMAKE_SYSTEM_NAME MATCHES Linux)
set
(
DEPENDENCIES
${
DEPENDENCIES
}
rt
)
endif
()
Set
(
CbmLinkSources
${
CBMDATA_DIR
}
/CbmLink.cxx
_GTestCbmLink.cxx
...
...
@@ -159,13 +167,6 @@ Set(CbmAddressSources
CreateGTestExeAndAddTest
(
_GTestCbmAddress
"
${
INCLUDE_DIRECTORIES
}
"
"
${
LINK_DIRECTORIES
}
"
"
${
CbmAddressSources
}
"
"
${
DEPENDENCIES
}
"
"_GTestCbmErrorMessage"
)
Set
(
CbmVertexSources
${
CBMDATA_DIR
}
/global/CbmVertex.cxx
global/_GTestCbmVertex.cxx
)
CreateGTestExeAndAddTest
(
_GTestCbmVertex
"
${
INCLUDE_DIRECTORIES
}
"
"
${
LINK_DIRECTORIES
}
"
"
${
CbmVertexSources
}
"
"
${
DEPENDENCIES
}
"
"_GTestCbmAddress"
)
#Set(CbmModuleListSources
...
...
core/data/test/global/CMakeLists.txt
0 → 100644
View file @
854e0124
# --- CMake steering file for core/data/test/global
# --- V. Friese, 2021
Set
(
INCLUDE_DIRECTORIES
${
CBMDATA_DIR
}
${
CBMDATA_DIR
}
/base
${
CBMDATA_DIR
}
/global
${
CBMDATA_DIR
}
/sts
${
CBMDATA_DIR
}
/test/sts
${
CMAKE_SOURCE_DIR
}
/external/ipc/ipc/lib/fles_ipc
${
BASE_INCLUDE_DIRECTORIES
}
${
GTEST_INCLUDE_DIR
}
)
MESSAGE
(
"FAIRROOT_LIBRARY_DIR:
${
FAIRROOT_LIBRARY_DIR
}
"
)
Set
(
LINK_DIRECTORIES
${
ROOT_LIBRARY_DIR
}
${
FAIRROOT_LIBRARY_DIR
}
${
SIMPATH
}
/lib
)
Set
(
DEPENDENCIES
Core
Matrix
Physics
${
GTEST_BOTH_LIBRARIES
}
FairTools
CbmData
boost_serialization
${
CMAKE_THREAD_LIBS_INIT
}
)
If
(
FAIRLOGGER_FOUND
)
set
(
DEPENDENCIES
${
DEPENDENCIES
}
FairLogger
)
EndIf
()
if
(
CMAKE_SYSTEM_NAME MATCHES Linux
)
set
(
DEPENDENCIES
${
DEPENDENCIES
}
rt
)
endif
()
# --- Test CbmDigiEvent
Set
(
CbmDigiEventSources
${
CBMDATA_DIR
}
/global/CbmDigiEvent.h
_GTestCbmDigiEvent.cxx
)
CreateGTestExeAndAddTest
(
_GTestCbmDigiEvent
"
${
INCLUDE_DIRECTORIES
}
"
"
${
LINK_DIRECTORIES
}
"
"
${
CbmDigiEventSources
}
"
"
${
DEPENDENCIES
}
"
""
)
# --- Test CbmDigiTimeslice
Set
(
CbmDigiTimesliceSources
${
CBMDATA_DIR
}
/global/CbmDigiTimeslice.h
_GTestCbmDigiTimeslice.cxx
)
CreateGTestExeAndAddTest
(
_GTestCbmDigiTimeslice
"
${
INCLUDE_DIRECTORIES
}
"
"
${
LINK_DIRECTORIES
}
"
"
${
CbmDigiTimesliceSources
}
"
"
${
DEPENDENCIES
}
"
"_GTestCbmDigiEvent"
)
# --- Test CbmVertex
Set
(
CbmVertexSources
${
CBMDATA_DIR
}
/global/CbmVertex.cxx
_GTestCbmVertex.cxx
)
CreateGTestExeAndAddTest
(
_GTestCbmVertex
"
${
INCLUDE_DIRECTORIES
}
"
"
${
LINK_DIRECTORIES
}
"
"
${
CbmVertexSources
}
"
"
${
DEPENDENCIES
}
"
"_GTestCbmDigiTimeslice"
)
core/data/test/global/_GTestCbmDigiEvent.cxx
0 → 100644
View file @
854e0124
/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Volker Friese [committer] */
#include "CbmDigiEvent.h"
#include "CbmStsDigi.h"
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <array>
#include <random>
#include "compareStsDigi.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
TEST
(
_GTestCbmDigiEvent
,
CheckSerialization
)
{
// Limits for STS digi member values
int32_t
maxUnit
=
(
1
<<
6
)
-
1
;
// 6 bits for address - unit
int32_t
maxLadd
=
(
1
<<
5
)
-
1
;
// 5 bits for address - ladder
int32_t
maxHlad
=
(
1
<<
1
)
-
1
;
// 1 bit for address - halfladder
int32_t
maxModu
=
(
1
<<
5
)
-
1
;
// 5 bits for address - module
uint16_t
maxChan
=
(
1
<<
11
)
-
1
;
// 11 bits for channel number
int32_t
maxTime
=
(
1
<<
30
)
-
1
;
// 31 bits for time
uint16_t
maxChrg
=
(
1
<<
5
)
-
1
;
// 5 bits for ADC
// Random generator
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<
int32_t
>
rEvtNumber
(
1
,
1000
);
// Event number
std
::
uniform_real_distribution
<
double
>
rEvtTime
(
0.
,
1.e10
);
// Event time
std
::
uniform_int_distribution
<
int32_t
>
rNumDigis
(
1
,
10
);
// Number of digis
std
::
uniform_int_distribution
<
int32_t
>
rUnit
(
0
,
maxUnit
);
// Digi address: unit
std
::
uniform_int_distribution
<
int32_t
>
rLadd
(
0
,
maxLadd
);
// Digi address: ladder
std
::
uniform_int_distribution
<
int32_t
>
rHlad
(
0
,
maxHlad
);
// Digi address: halfladder
std
::
uniform_int_distribution
<
int32_t
>
rModu
(
0
,
maxModu
);
// Digi address: module
std
::
uniform_int_distribution
<
uint16_t
>
rChan
(
0
,
maxChan
);
// Digi channel
std
::
uniform_int_distribution
<
int32_t
>
rTime
(
0
,
maxTime
);
// Digi time
std
::
uniform_int_distribution
<
uint16_t
>
rChrg
(
0
,
maxChrg
);
// Digi charge
// Create DigiEvent
CbmDigiEvent
eventOut
;
int32_t
evtNumber
=
rEvtNumber
(
gen
);
double
evtTime
=
rEvtTime
(
gen
);
eventOut
.
fNumber
=
evtNumber
;
eventOut
.
fTime
=
evtTime
;
// Create a number of STS digis and add them to the event
int32_t
numDigis
=
rNumDigis
(
gen
);
std
::
vector
<
int32_t
>
vAddr
(
numDigis
);
std
::
vector
<
uint16_t
>
vChan
(
numDigis
);
std
::
vector
<
int32_t
>
vTime
(
numDigis
);
std
::
vector
<
uint16_t
>
vChrg
(
numDigis
);
for
(
int32_t
iDigi
=
0
;
iDigi
<
numDigis
;
iDigi
++
)
{
int32_t
unit
=
rUnit
(
gen
);
int32_t
ladd
=
rLadd
(
gen
);
int32_t
hlad
=
rHlad
(
gen
);
int32_t
modu
=
rModu
(
gen
);
int32_t
addr
=
CbmStsAddress
::
GetAddress
(
unit
,
ladd
,
hlad
,
modu
,
0
,
0
);
uint16_t
chan
=
rChan
(
gen
);
int32_t
time
=
rTime
(
gen
);
uint16_t
chrg
=
rChrg
(
gen
);
vAddr
[
iDigi
]
=
addr
;
vChan
[
iDigi
]
=
chan
;
vTime
[
iDigi
]
=
time
;
vChrg
[
iDigi
]
=
chrg
;
eventOut
.
fData
.
fSts
.
fDigis
.
emplace_back
(
addr
,
chan
,
time
,
chrg
);
}
// Serialize event to string
std
::
stringstream
s
;
boost
::
archive
::
binary_oarchive
outArchive
(
s
);
outArchive
<<
eventOut
;
// Deserialize event from string
CbmDigiEvent
eventIn
;
boost
::
archive
::
binary_iarchive
inArchive
(
s
);
inArchive
>>
eventIn
;
// Compare output and input
EXPECT_EQ
(
eventIn
.
fNumber
,
evtNumber
);
EXPECT_FLOAT_EQ
(
eventIn
.
fTime
,
evtTime
);
EXPECT_EQ
(
eventIn
.
fData
.
fSts
.
fDigis
.
size
(),
numDigis
);
for
(
int32_t
iDigi
=
0
;
iDigi
<
numDigis
;
iDigi
++
)
{
compareStsDigiDataMembers
(
eventIn
.
fData
.
fSts
.
fDigis
[
iDigi
],
vAddr
[
iDigi
],
vChrg
[
iDigi
],
vChan
[
iDigi
],
ECbmModuleId
::
kSts
,
vTime
[
iDigi
]);
}
}
core/data/test/global/_GTestCbmDigiTimeslice.cxx
0 → 100644
View file @
854e0124
/* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Volker Friese [committer] */
#include "CbmDigiTimeslice.h"
#include "CbmStsDigi.h"
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <array>
#include <random>
#include "compareStsDigi.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
TEST
(
_GTestCbmDigiTimeslice
,
CheckSerialization
)
{
// Limits for STS digi member values
int32_t
maxUnit
=
(
1
<<
6
)
-
1
;
// 6 bits for address - unit
int32_t
maxLadd
=
(
1
<<
5
)
-
1
;
// 5 bits for address - ladder
int32_t
maxHlad
=
(
1
<<
1
)
-
1
;
// 1 bit for address - halfladder
int32_t
maxModu
=
(
1
<<
5
)
-
1
;
// 5 bits for address - module
uint16_t
maxChan
=
(
1
<<
11
)
-
1
;
// 11 bits for channel number
int32_t
maxTime
=
(
1
<<
30
)
-
1
;
// 31 bits for time
uint16_t
maxChrg
=
(
1
<<
5
)
-
1
;
// 5 bits for ADC
// Random generator
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<
uint64_t
>
rTsIndex
(
0
);
// Timeslice index
std
::
uniform_int_distribution
<
uint64_t
>
rTsPos
(
0
);
// Timeslice offset
std
::
uniform_int_distribution
<
uint32_t
>
rTsNumMs
(
0
);
// Number of microslices
std
::
uniform_int_distribution
<
uint32_t
>
rTsNumCp
(
0
);
// Number of components
std
::
uniform_int_distribution
<
int32_t
>
rNumDigis
(
1
,
10
);
// Number of digis
std
::
uniform_int_distribution
<
int32_t
>
rUnit
(
0
,
maxUnit
);
// Digi address: unit
std
::
uniform_int_distribution
<
int32_t
>
rLadd
(
0
,
maxLadd
);
// Digi address: ladder
std
::
uniform_int_distribution
<
int32_t
>
rHlad
(
0
,
maxHlad
);
// Digi address: halfladder
std
::
uniform_int_distribution
<
int32_t
>
rModu
(
0
,
maxModu
);
// Digi address: module
std
::
uniform_int_distribution
<
uint16_t
>
rChan
(
0
,
maxChan
);
// Digi channel
std
::
uniform_int_distribution
<
int32_t
>
rTime
(
0
,
maxTime
);
// Digi time
std
::
uniform_int_distribution
<
uint16_t
>
rChrg
(
0
,
maxChrg
);
// Digi charge
// Create DigiTimeslice
CbmDigiTimeslice
tsWrite
;
uint64_t
tsIndex
=
rTsIndex
(
gen
);
uint64_t
tsPos
=
rTsPos
(
gen
);
uint32_t
tsNumMs
=
rTsNumMs
(
gen
);
uint32_t
tsNumCp
=
rTsNumCp
(
gen
);
tsWrite
.
fDesc
.
index
=
tsIndex
;
tsWrite
.
fDesc
.
ts_pos
=
tsPos
;
tsWrite
.
fDesc
.
num_core_microslices
=
tsNumMs
;
tsWrite
.
fDesc
.
num_components
=
tsNumCp
;
// Create a number of STS digis and add them to the event
int32_t
numDigis
=
rNumDigis
(
gen
);
numDigis
=
1
;
std
::
vector
<
int32_t
>
vAddr
(
numDigis
);
std
::
vector
<
uint16_t
>
vChan
(
numDigis
);
std
::
vector
<
int32_t
>
vTime
(
numDigis
);
std
::
vector
<
uint16_t
>
vChrg
(
numDigis
);
for
(
int32_t
iDigi
=
0
;
iDigi
<
numDigis
;
iDigi
++
)
{
int32_t
unit
=
rUnit
(
gen
);
int32_t
ladd
=
rLadd
(
gen
);
int32_t
hlad
=
rHlad
(
gen
);
int32_t
modu
=
rModu
(
gen
);
int32_t
addr
=
CbmStsAddress
::
GetAddress
(
unit
,
ladd
,
hlad
,
modu
,
0
,
0
);
uint16_t
chan
=
rChan
(
gen
);
int32_t
time
=
rTime
(
gen
);
uint16_t
chrg
=
rChrg
(
gen
);
vAddr
[
iDigi
]
=
addr
;
vChan
[
iDigi
]
=
chan
;
vTime
[
iDigi
]
=
time
;
vChrg
[
iDigi
]
=
chrg
;
tsWrite
.
fData
.
fSts
.
fDigis
.
emplace_back
(
addr
,
chan
,
time
,
chrg
);
}
// Serialize timeslice to string
std
::
stringstream
s
;
boost
::
archive
::
binary_oarchive
outArchive
(
s
);
outArchive
<<
tsWrite
;
// Deserialize event from string
CbmDigiTimeslice
tsRead
;
boost
::
archive
::
binary_iarchive
inArchive
(
s
);
inArchive
>>
tsRead
;
// Compare output and input
EXPECT_EQ
(
tsRead
.
fDesc
.
index
,
tsIndex
);
EXPECT_EQ
(
tsRead
.
fDesc
.
ts_pos
,
tsPos
);
EXPECT_EQ
(
tsRead
.
fDesc
.
num_core_microslices
,
tsNumMs
);
EXPECT_EQ
(
tsRead
.
fDesc
.
num_components
,
tsNumCp
);
for
(
int32_t
iDigi
=
0
;
iDigi
<
numDigis
;
iDigi
++
)
{
compareStsDigiDataMembers
(
tsRead
.
fData
.
fSts
.
fDigis
[
iDigi
],
vAddr
[
iDigi
],
vChrg
[
iDigi
],
vChan
[
iDigi
],
ECbmModuleId
::
kSts
,
vTime
[
iDigi
]);
}
}
core/data/test/sts/_GTestCbmStsDigi.cxx
View file @
854e0124
...
...
@@ -5,12 +5,16 @@
#include "CbmStsAddress.h"
#include "CbmStsDigi.h"
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include "compareStsDigi.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
static
const
Int_t
kTestAddress
=
CbmStsAddress
::
GetAddress
(
5
,
6
,
1
,
8
,
0
,
0
,
1
);
TEST
(
_GTestCbmStsDigi
,
CheckDefaultConstructor
)
{
// Create object
...
...
@@ -143,3 +147,15 @@ TEST(_GTestCbmStsDigi, CheckGetClassName)
EXPECT_STREQ
(
"CbmStsDigi"
,
test
.
GetClassName
());
}
TEST
(
_GTestCbmStsDigi
,
CheckSerialization
)
{
CbmStsDigi
write
(
kTestAddress
,
42
,
987654321
,
23
);
std
::
stringstream
s
;
boost
::
archive
::
binary_oarchive
outArchive
(
s
);
outArchive
<<
write
;
CbmStsDigi
read
;
boost
::
archive
::
binary_iarchive
inArchive
(
s
);
inArchive
>>
read
;
compareStsDigiDataMembers
(
read
,
kTestAddress
,
23
,
42
,
ECbmModuleId
::
kSts
,
987654321
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment