CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/SiStripMonitorHardware/plugins/SiStripSpyUnpackerModule.cc

Go to the documentation of this file.
00001 /*\ \file SiStripSpyUnpackerModule.cc
00002  * \brief Source code for the spy unpacking plugin module.
00003  */
00004 
00005 // CMSSW includes
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/Framework/interface/EDProducer.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Utilities/interface/InputTag.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 
00017 // Needed for the FED cabling
00018 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00019 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00020 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00021 
00022 // Needed for the FED raw data collection
00023 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00024 
00025 // For the digi stuff.
00026 #include "DataFormats/Common/interface/DetSetVector.h"
00027 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00028 
00029 // For the unpacking object.
00030 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUnpacker.h"
00031 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
00032 
00033 // Standard includes
00034 #include <memory>
00035 #include <utility>
00036 #include <string>
00037 #include "boost/cstdint.hpp"
00038 
00039 namespace sistrip { class SpyUnpacker; class SpyUtilities; }
00040 class SiStripFedCabling;
00041 
00042 using edm::LogError;
00043 using edm::LogInfo;
00044 
00045 
00046 namespace sistrip {
00047 
00056     class SpyUnpackerModule : public edm::EDProducer
00057     {
00058       public:
00059         SpyUnpackerModule( const edm::ParameterSet& );
00060         virtual ~SpyUnpackerModule();
00061         virtual void beginRun( edm::Run&, const edm::EventSetup& );
00062         virtual void produce( edm::Event&, const edm::EventSetup& );
00063       private:
00064         static const char* msgLb_;
00065 
00066         // Data members
00067         //--------------
00068         // Configuration
00069         std::vector<uint32_t> fed_ids_;     
00070         const edm::InputTag productLabel_;  
00071         const bool allowIncompleteEvents_;  
00072         const bool storeCounters_;          
00073         const bool storeScopeRawDigis_;           
00074 
00075         // Unpacking
00076         SpyUnpacker* unpacker_;      
00077     
00078       //utilities for cabling etc...
00079       SpyUtilities utility_;
00080 
00081     }; // end of SpyUnpackerModule class.
00082 
00083 } // end of namespace sistrip.
00084 
00085 namespace sistrip {
00086 
00087   const char* SpyUnpackerModule::msgLb_ = "SiStripSpyUnpackerModule";
00088     
00089   SpyUnpackerModule::SpyUnpackerModule( const edm::ParameterSet& pset ) :
00090     fed_ids_( pset.getParameter< std::vector<uint32_t> >("FEDIDs")),
00091     productLabel_(pset.getParameter<edm::InputTag>("InputProductLabel")),
00092     allowIncompleteEvents_(pset.getParameter<bool>("AllowIncompleteEvents")),
00093     storeCounters_(pset.getParameter<bool>("StoreCounters")),
00094     storeScopeRawDigis_(pset.getParameter<bool>("StoreScopeRawDigis")),
00095     unpacker_(NULL)
00096   {
00097 
00098     if ((fed_ids_.size()==0)) {
00099       LogInfo(msgLb_) << "No FED IDs specified, so will try to unpack all FEDs with data" << std::endl;
00100       fed_ids_.reserve(FEDNumbering::MAXSiStripFEDID-FEDNumbering::MINSiStripFEDID+1);
00101       for ( uint32_t ifed = FEDNumbering::MINSiStripFEDID; ifed <= FEDNumbering::MAXSiStripFEDID; ifed++ ) {
00102         fed_ids_.push_back( ifed );    
00103       }
00104     } // end of FED ID specified check.
00105     
00106     if ( edm::isDebugEnabled() ) LogTrace(msgLb_) << "["<< __func__ << "]:" << " Constructing object...";
00107     
00108     unpacker_ = new sistrip::SpyUnpacker(allowIncompleteEvents_);
00109     
00110     if (storeScopeRawDigis_) produces< edm::DetSetVector<SiStripRawDigi> >("ScopeRawDigis");
00111     
00112     if (storeCounters_) {
00113       produces< std::vector<uint32_t> >("L1ACount");
00114       produces< std::vector<uint32_t> >("TotalEventCount");
00115     }
00116     
00117     produces<uint32_t>("GlobalRunNumber");
00118     
00119   } // end of SpyUnpackerModule constructor.
00120 
00121   SpyUnpackerModule::~SpyUnpackerModule() {
00122     if ( unpacker_ ) { delete unpacker_; }
00123     if ( edm::isDebugEnabled() ) {
00124       LogTrace("SiStripSpyUnpacker")
00125         << "[sistrip::SpyUnpackerModule::" << __func__ << "]"
00126         << " Destructing object...";
00127     }
00128   }
00129 
00130   void SpyUnpackerModule::beginRun( edm::Run& run, const edm::EventSetup& setup ) {
00131   }  
00132   
00133 
00134 
00141   void SpyUnpackerModule::produce( edm::Event& event, const edm::EventSetup& setup ) {
00142     
00143 
00144     const SiStripFedCabling* lCabling = utility_.getCabling( setup );
00145 
00146     //retrieve FED raw data (by label, which is "source" by default)
00147     edm::Handle<FEDRawDataCollection> buffers;
00148     event.getByLabel( productLabel_, buffers ); 
00149     
00150     //create container for digis
00151     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > digis(new edm::DetSetVector<SiStripRawDigi>);
00152     
00153     //if necessary, create container for event counters
00154     std::auto_ptr< std::vector<uint32_t> > pTotalCounts(new std::vector<uint32_t>);
00155     std::auto_ptr< std::vector<uint32_t> > pL1ACounts(new std::vector<uint32_t>);
00156     //and for run number
00157     std::auto_ptr<uint32_t> pGlobalRun(new uint32_t);
00158     //create digis
00159     // Using FED IDs...
00160     unpacker_->createDigis(*lCabling, 
00161                            *buffers, 
00162                            digis.get(), 
00163                            fed_ids_, 
00164                            pTotalCounts.get(), 
00165                            pL1ACounts.get(),
00166                            pGlobalRun.get()
00167                            );
00168     
00169     // Add digis to event
00170     if (storeScopeRawDigis_) event.put( digis, "ScopeRawDigis" );
00171     
00172     //add counters to event
00173     if (storeCounters_) {
00174       event.put(pTotalCounts, "TotalEventCount");
00175       event.put(pL1ACounts, "L1ACount");
00176     }
00177 
00178     //add global run to the event
00179     event.put(pGlobalRun, "GlobalRunNumber");
00180 
00181   } // end of SpyUnpackerModule::produce method.
00182 
00183 
00184 } // end of sistrip namespace
00185 
00186 typedef sistrip::SpyUnpackerModule SiStripSpyUnpackerModule;
00187 DEFINE_FWK_MODULE(SiStripSpyUnpackerModule);