Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write the configuration_metadata at initialize() in the Writer #262

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions k4FWCore/components/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
return StatusCode::FAILURE;
}

return StatusCode::SUCCESS;
}

StatusCode finalize() override {
podio::Frame config_metadata_frame;

//// prepare job options metadata ///////////////////////
Expand All @@ -104,7 +100,7 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
}
// Some default components are not captured by the job option service
// and have to be traversed like this. Note that Gaudi!577 will improve this.
for (const auto* name : {"NTupleSvc"}) {
for (const auto* name : {"ApplicationMgr", "MessageSvc", "NTupleSvc"}) {
std::stringstream config_stream;
auto svc = service<IProperty>(name);
if (!svc.isValid())
Expand All @@ -121,6 +117,10 @@ class Writer final : public Gaudi::Functional::Consumer<void(const EventContext&
}
iosvc->getWriter().writeFrame(config_metadata_frame, "configuration_metadata");

return StatusCode::SUCCESS;
}

StatusCode finalize() override {
if (const auto* metadata_frame = m_metadataSvc->getFrame(); metadata_frame) {
iosvc->getWriter().writeFrame(*metadata_frame, podio::Category::Metadata);
}
Expand Down
2 changes: 1 addition & 1 deletion test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ add_test(NAME AlgorithmWithTFileCheckMyTFileOutput
set_property(TEST AlgorithmWithTFileCheckMyTFileOutput APPEND PROPERTY DEPENDS AlgorithmWithTFile)
set_test_env(AlgorithmWithTFileCheckMyTFileOutput)

add_test_with_env(CreateExampleEventData_cellID options/createExampleEventData_cellID.py)
add_test_with_env(CreateExampleEventData_cellID options/createExampleEventData_cellID.py ADD_TO_CHECK_FILES)
add_test_with_env(TwoProducers options/TwoProducers.py --filename output_k4fwcore_test_twoproducer.root
--magicNumberOffset.Producer2 12345 --Producer1.magicNumberOffset 54321)
add_test_with_env(CheckCommandLineArguments options/createHelloWorld.py --HelloWorldAlg1.PerEventPrintMessage TwasBrilligAndTheSlithyToves
Expand Down
13 changes: 12 additions & 1 deletion test/k4FWCoreTest/options/ExampleFunctionalMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@
iosvc = IOSvc()
iosvc.Output = "functional_metadata.root"

producer = ExampleFunctionalMetadataProducer("Producer", OutputCollection=["MCParticles"])
producer = ExampleFunctionalMetadataProducer(
"Producer",
intProp2=69,
floatProp2=2.71828,
doubleProp2=2.7182818,
stringProp2="Hello, World!",
vectorIntProp2=[1, 2, 3, 4],
vectorFloatProp2=[1.1, 2.2, 3.3, 4.4],
vectorDoubleProp2=[1.1, 2.2, 3.3, 4.4],
vectorStringProp2=["one", "two", "three", "four"],
OutputCollection=["MCParticles"],
)
consumer = ExampleFunctionalMetadataConsumer("Consumer", InputCollection=["MCParticles"])

ApplicationMgr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
iosvc = IOSvc()
iosvc.Output = "functional_metadata_old_algorithm.root"

producer = k4FWCoreTest_cellID_writer()
producer = k4FWCoreTest_cellID_writer(
"CellIDWriter",
intProp2=69,
floatProp2=2.71828,
doubleProp2=2.7182818,
stringProp2="Hello, World!",
vectorIntProp2=[1, 2, 3, 4],
vectorFloatProp2=[1.1, 2.2, 3.3, 4.4],
vectorDoubleProp2=[1.1, 2.2, 3.3, 4.4],
vectorStringProp2=["one", "two", "three", "four"],
)
consumer = k4FWCoreTest_cellID_reader()


Expand Down
12 changes: 11 additions & 1 deletion test/k4FWCoreTest/options/createExampleEventData_cellID.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@
podioevent = k4DataSvc("EventDataSvc")


producer = k4FWCoreTest_cellID_writer()
producer = k4FWCoreTest_cellID_writer(
"CellIDWriter",
intProp2=69,
floatProp2=2.71828,
doubleProp2=2.7182818,
stringProp2="Hello, World!",
vectorIntProp2=[1, 2, 3, 4],
vectorFloatProp2=[1.1, 2.2, 3.3, 4.4],
vectorDoubleProp2=[1.1, 2.2, 3.3, 4.4],
vectorStringProp2=["one", "two", "three", "four"],
)
consumer = k4FWCoreTest_cellID_reader()


Expand Down
44 changes: 44 additions & 0 deletions test/k4FWCoreTest/scripts/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,47 @@ def check_metadata(filename, expected_metadata):
"functional_transformer_cli_multiple.root": 20,
}.items():
check_events(name, events)


for i, filename in enumerate(
[
"output_k4test_exampledata_cellid.root",
"functional_metadata_old_algorithm.root",
"functional_metadata.root",
]
):
reader = podio.root_io.Reader(filename)
configuration_metadata = reader.get("configuration_metadata")[0].get_parameter(
"gaudiConfigOptions"
)
configuration_metadata = [elem.strip(" ,;\n") for elem in configuration_metadata]
configuration_metadata = {
elem.split("=")[0]: elem.split("=")[1] for elem in configuration_metadata
}

props_and_values = {
"intProp": '"42"',
"intProp2": '"69"',
"floatProp": '"3.14000"',
"floatProp2": '"2.71828"',
"doubleProp": '"3.1400000"',
"doubleProp2": '"2.7182818"',
"stringProp": "\"'Hello'\"",
"stringProp2": "\"'Hello, World!'\"",
"vectorIntProp": '"[ 1 , 2 , 3 ]"',
"vectorIntProp2": '"[ 1 , 2 , 3 , 4 ]"',
"vectorFloatProp": '"[ 1.10000 , 2.20000 , 3.30000 ]"',
"vectorFloatProp2": '"[ 1.10000 , 2.20000 , 3.30000 , 4.40000 ]"',
"vectorDoubleProp": '"[ 1.1000000 , 2.2000000 , 3.3000000 ]"',
"vectorDoubleProp2": '"[ 1.1000000 , 2.2000000 , 3.3000000 , 4.4000000 ]"',
"vectorStringProp": "\"[ 'one' , 'two' , 'three' ]\"",
"vectorStringProp2": "\"[ 'one' , 'two' , 'three' , 'four' ]\"",
}

alg_name = "CellIDWriter" if i < 2 else "Producer"
for prop, value in props_and_values.items():
print(prop, value)
if configuration_metadata[f"{alg_name}.{prop} "] != f" {value}":
raise RuntimeError(
f"Property {prop} has value {configuration_metadata[f'CellIDWriter.{prop} ']}, expected {value}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ struct ExampleFunctionalMetadataProducer final : k4FWCore::Producer<edm4hep::MCP
Gaudi::Property<std::string> m_metadataString{this, "MetadataString", "hello", "Example of a string"};
Gaudi::Property<std::vector<int>> m_PDGValues{
this, "PDGValues", {1, 2, 3, 4}, "Values of the PDG used for the particles"};

// Some properties for the configuration metadata
Gaudi::Property<int> m_intProp{this, "intProp", 42, "An integer property"};
Gaudi::Property<int> m_intProp2{this, "intProp2", 42, "An integer property"};
Gaudi::Property<float> m_floatProp{this, "floatProp", 3.14, "A float property"};
Gaudi::Property<float> m_floatProp2{this, "floatProp2", 3.14, "A float property"};
Gaudi::Property<double> m_doubleProp{this, "doubleProp", 3.14, "A double property"};
Gaudi::Property<double> m_doubleProp2{this, "doubleProp2", 3.14, "A double property"};
Gaudi::Property<std::string> m_stringProp{this, "stringProp", "Hello", "A string property"};
Gaudi::Property<std::string> m_stringProp2{this, "stringProp2", "Hello", "A string property"};
Gaudi::Property<std::vector<int>> m_vectorIntProp{this, "vectorIntProp", {1, 2, 3}, "A vector of integers"};
Gaudi::Property<std::vector<int>> m_vectorIntProp2{this, "vectorIntProp2", {1, 2, 3}, "A vector of integers"};
Gaudi::Property<std::vector<float>> m_vectorFloatProp{this, "vectorFloatProp", {1.1, 2.2, 3.3}, "A vector of floats"};
Gaudi::Property<std::vector<float>> m_vectorFloatProp2{
this, "vectorFloatProp2", {1.1, 2.2, 3.3}, "A vector of floats"};
Gaudi::Property<std::vector<double>> m_vectorDoubleProp{
this, "vectorDoubleProp", {1.1, 2.2, 3.3}, "A vector of doubles"};
Gaudi::Property<std::vector<double>> m_vectorDoubleProp2{
this, "vectorDoubleProp2", {1.1, 2.2, 3.3}, "A vector of doubles"};
Gaudi::Property<std::vector<std::string>> m_vectorStringProp{
this, "vectorStringProp", {"one", "two", "three"}, "A vector of strings"};
Gaudi::Property<std::vector<std::string>> m_vectorStringProp2{
this,
"vectorStringProp2",
{"one", "two", "three"},
};
};

DECLARE_COMPONENT(ExampleFunctionalMetadataProducer)
26 changes: 26 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,31 @@ class k4FWCoreTest_cellID_writer : public Gaudi::Algorithm {
Gaudi::DataHandle::Writer, this};
MetaDataHandle<std::string> m_cellIDHandle{m_simTrackerHitWriterHandle, edm4hep::labels::CellIDEncoding,
Gaudi::DataHandle::Writer};

// Some properties for the configuration metadata
Gaudi::Property<int> m_intProp{this, "intProp", 42, "An integer property"};
Gaudi::Property<int> m_intProp2{this, "intProp2", 42, "An integer property"};
Gaudi::Property<float> m_floatProp{this, "floatProp", 3.14, "A float property"};
Gaudi::Property<float> m_floatProp2{this, "floatProp2", 3.14, "A float property"};
Gaudi::Property<double> m_doubleProp{this, "doubleProp", 3.14, "A double property"};
Gaudi::Property<double> m_doubleProp2{this, "doubleProp2", 3.14, "A double property"};
Gaudi::Property<std::string> m_stringProp{this, "stringProp", "Hello", "A string property"};
Gaudi::Property<std::string> m_stringProp2{this, "stringProp2", "Hello", "A string property"};
Gaudi::Property<std::vector<int>> m_vectorIntProp{this, "vectorIntProp", {1, 2, 3}, "A vector of integers"};
Gaudi::Property<std::vector<int>> m_vectorIntProp2{this, "vectorIntProp2", {1, 2, 3}, "A vector of integers"};
Gaudi::Property<std::vector<float>> m_vectorFloatProp{this, "vectorFloatProp", {1.1, 2.2, 3.3}, "A vector of floats"};
Gaudi::Property<std::vector<float>> m_vectorFloatProp2{
this, "vectorFloatProp2", {1.1, 2.2, 3.3}, "A vector of floats"};
Gaudi::Property<std::vector<double>> m_vectorDoubleProp{
this, "vectorDoubleProp", {1.1, 2.2, 3.3}, "A vector of doubles"};
Gaudi::Property<std::vector<double>> m_vectorDoubleProp2{
this, "vectorDoubleProp2", {1.1, 2.2, 3.3}, "A vector of doubles"};
Gaudi::Property<std::vector<std::string>> m_vectorStringProp{
this, "vectorStringProp", {"one", "two", "three"}, "A vector of strings"};
Gaudi::Property<std::vector<std::string>> m_vectorStringProp2{
this,
"vectorStringProp2",
{"one", "two", "three"},
};
};
#endif /* K4FWCORE_K4FWCORETEST_CELLID_WRITER */
Loading