From 521e5a5f979ca5ec27a8e00aaedcd8b5304ffafa Mon Sep 17 00:00:00 2001 From: Long Date: Sun, 20 Nov 2022 15:28:20 +0100 Subject: [PATCH] simplifying code --- .../plugins/HcalGPUComparisonTask.cc | 60 +++++++------------ 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc b/DQM/HcalTasks/plugins/HcalGPUComparisonTask.cc index 064c438be62b8..013d8a6bdd26d 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; } @@ -145,7 +131,7 @@ HcalGPUComparisonTask::HcalGPUComparisonTask(edm::ParameterSet const& ps) if (mRecHitEnergy.find(did) == mRecHitEnergy.end()) mRecHitEnergy.insert(std::make_pair(did, energy)); else - edm::LogError("HcalGPUComparisonTask") << "Duplicate Rechit from the same HcalDetId" << std::endl; + edm::LogError("HcalGPUComparisonTask") << "Duplicate Rechit from the same HcalDetId"; ; } @@ -174,14 +160,14 @@ HcalGPUComparisonTask::HcalGPUComparisonTask(edm::ParameterSet const& ps) } else { if (energy > 2.) edm::LogError("HcalGPUComparisonTask") - << "Energetic GPU Rechit exist, but not reconstructed by CPU. DetId = " << did << std::endl; + << "Energetic GPU Rechit exist, but not reconstructed by CPU. DetId = " << did; } } if (!mRecHitEnergy.empty()) { for (auto const& rhpair : mRecHitEnergy) { if (rhpair.second > 2.) edm::LogError("HcalGPUComparisonTask") - << "Energetic CPU Rechit exist, but not reconstructed by GPU. DetId = " << rhpair.first << std::endl; + << "Energetic CPU Rechit exist, but not reconstructed by GPU. DetId = " << rhpair.first; } } }