From 5ac3f25b4bfcd91f3128f12b22fd9b339724d43d Mon Sep 17 00:00:00 2001 From: scott snyder Date: Fri, 15 Dec 2023 18:42:29 -0500 Subject: [PATCH] Always record the output collection, even if it is empty. The output code decides what to write based on the contents of the first event. If we don't always record the collection, then it can either be missing in the output, or we can get crashes when the output code tries to access a nonexistent collection. --- .../src/MarlinLumiCalClusterer.cpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/source/LumiCalReco/src/MarlinLumiCalClusterer.cpp b/source/LumiCalReco/src/MarlinLumiCalClusterer.cpp index 48dfb32..65ae183 100644 --- a/source/LumiCalReco/src/MarlinLumiCalClusterer.cpp +++ b/source/LumiCalReco/src/MarlinLumiCalClusterer.cpp @@ -57,8 +57,7 @@ void MarlinLumiCalClusterer::TryMarlinLumiCalClusterer(EVENT::LCEvent* evt) { create clusters using: LumiCalClustererClass -------------------------------------------------------------------------- */ - if (!LumiCalClusterer.processEvent(evt)) - return; + bool stat = LumiCalClusterer.processEvent(evt); LCCollectionVec* LCalClusterCol = new LCCollectionVec(LCIO::CLUSTER); IMPL::LCFlagImpl lcFlagImpl; @@ -67,27 +66,29 @@ void MarlinLumiCalClusterer::TryMarlinLumiCalClusterer(EVENT::LCEvent* evt) { LCCollectionVec* LCalRPCol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE); - streamlog_out(DEBUG6) << " Transfering reco results to LCalClusterCollection....." << std::endl; + if (stat) { + streamlog_out(DEBUG6) << " Transfering reco results to LCalClusterCollection....." << std::endl; - for (int armNow = -1; armNow < 2; armNow += 2) { - streamlog_out(DEBUG6) << " Arm " << std::setw(4) << armNow - << "\t Number of clusters: " << LumiCalClusterer._superClusterIdToCellId[armNow].size() - << std::endl; + for (int armNow = -1; armNow < 2; armNow += 2) { + streamlog_out(DEBUG6) << " Arm " << std::setw(4) << armNow + << "\t Number of clusters: " << LumiCalClusterer._superClusterIdToCellId[armNow].size() + << std::endl; - for (auto const& pairIDCells : LumiCalClusterer._superClusterIdToCellId[armNow]) { - const int clusterId = pairIDCells.first; - LCCluster& thisClusterInfo = LumiCalClusterer._superClusterIdClusterInfo[armNow][clusterId]; - thisClusterInfo.recalculatePositionFromHits(gmc); - auto objectTuple(gmc.getLCIOObjects(thisClusterInfo, _minClusterEngy, _cutOnFiducialVolume)); - if (std::get<0>(objectTuple) == nullptr) - continue; + for (auto const& pairIDCells : LumiCalClusterer._superClusterIdToCellId[armNow]) { + const int clusterId = pairIDCells.first; + LCCluster& thisClusterInfo = LumiCalClusterer._superClusterIdClusterInfo[armNow][clusterId]; + thisClusterInfo.recalculatePositionFromHits(gmc); + auto objectTuple(gmc.getLCIOObjects(thisClusterInfo, _minClusterEngy, _cutOnFiducialVolume)); + if (std::get<0>(objectTuple) == nullptr) + continue; - LCalClusterCol->addElement(std::get<0>(objectTuple)); - LCalRPCol->addElement(std::get<1>(objectTuple)); + LCalClusterCol->addElement(std::get<0>(objectTuple)); + LCalRPCol->addElement(std::get<1>(objectTuple)); + } } } - //Add collections to the event if there are clusters + //Add collections to the event evt->addCollection(LCalClusterCol, LumiClusterColName); evt->addCollection(LCalRPCol, LumiRecoParticleColName);