Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "SiPixelRawToDigi.h"
00007
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/Framework/interface/ESTransientHandle.h"
00011
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013
00014 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00015
00016 #include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h"
00017
00018 #include "DataFormats/Common/interface/DetSetVector.h"
00019 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00020 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00021
00022 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00023 #include "DataFormats/DetId/interface/DetIdCollection.h"
00024 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
00025 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
00026 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
00027
00028 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
00029
00030 #include "EventFilter/SiPixelRawToDigi/interface/R2DTimerObserver.h"
00031
00032 #include "TH1D.h"
00033 #include "TFile.h"
00034
00035 using namespace std;
00036
00037
00038 SiPixelRawToDigi::SiPixelRawToDigi( const edm::ParameterSet& conf )
00039 : config_(conf),
00040 cabling_(0),
00041 badPixelInfo_(0),
00042 hCPU(0), hDigi(0), theTimer(0)
00043 {
00044
00045 includeErrors = config_.getParameter<bool>("IncludeErrors");
00046 useQuality = config_.getParameter<bool>("UseQualityInfo");
00047 useCablingTree_ = config_.getUntrackedParameter<bool>("UseCablingTree",true);
00048 if (config_.exists("ErrorList")) {
00049 errorList = config_.getParameter<std::vector<int> > ("ErrorList");
00050 }
00051
00052
00053 ndigis = 0;
00054 nwords = 0;
00055
00056
00057 produces< edm::DetSetVector<PixelDigi> >();
00058 if(includeErrors){
00059 produces< edm::DetSetVector<SiPixelRawDataError> >();
00060 produces<DetIdCollection>();
00061 }
00062
00063
00064 bool timing = config_.getUntrackedParameter<bool>("Timing",false);
00065 if (timing) {
00066 theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
00067 hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
00068 hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
00069 }
00070 }
00071
00072
00073
00074 SiPixelRawToDigi::~SiPixelRawToDigi() {
00075 edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
00076
00077 if(useCablingTree_) delete cabling_;
00078
00079 if (theTimer) {
00080 TFile rootFile("analysis.root", "RECREATE", "my histograms");
00081 hCPU->Write();
00082 hDigi->Write();
00083 delete theTimer;
00084 }
00085
00086 }
00087
00088
00089
00090
00091
00092
00093 void SiPixelRawToDigi::produce( edm::Event& ev,
00094 const edm::EventSetup& es)
00095 {
00096 const uint32_t dummydetid = 0xffffffff;
00097 debug = edm::MessageDrop::instance()->debugEnabled;
00098
00099
00100 if (recordWatcher.check( es )) {
00101
00102 if (useCablingTree_) {
00103 delete cabling_;
00104
00105 edm::ESTransientHandle<SiPixelFedCablingMap> cablingMap;
00106 es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
00107 fedIds = cablingMap->fedIds();
00108 cabling_ = cablingMap->cablingTree();
00109 } else {
00110
00111 edm::ESHandle<SiPixelFedCablingMap> cablingMap;
00112 es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
00113 fedIds = cablingMap->fedIds();
00114 cabling_ = cablingMap.product();
00115 }
00116 LogDebug("map version:")<< cabling_->version();
00117 }
00118
00119 if (qualityWatcher.check( es )&&useQuality) {
00120
00121 edm::ESHandle<SiPixelQuality> qualityInfo;
00122 es.get<SiPixelQualityRcd>().get( qualityInfo );
00123 badPixelInfo_ = qualityInfo.product();
00124 if (!badPixelInfo_) {
00125 edm::LogError("**SiPixelRawToDigi**")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
00126 }
00127 }
00128
00129 edm::Handle<FEDRawDataCollection> buffers;
00130 label = config_.getParameter<edm::InputTag>("InputLabel");
00131 ev.getByLabel( label, buffers);
00132
00133
00134 std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
00135 std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
00136 std::auto_ptr< DetIdCollection > error_detidcollection(new DetIdCollection());
00137
00138 PixelDataFormatter formatter(cabling_);
00139 formatter.setErrorStatus(includeErrors);
00140 if (useQuality) formatter.setQualityStatus(useQuality, badPixelInfo_);
00141
00142 if (theTimer) theTimer->start();
00143 bool errorsInEvent = false;
00144 PixelDataFormatter::DetErrors nodeterrors;
00145
00146 typedef std::vector<unsigned int>::const_iterator IF;
00147 for (IF aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
00148 int fedId = *aFed;
00149 if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
00150 PixelDataFormatter::Digis digis;
00151 PixelDataFormatter::Errors errors;
00152
00153
00154 const FEDRawData& fedRawData = buffers->FEDData( fedId );
00155
00156
00157 formatter.interpretRawData( errorsInEvent, fedId, fedRawData, digis, errors);
00158
00159
00160 typedef PixelDataFormatter::Digis::iterator ID;
00161 for (ID it = digis.begin(); it != digis.end(); it++) {
00162 uint32_t detid = it->first;
00163 edm::DetSet<PixelDigi>& detSet = collection->find_or_insert(detid);
00164 detSet.data = it->second;
00165 }
00166
00167
00168 if(includeErrors) {
00169 typedef PixelDataFormatter::Errors::iterator IE;
00170 for (IE is = errors.begin(); is != errors.end(); is++) {
00171 uint32_t errordetid = is->first;
00172 if (errordetid==dummydetid) {
00173 nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
00174 } else {
00175 edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
00176 errorDetSet.data = is->second;
00177
00178
00179
00180
00181 if(!errorList.empty()){
00182 DetId errorDetId(errordetid);
00183 edm::DetSet<SiPixelRawDataError>::const_iterator itPixelError=errorDetSet.begin();
00184 for(; itPixelError!=errorDetSet.end(); ++itPixelError){
00185 std::vector<int>::iterator it_find = find(errorList.begin(), errorList.end(), itPixelError->getType());
00186 if(it_find != errorList.end()){
00187 error_detidcollection->push_back(errordetid);
00188 }
00189 }
00190 }
00191 }
00192 }
00193 }
00194 }
00195
00196 if(includeErrors) {
00197 edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
00198 errorDetSet.data = nodeterrors;
00199 }
00200 if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
00201
00202 if (theTimer) {
00203 theTimer->stop();
00204 LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
00205 ndigis += formatter.nDigis();
00206 nwords += formatter.nWords();
00207 LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
00208 <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
00209 hCPU->Fill( theTimer->lastMeasurement().real() );
00210 hDigi->Fill(formatter.nDigis());
00211 }
00212
00213
00214 ev.put( collection );
00215 if(includeErrors){
00216 ev.put( errorcollection );
00217 ev.put( error_detidcollection );
00218 }
00219 }