Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    temp/CTPPSTotemDigiToRaw
0004 // Class:      CTPPSTotemDigiToRaw
0005 //
0006 /**\class CTPPSTotemDigiToRaw CTPPSTotemDigiToRaw.cc temp/CTPPSTotemDigiToRaw/plugins/CTPPSTotemDigiToRaw.cc
0007 
0008 Description: [one line class summary]
0009 
0010 Implementation:
0011 [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Dilson De Jesus Damiao
0015 //                   Maria Elena Pol
0016 //         Created:  Tue, 11 Sep 2018 17:12:12 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/ESWatcher.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/Framework/interface/stream/EDProducer.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0035 #include "FWCore/PluginManager/interface/ModuleDef.h"
0036 #include "FWCore/Utilities/interface/InputTag.h"
0037 #include "FWCore/Utilities/interface/StreamID.h"
0038 #include "FWCore/Utilities/interface/ESGetToken.h"
0039 
0040 #include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
0041 #include "CondFormats/PPSObjects/interface/TotemFramePosition.h"
0042 #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
0043 
0044 #include "DataFormats/CTPPSDetId/interface/TotemRPDetId.h"
0045 #include "DataFormats/CTPPSDigi/interface/TotemRPDigi.h"
0046 #include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
0047 #include "DataFormats/Common/interface/DetSetVector.h"
0048 #include "DataFormats/Common/interface/Handle.h"
0049 #include "DataFormats/DetId/interface/DetIdCollection.h"
0050 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0051 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0052 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0053 
0054 #include "EventFilter/CTPPSRawToDigi/interface/CTPPSTotemDataFormatter.h"
0055 #include "EventFilter/CTPPSRawToDigi/interface/VFATFrameCollection.h"
0056 //
0057 // class declaration
0058 //
0059 
0060 class CTPPSTotemDigiToRaw : public edm::stream::EDProducer<> {
0061 public:
0062   explicit CTPPSTotemDigiToRaw(const edm::ParameterSet&);
0063   ~CTPPSTotemDigiToRaw() override;
0064 
0065   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0066 
0067 private:
0068   void beginStream(edm::StreamID) override;
0069   void produce(edm::Event&, const edm::EventSetup&) override;
0070 
0071   unsigned long eventCounter_;
0072   std::set<unsigned int> fedIds_;
0073   int allDigiCounter_;
0074   int allWordCounter_;
0075   bool debug_;
0076   edm::ESWatcher<TotemReadoutRcd> recordWatcher_;
0077   edm::EDGetTokenT<edm::DetSetVector<TotemRPDigi>> tTotemRPDigi_;
0078   edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> tTotemDAQMapping_;
0079   std::vector<CTPPSTotemDataFormatter::PPSStripIndex> v_iDdet2fed_;
0080   TotemFramePosition fPos_;
0081 
0082   // ----------member data ---------------------------
0083 };
0084 
0085 //
0086 // constants, enums and typedefs
0087 //
0088 
0089 //
0090 // static data member definitions
0091 //
0092 
0093 //
0094 // constructors and destructor
0095 //
0096 CTPPSTotemDigiToRaw::CTPPSTotemDigiToRaw(const edm::ParameterSet& iConfig)
0097     : eventCounter_(0), allDigiCounter_(0), allWordCounter_(0) {
0098   //register your products
0099   tTotemRPDigi_ = consumes<edm::DetSetVector<TotemRPDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
0100   tTotemDAQMapping_ = esConsumes<TotemDAQMapping, TotemReadoutRcd>();
0101   produces<FEDRawDataCollection>();
0102 }
0103 
0104 CTPPSTotemDigiToRaw::~CTPPSTotemDigiToRaw() {
0105   edm::LogInfo("CTPPSTotemDigiToRaw") << " CTPPSTotemDigiToRaw destructor!";
0106 }
0107 
0108 //
0109 // member functions
0110 //
0111 
0112 // ------------ method called to produce the data  ------------
0113 void CTPPSTotemDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0114   using namespace edm;
0115   using namespace std;
0116   eventCounter_++;
0117 
0118   edm::Handle<edm::DetSetVector<TotemRPDigi>> digiCollection;
0119   iEvent.getByToken(tTotemRPDigi_, digiCollection);
0120 
0121   CTPPSTotemDataFormatter::RawData rawdata;
0122   CTPPSTotemDataFormatter::Digis digis;
0123 
0124   int digiCounter = 0;
0125   for (auto const& di : *digiCollection) {
0126     digiCounter += (di.data).size();
0127     digis[di.detId()] = di.data;
0128   }
0129   allDigiCounter_ += digiCounter;
0130   edm::ESHandle<TotemDAQMapping> mapping;
0131   // label of the CTPPS sub-system
0132   if (recordWatcher_.check(iSetup)) {
0133     mapping = iSetup.getHandle(tTotemDAQMapping_);
0134     for (const auto& p : mapping->VFATMapping) {
0135       //get TotemVFATInfo information
0136       fedIds_.emplace(p.first.getFEDId());
0137       CTPPSTotemDataFormatter::PPSStripIndex iDdet2fed = {(p.second.symbolicID).symbolicID,
0138                                                           p.second.hwID,
0139                                                           p.first.getFEDId(),
0140                                                           p.first.getIdxInFiber(),
0141                                                           p.first.getGOHId()};
0142       v_iDdet2fed_.emplace_back(iDdet2fed);
0143     }
0144   }
0145 
0146   CTPPSTotemDataFormatter formatter(mapping->VFATMapping);
0147 
0148   // create product (raw data)
0149   auto buffers = std::make_unique<FEDRawDataCollection>();
0150 
0151   std::sort(v_iDdet2fed_.begin(), v_iDdet2fed_.end(), CTPPSTotemDataFormatter::compare);
0152 
0153   // convert data to raw
0154   formatter.formatRawData(iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
0155 
0156   // pack raw data into collection
0157   for (auto it : fedIds_) {
0158     FEDRawData& fedRawData = buffers->FEDData(it);
0159     CTPPSTotemDataFormatter::RawData::iterator fedbuffer = rawdata.find(it);
0160     if (fedbuffer != rawdata.end())
0161       fedRawData = fedbuffer->second;
0162   }
0163   allWordCounter_ += formatter.nWords();
0164 
0165   if (debug_)
0166     LogDebug("CTPPSTotemDigiToRaw") << "Words/Digis this iEvent: " << digiCounter << "(fm:" << formatter.nDigis()
0167                                     << ")/" << formatter.nWords() << "  all: " << allDigiCounter_ << "/"
0168                                     << allWordCounter_;
0169 
0170   iEvent.put(std::move(buffers));
0171 }
0172 
0173 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0174 void CTPPSTotemDigiToRaw::beginStream(edm::StreamID) {}
0175 
0176 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0177 void CTPPSTotemDigiToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0178   edm::ParameterSetDescription desc;
0179   desc.add<edm::InputTag>("InputLabel", edm::InputTag("RPSiDetDigitizer"));
0180   descriptions.add("ctppsTotemRawData", desc);
0181 }
0182 
0183 //define this as a plug-in
0184 DEFINE_FWK_MODULE(CTPPSTotemDigiToRaw);