ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkDetDescrUnitTests
TrkDetDescrUnitTests
BinUtilityTest.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// BinUtilityTest.h, (c) ATLAS Detector software
8
9
#ifndef TRKDETDESCRUNITTESTS_BinUtilityTEST_H
10
#define TRKDETDESCRUNITTESTS_BinUtilityTEST_H
11
12
// Athena & Gaudi includes
13
#include "GaudiKernel/ServiceHandle.h"
14
#include "GaudiKernel/ToolHandle.h"
15
// Trk includes
16
#include "
TrkDetDescrUnitTests/TrkDetDescrUnitTestBase.h
"
17
#include "
TrkDetDescrInterfaces/ISurfaceBuilder.h
"
18
19
#include <vector>
20
#include <map>
21
#include <algorithm>
22
#include <stdexcept>
23
24
namespace
Trk
{
25
32
33
class
BinUtilityTest
:
public
TrkDetDescrUnitTestBase
{
34
public
:
35
37
BinUtilityTest
(
const
std::string& name, ISvcLocator* pSvcLocator);
38
39
/* specify the test here */
40
StatusCode
runTest
();
41
42
private
:
44
void
prepareData
(std::vector<float>&
vec
, std::map<float, std::size_t>&
map
,
float
& low,
float
& high);
45
47
std::size_t
searchInVectorWithBoundary
(std::vector<float>&
v
,
float
value)
48
{
49
if
(
v
.empty())[[
unlikely
]]{
50
throw
std::runtime_error(
"searchInVectorWithBoundary: vector is empty"
);
51
}
52
std::size_t
bin
{};
53
while
(
bin
<
v
.size() &&
v
[
bin
] < value){
54
++
bin
;
55
}
56
return
bin
== 0 ? 0 : std::min(
bin
- 1,
v
.size() - 1);
57
}
58
60
std::size_t
binarySearchWithBoundary
(
const
std::vector<float>&
v
,
float
value)
61
{
62
if
(
v
.empty())[[
unlikely
]]{
63
throw
std::runtime_error(
"binarySearchWithBoundary: vector is empty"
);
64
}
65
const
auto
it = std::upper_bound(
v
.begin(),
v
.end(), value);
66
if
(it ==
v
.begin()){
67
return
0;
68
}
69
return
std::min<std::size_t>(std::distance(
v
.begin(), it) - 1,
70
v
.size() - 1);
71
}
72
73
std::size_t
m_numberOfSegments
{};
74
std::size_t
m_numberOfTestsPerSet
{};
75
76
};
77
}
78
79
#endif
vec
std::vector< size_t > vec
Definition
CombinationsGeneratorTest.cxx:9
ISurfaceBuilder.h
TrkDetDescrUnitTestBase.h
Trk::BinUtilityTest::binarySearchWithBoundary
std::size_t binarySearchWithBoundary(const std::vector< float > &v, float value)
A binary search with underflow/overflow.
Definition
BinUtilityTest.h:60
Trk::BinUtilityTest::m_numberOfSegments
std::size_t m_numberOfSegments
Definition
BinUtilityTest.h:73
Trk::BinUtilityTest::BinUtilityTest
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition
BinUtilityTest.cxx:13
Trk::BinUtilityTest::m_numberOfTestsPerSet
std::size_t m_numberOfTestsPerSet
Definition
BinUtilityTest.h:74
Trk::BinUtilityTest::prepareData
void prepareData(std::vector< float > &vec, std::map< float, std::size_t > &map, float &low, float &high)
preparation of std::vector and std::map for comparison
Definition
BinUtilityTest.cxx:66
Trk::BinUtilityTest::runTest
StatusCode runTest()
Definition
BinUtilityTest.cxx:24
Trk::BinUtilityTest::searchInVectorWithBoundary
std::size_t searchInVectorWithBoundary(std::vector< float > &v, float value)
A linear search - superior in O(10) searches.
Definition
BinUtilityTest.h:47
Trk::TrkDetDescrUnitTestBase::TrkDetDescrUnitTestBase
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition
TrkDetDescrUnitTestBase.cxx:12
bin
Definition
BinsDiffFromStripMedian.h:43
map
STL class.
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition
FakeTrackBuilder.h:9
Trk::v
@ v
Definition
ParamDefs.h:78
unlikely
#define unlikely(x)
Definition
pythonic_coracool.cxx:9
Generated on
for ATLAS Offline Software by
1.17.0