CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripPsuDetIdMap.cc
Go to the documentation of this file.
7 
11 #include <cstdlib>
12 #include <iostream>
13 #include <iomanip>
14 #include <sstream>
15 #include <string>
16 
17 using namespace sistrip;
18 
19 // only one constructor
20 SiStripPsuDetIdMap::SiStripPsuDetIdMap() { LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Constructing ..."; }
21 // destructor
22 SiStripPsuDetIdMap::~SiStripPsuDetIdMap() {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Destructing ..."; }
23 
24 // Build PSU-DETID map
26 {
27  // initialize the map vector
28  pgMap.clear();
29  detectorLocations.clear();
30  dcuIds.clear();
31  cgDcuIds.clear();
32  ccuDcuIds.clear();
33 
34  // first = DCU ID, second = pointer to TkDcuInfo object
35  SiStripConfigDb::DcuDetIdsV dcu_detid_vector;
36  dcu_device_addr_vector.clear();
37  // pointer to TkDcuPsuMap objects
38  DcuPsuVector powerGroup, controlGroup;
39 
40  // check that the db connection is ready
41  if ( db_ ) {
42  // retrieve both maps, if available
43  SiStripDbParams dbParams_ = db_->dbParams();
44  SiStripDbParams::SiStripPartitions::const_iterator iter;
45  for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
46  if (iter->second.psuVersion().first > 0) {
47  DcuPsusRange PGrange, CGrange;
48  getDcuPsuMap(PGrange,CGrange,iter->second.partitionName());
49  if (!PGrange.empty()) {
50  DcuPsuVector nextVec( PGrange.begin(), PGrange.end() );
51  powerGroup.insert( powerGroup.end(), nextVec.begin(), nextVec.end() );
52  }
53  if (!CGrange.empty()) {
54  DcuPsuVector nextVec( CGrange.begin(), CGrange.end() );
55  controlGroup.insert( controlGroup.end(), nextVec.begin(), nextVec.end() );
56  }
57  }
58 
59  if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
60  SiStripConfigDb::DcuDetIdsRange range = db_->getDcuDetIds(iter->second.partitionName());
61  if (!range.empty()) {
62  SiStripConfigDb::DcuDetIdsV nextVec( range.begin(), range.end() );
63  dcu_detid_vector.insert( dcu_detid_vector.end(), nextVec.begin(), nextVec.end() );
64  }
65  // std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > nextControlVector = retrieveDcuDeviceAddresses(iter->second.partitionName());
66  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > nextControlVector = retrieveDcuDeviceAddresses(iter->second.partitionName());
67  dcu_device_addr_vector.insert( dcu_device_addr_vector.end(), nextControlVector.begin(), nextControlVector.end() );
68  }
69  }
70  } else {
71  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] NULL pointer to SiStripConfigDb service returned! Cannot build PSU <-> DETID map";
72  return;
73  }
74  LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] All information retrieved!";
75 
76  if (!powerGroup.empty()) {
77  if (!dcu_detid_vector.empty()) {
78  // Retrieve the collated information for all partitions
79  // Now build the map, starting from the PSUs for power groups
80  for (unsigned int psu = 0; psu < powerGroup.size(); psu++) {
81  SiStripConfigDb::DcuDetIdsV::iterator iter = SiStripConfigDb::findDcuDetId( dcu_detid_vector.begin(), dcu_detid_vector.end(), powerGroup[psu]->getDcuHardId() );
82  if (iter != dcu_detid_vector.end()) {
83  // check for duplicates
84  bool presentInMap = false, multiEntry = false;
85  unsigned int locInMap = 0;
86  for (unsigned int ch = 0; ch < pgMap.size(); ch++) {
87  if (pgMap[ch].first == iter->second->getDetId() && pgMap[ch].second == powerGroup[psu]->getDatapointName()) {presentInMap = true;}
88  if (pgMap[ch].first == iter->second->getDetId() && pgMap[ch].second != powerGroup[psu]->getDatapointName()) {
89  multiEntry = true;
90  locInMap = ch;
91  }
92  }
93  // if no duplicates, store it!
94  if (!presentInMap && !multiEntry) {
95  pgMap.push_back( std::make_pair( iter->second->getDetId(), powerGroup[psu]->getDatapointName() ) );
96  detectorLocations.push_back( powerGroup[psu]->getPVSSName() );
97  dcuIds.push_back( powerGroup[psu]->getDcuHardId() );
98  }
99  if (multiEntry) {
100  pgMap[locInMap].first = iter->second->getDetId();
101  pgMap[locInMap].second = powerGroup[psu]->getDatapointName();
102  detectorLocations[locInMap] = powerGroup[psu]->getPVSSName();
103  dcuIds[locInMap] = powerGroup[psu]->getDcuHardId();
104  }
105  }
106  }
107  } else {
108  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] DCU <-> DETID mapping missing! Cannot build PSU <-> DETID map";
109  }
110  } else {
111  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] DCU <-> PSU mapping missing! Cannot build PSU <-> DETID map";
112  }
113 
114  if (!controlGroup.empty() && !dcu_detid_vector.empty()) {
115  for (unsigned int cg = 0; cg < controlGroup.size(); cg++) {
116  std::vector<uint32_t> dcuids = findDcuIdFromDeviceAddress(controlGroup[cg]->getDcuHardId());
117 
118  for (unsigned int d = 0; d < dcuids.size(); d++) {
119  SiStripConfigDb::DcuDetIdsV::iterator iter = SiStripConfigDb::findDcuDetId( dcu_detid_vector.begin(), dcu_detid_vector.end(), dcuids[d] );
120  if (iter != dcu_detid_vector.end()) {
121  bool presentInMap = false, multiEntry = false;
122  unsigned int locInMap = 0, locOfCopy = 0;
123  for (unsigned int ch = 0; ch < cgMap.size(); ch++) {
124  if (cgMap[ch].first == iter->second->getDetId() && cgMap[ch].second == controlGroup[cg]->getDatapointName()) {
125  presentInMap = true;
126  locOfCopy = ch;
127  }
128  if (cgMap[ch].first == iter->second->getDetId() && cgMap[ch].second != controlGroup[cg]->getDatapointName()) {
129  multiEntry = true;
130  locInMap = ch;
131  }
132  }
133 
134  if (!presentInMap && !multiEntry) {
135  cgMap.push_back( std::make_pair(iter->second->getDetId(), controlGroup[cg]->getDatapointName()) );
136  controlLocations.push_back( controlGroup[cg]->getPVSSName() );
137  cgDcuIds.push_back( dcuids[d] );
138  ccuDcuIds.push_back( controlGroup[cg]->getDcuHardId() );
139  }
140  if (multiEntry) {
141  cgMap[locInMap].first = iter->second->getDetId();
142  cgMap[locInMap].second = controlGroup[cg]->getDatapointName();
143  controlLocations[locInMap] = controlGroup[cg]->getPVSSName();
144  cgDcuIds[locInMap] = dcuids[d];
145  ccuDcuIds[locInMap] = controlGroup[cg]->getDcuHardId();
146  }
147  }
148  }
149  }
150  }
151  LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "]: Size of power group PSU-DetID map is: " << pgMap.size();
152  LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "]: Size of control group PSU-DetID map is: " << cgMap.size();
153 }
154 
155 // Extract DCU-PSU map from DB
156 void SiStripPsuDetIdMap::getDcuPsuMap(DcuPsusRange &pRange, DcuPsusRange &cRange, std::string partition)
157 {
158  // initialize the DCU-PSU range
159  pRange = DcuPsuMapPG_.emptyRange();
160  cRange = DcuPsuMapCG_.emptyRange();
161  // check that the db connection is ready
162  SiStripDbParams dbParams_ = db_->dbParams();
163  // devicefactory needed for DCU-PSU information
164  if ( db_->deviceFactory() ) {
165  // loop over all specified partitions
166  SiStripDbParams::SiStripPartitions::const_iterator iter;
167  for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
168  if ( partition == "" || partition == iter->second.partitionName() ) {
169  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
170  // Stolen from RB code - modify to store DCU PSU map instead
171  // Do things the way RB does to make life easier
172  DcuPsusRange rangePG = DcuPsuMapPG_.find(iter->second.partitionName());
173 
174  if (rangePG == DcuPsuMapPG_.emptyRange()) {
175  try {
176  db_->deviceFactory()->getDcuPsuMapPartition(iter->second.partitionName(),iter->second.psuVersion().first,iter->second.psuVersion().second);
177  } catch (... ) { db_->handleException( __func__ ); }
178 
179  // now store it locally for power groups
180  DcuPsuVector pGroup = db_->deviceFactory()->getPowerGroupDcuPsuMaps();
181  DcuPsuVector cGroup = db_->deviceFactory()->getControlGroupDcuPsuMaps();
182  DcuPsuVector dstPG, dstCG;
183  clone(pGroup, dstPG);
184  clone(cGroup, dstCG);
185  DcuPsuMapPG_.loadNext(iter->second.partitionName(), dstPG);
186  DcuPsuMapCG_.loadNext(iter->second.partitionName(), dstCG);
187  }
188  } // if partition is blank or equal to the partitionName specified
189  } // for loop
190  } // device factory check
191 
192  // Create range object
193  uint16_t npPG = 0, ncPG = 0;
194  DcuPsusRange PGrange;
195  if ( partition != "" ) {
196  PGrange = DcuPsuMapPG_.find(partition);
197  npPG = 1;
198  ncPG = PGrange.size();
199  } else {
200  if (!DcuPsuMapPG_.empty()) {
201  PGrange = DcuPsusRange( DcuPsuMapPG_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
202  DcuPsuMapPG_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
203  } else {
204  PGrange = DcuPsuMapPG_.emptyRange();
205  }
206  npPG = DcuPsuMapPG_.size();
207  ncPG = PGrange.size();
208  }
209 
210  stringstream ss;
211  ss << "Found " << ncPG << " entries for power groups in DCU-PSU map";
212  if (DcuPsuMapPG_.empty()) {edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss.str();}
213  else {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss.str();}
214 
215  uint16_t npCG = 0, ncCG = 0;
216  DcuPsusRange CGrange;
217  if ( partition != "" ) {
218  CGrange = DcuPsuMapCG_.find(partition);
219  npCG = 1;
220  ncCG = CGrange.size();
221  } else {
222  if (!DcuPsuMapCG_.empty()) {
223  CGrange = DcuPsusRange( DcuPsuMapCG_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
224  DcuPsuMapCG_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
225  } else {
226  CGrange = DcuPsuMapCG_.emptyRange();
227  }
228  npCG = DcuPsuMapCG_.size();
229  ncCG = CGrange.size();
230  }
231 
232  std::stringstream ss1;
233  ss1 << "Found " << ncCG << " entries for control groups in DCU-PSU map";
234  if (DcuPsuMapCG_.empty()) {edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss1.str();}
235  else {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss1.str();}
236 
237  cRange = CGrange;
238  pRange = PGrange;
239 }
240 
241 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile )
242 {
243  BuildMap(mapFile, pgMap);
244 }
245 
246 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile, PsuDetIdMap & map )
247 {
248  edm::FileInPath file(mapFile.c_str());
249  ifstream ifs( file.fullPath().c_str() );
250  string line;
251  while( getline( ifs, line ) ) {
252  if( line != "" ) {
253  // split the line and insert in the map
254  stringstream ss(line);
255  string dpName;
256  uint32_t detId;
257  ss >> detId;
258  ss >> dpName;
259  map.push_back( std::make_pair(detId, dpName) );
260  }
261  }
262 }
263 
264 std::vector<uint32_t> SiStripPsuDetIdMap::getLvDetID(std::string pvss) {
265  std::vector<uint32_t> detids;
266 
267  for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
268  if (iter->first && iter->second == pvss) {
269  detids.push_back(iter->first);
270  }
271  }
272 
273  // remove duplicates
274  std::sort(detids.begin(),detids.end());
275  std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
276  detids.resize( it - detids.begin() );
277 
278  return detids;
279 }
280 
281 std::vector<uint32_t> SiStripPsuDetIdMap::getHvDetID(std::string pvss) {
282  std::vector<uint32_t> detids;
283  std::string inputBoard = pvss;
284  std::string::size_type loc = inputBoard.size()-3;
285  inputBoard.erase(loc,3);
286 
287  for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
288  std::string board = iter->second;
289  std::string::size_type loca = board.size()-3;
290  board.erase(loca,3);
291  if (iter->first && inputBoard == board) {
292  detids.push_back(iter->first);
293  }
294  }
295 
296  // remove duplicates
297  std::sort(detids.begin(),detids.end());
298  std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
299  detids.resize( it - detids.begin() );
300 
301  return detids;
302 }
303 
304 // This method needs to be updated once HV channel mapping is known
305 // Currently, channel number is ignored for mapping purposes
306 // check both PG and CG as the channels should be unique
307 std::vector<uint32_t> SiStripPsuDetIdMap::getDetID(std::string pvss) {
308  std::vector<uint32_t> detids;
309 
310  std::string inputBoard = pvss;
311  std::string::size_type loc = inputBoard.size()-3;
312  inputBoard.erase(loc,3);
313 
314  for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
315  std::string board = iter->second;
316  std::string::size_type loca = board.size()-3;
317  board.erase(loca,3);
318  if (inputBoard == board) {
319  detids.push_back(iter->first);
320  }
321  }
322  // 12/6/09 (JEC) Remove control groups because O2O is power groups ONLY
323  /*
324  if (detids.empty()) {
325  LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] PSU channel not found in PGs ... Searching CGs!";
326  for (PsuDetIdMap::iterator iter = cgMap.begin(); iter != cgMap.end(); iter++) {
327  std::string board = iter->second;
328  // control groups are ONLY LV
329  std::string::size_type loca = board.size()-3;
330  board.erase(loca,3);
331  if (iter->first && inputBoard == board) {detids.push_back(iter->first);}
332  }
333  }
334  */
335 
336  // remove duplicates
337  std::sort(detids.begin(),detids.end());
338  std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
339  detids.resize( it - detids.begin() );
340 
341  return detids;
342 }
343 
344 // returns PSU channel name for a given DETID
345 std::string SiStripPsuDetIdMap::getPSUName(uint32_t detid) {
346  PsuDetIdMap::iterator iter;
347  for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
348  if (iter->first && iter->first == detid) {return iter->second;}
349  }
350  // if we reach here, then we didn't find the detid in the map
351  return "UNKNOWN";
352 }
353 
354 std::string SiStripPsuDetIdMap::getPSUName(uint32_t detid, std::string group) {
355  PsuDetIdMap::iterator iter;
356  if (group == "PG") {
357  for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
358  if (iter->first && iter->first == detid) {return iter->second;}
359  }
360  }
361  if (group == "CG") {
362  for (iter = cgMap.begin(); iter != cgMap.end(); iter++) {
363  if (iter->first && iter->first == detid) {return iter->second;}
364  }
365  }
366  // if we reach here, then we didn't find the detid in the map
367  return "UNKNOWN";
368 }
369 
370 // returns the PVSS name for a given DETID
372  for (unsigned int i = 0; i < pgMap.size(); i++) {
373  if (pgMap[i].first == detid) {return detectorLocations[i];}
374  }
375  return "UNKNOWN";
376 }
377 
378 // returns the PVSS name for a given DETID, depending on specified map
379 std::string SiStripPsuDetIdMap::getDetectorLocation(uint32_t detid, std::string group) {
380  if (group == "PG") {
381  for (unsigned int i = 0; i < pgMap.size(); i++) {
382  if (pgMap[i].first == detid) {return detectorLocations[i];}
383  }
384  }
385  if (group == "CG") {
386  for (unsigned int i = 0; i < cgMap.size(); i++) {
387  if (cgMap[i].first == detid) {return controlLocations[i];}
388  }
389  }
390  return "UNKNOWN";
391 }
392 
393 // returns the PVSS name for a given PSU channel
394 std::string SiStripPsuDetIdMap::getDetectorLocation(std::string pvss) {
395  for (unsigned int i = 0; i < pgMap.size(); i++) {
396  if (pgMap[i].second == pvss) {return detectorLocations[i];}
397  }
398  for (unsigned int i = 0; i < cgMap.size(); i++) {
399  if (cgMap[i].second == pvss) {return controlLocations[i];}
400  }
401  return "UNKNOWN";
402 }
403 
404 // returns the DCU ID for a given PSU channel
405 uint32_t SiStripPsuDetIdMap::getDcuId(std::string pvss) {
406  for (unsigned int i = 0; i < pgMap.size(); i++) {
407  if (pgMap[i].second == pvss) {return dcuIds[i];}
408  }
409  for (unsigned int i = 0; i < cgMap.size(); i++) {
410  if (cgMap[i].second == pvss) {return cgDcuIds[i];}
411  }
412  return 0;
413 }
414 
416  for (unsigned int i = 0; i < pgMap.size(); i++) {
417  if (pgMap[i].first == detid) {return dcuIds[i];}
418  }
419  return 0;
420 }
421 
422 // determine if a given PSU channel is HV or not
423 int SiStripPsuDetIdMap::IsHVChannel(std::string pvss) {
424  // isHV = 0 means LV, = 1 means HV, = -1 means error
425  int isHV = 0;
426  std::string::size_type loc = pvss.find( "channel", 0 );
427  if (loc != std::string::npos) {
428  std::string chNumber = pvss.substr(loc+7,3);
429  if (chNumber == "002" || chNumber == "003") {
430  isHV = 1;
431  } else if (chNumber == "000" || chNumber == "001") {
432  isHV = 0;
433  } else {
434  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number of expected format, setting error flag!";
435  isHV = -1;
436  }
437  } else {
438  edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number not located in PVSS name, setting error flag!";
439  isHV = -1;
440  }
441  return isHV;
442 }
443 
445  output.clear();
446  for (unsigned int i = 0; i < input.size(); i++) {
447  output.push_back(new TkDcuPsuMap(*(input[i])));
448  }
449 }
450 
452  stringstream pg;
453  pg << "Map of power supplies to DET IDs: " << std::endl
454  << "-- PSU name -- -- Det Id --" << std::endl;
455  for (unsigned int p = 0; p < pgMap.size(); p++) {
456  pg << pgMap[p].first << " " << pgMap[p].second << std::endl;
457  }
458  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << pg.str();
459 }
460 
462  stringstream cg;
463  cg << "Map of control power supplies to DET IDs: " << std::endl
464  << "-- PSU name -- -- Det Id --" << std::endl;
465  for (unsigned int p = 0; p < cgMap.size(); p++) {
466  cg << cgMap[p].first << " " << cgMap[p].second << std::endl;
467  }
468  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << cg.str();
469 }
470 
471 std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::getDcuPsuMap() {
472  if (pgMap.size() != 0) { return pgMap; }
473  std::vector< std::pair<uint32_t, std::string> > emptyVec;
474  return emptyVec;
475 }
476 
478  std::cout << "Number of entries in DCU-PSU map: " << dcuPsus_.size() << std::endl;
479  std::cout << "Number of entries in DCU-DETID map: " << dcuDetIds_.size() << std::endl;
480  std::cout << std::endl;
481 
482  std::vector<bool> ddUsed(dcuDetIds_.size(),false);
483  std::vector<bool> dpUsed(dcuPsus_.size(),false);
484 
485  for (unsigned int dp = 0; dp < dcuPsus_.size(); dp++) {
486  for (unsigned int dd = 0; dd < dcuDetIds_.size(); dd++) {
487  if (dcuPsus_[dp]->getDcuHardId() == dcuDetIds_[dd].second->getDcuHardId()) {
488  dpUsed[dp] = true;
489  ddUsed[dd] = true;
490  }
491  }
492  }
493  unsigned int numDpUsed = 0, numDpNotUsed = 0;
494  for (unsigned int dp = 0; dp < dpUsed.size(); dp++) {
495  if (dpUsed[dp]) { numDpUsed++; }
496  else { numDpNotUsed++; }
497  }
498 
499  std::cout << "Number of used DCU-PSU entries: " << numDpUsed << std::endl;
500  std::cout << "Number of unused DCU-PSU entries: " << numDpNotUsed << std::endl;
501 
502  unsigned int numDdUsed = 0, numDdNotUsed = 0;
503  for (unsigned int dd = 0; dd < ddUsed.size(); dd++) {
504  if (ddUsed[dd]) { numDdUsed++; }
505  else { numDdNotUsed++; }
506  }
507 
508  std::cout << "Number of used DCU-DETID entries: " << numDdUsed << std::endl;
509  std::cout << "Number of unused DCU-DETID entries: " << numDdNotUsed << std::endl;
510  std::cout << std::endl;
511  std::cout << "Size of PSU-DETID map: " << pgMap.size() << std::endl;
512  std::cout << "Size of detectorLocations: " << detectorLocations.size() << std::endl;
513 }
514 
515 //std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses(std::string partition) {
516 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses(std::string partition) {
517  // get the DB parameters
518  SiStripDbParams dbParams_ = db_->dbParams();
519  SiStripDbParams::SiStripPartitions::const_iterator iter;
520 
521  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > resultVec;
522 
524  SiStripConfigDb::DeviceType device_ = DCU;
525 
526  for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
527  if ( partition == "" || partition == iter->second.partitionName() ) {
528  if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
529  if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
530  SiStripConfigDb::DeviceDescriptionsRange range = db_->getDeviceDescriptions(device_,iter->second.partitionName());
531  if (!range.empty()) {
532  SiStripConfigDb::DeviceDescriptionsV nextVec( range.begin(), range.end() );
533  for (unsigned int i = 0; i < nextVec.size(); i++) {
534  dcuDescription * desc = dynamic_cast<dcuDescription *>(nextVec[i]);
535  resultVec.push_back( std::make_pair( desc->getDcuHardId(), db_->deviceAddress(*(nextVec[i])) ) );
536  }
537  }
538  }
539  }
540  }
541 
542  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > testVec;
543  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator reorg_iter = resultVec.begin();
544 
545  for ( ; reorg_iter != resultVec.end(); reorg_iter++) {
546  std::vector<uint16_t> fecInfo(4,0);
547  fecInfo[0] = reorg_iter->second.fecCrate_;
548  fecInfo[1] = reorg_iter->second.fecSlot_;
549  fecInfo[2] = reorg_iter->second.fecRing_;
550  fecInfo[3] = reorg_iter->second.ccuAddr_;
551  std::vector<uint32_t> dcuids;
552  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator jter = reorg_iter;
553  for ( ; jter != resultVec.end(); jter++) {
554  if (reorg_iter->second.fecCrate_ == jter->second.fecCrate_ &&
555  reorg_iter->second.fecSlot_ == jter->second.fecSlot_ &&
556  reorg_iter->second.fecRing_ == jter->second.fecRing_ &&
557  reorg_iter->second.ccuAddr_ == jter->second.ccuAddr_) {
558  dcuids.push_back(jter->first);
559  }
560  }
561  // handle duplicates
562  bool isDup = false;
563  for (unsigned int i = 0; i < testVec.size(); i++) {
564  if (fecInfo == testVec[i].first) {
565  isDup = true;
566  dcuids.insert(dcuids.end(), (testVec[i].second).begin(), (testVec[i].second).end() );
567  std::sort(dcuids.begin(),dcuids.end());
568  std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
569  dcuids.resize( it - dcuids.begin() );
570  testVec[i].second = dcuids;
571  }
572  }
573  if (!isDup) {
574  std::sort(dcuids.begin(),dcuids.end());
575  std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
576  dcuids.resize( it - dcuids.begin() );
577  testVec.push_back(std::make_pair(fecInfo,dcuids));
578  }
579  }
580  // return resultVec;
581  return testVec;
582 }
583 
584 std::vector<uint32_t> SiStripPsuDetIdMap::findDcuIdFromDeviceAddress(uint32_t dcuid_) {
585  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator iter = dcu_device_addr_vector.begin();
586  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator res_iter = dcu_device_addr_vector.end();
587  std::vector<uint32_t> pgDcu;
588 
589  for ( ; iter != dcu_device_addr_vector.end(); iter++) {
590  std::vector<uint32_t> dcuids = iter->second;
591  std::vector<uint32_t>::iterator dcu_iter = std::find(dcuids.begin(),dcuids.end(),dcuid_);
592  bool alreadyFound = false;
593  if (res_iter != dcu_device_addr_vector.end()) {alreadyFound = true;}
594  if (dcu_iter != dcuids.end()) {
595  res_iter = iter;
596  if (!alreadyFound) {
597  for (unsigned int i = 0; i < dcuids.size(); i++) {
598  if (dcuids[i] != dcuid_) {pgDcu.push_back(dcuids[i]);}
599  }
600  } else {
601  std::cout << "Oh oh ... we have a duplicate :-(" << std::endl;
602  }
603  }
604  }
605  return pgDcu;
606 }
607 
608 
static std::string defaultPartitionName_
void clone(DcuPsuVector &input, DcuPsuVector &output)
int i
Definition: DBlmapReader.cc:9
DcuDetIds::range DcuDetIdsRange
std::string getPSUName(uint32_t detid)
std::vector< uint32_t > getDetID(std::string pvss)
std::vector< std::pair< std::vector< uint16_t >, std::vector< uint32_t > > > retrieveDcuDeviceAddresses(std::string partition)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
DcuPsus::range DcuPsusRange
uint16_t size_type
std::vector< std::pair< uint32_t, std::string > > PsuDetIdMap
U second(std::pair< T, U > const &p)
const_iterator_range partitions() const
static DcuDetIdsV::const_iterator findDcuDetId(DcuDetIdsV::const_iterator begin, DcuDetIdsV::const_iterator end, uint32_t dcu_id)
Definition: DcuDetIds.cc:396
enumDeviceType DeviceType
std::vector< uint32_t > getHvDetID(std::string pvss)
int IsHVChannel(std::string pvss)
DeviceDescriptions::range DeviceDescriptionsRange
#define end
Definition: vmac.h:38
std::vector< std::pair< uint32_t, std::string > > getDcuPsuMap()
bool first
Definition: L1TdeRCT.cc:79
#define LogTrace(id)
std::vector< uint32_t > findDcuIdFromDeviceAddress(uint32_t dcuid_)
tuple input
Definition: collect_tpl.py:10
std::vector< DcuDetId > DcuDetIdsV
Container class for database connection parameters.
T * clone(const T *tp)
Definition: Ptr.h:42
#define begin
Definition: vmac.h:31
uint32_t getDcuId(std::string pvss)
std::vector< TkDcuPsuMap * > DcuPsuVector
void checkMapInputValues(SiStripConfigDb::DcuDetIdsV dcuDetIds_, DcuPsuVector dcuPsus_)
tuple cout
Definition: gather_cfg.py:41
std::vector< uint32_t > getLvDetID(std::string pvss)
std::string getDetectorLocation(uint32_t detid)
std::vector< DeviceDescription * > DeviceDescriptionsV