Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:51

0001 //Class to produce a dummy SiStripEventSummary object so that spy channel data can be used with commissioning software.
0002 //Run types which need additional parameters from the trigger FED buffer or DAQ registers are not supported.
0003 //If an unsupported run type is used, an error message will be printed and parameters will be set to zero.
0004 //Author: Nick Cripps
0005 //Date: 10/05/2010
0006 
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/global/EDProducer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
0019 #include "DataFormats/SiStripCommon/interface/ConstantsForRunType.h"
0020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0021 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0022 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferComponents.h"
0023 #include <cstdint>
0024 #include <memory>
0025 #include <string>
0026 #include <vector>
0027 
0028 using edm::LogError;
0029 using edm::LogInfo;
0030 using edm::LogWarning;
0031 
0032 namespace sistrip {
0033 
0034   class SpyEventSummaryProducer : public edm::global::EDProducer<> {
0035   public:
0036     SpyEventSummaryProducer(const edm::ParameterSet& config);
0037     void produce(edm::StreamID, edm::Event& event, const edm::EventSetup&) const override;
0038 
0039   private:
0040     void warnAboutUnsupportedRunType() const;
0041     static const char* const messageLabel_;
0042     const edm::InputTag rawDataTag_;
0043     edm::EDGetTokenT<FEDRawDataCollection> rawDataToken_;
0044     const sistrip::RunType runType_;
0045   };
0046 
0047 }  // namespace sistrip
0048 
0049 namespace sistrip {
0050 
0051   const char* const SpyEventSummaryProducer::messageLabel_ = "SiStripSpyEventSummaryProducer";
0052 
0053   SpyEventSummaryProducer::SpyEventSummaryProducer(const edm::ParameterSet& config)
0054       : rawDataTag_(config.getParameter<edm::InputTag>("RawDataTag")),
0055         runType_(sistrip::RunType(config.getParameter<uint32_t>("RunType"))) {
0056     rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag_);
0057     produces<SiStripEventSummary>();
0058     warnAboutUnsupportedRunType();
0059   }
0060 
0061   void SpyEventSummaryProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup&) const {
0062     warnAboutUnsupportedRunType();
0063 
0064     //get the event number and Bx counter from the first valud FED buffer
0065     edm::Handle<FEDRawDataCollection> rawDataHandle;
0066     event.getByToken(rawDataToken_, rawDataHandle);
0067     const FEDRawDataCollection& rawData = *rawDataHandle;
0068     bool fedFound = false;
0069     uint32_t fedEventNumber = 0;
0070     uint32_t fedBxNumber = 0;
0071     for (uint16_t fedId = sistrip::FED_ID_MIN; fedId <= sistrip::FED_ID_MAX; ++fedId) {
0072       const FEDRawData& fedData = rawData.FEDData(fedId);
0073       if (fedData.size() && fedData.data()) {
0074         const auto st_buffer = preconstructCheckFEDBufferBase(fedData);
0075         if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
0076           LogInfo(messageLabel_) << "Skipping FED " << fedId << " because of exception: "
0077                                  << "An exception of category 'FEDBuffer' occurred.\n"
0078                                  << st_buffer;
0079           continue;
0080         }
0081         const sistrip::FEDBufferBase buffer{fedData};
0082         fedEventNumber = buffer.daqLvl1ID();
0083         fedBxNumber = buffer.daqBXID();
0084         fedFound = true;
0085         break;
0086       }
0087     }
0088     if (!fedFound) {
0089       LogError(messageLabel_) << "No SiStrip FED data found in raw data.";
0090       return;
0091     }
0092 
0093     //create summary object
0094     std::unique_ptr<SiStripEventSummary> pSummary(new SiStripEventSummary);
0095     //set the trigger FED number to zero to indicate that it doesn't exist
0096     pSummary->triggerFed(0);
0097     //set the event number and Bx from the FED packets
0098     pSummary->event(fedEventNumber);
0099     pSummary->bx(fedBxNumber);
0100     //create a fake trigger FED buffer to take comissioning parameters from
0101     const int maxTriggerFedBufferSize = 84;
0102     std::vector<uint32_t> fakeTriggerFedData(maxTriggerFedBufferSize);
0103     for (uint8_t i = 0; i < maxTriggerFedBufferSize; ++i) {
0104       fakeTriggerFedData[i] = 0;
0105     }
0106     //set the FED readout mode to virgin raw
0107     fakeTriggerFedData[15] = 1;
0108     //set the spill number
0109     fakeTriggerFedData[0] = 0;
0110     //set the number of data senders
0111     fakeTriggerFedData[20] = 1;
0112     //set the run type
0113     fakeTriggerFedData[10] = runType_;
0114     //fill the summarry using trigger FED buffer  with no data
0115     pSummary->commissioningInfo(fakeTriggerFedData.data(), fedEventNumber);
0116 
0117     //store in event
0118     event.put(std::move(pSummary));
0119   }
0120 
0121   void SpyEventSummaryProducer::warnAboutUnsupportedRunType() const {
0122     switch (runType_) {
0123       case sistrip::DAQ_SCOPE_MODE:
0124       case sistrip::PHYSICS:
0125       case sistrip::PHYSICS_ZS:
0126       case sistrip::PEDESTALS:
0127       case sistrip::MULTI_MODE:
0128       case sistrip::PEDS_ONLY:
0129       case sistrip::NOISE:
0130       case sistrip::PEDS_FULL_NOISE:
0131       case sistrip::UNKNOWN_RUN_TYPE:
0132       case sistrip::UNDEFINED_RUN_TYPE:
0133         break;
0134       case sistrip::CALIBRATION:
0135       case sistrip::CALIBRATION_DECO:
0136       case sistrip::CALIBRATION_SCAN:
0137       case sistrip::CALIBRATION_SCAN_DECO:
0138       case sistrip::APV_LATENCY:
0139       case sistrip::OPTO_SCAN:
0140       case sistrip::APV_TIMING:
0141       case sistrip::FED_TIMING:
0142       case sistrip::FINE_DELAY:
0143       case sistrip::FINE_DELAY_PLL:
0144       case sistrip::FINE_DELAY_TTC:
0145       case sistrip::FAST_CABLING:
0146       case sistrip::FED_CABLING:
0147       case sistrip::QUITE_FAST_CABLING:
0148       case sistrip::VPSP_SCAN:
0149         LogWarning(messageLabel_) << "Unsupported run type: " << runType_
0150                                   << ". Parameters need to be set from real trigger FED. Parameters will be set to 0.";
0151         break;
0152     }
0153   }
0154 
0155 }  // namespace sistrip
0156 
0157 typedef sistrip::SpyEventSummaryProducer SiStripSpyEventSummaryProducer;
0158 DEFINE_FWK_MODULE(SiStripSpyEventSummaryProducer);