Skip to content

Commit

Permalink
Use the Key4hepConfig flag to set the standard, compiler flags and rp…
Browse files Browse the repository at this point in the history
…ath magic (#96)
  • Loading branch information
jmcarcell committed Sep 10, 2024
1 parent 5b33233 commit a4977dd
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 127 deletions.
31 changes: 2 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,12 @@ set( ${PROJECT_NAME}_VERSION_MINOR 8 )
set( ${PROJECT_NAME}_VERSION_PATCH 2 )
set( ${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}" )

# Define a default build type can be overriden by passing
# ``-DCMAKE_BUILD_TYPE=<type>`` when invoking CMake
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo
CACHE STRING "Choose the type of build, options are: None Release MinSizeRel Debug RelWithDebInfo"
FORCE
)
else()
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}"
CACHE STRING "Choose the type of build, options are: None Release MinSizeRel Debug RelWithDebInfo"
FORCE
)
endif()
endif()

set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
include(cmake/Key4hepConfig.cmake)

include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 20 CACHE STRING "")

if(NOT CMAKE_CXX_STANDARD MATCHES "20")
message(FATAL_ERROR "Unsupported C++ standard: ${CMAKE_CXX_STANDARD}")
endif()

# Ninja compiler output
include(cmake/compiler_output.cmake)
include(cmake/build_flags.cmake)
k4edm4hep2lcioconv_set_compiler_flags()

k4edm4hep2lcioconv_set_linker_flags()
find_package(LCIO 2.22 REQUIRED)
find_package(podio 1.0 REQUIRED)
find_package(EDM4HEP 0.99 REQUIRED)
Expand Down
33 changes: 4 additions & 29 deletions cmake/build_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
#---------------------------------------------------------------------------------------------------
#---k4edm4hep2lcioconv_set_compiler_flags
#---k4edm4hep2lcioconv_set_linker_flags
#
# Set compiler and linker flags
# Set linker flags
#
#---------------------------------------------------------------------------------------------------

macro(k4edm4hep2lcioconv_set_compiler_flags)
include(CheckCXXCompilerFlag)

SET(COMPILER_FLAGS -fPIC -Wall -Wextra -Wpedantic)

# AppleClang/Clang specific warning flags
if(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
set ( COMPILER_FLAGS ${COMPILER_FLAGS} -Winconsistent-missing-override -Wheader-hygiene )
endif()

FOREACH( FLAG ${COMPILER_FLAGS} )
## need to replace the minus or plus signs from the variables, because it is passed
## as a macro to g++ which causes a warning about no whitespace after macro
## definition
STRING(REPLACE "-" "_" FLAG_WORD ${FLAG} )
STRING(REPLACE "+" "P" FLAG_WORD ${FLAG_WORD} )

CHECK_CXX_COMPILER_FLAG( "${FLAG}" CXX_FLAG_WORKS_${FLAG_WORD} )
IF( ${CXX_FLAG_WORKS_${FLAG_WORD}} )
message( STATUS "Adding ${FLAG} to CXX_FLAGS" )
SET ( CMAKE_CXX_FLAGS "${FLAG} ${CMAKE_CXX_FLAGS} ")
ELSE()
message( STATUS "NOT Adding ${FLAG} to CXX_FLAGS" )
ENDIF()
ENDFOREACH()

macro(k4edm4hep2lcioconv_set_linker_flags)
# resolve which linker we use
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET)
if("${stdout}" MATCHES "GNU ")
Expand All @@ -55,4 +30,4 @@ macro(k4edm4hep2lcioconv_set_compiler_flags)
MESSAGE( WARNING "No known linker (GNU or Apple) has been detected, pass no flags to linker" )
endif()

endmacro(k4edm4hep2lcioconv_set_compiler_flags)
endmacro()
9 changes: 0 additions & 9 deletions cmake/compiler_output.cmake

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ void resolveRelationsTracks(TrackMapT& tracksMap, const TrackHitMapT& trackerHit
if (!th.isAvailable()) {
continue;
}
if (const auto hit = k4EDM4hep2LcioConv::detail::mapLookupFrom(th, trackerHitMap)) {
lcio_tr->addHit(hit.value());
} else if (const auto hit = k4EDM4hep2LcioConv::detail::mapLookupFrom(th, trackerHitPlaneMap)) {
lcio_tr->addHit(hit.value());
if (const auto trackerHit = k4EDM4hep2LcioConv::detail::mapLookupFrom(th, trackerHitMap)) {
lcio_tr->addHit(trackerHit.value());
} else if (const auto trackerHitPlane = k4EDM4hep2LcioConv::detail::mapLookupFrom(th, trackerHitPlaneMap)) {
lcio_tr->addHit(trackerHitPlane.value());
}
}
}
Expand Down Expand Up @@ -764,23 +764,29 @@ createLCRelationCollections(const std::vector<std::tuple<std::string, const podi
relationColls.reserve(linkCollections.size());

for (const auto& [name, coll] : linkCollections) {
if (const auto links = dynamic_cast<const edm4hep::RecoMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name,
createLCRelationCollection(*links, objectMaps.recoParticles, objectMaps.mcParticles));
} else if (const auto links = dynamic_cast<const edm4hep::CaloHitSimCaloHitLinkCollection*>(coll)) {
relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.caloHits, objectMaps.simCaloHits));
} else if (const auto links = dynamic_cast<const edm4hep::TrackerHitSimTrackerHitLinkCollection*>(coll)) {
relationColls.emplace_back(name,
createLCRelationCollection(*links, objectMaps.trackerHits, objectMaps.simTrackerHits));
} else if (const auto links = dynamic_cast<const edm4hep::CaloHitMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.caloHits, objectMaps.mcParticles));
} else if (const auto links = dynamic_cast<const edm4hep::ClusterMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.clusters, objectMaps.mcParticles));
} else if (const auto links = dynamic_cast<const edm4hep::TrackMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.tracks, objectMaps.mcParticles));
} else if (const auto links = dynamic_cast<const edm4hep::VertexRecoParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name,
createLCRelationCollection(*links, objectMaps.vertices, objectMaps.recoParticles));
if (const auto recoMCParticleLink = dynamic_cast<const edm4hep::RecoMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*recoMCParticleLink, objectMaps.recoParticles, objectMaps.mcParticles));
} else if (const auto caloHitSimCaloHitLink = dynamic_cast<const edm4hep::CaloHitSimCaloHitLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*caloHitSimCaloHitLink, objectMaps.caloHits, objectMaps.simCaloHits));
} else if (const auto trackerHitSimTrackerHitLink =
dynamic_cast<const edm4hep::TrackerHitSimTrackerHitLinkCollection*>(coll)) {
relationColls.emplace_back(name, createLCRelationCollection(*trackerHitSimTrackerHitLink, objectMaps.trackerHits,
objectMaps.simTrackerHits));
} else if (const auto caloHitMCParticleLink = dynamic_cast<const edm4hep::CaloHitMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*caloHitMCParticleLink, objectMaps.caloHits, objectMaps.mcParticles));
} else if (const auto clusterMCParticleLink = dynamic_cast<const edm4hep::ClusterMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*clusterMCParticleLink, objectMaps.clusters, objectMaps.mcParticles));
} else if (const auto trackMCParticleLink = dynamic_cast<const edm4hep::TrackMCParticleLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*trackMCParticleLink, objectMaps.tracks, objectMaps.mcParticles));
} else if (const auto vertexRecoParticleLink =
dynamic_cast<const edm4hep::VertexRecoParticleLinkCollection*>(coll)) {
relationColls.emplace_back(
name, createLCRelationCollection(*vertexRecoParticleLink, objectMaps.vertices, objectMaps.recoParticles));
} else {
std::cerr << "Trying to create an LCRelation collection from a " << coll->getTypeName()
<< " which is not supported" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ void resolveRelationsTracks(TrackMapT& tracksMap, const TrackHitMapT& trackerHit
if (th == nullptr) {
continue;
}
if (const auto typedTH = dynamic_cast<EVENT::TrackerHitPlane*>(th)) {
if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTH, trackerHitPlaneMap)) {
if (const auto typedTHPlane = dynamic_cast<EVENT::TrackerHitPlane*>(th)) {
if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTHPlane, trackerHitPlaneMap)) {
edm.addToTrackerHits(trHit.value());
found = true;
}
Expand Down
64 changes: 34 additions & 30 deletions k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,52 @@ std::unique_ptr<lcio::LCEventImpl> convertEvent(const podio::Frame& edmEvent, co
const auto& cellIDStr =
metadata.getParameter<std::string>(podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding));

if (auto coll = dynamic_cast<const edm4hep::TrackCollection*>(edmCollection)) {
auto lcColl = convertTracks(coll, objectMappings.tracks);
if (const auto trackColl = dynamic_cast<const edm4hep::TrackCollection*>(edmCollection)) {
auto lcColl = convertTracks(trackColl, objectMappings.tracks);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::TrackerHit3DCollection*>(edmCollection)) {
auto lcColl = convertTrackerHits(coll, cellIDStr, objectMappings.trackerHits);
} else if (const auto trackerHit3DColl = dynamic_cast<const edm4hep::TrackerHit3DCollection*>(edmCollection)) {
auto lcColl = convertTrackerHits(trackerHit3DColl, cellIDStr, objectMappings.trackerHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::TrackerHitPlaneCollection*>(edmCollection)) {
auto lcColl = convertTrackerHitPlanes(coll, cellIDStr, objectMappings.trackerHitPlanes);
} else if (const auto trackerHitPlaneColl =
dynamic_cast<const edm4hep::TrackerHitPlaneCollection*>(edmCollection)) {
auto lcColl = convertTrackerHitPlanes(trackerHitPlaneColl, cellIDStr, objectMappings.trackerHitPlanes);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::SimTrackerHitCollection*>(edmCollection)) {
auto lcColl = convertSimTrackerHits(coll, cellIDStr, objectMappings.simTrackerHits);
} else if (const auto simTrackerHitColl = dynamic_cast<const edm4hep::SimTrackerHitCollection*>(edmCollection)) {
auto lcColl = convertSimTrackerHits(simTrackerHitColl, cellIDStr, objectMappings.simTrackerHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::CalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertCalorimeterHits(coll, cellIDStr, objectMappings.caloHits);
} else if (const auto calorimeterHitColl = dynamic_cast<const edm4hep::CalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertCalorimeterHits(calorimeterHitColl, cellIDStr, objectMappings.caloHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::RawCalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertRawCalorimeterHits(coll, objectMappings.rawCaloHits);
} else if (const auto rawCalorimeterHitColl =
dynamic_cast<const edm4hep::RawCalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertRawCalorimeterHits(rawCalorimeterHitColl, objectMappings.rawCaloHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::SimCalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertSimCalorimeterHits(coll, cellIDStr, objectMappings.simCaloHits);
} else if (const auto simCalorimeterHitColl =
dynamic_cast<const edm4hep::SimCalorimeterHitCollection*>(edmCollection)) {
auto lcColl = convertSimCalorimeterHits(simCalorimeterHitColl, cellIDStr, objectMappings.simCaloHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::RawTimeSeriesCollection*>(edmCollection)) {
auto lcColl = convertTPCHits(coll, objectMappings.tpcHits);
} else if (const auto rawTimeSeriesColl = dynamic_cast<const edm4hep::RawTimeSeriesCollection*>(edmCollection)) {
auto lcColl = convertTPCHits(rawTimeSeriesColl, objectMappings.tpcHits);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::ClusterCollection*>(edmCollection)) {
auto lcColl = convertClusters(coll, objectMappings.clusters);
} else if (const auto clusterColl = dynamic_cast<const edm4hep::ClusterCollection*>(edmCollection)) {
auto lcColl = convertClusters(clusterColl, objectMappings.clusters);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::VertexCollection*>(edmCollection)) {
auto lcColl = convertVertices(coll, objectMappings.vertices);
} else if (const auto vertexColl = dynamic_cast<const edm4hep::VertexCollection*>(edmCollection)) {
auto lcColl = convertVertices(vertexColl, objectMappings.vertices);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::MCParticleCollection*>(edmCollection)) {
auto lcColl = convertMCParticles(coll, objectMappings.mcParticles);
} else if (const auto mcParticleColl = dynamic_cast<const edm4hep::MCParticleCollection*>(edmCollection)) {
auto lcColl = convertMCParticles(mcParticleColl, objectMappings.mcParticles);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::ReconstructedParticleCollection*>(edmCollection)) {
auto lcColl = convertReconstructedParticles(coll, objectMappings.recoParticles);
} else if (const auto recoParticleColl =
dynamic_cast<const edm4hep::ReconstructedParticleCollection*>(edmCollection)) {
auto lcColl = convertReconstructedParticles(recoParticleColl, objectMappings.recoParticles);
lcioEvent->addCollection(lcColl.release(), name);
} else if (auto coll = dynamic_cast<const edm4hep::EventHeaderCollection*>(edmCollection)) {
convertEventHeader(coll, lcioEvent.get());
} else if (auto coll = dynamic_cast<const edm4hep::ParticleIDCollection*>(edmCollection)) {
pidCollections.emplace_back(name, coll, edm4hep::utils::PIDHandler::getAlgoInfo(metadata, name));
} else if (auto coll = dynamic_cast<const edm4hep::RecDqdxCollection*>(edmCollection)) {
dQdxCollections.emplace_back(name, coll);
} else if (const auto eventHeaderColl = dynamic_cast<const edm4hep::EventHeaderCollection*>(edmCollection)) {
convertEventHeader(eventHeaderColl, lcioEvent.get());
} else if (const auto particleIDColl = dynamic_cast<const edm4hep::ParticleIDCollection*>(edmCollection)) {
pidCollections.emplace_back(name, particleIDColl, edm4hep::utils::PIDHandler::getAlgoInfo(metadata, name));
} else if (const auto recDqdxColl = dynamic_cast<const edm4hep::RecDqdxCollection*>(edmCollection)) {
dQdxCollections.emplace_back(name, recDqdxColl);
} else if (dynamic_cast<const edm4hep::CaloHitContributionCollection*>(edmCollection)) {
// "converted" during relation resolving later
continue;
Expand Down
10 changes: 5 additions & 5 deletions k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ podio::Frame convertEvent(EVENT::LCEvent* evt, const std::vector<std::pair<std::
const auto collNames = [&collsToConvert, &evt]() {
if (collsToConvert.empty()) {
const auto evtColls = evt->getCollectionNames();
std::vector<std::pair<std::string, std::string>> collNames{};
collNames.reserve(evtColls->size());
std::vector<std::pair<std::string, std::string>> resCollNames{};
resCollNames.reserve(evtColls->size());
for (const auto& name : *evtColls) {
collNames.emplace_back(name, name);
resCollNames.emplace_back(name, name);
}
return collNames;
return resCollNames;
}
return std::move(collsToConvert);
return collsToConvert;
}();

// In this loop the data gets converted.
Expand Down
4 changes: 2 additions & 2 deletions tests/src/ComparisonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ bool compareValuesNanSafe(LCIO lcioV, EDM4hepT edm4hepV, const std::string& msg)
>;

if constexpr (isVectorLike) {
const auto vecSize = [](EDM4hepT& edm4hepV) -> std::size_t {
const auto vecSize = [](EDM4hepT& edm4hepVal) -> std::size_t {
if constexpr (has_size_method<EDM4hepT>::value) {
return edm4hepV.size();
return edm4hepVal.size();
} else if constexpr (std::is_same_v<EDM4hepT, edm4hep::Vector3f> || std::is_same_v<EDM4hepT, edm4hep::Vector3d>) {
return 3u;
} else if constexpr (std::is_same_v<EDM4hepT, edm4hep::Vector2i> || std::is_same_v<EDM4hepT, edm4hep::Vector2f>) {
Expand Down

0 comments on commit a4977dd

Please sign in to comment.