Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // user include files
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/global/EDProducer.h"
0004 
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 
0011 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0012 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0013 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0014 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
0015 #include "EventFilter/HcalRawToDigi/interface/HcalFEDList.h"
0016 
0017 class HcalCalibFEDSelector : public edm::global::EDProducer<> {
0018 public:
0019   HcalCalibFEDSelector(const edm::ParameterSet&);
0020 
0021 private:
0022   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0023 
0024   // ----------member data ---------------------------
0025   edm::EDGetTokenT<FEDRawDataCollection> tok_fed_;
0026   std::vector<int> extraFEDs_;
0027 };
0028 
0029 HcalCalibFEDSelector::HcalCalibFEDSelector(const edm::ParameterSet& iConfig) {
0030   tok_fed_ = consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("rawInputLabel"));
0031   extraFEDs_ = iConfig.getParameter<std::vector<int> >("extraFEDsToKeep");
0032   produces<FEDRawDataCollection>();
0033 }
0034 
0035 void HcalCalibFEDSelector::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0036   auto producedData = std::make_unique<FEDRawDataCollection>();
0037 
0038   edm::Handle<FEDRawDataCollection> rawIn;
0039   iEvent.getByToken(tok_fed_, rawIn);
0040 
0041   std::vector<int> selFEDs;
0042 
0043   //--- Get the list of FEDs to be kept ---//
0044   int calibType = -1;
0045   for (int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++) {
0046     const FEDRawData& fedData = rawIn->FEDData(i);
0047     if (fedData.size() < 24)
0048       continue;  // FED is empty
0049     int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType();
0050     if (calibType < 0) {
0051       calibType = value;
0052     } else {
0053       if (calibType != value)
0054         edm::LogWarning("HcalCalibFEDSelector") << "Conflicting calibration types found: " << calibType << " vs. "
0055                                                 << value << ".  Staying with " << calibType;
0056     }
0057   }
0058 
0059   HcalFEDList calibFeds(calibType);
0060   selFEDs = calibFeds.getListOfFEDs();
0061   for (unsigned int i = 0; i < extraFEDs_.size(); i++) {
0062     bool duplicate = false;
0063     for (unsigned int j = 0; j < selFEDs.size(); j++) {
0064       if (extraFEDs_.at(i) == selFEDs.at(j)) {
0065         duplicate = true;
0066         break;
0067       }
0068     }
0069     if (!duplicate)
0070       selFEDs.push_back(extraFEDs_.at(i));
0071   }
0072 
0073   // Copying:
0074   const FEDRawDataCollection* rdc = rawIn.product();
0075 
0076   for (int j = 0; j <= FEDNumbering::lastFEDId(); ++j) {
0077     bool rightFED = false;
0078     for (uint32_t k = 0; k < selFEDs.size(); k++) {
0079       if (j == selFEDs[k]) {
0080         rightFED = true;
0081       }
0082     }
0083     if (!rightFED)
0084       continue;
0085     const FEDRawData& fedData = rdc->FEDData(j);
0086     size_t size = fedData.size();
0087 
0088     if (size > 0) {
0089       // this fed has data -- lets copy it
0090       FEDRawData& fedDataProd = producedData->FEDData(j);
0091       if (fedDataProd.size() != 0) {
0092         continue;
0093       }
0094       fedDataProd.resize(size);
0095       unsigned char* dataProd = fedDataProd.data();
0096       const unsigned char* data = fedData.data();
0097       // memcpy is at-least-as-fast as assignment and can be much faster
0098       memcpy(dataProd, data, size);
0099     }
0100   }
0101 
0102   iEvent.put(std::move(producedData));
0103 }
0104 
0105 DEFINE_FWK_MODULE(HcalCalibFEDSelector);