Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:00:17

0001 #include <memory>
0002 
0003 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
0004 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0005 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0006 #include "DataFormats/Common/interface/DetSetVector.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/DetId/interface/DetIdCollection.h"
0009 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0010 #include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h"
0011 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0012 #include "DataFormats/SiPixelRawData/interface/SiPixelErrorsSoA.h"
0013 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
0014 #include "FWCore/Framework/interface/ESTransientHandle.h"
0015 #include "FWCore/Framework/interface/ESWatcher.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Framework/interface/stream/EDProducer.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 
0024 class SiPixelDigiErrorsFromSoA : public edm::stream::EDProducer<> {
0025 public:
0026   explicit SiPixelDigiErrorsFromSoA(const edm::ParameterSet& iConfig);
0027   ~SiPixelDigiErrorsFromSoA() override = default;
0028 
0029   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0030 
0031 private:
0032   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0033 
0034   const edm::ESGetToken<SiPixelFedCablingMap, SiPixelFedCablingMapRcd> cablingToken_;
0035   const edm::EDGetTokenT<SiPixelErrorsSoA> digiErrorSoAGetToken_;
0036   const edm::EDPutTokenT<edm::DetSetVector<SiPixelRawDataError>> errorPutToken_;
0037   const edm::EDPutTokenT<DetIdCollection> tkErrorPutToken_;
0038   const edm::EDPutTokenT<DetIdCollection> userErrorPutToken_;
0039   const edm::EDPutTokenT<edmNew::DetSetVector<PixelFEDChannel>> disabledChannelPutToken_;
0040 
0041   edm::ESWatcher<SiPixelFedCablingMapRcd> cablingWatcher_;
0042   std::unique_ptr<SiPixelFedCablingTree> cabling_;
0043 
0044   const std::vector<int> tkerrorlist_;
0045   const std::vector<int> usererrorlist_;
0046 
0047   const bool usePhase1_;
0048 };
0049 
0050 SiPixelDigiErrorsFromSoA::SiPixelDigiErrorsFromSoA(const edm::ParameterSet& iConfig)
0051     : cablingToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
0052       digiErrorSoAGetToken_{consumes<SiPixelErrorsSoA>(iConfig.getParameter<edm::InputTag>("digiErrorSoASrc"))},
0053       errorPutToken_{produces<edm::DetSetVector<SiPixelRawDataError>>()},
0054       tkErrorPutToken_{produces<DetIdCollection>()},
0055       userErrorPutToken_{produces<DetIdCollection>("UserErrorModules")},
0056       disabledChannelPutToken_{produces<edmNew::DetSetVector<PixelFEDChannel>>()},
0057       tkerrorlist_(iConfig.getParameter<std::vector<int>>("ErrorList")),
0058       usererrorlist_(iConfig.getParameter<std::vector<int>>("UserErrorList")),
0059       usePhase1_(iConfig.getParameter<bool>("UsePhase1")) {}
0060 
0061 void SiPixelDigiErrorsFromSoA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0062   edm::ParameterSetDescription desc;
0063   desc.add<edm::InputTag>("digiErrorSoASrc", edm::InputTag("siPixelDigiErrorsSoA"));
0064   // the configuration parameters here are named following those in SiPixelRawToDigi
0065   desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label");
0066   desc.add<bool>("UsePhase1", false)->setComment("##  Use phase1");
0067   desc.add<std::vector<int>>("ErrorList", std::vector<int>{29})
0068       ->setComment("## ErrorList: list of error codes used by tracking to invalidate modules");
0069   desc.add<std::vector<int>>("UserErrorList", std::vector<int>{40})
0070       ->setComment("## UserErrorList: list of error codes used by Pixel experts for investigation");
0071   descriptions.addWithDefaultLabel(desc);
0072 }
0073 
0074 void SiPixelDigiErrorsFromSoA::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075   // pack errors into collection
0076 
0077   // initialize cabling map or update if necessary
0078   if (cablingWatcher_.check(iSetup)) {
0079     // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
0080     const SiPixelFedCablingMap* cablingMap = &iSetup.getData(cablingToken_);
0081     cabling_ = cablingMap->cablingTree();
0082     LogDebug("map version:") << cabling_->version();
0083   }
0084 
0085   const auto& digiErrors = iEvent.get(digiErrorSoAGetToken_);
0086 
0087   edm::DetSetVector<SiPixelRawDataError> errorcollection{};
0088   DetIdCollection tkerror_detidcollection{};
0089   DetIdCollection usererror_detidcollection{};
0090   edmNew::DetSetVector<PixelFEDChannel> disabled_channelcollection{};
0091 
0092   PixelDataFormatter formatter(cabling_.get(), usePhase1_);  // for phase 1 & 0
0093   const PixelDataFormatter::Errors* formatterErrors = digiErrors.formatterErrors();
0094   assert(formatterErrors != nullptr);
0095   auto errors = *formatterErrors;  // make a copy
0096   PixelDataFormatter::DetErrors nodeterrors;
0097 
0098   auto size = digiErrors.size();
0099   for (auto i = 0U; i < size; i++) {
0100     SiPixelErrorCompact err = digiErrors.error(i);
0101     if (err.errorType != 0) {
0102       SiPixelRawDataError error(err.word, err.errorType, err.fedId + FEDNumbering::MINSiPixeluTCAFEDID);
0103       errors[err.rawId].push_back(error);
0104     }
0105   }
0106 
0107   formatter.unpackFEDErrors(errors,
0108                             tkerrorlist_,
0109                             usererrorlist_,
0110                             errorcollection,
0111                             tkerror_detidcollection,
0112                             usererror_detidcollection,
0113                             disabled_channelcollection,
0114                             nodeterrors);
0115 
0116   const uint32_t dummydetid = 0xffffffff;
0117   edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection.find_or_insert(dummydetid);
0118   errorDetSet.data = nodeterrors;
0119 
0120   iEvent.emplace(errorPutToken_, std::move(errorcollection));
0121   iEvent.emplace(tkErrorPutToken_, std::move(tkerror_detidcollection));
0122   iEvent.emplace(userErrorPutToken_, std::move(usererror_detidcollection));
0123   iEvent.emplace(disabledChannelPutToken_, std::move(disabled_channelcollection));
0124 }
0125 
0126 DEFINE_FWK_MODULE(SiPixelDigiErrorsFromSoA);