Skip to content

Commit f98acdf

Browse files
authored
Remove support for legacy I/O components (#475)
1 parent c8cf21e commit f98acdf

11 files changed

Lines changed: 124 additions & 301 deletions

File tree

k4MarlinWrapper/examples/clicRec_e4h_input.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121

2222
from Gaudi.Configuration import DEBUG, WARNING
2323

24-
from Configurables import MarlinProcessorWrapper
2524
from k4MarlinWrapper.parseConstants import parseConstants
2625

27-
from Configurables import Lcio2EDM4hepTool, EDM4hep2LcioTool
28-
from Configurables import k4DataSvc, PodioInput, PodioOutput, EventDataSvc
26+
from Configurables import (
27+
MarlinProcessorWrapper,
28+
Lcio2EDM4hepTool,
29+
EDM4hep2LcioTool,
30+
EventDataSvc,
31+
MetadataSvc,
32+
)
2933

3034
from k4FWCore import ApplicationMgr, IOSvc
3135
from k4FWCore.parseArgs import parser
@@ -39,12 +43,6 @@
3943

4044
parseConstants(CONSTANTS)
4145

42-
parser.add_argument(
43-
"--no-iosvc",
44-
action="store_true",
45-
default=False,
46-
help="Use k4DataSvc instead of IOSvc",
47-
)
4846
parser.add_argument(
4947
"--rec-output", default="Output_REC_e4h_input.slcio", help="Output file name for the REC file"
5048
)
@@ -54,27 +52,15 @@
5452
parser.add_argument(
5553
"--gaudi-output", default="my_output.root", help="Output file name for the Gaudi file"
5654
)
57-
5855
args = parser.parse_known_args()[0]
59-
if not args.no_iosvc:
60-
evtsvc = EventDataSvc("EventDataSvc")
61-
iosvc = IOSvc()
62-
iosvc.Input = os.path.join(
63-
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
64-
)
65-
iosvc.Output = args.gaudi_output
66-
iosvc.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]
67-
else:
68-
evtsvc = k4DataSvc("EventDataSvc")
69-
evtsvc.input = os.path.join(
70-
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
71-
)
72-
73-
inp = PodioInput("InputReader")
74-
inp.OutputLevel = DEBUG
75-
76-
out = PodioOutput("PodioOutput", filename=args.gaudi_output)
77-
out.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]
56+
57+
evtsvc = EventDataSvc("EventDataSvc")
58+
iosvc = IOSvc()
59+
iosvc.Input = os.path.join(
60+
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
61+
)
62+
iosvc.Output = args.gaudi_output
63+
iosvc.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]
7864

7965
MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor")
8066
MyAIDAProcessor.OutputLevel = WARNING
@@ -2504,7 +2490,6 @@
25042490
algList.append(Output_REC)
25052491
algList.append(Output_DST)
25062492

2507-
if args.no_iosvc:
2508-
algList = [inp] + algList + [out]
2509-
2510-
ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=3, ExtSvc=[evtsvc], OutputLevel=WARNING)
2493+
ApplicationMgr(
2494+
TopAlg=algList, EvtSel="NONE", EvtMax=3, ExtSvc=[evtsvc, MetadataSvc()], OutputLevel=WARNING
2495+
)

k4MarlinWrapper/k4MarlinWrapper/converters/EDM4hep2Lcio.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
#include <tuple>
3232
#include <vector>
3333

34-
class PodioDataSvc;
3534
class IDataProviderSvc;
36-
class IMetadataSvc;
3735

3836
template <typename K, typename V>
3937
using ObjMapT = k4EDM4hep2LcioConv::VecMapT<K, V>;
@@ -66,11 +64,7 @@ class EDM4hep2LcioTool : public AlgTool, virtual public IEDMConverter {
6664
Gaudi::Property<std::map<std::string, std::string>> m_collNames{this, "collNameMapping", {}};
6765
Gaudi::Property<bool> m_convertAll{this, "convertAll", true};
6866

69-
PodioDataSvc* m_podioDataSvc;
70-
// EventDataSvc that is used together with IOSvc
7167
ServiceHandle<IDataProviderSvc> m_eventDataSvc;
72-
// Metadata service from k4FWCore that is used together with IOSvc
73-
SmartIF<IMetadataSvc> m_metadataSvc;
7468
/// A (caching) "map" of original to new collection names that will be populated
7569
/// during the first conversion
7670
std::vector<std::tuple<std::string, std::string>> m_collsToConvert{};
@@ -121,8 +115,6 @@ class EDM4hep2LcioTool : public AlgTool, virtual public IEDMConverter {
121115
std::vector<EDM4hep2LCIOConv::ParticleIDConvData>& pidCollections,
122116
std::vector<EDM4hep2LCIOConv::TrackDqdxConvData>& dQdxCollections);
123117

124-
const podio::Frame& getEDM4hepEvent() const;
125-
126118
/// Get an EDM4hep collection by name, consulting either the podio based data
127119
/// svc or the IOSvc
128120
podio::CollectionBase* getEDM4hepCollection(const std::string& name, bool allowToFail = false) const;

k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <Gaudi/Property.h>
2323
#include <GaudiKernel/AlgTool.h>
2424

25-
#include "k4FWCore/IMetadataSvc.h"
26-
2725
#include "k4MarlinWrapper/converters/IEDMConverter.h"
2826

2927
#include <edm4hep/utils/ParticleIDUtils.h>
@@ -42,12 +40,10 @@ namespace EVENT {
4240
class LCCollection;
4341
}
4442

45-
class PodioDataSvc;
46-
4743
class Lcio2EDM4hepTool : public AlgTool, virtual public IEDMConverter {
4844
public:
4945
Lcio2EDM4hepTool(const std::string& type, const std::string& name, const IInterface* parent);
50-
StatusCode initialize() final;
46+
5147
StatusCode finalize() final;
5248

5349
// **********************************
@@ -63,8 +59,6 @@ class Lcio2EDM4hepTool : public AlgTool, virtual public IEDMConverter {
6359
Gaudi::Property<bool> m_convertAll{this, "convertAll", true};
6460

6561
ServiceHandle<IDataProviderSvc> m_eventDataSvc;
66-
SmartIF<IMetadataSvc> m_metadataSvc;
67-
PodioDataSvc* m_podioDataSvc;
6862

6963
std::map<std::string, std::string> m_cellIDEncodings{};
7064
std::map<std::string, edm4hep::utils::ParticleIDMeta> m_pidMetas{};

k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp

Lines changed: 28 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@
2626
#include "edm4hep/utils/ParticleIDUtils.h"
2727

2828
#include "k4FWCore/DataHandle.h"
29-
#include "k4FWCore/FunctionalUtils.h"
30-
#include "k4FWCore/MetaDataHandle.h"
31-
#include "k4FWCore/PodioDataSvc.h"
29+
#include <k4FWCore/MetadataUtils.h>
3230

3331
#include "GaudiKernel/AnyDataWrapper.h"
3432
#include "GaudiKernel/IDataManagerSvc.h"
3533
#include "GaudiKernel/IDataProviderSvc.h"
3634

37-
#include <functional>
3835
#include <memory>
3936

4037
DECLARE_COMPONENT(EDM4hep2LcioTool);
@@ -69,16 +66,6 @@ StatusCode EDM4hep2LcioTool::initialize() {
6966
return StatusCode::FAILURE;
7067
}
7168

72-
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(m_eventDataSvc.get());
73-
74-
if (!m_podioDataSvc) {
75-
m_metadataSvc = service("MetadataSvc", false);
76-
if (!m_metadataSvc) {
77-
error() << "Could not retrieve MetadataSvc" << endmsg;
78-
return StatusCode::FAILURE;
79-
}
80-
}
81-
8269
return AlgTool::initialize();
8370
}
8471

@@ -107,11 +94,10 @@ void EDM4hep2LcioTool::convertTrackerHits(TrackerHitMap& trackerhits_vec, const
10794
this};
10895
const auto trackerhits_coll = trackerhits_handle.get();
10996

110-
k4FWCore::MetaDataHandle<std::string> cellIDStrHandle{trackerhits_handle, edm4hep::labels::CellIDEncoding,
111-
Gaudi::DataHandle::Reader};
97+
const auto cellIDencoding = k4FWCore::getCellIDEncoding(trackerhits_handle.objKey(), this);
98+
debug() << "Retrieved CellID encoding: " << cellIDencoding.value_or("<not-present>") << endmsg;
11299

113-
auto conv_trackerhits =
114-
EDM4hep2LCIOConv::convertTrackerHits(trackerhits_coll, cellIDStrHandle.get(""), trackerhits_vec);
100+
auto conv_trackerhits = EDM4hep2LCIOConv::convertTrackerHits(trackerhits_coll, cellIDencoding, trackerhits_vec);
115101

116102
// Add all trackerhits to event
117103
lcio_event->addCollection(conv_trackerhits.release(), lcio_coll_name);
@@ -129,11 +115,10 @@ void EDM4hep2LcioTool::convertTrackerHitPlanes(TrackerHitPlaneMap& trackerhits_v
129115
this};
130116
const auto trackerhits_coll = trackerhits_handle.get();
131117

132-
k4FWCore::MetaDataHandle<std::string> cellIDStrHandle{trackerhits_handle, edm4hep::labels::CellIDEncoding,
133-
Gaudi::DataHandle::Reader};
118+
const auto cellIDencoding = k4FWCore::getCellIDEncoding(trackerhits_handle.objKey(), this);
119+
debug() << "Retrieved CellID encoding: " << cellIDencoding.value_or("<not-present>") << endmsg;
134120

135-
auto conv_trackerhits =
136-
EDM4hep2LCIOConv::convertTrackerHitPlanes(trackerhits_coll, cellIDStrHandle.get(""), trackerhits_vec);
121+
auto conv_trackerhits = EDM4hep2LCIOConv::convertTrackerHitPlanes(trackerhits_coll, cellIDencoding, trackerhits_vec);
137122

138123
// Add all trackerhits to event
139124
lcio_event->addCollection(conv_trackerhits.release(), lcio_coll_name);
@@ -148,12 +133,11 @@ void EDM4hep2LcioTool::convertSimTrackerHits(SimTrackerHitMap& simtrackerhits_ve
148133
this};
149134
const auto simtrackerhits_coll = simtrackerhits_handle.get();
150135

151-
k4FWCore::MetaDataHandle<std::string> cellIDHandle{simtrackerhits_handle, edm4hep::labels::CellIDEncoding,
152-
Gaudi::DataHandle::Reader};
153-
const auto cellIDstr = cellIDHandle.get();
136+
const auto cellIDencoding = k4FWCore::getCellIDEncoding(simtrackerhits_handle.objKey(), this);
137+
debug() << "Retrieved CellID encoding: " << cellIDencoding.value_or("<not-present>") << endmsg;
154138

155139
auto conv_simtrackerhits =
156-
EDM4hep2LCIOConv::convertSimTrackerHits(simtrackerhits_coll, cellIDstr, simtrackerhits_vec);
140+
EDM4hep2LCIOConv::convertSimTrackerHits(simtrackerhits_coll, cellIDencoding, simtrackerhits_vec);
157141

158142
// Add all simtrackerhits to event
159143
lcio_event->addCollection(conv_simtrackerhits.release(), lcio_coll_name);
@@ -168,11 +152,10 @@ void EDM4hep2LcioTool::convertCalorimeterHits(CaloHitMap& calo_hits_vec, const s
168152
this};
169153
const auto calohit_coll = calohit_handle.get();
170154

171-
k4FWCore::MetaDataHandle<std::string> cellIDHandle{calohit_handle, edm4hep::labels::CellIDEncoding,
172-
Gaudi::DataHandle::Reader};
173-
const auto cellIDstr = cellIDHandle.get();
155+
const auto cellIDencoding = k4FWCore::getCellIDEncoding(calohit_handle.objKey(), this);
156+
debug() << "Retrieved CellID encoding: " << cellIDencoding.value_or("<not-present>") << endmsg;
174157

175-
auto conv_calohits = EDM4hep2LCIOConv::convertCalorimeterHits(calohit_coll, cellIDstr, calo_hits_vec);
158+
auto conv_calohits = EDM4hep2LCIOConv::convertCalorimeterHits(calohit_coll, cellIDencoding, calo_hits_vec);
176159

177160
// Add all Calorimeter Hits to event
178161
lcio_event->addCollection(conv_calohits.release(), lcio_coll_name);
@@ -202,12 +185,12 @@ void EDM4hep2LcioTool::convertSimCalorimeterHits(SimCaloHitMap& sim_calo_hits_ve
202185
Gaudi::DataHandle::Reader, this};
203186
const auto simcalohit_coll = sim_calohit_handle.get();
204187

205-
k4FWCore::MetaDataHandle<std::string> cellIDHandle{sim_calohit_handle, edm4hep::labels::CellIDEncoding,
206-
Gaudi::DataHandle::Reader};
207-
const auto cellIDstr = cellIDHandle.get();
188+
const auto cellIDencoding = k4FWCore::getCellIDEncoding(sim_calohit_handle.objKey(), this);
189+
debug() << "Retrieved CellID encoding: " << cellIDencoding.value_or("<not-present>") << endmsg;
208190

209191
// TODO mcparticles_vdc
210-
auto conv_simcalohits = EDM4hep2LCIOConv::convertSimCalorimeterHits(simcalohit_coll, cellIDstr, sim_calo_hits_vec);
192+
auto conv_simcalohits =
193+
EDM4hep2LCIOConv::convertSimCalorimeterHits(simcalohit_coll, cellIDencoding, sim_calo_hits_vec);
211194

212195
// Add all Sim Calorimeter Hits to event
213196
lcio_event->addCollection(conv_simcalohits.release(), lcio_coll_name);
@@ -337,7 +320,6 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s
337320
lcio::LCEventImpl* lcio_event, CollectionPairMappings& collection_pairs,
338321
std::vector<EDM4hep2LCIOConv::ParticleIDConvData>& pidCollections,
339322
std::vector<EDM4hep2LCIOConv::TrackDqdxConvData>& dQdxCollections) {
340-
const auto& metadata = m_podioDataSvc->getMetaDataFrame();
341323
const auto collPtr = getEDM4hepCollection(e4h_coll_name);
342324
const auto fulltype = collPtr->getValueTypeName();
343325

@@ -370,13 +352,7 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s
370352
} else if (fulltype == "edm4hep::EventHeader") {
371353
convertEventHeader(e4h_coll_name, lcio_event);
372354
} else if (fulltype == "edm4hep::ParticleID") {
373-
std::optional<edm4hep::utils::ParticleIDMeta> pidInfo;
374-
if (m_podioDataSvc) {
375-
pidInfo = edm4hep::utils::PIDHandler::getAlgoInfo(metadata, e4h_coll_name);
376-
} else {
377-
pidInfo = m_metadataSvc->get<edm4hep::utils::ParticleIDMeta>(e4h_coll_name);
378-
}
379-
355+
const auto pidInfo = k4FWCore::getParameter<edm4hep::utils::ParticleIDMeta>(e4h_coll_name, this);
380356
pidCollections.emplace_back(e4h_coll_name, static_cast<const edm4hep::ParticleIDCollection*>(collPtr), pidInfo);
381357
} else if (fulltype == "edm4hep::RecDqDx") {
382358
dQdxCollections.emplace_back(e4h_coll_name, static_cast<const edm4hep::RecDqdxCollection*>(collPtr));
@@ -395,45 +371,10 @@ void EDM4hep2LcioTool::convertAdd(const std::string& e4h_coll_name, const std::s
395371
}
396372
}
397373

398-
const podio::Frame& EDM4hep2LcioTool::getEDM4hepEvent() const {
399-
debug() << "Retrieving EDM4hep event (Frame)" << endmsg;
400-
if (m_podioDataSvc) {
401-
debug() << "Getting it from PodioDataSvc" << endmsg;
402-
return m_podioDataSvc->getEventFrame();
403-
} else {
404-
debug() << "Trying to get it from TES" << endmsg;
405-
DataObject* p;
406-
StatusCode code = m_eventDataSvc->retrieveObject("/Event" + k4FWCore::frameLocation, p);
407-
if (code.isSuccess()) {
408-
auto* frame = dynamic_cast<AnyDataWrapper<podio::Frame>*>(p);
409-
return frame->getData();
410-
}
411-
}
412-
413-
// We can do this because the following assumptions are true:
414-
// - We only end up here if we are using the IOSvc and we are NOT reading
415-
// EDM4hep data. Otherwise the Reader will be scheduled as FIRST algorithm,
416-
// most importantly BEFORE any of the wrapped Marlin processors to which
417-
// this converter is attached.
418-
// - The empty Frame we introduce into the TES here does not interfere with
419-
// the Writer for EDM4hep output (which is always scheduled last), as that
420-
// will simply get this Frame instead of creating an empty one itself
421-
// - There are no scheduling issues / race conditions, since the
422-
// MarlinProcessorWrapper algorithm is not re-entrant and can thus not be
423-
// run in parallel
424-
debug() << "Could not retrieve Frame from expected location. Registering a new empty Frame into the TES" << endmsg;
425-
auto tmp = new AnyDataWrapper<podio::Frame>(podio::Frame());
426-
if (m_eventDataSvc->registerObject("/Event" + k4FWCore::frameLocation, tmp).isFailure()) {
427-
error() << "Could not retrieve Frame from expected location in TES and could not register a new one" << endmsg;
428-
throw std::runtime_error("Could not get EDM4hep event (Frame) for conversions");
429-
}
430-
return tmp->getData();
431-
}
432-
433374
// Parse property parameters and convert the indicated collections.
434375
// Use the collection names in the parameters to read and write them
435376
StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {
436-
const auto& edmEvent = getEDM4hepEvent();
377+
const auto& edmEvent = getEDM4hepEvent(this);
437378
// use m_collsToConvert to detect whether we run the first time and cache the
438379
// results as we can assume that all the events have the same contents
439380
if (m_collsToConvert.empty()) {
@@ -451,16 +392,6 @@ StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {
451392

452393
if (m_convertAll) {
453394
info() << "Converting all collections from EDM4hep to LCIO" << endmsg;
454-
if (m_podioDataSvc) {
455-
// If we have the PodioDataSvc get the collections available from frame
456-
for (const auto& name : edmEvent.getAvailableCollections()) {
457-
const auto& [_, inserted] = collNameMapping.emplace(name, name);
458-
debug() << fmt::format("Adding '{}' from Frame to conversion? {}", name, inserted) << endmsg;
459-
}
460-
}
461-
// Always check the contents of the TES because algorithms that do not use
462-
// the PodioDataSvc (e.g. all Functional ones) go to the TES directly and
463-
// the PodioDataSvc Frame doesn't now about them.
464395
std::optional<std::map<uint32_t, std::string>> idToNameOpt(std::move(m_idToName));
465396
for (const auto& name : getAvailableCollectionsFromStore(this, idToNameOpt)) {
466397
const auto& [_, inserted] = collNameMapping.emplace(name, name);
@@ -500,21 +431,16 @@ StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {
500431
for (const auto& pidCollMeta : pidCollections) {
501432
auto algoId = attachParticleIDMetaData(lcio_event, edmEvent, pidCollMeta);
502433
if (!algoId.has_value()) {
503-
// Now go over the collections that have been produced in a functional algorithm (if any)
504-
bool found = false;
505-
if (!m_podioDataSvc) {
506-
const auto id = (*pidCollMeta.coll)[0].getParticle().id().collectionID;
507-
if (auto it = m_idToName.find(id); it != m_idToName.end()) {
508-
auto name = it->second;
509-
if (pidCollMeta.metadata.has_value()) {
510-
UTIL::PIDHandler pidHandler(lcio_event->getCollection(name));
511-
algoId =
512-
pidHandler.addAlgorithm(pidCollMeta.metadata.value().algoName, pidCollMeta.metadata.value().paramNames);
513-
found = true;
514-
}
434+
// Check if we can figure out the collection from information on the TES
435+
const auto id = (*pidCollMeta.coll)[0].getParticle().id().collectionID;
436+
if (auto it = m_idToName.find(id); it != m_idToName.end()) {
437+
auto name = it->second;
438+
if (pidCollMeta.metadata.has_value()) {
439+
UTIL::PIDHandler pidHandler(lcio_event->getCollection(name));
440+
algoId =
441+
pidHandler.addAlgorithm(pidCollMeta.metadata.value().algoName, pidCollMeta.metadata.value().paramNames);
515442
}
516-
}
517-
if (!found) {
443+
} else {
518444
warning() << "Could not determine algorithm type for ParticleID collection " << pidCollMeta.name
519445
<< " for setting consistent metadata" << endmsg;
520446
}

0 commit comments

Comments
 (0)