From ac7fc23b86aaaa51b6f26ff67972c47938fa1989 Mon Sep 17 00:00:00 2001
From: Pascal Raisig <praisig@ikf.uni-frankfurt.de>
Date: Tue, 16 Mar 2021 18:02:05 +0100
Subject: [PATCH] Add a safety to capture digi=nullptr

In the processing routines for empty digi branches a situation could appear,
where nullptr were forwarded to unprotocted functions.
Now a protection against this situation and a safety against nullptr is implemented.
---
 reco/detectors/trd/CbmTrdClusterFinder.cxx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/reco/detectors/trd/CbmTrdClusterFinder.cxx b/reco/detectors/trd/CbmTrdClusterFinder.cxx
index 6324b16fd6..ecb64c6cd9 100644
--- a/reco/detectors/trd/CbmTrdClusterFinder.cxx
+++ b/reco/detectors/trd/CbmTrdClusterFinder.cxx
@@ -69,6 +69,7 @@ Bool_t CbmTrdClusterFinder::AddCluster(CbmTrdCluster* c)
 UInt_t CbmTrdClusterFinder::addDigisToModules()
 {
   UInt_t ndigis = static_cast<UInt_t>(std::abs(CbmDigiManager::Instance()->GetNofDigis(ECbmModuleId::kTrd)));
+  if (ndigis == 0) return 0;
   for (size_t idigi = 0; idigi < ndigis; idigi++) {
     addDigiToModule(idigi);
   }
@@ -79,6 +80,7 @@ UInt_t CbmTrdClusterFinder::addDigisToModules()
 UInt_t CbmTrdClusterFinder::addDigisToModules(CbmEvent* event)
 {
   UInt_t ndigis = static_cast<UInt_t>(std::abs(event->GetNofData(ECbmDataType::kTrdDigi)));
+  if (ndigis == 0) return 0;
   for (size_t idigi = 0; idigi < ndigis; idigi++) {
     auto digiindex = event->GetIndex(ECbmDataType::kTrdDigi, idigi);
     addDigiToModule(digiindex);
@@ -93,7 +95,7 @@ void CbmTrdClusterFinder::addDigiToModule(UInt_t digiIdx)
   CbmTrdModuleRec* mod = nullptr;
 
   const CbmTrdDigi* digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(digiIdx);
-
+  if (!digi) return;
   Int_t moduleAddress = digi->GetAddressModule();
 
   std::map<Int_t, CbmTrdModuleRec*>::iterator imod = fModules.find(moduleAddress);
-- 
GitLab