Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-09 00:45:02

0001 // -*- C++ -*-
0002 //
0003 // Package:    ProdTutorial/TcdsRawToDigi
0004 // Class:      TcdsRawToDigi
0005 //
0006 /**\class TcdsRawToDigi TcdsRawToDigi.cc ProdTutorial/TcdsRawToDigi/plugins/TcdsRawToDigi.cc
0007 
0008  Description:  Producer to unpack lumi nibble from TCDS
0009 
0010 */
0011 //
0012 // Original Author:  Chris Palmer
0013 // Improved by    :  Salvatore Di Guida and Remi Mommsen
0014 //         Created:  Thu, 28 May 2015 19:54:56 GMT
0015 //
0016 //
0017 
0018 // system include files
0019 #include <memory>
0020 #include <iostream>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0032 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0033 
0034 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0035 
0036 //
0037 // class declaration
0038 //
0039 
0040 class TcdsRawToDigi : public edm::stream::EDProducer<> {
0041 public:
0042   explicit TcdsRawToDigi(const edm::ParameterSet&);
0043   ~TcdsRawToDigi() override;
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047 private:
0048   void produce(edm::Event&, const edm::EventSetup&) override;
0049 
0050   edm::EDGetTokenT<FEDRawDataCollection> dataToken_;
0051 };
0052 
0053 TcdsRawToDigi::TcdsRawToDigi(const edm::ParameterSet& iConfig) {
0054   edm::InputTag dataLabel = iConfig.getParameter<edm::InputTag>("InputLabel");
0055   dataToken_ = consumes<FEDRawDataCollection>(dataLabel);
0056   produces<TCDSRecord>("tcdsRecord").setBranchAlias("tcdsRecord");
0057 }
0058 
0059 TcdsRawToDigi::~TcdsRawToDigi() {}
0060 
0061 //
0062 // member functions
0063 //
0064 
0065 // ------------ method called to produce the data  ------------
0066 void TcdsRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067   using namespace edm;
0068 
0069   edm::Handle<FEDRawDataCollection> rawdata;
0070   iEvent.getByToken(dataToken_, rawdata);
0071 
0072   TCDSRecord tcdsRecord;
0073   if (rawdata.isValid()) {
0074     uint16_t selectedId = 0;
0075     for (uint16_t fedId = FEDNumbering::MINTCDSuTCAFEDID; fedId <= FEDNumbering::MAXTCDSuTCAFEDID; fedId++) {
0076       const FEDRawData& tcdsData = rawdata->FEDData(fedId);
0077       if (tcdsData.size() > 0) {
0078         if (selectedId)
0079           throw cms::Exception("TcdsRawToDigi::produce")
0080               << "Second TCDS FED ID " << fedId << " found. First ID: " << selectedId;
0081         tcdsRecord = TCDSRecord(tcdsData.data());
0082         selectedId = fedId;
0083       }
0084     }
0085   }
0086   iEvent.put(std::make_unique<TCDSRecord>(tcdsRecord), "tcdsRecord");
0087 }
0088 
0089 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0090 void TcdsRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0091   //The following says we do not know what parameters are allowed so do no validation
0092   // Please change this to state exactly what you do use, even if it is no parameters
0093   edm::ParameterSetDescription desc;
0094   desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
0095   descriptions.add("tcdsRawToDigi", desc);
0096 }
0097 
0098 //define this as a plug-in
0099 DEFINE_FWK_MODULE(TcdsRawToDigi);