IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ff34f19a authored by ralfulrich's avatar ralfulrich
Browse files

added Particles to namespace-headers

parent 0923a571
No related branches found
No related tags found
No related merge requests found
......@@ -20,24 +20,37 @@ endfunction (CORSIKA_PREPEND_PATH)
#
# if needed, create symbolic links from the source files to this build-directory location
#
# any path information from input filenames is stripped, IF path was specified it is used for the link destination, if NOT the link is relative to the CMAKE_CURRENT_SOURCE_DIR
#
function (CORSIKA_COPY_HEADERS_TO_NAMESPACE for_library in_namespace)
CORSIKA_PREPEND_PATH (HEADERS_BUILD "${PROJECT_BINARY_DIR}/include/${in_namespace}" ${ARGN})
set (HEADERS_BUILD "")
foreach (HEADER ${ARGN})
# find eventual path, and handle it specificly
get_filename_component (barename ${HEADER} NAME)
get_filename_component (baredir ${HEADER} DIRECTORY)
# remove path, prepend build-directory destination
list (APPEND HEADERS_BUILD "${PROJECT_BINARY_DIR}/include/${in_namespace}/${barename}")
# define source location, use path if specified, otherwise CMAKE_CURRENT_SOURCE_DIR
set (FROM_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT "${baredir}" STREQUAL "")
set (FROM_DIR ${baredir})
endif ()
# define command to perform the symbolic linking
add_custom_command (
OUTPUT ${PROJECT_BINARY_DIR}/include/${in_namespace}/${HEADER}
OUTPUT ${PROJECT_BINARY_DIR}/include/${in_namespace}/${barename}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/include/${in_namespace}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} ${PROJECT_BINARY_DIR}/include/${in_namespace}/${HEADER}
COMMENT "Generate link: ${PROJECT_BINARY_DIR}/include/${in_namespace}/${HEADER}"
# VERBATIM
COMMAND ${CMAKE_COMMAND} -E create_symlink ${FROM_DIR}/${barename} ${PROJECT_BINARY_DIR}/include/${in_namespace}/${barename}
COMMENT "Generate link: ${PROJECT_BINARY_DIR}/include/${in_namespace}/${barename}"
)
endforeach (HEADER)
# main target for this library, depends on header files in build area
# main target for this build step, depends on header files in build area
add_custom_target (
${for_library}_BUILD
DEPENDS ${HEADERS_BUILD}
)
# connect the _BUILD target to the main (external) target
add_dependencies (${for_library} ${for_library}_BUILD)
endfunction (CORSIKA_COPY_HEADERS_TO_NAMESPACE)
......
add_custom_command (
OUTPUT
${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc
COMMAND
${PROJECT_SOURCE_DIR}/Framework/Particles/pdxml_reader.py ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleData.xml ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleClassNames.xml
OUTPUT ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc
COMMAND ${PROJECT_SOURCE_DIR}/Framework/Particles/pdxml_reader.py ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleData.xml ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleClassNames.xml
DEPENDS
pdxml_reader.py
ParticleData.xml
ParticleClassNames.xml
WORKING_DIRECTORY
${PROJECT_BINARY_DIR}/Framework/Particles/
COMMENT
"Read PYTHIA8 particle data and produce C++ source code GeneratedParticleProperties.inc"
COMMENT "Read PYTHIA8 particle data and produce C++ source code GeneratedParticleProperties.inc"
VERBATIM
)
#set (PARTICLES_SOURCES )
# all public header files of library, includes automatic generated file(s)
set (
PARTICLE_HEADERS
Particles.h
${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc
${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc # this one is auto-generated
)
add_library (CORSIKAparticles INTERFACE)
# we need 2nd list with just the header files from the source code directory
set (
PARTICLE_HEADERS_SOURCE
Particles.h
)
#set_target_properties (CORSIKAparticles PROPERTIES VERSION ${PROJECT_VERSION})
#set_target_properties (CORSIKAparticles PROPERTIES SOVERSION 1)
set (
PARTICLE_NAMESPACE
fwk
)
#set_target_properties (CORSIKAparticles PROPERTIES PUBLIC_HEADER "${PARTICLES_HEADERS}")
# target dependencies on other libraries (also header only)
#target_link_libraries (CORSIKAparticles CORSIKAunits)
add_library (CORSIKAparticles INTERFACE)
#target_include_directories (CORSIKAparticles PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories (
CORSIKAparticles
INTERFACE
${EIGEN3_INCLUDE_DIR}
)
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAparticles ${PARTICLE_NAMESPACE} ${PARTICLE_HEADERS})
target_include_directories (
CORSIKAparticles
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
# ${EIGEN3_INCLUDE_DIR}
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
#install (TARGETS CORSIKAparticles
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib
# PUBLIC_HEADER DESTINATION include/Particles)
install (
FILES
${PARTICLE_HEADERS}
......@@ -60,7 +49,8 @@ install (
include/Particles
)
# code testing
# --------------------
# code unit testing
add_executable (
testParticles
testParticles.cc
......
......@@ -5,41 +5,45 @@
#include <cstdint>
#include <iostream>
#include <Particles/GeneratedParticleProperties.inc>
#include <fwk/GeneratedParticleProperties.inc>
namespace ParticleProperties {
namespace fwk {
auto constexpr GetMass(InternalParticleCode const p)
{
return masses[static_cast<uint8_t const>(p)];
}
auto constexpr GetPDG(InternalParticleCode const p)
{
return pdg_codes[static_cast<uint8_t const>(p)];
}
auto constexpr GetElectricChargeQN(InternalParticleCode const p)
{
return electric_charge[static_cast<uint8_t const>(p)];
}
auto constexpr GetElectricCharge(InternalParticleCode const p)
{
return GetElectricChargeQN(p) * (phys::units::e / 3.);
}
auto const GetName(InternalParticleCode const p)
{
return names[static_cast<uint8_t const>(p)];
}
std::ostream& operator<< (std::ostream& stream, InternalParticleCode const p)
namespace particle {
auto constexpr GetMass(InternalParticleCode const p)
{
return masses[static_cast<uint8_t const>(p)];
}
auto constexpr GetPDG(InternalParticleCode const p)
{
return pdg_codes[static_cast<uint8_t const>(p)];
}
auto constexpr GetElectricChargeQN(InternalParticleCode const p)
{
return electric_charge[static_cast<uint8_t const>(p)];
}
auto constexpr GetElectricCharge(InternalParticleCode const p)
{
return GetElectricChargeQN(p) * (phys::units::e / 3.);
}
auto const GetName(InternalParticleCode const p)
{
stream << GetName(p);
return stream;
return names[static_cast<uint8_t const>(p)];
}
std::ostream& operator<< (std::ostream& stream, InternalParticleCode const p)
{
stream << GetName(p);
return stream;
}
}
} // end namespace
} // end namespace
#endif
......@@ -205,7 +205,8 @@ def gen_classes(pythia_db):
string += "\n";
string += "/** @class " + cname + "\n"
string += "*/\n\n"
string += "struct " + cname + "{\n"
string += "class " + cname + "{\n"
string += " public:\n"
string += " static InternalParticleCode GetType() { return Type; }\n"
string += " static quantity<energy_d> GetMass() { return masses[TypeIndex]; }\n"
string += " static quantity<electric_charge_d> GetCharge() { return phys::units::e*electric_charge[TypeIndex]/3; }\n"
......@@ -233,7 +234,8 @@ def inc_start():
string += "#include <iostream>\n\n"
string += "using namespace phys::units;\n"
string += "using namespace phys::units::literals;\n\n"
string += "namespace ParticleProperties {\n\n"
string += "namespace fwk { \n\n"
string += "namespace particle { \n\n"
string += "typedef int16_t PDGCode;\n\n"
return string
......@@ -245,6 +247,7 @@ def inc_start():
def inc_end():
string = ""
string += "\n}\n\n"
string += "\n}\n\n"
string += "#endif\n"
return string
......
......@@ -3,12 +3,12 @@
#include <Units/PhysicalUnits.h>
#include <Particles/Particles.h>
#include <fwk/Particles.h>
using namespace phys::units;
using namespace phys::units::literals;
using namespace ParticleProperties;
using namespace fwk::particle;
TEST_CASE( "Particles", "[Particles]" )
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment