CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/SiPixelMonitorRawData/plugins/SiPixelHLTSource.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelMonitorRawData
00004 // Class:      SiPixelHLTSource
00005 // 
00017 //
00018 // Original Author:  Andrew York
00019 //
00020 // Framework
00021 #include "FWCore/ServiceRegistry/interface/Service.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 // DQM Framework
00024 #include "DQM/SiPixelMonitorRawData/interface/SiPixelHLTSource.h"
00025 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00026 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 // Geometry
00029 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00030 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00031 #include "Geometry/CommonDetUnit/interface/GeomDetEnumerators.h"
00032 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00033 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00034 // DataFormats
00035 #include "DataFormats/DetId/interface/DetId.h"
00036 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00037 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00038 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00039 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00040 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00041 //
00042 #include <string>
00043 #include <stdlib.h>
00044 
00045 using namespace std;
00046 using namespace edm;
00047 
00048 SiPixelHLTSource::SiPixelHLTSource(const edm::ParameterSet& iConfig) :
00049   conf_(iConfig),
00050   rawin_( conf_.getParameter<edm::InputTag>( "RawInput" ) ),
00051   errin_( conf_.getParameter<edm::InputTag>( "ErrorInput" ) ),
00052   saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
00053   slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
00054   dirName_( conf_.getUntrackedParameter<std::string>("DirName","Pixel/FEDIntegrity/") )
00055 {
00056    theDMBE = edm::Service<DQMStore>().operator->();
00057    LogInfo ("PixelDQM") << "SiPixelHLTSource::SiPixelHLTSource: Got DQM BackEnd interface"<<endl;
00058 }
00059 
00060 
00061 SiPixelHLTSource::~SiPixelHLTSource()
00062 {
00063    // do anything here that needs to be done at desctruction time
00064    // (e.g. close files, deallocate resources etc.)
00065   LogInfo ("PixelDQM") << "SiPixelHLTSource::~SiPixelHLTSource: Destructor"<<endl;
00066 }
00067 
00068 
00069 void SiPixelHLTSource::beginJob(){
00070   firstRun = true;
00071 }
00072 
00073 void SiPixelHLTSource::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00074   LogInfo ("PixelDQM") << " SiPixelHLTSource::beginJob - Initialisation ... " << std::endl;
00075   
00076   if(firstRun){
00077     eventNo = 0;
00078     // Build map
00079     iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00080     // Book Monitoring Elements
00081     bookMEs();
00082     firstRun = false;
00083   }
00084 }
00085 
00086 
00087 void SiPixelHLTSource::endJob(void){
00088 
00089   if(saveFile) {
00090     LogInfo ("PixelDQM") << " SiPixelHLTSource::endJob - Saving Root File " << std::endl;
00091     std::string outputFile = conf_.getParameter<std::string>("outputFile");
00092     theDMBE->save( outputFile.c_str() );
00093   }
00094 
00095 }
00096 
00097 //------------------------------------------------------------------
00098 // Method called for every event
00099 //------------------------------------------------------------------
00100 void SiPixelHLTSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00101 {
00102   eventNo++;
00103   // get raw input data
00104   edm::Handle< FEDRawDataCollection >  rawinput;
00105   iEvent.getByLabel( rawin_, rawinput );
00106   // get error input data
00107   edm::Handle< edm::DetSetVector<SiPixelRawDataError> >  errorinput;
00108   iEvent.getByLabel( errin_, errorinput );
00109   if (!errorinput.isValid()) return;
00110 
00111   int fedId;
00112   
00113   for(fedId = 0; fedId <= 39; fedId++) {
00114     //get event data for this fed
00115     const FEDRawData& fedRawData = rawinput->FEDData( fedId );
00116     if (fedRawData.size() != 0) (meRawWords_)->Fill(fedId);
00117   } // end for
00118 
00119   edm::DetSet<SiPixelRawDataError>::const_iterator  di;
00120 
00121   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00122     if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
00123       uint32_t detId = (*it)->geographicalId();
00124       edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = errorinput->find(detId);
00125       if( isearch != errorinput->end() ) {
00126         for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00127           fedId = di->getFedId();                  // FED the error came from
00128           int errorType = di->getType();           // type of error
00129           switch(errorType) {
00130             case(35) : (meNErrors_)->Fill(fedId); break;
00131             case(36) : (meNErrors_)->Fill(fedId); break;
00132             case(37) : (meNErrors_)->Fill(fedId); break;
00133             case(38) : (meNErrors_)->Fill(fedId); break;
00134             default : break;
00135           }; // end switch
00136         } // end for(di
00137       } // end if( isearch
00138     } // end if( ((*it)->subDetector()
00139   } // for(TrackerGeometry
00140 
00141   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = errorinput->find(0xffffffff);
00142 
00143   if( isearch != errorinput->end() ) {  // Not at empty iterator
00144     for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00145       fedId = di->getFedId();                  // FED the error came from
00146       int errorType = di->getType();           // type of error
00147       switch(errorType) {
00148         case(35) : (meNErrors_)->Fill(fedId); break;
00149         case(36) : (meNErrors_)->Fill(fedId); break;
00150         case(37) : (meNErrors_)->Fill(fedId); break;
00151         case(38) : (meNErrors_)->Fill(fedId); break;
00152         case(39) : (meNCRCs_)->Fill(fedId); break;
00153         default : break;
00154       }; // end switch
00155     } // end for(di
00156   } // end if( isearch
00157   // slow down...
00158   if(slowDown) usleep(100000);
00159 
00160 }
00161 
00162 //------------------------------------------------------------------
00163 // Book MEs
00164 //------------------------------------------------------------------
00165 void SiPixelHLTSource::bookMEs(){
00166 
00167   theDMBE->cd();
00168   theDMBE->setCurrentFolder(dirName_);
00169 
00170   std::string rawhid;
00171   std::string errhid;
00172   // Get collection name and instantiate Histo Id builder
00173   edm::InputTag rawin = conf_.getParameter<edm::InputTag>( "RawInput" );
00174   SiPixelHistogramId* RawHistogramId = new SiPixelHistogramId( rawin.label() );
00175   edm::InputTag errin = conf_.getParameter<edm::InputTag>( "ErrorInput" );
00176   SiPixelHistogramId* ErrorHistogramId = new SiPixelHistogramId( errin.label() );
00177   // Get DQM interface
00178   DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00179 
00180   // Is a FED sending raw data
00181   meRawWords_ = theDMBE->book1D("FEDEntries","Number of raw words",40,-0.5,39.5);
00182   meRawWords_->setAxisTitle("Number of raw words",1);
00183 
00184   // Number of CRC errors
00185   meNCRCs_ = theDMBE->book1D("FEDFatal","Number of fatal errors",40,-0.5,39.5);
00186   meNCRCs_->setAxisTitle("Number of fatal errors",1);
00187 
00188   // Number of translation error words
00189   meNErrors_ = theDMBE->book1D("FEDNonFatal","Number of non-fatal errors",40,-0.5,39.5);
00190   meNErrors_->setAxisTitle("Number of non-fatal errors",1);
00191 
00192   delete RawHistogramId;
00193   delete ErrorHistogramId;
00194 
00195 }