From cd0c75de2c91727df59297d7d9de4dec957bd955 Mon Sep 17 00:00:00 2001 From: JeremyMcCormick <jermccormick@gmail.com> Date: Thu, 4 May 2017 20:23:44 -0700 Subject: [PATCH] add LCIO compatibility preprocessor macros --- CMakeLists.txt | 22 ++++++++++++++++++++++ include/StdHepGenerator.hh | 13 +++++++++++++ src/StdHepGenerator.cc | 5 ++++- src/TrackSummary.cc | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2301c8..77ba635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,28 @@ ELSE() # include directories INCLUDE_DIRECTORIES( ${XERCES_INCLUDE_DIR} ${LCIO_INCLUDE_DIRS} ${Geant4_INCLUDE_DIRS} ${GDML_INCLUDE_DIR} ${LCDD_INCLUDE_DIR} ${HEPPDT_INCLUDE_DIR} ) + # check for LCStdHepRdrNew class in LCIO + IF ( EXISTS "${LCIO_INCLUDE_DIRS}/UTIL/LCStdHepRdrNew.h" ) + ADD_DEFINITIONS( -DHAVE_STDHEPRDRNEW_H ) + ENDIF() + + # check if MCParticle implementation has endpoint momentum + SET( CMAKE_REQUIRED_INCLUDES ${LCIO_INCLUDE_DIRS} ) + INCLUDE(CheckCXXSourceCompiles) + CHECK_CXX_SOURCE_COMPILES( + " + #include \"EVENT/MCParticle.h\" + int main() { + EVENT::MCParticle* p; + p->getMomentumAtEndpoint(); + return 0; + } + " MCPARTICLE_HAS_MOMENTUMATENDPOINT + ) + IF ( MCPARTICLE_HAS_MOMENTUMATENDPOINT ) + ADD_DEFINITIONS( -DMCPARTICLE_HAS_MOMENTUMATENDPOINT ) + ENDIF() + # libraries TARGET_LINK_LIBRARIES( slic ${XERCES_LIBRARY} ${Geant4_LIBRARIES} ${GDML_LIBRARY} ${LCDD_LIBRARY} ${HEPPDT_LIBRARIES} ${LCIO_LIBRARIES} slicPlugins ) diff --git a/include/StdHepGenerator.hh b/include/StdHepGenerator.hh index d4b933a..a546cb2 100644 --- a/include/StdHepGenerator.hh +++ b/include/StdHepGenerator.hh @@ -5,7 +5,11 @@ #include "MCParticleManager.hh" // LCIO +#if HAVE_LCSTDHEPRDRNEW_H #include "UTIL/LCStdHepRdrNew.h" +#else +#include "UTIL/LCStdHepRdr.h" +#endif #include "EVENT/MCParticle.h" #include "IMPL/LCCollectionVec.h" @@ -16,7 +20,12 @@ // STL #include <set> +#if HAVE_LCSTDHEPRDRNEW_H using UTIL::LCStdHepRdrNew; +#else +using UTIL::LCStdHepRdr; +#endif + using EVENT::MCParticle; using EVENT::LCCollection; using IMPL::LCCollectionVec; @@ -60,7 +69,11 @@ public: LCCollectionVec* getCurrentParticleCollection(); private: +#if HAVE_LCSTDHEPRDRNEW_H LCStdHepRdrNew* _reader; +#else + LCStdHepRdr* _reader; +#endif LCCollectionVec* _particles; }; diff --git a/src/StdHepGenerator.cc b/src/StdHepGenerator.cc index 0c46005..e8d21c7 100644 --- a/src/StdHepGenerator.cc +++ b/src/StdHepGenerator.cc @@ -9,7 +9,6 @@ // Geant4 #include "G4SystemOfUnits.hh" -using UTIL::LCStdHepRdrNew; using EVENT::MCParticle; using EVENT::LCCollection; using IMPL::MCParticleImpl; @@ -18,7 +17,11 @@ namespace slic { StdHepGenerator::StdHepGenerator(G4String eventFile) : _particles(0) { +#if HAVE_LCSTDHEPRDRNEW_H _reader = new LCStdHepRdrNew(eventFile.data()); +#else + _reader = new LCStdHepRdr(eventFile.data()); +#endif } StdHepGenerator::~StdHepGenerator() { diff --git a/src/TrackSummary.cc b/src/TrackSummary.cc index 1105413..3bdd361 100644 --- a/src/TrackSummary.cc +++ b/src/TrackSummary.cc @@ -227,11 +227,13 @@ void TrackSummary::buildMCParticle() { _mcparticle->setTime(_globalTime); /* Set momentum at endpoint. */ +#ifdef MCPARTICLE_HAS_MOMENTUMATENDPOINT float momentumAtEndpoint[3]; momentumAtEndpoint[0] = _momentumAtEndpoint(0) / GeV; momentumAtEndpoint[1] = _momentumAtEndpoint(1) / GeV; momentumAtEndpoint[2] = _momentumAtEndpoint(2) / GeV; _mcparticle->setMomentumAtEndpoint(momentumAtEndpoint); +#endif /* Set up to date. */ _mcParticleIsUpToDate = true; -- GitLab