CMS 3D CMS Logo

SiPixelStatusHarvester.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * author
6  */
7 
8 // CMSSW FW
21 
22 // Condition Format
26 // CondOutput
28 
29 // Dataformat of SiPixel status in ALCAPROMPT data
31 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
32 //#include "CondCore/Utilities/interface/Utilities.h"
33 
34 // harvest helper class
36 // header file
38 
39 #include <iostream>
40 #include <cstring>
41 
42 using namespace edm;
43 
44 //--------------------------------------------------------------------------------------------------
46  outputBase_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("outputBase")),
47  aveDigiOcc_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<int>("aveDigiOcc", 20000)),
48  nLumi_(iConfig.getParameter<edm::ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<int>("resetEveryNLumi")),
49  moduleName_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("moduleName")),
50  label_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("label")),
51  siPixelStatusManager_(iConfig, consumesCollector()) {
52 
53  recordName_ = iConfig.getUntrackedParameter<std::string>("recordName", "SiPixelQualityFromDbRcd");
54  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
55  dumpTxt_ = iConfig.getUntrackedParameter<bool>("dumpTxt",false);
56  outTxtFileName_ = iConfig.getUntrackedParameter<std::string>("txtFileName");
57 
58 }
59 
60 //--------------------------------------------------------------------------------------------------
62 
63 //--------------------------------------------------------------------------------------------------
65 
66 //--------------------------------------------------------------------------------------------------
68 
69 //--------------------------------------------------------------------------------------------------
71 }
72 
73 //--------------------------------------------------------------------------------------------------
76  endLumiBlock_ = 0;
77 
79  iSetup.get<SiPixelQualityFromDbRcd>().get( qualityInfo );
80  badPixelInfo_ = qualityInfo.product();
81 
82 }
83 
84 //--------------------------------------------------------------------------------------------------
85 void SiPixelStatusHarvester::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
86 
88 
89  std::map<edm::LuminosityBlockNumber_t,std::map<int,std::vector<int>> > stuckTBMsMap = siPixelStatusManager_.getStuckTBMsRocs();
90 
91  std::map<edm::LuminosityBlockNumber_t,SiPixelDetectorStatus> siPixelStatusMap = siPixelStatusManager_.getBadComponents();
93 
94  if(poolDbService.isAvailable() ) {// if(poolDbService.isAvailable() )
95 
96  // start producing tag for permanent component removed
97  SiPixelQuality *siPixelQualityPermBad = new SiPixelQuality();
98  const std::vector<SiPixelQuality::disabledModuleType> badComponentList = badPixelInfo_->getBadComponentList();
99  for(unsigned int i = 0; i<badComponentList.size();i++){
100  siPixelQualityPermBad->addDisabledModule(badComponentList[i]);
101  }
102 
103  // stuckTBM tag from FED error 25 with permanent component removed
104  for(SiPixelStatusManager::stuckTBMsMap_iterator it=stuckTBMsMap.begin(); it!=stuckTBMsMap.end();it++){
105 
106  cond::Time_t thisIOV = 1;
107  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
108  thisIOV = (cond::Time_t)(lu.value());
109 
110  SiPixelQuality *siPixelQuality = new SiPixelQuality();
111 
112  std::map<int, std::vector<int> > tmpStuckTBMs = it->second;
113  for(std::map<int, std::vector<int> >::iterator ilist = tmpStuckTBMs.begin(); ilist!=tmpStuckTBMs.end();ilist++){
114 
115  int detid = ilist->first;
116 
118 
119  BadModule.DetID = uint32_t(detid);
120  BadModule.errorType = 3;
121 
122  BadModule.BadRocs = 0;
123  std::vector<uint32_t> BadRocList;
124  std::vector<int> list = ilist->second;
125 
126  for(unsigned int i=0; i<list.size();i++){
127  // only include rocs that are not permanent known bad
128  int iroc = list[i];
129  if(!badPixelInfo_->IsRocBad(detid, iroc)){
130  BadRocList.push_back(uint32_t(iroc));
131  }
132  }
133  // change module error type if all ROCs are bad
134  if(BadRocList.size()==16)
135  BadModule.errorType = 0;
136 
137  short badrocs = 0;
138  for(std::vector<uint32_t>::iterator iter = BadRocList.begin(); iter != BadRocList.end(); ++iter){
139  badrocs += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
140  }
141  // fill the badmodule only if there is(are) bad ROC(s) in it
142  if(badrocs!=0){
143  BadModule.BadRocs = badrocs;
144  siPixelQuality->addDisabledModule(BadModule);
145  }
146  }
147 
148  if (poolDbService->isNewTagRequest(recordName_+"_stuckTBM") ) {
149  edm::LogInfo("SiPixelStatusHarvester")
150  << "new tag requested for stuckTBM" << std::endl;
151  poolDbService->writeOne<SiPixelQuality>(siPixelQuality, thisIOV, recordName_+"_stuckTBM");
152  }
153  else {
154  edm::LogInfo("SiPixelStatusHarvester")
155  << "no new tag requested, appending IOV for stuckTBM" << std::endl;
156  poolDbService->writeOne<SiPixelQuality>(siPixelQuality, thisIOV, recordName_+"_stuckTBM");
157  }
158 
159  }
160 
161  // Payload for PCL combines permanent bad/stuckTBM/other
162  for(SiPixelStatusManager::siPixelStatusMap_iterator it=siPixelStatusMap.begin(); it!=siPixelStatusMap.end();it++){
163 
164  cond::Time_t thisIOV = 1;
165 
166  if (outputBase_ == "runbased") {
167  thisIOV = (cond::Time_t) iRun.id().run();
168  }
169  else if (outputBase_ == "nLumibased" || outputBase_ == "dynamicLumibased" ) {
170  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
171  thisIOV = (cond::Time_t)(lu.value());
172  }
173 
174  SiPixelDetectorStatus tmpSiPixelStatus = it->second;
175  double DetAverage = tmpSiPixelStatus.perRocDigiOcc();
176 
177  // For the IOV of which the statistics is too low, for e.g., a cosmic run
178  // When using dynamicLumibased harvester or runbased harvester
179  // this only happens when the full run is lack of statistics
180  if(DetAverage<aveDigiOcc_) {
181 
182  edm::LogInfo("SiPixelStatusHarvester")
183  << "Tag requested for prompt in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
184  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
185  // add empty bad components to "other" tag
186  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
187  edm::LogInfo("SiPixelStatusHarvester")
188  << "Tag requested for other in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
189  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
190 
191  continue;
192 
193  }
194 
196 
197  // create the DB object
198  // payload including all : permanent bad + other + stuckTBM
199  SiPixelQuality *siPixelQualityPCL = new SiPixelQuality();
200  // payload for prompt reco : permanent bad + other sources of bad components
201  SiPixelQuality *siPixelQualityPrompt = new SiPixelQuality();
202  // payload for : other sources of bad components
203  SiPixelQuality *siPixelQualityOther = new SiPixelQuality();
204 
205  // get badROC list due to stuck TBM
206  std::map<int, std::vector<int> > tmpStuckTBMs = tmpSiPixelStatus.getStuckTBMsRocs();
207 
208  std::map<int, SiPixelModuleStatus> detectorStatus = tmpSiPixelStatus.getDetectorStatus();
209  std::map<int, SiPixelModuleStatus>::iterator itModEnd = detectorStatus.end();
210  for (std::map<int, SiPixelModuleStatus>::iterator itMod = detectorStatus.begin(); itMod != itModEnd; ++itMod) {
211 
212  // create the bad module list
213  SiPixelQuality::disabledModuleType BadModulePCL, BadModulePrompt, BadModuleOther;
214 
215  int detid = itMod->first;
216  BadModulePCL.DetID = uint32_t(detid);
217  BadModulePrompt.DetID = uint32_t(detid); BadModuleOther.DetID = uint32_t(detid);
218 
219  BadModulePCL.errorType = 3;
220  BadModulePrompt.errorType = 3; BadModuleOther.errorType = 3;
221 
222  BadModulePCL.BadRocs = 0;
223  BadModulePrompt.BadRocs = 0; BadModuleOther.BadRocs = 0;
224 
225  std::vector<uint32_t> BadRocListPCL, BadRocListPrompt, BadRocListOther;
226 
227  SiPixelModuleStatus modStatus = itMod->second;
228  std::vector<int> listStuckTBM = tmpStuckTBMs[detid];
229 
230  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
231 
232  unsigned long int rocOccupancy = modStatus.digiOccROC(iroc);
233 
234  // Bad ROC are from low DIGI Occ ROCs
235  if(rocOccupancy<1.e-4*DetAverage){
236 
237  BadRocListPCL.push_back(uint32_t(iroc));
238  std::vector<int>::iterator it = std::find(listStuckTBM.begin(), listStuckTBM.end(),iroc);
239 
240  // from prompt = permanent bad + other
241  if(it==listStuckTBM.end() || badPixelInfo_->IsRocBad(detid, iroc))
242  // if permanent or not stuck TBM( in the stuckTBM list but not permanent)
243  BadRocListPrompt.push_back(uint32_t(iroc));
244 
245  // other source of bad components
246  if(it==listStuckTBM.end() && !(badPixelInfo_->IsRocBad(detid, iroc)))
247  // if not permanent and not stuck TBM
248  BadRocListOther.push_back(uint32_t(iroc));
249 
250  }
251  }
252 
253  if(BadRocListPCL.size()==16) BadModulePCL.errorType = 0;
254  if(BadRocListPrompt.size()==16) BadModulePrompt.errorType = 0;
255  if(BadRocListOther.size()==16) BadModuleOther.errorType = 0;
256 
257  short badrocsPCL = 0;
258  for(std::vector<uint32_t>::iterator iterPCL = BadRocListPCL.begin(); iterPCL != BadRocListPCL.end(); ++iterPCL){
259  badrocsPCL += 1 << *iterPCL; // 1 << *iter = 2^{*iter} using bitwise shift
260  }
261  // fill the badmodule only if there is(are) bad ROC(s) in it
262  if(badrocsPCL!=0){
263  BadModulePCL.BadRocs = badrocsPCL;
264  siPixelQualityPCL->addDisabledModule(BadModulePCL);
265  }
266 
267  short badrocsPrompt = 0;
268  for(std::vector<uint32_t>::iterator iterPrompt = BadRocListPrompt.begin(); iterPrompt != BadRocListPrompt.end(); ++iterPrompt){
269  badrocsPrompt += 1 << *iterPrompt; // 1 << *iter = 2^{*iter} using bitwise shift
270  }
271  // fill the badmodule only if there is(are) bad ROC(s) in it
272  if(badrocsPrompt!=0){
273  BadModulePrompt.BadRocs = badrocsPrompt;
274  siPixelQualityPrompt->addDisabledModule(BadModulePrompt);
275  }
276 
277  short badrocsOther = 0;
278  for(std::vector<uint32_t>::iterator iterOther = BadRocListOther.begin(); iterOther != BadRocListOther.end(); ++iterOther){
279  badrocsOther += 1 << *iterOther; // 1 << *iter = 2^{*iter} using bitwise shift
280  }
281  // fill the badmodule only if there is(are) bad ROC(s) in it
282  if(badrocsOther!=0){
283  BadModuleOther.BadRocs = badrocsOther;
284  siPixelQualityOther->addDisabledModule(BadModuleOther);
285  }
286 
287  } // end module loop
288 
289  if(debug_) // only produce the tag for all sources of bad components for debugging reason
290  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPCL, thisIOV, recordName_+"_PCL");
291 
292  if (poolDbService->isNewTagRequest(recordName_+"_prompt")) {
293  edm::LogInfo("SiPixelStatusHarvester")
294  << "new tag requested for prompt" << std::endl;
295  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPrompt, thisIOV, recordName_+"_prompt");
296  }
297  else {
298  edm::LogInfo("SiPixelStatusHarvester")
299  << "no new tag requested, appending IOV for prompt" << std::endl;
300  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPrompt, thisIOV, recordName_+"_prompt");
301  }
302 
303  if (poolDbService->isNewTagRequest(recordName_+"_other")) {
304  edm::LogInfo("SiPixelStatusHarvester")
305  << "new tag requested for other" << std::endl;
306  poolDbService->writeOne<SiPixelQuality>(siPixelQualityOther, thisIOV, recordName_+"_other");
307  }
308  else {
309  edm::LogInfo("SiPixelStatusHarvester")
310  << "no new tag requested, appending IOV for other" << std::endl;
311  poolDbService->writeOne<SiPixelQuality>(siPixelQualityOther, thisIOV, recordName_+"_other");
312  }
313 
314  if (dumpTxt_){ // text dump for the DIGI occuancy for all pixels in all ROCs for the pixle detector
315  std::string outTxt = Form("%s_Run%d_Lumi%d_SiPixelStatus.txt", outTxtFileName_.c_str(), iRun.id().run(),it->first);
316  tmpSiPixelStatus.dumpToFile(outTxt);
317  }
318 
319  }// loop over IOV-structured Map (payloads)
320 
321  // Add a dummy IOV starting from last lumisection+1 to close the tag for the run
322  if(outputBase_ == "nLumibased" || outputBase_ == "dynamicLumibased"){
323 
325  cond::Time_t thisIOV = (cond::Time_t)(lu.value());
326 
327  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
328 
329  // add empty bad components to "other" tag
330  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
331  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
332 
333  }
334 
335  } // end of if(poolDbService.isAvailable() )
336 
337 }
338 
339 //--------------------------------------------------------------------------------------------------
341 }
342 
343 //--------------------------------------------------------------------------------------------------
345 
347  // update endLumiBlock_ by current lumi block
348  if(endLumiBlock_<iLumi.luminosityBlock())
349  endLumiBlock_ = iLumi.luminosityBlock();
350 
351 }
352 
353 
void addDisabledModule(disabledModuleType module)
T getUntrackedParameter(std::string const &, T const &) const
RunID const & id() const
Definition: RunBase.h:39
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: RunID.h:39
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::LuminosityBlockNumber_t endLumiBlock_
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
SiPixelStatusManager siPixelStatusManager_
void analyze(const edm::Event &, const edm::EventSetup &) override
LuminosityBlockNumber_t luminosityBlock() const
const std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > & getStuckTBMsRocs()
std::map< int, std::vector< int > > getStuckTBMsRocs()
int iEvent
Definition: GenABIO.cc:230
unsigned long long Time_t
Definition: Time.h:16
void beginRun(const edm::Run &, const edm::EventSetup &) override
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
bool isNewTagRequest(const std::string &recordName)
const SiPixelQuality * badPixelInfo_
unsigned long int digiOccROC(int iroc)
return ROC status (= hits on ROC iroc)
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > >::iterator stuckTBMsMap_iterator
const std::vector< disabledModuleType > getBadComponentList() const
std::map< int, SiPixelModuleStatus > getDetectorStatus()
void dumpToFile(std::string filename)
SiPixelStatusHarvester(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:59
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
HLT enums.
void readLumi(const edm::LuminosityBlock &)
const std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > & getBadComponents()
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:43
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
void endRun(const edm::Run &, const edm::EventSetup &) override