From a24eeb4ebaf5c75a236083b55b39aaca34e8826d Mon Sep 17 00:00:00 2001
From: Tadej Novak <tadej.novak@cern.ch>
Date: Mon, 25 Nov 2024 11:15:47 +0100
Subject: [PATCH] LArGMConfig: use GeoModel.Align.LegacyConditionsAccess

LArGMConfig: use GeoModel.Align.LegacyConditionsAccess to decide if conditions algorithms are needed
---
 .../python/GeoModelConfigFlags.py             | 25 +++++++++++++------
 .../LArGeoAlgsNV/python/LArGMConfig.py        |  9 +++----
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/Control/AthenaConfiguration/python/GeoModelConfigFlags.py b/Control/AthenaConfiguration/python/GeoModelConfigFlags.py
index b00b04dcb164..f9a1a0425e67 100644
--- a/Control/AthenaConfiguration/python/GeoModelConfigFlags.py
+++ b/Control/AthenaConfiguration/python/GeoModelConfigFlags.py
@@ -17,7 +17,7 @@ def createGeoModelConfigFlags(analysis=False):
 
     # Special handling of analysis releases where we only want AtlasVersion and Run
     if analysis:
-        def _deduct_LHCPeriod(prevFlags):
+        def _deduce_LHCPeriod(prevFlags):
             import logging
             log = logging.getLogger("GeoModelConfigFlags")
             log.info('Deducing LHC Run period from the geometry tag name "%s" as database access is not available in analysis releases', prevFlags.GeoModel.AtlasVersion)
@@ -31,16 +31,16 @@ def createGeoModelConfigFlags(analysis=False):
             elif prevFlags.GeoModel.AtlasVersion.startswith("ATLAS-R3"):
                 period = LHCPeriod.Run3
             else:
-                raise ValueError(f'Can not deduct LHC Run period from "{prevFlags.GeoModel.AtlasVersion}", please set "flags.GeoModel.Run" manually.')
+                raise ValueError(f'Can not deduce LHC Run period from "{prevFlags.GeoModel.AtlasVersion}", please set "flags.GeoModel.Run" manually.')
 
             log.info('Using LHC Run period "%s"', period.value)
             return period
 
-        gcf.addFlag("GeoModel.Run",  # Run deducted from other metadata
-                    _deduct_LHCPeriod, type=LHCPeriod, help='LHC Run period')
+        gcf.addFlag("GeoModel.Run",  # Run deduced from other metadata
+                    _deduce_LHCPeriod, type=LHCPeriod, help='LHC Run period')
         return gcf
 
-    def _deduct_LHCPeriod(prevFlags):
+    def _deduce_LHCPeriod(prevFlags):
         if prevFlags.GeoModel.AtlasVersion:
             return LHCPeriod(DetDescrInfo(prevFlags.GeoModel.AtlasVersion,prevFlags.GeoModel.SQLiteDB,prevFlags.GeoModel.SQLiteDBFullPath)['Common']['Run'])
 
@@ -56,7 +56,7 @@ def createGeoModelConfigFlags(analysis=False):
 
         raise RuntimeError('Can not determine LHC period from the data project name')
 
-    gcf.addFlag("GeoModel.Run", _deduct_LHCPeriod, type=LHCPeriod, help='LHC Run period')
+    gcf.addFlag("GeoModel.Run", _deduce_LHCPeriod, type=LHCPeriod, help='LHC Run period')
 
     gcf.addFlag('GeoModel.Layout', 'atlas', help='Geometry layout') # replaces global.GeoLayout
 
@@ -65,8 +65,17 @@ def createGeoModelConfigFlags(analysis=False):
                 # TODO: dynamic alignment is for now enabled by default for data overlay
                 # to disable, add 'and prevFlags.Common.ProductionStep not in [ProductionStep.Simulation, ProductionStep.Overlay]'
 
-    gcf.addFlag("GeoModel.Align.LegacyConditionsAccess",
-                lambda prevFlags : prevFlags.Common.Project is Project.AthSimulation or prevFlags.Common.ProductionStep is ProductionStep.Simulation,
+    def _deduce_LegacyConditionsAccess(prevFlags):
+        if prevFlags.Common.Project is Project.AthSimulation:
+            return True
+        if prevFlags.Common.ProductionStep is not ProductionStep.Simulation:
+            return False
+        from SimulationConfig.SimEnums import LArParameterization
+        if prevFlags.Sim.ISF.Simulator.usesFastCaloSim() or prevFlags.Sim.LArParameterization is LArParameterization.FastCaloSim:
+            return False
+        return True
+
+    gcf.addFlag("GeoModel.Align.LegacyConditionsAccess", _deduce_LegacyConditionsAccess,
                 help='Flag for using the legacy conditions access infrastructure')
                 # Mainly for G4 which still loads alignment on initialize
 
diff --git a/LArCalorimeter/LArGeoModel/LArGeoAlgsNV/python/LArGMConfig.py b/LArCalorimeter/LArGeoModel/LArGeoAlgsNV/python/LArGMConfig.py
index 94772afd84b2..e889daf2d34f 100644
--- a/LArCalorimeter/LArGeoModel/LArGeoAlgsNV/python/LArGMConfig.py
+++ b/LArCalorimeter/LArGeoModel/LArGeoAlgsNV/python/LArGMConfig.py
@@ -2,13 +2,12 @@
 
 from AtlasGeoModel.GeoModelConfig import GeoModelCfg
 from AthenaConfiguration.ComponentFactory import CompFactory
-from AthenaConfiguration.Enums import LHCPeriod, ProductionStep, Project
+from AthenaConfiguration.Enums import LHCPeriod, ProductionStep
 from IOVDbSvc.IOVDbSvcConfig import addFolders
 
 def LArGMCfg(flags):    
     result=GeoModelCfg(flags)
 
-    activateCondAlgs = flags.Common.Project is not Project.AthSimulation
     tool = CompFactory.LArDetectorToolNV(ApplyAlignments=flags.LAr.doAlign, EnableMBTS=flags.Detector.GeometryMBTS)
     if flags.Common.ProductionStep != ProductionStep.Simulation and flags.Common.ProductionStep != ProductionStep.FastChain:
         tool.GeometryConfig = "RECO"
@@ -18,7 +17,7 @@ def LArGMCfg(flags):
     if flags.LAr.doAlign:
         if flags.Input.isMC:
             #Monte Carlo case:
-            if activateCondAlgs:
+            if not flags.GeoModel.Align.LegacyConditionsAccess:
                 result.merge(addFolders(flags,"/LAR/Align","LAR_OFL",className="DetCondKeyTrans"))
                 result.merge(addFolders(flags,"/LAR/LArCellPositionShift","LAR_OFL",className="CaloRec::CaloCellPositionShift"))
             else:
@@ -28,7 +27,7 @@ def LArGMCfg(flags):
             result.merge(addFolders(flags,"/LAR/Align","LAR_ONL",className="DetCondKeyTrans"))
             result.merge(addFolders(flags,"/LAR/LArCellPositionShift","LAR_ONL",className="CaloRec::CaloCellPositionShift"))
 
-        if activateCondAlgs:
+        if not flags.GeoModel.Align.LegacyConditionsAccess:
             result.addCondAlgo(CompFactory.LArAlignCondAlg())
             result.addCondAlgo(CompFactory.CaloAlignCondAlg())
             AthReadAlg_ExtraInputs = set()
@@ -63,7 +62,7 @@ def LArGMCfg(flags):
                     result.addCondAlgo(AthReadAlg_CaloCellCont)
     else:
         # Build unalinged CaloDetDescrManager instance in the Condition Store
-        if activateCondAlgs:
+        if not flags.GeoModel.Align.LegacyConditionsAccess:
             result.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
             if flags.GeoModel.Run >= LHCPeriod.Run3 and flags.Detector.GeometryTile and flags.Common.ProductionStep != ProductionStep.Overlay:
                 # TODO: avoid depending on Tile in SuperCell alignment
-- 
GitLab