CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTT0.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/03/08 23:46:01 $
5  * $Revision: 1.20 $
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"
20 
21 //---------------
22 // C++ Headers --
23 //---------------
24 #include <iostream>
25 #include <sstream>
26 
27 //-------------------
28 // Initializations --
29 //-------------------
30 
31 
32 //----------------
33 // Constructors --
34 //----------------
36  dataVersion( " " ),
37  nsPerCount( 25.0 / 32.0 ) {
38  dataList.reserve( 12000 );
39 // dBuf = sortedLayers = 0;
40  dBuf = 0;
41  sortedLayers = 0;
42  sequencePtr = 0;
43 }
44 
45 
46 DTT0::DTT0( const std::string& version ):
47  dataVersion( version ),
48  nsPerCount( 25.0 / 32.0 ) {
49  dataList.reserve( 12000 );
50 // dBuf = sortedLayers = 0;
51  dBuf = 0;
52  sortedLayers = 0;
53  sequencePtr = 0;
54 }
55 
56 
58  wheelId( 0 ),
59  stationId( 0 ),
60  sectorId( 0 ),
61  slId( 0 ),
62  layerId( 0 ),
63  cellId( 0 ) {
64 }
65 
66 
68  t0mean( 0.0 ),
69  t0rms( 0.0 ) {
70 }
71 
72 
73 //--------------
74 // Destructor --
75 //--------------
77  delete dBuf;
78  delete sortedLayers;
79  delete sequencePtr;
80 }
81 
82 
84 }
85 
86 
88 }
89 
90 
91 //--------------
92 // Operations --
93 //--------------
94 int DTT0::get( int wheelId,
95  int stationId,
96  int sectorId,
97  int slId,
98  int layerId,
99  int cellId,
100  float& t0mean,
101  float& t0rms,
102  DTTimeUnits::type unit ) const {
103 
104  t0mean =
105  t0rms = 0.0;
106 
107  if ( ( dBuf == 0 ) && ( sortedLayers == 0 ) ) checkOrder();
108 // if ( sortedLayers != 0 ) std::cout << "sorted data" << std::endl;
109 // else std::cout << "random data" << std::endl;
110  if ( sortedLayers != 0 ) return getSorted( wheelId, stationId, sectorId,
111  slId, layerId, cellId,
112  t0mean, t0rms, unit );
113  else return getRandom( wheelId, stationId, sectorId,
114  slId, layerId, cellId,
115  t0mean, t0rms, unit );
116  return -999999999;
117 }
118 
119 
120 int DTT0::getRandom( int wheelId,
121  int stationId,
122  int sectorId,
123  int slId,
124  int layerId,
125  int cellId,
126  float& t0mean,
127  float& t0rms,
128  DTTimeUnits::type unit ) const {
129 
130 // DTWireId detId( wheelId, stationId, sectorId,
131 // slId, layerId, cellId );
132 // int chanKey = detId.rawId();
133  std::vector<int> chanKey;
134  chanKey.reserve(6);
135  chanKey.push_back( wheelId );
136  chanKey.push_back( stationId );
137  chanKey.push_back( sectorId );
138  chanKey.push_back( slId );
139  chanKey.push_back( layerId );
140  chanKey.push_back( cellId );
141 
142  int ientry;
143 // std::map<int,int>::const_iterator buf_iter = dBuf->find( chanKey );
144 // std::map<int,int>::const_iterator buf_iend = dBuf->end();
145 // int searchStatus = ( buf_iter == buf_iend );
146  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
147  if ( !searchStatus ) {
148 // ientry = buf_iter->second;
149  const DTT0Data& data( dataList[ientry].second );
150  t0mean = data.t0mean;
151  t0rms = data.t0rms;
152  if ( unit == DTTimeUnits::ns ) {
153  t0mean *= nsPerCount;
154  t0rms *= nsPerCount;
155  }
156  }
157 
158  return searchStatus;
159 
160 }
161 
162 
164  return 2000;
165 }
166 
167 
168 int DTT0::getSorted( int wheelId,
169  int stationId,
170  int sectorId,
171  int slId,
172  int layerId,
173  int cellId,
174  float& t0mean,
175  float& t0rms,
176  DTTimeUnits::type unit ) const {
177 
178  int lCode;
179  int seqId;
180  std::vector<int>& sequenceLay = *sequencePtr;
181 
182  if ( ( seqId = DTSequentialLayerNumber::id( wheelId, stationId, sectorId,
183  slId, layerId ) ) < 0 ) {
184 // DTLayerId detId( wheelId, stationId, sectorId,
185 // slId, layerId );
186 // int chanKey = detId.rawId();
187  std::vector<int> chanKey;
188  chanKey.reserve(6);
189  chanKey.push_back( wheelId );
190  chanKey.push_back( stationId );
191  chanKey.push_back( sectorId );
192  chanKey.push_back( slId );
193  chanKey.push_back( layerId );
194 
195 // std::map<int,int>::iterator layer_iter = sortedLayers->find( chanKey );
196 // std::map<int,int>::iterator layer_iend = sortedLayers->end();
197 //
198 // if ( layer_iter == layer_iend ) return 1;
199 //
200 // int& lCode = layer_iter->second;
201  if ( sortedLayers->find( chanKey.begin(), chanKey.end(), lCode ) )
202  return 1;
203  }
204  else {
205  lCode = sequenceLay[seqId];
206  }
207  int mCells = maxCellsPerLayer();
208  int idprev = lCode / mCells;
209  int length = lCode % mCells;
210  int idnext = idprev + length;
211 
212  --idprev;
213  int idtest;
214  while ( ( length = idnext - idprev ) >= 2 ) {
215  idtest = idprev + ( length / 2 );
216  int cCell = dataList[idtest].first.cellId;
217  if ( cCell < cellId ) {
218  idprev = idtest;
219  continue;
220  }
221  if ( cCell > cellId ) {
222  idnext = idtest;
223  continue;
224  }
225  idprev = idtest++;
226  idnext = idtest;
227  const DTT0Data& data( dataList[idprev].second );
228  t0mean = data.t0mean;
229  t0rms = data.t0rms;
230  if ( unit == DTTimeUnits::ns ) {
231  t0mean *= nsPerCount;
232  t0rms *= nsPerCount;
233  }
234  return 0;
235  }
236  // std::cout << "cell not found!" << std::endl;
237  return 1;
238 }
239 
240 
241 int DTT0::get( const DTWireId& id,
242  float& t0mean,
243  float& t0rms,
244  DTTimeUnits::type unit ) const {
245  return get( id.wheel(),
246  id.station(),
247  id.sector(),
248  id.superLayer(),
249  id.layer(),
250  id.wire(),
251  t0mean, t0rms, unit );
252 }
253 
254 
255 float DTT0::unit() const {
256  return nsPerCount;
257 }
258 
259 
260 const
261 std::string& DTT0::version() const {
262  return dataVersion;
263 }
264 
265 
266 std::string& DTT0::version() {
267  return dataVersion;
268 }
269 
270 
271 void DTT0::clear() {
272  delete dBuf;
273  dBuf = 0;
274  dataList.clear();
275  return;
276 }
277 
278 
279 int DTT0::set( int wheelId,
280  int stationId,
281  int sectorId,
282  int slId,
283  int layerId,
284  int cellId,
285  float t0mean,
286  float t0rms,
288 
289  if ( unit == DTTimeUnits::ns ) {
290  t0mean /= nsPerCount;
291  t0rms /= nsPerCount;
292  }
293 
294  if ( dBuf == 0 ) cacheMap();
295 
296 // DTWireId detId( wheelId, stationId, sectorId,
297 // slId, layerId, cellId );
298 // int chanKey = detId.rawId();
299  if ( dBuf == 0 ) cacheMap();
300  std::vector<int> chanKey;
301  chanKey.reserve(6);
302  chanKey.push_back( wheelId );
303  chanKey.push_back( stationId );
304  chanKey.push_back( sectorId );
305  chanKey.push_back( slId );
306  chanKey.push_back( layerId );
307  chanKey.push_back( cellId );
308 
309  int ientry;
310 // std::map<int,int>::const_iterator buf_iter = dBuf->find( chanKey );
311 // std::map<int,int>::const_iterator buf_iend = dBuf->end();
312 // int searchStatus = ( buf_iter == buf_iend );
313  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
314 
315  if ( !searchStatus ) {
316 // ientry = buf_iter->second;
317  DTT0Data& data( dataList[ientry].second );
318  data.t0mean = t0mean;
319  data.t0rms = t0rms;
320  return -1;
321  }
322  else {
323  DTT0Id key;
324  key. wheelId = wheelId;
325  key.stationId = stationId;
326  key. sectorId = sectorId;
327  key. slId = slId;
328  key. layerId = layerId;
329  key. cellId = cellId;
330  DTT0Data data;
331  data.t0mean = t0mean;
332  data.t0rms = t0rms;
333  ientry = dataList.size();
334  dataList.push_back( std::pair<const DTT0Id,DTT0Data>( key, data ) );
335 // dBuf->insert( std::pair<int,int>( detId.rawId(), ientry ) );
336  dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
337  return 0;
338  }
339 
340  return 99;
341 
342 }
343 
344 
345 int DTT0::set( const DTWireId& id,
346  float t0mean,
347  float t0rms,
349  return set( id.wheel(),
350  id.station(),
351  id.sector(),
352  id.superLayer(),
353  id.layer(),
354  id.wire(),
355  t0mean, t0rms, unit );
356 }
357 
358 
359 void DTT0::setUnit( float unit ) {
360  nsPerCount = unit;
361 }
362 
363 
365  if ( sortedLayers != 0 ) return;
366  if ( dBuf == 0 ) checkOrder();
367  if ( sortedLayers != 0 ) return;
368  if ( dBuf == 0 ) return;
369  std::vector< std::pair<DTT0Id,DTT0Data> > tempList;
370 // std::map<int,int>::const_iterator iter = dBuf->begin();
371 // std::map<int,int>::const_iterator iend = dBuf->end();
372 // while ( iter != iend ) tempList.push_back( dataList[iter++->second] );
373  std::vector<int> indexList = dBuf->contList();
374  std::vector<int>::const_iterator iter = indexList.begin();
375  std::vector<int>::const_iterator iend = indexList.end();
376  while ( iter != iend ) tempList.push_back( dataList[*iter++] );
377  dataList = tempList;
378  delete dBuf;
379  dBuf = 0;
380  return;
381 }
382 
383 
385  return dataList.begin();
386 }
387 
388 
390  return dataList.end();
391 }
392 
393 
394 std::string DTT0::mapName() const {
395  std::stringstream name;
396  name << dataVersion << "_map_T0" << this;
397  return name.str();
398 }
399 
400 
401 bool DTT0::checkOrder() const {
402 
403  delete sortedLayers;
404  delete sequencePtr;
405 // sortedLayers = new std::map<int,int>;
407 // sequencePtr = new std::vector<int>;
408 // sequencePtr->reserve( DTSequentialLayerNumber::max() + 2 );
409  sequencePtr = new std::vector<int>( DTSequentialLayerNumber::max() + 2 );
410  std::vector<int>::iterator iter = sequencePtr->begin();
411  std::vector<int>::iterator iend = sequencePtr->end();
412  while ( iter != iend ) *iter++ = 0;
413 
414  int entryNum = 0;
415  int mCells = maxCellsPerLayer();
416  int entryMax = dataList.size();
417 // int oldId = 0;
418  std::vector<int> chanOld;
419  int lCell = -999999999;
420  bool layerOrder = true;
421 
422  int lCode;
423  int seqId;
424  int oldId = 0;
425  std::vector<int>& sequenceLay = *sequencePtr;
426 
427  std::vector<int> chanKey;
428  chanKey.reserve(6);
429 
430  while ( entryNum < entryMax ) {
431  const DTT0Id& chan = dataList[entryNum].first;
432  if ( ( seqId = DTSequentialLayerNumber::id( chan. wheelId,
433  chan.stationId,
434  chan. sectorId,
435  chan. slId,
436  chan. layerId ) ) < 0 ) {
437  oldId = 0;
438 // std::cout << "out of sequence" << std::endl;
439 // DTLayerId detId( chan. wheelId, chan.stationId, chan. sectorId,
440 // chan. slId, chan. layerId );
441 // int rawId = detId.rawId();
442  chanKey.clear();
443  chanKey.push_back( chan. wheelId );
444  chanKey.push_back( chan.stationId );
445  chanKey.push_back( chan. sectorId );
446  chanKey.push_back( chan. slId );
447  chanKey.push_back( chan. layerId );
448 // std::map<int,int>::iterator layer_iter = sortedLayers->find( rawId );
449 // std::map<int,int>::iterator layer_iend = sortedLayers->end();
450 // if ( layer_iter == layer_iend ) {
451  if ( sortedLayers->find( chanKey.begin(), chanKey.end(), lCode ) ) {
452 // sortedLayers->insert( std::pair<int,int>( rawId,
453 // 1 + ( entryNum * 1000 ) ) );
454 // oldId = rawId;
455  sortedLayers->insert( chanKey.begin(), chanKey.end(),
456  1 + ( entryNum * mCells ) );
457  chanOld = chanKey;
458  }
459  else {
460 // int& lCode = layer_iter->second;
461  int offset = lCode / mCells;
462  int length = lCode % mCells;
463  int ncells = entryNum - offset;
464 // if ( ( ncells != length ) ||
465 // ( rawId != oldId ) ||
466 // ( chan.cellId <= lCell ) ) layerOrder = false;
467 // layer_iter->second = ( offset * 1000 ) + ncells + 1;
468  if ( ( ncells >= mCells ) ||
469  ( ncells != length ) ||
470  ( chanKey[0] != chanOld[0] ) ||
471  ( chanKey[1] != chanOld[1] ) ||
472  ( chanKey[2] != chanOld[2] ) ||
473  ( chanKey[3] != chanOld[3] ) ||
474  ( chanKey[4] != chanOld[4] ) ||
475  ( chan.cellId <= lCell ) ) layerOrder = false;
476  sortedLayers->insert( chanKey.begin(), chanKey.end(),
477  ( offset * mCells ) + ncells + 1 );
478  }
479  }
480  else {
481  chanOld.clear();
482 // std::cout << "inside sequence" << std::endl;
483  lCode = sequenceLay[seqId];
484  if ( lCode == 0 ) {
485  sequenceLay[seqId] = 1 + ( entryNum * mCells );
486  oldId = seqId;
487  }
488  else {
489  int offset = lCode / mCells;
490  int length = lCode % mCells;
491  int ncells = entryNum - offset;
492  if ( ( ncells >= mCells ) ||
493  ( ncells != length ) ||
494  ( seqId != oldId ) ||
495  ( chan.cellId <= lCell ) ) layerOrder = false;
496  sequenceLay[seqId] = ( offset * mCells ) + ncells + 1;
497  }
498  }
499  lCell = chan.cellId;
500  entryNum++;
501  }
502  if ( !layerOrder ) cacheMap();
503  return layerOrder;
504 }
505 
506 
507 void DTT0::cacheMap() const {
508 
509  delete sortedLayers;
510  sortedLayers = 0;
511 // dBuf = new std::map<int,int>;
513 
514  int entryNum = 0;
515  int entryMax = dataList.size();
516  std::vector<int> chanKey;
517  chanKey.reserve(6);
518  while ( entryNum < entryMax ) {
519 
520  const DTT0Id& chan = dataList[entryNum].first;
521 
522 // DTWireId detId( chan. wheelId, chan.stationId, chan. sectorId,
523 // chan. slId, chan. layerId, chan. cellId );
524 // dBuf->insert( std::pair<int,int>( detId.rawId(), entryNum++ ) );
525  chanKey.clear();
526  chanKey.push_back( chan. wheelId );
527  chanKey.push_back( chan.stationId );
528  chanKey.push_back( chan. sectorId );
529  chanKey.push_back( chan. slId );
530  chanKey.push_back( chan. layerId );
531  chanKey.push_back( chan. cellId );
532  dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
533 
534  }
535 
536  return;
537 
538 }
539 
const_iterator begin() const
Definition: DTT0.cc:384
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
Definition: DTT0.cc:279
DTT0Id()
Definition: DTT0.cc:57
int insert(ElementKey fKey, ElementKey lKey, const Content &cont)
DTBufferTree< int, int > * dBuf
Definition: DTT0.h:171
int cellId
Definition: DTT0.h:50
int getSorted(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:168
DTT0()
Definition: DTT0.cc:35
std::string dataVersion
Definition: DTT0.h:164
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:94
int maxCellsPerLayer() const
Definition: DTT0.cc:163
Definition: DTT0.h:38
std::vector< std::pair< DTT0Id, DTT0Data > > dataList
Definition: DTT0.h:167
U second(std::pair< T, U > const &p)
int stationId
Definition: DTT0.h:46
string unit
Definition: csvLumiCalc.py:46
int getRandom(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float &t0mean, float &t0rms, DTTimeUnits::type unit) const
Definition: DTT0.cc:120
std::vector< Content > contList()
unsigned int offset(bool)
void setUnit(float unit)
Definition: DTT0.cc:359
DTT0Data()
Definition: DTT0.cc:67
const_iterator end() const
Definition: DTT0.cc:389
float unit() const
Definition: DTT0.cc:255
~DTT0Data()
Definition: DTT0.cc:87
int find(ElementKey fKey, ElementKey lKey, Content &cont)
void sortData()
Definition: DTT0.cc:364
DTBufferTree< int, int > * sortedLayers
Definition: DTT0.h:170
float nsPerCount
Definition: DTT0.h:165
std::vector< std::pair< DTT0Id, DTT0Data > >::const_iterator const_iterator
Access methods to data.
Definition: DTT0.h:158
void cacheMap() const
Definition: DTT0.cc:507
~DTT0()
Definition: DTT0.cc:76
list key
Definition: combine.py:13
std::string mapName() const
Definition: DTT0.cc:394
~DTT0Id()
Definition: DTT0.cc:83
const std::string & version() const
access version
Definition: DTT0.cc:261
void clear()
reset content
Definition: DTT0.cc:271
bool checkOrder() const
read and store full content
Definition: DTT0.cc:401
float t0rms
Definition: DTT0.h:63
std::vector< int > * sequencePtr
Definition: DTT0.h:169
float t0mean
Definition: DTT0.h:62
Definition: DTT0.h:55
static int id(int wheel, int station, int sector, int superlayer, int layer)