diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f8593cc50e94dd298ac9661df115894fb3538d2..f3e63d09aa39110263ad40513a66bc485574e9e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,11 @@ endif() IF(DD4HEP_USE_HEPMC3) find_package(HepMC3 REQUIRED) + + # Optional dependencies for compressed input support + find_package(ZLIB) + find_package(LibLZMA) + find_package(BZip2) ENDIF() if(DD4HEP_USE_TBB) diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index 49ac13684c25bbe632f57521fc4e8579dcbb5640..f4f55c20ee2091ea4cc3310195cf63cefd0ffec2 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -113,10 +113,31 @@ IF(TARGET EDM4HEP::edm4hep) ENDIF() IF(DD4HEP_USE_HEPMC3) + set(DDG4HepMC3_INCLUDES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hepmc> $<BUILD_INTERFACE:${HEPMC3_INCLUDE_DIR}>) + set(DDG4HepMC3_USES DD4hep::DDG4 Geant4::Interface ${HEPMC3_LIBRARIES}) + set(DDG4HepMC3_DEFINITIONS) + + IF(ZLIB_FOUND) + list(APPEND DDG4HepMC3_INCLUDES ${ZLIB_INCLUDE_DIR}) + list(APPEND DDG4HepMC3_USES ${ZLIB_LIBRARIES}) + list(APPEND DDG4HepMC3_DEFINITIONS HEPMC3_USE_COMPRESSION HEPMC3_Z_SUPPORT=1) + ENDIF() + IF(LIBLZMA_FOUND) + list(APPEND DDG4HepMC3_INCLUDES ${LIBLZMA_INCLUDE_DIRS}) + list(APPEND DDG4HepMC3_USES ${LIBLZMA_LIBRARIES}) + list(APPEND DDG4HepMC3_DEFINITIONS HEPMC3_USE_COMPRESSION HEPMC3_LZMA_SUPPORT=1) + ENDIF() + IF(BZIP2_FOUND) + list(APPEND DDG4HepMC3_INCLUDES ${BZIP2_INCLUDE_DIRS}) + list(APPEND DDG4HepMC3_USES ${BZIP2_LIBRARIES}) + list(APPEND DDG4HepMC3_DEFINITIONS HEPMC3_USE_COMPRESSION HEPMC3_BZ2_SUPPORT=1) + ENDIF() + dd4hep_add_plugin(DDG4HepMC3 SOURCES hepmc/*.cpp - USES DD4hep::DDG4 Geant4::Interface ${HEPMC3_LIBRARIES} - INCLUDES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hepmc> $<BUILD_INTERFACE:${HEPMC3_INCLUDE_DIR}> + USES ${DDG4HepMC3_USES} + INCLUDES ${DDG4HepMC3_INCLUDES} + DEFINITIONS ${DDG4HepMC3_DEFINITIONS} ) install(TARGETS DDG4HepMC3 EXPORT DD4hep LIBRARY DESTINATION lib) set_target_properties(DDG4HepMC3 PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION}) diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py index 47ccb35b3cf8670c32373dec5e8f35b2d9bf5c90..6baf7eb3080a54c052d1c1de4b82b07c554bcb01 100644 --- a/DDG4/python/DDSim/DD4hepSimulation.py +++ b/DDG4/python/DDSim/DD4hepSimulation.py @@ -41,7 +41,7 @@ try: except ImportError: ARGCOMPLETEENABLED = False -POSSIBLEINPUTFILES = (".stdhep", ".slcio", ".HEPEvt", ".hepevt", ".hepmc", ".hepmc3", ".hepmc3.tree.root", ".pairs") +POSSIBLEINPUTFILES = (".stdhep", ".slcio", ".HEPEvt", ".hepevt", ".hepmc", ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2", ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2", ".hepmc3.tree.root", ".pairs") class DD4hepSimulation(object): @@ -408,7 +408,7 @@ class DD4hepSimulation(object): elif inputFile.endswith(".hepevt"): gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepevt%d" % index) gen.Input = "Geant4EventReaderHepEvtLong|" + inputFile - elif inputFile.endswith((".hepmc", ".hepmc3", ".hepmc3.tree.root")): + elif inputFile.endswith((".hepmc", ".hepmc.gz", ".hepmc.xz", ".hepmc.bz2", ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2", ".hepmc3.tree.root")): if self.hepmc3.useHepMC3: gen = DDG4.GeneratorAction(kernel, "Geant4InputAction/hepmc%d" % index) gen.Parameters = self.hepmc3.getParameters() @@ -532,8 +532,8 @@ class DD4hepSimulation(object): fileNames = [fileNames] if not all(fileName.endswith(extensions) for fileName in fileNames): self._errorMessages.append("ERROR: Unknown fileformat for file: %s" % fileNames) - if not self.hepmc3.useHepMC3 and any(fileName.endswith((".hepmc3", ".hepmc3.tree.root")) for fileName in fileNames): - self._errorMessages.append("ERROR: HepMC3 files require the use of HepMC3 library") + if not self.hepmc3.useHepMC3 and any(fileName.endswith((".hepmc.gz", ".hepmc.xz", ".hepmc.bz2", ".hepmc3", ".hepmc3.gz", ".hepmc3.xz", ".hepmc3.bz2", ".hepmc3.tree.root")) for fileName in fileNames): + self._errorMessages.append("ERROR: HepMC3 files or compressed HepMC2 require the use of HepMC3 library") return fileNames def __applyBoostOrSmear(self, kernel, actionList, mask): diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index 33de5c6ff83bc1f847c897692f52ef973846d691..d3c331f8ddcbeb320fc00bc40914c7b627095efd 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -58,13 +58,50 @@ if (DD4HEP_USE_GEANT4) SET_TESTS_PROPERTIES( t_test_python_import_ddg4 PROPERTIES FAIL_REGULAR_EXPRESSION "Exception;EXCEPTION;ERROR;Error" ) if(DD4HEP_USE_HEPMC3) - ADD_TEST( t_test_ddsim_ion_hepmc3 "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" - ddsim --compactFile=${CMAKE_INSTALL_PREFIX}/DDDetectors/compact/SiD.xml --runType=batch -N=1 - --outputFile=testSidIons.root --inputFiles ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc - --part.userParticleHandler=) - # Tests causes G4Exception about: Isomer level 9 may be ambiguous, just a warning - # space before Exception intentional!!! - SET_TESTS_PROPERTIES( t_test_ddsim_ion_hepmc3 PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR;Error; Exception" ) + set(TEST_HEPMC3_EXTENSIONS) + + if(ZLIB_FOUND) + file(ARCHIVE_CREATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.gz + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc + FORMAT raw + COMPRESSION GZip) + list(APPEND TEST_HEPMC3_EXTENSIONS .gz) + endif() + if(LIBLZMA_FOUND) + file(ARCHIVE_CREATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.xz + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc + FORMAT raw + COMPRESSION XZ) + list(APPEND TEST_HEPMC3_EXTENSIONS .xz) + endif() + if(BZIP2_FOUND) + file(ARCHIVE_CREATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.bz2 + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc + FORMAT raw + COMPRESSION BZip2) + list(APPEND TEST_HEPMC3_EXTENSIONS .bz2) + endif() + + foreach(TEST_HEPMC3_EXTENSION "" ${TEST_HEPMC3_EXTENSIONS}) + string(REPLACE "." "_" TEST_NAME "test_ddsim_ion_hepmc3${TEST_HEPMC3_EXTENSION}") + if("${TEST_HEPMC3_EXTENSION}" STREQUAL "") + set(TEST_HEPMC3_INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc${TEST_HEPMC3_EXTENSION}") + else() + set(TEST_HEPMC3_INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc${TEST_HEPMC3_EXTENSION}") + endif() + + add_test( t_${TEST_NAME} "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" + ddsim --compactFile=${CMAKE_INSTALL_PREFIX}/DDDetectors/compact/SiD.xml --runType=batch -N=1 + --outputFile=testSidIons.root --inputFiles ${TEST_HEPMC3_INPUT_FILE} + --part.userParticleHandler=) + + # Tests causes G4Exception about: Isomer level 9 may be ambiguous, just a warning + # space before Exception intentional!!! + set_tests_properties( t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR;Error; Exception" ) + endforeach() endif() foreach(TEST_NAME