CMS 3D CMS Logo

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