From a29b901a8ed9ab589a73f19903d25a80c57f7b44 Mon Sep 17 00:00:00 2001
From: John Chapman <John.Chapman@cern.ch>
Date: Thu, 13 Mar 2025 15:17:46 +0100
Subject: [PATCH] LArG4ShowerLibSvc: Throw an error if the expected frozen
 shower libraries are not all loaded (ATLASSIM-7444)

---
 .../src/LArG4ShowerLibSvc.cxx                 | 30 +++++++++++++------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/LArCalorimeter/LArG4/LArG4ShowerLibSvc/src/LArG4ShowerLibSvc.cxx b/LArCalorimeter/LArG4/LArG4ShowerLibSvc/src/LArG4ShowerLibSvc.cxx
index dd29b5a9a19..c3ddf5992d3 100755
--- a/LArCalorimeter/LArG4/LArG4ShowerLibSvc/src/LArG4ShowerLibSvc.cxx
+++ b/LArCalorimeter/LArG4/LArG4ShowerLibSvc/src/LArG4ShowerLibSvc.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "LArG4ShowerLibSvc/LArG4ShowerLibSvc.h"
@@ -45,11 +45,13 @@ StatusCode LArG4ShowerLibSvc::initialize()
 {
   ATH_MSG_INFO("Initializing");
 
+  std::vector<std::string> ignoredLibraryFiles{};
   // iterate through filenames in list
   for (const std::string& fileName : m_fileNameList) {
     std::string resolvedFilename = PathResolverFindCalibFile(fileName);
     if (resolvedFilename.empty()) {
       ATH_MSG_WARNING("Could not resolve input filename " << (fileName) << ". Ignoring!");
+      ignoredLibraryFiles.push_back(fileName);
       continue;
     } else {
       ATH_MSG_INFO("Resolving input filename to " << resolvedFilename);
@@ -59,6 +61,7 @@ StatusCode LArG4ShowerLibSvc::initialize()
 
     if (rootfile.IsZombie()) {
       ATH_MSG_WARNING("File " << resolvedFilename << " is not a valid ROOT file");
+      ignoredLibraryFiles.push_back(fileName);
       continue;
     }
 
@@ -70,11 +73,13 @@ StatusCode LArG4ShowerLibSvc::initialize()
     // if no library can be created based on the file nullptr is returned
     if (library == nullptr) {
       ATH_MSG_WARNING("File " << resolvedFilename << " is not a valid library file");
+      ignoredLibraryFiles.push_back(fileName);
       continue;
     }
 
     if (m_detmap.find(library->detector()) == m_detmap.end()) {
       ATH_MSG_WARNING("Library " << resolvedFilename << " is produced for unknown detector: " << library->detector());
+      ignoredLibraryFiles.push_back(fileName);
       delete library;
       continue;
     }
@@ -96,17 +101,24 @@ StatusCode LArG4ShowerLibSvc::initialize()
 
   // no point in the service with no libraries
   if (m_libraryMap.empty()) {
-    ATH_MSG_WARNING("No library files found");
-  } else {
-    ATH_MSG_INFO("List of loaded libraries:");
-    for (const auto& m : m_libraryMap) {
-      ATH_MSG_INFO("      " << m_locations[m.first] << ": " << m.second->comment());
+    ATH_MSG_ERROR("No library files found. Please check the configuration of this job.");
+    return StatusCode::FAILURE;
+  }
+  // some of the configured library files did not work
+  if (!ignoredLibraryFiles.empty() ) {
+    for (const std::string& fileName : ignoredLibraryFiles) {
+      ATH_MSG_ERROR("Failed to create a library from filename: " << (fileName));
+    }
+    ATH_MSG_ERROR("Some library filenames were invalid. Please check the configuration of this job.");
+    return StatusCode::FAILURE;
+  }
+  ATH_MSG_INFO("List of loaded libraries:");
+  for (const auto& m : m_libraryMap) {
+    ATH_MSG_INFO("      " << m_locations[m.first] << ": " << m.second->comment());
 #ifdef DEBUG_FrozenShowers
-      m_statisticsMap[m.second] = m.second->createStatistics();
+    m_statisticsMap[m.second] = m.second->createStatistics();
 #endif
-    }
   }
-
   ATH_MSG_INFO("Shower library successfully initialized.");
 
   return StatusCode::SUCCESS;
-- 
GitLab