From 76d901043ed4e486c8e7a790ffe544e02028e153 Mon Sep 17 00:00:00 2001
From: christos <christos@cern.ch>
Date: Mon, 4 Jan 2021 21:42:27 +0100
Subject: [PATCH] Factor common code used by std and LRT egamma config. Reduce
 LRT config log verbosity. Some flake8 related stylistic fixes

---
 .vscode/settings.json                         |   3 +-
 .../egamma/egammaRec/python/egammaKeys.py     | 152 +++++++++++++-----
 .../egammaLRTOutputItemList_jobOptions.py     |  94 ++++-------
 .../share/egammaLRTRec_jobOptions.py          |  26 +--
 .../share/egammaOutputItemList_jobOptions.py  |  53 ++----
 .../egammaRec/share/egammaRec_jobOptions.py   |   4 +-
 6 files changed, 172 insertions(+), 160 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index e1ebff53d0f..25f4f91c00d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,5 +3,6 @@
         "ms-vscode.cpptools",
         "twxs.cmake"
     ],
-    "remote.SSH.lockfilesInTmp": true
+    "remote.SSH.lockfilesInTmp": true,
+    "python.pythonPath": "/bin/python3"
 }
diff --git a/Reconstruction/egamma/egammaRec/python/egammaKeys.py b/Reconstruction/egamma/egammaRec/python/egammaKeys.py
index 51f654eb9a9..587a2040040 100644
--- a/Reconstruction/egamma/egammaRec/python/egammaKeys.py
+++ b/Reconstruction/egamma/egammaRec/python/egammaKeys.py
@@ -3,7 +3,8 @@
 __doc__ = "egammaKeys.py"
 __author__ = "Bruno Lenzi"
 
-# Name (i.e Electron) = [type =type of the collection, key = name of the collection,
+# Name (i.e Electron) = [
+# type =type of the collection, key = name of the collection,
 # option = for aux container applied in ALL cases (ESD and AOD),
 # option =  for additional suppression for  AOD only]
 
@@ -18,52 +19,90 @@ class egammaKeysDict:
     FwdElectronisemSupress = '-isEMTight.-isEMMedium.-isEMLoose'
 
     outputs = dict(
-        Conversion=['xAOD::VertexContainer',
-                    'GSFConversionVertices', '-vxTrackAtVertex.', ''],
-        Cluster=['xAOD::CaloClusterContainer', 'egammaClusters', '', ''],
-        EgammaLargeClusters=['xAOD::CaloClusterContainer',
-                             'egamma711Clusters', '', ''],  # not output to AOD
-        EgammaLargeFWDClusters=['xAOD::CaloClusterContainer',
-                                'egamma66FWDClusters', '', ''],  # not output to AOD
-        TopoSeededCluster=['xAOD::CaloClusterContainer',
-                           'egammaTopoSeededClusters', '', '-CellLink'],
-        Electron=['xAOD::ElectronContainer', 'Electrons',
-                  '', ShowerShapesSuppress+ElectronisemSupress],
-        EgammaRec=['egammaRecContainer', 'egammaRecCollection', '', ''],
-        PhotonSuperRec=['egammaRecContainer',
-                        'PhotonSuperRecCollection', '', ''],
-        ElectronSuperRec=['egammaRecContainer',
-                          'ElectronSuperRecCollection', '', ''],
+        Conversion=[
+            'xAOD::VertexContainer',
+            'GSFConversionVertices',
+            '-vxTrackAtVertex.',
+            ''],
+        Cluster=[
+            'xAOD::CaloClusterContainer',
+            'egammaClusters',
+            '',
+            ''],
+        EgammaLargeClusters=[
+            'xAOD::CaloClusterContainer',
+            'egamma711Clusters', '', ''],
+        EgammaLargeFWDClusters=[
+            'xAOD::CaloClusterContainer',
+            'egamma66FWDClusters',
+            '',
+            ''],
+        TopoSeededCluster=[
+            'xAOD::CaloClusterContainer',
+            'egammaTopoSeededClusters',
+            '',
+            '-CellLink'],
+        Electron=[
+            'xAOD::ElectronContainer',
+            'Electrons',
+            '',
+            ShowerShapesSuppress+ElectronisemSupress],
+        EgammaRec=['egammaRecContainer',
+                   'egammaRecCollection',
+                   '',
+                   ''],
+        PhotonSuperRec=[
+            'egammaRecContainer',
+            'PhotonSuperRecCollection', '', ''],
+        ElectronSuperRec=[
+            'egammaRecContainer',
+            'ElectronSuperRecCollection', '', ''],
         FwdElectron=['xAOD::ElectronContainer',
-                     'ForwardElectrons', '', FwdElectronisemSupress],
+                     'ForwardElectrons',
+                     '',
+                     FwdElectronisemSupress],
         FwdCluster=['xAOD::CaloClusterContainer',
-                    'ForwardElectronClusters', '-SisterCluster', ''],
-        Photon=['xAOD::PhotonContainer', 'Photons', '',
+                    'ForwardElectronClusters',
+                    '-SisterCluster', ''],
+        Photon=['xAOD::PhotonContainer',
+                'Photons', '',
                 ShowerShapesSuppress+PhotonisemSupress],
-        TrackParticle=['xAOD::TrackParticleContainer', 'GSFTrackParticles',
-                       '-caloExtension.-cellAssociation.-perigeeExtrapEta.-perigeeExtrapPhi', ''],
-        Track=['TrackCollection', 'GSFTracks', '', ''],
+        TrackParticle=[
+            'xAOD::TrackParticleContainer',
+            'GSFTrackParticles',
+            '-caloExtension.-cellAssociation.-perigeeExtrapEta.-perigeeExtrapPhi', ''],
+        Track=['TrackCollection',
+               'GSFTracks',
+               '',
+               ''],
         Truth=['xAOD::TruthParticleContainer',
-               'egammaTruthParticles', '-caloExtension', '']
+               'egammaTruthParticles',
+               '-caloExtension',
+               '']
     )
     #
-    outputs['CellLink'] = ['CaloClusterCellLinkContainer',
-                           outputs['Cluster'][1] + '_links', '', '']
-    outputs['TopoSeededCellLink'] = ['CaloClusterCellLinkContainer',
-                                     outputs['TopoSeededCluster'][1] +
-                                     '_links',
-                                     '', '']
-    outputs['FwdClusterCellLink'] = ['CaloClusterCellLinkContainer',
-                                     outputs['FwdCluster'][1] + '_links',
-                                     '', '']
-    outputs['EgammaLargeClustersCellLink'] = ['CaloClusterCellLinkContainer',
-                                              outputs['EgammaLargeClusters'][1] +
-                                              '_links',
-                                              '', '']
-    outputs['EgammaLargeFWDClustersCellLink'] = ['CaloClusterCellLinkContainer',
-                                              outputs['EgammaLargeFWDClusters'][1] +
-                                              '_links',
-                                              '', '']
+    outputs['CellLink'] = [
+        'CaloClusterCellLinkContainer',
+        outputs['Cluster'][1] + '_links', '', '']
+    outputs['TopoSeededCellLink'] = [
+        'CaloClusterCellLinkContainer',
+        outputs['TopoSeededCluster'][1] +
+        '_links',
+        '', '']
+    outputs['FwdClusterCellLink'] = [
+        'CaloClusterCellLinkContainer',
+        outputs['FwdCluster'][1] + '_links',
+        '', '']
+    outputs['EgammaLargeClustersCellLink'] = [
+        'CaloClusterCellLinkContainer',
+        outputs['EgammaLargeClusters'][1] +
+        '_links',
+        '', '']
+    outputs['EgammaLargeFWDClustersCellLink'] = [
+        'CaloClusterCellLinkContainer',
+        outputs['EgammaLargeFWDClusters'][1] +
+        '_links',
+        '', '']
     #
 
 
@@ -99,3 +138,34 @@ def truthParticleKey():
 
 def truthEventKey():
     return 'TruthEvents'
+
+
+def getItem(cType, cKey):
+    """getItem(cType, cKey) -> Return item to be added
+    to the output list: <cType>#<cKey>"""
+    return '%s#%s' % (cType, cKey)
+
+
+def getAuxItem(cType, cKey, auxOptionAll='', auxOptionAOD=''):
+    """getAuxItem(cType, cKey, auxOption='')
+    -> <cType>#<cKey>Aux.<auxOption>"""
+    auxType = cType.replace('Container', 'AuxContainer')
+    auxKey = cKey + 'Aux.'
+    return '%s#%s%s%s' % (auxType, auxKey, auxOptionAll, auxOptionAOD)
+
+
+def addContainer(outputList, cType, cKey):
+    """addContainer(outputList, cType, cKey)
+    -> Add container to outputList"""
+    # Skip containers if already in outputList
+    item = getItem(cType, cKey)
+    if item not in outputList:
+        outputList.append(item)
+
+
+def addAuxContainer(outputList, cType, cKey, auxOptionAll='', auxOptionAOD=''):
+    """addAux(outputList, cType, cKey, auxOption='')
+     -> Add aux container to outputList"""
+    item = getAuxItem(cType, cKey, auxOptionAll, auxOptionAOD)
+    if item not in outputList:
+        outputList.append(item)
diff --git a/Reconstruction/egamma/egammaRec/share/egammaLRTOutputItemList_jobOptions.py b/Reconstruction/egamma/egammaRec/share/egammaLRTOutputItemList_jobOptions.py
index cffca24281b..08eb3e8928f 100755
--- a/Reconstruction/egamma/egammaRec/share/egammaLRTOutputItemList_jobOptions.py
+++ b/Reconstruction/egamma/egammaRec/share/egammaLRTOutputItemList_jobOptions.py
@@ -3,79 +3,52 @@
 __doc__ = """Add containers to ESD/AOD ItemList using
 the definitions from egammaKeys"""
 from egammaRec import egammaKeys
-from egammaRec.egammaKeys import egammaKeysDict
+from egammaRec.egammaKeys import (
+    egammaKeysDict,
+    getItem,
+    addContainer,
+    addAuxContainer)
 from AthenaCommon.Logging import logging
 from RecExConfig.RecFlags import rec
 
 
-def getItem(cType, cKey):
-    """getItem(cType, cKey) -> Return item to be added
-    to the output list: <cType>#<cKey>"""
-    return '%s#%s' % (cType, cKey)
-
-
-def getAuxItem(cType, cKey, auxOptionAll='', auxOptionAOD=''):
-    """getAuxItem(cType, cKey, auxOption='')
-    -> <cType>#<cKey>Aux.<auxOption>"""
-    auxType = cType.replace('Container', 'AuxContainer')
-    auxKey = cKey + 'Aux.'
-    return '%s#%s%s%s' % (auxType, auxKey, auxOptionAll, auxOptionAOD)
-
-
-def addContainer(outputList, cType, cKey):
-    """addContainer(outputList, cType, cKey)
-    -> Add container to outputList"""
-    # Skip containers if already in outputList
-    item = getItem(cType, cKey)
-    if item not in outputList:
-        outputList.append(item)
-
-
-def addAuxContainer(outputList, cType, cKey, auxOptionAll='', auxOptionAOD=''):
-    """addAux(outputList, cType, cKey, auxOption='')
-     -> Add aux container to outputList"""
-    item = getAuxItem(cType, cKey, auxOptionAll, auxOptionAOD)
-    if item not in outputList:
-        outputList.append(item)
-
-
 # List for of keys to be written to AOD.
 # All egammaKeys.outputs but EgammaRec and TopoSeededCellLink
 
 AOD_outputs = [i for i, j in egammaKeysDict.outputs.items()
-               if i not in ('EgammaRec', 
-                            'ElectronSuperRec', 
+               if i not in ('EgammaRec',
+                            'ElectronSuperRec',
                             'EgammaLargeClusters',
                             'EgammaLargeClustersCellLink',
                             'CellLink',
                             'TopoSeededCellLink',
-                            'EgammaLargeClusters', 
-                            'EgammaLargeClustersCellLink', 
-                            'Photon', 
-                            'PhotonSuperRec', 
-                            'FwdElectron', 
-                            'FwdCluster', 
-                            'FwdClusterCellLink', 
+                            'EgammaLargeClusters',
+                            'EgammaLargeClustersCellLink',
+                            'Photon',
+                            'PhotonSuperRec',
+                            'FwdElectron',
+                            'FwdCluster',
+                            'FwdClusterCellLink',
                             'Conversion'
-                        )]
+                            )]
 
 
 ESD_outputs = [i for i, j in egammaKeysDict.outputs.items()
-               if i not in ('EgammaRec', 
-                            'ElectronSuperRec', 
+               if i not in ('EgammaRec',
+                            'ElectronSuperRec',
                             'EgammaLargeClusters',
                             'EgammaLargeClustersCellLink',
                             'TopoSeededCellLink',
                             'CellLink',
-                            'EgammaLargeClusters', 
-                            'EgammaLargeClustersCellLink', 
-                            'Photon', 
-                            'PhotonSuperRec', 
-                            'FwdElectron', 
-                            'FwdCluster', 
-                            'FwdClusterCellLink', 
+                            'EgammaLargeClusters',
+                            'EgammaLargeClustersCellLink',
+                            'Photon',
+                            'PhotonSuperRec',
+                            'FwdElectron',
+                            'FwdCluster',
+                            'FwdClusterCellLink',
                             'Conversion'
-                        )]
+                            )]
 
 # Define egammaLRTAODList in the proper format (<type>#<key><option>),
 # including aux containers
@@ -99,7 +72,8 @@ for i in AOD_outputs:
 
     # Add aux containers for xAOD containers
     if 'xAOD::' in cType:
-        addAuxContainer(egammaLRTAODList, cType, cKey, auxOptionAll, auxOptionAOD)
+        addAuxContainer(egammaLRTAODList, cType, cKey,
+                        auxOptionAll, auxOptionAOD)
 
 for i in ESD_outputs:
     cType, cKey, auxOptionAll, auxOptionAOD = egammaKeysDict.outputs[i]
@@ -107,7 +81,6 @@ for i in ESD_outputs:
     # Tag LRT containers
     cKey = 'LRT' + cKey
 
-
     # Skip truth if doTruth = False
     if not rec.doTruth() and 'Truth' in cKey:
         continue
@@ -124,12 +97,15 @@ for i in ESD_outputs:
 
 
 # Add the non xAOD kind of  collection in the ESD
-egammaLRTESDList.append(getItem(egammaKeys.outputTrackType(),
-                                egammaKeys.outputTrackKey()).replace('#','#LRT'))
+egammaLRTESDList.append(getItem(
+    egammaKeys.outputTrackType(),
+    egammaKeys.outputTrackKey()).replace('#', '#LRT'))
 egammaLRTESDList.append(getItem(egammaKeys.outputTopoSeededCellLinkType(
-), egammaKeys.outputTopoSeededCellLinkKey()).replace('#','#LRT'))
+), egammaKeys.outputTopoSeededCellLinkKey()).replace('#', '#LRT'))
 
 logEgammaLRTOutputItemList_jobOptions = logging.getLogger(
     'egammaLRTOutputItemList_jobOptions')
-logEgammaLRTOutputItemList_jobOptions.info('egammaLRTESDList: %s',  egammaLRTESDList)
-logEgammaLRTOutputItemList_jobOptions.info('egammaLRTAODList: %s',  egammaLRTAODList)
+logEgammaLRTOutputItemList_jobOptions.info(
+    'egammaLRTESDList: %s',  egammaLRTESDList)
+logEgammaLRTOutputItemList_jobOptions.info(
+    'egammaLRTAODList: %s',  egammaLRTAODList)
diff --git a/Reconstruction/egamma/egammaRec/share/egammaLRTRec_jobOptions.py b/Reconstruction/egamma/egammaRec/share/egammaLRTRec_jobOptions.py
index 39d59d0afc3..3b7f4ca669a 100755
--- a/Reconstruction/egamma/egammaRec/share/egammaLRTRec_jobOptions.py
+++ b/Reconstruction/egamma/egammaRec/share/egammaLRTRec_jobOptions.py
@@ -1,9 +1,6 @@
 # all these tests, except egamma, should be in egammaGetter
-from CaloRec.CaloRecFlags import jobproperties
 from egammaRec.egammaRecFlags import jobproperties
-from RecExConfig.RecFlags import rec
 from AthenaCommon.Resilience import treatException
-from AthenaCommon.DetFlags import DetFlags
 from AthenaCommon.AlgSequence import AlgSequence
 
 topSequence = AlgSequence()
@@ -16,7 +13,7 @@ def setupGSF_LRT():
     try:
         from egammaRec.LRTEgammaConfig import (
             LRTegammaSelectedTrackCopy)
-        LRTegammaSelectedTrackCopy(doPrint=True) # for debugging
+        LRTegammaSelectedTrackCopy(doPrint=False)  # for debugging
     except Exception:
         treatException(
             "Could not set up the egamma track Selection for LRT GSF."
@@ -24,7 +21,7 @@ def setupGSF_LRT():
     try:
         from egammaRec.LRTEgammaConfig import (
             LRTEMBremCollectionBuilder)
-        LRTEMBremCollectionBuilder(doPrint=True)
+        LRTEMBremCollectionBuilder(doPrint=False)
     except Exception:
         treatException(
             "Could not set up LRTEMBremCollectionBuilder."
@@ -32,7 +29,7 @@ def setupGSF_LRT():
     try:
         from egammaRec.LRTEgammaConfig import (
             LRTEMGSFCaloExtensionBuilder)
-        LRTEMGSFCaloExtensionBuilder(doPrint=True)
+        LRTEMGSFCaloExtensionBuilder(doPrint=False)
     except Exception:
         treatException("Could not set up LRTEMGSFCaloExtensionBuilder.")
 
@@ -45,29 +42,18 @@ def setupTopoSeededEgamma_LRT():
         from egammaRec.LRTtopoEgammaGetter import LRTtopoEgammaGetter
         LRTtopoEgammaGetter(ignoreExistingDataObject=True)
     except Exception:
-        treatException("Could not set up  LRTtopoEgammaGetter. Switch it off !")
+        treatException(
+            "Could not set up  LRTtopoEgammaGetter. Switch it off !")
         # If we wanted Topo based cluster seeded egamma it just failed
         jobproperties.egammaRecFlags.doEgammaCaloSeeded = False
         LRTtopoEgammaGetter(disable=True)
 
-#def setupTopoSeededEgamma_LRT():
-#    try:
-#        from egammaRec.LRTEgammaConfig import (
-#            LRTtopoEgammaBuilder)
-#        LRTtopoEgammaBuilder(doPrint=True)
-#    except Exception:
-#        treatException("Could not set up  LRTtopoEgammaBuilder. Switch it off !")
-#        # If we wanted Topo based cluster seeded egamma it just failed
-#        LRTtopoEgammaBuilder(disable=True)
-
-# Function to schedule the Truth Association
-
 
 def setupTruthAssociation_LRT():
     try:
         from egammaRec.LRTEgammaConfig import (
             LRTegammaTruthAssociationAlg)
-        LRTegammaTruthAssociationAlg(doPrint=True)
+        LRTegammaTruthAssociationAlg(doPrint=False)
     except Exception:
         treatException(
             "Could not set up LRTegammaTruthAssociationAlg. Switched off !")
diff --git a/Reconstruction/egamma/egammaRec/share/egammaOutputItemList_jobOptions.py b/Reconstruction/egamma/egammaRec/share/egammaOutputItemList_jobOptions.py
index 7b3d2acebc6..463e3fa2649 100755
--- a/Reconstruction/egamma/egammaRec/share/egammaOutputItemList_jobOptions.py
+++ b/Reconstruction/egamma/egammaRec/share/egammaOutputItemList_jobOptions.py
@@ -3,54 +3,33 @@
 __doc__ = """Add containers to ESD/AOD ItemList using
 the definitions from egammaKeys"""
 from egammaRec import egammaKeys
-from egammaRec.egammaKeys import egammaKeysDict
+from egammaRec.egammaKeys import (
+    egammaKeysDict,
+    getItem,
+    addContainer,
+    addAuxContainer)
 from AthenaCommon.Logging import logging
 from RecExConfig.RecFlags import rec
 
 
-def getItem(cType, cKey):
-    """getItem(cType, cKey) -> Return item to be added
-    to the output list: <cType>#<cKey>"""
-    return '%s#%s' % (cType, cKey)
-
-
-def getAuxItem(cType, cKey, auxOptionAll='', auxOptionAOD=''):
-    """getAuxItem(cType, cKey, auxOption='')
-    -> <cType>#<cKey>Aux.<auxOption>"""
-    auxType = cType.replace('Container', 'AuxContainer')
-    auxKey = cKey + 'Aux.'
-    return '%s#%s%s%s' % (auxType, auxKey, auxOptionAll, auxOptionAOD)
-
-
-def addContainer(outputList, cType, cKey):
-    """addContainer(outputList, cType, cKey)
-    -> Add container to outputList"""
-    # Skip containers if already in outputList
-    item = getItem(cType, cKey)
-    if item not in outputList:
-        outputList.append(item)
-
-
-def addAuxContainer(outputList, cType, cKey, auxOptionAll='', auxOptionAOD=''):
-    """addAux(outputList, cType, cKey, auxOption='')
-     -> Add aux container to outputList"""
-    item = getAuxItem(cType, cKey, auxOptionAll, auxOptionAOD)
-    if item not in outputList:
-        outputList.append(item)
-
-
 # List for of keys to be written to AOD.
 # All egammaKeys.outputs but EgammaRec and TopoSeededCellLink
 AOD_outputs = [i for i, j in egammaKeysDict.outputs.items()
-               if i not in ('EgammaRec', 'PhotonSuperRec',
-                            'ElectronSuperRec', 'TopoSeededCellLink',
+               if i not in ('EgammaRec',
+                            'PhotonSuperRec',
+                            'ElectronSuperRec',
+                            'TopoSeededCellLink',
                             'EgammaLargeClusters',
-                            'EgammaLargeClustersCellLink','EgammaLargeFWDClusters', 'EgammaLargeFWDClustersCellLink')]
+                            'EgammaLargeClustersCellLink',
+                            'EgammaLargeFWDClusters',
+                            'EgammaLargeFWDClustersCellLink')]
 
 
 ESD_outputs = [i for i, j in egammaKeysDict.outputs.items()
-               if i not in ('EgammaRec', 'PhotonSuperRec',
-                            'ElectronSuperRec', 'TopoSeededCellLink')]
+               if i not in ('EgammaRec',
+                            'PhotonSuperRec',
+                            'ElectronSuperRec',
+                            'TopoSeededCellLink')]
 
 # Define egammaAODList in the proper format (<type>#<key><option>),
 # including aux containers
diff --git a/Reconstruction/egamma/egammaRec/share/egammaRec_jobOptions.py b/Reconstruction/egamma/egammaRec/share/egammaRec_jobOptions.py
index 813a11cab2a..7ac2adcfcd9 100755
--- a/Reconstruction/egamma/egammaRec/share/egammaRec_jobOptions.py
+++ b/Reconstruction/egamma/egammaRec/share/egammaRec_jobOptions.py
@@ -1,5 +1,5 @@
 # all these tests, except egamma, should be in egammaGetter
-from CaloRec.CaloRecFlags import jobproperties
+from CaloRec.CaloRecFlags import jobproperties as caloproperties
 from egammaRec.egammaRecFlags import jobproperties
 from RecExConfig.RecFlags import rec
 from AthenaCommon.Resilience import treatException
@@ -21,7 +21,7 @@ if not DetFlags.detdescr.ID_on():
     jobproperties.egammaRecFlags.doVertexBuilding = False
 
 # We can not run without having the Calo
-if not (rec.readESD() or jobproperties.CaloRecFlags.doCaloTopoCluster()):
+if not (rec.readESD() or caloproperties.CaloRecFlags.doCaloTopoCluster()):
     jobproperties.egammaRecFlags.doEgammaCaloSeeded = False
     jobproperties.egammaRecFlags.doEgammaForwardSeeded = False
 
-- 
GitLab