ATLAS Offline Software
Loading...
Searching...
No Matches
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
14using namespace std;
15
21
22
24
26{
27public:
28 typedef unsigned int value_type;
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
63protected:
65 unsigned int m_position;
66};
67
68
69
71{
72public:
73friend 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
100protected:
101 std::vector< TPIntegerVector_p1::value_type > m_data;
102 std::vector<position_type> m_endPos;
103};
104
105
106
107inline
109 if( m_position == 0 ) return m_storage->m_endPos[0];
110 return m_storage->m_endPos[m_position] - m_storage->m_endPos[m_position-1];
111}
112
113inline
114void 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;
119 m_storage->m_data.resize( m_storage->m_endPos[m_position] );
120}
121
122inline
123void 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
130inline
133 return const_cast<value_type&>(((const TPIntegerVector_p1*)this)->operator[](idx));
134}
135
136inline
139 size_t pos = m_position? m_storage->m_endPos[m_position-1] : 0;
140 return m_storage->m_data[ pos + idx ];
141}
142
143inline
145{
146 m_storage->m_data.push_back( val );
147 m_storage->m_endPos[m_position]++;
148}
149
150inline
151void TPIntegerVector_p1::push_int( const int& val ){
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
158inline
159void 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
167inline
168void TPIntegerVector_p1::push_double( const double val ){
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
176inline
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
186inline
187void 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
202inline
204 union { int f; unsigned int i;} m_union;
205 m_union.i = (*i); i++;
206 return m_union.f;
207}
208
209inline
211 union { float f; unsigned int i;} m_union;
212 m_union.i = (*i); i++;
213 return m_union.f;
214}
215
216inline
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
224inline
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
232inline
233std::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
std::pair< std::vector< unsigned int >, bool > res
#define I(x, y, z)
Definition MD5.cxx:116
std::vector< TPIntegerVector_p1::value_type > m_data
std::vector< position_type > m_endPos
TPIntegerVector_p1 back()
TPIntegerVector_p1 operator[](int idx)
const_iterator end() const
value_type front_UI(const_iterator i) const
void push_float(const float &val)
value_type & operator[](size_t idx)
void resize(size_t new_size)
void push_vTPObjRef(const std::vector< TPObjRef > &val)
std::vector< TPObjRef > front_vTPObjRef(const_iterator &i) const
void push_TPObjRef(const TPObjRef &val)
TPIntegerVector_p1(TPIntegerVectorStorage_p1 *storage, int idx)
TPIntegerVectorStorage_p1 * m_storage
TPObjRef front_TPObjRef(const_iterator &i) const
void reserve(size_t new_size)
double front_double(const_iterator &i) const
const_iterator begin() const
const value_type * const_iterator
void push_back(const value_type &val)
int front_int(const_iterator &i) const
float front_float(const_iterator &i) const
void push_double(const double val)
void push_int(const int &val)
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
STL namespace.
This structure holds an ID of a persistent type.
Definition TPObjRef.h:31