Skip to content

Commit d7e4781

Browse files
committed
added protections to ScoutingMuonPropertiesAnalyzer in case of invalid handle
1 parent 4689422 commit d7e4781

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

HLTriggerOffline/Scouting/plugins/ScoutingMuonPropertiesAnalyzer.cc

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class ScoutingMuonPropertiesAnalyzer : public DQMEDAnalyzer {
5656
void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
5757

5858
private:
59+
template <typename T>
60+
bool getValidHandle(const edm::Event& iEvent,
61+
const edm::EDGetTokenT<T>& token,
62+
edm::Handle<T>& handle,
63+
const std::string& label);
64+
5965
// Output Folder
6066
const std::string outputInternalPath_;
6167
// do to some histogram duplicates with the ScoutingCollectionMonitor.cc module, we added the option to just fill the unique plots w.r.t the aforementioned module, if this bool is set to false
@@ -228,6 +234,19 @@ ScoutingMuonPropertiesAnalyzer::ScoutingMuonPropertiesAnalyzer(const edm::Parame
228234
};
229235
}
230236

237+
template <typename T>
238+
bool ScoutingMuonPropertiesAnalyzer::getValidHandle(const edm::Event& iEvent,
239+
const edm::EDGetTokenT<T>& token,
240+
edm::Handle<T>& handle,
241+
const std::string& label) {
242+
iEvent.getByToken(token, handle);
243+
if (!handle.isValid()) {
244+
edm::LogWarning("ScoutingMuonPropertiesAnalyzer") << "Invalid handle for " << label << "! Skipping event.";
245+
return false;
246+
}
247+
return true;
248+
}
249+
231250
void ScoutingMuonPropertiesAnalyzer::bookHistograms(DQMStore::IBooker& ibooker,
232251
edm::Run const&,
233252
edm::EventSetup const&) {
@@ -696,23 +715,22 @@ void ScoutingMuonPropertiesAnalyzer::analyze(const edm::Event& iEvent, const edm
696715
using namespace edm;
697716

698717
edm::Handle<edm::TriggerResults> triggerResults;
699-
iEvent.getByToken(triggerResultsToken_, triggerResults);
700-
701718
edm::Handle<std::vector<Run3ScoutingMuon>> muonsNoVtx;
702-
iEvent.getByToken(muonsNoVtxToken_, muonsNoVtx);
703-
704719
edm::Handle<std::vector<Run3ScoutingMuon>> muonsVtx;
705-
iEvent.getByToken(muonsVtxToken_, muonsVtx);
720+
edm::Handle<std::vector<Run3ScoutingVertex>> SVNoVtx;
721+
edm::Handle<std::vector<Run3ScoutingVertex>> SVVtx;
722+
723+
if (!getValidHandle(iEvent, triggerResultsToken_, triggerResults, "TriggerResults") ||
724+
!getValidHandle(iEvent, muonsNoVtxToken_, muonsNoVtx, "muonsNoVtx") ||
725+
!getValidHandle(iEvent, muonsVtxToken_, muonsVtx, "muonsVtx") ||
726+
!getValidHandle(iEvent, SVNoVtxToken_, SVNoVtx, "SVNoVtx") ||
727+
!getValidHandle(iEvent, SVVtxToken_, SVVtx, "SVVtx")) {
728+
return;
729+
}
706730

707731
edm::Handle<std::vector<Run3ScoutingVertex>> PV;
708732
iEvent.getByToken(PVToken_, PV);
709733

710-
edm::Handle<std::vector<Run3ScoutingVertex>> SVNoVtx;
711-
iEvent.getByToken(SVNoVtxToken_, SVNoVtx);
712-
713-
edm::Handle<std::vector<Run3ScoutingVertex>> SVVtx;
714-
iEvent.getByToken(SVVtxToken_, SVVtx);
715-
716734
const TransientTrackBuilder* theB = &iSetup.getData(ttbESToken_);
717735

718736
h_run_->Fill(iEvent.eventAuxiliary().run());

0 commit comments

Comments
 (0)