From fed538893d29071dc96920cfdc9c940728b7d013 Mon Sep 17 00:00:00 2001 From: Long Date: Sun, 20 Nov 2022 15:24:50 +0100 Subject: [PATCH] simplifying code from suggestion, tested works well --- .../plugins/HcalGPUComparisonTask.cc | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc b/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc index 064c438be62b8..8f0d500d52b5c 100644 --- a/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc +++ b/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc @@ -93,41 +93,27 @@ HcalGPUComparisonTask::HcalGPUComparisonTask(edm::ParameterSet const& ps) /* virtual */ void HcalGPUComparisonTask::_resetMonitors(hcaldqm::UpdateFreq uf) { DQTask::_resetMonitors(uf); } /* virtual */ void HcalGPUComparisonTask::_process(edm::Event const& e, edm::EventSetup const&) { - edm::Handle chbhe_ref; - edm::Handle chbhe_target; - - bool gotRefCollection = true, gotTargetCollection = true; - - if (!(e.getByToken(tokHBHE_ref_, chbhe_ref))) { - edm::LogWarning("HcalGPUComparisonTask") - << "The CPU HBHERecHitCollection " << tagHBHE_ref_.encode() << " is not available" << std::endl; - gotRefCollection = false; - } - if (!(e.getByToken(tokHBHE_target_, chbhe_target))) { - edm::LogWarning("HcalGPUComparisonTask") - << "The GPU HBHERecHitCollection " << tagHBHE_target_.encode() << " is not available" << std::endl; - gotTargetCollection = false; - } - - if (gotRefCollection && !gotTargetCollection) { - for (HBHERecHitCollection::const_iterator it = chbhe_ref->begin(); it != chbhe_ref->end(); ++it) { - double energy = it->energy(); - HcalDetId did = it->id(); - energyGPUvsCPU_subdet_.fill(did, energy, -0.5); - } - return; - } - if (!gotRefCollection && gotTargetCollection) { - for (HBHERecHitCollection::const_iterator it = chbhe_target->begin(); it != chbhe_target->end(); ++it) { - double energy = it->energy(); - HcalDetId did = it->id(); - energyGPUvsCPU_subdet_.fill(did, -0.5, energy); + auto const chbhe_ref = e.getHandle(tokHBHE_ref_); + auto const chbhe_target = e.getHandle(tokHBHE_target_); + + if (not(chbhe_ref.isValid() and chbhe_target.isValid())) { + if (chbhe_target.isValid()) { + edm::LogWarning("HcalGPUComparisonTask") + << "The CPU HBHERecHitCollection " << tagHBHE_ref_.encode() << " is not available"; + + for (auto const& rh : *chbhe_target) + energyGPUvsCPU_subdet_.fill(rh.id(), -0.5, rh.energy()); + } else if (chbhe_ref.isValid()) { + edm::LogWarning("HcalGPUComparisonTask") + << "The GPU HBHERecHitCollection " << tagHBHE_target_.encode() << " is not available"; + + for (auto const& rh : *chbhe_ref) + energyGPUvsCPU_subdet_.fill(rh.id(), rh.energy(), -0.5); + } else { + edm::LogWarning("HcalGPUComparisonTask") + << "Neither CPU nor GPU RecHit Collection available, will not fill this event."; } - return; - } - if (!gotRefCollection && !gotTargetCollection) { - edm::LogWarning("HcalGPUComparisonTask") - << "Neither CPU nor GPU RecHit Collection available, will not fill this event." << std::endl; + return; }