File indexing completed on 2024-04-06 12:10:56
0001 #include "DataFormats/Common/interface/DetSet.h"
0002 #include "DataFormats/Common/interface/Handle.h"
0003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0004 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerCommissioningDigi.h"
0005 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDBuffer.h"
0006 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDHeader.h"
0007 #include "EventFilter/Phase2TrackerRawToDigi/interface/utils.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014
0015 namespace Phase2Tracker {
0016
0017 class Phase2TrackerCommissioningDigiProducer : public edm::global::EDProducer<> {
0018 public:
0019
0020 Phase2TrackerCommissioningDigiProducer(const edm::ParameterSet& pset);
0021
0022 ~Phase2TrackerCommissioningDigiProducer() override = default;
0023 void produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const override;
0024
0025 private:
0026 edm::EDGetTokenT<FEDRawDataCollection> token_;
0027 };
0028 }
0029
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 typedef Phase2Tracker::Phase2TrackerCommissioningDigiProducer Phase2TrackerCommissioningDigiProducer;
0032 DEFINE_FWK_MODULE(Phase2TrackerCommissioningDigiProducer);
0033
0034 using namespace std;
0035
0036 Phase2Tracker::Phase2TrackerCommissioningDigiProducer::Phase2TrackerCommissioningDigiProducer(
0037 const edm::ParameterSet& pset) {
0038 produces<edm::DetSet<Phase2TrackerCommissioningDigi>>("ConditionData");
0039 token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
0040 }
0041
0042 void Phase2Tracker::Phase2TrackerCommissioningDigiProducer::produce(edm::StreamID,
0043 edm::Event& event,
0044 const edm::EventSetup& es) const {
0045
0046 edm::Handle<FEDRawDataCollection> buffers;
0047 event.getByToken(token_, buffers);
0048
0049
0050 size_t fedIndex;
0051 for (fedIndex = 0; fedIndex <= Phase2Tracker::CMS_FED_ID_MAX; ++fedIndex) {
0052 const FEDRawData& fed = buffers->FEDData(fedIndex);
0053 if (fed.size() != 0 && fedIndex >= Phase2Tracker::FED_ID_MIN && fedIndex <= Phase2Tracker::FED_ID_MAX) {
0054
0055 Phase2Tracker::Phase2TrackerFEDBuffer* buffer = nullptr;
0056 buffer = new Phase2Tracker::Phase2TrackerFEDBuffer(fed.data(), fed.size());
0057
0058
0059 std::map<uint32_t, uint32_t> cond_data = buffer->conditionData();
0060 delete buffer;
0061
0062
0063 LogTrace("Phase2TrackerCommissioningDigiProducer") << "--- Condition data debug ---" << std::endl;
0064 std::map<uint32_t, uint32_t>::const_iterator it;
0065 for (it = cond_data.begin(); it != cond_data.end(); it++) {
0066 LogTrace("Phase2TrackerCommissioningDigiProducer")
0067 << std::hex << "key: " << it->first << std::hex << " value: " << it->second << " (hex) " << std::dec
0068 << it->second << " (dec) " << std::endl;
0069 }
0070 LogTrace("Phase2TrackerCommissioningDigiProducer") << "----------------------------" << std::endl;
0071
0072 edm::DetSet<Phase2TrackerCommissioningDigi>* cond_data_digi =
0073 new edm::DetSet<Phase2TrackerCommissioningDigi>(fedIndex);
0074 for (it = cond_data.begin(); it != cond_data.end(); it++) {
0075 cond_data_digi->push_back(Phase2TrackerCommissioningDigi(it->first, it->second));
0076 }
0077 std::unique_ptr<edm::DetSet<Phase2TrackerCommissioningDigi>> cdd(cond_data_digi);
0078 event.put(std::move(cdd), "ConditionData");
0079 }
0080 }
0081 }