CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/SiStripMonitorHardware/plugins/SiStripSpyEventSummaryProducer.cc

Go to the documentation of this file.
00001 //Class to produce a dummy SiStripEventSummary object so that spy channel data can be used with commissioning software. 
00002 //Run types which need additional parameters from the trigger FED buffer or DAQ registers are not supported. 
00003 //If an unsupported run type is used, an error message will be printed and parameters will be set to zero. 
00004 //Author: Nick Cripps
00005 //Date: 10/05/2010
00006 
00007 #include "FWCore/Framework/interface/Frameworkfwd.h"
00008 #include "FWCore/Framework/interface/EDProducer.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/Utilities/interface/InputTag.h"
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "FWCore/Framework/interface/MakerMacros.h"
00017 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
00018 #include "DataFormats/SiStripCommon/interface/ConstantsForRunType.h"
00019 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00020 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00021 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferComponents.h"
00022 #include <memory>
00023 #include <string>
00024 #include "boost/scoped_array.hpp"
00025 #include "boost/cstdint.hpp"
00026 
00027 using edm::LogError;
00028 using edm::LogWarning;
00029 using edm::LogInfo;
00030 
00031 namespace sistrip {
00032   
00033   class SpyEventSummaryProducer : public edm::EDProducer
00034   {
00035     public:
00036       SpyEventSummaryProducer(const edm::ParameterSet& config);
00037       virtual ~SpyEventSummaryProducer();
00038       virtual void beginRun(edm::Run&, const edm::EventSetup&);
00039       virtual void produce(edm::Event& event, const edm::EventSetup&);
00040     private:
00041       void warnAboutUnsupportedRunType();
00042       static const char* messageLabel_;
00043       const edm::InputTag rawDataTag_;
00044       const sistrip::RunType runType_;
00045   };
00046   
00047 }
00048 
00049 namespace sistrip {
00050   
00051   const char* SpyEventSummaryProducer::messageLabel_ = "SiStripSpyEventSummaryProducer";
00052   
00053   SpyEventSummaryProducer::SpyEventSummaryProducer(const edm::ParameterSet& config)
00054     : rawDataTag_(config.getParameter<edm::InputTag>("RawDataTag")),
00055       runType_(sistrip::RunType(config.getParameter<uint32_t>("RunType")))
00056   {
00057     produces<SiStripEventSummary>();
00058     warnAboutUnsupportedRunType();
00059   }
00060   
00061   SpyEventSummaryProducer::~SpyEventSummaryProducer() {}
00062   
00063   void SpyEventSummaryProducer::beginRun(edm::Run&, const edm::EventSetup&)
00064   {}
00065   
00066   void SpyEventSummaryProducer::produce(edm::Event& event, const edm::EventSetup&)
00067   {
00068     warnAboutUnsupportedRunType();
00069     
00070     //get the event number and Bx counter from the first valud FED buffer
00071     edm::Handle<FEDRawDataCollection> rawDataHandle;
00072     event.getByLabel(rawDataTag_,rawDataHandle);
00073     const FEDRawDataCollection& rawData = *rawDataHandle;
00074     bool fedFound = false;
00075     uint32_t fedEventNumber = 0;
00076     uint32_t fedBxNumber = 0;
00077     for (uint16_t fedId = sistrip::FED_ID_MIN; fedId <= sistrip::FED_ID_MAX; ++fedId) {
00078       const FEDRawData& fedData = rawData.FEDData(fedId);
00079       if (fedData.size() && fedData.data()) {
00080         std::auto_ptr<sistrip::FEDBufferBase> pBuffer;
00081         try {
00082           pBuffer.reset(new sistrip::FEDBufferBase(fedData.data(),fedData.size()));
00083         } catch (const cms::Exception& e) {
00084           LogInfo(messageLabel_) << "Skipping FED " << fedId << " because of exception: " << e.what();
00085           continue;
00086         }
00087         fedEventNumber = pBuffer->daqLvl1ID();
00088         fedBxNumber = pBuffer->daqBXID();
00089         fedFound = true;
00090         break;
00091       }
00092     }
00093     if (!fedFound) {
00094       LogError(messageLabel_) << "No SiStrip FED data found in raw data.";
00095       return;
00096     }
00097     
00098     //create summary object
00099     std::auto_ptr<SiStripEventSummary> pSummary(new SiStripEventSummary);
00100     //set the trigger FED number to zero to indicate that it doesn't exist
00101     pSummary->triggerFed(0);
00102     //set the event number and Bx from the FED packets
00103     pSummary->event(fedEventNumber);
00104     pSummary->bx(fedBxNumber);
00105     //create a fake trigger FED buffer to take comissioning parameters from
00106     const int maxTriggerFedBufferSize = 84;
00107     boost::scoped_array<uint32_t> fakeTriggerFedData(new uint32_t[maxTriggerFedBufferSize]);
00108     for (uint8_t i=0; i<maxTriggerFedBufferSize; ++i) {
00109       fakeTriggerFedData[i] = 0;
00110     }
00111     //set the FED readout mode to virgin raw
00112     fakeTriggerFedData[15] = 1;
00113     //set the spill number
00114     fakeTriggerFedData[0] = 0;
00115     //set the number of data senders
00116     fakeTriggerFedData[20] = 1;
00117     //set the run type
00118     fakeTriggerFedData[10] = runType_;
00119     //fill the summarry using trigger FED buffer  with no data
00120     pSummary->commissioningInfo(fakeTriggerFedData.get(),fedEventNumber);
00121     
00122     //store in event
00123     event.put(pSummary);
00124   }
00125   
00126   void SpyEventSummaryProducer::warnAboutUnsupportedRunType()
00127   {
00128     switch(runType_) {
00129       case sistrip::DAQ_SCOPE_MODE:
00130       case sistrip::PHYSICS:
00131       case sistrip::PHYSICS_ZS:
00132       case sistrip::PEDESTALS:
00133       case sistrip::MULTI_MODE:
00134       case sistrip::PEDS_ONLY:
00135       case sistrip::NOISE:
00136       case sistrip::PEDS_FULL_NOISE:
00137       case sistrip::UNKNOWN_RUN_TYPE:
00138       case sistrip::UNDEFINED_RUN_TYPE:
00139         break;
00140       case sistrip::CALIBRATION:
00141       case sistrip::CALIBRATION_DECO:
00142       case sistrip::CALIBRATION_SCAN:
00143       case sistrip::CALIBRATION_SCAN_DECO:
00144       case sistrip::APV_LATENCY:
00145       case sistrip::OPTO_SCAN:
00146       case sistrip::APV_TIMING:
00147       case sistrip::FED_TIMING:
00148       case sistrip::FINE_DELAY:
00149       case sistrip::FINE_DELAY_PLL:
00150       case sistrip::FINE_DELAY_TTC:
00151       case sistrip::FAST_CABLING:
00152       case sistrip::FED_CABLING:
00153       case sistrip::QUITE_FAST_CABLING:
00154       case sistrip::VPSP_SCAN:
00155         LogWarning(messageLabel_) << "Unsupported run type: " << runType_ << ". Parameters need to be set from real trigger FED. Parameters will be set to 0.";
00156         break;
00157     }
00158   }
00159   
00160 }
00161 
00162 typedef sistrip::SpyEventSummaryProducer SiStripSpyEventSummaryProducer;
00163 DEFINE_FWK_MODULE(SiStripSpyEventSummaryProducer);