00001 #include "SiPixelDigiToRaw.h" 00002 00003 #include "DataFormats/Common/interface/Handle.h" 00004 #include "FWCore/Framework/interface/ESHandle.h" 00005 00006 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00007 00008 #include "DataFormats/Common/interface/DetSetVector.h" 00009 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h" 00010 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" 00011 #include "DataFormats/FEDRawData/interface/FEDRawData.h" 00012 00013 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" 00014 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h" 00015 00016 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h" 00017 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h" 00018 using namespace std; 00019 00020 SiPixelDigiToRaw::SiPixelDigiToRaw( const edm::ParameterSet& pset ) : 00021 cablingTree_(0), 00022 config_(pset) 00023 { 00024 00025 // Define EDProduct type 00026 produces<FEDRawDataCollection>(); 00027 00028 // start the counters 00029 eventCounter = 0; 00030 allDigiCounter = 0; 00031 allWordCounter = 0; 00032 00033 } 00034 00035 // ----------------------------------------------------------------------------- 00036 SiPixelDigiToRaw::~SiPixelDigiToRaw() { 00037 delete cablingTree_; 00038 } 00039 00040 // ----------------------------------------------------------------------------- 00041 00042 // ----------------------------------------------------------------------------- 00043 void SiPixelDigiToRaw::produce( edm::Event& ev, 00044 const edm::EventSetup& es) 00045 { 00046 using namespace sipixelobjects; 00047 eventCounter++; 00048 edm::LogInfo("SiPixelDigiToRaw") << "[SiPixelDigiToRaw::produce] " 00049 << "event number: " << eventCounter; 00050 00051 edm::Handle< edm::DetSetVector<PixelDigi> > digiCollection; 00052 label = config_.getParameter<edm::InputTag>("InputLabel"); 00053 ev.getByLabel( label, digiCollection); 00054 00055 PixelDataFormatter::Digis digis; 00056 typedef vector< edm::DetSet<PixelDigi> >::const_iterator DI; 00057 00058 int digiCounter = 0; 00059 for (DI di=digiCollection->begin(); di != digiCollection->end(); di++) { 00060 digiCounter += (di->data).size(); 00061 digis[ di->id] = di->data; 00062 } 00063 allDigiCounter += digiCounter; 00064 00065 if (recordWatcher.check( es )) { 00066 edm::ESHandle<SiPixelFedCablingMap> cablingMap; 00067 es.get<SiPixelFedCablingMapRcd>().get( cablingMap ); 00068 if (cablingTree_) delete cablingTree_; cablingTree_= cablingMap->cablingTree(); 00069 } 00070 00071 debug = edm::MessageDrop::instance()->debugEnabled; 00072 if (debug) LogDebug("SiPixelDigiToRaw") << cablingTree_->version(); 00073 00074 PixelDataFormatter formatter(cablingTree_); 00075 00076 // create product (raw data) 00077 std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection ); 00078 00079 const vector<const PixelFEDCabling *> fedList = cablingTree_->fedList(); 00080 00081 typedef vector<const PixelFEDCabling *>::const_iterator FI; 00082 for (FI it = fedList.begin(); it != fedList.end(); it++) { 00083 LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id(); 00084 FEDRawData * rawData = formatter.formatData( ev.id().event(),(**it).id(), digis); 00085 FEDRawData& fedRawData = buffers->FEDData( (**it).id() ); 00086 fedRawData = *rawData; 00087 LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size(); 00088 delete rawData; 00089 } 00090 allWordCounter += formatter.nWords(); 00091 if (debug) LogDebug("SiPixelDigiToRaw") 00092 00093 << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/" 00094 <<formatter.nWords() 00095 <<" all: "<< allDigiCounter <<"/"<<allWordCounter; 00096 00097 00098 ev.put( buffers ); 00099 00100 } 00101 00102 // ----------------------------------------------------------------------------- 00103