From 618a9998440536299a5fee5e2c94d12d0f313785 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Fri, 25 Aug 2023 18:06:12 +0200 Subject: [PATCH] workaround for unit test "testSiStripHitEfficiency" Suggested by @fwyzard in https://github.com/cms-sw/cmssw/pull/42662#issuecomment-1693530380 --- .../SiStripHitEfficiency/plugins/HitEff.cc | 24 ++++++++++++---- .../SiStripHitEfficiency/plugins/HitEff.h | 4 ++- .../plugins/SiStripHitEfficiencyWorker.cc | 28 +++++++++++++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc index 8019b037382ad..baaf910237727 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc @@ -43,6 +43,7 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/Exception.h" #include "Geometry/CommonDetUnit/interface/GeomDet.h" #include "Geometry/CommonDetUnit/interface/GeomDetType.h" #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h" @@ -81,7 +82,8 @@ HitEff::HitEff(const edm::ParameterSet& conf) trajTrackAsso_token_(consumes(conf.getParameter("trajectories"))), clusters_token_( consumes >(conf.getParameter("siStripClusters"))), - digis_token_(consumes(conf.getParameter("siStripDigis"))), + digisCol_token_(consumes(conf.getParameter("siStripDigis"))), + digisVec_token_(consumes(conf.getParameter("siStripDigis"))), trackerEvent_token_(consumes(conf.getParameter("trackerEvent"))), topoToken_(esConsumes()), geomToken_(esConsumes()), @@ -247,9 +249,19 @@ void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es) { const MagneticField* magField_ = &es.getData(magFieldToken_); // get the list of module IDs with FED-detected errors - edm::Handle fedErrorIds; - //e.getByLabel("siStripDigis", fedErrorIds ); - e.getByToken(digis_token_, fedErrorIds); + // - In Aug-2023, the data format was changed from DetIdCollection to DetIdVector. + // - To provide some level of backward-compatibility, + // the plugin checks for both types giving preference to the new format. + // - If only the old format is available, the collection is + // converted to the new format, then used downstream. + auto const& fedErrorIdsCol_h = e.getHandle(digisCol_token_); + auto const& fedErrorIdsVec_h = e.getHandle(digisVec_token_); + if (not fedErrorIdsCol_h.isValid() and not fedErrorIdsVec_h.isValid()) { + throw cms::Exception("InvalidProductSiStripDetIdsWithFEDErrors") + << "no valid product for SiStrip DetIds with FED errors (see parameter \"siStripDigis\"), " + "neither for new format (DetIdVector) nor old format (DetIdCollection)"; + } + auto const& fedErrorIds = fedErrorIdsVec_h.isValid() ? *fedErrorIdsVec_h : fedErrorIdsCol_h->as_vector(); edm::ESHandle measurementTrackerHandle = es.getHandle(measurementTkToken_); @@ -976,8 +988,8 @@ void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es) { } //check for FED-detected errors and include those in SiStripQualBad - for (unsigned int ii = 0; ii < fedErrorIds->size(); ii++) { - if (iidd == (*fedErrorIds)[ii].rawId()) + for (unsigned int ii = 0; ii < fedErrorIds.size(); ii++) { + if (iidd == fedErrorIds[ii].rawId()) SiStripQualBad = 1; } diff --git a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h index 467ab430cf06f..e7dec6afce623 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h +++ b/CalibTracker/SiStripHitEfficiency/plugins/HitEff.h @@ -7,6 +7,7 @@ // user includes #include "CommonTools/UtilAlgos/interface/TFileService.h" #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/DetId/interface/DetIdCollection.h" #include "DataFormats/DetId/interface/DetIdVector.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h" @@ -80,7 +81,8 @@ class HitEff : public edm::one::EDAnalyzer { const edm::EDGetTokenT > trajectories_token_; const edm::EDGetTokenT trajTrackAsso_token_; const edm::EDGetTokenT > clusters_token_; - const edm::EDGetTokenT digis_token_; + const edm::EDGetTokenT digisCol_token_; + const edm::EDGetTokenT digisVec_token_; const edm::EDGetTokenT trackerEvent_token_; // ES tokens diff --git a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc index 718a0c2d04b2b..89f096b9a75be 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEfficiencyWorker.cc @@ -17,6 +17,7 @@ #include "DataFormats/Common/interface/DetSetVector.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/DetId/interface/DetIdCollection.h" #include "DataFormats/DetId/interface/DetIdVector.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h" #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h" @@ -41,6 +42,7 @@ #include "FWCore/ParameterSet/interface/ParameterDescription.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Utilities/interface/Exception.h" #include "Geometry/CommonDetUnit/interface/GeomDet.h" #include "Geometry/CommonDetUnit/interface/GeomDetType.h" #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" @@ -92,7 +94,8 @@ class SiStripHitEfficiencyWorker : public DQMEDAnalyzer { const edm::EDGetTokenT> trajectories_token_; const edm::EDGetTokenT trajTrackAsso_token_; const edm::EDGetTokenT> clusters_token_; - const edm::EDGetTokenT digis_token_; + const edm::EDGetTokenT digisCol_token_; + const edm::EDGetTokenT digisVec_token_; const edm::EDGetTokenT trackerEvent_token_; // event setup tokens @@ -202,7 +205,8 @@ SiStripHitEfficiencyWorker::SiStripHitEfficiencyWorker(const edm::ParameterSet& trajTrackAsso_token_(consumes(conf.getParameter("trajectories"))), clusters_token_( consumes>(conf.getParameter("siStripClusters"))), - digis_token_(consumes(conf.getParameter("siStripDigis"))), + digisCol_token_(consumes(conf.getParameter("siStripDigis"))), + digisVec_token_(consumes(conf.getParameter("siStripDigis"))), trackerEvent_token_(consumes(conf.getParameter("trackerEvent"))), tTopoToken_(esConsumes()), tkGeomToken_(esConsumes()), @@ -445,11 +449,23 @@ void SiStripHitEfficiencyWorker::analyze(const edm::Event& e, const edm::EventSe edm::Handle> theClusters; e.getByToken(clusters_token_, theClusters); - edm::Handle fedErrorIds; - e.getByToken(digis_token_, fedErrorIds); + // get the list of module IDs with FED-detected errors + // - In Aug-2023, the data format was changed from DetIdCollection to DetIdVector. + // - To provide some level of backward-compatibility, + // the plugin checks for both types giving preference to the new format. + // - If only the old format is available, the collection is + // converted to the new format, then used downstream. + auto const& fedErrorIdsCol_h = e.getHandle(digisCol_token_); + auto const& fedErrorIdsVec_h = e.getHandle(digisVec_token_); + if (not fedErrorIdsCol_h.isValid() and not fedErrorIdsVec_h.isValid()) { + throw cms::Exception("InvalidProductSiStripDetIdsWithFEDErrors") + << "no valid product for SiStrip DetIds with FED errors (see parameter \"siStripDigis\"), " + "neither for new format (DetIdVector) nor old format (DetIdCollection)"; + } + auto const& fedErrorIds = fedErrorIdsVec_h.isValid() ? *fedErrorIdsVec_h : fedErrorIdsCol_h->as_vector(); // fill the calibData with the FEDErrors - for (const auto& fedErr : *fedErrorIds) { + for (const auto& fedErr : fedErrorIds) { // fill the TkHistoMap occupancy map calibData_.FEDErrorOccupancy->fill(fedErr.rawId(), 1.); @@ -826,7 +842,7 @@ void SiStripHitEfficiencyWorker::analyze(const edm::Event& e, const edm::EventSe tkgeom, stripcpe, stripQuality, - *fedErrorIds, + fedErrorIds, commonModeDigis, *theClusters, e.bunchCrossing(),