ATLAS Offline Software
Loading...
Searching...
No Matches
BinUtilityTest.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 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
22namespace Trk {
23
30
32 public:
33
35 BinUtilityTest(const std::string& name, ISvcLocator* pSvcLocator);
36
37 /* specify the test here */
38 StatusCode runTest();
39
40 private:
42 void prepareData(std::vector<float>& vec, std::map<float, size_t>& map, float& low, float& high);
43
45 size_t searchInVectorWithBoundary(std::vector<float>& array, float value)
46 {
47 if ( value < array[0] ) return 0;
48 if ( value > array[array.size()-1] ) return (array.size()-1);
49 std::vector<float>::iterator vIter = array.begin();
50 size_t bin = 0;
51 for ( ; vIter != array.end() ; ++vIter, ++bin )
52 if ((*vIter) > value) break;
53 return (bin-1);
54 }
55
57 size_t binarySearchWithBoundary(std::vector<float>& array, float value)
58 {
59 // Binary search in an array of n values to locate value
60 // underflow
61 if ( value < array[0] ) return 0;
62 if ( value > array[array.size()-1] ) return (array.size()-1);
63 // prepare and run
64 size_t nabove, nbelow, middle;
65 // overflow
66 nabove = array.size()+1;
67 if ( value > array[nabove-2]) return nabove-2;
68 // binary search
69 nbelow = 0;
70 while (nabove-nbelow > 1) {
71 middle = (nabove+nbelow)/2;
72 if (value == array[middle-1]) return middle-1;
73 if (value < array[middle-1]) nabove = middle;
74 else nbelow = middle;
75 }
76 return nbelow-1;
77 }
78
81
82 };
83}
84
85#endif
std::vector< size_t > vec
size_t searchInVectorWithBoundary(std::vector< float > &array, float value)
A binary search with a map - superior in O(10) searches.
size_t binarySearchWithBoundary(std::vector< float > &array, float value)
A binary search with underflow/overflow.
void prepareData(std::vector< float > &vec, std::map< float, size_t > &map, float &low, float &high)
preparation of std::vector and std::map for comparison
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
STL class.
Ensure that the ATLAS eigen extensions are properly loaded.