CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTRangeT0.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/01/20 18:20:08 $
5  * $Revision: 1.11 $
6  * \author Paolo Ronchese INFN Padova
7  *
8  */
9 
10 //----------------------
11 // This Class' Header --
12 //----------------------
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
18 //#include "CondFormats/DTObjects/interface/DTDataBuffer.h"
19 
20 //---------------
21 // C++ Headers --
22 //---------------
23 #include <iostream>
24 #include <sstream>
25 
26 //-------------------
27 // Initializations --
28 //-------------------
29 
30 
31 //----------------
32 // Constructors --
33 //----------------
35  dataVersion( " " ) {
36  dataList.reserve( 1000 );
37  dBuf = 0;
38 }
39 
40 
42  dataVersion( version ) {
43  dataList.reserve( 1000 );
44  dBuf = 0;
45 }
46 
47 
49  wheelId( 0 ),
50  stationId( 0 ),
51  sectorId( 0 ),
52  slId( 0 ) {
53 }
54 
55 
57  t0min( 0 ),
58  t0max( 0 ) {
59 }
60 
61 
62 //--------------
63 // Destructor --
64 //--------------
66 // DTDataBuffer<int,int>::dropBuffer( mapName() );
67  delete dBuf;
68 }
69 
70 
72 }
73 
74 
76 }
77 
78 
79 //--------------
80 // Operations --
81 //--------------
82 int DTRangeT0::get( int wheelId,
83  int stationId,
84  int sectorId,
85  int slId,
86  int& t0min,
87  int& t0max ) const {
88 
89  t0min =
90  t0max = 0;
91 
92 // std::string mName = mapName();
93 // DTBufferTree<int,int>* dBuf =
94 // DTDataBuffer<int,int>::findBuffer( mName );
95 // if ( dBuf == 0 ) {
96 // cacheMap();
97 // dBuf =
98 // DTDataBuffer<int,int>::findBuffer( mName );
99 // }
100  if ( dBuf == 0 ) cacheMap();
101 
102  std::vector<int> chanKey;
103  chanKey.reserve(4);
104  chanKey.push_back( wheelId );
105  chanKey.push_back( stationId );
106  chanKey.push_back( sectorId );
107  chanKey.push_back( slId );
108  int ientry;
109  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
110  if ( !searchStatus ) {
111  const DTRangeT0Data& data( dataList[ientry].second );
112  t0min = data.t0min;
113  t0max = data.t0max;
114  }
115 
116  return searchStatus;
117 
118 }
119 
120 
122  int& t0min,
123  int& t0max ) const {
124  return get( id.wheel(),
125  id.station(),
126  id.sector(),
127  id.superLayer(),
128  t0min, t0max );
129 }
130 
131 
132 const
134  return dataVersion;
135 }
136 
137 
139  return dataVersion;
140 }
141 
142 
144 // DTDataBuffer<int,int>::dropBuffer( mapName() );
145  delete dBuf;
146  dBuf = 0;
147  dataList.clear();
148  return;
149 }
150 
151 
152 int DTRangeT0::set( int wheelId,
153  int stationId,
154  int sectorId,
155  int slId,
156  int t0min,
157  int t0max ) {
158 
159 // std::string mName = mapName();
160 // DTBufferTree<int,int>* dBuf =
161 // DTDataBuffer<int,int>::findBuffer( mName );
162 // if ( dBuf == 0 ) {
163 // cacheMap();
164 // dBuf =
165 // DTDataBuffer<int,int>::findBuffer( mName );
166 // }
167  if ( dBuf == 0 ) cacheMap();
168  std::vector<int> chanKey;
169  chanKey.reserve(4);
170  chanKey.push_back( wheelId );
171  chanKey.push_back( stationId );
172  chanKey.push_back( sectorId );
173  chanKey.push_back( slId );
174  int ientry;
175  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
176 
177  if ( !searchStatus ) {
178  DTRangeT0Data& data( dataList[ientry].second );
179  data.t0min = t0min;
180  data.t0max = t0max;
181  return -1;
182  }
183  else {
185  key. wheelId = wheelId;
186  key.stationId = stationId;
187  key. sectorId = sectorId;
188  key. slId = slId;
190  data.t0min = t0min;
191  data.t0max = t0max;
192  ientry = dataList.size();
193  dataList.push_back( std::pair<DTRangeT0Id,DTRangeT0Data>( key, data ) );
194  dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
195  return 0;
196  }
197 
198  return 99;
199 
200 }
201 
202 
204  int t0min,
205  int t0max ) {
206  return set( id.wheel(),
207  id.station(),
208  id.sector(),
209  id.superLayer(),
210  t0min, t0max );
211 }
212 
213 
215  return dataList.begin();
216 }
217 
218 
220  return dataList.end();
221 }
222 
223 
225  std::stringstream name;
226  name << dataVersion << "_map_RangeT0" << this;
227  return name.str();
228 }
229 
230 
231 void DTRangeT0::cacheMap() const {
232 
233 // std::string mName = mapName();
234 // DTBufferTree<int,int>* dBuf =
235 // DTDataBuffer<int,int>::openBuffer( mName );
236  DTBufferTree<int,int>** pBuf;
237  pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
238  *pBuf = new DTBufferTree<int,int>;
239 
240  int entryNum = 0;
241  int entryMax = dataList.size();
242  std::vector<int> chanKey;
243  chanKey.reserve(4);
244  while ( entryNum < entryMax ) {
245 
246  const DTRangeT0Id& chan = dataList[entryNum].first;
247 
248  chanKey.clear();
249  chanKey.push_back( chan. wheelId );
250  chanKey.push_back( chan.stationId );
251  chanKey.push_back( chan. sectorId );
252  chanKey.push_back( chan. slId );
253  dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
254 
255  }
256 
257  return;
258 
259 }
260 
std::string mapName() const
Definition: DTRangeT0.cc:224
const_iterator end() const
Definition: DTRangeT0.cc:219
std::vector< std::pair< DTRangeT0Id, DTRangeT0Data > >::const_iterator const_iterator
Access methods to data.
Definition: DTRangeT0.h:134
int insert(ElementKey fKey, ElementKey lKey, const Content &cont)
int get(int wheelId, int stationId, int sectorId, int slId, int &t0min, int &t0max) const
Definition: DTRangeT0.cc:82
std::string dataVersion
Definition: DTRangeT0.h:140
const std::string & version() const
access version
Definition: DTRangeT0.cc:133
U second(std::pair< T, U > const &p)
std::vector< std::pair< DTRangeT0Id, DTRangeT0Data > > dataList
Definition: DTRangeT0.h:142
~DTRangeT0()
Definition: DTRangeT0.cc:65
void clear()
reset content
Definition: DTRangeT0.cc:143
int find(ElementKey fKey, ElementKey lKey, Content &cont)
void cacheMap() const
read and store full content
Definition: DTRangeT0.cc:231
const_iterator begin() const
Definition: DTRangeT0.cc:214
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
list key
Definition: combine.py:13
int set(int wheelId, int stationId, int sectorId, int slId, int t0min, int t0max)
Definition: DTRangeT0.cc:152
int stationId
Definition: DTRangeT0.h:44
DTBufferTree< int, int > * dBuf
Definition: DTRangeT0.h:144