mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-05 23:11:31 +01:00
switch to git no-history version
This commit is contained in:
8
AUTHORS
Normal file
8
AUTHORS
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* CMT - Written and Mantained by:
|
||||||
|
*
|
||||||
|
* A. Rigoni ( andrea.rigoni@pd.infn.it )
|
||||||
|
* M. Furlan ( matteo.furlan@pd.infn.it )
|
||||||
|
* S. Vanini ( sara.vanini@pd.infn.it )
|
||||||
|
*
|
||||||
|
**/
|
||||||
81
CMake/FindEigen3.cmake
Normal file
81
CMake/FindEigen3.cmake
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# - Try to find Eigen3 lib
|
||||||
|
#
|
||||||
|
# This module supports requiring a minimum version, e.g. you can do
|
||||||
|
# find_package(Eigen3 3.1.2)
|
||||||
|
# to require version 3.1.2 or newer of Eigen3.
|
||||||
|
#
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# EIGEN3_FOUND - system has eigen lib with correct version
|
||||||
|
# EIGEN3_INCLUDE_DIR - the eigen include directory
|
||||||
|
# EIGEN3_VERSION - eigen version
|
||||||
|
|
||||||
|
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
||||||
|
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
|
||||||
|
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
||||||
|
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
|
||||||
|
|
||||||
|
if(NOT Eigen3_FIND_VERSION)
|
||||||
|
if(NOT Eigen3_FIND_VERSION_MAJOR)
|
||||||
|
set(Eigen3_FIND_VERSION_MAJOR 2)
|
||||||
|
endif(NOT Eigen3_FIND_VERSION_MAJOR)
|
||||||
|
if(NOT Eigen3_FIND_VERSION_MINOR)
|
||||||
|
set(Eigen3_FIND_VERSION_MINOR 91)
|
||||||
|
endif(NOT Eigen3_FIND_VERSION_MINOR)
|
||||||
|
if(NOT Eigen3_FIND_VERSION_PATCH)
|
||||||
|
set(Eigen3_FIND_VERSION_PATCH 0)
|
||||||
|
endif(NOT Eigen3_FIND_VERSION_PATCH)
|
||||||
|
|
||||||
|
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
|
||||||
|
endif(NOT Eigen3_FIND_VERSION)
|
||||||
|
|
||||||
|
macro(_eigen3_check_version)
|
||||||
|
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
|
||||||
|
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
|
||||||
|
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
|
||||||
|
|
||||||
|
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
|
||||||
|
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||||
|
set(EIGEN3_VERSION_OK FALSE)
|
||||||
|
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||||
|
set(EIGEN3_VERSION_OK TRUE)
|
||||||
|
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
|
||||||
|
|
||||||
|
if(NOT EIGEN3_VERSION_OK)
|
||||||
|
|
||||||
|
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
|
||||||
|
"but at least version ${Eigen3_FIND_VERSION} is required")
|
||||||
|
endif(NOT EIGEN3_VERSION_OK)
|
||||||
|
endmacro(_eigen3_check_version)
|
||||||
|
|
||||||
|
if (EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
# in cache already
|
||||||
|
_eigen3_check_version()
|
||||||
|
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
|
||||||
|
|
||||||
|
else (EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
|
||||||
|
PATHS
|
||||||
|
${CMAKE_INSTALL_PREFIX}/include
|
||||||
|
${KDE4_INCLUDE_DIR}
|
||||||
|
PATH_SUFFIXES eigen3 eigen
|
||||||
|
)
|
||||||
|
|
||||||
|
if(EIGEN3_INCLUDE_DIR)
|
||||||
|
_eigen3_check_version()
|
||||||
|
endif(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
|
||||||
|
|
||||||
|
mark_as_advanced(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
|
endif(EIGEN3_INCLUDE_DIR)
|
||||||
|
|
||||||
63
CMake/FindGEANT4.cmake
Normal file
63
CMake/FindGEANT4.cmake
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# - Try to find GEANT4
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# GEANT4_FOUND - system has GEANT4
|
||||||
|
# GEANT4_INCLUDE_DIR - the GEANT4 include directory
|
||||||
|
# GEANT4_LIBRARIES - The libraries needed to use GEANT4
|
||||||
|
# GEANT4_DEFINITIONS - Compiler switches required for using GEANT4
|
||||||
|
#
|
||||||
|
|
||||||
|
if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||||
|
SET (GEANT4_INCLUDE_DIR GEANT4_INCLUDE_DIR-NOTFOUND)
|
||||||
|
SET (GEANT4_LIB_DIR GEANT4_LIB_DIR-NOTFOUND)
|
||||||
|
SET (GEANT4_PLISTS_LIB_DIR GEANT4_PLISTS_LIB_DIR-NOTFOUND)
|
||||||
|
SET (GEANT4_DIR GEANT4_DIR-NOTFOUND)
|
||||||
|
endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||||
|
|
||||||
|
MESSAGE(STATUS "Looking for GEANT4...")
|
||||||
|
|
||||||
|
FIND_PATH(GEANT4_DIR NAMES env.sh PATHS
|
||||||
|
${SIMPATH}/transport/geant4
|
||||||
|
${SIMPATH}/transport/geant4/source
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
FIND_PATH(GEANT4_INCLUDE_DIR NAMES G4Event.hh PATHS
|
||||||
|
${SIMPATH}/transport/geant4/include
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(GEANT4_INCLUDE_DIR
|
||||||
|
${SIMPATH}/transport/geant4/include
|
||||||
|
${SIMPATH}/transport/geant4/source/interfaces/common/include
|
||||||
|
${SIMPATH}/transport/geant4/physics_lists/hadronic/Packaging/include
|
||||||
|
${SIMPATH}/transport/geant4/physics_lists/hadronic/QGSP/include
|
||||||
|
)
|
||||||
|
|
||||||
|
FIND_PATH(GEANT4_LIB_DIR NAMES libG4baryons.so libG4baryons.dylib PATHS
|
||||||
|
${SIMPATH}/transport/geant4/lib/Linux-g++
|
||||||
|
${SIMPATH}/transport/geant4/lib/Linux-icc
|
||||||
|
${SIMPATH}/transport/geant4/lib
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
IF (GEANT4_LIB_DIR)
|
||||||
|
SET(GEANT4_LIBRARY_DIR ${GEANT4_LIB_DIR})
|
||||||
|
ENDIF (GEANT4_LIB_DIR)
|
||||||
|
|
||||||
|
if (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||||
|
set(GEANT4_FOUND TRUE)
|
||||||
|
endif (GEANT4_INCLUDE_DIR AND GEANT4_LIBRARY_DIR)
|
||||||
|
|
||||||
|
if (GEANT4_FOUND)
|
||||||
|
if (NOT GEANT4_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Looking for GEANT4... - found ${GEANT4_LIBRARY_DIR}")
|
||||||
|
# message(STATUS "Found ${GEANT4_LIBRARY_DIR}")
|
||||||
|
endif (NOT GEANT4_FIND_QUIETLY)
|
||||||
|
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4_LIBRARY_DIR})
|
||||||
|
else (GEANT4_FOUND)
|
||||||
|
if (GEANT4_FIND_REQUIRED)
|
||||||
|
message(FATAL_ERROR "Looking for GEANT4... - Not found")
|
||||||
|
endif (GEANT4_FIND_REQUIRED)
|
||||||
|
endif (GEANT4_FOUND)
|
||||||
|
|
||||||
97
CMake/FindGEANT4VMC.cmake
Normal file
97
CMake/FindGEANT4VMC.cmake
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
# - Try to find GEANT4VMC
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# GEANT4VMC_FOUND - system has GEANT3
|
||||||
|
# GEANT4VMC_INCLUDE_DIR - the GEANT3 include directory
|
||||||
|
# GEANT4VMC_LIBRARIES - The libraries needed to use GEANT3
|
||||||
|
# GEANT4VMC_DEFINITIONS - Compiler switches required for using GEANT3
|
||||||
|
#
|
||||||
|
|
||||||
|
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||||
|
SET (GEANT4VMC_INCLUDE_DIR GEANT4VMC_INCLUDE_DIR-NOTFOUND)
|
||||||
|
SET (GEANT4VMC_LIB_DIR GEANT4VMC_LIB_DIR-NOTFOUND)
|
||||||
|
SET (GEANT4VMC_PLISTS_LIB_DIR GEANT4VMC_PLISTS_LIB_DIR-NOTFOUND)
|
||||||
|
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||||
|
|
||||||
|
MESSAGE(STATUS "Looking for GEANT4VMC...")
|
||||||
|
|
||||||
|
FIND_PATH(GEANT4VMC_INCLUDE_DIR NAMES TG4G3Units.h PATHS
|
||||||
|
${SIMPATH}/transport/geant4_vmc/include
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
set(GEANT4VMC_INCLUDE_DIR
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/global/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/geometry/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/digits+hits/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/physics/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/event/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/run/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/interfaces/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/source/visualization/include
|
||||||
|
${SIMPATH}/transport/geant4_vmc/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/BaseVGM/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/ClhepVGM/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/Geant4GM/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/RootGM/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/VGM/include
|
||||||
|
${SIMPATH}/transport/vgm/packages/XmlVGM/include
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
FIND_PATH(GEANT4VMC_LIBRARY_DIR NAMES libgeant4vmc.so libgeant4vmc.dylib PATHS
|
||||||
|
${SIMPATH}/transport/geant4_vmc/lib/tgt_linux
|
||||||
|
${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxicc
|
||||||
|
${SIMPATH}/transport/geant4_vmc/lib/tgt_linuxx8664gcc
|
||||||
|
${SIMPATH}/transport/geant4_vmc/lib
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
# check for existence of header file, which is needed in CbmRunConfiguration
|
||||||
|
# The file is only present in old versions of VMC
|
||||||
|
FIND_FILE(GEANT4_MODULAR_PHYSICS_LIST TG4ModularPhysicsList.h PATHS
|
||||||
|
${GEANT4VMC_INCLUDE_DIR}
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||||
|
if (NOT GEANT4VMC_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Looking for GEANT4VMC... - found ${GEANT4VMC_LIBRARY_DIR}")
|
||||||
|
endif (NOT GEANT4VMC_FIND_QUIETLY)
|
||||||
|
else (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||||
|
if (GEANT4VMC_FIND_REQUIRED)
|
||||||
|
message(FATAL_ERROR "Looking for GEANT4VMC... - Not found ")
|
||||||
|
endif (GEANT4VMC_FIND_REQUIRED)
|
||||||
|
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
MESSAGE(STATUS "Looking for VGM...")
|
||||||
|
|
||||||
|
FIND_PATH(VGM_LIBRARY_DIR NAMES libBaseVGM.so libBaseVGM.dylib PATHS
|
||||||
|
${SIMPATH}/transport/vgm/lib/Linux-g++
|
||||||
|
${SIMPATH}/transport/vgm.2.08.04/lib/Linux-g++
|
||||||
|
${SIMPATH}/transport/vgm/lib/Linux-icc
|
||||||
|
${SIMPATH}/transport/vgm/lib
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
if (VGM_LIBRARY_DIR)
|
||||||
|
if (NOT GEANT4VMC_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Looking for VGM... - found ${VGM_LIBRARY_DIR}")
|
||||||
|
endif (NOT GEANT4VMC_FIND_QUIETLY)
|
||||||
|
else (VGM_LIBRARY_DIR)
|
||||||
|
if (GEANT4VMC_FIND_REQUIRED)
|
||||||
|
message(FATAL_ERROR "Looking for VGM... - Not found ")
|
||||||
|
endif (GEANT4VMC_FIND_REQUIRED)
|
||||||
|
endif (VGM_LIBRARY_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
if (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR)
|
||||||
|
set(GEANT4VMC_FOUND TRUE)
|
||||||
|
endif (GEANT4VMC_INCLUDE_DIR AND GEANT4VMC_LIBRARY_DIR AND VGM_LIBRARY_DIR)
|
||||||
|
|
||||||
|
if (GEANT4VMC_FOUND)
|
||||||
|
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${GEANT4VMC_LIBRARY_DIR}
|
||||||
|
${VGM_LIBRARY_DIR})
|
||||||
|
endif (GEANT4VMC_FOUND)
|
||||||
|
|
||||||
280
CMake/FindROOT.cmake
Normal file
280
CMake/FindROOT.cmake
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
# - Find ROOT instalation
|
||||||
|
# This module tries to find the ROOT installation on your system.
|
||||||
|
# It tries to find the root-config script which gives you all the needed information.
|
||||||
|
# If the system variable ROOTSYS is set this is straight forward.
|
||||||
|
# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
|
||||||
|
# If you need an other path you should add this path to this varaible.
|
||||||
|
# The root-config script is then used to detect basically everything else.
|
||||||
|
# This module defines a number of key variables and macros.
|
||||||
|
|
||||||
|
# F.Uhlig@gsi.de (fairroot.gsi.de)
|
||||||
|
|
||||||
|
|
||||||
|
MESSAGE(STATUS "Looking for Root...")
|
||||||
|
|
||||||
|
SET(ROOT_CONFIG_SEARCHPATH
|
||||||
|
/usr/bin
|
||||||
|
/usr/local/bin
|
||||||
|
${SIMPATH}/tools/root/bin
|
||||||
|
$ENV{ROOTSYS}/bin
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(ROOT_DEFINITIONS "")
|
||||||
|
|
||||||
|
SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
|
||||||
|
|
||||||
|
SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
|
||||||
|
|
||||||
|
FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
|
||||||
|
${ROOT_CONFIG_SEARCHPATH}
|
||||||
|
NO_DEFAULT_PATH)
|
||||||
|
|
||||||
|
IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||||
|
MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
|
||||||
|
set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
|
||||||
|
subdirectory cmake/modules.")
|
||||||
|
ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||||
|
STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
|
||||||
|
SET( ENV{ROOTSYS} ${test})
|
||||||
|
set( ROOTSYS ${test})
|
||||||
|
ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
|
||||||
|
|
||||||
|
|
||||||
|
IF (ROOT_CONFIG_EXECUTABLE)
|
||||||
|
|
||||||
|
SET(ROOT_FOUND FALSE)
|
||||||
|
|
||||||
|
EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
|
||||||
|
|
||||||
|
MESSAGE(STATUS "Looking for Root... - found $ENV{ROOTSYS}/bin/root")
|
||||||
|
MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ")
|
||||||
|
|
||||||
|
# we need at least version 5.00/00
|
||||||
|
IF (NOT ROOT_MIN_VERSION)
|
||||||
|
SET(ROOT_MIN_VERSION "5.00/00")
|
||||||
|
ENDIF (NOT ROOT_MIN_VERSION)
|
||||||
|
|
||||||
|
# now parse the parts of the user given version string into variables
|
||||||
|
STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
|
||||||
|
STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
|
||||||
|
STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
|
||||||
|
|
||||||
|
# and now the version string given by qmake
|
||||||
|
STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
|
||||||
|
STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
|
||||||
|
STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
|
||||||
|
|
||||||
|
IF (found_root_major_vers LESS 5)
|
||||||
|
MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
|
||||||
|
ENDIF (found_root_major_vers LESS 5)
|
||||||
|
|
||||||
|
# compute an overall version number which can be compared at once
|
||||||
|
MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
|
||||||
|
MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
|
||||||
|
|
||||||
|
IF (found_vers LESS req_vers)
|
||||||
|
SET(ROOT_FOUND FALSE)
|
||||||
|
SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
|
||||||
|
ELSE (found_vers LESS req_vers)
|
||||||
|
SET(ROOT_FOUND TRUE)
|
||||||
|
ENDIF (found_vers LESS req_vers)
|
||||||
|
|
||||||
|
ENDIF (ROOT_CONFIG_EXECUTABLE)
|
||||||
|
|
||||||
|
|
||||||
|
IF (ROOT_FOUND)
|
||||||
|
|
||||||
|
# ask root-config for the library dir
|
||||||
|
# Set ROOT_LIBRARY_DIR
|
||||||
|
|
||||||
|
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||||
|
ARGS "--libdir"
|
||||||
|
OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
|
||||||
|
|
||||||
|
IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||||
|
SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
|
||||||
|
ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||||
|
MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
|
||||||
|
MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
|
||||||
|
ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
|
||||||
|
|
||||||
|
# ask root-config for the binary dir
|
||||||
|
EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
|
||||||
|
ARGS "--bindir"
|
||||||
|
OUTPUT_VARIABLE root_bins )
|
||||||
|
SET(ROOT_BINARY_DIR ${root_bins})
|
||||||
|
|
||||||
|
# ask root-config for the include dir
|
||||||
|
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||||
|
ARGS "--incdir"
|
||||||
|
OUTPUT_VARIABLE root_headers )
|
||||||
|
SET(ROOT_INCLUDE_DIR ${root_headers})
|
||||||
|
# CACHE INTERNAL "")
|
||||||
|
|
||||||
|
# ask root-config for the library varaibles
|
||||||
|
EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
|
||||||
|
# ARGS "--noldflags --noauxlibs --libs"
|
||||||
|
ARGS "--glibs"
|
||||||
|
OUTPUT_VARIABLE root_flags )
|
||||||
|
|
||||||
|
# STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
|
||||||
|
# STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
|
||||||
|
# REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
|
||||||
|
|
||||||
|
SET(ROOT_LIBRARIES ${root_flags} -lGeom)
|
||||||
|
|
||||||
|
# Make variables changeble to the advanced user
|
||||||
|
MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
|
||||||
|
|
||||||
|
# Set ROOT_INCLUDES
|
||||||
|
SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
|
||||||
|
|
||||||
|
SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
#
|
||||||
|
# Check the executables of ROOT
|
||||||
|
# ( rootcint )
|
||||||
|
#
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
FIND_PROGRAM(ROOT_CINT_EXECUTABLE
|
||||||
|
NAMES rootcint
|
||||||
|
PATHS ${ROOT_BINARY_DIR}
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
ENDIF (ROOT_FOUND)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
#
|
||||||
|
# Macros for building ROOT dictionary
|
||||||
|
#
|
||||||
|
###########################################
|
||||||
|
|
||||||
|
MACRO (ROOT_GENERATE_DICTIONARY_OLD )
|
||||||
|
|
||||||
|
set(INFILES "")
|
||||||
|
|
||||||
|
foreach (_current_FILE ${ARGN})
|
||||||
|
|
||||||
|
IF (${_current_FILE} MATCHES "^.*\\.h$")
|
||||||
|
IF (${_current_FILE} MATCHES "^.*Link.*$")
|
||||||
|
set(LINKDEF_FILE ${_current_FILE})
|
||||||
|
ELSE (${_current_FILE} MATCHES "^.*Link.*$")
|
||||||
|
set(INFILES ${INFILES} ${_current_FILE})
|
||||||
|
ENDIF (${_current_FILE} MATCHES "^.*Link.*$")
|
||||||
|
ELSE (${_current_FILE} MATCHES "^.*\\.h$")
|
||||||
|
IF (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||||
|
set(OUTFILE ${_current_FILE})
|
||||||
|
ELSE (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||||
|
set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
|
||||||
|
ENDIF (${_current_FILE} MATCHES "^.*\\.cxx$")
|
||||||
|
ENDIF (${_current_FILE} MATCHES "^.*\\.h$")
|
||||||
|
|
||||||
|
endforeach (_current_FILE ${ARGN})
|
||||||
|
|
||||||
|
# MESSAGE("INFILES: ${INFILES}")
|
||||||
|
# MESSAGE("OutFILE: ${OUTFILE}")
|
||||||
|
# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
|
||||||
|
# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
|
||||||
|
|
||||||
|
STRING(REGEX REPLACE "(^.*).cxx" "\\1.h" bla "${OUTFILE}")
|
||||||
|
# MESSAGE("BLA: ${bla}")
|
||||||
|
SET (OUTFILES ${OUTFILE} ${bla})
|
||||||
|
|
||||||
|
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||||
|
COMMAND ${ROOT_CINT_EXECUTABLE}
|
||||||
|
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES})
|
||||||
|
|
||||||
|
# MESSAGE("ROOT_CINT_EXECUTABLE has created the dictionary ${OUTFILE}")
|
||||||
|
|
||||||
|
ENDMACRO (ROOT_GENERATE_DICTIONARY_OLD)
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
#
|
||||||
|
# Macros for building ROOT dictionary
|
||||||
|
#
|
||||||
|
###########################################
|
||||||
|
|
||||||
|
MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
|
||||||
|
|
||||||
|
set(INCLUDE_DIRS)
|
||||||
|
|
||||||
|
foreach (_current_FILE ${INCLUDE_DIRS_IN})
|
||||||
|
set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
|
||||||
|
endforeach (_current_FILE ${INCLUDE_DIRS_IN})
|
||||||
|
|
||||||
|
|
||||||
|
# MESSAGE("INFILES: ${INFILES}")
|
||||||
|
# MESSAGE("OutFILE: ${OUTFILE}")
|
||||||
|
# MESSAGE("LINKDEF_FILE: ${LINKDEF_FILE}")
|
||||||
|
# MESSAGE("INCLUDE_DIRS: ${INCLUDE_DIRS}")
|
||||||
|
|
||||||
|
STRING(REGEX REPLACE "^(.*)\\.(.*)$" "\\1.h" bla "${OUTFILE}")
|
||||||
|
# MESSAGE("BLA: ${bla}")
|
||||||
|
SET (OUTFILES ${OUTFILE} ${bla})
|
||||||
|
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||||
|
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||||
|
COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
|
||||||
|
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
|
||||||
|
else (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
|
||||||
|
COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
|
||||||
|
ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
|
||||||
|
endif (CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||||
|
|
||||||
|
ENDMACRO (ROOT_GENERATE_DICTIONARY)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME)
|
||||||
|
|
||||||
|
get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH)
|
||||||
|
get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT)
|
||||||
|
get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE)
|
||||||
|
set(shell_script_name "${file_name}.sh")
|
||||||
|
|
||||||
|
#MESSAGE("PATH: ${path_name}")
|
||||||
|
#MESSAGE("Ext: ${file_extension}")
|
||||||
|
#MESSAGE("Name: ${file_name}")
|
||||||
|
#MESSAGE("Shell Name: ${shell_script_name}")
|
||||||
|
|
||||||
|
string(REPLACE ${PROJECT_SOURCE_DIR}
|
||||||
|
${PROJECT_BINARY_DIR} new_path ${path_name}
|
||||||
|
)
|
||||||
|
|
||||||
|
#MESSAGE("New PATH: ${new_path}")
|
||||||
|
|
||||||
|
file(MAKE_DIRECTORY ${new_path}/data)
|
||||||
|
|
||||||
|
CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH})
|
||||||
|
set(MY_LD_LIBRARY_PATH ${output})
|
||||||
|
set(my_script_name ${SCRIPT_FULL_NAME})
|
||||||
|
|
||||||
|
if(CMAKE_SYSTEM MATCHES Darwin)
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in
|
||||||
|
${new_path}/${shell_script_name}
|
||||||
|
)
|
||||||
|
else(CMAKE_SYSTEM MATCHES Darwin)
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in
|
||||||
|
${new_path}/${shell_script_name}
|
||||||
|
)
|
||||||
|
endif(CMAKE_SYSTEM MATCHES Darwin)
|
||||||
|
|
||||||
|
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${new_path}/${shell_script_name}")
|
||||||
|
|
||||||
|
ENDMACRO (GENERATE_ROOT_TEST_SCRIPT)
|
||||||
164
CMake/FindROOTv6.cmake
Normal file
164
CMake/FindROOTv6.cmake
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
# - Finds ROOT instalation
|
||||||
|
# This module sets up ROOT information
|
||||||
|
# It defines:
|
||||||
|
# ROOT_FOUND If the ROOT is found
|
||||||
|
# ROOT_INCLUDE_DIR PATH to the include directory
|
||||||
|
# ROOT_LIBRARIES Most common libraries
|
||||||
|
# ROOT_LIBRARY_DIR PATH to the library directory
|
||||||
|
#
|
||||||
|
# Updated by K. Smith (ksmith37@nd.edu) to properly handle
|
||||||
|
# dependncies in ROOT_GENERATE_DICTIONARY
|
||||||
|
|
||||||
|
set(ROOT_ROOTSYS $ENV{ROOTSYS} CACHE PATH "path of root installation")
|
||||||
|
|
||||||
|
|
||||||
|
unset(ROOT_CONFIG_EXECUTABLE CACHE)
|
||||||
|
find_program(ROOT_CONFIG_EXECUTABLE root-config
|
||||||
|
PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH)
|
||||||
|
|
||||||
|
if(NOT ROOT_CONFIG_EXECUTABLE)
|
||||||
|
set(ROOT_FOUND FALSE)
|
||||||
|
else()
|
||||||
|
set(ROOT_FOUND TRUE)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix
|
||||||
|
OUTPUT_VARIABLE ROOTSYS
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${ROOT_CONFIG_EXECUTABLE} --version
|
||||||
|
OUTPUT_VARIABLE ROOT_VERSION
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
|
||||||
|
OUTPUT_VARIABLE ROOT_INCLUDE_DIR
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs --evelibs
|
||||||
|
OUTPUT_VARIABLE ROOT_LIBRARIES
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lThread -lMinuit -lHtml -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lProof)
|
||||||
|
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lProofPlayer -lMLP -lSpectrum -lEve -lRGL -lGed -lXMLParser -lPhysics)
|
||||||
|
set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE
|
||||||
|
ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR)
|
||||||
|
|
||||||
|
mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
|
||||||
|
|
||||||
|
include(CMakeParseArguments)
|
||||||
|
unset(ROOT_CINT_EXECUTABLE CACHE)
|
||||||
|
find_program(ROOT_CINT_EXECUTABLE rootcint PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH )
|
||||||
|
mark_as_advanced(ROOT_CINT_EXECUTABLE)
|
||||||
|
|
||||||
|
|
||||||
|
unset(ROOT_GENREFLEX_EXECUTABLE CACHE)
|
||||||
|
find_program(ROOT_GENREFLEX_EXECUTABLE genreflex PATHS ${ROOT_ROOTSYS}/bin NO_DEFAULT_PATH)
|
||||||
|
mark_as_advanced(ROOT_GENREFLEX_EXECUTABLE)
|
||||||
|
|
||||||
|
find_package(GCCXML)
|
||||||
|
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# function ROOT_GENERATE_DICTIONARY( dictionary
|
||||||
|
# header1 header2 ...
|
||||||
|
# LINKDEF linkdef1 ...
|
||||||
|
# OPTIONS opt1...)
|
||||||
|
function(ROOT_GENERATE_DICTIONARY dictionary)
|
||||||
|
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
|
||||||
|
message(" -- generating rootcint dictionary --------------------------------------- ")
|
||||||
|
#---Get the list of include directories------------------
|
||||||
|
get_directory_property(incdirs INCLUDE_DIRECTORIES)
|
||||||
|
set(includedirs)
|
||||||
|
foreach( d ${incdirs})
|
||||||
|
set(includedirs ${includedirs} -I${d})
|
||||||
|
endforeach()
|
||||||
|
#---Get the list of header files-------------------------
|
||||||
|
set(headerfiles)
|
||||||
|
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
|
||||||
|
find_file(headerFile ${fp} PATHS ${incdirs})
|
||||||
|
set(headerfiles ${headerfiles} ${headerFile})
|
||||||
|
debug(headerFile)
|
||||||
|
unset(headerFile CACHE)
|
||||||
|
endforeach()
|
||||||
|
#---Get LinkDef.h file------------------------------------
|
||||||
|
set(linkdefs)
|
||||||
|
foreach( f ${ARG_LINKDEF})
|
||||||
|
find_file(linkFile ${f} PATHS ${incdirs})
|
||||||
|
set(linkdefs ${linkdefs} ${linkFile})
|
||||||
|
debug(linkdefs)
|
||||||
|
unset(linkFile CACHE)
|
||||||
|
endforeach()
|
||||||
|
#---call rootcint------------------------------------------
|
||||||
|
add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h
|
||||||
|
COMMAND ${ROOT_CINT_EXECUTABLE} -cint -f ${dictionary}.cxx
|
||||||
|
-c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
|
||||||
|
DEPENDS ${headerfiles} ${linkdefs} VERBATIM)
|
||||||
|
message(" -- ---------------------------------------------------------------------- ")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# function REFLEX_GENERATE_DICTIONARY(dictionary
|
||||||
|
# header1 header2 ...
|
||||||
|
# SELECTION selectionfile ...
|
||||||
|
# OPTIONS opt1...)
|
||||||
|
function(REFLEX_GENERATE_DICTIONARY dictionary)
|
||||||
|
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN})
|
||||||
|
#---Get the list of header files-------------------------
|
||||||
|
set(headerfiles)
|
||||||
|
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
|
||||||
|
file(GLOB files ${fp})
|
||||||
|
if(files)
|
||||||
|
foreach(f ${files})
|
||||||
|
set(headerfiles ${headerfiles} ${f})
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
set(headerfiles ${headerfiles} ${fp})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
#---Get Selection file------------------------------------
|
||||||
|
if(IS_ABSOLUTE ${ARG_SELECTION})
|
||||||
|
set(selectionfile ${ARG_SELECTION})
|
||||||
|
else()
|
||||||
|
set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION})
|
||||||
|
endif()
|
||||||
|
#---Get the list of include directories------------------
|
||||||
|
get_directory_property(incdirs INCLUDE_DIRECTORIES)
|
||||||
|
set(includedirs)
|
||||||
|
foreach( d ${incdirs})
|
||||||
|
set(includedirs ${includedirs} -I${d})
|
||||||
|
endforeach()
|
||||||
|
#---Get preprocessor definitions--------------------------
|
||||||
|
get_directory_property(defs COMPILE_DEFINITIONS)
|
||||||
|
foreach( d ${defs})
|
||||||
|
set(definitions ${definitions} -D${d})
|
||||||
|
endforeach()
|
||||||
|
#---Nanes and others---------------------------------------
|
||||||
|
set(gensrcdict ${dictionary}.cpp)
|
||||||
|
if(MSVC)
|
||||||
|
set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"")
|
||||||
|
else()
|
||||||
|
#set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'")
|
||||||
|
set(gccxmlopts)
|
||||||
|
endif()
|
||||||
|
#set(rootmapname ${dictionary}Dict.rootmap)
|
||||||
|
#set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict)
|
||||||
|
#---Check GCCXML and get path-----------------------------
|
||||||
|
if(GCCXML)
|
||||||
|
get_filename_component(gccxmlpath ${GCCXML} PATH)
|
||||||
|
else()
|
||||||
|
message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable")
|
||||||
|
endif()
|
||||||
|
#---Actual command----------------------------------------
|
||||||
|
add_custom_command(OUTPUT ${gensrcdict} ${rootmapname}
|
||||||
|
COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile}
|
||||||
|
--gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions}
|
||||||
|
DEPENDS ${headerfiles} ${selectionfile})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
23
CMake/FindReadLine.cmake
Normal file
23
CMake/FindReadLine.cmake
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Base Io build system
|
||||||
|
# Written by Jeremy Tregunna <jeremy.tregunna@me.com>
|
||||||
|
#
|
||||||
|
# Find libreadline.
|
||||||
|
|
||||||
|
FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h readline/history.h)
|
||||||
|
|
||||||
|
SET(READLINE_NAMES ${READLINE_NAMES} readline libreadline history libhistory)
|
||||||
|
FIND_LIBRARY(READLINE_LIBRARY NAMES ${READLINE_NAMES} PATH)
|
||||||
|
|
||||||
|
IF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||||
|
SET(READLINE_FOUND TRUE)
|
||||||
|
ENDIF(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
|
||||||
|
|
||||||
|
IF(READLINE_FOUND)
|
||||||
|
IF(NOT Readline_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Found Readline: ${READLINE_LIBRARY}")
|
||||||
|
ENDIF (NOT Readline_FIND_QUIETLY)
|
||||||
|
ELSE(READLINE_FOUND)
|
||||||
|
IF(Readline_FIND_REQUIRED)
|
||||||
|
MESSAGE(FATAL_ERROR "Could not find readline")
|
||||||
|
ENDIF(Readline_FIND_REQUIRED)
|
||||||
|
ENDIF (READLINE_FOUND)
|
||||||
141
CMake/FindVTK.cmake
Normal file
141
CMake/FindVTK.cmake
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
# - Find a VTK installation or build tree.
|
||||||
|
# The following variables are set if VTK is found. If VTK is not
|
||||||
|
# found, VTK_FOUND is set to false.
|
||||||
|
# VTK_FOUND - Set to true when VTK is found.
|
||||||
|
# VTK_USE_FILE - CMake file to use VTK.
|
||||||
|
# VTK_MAJOR_VERSION - The VTK major version number.
|
||||||
|
# VTK_MINOR_VERSION - The VTK minor version number
|
||||||
|
# (odd non-release).
|
||||||
|
# VTK_BUILD_VERSION - The VTK patch level
|
||||||
|
# (meaningless for odd minor).
|
||||||
|
# VTK_INCLUDE_DIRS - Include directories for VTK
|
||||||
|
# VTK_LIBRARY_DIRS - Link directories for VTK libraries
|
||||||
|
# VTK_KITS - List of VTK kits, in CAPS
|
||||||
|
# (COMMON,IO,) etc.
|
||||||
|
# VTK_LANGUAGES - List of wrapped languages, in CAPS
|
||||||
|
# (TCL, PYHTON,) etc.
|
||||||
|
# The following cache entries must be set by the user to locate VTK:
|
||||||
|
# VTK_DIR - The directory containing VTKConfig.cmake.
|
||||||
|
# This is either the root of the build tree,
|
||||||
|
# or the lib/vtk directory. This is the
|
||||||
|
# only cache entry.
|
||||||
|
# The following variables are set for backward compatibility and
|
||||||
|
# should not be used in new code:
|
||||||
|
# USE_VTK_FILE - The full path to the UseVTK.cmake file.
|
||||||
|
# This is provided for backward
|
||||||
|
# compatibility. Use VTK_USE_FILE
|
||||||
|
# instead.
|
||||||
|
#
|
||||||
|
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2001-2009 Kitware, Inc.
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
# Assume not found.
|
||||||
|
SET(VTK_FOUND 0)
|
||||||
|
|
||||||
|
# VTK 4.0 did not provide VTKConfig.cmake.
|
||||||
|
IF("${VTK_FIND_VERSION}" VERSION_LESS 4.1)
|
||||||
|
SET(_VTK_40_ALLOW 1)
|
||||||
|
IF(VTK_FIND_VERSION)
|
||||||
|
SET(_VTK_40_ONLY 1)
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
# Construct consitent error messages for use below.
|
||||||
|
SET(VTK_DIR_DESCRIPTION "directory containing VTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/vtk for an installation.")
|
||||||
|
IF(_VTK_40_ALLOW)
|
||||||
|
SET(VTK_DIR_DESCRIPTION "${VTK_DIR_DESCRIPTION} For VTK 4.0, this is the location of UseVTK.cmake. This is either the root of the build tree or PREFIX/include/vtk for an installation.")
|
||||||
|
ENDIF()
|
||||||
|
SET(VTK_DIR_MESSAGE "VTK not found. Set the VTK_DIR cmake cache entry to the ${VTK_DIR_DESCRIPTION}")
|
||||||
|
|
||||||
|
# Check whether VTK 4.0 has already been found.
|
||||||
|
IF(_VTK_40_ALLOW AND VTK_DIR)
|
||||||
|
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||||
|
SET(VTK_FOUND 1)
|
||||||
|
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
# Use the Config mode of the find_package() command to find VTKConfig.
|
||||||
|
# If this succeeds (possibly because VTK_DIR is already set), the
|
||||||
|
# command will have already loaded VTKConfig.cmake and set VTK_FOUND.
|
||||||
|
IF(NOT _VTK_40_ONLY AND NOT VTK_FOUND)
|
||||||
|
FIND_PACKAGE(VTK QUIET NO_MODULE)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
# Special search for VTK 4.0.
|
||||||
|
IF(_VTK_40_ALLOW AND NOT VTK_DIR)
|
||||||
|
# Old scripts may set these directories in the CMakeCache.txt file.
|
||||||
|
# They can tell us where to find VTKConfig.cmake.
|
||||||
|
SET(VTK_DIR_SEARCH_LEGACY "")
|
||||||
|
IF(VTK_BINARY_PATH AND USE_BUILT_VTK)
|
||||||
|
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY} ${VTK_BINARY_PATH})
|
||||||
|
ENDIF(VTK_BINARY_PATH AND USE_BUILT_VTK)
|
||||||
|
IF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||||
|
SET(VTK_DIR_SEARCH_LEGACY ${VTK_DIR_SEARCH_LEGACY}
|
||||||
|
${VTK_INSTALL_PATH}/lib/vtk)
|
||||||
|
ENDIF(VTK_INSTALL_PATH AND USE_INSTALLED_VTK)
|
||||||
|
|
||||||
|
# Look for UseVTK.cmake in build trees or under <prefix>/include/vtk.
|
||||||
|
FIND_PATH(VTK_DIR
|
||||||
|
NAMES UseVTK.cmake
|
||||||
|
PATH_SUFFIXES vtk-4.0 vtk
|
||||||
|
HINTS $ENV{VTK_DIR}
|
||||||
|
|
||||||
|
PATHS
|
||||||
|
|
||||||
|
# Support legacy cache files.
|
||||||
|
${VTK_DIR_SEARCH_LEGACY}
|
||||||
|
|
||||||
|
# Read from the CMakeSetup registry entries. It is likely that
|
||||||
|
# VTK will have been recently built.
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
|
||||||
|
[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
|
||||||
|
|
||||||
|
# Help the user find it if we cannot.
|
||||||
|
DOC "The ${VTK_DIR_DESCRIPTION}"
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(VTK_DIR)
|
||||||
|
IF(EXISTS ${VTK_DIR}/UseVTK.cmake AND NOT EXISTS ${VTK_DIR}/VTKConfig.cmake)
|
||||||
|
SET(VTK_FOUND 1)
|
||||||
|
INCLUDE(UseVTKConfig40) # No VTKConfig; load VTK 4.0 settings.
|
||||||
|
ELSE()
|
||||||
|
# We found the wrong version. Pretend we did not find it.
|
||||||
|
SET(VTK_DIR "VTK_DIR-NOTFOUND" CACHE PATH "The ${VTK_DIR_DESCRIPTION}" FORCE)
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
IF(VTK_FOUND)
|
||||||
|
# Set USE_VTK_FILE for backward-compatability.
|
||||||
|
SET(USE_VTK_FILE ${VTK_USE_FILE})
|
||||||
|
ELSE(VTK_FOUND)
|
||||||
|
# VTK not found, explain to the user how to specify its location.
|
||||||
|
IF(VTK_FIND_REQUIRED)
|
||||||
|
MESSAGE(FATAL_ERROR ${VTK_DIR_MESSAGE})
|
||||||
|
ELSE(VTK_FIND_REQUIRED)
|
||||||
|
IF(NOT VTK_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS ${VTK_DIR_MESSAGE})
|
||||||
|
ENDIF(NOT VTK_FIND_QUIETLY)
|
||||||
|
ENDIF(VTK_FIND_REQUIRED)
|
||||||
|
ENDIF(VTK_FOUND)
|
||||||
62
CMake/FinduLib.cmake
Normal file
62
CMake/FinduLib.cmake
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# - Finds ROOT instalation
|
||||||
|
# This module sets up ROOT information
|
||||||
|
# It defines:
|
||||||
|
# ULIB_FOUND If the uLib is found
|
||||||
|
# ULIB_INCLUDE_DIRS PATH to the include directory
|
||||||
|
# ULIB_LIBRARIES Most common libraries
|
||||||
|
# ULIB_LIBRARY_DIRS PATH to the library directory
|
||||||
|
#
|
||||||
|
|
||||||
|
include(uLibFindDependencies)
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
|
||||||
|
## CONFIG FIND -------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")
|
||||||
|
unset(ULIB_CONFIG)
|
||||||
|
find_package(ULIB ${ULIB_PACKAGE_VERSION} CONFIG
|
||||||
|
NAMES uLib
|
||||||
|
PATH_SUFFIXES ${ULIB_PACKAGE_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
debug(ULIB_CONFIG)
|
||||||
|
debug(ULIB_CONSIDERED_CONFIGS)
|
||||||
|
debug(ULIB_CONSIDERED_VERSIONS)
|
||||||
|
debug(ULIB_INCLUDE_DIRS)
|
||||||
|
debug(ULIB_LIBRARIES)
|
||||||
|
|
||||||
|
if(ULIB_CONFIG)
|
||||||
|
set(ULIB_FOUND true)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
## MODULE FIND -------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
#find_path(uLib_INCLUDE_DIR
|
||||||
|
# NAMES ulib.h
|
||||||
|
# PATH_SUFFIXES mutom-0.2
|
||||||
|
#)
|
||||||
|
#debug(uLib_INCLUDE_DIR)
|
||||||
|
|
||||||
|
#find_file(uLib_USE_FILE
|
||||||
|
# NAMES uLib_exported_targets.cmake
|
||||||
|
# PATHS lib lib64
|
||||||
|
# PATH_SUFFIXES mutom-0.2
|
||||||
|
#)
|
||||||
|
#debug(uLib_USE_FILE)
|
||||||
|
|
||||||
|
#find_library(uLib_LIBRARY
|
||||||
|
# NAMES libmutomCore.so
|
||||||
|
# PATH_SUFFIXES mutom-0.2
|
||||||
|
# )
|
||||||
|
#debug(uLib_LIBRARY)
|
||||||
|
|
||||||
|
##set( uLib_PROCESS_INCLUDES uLib_INCLUDE_DIR ULIB_INCLUDE_DIRS )
|
||||||
|
##set( uLib_PROCESS_LIBS uLib_LIBRARY ULIB_LIBRARIES )
|
||||||
|
##libfind_process(uLib)
|
||||||
|
|
||||||
|
#set( ULIB_INCLUDE_DIRS ${uLib_INCLUDE_DIR} )
|
||||||
|
#set( ULIB_LIBRARIES ${uLib_LIBRARY} )
|
||||||
|
#include(FindPackageHandleStandardArgs)
|
||||||
|
#find_package_handle_standard_args(uLib DEFAULT_MSG
|
||||||
|
# uLib_LIBRARY uLib_INCLUDE_DIR)
|
||||||
|
#mark_as_advanced(uLib_INCLUDE_DIR uLib_LIBRARY)
|
||||||
11
CMake/clean-all.cmake
Normal file
11
CMake/clean-all.cmake
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt
|
||||||
|
${CMAKE_BINARY_DIR}/cmake_install.cmake
|
||||||
|
${CMAKE_BINARY_DIR}/Makefile
|
||||||
|
${CMAKE_BINARY_DIR}/CMakeFiles
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(file ${cmake_generated})
|
||||||
|
if (EXISTS ${file})
|
||||||
|
file(REMOVE_RECURSE ${file})
|
||||||
|
endif()
|
||||||
|
endforeach(file)
|
||||||
47
CMake/rmake.in
Normal file
47
CMake/rmake.in
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# CONNECTION ---------------------------------------------------------------- ##
|
||||||
|
USER=@REMOTE_BUILD_USER@
|
||||||
|
MACHINES="@REMOTE_BUILD_MACHINES@"
|
||||||
|
SSH=@REMOTE_BUILD_SSHBIN@
|
||||||
|
PORT=@REMOTE_BUILD_SSHPORT@
|
||||||
|
|
||||||
|
# BUILD --------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
MAKE=@REMOTE_BUILD_MAKEBIN@
|
||||||
|
BUILD_DIR=@REMOTE_BUILD_BULIDIR@
|
||||||
|
SOURCE_DIR=@REMOTE_BUILD_SRCDIR@
|
||||||
|
CURRENT_DIR=`pwd`
|
||||||
|
ARGS=$@
|
||||||
|
|
||||||
|
|
||||||
|
# FIND RELATIVE PATH -------------------------------------------------------- ##
|
||||||
|
|
||||||
|
function relpath {
|
||||||
|
# both $1 and $2 are absolute paths
|
||||||
|
# returns $2 relative to $1
|
||||||
|
source=$1
|
||||||
|
target=$2
|
||||||
|
common_part=$source
|
||||||
|
back=
|
||||||
|
while [ "${target#$common_part}" = "${target}" ]; do
|
||||||
|
common_part=$(dirname $common_part)
|
||||||
|
back="../${back}"
|
||||||
|
done
|
||||||
|
echo ${back}${target#$common_part/}
|
||||||
|
}
|
||||||
|
|
||||||
|
CURRENT_SRCDIR=$(cd -- ${CURRENT_DIR}/$(relpath $BUILD_DIR/ $SOURCE_DIR/)/ && pwd)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for m in ${MACHINES}; do
|
||||||
|
echo "building into machine: ${m}"
|
||||||
|
echo "remote commands: --------------------------------------------------------------------------------------------------------------"
|
||||||
|
echo "source dir = ${SOURCE_DIR}"
|
||||||
|
echo "build dir = ${BUILD_DIR}"
|
||||||
|
echo "repath to LOCAL MACHINE source dir = ${CURRENT_SRCDIR}"
|
||||||
|
echo "${SSH} -p ${PORT} ${USER}@${m} ${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g' 3>&1 1>&2 2>&3"
|
||||||
|
echo " ------------------------------------------------------------------------------------------------------------------------------"
|
||||||
|
${SSH} -p ${PORT} ${USER}@${m} "${MAKE} -C ${BUILD_DIR} ${ARGS} 3>&1 1>&2 2>&3 | sed -e 's|${SOURCE_DIR}|${CURRENT_SRCDIR}|g'" 3>&1 1>&2 2>&3
|
||||||
|
done
|
||||||
65
CMake/uLibCommon.cmake
Normal file
65
CMake/uLibCommon.cmake
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
include(uLibMacros)
|
||||||
|
include_guard(ULIB_COMMON_CMAKE)
|
||||||
|
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
|
||||||
|
## DIRECTORIES -------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
set(ULIB_PARENT_PATH "${PROJECT_SOURCE_DIR}")
|
||||||
|
message(STATUS "Setting uLib parent path to: ${ULIB_PARENT_PATH}")
|
||||||
|
|
||||||
|
## Build directories ##
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "build path for lib")
|
||||||
|
mark_as_advanced(LIBRARY_OUTPUT_PATH)
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "build path for binaries")
|
||||||
|
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
|
||||||
|
|
||||||
|
## Install directories ##
|
||||||
|
set(PACKAGE_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
|
||||||
|
set(PACKAGE_INSTALL_LIB_DIR lib/${PACKAGE_NAME} CACHE PATH "Installation directory for libraries")
|
||||||
|
set(PACKAGE_INSTALL_INC_DIR include/${PACKAGE_NAME} CACHE PATH "Installation directory for headers")
|
||||||
|
set(PACKAGE_INSTALL_DATA_DIR share/${PACKAGE_NAME} CACHE PATH "Installation directory for data files")
|
||||||
|
if(WIN32 AND NOT CYGWIN)
|
||||||
|
set(DEF_INSTALL_CMAKE_DIR CMake)
|
||||||
|
else()
|
||||||
|
set(DEF_INSTALL_CMAKE_DIR lib/cmake/${PACKAGE_NAME})
|
||||||
|
endif()
|
||||||
|
set(PACKAGE_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
|
||||||
|
|
||||||
|
# Make relative paths absolute (needed later on)
|
||||||
|
foreach(p LIB BIN INC DATA CMAKE)
|
||||||
|
set(var PACKAGE_INSTALL_${p}_DIR)
|
||||||
|
if(NOT IS_ABSOLUTE "${${var}}")
|
||||||
|
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
|
||||||
|
endif()
|
||||||
|
mark_as_advanced(PACKAGE_INSTALL_${p}_DIR)
|
||||||
|
debug(PACKAGE_INSTALL_${p}_DIR)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# add the binary tree to the search path for include files
|
||||||
|
# so that we will find config.h
|
||||||
|
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||||
|
include_directories(${PROJECT_BINARY_DIR})
|
||||||
|
include_directories(${SRC_DIR})
|
||||||
|
|
||||||
|
|
||||||
|
## GLOBAL OPTIONS ----------------------------------------------------------- ##
|
||||||
|
|
||||||
|
# Set a default build type to RELEASE WITH DEBUG INFO if none was specified
|
||||||
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
||||||
|
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")
|
||||||
|
# Set the possible values of build type for cmake-gui
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
||||||
|
"MinSizeRel" "RelWithDebInfo")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_WARNING_OPTION "" CACHE STRING "Warning level -WAll to verbose all warnings")
|
||||||
|
set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE STRING "Verbose compile output switch")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${CMAKE_CXX_WARNING_OPTION}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
57
CMake/uLibConfigHeader.cmake
Normal file
57
CMake/uLibConfigHeader.cmake
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
include(uLibMacros)
|
||||||
|
include_guard(ULIB_CONFIG_HEADER_CMAKE)
|
||||||
|
|
||||||
|
|
||||||
|
## CONFIG ------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
message("/////////// CONFIG HEADER //////////////")
|
||||||
|
|
||||||
|
include(CheckIncludeFiles)
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
|
||||||
|
## force to use PP variadics (FIX) ##
|
||||||
|
set(BOOST_PP_VARIADICS ON)
|
||||||
|
|
||||||
|
message(STATUS "PROJECT NAME = ${PROJECT_NAME}")
|
||||||
|
message(STATUS "PACKAGE VERSION = ${PACKAGE_VERSION}")
|
||||||
|
message(STATUS "PACKAGE NAME = ${PACKAGE_NAME}")
|
||||||
|
execute_process(COMMAND "svnversion"
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE SVN_REVISION
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE )
|
||||||
|
|
||||||
|
message(STATUS "SVN REVISION = ${SVN_REVISION}")
|
||||||
|
|
||||||
|
CHECK_INCLUDE_FILES(inittypes.h HAVE_INITTYPES_H)
|
||||||
|
CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
|
||||||
|
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
|
||||||
|
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
|
||||||
|
|
||||||
|
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
|
||||||
|
CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
|
||||||
|
CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC)
|
||||||
|
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)
|
||||||
|
|
||||||
|
CHECK_INCLUDE_FILES(math.h HAVE_MATH_H)
|
||||||
|
CHECK_FUNCTION_EXISTS(fsetround HAVE_FSETROUND)
|
||||||
|
CHECK_FUNCTION_EXISTS(floor HAVE_FLOOR)
|
||||||
|
CHECK_FUNCTION_EXISTS(pow HAVE_POW)
|
||||||
|
CHECK_FUNCTION_EXISTS(sqrt HAVE_SQRT)
|
||||||
|
|
||||||
|
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
|
||||||
|
CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR)
|
||||||
|
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
|
||||||
|
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
|
||||||
|
|
||||||
|
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
|
||||||
|
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
|
||||||
|
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
|
||||||
|
|
||||||
|
CHECK_INCLUDE_FILES(assert.h HAVE_ASSERT_H)
|
||||||
|
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${PROJECT_SOURCE_DIR}/CMakeConfig.in.h"
|
||||||
|
"${PROJECT_BINARY_DIR}/config.h"
|
||||||
|
)
|
||||||
54
CMake/uLibDebugMacro.cmake
Normal file
54
CMake/uLibDebugMacro.cmake
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
include(uLibMacros)
|
||||||
|
include_guard(ULIB_DEBUG_MACRO_CMAKE)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_CONFIGURE_DEBUG_ENABLE ON CACHE BOOL "cmake configure debugger")
|
||||||
|
set(CMAKE_CONFIGURE_DEBUG_LIST OFF CACHE BOOL "cmake debugger show list enable")
|
||||||
|
mark_as_advanced(
|
||||||
|
CMAKE_CONFIGURE_DEBUG_ENABLE
|
||||||
|
CMAKE_CONFIGURE_DEBUG_LIST
|
||||||
|
)
|
||||||
|
|
||||||
|
macro(debug str)
|
||||||
|
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||||
|
set(var ${${str}})
|
||||||
|
list(LENGTH var len)
|
||||||
|
if((${len} GREATER 1) AND CMAKE_CONFIGURE_DEBUG_LIST)
|
||||||
|
message(STATUS "[DEBUG] [${str}] list: ")
|
||||||
|
foreach(item ${var})
|
||||||
|
message(STATUS " -> ${item}")
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
message(STATUS "[DEBUG] [${str}] ${var}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(debug_list str)
|
||||||
|
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||||
|
set(var ${${str}})
|
||||||
|
list(LENGTH var len)
|
||||||
|
if((${len} GREATER 1))
|
||||||
|
message(STATUS "[DEBUG] [${str}] list: ")
|
||||||
|
foreach(item ${var})
|
||||||
|
message(STATUS " -> ${item}")
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
message(STATUS "[DEBUG] [${str}] ${var}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(debug_package str)
|
||||||
|
if(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||||
|
set(have ${str}_FOUND)
|
||||||
|
if(${have})
|
||||||
|
debug("${str}_INCLUDE_DIRS")
|
||||||
|
debug("${str}_LIBRARIES")
|
||||||
|
debug("${str}_LIBRARY_DIRS")
|
||||||
|
debug("${str}_DEFINITIONS")
|
||||||
|
else(${have})
|
||||||
|
message(WARNING "package ${str} not found")
|
||||||
|
endif(${have})
|
||||||
|
endif(CMAKE_CONFIGURE_DEBUG_ENABLE)
|
||||||
|
endmacro()
|
||||||
122
CMake/uLibFindDependencies.cmake
Normal file
122
CMake/uLibFindDependencies.cmake
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
include(uLibMacros)
|
||||||
|
include_guard(ULIB_FIND_DEPENDENCIES_CMAKE)
|
||||||
|
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## PKG FIND ##
|
||||||
|
message("/////////// LOOKING FOR EXTERNAL PACKAGES //////////////")
|
||||||
|
|
||||||
|
## BOOST ##
|
||||||
|
message(STATUS "## BOOST ##")
|
||||||
|
set(Boost_USE_STATIC_LIBS OFF)
|
||||||
|
set(Boost_USE_MULTITHREADED ON)
|
||||||
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
||||||
|
|
||||||
|
find_package(Boost 1.45.0 COMPONENTS serialization signals program_options REQUIRED)
|
||||||
|
if(Boost_FOUND)
|
||||||
|
set(HAVE_BOOST true)
|
||||||
|
endif(Boost_FOUND)
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
## OPEN MP ##
|
||||||
|
message(STATUS "## OPEN MP ##")
|
||||||
|
find_package(OpenMP)
|
||||||
|
option(OpenMP_ACTIVE "Activate OpenMP parallel compilation" ON)
|
||||||
|
if(OPENMP_FOUND AND OpenMP_ACTIVE)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
|
||||||
|
endif(OPENMP_FOUND AND OpenMP_ACTIVE)
|
||||||
|
|
||||||
|
## EIGEN ##
|
||||||
|
message(STATUS "## EIGEN ##")
|
||||||
|
# option(USE_EIGEN ON) ## REQUIRED
|
||||||
|
find_package(Eigen3 REQUIRED)
|
||||||
|
debug(EIGEN3_INCLUDE_DIR)
|
||||||
|
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||||
|
|
||||||
|
## ROOT ##
|
||||||
|
message(STATUS "## ROOT ##")
|
||||||
|
option(ULIB_USE_ROOT "Activate use of Root integration" ON)
|
||||||
|
### <<<--- ROOT IS REQUIRED FOR THE MOMENT ###
|
||||||
|
#if(ULIB_USE_ROOT)
|
||||||
|
#include(/etc/root/cmake/FindROOT.cmake)
|
||||||
|
find_package(ROOT REQUIRED)
|
||||||
|
if(ROOT_FOUND)
|
||||||
|
set(HAVE_ROOT true)
|
||||||
|
include_directories(${ROOT_INCLUDE_DIR})
|
||||||
|
link_directories(${ROOT_LIBRARY_DIR})
|
||||||
|
debug(ROOT_INCLUDE_DIR)
|
||||||
|
debug(ROOT_LIBRARY_DIR)
|
||||||
|
debug(ROOT_LIBRARIES)
|
||||||
|
else()
|
||||||
|
message(WARNING "Root not found")
|
||||||
|
endif(ROOT_FOUND)
|
||||||
|
#endif(ULIB_USE_ROOT)
|
||||||
|
|
||||||
|
|
||||||
|
## VTK ##
|
||||||
|
option(ULIB_USE_VTK "Activate use of Vtk Visual Pipelines" ON)
|
||||||
|
if(ULIB_USE_VTK)
|
||||||
|
message(STATUS "## VTK ##")
|
||||||
|
message(STATUS "Looking for VTK...")
|
||||||
|
set(VTK_DIR "PATH/TO/VTK/BUILD/DIRECTORY")
|
||||||
|
mark_as_advanced(VTK_DIR)
|
||||||
|
find_package(VTK REQUIRED)
|
||||||
|
include(${VTK_USE_FILE})
|
||||||
|
#message(STATUS "VTK included libraries: ${VTK_LIBRARIES}")
|
||||||
|
debug(VTK_USE_FILE)
|
||||||
|
debug(VTK_INCLUDE_DIRS)
|
||||||
|
debug(VTK_LIBRARY_DIRS)
|
||||||
|
debug(VTK_LIBRARIES)
|
||||||
|
# get_directory_property(compile_def COMPILE_DEFINITIONS)
|
||||||
|
# debug(compile_def)
|
||||||
|
endif(ULIB_USE_VTK)
|
||||||
|
|
||||||
|
|
||||||
|
## GEANT ##
|
||||||
|
option(ULIB_USE_GEANT4 "Activate use of GEANT Integration" ON)
|
||||||
|
message(STATUS "## GEANT 4 ##")
|
||||||
|
#include(FindGEANT4) # disabled using system finder
|
||||||
|
find_package(Geant4)
|
||||||
|
set(GEANT4_FOUND Geant4_DIR)
|
||||||
|
if(GEANT4_FOUND AND ULIB_USE_GEANT4)
|
||||||
|
message(STATUS "Looking for Geant4... - Geant4 found in ${Geant4_DIR}")
|
||||||
|
set(HAVE_GEANT4 true)
|
||||||
|
include_directories(${Geant4_INCLUDE_DIRS}) # Add -I type paths
|
||||||
|
add_definitions(${Geant4_DEFINITIONS}) # Add -D type defs
|
||||||
|
debug_package(Geant4)
|
||||||
|
endif(GEANT4_FOUND AND ULIB_USE_GEANT4)
|
||||||
|
|
||||||
|
## QT4 ##
|
||||||
|
option(ULIB_USE_QT4 "Activate use of Qt Framework" ON)
|
||||||
|
if(ULIB_USE_QT4)
|
||||||
|
message(STATUS "## QT4 ##")
|
||||||
|
find_package(Qt4)
|
||||||
|
# include_directories(${Qt4_INCLUDE_DIRS})
|
||||||
|
# debug(Qt4_INCLUDE_DIRS)
|
||||||
|
endif(ULIB_USE_QT4)
|
||||||
|
|
||||||
|
## QT5 ##
|
||||||
|
option(ULIB_USE_QT5 "Activate use of Qt Framework" ON)
|
||||||
|
if(ULIB_USE_QT5)
|
||||||
|
message(STATUS "## QT5 ##")
|
||||||
|
find_package(Qt5Widgets)
|
||||||
|
# include_directories(${Qt5_INCLUDE_DIRS})
|
||||||
|
# debug(Qt5_INCLUDE_DIRS)
|
||||||
|
endif(ULIB_USE_QT5)
|
||||||
|
|
||||||
|
## READLINE ##
|
||||||
|
message(STATUS "## READLINE ##")
|
||||||
|
find_package(ReadLine)
|
||||||
|
include_directories(${READLINE_INCLUDE_DIR})
|
||||||
|
debug(READLINE_INCLUDE_DIR)
|
||||||
|
|
||||||
|
## STD MATH REQUIRED ##
|
||||||
|
#message(STATUS "## STD MATH ##")
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES CMAKE_REQUIRED_LIBRARIES m)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
47
CMake/uLibGenerateRMake.cmake
Normal file
47
CMake/uLibGenerateRMake.cmake
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
|
||||||
|
include(uLibMacros)
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
|
||||||
|
## MAKE REMOTE -------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
#set(BUILD_REMOTE_MACHINES "10.62.19.4" CACHE STRING "remote build in cloud machine")
|
||||||
|
#set(BUILD_REMOTE_USER "rigoni" CACHE STRING "remote build user")
|
||||||
|
#set(BUILD_REMOTE_CMD "${SSH_COMMAND} ${BUILD_REMOTE_USER}@${BUILD_REMOTE_MACHINES} \"make -C \"")
|
||||||
|
#add_custom_target(cloud COMMAND ${SSH_COMMAND})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
set(REMOTE_BUILD_USER "$ENV{USER}" CACHE STRING "ssh remote build user name")
|
||||||
|
|
||||||
|
execute_process(COMMAND hostname -I OUTPUT_VARIABLE HOSTNAME_IP)
|
||||||
|
set(REMOTE_BUILD_MACHINES ${HOSTNAME_IP} CACHE STRING "ssh remote build machines")
|
||||||
|
|
||||||
|
find_file(SSH_EXECUTABLE ssh PATHS /bin/local/bin /usr/bin /bin)
|
||||||
|
set(REMOTE_BUILD_SSHBIN ${SSH_EXECUTABLE} CACHE FILEPATH "ssh remote build command path")
|
||||||
|
set(REMOTE_BUILD_SSHPORT 22 CACHE STRING "ssh remote build port")
|
||||||
|
|
||||||
|
find_file(MAKE_EXECUTABLE make PATHS /usr/local/bin /usr/bin /bin)
|
||||||
|
set(REMOTE_BUILD_MAKEBIN ${MAKE_EXECUTABLE} CACHE FILEPATH "ssh remote build make path")
|
||||||
|
set(REMOTE_BUILD_BULIDIR ${PROJECT_BINARY_DIR} CACHE PATH "ssh remote build build path")
|
||||||
|
set(REMOTE_BUILD_SRCDIR ${PROJECT_SOURCE_DIR} CACHE PATH "ssh remote build source path")
|
||||||
|
|
||||||
|
message("remote build ----------------------------------------------------------")
|
||||||
|
debug(REMOTE_BUILD_USER)
|
||||||
|
debug(REMOTE_BUILD_MACHINES)
|
||||||
|
debug(REMOTE_BUILD_SSHBIN)
|
||||||
|
debug(REMOTE_BUILD_SSHPORT)
|
||||||
|
debug(REMOTE_BUILD_MAKEBIN)
|
||||||
|
message("-----------------------------------------------------------------------")
|
||||||
|
|
||||||
|
|
||||||
|
find_file(RMAKE_IN_FILE rmake.in PATHS ${CMAKE_MODULE_PATH})
|
||||||
|
configure_file(
|
||||||
|
"${RMAKE_IN_FILE}"
|
||||||
|
"${PROJECT_BINARY_DIR}/CMake/rmake" @ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
file(COPY "${PROJECT_BINARY_DIR}/CMake/rmake"
|
||||||
|
DESTINATION "${PROJECT_BINARY_DIR}"
|
||||||
|
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
|
||||||
|
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||||
12
CMake/uLibMacros.cmake
Normal file
12
CMake/uLibMacros.cmake
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#if(ULIB_MACROS_CMAKE)
|
||||||
|
# return()
|
||||||
|
#endif()
|
||||||
|
#set(ULIB_MACROS_CMAKE 1)
|
||||||
|
|
||||||
|
|
||||||
|
function(include_guard var)
|
||||||
|
if(${var})
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(${var} 1)
|
||||||
|
endfunction()
|
||||||
186
CMake/uLibTargetMacros.cmake
Normal file
186
CMake/uLibTargetMacros.cmake
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
|
||||||
|
include(uLibMacros)
|
||||||
|
include_guard(ULIB_TARGET_MACRO_CMAKE)
|
||||||
|
|
||||||
|
## adds library target
|
||||||
|
macro(uLib_add_library name)
|
||||||
|
add_library(${name} ${ARGN})
|
||||||
|
if(NOT ULIB_INSTALL_NO_LIBRARIES)
|
||||||
|
set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name})
|
||||||
|
endif(NOT ULIB_INSTALL_NO_LIBRARIES)
|
||||||
|
endmacro(uLib_add_library)
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## Add SHARED library target ##
|
||||||
|
|
||||||
|
# HEADERS and SOURCES must be defined as list of library headers and sources
|
||||||
|
macro(uLib_add_shared_library name)
|
||||||
|
if(COMMAND cmake_policy)
|
||||||
|
# cmake_policy( SET CMP0022 NEW )
|
||||||
|
endif(COMMAND cmake_policy)
|
||||||
|
|
||||||
|
set(mname ${PACKAGE_LIBPREFIX}${name})
|
||||||
|
|
||||||
|
if(SOURCES)
|
||||||
|
uLib_add_library(${mname} SHARED ${SOURCES})
|
||||||
|
set(shared ${ULIB_SHARED_LIBRARIES})
|
||||||
|
list(APPEND shared ${mname})
|
||||||
|
set(ULIB_SHARED_LIBRARIES ${shared} PARENT_SCOPE)
|
||||||
|
source_group("${project_name}\\${name}" FILES ${SOURCES})
|
||||||
|
set_target_properties(${mname} PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${PROJECT_SOVERSION}
|
||||||
|
INTERFACE_LINK_LIBRARIES "${LIBRARIES}"
|
||||||
|
LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- ok for cmake from 2.12 ?
|
||||||
|
IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBRARIES}" ## <- breaks cmake after 2.11 ?
|
||||||
|
# PUBLIC_HEADER ""
|
||||||
|
)
|
||||||
|
debug(LIBRARIES)
|
||||||
|
|
||||||
|
install(TARGETS ${mname}
|
||||||
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
|
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
||||||
|
LIBRARY DESTINATION ${PACKAGE_INSTALL_LIB_DIR} COMPONENT lib
|
||||||
|
# PUBLIC_HEADER DESTINATION ${PACKAGE_INSTALL_INC_DIR} COMPONENT dev
|
||||||
|
)
|
||||||
|
endif(SOURCES)
|
||||||
|
|
||||||
|
if(HEADERS)
|
||||||
|
foreach(header ${HEADERS})
|
||||||
|
install(FILES ${header} DESTINATION ${PACKAGE_INSTALL_INC_DIR}/${name})
|
||||||
|
endforeach(header)
|
||||||
|
endif(HEADERS)
|
||||||
|
|
||||||
|
endmacro(uLib_add_shared_library)
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## Add Target ##
|
||||||
|
|
||||||
|
macro(uLib_add_target name)
|
||||||
|
debug(${name})
|
||||||
|
add_executable(${name} ${ARGN})
|
||||||
|
set_property(GLOBAL APPEND PROPERTY ULIB_TARGETS ${name})
|
||||||
|
|
||||||
|
set(exported ${ULIB_EXPORTED_TARGETS})
|
||||||
|
list(APPEND exported ${name})
|
||||||
|
set(ULIB_EXPORTED_TARGETS ${exported} PARENT_SCOPE)
|
||||||
|
|
||||||
|
install(TARGETS ${name}
|
||||||
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
|
RUNTIME DESTINATION ${PACKAGE_INSTALL_BIN_DIR} COMPONENT bin
|
||||||
|
)
|
||||||
|
ENDMACRO(uLib_add_target)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## TESTS ##
|
||||||
|
|
||||||
|
# TESTS and LIBRARIES must be defined
|
||||||
|
macro(uLib_add_tests name)
|
||||||
|
foreach(tn ${TESTS})
|
||||||
|
add_executable(${tn} EXCLUDE_FROM_ALL ${tn}.cpp)
|
||||||
|
add_test(${tn} ${tn})
|
||||||
|
|
||||||
|
# adds dependencies to all selected modules in uLib
|
||||||
|
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||||
|
# add_dependencies(${tn} ${project_name}${module})
|
||||||
|
# endforeach(module)
|
||||||
|
|
||||||
|
# adds libraries dependencies
|
||||||
|
foreach(library ${LIBRARIES})
|
||||||
|
target_link_libraries(${tn} ${library})
|
||||||
|
endforeach(library)
|
||||||
|
|
||||||
|
endforeach(tn)
|
||||||
|
|
||||||
|
# custom target to compile all tests
|
||||||
|
add_custom_target(all-${name}-tests)
|
||||||
|
add_dependencies(all-${name}-tests ${TESTS})
|
||||||
|
endmacro(uLib_add_tests name)
|
||||||
|
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## UTILS ##
|
||||||
|
|
||||||
|
# UTILS and LIBRARIES must be defined
|
||||||
|
macro(uLib_add_utils name)
|
||||||
|
foreach(tn ${UTILS})
|
||||||
|
add_executable(${tn} ${tn}.cpp)
|
||||||
|
install(TARGETS ${tn} RUNTIME DESTINATION bin)
|
||||||
|
|
||||||
|
# adds dependencies to all selected modules in uLib
|
||||||
|
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||||
|
# add_dependencies(${tn} ${project_name}${module})
|
||||||
|
# endforeach(module)
|
||||||
|
|
||||||
|
# adds libraries dependencies
|
||||||
|
foreach(library ${LIBRARIES})
|
||||||
|
target_link_libraries(${tn} ${library})
|
||||||
|
endforeach(library)
|
||||||
|
|
||||||
|
endforeach(tn)
|
||||||
|
|
||||||
|
# custom target to compile all tests
|
||||||
|
add_custom_target(all-${name})
|
||||||
|
add_dependencies(all-${name} ${UTILS})
|
||||||
|
|
||||||
|
endmacro(uLib_add_utils name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function(get_gcc_compile_flags target out_flags)
|
||||||
|
string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" name)
|
||||||
|
set(flags "${${name}} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILER_ARG1}")
|
||||||
|
get_target_property(value ${target} COMPILE_FLAGS)
|
||||||
|
if (value)
|
||||||
|
list(APPEND flags ${value})
|
||||||
|
endif()
|
||||||
|
get_target_property(value ${target} TYPE)
|
||||||
|
get_target_property(value ${target} COMPILE_DEFINITIONS)
|
||||||
|
if (value)
|
||||||
|
foreach(item ${value})
|
||||||
|
list(APPEND flags "-D${item}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
STRING(TOUPPER "COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE}" name)
|
||||||
|
get_target_property(value ${target} ${name})
|
||||||
|
if (value)
|
||||||
|
foreach(item ${value})
|
||||||
|
list(APPEND flags "-D${item}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
get_directory_property(value DEFINITIONS)
|
||||||
|
if (value)
|
||||||
|
list(APPEND flags ${value})
|
||||||
|
endif()
|
||||||
|
get_directory_property(value INCLUDE_DIRECTORIES)
|
||||||
|
if (value)
|
||||||
|
foreach(item ${value})
|
||||||
|
list(APPEND flags "-I${item}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
set(${out_flags} ${flags} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(get_gcc_link_flags target out_flags)
|
||||||
|
set(flags)
|
||||||
|
get_target_property(value ${target} LINK_FLAGS_RELEASE)
|
||||||
|
if (value)
|
||||||
|
message(STATUS "-> ${flags}")
|
||||||
|
list(APPEND flags ${value})
|
||||||
|
endif()
|
||||||
|
get_directory_property(value LINK_DIRECTORIES)
|
||||||
|
if (value)
|
||||||
|
message(STATUS "-> ${flags}")
|
||||||
|
foreach(item ${value})
|
||||||
|
list(APPEND flags "-L${item}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
message(STATUS "-> ${flags}")
|
||||||
|
set(${out_flags} ${flags} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
128
CMakeConfig.in.h
Normal file
128
CMakeConfig.in.h
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
|
#ifndef HAVE_CONFIG_H
|
||||||
|
#define HAVE_CONFIG_H
|
||||||
|
|
||||||
|
/* Compiler must have variadic macros */
|
||||||
|
//#cmakedefine BOOST_PP_VARIADICS
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <assert.h> header file. */
|
||||||
|
#cmakedefine HAVE_ASSERT_H
|
||||||
|
|
||||||
|
/* Defined if the requested minimum BOOST version is satisfied */
|
||||||
|
#cmakedefine HAVE_BOOST
|
||||||
|
|
||||||
|
/* Define to 1 if you have <boost/archive/text_oarchive.hpp> */
|
||||||
|
#cmakedefine HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP
|
||||||
|
|
||||||
|
/* Define to 1 if you have <boost/array.hpp> */
|
||||||
|
#cmakedefine HAVE_BOOST_ARRAY_HPP
|
||||||
|
|
||||||
|
/* Define to 1 if you have <boost/program_options.hpp> */
|
||||||
|
#cmakedefine HAVE_BOOST_PROGRAM_OPTIONS_HPP
|
||||||
|
|
||||||
|
/* Define to 1 if you have <boost/signal.hpp> */
|
||||||
|
#cmakedefine HAVE_BOOST_SIGNAL_HPP
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
|
#cmakedefine HAVE_DLFCN_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `fesetround' function. */
|
||||||
|
#cmakedefine HAVE_FESETROUND
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `floor' function. */
|
||||||
|
#cmakedefine HAVE_FLOOR
|
||||||
|
|
||||||
|
/* Having Geant4 installed */
|
||||||
|
#cmakedefine HAVE_GEANT4
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
|
#cmakedefine HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
/* Define if you have libreadline */
|
||||||
|
#cmakedefine HAVE_LIBREADLINE
|
||||||
|
|
||||||
|
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||||
|
to 0 otherwise. */
|
||||||
|
#cmakedefine HAVE_MALLOC
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
|
#cmakedefine HAVE_MEMORY_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `pow' function. */
|
||||||
|
#cmakedefine HAVE_POW
|
||||||
|
|
||||||
|
/* Having root installed */
|
||||||
|
#cmakedefine HAVE_ROOT
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `sqrt' function. */
|
||||||
|
#cmakedefine HAVE_SQRT
|
||||||
|
|
||||||
|
/* Define to 1 if stdbool.h conforms to C99. */
|
||||||
|
#cmakedefine HAVE_STDBOOL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdint.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDINT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||||
|
#cmakedefine HAVE_STDLIB_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strdup' function. */
|
||||||
|
#cmakedefine HAVE_STRDUP
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
|
#cmakedefine HAVE_STRINGS_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
|
#cmakedefine HAVE_STRING_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `strstr' function. */
|
||||||
|
#cmakedefine HAVE_STRSTR
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_STAT_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_TYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <unistd.h> header file. */
|
||||||
|
#cmakedefine HAVE_UNISTD_H
|
||||||
|
|
||||||
|
/* Define to 1 if the system has the type `_Bool'. */
|
||||||
|
#cmakedefine HAVE__BOOL
|
||||||
|
|
||||||
|
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||||
|
*/
|
||||||
|
#cmakedefine LT_OBJDIR
|
||||||
|
|
||||||
|
/* Define to the address where bug reports for this package should be sent. */
|
||||||
|
#cmakedefine PACKAGE_BUGREPORT
|
||||||
|
|
||||||
|
/* Define to the full name of this package. */
|
||||||
|
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
|
||||||
|
|
||||||
|
/* Define to the full name and version of this package. */
|
||||||
|
#cmakedefine PACKAGE_STRING
|
||||||
|
|
||||||
|
/* Define to the one symbol short name of this package. */
|
||||||
|
#cmakedefine PACKAGE_TARNAME
|
||||||
|
|
||||||
|
/* Define to the home page for this package. */
|
||||||
|
#cmakedefine PACKAGE_URL "@PACKAGE_URL@"
|
||||||
|
|
||||||
|
/* Define to the version of this package. */
|
||||||
|
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||||
|
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#cmakedefine STDC_HEADERS
|
||||||
|
|
||||||
|
/* SVN revision number */
|
||||||
|
#cmakedefine SVN_REVISION "@SVN_REVISION@"
|
||||||
|
|
||||||
|
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||||
|
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#undef inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // HAVE_CONFIG_H
|
||||||
237
CMakeLists.txt
Normal file
237
CMakeLists.txt
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
|
||||||
|
################################################################################
|
||||||
|
##### CMAKE LISTS ##############################################################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
cmake_minimum_required (VERSION 2.6)
|
||||||
|
|
||||||
|
execute_process(COMMAND "clear")
|
||||||
|
message("//////////////////////////////////////////////////////////////////////")
|
||||||
|
message("/////////////////// CMAKE PJOJECT CONFIGURATION //////////////////////")
|
||||||
|
message("//////////////////////////////////////////////////////////////////////")
|
||||||
|
|
||||||
|
## -------------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
project(uLib)
|
||||||
|
|
||||||
|
# The version number.
|
||||||
|
set(PROJECT_VERSION_MAJOR 0)
|
||||||
|
set(PROJECT_VERSION_MINOR 2)
|
||||||
|
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
|
||||||
|
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
|
||||||
|
|
||||||
|
set(PACKAGE_VERSION ${PROJECT_VERSION})
|
||||||
|
set(PACKAGE_NAME "mutom-${PROJECT_VERSION}" CACHE STRING "name of the package defined inside code (config.h)")
|
||||||
|
set(PACKAGE_LIBPREFIX "mutom" CACHE STRING "suffix for each library component name")
|
||||||
|
set(PACKAGE_URL "http:://mutom.pd.infn.it" CACHE STRING "url of the project")
|
||||||
|
set(PACKAGE_AUTHOR "Andrea Rigoni Garola <andrea.rigoni@pd.infn.it>")
|
||||||
|
|
||||||
|
|
||||||
|
## MACROS ------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
set(ULIB_CMAKE_DIR "${PROJECT_SOURCE_DIR}/CMake")
|
||||||
|
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
|
||||||
|
message(STATUS "Module path: ${CMAKE_MODULE_PATH}")
|
||||||
|
|
||||||
|
include(uLibMacros)
|
||||||
|
include(uLibDebugMacro)
|
||||||
|
include(uLibTargetMacros)
|
||||||
|
include(uLibGenerateRMake)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## GLOBALS ------------------------------------------------------------------ ##
|
||||||
|
|
||||||
|
include(uLibCommon)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") ## Add flags here ##
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
## FIND PACKAGES ------------------------------------------------------------ ##
|
||||||
|
|
||||||
|
include(uLibFindDependencies)
|
||||||
|
|
||||||
|
|
||||||
|
## CONFIG ------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
include(uLibConfigHeader)
|
||||||
|
|
||||||
|
## ADD LIBRARIES SUBDIRECTORIES --------------------------------------------- ##
|
||||||
|
|
||||||
|
## select modules ##
|
||||||
|
set(ULIB_SELECTED_MODULES
|
||||||
|
ltk
|
||||||
|
Core
|
||||||
|
Math
|
||||||
|
Detectors
|
||||||
|
Root
|
||||||
|
)
|
||||||
|
|
||||||
|
## uLib_add_shared_library puts names there
|
||||||
|
set(ULIB_SHARED_LIBRARIES)
|
||||||
|
|
||||||
|
if(ULIB_USE_VTK)
|
||||||
|
LIST(APPEND ULIB_SELECTED_MODULES Vtk)
|
||||||
|
endif(ULIB_USE_VTK)
|
||||||
|
|
||||||
|
## this gets ulib modules into a variable ##
|
||||||
|
function(uLib_modules result)
|
||||||
|
set(out)
|
||||||
|
foreach(module ${ULIB_SELECTED_MODULES})
|
||||||
|
list(APPEND out ${PACKAGE_LIBPREFIX}${module})
|
||||||
|
endforeach(module)
|
||||||
|
set(${result} "${out}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
## ENTERING MODULES SUBDIRECTORIES ##
|
||||||
|
message("/////////// SELECTED MODULES //////////////")
|
||||||
|
foreach(module ${ULIB_SELECTED_MODULES})
|
||||||
|
message(STATUS "adding module: ${module}")
|
||||||
|
set( uLib-module ${module})
|
||||||
|
include_directories(${SRC_DIR}/${module})
|
||||||
|
add_subdirectory(${SRC_DIR}/${module})
|
||||||
|
endforeach(module)
|
||||||
|
|
||||||
|
## SINGLE LIBRARY LINKING ## (work in progress ... )
|
||||||
|
option(ULIB_SINGLELIBRARY "Link everything to a single library" OFF)
|
||||||
|
if(ULIB_SINGLELIBRARY)
|
||||||
|
# set(modgrp)
|
||||||
|
# foreach(module ${ULIB_SELECTED_MODULES})
|
||||||
|
# set(grpn srcgrp_${module})
|
||||||
|
# list(APPEND modgrp ${grpn})
|
||||||
|
# endforeach(module)
|
||||||
|
# add_library(${project_name} SHARED ${srcgrp_Core})
|
||||||
|
endif(ULIB_SINGLELIBRARY)
|
||||||
|
|
||||||
|
## UTILITIES ##
|
||||||
|
add_subdirectory("${SRC_DIR}/utils/make_recipe")
|
||||||
|
|
||||||
|
|
||||||
|
## PKG CONFIG compatible file ----------------------------------------------- ##
|
||||||
|
|
||||||
|
set(PKGCONFIG_FILE_ENABLE OFF CACHE BOOL "enable pkg-config file")
|
||||||
|
if(PKGCONFIG_FILE_ENABLE)
|
||||||
|
message("/////////// PKG-CONFIG DISTILLER //////////////")
|
||||||
|
set(PKGCONFIG_FILE_DESTDIR "/lib/pkgconfig/" CACHE PATH "destination path for pkg-config file")
|
||||||
|
set(PKGCONFIG_LIBS)
|
||||||
|
|
||||||
|
message(STATUS "[cflags] ${CMAKE_C_FLAGS}")
|
||||||
|
message(STATUS "[cxxflags] ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
foreach(module ${ULIB_SHARED_LIBRARIES})
|
||||||
|
set(PKGCONFIG_LIBS "${PKGCONFIG_LIBS} ${CMAKE_LINK_LIBRARY_FLAG}${module}")
|
||||||
|
endforeach(module)
|
||||||
|
message(STATUS "[libs] ${PKGCONFIG_LIBS}")
|
||||||
|
|
||||||
|
set(PKGCONFIG_FLAGS)
|
||||||
|
#add_custom_target(Dummy)
|
||||||
|
|
||||||
|
# add the executable
|
||||||
|
uLib_add_target(Dummy test.cpp)
|
||||||
|
target_link_libraries(Dummy ${PACKAGE_LIBPREFIX}Core)
|
||||||
|
target_link_libraries(Dummy ${Boost_SERIALIZATION_LIBRARY})
|
||||||
|
target_link_libraries(Dummy ${Boost_SIGNALS_LIBRARY})
|
||||||
|
target_link_libraries(Dummy ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||||
|
target_link_libraries(Dummy ${Geant4_LIBRARIES})
|
||||||
|
target_link_libraries(Dummy ${ROOT_LIBRARIES})
|
||||||
|
target_link_libraries(Dummy ${VTK_LIBRARIES})
|
||||||
|
|
||||||
|
get_gcc_compile_flags(Dummy, gcc_flags_list)
|
||||||
|
foreach(item ${gcc_flags_list})
|
||||||
|
message(STATUS "[gcc cflags] ${item}")
|
||||||
|
set(PKGCONFIG_FLAGS "${PKGCONFIG_FLAGS} ${item}")
|
||||||
|
endforeach(item)
|
||||||
|
message(STATUS "[includes] ${PKGCONFIG_FLAGS}")
|
||||||
|
|
||||||
|
get_gcc_link_flags(Dummy, gcc_flags_list)
|
||||||
|
foreach(item ${gcc_flags_list})
|
||||||
|
message(STATUS "[gcc libs] ${item}")
|
||||||
|
endforeach(item)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
"${PROJECT_SOURCE_DIR}/CMakePkgConfig.pc.in"
|
||||||
|
"${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc"
|
||||||
|
)
|
||||||
|
INSTALL_FILES(${PKGCONFIG_FILE_DESTDIR} FILES ${PROJECT_BINARY_DIR}/libmutom-${PACKAGE_VERSION}.pc)
|
||||||
|
|
||||||
|
message("///////////////////////////////////////////")
|
||||||
|
endif(PKGCONFIG_FILE_ENABLE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## INSTALLS AND EXPORTS ----------------------------------------------------- ##
|
||||||
|
|
||||||
|
#export(PACKAGE uLib)
|
||||||
|
export(PACKAGE ULIB)
|
||||||
|
export(TARGETS ${ULIB_SHARED_LIBRARIES} ${ULIB_EXPORTED_TARGETS}
|
||||||
|
FILE "${PROJECT_BINARY_DIR}/uLibTargets.cmake" )
|
||||||
|
#export(TARGETS ${ULIB_EXPORTED_TARGETS}
|
||||||
|
# FILE "${PROJECT_BINARY_DIR}/uLibExeTargets.cmake" )
|
||||||
|
|
||||||
|
|
||||||
|
# Create the FooBarConfig.cmake and FooBarConfigVersion files
|
||||||
|
file(RELATIVE_PATH REL_INCLUDE_DIR "${PACKAGE_INSTALL_CMAKE_DIR}"
|
||||||
|
"${PACKAGE_INSTALL_INC_DIR}")
|
||||||
|
# ... for the build tree
|
||||||
|
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
|
||||||
|
configure_file(uLibConfig.cmake.in
|
||||||
|
"${PROJECT_BINARY_DIR}/uLibConfig.cmake" @ONLY)
|
||||||
|
# ... for the install tree
|
||||||
|
set(CONF_INCLUDE_DIRS "\${ULIB_CMAKE_DIR}/${REL_INCLUDE_DIR}")
|
||||||
|
configure_file(uLibConfig.cmake.in
|
||||||
|
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake" @ONLY)
|
||||||
|
# ... for both
|
||||||
|
configure_file(uLibConfigVersion.cmake.in
|
||||||
|
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake" @ONLY)
|
||||||
|
|
||||||
|
# Install the FooBarConfig.cmake and FooBarConfigVersion.cmake
|
||||||
|
install(FILES
|
||||||
|
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/uLibConfig.cmake"
|
||||||
|
"${PROJECT_BINARY_DIR}/uLibConfigVersion.cmake"
|
||||||
|
DESTINATION "${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||||
|
|
||||||
|
# Install the export set for use with the install-tree
|
||||||
|
install(EXPORT "${PROJECT_NAME}Targets" DESTINATION
|
||||||
|
"${PACKAGE_INSTALL_CMAKE_DIR}" COMPONENT dev)
|
||||||
|
|
||||||
|
install(FILES ${PROJECT_SOURCE_DIR}/ulib.h DESTINATION ${PACKAGE_INSTALL_INC_DIR})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## dummy main executable ---------------------------------------------------- ##
|
||||||
|
|
||||||
|
message("Sara's debug....")
|
||||||
|
message(${ROOT_LIBRARIES})
|
||||||
|
|
||||||
|
# add the executable
|
||||||
|
add_executable(Coretest test.cpp)
|
||||||
|
target_link_libraries(Coretest ${PACKAGE_LIBPREFIX}Core)
|
||||||
|
#target_link_libraries(Coretest ${Boost_SERIALIZATION_LIBRARY})
|
||||||
|
#target_link_libraries(Coretest ${Boost_SIGNALS_LIBRARY})
|
||||||
|
#target_link_libraries(Coretest ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||||
|
#target_link_libraries(Coretest ${Geant4_LIBRARIES})
|
||||||
|
target_link_libraries(Coretest ${ROOT_LIBRARIES})
|
||||||
|
target_link_libraries(Coretest ${VTK_LIBRARIES})
|
||||||
|
|
||||||
|
#message( "---------------------------------------------------------------------" )
|
||||||
|
#execute_process(COMMAND
|
||||||
|
# "ls"
|
||||||
|
## "cmake --find-package -DNAME=uLib -DLANGUAGE=C -DCOMPILER_ID=GNU -DMODE=COMPILE"
|
||||||
|
# )
|
||||||
|
#message( "---------------------------------------------------------------------" )
|
||||||
|
|
||||||
|
## -------------------------------------------------------------------------- ##
|
||||||
|
|
||||||
|
|
||||||
|
# TODO clean also subdirectories
|
||||||
|
add_custom_target(clean-cmake-files
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${ULIB_CMAKE_DIR}/clean-all.cmake
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
13
CMakePkgConfig.pc.in
Normal file
13
CMakePkgConfig.pc.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
prefix=@prefix@
|
||||||
|
exec_prefix=@exec_prefix@
|
||||||
|
libdir=@libdir@
|
||||||
|
includedir=@includedir@
|
||||||
|
|
||||||
|
Name: Mutom Library (INFN)
|
||||||
|
Description: Library for Muon Tomography experiments.
|
||||||
|
Url: @PACKAGE_URL@
|
||||||
|
Version: @PACKAGE_VERSION@
|
||||||
|
Requires: eigen3
|
||||||
|
Libs: -L${libdir} @PKGCONFIG_LIBS@
|
||||||
|
Cflags: @CMAKE_C_FLAGS@ @CMAKE_CXX_FLAGS@ @PKGCONFIG_INCLUDES@
|
||||||
92
src/Core/Archives.cpp
Normal file
92
src/Core/Archives.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Archives.h"
|
||||||
|
|
||||||
|
//#define BOOST_ARCHIVE_SOURCE
|
||||||
|
#include <boost/archive/detail/archive_serializer_map.hpp>
|
||||||
|
|
||||||
|
// explicitly instantiate for this type of xml stream
|
||||||
|
#include <boost/archive/impl/archive_serializer_map.ipp>
|
||||||
|
|
||||||
|
#include <boost/archive/impl/basic_xml_oarchive.ipp>
|
||||||
|
#include <boost/archive/impl/xml_oarchive_impl.ipp>
|
||||||
|
|
||||||
|
#include <boost/archive/impl/basic_xml_iarchive.ipp>
|
||||||
|
#include <boost/archive/impl/xml_iarchive_impl.ipp>
|
||||||
|
|
||||||
|
#include <boost/archive/impl/basic_text_oarchive.ipp>
|
||||||
|
#include <boost/archive/impl/text_oarchive_impl.ipp>
|
||||||
|
|
||||||
|
#include <boost/archive/impl/basic_text_iarchive.ipp>
|
||||||
|
#include <boost/archive/impl/text_iarchive_impl.ipp>
|
||||||
|
|
||||||
|
#include <boost/archive/polymorphic_xml_oarchive.hpp>
|
||||||
|
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::xml_oarchive> ;
|
||||||
|
template class basic_xml_oarchive <uLib::Archive::xml_oarchive> ;
|
||||||
|
template class xml_oarchive_impl <uLib::Archive::xml_oarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::xml_iarchive> ;
|
||||||
|
template class basic_xml_iarchive <uLib::Archive::xml_iarchive> ;
|
||||||
|
template class xml_iarchive_impl <uLib::Archive::xml_iarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::text_oarchive> ;
|
||||||
|
template class basic_text_oarchive <uLib::Archive::text_oarchive> ;
|
||||||
|
template class text_oarchive_impl <uLib::Archive::text_oarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::text_iarchive> ;
|
||||||
|
template class basic_text_iarchive <uLib::Archive::text_iarchive> ;
|
||||||
|
template class text_iarchive_impl <uLib::Archive::text_iarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::hrt_oarchive> ;
|
||||||
|
template class basic_text_oarchive <uLib::Archive::hrt_oarchive> ;
|
||||||
|
template class text_oarchive_impl <uLib::Archive::hrt_oarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::hrt_iarchive> ;
|
||||||
|
template class basic_text_iarchive <uLib::Archive::hrt_iarchive> ;
|
||||||
|
template class text_iarchive_impl <uLib::Archive::hrt_iarchive> ;
|
||||||
|
|
||||||
|
template class detail::archive_serializer_map <uLib::Archive::log_archive> ;
|
||||||
|
template class basic_xml_oarchive <uLib::Archive::log_archive> ;
|
||||||
|
template class xml_oarchive_impl <uLib::Archive::log_archive> ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace archive
|
||||||
|
} // namespace boost
|
||||||
781
src/Core/Archives.h
Normal file
781
src/Core/Archives.h
Normal file
@@ -0,0 +1,781 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_ARCHIVES_H
|
||||||
|
#define U_CORE_ARCHIVES_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
|
||||||
|
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/text_iarchive.hpp>
|
||||||
|
#include <boost/archive/text_oarchive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/xml_iarchive.hpp>
|
||||||
|
#include <boost/archive/xml_oarchive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/detail/register_archive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||||
|
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||||
|
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
|
||||||
|
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||||
|
|
||||||
|
#include "StringReader.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FWD DECLARATIONS OF ARCHIVES //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
|
||||||
|
class xml_iarchive;
|
||||||
|
class xml_oarchive;
|
||||||
|
class text_iarchive;
|
||||||
|
class text_oarchive;
|
||||||
|
class log_archive;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
namespace detail {
|
||||||
|
template<class ArchiveImplementation> class polymorphic_oarchive_route;
|
||||||
|
template<class ArchiveImplementation> class polymorphic_iarchive_route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace serialization {
|
||||||
|
template <typename T> struct hrp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES REGISTRATION //
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
namespace detail {
|
||||||
|
struct adl_tag {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
namespace detail {
|
||||||
|
// This function gets called, but its only purpose is to participate
|
||||||
|
// in overload resolution with the functions declared by
|
||||||
|
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
|
||||||
|
template <class Serializable>
|
||||||
|
void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The function declaration generated by this macro never actually
|
||||||
|
// gets called, but its return type gets instantiated, and that's
|
||||||
|
// enough to cause registration of serialization functions between
|
||||||
|
// Archive and any exported Serializable type. See also:
|
||||||
|
// boost/serialization/export.hpp
|
||||||
|
# define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
|
||||||
|
namespace boost { namespace archive { namespace detail { \
|
||||||
|
\
|
||||||
|
template <class Serializable> \
|
||||||
|
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \
|
||||||
|
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES IO INTERFACES //
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom implementation of boost interface_iarchive to add new operators
|
||||||
|
*/
|
||||||
|
template<class Archive>
|
||||||
|
class uLib_interface_iarchive
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
uLib_interface_iarchive(){};
|
||||||
|
public:
|
||||||
|
/////////////////////////////////////////////////////////
|
||||||
|
// archive public interface
|
||||||
|
typedef mpl::bool_<true> is_loading;
|
||||||
|
typedef mpl::bool_<false> is_saving;
|
||||||
|
|
||||||
|
// return a pointer to the most derived class
|
||||||
|
Archive * This(){
|
||||||
|
return static_cast<Archive *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const basic_pointer_iserializer *
|
||||||
|
register_type(T * = NULL){
|
||||||
|
const basic_pointer_iserializer & bpis =
|
||||||
|
boost::serialization::singleton<
|
||||||
|
pointer_iserializer<Archive, T>
|
||||||
|
>::get_const_instance();
|
||||||
|
this->This()->register_basic_serializer(bpis.get_basic_serializer());
|
||||||
|
return & bpis;
|
||||||
|
}
|
||||||
|
template<class T>
|
||||||
|
Archive & operator>>(T & t){
|
||||||
|
this->This()->load_override(t, 0);
|
||||||
|
return * this->This();
|
||||||
|
}
|
||||||
|
|
||||||
|
// the & operator
|
||||||
|
template<class T>
|
||||||
|
Archive & operator&(T & t){
|
||||||
|
return *(this->This()) >> t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the == operator
|
||||||
|
template <class T>
|
||||||
|
Archive & operator == (T & t) {
|
||||||
|
return this->operator &(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the != operator for human readable access
|
||||||
|
template <class T>
|
||||||
|
Archive & operator != (T & t) {
|
||||||
|
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
|
||||||
|
return * this->This();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom implementation of boost interface_oarchive to add new operators
|
||||||
|
*/
|
||||||
|
template <class Archive>
|
||||||
|
class uLib_interface_oarchive {
|
||||||
|
protected:
|
||||||
|
uLib_interface_oarchive(){};
|
||||||
|
public:
|
||||||
|
/////////////////////////////////////////////////////////
|
||||||
|
// archive public interface
|
||||||
|
typedef mpl::bool_<false> is_loading;
|
||||||
|
typedef mpl::bool_<true> is_saving;
|
||||||
|
|
||||||
|
// return a pointer to the most derived class
|
||||||
|
Archive * This(){
|
||||||
|
return static_cast<Archive *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const basic_pointer_oserializer *
|
||||||
|
register_type(const T * = NULL){
|
||||||
|
const basic_pointer_oserializer & bpos =
|
||||||
|
boost::serialization::singleton<
|
||||||
|
pointer_oserializer<Archive, T>
|
||||||
|
>::get_const_instance();
|
||||||
|
this->This()->register_basic_serializer(bpos.get_basic_serializer());
|
||||||
|
return & bpos;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Archive & operator<<(T & t){
|
||||||
|
// to get access you must redefine save_override by typing
|
||||||
|
// "using save_override" in archive impl
|
||||||
|
this->This()->save_override(t, 0);
|
||||||
|
return * this->This();
|
||||||
|
}
|
||||||
|
|
||||||
|
// the & operator
|
||||||
|
template<class T>
|
||||||
|
Archive & operator&(T & t){
|
||||||
|
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||||
|
return * this->This() << const_cast<const T &>(t);
|
||||||
|
#else
|
||||||
|
return * this->This() << t;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// the == operator
|
||||||
|
template <class T>
|
||||||
|
Archive & operator == (T & t) {
|
||||||
|
return this->operator &(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the != operator for human readable access
|
||||||
|
template <class T>
|
||||||
|
Archive & operator != (T & t) {
|
||||||
|
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
|
||||||
|
return * this->This();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
|
||||||
|
// With this declarations all uLib archive Implementation will use their own
|
||||||
|
// extended interface //
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_iarchive <uLib::Archive::xml_iarchive> : public
|
||||||
|
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_oarchive <uLib::Archive::xml_oarchive> : public
|
||||||
|
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_iarchive <uLib::Archive::text_iarchive> : public
|
||||||
|
uLib_interface_iarchive <uLib::Archive::text_iarchive> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_oarchive <uLib::Archive::text_oarchive> : public
|
||||||
|
uLib_interface_oarchive <uLib::Archive::text_oarchive> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_oarchive <uLib::Archive::log_archive> : public
|
||||||
|
uLib_interface_oarchive <uLib::Archive::log_archive> {};
|
||||||
|
|
||||||
|
|
||||||
|
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
|
||||||
|
// template <class TypeSeq> \
|
||||||
|
// struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
|
||||||
|
// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
|
||||||
|
// {};
|
||||||
|
|
||||||
|
//// Multiple size declaration //
|
||||||
|
//BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
|
||||||
|
|
||||||
|
//#undef _INERIT_NOFOLD_H
|
||||||
|
//#undef _INERIT_NOFOLD_V
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
} // archive
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES DEFINITIONS //
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
|
||||||
|
//template<class Archive>
|
||||||
|
//inline void load_const_override(Archive & ar, const char *t ){
|
||||||
|
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
|
||||||
|
// typex::invoke(ar, t);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//template<class Archive, class T>
|
||||||
|
//inline void load(Archive & ar, T &t){
|
||||||
|
// // if this assertion trips. It means we're trying to load a
|
||||||
|
// // const object with a compiler that doesn't have correct
|
||||||
|
// // funtion template ordering. On other compilers, this is
|
||||||
|
// // handled below.
|
||||||
|
// // detail::check_const_loading< T >();
|
||||||
|
// typedef
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
|
||||||
|
// mpl::identity<detail::load_pointer_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
|
||||||
|
// mpl::identity<detail::load_array_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
|
||||||
|
// mpl::identity<detail::load_enum_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// mpl::identity<detail::load_non_pointer_type<Archive> >
|
||||||
|
// >
|
||||||
|
// >
|
||||||
|
// >::type typex;
|
||||||
|
// typex::invoke(ar, t);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
namespace Archive {
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// POLYMORPHIC //
|
||||||
|
|
||||||
|
|
||||||
|
//class polymorphic_iarchive :
|
||||||
|
// public boost::archive::polymorphic_iarchive {
|
||||||
|
|
||||||
|
//public:
|
||||||
|
// void load_override(const char *t, BOOST_PFTO int)
|
||||||
|
// {
|
||||||
|
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t));
|
||||||
|
// }
|
||||||
|
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// XML //
|
||||||
|
|
||||||
|
class xml_iarchive :
|
||||||
|
public boost::archive::xml_iarchive_impl<xml_iarchive>
|
||||||
|
{
|
||||||
|
typedef xml_iarchive Archive;
|
||||||
|
typedef boost::archive::xml_iarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_xml_iarchive<Archive>;
|
||||||
|
friend class boost::archive::load_access;
|
||||||
|
public:
|
||||||
|
xml_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||||
|
xml_iarchive_impl<xml_iarchive>(is, flags)
|
||||||
|
{}
|
||||||
|
|
||||||
|
using basic_xml_iarchive::load_override;
|
||||||
|
|
||||||
|
// Anything not an attribute should be a name value pair as nvp or hrp
|
||||||
|
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive;
|
||||||
|
template<class T>
|
||||||
|
void load_override(
|
||||||
|
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||||
|
const
|
||||||
|
#endif
|
||||||
|
boost::serialization::hrp< T > & t,
|
||||||
|
int v
|
||||||
|
){
|
||||||
|
this->This()->load_start(t.name());
|
||||||
|
this->detail_common_iarchive::load_override(t.value(), 0);
|
||||||
|
// t.stov();
|
||||||
|
this->This()->load_end(t.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// class_name_type can't be handled here as it depends upon the
|
||||||
|
// char type used by the stream. So require the derived implementation.
|
||||||
|
// derived in this case is xml_iarchive_impl or base ..
|
||||||
|
using base::load_override;
|
||||||
|
|
||||||
|
void load_override(const char *str, int v) {
|
||||||
|
// StringReader sr(basic_text_iprimitive::is);
|
||||||
|
// sr >> str;
|
||||||
|
}
|
||||||
|
|
||||||
|
~xml_iarchive(){};
|
||||||
|
};
|
||||||
|
|
||||||
|
//typedef boost::archive::detail::polymorphic_iarchive_route<
|
||||||
|
//boost::archive::xml_iarchive_impl<xml_iarchive>
|
||||||
|
//> polymorphic_xml_iarchive;
|
||||||
|
|
||||||
|
template <class ArchiveImpl>
|
||||||
|
struct polymorphic_iarchive_route :
|
||||||
|
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl>
|
||||||
|
{
|
||||||
|
virtual void load(const char * t){
|
||||||
|
ArchiveImpl::load(t);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class polymorphic_xml_iarchive :
|
||||||
|
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> >
|
||||||
|
{
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
// friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||||
|
// friend class boost::archive::basic_xml_iarchive<Archive>;
|
||||||
|
// friend class boost::archive::load_access;
|
||||||
|
public:
|
||||||
|
virtual void load_override(const char *str, int v) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class xml_oarchive :
|
||||||
|
public boost::archive::xml_oarchive_impl<xml_oarchive>
|
||||||
|
{
|
||||||
|
typedef xml_oarchive Archive;
|
||||||
|
typedef boost::archive::xml_oarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_xml_oarchive<Archive>;
|
||||||
|
friend class boost::archive::save_access;
|
||||||
|
public:
|
||||||
|
xml_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||||
|
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// example of implementing save_override for const char* //
|
||||||
|
// void save_override(const char *t, int) {
|
||||||
|
// std::cout << "found char: " << t << "\n";
|
||||||
|
// }
|
||||||
|
|
||||||
|
using basic_xml_oarchive::save_override;
|
||||||
|
|
||||||
|
// special treatment for name-value pairs.
|
||||||
|
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive;
|
||||||
|
template<class T>
|
||||||
|
void save_override(
|
||||||
|
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||||
|
const
|
||||||
|
#endif
|
||||||
|
::boost::serialization::hrp< T > & t,
|
||||||
|
int v
|
||||||
|
){
|
||||||
|
this->This()->save_start(t.name());
|
||||||
|
// t.vtos();
|
||||||
|
// this->detail_common_oarchive::save_override(t.const_value(), 0);
|
||||||
|
this->This()->save_end(t.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_override(const char *str, int v) {
|
||||||
|
// Do not save any human decoration string //
|
||||||
|
// basic_text_oprimitive::save(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
~xml_oarchive(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||||
|
//boost::archive::xml_oarchive_impl<xml_oarchive>
|
||||||
|
//> polymorphic_xml_oarchive;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TEXT //
|
||||||
|
|
||||||
|
class text_iarchive :
|
||||||
|
public boost::archive::text_iarchive_impl<text_iarchive>
|
||||||
|
{
|
||||||
|
typedef text_iarchive Archive;
|
||||||
|
typedef boost::archive::text_iarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_text_iarchive<Archive>;
|
||||||
|
friend class boost::archive::load_access;
|
||||||
|
public:
|
||||||
|
text_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||||
|
text_iarchive_impl<Archive>(is, flags)
|
||||||
|
{}
|
||||||
|
|
||||||
|
using basic_text_iarchive::load_override;
|
||||||
|
|
||||||
|
void load_override(boost::archive::object_id_type & t, int) {}
|
||||||
|
|
||||||
|
// class_name_type can't be handled here as it depends upon the
|
||||||
|
// char type used by the stream. So require the derived implementation.
|
||||||
|
// derived in this case is xml_iarchive_impl or base ..
|
||||||
|
using base::load_override;
|
||||||
|
|
||||||
|
void load_override(const char *str, int v) {
|
||||||
|
StringReader sr(basic_text_iprimitive::is);
|
||||||
|
sr >> str;
|
||||||
|
}
|
||||||
|
|
||||||
|
~text_iarchive() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef text_iarchive naked_text_iarchive;
|
||||||
|
|
||||||
|
//typedef boost::archive::detail::polymorphic_iarchive_route<
|
||||||
|
//naked_text_iarchive
|
||||||
|
//> polymorphic_text_iarchive;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class text_oarchive :
|
||||||
|
public boost::archive::text_oarchive_impl<text_oarchive>
|
||||||
|
{
|
||||||
|
typedef text_oarchive Archive;
|
||||||
|
typedef boost::archive::text_oarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_text_oarchive<Archive>;
|
||||||
|
friend class boost::archive::save_access;
|
||||||
|
public:
|
||||||
|
text_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||||
|
boost::archive::text_oarchive_impl<Archive>(os, flags)
|
||||||
|
{}
|
||||||
|
|
||||||
|
using basic_text_oarchive::save_override;
|
||||||
|
|
||||||
|
void save_override(const char *str, int v) {
|
||||||
|
basic_text_oprimitive::save(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
~text_oarchive(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||||
|
//boost::archive::text_oarchive_impl<text_oarchive>
|
||||||
|
//> polymorphic_text_oarchive;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SIMPLE HUMAN READABLE TEXT //
|
||||||
|
|
||||||
|
class hrt_iarchive :
|
||||||
|
public boost::archive::text_iarchive_impl<hrt_iarchive>
|
||||||
|
{
|
||||||
|
typedef hrt_iarchive Archive;
|
||||||
|
typedef boost::archive::text_iarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_iarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_text_iarchive<Archive>;
|
||||||
|
friend class boost::archive::load_access;
|
||||||
|
public:
|
||||||
|
hrt_iarchive(std::istream & is, unsigned int flags = 0) :
|
||||||
|
base(is, flags | boost::archive::no_header )
|
||||||
|
{}
|
||||||
|
|
||||||
|
using basic_text_iarchive::load_override;
|
||||||
|
|
||||||
|
// hide all archive props //
|
||||||
|
void load_override( boost::archive::object_id_type & t, int) {}
|
||||||
|
void load_override( boost::archive::object_reference_type & t, int) {}
|
||||||
|
void load_override( boost::archive::version_type & t, int) {}
|
||||||
|
void load_override( boost::archive::class_id_type & t, int) {}
|
||||||
|
void load_override( boost::archive::class_id_optional_type & t, int) {}
|
||||||
|
void load_override( boost::archive::class_id_reference_type & t, int){}
|
||||||
|
void load_override( boost::archive::class_name_type & t, int) {}
|
||||||
|
void load_override( boost::archive::tracking_type & t, int) {}
|
||||||
|
|
||||||
|
// class_name_type can't be handled here as it depends upon the
|
||||||
|
// char type used by the stream. So require the derived implementation.
|
||||||
|
// derived in this case is xml_iarchive_impl or base ..
|
||||||
|
using base::load_override;
|
||||||
|
|
||||||
|
void load_override(const char *str, int v) {
|
||||||
|
StringReader sr(basic_text_iprimitive::is);
|
||||||
|
sr >> str;
|
||||||
|
}
|
||||||
|
|
||||||
|
~hrt_iarchive() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class hrt_oarchive :
|
||||||
|
public boost::archive::text_oarchive_impl<hrt_oarchive>
|
||||||
|
{
|
||||||
|
typedef hrt_oarchive Archive;
|
||||||
|
typedef boost::archive::text_oarchive_impl<Archive> base;
|
||||||
|
|
||||||
|
// give serialization implementation access to this class
|
||||||
|
friend class boost::archive::detail::interface_oarchive<Archive>;
|
||||||
|
friend class boost::archive::basic_text_oarchive<Archive>;
|
||||||
|
friend class boost::archive::save_access;
|
||||||
|
public:
|
||||||
|
hrt_oarchive(std::ostream & os, unsigned int flags = 0) :
|
||||||
|
base(os, flags | boost::archive::no_header )
|
||||||
|
{}
|
||||||
|
|
||||||
|
using basic_text_oarchive::save_override;
|
||||||
|
|
||||||
|
void save_override(const boost::archive::object_id_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::version_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||||
|
void save_override(const boost::archive::class_name_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::tracking_type & t, int) {}
|
||||||
|
|
||||||
|
|
||||||
|
void save_override(const char *str, int v) {
|
||||||
|
basic_text_oprimitive::save(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
~hrt_oarchive(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// XML FOR LOG OUTPUT PURPOUSE //
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
// log data to an output stream. This illustrates a simpler implemenation
|
||||||
|
// of text output which is useful for getting a formatted display of
|
||||||
|
// any serializable class. Intended to be useful as a debugging aid.
|
||||||
|
class log_archive :
|
||||||
|
/* protected ? */
|
||||||
|
public boost::archive::xml_oarchive_impl<log_archive>
|
||||||
|
{
|
||||||
|
typedef boost::archive::xml_oarchive_impl<log_archive> base;
|
||||||
|
typedef log_archive Archive;
|
||||||
|
// give serialization implementation access to this clas
|
||||||
|
friend class boost::archive::detail::interface_oarchive<log_archive>;
|
||||||
|
friend class boost::archive::basic_xml_oarchive<log_archive>;
|
||||||
|
friend class boost::archive::save_access;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void save_override(const char *str, int v) {
|
||||||
|
// Do not save any human decoration string //
|
||||||
|
// basic_text_oprimitive::save(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void save_override(T & t, BOOST_PFTO int){
|
||||||
|
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// activate this if you want to trap non nvp objects //
|
||||||
|
// template<class T>
|
||||||
|
// void save_override(T & t, BOOST_PFTO int)
|
||||||
|
// {
|
||||||
|
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
|
||||||
|
// // this->detail_common_oarchive::save_override(t, 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void save_override(const boost::serialization::nvp<T> & t, int){
|
||||||
|
base::save_override(t, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// specific overrides for attributes - not name value pairs so we
|
||||||
|
// want to trap them before the above "fall through"
|
||||||
|
// since we don't want to see these in the output - make them no-ops.
|
||||||
|
void save_override(const boost::archive::object_id_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::version_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||||
|
void save_override(const boost::archive::class_name_type & t, int) {}
|
||||||
|
void save_override(const boost::archive::tracking_type & t, int) {}
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
log_archive(std::ostream & os, unsigned int flags = 0) :
|
||||||
|
boost::archive::xml_oarchive_impl<log_archive>(
|
||||||
|
os,
|
||||||
|
flags | boost::archive::no_header
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
//typedef boost::archive::detail::polymorphic_oarchive_route<
|
||||||
|
//boost::archive::xml_oarchive_impl<log_archive>
|
||||||
|
//> polymorphic_log_archive;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // Archive
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_iarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_oarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_iarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_oarchive)
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
|
||||||
|
|
||||||
|
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_iarchive)
|
||||||
|
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_oarchive)
|
||||||
|
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_iarchive)
|
||||||
|
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive)
|
||||||
|
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_CORE_ARCHIVES_H
|
||||||
72
src/Core/Array.h
Normal file
72
src/Core/Array.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_ARRAY_H
|
||||||
|
#define U_CORE_ARRAY_H
|
||||||
|
|
||||||
|
#include <array> // std::array
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//// ERROR NOT WORKING CLASS, USE VECTOR INSTEAD //////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
template< typename T, Size_t size >
|
||||||
|
class Array : public std::array<T,size> {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template< typename T, Size_t size >
|
||||||
|
class SmartArray : public SmartPointer< Array<T,size> > {
|
||||||
|
typedef SmartPointer< Array<T,size> > ptr;
|
||||||
|
public:
|
||||||
|
SmartArray() : ptr(new Array<T,size>()) { }
|
||||||
|
SmartArray( const SmartArray ©) : ptr(copy) { }
|
||||||
|
virtual ~SmartArray() {}
|
||||||
|
|
||||||
|
T& operator[](unsigned int p) {
|
||||||
|
return ptr::get()->at(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ARRAY_H
|
||||||
46
src/Core/CMakeLists.txt
Normal file
46
src/Core/CMakeLists.txt
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
set(HEADERS
|
||||||
|
Archives.h
|
||||||
|
Array.h
|
||||||
|
Collection.h
|
||||||
|
Debug.h
|
||||||
|
Export.h
|
||||||
|
Function.h
|
||||||
|
Macros.h
|
||||||
|
Mpl.h
|
||||||
|
Object.h
|
||||||
|
ObjectProps.h
|
||||||
|
Options.h
|
||||||
|
Serializable.h
|
||||||
|
Signal.h
|
||||||
|
Singleton.h
|
||||||
|
SmartPointer.h
|
||||||
|
StaticInterface.h
|
||||||
|
StringReader.h
|
||||||
|
Types.h
|
||||||
|
Uuid.h
|
||||||
|
Vector.h
|
||||||
|
CommaInitializer.h
|
||||||
|
Timer.h
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(SOURCES
|
||||||
|
Archives.cpp
|
||||||
|
Object.cpp
|
||||||
|
Options.cpp
|
||||||
|
Serializable.cpp
|
||||||
|
Signal.cpp
|
||||||
|
Uuid.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${Boost_SERIALIZATION_LIBRARY}
|
||||||
|
${Boost_SIGNALS_LIBRARY}
|
||||||
|
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||||
|
${ROOT_LIBRARIES}
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
)
|
||||||
|
|
||||||
|
uLib_add_shared_library(${uLib-module})
|
||||||
|
add_subdirectory(testing)
|
||||||
100
src/Core/Collection.h
Normal file
100
src/Core/Collection.h
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_COLLECTION_H
|
||||||
|
#define U_CORE_COLLECTION_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "SmartPointer.h"
|
||||||
|
#include "Vector.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/////// COLLECTION TEMPLATE //////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Implements concept of unordered collection of elements
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
namespace Abstract {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Collection {
|
||||||
|
public:
|
||||||
|
virtual ~Collection() {}
|
||||||
|
|
||||||
|
virtual void AddItem(T obj) =0;
|
||||||
|
virtual void RemoveItem(int i) =0;
|
||||||
|
virtual int GetNumberOfItems() =0;
|
||||||
|
virtual T& At(unsigned int i) =0;
|
||||||
|
|
||||||
|
virtual void PrintSelf(std::ostream &o) =0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Collection : public Abstract::Collection<T> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Collection() : data() {}
|
||||||
|
Collection(int size) : data(size) {}
|
||||||
|
~Collection() {}
|
||||||
|
|
||||||
|
inline void AddItem(T obj) { data->push_back(obj); }
|
||||||
|
inline void RemoveItem(int i) { data.remove_element(i); }
|
||||||
|
inline int GetNumberOfItems() { return data->size(); }
|
||||||
|
|
||||||
|
inline T& At(unsigned int i) { return data->at(i); }
|
||||||
|
inline T& operator[] (unsigned int i) { return data->at(i); }
|
||||||
|
|
||||||
|
inline void PrintSelf(std::ostream &o);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SmartVector<T> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Collection<T>::PrintSelf(std::ostream &o)
|
||||||
|
{
|
||||||
|
o << " *** uLib Collection *** \n";
|
||||||
|
o << " n. of items = " << this->GetNumberOfItems() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // COLLECTION_H
|
||||||
89
src/Core/CommaInitializer.h
Normal file
89
src/Core/CommaInitializer.h
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#ifndef U_CORE_COMMAINITIALIZER_H
|
||||||
|
#define U_CORE_COMMAINITIALIZER_H
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
// Comma Initializer template ...
|
||||||
|
// ContentT should provide operator[] and resize() methods.
|
||||||
|
// Waiting for Static interface check
|
||||||
|
|
||||||
|
template < typename ContainerT, typename ContentT >
|
||||||
|
struct CommaInitializer
|
||||||
|
{
|
||||||
|
inline explicit CommaInitializer(ContainerT *container, ContentT s)
|
||||||
|
: container(container)
|
||||||
|
{
|
||||||
|
this->index = 0;
|
||||||
|
container->resize(1);
|
||||||
|
this->container->operator[](0) = s;
|
||||||
|
}
|
||||||
|
inline CommaInitializer & operator, (ContentT s) {
|
||||||
|
this->index++;
|
||||||
|
container->resize(index + 1);
|
||||||
|
this->container->operator[](this->index) = s;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContainerT *container;
|
||||||
|
unsigned int index;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Comma Initializer template for fixed array...
|
||||||
|
// ContentT should provide operator[] and size() methods.
|
||||||
|
// Waiting for Static interface check
|
||||||
|
|
||||||
|
template < typename ContainerT, typename ContentT >
|
||||||
|
struct CommaInitializerFixed
|
||||||
|
{
|
||||||
|
inline explicit CommaInitializerFixed(ContainerT *container, ContentT s)
|
||||||
|
: container(container)
|
||||||
|
{
|
||||||
|
this->index = 0;
|
||||||
|
this->container->operator[](0) = s;
|
||||||
|
}
|
||||||
|
inline CommaInitializerFixed & operator, (ContentT s) {
|
||||||
|
this->index++;
|
||||||
|
this->container->operator[](this->index) = s;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ContainerT *container;
|
||||||
|
unsigned int index;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // COMMAINITIALIZER_H
|
||||||
31
src/Core/Debug.cpp
Normal file
31
src/Core/Debug.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "Debug.h"
|
||||||
|
|
||||||
|
|
||||||
148
src/Core/Debug.h
Normal file
148
src/Core/Debug.h
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_DEBUG_H
|
||||||
|
#define U_CORE_DEBUG_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "ltk/ltkdebug.h"
|
||||||
|
#include "Macros.h"
|
||||||
|
#include "Types.h"
|
||||||
|
#include "Mpl.h"
|
||||||
|
#include "Vector.h"
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
#include <TObject.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct DebugAdapterInterface {
|
||||||
|
virtual ~DebugAdapterInterface() {}
|
||||||
|
|
||||||
|
virtual void operator()(char val) {}
|
||||||
|
virtual void operator()(unsigned char val) {}
|
||||||
|
virtual void operator()(short val) {}
|
||||||
|
virtual void operator()(unsigned short val) {}
|
||||||
|
virtual void operator()(int val) {}
|
||||||
|
virtual void operator()(unsigned int val) {}
|
||||||
|
virtual void operator()(long val) {}
|
||||||
|
virtual void operator()(unsigned long val) {}
|
||||||
|
|
||||||
|
virtual void operator()(float val) {}
|
||||||
|
virtual void operator()(double val) {}
|
||||||
|
|
||||||
|
virtual void operator()(std::string val) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct DebugAdapter {
|
||||||
|
struct AnyCastAdapterBase {
|
||||||
|
virtual ~AnyCastAdapterBase(){}
|
||||||
|
virtual void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
struct AnyCastAdapter : AnyCastAdapterBase {
|
||||||
|
void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) { ad->operator()(boost::any_cast<T>(val)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DItem {
|
||||||
|
DItem(){}
|
||||||
|
template <typename T> DItem(std::string str, T &t) :
|
||||||
|
m_adapter(new AnyCastAdapter<T>()),
|
||||||
|
m_name(str),
|
||||||
|
m_value(t) { }
|
||||||
|
|
||||||
|
SmartPointer<AnyCastAdapterBase> m_adapter;
|
||||||
|
std::string m_name;
|
||||||
|
boost::any m_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// text ADAPTER
|
||||||
|
|
||||||
|
class DebugAdapterText : public detail::DebugAdapterInterface {
|
||||||
|
std::ostream &m_out;
|
||||||
|
public:
|
||||||
|
DebugAdapterText(std::ostream &o) : m_out(o) {}
|
||||||
|
void operator()(int val) { m_out << "debug: " << val << "\n"; }
|
||||||
|
void operator()(std::string val) { m_out << "debug: " << val << "\n"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Debug {
|
||||||
|
typedef detail::DebugAdapterInterface AdapterInterface;
|
||||||
|
typedef SmartPointer<detail::DebugAdapterInterface> Adapter;
|
||||||
|
typedef detail::DebugAdapter::DItem DItem;
|
||||||
|
public:
|
||||||
|
|
||||||
|
template <typename T> void operator() (std::string str, T &t) { m_v.push_back(DItem(str,t)); }
|
||||||
|
|
||||||
|
void AddAdapter(AdapterInterface &ad) { m_a.push_back(Adapter(ad)); }
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
foreach(Adapter &ad, m_a) {
|
||||||
|
foreach(DItem &item, m_v) {
|
||||||
|
item.m_adapter->operator()(ad, item.m_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vector<DItem> m_v;
|
||||||
|
Vector<Adapter> m_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DEBUG_H
|
||||||
52
src/Core/DebugArchives.cpp
Normal file
52
src/Core/DebugArchives.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <TTree.h>
|
||||||
|
#include "DebugArchives.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
basic_Root_Ttree_oprimitive::basic_Root_Ttree_oprimitive(const char *tree_name)
|
||||||
|
{
|
||||||
|
m_tree = new TTree(tree_name,tree_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
basic_Root_Ttree_oprimitive::~basic_Root_Ttree_oprimitive()
|
||||||
|
{
|
||||||
|
m_tree->Write();
|
||||||
|
m_tree->ResetBranchAddresses();
|
||||||
|
m_tree->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
} // Archive
|
||||||
|
} // uLib
|
||||||
|
|
||||||
289
src/Core/DebugArchives.h
Normal file
289
src/Core/DebugArchives.h
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_DEBUGARCHIVES_H
|
||||||
|
#define U_CORE_DEBUGARCHIVES_H
|
||||||
|
|
||||||
|
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
|
||||||
|
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/text_iarchive.hpp>
|
||||||
|
#include <boost/archive/text_oarchive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/xml_iarchive.hpp>
|
||||||
|
#include <boost/archive/xml_oarchive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/detail/register_archive.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/polymorphic_iarchive.hpp>
|
||||||
|
#include <boost/archive/polymorphic_oarchive.hpp>
|
||||||
|
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
|
||||||
|
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/polymorphic_text_oarchive.hpp>
|
||||||
|
|
||||||
|
#include "Archives.h"
|
||||||
|
#include "StringReader.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FWD DECLARATIONS OF ARCHIVES //
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
|
||||||
|
class Root_debug_archive;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
namespace detail {
|
||||||
|
template<class ArchiveImplementation> class polymorphic_oarchive_route;
|
||||||
|
template<class ArchiveImplementation> class polymorphic_iarchive_route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace serialization {
|
||||||
|
template <typename T> struct hrp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES REGISTRATION //
|
||||||
|
|
||||||
|
// in Archives.h
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES IO INTERFACES //
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
|
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
|
||||||
|
// With this declarations all uLib archive Implementation will use their own
|
||||||
|
// extended interface //
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class interface_iarchive <uLib::Archive::Root_debug_archive> : public
|
||||||
|
uLib_interface_iarchive <uLib::Archive::Root_debug_archive> {};
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
} // archive
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ARCHIVES DEFINITIONS //
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
|
||||||
|
//template<class Archive>
|
||||||
|
//inline void load_const_override(Archive & ar, const char *t ){
|
||||||
|
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
|
||||||
|
// typex::invoke(ar, t);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//template<class Archive, class T>
|
||||||
|
//inline void load(Archive & ar, T &t){
|
||||||
|
// // if this assertion trips. It means we're trying to load a
|
||||||
|
// // const object with a compiler that doesn't have correct
|
||||||
|
// // funtion template ordering. On other compilers, this is
|
||||||
|
// // handled below.
|
||||||
|
// // detail::check_const_loading< T >();
|
||||||
|
// typedef
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
|
||||||
|
// mpl::identity<detail::load_pointer_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
|
||||||
|
// mpl::identity<detail::load_array_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
|
||||||
|
// mpl::identity<detail::load_enum_type<Archive> >
|
||||||
|
// ,//else
|
||||||
|
// mpl::identity<detail::load_non_pointer_type<Archive> >
|
||||||
|
// >
|
||||||
|
// >
|
||||||
|
// >::type typex;
|
||||||
|
// typex::invoke(ar, t);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROOT FWD
|
||||||
|
class TTree;
|
||||||
|
///////////
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
class basic_Root_Ttree_oprimitive
|
||||||
|
{
|
||||||
|
TTree *m_tree;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
basic_Root_Ttree_oprimitive(const char *tree_name);
|
||||||
|
~basic_Root_Ttree_oprimitive();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// XML FOR LOG OUTPUT PURPOUSE //
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
//// log data to an output stream. This illustrates a simpler implemenation
|
||||||
|
//// of text output which is useful for getting a formatted display of
|
||||||
|
//// any serializable class. Intended to be useful as a debugging aid.
|
||||||
|
class Root_debug_archive :
|
||||||
|
/* protected ? */
|
||||||
|
public boost::archive::detail::common_oarchive<Archive>
|
||||||
|
{
|
||||||
|
typedef boost::archive::detail::common_oarchive<Root_debug_archive> base;
|
||||||
|
typedef Root_debug_archive Archive;
|
||||||
|
|
||||||
|
// give serialization implementation access to this clas
|
||||||
|
friend class boost::archive::detail::interface_oarchive<Root_debug_archive>;
|
||||||
|
friend class boost::archive::save_access;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// void save_override(const char *str, int v) {
|
||||||
|
// // Do not save any human decoration string //
|
||||||
|
// // basic_text_oprimitive::save(str);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// template<class T>
|
||||||
|
// void save_override(T & t, BOOST_PFTO int){
|
||||||
|
// base::save_override(boost::serialization::make_nvp(NULL, t), 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // activate this if you want to trap non nvp objects //
|
||||||
|
// // template<class T>
|
||||||
|
// // void save_override(T & t, BOOST_PFTO int)
|
||||||
|
// // {
|
||||||
|
// // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
|
||||||
|
// // // this->detail_common_oarchive::save_override(t, 0);
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// template<class T>
|
||||||
|
// void save_override(const boost::serialization::nvp<T> & t, int){
|
||||||
|
// base::save_override(t, 0);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// // specific overrides for attributes - not name value pairs so we
|
||||||
|
// // want to trap them before the above "fall through"
|
||||||
|
// // since we don't want to see these in the output - make them no-ops.
|
||||||
|
// void save_override(const boost::archive::object_id_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::object_reference_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::version_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::class_id_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::class_id_optional_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::class_id_reference_type & t, int){}
|
||||||
|
// void save_override(const boost::archive::class_name_type & t, int) {}
|
||||||
|
// void save_override(const boost::archive::tracking_type & t, int) {}
|
||||||
|
|
||||||
|
|
||||||
|
//public:
|
||||||
|
// Root_debug_archive(std::ostream & os, unsigned int flags = 0) :
|
||||||
|
// boost::archive::xml_oarchive_impl<log_archive>(
|
||||||
|
// os,
|
||||||
|
// flags | boost::archive::no_header
|
||||||
|
// )
|
||||||
|
// {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // Archive
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::Root_debug_archive)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_CORE_DEBUGARCHIVES_H
|
||||||
117
src/Core/Export.h
Normal file
117
src/Core/Export.h
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_EXPORT_H
|
||||||
|
#define U_CORE_EXPORT_H
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <cstddef> // NULL
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
|
#include <boost/type_traits/is_polymorphic.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/assert.hpp>
|
||||||
|
#include <boost/mpl/and.hpp>
|
||||||
|
#include <boost/mpl/not.hpp>
|
||||||
|
#include <boost/mpl/bool.hpp>
|
||||||
|
|
||||||
|
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
|
||||||
|
#include <boost/serialization/static_warning.hpp>
|
||||||
|
#include <boost/serialization/assume_abstract.hpp>
|
||||||
|
#include <boost/serialization/force_include.hpp>
|
||||||
|
#include <boost/serialization/singleton.hpp>
|
||||||
|
|
||||||
|
#include <boost/archive/detail/register_archive.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Archives.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Archive {
|
||||||
|
namespace detail {
|
||||||
|
namespace extra_detail {
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct guid_initializer
|
||||||
|
{
|
||||||
|
void export_guid(mpl::false_) const {
|
||||||
|
// generates the statically-initialized objects whose constructors
|
||||||
|
// register the information allowing serialization of T objects
|
||||||
|
// through pointers to their base classes.
|
||||||
|
boost::archive::detail::
|
||||||
|
instantiate_ptr_serialization((T*)0, 0,
|
||||||
|
uLib::Archive::detail::adl_tag());
|
||||||
|
}
|
||||||
|
void export_guid(mpl::true_) const {
|
||||||
|
}
|
||||||
|
guid_initializer const & export_guid() const {
|
||||||
|
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
|
||||||
|
// note: exporting an abstract base class will have no effect
|
||||||
|
// and cannot be used to instantitiate serialization code
|
||||||
|
// (one might be using this in a DLL to instantiate code)
|
||||||
|
//BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
|
||||||
|
export_guid(boost::serialization::is_abstract< T >());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct init_guid;
|
||||||
|
|
||||||
|
} // anonymous
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace Archive
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
|
||||||
|
namespace uLib { \
|
||||||
|
namespace Archive { \
|
||||||
|
namespace detail { \
|
||||||
|
namespace extra_detail { \
|
||||||
|
template<> \
|
||||||
|
struct init_guid< T > { \
|
||||||
|
static guid_initializer< T > const & g; \
|
||||||
|
}; \
|
||||||
|
guid_initializer< T > const & init_guid< T >::g = \
|
||||||
|
::boost::serialization::singleton< \
|
||||||
|
guid_initializer< T > \
|
||||||
|
>::get_mutable_instance().export_guid(); \
|
||||||
|
}}}} \
|
||||||
|
/**/
|
||||||
|
|
||||||
|
#endif // EXPORT_H
|
||||||
54
src/Core/Flags.h
Normal file
54
src/Core/Flags.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef FLAGS_H
|
||||||
|
#define FLAGS_H
|
||||||
|
|
||||||
|
#include <Core/Types.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
template<typename Enum>
|
||||||
|
class Flags
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
public:
|
||||||
|
typedef Enum enum_type;
|
||||||
|
CONSTEXPR inline Flags(const Flags &f) : i(f.i) {}
|
||||||
|
CONSTEXPR inline Flags(Enum f) : i(f) {}
|
||||||
|
CONSTEXPR inline Flags() : i(0) {}
|
||||||
|
|
||||||
|
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
|
||||||
|
inline Flags &operator&=(int mask) { i &= mask; return *this; }
|
||||||
|
inline Flags &operator&=(uint mask) { i &= mask; return *this; }
|
||||||
|
inline Flags &operator|=(Flags f) { i |= f.i; return *this; }
|
||||||
|
inline Flags &operator|=(Enum f) { i |= f; return *this; }
|
||||||
|
inline Flags &operator^=(Flags f) { i ^= f.i; return *this; }
|
||||||
|
inline Flags &operator^=(Enum f) { i ^= f; return *this; }
|
||||||
|
|
||||||
|
CONSTEXPR inline operator int() const { return i; }
|
||||||
|
|
||||||
|
CONSTEXPR inline Flags operator|(Flags f) const { return Flags(Enum(i | f.i)); }
|
||||||
|
CONSTEXPR inline Flags operator|(Enum f) const { return Flags(Enum(i | f)); }
|
||||||
|
CONSTEXPR inline Flags operator^(Flags f) const { return Flags(Enum(i ^ f.i)); }
|
||||||
|
CONSTEXPR inline Flags operator^(Enum f) const { return Flags(Enum(i ^ f)); }
|
||||||
|
CONSTEXPR inline Flags operator&(int mask) const { return Flags(Enum(i & mask)); }
|
||||||
|
CONSTEXPR inline Flags operator&(uint mask) const { return Flags(Enum(i & mask)); }
|
||||||
|
CONSTEXPR inline Flags operator&(Enum f) const { return Flags(Enum(i & f)); }
|
||||||
|
CONSTEXPR inline Flags operator~() const { return Flags(Enum(~i)); }
|
||||||
|
|
||||||
|
CONSTEXPR inline bool operator!() const { return !i; }
|
||||||
|
|
||||||
|
inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ULIB_OPERATORS_FOR_FLAGS(Flags) \
|
||||||
|
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
|
||||||
|
{ return QFlags<Flags::enum_type>(f1) | f2; } \
|
||||||
|
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
|
||||||
|
{ return f2 | f1; }
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FLAGS_H
|
||||||
155
src/Core/Function.h
Normal file
155
src/Core/Function.h
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_FUNCTION_H
|
||||||
|
#define U_CORE_FUNCTION_H
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include <boost/type_traits.hpp>
|
||||||
|
#include <boost/type_traits/remove_pointer.hpp>
|
||||||
|
|
||||||
|
#include <boost/function_types/function_type.hpp>
|
||||||
|
#include <boost/function_types/parameter_types.hpp>
|
||||||
|
#include <boost/function_types/function_arity.hpp>
|
||||||
|
//#include <boost/typeof/std/utility.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// type synthesize ( please read: boost implementation synthesize.hpp ) //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO: change this to boost implementation //
|
||||||
|
// return a reference to function ... as the boost signal signature wants
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct FunctionTypes {};
|
||||||
|
|
||||||
|
template <typename R, class O>
|
||||||
|
struct FunctionTypes< R(O::*)() > {
|
||||||
|
typedef R ref();
|
||||||
|
typedef R (ptr)();
|
||||||
|
typedef O obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, class O, typename T0>
|
||||||
|
struct FunctionTypes< R(O::*)(T0) > {
|
||||||
|
typedef R ref(T0);
|
||||||
|
typedef R (ptr)(T0);
|
||||||
|
typedef O obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, class O, typename T0, typename T1>
|
||||||
|
struct FunctionTypes< R(O::*)(T0,T1) > {
|
||||||
|
typedef R ref(T0,T1);
|
||||||
|
typedef R (ptr)(T0,T1);
|
||||||
|
typedef O obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R, class O, typename T0, typename T1, typename T2>
|
||||||
|
struct FunctionTypes< R(O::*)(T0,T1,T2) > {
|
||||||
|
typedef R ref(T0,T1,T2);
|
||||||
|
typedef R (ptr)(T0,T1,T2);
|
||||||
|
typedef O obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Function pointers //
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
struct FunctionPointer {
|
||||||
|
typedef typename boost::function_types::function_type<Func>::type Signature;
|
||||||
|
typedef typename FunctionTypes<Func>::ref SignalSignature;
|
||||||
|
enum {
|
||||||
|
arity = boost::function_types::function_arity<Func>::value,
|
||||||
|
ismfp = boost::is_member_function_pointer<Func>::value
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::mpl::bool_< ismfp > HasObjectType;
|
||||||
|
typedef typename FunctionTypes<Func>::obj Object;
|
||||||
|
typedef boost::function_traits< Signature > Traits;
|
||||||
|
|
||||||
|
virtual void PrintSelf( std::ostream &o ) {
|
||||||
|
o << "[fp: " << typeid(Signature).name()
|
||||||
|
<< " arity: " << arity << "]\n"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////// generic mfp container object /////////////////////////////////////////
|
||||||
|
|
||||||
|
class GenericMFPtr {
|
||||||
|
typedef void (GenericMFPtr::*_MFPtrStub_t)();
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef _MFPtrStub_t Type;
|
||||||
|
|
||||||
|
GenericMFPtr() {}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
GenericMFPtr(T in) {
|
||||||
|
m_ptr = reinterpret_cast<_MFPtrStub_t>(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool operator == (T in) {
|
||||||
|
return m_ptr == reinterpret_cast<_MFPtrStub_t>(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator == (const GenericMFPtr &in) {
|
||||||
|
return m_ptr == in.m_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type operator()() { return m_ptr; }
|
||||||
|
|
||||||
|
_MFPtrStub_t m_ptr;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FUNCTION_H
|
||||||
133
src/Core/Macros.h
Normal file
133
src/Core/Macros.h
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_MACROS_H
|
||||||
|
#define U_CORE_MACROS_H
|
||||||
|
|
||||||
|
//#ifndef HAVE_CONFIG_H
|
||||||
|
// #include "config.h"
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#define uLibAssert(condition) assert(condition)
|
||||||
|
|
||||||
|
|
||||||
|
// Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility //
|
||||||
|
// http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol //
|
||||||
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
#ifdef BUILDING_DLL
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define DLL_PUBLIC __attribute__ ((dllexport))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define DLL_PUBLIC __attribute__ ((dllimport))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#define DLL_LOCAL
|
||||||
|
#else
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
|
||||||
|
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC
|
||||||
|
#define DLL_LOCAL
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// foreach Qt style
|
||||||
|
#ifndef foreach
|
||||||
|
#include "boost/foreach.hpp"
|
||||||
|
#define foreach(ref, list) BOOST_FOREACH(ref,list)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define uLibVGetMacro(name,type) \
|
||||||
|
virtual inline const type Get##name() const = 0;
|
||||||
|
|
||||||
|
#define uLibVSetMacro(name,type) \
|
||||||
|
virtual inline void Set##name(const type name) = 0;
|
||||||
|
|
||||||
|
#define uLibVGetSetMacro(name,type) \
|
||||||
|
uLibVGet(name,type); \
|
||||||
|
uLibVSet(name,type);
|
||||||
|
|
||||||
|
#define uLibVRefMacro(name,type) \
|
||||||
|
virtual inline type & name() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define uLibGetMacro(name,type) \
|
||||||
|
inline type Get##name() const { return this->m_##name; }
|
||||||
|
|
||||||
|
#define uLibConstRefMacro(name,type) \
|
||||||
|
inline const type & name() const { return this->m_##name; }
|
||||||
|
|
||||||
|
// verificare necessita' di typecast //
|
||||||
|
#define uLibSetMacro(name,type) \
|
||||||
|
inline void Set##name(type name) { this->m_##name = name; }
|
||||||
|
|
||||||
|
#define uLibGetSetMacro(name,type) \
|
||||||
|
inline type Get##name() const { return this->m_##name; } \
|
||||||
|
uLibSetMacro(name,type);
|
||||||
|
|
||||||
|
#define uLibRefMacro(name,type) \
|
||||||
|
inline type & name() { return this->m_##name; }
|
||||||
|
|
||||||
|
|
||||||
|
/* Following macros override usual branch prediction of compiler
|
||||||
|
* These are to be used in conditional statement whose result might
|
||||||
|
* be Bayesian biased:
|
||||||
|
*
|
||||||
|
* // previous_line
|
||||||
|
* if (likely(a>1)) { // block_1 }
|
||||||
|
* else { block_2 }
|
||||||
|
*
|
||||||
|
* will write the block_1 code right after previous line, without using
|
||||||
|
* compiler branch prediction for results. Otherwise
|
||||||
|
*
|
||||||
|
* // previous_line
|
||||||
|
* if (unlikely(a>1)) { // block_1 }
|
||||||
|
* else { block_2 }
|
||||||
|
*
|
||||||
|
* will write block_2 after previous_line, leaving block_1 after
|
||||||
|
* (usually after the end of the whole function! Use with care!)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define unlikely(expr) __builtin_expect(!!(expr), 0)
|
||||||
|
|
||||||
|
#define likely(expr) __builtin_expect(!!(expr), 1)
|
||||||
|
|
||||||
|
#endif // MACROS_H
|
||||||
41
src/Core/Makefile.am
Normal file
41
src/Core/Makefile.am
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
SUBDIRS = .
|
||||||
|
|
||||||
|
include $(top_srcdir)/Common.am
|
||||||
|
|
||||||
|
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Core
|
||||||
|
|
||||||
|
library_include_HEADERS = \
|
||||||
|
Archives.h \
|
||||||
|
Array.h \
|
||||||
|
Collection.h \
|
||||||
|
Debug.h \
|
||||||
|
Export.h \
|
||||||
|
Function.h \
|
||||||
|
Macros.h \
|
||||||
|
Mpl.h \
|
||||||
|
Object.h \
|
||||||
|
ObjectProps.h \
|
||||||
|
Options.h \
|
||||||
|
Serializable.h \
|
||||||
|
Signal.h \
|
||||||
|
Singleton.h \
|
||||||
|
SmartPointer.h \
|
||||||
|
StaticInterface.h \
|
||||||
|
StringReader.h \
|
||||||
|
Types.h \
|
||||||
|
Uuid.h \
|
||||||
|
Vector.h
|
||||||
|
|
||||||
|
|
||||||
|
_CORE_SOURCES = \
|
||||||
|
Archives.cpp \
|
||||||
|
Debug.cpp \
|
||||||
|
Object.cpp \
|
||||||
|
Options.cpp \
|
||||||
|
Serializable.cpp \
|
||||||
|
Signal.cpp \
|
||||||
|
Uuid.cpp
|
||||||
|
|
||||||
|
|
||||||
|
noinst_LTLIBRARIES = libmutomcore.la
|
||||||
|
libmutomcore_la_SOURCES = ${_CORE_SOURCES}
|
||||||
139
src/Core/Mpl.h
Normal file
139
src/Core/Mpl.h
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_MPL_H
|
||||||
|
#define U_MPL_H
|
||||||
|
|
||||||
|
#include <boost/preprocessor.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/fold.hpp>
|
||||||
|
#include <boost/mpl/inherit_linearly.hpp>
|
||||||
|
#include <boost/mpl/inherit.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/vector.hpp>
|
||||||
|
#include <boost/mpl/vector/vector0.hpp>
|
||||||
|
#include <boost/mpl/vector/vector10.hpp>
|
||||||
|
#include <boost/mpl/vector/vector20.hpp>
|
||||||
|
#include <boost/mpl/copy.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/transform.hpp>
|
||||||
|
#include <boost/mpl/transform_view.hpp>
|
||||||
|
#include <boost/mpl/filter_view.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/list.hpp>
|
||||||
|
#include <boost/mpl/string.hpp>
|
||||||
|
#include <boost/mpl/for_each.hpp>
|
||||||
|
#include <boost/mpl/has_xxx.hpp>
|
||||||
|
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Max size of nofold inerited capability
|
||||||
|
*/
|
||||||
|
#ifndef ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE
|
||||||
|
# define ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE 10
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
using namespace boost::mpl;
|
||||||
|
using namespace boost::mpl::placeholders;
|
||||||
|
|
||||||
|
//using boost::enable_if;
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inerit nofold implementation, set ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE to
|
||||||
|
* desired max derivation size keeping in mind that total size accounts all
|
||||||
|
* mutiple inherited classes.
|
||||||
|
*/
|
||||||
|
template <class TypeSeq, unsigned int size>
|
||||||
|
struct inherit_nofold {};
|
||||||
|
|
||||||
|
// Horizontal repetition macro //
|
||||||
|
#define _INERIT_NOFOLD_H(hz,hn,hdata) \
|
||||||
|
BOOST_PP_COMMA_IF(hn) \
|
||||||
|
mpl::at<TypeSeq,mpl::int_<hn> >::type
|
||||||
|
|
||||||
|
// Veritical repetition macro //
|
||||||
|
#define _INERIT_NOFOLD_V(vz,vn,vdata) \
|
||||||
|
template <class TypeSeq> \
|
||||||
|
struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
|
||||||
|
BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
|
||||||
|
{};
|
||||||
|
|
||||||
|
// Multiple size declaration //
|
||||||
|
BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
|
||||||
|
|
||||||
|
#undef _INERIT_NOFOLD_H
|
||||||
|
#undef _INERIT_NOFOLD_V
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a derivation tuple from mpl type sequence.
|
||||||
|
* The same behavior can be obtained by inherit_linearly but folding derivation
|
||||||
|
* results in a hard to read debugging
|
||||||
|
*/
|
||||||
|
template <class TypeSeq>
|
||||||
|
struct inherit_nofold {
|
||||||
|
typedef detail::inherit_nofold< TypeSeq, mpl::size<TypeSeq>::type::value > type;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** INHERIT LINEARLY standard utility macro */
|
||||||
|
#define ULIB_MPL_INHERIT_SEQ(_TypeList) \
|
||||||
|
uLib::mpl::inherit_linearly< _TypeList, mpl::inherit< mpl::_1, mpl::_2 > >::type
|
||||||
|
|
||||||
|
/** INHERIT NOFOLD utility macro (see struct inherit_nofold template) */
|
||||||
|
#define ULIB_MPL_INHERIT_NOFOLD_SEQ(_TypeList) \
|
||||||
|
uLib::mpl::inherit_nofold< _TypeList >::type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template< class T>
|
||||||
|
struct type {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <const char *N, class T>
|
||||||
|
struct nvp {
|
||||||
|
nvp() : name(N) {}
|
||||||
|
const char *name;
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // mpl
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
#endif // MPL_H
|
||||||
227
src/Core/Object.cpp
Normal file
227
src/Core/Object.cpp
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "Object.h"
|
||||||
|
#include "Vector.h"
|
||||||
|
|
||||||
|
#include "boost/archive/polymorphic_xml_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_xml_iarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_text_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_text_iarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_binary_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_binary_iarchive.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
const char *Version::PackageName = PACKAGE_NAME;
|
||||||
|
const char *Version::VersionNumber = PACKAGE_VERSION;
|
||||||
|
const char *Version::Release = "x"; //SVN_REVISION;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Object Private //
|
||||||
|
|
||||||
|
class ObjectPrivate {
|
||||||
|
public:
|
||||||
|
|
||||||
|
struct Signal {
|
||||||
|
GenericMFPtr sigptr;
|
||||||
|
std::string sigstr;
|
||||||
|
SignalBase *signal;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Slot {
|
||||||
|
GenericMFPtr sloptr;
|
||||||
|
std::string slostr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Vector<Signal> sigv;
|
||||||
|
Vector<Slot> slov;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// OBJECT IMPLEMENTATION
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Object::Object() :
|
||||||
|
d(new ObjectPrivate)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Object::Object(const Object ©) :
|
||||||
|
ObjectPropable(copy),
|
||||||
|
d(new ObjectPrivate(*copy.d))
|
||||||
|
{}
|
||||||
|
|
||||||
|
Object::~Object() {
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::DeepCopy(const Object ©)
|
||||||
|
{
|
||||||
|
// should lock to be tread safe //
|
||||||
|
memcpy(d,copy.d,sizeof(ObjectPrivate));
|
||||||
|
// ERROR! does not copy parameters ... <<<< FIXXXXX
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Object::SaveXml(std::ostream &os, Object &ob)
|
||||||
|
{
|
||||||
|
Archive::xml_oarchive ar(os);
|
||||||
|
ar << boost::serialization::make_nvp("Object",ob);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::LoadXml(std::istream &is, Object &ob)
|
||||||
|
{
|
||||||
|
Archive::xml_iarchive ar(is);
|
||||||
|
ar >> boost::serialization::make_nvp("Object",ob);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FINIRE
|
||||||
|
void Object::SaveConfig(std::ostream &os, int version)
|
||||||
|
{
|
||||||
|
Archive::xml_oarchive ar(os);
|
||||||
|
ObjectPropable::serialize(ar,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::LoadConfig(std::istream &is, int version)
|
||||||
|
{
|
||||||
|
if(!props()) this->init_properties();
|
||||||
|
Archive::xml_iarchive ar(is);
|
||||||
|
ObjectPropable::serialize(ar,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Object::PrintSelf(std::ostream &o) const
|
||||||
|
{
|
||||||
|
o << "OBJECT signals: ------------------\n";
|
||||||
|
Vector<ObjectPrivate::Signal>::Iterator itr;
|
||||||
|
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
|
||||||
|
{
|
||||||
|
o << " signal:[ " << itr->sigstr << " ]\n";
|
||||||
|
}
|
||||||
|
o << "--------------------------------------\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name)
|
||||||
|
{
|
||||||
|
ObjectPrivate::Signal s = {fptr,std::string(name),sig};
|
||||||
|
d->sigv.push_back(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name)
|
||||||
|
{
|
||||||
|
ObjectPrivate::Slot s = {fptr,std::string(name)};
|
||||||
|
d->slov.push_back(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const
|
||||||
|
{
|
||||||
|
for(int i=0; i<d->sigv.size(); ++i)
|
||||||
|
{
|
||||||
|
if(d->sigv[i].sigptr == fptr)
|
||||||
|
return d->sigv[i].signal;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SignalBase *Object::findSignalImpl(const char *name) const
|
||||||
|
{
|
||||||
|
std::string in(name);
|
||||||
|
for(int i=0; i<d->sigv.size(); ++i)
|
||||||
|
{
|
||||||
|
if(d->sigv[i].sigstr == in)
|
||||||
|
return d->sigv[i].signal;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenericMFPtr *Object::findSlotImpl(const char *name) const
|
||||||
|
{
|
||||||
|
std::string in(name);
|
||||||
|
for(int i=0; i<d->slov.size(); ++i)
|
||||||
|
{
|
||||||
|
if(d->slov[i].slostr == in)
|
||||||
|
return &d->slov[i].sloptr;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// std::ostream &
|
||||||
|
// operator << (std::ostream &os, uLib::Object &ob)
|
||||||
|
// {
|
||||||
|
// uLib::Object *op = &ob;
|
||||||
|
// uLib::Archive::hrt_oarchive (os) << op;
|
||||||
|
// return os;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// std::ostream &
|
||||||
|
// operator << (std::ostream &os, uLib::Object *ob)
|
||||||
|
// {
|
||||||
|
// uLib::Archive::hrt_oarchive(os) << ob;
|
||||||
|
// return os;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// std::istream &
|
||||||
|
// operator >> (std::istream &is, uLib::Object &ob)
|
||||||
|
// {
|
||||||
|
// // uLib::Object *op = &ob;
|
||||||
|
// uLib::Archive::hrt_iarchive(is) >> ob;
|
||||||
|
// return is;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
222
src/Core/Object.h
Normal file
222
src/Core/Object.h
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_OBJECT_H
|
||||||
|
#define U_CORE_OBJECT_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// WARNING: COPILE ERROR if this goes after mpl/vector //
|
||||||
|
//#include "Core/Vector.h"
|
||||||
|
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Debug.h"
|
||||||
|
|
||||||
|
#include "Core/Function.h"
|
||||||
|
#include "Core/Signal.h"
|
||||||
|
|
||||||
|
#include "Core/Mpl.h"
|
||||||
|
#include "Core/Serializable.h"
|
||||||
|
#include "Core/ObjectProps.h"
|
||||||
|
#include "Core/Uuid.h"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace archive {
|
||||||
|
class polymorphic_iarchive;
|
||||||
|
class polymorphic_oarchive;
|
||||||
|
} // archive
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class Version {
|
||||||
|
public:
|
||||||
|
static const char *PackageName;
|
||||||
|
static const char *VersionNumber;
|
||||||
|
static const char *Release;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//// OBJECT ////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object class is the object base implementation for uLib Framework.
|
||||||
|
*/
|
||||||
|
class Object : public ObjectPropable
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
// std::string name;
|
||||||
|
// void PrintName() { std::cout << "Ob name: " << name << "\n"; }
|
||||||
|
|
||||||
|
Object();
|
||||||
|
Object(const Object ©);
|
||||||
|
~Object();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// PARAMETERS //
|
||||||
|
|
||||||
|
// FIXX !!!
|
||||||
|
virtual void DeepCopy(const Object ©);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SERIALIZATION //
|
||||||
|
|
||||||
|
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||||
|
ObjectPropable::serialize(ar,version);
|
||||||
|
}
|
||||||
|
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
|
||||||
|
|
||||||
|
void SaveConfig(std::ostream &os, int version = 0);
|
||||||
|
void LoadConfig(std::istream &is, int version = 0);
|
||||||
|
|
||||||
|
static void SaveXml(std::ostream &os, Object &ob);
|
||||||
|
static void LoadXml(std::istream &is, Object &ob);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SIGNALS //
|
||||||
|
|
||||||
|
// Qt4 style connector //
|
||||||
|
static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) {
|
||||||
|
// // NOT WORKING YET //
|
||||||
|
// 1) find slot pointer from name
|
||||||
|
// SignalBase *sig = ob1->findSignal(signal_name);
|
||||||
|
// GenericMFPtr *slo = receiver->findSlot(slot_name);
|
||||||
|
// if(sig && slo)
|
||||||
|
// return Object::connect(sig,slo->operator ()(),receiver);
|
||||||
|
// else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Qt5 style connector //
|
||||||
|
template <typename Func1, typename Func2>
|
||||||
|
static bool connect( typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
|
||||||
|
typename FunctionPointer<Func2>::Object *receiver, Func2 slof)
|
||||||
|
{
|
||||||
|
SignalBase *sigb = sender->findOrAddSignal(sigf);
|
||||||
|
typedef boost::signals2::signal<typename FunctionPointer<Func2>::SignalSignature> SigT;
|
||||||
|
ConnectSignal(sigb,slof,receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
|
||||||
|
ConnectSignal(sigb,slof,receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< typename FuncT >
|
||||||
|
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
|
||||||
|
addSignal(FuncT fun, const char *name) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
SignalBase *sig = NewSignal(fun);
|
||||||
|
addSignalImpl(sig,fun,name);
|
||||||
|
return (SigT *)sig;
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename FuncT>
|
||||||
|
inline bool addSlot(FuncT fun, const char *name) {
|
||||||
|
this->addSlotImpl(GenericMFPtr(fun),name);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename FuncT >
|
||||||
|
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
|
||||||
|
findSignal(FuncT fptr)
|
||||||
|
{
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename FuncT >
|
||||||
|
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
|
||||||
|
findOrAddSignal(FuncT fptr)
|
||||||
|
{
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
|
||||||
|
if(!sig) {
|
||||||
|
sig = NewSignal(fptr);
|
||||||
|
addSignalImpl(sig,fptr,"signal_name_to_be_implemented");
|
||||||
|
}
|
||||||
|
return (SigT *)sig;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline SignalBase *
|
||||||
|
findSignal(const char *name) const
|
||||||
|
{
|
||||||
|
return findSignalImpl(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline GenericMFPtr *
|
||||||
|
findSlot(const char *name) const
|
||||||
|
{
|
||||||
|
return findSlotImpl(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
|
inline const Object& operator = (const Object ©)
|
||||||
|
{ this->DeepCopy(copy); return *this; }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
|
||||||
|
bool addSlotImpl(GenericMFPtr fptr, const char *name);
|
||||||
|
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
|
||||||
|
SignalBase *findSignalImpl(const char *name) const;
|
||||||
|
GenericMFPtr *findSlotImpl(const char *name) const;
|
||||||
|
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
friend class ObjectPrivate;
|
||||||
|
class ObjectPrivate *d;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//std::ostream & operator << (std::ostream &os, uLib::Object &ob);
|
||||||
|
//std::ostream & operator << (std::ostream &os, uLib::Object *ob);
|
||||||
|
//std::istream & operator >> (std::istream &is, uLib::Object &ob);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_OBJECT_H
|
||||||
278
src/Core/ObjectProps.h
Normal file
278
src/Core/ObjectProps.h
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_OBJECTPROPS_H
|
||||||
|
#define U_OBJECTPROPS_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
|
||||||
|
#include <Core/Mpl.h>
|
||||||
|
#include <Core/Types.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// MACROS //
|
||||||
|
|
||||||
|
|
||||||
|
#define ULIB_props() \
|
||||||
|
public: struct ObjectProps; \
|
||||||
|
virtual void init_properties(); \
|
||||||
|
inline struct ObjectProps &p() { /* static const unsigned int offset = props_offset(this); */ \
|
||||||
|
/* NON FUNZIA! return * (struct ObjectProps *)(reinterpret_cast<char*>(props())+offset); */ \
|
||||||
|
return *props()->ptr<ObjectProps>(); } \
|
||||||
|
typedef uLib::mpl::bool_<true>::type propable_trait; \
|
||||||
|
public: struct DLL_PUBLIC ObjectProps
|
||||||
|
|
||||||
|
#define properties() ULIB_props()
|
||||||
|
|
||||||
|
#define default(vlaue)
|
||||||
|
|
||||||
|
#define $$ p()
|
||||||
|
|
||||||
|
#define $(_name) props_ref<_name>()
|
||||||
|
|
||||||
|
#define $_init() \
|
||||||
|
if(props(this)) return; \
|
||||||
|
props_new(this); \
|
||||||
|
uLib::detail::ObjectProps::initializer::init_object_baselist(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace serialization {
|
||||||
|
class access;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct ObjectProps {
|
||||||
|
|
||||||
|
/** Define a trait has_member to find if an Object is Propable*/
|
||||||
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(propable_trait)
|
||||||
|
|
||||||
|
/** IsA ProbapleObject Implementation Template */
|
||||||
|
template <class T>
|
||||||
|
struct IsA : has_propable_trait<T> {};
|
||||||
|
|
||||||
|
/** Lambda to get Props member type */
|
||||||
|
template <class T>
|
||||||
|
struct props_type {
|
||||||
|
typedef typename T::ObjectProps type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct get_props {
|
||||||
|
|
||||||
|
/** CFList has result but this method check for has BaseList */
|
||||||
|
typedef typename detail::TypeIntrospection::child_first<T>::type CFTypeList;
|
||||||
|
|
||||||
|
/** Filter List items that have not Propable feature */
|
||||||
|
typedef typename mpl::filter_view< CFTypeList, IsA<mpl::_> >::type FilteredCFTypeList;
|
||||||
|
|
||||||
|
/** Get Props from each Parent in Seq */
|
||||||
|
typedef typename mpl::transform_view< FilteredCFTypeList, props_type<mpl::_> >::type type;
|
||||||
|
|
||||||
|
|
||||||
|
// qui sotto ho un problema che ho temporaneamente tamponato //
|
||||||
|
// ovvero ho usato child_first_impl per ottenere la lista delle basi //
|
||||||
|
// vorrei farlo facendo un pop_back ma non va forse perche il tipo //
|
||||||
|
// non e' corretto. //
|
||||||
|
|
||||||
|
/** Get Parent list from CFTypeList */
|
||||||
|
typedef typename detail::TypeIntrospection::child_first_impl<T>::Childs CFBaseList;
|
||||||
|
|
||||||
|
/** Filter Parents that have not Propable feature */
|
||||||
|
typedef typename mpl::filter_view< CFBaseList, IsA<mpl::_> >::type FilteredCFBaseList;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: convert to pp const value,
|
||||||
|
// (non so se sia possibile con il dinamic casting intanto funziona cosi' )
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
static unsigned int measure_offset(T1 base, T2 derived) {
|
||||||
|
return reinterpret_cast<char*>(derived) - reinterpret_cast<char*>(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct initializer {
|
||||||
|
|
||||||
|
template <class _ObjectT>
|
||||||
|
struct lambda_init_object {
|
||||||
|
_ObjectT *o;
|
||||||
|
lambda_init_object(_ObjectT *o) : o(o) {}
|
||||||
|
template<class T> void operator()(T) {
|
||||||
|
o->T::init_properties();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This calls the internal init_properties() virtual function for each
|
||||||
|
* object parent defined in BaseList only if it is propable
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static void init_object_baselist(T *o) {
|
||||||
|
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFBaseList CFBaseList;
|
||||||
|
mpl::for_each<CFBaseList>(lambda_init_object<T>(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This calls the internal init_properties() virtual function only if
|
||||||
|
* object is propable ( implementation if not propable )
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static
|
||||||
|
typename boost::enable_if<mpl::not_<IsA<T> >,void>::type
|
||||||
|
init_object(T *o) {
|
||||||
|
; // do nothing //
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This calls the internal init_properties() virtual function only if
|
||||||
|
* object is propable ( implementation if propable )
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
static
|
||||||
|
typename boost::enable_if<IsA<T>,void>::type
|
||||||
|
init_object(T *o) {
|
||||||
|
o->init_properties();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class ThisClass, class Archive>
|
||||||
|
struct serialize_baselist {
|
||||||
|
ThisClass & m_object;
|
||||||
|
Archive & m_ar;
|
||||||
|
serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
|
||||||
|
template <class T> void operator()(T &o) {
|
||||||
|
// T is taken fron get_props<BaseList>::FilteredPList types to get
|
||||||
|
// type_info_name that is the type name defined by Type macro
|
||||||
|
typedef typename props_type<T>::type PType;
|
||||||
|
std::string name(TypeIntrospection::access<T>::type_info::name);
|
||||||
|
boost::algorithm::replace_all(name,"::","_");
|
||||||
|
m_ar & boost::serialization::make_nvp(
|
||||||
|
name.c_str() ,
|
||||||
|
boost::serialization::base_object<PType>(m_object));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ObjectPropsBase {
|
||||||
|
virtual ~ObjectPropsBase() {}
|
||||||
|
virtual ObjectPropsBase *copy() = 0;
|
||||||
|
|
||||||
|
template <class T> inline T *ptr() { return dynamic_cast<T*>(this); }
|
||||||
|
|
||||||
|
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct ObjectPropsImpl :
|
||||||
|
ObjectPropsBase,
|
||||||
|
ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props<T>::type)
|
||||||
|
{
|
||||||
|
typedef ObjectPropsImpl<T> ThisClass;
|
||||||
|
typedef typename uLib::detail::ObjectProps::get_props<T>::type CFList;
|
||||||
|
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFTypeList FilteredCFTypeList;
|
||||||
|
ObjectPropsBase *copy() { return new ThisClass(*this); }
|
||||||
|
|
||||||
|
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||||
|
boost::serialization::void_cast_register<ThisClass,ObjectPropsBase>();
|
||||||
|
mpl::for_each<FilteredCFTypeList>(detail::ObjectProps::serialize_baselist<ThisClass,ArchiveT>(*this,ar));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectPropable {
|
||||||
|
|
||||||
|
ObjectPropsBase *m_props;
|
||||||
|
friend class uLib::detail::ObjectProps;
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
public:
|
||||||
|
ObjectPropable() : m_props(NULL) {}
|
||||||
|
ObjectPropable(const ObjectPropable &c) { if(c.m_props) m_props = c.m_props->copy(); else m_props = NULL; }
|
||||||
|
~ObjectPropable() { if(m_props) delete m_props; }
|
||||||
|
|
||||||
|
|
||||||
|
template <class T> inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr<typename T::ObjectProps>(); else exit(1); }
|
||||||
|
template <class T> inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr<typename T::ObjectProps>(); else return NULL; }
|
||||||
|
protected:
|
||||||
|
ObjectPropsBase *props() const { return m_props; }
|
||||||
|
template <class T> inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl<T>; }
|
||||||
|
|
||||||
|
/** NOT working dynamic cache casting */
|
||||||
|
template <class T> inline unsigned int props_offset(T *ptr) const
|
||||||
|
{ if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr<T>()); else return -1; }
|
||||||
|
|
||||||
|
|
||||||
|
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
|
||||||
|
if(m_props) ar & boost::serialization::make_nvp("properties",m_props);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* ObjectPropable is not directly propable itself to prevent Basclass
|
||||||
|
* duplication in inherit_nofold. And for the same reason ANY VIRTUAL BASE
|
||||||
|
* SHOULD NOT BE PROPABLE
|
||||||
|
*/
|
||||||
|
virtual void init_properties() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_OBJECTPROPS_H
|
||||||
87
src/Core/Options.cpp
Normal file
87
src/Core/Options.cpp
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include "Core/Options.h"
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
//class boost::program_options::error_with_option_name;
|
||||||
|
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
|
||||||
|
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>(int *);
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
Options::Options(const char *str) :
|
||||||
|
m_global(str),
|
||||||
|
m_configuration("Configuration")
|
||||||
|
{}
|
||||||
|
|
||||||
|
void Options::parse_command_line(int argc, char *argv[]) {
|
||||||
|
boost::program_options::store(boost::program_options::parse_command_line(argc,argv,m_global),m_vm);
|
||||||
|
boost::program_options::notify(m_vm);
|
||||||
|
|
||||||
|
if(m_vm.count("help")) {
|
||||||
|
std::cout << "\n" << m_global << "\n";
|
||||||
|
if(m_configuration.options().size()) {
|
||||||
|
std::cout << "\n" << m_configuration << "\n\n";
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Options::parse_config_file(std::string &str)
|
||||||
|
{
|
||||||
|
this->parse_config_file(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Options::parse_config_file(const char *fname)
|
||||||
|
{
|
||||||
|
std::ifstream is;
|
||||||
|
is.open(fname);
|
||||||
|
boost::program_options::options_description fileopt;
|
||||||
|
fileopt.add(m_global).add(m_configuration);
|
||||||
|
if(is.is_open()) {
|
||||||
|
boost::program_options::store(boost::program_options::parse_config_file(is,fileopt,true),m_vm);
|
||||||
|
boost::program_options::notify(m_vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Options::count(const char *str) const
|
||||||
|
{
|
||||||
|
return (m_vm.count(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
179
src/Core/Options.h
Normal file
179
src/Core/Options.h
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_OPTIONS_H
|
||||||
|
#define U_CORE_OPTIONS_H
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct Options {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for boost program_options easy init syntax
|
||||||
|
*/
|
||||||
|
class options_description_easy_init {
|
||||||
|
typedef boost::program_options::options_description_easy_init InitClass;
|
||||||
|
InitClass m_init;
|
||||||
|
public:
|
||||||
|
options_description_easy_init(InitClass init) :
|
||||||
|
m_init(init) {}
|
||||||
|
|
||||||
|
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
const char* description)
|
||||||
|
{
|
||||||
|
m_init(name,description);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
const boost::program_options::value_semantic* s)
|
||||||
|
{
|
||||||
|
m_init(name,s);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
const boost::program_options::value_semantic* s,
|
||||||
|
const char* description)
|
||||||
|
{
|
||||||
|
m_init(name,s,description);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
T * value,
|
||||||
|
const T default_value,
|
||||||
|
const char* description)
|
||||||
|
{
|
||||||
|
m_init(name,
|
||||||
|
boost::program_options::value<T>(value)->default_value(default_value),
|
||||||
|
description);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
T * value,
|
||||||
|
const char* description)
|
||||||
|
{
|
||||||
|
assert(value);
|
||||||
|
m_init(name,
|
||||||
|
boost::program_options::value<T>(value)->default_value(*value),
|
||||||
|
description);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
T * value,
|
||||||
|
const T default_value)
|
||||||
|
{
|
||||||
|
m_init(name,
|
||||||
|
boost::program_options::value<T>(value)->default_value(default_value));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
options_description_easy_init&
|
||||||
|
operator()(const char* name,
|
||||||
|
T * value)
|
||||||
|
{
|
||||||
|
assert(value);
|
||||||
|
m_init(name,
|
||||||
|
boost::program_options::value<T>(value)->default_value(*value));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // Options
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Options {
|
||||||
|
boost::program_options::options_description m_global;
|
||||||
|
boost::program_options::options_description m_configuration;
|
||||||
|
boost::program_options::positional_options_description m_posdesc;
|
||||||
|
boost::program_options::variables_map m_vm;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef detail::Options::options_description_easy_init initType;
|
||||||
|
|
||||||
|
Options(const char *str = "Program options");
|
||||||
|
|
||||||
|
initType add_options() {
|
||||||
|
return initType(m_global.add_options());
|
||||||
|
}
|
||||||
|
|
||||||
|
initType add_config_options() {
|
||||||
|
return initType(m_configuration.add_options());
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_positional_option(const char *name, int max_count) {
|
||||||
|
// TODO:
|
||||||
|
// m_posdesc(name,max_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_command_line(int argc, char *argv[]);
|
||||||
|
|
||||||
|
void parse_config_file(std::string &str);
|
||||||
|
|
||||||
|
void parse_config_file(const char *fname);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
|
||||||
|
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
|
||||||
|
r->default_value(dvalue);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool count(const char *str) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_CORE_OPTIONS_H
|
||||||
95
src/Core/Serializable.cpp
Normal file
95
src/Core/Serializable.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "boost/archive/polymorphic_xml_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_xml_iarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_text_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_text_iarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_binary_oarchive.hpp"
|
||||||
|
#include "boost/archive/polymorphic_binary_iarchive.hpp"
|
||||||
|
|
||||||
|
#include "Serializable.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//void Serializable::SaveXml(std::ostream &os, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_xml_oarchive(os);
|
||||||
|
// this->Save(*xoa);
|
||||||
|
// delete xoa;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::LoadXml(std::istream &is, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_xml_iarchive(is);
|
||||||
|
// this->Load(*xia,this);
|
||||||
|
// delete xia;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::SaveText(std::ostream &os, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_text_oarchive(os);
|
||||||
|
// this->Save(*xoa);
|
||||||
|
// delete xoa;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::LoadText(std::istream &is, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_text_iarchive(is);
|
||||||
|
// this->Load(*xia,this);
|
||||||
|
// delete xia;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::SaveBin(std::ostream &os, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_binary_oarchive(os);
|
||||||
|
// this->Save(*xoa);
|
||||||
|
// delete xoa;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::LoadBin(std::istream &is, const char *name)
|
||||||
|
//{
|
||||||
|
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_binary_iarchive(is);
|
||||||
|
// Serializable::Load(*xia,this);
|
||||||
|
// delete xia;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//void Serializable::Save(boost::archive::polymorphic_oarchive &ar, Serializable *ob)
|
||||||
|
//{
|
||||||
|
// ar << boost::serialization::make_nvp("Object",ob);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void Serializable::Load(boost::archive::polymorphic_iarchive &ar, Serializable *ob)
|
||||||
|
//{
|
||||||
|
// ar >> boost::serialization::make_nvp("Object",ob);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
412
src/Core/Serializable.h
Normal file
412
src/Core/Serializable.h
Normal file
@@ -0,0 +1,412 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_SERIALIZABLE_H
|
||||||
|
#define U_SERIALIZABLE_H
|
||||||
|
|
||||||
|
/* Serialization:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
* Problema nella serializzazione delle properties in test_archive
|
||||||
|
* implementare human readable make_hrp ... non riesco..
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/serialization/access.hpp>
|
||||||
|
#include <boost/serialization/export.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/for_each.hpp>
|
||||||
|
#include <boost/mpl/remove_if.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
|
||||||
|
//#include <boost/archive/xml_iarchive.hpp>
|
||||||
|
//#include <boost/archive/xml_oarchive.hpp>
|
||||||
|
//#include <boost/archive/text_iarchive.hpp>
|
||||||
|
//#include <boost/archive/text_oarchive.hpp>
|
||||||
|
//#include "boost/archive/polymorphic_iarchive.hpp"
|
||||||
|
//#include "boost/archive/polymorphic_oarchive.hpp"
|
||||||
|
|
||||||
|
#include <boost/preprocessor/comma_if.hpp>
|
||||||
|
#include <boost/preprocessor/repeat.hpp>
|
||||||
|
#include <boost/preprocessor/inc.hpp>
|
||||||
|
#include <boost/preprocessor/cat.hpp>
|
||||||
|
#include <boost/preprocessor/tuple/to_seq.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Mpl.h"
|
||||||
|
#include "Core/ObjectProps.h"
|
||||||
|
#include "Core/Archives.h"
|
||||||
|
#include "Core/Export.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// BOOST SERIALIZATION ADD-ON
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace serialization {
|
||||||
|
|
||||||
|
// ACCESS 2 //
|
||||||
|
template <class T> struct access2 {};
|
||||||
|
|
||||||
|
|
||||||
|
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
|
||||||
|
template<class T>
|
||||||
|
class hrp :
|
||||||
|
public wrapper_traits<const hrp< T > >
|
||||||
|
{
|
||||||
|
const char *m_name;
|
||||||
|
T *m_value;
|
||||||
|
std::string *m_str;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit hrp(const char * name_, T &t) :
|
||||||
|
m_str(new std::string),
|
||||||
|
m_name(name_), m_value(&t) {}
|
||||||
|
|
||||||
|
const char * name() const {
|
||||||
|
return this->m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Archivex>
|
||||||
|
void save( Archivex & ar, const unsigned int /* file_version */) const {
|
||||||
|
//// ar.operator<<(const_value());
|
||||||
|
// std::stringstream ss;
|
||||||
|
// uLib::Archive::hrt_oarchive har(ss);
|
||||||
|
// har << make_nvp(m_name,*m_value);
|
||||||
|
// // (*m_str) = ss.str();
|
||||||
|
//// ar.operator << (make_nvp(m_name, ss.str());
|
||||||
|
}
|
||||||
|
template<class Archivex>
|
||||||
|
void load( Archivex & ar, const unsigned int /* file_version */) {
|
||||||
|
// ar.operator>>(value());
|
||||||
|
}
|
||||||
|
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline
|
||||||
|
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||||
|
const
|
||||||
|
#endif
|
||||||
|
hrp< T > make_hrp(const char * name, T & t){
|
||||||
|
return hrp< T >(name, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define HRP(name) \
|
||||||
|
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
|
||||||
|
|
||||||
|
|
||||||
|
} // serialization
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ULIB SERIALIZATION
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
|
||||||
|
|
||||||
|
#define NVP(data) BOOST_SERIALIZATION_NVP(data)
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SERIALIZTION MACROS //
|
||||||
|
|
||||||
|
// !!! WARNING !!! INTRUSIVE SERIALIZATION IS ACTUALLY NOT WORKING FEATURE
|
||||||
|
// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED
|
||||||
|
|
||||||
|
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
|
||||||
|
# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
|
||||||
|
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
|
||||||
|
# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
|
||||||
|
#else
|
||||||
|
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
|
||||||
|
ULIB_CLASS_EXPORT_KEY(_Ob)
|
||||||
|
# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
|
||||||
|
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__)
|
||||||
|
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
|
||||||
|
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
|
||||||
|
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
|
||||||
|
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob)
|
||||||
|
# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
|
||||||
|
# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define ULIB_SERIALIZE_ACCESS \
|
||||||
|
friend class boost::serialization::access; \
|
||||||
|
template <class T> friend class boost::serialization::access2;
|
||||||
|
|
||||||
|
#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \
|
||||||
|
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass)
|
||||||
|
|
||||||
|
#define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \
|
||||||
|
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) \
|
||||||
|
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass::ObjectProps) \
|
||||||
|
BOOST_CLASS_EXPORT_KEY(uLib::ObjectPropsImpl<_FullNamespaceClass>)
|
||||||
|
|
||||||
|
|
||||||
|
#define _SERIALIZE_IMPL_SEQ \
|
||||||
|
(uLib::Archive::text_iarchive) \
|
||||||
|
(uLib::Archive::text_oarchive) \
|
||||||
|
(uLib::Archive::hrt_iarchive) \
|
||||||
|
(uLib::Archive::hrt_oarchive) \
|
||||||
|
(uLib::Archive::xml_iarchive) \
|
||||||
|
(uLib::Archive::xml_oarchive) \
|
||||||
|
(uLib::Archive::log_archive)
|
||||||
|
|
||||||
|
|
||||||
|
/** Solving virtual class check problem */
|
||||||
|
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; }
|
||||||
|
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) //
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name);
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
|
||||||
|
template void Class::serialize(Archive &ar,const unsigned int);
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem);
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
|
||||||
|
typedef boost::mpl::bool_<true> serializable; \
|
||||||
|
typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \
|
||||||
|
void PrintSerializableListId() { boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); } \
|
||||||
|
template <class ArchiveT> void serialize(ArchiveT &ar,const unsigned int version); \
|
||||||
|
template <class ArchiveT> void serialize_parents(ArchiveT &ar,const unsigned int version); \
|
||||||
|
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version);
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
|
||||||
|
template <class ArchiveT> void _Ob::serialize(ArchiveT &ar, const unsigned int version) { \
|
||||||
|
boost::serialization::void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); \
|
||||||
|
_Ob::serialize_parents(ar,version); \
|
||||||
|
_Ob::save_override(ar,version); }\
|
||||||
|
template <class ArchiveT> void _Ob::serialize_parents(ArchiveT &ar, const unsigned int v) { \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_AR_OP,ar,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); } \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||||
|
namespace boost { \
|
||||||
|
namespace serialization { \
|
||||||
|
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \
|
||||||
|
{ ::new(o)_Ob(); o->init_parameters(); } }}\
|
||||||
|
template <class ArchiveT> void _Ob::save_override(ArchiveT &ar, const unsigned int version)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// UNINTRUSIVE SERIALIZATION
|
||||||
|
|
||||||
|
#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object<elem>(ob));
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
|
||||||
|
template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i);
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data,elem)
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
|
||||||
|
// different implementation
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||||
|
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||||
|
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }}
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||||
|
serialize_parents(ar,ob,version); \
|
||||||
|
access2< _Ob >::save_override(ar,ob,version); } }}\
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||||
|
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,...) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
|
||||||
|
BOOST_PP_IF(BOOST_PP_VARIADIC_SIZE((__VA_ARGS__)),BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__)));,) } \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||||
|
serialize_parents(ar,ob,version); \
|
||||||
|
access2< _Ob >::save_override (ar,ob,version); } }}\
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ) \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||||
|
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||||
|
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||||
|
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
|
||||||
|
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \
|
||||||
|
template <class ArchiveT> void save_override (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); }}
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
|
||||||
|
/* PP serialize */ BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); \
|
||||||
|
/* MPL serialize */ /*uLib::mpl::for_each<_Ob::BaseList>(uLib::detail::Serializable::serialize_baseobject<_Ob,ArchiveT>(ob,ar) );*/ } \
|
||||||
|
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *ob, const unsigned int file_version) { \
|
||||||
|
::new(ob)_Ob(); uLib::detail::ObjectProps::initializer::init_object(ob); } \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
|
||||||
|
void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); /*fix*/ \
|
||||||
|
serialize_parents(ar,ob,version); \
|
||||||
|
access2< _Ob >::save_override (ar,ob,version); } }}\
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
|
||||||
|
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) \
|
||||||
|
namespace boost { namespace serialization { \
|
||||||
|
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) { \
|
||||||
|
save_override (ar,ob,version); } }}\
|
||||||
|
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob::ObjectProps,_SERIALIZE_IMPL_SEQ)\
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob::ObjectProps) \
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(uLib::ObjectPropsImpl<_Ob>) \
|
||||||
|
template <class ArchiveT> void boost::serialization::save_override(ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version)
|
||||||
|
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name),ob.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializable trait to check if an object type is serializable.
|
||||||
|
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
|
||||||
|
* cases a has_serialize trait should be implemented
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct serializable_trait : mpl::bool_<false> {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IsA Serializable Implementation Template
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
struct IsA : serializable_trait<T> {};
|
||||||
|
|
||||||
|
template <class ThisClass, class Archive>
|
||||||
|
struct serialize_baseobject {
|
||||||
|
ThisClass & m_object;
|
||||||
|
Archive & m_ar;
|
||||||
|
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
|
||||||
|
template <class T> void operator()(T &o) {
|
||||||
|
m_ar & boost::serialization::make_nvp(
|
||||||
|
typeid(T).name() ,
|
||||||
|
boost::serialization::base_object<T>(m_object));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct Serializable {
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template <class T> friend class boost::serialization::access2;
|
||||||
|
virtual ~Serializable() {}
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_SERIALIZABLE_H
|
||||||
28
src/Core/Signal.cpp
Normal file
28
src/Core/Signal.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
168
src/Core/Signal.h
Normal file
168
src/Core/Signal.h
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_SIGNAL_H
|
||||||
|
#define U_CORE_SIGNAL_H
|
||||||
|
|
||||||
|
#include <boost/typeof/typeof.hpp>
|
||||||
|
|
||||||
|
#include <boost/signals2/signal.hpp>
|
||||||
|
#include <boost/signals2/slot.hpp>
|
||||||
|
#include <boost/signals2/signal_type.hpp>
|
||||||
|
|
||||||
|
#include "Function.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Signals macro //
|
||||||
|
|
||||||
|
#define default(vlaue)
|
||||||
|
#define slots
|
||||||
|
#define signals /*virtual void init_signals();*/ public
|
||||||
|
#define emit
|
||||||
|
#define SLOT(a) BOOST_STRINGIZE(a)
|
||||||
|
#define SIGNAL(a) BOOST_STRINGIZE(a)
|
||||||
|
|
||||||
|
#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \
|
||||||
|
static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \
|
||||||
|
sig->operator()(__VA_ARGS__);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility macro to implement signal emission implementa una delle seguenti:
|
||||||
|
*
|
||||||
|
* // metodo standard con cast //
|
||||||
|
* SignalBase * sig = this->findSignal((void (Ob1::*)(void))&Ob1::V0);
|
||||||
|
* typedef Signal<void()>::type SigT;
|
||||||
|
* if(sig) reinterpret_cast<SigT*>(sig)->operator()();
|
||||||
|
*
|
||||||
|
* // cast automatico //
|
||||||
|
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
|
||||||
|
* sig->operator()();
|
||||||
|
*/
|
||||||
|
#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
// A boost::signal wrapper structure ///////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO ...
|
||||||
|
|
||||||
|
typedef boost::signals2::signal_base SignalBase;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct Signal {
|
||||||
|
typedef boost::signals2::signal<T> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
|
template <typename FuncT, int arity>
|
||||||
|
struct ConnectSignal {};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 0 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(slof);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 1 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 2 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 3 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 4 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
struct ConnectSignal< FuncT, 5 > {
|
||||||
|
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
|
||||||
|
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
|
||||||
|
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
SignalBase *NewSignal(FuncT f) {
|
||||||
|
// seems to work wow !
|
||||||
|
return new Signal<void()>::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FuncT>
|
||||||
|
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver)
|
||||||
|
{
|
||||||
|
detail::ConnectSignal< FuncT, FunctionPointer<FuncT>::arity >::connect(sigb,slof,receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
#endif // SIGNAL_H
|
||||||
46
src/Core/Singleton.h
Normal file
46
src/Core/Singleton.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_SINGLETON_H
|
||||||
|
#define U_CORE_SINGLETON_H
|
||||||
|
|
||||||
|
#include <boost/serialization/singleton.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct Singleton : boost::serialization::singleton<T> {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SINGLETON_H
|
||||||
111
src/Core/SmartPointer.h
Normal file
111
src/Core/SmartPointer.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_SMARTPOINTER_H
|
||||||
|
#define U_CORE_SMARTPOINTER_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class SmartPointer {
|
||||||
|
typedef T element_type;
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit
|
||||||
|
SmartPointer(T* ptr = NULL) : m_counter(0) {
|
||||||
|
if(!ptr) ptr = new T;
|
||||||
|
if (ptr) m_counter = new ReferenceCounter(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TakeReference //
|
||||||
|
SmartPointer(T &ref) : m_counter(new ReferenceCounter(&ref,0)) { }
|
||||||
|
|
||||||
|
SmartPointer(const SmartPointer& copy) throw () {
|
||||||
|
acquire(copy.m_counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
SmartPointer(SmartPointer * copy) throw () {
|
||||||
|
acquire(copy->m_counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~SmartPointer() { release(); }
|
||||||
|
|
||||||
|
SmartPointer & operator=(const SmartPointer& copy) {
|
||||||
|
if (this != ©)
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
acquire(copy.m_counter);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
T & operator*() const throw () { return *m_counter->ptr; }
|
||||||
|
T * operator->() const throw () { return m_counter->ptr; }
|
||||||
|
|
||||||
|
T * get() const throw () {
|
||||||
|
return m_counter ? m_counter->ptr : 0; }
|
||||||
|
bool unique() const throw () {
|
||||||
|
return (m_counter ? m_counter->count == 1 : true); }
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct ReferenceCounter
|
||||||
|
{
|
||||||
|
ReferenceCounter(T* ptr = 0, unsigned c = 1) : ptr(ptr), count(c) { }
|
||||||
|
T* ptr;
|
||||||
|
unsigned count;
|
||||||
|
} * m_counter;
|
||||||
|
|
||||||
|
// increment the count
|
||||||
|
void acquire(ReferenceCounter* c) throw ()
|
||||||
|
{
|
||||||
|
m_counter = c;
|
||||||
|
if (c && c->count>0) ++c->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// decrement the count, delete if it is 0
|
||||||
|
void release() {
|
||||||
|
if (m_counter) {
|
||||||
|
if (--m_counter->count == 0) {
|
||||||
|
delete m_counter->ptr;
|
||||||
|
}
|
||||||
|
if (m_counter->count <= 0) {
|
||||||
|
delete m_counter;
|
||||||
|
m_counter = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SMARTPOINTER_H
|
||||||
77
src/Core/StaticInterface.h
Normal file
77
src/Core/StaticInterface.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_STATICINTERFACE_H
|
||||||
|
#define U_CORE_STATICINTERFACE_H
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
#define MAKE_TRAITS ; // TODO
|
||||||
|
|
||||||
|
#define uLibCheckFunction(class_name,name,out, ... ) \
|
||||||
|
{ out (class_name::*x)(__VA_ARGS__) = &class_name::name; (void) x; }
|
||||||
|
|
||||||
|
#define uLibCheckConstFunction(class_name,name,out,...) \
|
||||||
|
{ out (class_name::*x)(__VA_ARGS__) const = &class_name::name; (void) x; }
|
||||||
|
|
||||||
|
#define uLibCheckMember(class_name,name,type) \
|
||||||
|
{ class_name x; type *y = &x.name; (void) y; }
|
||||||
|
|
||||||
|
|
||||||
|
namespace Interface {
|
||||||
|
|
||||||
|
// EXAMPLE :
|
||||||
|
//template <class T> struct Voxel {
|
||||||
|
// MAKE_TRAITS;
|
||||||
|
// template<class Self> void check_structural() {
|
||||||
|
// { float & (Self::*x)() = &Self::Density; (void) x; }
|
||||||
|
// { int & (Self::*x)() = &Self::TrackCount; (void) x; }
|
||||||
|
// }
|
||||||
|
//protected:
|
||||||
|
// ~Voxel() {}
|
||||||
|
//};
|
||||||
|
|
||||||
|
template <class T, class SI>
|
||||||
|
static inline void IsA() {
|
||||||
|
(void) ((void (SI::*)()) &SI::template check_structural<T>);
|
||||||
|
}
|
||||||
|
|
||||||
|
// not working
|
||||||
|
//template <class T, class SI>
|
||||||
|
//struct StaticIsA {
|
||||||
|
// void test() {
|
||||||
|
// static const void (SI::*x)() = SI::template check_structural<T>;
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // STATICINTERFACE_H
|
||||||
94
src/Core/StringReader.h
Normal file
94
src/Core/StringReader.h
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_STRINGREADER_H
|
||||||
|
#define U_CORE_STRINGREADER_H
|
||||||
|
|
||||||
|
#include <istream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
// RIPENSARE COMPLETAMENTE !!!
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
struct StringReader {
|
||||||
|
|
||||||
|
std::istream & m_is;
|
||||||
|
|
||||||
|
StringReader(std::istream &is) : m_is(is) {}
|
||||||
|
|
||||||
|
void ReadString(const char *str) {
|
||||||
|
// // clean compared string //
|
||||||
|
// char chars[] = " \t\n";
|
||||||
|
// for (unsigned int i = 0; i < strlen(chars); ++i)
|
||||||
|
// { cmps.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); }
|
||||||
|
|
||||||
|
// SISTEMARE !!!
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
|
char c;
|
||||||
|
while( pos < strlen(str) ) {
|
||||||
|
while( IsEscape(str[pos])) pos++;
|
||||||
|
if ( pos >= strlen(str) ) break;
|
||||||
|
while( IsEscape(c = m_is.get()) );
|
||||||
|
if (c == str[pos] ) pos++;
|
||||||
|
else pos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsEscape(char c){
|
||||||
|
const char *escapes = " \r\n\t";
|
||||||
|
for ( int i = 0 ; i < 4 ; ++i) {
|
||||||
|
if(c == escapes[i]) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline StringReader & operator >> (StringReader &isr, T &t) {
|
||||||
|
isr.m_is >> t;
|
||||||
|
return isr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline StringReader & operator >> (StringReader &isr, const char *str) {
|
||||||
|
isr.ReadString(str);
|
||||||
|
return isr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STRINGREADER_H
|
||||||
28
src/Core/Timer.h
Normal file
28
src/Core/Timer.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef TIMER_H
|
||||||
|
#define TIMER_H
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Timer /////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Start() { gettimeofday(&m_start, NULL); }
|
||||||
|
|
||||||
|
double StopWatch() {
|
||||||
|
gettimeofday(&m_end, NULL);
|
||||||
|
double timeSec = m_end.tv_sec - m_start.tv_sec +
|
||||||
|
(m_end.tv_usec - m_start.tv_usec)*1E-6;
|
||||||
|
return timeSec;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct timeval m_start, m_end;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TIMER_H
|
||||||
276
src/Core/Types.h
Normal file
276
src/Core/Types.h
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_TYPES_H
|
||||||
|
#define U_CORE_TYPES_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include <boost/preprocessor.hpp>
|
||||||
|
|
||||||
|
#include <ltk/ltktypes.h>
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Core/Mpl.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct TypeIntrospection {
|
||||||
|
|
||||||
|
// BOOST IMPL //
|
||||||
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
|
||||||
|
|
||||||
|
// SFINAE IMPL //
|
||||||
|
/*
|
||||||
|
template <typename T>
|
||||||
|
struct has_type_info {
|
||||||
|
typedef char yes[1];
|
||||||
|
typedef char no[2];
|
||||||
|
template <typename U> static yes& test(typename U::type_info::BaseList*);
|
||||||
|
template <typename > static no& test(...);
|
||||||
|
// struct apply {
|
||||||
|
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
|
||||||
|
typedef boost::mpl::bool_<value> type;
|
||||||
|
// };
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** IsA Introspectable Object Implementation Template */
|
||||||
|
template <class T>
|
||||||
|
struct IsIntrospectable : has_type_info<T> {};
|
||||||
|
|
||||||
|
template <typename T> struct access {
|
||||||
|
typedef typename T::type_info type_info;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct child_first_impl {
|
||||||
|
|
||||||
|
template <class T1, bool cond>
|
||||||
|
struct lambda_CFList_f {
|
||||||
|
typedef mpl::vector<T1> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T1>
|
||||||
|
struct lambda_CFList_f<T1,true> {
|
||||||
|
// typedef typename T1::type_info::CFList type;
|
||||||
|
typedef typename access<T1>::type_info::CFList type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T1>
|
||||||
|
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
|
||||||
|
|
||||||
|
/** Transforms all Base Type into proper CFList */
|
||||||
|
typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
|
||||||
|
, lambda_CFList<mpl::_>
|
||||||
|
>::type CFListSeq;
|
||||||
|
|
||||||
|
/** Folds each CFList into a new sequence */
|
||||||
|
typedef typename mpl::fold< CFListSeq
|
||||||
|
, mpl::vector<>
|
||||||
|
, mpl::copy< mpl::_1
|
||||||
|
, mpl::back_inserter<mpl::_2>
|
||||||
|
>
|
||||||
|
>::type Childs;
|
||||||
|
|
||||||
|
/** Add This Class to final CFList sequence */
|
||||||
|
typedef typename mpl::copy< Childs
|
||||||
|
, mpl::back_inserter< mpl::vector<T> >
|
||||||
|
>::type type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if T has a member called type_info then compile type CFList
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
struct child_first : mpl::if_< has_type_info<T>
|
||||||
|
, child_first_impl<T>
|
||||||
|
, mpl::vector<>
|
||||||
|
>::type {};
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TYPE ADAPTERS // FINIRE !!!
|
||||||
|
|
||||||
|
//#define _REPETITION_V(vz,vn,vdata)
|
||||||
|
|
||||||
|
|
||||||
|
//template < class TypeList >
|
||||||
|
//class TypeAdapterInputInterface {
|
||||||
|
// virtual ~TypeAdapterInputInterface() {}
|
||||||
|
//public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// virtual void operator()(int val) {}
|
||||||
|
// virtual void operator()(std::string val) {}
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // detail ////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#define CONSTEXPR BOOST_CONSTEXPR
|
||||||
|
|
||||||
|
|
||||||
|
typedef ltk::Real_t Real_t;
|
||||||
|
typedef ltk::Id_t Id_t;
|
||||||
|
//typedef ltk::Size_t Size_t;
|
||||||
|
typedef ltk::Pointer_t Pointer_t;
|
||||||
|
typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
|
||||||
|
|
||||||
|
//--- bit manipulation ---------------------------------------------------------
|
||||||
|
#ifndef BIT
|
||||||
|
#define BIT(n) (1ULL << (n))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SETBIT
|
||||||
|
#define SETBIT(n,i) ((n) |= BIT(i))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CLRBIT
|
||||||
|
#define CLRBIT(n,i) ((n) &= ~BIT(i))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TESTBIT
|
||||||
|
#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TYPE INTROSPECTION FOR OBJECTS //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define uLibTypeMacro(thisClass,...) \
|
||||||
|
\
|
||||||
|
/* Friendship detail for accessing introspection */ \
|
||||||
|
template <typename> friend class uLib::detail::TypeIntrospection::access; \
|
||||||
|
\
|
||||||
|
/* type info structure*/ public: \
|
||||||
|
/* in GCC 4.8 must be public or dynamic_cast wont work */ \
|
||||||
|
struct type_info { \
|
||||||
|
/*WARNING: -std=c++0x required for this! */ \
|
||||||
|
constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
|
||||||
|
typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \
|
||||||
|
typedef thisClass ThisClass; \
|
||||||
|
typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \
|
||||||
|
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
|
||||||
|
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
|
||||||
|
}; \
|
||||||
|
\
|
||||||
|
public: \
|
||||||
|
typedef type_info::BaseClass BaseClass; \
|
||||||
|
virtual const char *type_name() const { return type_info::name; } \
|
||||||
|
/* Object Props fwd declaration*/ \
|
||||||
|
struct ObjectProps; \
|
||||||
|
/**/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TypeList inheritance introspection
|
||||||
|
*/
|
||||||
|
struct TypeIntrospection {
|
||||||
|
template <typename T>
|
||||||
|
struct child_first : detail::TypeIntrospection::child_first<T> {};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// SISTEMARE //
|
||||||
|
struct PrintTypeId {
|
||||||
|
template <class T>
|
||||||
|
void operator()(T) const
|
||||||
|
{ std::cout << typeid(T).name() << std::endl; }
|
||||||
|
|
||||||
|
template <typename SeqT>
|
||||||
|
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
|
||||||
|
|
||||||
|
template <typename Class>
|
||||||
|
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
#endif // U_CORE_TYPES_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
45
src/Core/Uuid.cpp
Normal file
45
src/Core/Uuid.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "Uuid.h"
|
||||||
|
#include "Singleton.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
uLib::uuid_t uLib::uLib_dns_uuid;
|
||||||
|
TypeRegister* TypeRegister::s_Instance = new TypeRegister();
|
||||||
|
|
||||||
|
TypeRegister::TypeRegister() :
|
||||||
|
BaseClass(uLib_dns_uuid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
TypeRegister * TypeRegister::Controller() {
|
||||||
|
return TypeRegister::s_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
163
src/Core/Uuid.h
Normal file
163
src/Core/Uuid.h
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_UUID_H
|
||||||
|
#define U_CORE_UUID_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/name_generator.hpp>
|
||||||
|
#include <boost/uuid/random_generator.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
|
#include "Core/Mpl.h"
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Object Registration //
|
||||||
|
|
||||||
|
|
||||||
|
typedef boost::uuids::uuid uuid_t;
|
||||||
|
|
||||||
|
extern uuid_t uLib_dns_uuid;
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
class type_id : public boost::uuids::uuid {
|
||||||
|
public:
|
||||||
|
type_id() :
|
||||||
|
m_size(sizeof(T)),
|
||||||
|
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name()))
|
||||||
|
{
|
||||||
|
std::cout << "Request for register new type\n" <<
|
||||||
|
"name: " << typeid(T).name() << "\n" <<
|
||||||
|
"uuid: " << to_string(*this) << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit type_id(boost::uuids::uuid const& u)
|
||||||
|
: boost::uuids::uuid(u) {}
|
||||||
|
|
||||||
|
operator boost::uuids::uuid() {
|
||||||
|
return static_cast<boost::uuids::uuid&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator boost::uuids::uuid() const {
|
||||||
|
return static_cast<boost::uuids::uuid const&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int size() const { return m_size; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int m_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TYPE REGISTER //
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
class TypeRegister {
|
||||||
|
typedef boost::uuids::name_generator IDGen_t;
|
||||||
|
public:
|
||||||
|
struct RegisterEntry {
|
||||||
|
uuid_t id;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
TypeRegister(uuid_t const &dns) :
|
||||||
|
gen(dns) {}
|
||||||
|
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
RegisterEntry * AddType(T *t = NULL) {
|
||||||
|
RegisterEntry en = { gen(typeid(T).name()), sizeof(T) };
|
||||||
|
for(int i=0; i < m_registry.size(); ++i)
|
||||||
|
if(en.id == m_registry[i].id) return &(m_registry[i]);
|
||||||
|
m_registry.push_back(en);
|
||||||
|
return &m_registry.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintSelf(std::ostream &o) {
|
||||||
|
std::cout << "RegisterController: \n";
|
||||||
|
for (int i=0; i<m_registry.size(); ++i)
|
||||||
|
o << "type [" << i << "]: "
|
||||||
|
<< to_string(m_registry[i].id) << " "
|
||||||
|
<< m_registry[i].size << "\n";
|
||||||
|
o << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
IDGen_t gen;
|
||||||
|
Vector<RegisterEntry> m_registry;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TypeRegister : public detail::TypeRegister {
|
||||||
|
public:
|
||||||
|
typedef detail::TypeRegister BaseClass;
|
||||||
|
typedef detail::TypeRegister::RegisterEntry Entry;
|
||||||
|
|
||||||
|
static TypeRegister* Controller();
|
||||||
|
|
||||||
|
private:
|
||||||
|
TypeRegister(); // Blocks constructor
|
||||||
|
static TypeRegister *s_Instance; // Singleton instance
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// OBJECT REGISTER //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
#endif // UUID_H
|
||||||
178
src/Core/Vector.h
Normal file
178
src/Core/Vector.h
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_VECTOR_H
|
||||||
|
#define U_CORE_VECTOR_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <Core/StaticInterface.h>
|
||||||
|
#include <Core/SmartPointer.h>
|
||||||
|
#include <Core/CommaInitializer.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
// Vector Implemetation ... wraps std::vector
|
||||||
|
template <typename T>
|
||||||
|
class Vector : public std::vector<T, std::allocator<T> >
|
||||||
|
{
|
||||||
|
typedef std::vector< T,std::allocator<T> > BaseClass;
|
||||||
|
typedef std::allocator<T> Allocator;
|
||||||
|
public:
|
||||||
|
typedef T TypeData;
|
||||||
|
typedef __gnu_cxx::__normal_iterator<T*, BaseClass > Iterator;
|
||||||
|
typedef __gnu_cxx::__normal_iterator<const T*, BaseClass> ConstIterator;
|
||||||
|
|
||||||
|
typedef CommaInitializer< Vector<T> , T > VectorCommaInit;
|
||||||
|
|
||||||
|
Vector(unsigned int size) : BaseClass(size) {}
|
||||||
|
Vector(unsigned int size, T &value) : BaseClass(size,value) {}
|
||||||
|
Vector() : BaseClass(0) {}
|
||||||
|
|
||||||
|
inline VectorCommaInit operator <<(T scalar) {
|
||||||
|
return VectorCommaInit(this, scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void PrintSelf(std::ostream &o);
|
||||||
|
|
||||||
|
void remove_element(unsigned int index) {
|
||||||
|
std::swap(this->at(index),this->back());
|
||||||
|
this->pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_element(T &t) {
|
||||||
|
std::swap(t, this->back());
|
||||||
|
this->pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Vector<T>::PrintSelf(std::ostream &o)
|
||||||
|
{
|
||||||
|
o << " *** uLib Vector *** \n";
|
||||||
|
o << " n. of items = " << this->size() << "\n";
|
||||||
|
for(int i=0; i< this->size(); ++i)
|
||||||
|
o << (T)this->at(i) << " ";
|
||||||
|
o << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream & operator << (std::ostream &o, const Vector<T> &v) {
|
||||||
|
for(int i=0; i< v.size(); ++i)
|
||||||
|
o << (T)v.at(i) << " ";
|
||||||
|
o << "\n";
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ofstream & operator << (std::ofstream &o, const Vector<T> &v) {
|
||||||
|
for(int i=0; i< v.size(); ++i)
|
||||||
|
o << (T)v.at(i) << " ";
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
std::istream & operator >> (std::istream &is, Vector<T> &v) {
|
||||||
|
T value;
|
||||||
|
while( is >> value ) {
|
||||||
|
if(is.fail()) v.push_back(0);
|
||||||
|
else v.push_back( value );
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Smart pointer Vector Implementation //
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class SmartVector : public SmartPointer< Vector<T> > {
|
||||||
|
typedef SmartPointer< Vector<T> > Base;
|
||||||
|
public:
|
||||||
|
|
||||||
|
SmartVector() : Base(new Vector<T>()) { }
|
||||||
|
SmartVector( const SmartVector ©) : Base(copy) { }
|
||||||
|
SmartVector(unsigned int size) : Base(new Vector<T>((int)size)) { }
|
||||||
|
|
||||||
|
virtual ~SmartVector() {}
|
||||||
|
|
||||||
|
T& operator[](int p) {
|
||||||
|
return Base::get()->at(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_elements(unsigned int first, unsigned int second) {
|
||||||
|
std::swap(Base::get()->at(first),Base::get()->at(second));
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_element(unsigned int index) {
|
||||||
|
std::swap(Base::get()->at(index),Base::get()->back());
|
||||||
|
Base::get()->pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_element(T &t) {
|
||||||
|
std::swap(t, Base::get()->back());
|
||||||
|
Base::get()->pop_back();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ------ Utils ------------------------------------------------------------- //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// RIFARE con iteratore !
|
||||||
|
template <typename _Tp, class _CmpT>
|
||||||
|
inline const unsigned long
|
||||||
|
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
|
||||||
|
{
|
||||||
|
_Tp it = _it;
|
||||||
|
_Tp end = _end-1;
|
||||||
|
for(it; it != end;)
|
||||||
|
{
|
||||||
|
if (_comp(*it,value)) ++it;
|
||||||
|
else if(_comp(*end,value)) std::swap(*it,*end--);
|
||||||
|
else --end;
|
||||||
|
}
|
||||||
|
return it - _it;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // VECTOR_H
|
||||||
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
88
src/Core/testing/BoostAccumulatorTest.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Core/Object.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/accumulators/accumulators.hpp>
|
||||||
|
#include <boost/accumulators/statistics/stats.hpp>
|
||||||
|
#include <boost/accumulators/statistics/mean.hpp>
|
||||||
|
#include <boost/accumulators/statistics/moment.hpp>
|
||||||
|
#include <boost/accumulators/statistics/density.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace boost::accumulators;
|
||||||
|
|
||||||
|
using namespace boost;
|
||||||
|
using namespace boost::accumulators;
|
||||||
|
|
||||||
|
typedef accumulator_set<double, features<tag::density> > acc;
|
||||||
|
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class data_filler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
data_filler(){}
|
||||||
|
T operator()() { return rand()/(T)RAND_MAX; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
//create some random data
|
||||||
|
std::vector<double> data(100);
|
||||||
|
std::generate(data.begin(), data.end(), data_filler<double>());
|
||||||
|
int c = data.size();//cache size for histogramm.
|
||||||
|
|
||||||
|
//create an accumulator
|
||||||
|
acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);
|
||||||
|
|
||||||
|
//fill accumulator
|
||||||
|
for (int j = 0; j < c; ++j)
|
||||||
|
{
|
||||||
|
myAccumulator(data[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
histogram_type hist = density(myAccumulator);
|
||||||
|
|
||||||
|
double total = 0.0;
|
||||||
|
|
||||||
|
for( int i = 0; i < hist.size(); i++ )
|
||||||
|
{
|
||||||
|
std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl;
|
||||||
|
total += hist[i].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Total: " << total << std::endl; //should be 1 (and it is)
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
64
src/Core/testing/BoostTest.cpp
Normal file
64
src/Core/testing/BoostTest.cpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Options.h"
|
||||||
|
|
||||||
|
#include "Core/Singleton.h"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
struct A : Object {
|
||||||
|
A() : a(0) {}
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(Boost Mock);
|
||||||
|
|
||||||
|
A &a = Singleton<A>::get_mutable_instance();
|
||||||
|
a.a = 5552368;
|
||||||
|
|
||||||
|
const A &aa = Singleton<A>::get_const_instance();
|
||||||
|
|
||||||
|
std::cout << a.a << "\n";
|
||||||
|
std::cout << aa.a << "\n";
|
||||||
|
|
||||||
|
TEST1( a.a == 5552368 );
|
||||||
|
TEST1( aa.a == 5552368 );
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
33
src/Core/testing/CMakeLists.txt
Normal file
33
src/Core/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
# TESTS
|
||||||
|
set( TESTS
|
||||||
|
SmartVectorTest
|
||||||
|
VectorTest
|
||||||
|
ObjectFlagsTest
|
||||||
|
ObjectParametersTest
|
||||||
|
ObjectCopyTest
|
||||||
|
StaticInterfaceTest
|
||||||
|
CommaInitTest
|
||||||
|
DebugTTreeDumpTest
|
||||||
|
BoostTest
|
||||||
|
BoostAccumulatorTest
|
||||||
|
PropertiesTest
|
||||||
|
SignalTest
|
||||||
|
SerializeTest
|
||||||
|
SerializeDreadDiamondTest
|
||||||
|
DreadDiamondParameters
|
||||||
|
ObjectPropableTest
|
||||||
|
UuidTest
|
||||||
|
TypeIntrospectionTraversal
|
||||||
|
OptionsTest
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${Boost_SERIALIZATION_LIBRARY}
|
||||||
|
${Boost_SIGNALS_LIBRARY}
|
||||||
|
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||||
|
${ROOT_LIBRARIES}
|
||||||
|
)
|
||||||
|
uLib_add_tests(${uLib-module})
|
||||||
57
src/Core/testing/CommaInitTest.cpp
Executable file
57
src/Core/testing/CommaInitTest.cpp
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
|
||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
#define test_print(file,str,...) \
|
||||||
|
printf(str,__VA_ARGS__)
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING( Comma Init );
|
||||||
|
|
||||||
|
Vector<int> test;
|
||||||
|
|
||||||
|
test << 1,2,3,4,5;
|
||||||
|
|
||||||
|
test.PrintSelf(std::cout);
|
||||||
|
|
||||||
|
|
||||||
|
test_print(stdout,"ciao %d \n",5);
|
||||||
|
|
||||||
|
printf("ciao\n");
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
118
src/Core/testing/DebugTTreeDumpTest.cpp
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Debug.h"
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
#include <boost/fusion/sequence.hpp>
|
||||||
|
#include <boost/fusion/include/sequence.hpp>
|
||||||
|
|
||||||
|
#include <boost/fusion/container.hpp>
|
||||||
|
#include <boost/fusion/algorithm/transformation/push_back.hpp>
|
||||||
|
#include <boost/fusion/include/push_back.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <Rtypes.h>
|
||||||
|
#include <TFile.h>
|
||||||
|
#include <TObject.h>
|
||||||
|
#include <TTree.h>
|
||||||
|
#include <TApplication.h>
|
||||||
|
#include <TBrowser.h>
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DebugAdapterTTree : public detail::DebugAdapterInterface {
|
||||||
|
TTree *m_tree;
|
||||||
|
public:
|
||||||
|
|
||||||
|
DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {}
|
||||||
|
~DebugAdapterTTree() { delete m_tree; }
|
||||||
|
|
||||||
|
void operator()(int val) {
|
||||||
|
std::cout << "debugger 2 prints: " << val << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
{
|
||||||
|
Debug debug;
|
||||||
|
DebugAdapterText adapter(std::cout);
|
||||||
|
DebugAdapterTTree treead("test");
|
||||||
|
|
||||||
|
debug.AddAdapter(adapter);
|
||||||
|
debug.AddAdapter(treead);
|
||||||
|
|
||||||
|
int a = 5552368;
|
||||||
|
debug("a",a);
|
||||||
|
|
||||||
|
std::string str = "ciao";
|
||||||
|
debug("str",str);
|
||||||
|
|
||||||
|
debug.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TestTObject *test = new TestTObject;
|
||||||
|
|
||||||
|
|
||||||
|
TFile *file = new TFile("test_file.root","RECREATE");
|
||||||
|
file->cd();
|
||||||
|
TTree *tree = new TTree;
|
||||||
|
// tree->Branch("test",&test);
|
||||||
|
|
||||||
|
// for(int i=0;i<10;++i) {
|
||||||
|
// test->a = i;
|
||||||
|
// test->b = -i;
|
||||||
|
// tree->Fill();
|
||||||
|
// }
|
||||||
|
tree->Write();
|
||||||
|
|
||||||
|
gApplication = new TApplication("My ROOT Application", &argc, argv);
|
||||||
|
TBrowser *tbr = new TBrowser("test");
|
||||||
|
tbr->Show();
|
||||||
|
|
||||||
|
|
||||||
|
gApplication->Run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
80
src/Core/testing/DreadDiamondParameters.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "boost/archive/xml_oarchive.hpp"
|
||||||
|
#include "boost/archive/xml_iarchive.hpp"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Core/Mpl.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
76
src/Core/testing/Flags.h
Normal file
76
src/Core/testing/Flags.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CORE_FLAGS_H
|
||||||
|
#define U_CORE_FLAGS_H
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
template<typename T> class Flags
|
||||||
|
{
|
||||||
|
T i;
|
||||||
|
public:
|
||||||
|
typedef T EnumT;
|
||||||
|
|
||||||
|
inline Flags(const Flags &f) : i(f.i) {}
|
||||||
|
inline Flags() : i((T)0) {}
|
||||||
|
inline Flags(T f) : i(f) {}
|
||||||
|
|
||||||
|
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
|
||||||
|
inline Flags &operator&=(T mask) { i &= mask; return *this; }
|
||||||
|
|
||||||
|
inline Flags &operator|=(const Flags f) { i |= f.i; return *this; }
|
||||||
|
inline Flags &operator|=(const T f) { i |= f; return *this; }
|
||||||
|
inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; }
|
||||||
|
inline Flags &operator^=(const T f) { i ^= f; return *this; }
|
||||||
|
|
||||||
|
inline Flags operator|(const Flags f) const { return Flags(i | f.i); }
|
||||||
|
inline Flags operator|(const T f) const { return Flags(i | f); }
|
||||||
|
inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); }
|
||||||
|
inline Flags operator^(const T f) const { return Flags(i ^ f); }
|
||||||
|
inline Flags operator&(const Flags f) const { return Flags(i & f.i); }
|
||||||
|
inline Flags operator&(const T f) const { return Flags(i & f); }
|
||||||
|
inline Flags operator~() const { return Flags(~i); }
|
||||||
|
|
||||||
|
inline bool operator !() const { return !i; }
|
||||||
|
inline bool testFlag(const T f) const
|
||||||
|
{ return (i & f) == f && (f != 0 || i == f ); }
|
||||||
|
// inline bool operator==(const T f) const { return i==f; }
|
||||||
|
|
||||||
|
inline T operator()() { return i; }
|
||||||
|
inline operator T() const { return i; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef Flags<unsigned short> Flags2B;
|
||||||
|
typedef Flags<unsigned int> Flags4B;
|
||||||
|
typedef Flags<unsigned long> Flags8B;
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FLAGS_H
|
||||||
38
src/Core/testing/Makefile.am
Normal file
38
src/Core/testing/Makefile.am
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
include $(top_srcdir)/Common.am
|
||||||
|
|
||||||
|
#AM_DEFAULT_SOURCE_EXT = .cpp
|
||||||
|
|
||||||
|
# if HAVE_CHECK
|
||||||
|
TESTS = SmartPointerTest \
|
||||||
|
SmartVectorTest \
|
||||||
|
VectorTest \
|
||||||
|
ObjectFlagsTest \
|
||||||
|
ObjectParametersTest \
|
||||||
|
ObjectCopyTest \
|
||||||
|
StaticInterfaceTest \
|
||||||
|
CommaInitTest \
|
||||||
|
DebugTTreeDumpTest \
|
||||||
|
BoostTest \
|
||||||
|
BoostAccumulatorTest \
|
||||||
|
PropertiesTest \
|
||||||
|
SignalTest \
|
||||||
|
SerializeTest \
|
||||||
|
SerializeDreadDiamondTest \
|
||||||
|
DreadDiamondParameters \
|
||||||
|
ObjectPropableTest \
|
||||||
|
TypeIntrospectionTraversal \
|
||||||
|
OptionsTest
|
||||||
|
|
||||||
|
# UuidTest
|
||||||
|
|
||||||
|
# else
|
||||||
|
# TEST =
|
||||||
|
# endif
|
||||||
|
|
||||||
|
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
|
||||||
|
|
||||||
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
|
|
||||||
|
all: $(TESTS)
|
||||||
|
|
||||||
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
50
src/Core/testing/ObjectCopyTest.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(ObjectParameters);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
69
src/Core/testing/ObjectFlagsTest.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
//class Derived : public uLib::Object {
|
||||||
|
//public:
|
||||||
|
// Derived(int flags) : uLib::Object(flags) {}
|
||||||
|
// enum Flags {
|
||||||
|
// a = 1<<0, // 1
|
||||||
|
// b = 1<<1, // 2
|
||||||
|
// c = 1<<2 // 4
|
||||||
|
// };
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(ObjectFlags);
|
||||||
|
|
||||||
|
// Object o(2);
|
||||||
|
// o.flags() = 4;
|
||||||
|
// o.flags() |= 1;
|
||||||
|
// TEST1( o.flags() == 5);
|
||||||
|
// o.flags() &= 1;
|
||||||
|
// TEST1( o.flags() == 1);
|
||||||
|
// TEST1( o.flags().testFlag(1) );
|
||||||
|
|
||||||
|
// Derived d( Derived::a | Derived::b);
|
||||||
|
// d.flags() = Derived::c;
|
||||||
|
// d.flags() |= Derived::a;
|
||||||
|
// TEST1( d.flags() == Derived::a | Derived::c);
|
||||||
|
// d.flags() &= 1;
|
||||||
|
// TEST1( d.flags() == Derived::a);
|
||||||
|
// TEST1( d.flags().testFlag(Derived::a) );
|
||||||
|
|
||||||
|
END_TESTING
|
||||||
|
}
|
||||||
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
61
src/Core/testing/ObjectParametersTest.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "boost/archive/xml_oarchive.hpp"
|
||||||
|
#include "boost/archive/xml_iarchive.hpp"
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
237
src/Core/testing/ObjectPropableTest.cpp
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/ObjectProps.h"
|
||||||
|
#include "Core/StringReader.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
#include "boost/archive/text_oarchive.hpp"
|
||||||
|
#include "boost/archive/text_iarchive.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// STRUCTURES //
|
||||||
|
|
||||||
|
|
||||||
|
struct A : virtual Object {
|
||||||
|
|
||||||
|
uLibTypeMacro(A, Object)
|
||||||
|
|
||||||
|
properties() {
|
||||||
|
int p_a;
|
||||||
|
Vector3f p_3f;
|
||||||
|
};
|
||||||
|
|
||||||
|
int m_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
void A::init_properties() {
|
||||||
|
$_init();
|
||||||
|
$$.p_a = 0;
|
||||||
|
$$.p_3f << 1,2,3;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(A)
|
||||||
|
ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); }
|
||||||
|
ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct B : A {
|
||||||
|
uLibTypeMacro(B,A)
|
||||||
|
|
||||||
|
properties() {
|
||||||
|
std::string p;
|
||||||
|
};
|
||||||
|
|
||||||
|
B() : m_b(324) {}
|
||||||
|
|
||||||
|
int m_b;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void B::init_properties() {
|
||||||
|
$_init();
|
||||||
|
$$.p = "ciao";
|
||||||
|
}
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(B)
|
||||||
|
ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); }
|
||||||
|
ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct C {
|
||||||
|
int m_c;
|
||||||
|
std::string m_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE(C)
|
||||||
|
ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct D : virtual Object, B {
|
||||||
|
uLibTypeMacro(D,Object,B)
|
||||||
|
|
||||||
|
properties() {
|
||||||
|
C p_c;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void D::init_properties() {
|
||||||
|
$_init();
|
||||||
|
$$.p_c.m_c = 1234;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(D)
|
||||||
|
ULIB_SERIALIZE_OBJECT(D,Object) {}
|
||||||
|
ULIB_SERIALIZE_OBJECT_PROPS(D) {
|
||||||
|
ar & AR(p_c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class E : public C, public D {
|
||||||
|
uLibTypeMacro(E,D,C)
|
||||||
|
public:
|
||||||
|
E() : m_Ea(5552368) {}
|
||||||
|
int m_Ea;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(E)
|
||||||
|
ULIB_SERIALIZE_OBJECT(E,C,D) {
|
||||||
|
ar & AR(m_Ea);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TESTS //
|
||||||
|
|
||||||
|
|
||||||
|
int test_xml_direct() {
|
||||||
|
// TEST ARCHIVE SAVE AND LOAD direct //
|
||||||
|
E o; o.init_properties();
|
||||||
|
o.$$.p_c.m_str = "works";
|
||||||
|
{
|
||||||
|
std::ofstream file("test.xml");
|
||||||
|
Archive::xml_oarchive ar(file);
|
||||||
|
ar << NVP(o);
|
||||||
|
}
|
||||||
|
o.$$.p_c.m_str = "hola";
|
||||||
|
{
|
||||||
|
std::ifstream file("test.xml");
|
||||||
|
Archive::xml_iarchive ar(file);
|
||||||
|
ar >> NVP(o);
|
||||||
|
}
|
||||||
|
std::cout << o.$$.p_c.m_str << "\n";
|
||||||
|
return ( o.$$.p_c.m_str == "works" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_xml_pointer() {
|
||||||
|
// TEST ARCHIVE SAVE AND LOAD from pointer //
|
||||||
|
E *o = new E; o->init_properties();
|
||||||
|
o->$$.p_c.m_str = "works";
|
||||||
|
{
|
||||||
|
std::ofstream file("test.xml");
|
||||||
|
Archive::xml_oarchive ar(file);
|
||||||
|
ar << NVP(o);
|
||||||
|
}
|
||||||
|
o->$$.p_c.m_str = "hola";
|
||||||
|
{
|
||||||
|
std::ifstream file("test.xml");
|
||||||
|
Archive::xml_iarchive ar(file);
|
||||||
|
ar >> NVP(o);
|
||||||
|
}
|
||||||
|
std::cout << o->$$.p_c.m_str << "\n";
|
||||||
|
return ( o->$$.p_c.m_str == "works" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_xml_objsave() {
|
||||||
|
// TEST SELF SAVE
|
||||||
|
E o; o.init_properties();
|
||||||
|
o.$(B).p = "works";
|
||||||
|
{
|
||||||
|
std::ofstream file("test.xml");
|
||||||
|
Object::SaveXml(file,o);
|
||||||
|
}
|
||||||
|
o.$(B).p = "hola";
|
||||||
|
{
|
||||||
|
std::ifstream file("test.xml");
|
||||||
|
Object::LoadXml(file,o);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << o.$(B).p << "\n";
|
||||||
|
return ( o.$(B).p == "works" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// MAIN //
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(PropableTest);
|
||||||
|
|
||||||
|
TEST1( test_xml_direct() );
|
||||||
|
TEST1( test_xml_pointer() );
|
||||||
|
TEST1( test_xml_objsave() );
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
72
src/Core/testing/OptionsTest.cpp
Normal file
72
src/Core/testing/OptionsTest.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Options.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(Boost ProgramOptions);
|
||||||
|
|
||||||
|
|
||||||
|
std::string optfile("configuration.ini");
|
||||||
|
int a = 0;
|
||||||
|
int b = 0;
|
||||||
|
Options opt;
|
||||||
|
|
||||||
|
opt.add_options()
|
||||||
|
("help", "printout help")
|
||||||
|
("value",&a,"value")
|
||||||
|
("config",&optfile,"config_file");
|
||||||
|
|
||||||
|
opt.add_config_options()
|
||||||
|
("B.value",&b,"b vlaue");
|
||||||
|
|
||||||
|
opt.parse_command_line(argc,argv);
|
||||||
|
opt.parse_config_file(optfile.c_str());
|
||||||
|
|
||||||
|
std::cout << "a = " << a << "\n";
|
||||||
|
std::cout << "b = " << b << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
96
src/Core/testing/PropertiesTest.cpp
Normal file
96
src/Core/testing/PropertiesTest.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/signals2/signal.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
#define emit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, bool copyable = true>
|
||||||
|
class property
|
||||||
|
{
|
||||||
|
typedef boost::signals2::signal<void(const property<T>& )> signal_t;
|
||||||
|
|
||||||
|
public:
|
||||||
|
property() : m_changed(new signal_t) {}
|
||||||
|
property(const T in) : value(in) , m_changed(new signal_t) {}
|
||||||
|
|
||||||
|
inline operator T const & () const { return value; }
|
||||||
|
inline operator T & () { return value; }
|
||||||
|
inline T & operator = (const T &i) { value = i; return value; }
|
||||||
|
template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||||
|
inline signal_t & valueChanged() { return *m_changed; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
T value;
|
||||||
|
boost::shared_ptr<signal_t> m_changed;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//template <typename T>
|
||||||
|
//class property <T,false> {
|
||||||
|
// typedef boost::signals2::signal<void( T )> signal_t;
|
||||||
|
|
||||||
|
//public:
|
||||||
|
// property() : m_changed() {}
|
||||||
|
// property(const T in) : value(in) , m_changed() {}
|
||||||
|
|
||||||
|
// inline operator T const & () const { return value; }
|
||||||
|
// inline operator T & () { valueChanged()(value); return value; }
|
||||||
|
// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; }
|
||||||
|
// template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
|
||||||
|
// inline signal_t &valueChanged() { return m_changed; }
|
||||||
|
|
||||||
|
//private:
|
||||||
|
// property(const property<T> &);
|
||||||
|
// property<T> &operator = (const property<T>&);
|
||||||
|
|
||||||
|
// T value;
|
||||||
|
// signal_t m_changed;
|
||||||
|
//};
|
||||||
|
|
||||||
|
// test generic void function slot //
|
||||||
|
void PrintSlot(const property<int> &i) { std::cout << "slot called, new value = " << i << "!\n"; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
114
src/Core/testing/SerializeDreadDiamondTest.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct A : Object {
|
||||||
|
uLibTypeMacro(A,Object)
|
||||||
|
A() : numa(5552368) {}
|
||||||
|
int numa;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(A)
|
||||||
|
ULIB_SERIALIZE_OBJECT(A,Object) {
|
||||||
|
ar & AR(numa);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct B : virtual Object {
|
||||||
|
uLibTypeMacro(B,Object)
|
||||||
|
B() : numb(5552369) {}
|
||||||
|
int numb;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(B)
|
||||||
|
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); }
|
||||||
|
|
||||||
|
|
||||||
|
struct C : B {
|
||||||
|
uLibTypeMacro(C,B)
|
||||||
|
C() : numc(5552370) {}
|
||||||
|
int numc;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(C)
|
||||||
|
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
|
||||||
|
|
||||||
|
struct D : A,B {
|
||||||
|
uLibTypeMacro(D,A,B)
|
||||||
|
|
||||||
|
D() : numd(5552371) {}
|
||||||
|
int numd;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(D)
|
||||||
|
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
main() {
|
||||||
|
A o; o.init_properties();
|
||||||
|
|
||||||
|
Archive::xml_oarchive(std::cout) << NVP(o);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
249
src/Core/testing/SerializeTest.cpp
Normal file
249
src/Core/testing/SerializeTest.cpp
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Archives.h"
|
||||||
|
#include "ParticlePhysics/MuonTomography/MuonScatter.h"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// MANUAL SERIALIZATION //
|
||||||
|
|
||||||
|
struct V3f {
|
||||||
|
|
||||||
|
float x,y,z;
|
||||||
|
V3f()
|
||||||
|
{ x = y = z =0; }
|
||||||
|
|
||||||
|
V3f(float x, float y, float z) :
|
||||||
|
x(x), y(y), z(z) {}
|
||||||
|
|
||||||
|
template <class Archive>
|
||||||
|
void serialize (Archive &ar,unsigned int v) {
|
||||||
|
ar
|
||||||
|
& "<" & NVP(x) & NVP(y) & NVP(z) & ">";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ULIB_CLASS_EXPORT_KEY(V3f);
|
||||||
|
ULIB_CLASS_EXPORT_IMPLEMENT(V3f);
|
||||||
|
|
||||||
|
|
||||||
|
inline std::ostream &
|
||||||
|
operator <<(std::ostream &o, const V3f &v) {
|
||||||
|
Archive::hrt_oarchive(o) << v;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::istream &
|
||||||
|
operator >>(std::istream &is, V3f &v) {
|
||||||
|
Archive::hrt_iarchive(is) >> v;
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int test_V3f() {
|
||||||
|
// testing human readble archive with simple serializable structure //
|
||||||
|
|
||||||
|
V3f v1(1,2,3),v2,v3,v4;
|
||||||
|
std::cout << "v --> " << v1 << "\n";
|
||||||
|
|
||||||
|
std::stringstream ss; ss << v1;
|
||||||
|
std::cout << "ss.v --> " << ss.str() << "\n";
|
||||||
|
|
||||||
|
Archive::hrt_iarchive ar(ss); ar >> v2;
|
||||||
|
std::cout << "v2 --> " << v2 << "\n";
|
||||||
|
|
||||||
|
std::stringstream("<2 3 4>") >> v3;
|
||||||
|
std::cout << "v3 --> " << v3 << "\n";
|
||||||
|
|
||||||
|
// std::cout << "insert V3f string to parse: "; std::cin >> v4;
|
||||||
|
// std::cout << "v4 --> " << v4 << "\n";
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// OBJECT SERIALIZATION //
|
||||||
|
|
||||||
|
class A : public virtual Object {
|
||||||
|
uLibTypeMacro(A,Object)
|
||||||
|
ULIB_SERIALIZE_ACCESS
|
||||||
|
public:
|
||||||
|
A() : m_a(5552368) {}
|
||||||
|
|
||||||
|
properties() {
|
||||||
|
std::string p_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
uLibRefMacro (a,int);
|
||||||
|
private:
|
||||||
|
int m_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
void A::init_properties() {
|
||||||
|
$_init();
|
||||||
|
$$.p_a = "A property string";
|
||||||
|
}
|
||||||
|
|
||||||
|
ULIB_SERIALIZABLE_OBJECT(A)
|
||||||
|
ULIB_SERIALIZE_OBJECT(A,Object) {
|
||||||
|
ar
|
||||||
|
& "Object A : "
|
||||||
|
& "--> m_a = " & AR(m_a)
|
||||||
|
& "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
ULIB_SERIALIZE_OBJECT_PROPS(A) {
|
||||||
|
ar
|
||||||
|
& "Object A properties: "
|
||||||
|
& "---> p_a = " & AR(p_a) & "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int testing_xml_class() {
|
||||||
|
|
||||||
|
A a; a.init_properties();
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ofstream file("test.xml");
|
||||||
|
Archive::xml_oarchive(file) << NVP(a);
|
||||||
|
}
|
||||||
|
a.a() = 0;
|
||||||
|
a.$$.p_a = "zero string";
|
||||||
|
{
|
||||||
|
std::ifstream file("test.xml");
|
||||||
|
Archive::xml_iarchive(file) >> NVP(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Archive::xml_oarchive(std::cout) << NVP(a);
|
||||||
|
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
|
||||||
|
}
|
||||||
|
|
||||||
|
int testing_hrt_class() {
|
||||||
|
|
||||||
|
A a; a.init_properties();
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ofstream file("test.xml");
|
||||||
|
Archive::hrt_oarchive(file) << NVP(a);
|
||||||
|
}
|
||||||
|
a.a() = 0;
|
||||||
|
a.$$.p_a = "zero string";
|
||||||
|
{
|
||||||
|
// ERRORE FIX !
|
||||||
|
// std::ifstream file("test.xml");
|
||||||
|
// Archive::hrt_iarchive(file) >> NVP(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Archive::hrt_oarchive(std::cout) << NVP(a);
|
||||||
|
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// MUON SCATTER EXAMPLE //
|
||||||
|
|
||||||
|
int testing_mu()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
MuonScatter mu;
|
||||||
|
mu.SetMomentumIn(555);
|
||||||
|
mu.SetMomentumOut(2368);
|
||||||
|
{
|
||||||
|
std::ofstream file("test.txt");
|
||||||
|
file << mu;
|
||||||
|
}
|
||||||
|
|
||||||
|
mu.SetMomentumIn(0);
|
||||||
|
mu.SetMomentumOut(0);
|
||||||
|
{
|
||||||
|
std::ifstream file("test.txt");
|
||||||
|
file >> mu;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << mu << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(Serialize Test);
|
||||||
|
|
||||||
|
TEST1( test_V3f() );
|
||||||
|
TEST1( testing_xml_class() );
|
||||||
|
// testing_hrt_class(); ///// << ERRORE in HRT with properties
|
||||||
|
TEST1( testing_mu() );
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
115
src/Core/testing/SignalTest.cpp
Normal file
115
src/Core/testing/SignalTest.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Signal.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Ob1 : public Object {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void V0();
|
||||||
|
|
||||||
|
int V1(int a);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// should be done by moc //
|
||||||
|
void Ob1::V0() {
|
||||||
|
ULIB_SIGNAL_EMIT(Ob1::V0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Ob1::V1(int a) {
|
||||||
|
ULIB_SIGNAL_EMIT(Ob1::V1,a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Ob2 : public Object {
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void PrintV0() {
|
||||||
|
std::cout << "Ob2 prints V0\n" << std::flush;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Ob3 : public Object {
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void PrintV0() {
|
||||||
|
std::cout << "Ob3 prints V0\n" << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintNumber(int n) {
|
||||||
|
std::cout << "Ob3 is printing number: " << n << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(Signals);
|
||||||
|
|
||||||
|
Ob1 ob1;
|
||||||
|
Ob2 ob2;
|
||||||
|
Ob3 ob3;
|
||||||
|
|
||||||
|
Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0);
|
||||||
|
Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0);
|
||||||
|
Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber);
|
||||||
|
|
||||||
|
// not working yet
|
||||||
|
// Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0())
|
||||||
|
|
||||||
|
ob1.PrintSelf(std::cout);
|
||||||
|
|
||||||
|
emit ob1.V0();
|
||||||
|
emit ob1.V1(5552368);
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
94
src/Core/testing/SmartPointerTest.cpp
Normal file
94
src/Core/testing/SmartPointerTest.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Core/SmartPointer.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
namespace Test {
|
||||||
|
|
||||||
|
struct ObjectMockInterface {
|
||||||
|
virtual void PrintValue()=0;
|
||||||
|
virtual int& Value()=0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ObjectMock : ObjectMockInterface {
|
||||||
|
int value;
|
||||||
|
public:
|
||||||
|
int& Value() { return value; }
|
||||||
|
void PrintValue() { std::cout << "Value: " << value << "\n"; }
|
||||||
|
|
||||||
|
};
|
||||||
|
} // Test
|
||||||
|
|
||||||
|
|
||||||
|
bool test_smpt(SmartPointer<Test::ObjectMock> &p) {
|
||||||
|
|
||||||
|
SmartPointer<Test::ObjectMock> spt = p;
|
||||||
|
spt->Value() = 5552368;
|
||||||
|
{
|
||||||
|
SmartPointer<Test::ObjectMock> copy = spt;
|
||||||
|
copy->Value() = 123;
|
||||||
|
}
|
||||||
|
return (spt->Value() == 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main () {
|
||||||
|
BEGIN_TESTING(SmartPointer);
|
||||||
|
|
||||||
|
// HOLD REFERENCE //
|
||||||
|
{
|
||||||
|
SmartPointer<Test::ObjectMock> spt(new Test::ObjectMock);
|
||||||
|
TEST1(test_smpt(spt));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SmartPointer<Test::ObjectMock> spt;
|
||||||
|
TEST1(test_smpt(spt));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SmartPointer<Test::ObjectMock> spt = new SmartPointer<Test::ObjectMock>;
|
||||||
|
TEST1(test_smpt(spt));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TAKE REFERENCE //
|
||||||
|
{
|
||||||
|
Test::ObjectMock obj;
|
||||||
|
SmartPointer<Test::ObjectMock> spt(obj);
|
||||||
|
TEST1(test_smpt(spt));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
120
src/Core/testing/SmartVectorTest.cpp
Normal file
120
src/Core/testing/SmartVectorTest.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
static int instanziated_objects_number;
|
||||||
|
|
||||||
|
class ObjectTest : public Object {
|
||||||
|
public:
|
||||||
|
ObjectTest() {
|
||||||
|
data[0] = 0;
|
||||||
|
data[1] = 1;
|
||||||
|
data[2] = 2;
|
||||||
|
instanziated_objects_number++;
|
||||||
|
}
|
||||||
|
ObjectTest(const ObjectTest ©) {
|
||||||
|
data[0] = copy.data[0];
|
||||||
|
data[1] = copy.data[1];
|
||||||
|
data[2] = copy.data[2];
|
||||||
|
instanziated_objects_number++;
|
||||||
|
}
|
||||||
|
|
||||||
|
~ObjectTest()
|
||||||
|
{
|
||||||
|
instanziated_objects_number--;
|
||||||
|
}
|
||||||
|
float data[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(SmartVector);
|
||||||
|
|
||||||
|
instanziated_objects_number =0;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////// SMART POINTER FUNCIONALITY ///////////////////////
|
||||||
|
|
||||||
|
// int smart vector //
|
||||||
|
SmartVector<int> sv(10);
|
||||||
|
for (int i=0;i<10;++i)
|
||||||
|
sv[i] = i;
|
||||||
|
// new shallow copy inside a code block //
|
||||||
|
{
|
||||||
|
SmartVector<int> newsv = sv;
|
||||||
|
newsv[5] = 5552368;
|
||||||
|
TEST1(sv[5] == newsv[5]);
|
||||||
|
}
|
||||||
|
// verify that newsv destruction does not delete instance //
|
||||||
|
TEST1( sv[5] == 5552368 );
|
||||||
|
|
||||||
|
SmartVector<ObjectTest> svo(10);
|
||||||
|
for (int i=0;i<10;++i)
|
||||||
|
svo[i] = ObjectTest();
|
||||||
|
|
||||||
|
TEST1(instanziated_objects_number == 10);
|
||||||
|
{
|
||||||
|
SmartVector<ObjectTest> newsvo = svo;
|
||||||
|
newsvo[5].data[1] = 5552368.0;
|
||||||
|
TEST1(svo[5].data[1] == newsvo[5].data[1]);
|
||||||
|
TEST1(instanziated_objects_number == 10);
|
||||||
|
}
|
||||||
|
TEST1(instanziated_objects_number == 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////// ITERATOR FUNCIONALITY //////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
Vector<int> v(10);
|
||||||
|
Vector<int>::Iterator it;
|
||||||
|
|
||||||
|
int i=1;
|
||||||
|
for(it=v.begin() ; it==v.end(); it++, i++)
|
||||||
|
*it = i;
|
||||||
|
|
||||||
|
for(i = 0; i<v.size(); i++)
|
||||||
|
TEST1( v[i] = i+1 );
|
||||||
|
|
||||||
|
Vector<int>::ConstIterator cit;
|
||||||
|
i=1;
|
||||||
|
for(cit=v.begin(); cit==v.end(); cit++, i++)
|
||||||
|
TEST1( *cit == i+1 );
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
112
src/Core/testing/StaticInterfaceTest.cpp
Normal file
112
src/Core/testing/StaticInterfaceTest.cpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include <Core/StaticInterface.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
//// INTERFACE TO COMPLEX CLASS /////
|
||||||
|
|
||||||
|
namespace Interface {
|
||||||
|
struct Test {
|
||||||
|
MAKE_TRAITS
|
||||||
|
template<class Self> void check_structural() {
|
||||||
|
uLibCheckFunction(Self,test,bool,int,float);
|
||||||
|
uLibCheckMember(Self,testmemb,int);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Test {
|
||||||
|
bool test(int i, float f){}
|
||||||
|
int testmemb;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// INTERFAC TO SIMPLE CLASS ///////////
|
||||||
|
|
||||||
|
namespace Interface {
|
||||||
|
struct Simple {
|
||||||
|
MAKE_TRAITS
|
||||||
|
template<class Self> void check_structural() {
|
||||||
|
uLibCheckMember(Self,memb1,int);
|
||||||
|
uLibCheckMember(Self,memb2,float);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Simple {
|
||||||
|
int memb1;
|
||||||
|
float memb2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class UseTest {
|
||||||
|
public:
|
||||||
|
UseTest() {
|
||||||
|
Interface::IsA<T,Interface::Test>();
|
||||||
|
T t;
|
||||||
|
int i; float f;
|
||||||
|
t.test(i,f);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class UseSimple {
|
||||||
|
public:
|
||||||
|
UseSimple() {
|
||||||
|
Interface::IsA<T,Interface::Simple>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(Static Interface);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uLib::UseTest<uLib::Test> u;
|
||||||
|
|
||||||
|
uLib::UseSimple<uLib::Simple> s;
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
52
src/Core/testing/TypeIntrospectionTraversal.cpp
Normal file
52
src/Core/testing/TypeIntrospectionTraversal.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
45
src/Core/testing/UuidTest.cpp
Normal file
45
src/Core/testing/UuidTest.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Uuid.h"
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(uuid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
84
src/Core/testing/VectorTest.cpp
Normal file
84
src/Core/testing/VectorTest.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Core/Vector.h>
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
struct __Cmp {
|
||||||
|
bool operator()(const T &data, const float value) {
|
||||||
|
return data <= value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename _Tp, typename _CmpT>
|
||||||
|
inline const unsigned long
|
||||||
|
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
|
||||||
|
{
|
||||||
|
|
||||||
|
_Tp it = _it;
|
||||||
|
_Tp end = _end-1;
|
||||||
|
for(it; it != end; )
|
||||||
|
{
|
||||||
|
if ( _comp(*it, value) ) it++;
|
||||||
|
else if( _comp(*end, value) )
|
||||||
|
{
|
||||||
|
std::swap(*it,*end--);
|
||||||
|
}
|
||||||
|
else --end;
|
||||||
|
}
|
||||||
|
return it - _it;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BEGIN_TESTING(Vector);
|
||||||
|
|
||||||
|
uLib::Vector<float> v;
|
||||||
|
v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int id = VectorSplice(v.begin(),v.end(),3,__Cmp<float>());
|
||||||
|
|
||||||
|
std::cout << "id: " << id << "\n";
|
||||||
|
std::cout << "vector: ";
|
||||||
|
for(uLib::Vector<float>::Iterator it = v.begin(); it!=v.end(); it++)
|
||||||
|
std::cout << *it <<" ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
// std::sort(v.begin(),v.end(),LT<float>());
|
||||||
|
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
37
src/Core/testing/testing-prototype.h
Normal file
37
src/Core/testing/testing-prototype.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define BEGIN_TESTING(name) \
|
||||||
|
static int _fail = 0; \
|
||||||
|
printf("..:: Testing " #name " ::..\n");
|
||||||
|
|
||||||
|
#define TEST1(val) _fail += (val)==0
|
||||||
|
#define TEST0(val) _fail += (val)!=0
|
||||||
|
#define END_TESTING return _fail;
|
||||||
|
|
||||||
38
src/Detectors/CMakeLists.txt
Normal file
38
src/Detectors/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# HEADERS
|
||||||
|
set(HEADERS
|
||||||
|
DetectorChamber.h
|
||||||
|
ExperimentFitEvent.h
|
||||||
|
GeantEvent.h
|
||||||
|
HitMC.h
|
||||||
|
MuonScatter.h
|
||||||
|
MuonEvent.h
|
||||||
|
MuonError.h
|
||||||
|
ChamberHitEvent.h
|
||||||
|
Hit.h
|
||||||
|
LinearFit.h
|
||||||
|
Solid.h
|
||||||
|
Matter.h
|
||||||
|
Scene.h
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# SOURCES
|
||||||
|
set(SOURCES
|
||||||
|
Solid.cpp
|
||||||
|
Scene.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${Boost_SERIALIZATION_LIBRARY}
|
||||||
|
${Boost_SIGNALS_LIBRARY}
|
||||||
|
${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||||
|
${Eigen_LIBRARY}
|
||||||
|
${Geant4_LIBRARIES}
|
||||||
|
${ROOT_LIBRARIES}
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${PACKAGE_LIBPREFIX}Detectors
|
||||||
|
)
|
||||||
|
|
||||||
|
uLib_add_shared_library(${uLib-module})
|
||||||
|
add_subdirectory(testing)
|
||||||
56
src/Detectors/ChamberHitEvent.h
Normal file
56
src/Detectors/ChamberHitEvent.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CHAMBERHITEVENT_H
|
||||||
|
#define U_CHAMBERHITEVENT_H
|
||||||
|
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Hit.h"
|
||||||
|
#include "ChamberDetector.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class ChamberHitEventData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uLibConstRefMacro (Hits, Vector<HitData> )
|
||||||
|
uLibGetMacro (Idv, ChamberDetector::ID)
|
||||||
|
private:
|
||||||
|
friend class ChamberHitEvent;
|
||||||
|
Vector<HitData> m_Hits;
|
||||||
|
DetectorChamber::ID m_Idv; // -> chamber/view
|
||||||
|
};
|
||||||
|
|
||||||
|
class ChamberHitEvent : public ChamberHitEventData {
|
||||||
|
public:
|
||||||
|
uLibRefMacro (Hits, Vector<HitData> )
|
||||||
|
uLibSetMacro (Idv, ChamberDetector::ID)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CHAMBERHITEVENT_H
|
||||||
48
src/Detectors/DetectorChamber.h
Normal file
48
src/Detectors/DetectorChamber.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_CHAMBERDETECTOR_H
|
||||||
|
#define U_CHAMBERDETECTOR_H
|
||||||
|
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class DetectorChamber : public ContainerBox {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // CHAMBERDETECTOR_H
|
||||||
48
src/Detectors/ExperimentFitEvent.h
Normal file
48
src/Detectors/ExperimentFitEvent.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_EXPERIMENTFITEVENT_H
|
||||||
|
#define U_EXPERIMENTFITEVENT_H
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class ExperimentFitEventData {
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // EXPERIMENTFITEVENT_H
|
||||||
69
src/Detectors/GeantEvent.h
Normal file
69
src/Detectors/GeantEvent.h
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_GEANTEVENT_H
|
||||||
|
#define U_GEANTEVENT_H
|
||||||
|
|
||||||
|
#include "Core/Types.h"
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
#include "ChamberHitEvent.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class GeantEventData {
|
||||||
|
public:
|
||||||
|
uLibGetMacro (EventID, Id_t )
|
||||||
|
uLibGetMacro (Momentum,Scalarf )
|
||||||
|
uLibConstRefMacro (GenPos, Vector3f)
|
||||||
|
uLibConstRefMacro (GenDir, Vector3f)
|
||||||
|
uLibConstRefMacro (ChEvents,Vector<ChamberHitEventData>)
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class GeantEvent;
|
||||||
|
Id_t m_EventID;
|
||||||
|
Scalarf m_Momentum;
|
||||||
|
Vector3f m_GenPos;
|
||||||
|
Vector3f m_GenDir;
|
||||||
|
Vector<ChamberHitEventData> m_ChEvents;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GeantEvent {
|
||||||
|
public:
|
||||||
|
uLibSetMacro (EventID, Id_t )
|
||||||
|
uLibSetMacro (Momentum,Scalarf )
|
||||||
|
uLibRefMacro (GenPos, Vector3f)
|
||||||
|
uLibRefMacro (GenDir, Vector3f)
|
||||||
|
uLibRefMacro (ChEvents,Vector<ChamberHitEventData>)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // GEANTEVENT_H
|
||||||
41
src/Detectors/HierarchicalEncoding.h
Normal file
41
src/Detectors/HierarchicalEncoding.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#ifndef U_DETECTORS_HIERARCHICALENCODING_H
|
||||||
|
#define U_DETECTORS_HIERARCHICALENCODING_H
|
||||||
|
|
||||||
|
#include <Core/BitCoding.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // uLib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HIERARCHICALENCODING_H
|
||||||
70
src/Detectors/Hit.h
Normal file
70
src/Detectors/Hit.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HIT_H
|
||||||
|
#define HIT_H
|
||||||
|
|
||||||
|
#include "Math/BitCode.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class HitRawCode_CMSDrift :
|
||||||
|
public BitCode4<unsigned short,6,3,2,5>
|
||||||
|
{
|
||||||
|
typedef unsigned short T;
|
||||||
|
public:
|
||||||
|
HitRawCode_CMSDrift() : BitCode4(0) {}
|
||||||
|
HitRawCode_CMSDrift(const Vector4i &v) : BitCode4(v) {}
|
||||||
|
HitRawCode_CMSDrift(T Chamber, T ROB, T TDC, T Channel ) {
|
||||||
|
(*this) << Chamber, ROB, TDC, Channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline T Chamber() const { return m_data.bitf.field1; }
|
||||||
|
inline void SetChamber(const T data) { m_data.bitf.field1 = data; }
|
||||||
|
inline T ROB() const { return m_data.bitf.field2; }
|
||||||
|
inline void SetROB(const T data) { m_data.bitf.field2 = data; }
|
||||||
|
inline T TDC() const { return m_data.bitf.field3; }
|
||||||
|
inline void SetTDC(const T data) { m_data.bitf.field3 = data; }
|
||||||
|
inline T Channel() const { return m_data.bitf.field4; }
|
||||||
|
inline void SetChannel(const T data) { m_data.bitf.field4 = data; }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // HIT_H
|
||||||
67
src/Detectors/HitMC.h
Normal file
67
src/Detectors/HitMC.h
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_HITMC_H
|
||||||
|
#define U_HITMC_H
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Hit.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class HitMCData : public HitData{
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
PrimaryMu,
|
||||||
|
SecondaryMu,
|
||||||
|
DeltaRay
|
||||||
|
};
|
||||||
|
|
||||||
|
uLibConstRefMacro(Position,HPoint3f)
|
||||||
|
uLibGetMacro(Type, enum Type)
|
||||||
|
|
||||||
|
private:
|
||||||
|
HPoint3f m_Position;
|
||||||
|
enum Type m_Type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class HitMC : public HitMCData {
|
||||||
|
public:
|
||||||
|
uLibRefMacro(Position,HPoint3f)
|
||||||
|
uLibSetMacro(Type, enum Type)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HITMC_H
|
||||||
73
src/Detectors/LinearFit.h
Normal file
73
src/Detectors/LinearFit.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_LINEARFIT_H
|
||||||
|
#define U_LINEARFIT_H
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "ChamberDetector.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class LinearFitData {
|
||||||
|
public:
|
||||||
|
uLibConstRefMacro(Position,Vector2f)
|
||||||
|
uLibConstRefMacro(Slope,Vector2f)
|
||||||
|
uLibConstRefMacro(PositionError,Vector2f)
|
||||||
|
uLibConstRefMacro(SlopeError,Vector2f)
|
||||||
|
uLibGetMacro(HitsNumber,int)
|
||||||
|
uLibGetMacro(Idv,ChamberDetector::ID)
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class LinearFit;
|
||||||
|
Vector2f m_Position;
|
||||||
|
Vector2f m_Slope;
|
||||||
|
Vector2f m_PositionError;
|
||||||
|
Vector2f m_SlopeError;
|
||||||
|
int m_HitsNumber;
|
||||||
|
DetectorChamber::ID m_Idv;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class LinearFit : public LinearFitData {
|
||||||
|
public:
|
||||||
|
uLibRefMacro(Position,Vector2f)
|
||||||
|
uLibRefMacro(Slope,Vector2f)
|
||||||
|
uLibRefMacro(PositionError,Vector2f)
|
||||||
|
uLibRefMacro(SlopeError,Vector2f)
|
||||||
|
uLibSetMacro(HitsNumber,int)
|
||||||
|
uLibSetMacro(Idv,ChamberDetector::ID)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LINEARFIT_H
|
||||||
25
src/Detectors/Makefile.am
Normal file
25
src/Detectors/Makefile.am
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
include $(top_srcdir)/Common.am
|
||||||
|
|
||||||
|
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Detectors
|
||||||
|
library_include_HEADERS = DetectorChamber.h \
|
||||||
|
ExperimentFitEvent.h \
|
||||||
|
GeantEvent.h \
|
||||||
|
HitMC.h \
|
||||||
|
MuonScatter.h \
|
||||||
|
MuonEvent.h \
|
||||||
|
MuonError.h \
|
||||||
|
ChamberHitEvent.h \
|
||||||
|
Hit.h \
|
||||||
|
LinearFit.h \
|
||||||
|
Solid.h \
|
||||||
|
Matter.h \
|
||||||
|
Scene.h
|
||||||
|
|
||||||
|
_DETECTORS_SOURCES = \
|
||||||
|
Solid.cpp \
|
||||||
|
Scene.cpp
|
||||||
|
|
||||||
|
noinst_LTLIBRARIES = libmutomdetectors.la
|
||||||
|
libmutomdetectors_la_SOURCES = ${_DETECTORS_SOURCES}
|
||||||
|
|
||||||
|
|
||||||
71
src/Detectors/Matter.h
Normal file
71
src/Detectors/Matter.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MATTER_H
|
||||||
|
#define MATTER_H
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
|
||||||
|
class G4Element;
|
||||||
|
class G4Material;
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//// ELEMENT ///////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class Element {
|
||||||
|
public:
|
||||||
|
|
||||||
|
uLibRefMacro(G4Data,G4Element *)
|
||||||
|
private:
|
||||||
|
G4Element *m_G4Data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//// MATERIAL //////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
class Material : public Object {
|
||||||
|
public:
|
||||||
|
|
||||||
|
uLibRefMacro(G4Data,G4Material *)
|
||||||
|
private:
|
||||||
|
G4Material *m_G4Data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MATTER_H
|
||||||
58
src/Detectors/MuonError.h
Normal file
58
src/Detectors/MuonError.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_MUONERROR_H
|
||||||
|
#define U_MUONERROR_H
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class MuonErrorData {
|
||||||
|
friend class MuonError;
|
||||||
|
public:
|
||||||
|
uLibConstRefMacro(Theta,Scalarf)
|
||||||
|
uLibConstRefMacro(Phi,Scalarf)
|
||||||
|
private:
|
||||||
|
Scalarf m_Theta;
|
||||||
|
Scalarf m_Phi;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class MuonError : public MuonErrorData {
|
||||||
|
public:
|
||||||
|
uLibRefMacro(Theta,Scalarf)
|
||||||
|
uLibRefMacro(Phi,Scalarf)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // end ulib space
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_MUONERROR_H
|
||||||
75
src/Detectors/MuonEvent.h
Normal file
75
src/Detectors/MuonEvent.h
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_MUONEVENT_H
|
||||||
|
#define U_MUONEVENT_H
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class MuonEventData {
|
||||||
|
friend class MuonEvent;
|
||||||
|
public:
|
||||||
|
uLibConstRefMacro(LineIn,HLine3f)
|
||||||
|
uLibConstRefMacro(LineOut,HLine3f)
|
||||||
|
uLibGetMacro(Momentum,Scalarf)
|
||||||
|
|
||||||
|
private:
|
||||||
|
HLine3f m_LineIn;
|
||||||
|
HLine3f m_LineOut;
|
||||||
|
Scalarf m_Momentum;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class MuonEvent : public MuonEventData {
|
||||||
|
public:
|
||||||
|
uLibRefMacro(LineIn,HLine3f)
|
||||||
|
uLibRefMacro(LineOut,HLine3f)
|
||||||
|
uLibRefMacro(Momentum,Scalarf)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::ostream&
|
||||||
|
operator<< (std::ostream& stream, const MuonEventData &mu) {
|
||||||
|
stream << " MuonEventData: --------------- \n"
|
||||||
|
<< " P: " << mu.GetMomentum() << "\n"
|
||||||
|
<< " IN: " << mu.LineIn() << "\n"
|
||||||
|
<< " OUT: " << mu.LineOut() << "\n"
|
||||||
|
<< " ------------------------------ \n";
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // end ulib space
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // U_MUONEVENT_H
|
||||||
80
src/Detectors/MuonScatter.h
Normal file
80
src/Detectors/MuonScatter.h
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef U_MUONSCATTER_H
|
||||||
|
#define U_MUONSCATTER_H
|
||||||
|
|
||||||
|
#include "Core/Macros.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class MuonScatter {
|
||||||
|
public:
|
||||||
|
uLibConstRefMacro(LineIn,HLine3f)
|
||||||
|
uLibConstRefMacro(ErrorIn,HError3f)
|
||||||
|
uLibConstRefMacro(LineOut,HLine3f)
|
||||||
|
uLibConstRefMacro(ErrorOut,HError3f)
|
||||||
|
|
||||||
|
uLibRefMacro(LineIn,HLine3f)
|
||||||
|
uLibRefMacro(ErrorIn,HError3f)
|
||||||
|
uLibRefMacro(LineOut,HLine3f)
|
||||||
|
uLibRefMacro(ErrorOut,HError3f)
|
||||||
|
uLibSetMacro(Momentum,Scalarf)
|
||||||
|
uLibSetMacro(MomentumPrime,Scalarf)
|
||||||
|
|
||||||
|
uLibGetMacro(Momentum,Scalarf)
|
||||||
|
uLibGetMacro(MomentumPrime,Scalarf)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HLine3f m_LineIn;
|
||||||
|
HLine3f m_LineOut;
|
||||||
|
HError3f m_ErrorIn;
|
||||||
|
HError3f m_ErrorOut;
|
||||||
|
Scalarf m_Momentum;
|
||||||
|
Scalarf m_MomentumPrime;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef MuonScatter MuonScatterData;
|
||||||
|
|
||||||
|
inline std::ostream&
|
||||||
|
operator<< (std::ostream& stream, const MuonScatterData &mu) {
|
||||||
|
stream << " MuonScatterData: ------------- \n"
|
||||||
|
<< " P: " << mu.GetMomentum() << " Pprim: " << mu.GetMomentumPrime() << "\n"
|
||||||
|
<< " IN: " << mu.LineIn() << "\n"
|
||||||
|
<< " " << mu.ErrorIn() << "\n"
|
||||||
|
<< " OUT: " << mu.LineOut() << "\n"
|
||||||
|
<< " " << mu.ErrorOut() <<"\n"
|
||||||
|
<< " ------------------------------ \n";
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // U_MUONSCATTER_H
|
||||||
74
src/Detectors/Scene.cpp
Normal file
74
src/Detectors/Scene.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Matter.h"
|
||||||
|
#include "Solid.h"
|
||||||
|
|
||||||
|
#include "Scene.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class DetectorsScenePimpl {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
// members //
|
||||||
|
//Vector<Solid> m_Solids;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DetectorsScene::DetectorsScene() :
|
||||||
|
d(new DetectorsScenePimpl())
|
||||||
|
{}
|
||||||
|
|
||||||
|
DetectorsScene::~DetectorsScene()
|
||||||
|
{
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DetectorsScene::AddSolid(const Solid &solid)
|
||||||
|
{
|
||||||
|
// d->m_Solids.push_back(solid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
52
src/Detectors/Scene.h
Normal file
52
src/Detectors/Scene.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SCENE_H
|
||||||
|
#define SCENE_H
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "Solid.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
class DetectorsScene : public Object {
|
||||||
|
public:
|
||||||
|
DetectorsScene();
|
||||||
|
~DetectorsScene();
|
||||||
|
|
||||||
|
|
||||||
|
void AddSolid(const Solid &solid);
|
||||||
|
|
||||||
|
private:
|
||||||
|
class DetectorsScenePimpl *d;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // SCENE_H
|
||||||
114
src/Detectors/Solid.cpp
Normal file
114
src/Detectors/Solid.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// G4 Solid //
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
|
||||||
|
// Tessellated solid //
|
||||||
|
#include <Geant4/G4TessellatedSolid.hh>
|
||||||
|
#include <Geant4/G4TriangularFacet.hh>
|
||||||
|
#include <Geant4/G4ThreeVector.hh>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
|
#include "Solid.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class DetectorsSolidPimpl {
|
||||||
|
public:
|
||||||
|
static G4ThreeVector getG4Vector3f(const Vector3f &vector) {
|
||||||
|
return G4ThreeVector( vector(0), vector(1), vector(2) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Solid::Solid() :
|
||||||
|
m_Logical (new G4LogicalVolume(NULL,NULL,"unnamed_solid")),
|
||||||
|
m_Material(NULL)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Solid::Solid(const char *name) :
|
||||||
|
m_Logical(new G4LogicalVolume(NULL,NULL,name)),
|
||||||
|
m_Material(NULL)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Solid::SetNistMaterial(const char *name)
|
||||||
|
{
|
||||||
|
G4NistManager *nist = G4NistManager::Instance();
|
||||||
|
if (m_Material) delete m_Material;
|
||||||
|
m_Material = nist->FindOrBuildMaterial(name);
|
||||||
|
m_Logical->SetMaterial(m_Material);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Solid::SetMaterial(G4Material *material)
|
||||||
|
{
|
||||||
|
if(material)
|
||||||
|
{
|
||||||
|
m_Material = material;
|
||||||
|
m_Logical->SetMaterial(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TessellatedSolid::TessellatedSolid(const char *name) :
|
||||||
|
BaseClass(name),
|
||||||
|
m_Solid(new G4TessellatedSolid(name))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void TessellatedSolid::SetMesh(TriangleMesh &mesh)
|
||||||
|
{
|
||||||
|
G4TessellatedSolid *ts = this->m_Solid;
|
||||||
|
for (int i=0; i<mesh.Triangles().size(); ++i) {
|
||||||
|
const Vector3i &trg = mesh.Triangles().at(i);
|
||||||
|
G4TriangularFacet *facet = new G4TriangularFacet(
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(0))),
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(1))),
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(2))),
|
||||||
|
ABSOLUTE);
|
||||||
|
ts->AddFacet((G4VFacet *)facet);
|
||||||
|
}
|
||||||
|
this->m_Logical->SetSolid(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
86
src/Detectors/Solid.h
Normal file
86
src/Detectors/Solid.h
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SOLID_H
|
||||||
|
#define SOLID_H
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Math/TriangleMesh.h"
|
||||||
|
#include "Detectors/Matter.h"
|
||||||
|
|
||||||
|
class G4Material;
|
||||||
|
class G4LogicalVolume;
|
||||||
|
class G4TessellatedSolid;
|
||||||
|
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class Solid : public Object {
|
||||||
|
public:
|
||||||
|
|
||||||
|
Solid();
|
||||||
|
Solid(const char *name);
|
||||||
|
|
||||||
|
void SetNistMaterial(const char *name);
|
||||||
|
|
||||||
|
void SetMaterial(G4Material *material);
|
||||||
|
|
||||||
|
uLibGetMacro(Material,G4Material *)
|
||||||
|
uLibGetMacro(Logical,G4LogicalVolume *)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
G4Material *m_Material;
|
||||||
|
G4LogicalVolume *m_Logical;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TessellatedSolid : public Solid {
|
||||||
|
typedef Solid BaseClass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TessellatedSolid(const char *name);
|
||||||
|
|
||||||
|
void SetMesh(TriangleMesh &mesh);
|
||||||
|
|
||||||
|
uLibGetMacro(Solid,G4TessellatedSolid *)
|
||||||
|
private:
|
||||||
|
G4TessellatedSolid *m_Solid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SOLID_H
|
||||||
18
src/Detectors/testing/CMakeLists.txt
Normal file
18
src/Detectors/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# TESTS
|
||||||
|
set( TESTS
|
||||||
|
GDMLSolidTest
|
||||||
|
HierarchicalEncodingTest
|
||||||
|
)
|
||||||
|
|
||||||
|
#set(LIBRARIES
|
||||||
|
# ${PACKAGE_LIBPREFIX}Core
|
||||||
|
# ${PACKAGE_LIBPREFIX}Math
|
||||||
|
# ${PACKAGE_LIBPREFIX}Detectors
|
||||||
|
# ${Boost_SERIALIZATION_LIBRARY}
|
||||||
|
# ${Boost_SIGNALS_LIBRARY}
|
||||||
|
# ${Boost_PROGRAM_OPTIONS_LIBRARY}
|
||||||
|
# ${Eigen_LIBRARY}
|
||||||
|
# ${Geant4_LIBRARIES}
|
||||||
|
# ${ROOT_LIBRARIES}
|
||||||
|
#)
|
||||||
|
uLib_add_tests(${uLib-module})
|
||||||
72
src/Detectors/testing/GDMLSolidTest.cpp
Normal file
72
src/Detectors/testing/GDMLSolidTest.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Geant4/G4RunManager.hh>
|
||||||
|
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
|
||||||
|
#include <Geant4/G4Box.hh>
|
||||||
|
#include <Geant4/G4TessellatedSolid.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include <Geant4/G4PVPlacement.hh>
|
||||||
|
|
||||||
|
#include <Geant4/G4GDMLParser.hh>
|
||||||
|
//#include <Geant4/G4GDMLRead.hh>
|
||||||
|
//#include <Geant4/G4GDMLReadSolids.hh>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Detectors/Solid.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
// G4RunManager* runManager = new G4RunManager;
|
||||||
|
|
||||||
|
G4NistManager *nist = G4NistManager::Instance();
|
||||||
|
G4Material *air = nist->FindOrBuildMaterial("G4_AIR");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
G4Box *box = new G4Box("box",5,5,5);
|
||||||
|
|
||||||
|
G4LogicalVolume box_lv(NULL,NULL,"box test");
|
||||||
|
box_lv.SetSolid(box);
|
||||||
|
box_lv.SetMaterial(air);
|
||||||
|
G4PVPlacement box_pl(0,G4ThreeVector(),&box_lv,"box test",0,0,0);
|
||||||
|
|
||||||
|
G4GDMLParser parser;
|
||||||
|
|
||||||
|
parser.Write("test_out.gdml",&box_lv);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
50
src/Detectors/testing/HierarchicalEncodingTest.cpp
Normal file
50
src/Detectors/testing/HierarchicalEncodingTest.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <Detectors/Hit.h>
|
||||||
|
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(Hierarchical Encoding);
|
||||||
|
|
||||||
|
|
||||||
|
HitRawCode_CMSDrift code;
|
||||||
|
code = Vector4i(5,6,2,8);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Vector4i v = code;
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << code << "\n";
|
||||||
|
std::cout << v << "\n";
|
||||||
|
|
||||||
|
END_TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user