From e0778b3da9d81250e9889254395acf60442de47e Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:35:11 +0200 Subject: [PATCH] IOSvc: Minor fixes for improving usage and errors (#213) --- k4FWCore/components/IIOSvc.h | 2 +- k4FWCore/components/IOSvc.cpp | 17 +++++++ k4FWCore/components/IOSvc.h | 12 +++-- k4FWCore/python/k4FWCore/utils.py | 38 ++++++++++++++- python/k4FWCore/ApplicationMgr.py | 46 +++++++++++++++---- python/k4FWCore/IOSvc.py | 6 +-- test/k4FWCoreTest/CMakeLists.txt | 3 ++ .../ExampleFunctionalCollectionMerger.py | 4 +- .../options/ExampleFunctionalFile.py | 4 +- .../options/ExampleFunctionalFileMultiple.py | 4 +- .../options/ExampleFunctionalFilterFile.py | 2 +- .../options/ExampleFunctionalMTFile.py | 9 ++-- .../options/ExampleFunctionalMTMemory.py | 4 +- .../options/ExampleFunctionalMetadata.py | 2 +- .../ExampleFunctionalMetadataOldAlgorithm.py | 2 +- .../ExampleFunctionalOutputCommands.py | 4 +- .../options/ExampleFunctionalProducer.py | 4 +- .../ExampleFunctionalProducerAbsolutePath.py | 2 +- .../ExampleFunctionalProducerMultiple.py | 4 +- .../ExampleFunctionalSeveralInputFiles.py | 2 +- .../ExampleFunctionalTransformerHist.py | 5 +- ...xampleFunctionalTransformerRuntimeEmpty.py | 2 +- .../options/ExampleFunctionalWrongImport.py | 36 +++++++++++++++ .../options/TestAlgorithmWithTFile.py | 6 +-- .../options/TestUniqueIDGenSvc.py | 10 ++-- test/k4FWCoreTest/options/TwoProducers.py | 13 ++---- .../options/checkExampleEventData.py | 13 ++---- .../k4FWCoreTest/options/createEventHeader.py | 6 +-- .../options/createExampleEventData.py | 8 ++-- .../createExampleEventDataInDirectory.py | 2 +- .../options/createExampleEventData_cellID.py | 8 ++-- test/k4FWCoreTest/options/createHelloWorld.py | 10 ++-- .../options/readExampleDataFromNthEvent.py | 8 ++-- .../options/readExampleEventData.py | 8 ++-- .../options/runEventHeaderCheck.py | 10 ++-- test/k4FWCoreTest/options/runFunctionalMix.py | 10 ++-- 36 files changed, 225 insertions(+), 101 deletions(-) create mode 100644 test/k4FWCoreTest/options/ExampleFunctionalWrongImport.py diff --git a/k4FWCore/components/IIOSvc.h b/k4FWCore/components/IIOSvc.h index d5721e0a..e12ae13f 100644 --- a/k4FWCore/components/IIOSvc.h +++ b/k4FWCore/components/IIOSvc.h @@ -28,7 +28,7 @@ #include /** - * The interface implemented by any class making IO and reading RawEvent Data + * The interface implemented by any class making IO with functional algorithms */ class IIOSvc : virtual public IInterface { public: diff --git a/k4FWCore/components/IOSvc.cpp b/k4FWCore/components/IOSvc.cpp index 1369bd6e..f48c501d 100644 --- a/k4FWCore/components/IOSvc.cpp +++ b/k4FWCore/components/IOSvc.cpp @@ -38,7 +38,19 @@ StatusCode IOSvc::initialize() { error() << "Unable to initialize base class Service." << endmsg; return sc; } + + if (!m_importedFromk4FWCore) { + error() << "Use 'from k4FWCore import IOSvc' instead of 'from Configurables import IOSvc' to access the service" + << endmsg; + return StatusCode::FAILURE; + } + + if (!m_readingFileNamesDeprecated.empty()) { + warning() << ".input is deprecated, use .Input instead in the steering file" << endmsg; + m_readingFileNames = m_readingFileNamesDeprecated; + } if (!m_readingFileNames.empty()) { + info() << m_readingFileNames.size() << " files to be read" << endmsg; m_reader = std::make_unique(); try { m_reader->openFiles(m_readingFileNames); @@ -49,6 +61,11 @@ StatusCode IOSvc::initialize() { m_entries = m_reader->getEntries(podio::Category::Event); } + if (!m_writingFileNameDeprecated.empty()) { + warning() << ".output is deprecated, use .Output instead in the steering file" << endmsg; + m_writingFileName = m_writingFileNameDeprecated; + } + m_switch = KeepDropSwitch(m_outputCommands); m_incidentSvc = service("IncidentSvc"); diff --git a/k4FWCore/components/IOSvc.h b/k4FWCore/components/IOSvc.h index 25890c84..4a986dfe 100644 --- a/k4FWCore/components/IOSvc.h +++ b/k4FWCore/components/IOSvc.h @@ -56,11 +56,17 @@ class IOSvc : public extends { protected: Gaudi::Property> m_collectionNames{ this, "CollectionNames", {}, "List of collections to read"}; - Gaudi::Property> m_readingFileNames{this, "input", {}, "List of files to read"}; - Gaudi::Property m_writingFileName{this, "output", {}, "List of files to write output to"}; + Gaudi::Property> m_readingFileNamesDeprecated{this, "input", {}, "List of files to read"}; + Gaudi::Property> m_readingFileNames{this, "Input", {}, "List of files to read"}; + Gaudi::Property m_writingFileNameDeprecated{this, "output", {}, "List of files to write output to"}; + Gaudi::Property m_writingFileName{this, "Output", {}, "List of files to write output to"}; Gaudi::Property> m_outputCommands{ this, "outputCommands", {"keep *"}, "A set of commands to declare which collections to keep or drop."}; - Gaudi::Property m_inputType{this, "ioType", "ROOT", "Type of input file (ROOT, RNTuple)"}; + Gaudi::Property m_inputType{this, "IOType", "ROOT", "Type of input file (ROOT, RNTuple)"}; + + Gaudi::Property m_importedFromk4FWCore{ + this, "ImportedFromk4FWCore", false, + "This is set to true when IOSvc is imported from k4FWCore instead of Configurables in python"}; std::mutex m_changeBufferLock; diff --git a/k4FWCore/python/k4FWCore/utils.py b/k4FWCore/python/k4FWCore/utils.py index 6b2c672e..ec257139 100644 --- a/k4FWCore/python/k4FWCore/utils.py +++ b/k4FWCore/python/k4FWCore/utils.py @@ -18,10 +18,43 @@ # limitations under the License. # import os +import re from io import TextIOWrapper from typing import Union +def check_wrong_imports(code: str) -> None: + """Check for wrong imports in the given code. + + This function checks the given code for any imports of IOSvc or ApplicationMgr + from Configurables instead of k4FWCore. If such an import is found, an ImportError + is raised. + + If IOSvc and ApplicationMgr are not imported from k4FWCore it's possible + that k4run will fail, for example, by not adding the reader and writer + algorithms manually, which is done by the wrapper in k4FWCore. The checks + are not comprehensive, it's still possible to import IOSvc or ApplicationMgr + from Configurables. + + Args: + code (str): The code to check for wrong imports. + + Raises: + ImportError: If the code contains an import of IOSvc or ApplicationMgr from Configurables. + + """ + # Check first that IOSvc is being used, in that case + # Importing either ApplicationMgr or IOSvc from Configurables is not allowed + iosvc_regex = re.compile( + r"^\s*from\s+(Configurables|k4FWCore)\s+import\s+\(?.*IOSvc.*\)?", re.MULTILINE + ) + regex = re.compile( + r"^\s*from\s+Configurables\s+import\s+\(?.*(ApplicationMgr|IOSvc).*\)?", re.MULTILINE + ) + if re.search(iosvc_regex, code) and re.search(regex, code): + raise ImportError("Importing ApplicationMgr or IOSvc from Configurables is not allowed.") + + def load_file(opt_file: Union[TextIOWrapper, str, os.PathLike]) -> None: """Loads and executes the content of a given file in the current interpreter session. @@ -44,8 +77,9 @@ def load_file(opt_file: Union[TextIOWrapper, str, os.PathLike]) -> None: """ if isinstance(opt_file, (str, os.PathLike)): with open(opt_file, "r") as file: - code = compile(file.read(), file.name, "exec") + code = file.read() else: - code = compile(opt_file.read(), opt_file.name, "exec") + code = opt_file.read() + check_wrong_imports(str(code)) exec(code, globals()) diff --git a/python/k4FWCore/ApplicationMgr.py b/python/k4FWCore/ApplicationMgr.py index 06f2a499..f2085c7d 100644 --- a/python/k4FWCore/ApplicationMgr.py +++ b/python/k4FWCore/ApplicationMgr.py @@ -17,7 +17,7 @@ # limitations under the License. # from Configurables import ApplicationMgr as AppMgr -from Configurables import Reader, Writer, IOSvc, MetadataSvc, Gaudi__Sequencer +from Configurables import Reader, Writer, IOSvc, MetadataSvc, Gaudi__Sequencer, EventLoopMgr import os from podio.root_io import Reader as PodioReader @@ -37,6 +37,12 @@ class ApplicationMgr: def __init__(self, **kwargs): self._mgr = AppMgr(**kwargs) + # If there isn't an EventLoopMgr then it's the default + # This will suppress two warnings about not using external input + try: + self._mgr.EventLoop + except AttributeError: + self._mgr.EventLoop = EventLoopMgr(Warnings=False) for conf in frozenset(self._mgr.allConfigurables.values()): if isinstance(conf, MetadataSvc): @@ -45,18 +51,24 @@ def __init__(self, **kwargs): continue props = conf.getPropertiesWithDescription() reader = writer = None - add_reader = add_writer = False + add_reader = False for alg in self._mgr.TopAlg: if isinstance(alg, Reader): reader = alg elif isinstance(alg, Writer): writer = alg - if reader is None and props["input"][0]: + # Remove "input" when the corresponding property is removed from IOSvc + if reader is None and (props["input"][0] or props["Input"][0]): reader = Reader("k4FWCore__Reader") add_reader = True # It seems for a single string the default without a value is '' # while for a list it's an empty list - if writer is None and props["output"][0] and props["output"][0] != "": + # Remove "output" when the corresponding property is removed from IOSvc + if ( + writer is None + and (props["output"][0] and props["output"][0] != "") + or (props["Output"][0] and props["Output"][0] != "") + ): writer = Writer("k4FWCore__Writer") # Let's tell the Reader one of the input files so it can # know which collections it's going to read @@ -67,15 +79,24 @@ def __init__(self, **kwargs): # (possibly) the first 9 complete and 9 more are scheduled, out of # which only one will be finished without errors. If we know the # number of events in advance then we can just schedule those. + inp = None if props["input"][0]: - if os.path.exists(props["input"][0][0]): - path = props["input"][0][0] + inp = "input" + elif props["Input"][0]: + inp = "Input" + if inp: + if os.path.exists(props[inp][0][0]): + path = props[inp][0][0] else: - path = os.getcwd() + "/" + props["input"][0][0] + path = os.getcwd() + "/" + props[inp][0][0] podio_reader = PodioReader(path) if self._mgr.EvtMax == -1: self._mgr.EvtMax = podio_reader._reader.getEntries("events") - frame = podio_reader.get("events")[0] + try: + frame = podio_reader.get("events")[0] + except IndexError: + print("Warning, the events category wasn't found in the input file") + raise collections = list(frame.getAvailableCollections()) reader.InputCollections = collections self._mgr.TopAlg = ([reader] if add_reader else []) + self._mgr.TopAlg @@ -99,3 +120,12 @@ def __init__(self, **kwargs): ], ) ] + + def __getattr__(self, name): + return getattr(self._mgr, name) + + def __setattr__(self, name, value): + if name == "_mgr": + super().__setattr__(name, value) + else: + setattr(self._mgr, name, value) diff --git a/python/k4FWCore/IOSvc.py b/python/k4FWCore/IOSvc.py index 86786991..5add6236 100644 --- a/python/k4FWCore/IOSvc.py +++ b/python/k4FWCore/IOSvc.py @@ -22,7 +22,7 @@ class IOSvc: def __init__(self, *args, **kwargs): - self._svc = IO(**kwargs) + self._svc = IO(**kwargs, ImportedFromk4FWCore=True) MetadataSvc("MetadataSvc") def __getattr__(self, attr): @@ -34,10 +34,10 @@ def __setattr__(self, attr, value): return # Allow to specify a single string for input when what we want is a list - if attr == "input": + if attr == "input" or attr == "Input": if isinstance(value, str): value = [value] - if attr == "output": + elif attr == "output" or attr == "Output": if os.path.dirname(value) and not os.path.exists(os.path.dirname(value)): os.makedirs(os.path.dirname(value)) setattr(self._svc, attr, value) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 8f18f36c..e8d9e22c 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -138,6 +138,9 @@ add_test_with_env(FunctionalFilterFile options/ExampleFunctionalFilterFile.py) add_test_with_env(FunctionalMetadata options/ExampleFunctionalMetadata.py) add_test_with_env(FunctionalMetadataOldAlgorithm options/ExampleFunctionalMetadataOldAlgorithm.py) +add_test_with_env(FunctionalWrongImport options/ExampleFunctionalWrongImport.py) +set_tests_properties(FunctionalWrongImport PROPERTIES PASS_REGULAR_EXPRESSION "ImportError: Importing ApplicationMgr or IOSvc from Configurables is not allowed.") + add_test(NAME FunctionalCheckFiles COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/options/CheckOutputFiles.py) set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataOldAlgorithm") diff --git a/test/k4FWCoreTest/options/ExampleFunctionalCollectionMerger.py b/test/k4FWCoreTest/options/ExampleFunctionalCollectionMerger.py index 2c6b8a73..8a27e67b 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalCollectionMerger.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalCollectionMerger.py @@ -28,8 +28,8 @@ from Configurables import ExampleFunctionalProducer svc = IOSvc("IOSvc") -svc.input = "functional_producer_multiple.root" -svc.output = "functional_merged_collections.root" +svc.Input = "functional_producer_multiple.root" +svc.Output = "functional_merged_collections.root" svc.outputCommands = [ "drop *", "keep MCParticles1", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalFile.py b/test/k4FWCoreTest/options/ExampleFunctionalFile.py index b447ea8e..d4d58484 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalFile.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalFile.py @@ -26,8 +26,8 @@ from k4FWCore import ApplicationMgr, IOSvc svc = IOSvc("IOSvc") -svc.input = "functional_producer.root" -svc.output = "functional_transformer.root" +svc.Input = "functional_producer.root" +svc.Output = "functional_transformer.root" transformer = ExampleFunctionalTransformer( "Transformer", InputCollection=["MCParticles"], OutputCollection=["NewMCParticles"] diff --git a/test/k4FWCoreTest/options/ExampleFunctionalFileMultiple.py b/test/k4FWCoreTest/options/ExampleFunctionalFileMultiple.py index 46b341a5..5f1978c2 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalFileMultiple.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalFileMultiple.py @@ -26,8 +26,8 @@ from k4FWCore import ApplicationMgr, IOSvc svc = IOSvc("IOSvc") -svc.input = "functional_producer_multiple.root" -svc.output = "functional_transformer_multiple.root" +svc.Input = "functional_producer_multiple.root" +svc.Output = "functional_transformer_multiple.root" transformer = ExampleFunctionalTransformerMultiple( "Transformer", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalFilterFile.py b/test/k4FWCoreTest/options/ExampleFunctionalFilterFile.py index e723cfb7..43c3aa75 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalFilterFile.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalFilterFile.py @@ -30,7 +30,7 @@ from Configurables import EventDataSvc iosvc = IOSvc("IOSvc") -iosvc.output = "functional_filter.root" +iosvc.Output = "functional_filter.root" transformer = ExampleFunctionalTransformer( "Transformer", InputCollection=["MCParticles"], OutputCollection=["NewMCParticles"] diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMTFile.py b/test/k4FWCoreTest/options/ExampleFunctionalMTFile.py index 0ce0c058..0fd052f9 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalMTFile.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalMTFile.py @@ -35,14 +35,17 @@ ) slimeventloopmgr = HiveSlimEventLoopMgr( - "HiveSlimEventLoopMgr", SchedulerName="AvalancheSchedulerSvc", OutputLevel=WARNING + "HiveSlimEventLoopMgr", + SchedulerName="AvalancheSchedulerSvc", + Warnings=False, + OutputLevel=WARNING, ) scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, ShowDataFlow=True, OutputLevel=WARNING) svc = IOSvc("IOSvc") -svc.input = "functional_producer_multiple.root" -svc.output = "functional_transformerMT.root" +svc.Input = "functional_producer_multiple.root" +svc.Output = "functional_transformerMT.root" consumer = ExampleFunctionalConsumer( "Consumer1", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMTMemory.py b/test/k4FWCoreTest/options/ExampleFunctionalMTMemory.py index 55daa51e..5c8e636b 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalMTMemory.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalMTMemory.py @@ -38,7 +38,9 @@ ForceLeaves=True, ) -slimeventloopmgr = HiveSlimEventLoopMgr(SchedulerName="AvalancheSchedulerSvc", OutputLevel=WARNING) +slimeventloopmgr = HiveSlimEventLoopMgr( + SchedulerName="AvalancheSchedulerSvc", Warnings=False, OutputLevel=WARNING +) scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, OutputLevel=WARNING) scheduler.ShowDataDependencies = True diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py index 95338819..06853618 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py @@ -28,7 +28,7 @@ from Configurables import EventDataSvc iosvc = IOSvc() -iosvc.output = "functional_metadata.root" +iosvc.Output = "functional_metadata.root" producer = ExampleFunctionalMetadataProducer("Producer", OutputCollection=["MCParticles"]) consumer = ExampleFunctionalMetadataConsumer("Consumer", InputCollection=["MCParticles"]) diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py b/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py index 2cbda6a2..9c2459f5 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py @@ -21,7 +21,7 @@ from k4FWCore import ApplicationMgr, IOSvc iosvc = IOSvc() -iosvc.output = "functional_metadata_old_algorithm.root" +iosvc.Output = "functional_metadata_old_algorithm.root" producer = k4FWCoreTest_cellID_writer() consumer = k4FWCoreTest_cellID_reader() diff --git a/test/k4FWCoreTest/options/ExampleFunctionalOutputCommands.py b/test/k4FWCoreTest/options/ExampleFunctionalOutputCommands.py index a9368baf..c9379c02 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalOutputCommands.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalOutputCommands.py @@ -25,8 +25,8 @@ from k4FWCore import ApplicationMgr, IOSvc svc = IOSvc("IOSvc") -svc.input = "functional_producer_multiple.root" -svc.output = "functional_transformer_multiple_output_commands.root" +svc.Input = "functional_producer_multiple.root" +svc.Output = "functional_transformer_multiple_output_commands.root" svc.outputCommands = [ "drop Tracks", "drop Counter", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalProducer.py b/test/k4FWCoreTest/options/ExampleFunctionalProducer.py index e1d4d265..249a58d8 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalProducer.py @@ -30,9 +30,9 @@ iosvc = IOSvc("IOSvc") name = "functional_producer.root" if not args[0].second else "functional_producer2.root" -iosvc.output = name +iosvc.Output = name # Collections can be dropped -# out.outputCommands = ["drop *"] +# out.OutputCommands = ["drop *"] producer = ExampleFunctionalProducer("ExampleFunctionalProducer") diff --git a/test/k4FWCoreTest/options/ExampleFunctionalProducerAbsolutePath.py b/test/k4FWCoreTest/options/ExampleFunctionalProducerAbsolutePath.py index d92cf215..41b2809d 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalProducerAbsolutePath.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalProducerAbsolutePath.py @@ -26,7 +26,7 @@ from k4FWCore import ApplicationMgr, IOSvc io = IOSvc("IOSvc") -io.output = "/tmp/a/b/c/functional_producer.root" +io.Output = "/tmp/a/b/c/functional_producer.root" producer = ExampleFunctionalProducer("ExampleFunctionalProducer") diff --git a/test/k4FWCoreTest/options/ExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/ExampleFunctionalProducerMultiple.py index c6b567dd..6d9099f0 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalProducerMultiple.py @@ -27,9 +27,9 @@ iosvc = IOSvc("IOSvc") -iosvc.output = "functional_producer_multiple.root" +iosvc.Output = "functional_producer_multiple.root" # Collections can be dropped -# out.outputCommands = ["drop *"] +# out.OutputCommands = ["drop *"] producer = ExampleFunctionalProducerMultiple( "ExampleFunctionalProducerMultiple", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalSeveralInputFiles.py b/test/k4FWCoreTest/options/ExampleFunctionalSeveralInputFiles.py index fd26bd00..db5095b3 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalSeveralInputFiles.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalSeveralInputFiles.py @@ -25,7 +25,7 @@ from k4FWCore import ApplicationMgr, IOSvc svc = IOSvc("IOSvc") -svc.input = [ +svc.Input = [ "functional_producer.root", "functional_producer2.root", ] diff --git a/test/k4FWCoreTest/options/ExampleFunctionalTransformerHist.py b/test/k4FWCoreTest/options/ExampleFunctionalTransformerHist.py index 742bb09c..c81e249d 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalTransformerHist.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalTransformerHist.py @@ -37,7 +37,10 @@ ForceLeaves=True, ) slimeventloopmgr = HiveSlimEventLoopMgr( - "HiveSlimEventLoopMgr", SchedulerName="AvalancheSchedulerSvc", OutputLevel=INFO + "HiveSlimEventLoopMgr", + SchedulerName="AvalancheSchedulerSvc", + Warnings=False, + OutputLevel=INFO, ) scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, OutputLevel=INFO) diff --git a/test/k4FWCoreTest/options/ExampleFunctionalTransformerRuntimeEmpty.py b/test/k4FWCoreTest/options/ExampleFunctionalTransformerRuntimeEmpty.py index bfe83f79..8503f079 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalTransformerRuntimeEmpty.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalTransformerRuntimeEmpty.py @@ -29,7 +29,7 @@ from Configurables import EventDataSvc iosvc = IOSvc("IOSvc") -iosvc.output = "functional_transformer_runtime_empty.root" +iosvc.Output = "functional_transformer_runtime_empty.root" producer0 = ExampleFunctionalProducer( "Producer0", diff --git a/test/k4FWCoreTest/options/ExampleFunctionalWrongImport.py b/test/k4FWCoreTest/options/ExampleFunctionalWrongImport.py new file mode 100644 index 00000000..3edcfa49 --- /dev/null +++ b/test/k4FWCoreTest/options/ExampleFunctionalWrongImport.py @@ -0,0 +1,36 @@ +# +# Copyright (c) 2014-2024 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This is an example reading from a file and using a transformer to create new +# data + + +# fmt: off +from Configurables import ApplicationMgr +from Configurables import IOSvc +from Configurables import IOSvc, ApplicationMgr +from Configurables import ApplicationMgr, IOSvc +from Configurables import ApplicationMgr, IOSvc, ExampleFunctionalTransformer +from Configurables import ApplicationMgr, ExampleFunctionalTransformer, IOSvc +from Configurables import ExampleFunctionalTransformer, IOSvc, ApplicationMgr +from Configurables import (ApplicationMgr, IOSvc) +from Configurables import (IOSvc, ApplicationMgr) +from Configurables import (IOSvc, ApplicationMgr, ExampleFunctionalTransformer) +from Configurables import (ApplicationMgr, IOSvc, ExampleFunctionalTransformer) +from Configurables import (ExampleFunctionalTransformer, IOSvc, ApplicationMgr) diff --git a/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py b/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py index e7857970..b1046bb5 100644 --- a/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py +++ b/test/k4FWCoreTest/options/TestAlgorithmWithTFile.py @@ -19,20 +19,20 @@ from Gaudi.Configuration import * from Configurables import k4DataSvc +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr +from Configurables import k4FWCoreTest_AlgorithmWithTFile 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], diff --git a/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py b/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py index b6f1f002..8eb66c79 100644 --- a/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py +++ b/test/k4FWCoreTest/options/TestUniqueIDGenSvc.py @@ -16,25 +16,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO from Configurables import UniqueIDGenSvc +from k4FWCore import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import TestUniqueIDGenSvc 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 2e088acf..ec050994 100644 --- a/test/k4FWCoreTest/options/TwoProducers.py +++ b/test/k4FWCoreTest/options/TwoProducers.py @@ -16,9 +16,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO -from Configurables import ApplicationMgr +from k4FWCore import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import k4FWCoreTest_CreateExampleEventData +from Configurables import PodioOutput ApplicationMgr( EvtSel="NONE", @@ -28,19 +31,14 @@ ) -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" @@ -49,7 +47,6 @@ producer2.vectorfloat.Path = "vectorfloat2" ApplicationMgr().TopAlg += [producer2] -from Configurables import PodioOutput out = PodioOutput("out") out.filename = "output_k4test_exampledata_twoproducer.root" diff --git a/test/k4FWCoreTest/options/checkExampleEventData.py b/test/k4FWCoreTest/options/checkExampleEventData.py index 9101ed64..36572d3e 100644 --- a/test/k4FWCoreTest/options/checkExampleEventData.py +++ b/test/k4FWCoreTest/options/checkExampleEventData.py @@ -17,17 +17,17 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO from Configurables import k4DataSvc +from Configurables import PodioInput +from k4FWCore.parseArgs import parser +from Configurables import k4FWCoreTest_CheckExampleEventData +from k4FWCore import ApplicationMgr podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata.root" -from Configurables import PodioInput - -from k4FWCore.parseArgs import parser - parser.add_argument( "--collections", action="extend", @@ -40,12 +40,9 @@ inp = PodioInput() inp.collections = my_args.collections -from Configurables import k4FWCoreTest_CheckExampleEventData checker = k4FWCoreTest_CheckExampleEventData() -from Configurables import ApplicationMgr - ApplicationMgr( TopAlg=[inp, checker], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/createEventHeader.py b/test/k4FWCoreTest/options/createEventHeader.py index 66c84046..b9d74e57 100644 --- a/test/k4FWCoreTest/options/createEventHeader.py +++ b/test/k4FWCoreTest/options/createEventHeader.py @@ -19,21 +19,21 @@ from Gaudi.Configuration import * from Configurables import EventHeaderCreator +from Configurables import k4DataSvc +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr eventHeaderCreator = EventHeaderCreator( "eventHeaderCreator", runNumber=42, eventNumberOffset=42, OutputLevel=DEBUG ) -from Configurables import k4DataSvc podioevent = k4DataSvc("EventDataSvc") -from Configurables import PodioOutput out = PodioOutput("out") out.filename = "eventHeader.root" -from Configurables import ApplicationMgr ApplicationMgr( TopAlg=[ diff --git a/test/k4FWCoreTest/options/createExampleEventData.py b/test/k4FWCoreTest/options/createExampleEventData.py index c71dc2ae..fe4e10fa 100644 --- a/test/k4FWCoreTest/options/createExampleEventData.py +++ b/test/k4FWCoreTest/options/createExampleEventData.py @@ -16,23 +16,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO from Configurables import k4DataSvc +from Configurables import k4FWCoreTest_CreateExampleEventData +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr 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], diff --git a/test/k4FWCoreTest/options/createExampleEventDataInDirectory.py b/test/k4FWCoreTest/options/createExampleEventDataInDirectory.py index 1d1e06a8..691f55fa 100644 --- a/test/k4FWCoreTest/options/createExampleEventDataInDirectory.py +++ b/test/k4FWCoreTest/options/createExampleEventDataInDirectory.py @@ -17,7 +17,7 @@ # limitations under the License. # from Gaudi.Configuration import INFO -from Configurables import ApplicationMgr +from k4FWCore import ApplicationMgr from Configurables import k4FWCoreTest_CreateExampleEventData from Configurables import k4DataSvc from Configurables import PodioOutput diff --git a/test/k4FWCoreTest/options/createExampleEventData_cellID.py b/test/k4FWCoreTest/options/createExampleEventData_cellID.py index 9a189e4b..f4c46f3b 100644 --- a/test/k4FWCoreTest/options/createExampleEventData_cellID.py +++ b/test/k4FWCoreTest/options/createExampleEventData_cellID.py @@ -16,24 +16,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO from Configurables import k4DataSvc +from Configurables import k4FWCoreTest_cellID_writer, k4FWCoreTest_cellID_reader +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr 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], diff --git a/test/k4FWCoreTest/options/createHelloWorld.py b/test/k4FWCoreTest/options/createHelloWorld.py index cae9631c..e79998ca 100644 --- a/test/k4FWCoreTest/options/createHelloWorld.py +++ b/test/k4FWCoreTest/options/createHelloWorld.py @@ -16,21 +16,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO -from Configurables import ApplicationMgr +from k4FWCore import ApplicationMgr +from Configurables import k4FWCoreTest_HelloWorldAlg ApplicationMgr().EvtSel = "NONE" -ApplicationMgr().EvtMax = 1 +ApplicationMgr().EvtMax = 2 ApplicationMgr().OutputLevel = INFO -from Configurables import k4FWCoreTest_HelloWorldAlg producer = k4FWCoreTest_HelloWorldAlg("HelloWorldAlg1") producer.PerEventPrintMessage = "Hello World !" +print(ApplicationMgr()) ApplicationMgr().TopAlg += [producer] -from Configurables import k4FWCoreTest_HelloWorldAlg producer2 = k4FWCoreTest_HelloWorldAlg("HelloWorldAlg2") producer2.PerEventPrintMessage = "Hello World2 !" diff --git a/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py b/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py index 0057fd3b..6fd41518 100644 --- a/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py +++ b/test/k4FWCoreTest/options/readExampleDataFromNthEvent.py @@ -16,25 +16,25 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import DEBUG from Configurables import k4DataSvc +from Configurables import PodioInput +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr 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], diff --git a/test/k4FWCoreTest/options/readExampleEventData.py b/test/k4FWCoreTest/options/readExampleEventData.py index c4b95280..09bdb6df 100644 --- a/test/k4FWCoreTest/options/readExampleEventData.py +++ b/test/k4FWCoreTest/options/readExampleEventData.py @@ -16,25 +16,25 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Gaudi.Configuration import * +from Gaudi.Configuration import DEBUG from Configurables import k4DataSvc +from Configurables import PodioInput +from Configurables import PodioOutput +from k4FWCore import ApplicationMgr 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], diff --git a/test/k4FWCoreTest/options/runEventHeaderCheck.py b/test/k4FWCoreTest/options/runEventHeaderCheck.py index d15eefb3..b01ce34d 100644 --- a/test/k4FWCoreTest/options/runEventHeaderCheck.py +++ b/test/k4FWCoreTest/options/runEventHeaderCheck.py @@ -20,19 +20,17 @@ from Gaudi.Configuration import INFO from Configurables import ExampleEventHeaderConsumer -from k4FWCore import ApplicationMgr -from Configurables import EventDataSvc, IOSvc, Reader +from k4FWCore import ApplicationMgr, IOSvc +from Configurables import EventDataSvc svc = IOSvc("IOSvc") -svc.input = ["eventHeader.root"] +svc.Input = ["eventHeader.root"] # svc.CollectionNames = ['MCParticles'] -reader = Reader("Reader") - consumer = ExampleEventHeaderConsumer("EventHeaderCheck", runNumber=42, eventNumberOffset=42) ApplicationMgr( - TopAlg=[reader, consumer], + TopAlg=[consumer], EvtSel="NONE", EvtMax=-1, ExtSvc=[EventDataSvc("EventDataSvc")], diff --git a/test/k4FWCoreTest/options/runFunctionalMix.py b/test/k4FWCoreTest/options/runFunctionalMix.py index 0b819a7c..4daa5b6a 100644 --- a/test/k4FWCoreTest/options/runFunctionalMix.py +++ b/test/k4FWCoreTest/options/runFunctionalMix.py @@ -30,7 +30,7 @@ k4FWCoreTest_CreateExampleEventData, ) from Configurables import k4FWCoreTest_CheckExampleEventData -from Configurables import ApplicationMgr +from k4FWCore import ApplicationMgr from Configurables import k4DataSvc from Configurables import PodioInput, PodioOutput from k4FWCore.parseArgs import parser @@ -67,8 +67,8 @@ from k4FWCore import IOSvc, ApplicationMgr iosvc = IOSvc("IOSvc") - iosvc.input = "functional_producer_multiple.root" - iosvc.output = "functional_mix_iosvc.root" + iosvc.Input = "functional_producer_multiple.root" + iosvc.Output = "functional_mix_iosvc.root" # Check input with functional and old algorithms @@ -149,12 +149,12 @@ # Check we can read input consumer_input_functional, consumer_input_algorithm, - producer_functional, # Check we can read what's produced by a functional + producer_functional, consumer_producerfun_functional, consumer_producerfun_algorithm, - producer_algorithm, # Check we can read what's produced by an algorithm + producer_algorithm, consumer_produceralg_functional, consumer_produceralg_algorithm, transformer_functional,