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 #include "EventFilter/SiPixelRawToDigi/interface/PixelUnpackingRegions.h"
00032
00033 #include "TH1D.h"
00034 #include "TFile.h"
00035
00036 using namespace std;
00037
00038
00039 SiPixelRawToDigi::SiPixelRawToDigi( const edm::ParameterSet& conf )
00040 : config_(conf),
00041 cabling_(0),
00042 badPixelInfo_(0),
00043 regions_(0),
00044 hCPU(0), hDigi(0), theTimer(0)
00045 {
00046
00047 includeErrors = config_.getParameter<bool>("IncludeErrors");
00048 useQuality = config_.getParameter<bool>("UseQualityInfo");
00049 useCablingTree_ = config_.getUntrackedParameter<bool>("UseCablingTree",true);
00050 if (config_.exists("ErrorList")) {
00051 tkerrorlist = config_.getParameter<std::vector<int> > ("ErrorList");
00052 }
00053 if (config_.exists("UserErrorList")) {
00054 usererrorlist = config_.getParameter<std::vector<int> > ("UserErrorList");
00055 }
00056
00057
00058 ndigis = 0;
00059 nwords = 0;
00060
00061
00062 produces< edm::DetSetVector<PixelDigi> >();
00063 if(includeErrors){
00064 produces< edm::DetSetVector<SiPixelRawDataError> >();
00065 produces<DetIdCollection>();
00066 produces<DetIdCollection>("UserErrorModules");
00067 }
00068
00069
00070 if (config_.exists("Regions")) {
00071 if(config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().size() > 0)
00072 {
00073 regions_ = new PixelUnpackingRegions(config_);
00074 }
00075 }
00076
00077
00078 bool timing = config_.getUntrackedParameter<bool>("Timing",false);
00079 if (timing) {
00080 theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
00081 hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
00082 hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
00083 }
00084 }
00085
00086
00087
00088 SiPixelRawToDigi::~SiPixelRawToDigi() {
00089 edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
00090
00091 if (useCablingTree_) delete cabling_;
00092 if (regions_) delete regions_;
00093
00094 if (theTimer) {
00095 TFile rootFile("analysis.root", "RECREATE", "my histograms");
00096 hCPU->Write();
00097 hDigi->Write();
00098 delete theTimer;
00099 }
00100
00101 }
00102
00103
00104
00105
00106
00107
00108 void SiPixelRawToDigi::produce( edm::Event& ev,
00109 const edm::EventSetup& es)
00110 {
00111 const uint32_t dummydetid = 0xffffffff;
00112 debug = edm::MessageDrop::instance()->debugEnabled;
00113
00114
00115 if (recordWatcher.check( es )) {
00116
00117 if (useCablingTree_) {
00118 delete cabling_;
00119
00120 edm::ESTransientHandle<SiPixelFedCablingMap> cablingMap;
00121 es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
00122 fedIds = cablingMap->fedIds();
00123 cabling_ = cablingMap->cablingTree();
00124 } else {
00125
00126 edm::ESHandle<SiPixelFedCablingMap> cablingMap;
00127 es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
00128 fedIds = cablingMap->fedIds();
00129 cabling_ = cablingMap.product();
00130 }
00131 LogDebug("map version:")<< cabling_->version();
00132 }
00133
00134 if (qualityWatcher.check( es )&&useQuality) {
00135
00136 edm::ESHandle<SiPixelQuality> qualityInfo;
00137 es.get<SiPixelQualityRcd>().get( qualityInfo );
00138 badPixelInfo_ = qualityInfo.product();
00139 if (!badPixelInfo_) {
00140 edm::LogError("**SiPixelRawToDigi**")<<" Configured to use SiPixelQuality, but SiPixelQuality not present"<<endl;
00141 }
00142 }
00143
00144 edm::Handle<FEDRawDataCollection> buffers;
00145 label = config_.getParameter<edm::InputTag>("InputLabel");
00146 ev.getByLabel( label, buffers);
00147
00148
00149 std::auto_ptr< edm::DetSetVector<PixelDigi> > collection( new edm::DetSetVector<PixelDigi> );
00150 std::auto_ptr< edm::DetSetVector<SiPixelRawDataError> > errorcollection( new edm::DetSetVector<SiPixelRawDataError> );
00151 std::auto_ptr< DetIdCollection > tkerror_detidcollection(new DetIdCollection());
00152 std::auto_ptr< DetIdCollection > usererror_detidcollection(new DetIdCollection());
00153
00154 PixelDataFormatter formatter(cabling_);
00155 formatter.setErrorStatus(includeErrors);
00156
00157 if (useQuality) formatter.setQualityStatus(useQuality, badPixelInfo_);
00158
00159 if (theTimer) theTimer->start();
00160 bool errorsInEvent = false;
00161 PixelDataFormatter::DetErrors nodeterrors;
00162
00163 if (regions_) {
00164 regions_->run(ev, es);
00165 formatter.setModulesToUnpack(regions_->modulesToUnpack());
00166 LogDebug("SiPixelRawToDigi") << "region2unpack #feds (BPIX,EPIX,total): "<<regions_->nBarrelFEDs()<<" "<<regions_->nForwardFEDs()<<" "<<regions_->nFEDs();
00167 LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): "<<regions_->nBarrelModules()<<" "<<regions_->nForwardModules()<<" "<<regions_->nModules();
00168 }
00169
00170 typedef std::vector<unsigned int>::const_iterator IF;
00171 for (IF aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) {
00172 int fedId = *aFed;
00173
00174 if (regions_ && !regions_->mayUnpackFED(fedId)) continue;
00175
00176 if(debug) LogDebug("SiPixelRawToDigi")<< " PRODUCE DIGI FOR FED: " << fedId << endl;
00177 PixelDataFormatter::Digis digis;
00178 PixelDataFormatter::Errors errors;
00179
00180
00181 const FEDRawData& fedRawData = buffers->FEDData( fedId );
00182
00183
00184 formatter.interpretRawData( errorsInEvent, fedId, fedRawData, digis, errors);
00185
00186
00187 typedef PixelDataFormatter::Digis::iterator ID;
00188 for (ID it = digis.begin(); it != digis.end(); it++) {
00189 uint32_t detid = it->first;
00190 edm::DetSet<PixelDigi>& detSet = collection->find_or_insert(detid);
00191 detSet.data.insert(detSet.data.end(), it->second.begin(), it->second.end());
00192 }
00193
00194
00195 if(includeErrors) {
00196 typedef PixelDataFormatter::Errors::iterator IE;
00197 for (IE is = errors.begin(); is != errors.end(); is++) {
00198 uint32_t errordetid = is->first;
00199 if (errordetid==dummydetid) {
00200 nodeterrors.insert( nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end() );
00201 } else {
00202 edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
00203 errorDetSet.data.insert(errorDetSet.data.end(), is->second.begin(), is->second.end());
00204
00205
00206
00207
00208 if(!tkerrorlist.empty() || !usererrorlist.empty()){
00209 DetId errorDetId(errordetid);
00210 edm::DetSet<SiPixelRawDataError>::const_iterator itPixelError=errorDetSet.begin();
00211 for(; itPixelError!=errorDetSet.end(); ++itPixelError){
00212
00213 if(!tkerrorlist.empty()) {
00214 std::vector<int>::iterator it_find = find(tkerrorlist.begin(), tkerrorlist.end(), itPixelError->getType());
00215 if(it_find != tkerrorlist.end()){
00216 tkerror_detidcollection->push_back(errordetid);
00217 }
00218 }
00219
00220 if(!usererrorlist.empty()) {
00221 std::vector<int>::iterator it_find = find(usererrorlist.begin(), usererrorlist.end(), itPixelError->getType());
00222 if(it_find != usererrorlist.end()){
00223 usererror_detidcollection->push_back(errordetid);
00224 }
00225 }
00226 }
00227 }
00228 }
00229 }
00230 }
00231 }
00232
00233 if(includeErrors) {
00234 edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection->find_or_insert(dummydetid);
00235 errorDetSet.data = nodeterrors;
00236 }
00237 if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
00238
00239 if (theTimer) {
00240 theTimer->stop();
00241 LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
00242 ndigis += formatter.nDigis();
00243 nwords += formatter.nWords();
00244 LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: "
00245 <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<nwords<<"/"<<ndigis;
00246 hCPU->Fill( theTimer->lastMeasurement().real() );
00247 hDigi->Fill(formatter.nDigis());
00248 }
00249
00250
00251 ev.put( collection );
00252 if(includeErrors){
00253 ev.put( errorcollection );
00254 ev.put( tkerror_detidcollection );
00255 ev.put( usererror_detidcollection, "UserErrorModules" );
00256 }
00257 }