Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-13 23:03:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    CTPPSPixelDigiToRaw
0004 // Class:      CTPPSPixelDigiToRaw
0005 //
0006 /**\class CTPPSPixelDigiToRaw CTPPSPixelDigiToRaw.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:  Wed, 12 Sep 2018 12:59:49 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/StreamID.h"
0032 
0033 #include "DataFormats/Common/interface/Handle.h"
0034 #include "FWCore/Framework/interface/ESHandle.h"
0035 #include "FWCore/Framework/interface/ESWatcher.h"
0036 #include "FWCore/Framework/interface/EventSetup.h"
0037 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0039 #include "FWCore/Utilities/interface/ESGetToken.h"
0040 
0041 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0042 
0043 #include "FWCore/Utilities/interface/InputTag.h"
0044 
0045 #include "DataFormats/Common/interface/DetSetVector.h"
0046 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
0047 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0048 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0049 
0050 #include "EventFilter/CTPPSRawToDigi/interface/CTPPSPixelDataFormatter.h"
0051 
0052 #include "CondFormats/DataRecord/interface/CTPPSPixelDAQMappingRcd.h"
0053 #include "CondFormats/PPSObjects/interface/CTPPSPixelDAQMapping.h"
0054 #include "CondFormats/PPSObjects/interface/CTPPSPixelFramePosition.h"
0055 
0056 #include "FWCore/PluginManager/interface/ModuleDef.h"
0057 #include "FWCore/Framework/interface/MakerMacros.h"
0058 
0059 //
0060 // class declaration
0061 //
0062 
0063 class CTPPSPixelDigiToRaw : public edm::stream::EDProducer<> {
0064 public:
0065   explicit CTPPSPixelDigiToRaw(const edm::ParameterSet&);
0066   ~CTPPSPixelDigiToRaw() override;
0067 
0068   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0069 
0070 private:
0071   void produce(edm::Event&, const edm::EventSetup&) override;
0072 
0073   // ----------member data ---------------------------
0074   unsigned long eventCounter_;
0075   int allDigiCounter_;
0076   int allWordCounter_;
0077   bool debug_;
0078   std::set<unsigned int> fedIds_;
0079   std::string mappingLabel_;
0080   edm::ESWatcher<CTPPSPixelDAQMappingRcd> recordWatcher_;
0081   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelDigi>> tCTPPSPixelDigi_;
0082   edm::ESGetToken<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd> tCTPPSPixelDAQMapping_;
0083   std::vector<CTPPSPixelDataFormatter::PPSPixelIndex> v_iDdet2fed_;
0084   CTPPSPixelFramePosition fPos_;
0085   bool isRun3_;
0086 };
0087 
0088 //
0089 // constants, enums and typedefs
0090 //
0091 
0092 //
0093 // static data member definitions
0094 //
0095 
0096 //
0097 // constructors and destructor
0098 //
0099 CTPPSPixelDigiToRaw::CTPPSPixelDigiToRaw(const edm::ParameterSet& iConfig)
0100     : eventCounter_(0),
0101       allDigiCounter_(0),
0102       allWordCounter_(0),
0103       debug_(false),
0104       mappingLabel_(iConfig.getParameter<std::string>("mappingLabel")) {
0105   //register your products
0106   tCTPPSPixelDigi_ = consumes<edm::DetSetVector<CTPPSPixelDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
0107   tCTPPSPixelDAQMapping_ = esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>();
0108 
0109   // Define EDProduct type
0110   produces<FEDRawDataCollection>();
0111 
0112   isRun3_ = iConfig.getParameter<bool>("isRun3");
0113 }
0114 
0115 CTPPSPixelDigiToRaw::~CTPPSPixelDigiToRaw() {}
0116 
0117 //
0118 // member functions
0119 //
0120 
0121 // ------------ method called to produce the data  ------------
0122 void CTPPSPixelDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0123   using namespace edm;
0124   using namespace std;
0125 
0126   eventCounter_++;
0127 
0128   edm::Handle<edm::DetSetVector<CTPPSPixelDigi>> digiCollection;
0129   iEvent.getByToken(tCTPPSPixelDigi_, digiCollection);
0130 
0131   CTPPSPixelDataFormatter::RawData rawdata;
0132   CTPPSPixelDataFormatter::Digis digis;
0133 
0134   int digiCounter = 0;
0135   for (auto const& di : *digiCollection) {
0136     digiCounter += (di.data).size();
0137     digis[di.id] = di.data;
0138   }
0139   allDigiCounter_ += digiCounter;
0140   edm::ESHandle<CTPPSPixelDAQMapping> mapping;
0141 
0142   mapping = iSetup.getHandle(tCTPPSPixelDAQMapping_);
0143   for (const auto& p : mapping->ROCMapping)
0144     v_iDdet2fed_.emplace_back(CTPPSPixelDataFormatter::PPSPixelIndex{
0145         p.second.iD, p.second.roc, p.first.getROC(), p.first.getFEDId(), p.first.getChannelIdx()});
0146   fedIds_ = mapping->fedIds();
0147 
0148   CTPPSPixelDataFormatter formatter(mapping->ROCMapping);
0149 
0150   // create product (raw data)
0151   auto buffers = std::make_unique<FEDRawDataCollection>();
0152 
0153   std::sort(v_iDdet2fed_.begin(), v_iDdet2fed_.end(), CTPPSPixelDataFormatter::compare);
0154 
0155   // convert data to raw
0156   formatter.formatRawData(isRun3_, iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
0157 
0158   // pack raw data into collection
0159   for (auto it = fedIds_.begin(); it != fedIds_.end(); it++) {
0160     FEDRawData& fedRawData = buffers->FEDData(*it);
0161     CTPPSPixelDataFormatter::RawData::iterator fedbuffer = rawdata.find(*it);
0162     if (fedbuffer != rawdata.end())
0163       fedRawData = fedbuffer->second;
0164   }
0165   allWordCounter_ += formatter.nWords();
0166 
0167   if (debug_)
0168     LogDebug("CTPPSPixelDigiToRaw") << "Words/Digis this iEvent: " << digiCounter << "(fm:" << formatter.nDigis()
0169                                     << ")/" << formatter.nWords() << "  all: " << allDigiCounter_ << "/"
0170                                     << allWordCounter_;
0171 
0172   iEvent.put(std::move(buffers));
0173 }
0174 
0175 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0176 void CTPPSPixelDigiToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0177   edm::ParameterSetDescription desc;
0178   desc.add<bool>("isRun3", true);
0179   desc.add<edm::InputTag>("InputLabel", edm::InputTag("RPixDetDigitizer"));
0180   desc.add<std::string>("mappingLabel", "RPix");
0181   descriptions.add("ctppsPixelRawData", desc);
0182 }
0183 
0184 //define this as a plug-in
0185 DEFINE_FWK_MODULE(CTPPSPixelDigiToRaw);