CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/SiStripMonitorHardware/plugins/SiStripSpyDigiConverterModule.cc

Go to the documentation of this file.
00001 #include <string>
00002 #include <memory>
00003 #include <vector>
00004 #include <utility>
00005 #include "boost/cstdint.hpp"
00006 
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 "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DataFormats/Common/interface/Handle.h"
00016 #include "DataFormats/Common/interface/DetSetVector.h"
00017 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00018 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00019 
00020 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyDigiConverter.h"
00021 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
00022 
00023 class SiStripFedCabling;
00024 
00034 namespace sistrip {
00035 
00036   class SpyDigiConverterModule : public edm::EDProducer
00037   {
00038   public:
00039     SpyDigiConverterModule( const edm::ParameterSet& );
00040     ~SpyDigiConverterModule();
00041     virtual void beginRun( edm::Run&, const edm::EventSetup& );
00042     virtual void produce( edm::Event&, const edm::EventSetup& );
00043 
00044   private:
00045     const edm::InputTag productLabel_;
00046     const bool storeAPVAddress_;             
00047     const bool storePayloadDigis_, storeReorderedDigis_, storeModuleDigis_;
00048     sistrip::SpyUtilities::FrameQuality frameQuality_;
00049     const bool discardDigisWithAPVAddressError_;
00050     const uint32_t expectedHeaderBit_;
00051     
00052     //utilities for cabling etc...
00053     SpyUtilities utility_;
00054   };
00055 
00056 } // end of sistrip namespace.
00057 
00058 
00059 
00060 namespace sistrip {
00061 
00062   SpyDigiConverterModule::SpyDigiConverterModule( const edm::ParameterSet& pset ) :
00063     productLabel_(pset.getParameter<edm::InputTag>("InputProductLabel")),
00064     storeAPVAddress_(pset.getParameter<bool>("StoreAPVAddress")),
00065     storePayloadDigis_(pset.getParameter<bool>("StorePayloadDigis")),
00066     storeReorderedDigis_(pset.getParameter<bool>("StoreReorderedDigis")),
00067     storeModuleDigis_(pset.getParameter<bool>("StoreModuleDigis")),
00068     discardDigisWithAPVAddressError_(pset.getParameter<bool>("DiscardDigisWithWrongAPVAddress")),
00069     expectedHeaderBit_(pset.getParameter<uint32_t>("ExpectedPositionOfFirstHeaderBit"))
00070   {
00071     if ( edm::isDebugEnabled() ) {
00072       LogTrace("SiStripSpyDigiConverter")
00073         << "[sistrip::SpyDigiConverterModule::" << __func__ << "]"
00074         << " Constructing object...";
00075     }
00076     
00077     if (storePayloadDigis_)   produces< edm::DetSetVector<SiStripRawDigi> >("Payload");
00078     if (storeReorderedDigis_) produces< edm::DetSetVector<SiStripRawDigi> >("Reordered");
00079     if (storeModuleDigis_)    produces< edm::DetSetVector<SiStripRawDigi> >("VirginRaw");
00080         
00081     if (storeAPVAddress_) {
00082       produces< std::vector<uint32_t> >("APVAddress");
00083       //produces<uint8_t>("APVAddress");
00084     }
00085 
00086 
00087     frameQuality_.minDigiRange = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinDigiRange"));
00088     frameQuality_.maxDigiRange = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxDigiRange"));
00089     frameQuality_.minZeroLight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinZeroLight"));
00090     frameQuality_.maxZeroLight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxZeroLight"));
00091     frameQuality_.minTickHeight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinTickHeight"));
00092     frameQuality_.maxTickHeight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxTickHeight"));
00093 
00094     
00095   } // end of constructor.
00096 
00097 
00098   SpyDigiConverterModule::~SpyDigiConverterModule() {
00099     if ( edm::isDebugEnabled() ) {
00100       LogTrace("SiStripSpyDigiConverter")
00101         << "[sistrip::SpyDigiConverterModule::" << __func__ << "]"
00102         << " Destructing object...";
00103     }
00104   } // end of destructor.
00105 
00106 
00107   void SpyDigiConverterModule::beginRun( edm::Run& run, const edm::EventSetup& setup ) {
00108 
00109   }  
00110   
00117   void SpyDigiConverterModule::produce( edm::Event& event, const edm::EventSetup& setup ) {
00118 
00119     static bool lFirstEvent = true;
00120 
00121     const SiStripFedCabling* lCabling = utility_.getCabling( setup );
00122 
00123     if ( !(storePayloadDigis_ || storeReorderedDigis_ || storeModuleDigis_ || storeAPVAddress_) ) return;
00124     
00125     //retrieve the scope mode digis
00126     edm::Handle<sistrip::SpyDigiConverter::DSVRawDigis> scopeDigisHandle;
00127     event.getByLabel(productLabel_, scopeDigisHandle);
00128     
00129     //32-bit to accomodate known CMSSW container
00130     std::auto_ptr< std::vector<uint32_t> > pAPVAddresses(new std::vector<uint32_t>);
00131         
00132     std::auto_ptr<sistrip::SpyDigiConverter::DSVRawDigis> payloadDigis, reorderedDigis, moduleDigis;
00133     
00134     //get the majority value for expected position of first header bit
00135     //from first event, compare to expected one, else output warning.
00136     if (lFirstEvent){
00137       uint16_t lFirstHeaderBit;
00138       sistrip::SpyUtilities::getMajorityHeader(scopeDigisHandle.product(),lFirstHeaderBit);
00139 
00140       if (lFirstHeaderBit != static_cast<uint16_t>(expectedHeaderBit_)) {
00141         edm::LogWarning("") << " -- Majority position for firstHeaderBit in first event ("
00142                             << lFirstHeaderBit
00143                             << ") is not where expected: "
00144                             << static_cast<uint16_t>(expectedHeaderBit_)
00145                             << std::endl;
00146       }
00147 
00148     }
00149 
00150 
00151 
00152     //extract frame digis and APV addresses
00153     payloadDigis = sistrip::SpyDigiConverter::extractPayloadDigis(scopeDigisHandle.product(), 
00154                                                                   pAPVAddresses.get(),
00155                                                                   discardDigisWithAPVAddressError_,
00156                                                                   frameQuality_, 
00157                                                                   static_cast<uint16_t>(expectedHeaderBit_));
00158         
00159     // Reorder
00160     if (storeReorderedDigis_ || storeModuleDigis_) {
00161       reorderedDigis = sistrip::SpyDigiConverter::reorderDigis(payloadDigis.get());
00162     }
00163     
00164     // Merge into modules
00165     if (storeModuleDigis_) {
00166       moduleDigis = sistrip::SpyDigiConverter::mergeModuleChannels(reorderedDigis.get(), *lCabling);
00167     }
00168     
00169     //add to event
00170     if (storePayloadDigis_) event.put(payloadDigis,"Payload");
00171     if (storeReorderedDigis_) event.put(reorderedDigis,"Reordered");
00172     if (storeModuleDigis_) event.put(moduleDigis,"VirginRaw");
00173     if (storeAPVAddress_) {
00174       event.put(pAPVAddresses, "APVAddress");
00175     }
00176         
00177 
00178     lFirstEvent = false;
00179 
00180   } // end of SpyDigiConverter::produce method.
00181 
00182 } // end of sistrip namespace.
00183 
00184 
00185 #include "FWCore/Framework/interface/MakerMacros.h"
00186 typedef sistrip::SpyDigiConverterModule SiStripSpyDigiConverterModule;
00187 DEFINE_FWK_MODULE(SiStripSpyDigiConverterModule);