17 using namespace sistrip;
29 detectorLocations.clear();
36 dcu_device_addr_vector.clear();
44 SiStripDbParams::SiStripPartitions::const_iterator iter;
46 if (iter->second.psuVersion().first > 0) {
48 getDcuPsuMap(PGrange,CGrange,iter->second.partitionName());
49 if (!PGrange.empty()) {
51 powerGroup.insert( powerGroup.end(), nextVec.begin(), nextVec.end() );
53 if (!CGrange.empty()) {
55 controlGroup.insert( controlGroup.end(), nextVec.begin(), nextVec.end() );
59 if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
63 dcu_detid_vector.insert( dcu_detid_vector.end(), nextVec.begin(), nextVec.end() );
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() );
71 edm::LogWarning(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] NULL pointer to SiStripConfigDb service returned! Cannot build PSU <-> DETID map";
74 LogTrace(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] All information retrieved!";
76 if (!powerGroup.empty()) {
77 if (!dcu_detid_vector.empty()) {
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()) {
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()) {
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() );
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();
108 edm::LogWarning(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] DCU <-> DETID mapping missing! Cannot build PSU <-> DETID map";
111 edm::LogWarning(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] DCU <-> PSU mapping missing! Cannot build PSU <-> DETID map";
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());
118 for (
unsigned int d = 0; d < dcuids.size(); 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()) {
128 if (cgMap[ch].
first == iter->second->getDetId() && cgMap[ch].second != controlGroup[cg]->getDatapointName()) {
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() );
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();
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();
159 pRange = DcuPsuMapPG_.emptyRange();
160 cRange = DcuPsuMapCG_.emptyRange();
164 if ( db_->deviceFactory() ) {
166 SiStripDbParams::SiStripPartitions::const_iterator iter;
168 if ( partition ==
"" || partition == iter->second.partitionName() ) {
172 DcuPsusRange rangePG = DcuPsuMapPG_.find(iter->second.partitionName());
174 if (rangePG == DcuPsuMapPG_.emptyRange()) {
176 db_->deviceFactory()->getDcuPsuMapPartition(iter->second.partitionName(),iter->second.psuVersion().first,iter->second.psuVersion().second);
177 }
catch (... ) { db_->handleException( __func__ ); }
180 DcuPsuVector pGroup = db_->deviceFactory()->getPowerGroupDcuPsuMaps();
181 DcuPsuVector cGroup = db_->deviceFactory()->getControlGroupDcuPsuMaps();
183 clone(pGroup, dstPG);
184 clone(cGroup, dstCG);
185 DcuPsuMapPG_.loadNext(iter->second.partitionName(), dstPG);
186 DcuPsuMapCG_.loadNext(iter->second.partitionName(), dstCG);
193 uint16_t npPG = 0, ncPG = 0;
195 if ( partition !=
"" ) {
196 PGrange = DcuPsuMapPG_.find(partition);
198 ncPG = PGrange.size();
200 if (!DcuPsuMapPG_.empty()) {
202 DcuPsuMapPG_.find( (--(dbParams_.
partitions().end()))->second.partitionName() ).
end() );
204 PGrange = DcuPsuMapPG_.emptyRange();
206 npPG = DcuPsuMapPG_.size();
207 ncPG = PGrange.size();
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();}
215 uint16_t npCG = 0, ncCG = 0;
217 if ( partition !=
"" ) {
218 CGrange = DcuPsuMapCG_.find(partition);
220 ncCG = CGrange.size();
222 if (!DcuPsuMapCG_.empty()) {
224 DcuPsuMapCG_.find( (--(dbParams_.
partitions().end()))->second.partitionName() ).
end() );
226 CGrange = DcuPsuMapCG_.emptyRange();
228 npCG = DcuPsuMapCG_.size();
229 ncCG = CGrange.size();
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();}
243 BuildMap(mapFile, pgMap);
249 ifstream ifs(
file.fullPath().c_str() );
251 while( getline( ifs, line ) ) {
254 stringstream ss(line);
259 map.push_back( std::make_pair(detId, dpName) );
265 std::vector<uint32_t> detids;
267 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
268 if (iter->first && iter->second == pvss) {
269 detids.push_back(iter->first);
275 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
276 detids.resize( it - detids.begin() );
282 std::vector<uint32_t> detids;
283 std::string inputBoard = pvss;
285 inputBoard.erase(loc,3);
287 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
288 std::string board = iter->second;
291 if (iter->first && inputBoard == board) {
292 detids.push_back(iter->first);
298 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
299 detids.resize( it - detids.begin() );
308 std::vector<uint32_t> detids;
310 std::string inputBoard = pvss;
312 inputBoard.erase(loc,3);
314 for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
315 std::string board = iter->second;
318 if (inputBoard == board) {
319 detids.push_back(iter->first);
338 std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
339 detids.resize( it - detids.begin() );
346 PsuDetIdMap::iterator iter;
347 for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
348 if (iter->first && iter->first == detid) {
return iter->second;}
355 PsuDetIdMap::iterator iter;
357 for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
358 if (iter->first && iter->first == detid) {
return iter->second;}
362 for (iter = cgMap.begin(); iter != cgMap.end(); iter++) {
363 if (iter->first && iter->first == detid) {
return iter->second;}
372 for (
unsigned int i = 0;
i < pgMap.size();
i++) {
373 if (pgMap[
i].
first == detid) {
return detectorLocations[
i];}
381 for (
unsigned int i = 0;
i < pgMap.size();
i++) {
382 if (pgMap[
i].
first == detid) {
return detectorLocations[
i];}
386 for (
unsigned int i = 0;
i < cgMap.size();
i++) {
387 if (cgMap[
i].
first == detid) {
return controlLocations[
i];}
395 for (
unsigned int i = 0;
i < pgMap.size();
i++) {
396 if (pgMap[
i].
second == pvss) {
return detectorLocations[
i];}
398 for (
unsigned int i = 0;
i < cgMap.size();
i++) {
399 if (cgMap[
i].
second == pvss) {
return controlLocations[
i];}
406 for (
unsigned int i = 0;
i < pgMap.size();
i++) {
407 if (pgMap[
i].
second == pvss) {
return dcuIds[
i];}
409 for (
unsigned int i = 0;
i < cgMap.size();
i++) {
410 if (cgMap[
i].
second == pvss) {
return cgDcuIds[
i];}
416 for (
unsigned int i = 0;
i < pgMap.size();
i++) {
417 if (pgMap[
i].
first == detid) {
return dcuIds[
i];}
427 if (loc != std::string::npos) {
428 std::string chNumber = pvss.substr(loc+7,3);
429 if (chNumber ==
"002" || chNumber ==
"003") {
431 }
else if (chNumber ==
"000" || chNumber ==
"001") {
434 edm::LogWarning(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] channel number of expected format, setting error flag!";
438 edm::LogWarning(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] channel number not located in PVSS name, setting error flag!";
446 for (
unsigned int i = 0;
i < input.size();
i++) {
447 output.push_back(
new TkDcuPsuMap(*(input[
i])));
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;
458 edm::LogInfo(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] " << pg.str();
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;
468 edm::LogInfo(
"SiStripPsuDetIdMap") <<
"[SiStripPsuDetIdMap::" << __func__ <<
"] " << cg.str();
472 if (pgMap.size() != 0) {
return pgMap; }
473 std::vector< std::pair<uint32_t, std::string> > emptyVec;
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;
482 std::vector<bool> ddUsed(dcuDetIds_.size(),
false);
483 std::vector<bool> dpUsed(dcuPsus_.size(),
false);
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()) {
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++; }
499 std::cout <<
"Number of used DCU-PSU entries: " << numDpUsed << std::endl;
500 std::cout <<
"Number of unused DCU-PSU entries: " << numDpNotUsed << std::endl;
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++; }
508 std::cout <<
"Number of used DCU-DETID entries: " << numDdUsed << std::endl;
509 std::cout <<
"Number of unused DCU-DETID entries: " << numDdNotUsed << std::endl;
511 std::cout <<
"Size of PSU-DETID map: " << pgMap.size() << std::endl;
512 std::cout <<
"Size of detectorLocations: " << detectorLocations.size() << std::endl;
519 SiStripDbParams::SiStripPartitions::const_iterator iter;
521 std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > resultVec;
527 if ( partition ==
"" || partition == iter->second.partitionName() ) {
529 if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
531 if (!range.empty()) {
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])) ) );
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();
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);
563 for (
unsigned int i = 0;
i < testVec.size();
i++) {
564 if (fecInfo == testVec[
i].
first) {
566 dcuids.insert(dcuids.end(), (testVec[
i].second).
begin(), (testVec[
i].second).
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;
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));
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;
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()) {
597 for (
unsigned int i = 0;
i < dcuids.size();
i++) {
598 if (dcuids[
i] != dcuid_) {pgDcu.push_back(dcuids[
i]);}
601 std::cout <<
"Oh oh ... we have a duplicate :-(" << std::endl;
static std::string defaultPartitionName_
void clone(DcuPsuVector &input, DcuPsuVector &output)
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)
DcuPsus::range DcuPsusRange
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)
enumDeviceType DeviceType
std::vector< uint32_t > getHvDetID(std::string pvss)
int IsHVChannel(std::string pvss)
DeviceDescriptions::range DeviceDescriptionsRange
std::vector< std::pair< uint32_t, std::string > > getDcuPsuMap()
std::vector< uint32_t > findDcuIdFromDeviceAddress(uint32_t dcuid_)
std::vector< DcuDetId > DcuDetIdsV
Container class for database connection parameters.
uint32_t getDcuId(std::string pvss)
std::vector< TkDcuPsuMap * > DcuPsuVector
void checkMapInputValues(SiStripConfigDb::DcuDetIdsV dcuDetIds_, DcuPsuVector dcuPsus_)
std::vector< uint32_t > getLvDetID(std::string pvss)
std::string getDetectorLocation(uint32_t detid)
std::vector< DeviceDescription * > DeviceDescriptionsV