CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00076   if(firstRun){
00077     eventNo = 0;
00078     // Build map
00079     // Book Monitoring Elements
00080     bookMEs();
00081     firstRun = false;
00082   }
00083 }
00084 
00085 
00086 void SiPixelHLTSource::endJob(void){
00087 
00088   if(saveFile) {
00089     LogInfo ("PixelDQM") << " SiPixelHLTSource::endJob - Saving Root File " << std::endl;
00090     std::string outputFile = conf_.getParameter<std::string>("outputFile");
00091     theDMBE->save( outputFile.c_str() );
00092   }
00093 
00094 }
00095 
00096 //------------------------------------------------------------------
00097 // Method called for every event
00098 //------------------------------------------------------------------
00099 void SiPixelHLTSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00100 {
00101   eventNo++;
00102   // get raw input data
00103   edm::Handle< FEDRawDataCollection >  rawinput;
00104   iEvent.getByLabel( rawin_, rawinput );
00105   // get error input data
00106   edm::Handle< edm::DetSetVector<SiPixelRawDataError> >  errorinput;
00107   iEvent.getByLabel( errin_, errorinput );
00108   if (!errorinput.isValid()) return;
00109 
00110   int fedId;
00111   
00112   for(fedId = 0; fedId <= 39; fedId++) {
00113     //get event data for this fed
00114     const FEDRawData& fedRawData = rawinput->FEDData( fedId );
00115     if (fedRawData.size() != 0) (meRawWords_)->Fill(fedId);
00116   } // end for
00117 
00118   edm::DetSet<SiPixelRawDataError>::const_iterator  di;
00119 
00120   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00121     if( ((*it)->subDetector()==GeomDetEnumerators::PixelBarrel) || ((*it)->subDetector()==GeomDetEnumerators::PixelEndcap) ){
00122       uint32_t detId = (*it)->geographicalId();
00123       edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = errorinput->find(detId);
00124       if( isearch != errorinput->end() ) {
00125         for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00126           fedId = di->getFedId();                  // FED the error came from
00127           int errorType = di->getType();           // type of error
00128           switch(errorType) {
00129             case(35) : (meNErrors_)->Fill(fedId); break;
00130             case(36) : (meNErrors_)->Fill(fedId); break;
00131             case(37) : (meNErrors_)->Fill(fedId); break;
00132             case(38) : (meNErrors_)->Fill(fedId); break;
00133             default : break;
00134           }; // end switch
00135         } // end for(di
00136       } // end if( isearch
00137     } // end if( ((*it)->subDetector()
00138   } // for(TrackerGeometry
00139 
00140   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = errorinput->find(0xffffffff);
00141 
00142   if( isearch != errorinput->end() ) {  // Not at empty iterator
00143     for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00144       fedId = di->getFedId();                  // FED the error came from
00145       int errorType = di->getType();           // type of error
00146       switch(errorType) {
00147         case(35) : (meNErrors_)->Fill(fedId); break;
00148         case(36) : (meNErrors_)->Fill(fedId); break;
00149         case(37) : (meNErrors_)->Fill(fedId); break;
00150         case(38) : (meNErrors_)->Fill(fedId); break;
00151         case(39) : (meNCRCs_)->Fill(fedId); break;
00152         default : break;
00153       }; // end switch
00154     } // end for(di
00155   } // end if( isearch
00156   // slow down...
00157   if(slowDown) usleep(100000);
00158 
00159 }
00160 
00161 //------------------------------------------------------------------
00162 // Book MEs
00163 //------------------------------------------------------------------
00164 void SiPixelHLTSource::bookMEs(){
00165 
00166   theDMBE->cd();
00167   theDMBE->setCurrentFolder(dirName_);
00168 
00169   std::string rawhid;
00170   std::string errhid;
00171   // Get collection name and instantiate Histo Id builder
00172   edm::InputTag rawin = conf_.getParameter<edm::InputTag>( "RawInput" );
00173   SiPixelHistogramId* RawHistogramId = new SiPixelHistogramId( rawin.label() );
00174   edm::InputTag errin = conf_.getParameter<edm::InputTag>( "ErrorInput" );
00175   SiPixelHistogramId* ErrorHistogramId = new SiPixelHistogramId( errin.label() );
00176   // Get DQM interface
00177   DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00178 
00179   // Is a FED sending raw data
00180   meRawWords_ = theDMBE->book1D("FEDEntries","Number of raw words",40,-0.5,39.5);
00181   meRawWords_->setAxisTitle("Number of raw words",1);
00182 
00183   // Number of CRC errors
00184   meNCRCs_ = theDMBE->book1D("FEDFatal","Number of fatal errors",40,-0.5,39.5);
00185   meNCRCs_->setAxisTitle("Number of fatal errors",1);
00186 
00187   // Number of translation error words
00188   meNErrors_ = theDMBE->book1D("FEDNonFatal","Number of non-fatal errors",40,-0.5,39.5);
00189   meNErrors_->setAxisTitle("Number of non-fatal errors",1);
00190 
00191   delete RawHistogramId;
00192   delete ErrorHistogramId;
00193 
00194 }