Skip to content

Commit 03ad3bb

Browse files
Python interface: various PR bugs caught by Copilot
1 parent 8fa1a79 commit 03ad3bb

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

sbnalg/gallery/python/LArSoftUtils.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def serviceClassToConfigKeys(serviceClassName: str) -> list[str]:
226226
candidates = []
227227

228228
# remove namespaces (namespaces are not part of any candidate)
229-
try: serviceClassName = serviceClassName[:serviceClassName.index('::')]
229+
try: serviceClassName = serviceClassName[serviceClassName.rindex('::')+2:]
230230
except ValueError: pass # no namespace
231231

232232
if not serviceClassName: return [] # ?!
@@ -284,10 +284,10 @@ def readServiceConfig(getConfig, configKey, returnConfigKey = True):
284284
= tuple(base + suffix for base in serviceClassToConfigKeys(configKey))
285285

286286
Logger.debug("Configuration from candidates: '%s'", "', '".join(configKeys))
287-
for configKey in configKeys:
288-
try: config = getConfig(configKey)
287+
for candidateKey in configKeys:
288+
try: config = getConfig(candidateKey)
289289
except Exception: continue
290-
return (config, configKey) if returnConfigKey else config
290+
return (config, candidateKey) if returnConfigKey else config
291291
raise RuntimeError(f"No configuration for service key '{configKey}'")
292292
# readServiceConfig()
293293

@@ -701,6 +701,8 @@ def fullConfig(self): return self.serviceTable is None
701701
def isValid(self): return self.configPath is not None
702702
def hasExtraConfig(self): return bool(self.extraConfig)
703703
def needsCustom(self): return not self.fullConfig() or self.hasExtraConfig()
704+
def serviceTableName(self):
705+
return 'services' if self.fullConfig() else self.serviceTable
704706

705707
def addExtraConfig(self, extra): self.extraConfig += "\n" + extra
706708

@@ -743,7 +745,15 @@ def get(self, serviceKey, interfaceClass = None):
743745
# get()
744746

745747

746-
def defaultConfiguration(self): return None
748+
def defaultConfiguration(self):
749+
"""Returns the default configuration.
750+
751+
The configuration is delivered as a ServiceManagerInstance.ConfigurationInfo object.
752+
This configuration is used when the service manager is not explicitly
753+
configured with `setConfiguration()`.
754+
"""
755+
return ServiceManagerInstance.ConfigurationInfo()
756+
# defaultConfiguration()
747757

748758
def setConfiguration(self, configFile, serviceTable = None, extra = ""):
749759
"""Sets which configuration to use for setup.
@@ -811,7 +821,7 @@ def loadConfiguration(self):
811821
'\n# ==============================='
812822
.format(
813823
configPath=configurationInfo.configPath,
814-
serviceTable=configurationInfo.serviceTable,
824+
serviceTable=configurationInfo.serviceTableName(),
815825
extraConfig=configurationInfo.extraConfig,
816826
)
817827
)

sbnalg/gallery/python/cppUtils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ def loadMany(self, *pathSpecs, extraPaths = [], force = False, loadAll = False):
148148
`{ relPath: 'larcorealg_Geometry', extraPaths: [] }`.
149149
If a path specification is not a dictionary, it is assumed to be a `relPath`
150150
and it is equivalent to having `{ relPath: pathSpec }`.
151-
If an argument `extraPath` or `force` is specified in the path
152-
specification, a value is used from the `extraPath` and `force` arguments
153-
of this function.
151+
If `extraPaths` or `force` are not specified in a path specification,
152+
they default to the `extraPaths` and `force` arguments of this function;
153+
if they are specified in the path specification, their values override
154+
the defaults from this function.
154155
155156
If `loadAll` is set, all loads are attempted; the return value is a pair:
156157
whether an exception was thrown, and a list of all return values or

sbnalg/gallery/python/galleryUtils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,8 @@ def eventLoop(inputFiles,
289289
nSkip = options.get('nSkip', 0)
290290
nEvents = options.get('nEvents', None)
291291

292-
# make sure the input file list is in the right format
293-
if not isinstance(inputFiles, ROOT.vector(ROOT.string)):
294-
if isinstance(inputFiles, str): inputFiles = [ inputFiles, ]
295-
inputFiles = makeFileList(*inputFiles)
296-
# if
292+
# create a gallery event with an expanded (flattened) input list
293+
inputFiles = makeFileList(*inputFiles)
297294

298295
event = ROOT.gallery.Event(inputFiles)
299296

0 commit comments

Comments
 (0)