Skip to content

Commit 86bcaa9

Browse files
committed
Add conversion of CellIDEncoding collection parameter
1 parent bb575ff commit 86bcaa9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

standalone/lcio2edm4hep.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#include <IOIMPL/LCFactory.h>
55
#include <UTIL/CheckCollections.h>
66

7+
#include <edm4hep/Constants.h>
78
#include <edm4hep/utils/ParticleIDUtils.h>
89

910
#include "podio/ROOTWriter.h"
1011

12+
#include <array>
1113
#include <cstdlib>
1214
#include <fstream>
1315
#include <iostream>
@@ -147,6 +149,24 @@ ParsedArgs parseArgs(std::vector<std::string> argv) {
147149
return args;
148150
}
149151

152+
const static std::array<std::tuple<std::string, std::string>, 1> STRING_PARAMS_TO_CONVERT = {
153+
{{EVENT::LCIO::CellIDEncoding, edm4hep::labels::CellIDEncoding}}};
154+
155+
void attachCollectionParamters(podio::Frame& metadata, const EVENT::LCCollection* coll, const std::string& name) {
156+
const auto& collParams = coll->getParameters();
157+
std::vector<std::string> stringKeys;
158+
collParams.getStringKeys(stringKeys);
159+
160+
for (const auto& [lcioParam, edm4hepParam] : STRING_PARAMS_TO_CONVERT) {
161+
if (std::ranges::find(stringKeys, lcioParam) != stringKeys.end()) {
162+
// We copy the full vector because in both cases that is what actually is persisted
163+
std::vector<std::string> vals{};
164+
collParams.getStringVals(lcioParam, vals);
165+
metadata.putParameter(podio::collMetadataParamName(name, edm4hepParam), std::move(vals));
166+
}
167+
}
168+
}
169+
150170
int main(int argc, char* argv[]) {
151171
const auto args = parseArgs({argv, argv + argc});
152172

@@ -226,10 +246,15 @@ int main(int argc, char* argv[]) {
226246
}
227247

228248
// For the first event we also convert some meta information for the
229-
// ParticleID handling
249+
// ParticleID handling as well as for the collection level parameters
230250
if (i == 0) {
231251
for (const auto& name : *evt->getCollectionNames()) {
232252
auto coll = evt->getCollection(name);
253+
const auto edm4hepName = k4EDM4hep2LcioConv::detail::mapLookupFrom(name, collsToConvert);
254+
if (edm4hepName.has_value()) {
255+
attachCollectionParamters(metadata, coll, edm4hepName.value());
256+
}
257+
233258
if (coll->getTypeName() == "ReconstructedParticle") {
234259
for (const auto& pidInfo : LCIO2EDM4hepConv::getPIDMetaInfo(coll)) {
235260
edm4hep::utils::PIDHandler::setAlgoInfo(metadata, LCIO2EDM4hepConv::getPIDCollName(name, pidInfo.algoName),

0 commit comments

Comments
 (0)