CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorHardware/src/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 produce( edm::Event&, const edm::EventSetup& ) override;
00062       private:
00063         static const char* msgLb_;
00064 
00065         // Data members
00066         //--------------
00067         // Configuration
00068         std::vector<uint32_t> fed_ids_;     
00069         const edm::InputTag productLabel_;  
00070         const bool allowIncompleteEvents_;  
00071         const bool storeCounters_;          
00072         const bool storeScopeRawDigis_;           
00073 
00074         // Unpacking
00075         SpyUnpacker* unpacker_;      
00076     
00077       //utilities for cabling etc...
00078       SpyUtilities utility_;
00079 
00080     }; // end of SpyUnpackerModule class.
00081 
00082 } // end of namespace sistrip.
00083 
00084 namespace sistrip {
00085 
00086   const char* SpyUnpackerModule::msgLb_ = "SiStripSpyUnpackerModule";
00087     
00088   SpyUnpackerModule::SpyUnpackerModule( const edm::ParameterSet& pset ) :
00089     fed_ids_( pset.getParameter< std::vector<uint32_t> >("FEDIDs")),
00090     productLabel_(pset.getParameter<edm::InputTag>("InputProductLabel")),
00091     allowIncompleteEvents_(pset.getParameter<bool>("AllowIncompleteEvents")),
00092     storeCounters_(pset.getParameter<bool>("StoreCounters")),
00093     storeScopeRawDigis_(pset.getParameter<bool>("StoreScopeRawDigis")),
00094     unpacker_(NULL)
00095   {
00096 
00097     if ((fed_ids_.size()==0)) {
00098       LogInfo(msgLb_) << "No FED IDs specified, so will try to unpack all FEDs with data" << std::endl;
00099       fed_ids_.reserve(FEDNumbering::MAXSiStripFEDID-FEDNumbering::MINSiStripFEDID+1);
00100       for ( uint32_t ifed = FEDNumbering::MINSiStripFEDID; ifed <= FEDNumbering::MAXSiStripFEDID; ifed++ ) {
00101         fed_ids_.push_back( ifed );    
00102       }
00103     } // end of FED ID specified check.
00104     
00105     if ( edm::isDebugEnabled() ) LogTrace(msgLb_) << "["<< __func__ << "]:" << " Constructing object...";
00106     
00107     unpacker_ = new sistrip::SpyUnpacker(allowIncompleteEvents_);
00108     
00109     if (storeScopeRawDigis_) produces< edm::DetSetVector<SiStripRawDigi> >("ScopeRawDigis");
00110     
00111     if (storeCounters_) {
00112       produces< std::vector<uint32_t> >("L1ACount");
00113       produces< std::vector<uint32_t> >("TotalEventCount");
00114     }
00115     
00116     produces<uint32_t>("GlobalRunNumber");
00117     
00118   } // end of SpyUnpackerModule constructor.
00119 
00120   SpyUnpackerModule::~SpyUnpackerModule() {
00121     if ( unpacker_ ) { delete unpacker_; }
00122     if ( edm::isDebugEnabled() ) {
00123       LogTrace("SiStripSpyUnpacker")
00124         << "[sistrip::SpyUnpackerModule::" << __func__ << "]"
00125         << " Destructing object...";
00126     }
00127   }
00128 
00135   void SpyUnpackerModule::produce( edm::Event& event, const edm::EventSetup& setup ) {
00136     
00137 
00138     const SiStripFedCabling* lCabling = utility_.getCabling( setup );
00139 
00140     //retrieve FED raw data (by label, which is "source" by default)
00141     edm::Handle<FEDRawDataCollection> buffers;
00142     event.getByLabel( productLabel_, buffers ); 
00143     
00144     //create container for digis
00145     std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > digis(new edm::DetSetVector<SiStripRawDigi>);
00146     
00147     //if necessary, create container for event counters
00148     std::auto_ptr< std::vector<uint32_t> > pTotalCounts(new std::vector<uint32_t>);
00149     std::auto_ptr< std::vector<uint32_t> > pL1ACounts(new std::vector<uint32_t>);
00150     //and for run number
00151     std::auto_ptr<uint32_t> pGlobalRun(new uint32_t);
00152     //create digis
00153     // Using FED IDs...
00154     unpacker_->createDigis(*lCabling, 
00155                            *buffers, 
00156                            digis.get(), 
00157                            fed_ids_, 
00158                            pTotalCounts.get(), 
00159                            pL1ACounts.get(),
00160                            pGlobalRun.get()
00161                            );
00162     
00163     // Add digis to event
00164     if (storeScopeRawDigis_) event.put( digis, "ScopeRawDigis" );
00165     
00166     //add counters to event
00167     if (storeCounters_) {
00168       event.put(pTotalCounts, "TotalEventCount");
00169       event.put(pL1ACounts, "L1ACount");
00170     }
00171 
00172     //add global run to the event
00173     event.put(pGlobalRun, "GlobalRunNumber");
00174 
00175   } // end of SpyUnpackerModule::produce method.
00176 
00177 
00178 } // end of sistrip namespace
00179 
00180 typedef sistrip::SpyUnpackerModule SiStripSpyUnpackerModule;
00181 DEFINE_FWK_MODULE(SiStripSpyUnpackerModule);