ATLAS Offline Software
TPIntegerVector_p1.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 TPINTEGERVECTOR_H
6 #define TPINTEGERVECTOR_H
7 
8 #include <cstring>
9 #include <vector>
10 #include <stdexcept>
12 #include <iostream>
13 
14 using namespace std;
15 
24 
26 {
27 public:
28  typedef unsigned int value_type;
29  typedef value_type* iterator;
30  typedef const value_type* const_iterator;
31 
33  : m_storage(storage), m_position(idx)
34  {}
35 
36  size_t size() const;
37  void resize( size_t new_size );
38  void reserve( size_t new_size );
39  value_type& operator[]( size_t idx );
40  const value_type& operator[]( size_t idx ) const;
41 
42  void push_back( const value_type& val );
43  void push_int( const int& val );
44  void push_float( const float& val );
45  void push_double( const double val );
46  void push_TPObjRef( const TPObjRef& val );
47  void push_vTPObjRef( const std::vector<TPObjRef>& val );
48 
49 
50  value_type front_UI( const_iterator i ) const{value_type res=(*i); i++; return res;}
51  int front_int( const_iterator& i ) const;
52  float front_float( const_iterator& i ) const;
53  double front_double( const_iterator& i ) const;
54  TPObjRef front_TPObjRef( const_iterator& i ) const;
55  std::vector<TPObjRef> front_vTPObjRef( const_iterator& i ) const;
56 
57  iterator begin() { return &operator[](0); }
58  iterator end() { return &operator[](size()); };
59 
60  const_iterator begin() const { return &operator[](0); }
61  const_iterator end() const { return &operator[](size()); };
62 
63 protected:
65  unsigned int m_position;
66 };
67 
68 
69 
71 {
72 public:
73 friend class TPIntegerVector_p1;
74 
76 
77  typedef unsigned short position_type;
78 
79  size_t size() const {
80  return m_endPos.size();
81  }
82 
83  void grow() {
84  if( !size() ) m_endPos.push_back(0);
85  else m_endPos.push_back( m_endPos.back() );
86  }
87 
89  return TPIntegerVector_p1( this, idx );
90  }
91 
93  return TPIntegerVector_p1( this, size()-1 );
94  }
95 
96  void reserve( size_t s ) {
97  m_endPos.reserve(s);
98  }
99 
100 protected:
101  std::vector< TPIntegerVector_p1::value_type > m_data;
102  std::vector<position_type> m_endPos;
103 };
104 
105 
106 
107 inline
108 size_t TPIntegerVector_p1::size() const {
109  if( m_position == 0 ) return m_storage->m_endPos[0];
111 }
112 
113 inline
114 void TPIntegerVector_p1::resize( size_t new_size ) {
115  if( m_position != m_storage->size() - 1 )
116  throw std::runtime_error("TPIntegerVector_p1::resize() only supported on the last element");
117  size_t change = new_size - size();
118  m_storage->m_endPos[m_position] += change;
120 }
121 
122 inline
123 void TPIntegerVector_p1::reserve( size_t new_size ) {
124  if( m_position != m_storage->size() - 1 )
125  throw std::runtime_error("TPIntegerVector_p1::reserve() only supported on the last element");
126  size_t change = new_size - size();
127  m_storage->m_data.reserve( m_storage->m_endPos[m_position] + change );
128 }
129 
130 inline
133  return const_cast<value_type&>(((const TPIntegerVector_p1*)this)->operator[](idx));
134 }
135 
136 inline
139  size_t pos = m_position? m_storage->m_endPos[m_position-1] : 0;
140  return m_storage->m_data[ pos + idx ];
141 }
142 
143 inline
145 {
146  m_storage->m_data.push_back( val );
148 }
149 
150 inline
152  union {unsigned int i; int f;} m_union;
153  m_union.f = val;
154  m_storage->m_data.push_back( m_union.i );
155  m_storage->m_endPos[m_position]++;
156 }
157 
158 inline
159 void TPIntegerVector_p1::push_float( const float& val ){
160  union {unsigned int i; float f;} m_union;
161  m_union.f = val;
162  m_storage->m_data.push_back( m_union.i );
163  m_storage->m_endPos[m_position]++;
164 }
165 
166 
167 inline
169  union {struct{unsigned int i1;unsigned int i2;} c; double d;} m_union;
170  m_union.d = val;
171  m_storage->m_data.push_back( m_union.c.i1 );
172  m_storage->m_data.push_back( m_union.c.i2 );
173  m_storage->m_endPos[m_position]+=2;
174 }
175 
176 inline
178  union {struct{unsigned short i1;unsigned short i2;} c; unsigned int I;} m_union;
179  m_union.c.i1 = val.typeID();
180  m_union.c.i2 = val.topLevelCnvID();
181  m_storage->m_data.push_back( m_union.I );
182  m_storage->m_data.push_back( val.index());
183  m_storage->m_endPos[m_position]+=2;
184 }
185 
186 inline
187 void TPIntegerVector_p1::push_vTPObjRef( const std::vector<TPObjRef>& val ){
188  m_storage->m_data.push_back( val.size());
189  m_storage->m_endPos[m_position]++;
190  union {struct{unsigned short i1;unsigned short i2;} c; unsigned int I;} m_union;
191  std::vector<TPObjRef>::const_iterator it=val.begin();
192  for (;it!=val.end();it++){
193  TPObjRef v = (*it);
194  m_union.c.i1 = v.typeID();
195  m_union.c.i2 = v.topLevelCnvID();
196  m_storage->m_data.push_back( m_union.I );
197  m_storage->m_data.push_back( v.index());
198  }
199  m_storage->m_endPos[m_position]+= 2*val.size();
200 }
201 
202 inline
204  union { int f; unsigned int i;} m_union;
205  m_union.i = (*i); i++;
206  return m_union.f;
207 }
208 
209 inline
211  union { float f; unsigned int i;} m_union;
212  m_union.i = (*i); i++;
213  return m_union.f;
214 }
215 
216 inline
218  union { double d; struct{unsigned int i1; unsigned int i2;}c; } m_union;
219  m_union.c.i1 = (*i); i++;
220  m_union.c.i2 = (*i); i++;
221  return m_union.d;
222 }
223 
224 inline
226  union {struct{unsigned short i1;unsigned short i2;} c; unsigned int I;} m_union;
227  m_union.I = (*i); i++;
228  TPObjRef res(TPObjRef::typeID_t(m_union.c.i2, m_union.c.i1),(int) (*i)); i++;
229  return res;
230 }
231 
232 inline
233 std::vector<TPObjRef> TPIntegerVector_p1::front_vTPObjRef( const_iterator& i ) const{
234  int size = (*i); i++;
235  union {struct{unsigned short i1;unsigned short i2;} c; unsigned int I;} m_union;
236  std::vector<TPObjRef> res;
237  res.reserve(size);
238  for(int it=0;it<size;it++){
239  m_union.I = (*i); i++;
240  res.push_back( TPObjRef(TPObjRef::typeID_t(m_union.c.i2, m_union.c.i1),(int) (*i)) ); i++;
241  }
242  return res;
243 }
244 
245 #endif
246 
TPIntegerVector_p1::reserve
void reserve(size_t new_size)
Definition: TPIntegerVector_p1.h:123
TPIntegerVector_p1::resize
void resize(size_t new_size)
Definition: TPIntegerVector_p1.h:114
TPIntegerVectorStorage_p1::position_type
unsigned short position_type
Definition: TPIntegerVector_p1.h:77
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TPIntegerVector_p1::m_position
unsigned int m_position
Definition: TPIntegerVector_p1.h:65
TPIntegerVector_p1::end
const_iterator end() const
Definition: TPIntegerVector_p1.h:61
TPIntegerVector_p1::front_int
int front_int(const_iterator &i) const
Definition: TPIntegerVector_p1.h:203
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TPIntegerVector_p1::end
iterator end()
Definition: TPIntegerVector_p1.h:58
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TPIntegerVector_p1::push_vTPObjRef
void push_vTPObjRef(const std::vector< TPObjRef > &val)
Definition: TPIntegerVector_p1.h:187
TPIntegerVectorStorage_p1::back
TPIntegerVector_p1 back()
Definition: TPIntegerVector_p1.h:92
TPIntegerVectorStorage_p1
Definition: TPIntegerVector_p1.h:71
TPIntegerVector_p1::push_back
void push_back(const value_type &val)
Definition: TPIntegerVector_p1.h:144
TPIntegerVectorStorage_p1::m_data
std::vector< TPIntegerVector_p1::value_type > m_data
Definition: TPIntegerVector_p1.h:101
TPIntegerVectorStorage_p1::operator[]
TPIntegerVector_p1 operator[](int idx)
Definition: TPIntegerVector_p1.h:88
TPIntegerVector_p1::m_storage
TPIntegerVectorStorage_p1 * m_storage
Definition: TPIntegerVector_p1.h:61
TPObjRef
Definition: TPObjRef.h:20
TPIntegerVector_p1::push_float
void push_float(const float &val)
Definition: TPIntegerVector_p1.h:159
TPIntegerVector_p1::push_int
void push_int(const int &val)
Definition: TPIntegerVector_p1.h:151
TPIntegerVector_p1::TPIntegerVector_p1
TPIntegerVector_p1(TPIntegerVectorStorage_p1 *storage, int idx)
Definition: TPIntegerVector_p1.h:32
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TPIntegerVector_p1::front_UI
value_type front_UI(const_iterator i) const
Definition: TPIntegerVector_p1.h:50
TPIntegerVector_p1::iterator
value_type * iterator
Definition: TPIntegerVector_p1.h:29
TPIntegerVector_p1::front_vTPObjRef
std::vector< TPObjRef > front_vTPObjRef(const_iterator &i) const
Definition: TPIntegerVector_p1.h:233
lumiFormat.i
int i
Definition: lumiFormat.py:85
TPIntegerVector_p1::begin
iterator begin()
Definition: TPIntegerVector_p1.h:57
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
TPIntegerVector_p1::begin
const_iterator begin() const
Definition: TPIntegerVector_p1.h:60
hist_file_dump.f
f
Definition: hist_file_dump.py:135
TPIntegerVector_p1::push_double
void push_double(const double val)
Definition: TPIntegerVector_p1.h:168
TPIntegerVectorStorage_p1::size
size_t size() const
Definition: TPIntegerVector_p1.h:79
TPIntegerVectorStorage_p1::TPIntegerVectorStorage_p1
TPIntegerVectorStorage_p1()
Definition: TPIntegerVector_p1.h:75
TPIntegerVector_p1::front_TPObjRef
TPObjRef front_TPObjRef(const_iterator &i) const
Definition: TPIntegerVector_p1.h:225
TPIntegerVector_p1
Definition: TPIntegerVector_p1.h:26
TPIntegerVector_p1::size
size_t size() const
Definition: TPIntegerVector_p1.h:108
TPIntegerVector_p1::operator[]
value_type & operator[](size_t idx)
Definition: TPIntegerVector_p1.h:132
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
TPObjRef.h
TPIntegerVector_p1::push_TPObjRef
void push_TPObjRef(const TPObjRef &val)
Definition: TPIntegerVector_p1.h:177
python.PyAthena.v
v
Definition: PyAthena.py:154
TPIntegerVectorStorage_p1::m_endPos
std::vector< position_type > m_endPos
Definition: TPIntegerVector_p1.h:102
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TPIntegerVectorStorage_p1::reserve
void reserve(size_t s)
Definition: TPIntegerVector_p1.h:96
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
TPObjRef::typeID_t
Definition: TPObjRef.h:31
I
#define I(x, y, z)
Definition: MD5.cxx:116
TPIntegerVector_p1::front_double
double front_double(const_iterator &i) const
Definition: TPIntegerVector_p1.h:217
TPIntegerVector_p1::front_float
float front_float(const_iterator &i) const
Definition: TPIntegerVector_p1.h:210
TPIntegerVector_p1::const_iterator
const value_type * const_iterator
Definition: TPIntegerVector_p1.h:30
value_type
Definition: EDM_MasterSearch.h:11
python.compressB64.c
def c
Definition: compressB64.py:93
TPIntegerVectorStorage_p1::grow
void grow()
Definition: TPIntegerVector_p1.h:83
TPIntegerVector_p1::value_type
unsigned int value_type
Definition: TPIntegerVector_p1.h:28