ATLAS Offline Software
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 
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 
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:
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
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LookUpTable::vec_type_cit
vec_type::const_iterator vec_type_cit
Definition: LookUpTable.h:28
LookUpTable::~LookUpTable
~LookUpTable()=default
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LookUpTable::setData
void setData(const vec_type &data)
Definition: LookUpTable.h:60
LookUpTable::find
pair_type find(const val_type &val) const
Definition: LookUpTable.h:71
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
DMTest::C
C_v1 C
Definition: C.h:26
LookUpTable::LookUpTable
LookUpTable()=default
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LookUpTable::end
vec_type_cit end() const
Definition: LookUpTable.h:41
LookUpTable::lowerBound
vec_type_cit lowerBound(const val_type &val)
Definition: LookUpTable.h:65
LookUpTable::find
pair_type find(const val_type &val, const CC &c) const
Definition: LookUpTable.h:46
LookUpTable::pair_type
std::pair< val_type, val_type > pair_type
Definition: LookUpTable.h:25
LookUpTable::begin
vec_type_cit begin() const
Definition: LookUpTable.h:40
LookUpTable::end
vec_type_it end()
Definition: LookUpTable.h:39
LookUpTable::vec_type
std::vector< val_type > vec_type
Definition: LookUpTable.h:24
LookUpTable::getData
const vec_type & getData() const
Definition: LookUpTable.h:36
LookUpTable::begin
vec_type_it begin()
Definition: LookUpTable.h:38
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
LookUpTable::vec_type_it
vec_type::iterator vec_type_it
Definition: LookUpTable.h:27
LookUpTable::empty
bool empty() const
Definition: LookUpTable.h:33
LookUpTable::val_type
T val_type
Definition: LookUpTable.h:23
LookUpTable::m_data
vec_type m_data
Definition: LookUpTable.h:57
python.compressB64.c
def c
Definition: compressB64.py:93
LookUpTable
Definition: LookUpTable.h:21
Analysis::CC
@ CC
Definition: JpsiFinder.h:39
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35