Skip to content
Closed
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
1 change: 1 addition & 0 deletions k4MarlinWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gaudi_install(SCRIPTS)
# k4MarlinWrapperPlugins
gaudi_add_module(k4MarlinWrapperPlugins
SOURCES
src/components/CellIDEncodingFiller.cpp
src/components/LcioEventAlgo.cpp
src/components/LcioEventOutput.cpp
src/components/MarlinProcessorWrapper.cpp
Expand Down
51 changes: 18 additions & 33 deletions k4MarlinWrapper/examples/clicRec_e4h_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@

from Gaudi.Configuration import DEBUG, WARNING

from Configurables import MarlinProcessorWrapper
from k4MarlinWrapper.parseConstants import parseConstants

from Configurables import Lcio2EDM4hepTool, EDM4hep2LcioTool
from Configurables import k4DataSvc, PodioInput, PodioOutput, EventDataSvc
from Configurables import (
MarlinProcessorWrapper,
Lcio2EDM4hepTool,
EDM4hep2LcioTool,
EventDataSvc,
MetadataSvc,
)

from k4FWCore import ApplicationMgr, IOSvc
from k4FWCore.parseArgs import parser
Expand All @@ -39,12 +43,6 @@

parseConstants(CONSTANTS)

parser.add_argument(
"--no-iosvc",
action="store_true",
default=False,
help="Use k4DataSvc instead of IOSvc",
)
parser.add_argument(
"--rec-output", default="Output_REC_e4h_input.slcio", help="Output file name for the REC file"
)
Expand All @@ -54,27 +52,15 @@
parser.add_argument(
"--gaudi-output", default="my_output.root", help="Output file name for the Gaudi file"
)

args = parser.parse_known_args()[0]
if not args.no_iosvc:
evtsvc = EventDataSvc("EventDataSvc")
iosvc = IOSvc()
iosvc.Input = os.path.join(
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
)
iosvc.Output = args.gaudi_output
iosvc.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]
else:
evtsvc = k4DataSvc("EventDataSvc")
evtsvc.input = os.path.join(
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
)

inp = PodioInput("InputReader")
inp.OutputLevel = DEBUG

out = PodioOutput("PodioOutput", filename=args.gaudi_output)
out.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]

evtsvc = EventDataSvc("EventDataSvc")
iosvc = IOSvc()
iosvc.Input = os.path.join(
"$TEST_DIR/inputFiles/", os.environ.get("INPUTFILE", "ttbar_edm4hep_frame.root")
)
iosvc.Output = args.gaudi_output
iosvc.outputCommands = ["keep *", "drop RefinedVertexJets_PID_RefinedVertex"]

MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor")
MyAIDAProcessor.OutputLevel = WARNING
Expand Down Expand Up @@ -2504,7 +2490,6 @@
algList.append(Output_REC)
algList.append(Output_DST)

if args.no_iosvc:
algList = [inp] + algList + [out]

ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=3, ExtSvc=[evtsvc], OutputLevel=WARNING)
ApplicationMgr(
TopAlg=algList, EvtSel="NONE", EvtMax=3, ExtSvc=[evtsvc, MetadataSvc()], OutputLevel=WARNING
)
7 changes: 0 additions & 7 deletions k4MarlinWrapper/k4MarlinWrapper/converters/EDM4hep2Lcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include <tuple>
#include <vector>

class PodioDataSvc;
class IDataProviderSvc;
class IMetadataSvc;

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

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

const podio::Frame& getEDM4hepEvent() const;

/// Get an EDM4hep collection by name, consulting either the podio based data
/// svc or the IOSvc
podio::CollectionBase* getEDM4hepCollection(const std::string& name, bool allowToFail = false) const;
Expand Down
10 changes: 2 additions & 8 deletions k4MarlinWrapper/k4MarlinWrapper/converters/Lcio2EDM4hep.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <Gaudi/Property.h>
#include <GaudiKernel/AlgTool.h>

#include "k4FWCore/IMetadataSvc.h"

#include "k4MarlinWrapper/converters/IEDMConverter.h"

#include <lcio.h>
Expand All @@ -40,13 +38,9 @@ namespace EVENT {
class LCCollection;
}

class PodioDataSvc;

class Lcio2EDM4hepTool : public AlgTool, virtual public IEDMConverter {
public:
Lcio2EDM4hepTool(const std::string& type, const std::string& name, const IInterface* parent);
StatusCode initialize() final;
StatusCode finalize() final;

// **********************************
// - Convert all collections indicated in Tool parameters
Expand All @@ -61,8 +55,8 @@ class Lcio2EDM4hepTool : public AlgTool, virtual public IEDMConverter {
Gaudi::Property<bool> m_convertAll{this, "convertAll", true};

ServiceHandle<IDataProviderSvc> m_eventDataSvc;
SmartIF<IMetadataSvc> m_metadataSvc;
PodioDataSvc* m_podioDataSvc;

std::map<std::string, std::string> m_cellIDEncodings{};

// **********************************
// Check if a collection was already registered to skip it
Expand Down
50 changes: 50 additions & 0 deletions k4MarlinWrapper/src/components/CellIDEncodingFiller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2019-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 <k4FWCore/MetadataUtils.h>

#include <Gaudi/Algorithm.h>
#include <GaudiKernel/StatusCode.h>

#include <map>
#include <string>

class CellIDEncodingFiller final : public Gaudi::Algorithm {
public:
CellIDEncodingFiller(const std::string& name, ISvcLocator* pSL) : Gaudi::Algorithm(name, pSL) {}

StatusCode initialize() override {
if (Gaudi::Algorithm::initialize().isFailure()) {
return StatusCode::FAILURE;
}
for (const auto& [collName, encoding] : m_cellIDEncodings) {
debug() << "Putting CellID encoding for collection '" << collName << "': " << encoding << endmsg;
k4FWCore::putCellIDEncoding(collName, encoding, this);
}
return StatusCode::SUCCESS;
}

StatusCode execute(const EventContext&) const override { return StatusCode::SUCCESS; }

private:
Gaudi::Property<std::map<std::string, std::string>> m_cellIDEncodings{
this, "CellIDEncodings", {}, "Map of collection names to CellID encoding strings"};
};

DECLARE_COMPONENT(CellIDEncodingFiller)
Loading
Loading