Skip to content

Commit

Permalink
Add automated test cases for standalone converter and also check rela…
Browse files Browse the repository at this point in the history
…tions (#28)
  • Loading branch information
tmadlener authored Oct 4, 2023
1 parent 2e6f6c3 commit ef75a5d
Show file tree
Hide file tree
Showing 12 changed files with 698 additions and 132 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,3 @@ test/k4FWCoreTest/**/*.root
## k4MarlinWrapper
test/inputFiles/*.slcio
test/gaudi_opts/testConverterConstants.py

16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ set( ${PROJECT_NAME}_VERSION_MINOR 5 )
set( ${PROJECT_NAME}_VERSION_PATCH 0 )
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")
Expand Down
25 changes: 12 additions & 13 deletions k4EDM4hep2LcioConv/src/k4Lcio2EDM4hepConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,20 +747,19 @@ namespace LCIO2EDM4hepConv {
for (auto& [lcio, edm] : recoparticlesMap) {
edmnum++;

auto vertex = lcio->getStartVertex();
if (vertex == nullptr) {
continue;
}
if (const auto it = vertexMap.find(vertex); it != vertexMap.end()) {
edm.setStartVertex(it->second);
}
else {
std::cerr << "Cannot find corresponding EDM4hep Vertex for a LCIO Vertex, "
"while trying to resolve the ReconstructedParticle Relations "
<< std::endl;
const auto vertex = lcio->getStartVertex();
if (vertex) {
if (const auto it = vertexMap.find(vertex); it != vertexMap.end()) {
edm.setStartVertex(it->second);
}
else {
std::cerr << "Cannot find corresponding EDM4hep Vertex for a LCIO Vertex, "
"while trying to resolve the ReconstructedParticle Relations "
<< std::endl;
}
}

auto clusters = lcio->getClusters();
const auto& clusters = lcio->getClusters();
for (auto c : clusters) {
if (c == nullptr) {
continue;
Expand All @@ -776,7 +775,7 @@ namespace LCIO2EDM4hepConv {
}
}

auto tracks = lcio->getTracks();
const auto& tracks = lcio->getTracks();
for (auto t : tracks) {
if (t == nullptr) {
continue;
Expand Down
25 changes: 24 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
add_library(edmCompare SHARED src/CompareEDM4hepLCIO.cc)
add_library(edmCompare SHARED src/CompareEDM4hepLCIO.cc src/ObjectMapping.cc)
target_link_libraries(edmCompare PUBLIC EDM4HEP::edm4hep ${LCIO_LIBRARIES})
target_include_directories(edmCompare PUBLIC ${LCIO_INCLUDE_DIRS})

add_executable(compare-contents compare_contents.cpp)
target_link_libraries(compare-contents PRIVATE edmCompare podio::podioRootIO)
target_include_directories(compare-contents PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>)

find_program(BASH_PROGRAM bash)

add_test(fetch_test_inputs ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/get_test_data.sh)

add_test(standalone_ild_rec_file ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_standalone_converter.sh ild_higgs_rec.slcio)

add_test(standalone_ild_dst_file ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_standalone_converter.sh ild_higgs_dst.slcio)

set_tests_properties(
fetch_test_inputs
standalone_ild_rec_file
standalone_ild_dst_file
PROPERTIES
ENVIRONMENT "TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_CURRENT_BINARY_DIR}:${PROJECT_BINARY_DIR}/standalone:$ENV{PATH}"
)

set_tests_properties(
standalone_ild_rec_file
standalone_ild_dst_file
PROPERTIES
DEPENDS fetch_test_inputs
)
24 changes: 19 additions & 5 deletions tests/compare_contents.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CompareEDM4hepLCIO.h"
#include "ObjectMapping.h"

#include "podio/ROOTFrameReader.h"
#include "podio/Frame.h"
Expand All @@ -11,7 +12,7 @@
#define ASSERT_COMPARE_OR_EXIT(collType) \
if (type == #collType) { \
auto& edmcoll = edmEvent.get<collType>(name); \
if (!compare(lcioColl, edmcoll)) { \
if (!compare(lcioColl, edmcoll, objectMapping)) { \
std::cerr << "in collection: " << name << std::endl; \
return 1; \
} \
Expand Down Expand Up @@ -60,6 +61,23 @@ int main(int argc, char* argv[])
continue;
}
}
const auto coll = edmEvent.get(name);
if (!coll) {
std::cerr << "Collection " << name << " not present in edm4hep file" << std::endl;
return 1;
}

if (edmEvent.get(name)->size() != lcioColl->getNumberOfElements()) {
std::cerr << "Collection " << name << " has different sizes. LCIO: " << lcioColl->getNumberOfElements()
<< ", EDM4hep: " << coll->size() << std::endl;
return 1;
}
}

const auto objectMapping = ObjectMappings::fromEvent(lcEvent, edmEvent);

for (const auto& name : *(lcEvent->getCollectionNames())) {
const auto lcioColl = lcEvent->getCollection(name);
const auto type = [&edmEvent, &name]() {
const auto coll = edmEvent.get(name);
if (coll) {
Expand All @@ -68,10 +86,6 @@ int main(int argc, char* argv[])
static const decltype(coll->getTypeName()) empty = "";
return empty;
}();
if (type.empty()) {
std::cerr << "Collection " << name << " not present in edm4hep file" << std::endl;
return 1;
}

ASSERT_COMPARE_OR_EXIT(edm4hep::MCParticleCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::ReconstructedParticleCollection)
Expand Down
15 changes: 15 additions & 0 deletions tests/scripts/get_test_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -eu

TEST_INPUT_DIR=${TEST_DIR}/inputFiles
mkdir -p ${TEST_INPUT_DIR}

TEST_FILES=("ild_higgs_rec.slcio" "ild_higgs_dst.slcio")

for input_file in ${TEST_FILES[@]}; do
if [ ! -f ${TEST_INPUT_DIR}/${input_file} ]; then
echo "${input_file} test input file not yet present. Fetching it"
wget https://key4hep.web.cern.ch/testFiles/k4EDM4hep2LcioConv/ILD/${input_file} -P ${TEST_INPUT_DIR}
fi
done
22 changes: 22 additions & 0 deletions tests/scripts/run_standalone_converter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -eu

input_file_base=${1}

TEST_INPUT_DIR=${TEST_DIR}/inputFiles
TEST_OUTPUT_DIR=testOutputs
mkdir -p ${TEST_OUTPUT_DIR}

input_file=${TEST_INPUT_DIR}/${input_file_base}
output_file=${TEST_OUTPUT_DIR}/${input_file_base/.slcio/.edm4hep.root}
patch_file=${TEST_OUTPUT_DIR}/${input_file_base/.slcio/_colls.txt}

echo "Creating the patch file for the standalone converter"
check_missing_cols --minimal ${input_file} > ${patch_file}

echo "Running the standalone converter"
lcio2edm4hep ${input_file} ${output_file} ${patch_file}

echo "Comparing the converted and original contents"
compare-contents ${input_file} ${output_file}
Loading

0 comments on commit ef75a5d

Please sign in to comment.