File indexing completed on 2024-04-06 12:00:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/Utilities/interface/InputTag.h"
0030 #include "FWCore/Framework/interface/one/EDProducer.h"
0031
0032 #include <string>
0033 #include <iostream>
0034 #include <vector>
0035 #include <iomanip>
0036
0037 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0038 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
0039 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0040
0041
0042
0043
0044 class EcalFEDWithCRCErrorProducer : public edm::one::EDProducer<> {
0045 public:
0046 explicit EcalFEDWithCRCErrorProducer(const edm::ParameterSet&);
0047 ~EcalFEDWithCRCErrorProducer() override;
0048
0049 private:
0050 void produce(edm::Event&, const edm::EventSetup&) override;
0051
0052
0053
0054 edm::EDGetTokenT<FEDRawDataCollection> DataToken_;
0055 std::vector<int> fedUnpackList_;
0056 bool writeAllEcalFEDs_;
0057 };
0058
0059
0060
0061
0062 EcalFEDWithCRCErrorProducer::EcalFEDWithCRCErrorProducer(const edm::ParameterSet& iConfig) {
0063
0064
0065 DataToken_ = consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("InputLabel"));
0066 fedUnpackList_ = iConfig.getUntrackedParameter<std::vector<int> >("FEDs", std::vector<int>());
0067 writeAllEcalFEDs_ = iConfig.getUntrackedParameter<bool>("writeAllEcalFED", false);
0068 if (fedUnpackList_.empty())
0069 for (int i = FEDNumbering::MINECALFEDID; i <= FEDNumbering::MAXECALFEDID; i++)
0070 fedUnpackList_.push_back(i);
0071
0072 produces<FEDRawDataCollection>();
0073 }
0074
0075 EcalFEDWithCRCErrorProducer::~EcalFEDWithCRCErrorProducer() {
0076
0077
0078 }
0079
0080
0081
0082
0083
0084
0085 void EcalFEDWithCRCErrorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0086 using namespace edm;
0087
0088 const edm::Handle<FEDRawDataCollection>& rawdata = iEvent.getHandle(DataToken_);
0089
0090 auto producedData = std::make_unique<FEDRawDataCollection>();
0091
0092
0093
0094 for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
0095
0096 const FEDRawData& fedData = rawdata->FEDData(*i);
0097 int length = fedData.size() / sizeof(uint64_t);
0098
0099
0100
0101 if (length >= 1) {
0102 uint64_t* pData = (uint64_t*)(fedData.data());
0103
0104 uint64_t* fedTrailer = pData + (length - 1);
0105 bool crcError = (*fedTrailer >> 2) & 0x1;
0106
0107 if (writeAllEcalFEDs_ || crcError) {
0108 FEDRawData& fedDataProd = producedData->FEDData(*i);
0109 if (fedDataProd.size() != 0) {
0110
0111
0112 continue;
0113 }
0114 fedDataProd.resize(fedData.size());
0115 unsigned char* dataProd = fedDataProd.data();
0116 const unsigned char* data = fedData.data();
0117 for (unsigned int k = 0; k < fedData.size(); ++k) {
0118 dataProd[k] = data[k];
0119 }
0120 }
0121 }
0122 }
0123
0124 iEvent.put(std::move(producedData));
0125 }
0126
0127
0128 DEFINE_FWK_MODULE(EcalFEDWithCRCErrorProducer);