diff --git a/EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h b/EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h index 189763dc6fd46..cd5b02c5d848c 100644 --- a/EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h +++ b/EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h @@ -37,7 +37,7 @@ #include "DataFormats/SiPixelDigi/interface/PixelDigi.h" #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h" -#include "DataFormats/Common/interface/DetSetVector.h" +#include "DataFormats/DetId/interface/DetIdCollection.h" #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h" #include "EventFilter/SiPixelRawToDigi/interface/ErrorCheckerPhase0.h" #include "FWCore/Utilities/interface/typedefs.h" @@ -70,7 +70,7 @@ class PixelDataFormatter { typedef cms_uint32_t Word32; typedef cms_uint64_t Word64; - PixelDataFormatter(const SiPixelFedCabling* map, bool phase1 = false); + PixelDataFormatter(const SiPixelFedCablingTree* map, bool phase1 = false); void setErrorStatus(bool ErrorStatus); void setQualityStatus(bool QualityStatus, const SiPixelQuality* QualityInfo); @@ -84,20 +84,28 @@ class PixelDataFormatter { void formatRawData(unsigned int lvl1_ID, RawData& fedRawData, const Digis& digis, const BadChannels& badChannels); - cms_uint32_t linkId(cms_uint32_t word32) { return (word32 >> LINK_shift) & LINK_mask; } + void unpackFEDErrors(Errors const& errors, + std::vector const& tkerrorlist, + std::vector const& usererrorlist, + edm::DetSetVector& errorcollection, + DetIdCollection& tkerror_detidcollection, + DetIdCollection& usererror_detidcollection, + edmNew::DetSetVector& disabled_channelcollection, + DetErrors& nodeterrors); + + cms_uint32_t getLinkId(cms_uint32_t word32) { return (word32 >> LINK_shift) & LINK_mask; } private: mutable int theDigiCounter; mutable int theWordCounter; - SiPixelFedCabling const* theCablingTree; + SiPixelFedCablingTree const* theCablingTree; const SiPixelFrameReverter* theFrameReverter; const SiPixelQuality* badPixelInfo; const std::set* modulesToUnpack; bool includeErrors; bool useQualityInfo; - bool debug; int allDetDigis; int hasDetDigis; std::unique_ptr errorcheck; @@ -116,13 +124,6 @@ class PixelDataFormatter { const PixelDigi& digi, std::map >& words) const; - int word2digi(const int fedId, - const SiPixelFrameConverter* converter, - const bool includeError, - const bool useQuality, - const Word32& word, - Digis& digis) const; - std::string print(const PixelDigi& digi) const; std::string print(const Word64& word) const; diff --git a/EventFilter/SiPixelRawToDigi/plugins/SiPixelDigiErrorsFromSoA.cc b/EventFilter/SiPixelRawToDigi/plugins/SiPixelDigiErrorsFromSoA.cc index d09e703c36a00..9e2bf3d5820e9 100644 --- a/EventFilter/SiPixelRawToDigi/plugins/SiPixelDigiErrorsFromSoA.cc +++ b/EventFilter/SiPixelRawToDigi/plugins/SiPixelDigiErrorsFromSoA.cc @@ -104,72 +104,16 @@ void SiPixelDigiErrorsFromSoA::produce(edm::Event& iEvent, const edm::EventSetup } } - constexpr uint32_t dummydetid = 0xffffffff; - typedef PixelDataFormatter::Errors::iterator IE; - for (auto& error : errors) { - uint32_t errordetid = error.first; - if (errordetid == dummydetid) { // errors given dummy detId must be sorted by Fed - nodeterrors.insert(nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end()); - } else { - edm::DetSet& errorDetSet = errorcollection.find_or_insert(errordetid); - errorDetSet.data.insert(errorDetSet.data.end(), error.second.begin(), error.second.end()); - // Fill detid of the detectors where there is error AND the error number is listed - // in the configurable error list in the job option cfi. - // Code needs to be here, because there can be a set of errors for each - // entry in the for loop over PixelDataFormatter::Errors - - std::vector disabledChannelsDetSet; - - for (auto const& aPixelError : errorDetSet) { - // For the time being, we extend the error handling functionality with ErrorType 25 - // In the future, we should sort out how the usage of tkerrorlist can be generalized - if (aPixelError.getType() == 25) { - int fedId = aPixelError.getFedId(); - const sipixelobjects::PixelFEDCabling* fed = cabling_->fed(fedId); - if (fed) { - cms_uint32_t linkId = formatter.linkId(aPixelError.getWord32()); - const sipixelobjects::PixelFEDLink* link = fed->link(linkId); - if (link) { - // The "offline" 0..15 numbering is fixed by definition, also, the FrameConversion depends on it - // in contrast, the ROC-in-channel numbering is determined by hardware --> better to use the "offline" scheme - PixelFEDChannel ch = {fed->id(), linkId, 25, 0}; - for (unsigned int iRoc = 1; iRoc <= link->numberOfROCs(); iRoc++) { - const sipixelobjects::PixelROC* roc = link->roc(iRoc); - if (roc->idInDetUnit() < ch.roc_first) - ch.roc_first = roc->idInDetUnit(); - if (roc->idInDetUnit() > ch.roc_last) - ch.roc_last = roc->idInDetUnit(); - } - disabledChannelsDetSet.push_back(ch); - } - } - } else { - // fill list of detIds to be turned off by tracking - if (!tkerrorlist_.empty()) { - auto it_find = std::find(tkerrorlist_.begin(), tkerrorlist_.end(), aPixelError.getType()); - if (it_find != tkerrorlist_.end()) { - tkerror_detidcollection.push_back(errordetid); - } - } - } - - // fill list of detIds with errors to be studied - if (!usererrorlist_.empty()) { - auto it_find = std::find(usererrorlist_.begin(), usererrorlist_.end(), aPixelError.getType()); - if (it_find != usererrorlist_.end()) { - usererror_detidcollection.push_back(errordetid); - } - } - - } // loop on DetSet of errors - - if (!disabledChannelsDetSet.empty()) { - disabled_channelcollection.insert(errordetid, disabledChannelsDetSet.data(), disabledChannelsDetSet.size()); - } - - } // if error assigned to a real DetId - } // loop on errors in event for this FED - + formatter.unpackFEDErrors(errors, + tkerrorlist_, + usererrorlist_, + errorcollection, + tkerror_detidcollection, + usererror_detidcollection, + disabled_channelcollection, + nodeterrors); + + const uint32_t dummydetid = 0xffffffff; edm::DetSet& errorDetSet = errorcollection.find_or_insert(dummydetid); errorDetSet.data = nodeterrors; diff --git a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc index 93d3f023d44e8..ffe3b246782e6 100644 --- a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc +++ b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.cc @@ -1,13 +1,11 @@ // Skip FED40 pilot-blade // Include parameter driven interface to SiPixelQuality for study purposes // exclude ROC(raw) based on bad ROC list in SiPixelQuality -// enabled by: process.siPixelDigis.UseQualityInfo = True (BY DEFAULT NOT USED) +// enabled by: process.siPixelDigis.useQualityInfo = True (BY DEFAULT NOT USED) // 20-10-2010 Andrew York (Tennessee) // Jan 2016 Tamas Almos Vami (Tav) (Wigner RCP) -- Cabling Map label option // Jul 2017 Viktor Veszpremi -- added PixelFEDChannel -#include "SiPixelRawToDigi.h" - #include #include "DataFormats/Common/interface/Handle.h" @@ -16,55 +14,106 @@ #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/ESGetToken.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" - -#include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h" +#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h" +#include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" +#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h" #include "DataFormats/Common/interface/DetSetVector.h" -#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/DetId/interface/DetIdCollection.h" #include "DataFormats/FEDRawData/interface/FEDRawData.h" +#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" +#include "DataFormats/SiPixelDigi/interface/PixelDigi.h" +#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" +#include "DataFormats/SiPixelRawData/interface/SiPixelRawDataError.h" -#include "DataFormats/FEDRawData/interface/FEDNumbering.h" -#include "DataFormats/DetId/interface/DetIdCollection.h" -#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h" #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h" - -#include "DataFormats/SiPixelDetId/interface/PixelFEDChannel.h" #include "EventFilter/SiPixelRawToDigi/interface/PixelUnpackingRegions.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" -#include "TH1D.h" -#include "TFile.h" - -using namespace std; +/** \class SiPixelRawToDigi + * Plug-in module that performs Raw data to digi conversion + * for pixel subdetector + */ + +class SiPixelRawToDigi : public edm::stream::EDProducer<> { +public: + /// ctor + explicit SiPixelRawToDigi(const edm::ParameterSet&); + + /// dtor + ~SiPixelRawToDigi() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + /// get data, convert to digis attach againe to Event + void produce(edm::Event&, const edm::EventSetup&) override; + +private: + edm::ParameterSet config_; + std::unique_ptr cabling_; + const SiPixelQuality* badPixelInfo_; + PixelUnpackingRegions* regions_; + const std::vector tkerrorlist_; + const std::vector usererrorlist_; + std::vector fedIds_; + edm::ESWatcher recordWatcher_; + edm::ESWatcher qualityWatcher_; + // always consumed + const edm::EDGetTokenT fedRawDataCollectionToken_; + const edm::ESGetToken cablingMapToken_; + // consume only if pixel quality is used -> useQuality_ + edm::ESGetToken siPixelQualityToken_; + // always produced + const edm::EDPutTokenT> siPixelDigiCollectionToken_; + // produce only if error collections are included -> includeErrors_ + edm::EDPutTokenT> errorPutToken_; + edm::EDPutTokenT tkErrorPutToken_; + edm::EDPutTokenT userErrorPutToken_; + edm::EDPutTokenT> disabledChannelPutToken_; + const bool includeErrors_; + const bool useQuality_; + const bool usePilotBlade_; + const bool usePhase1_; +}; // ----------------------------------------------------------------------------- SiPixelRawToDigi::SiPixelRawToDigi(const edm::ParameterSet& conf) - : config_(conf), badPixelInfo_(nullptr), regions_(nullptr), hCPU(nullptr), hDigi(nullptr) { - includeErrors = config_.getParameter("IncludeErrors"); - useQuality = config_.getParameter("UseQualityInfo"); - - tkerrorlist = config_.getParameter>("ErrorList"); - usererrorlist = config_.getParameter>("UserErrorList"); - - tFEDRawDataCollection = consumes(config_.getParameter("InputLabel")); - if (useQuality) { - tSiPixelQuality = esConsumes(); + : config_(conf), + badPixelInfo_(nullptr), + regions_(nullptr), + tkerrorlist_(config_.getParameter>("ErrorList")), + usererrorlist_(config_.getParameter>("UserErrorList")), + fedRawDataCollectionToken_{consumes(config_.getParameter("InputLabel"))}, + cablingMapToken_{esConsumes( + edm::ESInputTag("", config_.getParameter("CablingMapLabel")))}, + siPixelDigiCollectionToken_{produces>()}, + includeErrors_(config_.getParameter("IncludeErrors")), + useQuality_(config_.getParameter("UseQualityInfo")), + usePilotBlade_(config_.getParameter("UsePilotBlade")), + usePhase1_(config_.getParameter("UsePhase1")) + +{ + if (useQuality_) { + siPixelQualityToken_ = esConsumes(); } - //start counters - ndigis = 0; - nwords = 0; - // Products - produces>(); - if (includeErrors) { - produces>(); - produces(); - produces("UserErrorModules"); - produces>(); + if (includeErrors_) { + errorPutToken_ = produces>(); + tkErrorPutToken_ = produces(); + userErrorPutToken_ = produces("UserErrorModules"); + disabledChannelPutToken_ = produces>(); } // regions @@ -72,41 +121,20 @@ SiPixelRawToDigi::SiPixelRawToDigi(const edm::ParameterSet& conf) regions_ = new PixelUnpackingRegions(config_, consumesCollector()); } - // Timing - bool timing = config_.getUntrackedParameter("Timing", false); - if (timing) { - theTimer = std::make_unique(); - hCPU = new TH1D("hCPU", "hCPU", 100, 0., 0.050); - hDigi = new TH1D("hDigi", "hDigi", 50, 0., 15000.); - } - // Control the usage of pilot-blade data, FED=40 - usePilotBlade = config_.getParameter("UsePilotBlade"); - if (usePilotBlade) + if (usePilotBlade_) edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)"; // Control the usage of phase1 - usePhase1 = config_.getParameter("UsePhase1"); - if (usePhase1) + if (usePhase1_) edm::LogInfo("SiPixelRawToDigi") << " Using phase1"; - - //CablingMap could have a label //Tav - cablingMapLabel = config_.getParameter("CablingMapLabel"); - tCablingMap = esConsumes(edm::ESInputTag("", cablingMapLabel)); } // ----------------------------------------------------------------------------- SiPixelRawToDigi::~SiPixelRawToDigi() { edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!"; - if (regions_) delete regions_; - - if (theTimer) { - TFile rootFile("analysis.root", "RECREATE", "my histograms"); - hCPU->Write(); - hDigi->Write(); - } } void SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -114,17 +142,11 @@ void SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descript desc.add("IncludeErrors", true); desc.add("UseQualityInfo", false); { - std::vector temp1; - temp1.reserve(1); - temp1.push_back(29); - desc.add>("ErrorList", temp1) + desc.add>("ErrorList", std::vector{29}) ->setComment("## ErrorList: list of error codes used by tracking to invalidate modules"); } { - std::vector temp1; - temp1.reserve(1); - temp1.push_back(40); - desc.add>("UserErrorList", temp1) + desc.add>("UserErrorList", std::vector{40}) ->setComment("## UserErrorList: list of error codes used by Pixel experts for investigation"); } desc.add("InputLabel", edm::InputTag("siPixelRawData")); @@ -137,11 +159,9 @@ void SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descript desc.add("Regions", psd0) ->setComment("## Empty Regions PSet means complete unpacking"); } - desc.addUntracked("Timing", false); desc.add("UsePilotBlade", false)->setComment("## Use pilot blades"); desc.add("UsePhase1", false)->setComment("## Use phase1"); desc.add("CablingMapLabel", "")->setComment("CablingMap label"); //Tav - desc.addOptional("CheckPixelOrder"); // never used, kept for back-compatibility descriptions.add("siPixelRawToDigi", desc); } @@ -150,47 +170,43 @@ void SiPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descript // ----------------------------------------------------------------------------- void SiPixelRawToDigi::produce(edm::Event& ev, const edm::EventSetup& es) { const uint32_t dummydetid = 0xffffffff; - debug = edm::MessageDrop::instance()->debugEnabled; // initialize cabling map or update if necessary - if (recordWatcher.check(es)) { + if (recordWatcher_.check(es)) { // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel) - edm::ESHandle cablingMap = es.getHandle(tCablingMap); - fedIds = cablingMap->fedIds(); + edm::ESHandle cablingMap = es.getHandle(cablingMapToken_); + fedIds_ = cablingMap->fedIds(); cabling_ = cablingMap->cablingTree(); LogDebug("map version:") << cabling_->version(); } // initialize quality record or update if necessary - if (qualityWatcher.check(es) && useQuality) { + if (qualityWatcher_.check(es) && useQuality_) { // quality info for dead pixel modules or ROCs - edm::ESHandle qualityInfo = es.getHandle(tSiPixelQuality); + edm::ESHandle qualityInfo = es.getHandle(siPixelQualityToken_); badPixelInfo_ = qualityInfo.product(); if (!badPixelInfo_) { - edm::LogError("SiPixelQualityNotPresent") - << " Configured to use SiPixelQuality, but SiPixelQuality not present" << endl; + edm::LogError("SiPixelQualityNotPresent") << "Configured to use SiPixelQuality, but SiPixelQuality not present"; } } edm::Handle buffers; - ev.getByToken(tFEDRawDataCollection, buffers); + ev.getByToken(fedRawDataCollectionToken_, buffers); // create product (digis & errors) - auto collection = std::make_unique>(); + auto collection = edm::DetSetVector(); // collection->reserve(8*1024); - auto errorcollection = std::make_unique>(); - auto tkerror_detidcollection = std::make_unique(); - auto usererror_detidcollection = std::make_unique(); - auto disabled_channelcollection = std::make_unique>(); + auto errorcollection = edm::DetSetVector{}; + auto tkerror_detidcollection = DetIdCollection{}; + auto usererror_detidcollection = DetIdCollection{}; + auto disabled_channelcollection = edmNew::DetSetVector{}; - PixelDataFormatter formatter(cabling_.get(), usePhase1); // for phase 1 & 0 + PixelDataFormatter formatter(cabling_.get(), usePhase1_); // for phase 1 & 0 - formatter.setErrorStatus(includeErrors); + formatter.setErrorStatus(includeErrors_); - if (useQuality) - formatter.setQualityStatus(useQuality, badPixelInfo_); + if (useQuality_) + formatter.setQualityStatus(useQuality_, badPixelInfo_); - if (theTimer) - theTimer->start(); bool errorsInEvent = false; PixelDataFormatter::DetErrors nodeterrors; @@ -202,17 +218,16 @@ void SiPixelRawToDigi::produce(edm::Event& ev, const edm::EventSetup& es) { << regions_->nForwardModules() << " " << regions_->nModules(); } - for (auto aFed = fedIds.begin(); aFed != fedIds.end(); ++aFed) { + for (auto aFed = fedIds_.begin(); aFed != fedIds_.end(); ++aFed) { int fedId = *aFed; - if (!usePilotBlade && (fedId == 40)) + if (!usePilotBlade_ && (fedId == 40)) continue; // skip pilot blade data if (regions_ && !regions_->mayUnpackFED(fedId)) continue; - if (debug) - LogDebug("SiPixelRawToDigi") << " PRODUCE DIGI FOR FED: " << fedId << endl; + LogDebug("SiPixelRawToDigi") << "PRODUCE DIGI FOR FED:" << fedId; PixelDataFormatter::Errors errors; @@ -220,103 +235,34 @@ void SiPixelRawToDigi::produce(edm::Event& ev, const edm::EventSetup& es) { const FEDRawData& fedRawData = buffers->FEDData(fedId); //convert data to digi and strip off errors - formatter.interpretRawData(errorsInEvent, fedId, fedRawData, *collection, errors); + formatter.interpretRawData(errorsInEvent, fedId, fedRawData, collection, errors); //pack errors into collection - if (includeErrors) { - typedef PixelDataFormatter::Errors::iterator IE; - for (IE is = errors.begin(); is != errors.end(); is++) { - uint32_t errordetid = is->first; - if (errordetid == dummydetid) { // errors given dummy detId must be sorted by Fed - nodeterrors.insert(nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end()); - } else { - edm::DetSet& errorDetSet = errorcollection->find_or_insert(errordetid); - errorDetSet.data.insert(errorDetSet.data.end(), is->second.begin(), is->second.end()); - // Fill detid of the detectors where there is error AND the error number is listed - // in the configurable error list in the job option cfi. - // Code needs to be here, because there can be a set of errors for each - // entry in the for loop over PixelDataFormatter::Errors - - std::vector disabledChannelsDetSet; - - for (auto const& aPixelError : errorDetSet) { - // For the time being, we extend the error handling functionality with ErrorType 25 - // In the future, we should sort out how the usage of tkerrorlist can be generalized - if (usePhase1 && aPixelError.getType() == 25) { - assert(aPixelError.getFedId() == fedId); - const sipixelobjects::PixelFEDCabling* fed = cabling_->fed(fedId); - if (fed) { - cms_uint32_t linkId = formatter.linkId(aPixelError.getWord32()); - const sipixelobjects::PixelFEDLink* link = fed->link(linkId); - if (link) { - // The "offline" 0..15 numbering is fixed by definition, also, the FrameConversion depends on it - // in contrast, the ROC-in-channel numbering is determined by hardware --> better to use the "offline" scheme - PixelFEDChannel ch = {fed->id(), linkId, 25, 0}; - for (unsigned int iRoc = 1; iRoc <= link->numberOfROCs(); iRoc++) { - const sipixelobjects::PixelROC* roc = link->roc(iRoc); - if (roc->idInDetUnit() < ch.roc_first) - ch.roc_first = roc->idInDetUnit(); - if (roc->idInDetUnit() > ch.roc_last) - ch.roc_last = roc->idInDetUnit(); - } - disabledChannelsDetSet.push_back(ch); - } - } - } else { - // fill list of detIds to be turned off by tracking - if (!tkerrorlist.empty()) { - std::vector::iterator it_find = - find(tkerrorlist.begin(), tkerrorlist.end(), aPixelError.getType()); - if (it_find != tkerrorlist.end()) { - tkerror_detidcollection->push_back(errordetid); - } - } - } - - // fill list of detIds with errors to be studied - if (!usererrorlist.empty()) { - std::vector::iterator it_find = - find(usererrorlist.begin(), usererrorlist.end(), aPixelError.getType()); - if (it_find != usererrorlist.end()) { - usererror_detidcollection->push_back(errordetid); - } - } - - } // loop on DetSet of errors - - if (!disabledChannelsDetSet.empty()) { - disabled_channelcollection->insert( - errordetid, disabledChannelsDetSet.data(), disabledChannelsDetSet.size()); - } - } // if error assigned to a real DetId - } // loop on errors in event for this FED - } // if errors to be included in the event - } // loop on FED data to be unpacked - - if (includeErrors) { - edm::DetSet& errorDetSet = errorcollection->find_or_insert(dummydetid); + if (includeErrors_) { + formatter.unpackFEDErrors(errors, + tkerrorlist_, + usererrorlist_, + errorcollection, + tkerror_detidcollection, + usererror_detidcollection, + disabled_channelcollection, + nodeterrors); + } // if errors to be included in the event + } // loop on FED data to be unpacked + + if (includeErrors_) { + edm::DetSet& errorDetSet = errorcollection.find_or_insert(dummydetid); errorDetSet.data = nodeterrors; } if (errorsInEvent) LogDebug("SiPixelRawToDigi") << "Error words were stored in this event"; - if (theTimer) { - theTimer->stop(); - LogDebug("SiPixelRawToDigi") << "TIMING IS: (real)" << theTimer->realTime(); - ndigis += formatter.nDigis(); - nwords += formatter.nWords(); - LogDebug("SiPixelRawToDigi") << " (Words/Digis) this ev: " << formatter.nWords() << "/" << formatter.nDigis() - << "--- all :" << nwords << "/" << ndigis; - hCPU->Fill(theTimer->realTime()); - hDigi->Fill(formatter.nDigis()); - } - - ev.put(std::move(collection)); - if (includeErrors) { - ev.put(std::move(errorcollection)); - ev.put(std::move(tkerror_detidcollection)); - ev.put(std::move(usererror_detidcollection), "UserErrorModules"); - ev.put(std::move(disabled_channelcollection)); + ev.emplace(siPixelDigiCollectionToken_, std::move(collection)); + if (includeErrors_) { + ev.emplace(errorPutToken_, std::move(errorcollection)); + ev.emplace(tkErrorPutToken_, std::move(tkerror_detidcollection)); + ev.emplace(userErrorPutToken_, std::move(usererror_detidcollection)); + ev.emplace(disabledChannelPutToken_, std::move(disabled_channelcollection)); } } // declare this as a framework plugin diff --git a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h b/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h deleted file mode 100644 index c475479cc7303..0000000000000 --- a/EventFilter/SiPixelRawToDigi/plugins/SiPixelRawToDigi.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SiPixelRawToDigi_H -#define SiPixelRawToDigi_H - -/** \class SiPixelRawToDigi_H - * Plug-in module that performs Raw data to digi conversion - * for pixel subdetector - */ - -#include "FWCore/Framework/interface/ESWatcher.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h" -#include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" -#include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h" -#include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h" -#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" -#include "FWCore/Utilities/interface/CPUTimer.h" -#include "FWCore/Utilities/interface/ESGetToken.h" - -class SiPixelFedCablingTree; -class SiPixelFedCabling; -class SiPixelQuality; -class TH1D; -class PixelUnpackingRegions; - -class SiPixelRawToDigi : public edm::stream::EDProducer<> { -public: - /// ctor - explicit SiPixelRawToDigi(const edm::ParameterSet&); - - /// dtor - ~SiPixelRawToDigi() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - /// get data, convert to digis attach againe to Event - void produce(edm::Event&, const edm::EventSetup&) override; - -private: - edm::ParameterSet config_; - std::unique_ptr cabling_; - const SiPixelQuality* badPixelInfo_; - PixelUnpackingRegions* regions_; - edm::EDGetTokenT tFEDRawDataCollection; - TH1D *hCPU, *hDigi; - std::unique_ptr theTimer; - bool includeErrors; - bool useQuality; - bool debug; - std::vector tkerrorlist; - std::vector usererrorlist; - std::vector fedIds; - edm::ESWatcher recordWatcher; - edm::ESWatcher qualityWatcher; - edm::InputTag label; - edm::ESGetToken tSiPixelQuality; - edm::ESGetToken tCablingMap; - int ndigis; - int nwords; - bool usePilotBlade; - bool usePhase1; - std::string cablingMapLabel; -}; -#endif diff --git a/EventFilter/SiPixelRawToDigi/python/SiPixelDigiToRaw_cfi.py b/EventFilter/SiPixelRawToDigi/python/SiPixelDigiToRaw_cfi.py index bb78b3ee8c6ea..0c5946f226a11 100644 --- a/EventFilter/SiPixelRawToDigi/python/SiPixelDigiToRaw_cfi.py +++ b/EventFilter/SiPixelRawToDigi/python/SiPixelDigiToRaw_cfi.py @@ -1,7 +1,6 @@ import FWCore.ParameterSet.Config as cms siPixelRawData = cms.EDProducer("SiPixelDigiToRaw", - Timing = cms.untracked.bool(False), InputLabel = cms.InputTag("simSiPixelDigis"), ## Use phase1 UsePhase1 = cms.bool(False), diff --git a/EventFilter/SiPixelRawToDigi/src/PixelDataFormatter.cc b/EventFilter/SiPixelRawToDigi/src/PixelDataFormatter.cc index 74514b5bdf4dd..5557f8061446e 100644 --- a/EventFilter/SiPixelRawToDigi/src/PixelDataFormatter.cc +++ b/EventFilter/SiPixelRawToDigi/src/PixelDataFormatter.cc @@ -39,22 +39,9 @@ namespace { // Special for layer 1 bpix rocs 6/9/16 d.k. THIS STAYS. constexpr int COL_bits1_l1 = 6; constexpr int ROW_bits1_l1 = 7; - - // Moved to the header file, keep commented out unti the final version is done/ - // constexpr int ADC_shift = 0; - // constexpr int PXID_shift = ADC_shift + ADC_bits; - // constexpr int DCOL_shift = PXID_shift + PXID_bits; - // constexpr int ROC_shift = DCOL_shift + DCOL_bits; - // constexpr int LINK_shift = ROC_shift + ROC_bits; - // constexpr PixelDataFormatter::Word32 LINK_mask = ~(~PixelDataFormatter::Word32(0) << LINK_bits); - // constexpr PixelDataFormatter::Word32 ROC_mask = ~(~PixelDataFormatter::Word32(0) << ROC_bits); - // constexpr PixelDataFormatter::Word32 DCOL_mask = ~(~PixelDataFormatter::Word32(0) << DCOL_bits); - // constexpr PixelDataFormatter::Word32 PXID_mask = ~(~PixelDataFormatter::Word32(0) << PXID_bits); - // constexpr PixelDataFormatter::Word32 ADC_mask = ~(~PixelDataFormatter::Word32(0) << ADC_bits); - //const bool DANEK = false; } // namespace -PixelDataFormatter::PixelDataFormatter(const SiPixelFedCabling* map, bool phase) +PixelDataFormatter::PixelDataFormatter(const SiPixelFedCablingTree* map, bool phase) : theDigiCounter(0), theWordCounter(0), theCablingTree(map), @@ -81,25 +68,25 @@ PixelDataFormatter::PixelDataFormatter(const SiPixelFedCabling* map, bool phase) if (phase1) { // for phase 1 LINK_shift = ROC_shift + ROC_bits1; - LINK_mask = ~(~PixelDataFormatter::Word32(0) << LINK_bits1); - ROC_mask = ~(~PixelDataFormatter::Word32(0) << ROC_bits1); + LINK_mask = ~(~Word32(0) << LINK_bits1); + ROC_mask = ~(~Word32(0) << ROC_bits1); // special for layer 1 ROC ROW_shift = ADC_shift + ADC_bits; COL_shift = ROW_shift + ROW_bits1_l1; - COL_mask = ~(~PixelDataFormatter::Word32(0) << COL_bits1_l1); - ROW_mask = ~(~PixelDataFormatter::Word32(0) << ROW_bits1_l1); + COL_mask = ~(~Word32(0) << COL_bits1_l1); + ROW_mask = ~(~Word32(0) << ROW_bits1_l1); maxROCIndex = 8; } else { // for phase 0 LINK_shift = ROC_shift + ROC_bits; - LINK_mask = ~(~PixelDataFormatter::Word32(0) << LINK_bits); - ROC_mask = ~(~PixelDataFormatter::Word32(0) << ROC_bits); + LINK_mask = ~(~Word32(0) << LINK_bits); + ROC_mask = ~(~Word32(0) << ROC_bits); maxROCIndex = 25; } - DCOL_mask = ~(~PixelDataFormatter::Word32(0) << DCOL_bits); - PXID_mask = ~(~PixelDataFormatter::Word32(0) << PXID_bits); - ADC_mask = ~(~PixelDataFormatter::Word32(0) << ADC_bits); + DCOL_mask = ~(~Word32(0) << DCOL_bits); + PXID_mask = ~(~Word32(0) << PXID_bits); + ADC_mask = ~(~Word32(0) << ADC_bits); if (phase1) { errorcheck = std::unique_ptr(new ErrorChecker()); @@ -186,8 +173,6 @@ void PixelDataFormatter::interpretRawData( int nlink = (ww >> LINK_shift) & LINK_mask; int nroc = (ww >> ROC_shift) & ROC_mask; - //if(DANEK) cout<<" fed, link, roc "<print()<<" layer "<bpixLayerPhase1(rawId)<<" " - // <idInDetUnit(); skipROC = badPixelInfo->IsRocBad(rawId, rocInDet); @@ -239,11 +221,8 @@ void PixelDataFormatter::interpretRawData( // for l1 roc use the roc column and row index instead of dcol and pixel index. int col = (ww >> COL_shift) & COL_mask; int row = (ww >> ROW_shift) & ROW_mask; - //if(DANEK) cout<<" layer 1: raw2digi "<(localCR); // local pixel coordinate - //if(DANEK) cout<dcol()<<" "<pxid()<<" "<rocCol()<<" "<rocRow()<> DCOL_shift) & DCOL_mask; int pxid = (ww >> PXID_shift) & PXID_mask; - //if(DANEK) cout<<" raw2digi "<(localDP); // local pixel coordinate - //if(DANEK) cout<dcol()<<" "<pxid()<<" "<rocCol()<<" "<rocRow()<toGlobal(*local); // global pixel coordinate (in module) (*detDigis).data.emplace_back(global.row, global.col, adc); - //if(DANEK) cout<> DCOL_shift) & DCOL_mask; -// int pxid = (ww >> PXID_shift) & PXID_mask; -// // int adc = (ww >> ADC_shift) & ADC_mask; -// LocalPixel::DcolPxid local = { dcol, pxid }; -// valid[i] = local.valid(); -// GlobalPixel global = rocp->toGlobal( LocalPixel(local) ); -// row[i]=global.row; col[i]=global.col; -// } -// } - void PixelDataFormatter::formatRawData(unsigned int lvl1_ID, RawData& fedRawData, const Digis& digis, @@ -308,7 +266,6 @@ void PixelDataFormatter::formatRawData(unsigned int lvl1_ID, bool barrel = PixelModuleName::isBarrel(rawId); if (barrel) layer = PixelROC::bpixLayerPhase1(rawId); - //if(DANEK) cout<<" layer "<second.begin(), detBadChannels->second.end(), [&](const PixelFEDChannel& ch) { - return (int(ch.fed) == fedId && ch.link == linkId(words[fedId].back())); + return (int(ch.fed) == fedId && ch.link == getLinkId(words[fedId].back())); }); if (badChannel != detBadChannels->second.end()) { LogError("FormatDataException") << " while marked bad, found digi for FED " << fedId << " Link " - << linkId(words[fedId].back()) << " on module " << rawId << endl + << getLinkId(words[fedId].back()) << " on module " << rawId << endl << print(digi) << endl; } } // if (fedId) @@ -401,9 +358,7 @@ void PixelDataFormatter::formatRawData(unsigned int lvl1_ID, int PixelDataFormatter::digi2word(cms_uint32_t detId, const PixelDigi& digi, std::map >& words) const { - LogDebug("PixelDataFormatter") - // <<" detId: " << detId - << print(digi); + LogDebug("PixelDataFormatter") << print(digi); DetectorIndex detector = {detId, digi.row(), digi.column()}; ElectronicIndex cabling; @@ -411,9 +366,6 @@ int PixelDataFormatter::digi2word(cms_uint32_t detId, if (fedId < 0) return fedId; - //if(DANEK) cout<<" digi2raw "< >& words) const { - LogDebug("PixelDataFormatter") - // <<" detId: " << detId - << print(digi); + LogDebug("PixelDataFormatter") << print(digi); DetectorIndex detector = {detId, digi.row(), digi.column()}; ElectronicIndex cabling; @@ -437,10 +387,6 @@ int PixelDataFormatter::digi2wordPhase1Layer1(cms_uint32_t detId, int col = ((cabling.dcol) * 2) + ((cabling.pxid) % 2); int row = LocalPixel::numRowsInRoc - ((cabling.pxid) / 2); - //if(DANEK) cout<<" layer 1: digi2raw "<> DCOL_shift) & DCOL_mask; - cabling.pxid = (word >> PXID_shift) & PXID_mask; - cabling.link = (word >> LINK_shift) & LINK_mask; - cabling.roc = (word >> ROC_shift) & ROC_mask; - int adc = (word >> ADC_shift) & ADC_mask; - - if (debug) { - LocalPixel::DcolPxid pixel = {cabling.dcol, cabling.pxid}; - LocalPixel local(pixel); - LogTrace("") << " link: " << cabling.link << ", roc: " << cabling.roc << " rocRow: " << local.rocRow() - << ", rocCol:" << local.rocCol() << " (dcol: " << cabling.dcol << ", pxid:" << cabling.pxid - << "), adc:" << adc; - } - - if (!converter) - return 0; - - DetectorIndex detIdx; - int status = converter->toDetector(cabling, detIdx); - if (status) - return status; - - // exclude ROC(raw) based on bad ROC list bad in SiPixelQuality - // enable: process.siPixelDigis.UseQualityInfo = True - // 20-10-2010 A.Y. - if (useQuality && badPixelInfo) { - CablingPathToDetUnit path = {static_cast(fedId), - static_cast(cabling.link), - static_cast(cabling.roc)}; - const PixelROC* roc = theCablingTree->findItem(path); - short rocInDet = (short)roc->idInDetUnit(); - bool badROC = badPixelInfo->IsRocBad(detIdx.rawId, rocInDet); - if (badROC) - return 0; - } - - if (modulesToUnpack && modulesToUnpack->find(detIdx.rawId) == modulesToUnpack->end()) - return 0; - - digis[detIdx.rawId].emplace_back(detIdx.row, detIdx.col, adc); - - theDigiCounter++; - - if (debug) - LogTrace("") << digis[detIdx.rawId].back(); - return 0; -} - std::string PixelDataFormatter::print(const PixelDigi& digi) const { ostringstream str; str << " DIGI: row: " << digi.row() << ", col: " << digi.column() << ", adc: " << digi.adc(); @@ -520,3 +406,76 @@ std::string PixelDataFormatter::print(const Word64& word) const { str << "word64: " << reinterpret_cast&>(word); return str.str(); } + +void PixelDataFormatter::unpackFEDErrors(PixelDataFormatter::Errors const& errors, + std::vector const& tkerrorlist, + std::vector const& usererrorlist, + edm::DetSetVector& errorcollection, + DetIdCollection& tkerror_detidcollection, + DetIdCollection& usererror_detidcollection, + edmNew::DetSetVector& disabled_channelcollection, + DetErrors& nodeterrors) { + const uint32_t dummyDetId = 0xffffffff; + for (const auto& [errorDetId, rawErrorsVec] : errors) { + if (errorDetId == dummyDetId) { // errors given dummy detId must be sorted by Fed + nodeterrors.insert(nodeterrors.end(), rawErrorsVec.begin(), rawErrorsVec.end()); + } else { + edm::DetSet& errorDetSet = errorcollection.find_or_insert(errorDetId); + errorDetSet.data.insert(errorDetSet.data.end(), rawErrorsVec.begin(), rawErrorsVec.end()); + // Fill detid of the detectors where there is error AND the error number is listed + // in the configurable error list in the job option cfi. + // Code needs to be here, because there can be a set of errors for each + // entry in the for loop over PixelDataFormatter::Errors + + std::vector disabledChannelsDetSet; + + for (auto const& aPixelError : errorDetSet) { + // For the time being, we extend the error handling functionality with ErrorType 25 + // In the future, we should sort out how the usage of tkerrorlist can be generalized + if (phase1 && aPixelError.getType() == 25) { + int fedId = aPixelError.getFedId(); + const sipixelobjects::PixelFEDCabling* fed = theCablingTree->fed(fedId); + if (fed) { + cms_uint32_t linkId = getLinkId(aPixelError.getWord32()); + const sipixelobjects::PixelFEDLink* link = fed->link(linkId); + if (link) { + // The "offline" 0..15 numbering is fixed by definition, also, the FrameConversion depends on it + // in contrast, the ROC-in-channel numbering is determined by hardware --> better to use the "offline" scheme + PixelFEDChannel ch = {fed->id(), linkId, 25, 0}; + for (unsigned int iRoc = 1; iRoc <= link->numberOfROCs(); iRoc++) { + const sipixelobjects::PixelROC* roc = link->roc(iRoc); + if (roc->idInDetUnit() < ch.roc_first) + ch.roc_first = roc->idInDetUnit(); + if (roc->idInDetUnit() > ch.roc_last) + ch.roc_last = roc->idInDetUnit(); + } + disabledChannelsDetSet.push_back(ch); + } + } + } else { + // fill list of detIds to be turned off by tracking + if (!tkerrorlist.empty()) { + auto it_find = std::find(tkerrorlist.begin(), tkerrorlist.end(), aPixelError.getType()); + if (it_find != tkerrorlist.end()) { + tkerror_detidcollection.push_back(errorDetId); + } + } + } + + // fill list of detIds with errors to be studied + if (!usererrorlist.empty()) { + auto it_find = std::find(usererrorlist.begin(), usererrorlist.end(), aPixelError.getType()); + if (it_find != usererrorlist.end()) { + usererror_detidcollection.push_back(errorDetId); + } + } + + } // loop on DetSet of errors + + if (!disabledChannelsDetSet.empty()) { + disabled_channelcollection.insert(errorDetId, disabledChannelsDetSet.data(), disabledChannelsDetSet.size()); + } + + } // if error assigned to a real DetId + } // loop on errors in event for this FED +} diff --git a/EventFilter/SiPixelRawToDigi/test/runHotPixels_cfg.py b/EventFilter/SiPixelRawToDigi/test/runHotPixels_cfg.py index 5a82f804ee8fe..b457b7f840843 100644 --- a/EventFilter/SiPixelRawToDigi/test/runHotPixels_cfg.py +++ b/EventFilter/SiPixelRawToDigi/test/runHotPixels_cfg.py @@ -78,7 +78,6 @@ # In 2012, extension = _LHC InputLabel = cms.untracked.string('rawDataCollector'), # InputLabel = cms.untracked.string('siPixelRawData'), - CheckPixelOrder = cms.untracked.bool(False) ) process.p = cms.Path(process.hltfilter*process.dumper) diff --git a/EventFilter/SiPixelRawToDigi/test/runRawDumper_cfg.py b/EventFilter/SiPixelRawToDigi/test/runRawDumper_cfg.py index 8cfcdf2944364..17c420cca4488 100644 --- a/EventFilter/SiPixelRawToDigi/test/runRawDumper_cfg.py +++ b/EventFilter/SiPixelRawToDigi/test/runRawDumper_cfg.py @@ -273,7 +273,6 @@ #process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange('205718:49-205718:734') process.d = cms.EDAnalyzer("SiPixelRawDumper", - Timing = cms.untracked.bool(False), IncludeErrors = cms.untracked.bool(True), # In 2012, label = rawDataCollector, extension = _LHC # InputLabel = cms.untracked.string('rawDataCollector'), @@ -284,7 +283,6 @@ # old # InputLabel = cms.untracked.string('siPixelRawData'), # InputLabel = cms.untracked.string('source'), - CheckPixelOrder = cms.untracked.bool(False), # 0 - nothing, 1 - error , 2- data, 3-headers, 4-hex Verbosity = cms.untracked.int32(1), # threshold, print fed/channel num of errors if tot_errors > events * PrintThreshold, default 0,001 diff --git a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py index b5499e80b4306..3485f90b5b4b0 100644 --- a/HLTrigger/Configuration/python/customizeHLTforCMSSW.py +++ b/HLTrigger/Configuration/python/customizeHLTforCMSSW.py @@ -150,14 +150,23 @@ def customiseFor33495(process): del producer.DoLorentz return process +def customizeFor33526(process): + """ Customize HLT menu to remove deprecated parameters for the pixel raw to digi step""" + for producer in producers_by_type(process, "SiPixelRawToDigi"): + if hasattr(producer, "Timing"): + del producer.Timing + if hasattr(producer, "CheckPixelOrder"): + del producer.CheckPixelOrder + return process # CMSSW version specific customizations def customizeHLTforCMSSW(process, menuType="GRun"): - + # add call to action function in proper order: newest last! # process = customiseFor12718(process) process = customiseFor33495(process) + process = customizeFor33526(process) process = customizeFor33543(process) return process