CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/EventFilter/SiStripRawToDigi/plugins/SiStripDigiToRawModule.cc

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripDigiToRawModule.cc,v 1.11 2009/11/10 15:10:00 nc302 Exp $
00002 
00003 #include "EventFilter/SiStripRawToDigi/plugins/SiStripDigiToRawModule.h"
00004 #include "EventFilter/SiStripRawToDigi/interface/SiStripDigiToRaw.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/Common/interface/DetSetVector.h"
00012 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00013 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00014 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00015 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00016 #include <cstdlib>
00017 
00018 namespace sistrip {
00019 
00020   // -----------------------------------------------------------------------------
00024   DigiToRawModule::DigiToRawModule( const edm::ParameterSet& pset ) :
00025     inputModuleLabel_( pset.getParameter<std::string>( "InputModuleLabel" ) ),
00026     inputDigiLabel_( pset.getParameter<std::string>( "InputDigiLabel" ) ),
00027     mode_( fedReadoutModeFromString(pset.getParameter<std::string>( "FedReadoutMode" ))),
00028     rawdigi_( false ),
00029     digiToRaw_(0),
00030     eventCounter_(0)
00031   {
00032     if ( edm::isDebugEnabled() ) {
00033       LogDebug("DigiToRawModule") 
00034         << "[sistrip::DigiToRawModule::DigiToRawModule]"
00035         << " Constructing object...";
00036     }  
00037     
00038     switch(mode_) {
00039     case READOUT_MODE_ZERO_SUPPRESSED_LITE: rawdigi_ = false; break;
00040     case READOUT_MODE_ZERO_SUPPRESSED:      rawdigi_ = false; break;
00041     case READOUT_MODE_VIRGIN_RAW:      rawdigi_ = true; break;
00042     case READOUT_MODE_PROC_RAW:        rawdigi_ = true; break;
00043     case READOUT_MODE_SCOPE:           rawdigi_ = true; break;
00044     case READOUT_MODE_INVALID: {
00045       if( edm::isDebugEnabled()) {
00046         edm::LogWarning("DigiToRawModule") 
00047           << "[sistrip::DigiToRawModule::DigiToRawModule]"
00048           << " UNKNOWN readout mode: " << pset.getParameter<std::string>("FedReadoutMode");
00049       }} break;
00050     case READOUT_MODE_SPY: {
00051       if( edm::isDebugEnabled()) {
00052         edm::LogWarning("DigiToRawModule") 
00053           << "[sistrip::DigiToRawModule::DigiToRawModule]"
00054           << " Digi to raw is not supported for spy channel data";
00055       }} break;
00056     }
00057     if(pset.getParameter<bool>("UseWrongDigiType")) {
00058       rawdigi_ = !rawdigi_;
00059       if( edm::isDebugEnabled()) {
00060         edm::LogWarning("DigiToRawModule") 
00061           << "[sistrip::DigiToRawModule::DigiToRawModule]"
00062           << " You are using the wrong type of digis!";
00063       }
00064     }
00065 
00066     // Create instance of DigiToRaw formatter
00067     digiToRaw_ = new DigiToRaw( mode_, pset.getParameter<bool>("UseFedKey") );
00068   
00069     produces<FEDRawDataCollection>();
00070 
00071   }
00072 
00073   // -----------------------------------------------------------------------------
00075   DigiToRawModule::~DigiToRawModule() {
00076     if ( edm::isDebugEnabled() ) {
00077       LogDebug("DigiToRaw")
00078         << "[sistrip::DigiToRawModule::~DigiToRawModule]"
00079         << " Destructing object...";
00080     }
00081     if ( digiToRaw_ ) delete digiToRaw_;
00082   }
00083 
00084   // -----------------------------------------------------------------------------
00091   void DigiToRawModule::produce( edm::Event& iEvent, 
00092                                  const edm::EventSetup& iSetup ) {
00093 
00094     eventCounter_++; 
00095   
00096     std::auto_ptr<FEDRawDataCollection> buffers( new FEDRawDataCollection );
00097 
00098     edm::ESHandle<SiStripFedCabling> cabling;
00099     iSetup.get<SiStripFedCablingRcd>().get( cabling );
00100 
00101     if( rawdigi_ ) {
00102       edm::Handle< edm::DetSetVector<SiStripRawDigi> > rawdigis;
00103       iEvent.getByLabel( inputModuleLabel_, inputDigiLabel_, rawdigis );
00104       digiToRaw_->createFedBuffers( iEvent, cabling, rawdigis, buffers );
00105     } else {
00106       edm::Handle< edm::DetSetVector<SiStripDigi> > digis;
00107       iEvent.getByLabel( inputModuleLabel_, inputDigiLabel_, digis );
00108       digiToRaw_->createFedBuffers( iEvent, cabling, digis, buffers );
00109     }
00110 
00111     iEvent.put( buffers );
00112   
00113   }
00114 
00115 }
00116