From 8e6428ddbb2d799075d8adfc856103d4b77987e9 Mon Sep 17 00:00:00 2001 From: erodrigu Date: Wed, 20 Jan 2021 17:24:37 +0100 Subject: [PATCH 1/8] Use snake_case rather than CamelCase --- .../python/DaVinci/ConfigurationUpgrade.py | 14 ++++++----- Phys/DaVinci/python/DaVinci/algorithms.py | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py index b339afd8..f1c1bdb1 100644 --- a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py +++ b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py @@ -1,5 +1,5 @@ -############################################################################## -# (c) Copyright 2020 CERN for the benefit of the LHCb Collaboration # +############################################################################### +# (c) Copyright 2020-2021 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -15,9 +15,11 @@ from GaudiConfig2 import Configurables as C from GaudiConfig2 import mergeConfigs from DaVinci.configOptions import initializeSlots, checkOptions, setFileOptions, setJobOptions -from DaVinci.algorithms import dvInit, defineInput, setupAlgorithms, setupExtSvc, rootFiles, defineMonitors, defineLog +from DaVinci.algorithms import define_input, define_monitors, define_log +from DaVinci.algorithms import dvInit, setupAlgorithms, setupExtSvc, rootFiles from DaVinci.configurations import configureAppMgr + def mc(key='Upgrade_genFSR_ldst', dbFile='$DAVINCIROOT/options/DaVinciDB-Example.yaml', jobOptFile='$DAVINCIROOT/options/jobOptions-Example.yaml'): return main(key, dbFile, jobOptFile, True) @@ -33,14 +35,14 @@ def main(key, dbFile, jobOptFile, isMC): propertyDocDct = {} initializeSlots(slots, propertyDocDct) - defineLog(slots) + define_log(slots) setFileOptions(slots, key, dbFile, isMC) setJobOptions(slots, jobOptFile, key, dbFile) checkOptions(slots) - defineInput(slots) + define_input(slots) config = [] appMgr = C.ApplicationMgr() @@ -48,7 +50,7 @@ def main(key, dbFile, jobOptFile, isMC): dvInit(config, slots) - defineMonitors(config, slots) + define_monitors(config, slots) setupAlgorithms(config, slots) diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py index 75cf9266..a941095c 100644 --- a/Phys/DaVinci/python/DaVinci/algorithms.py +++ b/Phys/DaVinci/python/DaVinci/algorithms.py @@ -13,6 +13,7 @@ from GaudiConfig2 import Configurables as C from DaVinci.configOptions import getSlotValue, setSlotValue from DaVinci.configurations import * + def dvInit(config, slots): """ Set initialisation algorithm @@ -21,15 +22,16 @@ def dvInit(config, slots): configureInit(dvInit, slots) config.append(dvInit) -def defineInput(slots): + +def define_input(slots): """ - Set input files + Define the input files via the IOHelper. """ - input = getSlotValue(slots, "Input") + from GaudiConf import IOHelper - if ( len(input) > 0 ): - from GaudiConf import IOHelper + input = getSlotValue(slots, "Input") + if ( len(input) > 0 ): persistency = None inputType = getSlotValue(slots, "InputType").upper() if inputType == "MDF" : persistency = "MDF" @@ -41,9 +43,10 @@ def defineInput(slots): log = getSlotValue(slots, "Log") log.warning('No input files available along with the selected key. Check the related DaVinciDB.') -def defineMonitors(config, slots): + +def define_monitors(config, slots): """ - Set monitors + Define monitors. """ auditor = C.AuditorSvc() timer = C.TimingAuditor() @@ -55,6 +58,7 @@ def defineMonitors(config, slots): config.extend([auditor, timer, sequencer, evtSel]) + def setupAlgorithms(config, slots): """ Set DaVinci algorithms @@ -65,6 +69,7 @@ def setupAlgorithms(config, slots): config.extend(algorithms) + def setupExtSvc(config, slots): """ Set DaVinci services @@ -88,6 +93,7 @@ def setupExtSvc(config, slots): config.extend(extSvc) + def rootFiles(config, slots): """ Set output .root files @@ -105,7 +111,8 @@ def rootFiles(config, slots): from GaudiKernel.Configurable import ConfigurableGeneric as RFileCnv RFileCnv('RFileCnv').GlobalCompression = getSlotValue(slots, "RootCompressionLevel") -def defineLog(slots): + +def define_log(slots): """ Set logger """ @@ -113,4 +120,3 @@ def defineLog(slots): log = getLogger ( 'DaVinci' ) log.info("Applying DaVinci configuration") setSlotValue(slots, "Log", log) - -- GitLab From e4dd186cd2d327f5114adf834deef130217d119a Mon Sep 17 00:00:00 2001 From: erodrigu Date: Wed, 20 Jan 2021 17:25:05 +0100 Subject: [PATCH 2/8] Top-level import of configurable main functions --- .../test_davinci_initialise_upgrade.qmt | 2 +- Phys/DaVinci/python/DaVinci/__init__.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/DaVinciTests/tests/qmtest/davinci.qms/test_davinci_initialise_upgrade.qmt b/DaVinciTests/tests/qmtest/davinci.qms/test_davinci_initialise_upgrade.qmt index 520e8c10..183352a8 100755 --- a/DaVinciTests/tests/qmtest/davinci.qms/test_davinci_initialise_upgrade.qmt +++ b/DaVinciTests/tests/qmtest/davinci.qms/test_davinci_initialise_upgrade.qmt @@ -23,7 +23,7 @@ --> gaudirun.py - DaVinci.ConfigurationUpgrade:mc + DaVinci:mc $DAVINCITESTSROOT/tests/refs/test_davinci_initialise_upgrade.ref $DAVINCITESTSROOT/tests/refs/empty.ref diff --git a/Phys/DaVinci/python/DaVinci/__init__.py b/Phys/DaVinci/python/DaVinci/__init__.py index e69de29b..3870abce 100644 --- a/Phys/DaVinci/python/DaVinci/__init__.py +++ b/Phys/DaVinci/python/DaVinci/__init__.py @@ -0,0 +1,17 @@ +############################################################################## +# (c) Copyright 2020-2021 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### + +from __future__ import absolute_import + +from .ConfigurationUpgrade import data, mc, main + + +__all__ = ('data', 'mc', 'main') -- GitLab From 46d1c0ecf819c3ec1ab7a385cb7e3d69851001ad Mon Sep 17 00:00:00 2001 From: erodrigu Date: Wed, 20 Jan 2021 17:52:50 +0100 Subject: [PATCH 3/8] Further updates to naming conventions --- .../python/DaVinci/ConfigurationUpgrade.py | 6 +++--- Phys/DaVinci/python/DaVinci/algorithms.py | 20 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py index f1c1bdb1..705a384e 100644 --- a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py +++ b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py @@ -15,8 +15,8 @@ from GaudiConfig2 import Configurables as C from GaudiConfig2 import mergeConfigs from DaVinci.configOptions import initializeSlots, checkOptions, setFileOptions, setJobOptions -from DaVinci.algorithms import define_input, define_monitors, define_log -from DaVinci.algorithms import dvInit, setupAlgorithms, setupExtSvc, rootFiles +from DaVinci.algorithms import define_input, define_monitors, define_log, define_root_files +from DaVinci.algorithms import dvInit, setupAlgorithms, setupExtSvc from DaVinci.configurations import configureAppMgr @@ -56,7 +56,7 @@ def main(key, dbFile, jobOptFile, isMC): setupExtSvc(config, slots) - rootFiles(config, slots) + define_root_files(config, slots) configureAppMgr(appMgr, slots, config) diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py index a941095c..f3402586 100644 --- a/Phys/DaVinci/python/DaVinci/algorithms.py +++ b/Phys/DaVinci/python/DaVinci/algorithms.py @@ -1,5 +1,5 @@ ############################################################################### -# (c) Copyright 2020 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2020-20201 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -94,10 +94,16 @@ def setupExtSvc(config, slots): config.extend(extSvc) -def rootFiles(config, slots): +def define_root_files(config, slots): """ - Set output .root files + Set the output ROOT file names for ntuples and histograms. + + Note + ---- + Ntuples and histograms can be output to different files, and are so typically. """ + from GaudiKernel.Configurable import ConfigurableGeneric as RFileCnv + if getSlotValue(slots, "HistogramFile"): histoSvc = C.HistogramPersistencySvc(OutputFile = getSlotValue(slots, "HistogramFile")) config.append(histoSvc) @@ -108,15 +114,15 @@ def rootFiles(config, slots): config.append(ntSvc) # Set the compression level for the ROOT tuple file - from GaudiKernel.Configurable import ConfigurableGeneric as RFileCnv - RFileCnv('RFileCnv').GlobalCompression = getSlotValue(slots, "RootCompressionLevel") + RFileCnv("RFileCnv").GlobalCompression = getSlotValue(slots, "RootCompressionLevel") def define_log(slots): """ - Set logger + Define the logger. """ from AnalysisPython.Logger import getLogger - log = getLogger ( 'DaVinci' ) + + log = getLogger ("DaVinci") log.info("Applying DaVinci configuration") setSlotValue(slots, "Log", log) -- GitLab From 14669089b7a8c29d3136fbbf15d9330f726ee2b6 Mon Sep 17 00:00:00 2001 From: erodrigu Date: Wed, 20 Jan 2021 18:53:36 +0100 Subject: [PATCH 4/8] Further updates to naming conventions --- .../python/DaVinci/ConfigurationUpgrade.py | 8 +++--- Phys/DaVinci/python/DaVinci/algorithms.py | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py index 705a384e..75ff7103 100644 --- a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py +++ b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py @@ -15,8 +15,8 @@ from GaudiConfig2 import Configurables as C from GaudiConfig2 import mergeConfigs from DaVinci.configOptions import initializeSlots, checkOptions, setFileOptions, setJobOptions -from DaVinci.algorithms import define_input, define_monitors, define_log, define_root_files -from DaVinci.algorithms import dvInit, setupAlgorithms, setupExtSvc +from DaVinci.algorithms import define_input, define_monitors, define_log, define_root_files, define_services +from DaVinci.algorithms import define_dv_init_algo, setupAlgorithms from DaVinci.configurations import configureAppMgr @@ -48,13 +48,13 @@ def main(key, dbFile, jobOptFile, isMC): appMgr = C.ApplicationMgr() config.append(appMgr) - dvInit(config, slots) + define_dv_init_algo(config, slots) define_monitors(config, slots) setupAlgorithms(config, slots) - setupExtSvc(config, slots) + define_services(config, slots) define_root_files(config, slots) diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py index f3402586..a26a8b9d 100644 --- a/Phys/DaVinci/python/DaVinci/algorithms.py +++ b/Phys/DaVinci/python/DaVinci/algorithms.py @@ -14,11 +14,11 @@ from DaVinci.configOptions import getSlotValue, setSlotValue from DaVinci.configurations import * -def dvInit(config, slots): +def define_dv_init_algo(config, slots): """ - Set initialisation algorithm + Define the DaVinci initialisation algorithm. """ - dvInit = C.DaVinciInit('DaVinciInitAlg') + dvInit = C.DaVinciInit("DaVinciInitAlg") configureInit(dvInit, slots) config.append(dvInit) @@ -35,9 +35,9 @@ def define_input(slots): persistency = None inputType = getSlotValue(slots, "InputType").upper() if inputType == "MDF" : persistency = "MDF" - #support connection strings and lists of files + # Support connection strings and lists of files input = IOHelper(persistency, persistency).convertConnectionStrings(input, "I") - #clear selector to maintain the same behaviour + # Clear selector to maintain the same behaviour IOHelper(persistency, persistency).inputFiles(input, clear = True) else: log = getSlotValue(slots, "Log") @@ -46,7 +46,7 @@ def define_input(slots): def define_monitors(config, slots): """ - Define monitors. + Define the monitors - AuditorSvc, EventSelector, SequencerTimerTool, TimingAuditor. """ auditor = C.AuditorSvc() timer = C.TimingAuditor() @@ -70,9 +70,18 @@ def setupAlgorithms(config, slots): config.extend(algorithms) -def setupExtSvc(config, slots): +def define_services(config, slots): """ - Set DaVinci services + Define standard services: + + - DataOnDemandSvc + - DetDataSvc + - EvtPersistencySvc + - IODataManager + - LoKiSvc + - MultiFileCatalog + - RootCnvSvc + - ToolSvc """ lokiSvc = C.LoKiSvc() dataSvc = C.DataOnDemandSvc() -- GitLab From ffb5ecb617ebf6aead569873389bc19bdf9e9a8c Mon Sep 17 00:00:00 2001 From: erodrigu Date: Thu, 21 Jan 2021 10:42:50 +0100 Subject: [PATCH 5/8] Adapt getSlotValue and setSlotValue --- Phys/DaVinci/python/DaVinci/algorithms.py | 20 ++++----- Phys/DaVinci/python/DaVinci/configOptions.py | 42 +++++++++---------- Phys/DaVinci/python/DaVinci/configurations.py | 16 +++---- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py index a26a8b9d..d9a9f891 100644 --- a/Phys/DaVinci/python/DaVinci/algorithms.py +++ b/Phys/DaVinci/python/DaVinci/algorithms.py @@ -10,7 +10,7 @@ ############################################################################### from GaudiConfig2 import Configurables as C -from DaVinci.configOptions import getSlotValue, setSlotValue +from DaVinci.configOptions import get_slot_value, set_slot_value from DaVinci.configurations import * @@ -29,18 +29,18 @@ def define_input(slots): """ from GaudiConf import IOHelper - input = getSlotValue(slots, "Input") + input = get_slot_value(slots, "Input") if ( len(input) > 0 ): persistency = None - inputType = getSlotValue(slots, "InputType").upper() + inputType = get_slot_value(slots, "InputType").upper() if inputType == "MDF" : persistency = "MDF" # Support connection strings and lists of files input = IOHelper(persistency, persistency).convertConnectionStrings(input, "I") # Clear selector to maintain the same behaviour IOHelper(persistency, persistency).inputFiles(input, clear = True) else: - log = getSlotValue(slots, "Log") + log = get_slot_value(slots, "Log") log.warning('No input files available along with the selected key. Check the related DaVinciDB.') @@ -65,7 +65,7 @@ def setupAlgorithms(config, slots): """ algorithms = [C.GaudiHistoAlgorithm('SimpleHistos', HistoPrint=True, - OutputLevel=getSlotValue(slots, "OutputLevel"))] + OutputLevel=get_slot_value(slots, "OutputLevel"))] config.extend(algorithms) @@ -113,17 +113,17 @@ def define_root_files(config, slots): """ from GaudiKernel.Configurable import ConfigurableGeneric as RFileCnv - if getSlotValue(slots, "HistogramFile"): - histoSvc = C.HistogramPersistencySvc(OutputFile = getSlotValue(slots, "HistogramFile")) + if get_slot_value(slots, "HistogramFile"): + histoSvc = C.HistogramPersistencySvc(OutputFile = get_slot_value(slots, "HistogramFile")) config.append(histoSvc) - if getSlotValue(slots, "TupleFile"): + if get_slot_value(slots, "TupleFile"): ntSvc = C.NTupleSvc() configureOptions_rootNtuples(ntSvc, slots) config.append(ntSvc) # Set the compression level for the ROOT tuple file - RFileCnv("RFileCnv").GlobalCompression = getSlotValue(slots, "RootCompressionLevel") + RFileCnv("RFileCnv").GlobalCompression = get_slot_value(slots, "RootCompressionLevel") def define_log(slots): @@ -134,4 +134,4 @@ def define_log(slots): log = getLogger ("DaVinci") log.info("Applying DaVinci configuration") - setSlotValue(slots, "Log", log) + set_slot_value(slots, "Log", log) diff --git a/Phys/DaVinci/python/DaVinci/configOptions.py b/Phys/DaVinci/python/DaVinci/configOptions.py index 0f1b337b..4fc35501 100644 --- a/Phys/DaVinci/python/DaVinci/configOptions.py +++ b/Phys/DaVinci/python/DaVinci/configOptions.py @@ -17,10 +17,10 @@ import os """ Set and retrieve the value of a specific slot property """ -def getSlotValue(slots, name): +def get_slot_value(slots, name): return slots[name] -def setSlotValue(slots, name, value): +def set_slot_value(slots, name, value): if name in slots: slots[name] = value else: @@ -78,21 +78,21 @@ def setFileOptions(slots, myKey, dbName, isMC): for item, obj in config.items(): if item == 'qualifiers': for prop, value in obj.items(): - setSlotValue(slots, prop, value) + set_slot_value(slots, prop, value) elif item == 'filenames': if idxFile > -1: if idxFile < len(obj): - setSlotValue(slots, "Input", [obj[idxFile]]) + set_slot_value(slots, "Input", [obj[idxFile]]) else: raise ValueError('Index file requested exceeds the number of available files related to the given key!') else: - setSlotValue(slots, "Input", obj) + set_slot_value(slots, "Input", obj) def setJobOptions(slots, configName, myKey, dbName): """ Set the job properties required by the user """ - log = getSlotValue(slots, "Log") + log = get_slot_value(slots, "Log") if configName == '': log.warning('No jobOption file selected, the default values are used.') else: @@ -117,15 +117,15 @@ def setJobOptions(slots, configName, myKey, dbName): for key, value in config.items(): if key in dataOptions: - if getSlotValue(slots, "OverwriteDataOptions"): + if get_slot_value(slots, "OverwriteDataOptions"): log.warning('Default value for option %s is taken from DaVinciDB but a new value is found in option file. ' 'Since "OverwriteDataOptions" is active the new value is used. Make sure this is the configuration you want to use for this job.' %key) - setSlotValue(slots, key, value) + set_slot_value(slots, key, value) else: log.warning('Default value for option %s is taken from DaVinciDB but a new value is found in option file. ' 'Since "OverwriteDataOptions" is not active the default value is used. Make sure this is the configuration you want to use for this job.' %key) else: - setSlotValue(slots, key, value) + set_slot_value(slots, key, value) def listDataOptions(myKey, dbName): """ @@ -151,36 +151,36 @@ def checkOptions(slots): """ Checks options. Changes a few if needed. """ - log = getSlotValue(slots, "Log") + log = get_slot_value(slots, "Log") known_datatypes = ["Upgrade"] known_default_detectors = ['VP', 'UT', 'FT', 'Rich1Pmt', 'Rich2Pmt', 'Ecal', 'Hcal', 'Muon', 'Magnet', 'Tr' ] - dataType = getSlotValue(slots,"DataType") + dataType = get_slot_value(slots,"DataType") if (not dataType): raise TypeError( "You must set DataType" ) if dataType not in known_datatypes: raise TypeError( "Invalid DataType '%s'" %dataType ) - inputType = getSlotValue(slots, "InputType").upper() + inputType = get_slot_value(slots, "InputType").upper() if inputType not in [ "MDF", "DST", "DIGI", "RDST", "MDST", "SDST", "XDST", "LDST" ]: raise TypeError( "Invalid inputType '%s'"%inputType ) - if getSlotValue(slots, "Simulation") and not inputType in ( "MDF" , "DIGI" , "MDST" ): - redo = getSlotValue(slots, "RedoMCLinks") + if get_slot_value(slots, "Simulation") and not inputType in ( "MDF" , "DIGI" , "MDST" ): + redo = get_slot_value(slots, "RedoMCLinks") if (inputType == "RDST") and (redo): log.warning("Re-doing MC links not possible for RDST") - setSlotValue(slots, "RedoMCLinks", False) + set_slot_value(slots, "RedoMCLinks", False) - if getSlotValue(slots, "Simulation") and getSlotValue(slots,'Lumi'): + if get_slot_value(slots, "Simulation") and get_slot_value(slots,'Lumi'): log.warning('Lumi not valid for Simulation. Setting Lumi = False') - setSlotValue(slots, 'Lumi', False) + set_slot_value(slots, 'Lumi', False) ## for simulation, it is very important to specify proper DB-tags: - if getSlotValue(slots, 'Simulation'): - if not getSlotValue(slots,'DDDBtag'): + if get_slot_value(slots, 'Simulation'): + if not get_slot_value(slots,'DDDBtag'): log.warning("``DDDBtag'' is not specified for simulated data") - if not getSlotValue(slots, 'CondDBtag'): + if not get_slot_value(slots, 'CondDBtag'): log.warning("``CondDBtag'' is not specified for simulated data") - if getSlotValue(slots, "MergeGenFSR") and not getSlotValue(slots, "Simulation"): + if get_slot_value(slots, "MergeGenFSR") and not get_slot_value(slots, "Simulation"): raise TypeError("Cannot MergeGenFSR on real data"); diff --git a/Phys/DaVinci/python/DaVinci/configurations.py b/Phys/DaVinci/python/DaVinci/configurations.py index 4b323db0..8a2e2898 100644 --- a/Phys/DaVinci/python/DaVinci/configurations.py +++ b/Phys/DaVinci/python/DaVinci/configurations.py @@ -10,7 +10,7 @@ ############################################################################### from GaudiConfig2 import Configurables as C -from DaVinci.configOptions import getSlotValue +from DaVinci.configOptions import get_slot_value ################################################################################ # Define configurations for applications and algorithms @@ -25,7 +25,7 @@ def configureAppMgr(appMgr, slots, config): if c.name == 'MessageSvc': messageSvc = c - appMgr.EvtMax = getSlotValue(slots,"EvtMax") + appMgr.EvtMax = get_slot_value(slots,"EvtMax") appMgr.HistogramPersistency = 'ROOT' appMgr.AuditAlgorithms = True @@ -40,7 +40,7 @@ def configureInit(dvInit, slots): """ Configuration of initialisation algorithm """ - dvInit.Increment = getSlotValue(slots, "PrintFreq") + dvInit.Increment = get_slot_value(slots, "PrintFreq") ################################################################################ @@ -60,10 +60,10 @@ def configureOptions_rootNtuples(svc, slots): """ for _line in svc.Output : if 0 <= _line.find ('FILE1') : - log = getSlotValue(slots, "Log") + log = get_slot_value(slots, "Log") log.warning ('Replace NTuple-LUN FILE1: ' + _line ) svc.Output.remove ( _line ) - tupleFile = getSlotValue(slots, "TupleFile") + tupleFile = get_slot_value(slots, "TupleFile") tupleStr = "FILE1 DATAFILE='%s' TYP='ROOT' OPT='NEW'" % tupleFile svc.Output += [ tupleStr ] svc.OutputLevel = 1 @@ -78,7 +78,7 @@ def configurePrintOuts(lokiSvc, dataSvc, slots): """ Configuration of the printout services """ - verbosePrint = getSlotValue(slots, "VerboseMessages") + verbosePrint = get_slot_value(slots, "VerboseMessages") lokiSvc.Welcome = verbosePrint dataSvc.Dump = verbosePrint @@ -86,10 +86,10 @@ def configureEventSelector(svc, slots): """ Configuration of the event selector """ - printFreq = getSlotValue(slots, "PrintFreq") + printFreq = get_slot_value(slots, "PrintFreq") if printFreq == 0: printFreq = getDefaultValue("PrintFreq") - log = getSlotValue(slots, "Log") + log = get_slot_value(slots, "Log") log.warning("Print frequency cannot be 0. Set to %f." %printFreq) svc.PrintFreq = printFreq -- GitLab From 1958b9404d23ec914df5d5725b2f226e5ebf76f6 Mon Sep 17 00:00:00 2001 From: erodrigu Date: Thu, 21 Jan 2021 11:02:48 +0100 Subject: [PATCH 6/8] Yet another batch of functions put to snake_case --- .../python/DaVinci/ConfigurationUpgrade.py | 14 +++--- Phys/DaVinci/python/DaVinci/algorithms.py | 31 ++++++------ Phys/DaVinci/python/DaVinci/configOptions.py | 49 +++++++++++-------- Phys/DaVinci/python/DaVinci/configurations.py | 34 +++++++------ 4 files changed, 69 insertions(+), 59 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py index 75ff7103..ed16d609 100644 --- a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py +++ b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py @@ -14,10 +14,10 @@ High level configuration tools for DaVinci from GaudiConfig2 import Configurables as C from GaudiConfig2 import mergeConfigs -from DaVinci.configOptions import initializeSlots, checkOptions, setFileOptions, setJobOptions +from DaVinci.configOptions import initialize_slots, check_options, set_file_options, set_job_options from DaVinci.algorithms import define_input, define_monitors, define_log, define_root_files, define_services from DaVinci.algorithms import define_dv_init_algo, setupAlgorithms -from DaVinci.configurations import configureAppMgr +from DaVinci.configurations import configure_app_mgr def mc(key='Upgrade_genFSR_ldst', dbFile='$DAVINCIROOT/options/DaVinciDB-Example.yaml', jobOptFile='$DAVINCIROOT/options/jobOptions-Example.yaml'): @@ -33,14 +33,14 @@ def main(key, dbFile, jobOptFile, isMC): """ slots = {} propertyDocDct = {} - initializeSlots(slots, propertyDocDct) + initialize_slots(slots, propertyDocDct) define_log(slots) - setFileOptions(slots, key, dbFile, isMC) - setJobOptions(slots, jobOptFile, key, dbFile) + set_file_options(slots, key, dbFile, isMC) + set_job_options(slots, jobOptFile, key, dbFile) - checkOptions(slots) + check_options(slots) define_input(slots) @@ -58,7 +58,7 @@ def main(key, dbFile, jobOptFile, isMC): define_root_files(config, slots) - configureAppMgr(appMgr, slots, config) + configure_app_mgr(appMgr, slots, config) config = mergeConfigs(config) return config diff --git a/Phys/DaVinci/python/DaVinci/algorithms.py b/Phys/DaVinci/python/DaVinci/algorithms.py index d9a9f891..6c0009eb 100644 --- a/Phys/DaVinci/python/DaVinci/algorithms.py +++ b/Phys/DaVinci/python/DaVinci/algorithms.py @@ -19,7 +19,7 @@ def define_dv_init_algo(config, slots): Define the DaVinci initialisation algorithm. """ dvInit = C.DaVinciInit("DaVinciInitAlg") - configureInit(dvInit, slots) + configure_init(dvInit, slots) config.append(dvInit) @@ -41,7 +41,7 @@ def define_input(slots): IOHelper(persistency, persistency).inputFiles(input, clear = True) else: log = get_slot_value(slots, "Log") - log.warning('No input files available along with the selected key. Check the related DaVinciDB.') + log.warning("No input files available along with the selected key. Check the related DaVinciDB.") def define_monitors(config, slots): @@ -51,10 +51,10 @@ def define_monitors(config, slots): auditor = C.AuditorSvc() timer = C.TimingAuditor() sequencer = C.SequencerTimerTool() - configureTiming(auditor, timer, sequencer) + configure_timing(auditor, timer, sequencer) evtSel = C.EventSelector() - configureEventSelector(evtSel, slots) + configure_event_selector(evtSel, slots) config.extend([auditor, timer, sequencer, evtSel]) @@ -63,8 +63,8 @@ def setupAlgorithms(config, slots): """ Set DaVinci algorithms """ - algorithms = [C.GaudiHistoAlgorithm('SimpleHistos', - HistoPrint=True, + algorithms = [C.GaudiHistoAlgorithm("SimpleHistos", + HistoPrint=True, OutputLevel=get_slot_value(slots, "OutputLevel"))] config.extend(algorithms) @@ -85,19 +85,19 @@ def define_services(config, slots): """ lokiSvc = C.LoKiSvc() dataSvc = C.DataOnDemandSvc() - configurePrintOuts(lokiSvc, dataSvc, slots) + configure_printouts(lokiSvc, dataSvc, slots) evtPers = C.EvtPersistencySvc("EventPersistencySvc") - configureEventPersistency(evtPers) + configure_event_persistency(evtPers) extSvc = [lokiSvc, dataSvc, evtPers, C.ToolSvc(), - C.DetDataSvc('DetectorDataSvc'), - C.Gaudi.MultiFileCatalog('FileCatalog'), - C.Gaudi.IODataManager('IODataManager'), - C.Gaudi.RootCnvSvc('FileRecordCnvSvc'), + C.DetDataSvc("DetectorDataSvc"), + C.Gaudi.MultiFileCatalog("FileCatalog"), + C.Gaudi.IODataManager("IODataManager"), + C.Gaudi.RootCnvSvc("FileRecordCnvSvc"), ] config.extend(extSvc) @@ -107,9 +107,8 @@ def define_root_files(config, slots): """ Set the output ROOT file names for ntuples and histograms. - Note - ---- - Ntuples and histograms can be output to different files, and are so typically. + Note: + Ntuples and histograms can be output to different files, and are so typically. """ from GaudiKernel.Configurable import ConfigurableGeneric as RFileCnv @@ -119,7 +118,7 @@ def define_root_files(config, slots): if get_slot_value(slots, "TupleFile"): ntSvc = C.NTupleSvc() - configureOptions_rootNtuples(ntSvc, slots) + configure_options_root_ntuples(ntSvc, slots) config.append(ntSvc) # Set the compression level for the ROOT tuple file diff --git a/Phys/DaVinci/python/DaVinci/configOptions.py b/Phys/DaVinci/python/DaVinci/configOptions.py index 4fc35501..24a7fd66 100644 --- a/Phys/DaVinci/python/DaVinci/configOptions.py +++ b/Phys/DaVinci/python/DaVinci/configOptions.py @@ -9,30 +9,32 @@ # or submit itself to any jurisdiction. # ############################################################################### -import os - -################################################################################ -# Manage slots properties and input job and data options -# """ -Set and retrieve the value of a specific slot property +Set and retrieve the value of a specific slot property. """ + +import os + + def get_slot_value(slots, name): return slots[name] + def set_slot_value(slots, name, value): if name in slots: slots[name] = value else: import difflib - raise ValueError('Unknown qualifier called %s. Please check the DaVinci database or the job option file!\n ' - 'List of possible valid qualifiers: %s' %(name, difflib.get_close_matches(name, slots))) + raise ValueError("Unknown qualifier called %s. Please check the DaVinci database or the job option file!\n " + "List of possible valid qualifiers: %s" %(name, difflib.get_close_matches(name, slots))) -def getDefaultValue(myKey): + +def get_default_value(myKey): """ - Get default value for a specific property + Get the default value for a specific property. """ import yaml + optsDefaultName = "$DAVINCIROOT/options/DVconfig-Default.yaml" with open(os.path.expandvars(optsDefaultName)) as optsDefault: config = yaml.safe_load(optsDefault) @@ -44,11 +46,13 @@ def getDefaultValue(myKey): return value return 0 -def initializeSlots(slots, propDct): + +def initialize_slots(slots, propDct): """ - Initialize properties with default values. + Initialize the properties with default values. """ import yaml + optsDefaultName = "$DAVINCIROOT/options/DVconfig-Default.yaml" with open(os.path.expandvars(optsDefaultName)) as optsDefault: config = yaml.safe_load(optsDefault) @@ -60,9 +64,10 @@ def initializeSlots(slots, propDct): else: propDct[key] = value -def setFileOptions(slots, myKey, dbName, isMC): + +def set_file_options(slots, myKey, dbName, isMC): """ - Set the dataset properties required by the user + Set the dataset properties required by the user. """ import yaml with open(os.path.expandvars(dbName)) as dbFile: @@ -88,15 +93,16 @@ def setFileOptions(slots, myKey, dbName, isMC): else: set_slot_value(slots, "Input", obj) -def setJobOptions(slots, configName, myKey, dbName): + +def set_job_options(slots, configName, myKey, dbName): """ - Set the job properties required by the user + Set the job properties required by the user. """ log = get_slot_value(slots, "Log") if configName == '': log.warning('No jobOption file selected, the default values are used.') else: - dataOptions = listDataOptions(myKey.split(":")[0], dbName) + dataOptions = list_data_options(myKey.split(":")[0], dbName) with open(os.path.expandvars(configName)) as config_file: """ @@ -127,9 +133,10 @@ def setJobOptions(slots, configName, myKey, dbName): else: set_slot_value(slots, key, value) -def listDataOptions(myKey, dbName): + +def list_data_options(myKey, dbName): """ - List of the properties that are set automatically given a dataset + List of the properties that are set automatically given a dataset. """ import yaml @@ -147,9 +154,9 @@ def listDataOptions(myKey, dbName): return optionList -def checkOptions(slots): +def check_options(slots): """ - Checks options. Changes a few if needed. + Check the options. Applies changes if needed. """ log = get_slot_value(slots, "Log") known_datatypes = ["Upgrade"] diff --git a/Phys/DaVinci/python/DaVinci/configurations.py b/Phys/DaVinci/python/DaVinci/configurations.py index 8a2e2898..fe2b9781 100644 --- a/Phys/DaVinci/python/DaVinci/configurations.py +++ b/Phys/DaVinci/python/DaVinci/configurations.py @@ -16,9 +16,9 @@ from DaVinci.configOptions import get_slot_value # Define configurations for applications and algorithms # -def configureAppMgr(appMgr, slots, config): +def configure_app_mgr(appMgr, slots, config): """ - Configuration of the main application + Configuration of the main application. """ messageSvc = 0 for c in config: @@ -36,9 +36,10 @@ def configureAppMgr(appMgr, slots, config): if c.__component_type__ == 'Algorithm' and c.name not in ['ApplicationMgr']] -def configureInit(dvInit, slots): + +def configure_init(dvInit, slots): """ - Configuration of initialisation algorithm + Configuration of initialisation algorithm. """ dvInit.Increment = get_slot_value(slots, "PrintFreq") @@ -47,14 +48,15 @@ def configureInit(dvInit, slots): # Define configurations for external services # -def configureTiming(auditor, timer, sequencer): +def configure_timing(auditor, timer, sequencer): """ - Configuration of timing auditors + Configuration of timing auditors. """ auditor.Auditors = ['ChronoAuditor', 'TimingAuditor'] sequencer.OutputLevel = 4 -def configureOptions_rootNtuples(svc, slots): + +def configure_options_root_ntuples(svc, slots): """ Configuration of output .root ntuples """ @@ -68,28 +70,30 @@ def configureOptions_rootNtuples(svc, slots): svc.Output += [ tupleStr ] svc.OutputLevel = 1 -def configureEventPersistency(svc): + +def configure_event_persistency(svc): """ Configuration of the event persistency service """ svc.CnvServices.append("Gaudi::RootCnvSvc/RootCnvSvc") -def configurePrintOuts(lokiSvc, dataSvc, slots): + +def configure_printouts(lokiSvc, dataSvc, slots): """ - Configuration of the printout services + Configuration of the printout services. """ verbosePrint = get_slot_value(slots, "VerboseMessages") lokiSvc.Welcome = verbosePrint dataSvc.Dump = verbosePrint - -def configureEventSelector(svc, slots): + + +def configure_event_selector(svc, slots): """ - Configuration of the event selector + Configuration of the event selector. """ printFreq = get_slot_value(slots, "PrintFreq") if printFreq == 0: - printFreq = getDefaultValue("PrintFreq") + printFreq = get_default_value("PrintFreq") log = get_slot_value(slots, "Log") log.warning("Print frequency cannot be 0. Set to %f." %printFreq) svc.PrintFreq = printFreq - -- GitLab From 0b5d871f3da46ce08196ac851469376db1eac362 Mon Sep 17 00:00:00 2001 From: erodrigu Date: Thu, 21 Jan 2021 11:08:39 +0100 Subject: [PATCH 7/8] Remove spurious spaces and text --- Phys/DaVinci/options/DaVinci-Default.py | 3 +-- Phys/DaVinci/options/DaVinciDB-Example.yaml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Phys/DaVinci/options/DaVinci-Default.py b/Phys/DaVinci/options/DaVinci-Default.py index df0cbceb..7f0ca1b7 100644 --- a/Phys/DaVinci/options/DaVinci-Default.py +++ b/Phys/DaVinci/options/DaVinci-Default.py @@ -9,7 +9,6 @@ # or submit itself to any jurisdiction. # ############################################################################### ############################################################################## -#$Id: DaVinci-Default.py,v 1.9 2009-01-12 14:10:09 pkoppenb Exp $ # # syntax: gaudirun.py DaVinci-Default.py # @@ -17,6 +16,6 @@ # ############################################################################## from Configurables import DaVinci -############################################################################## + d = DaVinci() d.DataType = "Upgrade" diff --git a/Phys/DaVinci/options/DaVinciDB-Example.yaml b/Phys/DaVinci/options/DaVinciDB-Example.yaml index 1b0463e8..4f360ba5 100644 --- a/Phys/DaVinci/options/DaVinciDB-Example.yaml +++ b/Phys/DaVinci/options/DaVinciDB-Example.yaml @@ -42,4 +42,3 @@ Upgrade_Bd2KstarMuMu_ldst: Author: 'Patrick Koppenburg' Date: '2020-05-28 11:12:55' Comment: 'K*mumu by Moore Hlt1-filtered with TCK-0x52000000' - \ No newline at end of file -- GitLab From 9cbcb078504e6fd676add0e8218576bff2053bd8 Mon Sep 17 00:00:00 2001 From: erodrigu Date: Thu, 21 Jan 2021 11:10:47 +0100 Subject: [PATCH 8/8] 2 spaces between functions --- Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py index ed16d609..a0a95bde 100644 --- a/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py +++ b/Phys/DaVinci/python/DaVinci/ConfigurationUpgrade.py @@ -9,7 +9,7 @@ # or submit itself to any jurisdiction. # ############################################################################### """ -High level configuration tools for DaVinci +High level configuration tools for DaVinci. """ from GaudiConfig2 import Configurables as C from GaudiConfig2 import mergeConfigs @@ -22,11 +22,13 @@ from DaVinci.configurations import configure_app_mgr def mc(key='Upgrade_genFSR_ldst', dbFile='$DAVINCIROOT/options/DaVinciDB-Example.yaml', jobOptFile='$DAVINCIROOT/options/jobOptions-Example.yaml'): return main(key, dbFile, jobOptFile, True) - + + def data(key='', dbFile='', jobOptFile=''): raise ValueError('Data file with upgrade conditions are not yet available. Please use :mc function instead.') return main(key, dbFile, jobOptFile, False) + def main(key, dbFile, jobOptFile, isMC): """ DaVinci application main configuration. @@ -62,7 +64,3 @@ def main(key, dbFile, jobOptFile, isMC): config = mergeConfigs(config) return config - - - - -- GitLab