CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTMtime.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.16 $
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  nsPerCount( 25.0 / 32.0 ) {
37  dataList.reserve( 1000 );
38  dBuf = 0;
39 }
40 
41 
42 DTMtime::DTMtime( const std::string& version ):
43  dataVersion( version ),
44  nsPerCount( 25.0 / 32.0 ) {
45  dataList.reserve( 1000 );
46  dBuf = 0;
47 }
48 
49 
51  wheelId( 0 ),
52  stationId( 0 ),
53  sectorId( 0 ),
54  slId( 0 ),
55  layerId( 0 ),
56  cellId( 0 ) {
57 }
58 
59 
61  mTime( 0.0 ),
62  mTrms( 0.0 ) {
63 }
64 
65 
66 //--------------
67 // Destructor --
68 //--------------
70 // DTDataBuffer<int,int>::dropBuffer( mapName() );
71  delete dBuf;
72 }
73 
74 
76 }
77 
78 
80 }
81 
82 
83 //--------------
84 // Operations --
85 //--------------
86 int DTMtime::get( int wheelId,
87  int stationId,
88  int sectorId,
89  int slId,
90  float& mTime,
91  float& mTrms,
92  DTTimeUnits::type unit ) const {
93  return get( wheelId, stationId, sectorId,
94  slId, 0, 0,
95  mTime, mTrms, unit );
96 
97 }
98 
99 
100 int DTMtime::get( int wheelId,
101  int stationId,
102  int sectorId,
103  int slId,
104  float& mTime,
105  float& mTrms,
106  DTVelocityUnits::type unit ) const {
107  return get( wheelId, stationId, sectorId,
108  slId, 0, 0,
109  mTime, mTrms, unit );
110 
111 }
112 
113 
114 int DTMtime::get( int wheelId,
115  int stationId,
116  int sectorId,
117  int slId,
118  int layerId,
119  int cellId,
120  float& mTime,
121  float& mTrms,
122  DTTimeUnits::type unit ) const {
123 
124  mTime =
125  mTrms = 0.0;
126 
127 // std::string mName = mapName();
128 // DTBufferTree<int,int>* dBuf =
129 // DTDataBuffer<int,int>::findBuffer( mName );
130 // if ( dBuf == 0 ) {
131 // cacheMap();
132 // dBuf =
133 // DTDataBuffer<int,int>::findBuffer( mName );
134 // }
135  if ( dBuf == 0 ) cacheMap();
136 
137  std::vector<int> chanKey;
138  chanKey.reserve(6);
139  chanKey.push_back( wheelId );
140  chanKey.push_back( stationId );
141  chanKey.push_back( sectorId );
142  chanKey.push_back( slId );
143  chanKey.push_back( layerId );
144  chanKey.push_back( cellId );
145  int ientry;
146  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
147  if ( !searchStatus ) {
148  const DTMtimeData& data( dataList[ientry].second );
149  mTime = data.mTime;
150  mTrms = data.mTrms;
151  if ( unit == DTTimeUnits::ns ) {
152  mTime *= nsPerCount;
153  mTrms *= nsPerCount;
154  }
155  }
156 
157  return searchStatus;
158 
159 }
160 
161 
162 int DTMtime::get( int wheelId,
163  int stationId,
164  int sectorId,
165  int slId,
166  int layerId,
167  int cellId,
168  float& mTime,
169  float& mTrms,
170  DTVelocityUnits::type unit ) const {
171  int status = get( wheelId, stationId, sectorId,
172  slId, layerId, cellId,
173  mTime, mTrms, DTTimeUnits::counts );
174  if ( unit == DTVelocityUnits::cm_per_count ) {
175  mTime = 2.1 / mTime;
176  mTrms *= mTime;
177  }
178  if ( unit == DTVelocityUnits::cm_per_ns ) {
179  mTime = 2.1 / mTime;
180  mTrms *= mTime;
181  mTime /= nsPerCount;
182  }
183  return status;
184 }
185 
186 
188  float& mTime,
189  float& mTrms,
190  DTTimeUnits::type unit ) const {
191  return get( id.wheel(),
192  id.station(),
193  id.sector(),
194  id.superLayer(), 0, 0,
195  mTime, mTrms, unit );
196 }
197 
198 
200  float& mTime,
201  float& mTrms,
202  DTVelocityUnits::type unit ) const {
203  return get( id.wheel(),
204  id.station(),
205  id.sector(),
206  id.superLayer(), 0, 0,
207  mTime, mTrms, unit );
208 }
209 
210 
211 int DTMtime::get( const DetId& id,
212  float& mTime,
213  float& mTrms,
214  DTTimeUnits::type unit ) const {
215  DTWireId wireId( id.rawId() );
216  return get( wireId.wheel(),
217  wireId.station(),
218  wireId.sector(),
219  wireId.superLayer(),
220  wireId.layer(),
221  wireId.wire(),
222  mTime, mTrms, unit );
223 }
224 
225 
226 int DTMtime::get( const DetId& id,
227  float& mTime,
228  float& mTrms,
229  DTVelocityUnits::type unit ) const {
230  DTWireId wireId( id.rawId() );
231  return get( wireId.wheel(),
232  wireId.station(),
233  wireId.sector(),
234  wireId.superLayer(),
235  wireId.layer(),
236  wireId.wire(),
237  mTime, mTrms, unit );
238 }
239 
240 
241 float DTMtime::unit() const {
242  return nsPerCount;
243 }
244 
245 
246 const
247 std::string& DTMtime::version() const {
248  return dataVersion;
249 }
250 
251 
252 std::string& DTMtime::version() {
253  return dataVersion;
254 }
255 
256 
258 // DTDataBuffer<int,int>::dropBuffer( mapName() );
259  delete dBuf;
260  dBuf = 0;
261  dataList.clear();
262  return;
263 }
264 
265 
266 int DTMtime::set( int wheelId,
267  int stationId,
268  int sectorId,
269  int slId,
270  float mTime,
271  float mTrms,
273  return set( wheelId, stationId, sectorId,
274  slId, 0, 0,
275  mTime, mTrms, unit );
276 }
277 
278 
279 int DTMtime::set( int wheelId,
280  int stationId,
281  int sectorId,
282  int slId,
283  float mTime,
284  float mTrms,
286  return set( wheelId, stationId, sectorId,
287  slId, 0, 0,
288  mTime, mTrms, unit );
289 }
290 
291 
292 int DTMtime::set( int wheelId,
293  int stationId,
294  int sectorId,
295  int slId,
296  int layerId,
297  int cellId,
298  float mTime,
299  float mTrms,
301 
302  if ( unit == DTTimeUnits::ns ) {
303  mTime /= nsPerCount;
304  mTrms /= nsPerCount;
305  }
306 
307 // std::string mName = mapName();
308 // DTBufferTree<int,int>* dBuf =
309 // DTDataBuffer<int,int>::findBuffer( mName );
310 // if ( dBuf == 0 ) {
311 // cacheMap();
312 // dBuf =
313 // DTDataBuffer<int,int>::findBuffer( mName );
314 // }
315  if ( dBuf == 0 ) cacheMap();
316  std::vector<int> chanKey;
317  chanKey.reserve(6);
318  chanKey.push_back( wheelId );
319  chanKey.push_back( stationId );
320  chanKey.push_back( sectorId );
321  chanKey.push_back( slId );
322  chanKey.push_back( layerId );
323  chanKey.push_back( cellId );
324  int ientry;
325  int searchStatus = dBuf->find( chanKey.begin(), chanKey.end(), ientry );
326 
327  if ( !searchStatus ) {
328  DTMtimeData& data( dataList[ientry].second );
329  data.mTime = mTime;
330  data.mTrms = mTrms;
331  return -1;
332  }
333  else {
334  DTMtimeId key;
335  key. wheelId = wheelId;
336  key.stationId = stationId;
337  key. sectorId = sectorId;
338  key. slId = slId;
339  key. layerId = layerId;
340  key. cellId = cellId;
342  data.mTime = mTime;
343  data.mTrms = mTrms;
344  ientry = dataList.size();
345  dataList.push_back( std::pair<DTMtimeId,DTMtimeData>( key, data ) );
346  dBuf->insert( chanKey.begin(), chanKey.end(), ientry );
347  return 0;
348  }
349 
350  return 99;
351 
352 }
353 
354 
355 int DTMtime::set( int wheelId,
356  int stationId,
357  int sectorId,
358  int slId,
359  int layerId,
360  int cellId,
361  float mTime,
362  float mTrms,
364  if ( unit == DTVelocityUnits::cm_per_count ) {
365  mTrms /= mTime;
366  mTime = 2.1 / mTime;
367  }
368  if ( unit == DTVelocityUnits::cm_per_ns ) {
369  mTime *= nsPerCount;
370  mTrms /= mTime;
371  mTime = 2.1 / mTime;
372  }
373  return set( wheelId, stationId, sectorId,
374  slId, layerId, cellId,
375  mTime, mTrms, DTTimeUnits::counts );
376 
377 }
378 
379 
381  float mTime,
382  float mTrms,
384  return set( id.wheel(),
385  id.station(),
386  id.sector(),
387  id.superLayer(), 0, 0,
388  mTime, mTrms, unit );
389 }
390 
391 
393  float mTime,
394  float mTrms,
396  return set( id.wheel(),
397  id.station(),
398  id.sector(),
399  id.superLayer(), 0, 0,
400  mTime, mTrms, unit );
401 }
402 
403 
404 int DTMtime::set( const DetId& id,
405  float mTime,
406  float mTrms,
408  DTWireId wireId( id.rawId() );
409  return set( wireId.wheel(),
410  wireId.station(),
411  wireId.sector(),
412  wireId.superLayer(),
413  wireId.layer(),
414  wireId.wire(),
415  mTime, mTrms, unit );
416 }
417 
418 
419 int DTMtime::set( const DetId& id,
420  float mTime,
421  float mTrms,
423  DTWireId wireId( id.rawId() );
424  return set( wireId.wheel(),
425  wireId.station(),
426  wireId.sector(),
427  wireId.superLayer(),
428  wireId.layer(),
429  wireId.wire(),
430  mTime, mTrms, unit );
431 }
432 
433 
434 void DTMtime::setUnit( float unit ) {
435  nsPerCount = unit;
436 }
437 
438 
440  return dataList.begin();
441 }
442 
443 
445  return dataList.end();
446 }
447 
448 
449 std::string DTMtime::mapName() const {
450  std::stringstream name;
451  name << dataVersion << "_map_Mtime" << this;
452  return name.str();
453 }
454 
455 
456 void DTMtime::cacheMap() const {
457 
458 // std::string mName = mapName();
459 // DTBufferTree<int,int>* dBuf =
460 // DTDataBuffer<int,int>::openBuffer( mName );
461  DTBufferTree<int,int>** pBuf;
462  pBuf = const_cast<DTBufferTree<int,int>**>( &dBuf );
463  *pBuf = new DTBufferTree<int,int>;
464 
465  int entryNum = 0;
466  int entryMax = dataList.size();
467  std::vector<int> chanKey;
468  chanKey.reserve(6);
469  while ( entryNum < entryMax ) {
470 
471  const DTMtimeId& chan = dataList[entryNum].first;
472 
473  chanKey.clear();
474  chanKey.push_back( chan. wheelId );
475  chanKey.push_back( chan.stationId );
476  chanKey.push_back( chan. sectorId );
477  chanKey.push_back( chan. slId );
478  chanKey.push_back( chan. layerId );
479  chanKey.push_back( chan. cellId );
480  dBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
481 
482  }
483 
484  return;
485 
486 }
487 
int stationId
Definition: DTMtime.h:47
float nsPerCount
Definition: DTMtime.h:263
~DTMtimeData()
Definition: DTMtime.cc:79
int set(int wheelId, int stationId, int sectorId, int slId, float mTime, float mTrms, DTTimeUnits::type unit)
Definition: DTMtime.cc:266
int insert(ElementKey fKey, ElementKey lKey, const Content &cont)
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
void setUnit(float unit)
Definition: DTMtime.cc:434
U second(std::pair< T, U > const &p)
void cacheMap() const
read and store full content
Definition: DTMtime.cc:456
DTBufferTree< int, int > * dBuf
Definition: DTMtime.h:267
string unit
Definition: csvLumiCalc.py:46
DTMtimeData()
Definition: DTMtime.cc:60
int superLayer() const
Return the superlayer number.
float mTrms
Definition: DTMtime.h:64
int wire() const
Return the wire number.
Definition: DTWireId.h:58
Definition: DetId.h:20
std::vector< std::pair< DTMtimeId, DTMtimeData > > dataList
Definition: DTMtime.h:265
const_iterator begin() const
Definition: DTMtime.cc:439
std::vector< std::pair< DTMtimeId, DTMtimeData > >::const_iterator const_iterator
Access methods to data.
Definition: DTMtime.h:256
std::string mapName() const
Definition: DTMtime.cc:449
int find(ElementKey fKey, ElementKey lKey, Content &cont)
DTMtime()
Definition: DTMtime.cc:34
float unit() const
Definition: DTMtime.cc:241
const std::string & version() const
access version
Definition: DTMtime.cc:247
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:86
~DTMtime()
Definition: DTMtime.cc:69
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
list key
Definition: combine.py:13
float mTime
Definition: DTMtime.h:63
DTMtimeId()
Definition: DTMtime.cc:50
int sector() const
Definition: DTChamberId.h:63
const_iterator end() const
Definition: DTMtime.cc:444
~DTMtimeId()
Definition: DTMtime.cc:75
std::string dataVersion
Definition: DTMtime.h:262
void clear()
reset content
Definition: DTMtime.cc:257
tuple status
Definition: ntuplemaker.py:245
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47