diff --git a/CMakeLists.txt b/CMakeLists.txt index d49ceb2..73463da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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=`` 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) diff --git a/cmake/build_flags.cmake b/cmake/build_flags.cmake index 2538ce1..1f42a44 100644 --- a/cmake/build_flags.cmake +++ b/cmake/build_flags.cmake @@ -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 ") @@ -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() diff --git a/cmake/compiler_output.cmake b/cmake/compiler_output.cmake deleted file mode 100644 index c2e7227..0000000 --- a/cmake/compiler_output.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# Enable compiler output highligh (for Ninja) -option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE) -if (FORCE_COLORED_OUTPUT) - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - add_compile_options (-fdiagnostics-color=always) - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_compile_options (-fcolor-diagnostics) - endif () -endif () \ No newline at end of file diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp index c5a7a1b..a636288 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp @@ -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()); } } } @@ -764,23 +764,29 @@ createLCRelationCollections(const std::vector(coll)) { - relationColls.emplace_back(name, - createLCRelationCollection(*links, objectMaps.recoParticles, objectMaps.mcParticles)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.caloHits, objectMaps.simCaloHits)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, - createLCRelationCollection(*links, objectMaps.trackerHits, objectMaps.simTrackerHits)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.caloHits, objectMaps.mcParticles)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.clusters, objectMaps.mcParticles)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, createLCRelationCollection(*links, objectMaps.tracks, objectMaps.mcParticles)); - } else if (const auto links = dynamic_cast(coll)) { - relationColls.emplace_back(name, - createLCRelationCollection(*links, objectMaps.vertices, objectMaps.recoParticles)); + if (const auto recoMCParticleLink = dynamic_cast(coll)) { + relationColls.emplace_back( + name, createLCRelationCollection(*recoMCParticleLink, objectMaps.recoParticles, objectMaps.mcParticles)); + } else if (const auto caloHitSimCaloHitLink = dynamic_cast(coll)) { + relationColls.emplace_back( + name, createLCRelationCollection(*caloHitSimCaloHitLink, objectMaps.caloHits, objectMaps.simCaloHits)); + } else if (const auto trackerHitSimTrackerHitLink = + dynamic_cast(coll)) { + relationColls.emplace_back(name, createLCRelationCollection(*trackerHitSimTrackerHitLink, objectMaps.trackerHits, + objectMaps.simTrackerHits)); + } else if (const auto caloHitMCParticleLink = dynamic_cast(coll)) { + relationColls.emplace_back( + name, createLCRelationCollection(*caloHitMCParticleLink, objectMaps.caloHits, objectMaps.mcParticles)); + } else if (const auto clusterMCParticleLink = dynamic_cast(coll)) { + relationColls.emplace_back( + name, createLCRelationCollection(*clusterMCParticleLink, objectMaps.clusters, objectMaps.mcParticles)); + } else if (const auto trackMCParticleLink = dynamic_cast(coll)) { + relationColls.emplace_back( + name, createLCRelationCollection(*trackMCParticleLink, objectMaps.tracks, objectMaps.mcParticles)); + } else if (const auto vertexRecoParticleLink = + dynamic_cast(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; diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp index b5b74c7..0598ba2 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp @@ -743,8 +743,8 @@ void resolveRelationsTracks(TrackMapT& tracksMap, const TrackHitMapT& trackerHit if (th == nullptr) { continue; } - if (const auto typedTH = dynamic_cast(th)) { - if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTH, trackerHitPlaneMap)) { + if (const auto typedTHPlane = dynamic_cast(th)) { + if (const auto trHit = k4EDM4hep2LcioConv::detail::mapLookupTo(typedTHPlane, trackerHitPlaneMap)) { edm.addToTrackerHits(trHit.value()); found = true; } diff --git a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp index 2075816..2666ba0 100644 --- a/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp @@ -85,48 +85,52 @@ std::unique_ptr convertEvent(const podio::Frame& edmEvent, co const auto& cellIDStr = metadata.getParameter(podio::collMetadataParamName(name, edm4hep::labels::CellIDEncoding)); - if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertTracks(coll, objectMappings.tracks); + if (const auto trackColl = dynamic_cast(edmCollection)) { + auto lcColl = convertTracks(trackColl, objectMappings.tracks); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertTrackerHits(coll, cellIDStr, objectMappings.trackerHits); + } else if (const auto trackerHit3DColl = dynamic_cast(edmCollection)) { + auto lcColl = convertTrackerHits(trackerHit3DColl, cellIDStr, objectMappings.trackerHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertTrackerHitPlanes(coll, cellIDStr, objectMappings.trackerHitPlanes); + } else if (const auto trackerHitPlaneColl = + dynamic_cast(edmCollection)) { + auto lcColl = convertTrackerHitPlanes(trackerHitPlaneColl, cellIDStr, objectMappings.trackerHitPlanes); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertSimTrackerHits(coll, cellIDStr, objectMappings.simTrackerHits); + } else if (const auto simTrackerHitColl = dynamic_cast(edmCollection)) { + auto lcColl = convertSimTrackerHits(simTrackerHitColl, cellIDStr, objectMappings.simTrackerHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertCalorimeterHits(coll, cellIDStr, objectMappings.caloHits); + } else if (const auto calorimeterHitColl = dynamic_cast(edmCollection)) { + auto lcColl = convertCalorimeterHits(calorimeterHitColl, cellIDStr, objectMappings.caloHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertRawCalorimeterHits(coll, objectMappings.rawCaloHits); + } else if (const auto rawCalorimeterHitColl = + dynamic_cast(edmCollection)) { + auto lcColl = convertRawCalorimeterHits(rawCalorimeterHitColl, objectMappings.rawCaloHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertSimCalorimeterHits(coll, cellIDStr, objectMappings.simCaloHits); + } else if (const auto simCalorimeterHitColl = + dynamic_cast(edmCollection)) { + auto lcColl = convertSimCalorimeterHits(simCalorimeterHitColl, cellIDStr, objectMappings.simCaloHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertTPCHits(coll, objectMappings.tpcHits); + } else if (const auto rawTimeSeriesColl = dynamic_cast(edmCollection)) { + auto lcColl = convertTPCHits(rawTimeSeriesColl, objectMappings.tpcHits); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertClusters(coll, objectMappings.clusters); + } else if (const auto clusterColl = dynamic_cast(edmCollection)) { + auto lcColl = convertClusters(clusterColl, objectMappings.clusters); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertVertices(coll, objectMappings.vertices); + } else if (const auto vertexColl = dynamic_cast(edmCollection)) { + auto lcColl = convertVertices(vertexColl, objectMappings.vertices); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertMCParticles(coll, objectMappings.mcParticles); + } else if (const auto mcParticleColl = dynamic_cast(edmCollection)) { + auto lcColl = convertMCParticles(mcParticleColl, objectMappings.mcParticles); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - auto lcColl = convertReconstructedParticles(coll, objectMappings.recoParticles); + } else if (const auto recoParticleColl = + dynamic_cast(edmCollection)) { + auto lcColl = convertReconstructedParticles(recoParticleColl, objectMappings.recoParticles); lcioEvent->addCollection(lcColl.release(), name); - } else if (auto coll = dynamic_cast(edmCollection)) { - convertEventHeader(coll, lcioEvent.get()); - } else if (auto coll = dynamic_cast(edmCollection)) { - pidCollections.emplace_back(name, coll, edm4hep::utils::PIDHandler::getAlgoInfo(metadata, name)); - } else if (auto coll = dynamic_cast(edmCollection)) { - dQdxCollections.emplace_back(name, coll); + } else if (const auto eventHeaderColl = dynamic_cast(edmCollection)) { + convertEventHeader(eventHeaderColl, lcioEvent.get()); + } else if (const auto particleIDColl = dynamic_cast(edmCollection)) { + pidCollections.emplace_back(name, particleIDColl, edm4hep::utils::PIDHandler::getAlgoInfo(metadata, name)); + } else if (const auto recDqdxColl = dynamic_cast(edmCollection)) { + dQdxCollections.emplace_back(name, recDqdxColl); } else if (dynamic_cast(edmCollection)) { // "converted" during relation resolving later continue; diff --git a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp index 6c58f94..e380139 100644 --- a/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp +++ b/k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp @@ -70,14 +70,14 @@ podio::Frame convertEvent(EVENT::LCEvent* evt, const std::vectorgetCollectionNames(); - std::vector> collNames{}; - collNames.reserve(evtColls->size()); + std::vector> 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. diff --git a/tests/src/ComparisonUtils.h b/tests/src/ComparisonUtils.h index 26cb242..887a45b 100644 --- a/tests/src/ComparisonUtils.h +++ b/tests/src/ComparisonUtils.h @@ -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::value) { - return edm4hepV.size(); + return edm4hepVal.size(); } else if constexpr (std::is_same_v || std::is_same_v) { return 3u; } else if constexpr (std::is_same_v || std::is_same_v) {