CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTtrig.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2008/12/11 09:44:53 $
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 = nullptr;
39 }
40 
41 
43  dataVersion( version ),
44  nsPerCount( 25.0 / 32.0 ) {
45  dataList.reserve( 1000 );
46  dBuf = nullptr;
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  tTrig( 0.0 ),
62  tTrms( 0.0 ),
63  kFact( 0.0 ) {
64 }
65 
66 
67 //--------------
68 // Destructor --
69 //--------------
71 // DTDataBuffer<int,int>::dropBuffer( mapName() );
72  delete dBuf;
73 }
74 
75 
77 }
78 
79 
81 }
82 
83 //--------------
84 // Operations --
85 //--------------
86 int DTTtrig::get( int wheelId,
87  int stationId,
88  int sectorId,
89  int slId,
90  float& tTrig,
91  float& tTrms,
92  float& kFact,
93  DTTimeUnits::type unit ) const {
94  return get( wheelId, stationId, sectorId,
95  slId, 0, 0,
96  tTrig, tTrms, kFact, unit );
97 
98 }
99 
100 
101 int DTTtrig::get( int wheelId,
102  int stationId,
103  int sectorId,
104  int slId,
105  int layerId,
106  int cellId,
107  float& tTrig,
108  float& tTrms,
109  float& kFact,
110  DTTimeUnits::type unit ) const {
111 
112  tTrig =
113  tTrms =
114  kFact = 0.0;
115 
116 // std::string mName = mapName();
117 // DTBufferTree<int,int>* dBuf =
118 // DTDataBuffer<int,int>::findBuffer( mName );
119 // if ( dBuf == 0 ) {
120 // cacheMap();
121 // dBuf =
122 // DTDataBuffer<int,int>::findBuffer( mName );
123 // }
124  if (!dBuf.load(std::memory_order_acquire)) cacheMap();
125 
126  std::vector<int> chanKey;
127  chanKey.reserve(6);
128  chanKey.push_back( wheelId );
129  chanKey.push_back( stationId );
130  chanKey.push_back( sectorId );
131  chanKey.push_back( slId );
132  chanKey.push_back( layerId );
133  chanKey.push_back( cellId );
134  int ientry;
135  int searchStatus = (*dBuf.load(std::memory_order_acquire)).find( chanKey.begin(), chanKey.end(), ientry );
136  if ( !searchStatus ) {
137  const DTTtrigData& data( dataList[ientry].second );
138  tTrig = data.tTrig;
139  tTrms = data.tTrms;
140  kFact = data.kFact;
141  if ( unit == DTTimeUnits::ns ) {
142  tTrig *= nsPerCount;
143  tTrms *= nsPerCount;
144  }
145  }
146 
147  return searchStatus;
148 
149 }
150 
151 
153  float& tTrig,
154  float& tTrms,
155  float& kFact,
156  DTTimeUnits::type unit ) const {
157  return get( id.wheel(),
158  id.station(),
159  id.sector(),
160  id.superLayer(), 0, 0,
161  tTrig, tTrms, kFact, unit );
162 }
163 
164 
165 int DTTtrig::get( const DetId& id,
166  float& tTrig,
167  float& tTrms,
168  float& kFact,
169  DTTimeUnits::type unit ) const {
170  DTWireId wireId( id.rawId() );
171  return get( wireId.wheel(),
172  wireId.station(),
173  wireId.sector(),
174  wireId.superLayer(),
175  wireId.layer(),
176  wireId.wire(),
177  tTrig, tTrms, kFact, unit );
178 }
179 
180 
181 int DTTtrig::get( int wheelId,
182  int stationId,
183  int sectorId,
184  int slId,
185  float& tTrig,
186  DTTimeUnits::type unit ) const {
187  return get( wheelId, stationId, sectorId,
188  slId, 0, 0, tTrig, unit );
189 }
190 
191 
192 int DTTtrig::get( int wheelId,
193  int stationId,
194  int sectorId,
195  int slId,
196  int layerId,
197  int cellId,
198  float& tTrig,
199  DTTimeUnits::type unit ) const {
200  float tMean;
201  float tTrms;
202  float kFact;
203  int status = get( wheelId, stationId, sectorId,
204  slId, layerId, cellId,
205  tMean, tTrms, kFact, unit );
206  tTrig = tMean + ( kFact * tTrms );
207  return status;
208 }
209 
210 
212  float& tTrig,
213  DTTimeUnits::type unit ) const {
214  return get( id.wheel(),
215  id.station(),
216  id.sector(),
217  id.superLayer(), 0, 0,
218  tTrig, unit );
219 }
220 
221 
222 int DTTtrig::get( const DetId& id,
223  float& tTrig,
224  DTTimeUnits::type unit ) const {
225  DTWireId wireId( id.rawId() );
226  return get( wireId.wheel(),
227  wireId.station(),
228  wireId.sector(),
229  wireId.superLayer(),
230  wireId.layer(),
231  wireId.wire(),
232  tTrig, unit );
233 }
234 
235 
236 float DTTtrig::unit() const {
237  return nsPerCount;
238 }
239 
240 
241 const
243  return dataVersion;
244 }
245 
246 
248  return dataVersion;
249 }
250 
251 
253 // DTDataBuffer<int,int>::dropBuffer( mapName() );
254  delete dBuf;
255  dBuf = nullptr;
256  dataList.clear();
257  return;
258 }
259 
260 
261 int DTTtrig::set( int wheelId,
262  int stationId,
263  int sectorId,
264  int slId,
265  float tTrig,
266  float tTrms,
267  float kFact,
269  return set( wheelId, stationId, sectorId,
270  slId, 0, 0,
271  tTrig, tTrms, kFact, unit );
272 
273 }
274 
275 
276 int DTTtrig::set( int wheelId,
277  int stationId,
278  int sectorId,
279  int slId,
280  int layerId,
281  int cellId,
282  float tTrig,
283  float tTrms,
284  float kFact,
286 
287  if ( unit == DTTimeUnits::ns ) {
288  tTrig /= nsPerCount;
289  tTrms /= nsPerCount;
290  }
291 
292 // std::string mName = mapName();
293 // DTBufferTree<int,int>* dBuf =
294 // DTDataBuffer<int,int>::findBuffer( mName );
295 // if ( dBuf == 0 ) {
296 // cacheMap();
297 // dBuf =
298 // DTDataBuffer<int,int>::findBuffer( mName );
299 // }
300  if (!dBuf.load(std::memory_order_acquire)) cacheMap();
301  std::vector<int> chanKey;
302  chanKey.reserve(6);
303  chanKey.push_back( wheelId );
304  chanKey.push_back( stationId );
305  chanKey.push_back( sectorId );
306  chanKey.push_back( slId );
307  chanKey.push_back( layerId );
308  chanKey.push_back( cellId );
309  int ientry;
310  int searchStatus = (*dBuf.load(std::memory_order_acquire)).find( chanKey.begin(), chanKey.end(), ientry );
311 
312  if ( !searchStatus ) {
313  DTTtrigData& data( dataList[ientry].second );
314  data.tTrig = tTrig;
315  data.tTrms = tTrms;
316  data.kFact = kFact;
317  return -1;
318  }
319  else {
320  DTTtrigId key;
321  key. wheelId = wheelId;
322  key.stationId = stationId;
323  key. sectorId = sectorId;
324  key. slId = slId;
325  key. layerId = layerId;
326  key. cellId = cellId;
328  data.tTrig = tTrig;
329  data.tTrms = tTrms;
330  data.kFact = kFact;
331  ientry = dataList.size();
332  dataList.push_back( std::pair<DTTtrigId,DTTtrigData>( key, data ) );
333  (*dBuf.load(std::memory_order_acquire)).insert( chanKey.begin(), chanKey.end(), ientry );
334  return 0;
335  }
336 
337  return 99;
338 
339 }
340 
341 
343  float tTrig,
344  float tTrms,
345  float kFact,
347  return set( id.wheel(),
348  id.station(),
349  id.sector(),
350  id.superLayer(), 0, 0,
351  tTrig, tTrms, kFact, unit );
352 }
353 
354 
355 int DTTtrig::set( const DetId& id,
356  float tTrig,
357  float tTrms,
358  float kFact,
360  DTWireId wireId( id.rawId() );
361  return set( wireId.wheel(),
362  wireId.station(),
363  wireId.sector(),
364  wireId.superLayer(),
365  wireId.layer(),
366  wireId.wire(),
367  tTrig, tTrms, kFact, unit );
368 }
369 
370 
371 void DTTtrig::setUnit( float unit ) {
372  nsPerCount = unit;
373 }
374 
375 
377  return dataList.begin();
378 }
379 
380 
382  return dataList.end();
383 }
384 
385 
387  std::stringstream name;
388  name << dataVersion << "_map_Ttrig" << this;
389  return name.str();
390 }
391 
392 
393 void DTTtrig::cacheMap() const {
394 
395 // std::string mName = mapName();
396 // DTBufferTree<int,int>* dBuf =
397 // DTDataBuffer<int,int>::openBuffer( mName );
398 //
399  auto pBuf = new DTBufferTree<int,int>;
400 
401  int entryNum = 0;
402  int entryMax = dataList.size();
403  std::vector<int> chanKey;
404  chanKey.reserve(6);
405  while ( entryNum < entryMax ) {
406 
407  const DTTtrigId& chan = dataList[entryNum].first;
408 
409  chanKey.clear();
410  chanKey.push_back( chan. wheelId );
411  chanKey.push_back( chan.stationId );
412  chanKey.push_back( chan. sectorId );
413  chanKey.push_back( chan. slId );
414  chanKey.push_back( chan. layerId );
415  chanKey.push_back( chan. cellId );
416  pBuf->insert( chanKey.begin(), chanKey.end(), entryNum++ );
417  }
418 
419  //atomically try to swap this to become dBuf
420  DTBufferTree<int,int>* expect = nullptr;
421  bool exchanged = dBuf.compare_exchange_strong(expect, pBuf, std::memory_order_acq_rel);
422  if(!exchanged) {
423  //some other thread beat us to this so need to get rid of the work we did
424  delete pBuf;
425  }
426 
427  return;
428 
429 }
430 
~DTTtrigId()
Definition: DTTtrig.cc:76
int set(int wheelId, int stationId, int sectorId, int slId, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit)
Definition: DTTtrig.cc:261
DTTtrigId()
Definition: DTTtrig.cc:50
DTTtrig()
Definition: DTTtrig.cc:34
~DTTtrig()
Definition: DTTtrig.cc:70
~DTTtrigData()
Definition: DTTtrig.cc:80
float nsPerCount
Definition: DTTtrig.h:197
float tTrms
Definition: DTTtrig.h:66
void setUnit(float unit)
Definition: DTTtrig.cc:371
const std::string & version() const
access version
Definition: DTTtrig.cc:242
int stationId
Definition: DTTtrig.h:49
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::atomic< DTBufferTree< int, int > * > dBuf
Definition: DTTtrig.h:202
std::vector< std::pair< DTTtrigId, DTTtrigData > > dataList
Definition: DTTtrig.h:199
DTTtrigData()
Definition: DTTtrig.cc:60
void clear()
reset content
Definition: DTTtrig.cc:252
std::vector< std::pair< DTTtrigId, DTTtrigData > >::const_iterator const_iterator
Access methods to data.
Definition: DTTtrig.h:179
U second(std::pair< T, U > const &p)
string unit
Definition: csvLumiCalc.py:46
int superLayer() const
Return the superlayer number.
std::string mapName() const
Definition: DTTtrig.cc:386
float unit() const
Definition: DTTtrig.cc:236
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
void cacheMap() const
read and store full content
Definition: DTTtrig.cc:393
int wire() const
Return the wire number.
Definition: DTWireId.h:56
float kFact
Definition: DTTtrig.h:67
Definition: DetId.h:18
std::string dataVersion
Definition: DTTtrig.h:196
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:86
float tTrig
Definition: DTTtrig.h:65
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
list key
Definition: combine.py:13
int sector() const
Definition: DTChamberId.h:61
const_iterator begin() const
Definition: DTTtrig.cc:376
tuple status
Definition: ntuplemaker.py:245
int station() const
Return the station number.
Definition: DTChamberId.h:51
const_iterator end() const
Definition: DTTtrig.cc:381
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45