From c96825eb7053d919403bad59a014053d383043d9 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 25 Jul 2024 20:55:26 +0200 Subject: [PATCH 01/22] Add a metadata service and a test --- k4FWCore/components/IMetadataSvc.h | 51 +++++++++++++++++ k4FWCore/components/IOSvc.cpp | 18 ++++++ k4FWCore/components/IOSvc.h | 2 + k4FWCore/components/MetadataSvc.cpp | 53 ++++++++++++++++++ k4FWCore/components/MetadataSvc.h | 47 ++++++++++++++++ k4FWCore/components/Writer.cpp | 14 +++++ k4FWCore/include/k4FWCore/IMetadataSvc.h | 56 +++++++++++++++++++ k4FWCore/include/k4FWCore/MetadataUtils.h | 51 +++++++++++++++++ python/k4FWCore/ApplicationMgr.py | 4 +- python/k4FWCore/IOSvc.py | 3 +- test/k4FWCoreTest/CMakeLists.txt | 5 +- test/k4FWCoreTest/options/CheckOutputFiles.py | 9 +++ 12 files changed, 308 insertions(+), 5 deletions(-) create mode 100644 k4FWCore/components/IMetadataSvc.h create mode 100644 k4FWCore/components/MetadataSvc.cpp create mode 100644 k4FWCore/components/MetadataSvc.h create mode 100644 k4FWCore/include/k4FWCore/IMetadataSvc.h create mode 100644 k4FWCore/include/k4FWCore/MetadataUtils.h diff --git a/k4FWCore/components/IMetadataSvc.h b/k4FWCore/components/IMetadataSvc.h new file mode 100644 index 00000000..b7db701e --- /dev/null +++ b/k4FWCore/components/IMetadataSvc.h @@ -0,0 +1,51 @@ +/* + * 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. + */ +#ifndef FWCORE_IMETADATASERVICE_H +#define FWCORE_IMETADATASERVICE_H + +#include "GaudiKernel/IInterface.h" + +#include "podio/Frame.h" + +/** + * The interface implemented by any class making IO and reading RawEvent Data + */ +class IMetadataSvc : virtual public IInterface { +public: + /// InterfaceID + DeclareInterfaceID(IMetadataSvc, 1, 0); + + /** + * @brief Read the next event from the input file + * @return A tuple containing the collections read, the collection names and the frame that owns the collections + */ + + std::unique_ptr m_frame{nullptr}; + + virtual void setFrame(podio::Frame&& fr) = 0; + template void put(const std::string& name, const T& obj) { + if (!m_frame) { + m_frame.reset(new podio::Frame()); + } + m_frame->putParameter(name, obj); + } + template T get(const std::string& name) { return m_frame->getParameter(name); } +}; + +#endif diff --git a/k4FWCore/components/IOSvc.cpp b/k4FWCore/components/IOSvc.cpp index 0a92a560..6efded63 100644 --- a/k4FWCore/components/IOSvc.cpp +++ b/k4FWCore/components/IOSvc.cpp @@ -28,6 +28,7 @@ #include "GaudiKernel/AnyDataWrapper.h" #include "GaudiKernel/IEventProcessor.h" +#include #include #include @@ -63,6 +64,23 @@ StatusCode IOSvc::initialize() { return StatusCode::FAILURE; } + m_metadataSvc = service("MetadataSvc"); + if (!m_metadataSvc) { + error() << "Unable to locate the MetadataSvc" << endmsg; + return StatusCode::FAILURE; + } + if (m_reader) { + auto categories = m_reader->getAvailableCategories(); + if ( + // std::find(m_reader->getAvailableCategories().begin(), m_reader->getAvailableCategories().end(), + // podio::Category::Metadata) != m_reader->getAvailableCategories().end() && + std::find(categories.begin(), categories.end(), podio::Category::Metadata) != categories.end() && + m_reader->getEntries(podio::Category::Metadata) > 0) { + info() << "Setting metadata frame" << endmsg; + m_metadataSvc->setFrame(m_reader->readEntry(podio::Category::Metadata, 0)); + } + } + m_hiveWhiteBoard = service("EventDataSvc"); return StatusCode::SUCCESS; diff --git a/k4FWCore/components/IOSvc.h b/k4FWCore/components/IOSvc.h index b77025d1..5fef239d 100644 --- a/k4FWCore/components/IOSvc.h +++ b/k4FWCore/components/IOSvc.h @@ -31,6 +31,7 @@ #include "IIOSvc.h" #include "k4FWCore/KeepDropSwitch.h" +#include "k4FWCore/IMetadataSvc.h" #include #include @@ -85,6 +86,7 @@ class IOSvc : public extends { SmartIF m_dataSvc; SmartIF m_incidentSvc; SmartIF m_hiveWhiteBoard; + SmartIF m_metadataSvc; void handle(const Incident& incident) override; int m_entries{0}; diff --git a/k4FWCore/components/MetadataSvc.cpp b/k4FWCore/components/MetadataSvc.cpp new file mode 100644 index 00000000..36e195b4 --- /dev/null +++ b/k4FWCore/components/MetadataSvc.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "MetadataSvc.h" + +#include "podio/Frame.h" + +#include +#include +#include + +#include "podio/Frame.h" + +StatusCode MetadataSvc::initialize() { + StatusCode sc = Service::initialize(); + if (sc.isFailure()) { + error() << "Unable to initialize base class Service." << endmsg; + return sc; + } + m_dataSvc = service("EventDataSvc"); + if (!m_dataSvc) { + error() << "Unable to locate the EventDataSvc" << endmsg; + return StatusCode::FAILURE; + } + + m_frame.reset(new podio::Frame()); + + return StatusCode::SUCCESS; +} + +StatusCode MetadataSvc::finalize() { return Service::finalize(); } + +void MetadataSvc::setFrame(podio::Frame&& fr) { + m_frame.reset(new podio::Frame(std::move(fr))); +} + +DECLARE_COMPONENT(MetadataSvc) diff --git a/k4FWCore/components/MetadataSvc.h b/k4FWCore/components/MetadataSvc.h new file mode 100644 index 00000000..7c6aa14c --- /dev/null +++ b/k4FWCore/components/MetadataSvc.h @@ -0,0 +1,47 @@ +/* + * 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. + */ +#ifndef FWCORE_METADATASVC_H +#define FWCORE_METADATASVC_H + +#include "GaudiKernel/IDataProviderSvc.h" +#include "GaudiKernel/Service.h" + +#include "podio/Frame.h" + +#include "k4FWCore/IMetadataSvc.h" + +class MetadataSvc : public extends { + using extends::extends; + +public: + ~MetadataSvc() override = default; + + StatusCode initialize() override; + StatusCode finalize() override; + +protected: + + SmartIF m_dataSvc; + + std::unique_ptr m_frame; + + void setFrame(podio::Frame&& frame) override; +}; + +#endif diff --git a/k4FWCore/components/Writer.cpp b/k4FWCore/components/Writer.cpp index 38ae00e5..99976c15 100644 --- a/k4FWCore/components/Writer.cpp +++ b/k4FWCore/components/Writer.cpp @@ -30,6 +30,7 @@ #include "k4FWCore/DataWrapper.h" #include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/IMetadataSvc.h" #include #include @@ -53,6 +54,7 @@ class Writer final : public Gaudi::Functional::Consumer iosvc{this, "IOSvc", "IOSvc"}; SmartIF m_hiveWhiteBoard; SmartIF m_dataSvc; + SmartIF m_metadataSvc; mutable bool m_first{true}; StatusCode initialize() override { @@ -74,6 +76,12 @@ class Writer final : public Gaudi::Functional::ConsumergetWriter()->writeFrame(config_metadata_frame, "configuration_metadata"); + + if (m_metadataSvc->m_frame) { + iosvc->getWriter()->writeFrame(*std::move(m_metadataSvc->m_frame), podio::Category::Metadata); + } + iosvc->deleteWriter(); + return StatusCode::SUCCESS; } diff --git a/k4FWCore/include/k4FWCore/IMetadataSvc.h b/k4FWCore/include/k4FWCore/IMetadataSvc.h new file mode 100644 index 00000000..239d369d --- /dev/null +++ b/k4FWCore/include/k4FWCore/IMetadataSvc.h @@ -0,0 +1,56 @@ +/* + * 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. + */ +#ifndef FWCORE_IMETADATASERVICE_H +#define FWCORE_IMETADATASERVICE_H + +#include "GaudiKernel/IInterface.h" + +#include "podio/Frame.h" + +/** + * The interface implemented by any class making IO and reading RawEvent Data + */ +class IMetadataSvc : virtual public IInterface { + +public: + /// InterfaceID + DeclareInterfaceID(IMetadataSvc, 1, 0); + + /** + * @brief Read the next event from the input file + * @return A tuple containing the collections read, the collection names and the frame that owns the collections + */ + + std::unique_ptr m_frame; + + virtual void setFrame(podio::Frame&& fr) = 0; + template + void put(const std::string& name, const T& obj) { + if (!m_frame) { + m_frame.reset(new podio::Frame()); + } + m_frame->putParameter(name, obj); + } + template + std::optional get(const std::string& name) { + return m_frame->getParameter(name); + } +}; + +#endif diff --git a/k4FWCore/include/k4FWCore/MetadataUtils.h b/k4FWCore/include/k4FWCore/MetadataUtils.h new file mode 100644 index 00000000..d0447b6e --- /dev/null +++ b/k4FWCore/include/k4FWCore/MetadataUtils.h @@ -0,0 +1,51 @@ +/* + * 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. + */ +#ifndef FWCORE_METADATAUTILS_H +#define FWCORE_METADATAUTILS_H + +#include +#include "Gaudi/Algorithm.h" + +#include "k4FWCore/IMetadataSvc.h" + +// #include "GaudiKernel/CommonMessaging.h" + +namespace k4FWCore { + + template + void putParameter(const std::string& name, const T& value, const Gaudi::Algorithm* alg) { + auto metadataSvc = alg->service("MetadataSvc", false); + if (!metadataSvc) { + alg->error() << "MetadataSvc not found" << endmsg; + return; + } + metadataSvc->put(name, value); + } + template + std::optional getParameter(const std::string& name, const Gaudi::Algorithm* alg) { + auto metadataSvc = alg->service("MetadataSvc", false); + if (!metadataSvc) { + alg->error() << "MetadataSvc not found" << endmsg; + return std::nullopt; + } + return metadataSvc->get(name); + } +} // namespace k4FWCore + +#endif // CORE_FUNCTIONALUTILS_H diff --git a/python/k4FWCore/ApplicationMgr.py b/python/k4FWCore/ApplicationMgr.py index 8c5dc2f3..06f2a499 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, Gaudi__Sequencer +from Configurables import Reader, Writer, IOSvc, MetadataSvc, Gaudi__Sequencer import os from podio.root_io import Reader as PodioReader @@ -39,6 +39,8 @@ def __init__(self, **kwargs): self._mgr = AppMgr(**kwargs) for conf in frozenset(self._mgr.allConfigurables.values()): + if isinstance(conf, MetadataSvc): + self._mgr.ExtSvc.append(conf) if not isinstance(conf, IOSvc): continue props = conf.getPropertiesWithDescription() diff --git a/python/k4FWCore/IOSvc.py b/python/k4FWCore/IOSvc.py index edae89fb..86786991 100644 --- a/python/k4FWCore/IOSvc.py +++ b/python/k4FWCore/IOSvc.py @@ -16,13 +16,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from Configurables import IOSvc as IO +from Configurables import IOSvc as IO, MetadataSvc import os class IOSvc: def __init__(self, *args, **kwargs): self._svc = IO(**kwargs) + MetadataSvc("MetadataSvc") def __getattr__(self, attr): return getattr(self._svc, attr) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index f31e5ede..d084a308 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -135,9 +135,8 @@ add_test_with_env(FunctionalTransformerRuntimeCollectionsMultiple options/Exampl add_test_with_env(FunctionalTransformerHist options/ExampleFunctionalTransformerHist.py) add_test_with_env(FunctionalCollectionMerger options/ExampleFunctionalCollectionMerger.py) add_test_with_env(FunctionalFilterFile options/ExampleFunctionalFilterFile.py) - -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") +add_test_with_env(FunctionalMetadata options/ExampleFunctionalMetadata.py) +set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata") # Do this after checking the files not to overwrite them add_test_with_env(FunctionalFile_toolong options/ExampleFunctionalFile.py -n 999 PROPERTIES DEPENDS FunctionalCheckFiles PASS_REGULAR_EXPRESSION diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 2c6937db..c9ddcc21 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -154,3 +154,12 @@ def check_events(filename, number): "functional_filter.root", 5, ) + +reader = podio.root_io.Reader("functional_metadata.root") +metadata = reader.get("metadata")[0] +for key, value in zip( + ["NumberOfParticles", "ParticleTime", "PDGValues", "MetadataString"], + [3, 1.5, [1, 2, 3, 4], "hello"], +): + if metadata.get_parameter(key) != value: + raise RuntimeError(f"Metadata parameter {key} does not match expected value") From 08fdf9166ffe829bdf593f57a1589298183ca8bb Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 21:58:31 +0200 Subject: [PATCH 02/22] Fix pre-commit --- k4FWCore/components/IOSvc.h | 2 +- k4FWCore/components/MetadataSvc.h | 1 - k4FWCore/include/k4FWCore/MetadataUtils.h | 30 +++++++++++------------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/k4FWCore/components/IOSvc.h b/k4FWCore/components/IOSvc.h index 5fef239d..fe23352e 100644 --- a/k4FWCore/components/IOSvc.h +++ b/k4FWCore/components/IOSvc.h @@ -30,8 +30,8 @@ #include "podio/ROOTWriter.h" #include "IIOSvc.h" -#include "k4FWCore/KeepDropSwitch.h" #include "k4FWCore/IMetadataSvc.h" +#include "k4FWCore/KeepDropSwitch.h" #include #include diff --git a/k4FWCore/components/MetadataSvc.h b/k4FWCore/components/MetadataSvc.h index 7c6aa14c..97fa5e92 100644 --- a/k4FWCore/components/MetadataSvc.h +++ b/k4FWCore/components/MetadataSvc.h @@ -36,7 +36,6 @@ class MetadataSvc : public extends { StatusCode finalize() override; protected: - SmartIF m_dataSvc; std::unique_ptr m_frame; diff --git a/k4FWCore/include/k4FWCore/MetadataUtils.h b/k4FWCore/include/k4FWCore/MetadataUtils.h index d0447b6e..a434cc9d 100644 --- a/k4FWCore/include/k4FWCore/MetadataUtils.h +++ b/k4FWCore/include/k4FWCore/MetadataUtils.h @@ -28,24 +28,22 @@ namespace k4FWCore { - template - void putParameter(const std::string& name, const T& value, const Gaudi::Algorithm* alg) { - auto metadataSvc = alg->service("MetadataSvc", false); - if (!metadataSvc) { - alg->error() << "MetadataSvc not found" << endmsg; - return; - } - metadataSvc->put(name, value); + template void putParameter(const std::string& name, const T& value, const Gaudi::Algorithm* alg) { + auto metadataSvc = alg->service("MetadataSvc", false); + if (!metadataSvc) { + alg->error() << "MetadataSvc not found" << endmsg; + return; } - template - std::optional getParameter(const std::string& name, const Gaudi::Algorithm* alg) { - auto metadataSvc = alg->service("MetadataSvc", false); - if (!metadataSvc) { - alg->error() << "MetadataSvc not found" << endmsg; - return std::nullopt; - } - return metadataSvc->get(name); + metadataSvc->put(name, value); + } + template std::optional getParameter(const std::string& name, const Gaudi::Algorithm* alg) { + auto metadataSvc = alg->service("MetadataSvc", false); + if (!metadataSvc) { + alg->error() << "MetadataSvc not found" << endmsg; + return std::nullopt; } + return metadataSvc->get(name); + } } // namespace k4FWCore #endif // CORE_FUNCTIONALUTILS_H From 4e8fee2b80671b0ff500a27294b609cb28e12f87 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 22:02:49 +0200 Subject: [PATCH 03/22] Add missing files --- .../options/ExampleFunctionalMetadata.py | 42 ++++++++++ .../ExampleFunctionalMetadataConsumer.cpp | 84 +++++++++++++++++++ .../ExampleFunctionalMetadataProducer.cpp | 60 +++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 test/k4FWCoreTest/options/ExampleFunctionalMetadata.py create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py new file mode 100644 index 00000000..12d2868d --- /dev/null +++ b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py @@ -0,0 +1,42 @@ +# +# 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 producing metadata + +from Gaudi.Configuration import INFO +from Configurables import ( + ExampleFunctionalMetadataProducer, + ExampleFunctionalMetadataConsumer, +) +from k4FWCore import ApplicationMgr, IOSvc +from Configurables import EventDataSvc + +iosvc = IOSvc() +iosvc.output = "functional_metadata.root" + +producer = ExampleFunctionalMetadataProducer("Producer", OutputCollection=["MCParticles"]) +consumer = ExampleFunctionalMetadataConsumer("Consumer", InputCollection=["MCParticles"]) + +ApplicationMgr( + TopAlg=[producer, consumer], + + EvtMax=10, + ExtSvc=[EventDataSvc("EventDataSvc")], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp new file mode 100644 index 00000000..81e1e47f --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -0,0 +1,84 @@ +/* + * 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. + */ + +#include "edm4hep/MCParticleCollection.h" + +#include "k4FWCore/Consumer.h" +#include "k4FWCore/MetadataUtils.h" + +#include +#include + +struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer { + ExampleFunctionalMetadataConsumer(const std::string& name, ISvcLocator* svcLoc) + : Consumer(name, svcLoc, KeyValues("InputCollection", {"MCParticles"})) {} + + StatusCode initialize() override { + m_particleNum = k4FWCore::getParameter("NumberOfParticles", this).value_or(0); + if (m_particleNum != 3) { + error() << "ExampleInt is not 3" << endmsg; + return StatusCode::FAILURE; + } + + m_particleTime = k4FWCore::getParameter("ParticleTime", this).value_or(0); + if (m_particleTime != 1.5) { + error() << "ExampleFloat is not 1.5" << endmsg; + return StatusCode::FAILURE; + } + m_PDGValues = k4FWCore::getParameter>("PDGValues", this).value_or(std::vector{}); + if (m_PDGValues != std::vector{1, 2, 3, 4}) { + error() << "ExampleVector is not {1, 2, 3, 4}" << endmsg; + return StatusCode::FAILURE; + } + m_metadataString = k4FWCore::getParameter("MetadataString", this).value_or(""); + if (m_metadataString != "hello") { + error() << "ExampleString is not 'hello'" << endmsg; + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; + } + + void operator()(const edm4hep::MCParticleCollection& input) const override { + if (input.size() != m_particleNum) { + error() << "Input MCParticleCollection size is not " << m_particleNum << endmsg; + return; + } + int i = 0; + for (const auto& particle : input) { + if (particle.getTime() != m_particleTime) { + error() << "Particle time is not " << m_particleTime << endmsg; + return; + } + if (particle.getPDG() != m_PDGValues[i]) { + error() << "Particle PDG is not " << m_PDGValues[i] << endmsg; + return; + } + ++i; + } + + } + +private: + int m_particleNum; + float m_particleTime; + std::string m_metadataString; + std::vector m_PDGValues; +}; + +DECLARE_COMPONENT(ExampleFunctionalMetadataConsumer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp new file mode 100644 index 00000000..4c4c19e3 --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#include "Gaudi/Property.h" + +#include "edm4hep/MCParticleCollection.h" + +#include "k4FWCore/MetadataUtils.h" +#include "k4FWCore/Producer.h" + +#include +#include + +struct ExampleFunctionalMetadataProducer final : k4FWCore::Producer { + ExampleFunctionalMetadataProducer(const std::string& name, ISvcLocator* svcLoc) + : Producer(name, svcLoc, {}, KeyValues("OutputCollection", {"MCParticles"})) {} + + StatusCode initialize() override { + k4FWCore::putParameter("NumberOfParticles", m_particleNum.value(), this); + k4FWCore::putParameter("ParticleTime", m_particleTime.value(), this); + k4FWCore::putParameter("PDGValues", m_PDGValues.value(), this); + k4FWCore::putParameter("MetadataString", m_metadataString.value(), this); + return StatusCode::SUCCESS; + } + + edm4hep::MCParticleCollection operator()() const override { + auto coll = edm4hep::MCParticleCollection(); + for (int i = 0; i < m_particleNum.value(); ++i) { + auto particle = coll.create(); + particle.setPDG(m_PDGValues.value()[i]); + particle.setTime(m_particleTime.value()); + } + return coll; + } + +private: + Gaudi::Property m_particleNum{this, "NumberOfParticles", 3, "How many particles will be produced"}; + Gaudi::Property m_particleTime{this, "ParticleTime", 1.5, "Which time will be set for the particles"}; + Gaudi::Property m_metadataString{this, "MetadataString", "hello", "Example of a string"}; + Gaudi::Property> m_PDGValues{ + this, "PDGValues", {1, 2, 3, 4}, "Values of the PDG used for the particles"}; +}; + +DECLARE_COMPONENT(ExampleFunctionalMetadataProducer) From 58bcb6309a55360312ad38d5003f15f133f24668 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 22:03:05 +0200 Subject: [PATCH 04/22] Fix pre-commit --- k4FWCore/components/MetadataSvc.cpp | 4 +--- k4FWCore/components/Writer.cpp | 1 - k4FWCore/include/k4FWCore/IMetadataSvc.h | 11 +++-------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/k4FWCore/components/MetadataSvc.cpp b/k4FWCore/components/MetadataSvc.cpp index 36e195b4..eb672ae4 100644 --- a/k4FWCore/components/MetadataSvc.cpp +++ b/k4FWCore/components/MetadataSvc.cpp @@ -46,8 +46,6 @@ StatusCode MetadataSvc::initialize() { StatusCode MetadataSvc::finalize() { return Service::finalize(); } -void MetadataSvc::setFrame(podio::Frame&& fr) { - m_frame.reset(new podio::Frame(std::move(fr))); -} +void MetadataSvc::setFrame(podio::Frame&& fr) { m_frame.reset(new podio::Frame(std::move(fr))); } DECLARE_COMPONENT(MetadataSvc) diff --git a/k4FWCore/components/Writer.cpp b/k4FWCore/components/Writer.cpp index 99976c15..bcf8fe37 100644 --- a/k4FWCore/components/Writer.cpp +++ b/k4FWCore/components/Writer.cpp @@ -121,7 +121,6 @@ class Writer final : public Gaudi::Functional::ConsumergetWriter()->writeFrame(config_metadata_frame, "configuration_metadata"); - if (m_metadataSvc->m_frame) { iosvc->getWriter()->writeFrame(*std::move(m_metadataSvc->m_frame), podio::Category::Metadata); } diff --git a/k4FWCore/include/k4FWCore/IMetadataSvc.h b/k4FWCore/include/k4FWCore/IMetadataSvc.h index 239d369d..03197672 100644 --- a/k4FWCore/include/k4FWCore/IMetadataSvc.h +++ b/k4FWCore/include/k4FWCore/IMetadataSvc.h @@ -27,7 +27,6 @@ * The interface implemented by any class making IO and reading RawEvent Data */ class IMetadataSvc : virtual public IInterface { - public: /// InterfaceID DeclareInterfaceID(IMetadataSvc, 1, 0); @@ -39,18 +38,14 @@ class IMetadataSvc : virtual public IInterface { std::unique_ptr m_frame; - virtual void setFrame(podio::Frame&& fr) = 0; - template - void put(const std::string& name, const T& obj) { + virtual void setFrame(podio::Frame&& fr) = 0; + template void put(const std::string& name, const T& obj) { if (!m_frame) { m_frame.reset(new podio::Frame()); } m_frame->putParameter(name, obj); } - template - std::optional get(const std::string& name) { - return m_frame->getParameter(name); - } + template std::optional get(const std::string& name) { return m_frame->getParameter(name); } }; #endif From 533f61839bf06b1efb1cc1a516e33e737a3969ac Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 22:03:54 +0200 Subject: [PATCH 05/22] Remove unnecessary file --- k4FWCore/components/IMetadataSvc.h | 51 ------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 k4FWCore/components/IMetadataSvc.h diff --git a/k4FWCore/components/IMetadataSvc.h b/k4FWCore/components/IMetadataSvc.h deleted file mode 100644 index b7db701e..00000000 --- a/k4FWCore/components/IMetadataSvc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - */ -#ifndef FWCORE_IMETADATASERVICE_H -#define FWCORE_IMETADATASERVICE_H - -#include "GaudiKernel/IInterface.h" - -#include "podio/Frame.h" - -/** - * The interface implemented by any class making IO and reading RawEvent Data - */ -class IMetadataSvc : virtual public IInterface { -public: - /// InterfaceID - DeclareInterfaceID(IMetadataSvc, 1, 0); - - /** - * @brief Read the next event from the input file - * @return A tuple containing the collections read, the collection names and the frame that owns the collections - */ - - std::unique_ptr m_frame{nullptr}; - - virtual void setFrame(podio::Frame&& fr) = 0; - template void put(const std::string& name, const T& obj) { - if (!m_frame) { - m_frame.reset(new podio::Frame()); - } - m_frame->putParameter(name, obj); - } - template T get(const std::string& name) { return m_frame->getParameter(name); } -}; - -#endif From 19d8a5ffbc8cba55bc5f4882edad4fddc90a2d18 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 22:09:44 +0200 Subject: [PATCH 06/22] Fix pre-commit --- .../src/components/ExampleFunctionalMetadataConsumer.cpp | 7 +++---- .../src/components/ExampleFunctionalMetadataProducer.cpp | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp index 81e1e47f..2e08cc7c 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -71,13 +71,12 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer m_PDGValues; }; diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp index 4c4c19e3..a8cb3c64 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp @@ -50,9 +50,9 @@ struct ExampleFunctionalMetadataProducer final : k4FWCore::Producer m_particleNum{this, "NumberOfParticles", 3, "How many particles will be produced"}; - Gaudi::Property m_particleTime{this, "ParticleTime", 1.5, "Which time will be set for the particles"}; - Gaudi::Property m_metadataString{this, "MetadataString", "hello", "Example of a string"}; + Gaudi::Property m_particleNum{this, "NumberOfParticles", 3, "How many particles will be produced"}; + Gaudi::Property m_particleTime{this, "ParticleTime", 1.5, "Which time will be set for the particles"}; + Gaudi::Property m_metadataString{this, "MetadataString", "hello", "Example of a string"}; Gaudi::Property> m_PDGValues{ this, "PDGValues", {1, 2, 3, 4}, "Values of the PDG used for the particles"}; }; From e836cc091b27c374bfc791be964eb639b400b897 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 23 Jul 2024 17:27:37 +0200 Subject: [PATCH 07/22] Remove a few outdated docstrings --- k4FWCore/include/k4FWCore/IMetadataSvc.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/k4FWCore/include/k4FWCore/IMetadataSvc.h b/k4FWCore/include/k4FWCore/IMetadataSvc.h index 03197672..cae69da5 100644 --- a/k4FWCore/include/k4FWCore/IMetadataSvc.h +++ b/k4FWCore/include/k4FWCore/IMetadataSvc.h @@ -23,19 +23,11 @@ #include "podio/Frame.h" -/** - * The interface implemented by any class making IO and reading RawEvent Data - */ class IMetadataSvc : virtual public IInterface { public: /// InterfaceID DeclareInterfaceID(IMetadataSvc, 1, 0); - /** - * @brief Read the next event from the input file - * @return A tuple containing the collections read, the collection names and the frame that owns the collections - */ - std::unique_ptr m_frame; virtual void setFrame(podio::Frame&& fr) = 0; From 5ac9723b59bfd8723127eddb0acb5c83de5be428 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 23 Jul 2024 17:34:01 +0200 Subject: [PATCH 08/22] Add an example showing how to get metadata in the main loop and in finalize() --- .../ExampleFunctionalMetadataConsumer.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp index 2e08cc7c..b22d270e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -55,8 +55,10 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("NumberOfParticles", this).value_or(-1); + if (input.size() != particleNum) { + error() << "Input MCParticleCollection size is not " << particleNum << endmsg; return; } int i = 0; @@ -73,6 +75,15 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("NumberOfParticles", this).value_or(-1); + if (particleNum != 3) { + error() << "Metadata parameter NumberOfParticles is not 3" << endmsg; + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; + } + private: int m_particleNum; float m_particleTime; From bc2b29c1037ae99a23298a6576d15df9ec07204c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 25 Jul 2024 20:56:26 +0200 Subject: [PATCH 09/22] Fix test files --- test/k4FWCoreTest/options/CheckOutputFiles.py | 7 +++++++ test/k4FWCoreTest/options/ExampleFunctionalMetadata.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index c9ddcc21..696da8f3 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -29,9 +29,13 @@ def check_collections(filename, names): print(f'Checking file "{filename}" for collections {names}') podio_reader = podio.root_io.Reader(filename) + if 'events' not in podio_reader.categories: + raise RuntimeError(f"File {filename} has no events") frames = podio_reader.get("events") if not len(frames) and len(names): print(f"File {filename} is empty but {names} are expected") + # Prevent a possible crash + del podio_reader raise RuntimeError("File is empty but should not be") for frame in frames: available = set(frame.getAvailableCollections()) @@ -155,6 +159,8 @@ def check_events(filename, number): 5, ) +check_collections("functional_metadata.root", ["MCParticles"]) + reader = podio.root_io.Reader("functional_metadata.root") metadata = reader.get("metadata")[0] for key, value in zip( @@ -163,3 +169,4 @@ def check_events(filename, number): ): if metadata.get_parameter(key) != value: raise RuntimeError(f"Metadata parameter {key} does not match expected value") + diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py index 12d2868d..95338819 100644 --- a/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py +++ b/test/k4FWCoreTest/options/ExampleFunctionalMetadata.py @@ -35,7 +35,7 @@ ApplicationMgr( TopAlg=[producer, consumer], - + EvtSel="NONE", EvtMax=10, ExtSvc=[EventDataSvc("EventDataSvc")], OutputLevel=INFO, From 339bd95aa3e1f4f3297d3242f395459dc2b19dea Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 23 Jul 2024 18:42:35 +0200 Subject: [PATCH 10/22] Produce metadata in the event and finalize() --- test/k4FWCoreTest/options/CheckOutputFiles.py | 4 ++-- .../ExampleFunctionalMetadataConsumer.cpp | 13 +++++++++++++ .../ExampleFunctionalMetadataProducer.cpp | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 696da8f3..1de4155a 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -164,8 +164,8 @@ def check_events(filename, number): reader = podio.root_io.Reader("functional_metadata.root") metadata = reader.get("metadata")[0] for key, value in zip( - ["NumberOfParticles", "ParticleTime", "PDGValues", "MetadataString"], - [3, 1.5, [1, 2, 3, 4], "hello"], + ["NumberOfParticles", "ParticleTime", "PDGValues", "MetadataString", "EventMetadataInt", "FinalizeMetadataInt"], + [3, 1.5, [1, 2, 3, 4], "hello", 5, 10], ): if metadata.get_parameter(key) != value: raise RuntimeError(f"Metadata parameter {key} does not match expected value") diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp index b22d270e..836a3dee 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -81,6 +81,19 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("EventMetadataInt", this).value_or(-1); + if (eventMetadataInt != 5) { + error() << "EventMetadataInt is not 5" << endmsg; + return StatusCode::FAILURE; + } + + auto finalizeMetadataInt = k4FWCore::getParameter("FinalizeMetadataInt", this).value_or(-1); + if (finalizeMetadataInt != 10) { + error() << "FinalizeMetadataInt is not 10" << endmsg; + return StatusCode::FAILURE; + } + return StatusCode::SUCCESS; } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp index a8cb3c64..eb1905b6 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp @@ -40,6 +40,7 @@ struct ExampleFunctionalMetadataProducer final : k4FWCore::Producer m_particleNum{this, "NumberOfParticles", 3, "How many particles will be produced"}; Gaudi::Property m_particleTime{this, "ParticleTime", 1.5, "Which time will be set for the particles"}; From decee20dea0541193db6f6e89ed9c21cffb74e1c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 23 Jul 2024 18:44:26 +0200 Subject: [PATCH 11/22] Fix pre-commit --- test/k4FWCoreTest/options/CheckOutputFiles.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 1de4155a..777546f1 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -29,7 +29,7 @@ def check_collections(filename, names): print(f'Checking file "{filename}" for collections {names}') podio_reader = podio.root_io.Reader(filename) - if 'events' not in podio_reader.categories: + if "events" not in podio_reader.categories: raise RuntimeError(f"File {filename} has no events") frames = podio_reader.get("events") if not len(frames) and len(names): @@ -164,9 +164,15 @@ def check_events(filename, number): reader = podio.root_io.Reader("functional_metadata.root") metadata = reader.get("metadata")[0] for key, value in zip( - ["NumberOfParticles", "ParticleTime", "PDGValues", "MetadataString", "EventMetadataInt", "FinalizeMetadataInt"], + [ + "NumberOfParticles", + "ParticleTime", + "PDGValues", + "MetadataString", + "EventMetadataInt", + "FinalizeMetadataInt", + ], [3, 1.5, [1, 2, 3, 4], "hello", 5, 10], ): if metadata.get_parameter(key) != value: raise RuntimeError(f"Metadata parameter {key} does not match expected value") - From f3a0ca5c79aa70b8ccfb44362849d0f75c4f1390 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Fri, 26 Jul 2024 15:55:02 +0200 Subject: [PATCH 12/22] Do not allow to put parameters during the event loop --- k4FWCore/include/k4FWCore/IMetadataSvc.h | 1 - test/k4FWCoreTest/CMakeLists.txt | 2 ++ test/k4FWCoreTest/options/CheckOutputFiles.py | 3 +-- .../components/ExampleFunctionalMetadataConsumer.cpp | 11 ++++++----- .../components/ExampleFunctionalMetadataProducer.cpp | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/k4FWCore/include/k4FWCore/IMetadataSvc.h b/k4FWCore/include/k4FWCore/IMetadataSvc.h index cae69da5..ac12dce1 100644 --- a/k4FWCore/include/k4FWCore/IMetadataSvc.h +++ b/k4FWCore/include/k4FWCore/IMetadataSvc.h @@ -25,7 +25,6 @@ class IMetadataSvc : virtual public IInterface { public: - /// InterfaceID DeclareInterfaceID(IMetadataSvc, 1, 0); std::unique_ptr m_frame; diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index d084a308..455353b2 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -136,6 +136,8 @@ add_test_with_env(FunctionalTransformerHist options/ExampleFunctionalTransformer add_test_with_env(FunctionalCollectionMerger options/ExampleFunctionalCollectionMerger.py) add_test_with_env(FunctionalFilterFile options/ExampleFunctionalFilterFile.py) add_test_with_env(FunctionalMetadata options/ExampleFunctionalMetadata.py) + +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") # Do this after checking the files not to overwrite them diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 777546f1..52783b61 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -169,10 +169,9 @@ def check_events(filename, number): "ParticleTime", "PDGValues", "MetadataString", - "EventMetadataInt", "FinalizeMetadataInt", ], - [3, 1.5, [1, 2, 3, 4], "hello", 5, 10], + [3, 1.5, [1, 2, 3, 4], "hello", 10], ): if metadata.get_parameter(key) != value: raise RuntimeError(f"Metadata parameter {key} does not match expected value") diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp index 836a3dee..c2cae5c6 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -82,11 +82,12 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("EventMetadataInt", this).value_or(-1); - if (eventMetadataInt != 5) { - error() << "EventMetadataInt is not 5" << endmsg; - return StatusCode::FAILURE; - } + // Putting parameters in the main loop fails + // auto eventMetadataInt = k4FWCore::getParameter("EventMetadataInt", this).value_or(-1); + // if (eventMetadataInt != 5) { + // error() << "EventMetadataInt is not 5" << endmsg; + // return StatusCode::FAILURE; + // } auto finalizeMetadataInt = k4FWCore::getParameter("FinalizeMetadataInt", this).value_or(-1); if (finalizeMetadataInt != 10) { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp index eb1905b6..d368f8fa 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataProducer.cpp @@ -40,7 +40,8 @@ struct ExampleFunctionalMetadataProducer final : k4FWCore::Producer Date: Wed, 7 Aug 2024 15:50:08 +0200 Subject: [PATCH 13/22] Improve comments and remove duplicated include --- k4FWCore/components/MetadataSvc.cpp | 2 -- .../ExampleFunctionalMetadataConsumer.cpp | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/k4FWCore/components/MetadataSvc.cpp b/k4FWCore/components/MetadataSvc.cpp index eb672ae4..9c0b82f5 100644 --- a/k4FWCore/components/MetadataSvc.cpp +++ b/k4FWCore/components/MetadataSvc.cpp @@ -25,8 +25,6 @@ #include #include -#include "podio/Frame.h" - StatusCode MetadataSvc::initialize() { StatusCode sc = Service::initialize(); if (sc.isFailure()) { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp index c2cae5c6..11bc49e4 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalMetadataConsumer.cpp @@ -32,23 +32,27 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("NumberOfParticles", this).value_or(0); if (m_particleNum != 3) { - error() << "ExampleInt is not 3" << endmsg; + error() << "NumberOfParticles expected to be 3 but is " << m_particleNum << endmsg; return StatusCode::FAILURE; } m_particleTime = k4FWCore::getParameter("ParticleTime", this).value_or(0); if (m_particleTime != 1.5) { - error() << "ExampleFloat is not 1.5" << endmsg; + error() << "ParticleTime expected to be 1.5 but is " << m_particleTime << endmsg; return StatusCode::FAILURE; } m_PDGValues = k4FWCore::getParameter>("PDGValues", this).value_or(std::vector{}); if (m_PDGValues != std::vector{1, 2, 3, 4}) { - error() << "ExampleVector is not {1, 2, 3, 4}" << endmsg; + error() << "PDGValues expected to be {1, 2, 3, 4} but is {"; + for (const auto& pdg : m_PDGValues) { + error() << pdg << ", "; + } + error() << "}" << endmsg; return StatusCode::FAILURE; } m_metadataString = k4FWCore::getParameter("MetadataString", this).value_or(""); if (m_metadataString != "hello") { - error() << "ExampleString is not 'hello'" << endmsg; + error() << "MetadataString expected to be 'hello' but is '" << m_metadataString << "'" << endmsg; return StatusCode::FAILURE; } return StatusCode::SUCCESS; @@ -64,11 +68,11 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("NumberOfParticles", this).value_or(-1); if (particleNum != 3) { - error() << "Metadata parameter NumberOfParticles is not 3" << endmsg; + error() << "NumberOfParticles expected to be 3 but is " << particleNum << endmsg; return StatusCode::FAILURE; } @@ -91,7 +95,7 @@ struct ExampleFunctionalMetadataConsumer final : k4FWCore::Consumer("FinalizeMetadataInt", this).value_or(-1); if (finalizeMetadataInt != 10) { - error() << "FinalizeMetadataInt is not 10" << endmsg; + error() << "FinalizeMetadataInt expected to be 10 but is " << finalizeMetadataInt << endmsg; return StatusCode::FAILURE; } From b9dcb2a62e070b1bfd2fa1350af9aa9f934e0dc8 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 11:37:12 +0200 Subject: [PATCH 14/22] Add docstrings for the metadata utility functions --- k4FWCore/include/k4FWCore/MetadataUtils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/k4FWCore/include/k4FWCore/MetadataUtils.h b/k4FWCore/include/k4FWCore/MetadataUtils.h index a434cc9d..dc2c3008 100644 --- a/k4FWCore/include/k4FWCore/MetadataUtils.h +++ b/k4FWCore/include/k4FWCore/MetadataUtils.h @@ -24,10 +24,12 @@ #include "k4FWCore/IMetadataSvc.h" -// #include "GaudiKernel/CommonMessaging.h" - namespace k4FWCore { + /// @brief Save a metadata parameter in the metadata frame + /// @param name The name of the parameter + /// @param value The value of the parameter + /// @param alg The algorithm that is saving the parameter, typically "this" template void putParameter(const std::string& name, const T& value, const Gaudi::Algorithm* alg) { auto metadataSvc = alg->service("MetadataSvc", false); if (!metadataSvc) { @@ -36,6 +38,10 @@ namespace k4FWCore { } metadataSvc->put(name, value); } + /// @brief Get a metadata parameter from the metadata frame + /// @param name The name of the parameter + /// @param alg The algorithm that is saving the parameter, typically "this" + /// @return std::optional The value of the parameter, if it exists or std::nullopt template std::optional getParameter(const std::string& name, const Gaudi::Algorithm* alg) { auto metadataSvc = alg->service("MetadataSvc", false); if (!metadataSvc) { From 8a5a885f3cc3f05f8414f6caf1deb07847867789 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 11:48:37 +0200 Subject: [PATCH 15/22] Fix include guard --- k4FWCore/include/k4FWCore/MetadataUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k4FWCore/include/k4FWCore/MetadataUtils.h b/k4FWCore/include/k4FWCore/MetadataUtils.h index dc2c3008..c6ef1111 100644 --- a/k4FWCore/include/k4FWCore/MetadataUtils.h +++ b/k4FWCore/include/k4FWCore/MetadataUtils.h @@ -52,4 +52,4 @@ namespace k4FWCore { } } // namespace k4FWCore -#endif // CORE_FUNCTIONALUTILS_H +#endif // FWCORE_METADATAUTILS_H From c862fba4840cffc6afa5de9a9b4c20e22aa27209 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 15:30:10 +0200 Subject: [PATCH 16/22] Make the new MetadataSvc compatible with DataHandle based algorithms --- k4FWCore/include/k4FWCore/MetaDataHandle.h | 43 ++++++++++++++----- k4FWCore/include/k4FWCore/MetadataUtils.h | 19 ++++++++ test/k4FWCoreTest/CMakeLists.txt | 3 +- test/k4FWCoreTest/options/CheckOutputFiles.py | 9 ++++ .../ExampleFunctionalMetadataOldAlgorithm.py | 42 ++++++++++++++++++ 5 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py diff --git a/k4FWCore/include/k4FWCore/MetaDataHandle.h b/k4FWCore/include/k4FWCore/MetaDataHandle.h index ced03f49..53c94635 100644 --- a/k4FWCore/include/k4FWCore/MetaDataHandle.h +++ b/k4FWCore/include/k4FWCore/MetaDataHandle.h @@ -19,6 +19,13 @@ #ifndef K4FWCORE_METADATAHANDLE_H #define K4FWCORE_METADATAHANDLE_H +#include +#include +#include +#include + +#include "MetadataUtils.h" +#include "k4FWCore/IMetadataSvc.h" #include "k4FWCore/PodioDataSvc.h" template class MetaDataHandle { @@ -95,10 +102,17 @@ template std::optional MetaDataHandle::get_optional() const { //--------------------------------------------------------------------------- template const T MetaDataHandle::get() const { - const auto maybeVal = get_optional(); - if (!maybeVal.has_value()) { - throw GaudiException("MetaDataHandle empty handle access", - "MetaDataHandle " + fullDescriptor() + " not (yet?) available", StatusCode::FAILURE); + std::optional maybeVal; + // DataHandle based algorithms + if (m_podio_data_service) { + maybeVal = get_optional(); + if (!maybeVal.has_value()) { + throw GaudiException("MetaDataHandle empty handle access", + "MetaDataHandle " + fullDescriptor() + " not (yet?) available", StatusCode::FAILURE); + } + // Functional algorithms + } else { + maybeVal = k4FWCore::getParameter(fullDescriptor()); } return maybeVal.value(); } @@ -115,13 +129,20 @@ template void MetaDataHandle::put(T value) { StatusCode::FAILURE); // check whether we are in the proper State // put is only allowed in the initalization - if (m_podio_data_service->targetFSMState() == Gaudi::StateMachine::RUNNING) { - throw GaudiException("MetaDataHandle policy violation", "Put cannot be used during the event loop", - StatusCode::FAILURE); + + std::string full_descriptor = fullDescriptor(); + // DataHandle based algorithms + if (m_podio_data_service) { + if (m_podio_data_service->targetFSMState() == Gaudi::StateMachine::RUNNING) { + throw GaudiException("MetaDataHandle policy violation", "Put cannot be used during the event loop", + StatusCode::FAILURE); + } + podio::Frame& frame = m_podio_data_service->getMetaDataFrame(); + frame.putParameter(full_descriptor, value); + // Functional algorithms + } else { + k4FWCore::putParameter(full_descriptor, value); } - std::string full_descriptor = fullDescriptor(); - podio::Frame& frame = m_podio_data_service->getMetaDataFrame(); - frame.putParameter(full_descriptor, value); } //--------------------------------------------------------------------------- @@ -145,7 +166,7 @@ template void MetaDataHandle::checkPodioDataSvc() { if (cmd.find("genconf") != std::string::npos) return; - if (nullptr == m_podio_data_service) { + if (!m_podio_data_service && !Gaudi::svcLocator()->service("MetadataSvc")) { std::cout << "ERROR: MetaDataHandles require the PodioDataSvc" << std::endl; } } diff --git a/k4FWCore/include/k4FWCore/MetadataUtils.h b/k4FWCore/include/k4FWCore/MetadataUtils.h index c6ef1111..2113773e 100644 --- a/k4FWCore/include/k4FWCore/MetadataUtils.h +++ b/k4FWCore/include/k4FWCore/MetadataUtils.h @@ -38,6 +38,16 @@ namespace k4FWCore { } metadataSvc->put(name, value); } + /// @brief Save a metadata parameter in the metadata frame. Overload for compatibility + /// with the MetadataHandle, don't use! + template void putParameter(const std::string& name, const T& value) { + auto metadataSvc = Gaudi::svcLocator()->service("MetadataSvc", false); + if (!metadataSvc) { + std::cout << "MetadataSvc not found" << std::endl; + return; + } + return metadataSvc->put(name, value); + } /// @brief Get a metadata parameter from the metadata frame /// @param name The name of the parameter /// @param alg The algorithm that is saving the parameter, typically "this" @@ -50,6 +60,15 @@ namespace k4FWCore { } return metadataSvc->get(name); } + /// @brief Get a metadata parameter from the metadata frame. Overload for compatibility + /// with the MetadataHandle, don't use! + template std::optional getParameter(const std::string& name) { + auto metadataSvc = Gaudi::svcLocator()->service("MetadataSvc", false); + if (!metadataSvc) { + return std::nullopt; + } + return metadataSvc->get(name); + } } // namespace k4FWCore #endif // FWCORE_METADATAUTILS_H diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 455353b2..8f18f36c 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -136,9 +136,10 @@ add_test_with_env(FunctionalTransformerHist options/ExampleFunctionalTransformer add_test_with_env(FunctionalCollectionMerger options/ExampleFunctionalCollectionMerger.py) 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(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") +set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataOldAlgorithm") # Do this after checking the files not to overwrite them add_test_with_env(FunctionalFile_toolong options/ExampleFunctionalFile.py -n 999 PROPERTIES DEPENDS FunctionalCheckFiles PASS_REGULAR_EXPRESSION diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 52783b61..20240d83 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -175,3 +175,12 @@ def check_events(filename, number): ): if metadata.get_parameter(key) != value: raise RuntimeError(f"Metadata parameter {key} does not match expected value") + +reader = podio.root_io.Reader("functional_metadata_old_algorithm.root") +metadata = reader.get("metadata")[0] +for key, value in zip( + ["SimTrackerHits__CellIDEncoding"], + ["M:3,S-1:3,I:9,J:9,K-1:6"], +): + if metadata.get_parameter(key) != value: + raise RuntimeError(f"Metadata parameter {key} does not match expected value") diff --git a/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py b/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py new file mode 100644 index 00000000..2cbda6a2 --- /dev/null +++ b/test/k4FWCoreTest/options/ExampleFunctionalMetadataOldAlgorithm.py @@ -0,0 +1,42 @@ +# +# 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. +# +from Gaudi.Configuration import INFO +from Configurables import k4FWCoreTest_cellID_writer, k4FWCoreTest_cellID_reader +from k4FWCore import ApplicationMgr, IOSvc + +iosvc = IOSvc() +iosvc.output = "functional_metadata_old_algorithm.root" + +producer = k4FWCoreTest_cellID_writer() +consumer = k4FWCoreTest_cellID_reader() + + +# out = PodioOutput("out") +# out.filename = "output_k4test_exampledata_cellid.root" +# out.outputCommands = ["keep *"] + + +ApplicationMgr( + TopAlg=[producer, consumer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[], + OutputLevel=INFO, + StopOnSignal=True, +) From be968875b82c6bba796876d2117958395a86f1df Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 16:26:26 +0200 Subject: [PATCH 17/22] Add a comment about a warning and remove another comment --- k4FWCore/components/IOSvc.cpp | 2 -- k4FWCore/include/k4FWCore/MetaDataHandle.h | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/k4FWCore/components/IOSvc.cpp b/k4FWCore/components/IOSvc.cpp index 6efded63..5743d590 100644 --- a/k4FWCore/components/IOSvc.cpp +++ b/k4FWCore/components/IOSvc.cpp @@ -72,8 +72,6 @@ StatusCode IOSvc::initialize() { if (m_reader) { auto categories = m_reader->getAvailableCategories(); if ( - // std::find(m_reader->getAvailableCategories().begin(), m_reader->getAvailableCategories().end(), - // podio::Category::Metadata) != m_reader->getAvailableCategories().end() && std::find(categories.begin(), categories.end(), podio::Category::Metadata) != categories.end() && m_reader->getEntries(podio::Category::Metadata) > 0) { info() << "Setting metadata frame" << endmsg; diff --git a/k4FWCore/include/k4FWCore/MetaDataHandle.h b/k4FWCore/include/k4FWCore/MetaDataHandle.h index 53c94635..48c9c861 100644 --- a/k4FWCore/include/k4FWCore/MetaDataHandle.h +++ b/k4FWCore/include/k4FWCore/MetaDataHandle.h @@ -166,8 +166,12 @@ template void MetaDataHandle::checkPodioDataSvc() { if (cmd.find("genconf") != std::string::npos) return; - if (!m_podio_data_service && !Gaudi::svcLocator()->service("MetadataSvc")) { - std::cout << "ERROR: MetaDataHandles require the PodioDataSvc" << std::endl; + // The proper check would be the following: + // if (!m_podio_data_service && !Gaudi::svcLocator()->service("MetadataSvc")) { + // However, it seems there is always a service called "MetadataSvc" from Gaudi, + // so the check will always pass + if (!m_podio_data_service) { + std::cout << "Warning: MetaDataHandles require the PodioDataSvc (ignore if using IOSvc)" << std::endl; } } From 6f5d88d636dbc950cd454b2efb1ac9b5147ecf43 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 16:29:43 +0200 Subject: [PATCH 18/22] Improve an error message --- test/k4FWCoreTest/options/CheckOutputFiles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 20240d83..702e93a7 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -174,7 +174,7 @@ def check_events(filename, number): [3, 1.5, [1, 2, 3, 4], "hello", 10], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match expected value") + raise RuntimeError(f"Metadata parameter {key} does not match the expected value {value}") reader = podio.root_io.Reader("functional_metadata_old_algorithm.root") metadata = reader.get("metadata")[0] @@ -183,4 +183,4 @@ def check_events(filename, number): ["M:3,S-1:3,I:9,J:9,K-1:6"], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match expected value") + raise RuntimeError(f"Metadata parameter {key} does not match the expected value {value}") From d5fa73816c244c4191f842d3efcb4f78e24a6e75 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 16:31:59 +0200 Subject: [PATCH 19/22] Improve error message --- test/k4FWCoreTest/options/CheckOutputFiles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index 702e93a7..ddf4834c 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -174,7 +174,7 @@ def check_events(filename, number): [3, 1.5, [1, 2, 3, 4], "hello", 10], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match the expected value {value}") + raise RuntimeError(f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}") reader = podio.root_io.Reader("functional_metadata_old_algorithm.root") metadata = reader.get("metadata")[0] @@ -183,4 +183,4 @@ def check_events(filename, number): ["M:3,S-1:3,I:9,J:9,K-1:6"], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match the expected value {value}") + raise RuntimeError(f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}") From 1fdcefc8e93b5c4a66c055f7965c0be7aaf14561 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 16:37:41 +0200 Subject: [PATCH 20/22] Fix pre-commit --- test/k4FWCoreTest/options/CheckOutputFiles.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/options/CheckOutputFiles.py b/test/k4FWCoreTest/options/CheckOutputFiles.py index ddf4834c..665c2562 100644 --- a/test/k4FWCoreTest/options/CheckOutputFiles.py +++ b/test/k4FWCoreTest/options/CheckOutputFiles.py @@ -174,7 +174,9 @@ def check_events(filename, number): [3, 1.5, [1, 2, 3, 4], "hello", 10], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}") + raise RuntimeError( + f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}" + ) reader = podio.root_io.Reader("functional_metadata_old_algorithm.root") metadata = reader.get("metadata")[0] @@ -183,4 +185,6 @@ def check_events(filename, number): ["M:3,S-1:3,I:9,J:9,K-1:6"], ): if metadata.get_parameter(key) != value: - raise RuntimeError(f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}") + raise RuntimeError( + f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}" + ) From 2054dd7d887454476f09be6f1ddb6a82cdd2ef48 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 16:50:08 +0200 Subject: [PATCH 21/22] Fix pre-commit --- k4FWCore/components/IOSvc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/k4FWCore/components/IOSvc.cpp b/k4FWCore/components/IOSvc.cpp index 5743d590..8bba0442 100644 --- a/k4FWCore/components/IOSvc.cpp +++ b/k4FWCore/components/IOSvc.cpp @@ -71,8 +71,7 @@ StatusCode IOSvc::initialize() { } if (m_reader) { auto categories = m_reader->getAvailableCategories(); - if ( - std::find(categories.begin(), categories.end(), podio::Category::Metadata) != categories.end() && + if (std::find(categories.begin(), categories.end(), podio::Category::Metadata) != categories.end() && m_reader->getEntries(podio::Category::Metadata) > 0) { info() << "Setting metadata frame" << endmsg; m_metadataSvc->setFrame(m_reader->readEntry(podio::Category::Metadata, 0)); From 315dc13a2800b52a8719e36ed39c14fde51257a1 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 8 Aug 2024 17:04:53 +0200 Subject: [PATCH 22/22] Remove a few unnecessary includes --- k4FWCore/include/k4FWCore/MetaDataHandle.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/k4FWCore/include/k4FWCore/MetaDataHandle.h b/k4FWCore/include/k4FWCore/MetaDataHandle.h index 48c9c861..be05fb9c 100644 --- a/k4FWCore/include/k4FWCore/MetaDataHandle.h +++ b/k4FWCore/include/k4FWCore/MetaDataHandle.h @@ -19,13 +19,9 @@ #ifndef K4FWCORE_METADATAHANDLE_H #define K4FWCORE_METADATAHANDLE_H -#include #include -#include -#include -#include "MetadataUtils.h" -#include "k4FWCore/IMetadataSvc.h" +#include "k4FWCore/MetadataUtils.h" #include "k4FWCore/PodioDataSvc.h" template class MetaDataHandle {