CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorHardware/src/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 produce(edm::Event& event, const edm::EventSetup&) override;
00039     private:
00040       void warnAboutUnsupportedRunType();
00041       static const char* messageLabel_;
00042       const edm::InputTag rawDataTag_;
00043       const sistrip::RunType runType_;
00044   };
00045   
00046 }
00047 
00048 namespace sistrip {
00049   
00050   const char* SpyEventSummaryProducer::messageLabel_ = "SiStripSpyEventSummaryProducer";
00051   
00052   SpyEventSummaryProducer::SpyEventSummaryProducer(const edm::ParameterSet& config)
00053     : rawDataTag_(config.getParameter<edm::InputTag>("RawDataTag")),
00054       runType_(sistrip::RunType(config.getParameter<uint32_t>("RunType")))
00055   {
00056     produces<SiStripEventSummary>();
00057     warnAboutUnsupportedRunType();
00058   }
00059   
00060   SpyEventSummaryProducer::~SpyEventSummaryProducer() {}
00061   
00062   void SpyEventSummaryProducer::produce(edm::Event& event, const edm::EventSetup&)
00063   {
00064     warnAboutUnsupportedRunType();
00065     
00066     //get the event number and Bx counter from the first valud FED buffer
00067     edm::Handle<FEDRawDataCollection> rawDataHandle;
00068     event.getByLabel(rawDataTag_,rawDataHandle);
00069     const FEDRawDataCollection& rawData = *rawDataHandle;
00070     bool fedFound = false;
00071     uint32_t fedEventNumber = 0;
00072     uint32_t fedBxNumber = 0;
00073     for (uint16_t fedId = sistrip::FED_ID_MIN; fedId <= sistrip::FED_ID_MAX; ++fedId) {
00074       const FEDRawData& fedData = rawData.FEDData(fedId);
00075       if (fedData.size() && fedData.data()) {
00076         std::auto_ptr<sistrip::FEDBufferBase> pBuffer;
00077         try {
00078           pBuffer.reset(new sistrip::FEDBufferBase(fedData.data(),fedData.size()));
00079         } catch (const cms::Exception& e) {
00080           LogInfo(messageLabel_) << "Skipping FED " << fedId << " because of exception: " << e.what();
00081           continue;
00082         }
00083         fedEventNumber = pBuffer->daqLvl1ID();
00084         fedBxNumber = pBuffer->daqBXID();
00085         fedFound = true;
00086         break;
00087       }
00088     }
00089     if (!fedFound) {
00090       LogError(messageLabel_) << "No SiStrip FED data found in raw data.";
00091       return;
00092     }
00093     
00094     //create summary object
00095     std::auto_ptr<SiStripEventSummary> pSummary(new SiStripEventSummary);
00096     //set the trigger FED number to zero to indicate that it doesn't exist
00097     pSummary->triggerFed(0);
00098     //set the event number and Bx from the FED packets
00099     pSummary->event(fedEventNumber);
00100     pSummary->bx(fedBxNumber);
00101     //create a fake trigger FED buffer to take comissioning parameters from
00102     const int maxTriggerFedBufferSize = 84;
00103     boost::scoped_array<uint32_t> fakeTriggerFedData(new uint32_t[maxTriggerFedBufferSize]);
00104     for (uint8_t i=0; i<maxTriggerFedBufferSize; ++i) {
00105       fakeTriggerFedData[i] = 0;
00106     }
00107     //set the FED readout mode to virgin raw
00108     fakeTriggerFedData[15] = 1;
00109     //set the spill number
00110     fakeTriggerFedData[0] = 0;
00111     //set the number of data senders
00112     fakeTriggerFedData[20] = 1;
00113     //set the run type
00114     fakeTriggerFedData[10] = runType_;
00115     //fill the summarry using trigger FED buffer  with no data
00116     pSummary->commissioningInfo(fakeTriggerFedData.get(),fedEventNumber);
00117     
00118     //store in event
00119     event.put(pSummary);
00120   }
00121   
00122   void SpyEventSummaryProducer::warnAboutUnsupportedRunType()
00123   {
00124     switch(runType_) {
00125       case sistrip::DAQ_SCOPE_MODE:
00126       case sistrip::PHYSICS:
00127       case sistrip::PHYSICS_ZS:
00128       case sistrip::PEDESTALS:
00129       case sistrip::MULTI_MODE:
00130       case sistrip::PEDS_ONLY:
00131       case sistrip::NOISE:
00132       case sistrip::PEDS_FULL_NOISE:
00133       case sistrip::UNKNOWN_RUN_TYPE:
00134       case sistrip::UNDEFINED_RUN_TYPE:
00135         break;
00136       case sistrip::CALIBRATION:
00137       case sistrip::CALIBRATION_DECO:
00138       case sistrip::CALIBRATION_SCAN:
00139       case sistrip::CALIBRATION_SCAN_DECO:
00140       case sistrip::APV_LATENCY:
00141       case sistrip::OPTO_SCAN:
00142       case sistrip::APV_TIMING:
00143       case sistrip::FED_TIMING:
00144       case sistrip::FINE_DELAY:
00145       case sistrip::FINE_DELAY_PLL:
00146       case sistrip::FINE_DELAY_TTC:
00147       case sistrip::FAST_CABLING:
00148       case sistrip::FED_CABLING:
00149       case sistrip::QUITE_FAST_CABLING:
00150       case sistrip::VPSP_SCAN:
00151         LogWarning(messageLabel_) << "Unsupported run type: " << runType_ << ". Parameters need to be set from real trigger FED. Parameters will be set to 0.";
00152         break;
00153     }
00154   }
00155   
00156 }
00157 
00158 typedef sistrip::SpyEventSummaryProducer SiStripSpyEventSummaryProducer;
00159 DEFINE_FWK_MODULE(SiStripSpyEventSummaryProducer);