Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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