Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:00:04

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalFEDWithCRCErrorProducer
0004 // Class:      EcalFEDWithCRCErrorProducer
0005 //
0006 /**\class EcalFEDWithCRCErrorProducer EcalFEDWithCRCErrorProducer.cc filter/EcalFEDWithCRCErrorProducer/src/EcalFEDWithCRCErrorProducer.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Giovanni FRANZONI
0015 //         Created:  Tue Jan 22 13:55:00 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   // ----------member data ---------------------------
0053 
0054   edm::EDGetTokenT<FEDRawDataCollection> DataToken_;
0055   std::vector<int> fedUnpackList_;
0056   bool writeAllEcalFEDs_;
0057 };
0058 
0059 //
0060 // constructors and destructor
0061 //
0062 EcalFEDWithCRCErrorProducer::EcalFEDWithCRCErrorProducer(const edm::ParameterSet& iConfig) {
0063   //now do what ever initialization is needed
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   // do anything here that needs to be done at desctruction time
0077   // (e.g. close files, deallocate resources etc.)
0078 }
0079 
0080 //
0081 // member functions
0082 //
0083 
0084 // ------------ method called on each new Event  ------------
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   // get fed raw data and SM id
0092 
0093   // loop over FEDS
0094   for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
0095     // get fed raw data and SM id
0096     const FEDRawData& fedData = rawdata->FEDData(*i);
0097     int length = fedData.size() / sizeof(uint64_t);
0098 
0099     //    LogDebug("EcalRawToDigi") << "raw data length: " << length ;
0100     //if data size is not null interpret data
0101     if (length >= 1) {
0102       uint64_t* pData = (uint64_t*)(fedData.data());
0103       //When crc error is found return true
0104       uint64_t* fedTrailer = pData + (length - 1);
0105       bool crcError = (*fedTrailer >> 2) & 0x1;
0106       // this fed has data -- lets copy it
0107       if (writeAllEcalFEDs_ || crcError) {
0108         FEDRawData& fedDataProd = producedData->FEDData(*i);
0109         if (fedDataProd.size() != 0) {
0110           //                edm::LogVerbatim("EcalTools") << " More than one FEDRawDataCollection with data in FED ";
0111           //                                              << j << " Skipping the 2nd";
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 //define this as a plug-in
0128 DEFINE_FWK_MODULE(EcalFEDWithCRCErrorProducer);