File indexing completed on 2024-04-06 12:10:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
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
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
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
0092
0093
0094
0095
0096
0097
0098
0099
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
0109 tCTPPSPixelDigi_ = consumes<edm::DetSetVector<CTPPSPixelDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
0110 tCTPPSPixelDAQMapping_ = esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>();
0111
0112
0113 produces<FEDRawDataCollection>();
0114
0115 isRun3_ = iConfig.getParameter<bool>("isRun3");
0116 }
0117
0118 CTPPSPixelDigiToRaw::~CTPPSPixelDigiToRaw() {}
0119
0120
0121
0122
0123
0124
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
0154 auto buffers = std::make_unique<FEDRawDataCollection>();
0155
0156 std::sort(v_iDdet2fed_.begin(), v_iDdet2fed_.end(), CTPPSPixelDataFormatter::compare);
0157
0158
0159 formatter.formatRawData(isRun3_, iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
0160
0161
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
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
0188 DEFINE_FWK_MODULE(CTPPSPixelDigiToRaw);