diff --git a/k4FWCore/python/k4FWCore/parseArgs.py b/k4FWCore/python/k4FWCore/parseArgs.py index 3473e9de..7df291f1 100644 --- a/k4FWCore/python/k4FWCore/parseArgs.py +++ b/k4FWCore/python/k4FWCore/parseArgs.py @@ -18,4 +18,4 @@ # import argparse -parser = argparse.ArgumentParser(description="Run job in the Key4HEP framework", add_help=False) \ No newline at end of file +parser = argparse.ArgumentParser(description="Run job in the Key4HEP framework", add_help=False) diff --git a/k4FWCore/scripts/k4-print-joboptions b/k4FWCore/scripts/k4-print-joboptions index 7e5d03b0..6aeb07a9 100755 --- a/k4FWCore/scripts/k4-print-joboptions +++ b/k4FWCore/scripts/k4-print-joboptions @@ -14,54 +14,56 @@ import re # groups are added for each quote, the number and the semicolon # so the quote can easily be removed _regexp_int = re.compile(r'(")([-+]?[0-9]+)(")(;)') + + def _sanitize(s): - """ - helper function for postprocessing of key4hep job options - quotes need to be removed around ints, lists, dicts and bools, - and some properties that get stored by the job options svc need to be disabled - - Parameters - ---------- - - s: str - String containing key4hep joboptions (.opts format) to be sanitized. - - Returns - ------- - - s: str - The sanitized string that should be compatible with gaudirun.py - """ - # convert s to standard string (might be a root string) - s = str(s) - s = s.replace('"False"', 'False') - s = s.replace('"True"', 'True') - s = s.replace('"[', '[') - s = s.replace(']"', ']') - s = s.replace('"{', '{') - s = s.replace('}"', '}') - s = re.sub(_regexp_int, r"\g<2>\g<4>", s) - s = s.replace("ApplicationMgr.Go = ", "#ApplicationMgr.Go = ") - s = s.replace("ApplicationMgr.Exit = ", "#ApplicationMgr.Exit = ") - s = s.replace("ApplicationMgr.Environment = { };", "#ApplicationMgr.Environment = { };") - s = s.replace("ApplicationMgr.AlgTypeAliases = { };", "#ApplicationMgr.AlgTypeAliases = { };") - return s + """ + helper function for postprocessing of key4hep job options + quotes need to be removed around ints, lists, dicts and bools, + and some properties that get stored by the job options svc need to be disabled + + Parameters + ---------- + + s: str + String containing key4hep joboptions (.opts format) to be sanitized. + + Returns + ------- + + s: str + The sanitized string that should be compatible with gaudirun.py + """ + # convert s to standard string (might be a root string) + s = str(s) + s = s.replace('"False"', "False") + s = s.replace('"True"', "True") + s = s.replace('"[', "[") + s = s.replace(']"', "]") + s = s.replace('"{', "{") + s = s.replace('}"', "}") + s = re.sub(_regexp_int, r"\g<2>\g<4>", s) + s = s.replace("ApplicationMgr.Go = ", "#ApplicationMgr.Go = ") + s = s.replace("ApplicationMgr.Exit = ", "#ApplicationMgr.Exit = ") + s = s.replace("ApplicationMgr.Environment = { };", "#ApplicationMgr.Environment = { };") + s = s.replace( + "ApplicationMgr.AlgTypeAliases = { };", "#ApplicationMgr.AlgTypeAliases = { };" + ) + return s def dump_joboptions(filename): - f = ROOT.TFile.Open(filename) - t = f.metadata - for event in t: - s = event.gaudiConfigOptions - for e in s: - print(_sanitize(e)) + f = ROOT.TFile.Open(filename) + t = f.metadata + for event in t: + s = event.gaudiConfigOptions + for e in s: + print(_sanitize(e)) -parser = argparse.ArgumentParser(description='K4 Job Options Writer') -parser.add_argument( dest='filename', type=str, help="name of file to read") +parser = argparse.ArgumentParser(description="K4 Job Options Writer") +parser.add_argument(dest="filename", type=str, help="name of file to read") if __name__ == "__main__": args = parser.parse_args() dump_joboptions(args.filename) - - diff --git a/k4FWCore/scripts/k4run b/k4FWCore/scripts/k4run index 8f7a5144..3e1049d7 100755 --- a/k4FWCore/scripts/k4run +++ b/k4FWCore/scripts/k4run @@ -7,91 +7,146 @@ from multiprocessing import cpu_count import logging # these default properties are filtered as otherwise they will clutter the argument list -FILTER_GAUDI_PROPS = [ "ContextService", "Cardinality", "Context", "CounterList", "EfficiencyRowFormat", - "Enable", "ErrorCount", "ErrorMax", "ErrorsPrint", "ExtraInputs", "ExtraOutputs", - "FilterCircularDependencies", "StatEntityList", "IsIOBound", "MonitorService", "NeededResources", - "PropertiesPrint", "RegisterForContextService", "RegularRowFormat", "RequireObjects", "RootInTES", - "StatPrint", "StatTableHeader", "Timeline", "TypePrint", "UseEfficiencyRowFormat", - "EnableFaultHandler", "InhibitPathes", "EnableAccessHandler", "ForceLeaves", "RootName", - "DataAccessName", "DataFaultName", "RootCLID", "PrintEmptyCounters", "Blocking", - "VetoObjects", "CheckToolDeps", "AutoRetrieveTools", - ] - -#--------------------------------------------------------------------- +FILTER_GAUDI_PROPS = [ + "ContextService", + "Cardinality", + "Context", + "CounterList", + "EfficiencyRowFormat", + "Enable", + "ErrorCount", + "ErrorMax", + "ErrorsPrint", + "ExtraInputs", + "ExtraOutputs", + "FilterCircularDependencies", + "StatEntityList", + "IsIOBound", + "MonitorService", + "NeededResources", + "PropertiesPrint", + "RegisterForContextService", + "RegularRowFormat", + "RequireObjects", + "RootInTES", + "StatPrint", + "StatTableHeader", + "Timeline", + "TypePrint", + "UseEfficiencyRowFormat", + "EnableFaultHandler", + "InhibitPathes", + "EnableAccessHandler", + "ForceLeaves", + "RootName", + "DataAccessName", + "DataFaultName", + "RootCLID", + "PrintEmptyCounters", + "Blocking", + "VetoObjects", + "CheckToolDeps", + "AutoRetrieveTools", +] + +# --------------------------------------------------------------------- seen_files = set() option_db = {} + def load_file(file): - exec(file.read(), {}) + exec(file.read(), {}) def add_arguments(parser, app_mgr): - # length increases when properties of an algorithm with tools are inspected - # see https://github.com/key4hep/k4FWCore/pull/138 - # can contain the same value multiple times - # see https://github.com/key4hep/k4FWCore/issues/141 - for conf in frozenset(app_mgr.allConfigurables.values()): - # skip public tools and the applicationmgr itself - if "ToolSvc" in conf.name() or "ApplicationMgr" in conf.name(): - continue - props = conf.getPropertiesWithDescription() #dict propertyname: (propertyvalue, propertydescription) - for prop in props: - # only add arguments for relevant properties - if prop in FILTER_GAUDI_PROPS or "Audit" in prop or hasattr(props[prop][0], '__slots__'): - continue - propvalue = props[prop][0] - - # if it is set to "no value" it hasn't been touched in the options file - if propvalue == conf.propertyNoValue: - propvalue = conf.getDefaultProperty(prop) # thus get the default value - proptype = type(props[prop][0]) - # if the property is a list of something, we need to set argparse nargs to '+' - propnargs = "?" - if proptype == list: - # tricky edgecase: if the default is an empty list there is no way to get the type - if len(propvalue) == 0: - # just skip for now - #print("Warning: argparse cannot deduce type for property %s of %s. Needs to be set in options file." % (prop, conf.name())) + # length increases when properties of an algorithm with tools are inspected + # see https://github.com/key4hep/k4FWCore/pull/138 + # can contain the same value multiple times + # see https://github.com/key4hep/k4FWCore/issues/141 + for conf in frozenset(app_mgr.allConfigurables.values()): + # skip public tools and the applicationmgr itself + if "ToolSvc" in conf.name() or "ApplicationMgr" in conf.name(): continue - else: - # deduce type from first item of the list - proptype = type(propvalue[0]) - propnargs = "+" - - # add the argument twice, once as "--PodioOutput.filename" - # and once as "--filename.PodioOutput" - propName = conf.name() + '.' + prop - propNameReversed = prop + '.' + conf.name() - option_db[propName] = (conf, propName) - parser.add_argument( f"--{propName}", f"--{propNameReversed}", type=proptype, help=props[prop][1], - nargs=propnargs, - default=propvalue) + props = ( + conf.getPropertiesWithDescription() + ) # dict propertyname: (propertyvalue, propertydescription) + for prop in props: + # only add arguments for relevant properties + if ( + prop in FILTER_GAUDI_PROPS + or "Audit" in prop + or hasattr(props[prop][0], "__slots__") + ): + continue + propvalue = props[prop][0] + + # if it is set to "no value" it hasn't been touched in the options file + if propvalue == conf.propertyNoValue: + propvalue = conf.getDefaultProperty(prop) # thus get the default value + proptype = type(props[prop][0]) + # if the property is a list of something, we need to set argparse nargs to '+' + propnargs = "?" + if proptype == list: + # tricky edgecase: if the default is an empty list there is no way to get the type + if len(propvalue) == 0: + # just skip for now + # print("Warning: argparse cannot deduce type for property %s of %s. Needs to be set in options file." % (prop, conf.name())) + continue + else: + # deduce type from first item of the list + proptype = type(propvalue[0]) + propnargs = "+" + + # add the argument twice, once as "--PodioOutput.filename" + # and once as "--filename.PodioOutput" + propName = conf.name() + "." + prop + propNameReversed = prop + "." + conf.name() + option_db[propName] = (conf, propName) + parser.add_argument( + f"--{propName}", + f"--{propNameReversed}", + type=proptype, + help=props[prop][1], + nargs=propnargs, + default=propvalue, + ) if __name__ == "__main__": # ensure that we (and the subprocesses) use the C standard localization - os.environ['LC_ALL'] = 'C' + os.environ["LC_ALL"] = "C" logger = logging.getLogger() logger.setLevel(logging.INFO) # formatter = logging.Formatter('[%(asctime)s %(levelname)s] %(message)s', datefmt='%Y-%b-%d %H:%M:%S') - formatter = logging.Formatter('[k4run] %(message)s') + formatter = logging.Formatter("[k4run] %(message)s") handler = logging.StreamHandler(stream=sys.stdout) handler.setFormatter(formatter) logger.addHandler(handler) from k4FWCore.parseArgs import parser - parser.add_argument("config_files", type=open, action="store", nargs="*", - help="Gaudi config (python) files describing the job") - parser.add_argument("--dry-run", action="store_true", - help="Do not actually run the job, just parse the config files") - parser.add_argument("-v", "--verbose", action="store_true", - help="Run job with verbose output") - parser.add_argument("-n", "--num-events", type=int, - help="Number of events to run") - parser.add_argument("-l", "--list", action="store_true", - help="Print all the configurable components available in the framework and exit") + + parser.add_argument( + "config_files", + type=open, + action="store", + nargs="*", + help="Gaudi config (python) files describing the job", + ) + parser.add_argument( + "--dry-run", + action="store_true", + help="Do not actually run the job, just parse the config files", + ) + parser.add_argument("-v", "--verbose", action="store_true", help="Run job with verbose output") + parser.add_argument("-n", "--num-events", type=int, help="Number of events to run") + parser.add_argument( + "-l", + "--list", + action="store_true", + help="Print all the configurable components available in the framework and exit", + ) parser.add_argument("--gdb", action="store_true", help="Attach gdb debugger") # TODO: Don't want to advertise this until tested. @@ -100,9 +155,13 @@ if __name__ == "__main__": # -1 : All available cpus # 0 : Serial Mode (traditional gaudirun) # n>0 : parallel with n cpus (n <= sys_cpus) - parser.add_argument("--ncpus", type=int, default=0, - help="Start Gaudi in parallel mode using NCPUS processes. " - "0 => serial mode (default), -1 => use all CPUs") + parser.add_argument( + "--ncpus", + type=int, + default=0, + help="Start Gaudi in parallel mode using NCPUS processes. " + "0 => serial mode (default), -1 => use all CPUs", + ) # Once to parse the files and another time below to have the new parameters # in the namespace since parsing of the file happens when the namespace @@ -111,50 +170,64 @@ if __name__ == "__main__": if opts[0].list: from Gaudi import Configuration + cfgDb = Configuration.cfgDb logger.info("Available components:\n%s", (21 * "=")) for item in sorted(cfgDb): if True: # another option could filter Gaudi components here - try: - path_to_component = __import__(cfgDb[item]["module"]).__file__ - except ImportError: - path_to_component = "NotFound" - print(" %s (from %s), \n\t\t path: %s\n" % (item, cfgDb[item]["lib"], path_to_component)) + try: + path_to_component = __import__(cfgDb[item]["module"]).__file__ + except ImportError: + path_to_component = "NotFound" + print( + " %s (from %s), \n\t\t path: %s\n" + % (item, cfgDb[item]["lib"], path_to_component) + ) else: if not "Gaudi" in cfgDb[item]["lib"]: - print(" %s (from %s)" % (item, cfgDb[item]["lib"])) + print(" %s (from %s)" % (item, cfgDb[item]["lib"])) sys.exit() for file in opts[0].config_files: - load_file(file) + load_file(file) # ApplicationMgr is a singleton from Configurables import ApplicationMgr + add_arguments(parser, ApplicationMgr()) # add help manually here, if it is added earlier the parser exits after the first parse_arguments call - parser.add_argument("-h", "--help", action="help", default=argparse.SUPPRESS, help="show this help message and exit") + parser.add_argument( + "-h", + "--help", + action="help", + default=argparse.SUPPRESS, + help="show this help message and exit", + ) opts = parser.parse_args() if len(opts.config_files) == 0: - print('Error: missing gaudi options file.\n' - 'Usage: k4run , use --help to get a complete list of arguments') - sys.exit(1) + print( + "Error: missing gaudi options file.\n" + "Usage: k4run , use --help to get a complete list of arguments" + ) + sys.exit(1) # print a doc line showing the configured algorithms - logger.info(' '.join(f'--> {alg.name()}' for alg in ApplicationMgr().TopAlg)) + logger.info(" ".join(f"--> {alg.name()}" for alg in ApplicationMgr().TopAlg)) opts_dict = vars(opts) for optionName, propTuple in option_db.items(): - logger.info("Option name: %s %s %s", propTuple[1], optionName, opts_dict[optionName]) - propTuple[0].setProp(propTuple[1].rsplit(".",1)[1], opts_dict[optionName]) + logger.info("Option name: %s %s %s", propTuple[1], optionName, opts_dict[optionName]) + propTuple[0].setProp(propTuple[1].rsplit(".", 1)[1], opts_dict[optionName]) if opts.verbose: - from Gaudi.Configuration import VERBOSE - ApplicationMgr().OutputLevel = VERBOSE + from Gaudi.Configuration import VERBOSE + + ApplicationMgr().OutputLevel = VERBOSE if opts.num_events is not None: - ApplicationMgr().EvtMax = opts.num_events + ApplicationMgr().EvtMax = opts.num_events # Allow graceful exit with Ctrl + C ApplicationMgr().StopOnSignal = True @@ -169,11 +242,12 @@ if __name__ == "__main__": parser.error(s) from Gaudi.Main import gaudimain + c = gaudimain() if not opts.dry_run: # Do the real processing retcode = c.run(opts.gdb, opts.ncpus) # User requested stop returns non-zero exit code see: https://github.com/key4hep/k4FWCore/issues/125 if ApplicationMgr().EvtMax == -1 and retcode == 4: - retcode = 0 + retcode = 0 sys.exit(retcode) diff --git a/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py b/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py index d6f342c6..e7857970 100644 --- a/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py +++ b/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py @@ -19,23 +19,26 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") from Configurables import k4FWCoreTest_AlgorithmWithTFile + producer = k4FWCoreTest_AlgorithmWithTFile() from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "output_TestAlgorithmWithTFile_framework.root" out.outputCommands = ["keep *"] from Configurables import ApplicationMgr -ApplicationMgr( TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=100, - ExtSvc=[podioevent], - OutputLevel=INFO, - StopOnSignal=True, - ) - +ApplicationMgr( + TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=100, + ExtSvc=[podioevent], + OutputLevel=INFO, + StopOnSignal=True, +) diff --git a/test/k4FWCoreTest/options/TestArgs.py b/test/k4FWCoreTest/options/TestArgs.py index 6119314d..5e595a00 100644 --- a/test/k4FWCoreTest/options/TestArgs.py +++ b/test/k4FWCoreTest/options/TestArgs.py @@ -17,7 +17,8 @@ # limitations under the License. # from k4FWCore.parseArgs import parser + parser.add_argument("-f", "--foo", type=int, help="hello world") my_opts = parser.parse_known_args() -print(f"The answer is {my_opts[0].foo}") \ No newline at end of file +print(f"The answer is {my_opts[0].foo}") diff --git a/test/k4FWCoreTest/options/TestDataHandleUniquePtr.py b/test/k4FWCoreTest/options/TestDataHandleUniquePtr.py index 4b054adf..20a64de2 100644 --- a/test/k4FWCoreTest/options/TestDataHandleUniquePtr.py +++ b/test/k4FWCoreTest/options/TestDataHandleUniquePtr.py @@ -19,24 +19,25 @@ from Gaudi.Configuration import * from Configurables import ApplicationMgr + ApplicationMgr().EvtSel = "NONE" ApplicationMgr().EvtMax = 100 ApplicationMgr().OutputLevel = INFO ApplicationMgr().StopOnSignal = True from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") ApplicationMgr().ExtSvc += [podioevent] from Configurables import TestDataHandleUniquePtr + producer = TestDataHandleUniquePtr() ApplicationMgr().TopAlg += [producer] from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "output_TestDataHandleUniquePtr.root" out.outputCommands = ["keep *"] ApplicationMgr().TopAlg += [out] - - - diff --git a/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py b/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py index cb7af0ea..b6f1f002 100644 --- a/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py +++ b/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py @@ -19,18 +19,22 @@ from Gaudi.Configuration import * from Configurables import UniqueIDGenSvc + UniqueIDGenSvc().Seed = 987 from Configurables import ApplicationMgr + ApplicationMgr().EvtSel = "NONE" ApplicationMgr().EvtMax = 5 ApplicationMgr().OutputLevel = INFO ApplicationMgr().StopOnSignal = True from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") ApplicationMgr().ExtSvc += [podioevent] from Configurables import TestUniqueIDGenSvc + uniqueidtest = TestUniqueIDGenSvc() ApplicationMgr().TopAlg += [uniqueidtest] diff --git a/test/k4FWCoreTest/options/TwoProducers.py b/test/k4FWCoreTest/options/TwoProducers.py index a92441cc..2e088acf 100644 --- a/test/k4FWCoreTest/options/TwoProducers.py +++ b/test/k4FWCoreTest/options/TwoProducers.py @@ -19,24 +19,28 @@ from Gaudi.Configuration import * from Configurables import ApplicationMgr + ApplicationMgr( - EvtSel="NONE", - EvtMax=100, - OutputLevel=INFO, - StopOnSignal=True, - ) + EvtSel="NONE", + EvtMax=100, + OutputLevel=INFO, + StopOnSignal=True, +) from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") ApplicationMgr().ExtSvc += [podioevent] from Configurables import k4FWCoreTest_CreateExampleEventData + producer1 = k4FWCoreTest_CreateExampleEventData("Producer1") ApplicationMgr().TopAlg += [producer1] from Configurables import k4FWCoreTest_CreateExampleEventData + producer2 = k4FWCoreTest_CreateExampleEventData("Producer2") producer2.mcparticles.Path = "mcparticles2" producer2.trackhits.Path = "trackhits2" @@ -46,10 +50,8 @@ ApplicationMgr().TopAlg += [producer2] from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "output_k4test_exampledata_twoproducer.root" out.outputCommands = ["keep *"] ApplicationMgr().TopAlg += [out] - - - diff --git a/test/k4FWCoreTest/options/createEventHeader.py b/test/k4FWCoreTest/options/createEventHeader.py index 016528f9..66c84046 100644 --- a/test/k4FWCoreTest/options/createEventHeader.py +++ b/test/k4FWCoreTest/options/createEventHeader.py @@ -19,25 +19,29 @@ from Gaudi.Configuration import * from Configurables import EventHeaderCreator -eventHeaderCreator = EventHeaderCreator("eventHeaderCreator", - runNumber = 42, - eventNumberOffset = 42, - OutputLevel=DEBUG) + +eventHeaderCreator = EventHeaderCreator( + "eventHeaderCreator", runNumber=42, eventNumberOffset=42, OutputLevel=DEBUG +) from Configurables import k4DataSvc -podioevent = k4DataSvc("EventDataSvc") + +podioevent = k4DataSvc("EventDataSvc") from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "eventHeader.root" from Configurables import ApplicationMgr + ApplicationMgr( - TopAlg = [ - eventHeaderCreator, - out, - ], - EvtSel = 'NONE', - EvtMax = 2, - ExtSvc = [podioevent], - StopOnSignal = True) + TopAlg=[ + eventHeaderCreator, + out, + ], + EvtSel="NONE", + EvtMax=2, + ExtSvc=[podioevent], + StopOnSignal=True, +) diff --git a/test/k4FWCoreTest/options/createExampleEventData.py b/test/k4FWCoreTest/options/createExampleEventData.py index a16da935..c71dc2ae 100644 --- a/test/k4FWCoreTest/options/createExampleEventData.py +++ b/test/k4FWCoreTest/options/createExampleEventData.py @@ -19,23 +19,26 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") from Configurables import k4FWCoreTest_CreateExampleEventData + producer = k4FWCoreTest_CreateExampleEventData() from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "output_k4test_exampledata.root" out.outputCommands = ["keep *"] from Configurables import ApplicationMgr -ApplicationMgr( TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=100, - ExtSvc=[podioevent], - OutputLevel=INFO, - StopOnSignal=True, - ) - +ApplicationMgr( + TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=100, + ExtSvc=[podioevent], + OutputLevel=INFO, + StopOnSignal=True, +) diff --git a/test/k4FWCoreTest/options/createExampleEventData_cellID.py b/test/k4FWCoreTest/options/createExampleEventData_cellID.py index 8bbc15c7..9a189e4b 100644 --- a/test/k4FWCoreTest/options/createExampleEventData_cellID.py +++ b/test/k4FWCoreTest/options/createExampleEventData_cellID.py @@ -19,24 +19,27 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") from Configurables import k4FWCoreTest_cellID_writer, k4FWCoreTest_cellID_reader + producer = k4FWCoreTest_cellID_writer() consumer = k4FWCoreTest_cellID_reader() from Configurables import PodioOutput + out = PodioOutput("out") out.filename = "output_k4test_exampledata_cellid.root" out.outputCommands = ["keep *"] from Configurables import ApplicationMgr -ApplicationMgr( TopAlg=[producer, consumer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[podioevent], - OutputLevel=INFO, - StopOnSignal=True, - ) - +ApplicationMgr( + TopAlg=[producer, consumer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, + StopOnSignal=True, +) diff --git a/test/k4FWCoreTest/options/createHelloWorld.py b/test/k4FWCoreTest/options/createHelloWorld.py index 539064b1..cae9631c 100644 --- a/test/k4FWCoreTest/options/createHelloWorld.py +++ b/test/k4FWCoreTest/options/createHelloWorld.py @@ -19,18 +19,19 @@ from Gaudi.Configuration import * from Configurables import ApplicationMgr + ApplicationMgr().EvtSel = "NONE" ApplicationMgr().EvtMax = 1 ApplicationMgr().OutputLevel = INFO from Configurables import k4FWCoreTest_HelloWorldAlg + producer = k4FWCoreTest_HelloWorldAlg("HelloWorldAlg1") producer.PerEventPrintMessage = "Hello World !" ApplicationMgr().TopAlg += [producer] from Configurables import k4FWCoreTest_HelloWorldAlg + producer2 = k4FWCoreTest_HelloWorldAlg("HelloWorldAlg2") producer2.PerEventPrintMessage = "Hello World2 !" ApplicationMgr().TopAlg += [producer2] - - diff --git a/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py b/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py index a5dd7dd9..0057fd3b 100644 --- a/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py +++ b/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py @@ -19,24 +19,27 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata.root" podioevent.FirstEventEntry = 66 from Configurables import PodioInput + inp = PodioInput() inp.collections = ["MCParticles", "SimTrackerHits", "Tracks"] from Configurables import PodioOutput + oup = PodioOutput() oup.filename = "output_k4test_exampledata_3.root" from Configurables import ApplicationMgr -ApplicationMgr( TopAlg=[inp, oup], - EvtSel="NONE", - EvtMax=5, - ExtSvc=[podioevent], - OutputLevel=DEBUG, - ) - +ApplicationMgr( + TopAlg=[inp, oup], + EvtSel="NONE", + EvtMax=5, + ExtSvc=[podioevent], + OutputLevel=DEBUG, +) diff --git a/test/k4FWCoreTest/options/readExampleEventData.py b/test/k4FWCoreTest/options/readExampleEventData.py index daeac03a..c4b95280 100644 --- a/test/k4FWCoreTest/options/readExampleEventData.py +++ b/test/k4FWCoreTest/options/readExampleEventData.py @@ -19,24 +19,27 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc + podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata.root" from Configurables import PodioInput + inp = PodioInput() inp.collections = ["MCParticles", "SimTrackerHits", "TrackerHits", "Tracks"] from Configurables import PodioOutput + oup = PodioOutput() oup.filename = "output_k4test_exampledata_2.root" oup.outputCommands = ["drop MCParticles"] from Configurables import ApplicationMgr -ApplicationMgr( TopAlg=[inp, oup], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[podioevent], - OutputLevel=DEBUG, - ) - +ApplicationMgr( + TopAlg=[inp, oup], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=DEBUG, +) diff --git a/test/k4FWCoreTest/options/runEventHeaderCheck.py b/test/k4FWCoreTest/options/runEventHeaderCheck.py index 22c7444f..b7d0af72 100644 --- a/test/k4FWCoreTest/options/runEventHeaderCheck.py +++ b/test/k4FWCoreTest/options/runEventHeaderCheck.py @@ -30,9 +30,7 @@ inp = PodioInput() inp.collections = [] -consumer = ExampleEventHeaderConsumer( - "EventHeaderCheck", runNumber=42, eventNumberOffset=42 -) +consumer = ExampleEventHeaderConsumer("EventHeaderCheck", runNumber=42, eventNumberOffset=42) ApplicationMgr( TopAlg=[inp, consumer], diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index 16dbb770..e8637492 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -34,13 +34,15 @@ "MCParticles", ] -consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", - InputCollection="MCParticles", - ) +consumer = ExampleFunctionalConsumer( + "ExampleFunctionalConsumer", + InputCollection="MCParticles", +) -ApplicationMgr(TopAlg=[inp, consumer], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[podioevent], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[inp, consumer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py index 971627ba..d103921b 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -39,12 +39,14 @@ "Tracks", ] -consumer = ExampleFunctionalConsumerMultiple("ExampleFunctionalConsumerMultiple", - ) +consumer = ExampleFunctionalConsumerMultiple( + "ExampleFunctionalConsumerMultiple", +) -ApplicationMgr(TopAlg=[inp, consumer], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[podioevent], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[inp, consumer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index a2775b08..e66ff707 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -35,9 +35,10 @@ producer = ExampleFunctionalProducer("ExampleFunctionalProducer") -ApplicationMgr(TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index dd89a16e..b3920470 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -32,18 +32,21 @@ # Collections can be dropped # out.outputCommands = ["drop *"] -producer = ExampleFunctionalProducerMultiple("ExampleFunctionalProducerMultiple", - OutputCollectionFloat="VectorFloat", - OutputCollectionParticles1="MCParticles1", - OutputCollectionParticles2="MCParticles2", - OutputCollectionSimTrackerHits="SimTrackerHits", - OutputCollectionTrackerHits="TrackerHits", - OutputCollectionTracks="Tracks", - ExampleInt=5) +producer = ExampleFunctionalProducerMultiple( + "ExampleFunctionalProducerMultiple", + OutputCollectionFloat="VectorFloat", + OutputCollectionParticles1="MCParticles1", + OutputCollectionParticles2="MCParticles2", + OutputCollectionSimTrackerHits="SimTrackerHits", + OutputCollectionTrackerHits="TrackerHits", + OutputCollectionTracks="Tracks", + ExampleInt=5, +) -ApplicationMgr(TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index f0be66e1..2047c939 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -40,13 +40,16 @@ # The collections that we don't drop will also be present in the output file out.outputCommands = ["drop MCParticles"] -transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", - InputCollection="MCParticles", - OutputCollection="NewMCParticles") +transformer = ExampleFunctionalTransformer( + "ExampleFunctionalTransformer", + InputCollection="MCParticles", + OutputCollection="NewMCParticles", +) -ApplicationMgr(TopAlg=[inp, transformer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[inp, transformer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py index ed48163d..44356fe1 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -39,23 +39,29 @@ out = PodioOutput("out") out.filename = "output_k4test_exampledata_transformer_multiple.root" # The collections that we don't drop will also be present in the output file -out.outputCommands = ["drop VectorFloat", "drop MCParticles1", - "drop SimTrackerHits", "drop TrackerHits", - "drop Tracks"] +out.outputCommands = [ + "drop VectorFloat", + "drop MCParticles1", + "drop SimTrackerHits", + "drop TrackerHits", + "drop Tracks", +] -transformer = ExampleFunctionalTransformerMultiple("ExampleFunctionalTransformerMultiple", - InputCollectionFloat="VectorFloat", - InputCollectionParticles="MCParticles1", - InputCollectionSimTrackerHits="SimTrackerHits", - InputCollectionTrackerHits="TrackerHits", - InputCollectionTracks="Tracks", - OutputCollectionCounter="Counter", - OutputCollectionParticles="NewMCParticles", - ) +transformer = ExampleFunctionalTransformerMultiple( + "ExampleFunctionalTransformerMultiple", + InputCollectionFloat="VectorFloat", + InputCollectionParticles="MCParticles1", + InputCollectionSimTrackerHits="SimTrackerHits", + InputCollectionTrackerHits="TrackerHits", + InputCollectionTracks="Tracks", + OutputCollectionCounter="Counter", + OutputCollectionParticles="NewMCParticles", +) -ApplicationMgr(TopAlg=[inp, transformer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[inp, transformer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runFunctionalChain.py b/test/k4FWCoreTest/options/runFunctionalChain.py index ed421748..ec2affd0 100644 --- a/test/k4FWCoreTest/options/runFunctionalChain.py +++ b/test/k4FWCoreTest/options/runFunctionalChain.py @@ -36,20 +36,25 @@ out.filename = "functional_chain.root" producer = ExampleFunctionalProducer("ExampleFunctionalProducer") -consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", - InputCollection="MCParticles", - ) -transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", - InputCollection="MCParticles", - OutputCollection="NewMCParticles") -new_consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer2", - InputCollection="NewMCParticles", - ) +consumer = ExampleFunctionalConsumer( + "ExampleFunctionalConsumer", + InputCollection="MCParticles", +) +transformer = ExampleFunctionalTransformer( + "ExampleFunctionalTransformer", + InputCollection="MCParticles", + OutputCollection="NewMCParticles", +) +new_consumer = ExampleFunctionalConsumer( + "ExampleFunctionalConsumer2", + InputCollection="NewMCParticles", +) new_consumer.PossibleOffset = 10 -ApplicationMgr(TopAlg=[producer, consumer, transformer, new_consumer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[event_data_svc], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[producer, consumer, transformer, new_consumer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[event_data_svc], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/options/runFunctionalMix.py b/test/k4FWCoreTest/options/runFunctionalMix.py index a12fd861..2752e028 100644 --- a/test/k4FWCoreTest/options/runFunctionalMix.py +++ b/test/k4FWCoreTest/options/runFunctionalMix.py @@ -43,37 +43,40 @@ consumer_input_functional = ExampleFunctionalConsumerMultiple("ExampleFunctionalConsumerMultiple") consumer_input_algorithm = k4FWCoreTest_CheckExampleEventData("CheckExampleEventData") -consumer_input_algorithm.mcparticles = 'MCParticles1' +consumer_input_algorithm.mcparticles = "MCParticles1" consumer_input_algorithm.keepEventNumberZero = True # We only care about the new FunctionalMCParticles collection in this example -producer_functional = ExampleFunctionalProducerMultiple("ProducerFunctional", - OutputCollectionFloat="VectorFloat_", - OutputCollectionParticles1="FunctionalMCParticles", - OutputCollectionParticles2="MCParticles2_", - OutputCollectionSimTrackerHits="SimTrackerHits_", - OutputCollectionTrackerHits="TrackerHits_", - OutputCollectionTracks="Tracks_", - ExampleInt=5) - -consumer_producerfun_functional = ExampleFunctionalConsumerMultiple("FunctionalConsumerFunctional", - InputCollectionParticles="FunctionalMCParticles", - ) +producer_functional = ExampleFunctionalProducerMultiple( + "ProducerFunctional", + OutputCollectionFloat="VectorFloat_", + OutputCollectionParticles1="FunctionalMCParticles", + OutputCollectionParticles2="MCParticles2_", + OutputCollectionSimTrackerHits="SimTrackerHits_", + OutputCollectionTrackerHits="TrackerHits_", + OutputCollectionTracks="Tracks_", + ExampleInt=5, +) + +consumer_producerfun_functional = ExampleFunctionalConsumerMultiple( + "FunctionalConsumerFunctional", + InputCollectionParticles="FunctionalMCParticles", +) consumer_producerfun_algorithm = k4FWCoreTest_CheckExampleEventData("CheckFunctional") -consumer_producerfun_algorithm.mcparticles = 'FunctionalMCParticles' +consumer_producerfun_algorithm.mcparticles = "FunctionalMCParticles" consumer_producerfun_algorithm.keepEventNumberZero = True producer_algorithm = k4FWCoreTest_CreateExampleEventData("CreateExampleEventData") # We only care about the MCParticles collection -producer_algorithm.mcparticles = 'AlgorithmMCParticles' -producer_algorithm.simtrackhits = 'SimTrackerHits__' -producer_algorithm.trackhits = 'TrackerHits__' -producer_algorithm.tracks = 'Tracks__' -producer_algorithm.vectorfloat = 'VectorFloat__' +producer_algorithm.mcparticles = "AlgorithmMCParticles" +producer_algorithm.simtrackhits = "SimTrackerHits__" +producer_algorithm.trackhits = "TrackerHits__" +producer_algorithm.tracks = "Tracks__" +producer_algorithm.vectorfloat = "VectorFloat__" consumer_produceralg_functional = ExampleFunctionalConsumerMultiple("FunctionalConsumerAlgorithm") consumer_produceralg_algorithm = k4FWCoreTest_CheckExampleEventData("CheckAlgorithm") -consumer_produceralg_algorithm.mcparticles = 'FunctionalMCParticles' +consumer_produceralg_algorithm.mcparticles = "FunctionalMCParticles" consumer_produceralg_algorithm.keepEventNumberZero = True # Let's also run the transformer, why not @@ -82,29 +85,25 @@ out = PodioOutput("out") out.filename = "output_k4test_exampledata_functional_mix.root" -ApplicationMgr(TopAlg=[inp, - # Check we can read input - consumer_input_functional, - consumer_input_algorithm, - - producer_functional, - - # Check we can read what's produced by a functional - consumer_producerfun_functional, - consumer_producerfun_algorithm, - - producer_algorithm, - - # Check we can read what's produced by an algorithm - consumer_produceralg_functional, - consumer_produceralg_algorithm, - - transformer_functional, - - out - ], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[podioevent], - OutputLevel=INFO, - ) +ApplicationMgr( + TopAlg=[ + inp, + # Check we can read input + consumer_input_functional, + consumer_input_algorithm, + producer_functional, + # Check we can read what's produced by a functional + consumer_producerfun_functional, + consumer_producerfun_algorithm, + producer_algorithm, + # Check we can read what's produced by an algorithm + consumer_produceralg_functional, + consumer_produceralg_algorithm, + transformer_functional, + out, + ], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/scripts/check_KeepDropSwitch.py b/test/k4FWCoreTest/scripts/check_KeepDropSwitch.py index ac438da0..82c3e576 100644 --- a/test/k4FWCoreTest/scripts/check_KeepDropSwitch.py +++ b/test/k4FWCoreTest/scripts/check_KeepDropSwitch.py @@ -25,10 +25,9 @@ tree.GetEntry(0) ndf = tree.Tracks.at(0).ndf -if ndf==0: - raise Exception('podio::CollectionBase read from file did not saved properly') +if ndf == 0: + raise Exception("podio::CollectionBase read from file did not saved properly") status = tree.GetBranchStatus("MCParticles") -if status==True: - raise Exception('KeepDropSwitch did not drop the collection') - +if status == True: + raise Exception("KeepDropSwitch did not drop the collection") diff --git a/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_framework_nonempty.py b/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_framework_nonempty.py index 929c4735..0aa70dfb 100644 --- a/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_framework_nonempty.py +++ b/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_framework_nonempty.py @@ -20,4 +20,8 @@ f = ROOT.TFile.Open("output_TestAlgorithmWithTFile_framework.root") t = f.Get("events") -print("File: output_TestAlgorithmWithTFile_framework.root contains TTree events with " + str(t.GetEntries()) + " entries.") +print( + "File: output_TestAlgorithmWithTFile_framework.root contains TTree events with " + + str(t.GetEntries()) + + " entries." +) diff --git a/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_myTFile_nonempty.py b/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_myTFile_nonempty.py index bc5aaa3b..82b99033 100644 --- a/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_myTFile_nonempty.py +++ b/test/k4FWCoreTest/scripts/check_TestAlgorithmWithTFile_myTFile_nonempty.py @@ -20,4 +20,8 @@ f = ROOT.TFile.Open("output_TestAlgorithmWithTFile_myTFile.root") t = f.Get("mytree") -print("File: output_TestAlgorithmWithTFile_myTFile.root contains TTree mytree with " + str(t.GetEntries()) + " entries.") +print( + "File: output_TestAlgorithmWithTFile_myTFile.root contains TTree mytree with " + + str(t.GetEntries()) + + " entries." +)