CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/EventFilter/SiPixelRawToDigi/plugins/SiPixelDigiToRaw.cc

Go to the documentation of this file.
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 
00019 #include "EventFilter/SiPixelRawToDigi/interface/R2DTimerObserver.h"
00020 #include "TH1D.h"
00021 #include "TFile.h"
00022 
00023 using namespace std;
00024 
00025 SiPixelDigiToRaw::SiPixelDigiToRaw( const edm::ParameterSet& pset ) :
00026   cablingTree_(0),
00027   frameReverter_(0),
00028   config_(pset),
00029   hCPU(0), hDigi(0), theTimer(0)
00030 {
00031 
00032   // Define EDProduct type
00033   produces<FEDRawDataCollection>();
00034 
00035   // start the counters
00036   eventCounter = 0;
00037   allDigiCounter = 0;
00038   allWordCounter = 0;
00039 
00040   // Timing
00041   bool timing = config_.getUntrackedParameter<bool>("Timing",false);
00042   if (timing) {
00043     theTimer = new R2DTimerObserver("**** MY TIMING REPORT ***");
00044     hCPU = new TH1D ("hCPU","hCPU",100,0.,0.050);
00045     hDigi = new TH1D("hDigi","hDigi",50,0.,15000.);
00046   }
00047 }
00048 
00049 // -----------------------------------------------------------------------------
00050 SiPixelDigiToRaw::~SiPixelDigiToRaw() {
00051   delete cablingTree_;
00052   delete frameReverter_;
00053 
00054   if (theTimer) {
00055     TFile rootFile("analysis.root", "RECREATE", "my histograms");
00056     hCPU->Write();
00057     hDigi->Write();
00058     delete theTimer;
00059   }
00060 }
00061 
00062 // -----------------------------------------------------------------------------
00063 
00064 // -----------------------------------------------------------------------------
00065 void SiPixelDigiToRaw::produce( edm::Event& ev,
00066                               const edm::EventSetup& es)
00067 {
00068   using namespace sipixelobjects;
00069   eventCounter++;
00070   edm::LogInfo("SiPixelDigiToRaw") << "[SiPixelDigiToRaw::produce] "
00071                                    << "event number: " << eventCounter;
00072 
00073   edm::Handle< edm::DetSetVector<PixelDigi> > digiCollection;
00074   label = config_.getParameter<edm::InputTag>("InputLabel");
00075   ev.getByLabel( label, digiCollection);
00076 
00077   PixelDataFormatter::RawData rawdata;
00078   PixelDataFormatter::Digis digis;
00079   typedef vector< edm::DetSet<PixelDigi> >::const_iterator DI;
00080 
00081   int digiCounter = 0; 
00082   for (DI di=digiCollection->begin(); di != digiCollection->end(); di++) {
00083     digiCounter += (di->data).size(); 
00084     digis[ di->id] = di->data;
00085   }
00086   allDigiCounter += digiCounter;
00087 
00088   if (recordWatcher.check( es )) {
00089     edm::ESHandle<SiPixelFedCablingMap> cablingMap;
00090     es.get<SiPixelFedCablingMapRcd>().get( cablingMap );
00091     fedIds = cablingMap->fedIds();
00092     if (cablingTree_) delete cablingTree_; cablingTree_= cablingMap->cablingTree();
00093     if (frameReverter_) delete frameReverter_; frameReverter_ = new SiPixelFrameReverter( es, cablingMap.product() );
00094   }
00095 
00096   debug = edm::MessageDrop::instance()->debugEnabled;
00097   if (debug) LogDebug("SiPixelDigiToRaw") << cablingTree_->version();
00098 
00099   PixelDataFormatter formatter(cablingTree_);
00100   formatter.passFrameReverter(frameReverter_);
00101   if (theTimer) theTimer->start();
00102 
00103   // create product (raw data)
00104   std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
00105 
00106   const vector<const PixelFEDCabling *>  fedList = cablingTree_->fedList();
00107 
00108   // convert data to raw
00109   formatter.formatRawData( ev.id().event(), rawdata, digis );
00110 
00111   // pack raw data into collection
00112   typedef vector<const PixelFEDCabling *>::const_iterator FI;
00113   for (FI it = fedList.begin(); it != fedList.end(); it++) {
00114     LogDebug("SiPixelDigiToRaw")<<" PRODUCE DATA FOR FED_id: " << (**it).id();
00115     FEDRawData& fedRawData = buffers->FEDData( (**it).id() );
00116     PixelDataFormatter::RawData::iterator fedbuffer = rawdata.find( (**it).id() );
00117     if( fedbuffer != rawdata.end() ) fedRawData = fedbuffer->second;
00118     LogDebug("SiPixelDigiToRaw")<<"size of data in fedRawData: "<<fedRawData.size();
00119   }
00120   allWordCounter += formatter.nWords();
00121   if (debug) LogDebug("SiPixelDigiToRaw") 
00122 
00123         << "Words/Digis this ev: "<<digiCounter<<"(fm:"<<formatter.nDigis()<<")/"
00124         <<formatter.nWords()
00125         <<"  all: "<< allDigiCounter <<"/"<<allWordCounter;
00126 
00127   if (theTimer) {
00128     theTimer->stop();
00129     LogDebug("SiPixelDigiToRaw") << "TIMING IS: (real)" << theTimer->lastMeasurement().real() ;
00130     LogDebug("SiPixelDigiToRaw") << " (Words/Digis) this ev: "
00131          <<formatter.nWords()<<"/"<<formatter.nDigis() << "--- all :"<<allWordCounter<<"/"<<allDigiCounter;
00132     hCPU->Fill( theTimer->lastMeasurement().real() ); 
00133     hDigi->Fill(formatter.nDigis());
00134   }
00135   
00136   ev.put( buffers );
00137   
00138 }
00139 
00140 // -----------------------------------------------------------------------------
00141