From 64c1a821f9ca40b213c7c963049fa0d76c83a86d Mon Sep 17 00:00:00 2001 From: Valerio Pia <vpia@bo.infn.it> Date: Fri, 14 Apr 2023 12:29:30 +0000 Subject: [PATCH 1/2] Small naming changes --- examples/EDEPReader.cpp | 4 ++-- include/EDEPTree.h | 9 ++++----- src/EDEPTree.cpp | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/EDEPReader.cpp b/examples/EDEPReader.cpp index 9f40f29..54ec455 100644 --- a/examples/EDEPReader.cpp +++ b/examples/EDEPReader.cpp @@ -68,9 +68,9 @@ int main(int argc, char *argv[]) std::cout << "Is trj with id 1 in the trajectory with id 6? -> " << tree.IsTrajectoryIn(1, tree.GetTrajectory(6)) << std::endl; std::cout << "########### Selecting the trajectory having a child with id 23" << std::endl; - tree.GetTrajectoryWithChild(23)->Print(); + tree.GetParentOf(23)->Print(); std::cout << "########### Selecting the trajectory having a child with id 25 only if it is a child of trajectory 6" << std::endl; - tree.GetTrajectoryWithChildFrom(25, tree.GetTrajectory(6))->Print(); + tree.GetParentOf(25, tree.GetTrajectory(6))->Print(); std::cout << "########### Removing trajectory 3" << std::endl; tree.RemoveTrajectory(3); diff --git a/include/EDEPTree.h b/include/EDEPTree.h index 5306c14..9df3612 100644 --- a/include/EDEPTree.h +++ b/include/EDEPTree.h @@ -94,11 +94,10 @@ class EDEPTree : public EDEPTrajectory { iterator GetTrajectory(int trj_id) {return std::find_if(this->begin(), this->end(), [trj_id](const EDEPTrajectory& trj){ return trj_id == trj.GetId();});} const_iterator GetTrajectory(int trj_id) const {return std::find_if(this->begin(), this->end(), [trj_id](const EDEPTrajectory& trj){ return trj_id == trj.GetId();});} - iterator GetTrajectoryWithChild(int trj_id); - const_iterator GetTrajectoryWithChild(int trj_id) const; - - iterator GetTrajectoryWithChildFrom(int trj_id, iterator it); - const_iterator GetTrajectoryWithChildFrom(int trj_id, const_iterator it) const; + iterator GetParentOf(int trj_id); + const_iterator GetParentOf(int trj_id) const; + iterator GetParentOf(int trj_id, iterator it); + const_iterator GetParentOf(int trj_id, const_iterator it) const; iterator GetTrajectoryFrom(int trj_id, iterator it); const_iterator GetTrajectoryFrom(int trj_id, const_iterator it) const; diff --git a/src/EDEPTree.cpp b/src/EDEPTree.cpp index b4710d4..36db189 100644 --- a/src/EDEPTree.cpp +++ b/src/EDEPTree.cpp @@ -122,11 +122,11 @@ void EDEPTree::AddTrajectoryTo(const EDEPTrajectory& trajectory, iterator it) { } void EDEPTree::RemoveTrajectory(int trj_id) { - GetTrajectoryWithChild(trj_id)->RemoveChildWithId(trj_id); + GetParentOf(trj_id)->RemoveChildWithId(trj_id); } void EDEPTree::RemoveTrajectoryFrom(int trj_id, iterator it) { - GetTrajectoryWithChildFrom(trj_id, it)->RemoveChildWithId(trj_id); + GetParentOf(trj_id, it)->RemoveChildWithId(trj_id); } void EDEPTree::MoveTrajectoryTo(int id_to_move, int next_parent_id) { @@ -152,24 +152,24 @@ bool EDEPTree::IsTrajectoryIn(int trj_id, const_iterator it) const { return (found_it != end_it) ? true : false; } -EDEPTree::iterator EDEPTree::GetTrajectoryWithChild(int trj_id) { +EDEPTree::iterator EDEPTree::GetParentOf(int trj_id) { auto f = [trj_id](const EDEPTrajectory& trj){ for (const auto& t:trj.GetChildrenTrajectories()) { if (trj_id == t.GetId()) return true;}; return false;}; return std::find_if(this->begin(), this->end(), f); } -EDEPTree::const_iterator EDEPTree::GetTrajectoryWithChild(int trj_id) const { +EDEPTree::const_iterator EDEPTree::GetParentOf(int trj_id) const { auto f = [trj_id](const EDEPTrajectory& trj){ for (const auto& t:trj.GetChildrenTrajectories()) { if (trj_id == t.GetId()) return true;}; return false;}; return std::find_if(this->begin(), this->end(), f); } -EDEPTree::iterator EDEPTree::GetTrajectoryWithChildFrom(int trj_id, iterator it) { +EDEPTree::iterator EDEPTree::GetParentOf(int trj_id, iterator it) { EDEPTree::iterator end_it = GetTrajectoryEnd(it); auto f = [trj_id](const EDEPTrajectory& trj){ for (const auto& t:trj.GetChildrenTrajectories()) { if (trj_id == t.GetId()) return true;}; return false;}; EDEPTree::iterator found_it = std::find_if(it, end_it, f); return (found_it != end_it) ? found_it : this->end(); } -EDEPTree::const_iterator EDEPTree::GetTrajectoryWithChildFrom(int tid, const_iterator it) const { +EDEPTree::const_iterator EDEPTree::GetParentOf(int tid, const_iterator it) const { EDEPTree::const_iterator end_it = GetTrajectoryEnd(it); auto f = [tid](const EDEPTrajectory& trj){ for (const auto& t:trj.GetChildrenTrajectories()) { if (tid == t.GetId()) return true;}; return false;}; EDEPTree::const_iterator found_it = std::find_if(it, end_it, f); -- GitLab From bd5c46aeb7968fc1c285110ce16263cfa1a3df15 Mon Sep 17 00:00:00 2001 From: Valerio Pia <vpia@bo.infn.it> Date: Fri, 14 Apr 2023 16:49:15 +0000 Subject: [PATCH 2/2] Updated CMakeFile --- .gitignore | 30 ++++++++++++++++ CMakeLists.txt | 74 +++++++++++++++++++++++++++------------- PackageConfig.cmake.in | 41 ++++++++++++++++++++++ examples/CMakeLists.txt | 41 ++++++++++++++++++++++ include/EDEPTrajectory.h | 1 - include/EDEPTree.h | 2 -- setup.sh | 9 ++--- 7 files changed, 168 insertions(+), 30 deletions(-) create mode 100644 PackageConfig.cmake.in create mode 100644 examples/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 657dc2e..938caf6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,33 @@ build/* .vscode/* install/* +examples/build/cmake_install.cmake +examples/build/CMakeCache.txt +examples/build/install_manifest.txt +examples/build/Makefile +examples/build/CMakeFiles/cmake.check_cache +examples/build/CMakeFiles/CMakeDirectoryInformation.cmake +examples/build/CMakeFiles/CMakeOutput.log +examples/build/CMakeFiles/feature_tests.bin +examples/build/CMakeFiles/feature_tests.cxx +examples/build/CMakeFiles/Makefile.cmake +examples/build/CMakeFiles/Makefile2 +examples/build/CMakeFiles/progress.marks +examples/build/CMakeFiles/TargetDirectories.txt +examples/build/CMakeFiles/3.17.0-rc2/CMakeCXXCompiler.cmake +examples/build/CMakeFiles/3.17.0-rc2/CMakeDetermineCompilerABI_CXX.bin +examples/build/CMakeFiles/3.17.0-rc2/CMakeSystem.cmake +examples/build/CMakeFiles/3.17.0-rc2/CompilerIdCXX/a.out +examples/build/CMakeFiles/3.17.0-rc2/CompilerIdCXX/CMakeCXXCompilerId.cpp +examples/build/CMakeFiles/EDEPReader.dir/build.make +examples/build/CMakeFiles/EDEPReader.dir/cmake_clean.cmake +examples/build/CMakeFiles/EDEPReader.dir/CXX.includecache +examples/build/CMakeFiles/EDEPReader.dir/depend.internal +examples/build/CMakeFiles/EDEPReader.dir/depend.make +examples/build/CMakeFiles/EDEPReader.dir/DependInfo.cmake +examples/build/CMakeFiles/EDEPReader.dir/EDEPReader.cpp.o +examples/build/CMakeFiles/EDEPReader.dir/flags.make +examples/build/CMakeFiles/EDEPReader.dir/link.txt +examples/build/CMakeFiles/EDEPReader.dir/progress.make +examples/build/bin/EDEPReader +examples/install/bin/EDEPReader diff --git a/CMakeLists.txt b/CMakeLists.txt index 65bf1a6..76893eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,11 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) -project(STTTrackReco LANGUAGES CXX) +project(EDEPTree LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_PLATFORM_INDEPENDENT_CODE ON) -# Locate the ROOT package and define a number of useful targets and variables. -find_package(ROOT REQUIRED COMPONENTS RIO Net) - # Locate EDep-sim find_package(EDepSim) @@ -21,35 +18,37 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -# EDEPHit library -add_library(EDEPHit SHARED src/EDEPHit.cpp) -target_link_libraries(EDEPHit PUBLIC EDepSim::edepsim_io) - -# EDEPTrajectory library -add_library(EDEPTrajectory SHARED src/EDEPTrajectory.cpp) -target_link_libraries(EDEPTrajectory PUBLIC EDepSim::edepsim_io EDEPHit) - -# EDEPTree library -add_library(EDEPTree SHARED src/EDEPTree.cpp) -target_link_libraries(EDEPTree PUBLIC EDEPTrajectory EDepSim::edepsim_io EDEPTrajectory) - +add_library(EDEPTree SHARED src/EDEPTree.cpp src/EDEPTrajectory.cpp src/EDEPHit.cpp) +target_include_directories(EDEPTree PUBLIC + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" + "$<INSTALL_INTERFACE:include>") +target_link_libraries(EDEPTree PUBLIC EDepSim::edepsim_io) -# Creates EDEPReader executable. -add_executable(EDEPReader examples/EDEPReader.cpp) -target_link_libraries(EDEPReader PUBLIC EDepSim::edepsim_io EDEPTree EDEPTrajectory EDEPHit) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE) endif() -install(TARGETS EDEPReader EDEPTree EDEPTrajectory EDEPHit - EXPORT EDEPTargets +configure_file(setup.sh "${CMAKE_INSTALL_PREFIX}/setup.sh" COPYONLY) + +install(TARGETS EDEPTree + EXPORT EDEPTreeTargets RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") install( - DIRECTORY include + DIRECTORY "${CMAKE_BINARY_DIR}/." + DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" + FILES_MATCHING + PATTERN "*.pcm" + PATTERN "*.rootmap" + PATTERN "lib" EXCLUDE + PATTERN "bin" EXCLUDE + PATTERN "CMakeFiles" EXCLUDE) + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION "${CMAKE_INSTALL_PREFIX}" PATTERN "Linkdef.h" EXCLUDE) @@ -59,4 +58,33 @@ install( # ############################################################# -# Coming soon? +# Include module with function 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Build the targets description so that the package can be configured +# using find_package. +install(EXPORT EDEPTreeTargets + NAMESPACE EDEPTree:: + DESTINATION lib/cmake/EDEPTree) + +# Write the 'EDEPTreeConfigVersion.cmake' file which can be used to +# check if a version meets the requested properties. +write_basic_package_version_file( + EDEPTreeConfigVersion.cmake + VERSION 1.2.3 + COMPATIBILITY SameMajorVersion) + +# Write the 'EDEPTreeConfig.cmake' file so that a user package can +# access this with find_package. +configure_package_config_file( + PackageConfig.cmake.in + EDEPTreeConfig.cmake + PATH_VARS CMAKE_INSTALL_PREFIX + INSTALL_DESTINATION lib/cmake/EDEPTree) + +# Install the config files. +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/EDEPTreeConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/EDEPTreeConfigVersion.cmake + DESTINATION lib/cmake/EDEPTree ) + diff --git a/PackageConfig.cmake.in b/PackageConfig.cmake.in new file mode 100644 index 0000000..07ec3b8 --- /dev/null +++ b/PackageConfig.cmake.in @@ -0,0 +1,41 @@ +########################## +# A template for a <package>Config.cmake that can be found by using +# the find_package macro. This should be modified to import all of +# the dependencies required by the local package. The template is +# fairly generic, except for the "find_package" related code between +# the beginning and ending boiler plate. +# +# This expect that any targets that are being exported will be +# installed using a command like +# +# install(TARGETS myTarget +# EXPORT <project>Targets +# etc) +# +# Note that the <project> is set in the project(<name> <version>) macro +# that should be at the start of your top level CMakeLists.txt +########################## + +############# BOILER PLATE +# Include the cmake boiler plate. The next line should not be touched +@PACKAGE_INIT@ +############# END BOILER PLATE + +########################## +# Add any specific packages that the current package depends on. This is +# where the find_package commands needed to make the current package +# compile should be listed. +########################## + +# EDEPReader needs EDepSim +find_package(EDepSim REQUIRED) + +######################### +# Leave the next couple of lines alone since it will automatically customize +# for your package. +######################### + +############# BOILER PLATE +include("@CMAKE_INSTALL_PREFIX@/lib/cmake/@PROJECT_NAME@/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") +############# END BOILER PLATE \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..19f932c --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.0 FATAL_ERROR) +if(${CMAKE_VERSION} VERSION_LESS 3.12) + cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +endif() + +project(EDEPReader LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_PLATFORM_INDEPENDENT_CODE ON) + +# Locate EDep-sim +find_package(EDepSim) + +find_library(EDEPTree NAMES EDEPTree PATHS ENV LD_LIBRARY_PATH) +if(NOT EDEPTree) + message(FATAL_ERROR "Failed to find the EDEPTree library.") +endif() + + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-parameter") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{EDEPTree_DIR}) +message($ENV{EDEPTree_DIR}) + +# set output directory +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + +# Creates EDEPReader executable. +add_executable(EDEPReader EDEPReader.cpp) +target_link_libraries(EDEPReader PUBLIC EDepSim::edepsim_io ${EDEPTree}) + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "default install path" FORCE) +endif() + +install(TARGETS EDEPReader DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") + diff --git a/include/EDEPTrajectory.h b/include/EDEPTrajectory.h index 67c8b35..c434d06 100644 --- a/include/EDEPTrajectory.h +++ b/include/EDEPTrajectory.h @@ -4,7 +4,6 @@ #include <iostream> #include "TString.h" -#include <TG4Event.h> #include "EDEPHit.h" diff --git a/include/EDEPTree.h b/include/EDEPTree.h index 9df3612..750ac54 100644 --- a/include/EDEPTree.h +++ b/include/EDEPTree.h @@ -1,7 +1,5 @@ #include <iostream> -#include "TG4Event.h" - #include "EDEPTrajectory.h" #include "utils.h" diff --git a/setup.sh b/setup.sh index 5ec2b23..0d334b7 100644 --- a/setup.sh +++ b/setup.sh @@ -1,7 +1,8 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +echo $DIR -# SAND-RECO -export PATH=${DIR}/install/bin:${PATH} -export LD_LIBRARY_PATH=${DIR}/install/lib:${LD_LIBRARY_PATH} -export EDEPReader_DIR=${DIR} +# EDEPTree +export PATH=${DIR}/bin:${PATH} +export LD_LIBRARY_PATH=${DIR}/lib:${LD_LIBRARY_PATH} +export EDEPTree_DIR=${DIR}/include -- GitLab