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 
101  // IOV for final payloads. FEDerror25 and pcl
102  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> finalIOV;
103  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> fedError25IOV;
104  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> pclIOV;
105 
106  // stuckTBM tag from FED error 25 with permanent component removed
107  for(SiPixelStatusManager::FEDerror25Map_iterator it=FEDerror25Map.begin(); it!=FEDerror25Map.end();it++){
108 
109  cond::Time_t thisIOV = 1;
110  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
111  thisIOV = (cond::Time_t)(lu.value());
112 
113  SiPixelQuality *siPixelQuality = new SiPixelQuality();
114 
115  std::map<int, std::vector<int> > tmpFEDerror25 = it->second;
116  for(std::map<int, std::vector<int> >::iterator ilist = tmpFEDerror25.begin(); ilist!=tmpFEDerror25.end();ilist++){
117 
118  int detid = ilist->first;
119 
121 
122  BadModule.DetID = uint32_t(detid);
123  BadModule.errorType = 3;
124 
125  BadModule.BadRocs = 0;
126  std::vector<uint32_t> BadRocList;
127  std::vector<int> list = ilist->second;
128 
129  for(unsigned int i=0; i<list.size();i++){
130  // only include rocs that are not permanent known bad
131  int iroc = list[i];
132  if(!badPixelInfo_->IsRocBad(detid, iroc)){
133  BadRocList.push_back(uint32_t(iroc));
134  }
135  }
136  // change module error type if all ROCs are bad
137  if(BadRocList.size()==16)
138  BadModule.errorType = 0;
139 
140  short badrocs = 0;
141  for(std::vector<uint32_t>::iterator iter = BadRocList.begin(); iter != BadRocList.end(); ++iter){
142  badrocs += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
143  }
144  // fill the badmodule only if there is(are) bad ROC(s) in it
145  if(badrocs!=0){
146  BadModule.BadRocs = badrocs;
147  siPixelQuality->addDisabledModule(BadModule);
148  }
149 
150  } // loop over modules
151 
152  finalIOV[it->first] = it->first;
153  fedError25IOV[it->first] = it->first;
154 
155  poolDbService->writeOne<SiPixelQuality>(siPixelQuality, thisIOV, recordName_+"_stuckTBM");
156 
157  }
158 
159  // IOV for PCL combines permanent bad/stuckTBM/other
160  for(SiPixelStatusManager::siPixelStatusMap_iterator it=siPixelStatusMap.begin(); it!=siPixelStatusMap.end();it++){
161  finalIOV[it->first] = it->first;
162  pclIOV[it->first] = it->first;
163  }
164 
165  // loop over final IOV
166  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
167  for(itIOV=finalIOV.begin();itIOV!=finalIOV.end();itIOV++){
168 
169  cond::Time_t thisIOV = 1;
170  edm::LuminosityBlockID lu(iRun.id().run(),itIOV->first);
171  thisIOV = (cond::Time_t)(lu.value());
172 
173  edm::LuminosityBlockNumber_t lumiStuckTBMs = SiPixelStatusHarvester::stepIOV(itIOV->first,fedError25IOV);
174  edm::LuminosityBlockNumber_t lumiPCL = SiPixelStatusHarvester::stepIOV(itIOV->first,pclIOV);
175 
176  // get badROC list due to FEDerror25 = stuckTBM + permanent bad components
177  std::map<int, std::vector<int> > tmpFEDerror25 = FEDerror25Map[lumiStuckTBMs];
178  // get SiPixelDetectorStatus
179  SiPixelDetectorStatus tmpSiPixelStatus = siPixelStatusMap[lumiPCL];
180  double DetAverage = tmpSiPixelStatus.perRocDigiOcc();
181 
182  // For the IOV of which the statistics is too low, for e.g., a cosmic run
183  // When using dynamicLumibased harvester or runbased harvester
184  // this only happens when the full run is lack of statistics
185  if(DetAverage<aveDigiOcc_) {
186 
187  edm::LogInfo("SiPixelStatusHarvester")
188  << "Tag requested for prompt in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
189  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
190  // add empty bad components to "other" tag
191  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
192  edm::LogInfo("SiPixelStatusHarvester")
193  << "Tag requested for other in low statistics IOV in the "<<outputBase_<<" harvester"<< std::endl;
194  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
195 
196  continue;
197 
198  }
199 
201 
202  // create the DB object
203  // payload including all : PCL = permanent bad + other + stuckTBM
204  SiPixelQuality *siPixelQualityPCL = new SiPixelQuality();
205  SiPixelQuality *siPixelQualityPrompt = new SiPixelQuality();
206  SiPixelQuality *siPixelQualityOther = new SiPixelQuality();
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 for PCL, prompt and other
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> listFEDerror25 = tmpFEDerror25[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  //PCL bad roc list
238  BadRocListPCL.push_back(uint32_t(iroc));
239  //FEDerror25 list
240  std::vector<int>::iterator it = std::find(listFEDerror25.begin(), listFEDerror25.end(),iroc);
241 
242  // from prompt = PCL bad - stuckTBM = PCL bad - FEDerror25 + permanent bad
243  if(it==listFEDerror25.end() || badPixelInfo_->IsRocBad(detid, iroc))
244  // if not FEDerror25 or permanent bad
245  BadRocListPrompt.push_back(uint32_t(iroc));
246 
247  // other source of bad components = prompt - permanent bad = PCL bad - FEDerror25
248  // or to be safe, say not FEDerro25 and not permanent bad
249  if(it==listFEDerror25.end() && !(badPixelInfo_->IsRocBad(detid, iroc)))
250  // if not permanent and not stuck TBM
251  BadRocListOther.push_back(uint32_t(iroc));
252 
253  }
254 
255  } // loop over ROCs
256 
257  if(BadRocListPCL.size()==16) BadModulePCL.errorType = 0;
258  if(BadRocListPrompt.size()==16) BadModulePrompt.errorType = 0;
259  if(BadRocListOther.size()==16) BadModuleOther.errorType = 0;
260 
261  // pcl
262  short badrocsPCL = 0;
263  for(std::vector<uint32_t>::iterator iterPCL = BadRocListPCL.begin(); iterPCL != BadRocListPCL.end(); ++iterPCL){
264  badrocsPCL += 1 << *iterPCL; // 1 << *iter = 2^{*iter} using bitwise shift
265  }
266  if(badrocsPCL!=0){
267  BadModulePCL.BadRocs = badrocsPCL;
268  siPixelQualityPCL->addDisabledModule(BadModulePCL);
269  }
270 
271  // prompt
272  short badrocsPrompt = 0;
273  for(std::vector<uint32_t>::iterator iterPrompt = BadRocListPrompt.begin(); iterPrompt != BadRocListPrompt.end(); ++iterPrompt){
274  badrocsPrompt += 1 << *iterPrompt; // 1 << *iter = 2^{*iter} using bitwise shift
275  }
276  if(badrocsPrompt!=0){
277  BadModulePrompt.BadRocs = badrocsPrompt;
278  siPixelQualityPrompt->addDisabledModule(BadModulePrompt);
279  }
280 
281  // other
282  short badrocsOther= 0;
283  for(std::vector<uint32_t>::iterator iterOther = BadRocListOther.begin(); iterOther != BadRocListOther.end(); ++iterOther){
284  badrocsOther += 1 << *iterOther; // 1 << *iter = 2^{*iter} using bitwise shift
285  }
286  if(badrocsOther!=0){
287  BadModuleOther.BadRocs = badrocsOther;
288  siPixelQualityOther->addDisabledModule(BadModuleOther);
289  }
290 
291  } // end module loop
292 
293  //PCL
294  if(debug_==true) // only produce the tag for all sources of bad components for debugging reason
295  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPCL, thisIOV, recordName_+"_PCL");
296 
297  // prompt
298  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPrompt, thisIOV, recordName_+"_prompt");
299 
300  // other
301  poolDbService->writeOne<SiPixelQuality>(siPixelQualityOther, thisIOV, recordName_+"_other");
302 
303  }// loop over IOV
304 
305  // Add a dummy IOV starting from last lumisection+1 to close the tag for the run
306  if(outputBase_ == "nLumibased" || outputBase_ == "dynamicLumibased"){
307 
309  cond::Time_t thisIOV = (cond::Time_t)(lu.value());
310 
311  poolDbService->writeOne<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_+"_prompt");
312 
313  // add empty bad components to "other" tag
314  SiPixelQuality* siPixelQualityDummy = new SiPixelQuality();
315  poolDbService->writeOne<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_+"_other");
316 
317  }
318 
319  } // end of if(poolDbService.isAvailable() )
320 
321 }
322 
323 //--------------------------------------------------------------------------------------------------
325 }
326 
327 //--------------------------------------------------------------------------------------------------
329 
331  // update endLumiBlock_ by current lumi block
332  if(endLumiBlock_<iLumi.luminosityBlock())
333  endLumiBlock_ = iLumi.luminosityBlock();
334 
335 }
336 
337 // step function for IOV
338 edm::LuminosityBlockNumber_t SiPixelStatusHarvester::stepIOV(edm::LuminosityBlockNumber_t pin, std::map<edm::LuminosityBlockNumber_t,edm::LuminosityBlockNumber_t> IOV){
339 
340  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
341  for(itIOV=IOV.begin();itIOV!=IOV.end();itIOV++){
342  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator nextItIOV;
343  nextItIOV = itIOV; nextItIOV++;
344 
345  if(nextItIOV!=IOV.end()){
346  if(pin>=itIOV->first && pin<nextItIOV->first){
347  return itIOV->first;
348  }
349  }
350  else{
351  if(pin>=itIOV->first){
352  return itIOV->first;
353  }
354  }
355 
356  }
357 
358  // return the firstIOV in case all above fail
359  return (IOV.begin())->first;
360 
361 }
362 
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