-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiPixelBadModuleByHandBuilder.cc
141 lines (111 loc) · 4.94 KB
/
SiPixelBadModuleByHandBuilder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "CondTools/SiPixel/test/SiPixelBadModuleByHandBuilder.h"
#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
#include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
#include <math.h>
#include <iostream>
#include <fstream>
SiPixelBadModuleByHandBuilder::SiPixelBadModuleByHandBuilder(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiPixelQuality>(iConfig){
printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug",false);
BadModuleList_ = iConfig.getUntrackedParameter<Parameters>("BadModuleList");
ROCListFile_ = iConfig.getUntrackedParameter<std::string>("ROCListFile");
}
SiPixelBadModuleByHandBuilder::~SiPixelBadModuleByHandBuilder(){
}
SiPixelQuality* SiPixelBadModuleByHandBuilder::getNewObject(){
SiPixelQuality* obj = new SiPixelQuality();
for(Parameters::iterator it = BadModuleList_.begin(); it != BadModuleList_.end(); ++it) {
if (printdebug_)
edm::LogInfo("SiPixelBadModuleByHandBuilder") << " BadModule " << *it << " \t" << std::endl;
SiPixelQuality::disabledModuleType BadModule;
BadModule.errorType = 3; BadModule.BadRocs = 0;
BadModule.DetID = it->getParameter<uint32_t>("detid");
std::string errorstring = it->getParameter<std::string>("errortype");
std::cout << "now looking at detid " << BadModule.DetID << ", string " << errorstring << std::endl;
//////////////////////////////////////
// errortype "whole" = int 0 in DB //
// errortype "tbmA" = int 1 in DB //
// errortype "tbmB" = int 2 in DB //
// errortype "none" = int 3 in DB //
//////////////////////////////////////
/////////////////////////////////////////////////
//each bad roc correspond to a bit to 1: num= //
// 0 <-> all good rocs //
// 1 <-> only roc 0 bad //
// 2<-> only roc 1 bad //
// 3<-> roc 0 and 1 bad //
// 4 <-> only roc 2 bad //
// ... //
/////////////////////////////////////////////////
if(errorstring=="whole"){
BadModule.errorType = 0;
BadModule.BadRocs = 65535;} //corresponds to all rocs being bad
else if(errorstring=="tbmA"){
BadModule.errorType = 1;
BadModule.BadRocs = 255;} //corresponds to Rocs 0-7 being bad
else if(errorstring=="tbmB"){
BadModule.errorType = 2;
BadModule.BadRocs = 65280;} //corresponds to Rocs 8-15 being bad
else if(errorstring=="none"){
BadModule.errorType = 3;
// badroclist_ = iConfig.getUntrackedParameter<std::vector<uint32_t> >("badroclist");
std::vector<uint32_t> BadRocList = it->getParameter<std::vector<uint32_t> >("badroclist");
short badrocs = 0;
for(std::vector<uint32_t>::iterator iter = BadRocList.begin(); iter != BadRocList.end(); ++iter){
badrocs += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
}
BadModule.BadRocs = badrocs;
}
else
edm::LogError("SiPixelQuality") << "trying to fill error type " << errorstring << ", which is not defined!" ;
obj->addDisabledModule(BadModule);
}
// fill DB from DQM list
if (ROCListFile_!="") {
std::map<uint32_t,uint32_t> disabledModules;
std::ifstream aFile(ROCListFile_.c_str());
std::string aLine;
while (std::getline(aFile, aLine)) {
char name[100];
int roc;
sscanf(aLine.c_str(), "%s %d", name, &roc);
uint32_t detId;
if (name[0]=='B') {
PixelBarrelName bn(name, true);
detId=bn.getDetId(tTopo_);
} else {
PixelEndcapName en(name, true);
detId=en.getDetId(tTopo_);
}
std::map<uint32_t,uint32_t>::iterator it=disabledModules.find(detId);
if (it==disabledModules.end()) it=disabledModules.insert(disabledModules.begin(), std::make_pair(detId,0));
it->second += 1 << roc;
//std::cout<<"New module read "<<name<<" "<<roc<<" --> "<<detId<<" "<<std::bitset<32>(it->second)<<std::endl;
}
for (std::map<uint32_t,uint32_t>::iterator it=disabledModules.begin();
it!=disabledModules.end(); it++) {
SiPixelQuality::disabledModuleType BadModule;
BadModule.DetID = it->first;
if (it->second==65535) { // "whole"
BadModule.errorType = 0;
BadModule.BadRocs = 65535;
} //corresponds to all rocs being bad
else if(it->second==255) { // "tbmA"
BadModule.errorType = 1;
BadModule.BadRocs = 255;
} //corresponds to Rocs 0-7 being bad
else if(it->second==65280) { // "tbmB"
BadModule.errorType = 2;
BadModule.BadRocs = 65280;
} //corresponds to Rocs 8-15 being bad
else { // "none"
BadModule.errorType = 3;
BadModule.BadRocs = it->second;
}
obj->addDisabledModule(BadModule);
std::cout<<"New module added: "<<tTopo_->print(BadModule.DetID)
<<", errorType: "<<BadModule.errorType
<<", BadRocs: "<<std::bitset<16>(it->second)<<std::endl;
}
}
return obj;
}