From 2e064e2e21a5c6c0f324b3ded11040cfd5644b13 Mon Sep 17 00:00:00 2001
From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Date: Mon, 17 Apr 2023 16:31:45 -0400
Subject: [PATCH] DD4hepSimulation: define HEPMC3_SUPPORTED_EXTENSIONS

---
 DDG4/python/DDSim/DD4hepSimulation.py | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py
index a3779e923..41e41c224 100644
--- a/DDG4/python/DDSim/DD4hepSimulation.py
+++ b/DDG4/python/DDSim/DD4hepSimulation.py
@@ -41,13 +41,16 @@ try:
 except ImportError:
   ARGCOMPLETEENABLED = False
 
-POSSIBLEINPUTFILES = (
-    ".stdhep", ".slcio", ".HEPEvt", ".hepevt",
-    ".hepmc", ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2",
+HEPMC3_SUPPORTED_EXTENSIONS = [
+    ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2",
     ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2",
     ".hepmc3.tree.root",
+    ]
+POSSIBLEINPUTFILES = [
+    ".stdhep", ".slcio", ".HEPEvt", ".hepevt",
     ".pairs",
-    )
+    ".hepmc",
+    ] + HEPMC3_SUPPORTED_EXTENSIONS
 
 
 class DD4hepSimulation(object):
@@ -414,11 +417,7 @@ class DD4hepSimulation(object):
       elif inputFile.endswith(".hepevt"):
         gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepevt%d" % index)
         gen.Input = "Geant4EventReaderHepEvtLong|" + inputFile
-      elif inputFile.endswith((
-          ".hepmc", ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2",
-          ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2",
-          ".hepmc3.tree.root",
-          )):
+      elif inputFile.endswith(tuple([".hepmc"] + HEPMC3_SUPPORTED_EXTENSIONS)):
         if self.hepmc3.useHepMC3:
           gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepmc%d" % index)
           gen.Parameters = self.hepmc3.getParameters()
@@ -540,13 +539,9 @@ class DD4hepSimulation(object):
     """
     if isinstance(fileNames, six.string_types):
       fileNames = [fileNames]
-    if not all(fileName.endswith(extensions) for fileName in fileNames):
+    if not all(fileName.endswith(tuple(extensions)) for fileName in fileNames):
       self._errorMessages.append("ERROR: Unknown fileformat for file: %s" % fileNames)
-    if not self.hepmc3.useHepMC3 and any(fileName.endswith((
-        ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2",
-        ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2",
-        ".hepmc3.tree.root",
-        )) for fileName in fileNames):
+    if not self.hepmc3.useHepMC3 and any(fileName.endswith(tuple(HEPMC3_SUPPORTED_EXTENSIONS)) for fileName in fileNames):
       self._errorMessages.append("ERROR: HepMC3 files or compressed HepMC2 require the use of HepMC3 library")
     return fileNames
 
-- 
GitLab