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")),
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  debug_ = iConfig.getUntrackedParameter<bool>("debug");
54  recordName_ = iConfig.getUntrackedParameter<std::string>("recordName", "SiPixelQualityFromDbRcd");
55 
56 }
57 
58 //--------------------------------------------------------------------------------------------------
60 
61 //--------------------------------------------------------------------------------------------------
63 
64 //--------------------------------------------------------------------------------------------------
66 
67 //--------------------------------------------------------------------------------------------------
69 }
70 
71 //--------------------------------------------------------------------------------------------------
74  endLumiBlock_ = 0;
75 
77  iSetup.get<SiPixelQualityFromDbRcd>().get( qualityInfo );
78  badPixelInfo_ = qualityInfo.product();
79 
80 }
81 
82 //--------------------------------------------------------------------------------------------------
83 void SiPixelStatusHarvester::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
84 
86 
87  std::map<edm::LuminosityBlockNumber_t,std::map<int,std::vector<int>> > FEDerror25Map = siPixelStatusManager_.getFEDerror25Rocs();
88 
89  std::map<edm::LuminosityBlockNumber_t,SiPixelDetectorStatus> siPixelStatusMap = siPixelStatusManager_.getBadComponents();
91 
92  if(poolDbService.isAvailable() ) {// if(poolDbService.isAvailable() )
93 
94  // start producing tag for permanent component removed
95  SiPixelQuality *siPixelQualityPermBad = new SiPixelQuality();
96  const std::vector<SiPixelQuality::disabledModuleType> badComponentList = badPixelInfo_->getBadComponentList();
97  for(unsigned int i = 0; i<badComponentList.size();i++){
98  siPixelQualityPermBad->addDisabledModule(badComponentList[i]);
99  }
100  if(debug_==true){ // only produced for debugging reason
101  cond::Time_t thisIOV = (cond::Time_t) iRun.id().run();
102  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_permanentBad");
103  }
104 
105  // IOV for final payloads. FEDerror25 and pcl
106  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> finalIOV;
107  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> fedError25IOV;
108  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> pclIOV;
109 
110  // stuckTBM tag from FED error 25 with permanent component removed
111  for(SiPixelStatusManager::FEDerror25Map_iterator it=FEDerror25Map.begin(); it!=FEDerror25Map.end();it++){
112 
113  cond::Time_t thisIOV = 1;
114  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
115  thisIOV = (cond::Time_t)(lu.value());
116 
117  SiPixelQuality *siPixelQuality = new SiPixelQuality();
118  SiPixelQuality *siPixelQuality_FEDerror25 = new SiPixelQuality();
119 
120  std::map<int, std::vector<int> > tmpFEDerror25 = it->second;
121  for(std::map<int, std::vector<int> >::iterator ilist = tmpFEDerror25.begin(); ilist!=tmpFEDerror25.end();ilist++){
122 
123  int detid = ilist->first;
124 
125  SiPixelQuality::disabledModuleType BadModule, BadModule_FEDerror25;
126 
127  BadModule.DetID = uint32_t(detid); BadModule_FEDerror25.DetID = uint32_t(detid);
128  BadModule.errorType = 3; BadModule_FEDerror25.errorType = 3;
129 
130  BadModule.BadRocs = 0; BadModule_FEDerror25.BadRocs = 0;
131  std::vector<uint32_t> BadRocList, BadRocList_FEDerror25;
132  std::vector<int> list = ilist->second;
133 
134  for(unsigned int i=0; i<list.size();i++){
135  // only include rocs that are not permanent known bad
136  int iroc = list[i];
137  BadRocList_FEDerror25.push_back(uint32_t(iroc));
138  if(!badPixelInfo_->IsRocBad(detid, iroc)){
139  BadRocList.push_back(uint32_t(iroc));
140  }
141 
142  }
143 
144  // change module error type if all ROCs are bad
145  if(BadRocList.size()==16)
146  BadModule.errorType = 0;
147 
148  short badrocs = 0;
149  for(std::vector<uint32_t>::iterator iter = BadRocList.begin(); iter != BadRocList.end(); ++iter){
150  badrocs += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
151  }
152  // fill the badmodule only if there is(are) bad ROC(s) in it
153  if(badrocs!=0){
154  BadModule.BadRocs = badrocs;
155  siPixelQuality->addDisabledModule(BadModule);
156  }
157 
158  // change module error type if all ROCs are bad
159  if(BadRocList_FEDerror25.size()==16)
160  BadModule_FEDerror25.errorType = 0;
161 
162  short badrocs_FEDerror25 = 0;
163  for(std::vector<uint32_t>::iterator iter = BadRocList_FEDerror25.begin(); iter != BadRocList_FEDerror25.end(); ++iter){
164  badrocs_FEDerror25 += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
165  }
166  // fill the badmodule only if there is(are) bad ROC(s) in it
167  if(badrocs_FEDerror25!=0){
168  BadModule_FEDerror25.BadRocs = badrocs_FEDerror25;
169  siPixelQuality_FEDerror25->addDisabledModule(BadModule_FEDerror25);
170  }
171 
172  } // loop over modules
173 
174  finalIOV[it->first] = it->first;
175  fedError25IOV[it->first] = it->first;
176 
177  poolDbService->writeOne<SiPixelQuality>(siPixelQuality, thisIOV, recordName_+"_stuckTBM");
178  if(debug_==true) // only produced for debugging reason
179  poolDbService->writeOne<SiPixelQuality>(siPixelQuality_FEDerror25, thisIOV, recordName_+"_FEDerror25");
180 
181  delete siPixelQuality;
182  delete siPixelQuality_FEDerror25;
183 
184  }
185 
186  // IOV for PCL combines permanent bad/stuckTBM/other
187  for(SiPixelStatusManager::siPixelStatusMap_iterator it=siPixelStatusMap.begin(); it!=siPixelStatusMap.end();it++){
188  finalIOV[it->first] = it->first;
189  pclIOV[it->first] = it->first;
190  }
191 
192  // loop over final IOV
193  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
194  for(itIOV=finalIOV.begin();itIOV!=finalIOV.end();itIOV++){
195 
196  cond::Time_t thisIOV = 1;
197  edm::LuminosityBlockID lu(iRun.id().run(),itIOV->first);
198  thisIOV = (cond::Time_t)(lu.value());
199 
200  edm::LuminosityBlockNumber_t lumiStuckTBMs = SiPixelStatusHarvester::stepIOV(itIOV->first,fedError25IOV);
201  edm::LuminosityBlockNumber_t lumiPCL = SiPixelStatusHarvester::stepIOV(itIOV->first,pclIOV);
202 
203  // get badROC list due to FEDerror25 = stuckTBM + permanent bad components
204  std::map<int, std::vector<int> > tmpFEDerror25 = FEDerror25Map[lumiStuckTBMs];
205  // get SiPixelDetectorStatus
206  SiPixelDetectorStatus tmpSiPixelStatus = siPixelStatusMap[lumiPCL];
207  double DetAverage = tmpSiPixelStatus.perRocDigiOcc();
208 
209  // For the IOV of which the statistics is too low, for e.g., a cosmic run
210  // When using dynamicLumibased harvester or runbased harvester
211  // this only happens when the full run is lack of statistics
212  if(DetAverage<aveDigiOcc_) {
213 
214  edm::LogInfo("SiPixelStatusHarvester")
215  << "Tag requested for prompt in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
216  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
217  // add empty bad components to "other" tag
218  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
219  edm::LogInfo("SiPixelStatusHarvester")
220  << "Tag requested for other in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
221  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
222 
223  delete siPixelQualityDummy;
224  continue;
225 
226  }
227 
229 
230  // create the DB object
231  // payload including all : PCL = permanent bad + other + stuckTBM
232  SiPixelQuality *siPixelQualityPCL = new SiPixelQuality();
233  SiPixelQuality *siPixelQualityPrompt = new SiPixelQuality();
234  SiPixelQuality *siPixelQualityOther = new SiPixelQuality();
235 
236  std::map<int, SiPixelModuleStatus> detectorStatus = tmpSiPixelStatus.getDetectorStatus();
237  std::map<int, SiPixelModuleStatus>::iterator itModEnd = detectorStatus.end();
238  for (std::map<int, SiPixelModuleStatus>::iterator itMod = detectorStatus.begin(); itMod != itModEnd; ++itMod) {
239 
240  // create the bad module list for PCL, prompt and other
241  SiPixelQuality::disabledModuleType BadModulePCL, BadModulePrompt, BadModuleOther;
242 
243  int detid = itMod->first;
244  BadModulePCL.DetID = uint32_t(detid);
245  BadModulePrompt.DetID = uint32_t(detid); BadModuleOther.DetID = uint32_t(detid);
246 
247  BadModulePCL.errorType = 3;
248  BadModulePrompt.errorType = 3; BadModuleOther.errorType = 3;
249 
250  BadModulePCL.BadRocs = 0;
251  BadModulePrompt.BadRocs = 0; BadModuleOther.BadRocs = 0;
252 
253  std::vector<uint32_t> BadRocListPCL, BadRocListPrompt, BadRocListOther;
254 
255  SiPixelModuleStatus modStatus = itMod->second;
256  std::vector<int> listFEDerror25 = tmpFEDerror25[detid];
257 
258  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
259 
260  unsigned int rocOccupancy = modStatus.digiOccROC(iroc);
261 
262  // Bad ROC are from low DIGI Occ ROCs
263  if(rocOccupancy<1.e-4*DetAverage){
264 
265  //PCL bad roc list
266  BadRocListPCL.push_back(uint32_t(iroc));
267  //FEDerror25 list
268  std::vector<int>::iterator it = std::find(listFEDerror25.begin(), listFEDerror25.end(),iroc);
269 
270  // from prompt = PCL bad - stuckTBM = PCL bad - FEDerror25 + permanent bad
271  if(it==listFEDerror25.end() || badPixelInfo_->IsRocBad(detid, iroc))
272  // if not FEDerror25 or permanent bad
273  BadRocListPrompt.push_back(uint32_t(iroc));
274  // other source of bad components = prompt - permanent bad = PCL bad - FEDerror25
275  // or to be safe, say not FEDerro25 and not permanent bad
276  if(it==listFEDerror25.end() && !(badPixelInfo_->IsRocBad(detid, iroc))){
277  // if not permanent and not stuck TBM
278  BadRocListOther.push_back(uint32_t(iroc));
279 
280  }
281  }
282 
283  } // loop over ROCs
284 
285  if(BadRocListPCL.size()==16) BadModulePCL.errorType = 0;
286  if(BadRocListPrompt.size()==16) BadModulePrompt.errorType = 0;
287  if(BadRocListOther.size()==16) BadModuleOther.errorType = 0;
288 
289  // pcl
290  short badrocsPCL = 0;
291  for(std::vector<uint32_t>::iterator iterPCL = BadRocListPCL.begin(); iterPCL != BadRocListPCL.end(); ++iterPCL){
292  badrocsPCL += 1 << *iterPCL; // 1 << *iter = 2^{*iter} using bitwise shift
293  }
294  if(badrocsPCL!=0){
295  BadModulePCL.BadRocs = badrocsPCL;
296  siPixelQualityPCL->addDisabledModule(BadModulePCL);
297  }
298 
299  // prompt
300  short badrocsPrompt = 0;
301  for(std::vector<uint32_t>::iterator iterPrompt = BadRocListPrompt.begin(); iterPrompt != BadRocListPrompt.end(); ++iterPrompt){
302  badrocsPrompt += 1 << *iterPrompt; // 1 << *iter = 2^{*iter} using bitwise shift
303  }
304  if(badrocsPrompt!=0){
305  BadModulePrompt.BadRocs = badrocsPrompt;
306  siPixelQualityPrompt->addDisabledModule(BadModulePrompt);
307  }
308 
309  // other
310  short badrocsOther= 0;
311  for(std::vector<uint32_t>::iterator iterOther = BadRocListOther.begin(); iterOther != BadRocListOther.end(); ++iterOther){
312  badrocsOther += 1 << *iterOther; // 1 << *iter = 2^{*iter} using bitwise shift
313  }
314  if(badrocsOther!=0){
315  BadModuleOther.BadRocs = badrocsOther;
316  siPixelQualityOther->addDisabledModule(BadModuleOther);
317  }
318 
319  } // end module loop
320 
321  //PCL
322  if(debug_==true) // only produced for debugging reason
323  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPCL, thisIOV, recordName_+"_PCL");
324 
325  // prompt
326  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPrompt, thisIOV, recordName_+"_prompt");
327 
328  // other
329  poolDbService->writeOne<SiPixelQuality>(siPixelQualityOther, thisIOV, recordName_+"_other");
330 
331  delete siPixelQualityPCL;
332  delete siPixelQualityPrompt;
333  delete siPixelQualityOther;
334 
335  }// loop over IOV
336 
337  // Add a dummy IOV starting from last lumisection+1 to close the tag for the run
338  if(outputBase_ == "nLumibased" || outputBase_ == "dynamicLumibased"){
339 
341  cond::Time_t thisIOV = (cond::Time_t)(lu.value());
342 
343  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
344 
345  // add empty bad components to "other" tag
346  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
347  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
348  delete siPixelQualityDummy;
349  }
350 
351  delete siPixelQualityPermBad;
352 
353  } // end of if(poolDbService.isAvailable() )
354 
355 }
356 
357 //--------------------------------------------------------------------------------------------------
359 }
360 
361 //--------------------------------------------------------------------------------------------------
363 
365  // update endLumiBlock_ by current lumi block
366  if(endLumiBlock_<iLumi.luminosityBlock())
367  endLumiBlock_ = iLumi.luminosityBlock();
368 
369 }
370 
371 // step function for IOV
372 edm::LuminosityBlockNumber_t SiPixelStatusHarvester::stepIOV(edm::LuminosityBlockNumber_t pin, std::map<edm::LuminosityBlockNumber_t,edm::LuminosityBlockNumber_t> IOV){
373 
374  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
375  for(itIOV=IOV.begin();itIOV!=IOV.end();itIOV++){
376  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator nextItIOV;
377  nextItIOV = itIOV; nextItIOV++;
378 
379  if(nextItIOV!=IOV.end()){
380  if(pin>=itIOV->first && pin<nextItIOV->first){
381  return itIOV->first;
382  }
383  }
384  else{
385  if(pin>=itIOV->first){
386  return itIOV->first;
387  }
388  }
389 
390  }
391 
392  // return the firstIOV in case all above fail
393  return (IOV.begin())->first;
394 
395 }
396 
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
const std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > & getFEDerror25Rocs()
edm::LuminosityBlockNumber_t endLumiBlock_
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
edm::LuminosityBlockNumber_t stepIOV(edm::LuminosityBlockNumber_t pin, std::map< edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t > IOV)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
unsigned int LuminosityBlockNumber_t
SiPixelStatusManager siPixelStatusManager_
void analyze(const edm::Event &, const edm::EventSetup &) override
LuminosityBlockNumber_t luminosityBlock() const
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
const SiPixelQuality * badPixelInfo_
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
const std::vector< disabledModuleType > getBadComponentList() const
std::map< int, SiPixelModuleStatus > getDetectorStatus()
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > >::iterator FEDerror25Map_iterator
SiPixelStatusHarvester(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:59
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
HLT enums.
unsigned int digiOccROC(int iroc)
return ROC status (= hits on ROC iroc)
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