Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:59

0001 // -*- C++ -*-
0002 //
0003 // Package:    EventFilter/ScalersRawToDigi
0004 // Class:      ScalersRawToDigi
0005 //
0006 /**\class ScalersRawToDigi ScalersRawToDigi.cc EventFilter/ScalersRawToDigi/src/ScalersRawToDigi.cc
0007 
0008  Description: Unpack FED data to Trigger and Lumi Scalers "bank"
0009  These Scalers are in FED id ScalersRaw::SCALERS_FED_ID
0010 
0011 */
0012 //
0013 // Original Author:  William Badgett
0014 //         Created:  Wed Nov 14 07:47:59 CDT 2006
0015 //
0016 
0017 #include <memory>
0018 
0019 #include "FWCore/Framework/interface/global/EDProducer.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/Utilities/interface/InputTag.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 
0026 // FEDRawData
0027 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0028 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0029 
0030 // Scalers classes
0031 #include "DataFormats/Scalers/interface/L1AcceptBunchCrossing.h"
0032 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
0033 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0034 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
0035 #include "DataFormats/Scalers/interface/LumiScalers.h"
0036 #include "DataFormats/Scalers/interface/BeamSpotOnline.h"
0037 #include "DataFormats/Scalers/interface/DcsStatus.h"
0038 #include "DataFormats/Scalers/interface/ScalersRaw.h"
0039 
0040 class ScalersRawToDigi : public edm::global::EDProducer<> {
0041 public:
0042   explicit ScalersRawToDigi(const edm::ParameterSet&);
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0047 
0048 private:
0049   const edm::EDGetTokenT<FEDRawDataCollection> fedToken_;
0050   const edm::EDPutTokenT<L1AcceptBunchCrossingCollection> bunchPutToken_;
0051   const edm::EDPutTokenT<L1TriggerScalersCollection> l1ScalerPutToken_;
0052   const edm::EDPutTokenT<Level1TriggerScalersCollection> lvl1ScalerPutToken_;
0053   const edm::EDPutTokenT<LumiScalersCollection> lumiScalerPutToken_;
0054   const edm::EDPutTokenT<BeamSpotOnlineCollection> beamSpotPutToken_;
0055   const edm::EDPutTokenT<DcsStatusCollection> dcsPutToken_;
0056 };
0057 
0058 // Constructor
0059 ScalersRawToDigi::ScalersRawToDigi(const edm::ParameterSet& iConfig)
0060     : fedToken_{consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("scalersInputTag"))},
0061       bunchPutToken_{produces<L1AcceptBunchCrossingCollection>()},
0062       l1ScalerPutToken_{produces<L1TriggerScalersCollection>()},
0063       lvl1ScalerPutToken_{produces<Level1TriggerScalersCollection>()},
0064       lumiScalerPutToken_{produces<LumiScalersCollection>()},
0065       beamSpotPutToken_{produces<BeamSpotOnlineCollection>()},
0066       dcsPutToken_{produces<DcsStatusCollection>()} {}
0067 
0068 void ScalersRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0069   edm::ParameterSetDescription desc;
0070   desc.add<edm::InputTag>("scalersInputTag", edm::InputTag("rawDataCollector"));
0071   descriptions.add("scalersRawToDigi", desc);
0072 }
0073 
0074 // Method called to produce the data
0075 void ScalersRawToDigi::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0076   using namespace edm;
0077 
0078   // Get the FED data collection
0079   auto const& rawdata = iEvent.get(fedToken_);
0080 
0081   LumiScalersCollection pLumi;
0082 
0083   L1TriggerScalersCollection pOldTrigger;
0084 
0085   Level1TriggerScalersCollection pTrigger;
0086 
0087   L1AcceptBunchCrossingCollection pBunch;
0088 
0089   BeamSpotOnlineCollection pBeamSpotOnline;
0090   DcsStatusCollection pDcsStatus;
0091 
0092   /// Take a reference to this FED's data
0093   const FEDRawData& fedData = rawdata.FEDData(ScalersRaw::SCALERS_FED_ID);
0094   unsigned short int length = fedData.size();
0095   if (length > 0) {
0096     int nWords = length / 8;
0097     int nBytesExtra = 0;
0098 
0099     const ScalersEventRecordRaw_v6* raw = (struct ScalersEventRecordRaw_v6*)fedData.data();
0100     if ((raw->version == 1) || (raw->version == 2)) {
0101       pOldTrigger.emplace_back(fedData.data());
0102       nBytesExtra = length - sizeof(struct ScalersEventRecordRaw_v1);
0103     } else if (raw->version >= 3) {
0104       pTrigger.emplace_back(fedData.data());
0105       if (raw->version >= 6) {
0106         nBytesExtra = ScalersRaw::N_BX_v6 * sizeof(unsigned long long);
0107       } else {
0108         nBytesExtra = ScalersRaw::N_BX_v2 * sizeof(unsigned long long);
0109       }
0110     }
0111 
0112     pLumi.emplace_back(fedData.data());
0113 
0114     if ((nBytesExtra >= 8) && ((nBytesExtra % 8) == 0)) {
0115       unsigned long long const* data = (unsigned long long const*)fedData.data();
0116 
0117       int nWordsExtra = nBytesExtra / 8;
0118       for (int i = 0; i < nWordsExtra; i++) {
0119         int index = nWords - (nWordsExtra + 1) + i;
0120         pBunch.emplace_back(i, data[index]);
0121       }
0122     }
0123 
0124     if (raw->version >= 4) {
0125       pBeamSpotOnline.emplace_back(fedData.data());
0126 
0127       pDcsStatus.emplace_back(fedData.data());
0128     }
0129   }
0130   iEvent.emplace(l1ScalerPutToken_, std::move(pOldTrigger));
0131   iEvent.emplace(lvl1ScalerPutToken_, std::move(pTrigger));
0132   iEvent.emplace(lumiScalerPutToken_, std::move(pLumi));
0133   iEvent.emplace(bunchPutToken_, std::move(pBunch));
0134   iEvent.emplace(beamSpotPutToken_, std::move(pBeamSpotOnline));
0135   iEvent.emplace(dcsPutToken_, std::move(pDcsStatus));
0136 }
0137 
0138 // Define this as a plug-in
0139 DEFINE_FWK_MODULE(ScalersRawToDigi);