CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelRawDataErrorSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorRawData
4 // Class: SiPixelRawDataErrorSource
5 //
21 //
22 // Original Author: Andrew York
23 //
25 // Framework
28 // DQM Framework
32 
33 // Geometry
38 // DataFormats
46 //
47 #include <string>
48 #include <stdlib.h>
49 
50 using namespace std;
51 using namespace edm;
52 
54  conf_(iConfig),
55  src_( consumes<DetSetVector<SiPixelRawDataError> >( conf_.getParameter<edm::InputTag>( "src" ) ) ),
56  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
57  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
58  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
59  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
60  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
61  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
62  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
63  isUpgrade( conf_.getUntrackedParameter<bool>("isUpgrade",false) )
64 {
65  firstRun = true;
66  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource: Got DQM BackEnd interface"<<endl;
67  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
68  inputSourceToken_ = consumes<FEDRawDataCollection>(conf_.getUntrackedParameter<string>("inputSource", "source"));
69 }
70 
71 
73 {
74  // do anything here that needs to be done at desctruction time
75  // (e.g. close files, deallocate resources etc.)
76  LogInfo ("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor"<<endl;
77 }
78 
80 
81  LogInfo ("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
82  LogInfo ("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
83 
84  if(firstRun){
85  eventNo = 0;
86 
87  firstRun = false;
88  }
89 
90  // Build map
91  buildStructure(iSetup);
92 }
93 
95  // Book Monitoring Elements
96  bookMEs(iBooker);
97 }
98 
99 //------------------------------------------------------------------
100 // Method called for every event
101 //------------------------------------------------------------------
103 {
104  eventNo++;
105  //check feds in readout
106  if(eventNo==1){
107  // check if any Pixel FED is in readout:
108  edm::Handle<FEDRawDataCollection> rawDataHandle;
109  iEvent.getByToken(inputSourceToken_, rawDataHandle);
110  if(!rawDataHandle.isValid()){
111  edm::LogInfo("SiPixelRawDataErrorSource") << "inputsource is empty";
112  }
113  else{
114  const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
115  for(int i = 0; i != 40; i++){
116  if(rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data()) fedcounter->setBinContent(i+1,1);
117  }
118  }
119  }
120  // get input data
122  iEvent.getByToken( src_, input );
123  if (!input.isValid()) return;
124 
125  int lumiSection = (int)iEvent.luminosityBlock();
126 
127  int nEventBPIXModuleErrors = 0; int nEventFPIXModuleErrors = 0; int nEventBPIXFEDErrors = 0; int nEventFPIXFEDErrors = 0;
128  int nErrors = 0;
129 
130  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
131  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
132  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
133 
134  int numberOfModuleErrors = (*struct_iter).second->fill(*input, &meMapFEDs_, modOn, ladOn, bladeOn);
135  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
136  if(DetId( (*struct_iter).first ).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
137  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<endl;
138  nErrors = nErrors + numberOfModuleErrors;
139  //if(nErrors>0) cout<<"MODULES: nErrors: "<<nErrors<<endl;
140  }
141  for (struct_iter2 = theFEDStructure.begin() ; struct_iter2 != theFEDStructure.end() ; struct_iter2++) {
142 
143  int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input, &meMapFEDs_);
144  if((*struct_iter2).first <= 31) nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors; // (*struct_iter2).first >= 0, since (*struct_iter2).first is unsigned
145  if((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39) nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
146  //cout<<"NFEDErrors: "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
147  nErrors = nErrors + numberOfFEDErrors;
148  //if(nErrors>0) cout<<"FEDS: nErrors: "<<nErrors<<endl;
149  }
150  if(byLumiErrors){
152  //cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<" "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
153  if(nEventBPIXModuleErrors+nEventBPIXFEDErrors>0) byLumiErrors->Fill(0,1.);
154  if(nEventFPIXModuleErrors+nEventFPIXFEDErrors>0) byLumiErrors->Fill(1,1.);
155  //cout<<"histo: "<<byLumiErrors->getBinContent(0)<<" "<<byLumiErrors->getBinContent(1)<<" "<<byLumiErrors->getBinContent(2)<<endl;
156  }
157 
158  // Rate of errors per lumi section:
159  if(errorRate) errorRate->Fill(lumiSection, nErrors);
160 
161  // slow down...
162  if(slowDown) usleep(100000);
163 
164 }
165 
166 //------------------------------------------------------------------
167 // Build data structure
168 //------------------------------------------------------------------
170 
171  LogInfo ("PixelDQM") <<" SiPixelRawDataErrorSource::buildStructure" ;
172 
173 
175  edm::ESHandle<TrackerTopology> tTopoHandle;
176 
177  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
178  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
179 
180  const TrackerTopology *pTT = tTopoHandle.product();
181 
182 
183  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
184  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
185  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
186 
187  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
188 
189  if( GeomDetEnumerators::isTrackerPixel((*it)->subDetector())) {
190 
191  DetId detId = (*it)->geographicalId();
192  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
193  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
194  int nrows = (pixDet->specificTopology()).nrows();
195  int ncols = (pixDet->specificTopology()).ncolumns();
196 
197  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
198  if(isPIB) continue;
199  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
200  uint32_t id = detId();
201  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
202  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
203 
204  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) ) {
205  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
206  uint32_t id = detId();
207  SiPixelRawDataErrorModule* theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
208 
210  int disk = PixelEndcapName(DetId(id), pTT, isUpgrade).diskName();
211  int blade = PixelEndcapName(DetId(id), pTT, isUpgrade).bladeName();
212  int panel = PixelEndcapName(DetId(id), pTT, isUpgrade).pannelName();
214 
215  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
216  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
217  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
218  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
219  char smodule[80];sprintf(smodule,"Module_%i",module);
220  std::string side_str = sside;
221  std::string disk_str = sdisk;
222  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
223  side_str.find("HalfCylinder_2")!=string::npos||
224  side_str.find("HalfCylinder_4")!=string::npos||
225  disk_str.find("Disk_2")!=string::npos;
226  // clutch to take all of FPIX, but no BPIX:
227  mask = false;
228  if(isPIB && mask) continue;
229 
230  thePixelStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
231 
232  }
233  }//MAIN_IF
234  }//FOR_LOOP
235 
236  LogDebug ("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
238 
239  fedIds.first = 0;
240  fedIds.second = 39;
241 
242  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
243 
244  //std::cout<<"Adding FED module: "<<fedId<<std::endl;
245  uint32_t id = static_cast<uint32_t> (fedId);
247  theFEDStructure.insert(pair<uint32_t,SiPixelRawDataErrorModule*> (id,theModule));
248 
249  }
250 
251  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
252 }
253 //------------------------------------------------------------------
254 // Book MEs
255 //------------------------------------------------------------------
257  iBooker.setCurrentFolder(topFolderName_+"/EventInfo/DAQContents");
258  char title0[80]; sprintf(title0, "FED isPresent;FED ID;isPresent");
259  fedcounter = iBooker.book1D("fedcounter",title0,40,-0.5,39.5);
260  iBooker.setCurrentFolder(topFolderName_+"/AdditionalPixelErrors");
261  char title[80]; sprintf(title, "By-LumiSection Error counters");
262  byLumiErrors = iBooker.book1D("byLumiErrors",title,2,0.,2.);
264  char title1[80]; sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
265  errorRate = iBooker.book1D("errorRate",title1,5000,0.,5000.);
266 
267  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter;
268  std::map<uint32_t,SiPixelRawDataErrorModule*>::iterator struct_iter2;
269 
270  SiPixelFolderOrganizer theSiPixelFolder(false);
271 
272  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
274 
275  if(modOn){
276  if(!theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,0,isUpgrade)) {
277  //std::cout<<"PIB! not booking histograms for non-PIB modules!"<<std::endl;
278  if(!isPIB) throw cms::Exception("LogicError")
279  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
280  }
281  }
282 
283  if(ladOn){
284  if(!theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,1,isUpgrade)) {
285  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
286  }
287  }
288 
289  if(bladeOn){
290  if(!theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,4,isUpgrade)) {
291  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
292  }
293  }
294 
295  }//for loop
296 
297  for(struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++){
299  if(!theSiPixelFolder.setFedFolder(iBooker,(*struct_iter2).first)) {
300  throw cms::Exception("LogicError")
301  << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder failed";
302  }
303 
304  }
305 
306  //Booking FED histograms
307  std::string hid;
308  // Get collection name and instantiate Histo Id builder
310  SiPixelHistogramId* theHistogramId = new SiPixelHistogramId( src.label() );
311 
312  for (uint32_t id = 0; id < 40; id++){
313  char temp [50];
314  sprintf( temp, (topFolderName_+"/AdditionalPixelErrors/FED_%d").c_str(),id);
315  iBooker.cd(temp);
316  // Types of errors
317  hid = theHistogramId->setHistoId("errorType",id);
318  meErrorType_[id] = iBooker.book1D(hid,"Type of errors",15,24.5,39.5);
319  meErrorType_[id]->setAxisTitle("Type of errors",1);
320  // Number of errors
321  hid = theHistogramId->setHistoId("NErrors",id);
322  meNErrors_[id] = iBooker.book1D(hid,"Number of errors",36,0.,36.);
323  meNErrors_[id]->setAxisTitle("Number of errors",1);
324  // Type of FIFO full (errorType = 28). FIFO 1 is 1-5 (where fullType = channel of FIFO 1),
325  // fullType = 6 signifies FIFO 2 nearly full, 7 signifies trigger FIFO nearly full, 8
326  // indicates an unexpected result
327  hid = theHistogramId->setHistoId("fullType",id);
328  meFullType_[id] = iBooker.book1D(hid,"Type of FIFO full",7,0.5,7.5);
329  meFullType_[id]->setAxisTitle("FIFO type",1);
330  // For error type 30, the type of problem encoded in the TBM trailer
331  // 0 = stack full, 1 = Pre-cal issued, 2 = clear trigger counter, 3 = sync trigger,
332  // 4 = sync trigger error, 5 = reset ROC, 6 = reset TBM, 7 = no token bit pass
333  hid = theHistogramId->setHistoId("TBMMessage",id);
334  meTBMMessage_[id] = iBooker.book1D(hid,"TBM trailer message",8,-0.5,7.5);
335  meTBMMessage_[id]->setAxisTitle("TBM message",1);
336  // For error type 30, the type of problem encoded in the TBM error trailer 0 = none
337  // 1 = data stream too long, 2 = FSM errors, 3 = invalid # of ROCs, 4 = multiple
338  hid = theHistogramId->setHistoId("TBMType",id);
339  meTBMType_[id] = iBooker.book1D(hid,"Type of TBM trailer",5,-0.5,4.5);
340  meTBMType_[id]->setAxisTitle("TBM Type",1);
341  // For error type 31, the event number of the TBM header with the error
342  hid = theHistogramId->setHistoId("EvtNbr",id);
343  meEvtNbr_[id] = iBooker.book1D(hid,"Event number",1,0,1);
344  // For errorType = 34, datastream size according to error word
345  hid = theHistogramId->setHistoId("evtSize",id);
346  meEvtSize_[id] = iBooker.book1D(hid,"Event size",1,0,1);
347  //
348  hid = theHistogramId->setHistoId("FedChNErr",id);
349  meFedChNErr_[id] = iBooker.book1D(hid,"Number of errors per FED channel",37,0,37);
350  meFedChNErr_[id]->setAxisTitle("FED channel",1);
351  //
352  hid = theHistogramId->setHistoId("FedChLErr",id);
353  meFedChLErr_[id] = iBooker.book1D(hid,"Last error per FED channel",37,0,37);
354  meFedChLErr_[id]->setAxisTitle("FED channel",1);
355  //
356  hid = theHistogramId->setHistoId("FedETypeNErr", id);
357  meFedETypeNErr_[id] = iBooker.book1D(hid,"Number of errors per type",21,0,21);
358  meFedETypeNErr_[id]->setAxisTitle("Error type",1);
359  }
360  //Add the booked histograms to the histogram map for booking
361  meMapFEDs_["meErrorType_"] = meErrorType_;
362  meMapFEDs_["meNErrors_"] = meNErrors_;
363  meMapFEDs_["meFullType_"] = meFullType_;
364  meMapFEDs_["meTBMMessage_"] = meTBMMessage_;
365  meMapFEDs_["meTBMType_"] = meTBMType_;
366  meMapFEDs_["meEvtNbr_"] = meEvtNbr_;
367  meMapFEDs_["meEvtSize_"] = meEvtSize_;
368  meMapFEDs_["meFedChNErr_"] = meFedChNErr_;
369  meMapFEDs_["meFedChLErr_"] = meFedChLErr_;
370  meMapFEDs_["meFedETypeNErr_"] = meFedETypeNErr_;
371 
372  //cout<<"...leaving SiPixelRawDataErrorSource::bookMEs now! "<<endl;
373 }
374 
#define LogDebug(id)
int plaquetteName() const
plaquetteId (in pannel)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void bookMEs(DQMStore::IBooker &)
std::map< uint32_t, SiPixelRawDataErrorModule * > theFEDStructure
edm::EDGetTokenT< edm::DetSetVector< SiPixelRawDataError > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void cd(void)
Definition: DQMStore.cc:266
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * meFedETypeNErr_[40]
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static std::string const input
Definition: EdmProvDump.cc:43
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int bladeName() const
blade id
bool setFedFolder(const uint32_t FedId)
Set folder name for a FED (used in the case of errors without detId)
int iEvent
Definition: GenABIO.cc:230
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
std::map< uint32_t, SiPixelRawDataErrorModule * > thePixelStructure
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
bool isValid() const
Definition: HandleBase.h:75
SiPixelRawDataErrorSource(const edm::ParameterSet &conf)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
edm::EDGetTokenT< FEDRawDataCollection > inputSourceToken_
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
Definition: ESHandle.h:86
bool isTrackerPixel(const GeomDetEnumerators::SubDetector m)
std::string const & label() const
Definition: InputTag.h:42
std::map< std::string, MonitorElement ** > meMapFEDs_
virtual void buildStructure(edm::EventSetup const &)
int pannelName() const
pannel id
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int diskName() const
disk id
volatile std::atomic< bool > shutdown_flag false
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
HalfCylinder halfCylinder() const
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: vlib.h:208
Pixel error – collection of errors and error information.
Definition: Run.h:41
virtual void dqmBeginRun(const edm::Run &, edm::EventSetup const &)