CMS 3D CMS Logo

DTReadOutMapping.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //----------------------
9 // This Class' Header --
10 //----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
18 
19 //---------------
20 // C++ Headers --
21 //---------------
22 #include <iostream>
23 #include <sstream>
24 #include <map>
25 
26 //-------------------
27 // Initializations --
28 //-------------------
29 
30 //----------------
31 // Constructors --
32 //----------------
34  : cellMapVersion(" "), robMapVersion(" "), rgBuf(new DTBufferTree<int, int>), grBuf(new DTBufferTree<int, int>) {
35  readOutChannelDriftTubeMap.reserve(2000);
36 }
37 
38 DTReadOutMapping::DTReadOutMapping(const std::string& cell_map_version, const std::string& rob_map_version)
39  : cellMapVersion(cell_map_version),
40  robMapVersion(rob_map_version),
41  rgBuf(new DTBufferTree<int, int>),
42  grBuf(new DTBufferTree<int, int>) {
43  readOutChannelDriftTubeMap.reserve(2000);
44 }
45 
47  : dduId(0),
48  rosId(0),
49  robId(0),
50  tdcId(0),
51  channelId(0),
52  wheelId(0),
53  stationId(0),
54  sectorId(0),
55  slId(0),
56  layerId(0),
57  cellId(0) {}
58 
59 //--------------
60 // Destructor --
61 //--------------
63 
65 
66 //--------------
67 // Operations --
68 //--------------
70  int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId& wireId) const {
71  int wheelId;
72  int stationId;
73  int sectorId;
74  int slId;
75  int layerId;
76  int cellId;
77 
78  int status =
79  readOutToGeometry(dduId, rosId, robId, tdcId, channelId, wheelId, stationId, sectorId, slId, layerId, cellId);
80 
81  wireId = DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
82  return status;
83 }
84 
86  int rosId,
87  int robId,
88  int tdcId,
89  int channelId,
90  int& wheelId,
91  int& stationId,
92  int& sectorId,
93  int& slId,
94  int& layerId,
95  int& cellId) const {
96  wheelId = stationId = sectorId = slId = layerId = cellId = 0;
97 
98  if (!atomicCache().isSet()) {
99  cacheMap();
100  }
101 
102  int defaultValue;
104  if (defaultValue) {
105  int searchStatus;
106  int ientry;
107 
108  std::vector<int> dduKey;
109  dduKey.reserve(5);
110  dduKey.push_back(dduId);
111  dduKey.push_back(rosId);
112  searchStatus = atomicCache()->rgDDU.find(dduKey.begin(), dduKey.end(), ientry);
113  if (searchStatus)
114  return searchStatus;
116  wheelId = lros.wheelId;
117  sectorId = lros.sectorId;
118 
119  std::vector<int> rosKey;
120  rosKey.reserve(5);
121  rosKey.push_back(lros.cellId);
122  rosKey.push_back(robId);
123  searchStatus = atomicCache()->rgROS.find(rosKey.begin(), rosKey.end(), ientry);
124  if (searchStatus)
125  return searchStatus;
127  if (lrob.wheelId != defaultValue)
128  wheelId = lrob.wheelId;
129  stationId = lrob.stationId;
130  if (lrob.sectorId != defaultValue)
131  sectorId = lrob.sectorId;
132 
133  std::vector<int> robKey;
134  robKey.reserve(5);
135  robKey.push_back(lrob.cellId);
136  robKey.push_back(tdcId);
137  robKey.push_back(channelId);
138  searchStatus = atomicCache()->rgROB.find(robKey.begin(), robKey.end(), ientry);
139  if (searchStatus)
140  return searchStatus;
142  slId = ltdc.slId;
143  layerId = ltdc.layerId;
144  cellId = ltdc.cellId;
145  return 0;
146  }
147 
148  std::vector<int> chanKey;
149  chanKey.reserve(5);
150  chanKey.push_back(dduId);
151  chanKey.push_back(rosId);
152  chanKey.push_back(robId);
153  chanKey.push_back(tdcId);
154  chanKey.push_back(channelId);
155  int ientry;
156  int searchStatus = atomicCache()->rgBuf.find(chanKey.begin(), chanKey.end(), ientry);
157  if (!searchStatus) {
159  wheelId = link.wheelId;
160  stationId = link.stationId;
161  sectorId = link.sectorId;
162  slId = link.slId;
163  layerId = link.layerId;
164  cellId = link.cellId;
165  }
166 
167  return searchStatus;
168 }
169 
171  const DTWireId& wireId, int& dduId, int& rosId, int& robId, int& tdcId, int& channelId) const {
172  return geometryToReadOut(wireId.wheel(),
173  wireId.station(),
174  wireId.sector(),
175  wireId.superLayer(),
176  wireId.layer(),
177  wireId.wire(),
178  dduId,
179  rosId,
180  robId,
181  tdcId,
182  channelId);
183 }
184 
186  int stationId,
187  int sectorId,
188  int slId,
189  int layerId,
190  int cellId,
191  int& dduId,
192  int& rosId,
193  int& robId,
194  int& tdcId,
195  int& channelId) const {
196  dduId = rosId = robId = tdcId = channelId = 0;
197 
198  if (!atomicCache().isSet()) {
199  cacheMap();
200  }
201 
202  int defaultValue;
204  if (defaultValue) {
205  int searchStatus;
206  int mapId = 0;
207  std::vector<int> const* robMLgr;
208  std::vector<int> const* rosMLgr;
209  std::vector<int> const* dduMLgr;
210 
211  std::vector<int> cellKey;
212  cellKey.reserve(6);
213  cellKey.push_back(cellId);
214  cellKey.push_back(layerId);
215  cellKey.push_back(slId);
216  std::vector<int> stdcKey = cellKey;
217  searchStatus = atomicCache()->grROB.find(cellKey.begin(), cellKey.end(), robMLgr);
218  if (searchStatus)
219  return searchStatus;
220  if (robMLgr->empty())
221  return 1;
222  std::vector<int>::const_iterator tdc_iter = robMLgr->begin();
223  std::vector<int>::const_iterator tdc_iend = robMLgr->end();
224  while (tdc_iter != tdc_iend) {
225  const DTReadOutGeometryLink& ltdc(readOutChannelDriftTubeMap[*tdc_iter++]);
226  channelId = ltdc.channelId;
227  tdcId = ltdc.tdcId;
228  mapId = ltdc.rosId;
229  cellKey.clear();
230  cellKey.push_back(mapId);
231  cellKey.push_back(stationId);
232  std::vector<int> srosKey = cellKey;
233  searchStatus = atomicCache()->grROS.find(cellKey.begin(), cellKey.end(), rosMLgr);
234  if (searchStatus)
235  continue;
236  if (rosMLgr->empty())
237  continue;
238  std::vector<int>::const_iterator ros_iter = rosMLgr->begin();
239  std::vector<int>::const_iterator ros_iend = rosMLgr->end();
240  while (ros_iter != ros_iend) {
241  const DTReadOutGeometryLink& lros(readOutChannelDriftTubeMap[*ros_iter++]);
242  int secCk = lros.sectorId;
243  int wheCk = lros.wheelId;
244  if ((secCk != defaultValue) && (secCk != sectorId))
245  continue;
246  if ((wheCk != defaultValue) && (wheCk != wheelId))
247  continue;
248  robId = lros.robId;
249  mapId = lros.rosId;
250  cellKey.clear();
251  cellKey.push_back(mapId);
252  cellKey.push_back(wheelId);
253  cellKey.push_back(sectorId);
254  std::vector<int> sdduKey = cellKey;
255  searchStatus = atomicCache()->grDDU.find(cellKey.begin(), cellKey.end(), dduMLgr);
256  if (searchStatus)
257  continue;
258  if (dduMLgr->empty())
259  continue;
260  if (searchStatus)
261  return searchStatus;
262  if (dduMLgr->empty())
263  return 1;
264  std::vector<int>::const_iterator ddu_iter = dduMLgr->begin();
265  std::vector<int>::const_iterator ddu_iend = dduMLgr->end();
266  while (ddu_iter != ddu_iend) {
267  const DTReadOutGeometryLink& lddu(readOutChannelDriftTubeMap[*ddu_iter++]);
268  if (((sectorId == secCk) || (sectorId == lddu.sectorId)) &&
269  ((wheelId == wheCk) || (wheelId == lddu.wheelId))) {
270  rosId = lddu.rosId;
271  dduId = lddu.dduId;
272  return 0;
273  }
274  }
275  }
276  }
277 
278  return 1;
279  }
280 
281  std::vector<int> cellKey;
282  cellKey.reserve(6);
283  cellKey.push_back(wheelId);
284  cellKey.push_back(stationId);
285  cellKey.push_back(sectorId);
286  cellKey.push_back(slId);
287  cellKey.push_back(layerId);
288  cellKey.push_back(cellId);
289  int ientry;
290  int searchStatus = atomicCache()->grBuf.find(cellKey.begin(), cellKey.end(), ientry);
291  if (!searchStatus) {
293  dduId = link.dduId;
294  rosId = link.rosId;
295  robId = link.robId;
296  tdcId = link.tdcId;
297  channelId = link.channelId;
298  }
299 
300  return searchStatus;
301 }
302 
304  if (!atomicCache().isSet()) {
305  cacheMap();
306  }
307 
308  int defaultValue;
310  if (defaultValue)
311  return compact;
312  else
313  return plain;
314 }
315 
317 
319 
321 
323 
325  atomicCache().reset();
326  rgBuf->clear();
327  grBuf->clear();
329  return;
330 }
331 
333  int rosId,
334  int robId,
335  int tdcId,
336  int channelId,
337  int wheelId,
338  int stationId,
339  int sectorId,
340  int slId,
341  int layerId,
342  int cellId) {
344  link.dduId = dduId;
345  link.rosId = rosId;
346  link.robId = robId;
347  link.tdcId = tdcId;
348  link.channelId = channelId;
349  link.wheelId = wheelId;
350  link.stationId = stationId;
351  link.sectorId = sectorId;
352  link.slId = slId;
353  link.layerId = layerId;
354  link.cellId = cellId;
355 
356  int ientry = readOutChannelDriftTubeMap.size();
357  readOutChannelDriftTubeMap.push_back(link);
358 
359  DTBufferTree<int, int>* pgrBuf;
360  DTBufferTree<int, int>* prgBuf;
361 
362  if (atomicCache().isSet()) {
363  pgrBuf = &atomicCache()->grBuf;
364  prgBuf = &atomicCache()->rgBuf;
365  } else {
366  pgrBuf = grBuf.get();
367  prgBuf = rgBuf.get();
368  }
369 
370  std::vector<int> cellKey;
371  cellKey.reserve(6);
372  cellKey.push_back(wheelId);
373  cellKey.push_back(stationId);
374  cellKey.push_back(sectorId);
375  cellKey.push_back(slId);
376  cellKey.push_back(layerId);
377  cellKey.push_back(cellId);
378  int grStatus = pgrBuf->insert(cellKey.begin(), cellKey.end(), ientry);
379 
380  std::vector<int> chanKey;
381  chanKey.reserve(5);
382  chanKey.push_back(dduId);
383  chanKey.push_back(rosId);
384  chanKey.push_back(robId);
385  chanKey.push_back(tdcId);
386  chanKey.push_back(channelId);
387  int rgStatus = prgBuf->insert(chanKey.begin(), chanKey.end(), ientry);
388 
389  if (grStatus || rgStatus)
390  return 1;
391  else
392  return 0;
393 }
394 
396 
398 
400  if (mapType() == plain)
401  return this;
402  return expandMap(*this);
403 }
404 
405 // The code for this function was copied verbatim from
406 // CondCore/DTPlugins/src/DTCompactMapPluginHandler.c
408  std::vector<DTReadOutGeometryLink> entryList;
409  DTReadOutMapping::const_iterator compIter = compMap.begin();
410  DTReadOutMapping::const_iterator compIend = compMap.end();
411  while (compIter != compIend)
412  entryList.push_back(*compIter++);
413 
414  std::string rosMap = "expand_";
415  rosMap += compMap.mapRobRos();
416  std::string tdcMap = "expand_";
417  tdcMap += compMap.mapCellTdc();
418  DTReadOutMapping* fullMap = new DTReadOutMapping(tdcMap, rosMap);
419  int ddu;
420  int ros;
421  int rch;
422  int tdc;
423  int tch;
424  int whe;
425  int sta;
426  int sec;
427  int rob;
428  int qua;
429  int lay;
430  int cel;
431  int mt1;
432  int mi1;
433  int mt2;
434  int mi2;
435  int def;
436  int wha;
437  int sea;
438  std::vector<DTReadOutGeometryLink>::const_iterator iter = entryList.begin();
439  std::vector<DTReadOutGeometryLink>::const_iterator iend = entryList.end();
440  std::vector<DTReadOutGeometryLink>::const_iterator iros = entryList.end();
441  std::vector<DTReadOutGeometryLink>::const_iterator irob = entryList.end();
442  while (iter != iend) {
443  const DTReadOutGeometryLink& rosEntry(*iter++);
444  if (rosEntry.dduId > 0x3fffffff)
445  continue;
446  ddu = rosEntry.dduId;
447  ros = rosEntry.rosId;
448  whe = rosEntry.wheelId;
449  def = rosEntry.stationId;
450  sec = rosEntry.sectorId;
451  rob = rosEntry.slId;
452  mt1 = rosEntry.layerId;
453  mi1 = rosEntry.cellId;
454  iros = entryList.begin();
455  while (iros != iend) {
456  wha = whe;
457  sea = sec;
458  const DTReadOutGeometryLink& rchEntry(*iros++);
459  if ((rchEntry.dduId != mt1) || (rchEntry.rosId != mi1))
460  continue;
461  rch = rchEntry.robId;
462  if (rchEntry.wheelId != def)
463  wha = rchEntry.wheelId;
464  sta = rchEntry.stationId;
465  if (rchEntry.sectorId != def)
466  sea = rchEntry.sectorId;
467  rob = rchEntry.slId;
468  mt2 = rchEntry.layerId;
469  mi2 = rchEntry.cellId;
470  irob = entryList.begin();
471  while (irob != iend) {
472  const DTReadOutGeometryLink& robEntry(*irob++);
473  if ((robEntry.dduId != mt2) || (robEntry.rosId != mi2))
474  continue;
475  if (robEntry.robId != rob) {
476  std::cout << "ROB mismatch " << rob << " " << robEntry.robId << std::endl;
477  }
478  tdc = robEntry.tdcId;
479  tch = robEntry.channelId;
480  qua = robEntry.slId;
481  lay = robEntry.layerId;
482  cel = robEntry.cellId;
483  fullMap->insertReadOutGeometryLink(ddu, ros, rch, tdc, tch, wha, sta, sea, qua, lay, cel);
484  }
485  }
486  }
487  return fullMap;
488 }
489 
491  std::stringstream name;
492  name << cellMapVersion << "_" << robMapVersion << "_map_GR" << this;
493  return name.str();
494 }
495 
497  std::stringstream name;
498  name << cellMapVersion << "_" << robMapVersion << "_map_RG" << this;
499  return name.str();
500 }
501 
503  std::unique_ptr<DTReadOutMappingCache> localCache(new DTReadOutMappingCache);
504 
505  localCache->mType.insert(0, 0);
506 
507  int entryNum = 0;
508  int entryMax = readOutChannelDriftTubeMap.size();
509  std::vector<int> cellKey;
510  cellKey.reserve(6);
511  std::vector<int> chanKey;
512  chanKey.reserve(5);
513  int defaultValue = 0;
514  int key;
515  int val;
516  int rosMapKey = 0;
517  int robMapKey = 0;
518  std::map<int, std::vector<int>*> dduEntries;
519  for (entryNum = 0; entryNum < entryMax; entryNum++) {
520  const DTReadOutGeometryLink& link(readOutChannelDriftTubeMap[entryNum]);
521 
522  key = link.dduId;
523  val = link.stationId;
524  if (key > 0x3fffffff) {
525  if (link.tdcId > 0x3fffffff) {
526  localCache->mType.insert(0, defaultValue = link.tdcId);
527  rosMapKey = key;
528  } else {
529  localCache->mType.insert(0, defaultValue = link.wheelId);
530  robMapKey = key;
531  }
532  }
533 
534  if (defaultValue == 0) {
535  chanKey.clear();
536  chanKey.push_back(link.dduId);
537  chanKey.push_back(link.rosId);
538  chanKey.push_back(link.robId);
539  chanKey.push_back(link.tdcId);
540  chanKey.push_back(link.channelId);
541 
542  localCache->rgBuf.insert(chanKey.begin(), chanKey.end(), entryNum);
543 
544  cellKey.clear();
545  cellKey.push_back(link.wheelId);
546  cellKey.push_back(link.stationId);
547  cellKey.push_back(link.sectorId);
548  cellKey.push_back(link.slId);
549  cellKey.push_back(link.layerId);
550  cellKey.push_back(link.cellId);
551 
552  localCache->grBuf.insert(cellKey.begin(), cellKey.end(), entryNum);
553  }
554 
555  if (key == robMapKey) {
556  chanKey.clear();
557  chanKey.push_back(link.rosId);
558  chanKey.push_back(link.tdcId);
559  chanKey.push_back(link.channelId);
560  localCache->rgROB.insert(chanKey.begin(), chanKey.end(), entryNum);
561 
562  cellKey.clear();
563  cellKey.push_back(link.cellId);
564  cellKey.push_back(link.layerId);
565  cellKey.push_back(link.slId);
566  std::vector<int>* robMLgr;
567  localCache->grROB.find(cellKey.begin(), cellKey.end(), robMLgr);
568  if (robMLgr == nullptr) {
569  std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
570  robMLgr = newVector.get();
571  localCache->grROB.insert(cellKey.begin(), cellKey.end(), std::move(newVector));
572  }
573  robMLgr->push_back(entryNum);
574  }
575 
576  if (key == rosMapKey) {
577  chanKey.clear();
578  chanKey.push_back(link.rosId);
579  chanKey.push_back(link.robId);
580  localCache->rgROS.insert(chanKey.begin(), chanKey.end(), entryNum);
581 
582  cellKey.clear();
583  cellKey.push_back(link.cellId);
584  cellKey.push_back(link.stationId);
585  std::vector<int>* rosMLgr;
586  localCache->grROS.find(cellKey.begin(), cellKey.end(), rosMLgr);
587  if (rosMLgr == nullptr) {
588  std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
589  rosMLgr = newVector.get();
590  localCache->grROS.insert(cellKey.begin(), cellKey.end(), std::move(newVector));
591  }
592  rosMLgr->push_back(entryNum);
593  }
594 
595  if ((key < 0x3fffffff) && (val > 0x3fffffff)) {
596  chanKey.clear();
597  chanKey.push_back(link.dduId);
598  chanKey.push_back(link.rosId);
599  localCache->rgDDU.insert(chanKey.begin(), chanKey.end(), entryNum);
600 
601  int mapId = link.cellId;
602  std::vector<int>* dduMLgr;
603  std::map<int, std::vector<int>*>::const_iterator dduEntIter = dduEntries.find(mapId);
604  if (dduEntIter == dduEntries.end())
605  dduEntries.insert(std::pair<int, std::vector<int>*>(mapId, dduMLgr = new std::vector<int>));
606  else
607  dduMLgr = dduEntIter->second;
608  dduMLgr->push_back(entryNum);
609  }
610  }
611 
612  if (defaultValue != 0) {
613  for (entryNum = 0; entryNum < entryMax; entryNum++) {
614  const DTReadOutGeometryLink& link(readOutChannelDriftTubeMap[entryNum]);
615  key = link.dduId;
616  if (key != rosMapKey)
617  continue;
618  int mapId = link.rosId;
619  int whchkId = link.wheelId;
620  int secchkId = link.sectorId;
621 
622  std::vector<int>* dduMLgr;
623  std::map<int, std::vector<int>*>::const_iterator dduEntIter = dduEntries.find(mapId);
624  if (dduEntIter != dduEntries.end())
625  dduMLgr = dduEntIter->second;
626  else
627  continue;
628  std::vector<int>::const_iterator dduIter = dduMLgr->begin();
629  std::vector<int>::const_iterator dduIend = dduMLgr->end();
630  while (dduIter != dduIend) {
631  int ientry = *dduIter++;
633  int wheelId = whchkId;
634  int sectorId = secchkId;
635  if (wheelId == defaultValue)
636  wheelId = lros.wheelId;
637  if (sectorId == defaultValue)
638  sectorId = lros.sectorId;
639  cellKey.clear();
640  cellKey.push_back(mapId);
641  cellKey.push_back(wheelId);
642  cellKey.push_back(sectorId);
643  std::vector<int>* dduMLgr = nullptr;
644  localCache->grDDU.find(cellKey.begin(), cellKey.end(), dduMLgr);
645  if (dduMLgr == nullptr) {
646  std::unique_ptr<std::vector<int> > newVector(new std::vector<int>);
647  dduMLgr = newVector.get();
648  localCache->grDDU.insert(cellKey.begin(), cellKey.end(), std::move(newVector));
649  }
650  dduMLgr->push_back(ientry);
651  }
652  }
653 
654  std::map<int, std::vector<int>*>::const_iterator dduEntIter = dduEntries.begin();
655  std::map<int, std::vector<int>*>::const_iterator dduEntIend = dduEntries.end();
656  while (dduEntIter != dduEntIend) {
657  const std::pair<int, std::vector<int>*>& dduEntry = *dduEntIter++;
658  delete dduEntry.second;
659  }
660 
661  localCache->rgBuf.clear();
662  localCache->grBuf.clear();
663  }
664 
665  atomicCache().set(std::move(localCache));
666 
667  return;
668 }
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
DTBufferTree< int, int > rgDDU
int station() const
Return the station number.
Definition: DTChamberId.h:42
int def(FILE *, FILE *, int)
std::string robMapVersion
std::string mapNameRG() const
edm::ConstRespectingPtr< DTBufferTree< int, int > > rgBuf
int superLayer() const
Return the superlayer number.
bool set(std::unique_ptr< T > iNewValue) const
int wire() const
Return the wire number.
Definition: DTWireId.h:42
DTBufferTree< int, int > rgBuf
void clear()
clear map
const DTReadOutMapping * fullMap() const
Expand to full map.
std::vector< DTReadOutGeometryLink >::const_iterator const_iterator
Access methods to the connections.
int geometryToReadOut(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, int &dduId, int &rosId, int &robId, int &tdcId, int &channelId) const
void reset()
unsets the value and deletes the memory
std::vector< DTReadOutGeometryLink > readOutChannelDriftTubeMap
edm::ConstRespectingPtr< DTBufferTree< int, int > > grBuf
const std::string & mapRobRos() const
const_iterator begin() const
edm::AtomicPtrCache< DTReadOutMappingCache > const & atomicCache() const
const std::string & mapCellTdc() const
access parent maps identifiers
int insertReadOutGeometryLink(int dduId, int rosId, int robId, int tdcId, int channelId, int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId)
insert connection
DTBufferTree< int, int > rgROB
DTBufferTree< int, int > mType
DTBufferTree< int, std::unique_ptr< std::vector< int > > > grROB
void cacheMap() const
read and store full content
uint8_t channelId(const VFATFrame &frame)
retrieve this channel identifier
DTBufferTree< int, std::unique_ptr< std::vector< int > > > grROS
const_iterator end() const
static DTReadOutMapping * expandMap(const DTReadOutMapping &compMap)
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
int find(ElementKey fKey, ElementKey lKey, typename DTBufferTreeTrait< Content >::outputTypeOfConstFind &cont) const
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
DTBufferTree< int, std::unique_ptr< std::vector< int > > > grDDU
int sector() const
Definition: DTChamberId.h:49
int insert(ElementKey fKey, ElementKey lKey, Content cont)
std::string cellMapVersion
DTBufferTree< int, int > grBuf
DTBufferTree< int, int > rgROS
type mapType() const
std::string mapNameGR() const
def move(src, dest)
Definition: eostools.py:511