00001 #include "CalibTracker/SiStripDCS/interface/SiStripPsuDetIdMap.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007
00008 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
00009 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00010 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00011 #include <cstdlib>
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <sstream>
00015 #include <string>
00016
00017 using namespace sistrip;
00018
00019
00020 SiStripPsuDetIdMap::SiStripPsuDetIdMap() { LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Constructing ..."; }
00021
00022 SiStripPsuDetIdMap::~SiStripPsuDetIdMap() {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Destructing ..."; }
00023
00024
00025 void SiStripPsuDetIdMap::BuildMap()
00026 {
00027
00028 pgMap.clear();
00029 detectorLocations.clear();
00030 dcuIds.clear();
00031 cgDcuIds.clear();
00032 ccuDcuIds.clear();
00033
00034
00035 SiStripConfigDb::DcuDetIdsV dcu_detid_vector;
00036 dcu_device_addr_vector.clear();
00037
00038 DcuPsuVector powerGroup, controlGroup;
00039
00040
00041 if ( db_ ) {
00042
00043 SiStripDbParams dbParams_ = db_->dbParams();
00044 SiStripDbParams::SiStripPartitions::const_iterator iter;
00045 for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
00046 if (iter->second.psuVersion().first > 0) {
00047 DcuPsusRange PGrange, CGrange;
00048 getDcuPsuMap(PGrange,CGrange,iter->second.partitionName());
00049 if (!PGrange.empty()) {
00050 DcuPsuVector nextVec( PGrange.begin(), PGrange.end() );
00051 powerGroup.insert( powerGroup.end(), nextVec.begin(), nextVec.end() );
00052 }
00053 if (!CGrange.empty()) {
00054 DcuPsuVector nextVec( CGrange.begin(), CGrange.end() );
00055 controlGroup.insert( controlGroup.end(), nextVec.begin(), nextVec.end() );
00056 }
00057 }
00058
00059 if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
00060 SiStripConfigDb::DcuDetIdsRange range = db_->getDcuDetIds(iter->second.partitionName());
00061 if (!range.empty()) {
00062 SiStripConfigDb::DcuDetIdsV nextVec( range.begin(), range.end() );
00063 dcu_detid_vector.insert( dcu_detid_vector.end(), nextVec.begin(), nextVec.end() );
00064 }
00065
00066 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > nextControlVector = retrieveDcuDeviceAddresses(iter->second.partitionName());
00067 dcu_device_addr_vector.insert( dcu_device_addr_vector.end(), nextControlVector.begin(), nextControlVector.end() );
00068 }
00069 }
00070 } else {
00071 edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] NULL pointer to SiStripConfigDb service returned! Cannot build PSU <-> DETID map";
00072 return;
00073 }
00074 LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] All information retrieved!";
00075
00076 if (!powerGroup.empty()) {
00077 if (!dcu_detid_vector.empty()) {
00078
00079
00080 for (unsigned int psu = 0; psu < powerGroup.size(); psu++) {
00081 SiStripConfigDb::DcuDetIdsV::iterator iter = SiStripConfigDb::findDcuDetId( dcu_detid_vector.begin(), dcu_detid_vector.end(), powerGroup[psu]->getDcuHardId() );
00082 if (iter != dcu_detid_vector.end()) {
00083
00084 bool presentInMap = false, multiEntry = false;
00085 unsigned int locInMap = 0;
00086 for (unsigned int ch = 0; ch < pgMap.size(); ch++) {
00087 if (pgMap[ch].first == iter->second->getDetId() && pgMap[ch].second == powerGroup[psu]->getDatapointName()) {presentInMap = true;}
00088 if (pgMap[ch].first == iter->second->getDetId() && pgMap[ch].second != powerGroup[psu]->getDatapointName()) {
00089 multiEntry = true;
00090 locInMap = ch;
00091 }
00092 }
00093
00094 if (!presentInMap && !multiEntry) {
00095 pgMap.push_back( std::make_pair( iter->second->getDetId(), powerGroup[psu]->getDatapointName() ) );
00096 detectorLocations.push_back( powerGroup[psu]->getPVSSName() );
00097 dcuIds.push_back( powerGroup[psu]->getDcuHardId() );
00098 }
00099 if (multiEntry) {
00100 pgMap[locInMap].first = iter->second->getDetId();
00101 pgMap[locInMap].second = powerGroup[psu]->getDatapointName();
00102 detectorLocations[locInMap] = powerGroup[psu]->getPVSSName();
00103 dcuIds[locInMap] = powerGroup[psu]->getDcuHardId();
00104 }
00105 }
00106 }
00107 } else {
00108 edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] DCU <-> DETID mapping missing! Cannot build PSU <-> DETID map";
00109 }
00110 } else {
00111 edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] DCU <-> PSU mapping missing! Cannot build PSU <-> DETID map";
00112 }
00113
00114 if (!controlGroup.empty() && !dcu_detid_vector.empty()) {
00115 for (unsigned int cg = 0; cg < controlGroup.size(); cg++) {
00116 std::vector<uint32_t> dcuids = findDcuIdFromDeviceAddress(controlGroup[cg]->getDcuHardId());
00117
00118 for (unsigned int d = 0; d < dcuids.size(); d++) {
00119 SiStripConfigDb::DcuDetIdsV::iterator iter = SiStripConfigDb::findDcuDetId( dcu_detid_vector.begin(), dcu_detid_vector.end(), dcuids[d] );
00120 if (iter != dcu_detid_vector.end()) {
00121 bool presentInMap = false, multiEntry = false;
00122 unsigned int locInMap = 0, locOfCopy = 0;
00123 for (unsigned int ch = 0; ch < cgMap.size(); ch++) {
00124 if (cgMap[ch].first == iter->second->getDetId() && cgMap[ch].second == controlGroup[cg]->getDatapointName()) {
00125 presentInMap = true;
00126 locOfCopy = ch;
00127 }
00128 if (cgMap[ch].first == iter->second->getDetId() && cgMap[ch].second != controlGroup[cg]->getDatapointName()) {
00129 multiEntry = true;
00130 locInMap = ch;
00131 }
00132 }
00133
00134 if (!presentInMap && !multiEntry) {
00135 cgMap.push_back( std::make_pair(iter->second->getDetId(), controlGroup[cg]->getDatapointName()) );
00136 controlLocations.push_back( controlGroup[cg]->getPVSSName() );
00137 cgDcuIds.push_back( dcuids[d] );
00138 ccuDcuIds.push_back( controlGroup[cg]->getDcuHardId() );
00139 }
00140 if (multiEntry) {
00141 cgMap[locInMap].first = iter->second->getDetId();
00142 cgMap[locInMap].second = controlGroup[cg]->getDatapointName();
00143 controlLocations[locInMap] = controlGroup[cg]->getPVSSName();
00144 cgDcuIds[locInMap] = dcuids[d];
00145 ccuDcuIds[locInMap] = controlGroup[cg]->getDcuHardId();
00146 }
00147 }
00148 }
00149 }
00150 }
00151 LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "]: Size of power group PSU-DetID map is: " << pgMap.size();
00152 LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "]: Size of control group PSU-DetID map is: " << cgMap.size();
00153 }
00154
00155
00156 void SiStripPsuDetIdMap::getDcuPsuMap(DcuPsusRange &pRange, DcuPsusRange &cRange, std::string partition)
00157 {
00158
00159 pRange = DcuPsuMapPG_.emptyRange();
00160 cRange = DcuPsuMapCG_.emptyRange();
00161
00162 SiStripDbParams dbParams_ = db_->dbParams();
00163
00164 if ( db_->deviceFactory() ) {
00165
00166 SiStripDbParams::SiStripPartitions::const_iterator iter;
00167 for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
00168 if ( partition == "" || partition == iter->second.partitionName() ) {
00169 if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
00170
00171
00172 DcuPsusRange rangePG = DcuPsuMapPG_.find(iter->second.partitionName());
00173
00174 if (rangePG == DcuPsuMapPG_.emptyRange()) {
00175 try {
00176 db_->deviceFactory()->getDcuPsuMapPartition(iter->second.partitionName(),iter->second.psuVersion().first,iter->second.psuVersion().second);
00177 } catch (... ) { db_->handleException( __func__ ); }
00178
00179
00180 DcuPsuVector pGroup = db_->deviceFactory()->getPowerGroupDcuPsuMaps();
00181 DcuPsuVector cGroup = db_->deviceFactory()->getControlGroupDcuPsuMaps();
00182 DcuPsuVector dstPG, dstCG;
00183 clone(pGroup, dstPG);
00184 clone(cGroup, dstCG);
00185 DcuPsuMapPG_.loadNext(iter->second.partitionName(), dstPG);
00186 DcuPsuMapCG_.loadNext(iter->second.partitionName(), dstCG);
00187 }
00188 }
00189 }
00190 }
00191
00192
00193 uint16_t npPG = 0, ncPG = 0;
00194 DcuPsusRange PGrange;
00195 if ( partition != "" ) {
00196 PGrange = DcuPsuMapPG_.find(partition);
00197 npPG = 1;
00198 ncPG = PGrange.size();
00199 } else {
00200 if (!DcuPsuMapPG_.empty()) {
00201 PGrange = DcuPsusRange( DcuPsuMapPG_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00202 DcuPsuMapPG_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00203 } else {
00204 PGrange = DcuPsuMapPG_.emptyRange();
00205 }
00206 npPG = DcuPsuMapPG_.size();
00207 ncPG = PGrange.size();
00208 }
00209
00210 stringstream ss;
00211 ss << "Found " << ncPG << " entries for power groups in DCU-PSU map";
00212 if (DcuPsuMapPG_.empty()) {edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss.str();}
00213 else {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss.str();}
00214
00215 uint16_t npCG = 0, ncCG = 0;
00216 DcuPsusRange CGrange;
00217 if ( partition != "" ) {
00218 CGrange = DcuPsuMapCG_.find(partition);
00219 npCG = 1;
00220 ncCG = CGrange.size();
00221 } else {
00222 if (!DcuPsuMapCG_.empty()) {
00223 CGrange = DcuPsusRange( DcuPsuMapCG_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00224 DcuPsuMapCG_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00225 } else {
00226 CGrange = DcuPsuMapCG_.emptyRange();
00227 }
00228 npCG = DcuPsuMapCG_.size();
00229 ncCG = CGrange.size();
00230 }
00231
00232 std::stringstream ss1;
00233 ss1 << "Found " << ncCG << " entries for control groups in DCU-PSU map";
00234 if (DcuPsuMapCG_.empty()) {edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss1.str();}
00235 else {LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << ss1.str();}
00236
00237 cRange = CGrange;
00238 pRange = PGrange;
00239 }
00240
00241 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile )
00242 {
00243 BuildMap(mapFile, pgMap);
00244 }
00245
00246 void SiStripPsuDetIdMap::BuildMap( const std::string & mapFile, PsuDetIdMap & map )
00247 {
00248 edm::FileInPath file(mapFile.c_str());
00249 ifstream ifs( file.fullPath().c_str() );
00250 string line;
00251 while( getline( ifs, line ) ) {
00252 if( line != "" ) {
00253
00254 stringstream ss(line);
00255 string dpName;
00256 uint32_t detId;
00257 ss >> detId;
00258 ss >> dpName;
00259 map.push_back( std::make_pair(detId, dpName) );
00260 }
00261 }
00262 }
00263
00264 std::vector<uint32_t> SiStripPsuDetIdMap::getLvDetID(std::string pvss) {
00265 std::vector<uint32_t> detids;
00266
00267 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
00268 if (iter->first && iter->second == pvss) {
00269 detids.push_back(iter->first);
00270 }
00271 }
00272
00273
00274 std::sort(detids.begin(),detids.end());
00275 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
00276 detids.resize( it - detids.begin() );
00277
00278 return detids;
00279 }
00280
00281 std::vector<uint32_t> SiStripPsuDetIdMap::getHvDetID(std::string pvss) {
00282 std::vector<uint32_t> detids;
00283 std::string inputBoard = pvss;
00284 std::string::size_type loc = inputBoard.size()-3;
00285 inputBoard.erase(loc,3);
00286
00287 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
00288 std::string board = iter->second;
00289 std::string::size_type loca = board.size()-3;
00290 board.erase(loca,3);
00291 if (iter->first && inputBoard == board) {
00292 detids.push_back(iter->first);
00293 }
00294 }
00295
00296
00297 std::sort(detids.begin(),detids.end());
00298 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
00299 detids.resize( it - detids.begin() );
00300
00301 return detids;
00302 }
00303
00304
00305
00306
00307 std::vector<uint32_t> SiStripPsuDetIdMap::getDetID(std::string pvss) {
00308 std::vector<uint32_t> detids;
00309
00310 std::string inputBoard = pvss;
00311 std::string::size_type loc = inputBoard.size()-3;
00312 inputBoard.erase(loc,3);
00313
00314 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
00315 std::string board = iter->second;
00316 std::string::size_type loca = board.size()-3;
00317 board.erase(loca,3);
00318 if (inputBoard == board) {
00319 detids.push_back(iter->first);
00320 }
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 std::sort(detids.begin(),detids.end());
00338 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
00339 detids.resize( it - detids.begin() );
00340
00341 return detids;
00342 }
00343
00344
00345 std::string SiStripPsuDetIdMap::getPSUName(uint32_t detid) {
00346 PsuDetIdMap::iterator iter;
00347 for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
00348 if (iter->first && iter->first == detid) {return iter->second;}
00349 }
00350
00351 return "UNKNOWN";
00352 }
00353
00354 std::string SiStripPsuDetIdMap::getPSUName(uint32_t detid, std::string group) {
00355 PsuDetIdMap::iterator iter;
00356 if (group == "PG") {
00357 for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
00358 if (iter->first && iter->first == detid) {return iter->second;}
00359 }
00360 }
00361 if (group == "CG") {
00362 for (iter = cgMap.begin(); iter != cgMap.end(); iter++) {
00363 if (iter->first && iter->first == detid) {return iter->second;}
00364 }
00365 }
00366
00367 return "UNKNOWN";
00368 }
00369
00370
00371 std::string SiStripPsuDetIdMap::getDetectorLocation(uint32_t detid) {
00372 for (unsigned int i = 0; i < pgMap.size(); i++) {
00373 if (pgMap[i].first == detid) {return detectorLocations[i];}
00374 }
00375 return "UNKNOWN";
00376 }
00377
00378
00379 std::string SiStripPsuDetIdMap::getDetectorLocation(uint32_t detid, std::string group) {
00380 if (group == "PG") {
00381 for (unsigned int i = 0; i < pgMap.size(); i++) {
00382 if (pgMap[i].first == detid) {return detectorLocations[i];}
00383 }
00384 }
00385 if (group == "CG") {
00386 for (unsigned int i = 0; i < cgMap.size(); i++) {
00387 if (cgMap[i].first == detid) {return controlLocations[i];}
00388 }
00389 }
00390 return "UNKNOWN";
00391 }
00392
00393
00394 std::string SiStripPsuDetIdMap::getDetectorLocation(std::string pvss) {
00395 for (unsigned int i = 0; i < pgMap.size(); i++) {
00396 if (pgMap[i].second == pvss) {return detectorLocations[i];}
00397 }
00398 for (unsigned int i = 0; i < cgMap.size(); i++) {
00399 if (cgMap[i].second == pvss) {return controlLocations[i];}
00400 }
00401 return "UNKNOWN";
00402 }
00403
00404
00405 uint32_t SiStripPsuDetIdMap::getDcuId(std::string pvss) {
00406 for (unsigned int i = 0; i < pgMap.size(); i++) {
00407 if (pgMap[i].second == pvss) {return dcuIds[i];}
00408 }
00409 for (unsigned int i = 0; i < cgMap.size(); i++) {
00410 if (cgMap[i].second == pvss) {return cgDcuIds[i];}
00411 }
00412 return 0;
00413 }
00414
00415 uint32_t SiStripPsuDetIdMap::getDcuId(uint32_t detid) {
00416 for (unsigned int i = 0; i < pgMap.size(); i++) {
00417 if (pgMap[i].first == detid) {return dcuIds[i];}
00418 }
00419 return 0;
00420 }
00421
00422
00423 int SiStripPsuDetIdMap::IsHVChannel(std::string pvss) {
00424
00425 int isHV = 0;
00426 std::string::size_type loc = pvss.find( "channel", 0 );
00427 if (loc != std::string::npos) {
00428 std::string chNumber = pvss.substr(loc+7,3);
00429 if (chNumber == "002" || chNumber == "003") {
00430 isHV = 1;
00431 } else if (chNumber == "000" || chNumber == "001") {
00432 isHV = 0;
00433 } else {
00434 edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number of expected format, setting error flag!";
00435 isHV = -1;
00436 }
00437 } else {
00438 edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number not located in PVSS name, setting error flag!";
00439 isHV = -1;
00440 }
00441 return isHV;
00442 }
00443
00444 void SiStripPsuDetIdMap::clone(DcuPsuVector &input, DcuPsuVector &output) {
00445 output.clear();
00446 for (unsigned int i = 0; i < input.size(); i++) {
00447 output.push_back(new TkDcuPsuMap(*(input[i])));
00448 }
00449 }
00450
00451 void SiStripPsuDetIdMap::printMap() {
00452 stringstream pg;
00453 pg << "Map of power supplies to DET IDs: " << std::endl
00454 << "-- PSU name -- -- Det Id --" << std::endl;
00455 for (unsigned int p = 0; p < pgMap.size(); p++) {
00456 pg << pgMap[p].first << " " << pgMap[p].second << std::endl;
00457 }
00458 edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << pg.str();
00459 }
00460
00461 void SiStripPsuDetIdMap::printControlMap() {
00462 stringstream cg;
00463 cg << "Map of control power supplies to DET IDs: " << std::endl
00464 << "-- PSU name -- -- Det Id --" << std::endl;
00465 for (unsigned int p = 0; p < cgMap.size(); p++) {
00466 cg << cgMap[p].first << " " << cgMap[p].second << std::endl;
00467 }
00468 edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << cg.str();
00469 }
00470
00471 std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::getDcuPsuMap() {
00472 if (pgMap.size() != 0) { return pgMap; }
00473 std::vector< std::pair<uint32_t, std::string> > emptyVec;
00474 return emptyVec;
00475 }
00476
00477 void SiStripPsuDetIdMap::checkMapInputValues(SiStripConfigDb::DcuDetIdsV dcuDetIds_, DcuPsuVector dcuPsus_) {
00478 std::cout << "Number of entries in DCU-PSU map: " << dcuPsus_.size() << std::endl;
00479 std::cout << "Number of entries in DCU-DETID map: " << dcuDetIds_.size() << std::endl;
00480 std::cout << std::endl;
00481
00482 std::vector<bool> ddUsed(dcuDetIds_.size(),false);
00483 std::vector<bool> dpUsed(dcuPsus_.size(),false);
00484
00485 for (unsigned int dp = 0; dp < dcuPsus_.size(); dp++) {
00486 for (unsigned int dd = 0; dd < dcuDetIds_.size(); dd++) {
00487 if (dcuPsus_[dp]->getDcuHardId() == dcuDetIds_[dd].second->getDcuHardId()) {
00488 dpUsed[dp] = true;
00489 ddUsed[dd] = true;
00490 }
00491 }
00492 }
00493 unsigned int numDpUsed = 0, numDpNotUsed = 0;
00494 for (unsigned int dp = 0; dp < dpUsed.size(); dp++) {
00495 if (dpUsed[dp]) { numDpUsed++; }
00496 else { numDpNotUsed++; }
00497 }
00498
00499 std::cout << "Number of used DCU-PSU entries: " << numDpUsed << std::endl;
00500 std::cout << "Number of unused DCU-PSU entries: " << numDpNotUsed << std::endl;
00501
00502 unsigned int numDdUsed = 0, numDdNotUsed = 0;
00503 for (unsigned int dd = 0; dd < ddUsed.size(); dd++) {
00504 if (ddUsed[dd]) { numDdUsed++; }
00505 else { numDdNotUsed++; }
00506 }
00507
00508 std::cout << "Number of used DCU-DETID entries: " << numDdUsed << std::endl;
00509 std::cout << "Number of unused DCU-DETID entries: " << numDdNotUsed << std::endl;
00510 std::cout << std::endl;
00511 std::cout << "Size of PSU-DETID map: " << pgMap.size() << std::endl;
00512 std::cout << "Size of detectorLocations: " << detectorLocations.size() << std::endl;
00513 }
00514
00515
00516 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses(std::string partition) {
00517
00518 SiStripDbParams dbParams_ = db_->dbParams();
00519 SiStripDbParams::SiStripPartitions::const_iterator iter;
00520
00521 std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > resultVec;
00522
00523 SiStripConfigDb::DeviceDescriptionsV dcuDevices_;
00524 SiStripConfigDb::DeviceType device_ = DCU;
00525
00526 for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
00527 if ( partition == "" || partition == iter->second.partitionName() ) {
00528 if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
00529 if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
00530 SiStripConfigDb::DeviceDescriptionsRange range = db_->getDeviceDescriptions(device_,iter->second.partitionName());
00531 if (!range.empty()) {
00532 SiStripConfigDb::DeviceDescriptionsV nextVec( range.begin(), range.end() );
00533 for (unsigned int i = 0; i < nextVec.size(); i++) {
00534 dcuDescription * desc = dynamic_cast<dcuDescription *>(nextVec[i]);
00535 resultVec.push_back( std::make_pair( desc->getDcuHardId(), db_->deviceAddress(*(nextVec[i])) ) );
00536 }
00537 }
00538 }
00539 }
00540 }
00541
00542 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > testVec;
00543 std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator reorg_iter = resultVec.begin();
00544
00545 for ( ; reorg_iter != resultVec.end(); reorg_iter++) {
00546 std::vector<uint16_t> fecInfo(4,0);
00547 fecInfo[0] = reorg_iter->second.fecCrate_;
00548 fecInfo[1] = reorg_iter->second.fecSlot_;
00549 fecInfo[2] = reorg_iter->second.fecRing_;
00550 fecInfo[3] = reorg_iter->second.ccuAddr_;
00551 std::vector<uint32_t> dcuids;
00552 std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator jter = reorg_iter;
00553 for ( ; jter != resultVec.end(); jter++) {
00554 if (reorg_iter->second.fecCrate_ == jter->second.fecCrate_ &&
00555 reorg_iter->second.fecSlot_ == jter->second.fecSlot_ &&
00556 reorg_iter->second.fecRing_ == jter->second.fecRing_ &&
00557 reorg_iter->second.ccuAddr_ == jter->second.ccuAddr_) {
00558 dcuids.push_back(jter->first);
00559 }
00560 }
00561
00562 bool isDup = false;
00563 for (unsigned int i = 0; i < testVec.size(); i++) {
00564 if (fecInfo == testVec[i].first) {
00565 isDup = true;
00566 dcuids.insert(dcuids.end(), (testVec[i].second).begin(), (testVec[i].second).end() );
00567 std::sort(dcuids.begin(),dcuids.end());
00568 std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
00569 dcuids.resize( it - dcuids.begin() );
00570 testVec[i].second = dcuids;
00571 }
00572 }
00573 if (!isDup) {
00574 std::sort(dcuids.begin(),dcuids.end());
00575 std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
00576 dcuids.resize( it - dcuids.begin() );
00577 testVec.push_back(std::make_pair(fecInfo,dcuids));
00578 }
00579 }
00580
00581 return testVec;
00582 }
00583
00584 std::vector<uint32_t> SiStripPsuDetIdMap::findDcuIdFromDeviceAddress(uint32_t dcuid_) {
00585 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator iter = dcu_device_addr_vector.begin();
00586 std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator res_iter = dcu_device_addr_vector.end();
00587 std::vector<uint32_t> pgDcu;
00588
00589 for ( ; iter != dcu_device_addr_vector.end(); iter++) {
00590 std::vector<uint32_t> dcuids = iter->second;
00591 std::vector<uint32_t>::iterator dcu_iter = std::find(dcuids.begin(),dcuids.end(),dcuid_);
00592 bool alreadyFound = false;
00593 if (res_iter != dcu_device_addr_vector.end()) {alreadyFound = true;}
00594 if (dcu_iter != dcuids.end()) {
00595 res_iter = iter;
00596 if (!alreadyFound) {
00597 for (unsigned int i = 0; i < dcuids.size(); i++) {
00598 if (dcuids[i] != dcuid_) {pgDcu.push_back(dcuids[i]);}
00599 }
00600 } else {
00601 std::cout << "Oh oh ... we have a duplicate :-(" << std::endl;
00602 }
00603 }
00604 }
00605 return pgDcu;
00606 }
00607
00608