Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026
00027 #include "FWCore/Framework/interface/EDFilter.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032
00033 #include <string>
00034 #include <iostream>
00035
00036 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00037 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00038 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00039 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00040 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00041
00042
00043
00044
00045
00046 class HcalCalibTypeFilter : public edm::EDFilter {
00047 public:
00048 explicit HcalCalibTypeFilter(const edm::ParameterSet&);
00049 virtual ~HcalCalibTypeFilter();
00050
00051 private:
00052 virtual void beginJob() ;
00053 virtual bool filter(edm::Event&, const edm::EventSetup&);
00054 virtual void endJob() ;
00055
00056
00057
00058 std::string DataLabel_ ;
00059 bool Summary_ ;
00060 std::vector<int> CalibTypes_ ;
00061 std::vector<int> eventsByType ;
00062
00063 };
00064
00065
00066
00067
00068
00069 HcalCalibTypeFilter::HcalCalibTypeFilter(const edm::ParameterSet& iConfig)
00070 {
00071
00072
00073 DataLabel_ = iConfig.getParameter<std::string>("InputLabel") ;
00074 Summary_ = iConfig.getUntrackedParameter<bool>("FilterSummary",false) ;
00075 CalibTypes_ = iConfig.getParameter< std::vector<int> >("CalibTypes") ;
00076 }
00077
00078
00079 HcalCalibTypeFilter::~HcalCalibTypeFilter()
00080 {
00081
00082
00083
00084
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 bool
00094 HcalCalibTypeFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00095 {
00096 using namespace edm;
00097
00098 edm::Handle<FEDRawDataCollection> rawdata;
00099 iEvent.getByLabel(DataLabel_,rawdata);
00100
00101
00102 int calibType = -1 ; int numEmptyFEDs = 0 ;
00103 std::vector<int> calibTypeCounter(8,0) ;
00104 for (int i=FEDNumbering::MINHCALFEDID;
00105 i<=FEDNumbering::MAXHCALFEDID; i++) {
00106 const FEDRawData& fedData = rawdata->FEDData(i) ;
00107 if ( fedData.size() < 24 ) numEmptyFEDs++ ;
00108 if ( fedData.size() < 24 ) continue ;
00109 int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
00110 calibTypeCounter.at(value)++ ;
00111 }
00112
00113 int maxCount = 0 ;
00114 int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
00115 for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
00116 if ( calibTypeCounter.at(i) > maxCount ) { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
00117 if ( maxCount == numberOfFEDIds ) break ;
00118 }
00119 if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
00120 edm::LogWarning("HcalCalibTypeFilter") << "Conflicting calibration types found. Assigning type "
00121 << calibType ;
00122 LogDebug("HcalCalibTypeFilter") << "Calibration type is: " << calibType ;
00123 eventsByType.at(calibType)++ ;
00124 for (unsigned int i=0; i<CalibTypes_.size(); i++)
00125 if ( calibType == CalibTypes_.at(i) ) return true ;
00126 return false ;
00127 }
00128
00129
00130 void
00131 HcalCalibTypeFilter::beginJob()
00132 {
00133 eventsByType.clear() ;
00134 eventsByType.resize(8,0) ;
00135 }
00136
00137
00138 void
00139 HcalCalibTypeFilter::endJob() {
00140 if ( Summary_ )
00141 edm::LogWarning("HcalCalibTypeFilter") << "Summary of filter decisions: "
00142 << eventsByType.at(hc_Null) << "(No Calib), "
00143 << eventsByType.at(hc_Pedestal) << "(Pedestal), "
00144 << eventsByType.at(hc_RADDAM) << "(RADDAM), "
00145 << eventsByType.at(hc_HBHEHPD) << "(HBHE/HPD), "
00146 << eventsByType.at(hc_HOHPD) << "(HO/HPD), "
00147 << eventsByType.at(hc_HFPMT) << "(HF/PMT)" ;
00148 }
00149
00150
00151 DEFINE_FWK_MODULE(HcalCalibTypeFilter);