ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
19#include <vector>
20#include <map>
21#include <algorithm>
22#include <stdexcept>
23
24namespace Trk {
25
32
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
std::vector< size_t > vec
std::size_t binarySearchWithBoundary(const std::vector< float > &v, float value)
A binary search with underflow/overflow.
std::size_t m_numberOfSegments
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
std::size_t m_numberOfTestsPerSet
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
std::size_t searchInVectorWithBoundary(std::vector< float > &v, float value)
A linear search - superior in O(10) searches.
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
STL class.
Ensure that the ATLAS eigen extensions are properly loaded.
@ v
Definition ParamDefs.h:78
#define unlikely(x)