CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/EventFilter/SiStripRawToDigi/plugins/SiStripRawToDigiModule.cc

Go to the documentation of this file.
00001 
00002 #include "EventFilter/SiStripRawToDigi/plugins/SiStripRawToDigiModule.h"
00003 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00004 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00005 #include "DataFormats/Common/interface/DetSetVector.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "DataFormats/DetId/interface/DetIdCollection.h"
00008 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00009 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00010 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
00011 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00012 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00013 #include "EventFilter/SiStripRawToDigi/interface/SiStripRawToDigiUnpacker.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include <cstdlib>
00017 
00018 namespace sistrip {
00019 
00020   RawToDigiModule::RawToDigiModule( const edm::ParameterSet& pset ) :
00021     rawToDigi_(0),
00022     productLabel_(pset.getParameter<edm::InputTag>("ProductLabel")),
00023     cabling_(0),
00024     cacheId_(0),
00025     extractCm_(false),
00026     doFullCorruptBufferChecks_(false),
00027     doAPVEmulatorCheck_(true)
00028   {
00029     if ( edm::isDebugEnabled() ) {
00030       LogTrace("SiStripRawToDigi")
00031         << "[sistrip::RawToDigiModule::" << __func__ << "]"
00032         << " Constructing object...";
00033     }
00034     
00035     int16_t appended_bytes = pset.getParameter<int>("AppendedBytes");
00036     int16_t trigger_fed_id = pset.getParameter<int>("TriggerFedId");
00037     bool use_daq_register = pset.getParameter<bool>("UseDaqRegister");
00038     bool using_fed_key = pset.getParameter<bool>("UseFedKey");
00039     bool unpack_bad_channels = pset.getParameter<bool>("UnpackBadChannels");
00040     bool mark_missing_feds = pset.getParameter<bool>("MarkModulesOnMissingFeds");
00041 
00042     int16_t fed_buffer_dump_freq = pset.getUntrackedParameter<int>("FedBufferDumpFreq",0);
00043     int16_t fed_event_dump_freq = pset.getUntrackedParameter<int>("FedEventDumpFreq",0);
00044     bool quiet = pset.getUntrackedParameter<bool>("Quiet",true);
00045     extractCm_ = pset.getParameter<bool>("UnpackCommonModeValues");
00046     doFullCorruptBufferChecks_ = pset.getParameter<bool>("DoAllCorruptBufferChecks");
00047     doAPVEmulatorCheck_ = pset.getParameter<bool>("DoAPVEmulatorCheck");
00048 
00049     uint32_t errorThreshold = pset.getParameter<unsigned int>("ErrorThreshold");
00050 
00051     rawToDigi_ = new sistrip::RawToDigiUnpacker( appended_bytes, fed_buffer_dump_freq, fed_event_dump_freq, trigger_fed_id, using_fed_key, unpack_bad_channels, mark_missing_feds, errorThreshold);
00052     rawToDigi_->quiet(quiet);
00053     rawToDigi_->useDaqRegister( use_daq_register ); 
00054     rawToDigi_->extractCm(extractCm_);
00055     rawToDigi_->doFullCorruptBufferChecks(doFullCorruptBufferChecks_);
00056     rawToDigi_->doAPVEmulatorCheck(doAPVEmulatorCheck_);
00057 
00058     produces< SiStripEventSummary >();
00059     produces< edm::DetSetVector<SiStripRawDigi> >("ScopeMode");
00060     produces< edm::DetSetVector<SiStripRawDigi> >("VirginRaw");
00061     produces< edm::DetSetVector<SiStripRawDigi> >("ProcessedRaw");
00062     produces< edm::DetSetVector<SiStripDigi> >("ZeroSuppressed");
00063     produces<DetIdCollection>();
00064     if ( extractCm_ ) produces< edm::DetSetVector<SiStripRawDigi> >("CommonMode");
00065   
00066   }
00067 
00068   RawToDigiModule::~RawToDigiModule() {
00069     if ( rawToDigi_ ) { delete rawToDigi_; }
00070     if ( cabling_ ) { cabling_ = 0; }
00071     if ( edm::isDebugEnabled() ) {
00072       LogTrace("SiStripRawToDigi")
00073         << "[sistrip::RawToDigiModule::" << __func__ << "]"
00074         << " Destructing object...";
00075     }
00076   }
00077 
00078   void RawToDigiModule::beginRun( edm::Run& run, const edm::EventSetup& setup ) {
00079     updateCabling( setup );
00080   }  
00081   
00088   void RawToDigiModule::produce( edm::Event& event, const edm::EventSetup& setup ) {
00089   
00090     updateCabling( setup );
00091   
00092     // Retrieve FED raw data (by label, which is "source" by default)
00093     edm::Handle<FEDRawDataCollection> buffers;
00094     event.getByLabel( productLabel_, buffers ); 
00095 
00096     // Populate SiStripEventSummary object with "trigger FED" info
00097     std::auto_ptr<SiStripEventSummary> summary( new SiStripEventSummary() );
00098     rawToDigi_->triggerFed( *buffers, *summary, event.id().event() ); 
00099 
00100     // Create containers for digis
00101     edm::DetSetVector<SiStripRawDigi>* sm = new edm::DetSetVector<SiStripRawDigi>();
00102     edm::DetSetVector<SiStripRawDigi>* vr = new edm::DetSetVector<SiStripRawDigi>();
00103     edm::DetSetVector<SiStripRawDigi>* pr = new edm::DetSetVector<SiStripRawDigi>();
00104     edm::DetSetVector<SiStripDigi>* zs = new edm::DetSetVector<SiStripDigi>();
00105     DetIdCollection* ids = new DetIdCollection();
00106     edm::DetSetVector<SiStripRawDigi>* cm = new edm::DetSetVector<SiStripRawDigi>();
00107   
00108     // Create digis
00109     if ( rawToDigi_ ) { rawToDigi_->createDigis( *cabling_,*buffers,*summary,*sm,*vr,*pr,*zs,*ids,*cm ); }
00110   
00111     // Create auto_ptr's of digi products
00112     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > sm_dsv(sm);
00113     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > vr_dsv(vr);
00114     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > pr_dsv(pr);
00115     std::auto_ptr< edm::DetSetVector<SiStripDigi> > zs_dsv(zs);
00116     std::auto_ptr< DetIdCollection > det_ids(ids);
00117     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > cm_dsv(cm);
00118   
00119     // Add to event
00120     event.put( summary );
00121     event.put( sm_dsv, "ScopeMode" );
00122     event.put( vr_dsv, "VirginRaw" );
00123     event.put( pr_dsv, "ProcessedRaw" );
00124     event.put( zs_dsv, "ZeroSuppressed" );
00125     event.put( det_ids );
00126     if ( extractCm_ ) event.put( cm_dsv, "CommonMode" );
00127   
00128   }
00129 
00130   void RawToDigiModule::updateCabling( const edm::EventSetup& setup ) {
00131 
00132     uint32_t cache_id = setup.get<SiStripFedCablingRcd>().cacheIdentifier();
00133 
00134     if ( cacheId_ != cache_id ) {
00135     
00136       edm::ESHandle<SiStripFedCabling> c;
00137       setup.get<SiStripFedCablingRcd>().get( c );
00138       cabling_ = c.product();
00139     
00140       if ( edm::isDebugEnabled() ) {
00141         if ( !cacheId_ ) {
00142           std::stringstream ss;
00143           ss << "[sistrip::RawToDigiModule::" << __func__ << "]"
00144              << " Updating cabling for first time..." << std::endl
00145              << " Terse print out of FED cabling:" << std::endl;
00146           cabling_->terse(ss);
00147           LogTrace("SiStripRawToDigi") << ss.str();
00148         }
00149       }
00150     
00151       if ( edm::isDebugEnabled() ) {
00152         std::stringstream sss;
00153         sss << "[sistrip::RawToDigiModule::" << __func__ << "]"
00154             << " Summary of FED cabling:" << std::endl;
00155         cabling_->summary(sss);
00156         LogTrace("SiStripRawToDigi") << sss.str();
00157       }
00158       cacheId_ = cache_id;
00159     }
00160   }
00161 
00162 }
00163