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