ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonCalib
MdtCalib
MdtCalibUtils
MdtCalibUtils
LookUpTable.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef LOOKUPTABLE_H
6
#define LOOKUPTABLE_H
7
8
#include <algorithm>
9
#include <functional>
10
#include <iostream>
11
#include <iterator>
12
#include <vector>
13
20
21
template
<
class
T,
class
C = std::less<T> >
class
LookUpTable
{
22
public
:
23
typedef
T
val_type
;
24
typedef
std::vector<val_type>
vec_type
;
25
typedef
std::pair<val_type, val_type>
pair_type
;
26
// typename Data::iterator DataIt;
27
typedef
typename
vec_type::iterator
vec_type_it
;
28
typedef
typename
vec_type::const_iterator
vec_type_cit
;
29
30
LookUpTable
() =
default
;
31
~LookUpTable
() =
default
;
32
33
bool
empty
()
const
{
return
m_data
.empty(); }
34
35
void
setData
(
const
vec_type
& data);
36
const
vec_type
&
getData
()
const
{
return
m_data
; }
37
38
vec_type_it
begin
() {
return
m_data
.begin(); }
39
vec_type_it
end
() {
return
m_data
.end(); }
40
vec_type_cit
begin
()
const
{
return
m_data
.begin(); }
41
vec_type_cit
end
()
const
{
return
m_data
.end(); }
42
43
vec_type_cit
lowerBound
(
const
val_type
& val);
44
pair_type
find
(
const
val_type
& val)
const
;
45
46
template
<
class
CC>
pair_type
find
(
const
val_type
& val,
const
CC& c)
const
{
47
vec_type_cit
it = lower_bound(
m_data
.begin(),
m_data
.end(), val, c);
48
if
(it ==
m_data
.end())
49
return
std::make_pair(*(it - 2), *(it - 1));
50
else
if
(it ==
m_data
.begin())
51
return
std::make_pair(*it, *(it + 1));
52
else
53
return
std::make_pair(*(it - 1), *it);
54
}
55
56
private
:
57
vec_type
m_data
;
58
};
59
60
template
<
class
T,
class
C>
inline
void
LookUpTable<T, C>::setData
(
const
vec_type
& data) {
61
m_data
.assign(data.begin(), data.end());
62
sort
(
m_data
.begin(),
m_data
.end(),
C
());
63
}
64
65
template
<
class
T,
class
C>
inline
typename
LookUpTable<T, C>::vec_type_cit
LookUpTable<T, C>::lowerBound
(
const
val_type
& val) {
66
vec_type_cit
it = lower_bound(
m_data
.begin(),
m_data
.end(), val,
C
());
67
if
(it ==
m_data
.end())
return
m_data
.end() - 1;
68
return
it;
69
}
70
71
template
<
class
T,
class
C>
inline
typename
LookUpTable<T, C>::pair_type
LookUpTable<T, C>::find
(
const
val_type
& val)
const
{
72
vec_type_cit
it = lower_bound(
m_data
.begin(),
m_data
.end(), val,
C
());
73
if
(it ==
m_data
.end())
74
return
std::make_pair(*(it - 2), *(it - 1));
75
else
if
(it ==
m_data
.begin())
76
return
std::make_pair(*it, *(it + 1));
77
else
78
return
std::make_pair(*(it - 1), *it);
79
}
80
81
#endif
sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
LookUpTable::lowerBound
vec_type_cit lowerBound(const val_type &val)
Definition
LookUpTable.h:65
LookUpTable::end
vec_type_cit end() const
Definition
LookUpTable.h:41
LookUpTable::empty
bool empty() const
Definition
LookUpTable.h:33
LookUpTable::setData
void setData(const vec_type &data)
Definition
LookUpTable.h:60
LookUpTable::end
vec_type_it end()
Definition
LookUpTable.h:39
LookUpTable::pair_type
std::pair< val_type, val_type > pair_type
Definition
LookUpTable.h:25
LookUpTable::vec_type_cit
vec_type::const_iterator vec_type_cit
Definition
LookUpTable.h:28
LookUpTable::vec_type
std::vector< val_type > vec_type
Definition
LookUpTable.h:24
LookUpTable::vec_type_it
vec_type::iterator vec_type_it
Definition
LookUpTable.h:27
LookUpTable::find
pair_type find(const val_type &val) const
Definition
LookUpTable.h:71
LookUpTable::val_type
T val_type
Definition
LookUpTable.h:23
LookUpTable::LookUpTable
LookUpTable()=default
LookUpTable::getData
const vec_type & getData() const
Definition
LookUpTable.h:36
LookUpTable::~LookUpTable
~LookUpTable()=default
LookUpTable::begin
vec_type_it begin()
Definition
LookUpTable.h:38
LookUpTable::find
pair_type find(const val_type &val, const CC &c) const
Definition
LookUpTable.h:46
LookUpTable::m_data
vec_type m_data
Definition
LookUpTable.h:57
LookUpTable::begin
vec_type_cit begin() const
Definition
LookUpTable.h:40
C
struct color C
Generated on
for ATLAS Offline Software by
1.17.0