ATLAS Offline Software
IndexSet.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 // 09.05.2005, AUTHOR: OLIVER KORTNER
7 // Modified: 16.07.2006 by O. Kortner, vector size check in initialization
8 // added,
9 // != operator corrected.
10 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 
13 
14 #include <TString.h> // for Form
15 
16 #include <algorithm>
17 #include <cstdlib>
18 
19 using namespace MuonCalib;
20 
21 //*****************************************************************************
22 
23 //:::::::::::::::::
24 //:: METHOD init ::
25 //:::::::::::::::::
26 
28  m_nb_indices = 0;
29  return;
30 }
31 
32 //*****************************************************************************
33 
34 //::::::::::::::::::::
35 //:: METHOD init(.) ::
36 //::::::::::::::::::::
37 
38 void IndexSet::init(const unsigned int& r_nb_indices) {
39  m_nb_indices = r_nb_indices;
40  m_index = std::vector<int>(m_nb_indices);
41  return;
42 }
43 
44 //*****************************************************************************
45 
46 //::::::::::::::::::::::::
47 //:: METHOD init(.,.) ::
48 //::::::::::::::::::::::::
49 
50 void IndexSet::init(const unsigned int& r_nb_indices, const std::vector<int>& r_index) {
52  // CHECK VECTOR SIZE //
54 
55  if (r_index.size() < r_nb_indices) {
56  throw std::runtime_error(Form("File: %s, Line: %d\nIndexSet::init() - Index vector too short!", __FILE__, __LINE__));
57  }
58 
60  // INITIALIZATION //
62 
63  m_nb_indices = r_nb_indices;
64  m_index = std::vector<int>(m_nb_indices);
65  for (unsigned int k = 0; k < m_nb_indices; k++) {
66  if (k < r_index.size()) {
67  m_index[k] = r_index[k];
68  } else {
69  m_index[k] = 0;
70  }
71  }
72 
73  return;
74 }
75 
76 //*****************************************************************************
77 
78 //:::::::::::::::::
79 //:: METHOD size ::
80 //:::::::::::::::::
81 
82 unsigned int IndexSet::size() const { return m_nb_indices; }
83 
84 //*****************************************************************************
85 
86 //:::::::::::::::::::
87 //:: METHOD resize ::
88 //:::::::::::::::::::
89 
90 void IndexSet::resize(const unsigned int& r_size) {
91  //:::::::::::::::
92  //:: VARIABLES ::
93  //:::::::::::::::
94 
95  std::vector<int> aux_index = m_index; // vector for temporary storage of
96  // the indices
97 
98  //:::::::::::::::::::::::::::::::::::::
99  //:: RESIZE AND COPY THE OLD INDICES ::
100  //:::::::::::::::::::::::::::::::::::::
101 
102  m_index = std::vector<int>(r_size);
103  for (unsigned int k = 0; k < r_size; k++) {
104  if (k < m_nb_indices) {
105  m_index[k] = aux_index[k];
106  } else {
107  m_index[k] = 0;
108  }
109  }
110  m_nb_indices = r_size;
111 
112  return;
113 }
114 
115 //*****************************************************************************
116 
118 //:: METHOD operator [] ::
119 //::::::::::::::::::::::::
120 
121 int IndexSet::operator[](const unsigned int& r_k) { return m_index[r_k]; }
122 
123 //*****************************************************************************
124 
125 //::::::::::::::::::::::::
126 //:: METHOD operator [] ::
127 //::::::::::::::::::::::::
128 
129 int IndexSet::operator[](const unsigned int& r_k) const { return m_index[r_k]; }
130 
131 //*****************************************************************************
132 
133 //:::::::::::::::::
134 //:: METHOD sort ::
135 //:::::::::::::::::
136 
138  std::stable_sort(m_index.begin(), m_index.end());
139  return;
140 }
141 
142 //*****************************************************************************
143 
144 //::::::::::::::::::::::::
145 //:: METHOD operator == ::
146 //::::::::::::::::::::::::
147 
148 bool IndexSet::operator==(const IndexSet& r_index_set) const {
149  if (r_index_set.size() != m_nb_indices) { return false; }
150 
151  for (unsigned int k = 0; k < m_nb_indices; k++) {
152  if (m_index[k] != r_index_set[k]) { return false; }
153  }
154 
155  return true;
156 }
157 
158 //*****************************************************************************
159 
160 //:::::::::::::::
161 //:: METHOD != ::
162 //:::::::::::::::
163 
164 bool IndexSet::operator!=(const IndexSet& r_index_set) const { return !(*this == r_index_set); }
MuonCalib::IndexSet::operator[]
int operator[](const unsigned int &r_k)
:::::::::::::::::::::::
Definition: IndexSet.cxx:121
MuonCalib::IndexSet::size
unsigned int size() const
get the number of indices
Definition: IndexSet.cxx:82
MuonCalib::IndexSet::operator==
bool operator==(const IndexSet &r_index_set) const
Definition: IndexSet.cxx:148
MuonCalib::IndexSet::init
void init()
Definition: IndexSet.cxx:27
MuonCalib::IndexSet::m_nb_indices
unsigned int m_nb_indices
Definition: IndexSet.h:43
IndexSet.h
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::IndexSet::sort
void sort()
sort the indices in ascending order
Definition: IndexSet.cxx:137
MuonCalib::IndexSet
Definition: IndexSet.h:40
MuonCalib::IndexSet::resize
void resize(const unsigned int &r_size)
resize the index set to r_size; the index store is preserved as far as possible
Definition: IndexSet.cxx:90
MuonCalib::IndexSet::operator!=
bool operator!=(const IndexSet &r_index_set) const
comparison of two index sets; two index sets are considered equal if they are of the same size and th...
Definition: IndexSet.cxx:164
MuonCalib::IndexSet::m_index
std::vector< int > m_index
Definition: IndexSet.h:44
fitman.k
k
Definition: fitman.py:528