-
Notifications
You must be signed in to change notification settings - Fork 27
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
Use podio::Reader and podio::Writer with IOSvc #233
Changes from all commits
44d901e
eb62e1e
ff787ba
fa44370
1d08b9f
325721e
71ec32c
0430a5a
14cf9db
386197a
0ae6af4
7c68b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,14 @@ | |
|
||
#include "podio/Frame.h" | ||
#include "podio/FrameCategories.h" | ||
#include "podio/Reader.h" | ||
|
||
#include "k4FWCore/FunctionalUtils.h" | ||
#include "k4FWCore/KeepDropSwitch.h" | ||
|
||
#include "GaudiKernel/AnyDataWrapper.h" | ||
#include "GaudiKernel/IEventProcessor.h" | ||
|
||
#include <algorithm> | ||
#include <mutex> | ||
#include <tuple> | ||
|
||
|
@@ -42,6 +42,9 @@ StatusCode IOSvc::initialize() { | |
if (!m_importedFromk4FWCore) { | ||
error() << "Use 'from k4FWCore import IOSvc' instead of 'from Configurables import IOSvc' to access the service" | ||
<< endmsg; | ||
} | ||
if (m_outputType != "default" && m_outputType != "ROOT" && m_outputType != "RNTuple") { | ||
error() << "Unknown input type: " << m_outputType << ", expected ROOT, RNTuple or default" << endmsg; | ||
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The demand for writing EDM4hep files using SIO is quite low. If someone wants it we can add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be nice for some testing at some point, but I agree we can easily toggle this once it becomes necessary. |
||
return StatusCode::FAILURE; | ||
} | ||
|
||
|
@@ -50,15 +53,13 @@ StatusCode IOSvc::initialize() { | |
m_readingFileNames = m_readingFileNamesDeprecated; | ||
} | ||
if (!m_readingFileNames.empty()) { | ||
info() << m_readingFileNames.size() << " files to be read" << endmsg; | ||
m_reader = std::make_unique<podio::ROOTReader>(); | ||
try { | ||
m_reader->openFiles(m_readingFileNames); | ||
m_reader = podio::makeReader(m_readingFileNames.value()); | ||
} catch (std::runtime_error& e) { | ||
error() << "Error when opening files: " << e.what() << endmsg; | ||
return StatusCode::FAILURE; | ||
} | ||
m_entries = m_reader->getEntries(podio::Category::Event); | ||
m_entries = m_reader->getEvents(); | ||
} | ||
|
||
if ((m_entries && m_firstEventEntry >= m_entries) || m_firstEventEntry < 0) { | ||
|
@@ -97,7 +98,7 @@ StatusCode IOSvc::initialize() { | |
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)); | ||
m_metadataSvc->setFrame(m_reader->readFrame(podio::Category::Metadata, 0)); | ||
} | ||
} | ||
|
||
|
@@ -113,7 +114,7 @@ std::tuple<std::vector<std::shared_ptr<podio::CollectionBase>>, std::vector<std: | |
{ | ||
std::scoped_lock<std::mutex> lock(m_changeBufferLock); | ||
if (m_nextEntry < m_entries) { | ||
frame = podio::Frame(m_reader->readEntry(podio::Category::Event, m_nextEntry)); | ||
frame = podio::Frame(m_reader->readEvent(m_nextEntry)); | ||
} else { | ||
return std::make_tuple(std::vector<std::shared_ptr<podio::CollectionBase>>(), std::vector<std::string>(), | ||
std::move(frame)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# 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 using a producer with a single output and saving that to an RNTuple file | ||
|
||
from Gaudi.Configuration import INFO | ||
from Configurables import ExampleFunctionalProducer | ||
from Configurables import EventDataSvc | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
|
||
iosvc = IOSvc("IOSvc") | ||
iosvc.Output = "functional_producer_rntuple.root" | ||
iosvc.OutputType = "RNTuple" | ||
|
||
|
||
producer = ExampleFunctionalProducer("ExampleFunctionalProducer") | ||
|
||
ApplicationMgr( | ||
TopAlg=[producer], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[EventDataSvc("EventDataSvc")], | ||
OutputLevel=INFO, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# 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 algorithm to modify a TTree into an RNTuple | ||
# Don't use! There is already a converter in podio called | ||
# podio-ttree-to-rntuple | ||
# Running with k4run will add some extra configuration metadata to the file | ||
|
||
from Gaudi.Configuration import INFO | ||
from Configurables import EventDataSvc | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
|
||
iosvc = IOSvc("IOSvc") | ||
iosvc.Input = "functional_producer.root" | ||
iosvc.Output = "functional_producer_rntuple_converted.root" | ||
iosvc.OutputType = "RNTuple" | ||
|
||
ApplicationMgr( | ||
TopAlg=[], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[EventDataSvc("EventDataSvc")], | ||
OutputLevel=INFO, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be named differently now that they are no longer pointer backed? Something like
resetWriter|resetReader
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it doesn't matter but the reason why they are needed is because services in Gaudi are not deleted so making the connection would be easier in case one wants to look for the old issue where this is described in Gaudi and technically they are being deleted.