CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTHVStatus.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2009/09/25 12:03:19 $
5  * $Revision: 1.2 $
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"
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 #include <iostream>
27 #include <sstream>
28 
29 //-------------------
30 // Initializations --
31 //-------------------
32 
33 
34 //----------------
35 // Constructors --
36 //----------------
38  dataVersion( " " ) {
39  dataList.reserve( 10 );
40  dBuf = 0;
41 }
42 
43 
45  dataVersion( version ) {
46  dataList.reserve( 10 );
47  dBuf = 0;
48 }
49 
50 
52  wheelId( 0 ),
53  stationId( 0 ),
54  sectorId( 0 ),
55  slId( 0 ),
56  layerId( 0 ),
57  partId( 0 ) {
58 }
59 
60 
62  flagA( 0 ),
63  flagC( 0 ),
64  flagS( 0 ) {
65 }
66 
67 
68 //--------------
69 // Destructor --
70 //--------------
72 // DTDataBuffer<int,int>::dropBuffer( mapName() );
73  delete dBuf;
74 }
75 
76 
78 }
79 
80 
82 }
83 
84 
85 //--------------
86 // Operations --
87 //--------------
88 int DTHVStatus::get( int wheelId,
89  int stationId,
90  int sectorId,
91  int slId,
92  int layerId,
93  int partId,
94  int& fCell,
95  int& lCell,
96  int& flagA,
97  int& flagC,
98  int& flagS ) const {
99  fCell =
100  lCell =
101  flagA =
102  flagC =
103  flagS = 0;
104 
105 // std::string mName = mapName();
106 // DTBufferTree<int,int>* dBuf =
107 // DTDataBuffer<int,int>::findBuffer( mName );
108 // if ( dBuf == 0 ) {
109 // cacheMap();
110 // dBuf =
111 // DTDataBuffer<int,int>::findBuffer( mName );
112 // }
113  if ( dBuf == 0 ) cacheMap();
114 
115  std::vector<int> chanKey;
116  chanKey.reserve(6);
117  chanKey.push_back( wheelId );
118  chanKey.push_back( stationId );
119  chanKey.push_back( sectorId );
120  chanKey.push_back( slId );
121  chanKey.push_back( layerId );
122  chanKey.push_back( partId );
123  int ientry;
124  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
125  if ( !searchStatus ) {
126  const DTHVStatusData& data( dataList[ientry].second );
127  fCell = data.fCell;
128  lCell = data.lCell;
129  flagA = data.flagA;
130  flagC = data.flagC;
131  flagS = data.flagS;
132  }
133 
134  return searchStatus;
135 
136 }
137 
138 
139 int DTHVStatus::get( const DTLayerId& id,
140  int partId,
141  int& fCell,
142  int& lCell,
143  int& flagA,
144  int& flagC,
145  int& flagS ) const {
146  return get( id.wheel(),
147  id.station(),
148  id.sector(),
149  id.superLayer(),
150  id.layer(),
151  partId,
152  fCell, lCell, flagA, flagC, flagS );
153 }
154 
155 
156 int DTHVStatus::get( const DTWireId& id,
157  int& flagA,
158  int& flagC,
159  int& flagS ) const {
160  flagA = flagC = flagS = 0;
161  int iCell = id.wire();
162  int fCell;
163  int lCell;
164  int
165  fCheck = get( id.wheel(),
166  id.station(),
167  id.sector(),
168  id.superLayer(),
169  id.layer(),
170  0, fCell, lCell,
171  flagA, flagC, flagS );
172  if ( ( fCheck == 0 ) &&
173  ( fCell <= iCell ) &&
174  ( lCell >= iCell ) ) return 0;
175  fCheck = get( id.wheel(),
176  id.station(),
177  id.sector(),
178  id.superLayer(),
179  id.layer(),
180  1, fCell, lCell,
181  flagA, flagC, flagS );
182  if ( ( fCheck == 0 ) &&
183  ( fCell <= iCell ) &&
184  ( lCell >= iCell ) ) return 0;
185  flagA = flagC = flagS = 0;
186  return 1;
187 }
188 
189 
191  int offNum = 0;
194  while ( iter != iend ) {
195  const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
196  DTHVStatusId hvId = entry.first;
197  DTHVStatusData data = entry.second;
198  int offA = data.flagA & 1;
199  int offC = data.flagC & 1;
200  int offS = data.flagS & 1;
201  if ( offA || offC || offS )
202  offNum += ( 1 + data.lCell - data.fCell );
203  }
204  return offNum;
205 }
206 
207 
209  int offNum = 0;
212  while ( iter != iend ) {
213  const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
214  DTHVStatusId hvId = entry.first;
215  DTHVStatusData data = entry.second;
216  if ( hvId. wheelId != id. wheel() ) continue;
217  if ( hvId.stationId != id.station() ) continue;
218  if ( hvId. sectorId != id. sector() ) continue;
219  int offA = data.flagA & 1;
220  int offC = data.flagC & 1;
221  int offS = data.flagS & 1;
222  if ( offA || offC || offS )
223  offNum += ( 1 + data.lCell - data.fCell );
224  }
225  return offNum;
226 }
227 
228 
230  int offNum = 0;
233  while ( iter != iend ) {
234  const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
235  DTHVStatusId hvId = entry.first;
236  DTHVStatusData data = entry.second;
237  if ( data.flagA || data.flagC || data.flagS )
238  offNum += ( 1 + data.lCell - data.fCell );
239  }
240  return offNum;
241 }
242 
243 
245  int offNum = 0;
248  while ( iter != iend ) {
249  const std::pair<DTHVStatusId,DTHVStatusData>& entry = *iter++;
250  DTHVStatusId hvId = entry.first;
251  DTHVStatusData data = entry.second;
252  if ( hvId. wheelId != id. wheel() ) continue;
253  if ( hvId.stationId != id.station() ) continue;
254  if ( hvId. sectorId != id. sector() ) continue;
255  if ( data.flagA || data.flagC || data.flagS )
256  offNum += ( 1 + data.lCell - data.fCell );
257  }
258  return offNum;
259 }
260 
261 
262 const
264  return dataVersion;
265 }
266 
267 
269  return dataVersion;
270 }
271 
272 
274 // DTDataBuffer<int,int>::dropBuffer( mapName() );
275  delete dBuf;
276  dBuf = 0;
277  dataList.clear();
278  dataList.reserve( 10 );
279  return;
280 }
281 
282 
283 int DTHVStatus::set( int wheelId,
284  int stationId,
285  int sectorId,
286  int slId,
287  int layerId,
288  int partId,
289  int fCell,
290  int lCell,
291  int flagA,
292  int flagC,
293  int flagS ) {
294 
295 // std::string mName = mapName();
296 // DTBufferTree<int,int>* dBuf =
297 // DTDataBuffer<int,int>::findBuffer( mName );
298 // if ( dBuf == 0 ) {
299 // cacheMap();
300 // dBuf =
301 // DTDataBuffer<int,int>::findBuffer( mName );
302 // }
303  if ( dBuf == 0 ) cacheMap();
304  std::vector<int> chanKey;
305  chanKey.reserve(6);
306  chanKey.push_back( wheelId );
307  chanKey.push_back( stationId );
308  chanKey.push_back( sectorId );
309  chanKey.push_back( slId );
310  chanKey.push_back( layerId );
311  chanKey.push_back( partId );
312  int ientry;
313  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
314 
315  if ( !searchStatus ) {
316  DTHVStatusData& data( dataList[ientry].second );
317  data.fCell = fCell;
318  data.lCell = lCell;
319  data.flagA = flagA;
320  data.flagC = flagC;
321  data.flagS = flagS;
322  return -1;
323  }
324  else {
326  key. wheelId = wheelId;
327  key.stationId = stationId;
328  key. sectorId = sectorId;
329  key. slId = slId;
330  key. layerId = layerId;
331  key. partId = partId;
333  data.fCell = fCell;
334  data.lCell = lCell;
335  data.flagA = flagA;
336  data.flagC = flagC;
337  data.flagS = flagS;
338  ientry = dataList.size();
339  dataList.push_back( std::pair<DTHVStatusId,
340  DTHVStatusData>( key, data ) );
341  dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
342  return 0;
343  }
344 
345  return 99;
346 
347 }
348 
349 
350 int DTHVStatus::set( const DTLayerId& id,
351  int partId,
352  int fCell,
353  int lCell,
354  int flagA,
355  int flagC,
356  int flagS ) {
357  return set( id.wheel(),
358  id.station(),
359  id.sector(),
360  id.superLayer(),
361  id.layer(),
362  partId,
363  fCell, lCell, flagA, flagC, flagS );
364 }
365 
366 
367 int DTHVStatus::setFlagA( int wheelId,
368  int stationId,
369  int sectorId,
370  int slId,
371  int layerId,
372  int partId,
373  int flag ) {
374  int fCell;
375  int lCell;
376  int flagA;
377  int flagC;
378  int flagS;
379  get( wheelId,
380  stationId,
381  sectorId,
382  slId,
383  layerId,
384  partId,
385  fCell,
386  lCell,
387  flagA,
388  flagC,
389  flagS );
390  return set( wheelId,
391  stationId,
392  sectorId,
393  slId,
394  layerId,
395  partId,
396  fCell,
397  lCell,
398  flag,
399  flagC,
400  flagS );
401 }
402 
403 
405  int partId,
406  int flag ) {
407  return setFlagA( id.wheel(),
408  id.station(),
409  id.sector(),
410  id.superLayer(),
411  id.layer(),
412  partId,
413  flag );
414 }
415 
416 
417 int DTHVStatus::setFlagC( int wheelId,
418  int stationId,
419  int sectorId,
420  int slId,
421  int layerId,
422  int partId,
423  int flag ) {
424  int fCell;
425  int lCell;
426  int flagA;
427  int flagC;
428  int flagS;
429  get( wheelId,
430  stationId,
431  sectorId,
432  slId,
433  layerId,
434  partId,
435  fCell,
436  lCell,
437  flagA,
438  flagC,
439  flagS );
440  return set( wheelId,
441  stationId,
442  sectorId,
443  slId,
444  layerId,
445  partId,
446  fCell,
447  lCell,
448  flagA,
449  flag,
450  flagS );
451 }
452 
453 
455  int partId,
456  int flag ) {
457  return setFlagC( id.wheel(),
458  id.station(),
459  id.sector(),
460  id.superLayer(),
461  id.layer(),
462  partId,
463  flag );
464 }
465 
466 
467 int DTHVStatus::setFlagS( int wheelId,
468  int stationId,
469  int sectorId,
470  int slId,
471  int layerId,
472  int partId,
473  int flag ) {
474  int fCell;
475  int lCell;
476  int flagA;
477  int flagC;
478  int flagS;
479  get( wheelId,
480  stationId,
481  sectorId,
482  slId,
483  layerId,
484  partId,
485  fCell,
486  lCell,
487  flagA,
488  flagC,
489  flagS );
490  return set( wheelId,
491  stationId,
492  sectorId,
493  slId,
494  layerId,
495  partId,
496  fCell,
497  lCell,
498  flagA,
499  flagC,
500  flag );
501 }
502 
503 
505  int partId,
506  int flag ) {
507  return setFlagS( id.wheel(),
508  id.station(),
509  id.sector(),
510  id.superLayer(),
511  id.layer(),
512  partId,
513  flag );
514 }
515 
516 
518  return dataList.begin();
519 }
520 
521 
523  return dataList.end();
524 }
525 
526 
528  std::stringstream name;
529  name << dataVersion << "_map_HV" << this;
530  return name.str();
531 }
532 
533 
534 void DTHVStatus::cacheMap() const {
535 
536 // std::string mName = mapName();
537 // DTBufferTree<int,int>* dBuf =
538 // DTDataBuffer<int,int>::openBuffer( mName );
539  DTBufferTree<int,int>** pBuf;
540  pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
541  *pBuf = new DTBufferTree<int,int>;
542 
543  int entryNum = 0;
544  int entryMax = dataList.size();
545  std::vector<int> chanKey;
546  chanKey.reserve(6);
547  while ( entryNum < entryMax ) {
548 
549  const DTHVStatusId& chan = dataList[entryNum].first;
550 
551  chanKey.clear();
552  chanKey.push_back( chan. wheelId );
553  chanKey.push_back( chan.stationId );
554  chanKey.push_back( chan. sectorId );
555  chanKey.push_back( chan. slId );
556  chanKey.push_back( chan. layerId );
557  chanKey.push_back( chan. partId );
558  dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
559 
560  }
561 
562  return;
563 
564 }
565 
566 
std::vector< std::pair< DTHVStatusId, DTHVStatusData > > dataList
Definition: DTHVStatus.h:181
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int &fCell, int &lCell, int &flagA, int &flagC, int &flagS) const
get content
Definition: DTHVStatus.cc:88
int setFlagS(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag)
Definition: DTHVStatus.cc:467
DTBufferTree< int, int > * dBuf
Definition: DTHVStatus.h:183
void cacheMap() const
read and store full content
Definition: DTHVStatus.cc:534
void clear()
reset content
Definition: DTHVStatus.cc:273
int insert(ElementKey fKey, ElementKey lKey, const Content &cont)
int setFlagC(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag)
Definition: DTHVStatus.cc:417
int setFlagA(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int flag)
Definition: DTHVStatus.cc:367
U second(std::pair< T, U > const &p)
std::string mapName() const
Definition: DTHVStatus.cc:527
int offChannelsNumber() const
Definition: DTHVStatus.cc:190
int badChannelsNumber() const
Definition: DTHVStatus.cc:229
std::vector< std::pair< DTHVStatusId, DTHVStatusData > >::const_iterator const_iterator
Access methods to data.
Definition: DTHVStatus.h:173
int find(ElementKey fKey, ElementKey lKey, Content &cont)
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int fCell, int lCell, int flagA, int flagC, int flagS)
Definition: DTHVStatus.cc:283
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
list key
Definition: combine.py:13
const_iterator end() const
Definition: DTHVStatus.cc:522
std::string dataVersion
Definition: DTHVStatus.h:179
const_iterator begin() const
Definition: DTHVStatus.cc:517
const std::string & version() const
access version
Definition: DTHVStatus.cc:263