diff --git a/.gitignore b/.gitignore index 6defc076d658fdae44be4f9bffff26dcc854edbc..913334569d20d6c815183ecf4914132677e2141b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ *.swp *.swo - - +# VSCode-related files and folders +build +.vscode +install diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 40be5007b05fe7d2a2bea7d8276e1e0273ca8e6a..3a541275b64b88973e2709ddb7cae7626e6868cf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -350,7 +350,7 @@ ubu-single-gmfsl: stage: step-E needs: ["ubu-single-gmfullsimlight"] variables: - SOURCE_DIR: ${CMAKE_PROJECT_DIR}/FSL + SOURCE_DIR: ${CI_PROJECT_DIR}/FSL script: - CI/compile_GeoModel.sh @@ -359,7 +359,7 @@ ubu-geomodelatlas: stage: step-B needs : ["ubu-gm-all"] variables: - SOURCE_DIR: ${CMAKE_PROJECT_DIR}/GeoModelATLAS + SOURCE_DIR: ${CI_PROJECT_DIR}/GeoModelATLAS script: - git clone https://${EOS_ACCOUNT_USERNAME}:${GEOMODEL_READ_ACCESS}@gitlab.cern.ch/atlas/geomodelatlas/GeoModelATLAS.git - ls -lh @@ -371,7 +371,8 @@ ubu-geomodelatlas: docs-build: stage: step-A rules: - - changes: + - if: '$CI_COMMIT_BRANCH == "main"' # Build documentation only if changes are pushed to main. + changes: - documentation/**/* allow_failure: true timeout: 30 minutes diff --git a/CI/compile_GeoModel.sh b/CI/compile_GeoModel.sh index 864edae958d69eda794d586a9c988b71d41b08c3..6639d2055d7297164937e86e94fffe52c541f274 100755 --- a/CI/compile_GeoModel.sh +++ b/CI/compile_GeoModel.sh @@ -8,7 +8,6 @@ if [ -z "${SOURCE_DIR}" ]; then SOURCE_DIR="${PWD}" fi -echo "${EOS_ACCOUNT_PASSWORD}" | kinit ${EOS_ACCOUNT_USERNAME}@CERN.CH echo "SOURCE_DIR=\"${SOURCE_DIR}\"" echo "BUILD_DIR=\"${CI_PROJECT_DIR}/../build\"" echo "INSTALL_DIR=\"${CI_PROJECT_DIR}/install\"" @@ -34,22 +33,41 @@ echo "export ROOT_INCLUDE_PATH=\"${INSTALL_DIR}/include:${ROOT_INCLUDE_PATH}\"" echo "export PATH=\"${INSTALL_DIR}/bin:${PATH}\"" +echo "cmake ${CMAKE_CONFIG_FLAGS} \ + -DCMAKE_CXX_FLAGS=\"${CMAKE_EXTRA_FLAGS}\" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ + ${SOURCE_DIR}" + cmake ${CMAKE_CONFIG_FLAGS} \ -DCMAKE_CXX_FLAGS="${CMAKE_EXTRA_FLAGS}" \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ ${SOURCE_DIR} -echo "cmake ${CMAKE_CONFIG_FLAGS} \ - -DCMAKE_CXX_FLAGS=\"${CMAKE_EXTRA_FLAGS}\" \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ - ${SOURCE_DIR}" +result=$? +if [ ${result} -ne 0 ];then + echo "Cmake failed" + exit 1 +fi + make -j4 +result=$? +if [ ${result} -ne 0 ];then + echo "Compilation failed" + exit 1 +fi + make install +result=$? +if [ ${result} -ne 0 ];then + echo "Installation failed" + exit 1 +fi + ls -lh ${INSTALL_DIR} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d50d31b59d625d19d4facf2578b140c6d035da2..e747085ca71b79d5a625767de7e31a2eccd5dc6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,16 +29,15 @@ if( APPLE ) endif() # === Externally provided content === -# Set up how the project handle some of its dependenices. Either by ing them +# Set up how the project handle some of its dependenices. Either by picking them # up from the environment, or building them itself. include( SetupEigen3 ) include( SetupXercesC ) include( SetupJSON ) -# Find the dependencies that the project always s up from its environment. +# Find the dependencies that the project always picks up from its environment. find_package( SQLite3 3.7.17 ) - # === Enable testing functionality # NOTE: this must be in the root CMakeLists.txt file # even if the tests are defined in CMake files diff --git a/FSL/CMakeLists.txt b/FSL/CMakeLists.txt index 71e3a7131b3beff559728b327abc4cf44d08b387..ab5f322579032dfcb47ae3f50459b8538740497f 100644 --- a/FSL/CMakeLists.txt +++ b/FSL/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16...3.26) project(fsl VERSION 0.1 LANGUAGES CXX) +file( GLOB MANPAGES man/man1/* ) + if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) # I am top-level project. # Make the root module directory visible to CMake. @@ -96,3 +98,7 @@ install( TARGETS fsl LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) + +install( FILES ${MANPAGES} + DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 + COMPONENT Runtime ) diff --git a/FSL/man/man1/fsl.1 b/FSL/man/man1/fsl.1 new file mode 100644 index 0000000000000000000000000000000000000000..5ff21163c365d0fd6cb79a4e226c67b865419248 --- /dev/null +++ b/FSL/man/man1/fsl.1 @@ -0,0 +1,69 @@ +.\" Manpage for fsl. +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "fsl man page" +.SH NAME +fsl \- user interface for fullSimLight Geant4 simulation. +.SH SYNOPSIS + +fsl [-c JsonConfigFile] + +.SH DESCRIPTION +fsl is a graphical user front-end to fullSimLight. fsl/fullSimLight +runs Geant4 simulation using input files containing 1) event data, +2) geometry data, and 3) configuration data. + +Using the fsl application, one can configure and launch the simulation +interactively through a series of menus. The menus allow to select +the event type and input source, the geometry input, the magnetic +field, and any plugins. A number of example plugins appear in the +menus. For more information on writing custom plugins, see the web +page +.IR geomodel.web.cern.ch \. + +Default configuration files for fsl are typically installed in +/usr/share/fsl on linux systems. + +Users can either run fullSimLight simulation from within fsl or simply +configure the simulation, in which case the configuration may be saved +to a json file. The json file may read back into fsl +for further editing (see the -c option below) or passed to fullSimLight +on the command line. + +From the fsl main window, users may run the gmex geometry explorer, +and/or the gmclash clash detection utility, in addition to fullSimLight. + +.SH OPTIONS + +.TP +.BI \-c \ JsonConfigFile +Open a fullSimLight configuration file for further interactive configuration. + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmcat(1), gmclash(1), gmstatistics(1), gmex(1), fullSimLight(1) + + +.IR "geant4.web.cern.ch" +is the web page for the Geant4 toolkit, the development of which is led +by CERN. + +.IR "pythia.org" +is the web page for the pythia event generator + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite. +. + +.SH AUTHORS +.MT Marilena.Bandieramonte@\:cern\:.ch +Marilena Bandieramonte +.ME , +.MT Raees.Ahmad.Khan@\:cern\:.ch +Raees Khan +.ME +and +.MT boudreau@\:pitt\:.edu +Joe Boudreau +.ME . diff --git a/FullSimLight/CMakeLists.txt b/FullSimLight/CMakeLists.txt index 49fb3b6d21308d0b17a15afd3c187e9661081c2e..ffe89491c964bdba78d20b1f751b0736e431964a 100644 --- a/FullSimLight/CMakeLists.txt +++ b/FullSimLight/CMakeLists.txt @@ -3,6 +3,9 @@ # CMake settings cmake_minimum_required(VERSION 3.16...3.26) + +file( GLOB MANPAGES man/man1/* ) + #Set up the project. Check if we build it with GeoModel or individually if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) # I am top-level project. @@ -222,3 +225,8 @@ install(FILES FullSimLight/FSLSensitiveDetectorPlugin.h FullSimLight/FSLUserActionPlugin.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/FullSimLight COMPONENT Development ) + + +install( FILES ${MANPAGES} + DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 + COMPONENT Runtime ) diff --git a/FullSimLight/Plugins/Examples/UserActionPlugins/DummyUserActionPlugin/DummyUserActionsPlugin/CMakeLists.txt b/FullSimLight/Plugins/Examples/UserActionPlugins/DummyUserActionPlugin/DummyUserActionsPlugin/CMakeLists.txt index 617b3e584f677bbb1b40118bd207ff18a39decd0..0d1fcd9987d03831e61419fe920585cb567c6cbd 100644 --- a/FullSimLight/Plugins/Examples/UserActionPlugins/DummyUserActionPlugin/DummyUserActionsPlugin/CMakeLists.txt +++ b/FullSimLight/Plugins/Examples/UserActionPlugins/DummyUserActionPlugin/DummyUserActionsPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Set up the project. cmake_minimum_required(VERSION 3.16...3.26) project( "DummyUserActionsPlugin" ) @@ -10,7 +10,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) # Make the root module directory visible to CMake. list( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../cmake ) # get global GeoModel version - include( GeoModelATLAS-version ) + include( GeoModelATLAS-version ) # set the project, with the version taken from the GeoModel parent project project( "DummyUserActionsPlugin" VERSION ${GeoModelATLAS_VERSION} LANGUAGES CXX ) # Define color codes for CMake messages @@ -58,9 +58,8 @@ file( GLOB SOURCES src/*.cxx ) add_library( DummyUserActionsPlugin SHARED ${SOURCES} ) target_link_libraries ( DummyUserActionsPlugin PUBLIC FullSimLight ${CMAKE_DL_LIBS} ${Geant4_LIBRARIES} ) -target_include_directories( DummyUserActionsPlugin PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ${FullSimLight_INCLUDE_DIR} ) +target_include_directories( DummyUserActionsPlugin PUBLIC + ${FullSimLight_INCLUDE_DIR} ) source_group( "src" FILES ${SOURCES} ) diff --git a/FullSimLight/man/man1/fullSimLight.1 b/FullSimLight/man/man1/fullSimLight.1 new file mode 100644 index 0000000000000000000000000000000000000000..5ac7e3a1fc51afa004f801a96896cdd0b0d65844 --- /dev/null +++ b/FullSimLight/man/man1/fullSimLight.1 @@ -0,0 +1,112 @@ +.\" Manpage for fullSimLight. +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "fullSimLight man page" +.SH NAME +fullSimLight \- Geant4 simulation from the command line +.SH SYNOPSIS + +fullSimLight [-g geometry-input] [-m macro-file] [-f physics-list-name] [-P pythia-event-type] [-p] [-o] [h] ... + +fullSimLight [-c json-config-file] + +.SH DESCRIPTION +fullSimLight is a command-line interface to the Geant4, the toolkit +for simulation of particle transport and interaction with matter used +in particle physics and medical physics. fullSimLight takes geometry +data from a source specified on the command line. Event data is also +taken from a source specified on the command line or generated +internally using the Pythia event generator. Plugins for User Actions +and Sensitive Detectors can be used to interrupt processing, for +example in order to generate and record hits; by default no output is +generated. fullSimLight is intended as a convenient way to develop, +study, and benchmark Geant4 simulation outside of the context of large +scale applications. + +Default configuration files for fullSimLight are typically installed in +/usr/share/FullSimLight on linux systems. + +The fullSimLight application can be run from the command line, or alternately, +through the graphical user interface fsl (see fsl(1)). By default it runs 10 +events, each consisting of a single electron of energy 10 Gev and produces no +output. + +For more information on writing custom plugins for fullSimLight, see the web +page +.IR geomodel.web.cern.ch \. + +.SH OPTIONS + +.TP +.BI \-c \ json-config-file +Configure the run of fullSimLight through options recorded in a json +configuration file. These files are most easily produced through the +fsl utility (see fsl(1)), a graphical user front-end to fullSimLight. + +.TP +.BI \-g \ geometry-input +Specifies the geometry input. The input may be a GeoModel plugin, an SQLite +file containing a GeoModel description of a geometry, or a GDML file containing +a GDML description of a geometry. + + +.TP +.BI \-m \ macro-file +Override the Macro file used to steer Geant4 (typically installed in /usr/share/FullSimLight) with a custom macro file. + +.TP +.BI \-f \ physics-list-name +Geant4 physics list name. Currently FTP_BERT is default. + +.TP +.BI \-P \ event-type +Use the pythia primary event generator to generate events of specified type, +which may be ttbar (top antitop production), higgs (higgs boson production), +or minbias (minimum bias events), each arising from proton-proton collisions +at 13 TeV center-of-mass energy. + +.TP +.BI \-o +Check for geometry overlaps + +.TP +.BI \-p +Run in performance mode + +.TP +.BI \-h +Prints a help message + + + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmcat(1), gmclash(1), gmstatistics(1), gmex(1), fsl(1) + + +.IR "geant4.web.cern.ch" +is the web page for the Geant4 toolkit, the development of which is led +by CERN. + +.IR "pythia.org" +is the web page for the pythia event generator + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite. +. + +.SH AUTHORS + +.MT Marilena.Bandieramonte@\:cern\:.ch +Marilena Bandieramonte +.ME , +.MT Raees.Ahmad.Khan@\:cern\:.ch +Raees Khan +.ME +and +.MT boudreau@\:pitt\:.edu +Joe Boudreau +.ME . diff --git a/FullSimLight/man/man1/gmclash.1 b/FullSimLight/man/man1/gmclash.1 new file mode 100644 index 0000000000000000000000000000000000000000..82feb0e4e82baf5c6dc91ed247a61421d844815e --- /dev/null +++ b/FullSimLight/man/man1/gmclash.1 @@ -0,0 +1,79 @@ +.\" Manpage for gmclash. +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "gmclash man page" +.SH NAME +gmclash \- detect and report clashes in a geometry model +.SH SYNOPSIS + +gmclash [-g geometry-input] [-r root-volume-name] [-o output-file-name] [-t tolerance] [-n number=random-points] [-v] [h] ... + +.SH DESCRIPTION +gmclash is a command-line utility for detecting and reporting overlaps (or +clashes) in a geometry model. The geometry may be provided +in the form of a GeoModel description in an SQLite file, a GDML file +description, or a GeoModel plugin with .so or .dylib extension. gmclash +reports several abnormal conditions: Mother/Daughter clashes, Sister/Sister +clashes, Encapsulated sister clashes, or invalid solid. The report is +summarized in a .json file; this file may be opened in the ClashPoint system +of the gmex Geometry Explorer (see gmex(1)) and co-displayed with the +geometry. + +gmclash uses the Geant4 toolkit. + +.SH OPTIONS + +.TP +.BI \-o \ output-file-name +Specify OutputFile. Default: gmclash_report.json + +.TP +.BI \-g \ geometry-input +Specifies the geometry input. The input may be a GeoModel plugin, an SQLite +file containing a GeoModel description of a geometry, or a GDML file containing +a GDML description of a geometry. + +.TP +.BI \-r \ root-volume-name +Specify root volume name. If not specified, all volumes are considered. + +.TP +.BI \-t \ tolerance +Set the threshold value for clash reporting. + +.TP +.BI \-n +Specify the number of random points per volume (default: 1000) + +.TP +.BI \-h +Prints a help message + +.TP +.BI \-v +Enable verbose output + + + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmcat(1), gmmasscalc(1), gmstatistics(1), gmex(1), fullSimLight(1), fsl(1) + + +.IR "geant4.web.cern.ch" +is the web page for the Geant4 toolkit, the development of which is led +by CERN. + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite. +. + +.SH AUTHORS + +.MT Marilena.Bandieramonte@\:cern\:.ch +Marilena Bandieramonte +.ME + diff --git a/FullSimLight/man/man1/gmmasscalc.1 b/FullSimLight/man/man1/gmmasscalc.1 new file mode 100644 index 0000000000000000000000000000000000000000..7d9ad0729c78b4c40fc8c560795823b6b70e1602 --- /dev/null +++ b/FullSimLight/man/man1/gmmasscalc.1 @@ -0,0 +1,68 @@ +.\" Manpage for gmmasscalc. +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "gmmasscalc man page" +.SH NAME +gmmasscalc \- detect and report clashes in a geometry model +.SH SYNOPSIS + +gmmasscalc [-g geometry-input] [-p prefix-logical-volume] [-o output-file-name] [-m material-of-interest] [-v] [h] ... + +.SH DESCRIPTION +gmmasscalc is a command-line utility for performing a mass inventory of +a geometry model. The geometry may be provided in the form of a GeoModel description in an SQLite file, a GDML file description, or a GeoModel plugin with .so or .dylib extension. gmmasscalc reports the total inclusive mass, the total inclusive mass, and the apparent weight in air of the geometry. A summary in the form of a .json file is also saved. + +gmmasscalc uses the Geant4 toolkit. + +.SH OPTIONS + +.TP +.BI \-o \ output-file-name +Specify the output file. Default: gmmasscalc_report.json + +.TP +.BI \-g \ geometry-input +Specify the geometry input. The input may be a GeoModel plugin, an SQLite +file containing a GeoModel description of a geometry, or a GDML file containing +a GDML description of a geometry. + +.TP +.BI \-p \ prefix-logical-volume +Specify root volume name. If not specified, all volumes are considered. + +.TP +.BI \-m \ material-of-interest +Restrict the inventory to volumes of specific material composition. + +.TP +.BI \-h +Prints a help message + +.TP +.BI \-v +Enable verbose output + + + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmcat(1), gmclash(1), gmstatistics(1), gmex(1), fullSimLight(1), fsl(1) + + +.IR "geant4.web.cern.ch" +is the web page for the Geant4 toolkit, the development of which is led +by CERN. + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite. +. + +.SH AUTHORS + +.MT Marilena.Bandieramonte@\:cern\:.ch +Marilena Bandieramonte +.ME + diff --git a/GeoModelCore/GeoGenericFunctions/CMakeLists.txt b/GeoModelCore/GeoGenericFunctions/CMakeLists.txt index 67fcfca3f3efcb1e6d8110febf6a0ce9fedd71a0..11e7233e12bf7c60fd900dd89a82df97e2899350 100644 --- a/GeoModelCore/GeoGenericFunctions/CMakeLists.txt +++ b/GeoModelCore/GeoGenericFunctions/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cpp ) @@ -8,7 +8,7 @@ file( GLOB HEADERS GeoGenericFunctions/*.h GeoGenericFunctions/*.icc ) add_library( GeoGenericFunctions SHARED ${HEADERS} ${SOURCES} ) target_include_directories( GeoGenericFunctions PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoGenericFunctions" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoGenericFunctions PROPERTIES diff --git a/GeoModelCore/GeoGenericFunctions/GeoGenericFunctions/Power.h b/GeoModelCore/GeoGenericFunctions/GeoGenericFunctions/Power.h index df68063bd339b6720a1672861e96415388295f2d..a4cfb8bd74b159b9a7264ca04be31d1f6517ff96 100644 --- a/GeoModelCore/GeoGenericFunctions/GeoGenericFunctions/Power.h +++ b/GeoModelCore/GeoGenericFunctions/GeoGenericFunctions/Power.h @@ -48,8 +48,8 @@ namespace GeoGenfun { // It is illegal to assign a fixed constant const Power & operator=(const Power &right); - double _doublePower; // power (as a double) - int _intPower; // power (as an integer) + double _doublePower{}; // power (as a double) + int _intPower{}; // power (as an integer) bool _asInteger; // flag: object constructed with integer argument }; diff --git a/GeoModelCore/GeoGenericFunctions/src/ATan.cpp b/GeoModelCore/GeoGenericFunctions/src/ATan.cpp index 5496e79b2cf3b15e4dd333f8c12702e52a13f107..79a8c7f06194567bb8a2e1c5baf122f04360155e 100755 --- a/GeoModelCore/GeoGenericFunctions/src/ATan.cpp +++ b/GeoModelCore/GeoGenericFunctions/src/ATan.cpp @@ -5,7 +5,7 @@ //==========================================================================// #include "GeoGenericFunctions/ATan.h" #include "GeoGenericFunctions/Square.h" -#include <assert.h> +#include <cassert> #include <cmath> // for atan() namespace GeoGenfun { diff --git a/GeoModelCore/GeoGenericFunctions/src/Parameter.cpp b/GeoModelCore/GeoGenericFunctions/src/Parameter.cpp index 2f186cd2a9c3c4e6741188dcfa76689b19725f7f..f25166e10a8e9b313ab0fb7ceaf00071f16ae903 100644 --- a/GeoModelCore/GeoGenericFunctions/src/Parameter.cpp +++ b/GeoModelCore/GeoGenericFunctions/src/Parameter.cpp @@ -4,13 +4,15 @@ // GNU Lesser Public License v3. // //==========================================================================// +#include <utility> + #include "GeoGenericFunctions/Parameter.h" namespace GeoGenfun { PARAMETER_OBJECT_IMP(Parameter) Parameter::Parameter(std::string name, double value, double lowerLimit, double upperLimit): - _name(name),_value(value),_lowerLimit(lowerLimit),_upperLimit(upperLimit),_sourceParameter(NULL) + _name(std::move(name)),_value(value),_lowerLimit(lowerLimit),_upperLimit(upperLimit),_sourceParameter(NULL) { } diff --git a/GeoModelCore/GeoGenericFunctions/src/Rectangular.cpp b/GeoModelCore/GeoGenericFunctions/src/Rectangular.cpp index 1aa5e43e5763c35c228757c7aa237dbcef5b503a..0d285e3c23418642f7ae2ba2ec62a12f777786ce 100755 --- a/GeoModelCore/GeoGenericFunctions/src/Rectangular.cpp +++ b/GeoModelCore/GeoGenericFunctions/src/Rectangular.cpp @@ -5,7 +5,7 @@ //==========================================================================// #include "GeoGenericFunctions/Rectangular.h" #include "GeoGenericFunctions/FixedConstant.h" -#include <assert.h> +#include <cassert> namespace GeoGenfun { FUNCTION_OBJECT_IMP(Rectangular) diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoDeDuplicator.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoDeDuplicator.h index 904797a43e79b5ae7252714e803ef53c20ea0a83..1c2ce58ee5206e128b7b1efa378de1f45da74395 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoDeDuplicator.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoDeDuplicator.h @@ -14,6 +14,8 @@ #include "GeoModelHelpers/TransformSorter.h" #include <set> +#include <mutex> +#include <thread> /*** * Helper class to deduplicate shapes, volumes and non-alignable transforms in the GeoModel tree that are equivalent * but instantiated in different places. Every time when the cache function is invoked, it's tried to insert the object @@ -71,7 +73,7 @@ class GeoDeDuplicator { using GeoPhysVolPtr = GeoIntrusivePtr<GeoPhysVol>; GeoDeDuplicator() = default; - ~GeoDeDuplicator() = default; + virtual ~GeoDeDuplicator() = default; GeoPhysVolPtr cacheVolume(GeoPhysVolPtr vol) const; GeoTrfPtr makeTransform(const GeoTrf::Transform3D& trf) const; @@ -98,6 +100,8 @@ class GeoDeDuplicator { static TrfSet s_trfStore; static ShapeSet s_shapeStore; + + mutable std::mutex m_mutex{}; }; diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/MaterialManager.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/MaterialManager.h index 3110306f5251c736ff1620293b82049f4bb31b98..ab7a33eeedb8fd731263f111f54ccf2f4da184c9 100755 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/MaterialManager.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/MaterialManager.h @@ -90,8 +90,8 @@ class MaterialManager { ~MaterialFactory(); MaterialFactory(MaterialPtr mat); - void addComponent(ConstMaterialPtr mat, double fraction); - void addComponent(ConstElementPtr ele, double fraction); + void addComponent(const ConstMaterialPtr& mat, double fraction); + void addComponent(const ConstElementPtr& ele, double fraction); const GeoMaterial* get() const; private: diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.h index 6a7a3d2f24b553858b2d8383909145df4e859fd5..cc9e8c91bfef1250ceb5fc0ceef284bf1a2029d6 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.h @@ -28,6 +28,8 @@ namespace GeoStrUtils{ /// @return std::string resolveEnviromentVariables(const std::string_view str); + std::string getEnvVar(const std::string_view key); + /// @brief returns the longest substring that's common between the /// two given strings starting from character 0 std::string_view longestCommonString(const std::string_view firstStr, @@ -61,6 +63,10 @@ namespace GeoStrUtils{ template <class ObjType> std::string chainUp(const std::vector<ObjType>& vector, const std::string_view glue =";"); + /// Function to set the precision of the conversion from double to string + std::string to_string_with_precision(const double a_value, const unsigned n = 16); + + void printStdVectorStrings(const std::vector<std::string>& vec); } #include "GeoModelHelpers/StringUtils.icc" #endif \ No newline at end of file diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc index 04c7d2e17240a08c9b5a732f6e8f8ec35b6c754f..f5c659d8b2fc761016d4c9d3549faf3f302aca32 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc @@ -10,16 +10,16 @@ namespace GeoStrUtils { template <class ObjType> std::string chainUp(const std::vector<ObjType>& vector, const std::string_view glue) { - return chainUp(vector.size(), [&vector](const unsigned int ele)->ObjType { + return chainUp<ObjType>(vector.size(), [&vector](const unsigned int ele)->ObjType { return vector.at(ele); }, glue); } template <class ObjType> std::string chainUp(unsigned int numEles, - const std::function<ObjType(unsigned int)>& func, + const std::function<ObjType(const unsigned int)>& func, const std::string_view glue) { std::stringstream chain{}; - for (unsigned int k =0; k < numEles; ++k) { + for (unsigned int k=0; k < numEles; ++k) { chain<<func(k); if (k + 1 < numEles)chain<<glue; } diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/cloneVolume.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/cloneVolume.h index 944e1a0c4238eb4250e84c897278885906791234..6c31bed641489c18e8b114b0ea0fa46f6160e6fe 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/cloneVolume.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/cloneVolume.h @@ -13,6 +13,6 @@ * @param allowShared: Switch to allow that GeoPhysVols that don't host GeoFullPhysVols are simply moved to the copied * volume and hence become shared objects. */ -PVLink cloneVolume(PVLink volume, bool allowShared = true); +PVLink cloneVolume(const PVLink& volume, bool allowShared = true); #endif diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/getChildNodesWithTrf.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/getChildNodesWithTrf.h index 4e2b2e8e69fbf6a58fb37ce859c420ba564f9289..413646006e68886b5cc40319345182e1acc43f4a 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/getChildNodesWithTrf.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/getChildNodesWithTrf.h @@ -39,14 +39,18 @@ std::vector <GeoChildNodeWithTrf> getChildrenWithRef (PVConstLink physVol, bool summarizeEqualVol = true); /**** @brief Traverses through the GeoVPhysVol tree and returns all sub volumes of this tree.*/ std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol); - - +/*** @brief Traverses thorugh the GeoVPhysVOl tree and returns all subvolumes satisfying an external + * selection. + */ +std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol, + const std::function<bool(const GeoChildNodeWithTrf&)>& selector, + bool summarizeEqualVol = false); /** * Returns whether a volume has fullPhysical volume nodes in * it's children and grand children tree */ -bool hasFullPhysVolInTree(PVConstLink physVol); +bool hasFullPhysVolInTree(const PVConstLink& physVol); diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h new file mode 100644 index 0000000000000000000000000000000000000000..ec6702d989cf90a3375aa5564273617151943619 --- /dev/null +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h @@ -0,0 +1,126 @@ +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +/* + * This header file provides helper C++ functions used in GeoModel IO code. + * + * Author: Riccardo Maria BIANCHI @ CERN + * Created on: April, 2024 + * + */ + + +#ifndef GEOMODELHELPERS_VARIANTHELPERS_H +#define GEOMODELHELPERS_VARIANTHELPERS_H + +#include "GeoModelKernel/throwExcept.h" + +#include <iostream> +#include <string> +#include <vector> +#include <variant> +#include <type_traits> + + +namespace GeoModelHelpers { + + class variantHelper + { + public: + + static void printStdVectorVariants(const std::vector<std::variant<int, long, float, double, std::string>> vec) + { + for (const auto &item : vec) + { + if (std::holds_alternative<int>(item)) + std::cout << std::get<int>(item); + else if (std::holds_alternative<long>(item)) + std::cout << std::get<long>(item); + else if (std::holds_alternative<float>(item)) + std::cout << std::get<float>(item); + else if (std::holds_alternative<double>(item)) + std::cout << std::get<double>(item); + else if (std::holds_alternative<std::string>(item)) + std::cout << std::get<std::string>(item); + + std::cout << ", "; + } + std::cout << std::endl; + } + + static std::string getFromVariant_String(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") + { + std::string_view type{"string"}; + std::string ret; + try + { + ret = std::get<std::string>(record); + } + catch (std::bad_variant_access const &ex) + { + THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); + } + return ret; + } + static int getFromVariant_Int(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") + { + std::string_view type{"int"}; + int ret; + + try + { + ret = std::get<int>(record); + } + catch (std::bad_variant_access const &ex) + { + THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); + + } + return ret; + } + static double getFromVariant_Double(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") + { + std::string_view type{"double"}; + double ret; + try + { + ret = std::get<double>(record); + } + catch (std::bad_variant_access const &ex) + { + THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); + } + return ret; + } + static std::string getFromVariant_Type(const std::variant<int, long, float, double, std::string> &record) + { + std::string type; + if (std::holds_alternative<int>(record)) + { + type = "int"; + } + else if (std::holds_alternative<long>(record)) + { + type = "long"; + } + else if (std::holds_alternative<float>(record)) + { + type = "float"; + } + else if (std::holds_alternative<double>(record)) + { + type = "double"; + } + else if (std::holds_alternative<std::string>(record)) + { + type = "string"; + } else { + type = "UNKOWN"; + } + return type; + } + }; +} // end of namespace + + +#endif + diff --git a/GeoModelCore/GeoModelHelpers/src/FileUtils.cxx b/GeoModelCore/GeoModelHelpers/src/FileUtils.cxx index 2dbf708c8f9bf416ae3b27c69c77c4b9eff6605e..da1f8952ec1639cf67442e1888bed3a9e8980ff4 100644 --- a/GeoModelCore/GeoModelHelpers/src/FileUtils.cxx +++ b/GeoModelCore/GeoModelHelpers/src/FileUtils.cxx @@ -67,10 +67,10 @@ namespace GeoFileUtils { std::cerr<<"copyFile() -- File "<<from<<" does not exist"<<std::endl; return false; } - if (to.find("/") != std::string::npos) { - if (!mkdir(to.substr(0, to.rfind("/")))){ + if (to.find('/') != std::string::npos) { + if (!mkdir(to.substr(0, to.rfind('/')))){ std::cerr<<"copyFile() -- Cannot create directory " - <<to.substr(0, to.rfind("/"))<<"."; + <<to.substr(0, to.rfind('/'))<<"."; } } std::filesystem::copy(from, to, std::filesystem::copy_options::overwrite_existing); diff --git a/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx b/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx index 28415b1e403dfd1e4b2ccf1b8e99293651191bf9..e76926299712016ef55939b44ef68e56762bf580 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx @@ -6,7 +6,9 @@ GeoDeDuplicator::TrfSet GeoDeDuplicator::s_trfStore{}; GeoDeDuplicator::ShapeSet GeoDeDuplicator::s_shapeStore{}; - +namespace { + std::mutex s_mutex{}; +} void GeoDeDuplicator::setShapeDeDuplication(bool enable){ m_deDuplicateShape = enable; @@ -23,15 +25,18 @@ void GeoDeDuplicator::setPhysVolDeDuplication(bool enable) { GeoDeDuplicator::GeoTrfPtr GeoDeDuplicator::makeTransform(const GeoTrf::Transform3D& trf) const { - GeoTrfPtr trfNode{new GeoTransform(trf)}; + GeoTrfPtr trfNode{make_intrusive<GeoTransform>(trf)}; if (!m_deDuplicateTransform) { + std::lock_guard guard{m_mutex}; m_genericCache.push_back(trfNode); return trfNode; } + std::lock_guard guard{s_mutex}; return *s_trfStore.emplace(trfNode).first; } GeoDeDuplicator::GeoPhysVolPtr GeoDeDuplicator::cacheVolume(GeoPhysVolPtr vol) const { + std::lock_guard guard{m_mutex}; if (!m_deDuplicatePhysVol) { m_genericCache.push_back(vol); return vol; @@ -40,6 +45,7 @@ GeoDeDuplicator::GeoPhysVolPtr } GeoDeDuplicator::GeoLogVolPtr GeoDeDuplicator::cacheVolume(GeoLogVolPtr vol) const { + std::lock_guard guard{m_mutex}; if (!m_deDuplicateLogVol) { m_genericCache.push_back(vol); return vol; @@ -49,8 +55,10 @@ GeoDeDuplicator::GeoLogVolPtr GeoDeDuplicator::GeoShapePtr GeoDeDuplicator::cacheShape(GeoShapePtr shape) const { if (!m_deDuplicateShape) { + std::lock_guard guard{m_mutex}; m_genericCache.push_back(shape); return shape; - } + } + std::lock_guard guard{s_mutex}; return *s_shapeStore.insert(shape).first; } diff --git a/GeoModelCore/GeoModelHelpers/src/GeoLogVolSorter.cxx b/GeoModelCore/GeoModelHelpers/src/GeoLogVolSorter.cxx index 381c9896f1641d39b883d86000fbab086f8f2af1..c848f2e6860e24a17701cc50d0dae5eab0f4a0b6 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoLogVolSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoLogVolSorter.cxx @@ -2,7 +2,7 @@ Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelHelpers/GeoLogVolSorter.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelHelpers/GeoShapeSorter.h" bool GeoLogVolSorter::operator()(const GeoLogVol* a, const GeoLogVol* b) const{ diff --git a/GeoModelCore/GeoModelHelpers/src/GeoPhysVolSorter.cxx b/GeoModelCore/GeoModelHelpers/src/GeoPhysVolSorter.cxx index 73ee5dc0fc679565d6f5b954eef6d799f37c8274..c92d64b6b1174dcc948d3f4acb1c47bd43f91342 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoPhysVolSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoPhysVolSorter.cxx @@ -3,12 +3,13 @@ */ #include "GeoModelHelpers/GeoPhysVolSorter.h" #include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelHelpers/TransformSorter.h" #include "GeoModelHelpers/GeoLogVolSorter.h" #include "GeoModelKernel/GeoVolumeCursor.h" #include "GeoModelHelpers/getChildNodesWithTrf.h" -#include "GeoModelHelpers/throwExcept.h" + int GeoPhysVolSorter::compare(const GeoVPhysVol* a, const GeoVPhysVol* b) const { diff --git a/GeoModelCore/GeoModelHelpers/src/GeoShapeSorter.cxx b/GeoModelCore/GeoModelHelpers/src/GeoShapeSorter.cxx index b103d3ef97055e549b87bb5f40bd706f71d2166e..667201f3dc8d02fdf41cd0be0024c6a8591ddcb2 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoShapeSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoShapeSorter.cxx @@ -5,7 +5,7 @@ #include "GeoModelHelpers/TransformSorter.h" #include "GeoModelHelpers/TransformToStringConverter.h" #include "GeoModelHelpers/GeoShapeUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelKernel/Units.h" diff --git a/GeoModelCore/GeoModelHelpers/src/GeoShapeUtils.cxx b/GeoModelCore/GeoModelHelpers/src/GeoShapeUtils.cxx index 73ef9a7622a01cd6c69851a102ed6973ef4da387..e026be00a60e1a4c141aebeca1647fed14ed8515 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoShapeUtils.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoShapeUtils.cxx @@ -3,7 +3,7 @@ */ #include "GeoModelHelpers/GeoShapeUtils.h" #include "GeoModelHelpers/TransformToStringConverter.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" /// Boolean volume shapes #include "GeoModelKernel/GeoShapeUnion.h" @@ -24,6 +24,7 @@ #include "GeoModelKernel/GeoGenericTrap.h" #include "GeoModelKernel/Units.h" +#include "GeoModelHelpers/TransformSorter.h" #include <vector> @@ -51,12 +52,28 @@ unsigned int countComposedShapes(const GeoShape* shape) { } GeoIntrusivePtr<const GeoShape> compressShift(const GeoShape* shift) { - if (shift->typeID() != GeoShapeShift::getClassTypeID()) return GeoIntrusivePtr<const GeoShape>{shift}; - const GeoShapeShift* shapeShift = dynamic_cast<const GeoShapeShift*>(shift); - if (shapeShift->getOp()->typeID() != GeoShapeShift::getClassTypeID()) return GeoIntrusivePtr<const GeoShape>{shift}; + GeoIntrusivePtr<const GeoShape> retPtr{shift}; + if (shift->typeID() != GeoShapeShift::getClassTypeID()) { + return retPtr; + } + + GeoIntrusivePtr<const GeoShapeShift> shapeShift = dynamic_pointer_cast<const GeoShapeShift>(retPtr); + /// If the shape shift is an Identity no need to go go further. + if (!GeoTrf::TransformSorter{}.compare(shapeShift->getX(), GeoTrf::Transform3D::Identity())) { + retPtr = shapeShift->getOp(); + } + if (shapeShift->getOp()->typeID() != GeoShapeShift::getClassTypeID()) { + return retPtr; + } GeoIntrusivePtr<const GeoShape> subShape{compressShift(shapeShift->getOp())}; - const GeoShapeShift* subShift = dynamic_cast<const GeoShapeShift*>(subShape.get()); - return GeoIntrusivePtr<const GeoShape>{new GeoShapeShift(subShift->getOp(), subShift->getX() * shapeShift->getX())}; + + GeoIntrusivePtr<const GeoShapeShift> subShift = dynamic_pointer_cast<const GeoShapeShift>(subShape); + /// Check that the GeoShape shift is actually neccesary. If not bail out + GeoTrf::Transform3D shiftTrf{subShift->getX() * shapeShift->getX()}; + if (!GeoTrf::TransformSorter{}.compare(shiftTrf, GeoTrf::Transform3D::Identity())) { + return GeoIntrusivePtr<const GeoShape>{subShift->getOp()}; + } + return make_intrusive<GeoShapeShift>(subShift->getOp(), std::move(shiftTrf)); } std::vector<const GeoShape*> getBooleanComponents(const GeoShape* booleanShape) { std::pair<const GeoShape*, const GeoShape*> operands = getOps(booleanShape); diff --git a/GeoModelCore/GeoModelHelpers/src/MaterialManager.cxx b/GeoModelCore/GeoModelHelpers/src/MaterialManager.cxx index 2b292e451bdc621f9395e8ace14d549b13d55e3d..f9b996e2364769588d62601bb6a037a5d5817fc0 100644 --- a/GeoModelCore/GeoModelHelpers/src/MaterialManager.cxx +++ b/GeoModelCore/GeoModelHelpers/src/MaterialManager.cxx @@ -10,13 +10,14 @@ #include "GeoModelKernel/GeoMaterial.h" #include "GeoModelKernel/Units.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelHelpers/StringUtils.h" +#include <cstdio> #include <cstdlib> #include <iomanip> -#include <stdio.h> #include <iostream> +#include <utility> namespace { std::string replaceDColon(const std::string& name) { @@ -46,16 +47,16 @@ MaterialManager::MaterialFactory::~MaterialFactory() { } MaterialManager::MaterialFactory::MaterialFactory(MaterialPtr mat): - m_material{mat} { + m_material{std::move(mat)} { } -void MaterialManager::MaterialFactory::addComponent(ConstMaterialPtr mat, double fraction) { +void MaterialManager::MaterialFactory::addComponent(const ConstMaterialPtr& mat, double fraction) { for (unsigned int ele = 0 ; ele < mat->getNumElements(); ++ele) { ConstElementPtr elePtr{mat->getElement(ele)}; addComponent(elePtr, mat->getFraction(ele) * fraction); } } -void MaterialManager::MaterialFactory::addComponent(ConstElementPtr ele, +void MaterialManager::MaterialFactory::addComponent(const ConstElementPtr& ele, double fraction) { m_components.emplace_back(std::make_pair(ele, fraction)); m_totFraction += fraction; diff --git a/GeoModelCore/GeoModelHelpers/src/StringUtils.cxx b/GeoModelCore/GeoModelHelpers/src/StringUtils.cxx index 557a33534a25fcb0bde40271ed1caf9e564a11f6..02965abcf6cd99814d4f149b4efff790b1a2e67f 100644 --- a/GeoModelCore/GeoModelHelpers/src/StringUtils.cxx +++ b/GeoModelCore/GeoModelHelpers/src/StringUtils.cxx @@ -2,7 +2,7 @@ Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelHelpers/StringUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include <limits> #include <array> #include <functional> @@ -45,13 +45,20 @@ namespace GeoStrUtils { std::string str{inStr}; while (str.find("${") != std::string::npos) { - std::string varName = str.substr(str.find("${") + 2, str.find("}") - str.find("${") - 2); + std::string varName = str.substr(str.find("${") + 2, str.find('}') - str.find("${") - 2); std::string envVar{std::getenv(varName.data()) ? std::getenv(varName.data()) : ""}; - str = replaceExpInString(str, str.substr(str.find("${"), str.find("}") - str.find("${") + 1), envVar); + str = replaceExpInString(str, str.substr(str.find("${"), str.find('}') - str.find("${") + 1), envVar); } return str; } - + + std::string getEnvVar(const std::string_view key) + { + std::string keyStr{key}; + char *val = std::getenv(keyStr.c_str()); + return val == NULL ? std::string{} : std::string(val); + } + std::vector<std::string> tokenize(const std::string& str, std::string_view delimiters) { @@ -136,4 +143,22 @@ namespace GeoStrUtils { convertToNumber(str, result); return result; } + + std::string to_string_with_precision(const double a_value, const unsigned n) + { + std::ostringstream out; + out.precision(n); + out << std::fixed << a_value; + return out.str(); + } + + void printStdVectorStrings(const std::vector<std::string>& vec) + { + for (const auto &str : vec) + { + std::cout << str << " "; + } + std::cout << std::endl; + return; + } } diff --git a/GeoModelCore/GeoModelHelpers/src/TransformSorter.cxx b/GeoModelCore/GeoModelHelpers/src/TransformSorter.cxx index bf77383bf09c1bd4e74fff98d660dbab4c28dca0..b5cf8ec4cedff0833775bb83c7503f42ff5cb10a 100644 --- a/GeoModelCore/GeoModelHelpers/src/TransformSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/src/TransformSorter.cxx @@ -1,9 +1,10 @@ /* Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ +#include "GeoModelKernel/throwExcept.h" #include "GeoModelHelpers/TransformSorter.h" #include "GeoModelKernel/GeoAlignableTransform.h" -#include "GeoModelHelpers/throwExcept.h" + namespace GeoTrf { bool TransformSorter::operator()(const std::unique_ptr<Transform3D>& a, diff --git a/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx b/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx index a49048f21b166281c0170bf596278c01a657a5d8..63f625ae5f5685ae67207a6bc3dc52291af61474 100644 --- a/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx +++ b/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx @@ -7,14 +7,14 @@ #include "GeoModelKernel/GeoFullPhysVol.h" #include "GeoModelKernel/GeoPhysVol.h" -PVLink cloneVolume(PVLink volume, +PVLink cloneVolume(const PVLink& volume, bool allowShared) { PVLink newVolume{volume}; if (!allowShared || hasFullPhysVolInTree(volume)) { if (typeid(*volume) == typeid(GeoPhysVol)) { - newVolume = new GeoPhysVol(volume->getLogVol()); + newVolume = make_intrusive<GeoPhysVol>(volume->getLogVol()); } else if (typeid(*volume) == typeid(GeoFullPhysVol)) { - newVolume = new GeoFullPhysVol(volume->getLogVol()); + newVolume = make_intrusive<GeoFullPhysVol>(volume->getLogVol()); } for (unsigned int ch = 0; ch < volume->getNChildNodes(); ++ch){ const GeoGraphNode* node = (*volume->getChildNode(ch)); diff --git a/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx b/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx index 3aa9dd8eb97d1db64c0bb4824ca4269b10b923ba..cdfdce072f7fa3e53539f1631d22b9c2980790e1 100644 --- a/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx +++ b/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx @@ -1,6 +1,8 @@ /* Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ +#include <utility> + #include "GeoModelHelpers/getChildNodesWithTrf.h" #include "GeoModelHelpers/GeoPhysVolSorter.h" @@ -34,7 +36,7 @@ std::vector <GeoChildNodeWithTrf> getChildrenWithRef(PVConstLink physVol, static const GeoTrf::TransformSorter transSort{}; - GeoVolumeCursor cursor{physVol}; + GeoVolumeCursor cursor{std::move(physVol)}; GeoTrf::Transform3D lastNodeTrf{GeoTrf::Transform3D::Identity()}; while (!cursor.atEnd()) { @@ -64,14 +66,16 @@ std::vector <GeoChildNodeWithTrf> getChildrenWithRef(PVConstLink physVol, } return children; } - -std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol) { - std::vector<GeoChildNodeWithTrf> children{getChildrenWithRef(physVol, false)}, subVolumes{}; +std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol, + const std::function<bool(const GeoChildNodeWithTrf&)>& selector, + bool summarizeEqualVol) { + std::vector<GeoChildNodeWithTrf> children{getChildrenWithRef(std::move(physVol), summarizeEqualVol)}, subVolumes{}; subVolumes.reserve(children.size()); for (const GeoChildNodeWithTrf& child : children) { - subVolumes.push_back(child); - std::vector<GeoChildNodeWithTrf> grandChildren = getAllSubVolumes(child.volume); - subVolumes.reserve(grandChildren.size() + subVolumes.size()); + std::vector<GeoChildNodeWithTrf> grandChildren = getAllSubVolumes(child.volume, selector, summarizeEqualVol); + if (selector(child)) subVolumes.push_back(child); + + subVolumes.reserve(grandChildren.size() + subVolumes.capacity()); std::transform(std::make_move_iterator(grandChildren.begin()), std::make_move_iterator(grandChildren.end()), std::back_inserter(subVolumes), [&child](GeoChildNodeWithTrf&& grandChild){ @@ -80,9 +84,16 @@ std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol) { }); } return subVolumes; + } + + +std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol) { + return getAllSubVolumes(std::move(physVol), + [](const GeoChildNodeWithTrf& child){ + return true;}, false); } -bool hasFullPhysVolInTree(PVConstLink physVol) { +bool hasFullPhysVolInTree(const PVConstLink& physVol) { if (typeid(*physVol) == typeid(GeoFullPhysVol) || typeid(*physVol) == typeid(GeoVFullPhysVol)){ return true; diff --git a/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx b/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx index a3ef854fa10e496982bed95593981acf4fde0e71..4b1d3e6bfb3db7df8b6f71829b956bff861fe044 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx @@ -1,12 +1,11 @@ // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration -#include <GeoModelKernel/GeoFullPhysVol.h> -#include <GeoModelKernel/GeoTransform.h> -#include <GeoModelKernel/GeoPhysVol.h> -#include <GeoModelKernel/GeoFullPhysVol.h> #include <GeoModelKernel/GeoBox.h> +#include <GeoModelKernel/GeoFullPhysVol.h> #include <GeoModelKernel/GeoIdentifierTag.h> +#include <GeoModelKernel/GeoPhysVol.h> +#include <GeoModelKernel/GeoTransform.h> #include <GeoModelHelpers/defineWorld.h> #include <GeoModelHelpers/TransformSorter.h> diff --git a/GeoModelCore/GeoModelHelpers/tests/testGeoShapeSet.cxx b/GeoModelCore/GeoModelHelpers/tests/testGeoShapeSet.cxx index 108c93c694aa4020817318037bef59f49a6d3527..680ce6f979c5922b5477057c233c6658c8377e1d 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testGeoShapeSet.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testGeoShapeSet.cxx @@ -11,7 +11,7 @@ #include "GeoModelKernel/GeoShapeShift.h" -#include <stdlib.h> +#include <cstdlib> #include <iostream> template<class T, typename... args> bool insertVolume(const bool printFailure, diff --git a/GeoModelCore/GeoModelHelpers/tests/testPhysVolSorter.cxx b/GeoModelCore/GeoModelHelpers/tests/testPhysVolSorter.cxx index e1d8cf03f871b9729f884e85be674f8495f1e968..095ff482e334df00735d250457626ca0c8c849c3 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testPhysVolSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testPhysVolSorter.cxx @@ -3,13 +3,13 @@ */ #include "GeoModelHelpers/GeoPhysVolSorter.h" +#include "GeoModelHelpers/TransformToStringConverter.h" #include "GeoModelHelpers/defineWorld.h" #include "GeoModelKernel/GeoAlignableTransform.h" -#include "GeoModelHelpers/TransformToStringConverter.h" -#include "GeoModelKernel/GeoFullPhysVol.h" #include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoFullPhysVol.h" #include "GeoModelKernel/Units.h" -#include <stdlib.h> +#include <cstdlib> #include <iostream> #include <set> @@ -20,14 +20,14 @@ int main() { GeoIntrusivePtr<GeoPhysVol> world{createGeoWorld()}; const GeoMaterial* air = world->getLogVol()->getMaterial(); - GeoIntrusivePtr<GeoBox> externalBox{new GeoBox(500.,500., 500.)}; - GeoIntrusivePtr<GeoBox> internalBox{new GeoBox(100.,100., 100.)}; + GeoIntrusivePtr<GeoBox> externalBox{make_intrusive<GeoBox>(500.,500., 500.)}; + GeoIntrusivePtr<GeoBox> internalBox{make_intrusive<GeoBox>(100.,100., 100.)}; auto makeBox = [&](bool bigOne) { - return PVLink(new GeoPhysVol(new GeoLogVol("TestVolume", bigOne ? externalBox : internalBox, air))); + return make_intrusive<GeoPhysVol>(make_intrusive<GeoLogVol>("TestVolume", bigOne ? externalBox : internalBox, air)); }; auto makeFullBox = [&](bool bigOne) { - return PVLink(new GeoFullPhysVol(new GeoLogVol("TestFullPhysVol", bigOne ? externalBox : internalBox, air))); + return make_intrusive<GeoFullPhysVol>(make_intrusive<GeoLogVol>("TestFullPhysVol", bigOne ? externalBox : internalBox, air)); }; /// PVLink extVolume = makeBox(true); @@ -54,7 +54,7 @@ int main() { return EXIT_FAILURE; } extVolume = makeBox(true); - extVolume->add(new GeoTransform(GeoTrf::TranslateX3D(50.))); + extVolume->add(make_intrusive<GeoTransform>(GeoTrf::TranslateX3D(50.))); extVolume->add(makeBox(false)); if (!physVolSet.insert(extVolume).second) { std::cerr<<"testPhysVolSorter() "<<__LINE__<<" A box with a displaced box inside is not the same as box ception "<<std::endl; diff --git a/GeoModelCore/GeoModelHelpers/tests/testStringUtils.cxx b/GeoModelCore/GeoModelHelpers/tests/testStringUtils.cxx index 1fa425cc78555ca9c8e7ff0a46207365e5ecbc15..cbcbf453190c81e8c6f44c4b13154c311577d30c 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testStringUtils.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testStringUtils.cxx @@ -3,16 +3,11 @@ */ #include "GeoModelHelpers/StringUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" +#include <cstdlib> #include <iostream> -#include <stdlib.h> using namespace GeoStrUtils; -namespace { - std::string getEnvVar(const std::string& varName){ - return std::getenv(varName.c_str()) ? std::string{std::getenv(varName.c_str())} : std::string{}; - } -} int main() { if (resolveEnviromentVariables("${PWD}") != getEnvVar("PWD")) { diff --git a/GeoModelCore/GeoModelHelpers/tests/testTransformSorter.cxx b/GeoModelCore/GeoModelHelpers/tests/testTransformSorter.cxx index 064b6d4fbe056bf7ec01df5e82ab195f3501af5b..155d3bb44ed51ae5e3150ad66577c44dad174e45 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testTransformSorter.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testTransformSorter.cxx @@ -3,10 +3,10 @@ */ #include "GeoModelHelpers/TransformSorter.h" -#include "GeoModelKernel/GeoAlignableTransform.h" #include "GeoModelHelpers/TransformToStringConverter.h" +#include "GeoModelKernel/GeoAlignableTransform.h" #include "GeoModelKernel/Units.h" -#include <stdlib.h> +#include <cstdlib> #include <iostream> #include <set> diff --git a/GeoModelCore/GeoModelKernel/CMakeLists.txt b/GeoModelCore/GeoModelKernel/CMakeLists.txt index 11b72cbb7b2caec71e275d075a2ff33e55d67531..f4242540e787a29c5d5b8b866b3de1079a479fbb 100644 --- a/GeoModelCore/GeoModelKernel/CMakeLists.txt +++ b/GeoModelCore/GeoModelKernel/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -10,7 +10,7 @@ target_link_libraries( GeoModelKernel PUBLIC Eigen3::Eigen GeoGenericFunctions ${CMAKE_DL_LIBS} ) target_include_directories( GeoModelKernel PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelKernel" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelKernel PROPERTIES @@ -51,15 +51,14 @@ install( FILES ${HEADERS} foreach(_exeFile ${files}) get_filename_component(_theExec ${_exeFile} NAME_WE) get_filename_component(_theLoc ${_exeFile} DIRECTORY) - + if(${_theLoc} MATCHES "DoNotBuild") continue() - endif() - + endif() + add_executable(${_theExec} ${_exeFile}) target_link_libraries( ${_theExec} GeoModelKernel) add_test(NAME ${_theExec} COMMAND ${_theExec}) endforeach() - diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/CellBinning.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/CellBinning.h index 966ffdd6db8cc85bd4bc177a67e2821f4d99629c..1446c28babc57f12d887480fb139cc24431e06fb 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/CellBinning.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/CellBinning.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_CELLBINNING_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/CellPartitioning.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/CellPartitioning.h index 96ef57366da38c940aebe25ae14e8e86c423ace9..54a4e38964c9e8816bfa1d2b348d210d44ddd06a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/CellPartitioning.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/CellPartitioning.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_CELLPARTITIONING_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessSurfaceAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessSurfaceAction.h new file mode 100644 index 0000000000000000000000000000000000000000..00f68f895abd05c54af129c8506071ae79bb0530 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessSurfaceAction.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef GeoAccessSurfaceAction_h +#define GeoAccessSurfaceAction_h 1 + +#include "GeoModelKernel/GeoNodeAction.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include <vector> + +class GeoVSurface; +class GeoVPhysVol; +class GeoTransform; +class GeoVAlignmentStore; +using VSConstLink = GeoIntrusivePtr<const GeoVSurface>; +/** + * @class GeoAccessSurfaceAction + * + * @brief Accesses virtual surfaces, returning the ith surface and also its transformation relative to the parent. + */ + +class GeoAccessSurfaceAction final : public GeoNodeAction +{ + public: + GeoAccessSurfaceAction (unsigned int Index, const GeoVAlignmentStore* store); + virtual ~GeoAccessSurfaceAction() override; + + /// Handles a Transform. + virtual void handleTransform (const GeoTransform *xform) override; + + /// Handles a physical volume, to refresh the pendingTransformlist + virtual void handlePhysVol (const GeoPhysVol *vol) override; + + /// Handles a full physical volume, to refresh the pendingTransformlist + virtual void handleFullPhysVol (const GeoFullPhysVol *vol) override; + + /// Handles a virtual surface. + virtual void handleVSurface (const GeoVSurface *surface) override; + + /// Returns the selected virtual surface or nullptr if not found. + VSConstLink getSurface () const; + + /// Returns the transformation to the surface. + const GeoTrf::Transform3D & getTransform () const; + + /// Returns the default ransformation to the surface. + const GeoTrf::Transform3D & getDefTransform () const; + + private: + + GeoAccessSurfaceAction(const GeoAccessSurfaceAction &right); + GeoAccessSurfaceAction & operator=(const GeoAccessSurfaceAction &right); + + /// Returns a pointer to the ith virtual surface under this one. + VSConstLink m_surface{}; + + /// The transformation to the ith surface. + GeoTrf::Transform3D m_transform{GeoTrf::Transform3D::Identity()}; + + /// The default transformation to the ith surface. + GeoTrf::Transform3D m_defTransform{GeoTrf::Transform3D::Identity()}; + + /// The surface which we are interested in seeking. + unsigned int m_index{0}; + + /// The surface which we are interested in seeking. + unsigned int m_counter{0}; + + /// List of Pending Transformations. + std::vector<const GeoTransform *> m_pendingTransformList{}; + + const GeoVAlignmentStore* m_alignStore{nullptr}; +}; + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolAndSTAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolAndSTAction.h index da372256e53b7fbe1d5bcf9494a35010fd53eab6..3789197b83968d8f241c7bf06b0596cfca4b4d48 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolAndSTAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolAndSTAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOACCESSVOLANDSTACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolumeAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolumeAction.h index 64e9b24a9d591a9b45bd85c3367d6d766ddffb2e..2399f4c4ad1d49c7448e536ec4616f1e480f54f1 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolumeAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAccessVolumeAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GeoAccessVolumeAction_h @@ -9,6 +9,7 @@ #include "GeoModelKernel/GeoDefinitions.h" #include <vector> +class GeoVSurface; class GeoVPhysVol; class GeoTransform; class GeoVAlignmentStore; @@ -35,6 +36,9 @@ class GeoAccessVolumeAction final : public GeoNodeAction /// Handles a physical volume. virtual void handleFullPhysVol (const GeoFullPhysVol *vol) override; + /// Handles a virtual surface, to refresh the pendingTransformlist + virtual void handleVSurface (const GeoVSurface *surface) override; + /// Returns the selected physical volume or nullptr if not found. PVConstLink getVolume () const; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAlignableTransform.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAlignableTransform.h index b7c85ebc50eb8a5c3ba5748536ab3a21638e6be2..0e498a406492aa62ce011873b884560881f1c58e 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAlignableTransform.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAlignableTransform.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOALIGNABLETRANSFORM_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h new file mode 100644 index 0000000000000000000000000000000000000000..7dc31d3dc5e8e89b4be556755f90111b3d2f2a67 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h @@ -0,0 +1,94 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * + * Created on: July, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + +#ifndef GEOMODELKERNAL_GEOANNULUSSURFACE_H +#define GEOMODELKERNAL_GEOANNULUSSURFACE_H + +#include "GeoModelKernel/GeoVSurfaceShape.h" + +class GeoAnnulusSurface : public GeoVSurfaceShape +{ + public: + + // Constructor for a GeoAnnulusSurface + // The default position of the cyllinder center is at (0,0,0) + // Ox, Oy: the deviation of the focusing point from the default position + // radius_in: the inner radius of the annulus + // radius_out: the outer radius of the annulus + // phi: the span angle of the deviated circular sector, when phi = 2*PI, it is an annulus + GeoAnnulusSurface(double Ox, double Oy, double radius_in, double radius_out, double phi); + + // Returns the area of the annulus + // Proposed method: using Monte Carlo method to calculate the area + // it would need isInside() method to check if a point is inside the annulus + //double area() const; + + // Returns Ox + double getOx() const + { + return m_Ox; + } + + // Returns Oy + double getOy() const + { + return m_Oy; + } + + // Returns the inner radius of the annulus + double getRadiusIn() const + { + return m_radius_in; + } + + // Returns the outer radius of the annulus + double getRadiusOut() const + { + return m_radius_out; + } + + // Returns the span angle of the deviated circular sector + double getPhi() const + { + return m_phi; + } + + // Determine if a point is inside the annulus + // x, y: the coordinates of the point + // coming soon! + //bool isInside(double x, double y) const; + + virtual const std::string & type() const{ + return s_classType; + } + + virtual ShapeType typeID() const{ + return s_classTypeID; + } + + void exec (GeoShapeAction *action) const override final; + + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; + + protected: + + virtual ~GeoAnnulusSurface() = default; + static const std::string s_classType; + static const ShapeType s_classTypeID; + + double m_Ox{0.0}; + double m_Oy{0.0}; + double m_radius_in{0.0}; + double m_radius_out{0.1}; + double m_phi{2*M_PI}; +}; + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoBox.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoBox.h index 3542adc221cea86cfb8b9648a584b13c22b2b431..78c30c263ec2485371c8814670fd63882c2669e4 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoBox.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoBox.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOBOX_H @@ -14,7 +14,7 @@ class GeoBox : public GeoShape GeoBox (double XHalfLength, double YHalfLength, double ZHalfLength); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -33,7 +33,12 @@ class GeoBox : public GeoShape return getClassTypeID(); } - // Executes a GeoShapeAction + // Returns true as BOX is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + + // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const; // For type identification @@ -61,7 +66,6 @@ class GeoBox : public GeoShape return m_zHalfLength; } - protected: virtual ~GeoBox() = default; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoClearAbsPosAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoClearAbsPosAction.h index e079a39b20e7519ecfca7016d184b5311cd39738..5dce280d01bf5333d33aecbf0fb0aa3d3bc43465 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoClearAbsPosAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoClearAbsPosAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCons.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCons.h index b7fbf473caa3a3bb585142da5acf3b9efbb8e2be..28a13ef9fd15ead87e5a60da0dba315aaf4b38ad 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCons.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCons.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOCONS_H @@ -12,7 +12,7 @@ class GeoCons : public GeoShape { GeoCons (double RMin1, double RMin2, double RMax1, double RMax2, double DZ, double SPhi, double DPhi); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -31,6 +31,11 @@ class GeoCons : public GeoShape { return getClassTypeID(); } + // Returns false as CONS is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; @@ -63,8 +68,6 @@ protected: virtual ~GeoCons() = default; private: - - static const std::string s_classType; static const ShapeType s_classTypeID; @@ -77,5 +80,4 @@ protected: double m_dPhi{0.}; }; - #endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountSurfaceAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountSurfaceAction.h new file mode 100644 index 0000000000000000000000000000000000000000..b56a9c676c513a032124b7a7c18eec37d4d078d5 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountSurfaceAction.h @@ -0,0 +1,31 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef GEOMODELKERNEL_GEOCOUNTSURFACEACTION_H +#define GEOMODELKERNEL_GEOCOUNTSURFACEACTION_H + +#include "GeoModelKernel/GeoNodeAction.h" + +class GeoCountSurfaceAction final: public GeoNodeAction +{ + public: + GeoCountSurfaceAction (); + virtual ~GeoCountSurfaceAction(); + + // Handles a virtual surface. + virtual void handleVSurface (const GeoVSurface *) override; + + // The virtual surface count. + unsigned int getCount () const; + + + unsigned int m_count{0}; +}; + +inline unsigned int GeoCountSurfaceAction::getCount () const +{ + return m_count; +} + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h index 916670735230ace9fbbd258d251b9d2b10e8301e..34cfc02c7e915c15540237e2ac4541f3bad6db88 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOCOUNTVOLACTION_H @@ -21,7 +21,10 @@ class GeoCountVolAction : public GeoNodeAction // Handles a Serial Transformer virtual void handleSerialTransformer (const GeoSerialTransformer *st); - + + // Handles a virtual surface. + virtual void handleVSurface (const GeoVSurface *) override; + // The volume count. unsigned int getCount () const; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAndSTAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAndSTAction.h index 7d49c5f1bc191048c85172bc6d5a8ce1c20d8243..71abc4a43e70d2ec0f6a1a387a89b4c7f4e80ac2 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAndSTAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAndSTAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOCOUNTVOLANDSTACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h index ceee9b8184e058a3f3a4ea710af0a78b0f5d562a..95d0ad3753992cf18cc788b3e382e2f2f3d46e36 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOCUTVOLACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDefinitions.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDefinitions.h index cbc81fd9d4fb9ac7424c10951aee21e9a28e30f0..d1861a649cf047642cd5fff069252c009589503d 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDefinitions.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDefinitions.h @@ -197,6 +197,8 @@ namespace GeoTrf { /// @brief Simple comparison returning -1, 0, 1 int compare(const EulerAngles& other) const; operator bool() const; + /// @brief Returns the set of Euler angles to invert the rotation + EulerAngles inverse() const; }; @@ -218,6 +220,8 @@ namespace GeoTrf { bool operator<(const CoordEulerAngles& other) const; /// @brief Simple comparison returning -1, 0, 1 int compare(const CoordEulerAngles& other) const; + /// @brief Returns the set of CoordEulerAngles to invert the Rotation + CoordEulerAngles inverse() const; operator bool() const; }; @@ -250,9 +254,10 @@ namespace GeoTrf { class GeoTransformRT : public Transform3D { public: - GeoTransformRT(const GeoRotation& rot, const Vector3D& trans) - : Transform3D(Translation3D(trans)*Transform3D(AngleAxis3D(rot))) - {} + GeoTransformRT(const GeoRotation& rot, const Vector3D& trans); + GeoTransformRT(const EulerAngles& angles, const Vector3D& trans); + GeoTransformRT(const CoordEulerAngles&angles, const Vector3D& trans); + virtual ~GeoTransformRT() = default; }; } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h new file mode 100644 index 0000000000000000000000000000000000000000..bcf1b62cd6a63083768e28610e05b4aa76b9d9d3 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * + * Created on: Oct, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + + +#ifndef GEOMODELKERNEL_GEODIAMONDSURFACE_H +#define GEOMODELKERNEL_GEODIAMONDSURFACE_H + +#include "GeoModelKernel/GeoVSurfaceShape.h" + +class GeoDiamondSurface : public GeoVSurfaceShape +{ + public: + // Constructor for the Trapezoid Surface + GeoDiamondSurface (double X_bottom_half, double X_mid_half, double X_top_half, double Y_bottom_half, double Y_top_half); + + // Returns the area of the surface + double area() const; + + // Bottom Half Length in the x direction + double getXbottomHalf () const + { + return m_XbottomHalf; + } + + // Midddle Half Length in the x direction + double getXmidHalf () const + { + return m_XmidHalf; + } + + // Top Half Length in the x direction + double getXtopHalf () const + { + return m_XtopHalf; + } + + // Bottom Half Length in the y direction + double getYbottomHalf () const + { + return m_YbottomHalf; + } + + // Top Half Length in the y direction + double getYtopHalf () const + { + return m_YtopHalf; + } + + virtual const std::string & type () const{ + return s_classType; + } + + virtual ShapeType typeID () const{ + return s_classTypeID; + } + + // Executes a GeoShapeAction + void exec (GeoShapeAction *action) const override final; + + // Is the point (x,y,z) inside the shape? + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; + + + protected: + virtual ~GeoDiamondSurface() = default; + + static const std::string s_classType; + static const ShapeType s_classTypeID; + double m_XbottomHalf{0.}; + double m_XmidHalf{0.}; + double m_XtopHalf{0.}; + double m_YbottomHalf{0.}; + double m_YtopHalf{0.}; +}; + + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoElement.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoElement.h index 9eee6bc9e72c5b7be861f61832e7b24d416f2fd0..f8cfeee6074f16e4d63bb8471d08c393247eb712 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoElement.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoElement.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOELEMENT_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoEllipticalTube.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoEllipticalTube.h index a36c03120eb393a9191be9eab739c460e5c6c89c..65f9128e8aee39dc72c0d46f659237cb56332e09 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoEllipticalTube.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoEllipticalTube.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOELLIPTICALTUBE_H @@ -20,7 +20,7 @@ class GeoEllipticalTube : public GeoShape { GeoEllipticalTube(double XHalfLength, double YHalfLength, double ZHalfLength); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -39,6 +39,11 @@ class GeoEllipticalTube : public GeoShape { return getClassTypeID(); } + // Returns false as ELLIPTICAL TUBE is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const; @@ -71,7 +76,6 @@ class GeoEllipticalTube : public GeoShape { virtual ~GeoEllipticalTube() = default; private: - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFacet.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFacet.h index d73cb975fb47f7e5f9b33f320f504d51469ce816..14e3a3d8c37eec4e1d08a954daf4086743f373d5 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFacet.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFacet.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOFACET_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h index e1fafcec313716bfb847a58740c65a2d3e11e910..3d3f9aa92f92e42f6b446dc8d5e5e665e47955e4 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOFULLPHYSVOL_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGenericTrap.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGenericTrap.h index edbc1c077db9d52c587f421407eaedc17c32f42e..167c4cb1b1a8420d72c69f4f241377fabbfda4a3 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGenericTrap.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGenericTrap.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOGENERICTRAP_H @@ -17,7 +17,7 @@ class GeoGenericTrap : public GeoShape { GeoGenericTrap(double ZHalfLength, const GeoGenericTrapVertices& Vertices); // Returns the volume of the shape, for mass inventory. - virtual double volume() const; + virtual double volume(int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -36,6 +36,11 @@ class GeoGenericTrap : public GeoShape { return getClassTypeID(); } + // Returns false as GENERIC TRAP is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // For type identification. static const std::string& getClassType() { return s_classType; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGeometryPluginLoader.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGeometryPluginLoader.h index 73b0b93bd0152c9681c1be013e5f4d590b4e6af3..d929f9db1b7148b8953a88819089afc8e35ee3ba 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGeometryPluginLoader.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGeometryPluginLoader.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOGEOMETRYPLUGINLOADER_H_ diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGraphNode.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGraphNode.h index 1f8a2ae52ea942e9690b256b33f87895e40bd4a1..ace8fd4ef7939530a24849054a1a31cca6d9d01a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGraphNode.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoGraphNode.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOGRAPHNODE_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIdentifierTag.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIdentifierTag.h index f7b37647e537581acb829e35e4223344c864fdbe..a3eb36847308d65c07ed18f7718361f8d1507ba2 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIdentifierTag.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIdentifierTag.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOIDENTIFIERTAG_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h index dcd1c028c588918e7eaeb2e2bb73392e16f8e462..73910a75b68096afa927ae6e63d25148876c0014 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GeoIntrusivePtr_H #define GEOMODELKERNEL_GeoIntrusivePtr_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h index 7885deaad6f984ed3f19b9be46a0a7caa867df94..301a76d229c953f5b04c42d99968d870b44cd53f 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOLOGVOL_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoMaterial.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoMaterial.h index faa40989f58a1418f0d1631c9909c31275aa985a..78a1e6e382c57b7c6c4e48e97034b09aba173b18 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoMaterial.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoMaterial.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOMATERIAL_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNameTag.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNameTag.h index 3d378130100dc5caf6b4f65cd3c33b69bbc24d32..fcb7fe55d6b2bbd8031ccf01e400a6b1304ad07c 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNameTag.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNameTag.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEONAMETAG_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodeAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodeAction.h index 9cb8656cbb02ce8d277c4af33e97380cf09a8784..ba80f91982b7beeb721d054cef2eaf453a181afd 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodeAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodeAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEONODEACTION_H @@ -25,6 +25,11 @@ #include "GeoModelKernel/GeoSerialDenominator.h" #include "GeoModelKernel/GeoSerialIdentifier.h" #include "GeoModelKernel/GeoSerialTransformer.h" +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" #include "GeoModelKernel/GeoNodePath.h" class GeoNodeAction @@ -36,6 +41,8 @@ class GeoNodeAction public: GeoNodeAction(); + GeoNodeAction(const GeoNodeAction &right) = delete; + GeoNodeAction & operator=(const GeoNodeAction &right) = delete; virtual ~GeoNodeAction(); // Handles a Node. @@ -65,6 +72,20 @@ class GeoNodeAction // Handles a SerialIdentifier. virtual void handleSerialIdentifier(const GeoSerialIdentifier *); + // Handle GeoVSurface + virtual void handleVSurface (const GeoVSurface *surface); + + // Handle Rectangle Virtual Surface + virtual void handleRectSurface (const GeoRectSurface *surface); + + // Handle Trapezoid Virtual Surface + virtual void handleTrapezoidSurface (const GeoTrapezoidSurface *surface); + + // Handle Annulus Virtual Surface + virtual void handleAnnulusSurface (const GeoAnnulusSurface *surface); + + // Handle Diamond Virtual Surface + virtual void handleDiamondSurface (const GeoDiamondSurface *surface); // Returns a pointer to the path object. GeoNodePath* getPath (); @@ -83,14 +104,14 @@ class GeoNodeAction // Clears a depth limit, if any. void clearDepthLimit (); + + protected: // Termination flag; causes an abortion of action execution. bool m_terminate; private: - GeoNodeAction(const GeoNodeAction &right); - GeoNodeAction & operator=(const GeoNodeAction &right); // A limit may be placed upon the depth to which the action // descends. 0 = self. 1 = self and children. diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodePath.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodePath.h index b2cd5f73ed3b5ad2b7b7254a506668efa90c1d78..e796f317873688cba91fa68b56b349412971f872 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodePath.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoNodePath.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEONODEPATH_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPara.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPara.h index 26ad8555e7a937223f21eec27c125f655616a492..aa0a7abbc795e1c4f8371611609a0f41af893849 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPara.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPara.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPARA_H @@ -14,7 +14,7 @@ class GeoPara : public GeoShape GeoPara (double XHalfLength, double YHalfLength, double ZHalfLength, double Alpha, double Theta, double Phi); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -33,6 +33,11 @@ class GeoPara : public GeoShape return getClassTypeID(); } + // Returns true as PARA is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPcon.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPcon.h index 59b88f989bbda1cda986f6e00c642d7cbb60133f..080fd1ecf43d9e9028d573669a0a2b5603061c2c 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPcon.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPcon.h @@ -25,7 +25,7 @@ class GeoPcon : public GeoShape { GeoPcon (double SPhi, double DPhi); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -44,6 +44,11 @@ class GeoPcon : public GeoShape { return getClassTypeID(); } + // Returns false as PCON is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Add another plane to the polycone A minimum of two // planes are required to create a valid polycone. void addPlane (double ZPlane, double RMinPlane, double RMaxPlane); @@ -102,7 +107,6 @@ class GeoPcon : public GeoShape { virtual ~GeoPcon() = default; private: - static const std::string s_classType; static const ShapeType s_classTypeID; @@ -119,5 +123,4 @@ class GeoPcon : public GeoShape { std::vector<double> m_rMaxPlane{}; }; - #endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPerfUtils.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPerfUtils.h index a3e23d91318f9c3c504ea4e9cd54b27be2aa21e1..37233d3456b49cad4408674aef7fe1b9c81fc534 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPerfUtils.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPerfUtils.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPERFUTILS_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPgon.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPgon.h index 7dea7fad2eb73b4ee8bb79968a050900e40fe2ff..cfca2b3b08b2113a4fd37e3d434b211ccb11ad13 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPgon.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPgon.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPGON_H @@ -17,7 +17,7 @@ class GeoPgon : public GeoShape GeoPgon (double SPhi, double DPhi, unsigned int NSides); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -36,6 +36,11 @@ class GeoPgon : public GeoShape return getClassTypeID(); } + // Returns true as PGON is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // Add another plane to the polygon. A minimum of two // planes are required to create a valid polygon. void addPlane (double ZPlane, double RMinPlane, double RMaxPlane); @@ -99,7 +104,6 @@ class GeoPgon : public GeoShape virtual ~GeoPgon() = default; private: - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h index 160065c67f8b485edce641cb53299faf41a1d520..379957b8c532e3bec3c91304cf97d123bc448dea 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPHYSVOL_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPluginLoader.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPluginLoader.h index 4470c8c49300701061a3357731d3c102e1346585..e0d456925e4463d10a99b6ae90baee77423f526a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPluginLoader.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPluginLoader.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOPLUGINLOADER_H_ diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedrizeAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedrizeAction.h index 58d2a0456bc0b884da7645aed81706ae5e487e7f..2817492d6ca4be986e12d630eb891f49bda0d614 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedrizeAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedrizeAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPOLYHEDRIZEACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedron.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedron.h index 06bf1f3d5e3adc44aa58d19cd488cdab9c39f968..dac4b36365f5773d660d0283e4c841677b2699f3 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedron.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPolyhedron.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GeoPolyhedron_h @@ -224,8 +224,8 @@ protected: bool ifWholeCircle, int ns, int &kface); // Set side facets for the case of incomplete rotation - void SetSideFacets (int ii[4], int vv[4], - int *kk, double *r, double dphi, int ns, int &kface); + void SetSideFacets (const int ii[4], int vv[4], + const int *kk, const double *r, double dphi, int ns, int &kface); // Create GeoPolyhedron for body of revolution around Z-axis void RotateAroundZ (int nstep, double phi, double dphi, diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPrintGraphAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPrintGraphAction.h index bed2e982748e4513673ad6eae636e7cf7a4c759c..07ce459dd873cd2fdf67b69cd3a0f38677fbe8f9 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPrintGraphAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPrintGraphAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOPRINTGRAPHACTION_H @@ -31,26 +31,41 @@ class GeoPrintGraphAction : public GeoNodeAction virtual ~GeoPrintGraphAction(); // Handles a Transform. - virtual void handleTransform (const GeoTransform *xform); + virtual void handleTransform (const GeoTransform *xform) override final; // Handles a physical volume. - virtual void handlePhysVol (const GeoPhysVol *vol); + virtual void handlePhysVol (const GeoPhysVol *vol) override final; // Handles a physical volume. - virtual void handleFullPhysVol (const GeoFullPhysVol *vol); + virtual void handleFullPhysVol (const GeoFullPhysVol *vol) override final; // Handles a Name Tag. - virtual void handleNameTag (const GeoNameTag *nameTag); + virtual void handleNameTag (const GeoNameTag *nameTag) override final; // Handles a Serial Denominator. - virtual void handleSerialDenominator (const GeoSerialDenominator *sD); + virtual void handleSerialDenominator (const GeoSerialDenominator *sD) override final; // Handles a Serial Transformer - virtual void handleSerialTransformer (const GeoSerialTransformer *sT); + virtual void handleSerialTransformer (const GeoSerialTransformer *sT) override final; // Handles an Identifier Tag. - virtual void handleIdentifierTag (const GeoIdentifierTag *idTag); + virtual void handleIdentifierTag (const GeoIdentifierTag *idTag) override final; + // Handle a virtual surface. + virtual void handleVSurface(const GeoVSurface *surface) override final; + + // Handle a rectangular surface. + virtual void handleRectSurface( const GeoRectSurface *rect) override final; + + // Handle a trapezoid surface. + virtual void handleTrapezoidSurface( const GeoTrapezoidSurface *trapezoid) override final; + + // Handle an annulus surface. + virtual void handleAnnulusSurface( const GeoAnnulusSurface *annulus) override final; + + // Handle a diamond surface. + virtual void handleDiamondSurface( const GeoDiamondSurface *diamond) override final; + // Sets the notification state. Default: everything on. void setNotification (Type type, bool state); diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h index 28ad17a2ed6fc07a1c57940a858ac106634f715a..a0cb9da1d50efae8f7b342a43eba7c3d5e4169a3 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSTORE_H @@ -56,7 +56,7 @@ class GeoPublisher void setName(std::string name); std::string getName() { return m_name; } - void storeDataTable( std::string tableName, std::vector<std::string> colNames, std::vector<std::string> colTypes, std::vector<std::vector<std::variant<int,long,float,double,std::string>>> tableData ); + void storeDataTable( const std::string& tableName, const std::vector<std::string>& colNames, const std::vector<std::string>& colTypes, std::vector<std::vector<std::variant<int,long,float,double,std::string>>> tableData ); std::pair<AuxTableDefs, AuxTableData> getPublishedAuxData() { return std::make_pair(m_auxiliaryTablesVar, m_auxiliaryTablesVarData); } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp index cd040dbeabf2c3676392b71681445a84106f8048..8114cebe74fe696a74ea6c492ce98735f40a9c74 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp @@ -6,18 +6,26 @@ template<typename Iter> void GeoPublisher::printInsertionStatus(Iter it, bool su std::cout << "GeoModelKernel::GeoPublisher : Insertion of " << it->first << (success ? " succeeded\n" : " failed\n"); } -template<class N, typename T> void GeoPublisher::publishNode(N node,T keyT) +template <class N, typename T> +void GeoPublisher::publishNode(N node, T keyT) { std::any key = keyT; - static_assert(std::is_same_v<GeoVFullPhysVol*, N> || std::is_same_v<GeoAlignableTransform*, N>, + static_assert(std::is_same_v<GeoVFullPhysVol *, N> || std::is_same_v<GeoAlignableTransform *, N>, "ERROR!!! The node type is not currently supported by 'GeoPublisher'.\n If in doubt, please ask to `geomodel-developers@cern.ch'.\n"); - if constexpr (std::is_same_v<GeoVFullPhysVol*, N>) { - const auto [iter, success] = m_publishedFPV.insert( {node, key} ); - if(!success) printInsertionStatus(iter, success); - } else if constexpr (std::is_same_v<GeoAlignableTransform*, N>) { - const auto [iter, success] = m_publishedAXF.insert( {node, key} ); - if(!success) printInsertionStatus(iter, success); + if constexpr (std::is_same_v<GeoVFullPhysVol *, N>) + { + const auto [iter, success] = m_publishedFPV.insert({node, key}); + if (!success) { + std::cout << "WARNING! Publication of GeoVFullPhysVol node: " << node << ", key: " << keyT << " failed." << std::endl; + printInsertionStatus(iter, success); + } + } + else if constexpr (std::is_same_v<GeoAlignableTransform *, N>) + { + const auto [iter, success] = m_publishedAXF.insert({node, key}); + if (!success) { + std::cout << "WARNING! Publication of AlignableTransform node: " << node << ", key: " << keyT << " failed." << std::endl; + printInsertionStatus(iter, success); + } } } - - diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h index 40f267001cf3bf9e89b23003aefd3fa7e6c6df9c..c5a9935c961c2f8d412c0e43279f18995ba9d1ca 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h @@ -1,30 +1,60 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * + * Created on: April, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + + #ifndef GEOMODELKERNEL_GEORECTSURFACE_H #define GEOMODELKERNEL_GEORECTSURFACE_H -#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/GeoVSurfaceShape.h" -class GeoRectSurface : public GeoVSurface +class GeoRectSurface : public GeoVSurfaceShape { public: // Constructor for the Rectangular Surface GeoRectSurface (double XHalfLength, double YHalfLength); // Returns the area of the surface - double area() const override; + double area() const; // Half length in the x-direction - double getXHalfLength () const { + double getXHalfLength () const + { return m_xHalfLength; } // Half-length in the y direction - double getYHalfLength () const { + double getYHalfLength () const + { return m_yHalfLength; } + virtual const std::string & type () const{ + return s_classType; + } + + virtual ShapeType typeID () const{ + return s_classTypeID; + } + + // Executes a GeoShapeAction + void exec (GeoShapeAction *action) const override final; + + // Is the point (x,y,z) inside the shape? + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; + protected: virtual ~GeoRectSurface() = default; - + + static const std::string s_classType; + static const ShapeType s_classTypeID; double m_xHalfLength{0.}; double m_yHalfLength{0.}; }; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialDenominator.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialDenominator.h index 6e85abef4c7e5a3b0fcd16104a59e768869b336e..5f2235fb09a06a6e46e4ca76a2250306a7c786ff 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialDenominator.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialDenominator.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSERIALDENOMINATOR_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialIdentifier.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialIdentifier.h index 63a06d4756bfa93ae0a9e049049e9f963a5eea08..b98285bda000f7da1a2bfd1a39d23aa7bb607fc2 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialIdentifier.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialIdentifier.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSERIALIDENTIFIER_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialTransformer.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialTransformer.h index ffd4d146c709249a53393e6c6f309086a18cb482..cdd09dc21971ab635ab26b09e080d5e6c7878cbf 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialTransformer.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSerialTransformer.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSERIALTRANSFORMER_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShape.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShape.h index 493ef70461396707ac473e186ac66c912a1695e3..c58e237e0ac860fedbb367a9aab9be1738f8816a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShape.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShape.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPE_H @@ -27,6 +27,7 @@ #include "GeoModelKernel/RCBase.h" #include <GeoModelKernel/GeoDefinitions.h> #include <string> +#include <atomic> using ShapeType = unsigned int; class GeoShapeIntersection; @@ -42,7 +43,7 @@ class GeoShape : public RCBase GeoShape () = default; // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 1000000) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -69,19 +70,38 @@ class GeoShape : public RCBase // Returns the shape type, as an coded integer. virtual ShapeType typeID () const = 0; + // Returns true if the shape is a polyhedron. + virtual bool isPolyhedron () const = 0; + + // Returns number of constituents + virtual unsigned int getNoConstituents () const { + return 1; + } + // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const = 0; + // Returns volume value + double getVolumeValue () const { + return m_shape_volume.load(); + } + + // Sets volume value + void setVolumeValue (double value) const { + m_shape_volume = value; + } + protected: - virtual ~GeoShape() = default; + virtual ~GeoShape () = default; // Returns the bounding box of the specified disk. This method is used // for calculation of the extend of a tube, cone, polycone, torus. static void diskExtent(double rmin, double rmax, double sphi, double dphi, double& xmin, double& ymin, double& xmax, double& ymax); - - + private: + // Cached volume + mutable std::atomic<double> m_shape_volume{-1.}; }; #endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeAction.h index df4a430f1a0b449ff5fdd1ed883aa53b7441a1ca..94280aa97ce6e948a6c56475c0892c880f9b9f18 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPEACTION_H @@ -40,6 +40,12 @@ class GeoTessellatedSolid; class GeoGenericTrap; +class GeoVSurfaceShape; +class GeoRectSurface; +class GeoTrapezoidSurface; +class GeoAnnulusSurface; +class GeoDiamondSurface; + class GeoShapeAction { public: @@ -104,6 +110,21 @@ class GeoShapeAction // Handles a tubs shape. virtual void handleTubs (const GeoTubs *tubs); + + // Handles a virtual surface. + virtual void handleShape (const GeoVSurfaceShape *); + + // Handles a rectangular surface. + virtual void handleRectSurface (const GeoRectSurface *surf); + + // Handles a trapezoid surface. + virtual void handleTrapezoidSurface (const GeoTrapezoidSurface *surf); + + // Handles an annulus surface. + virtual void handleAnnulusSurface (const GeoAnnulusSurface *surf); + + // Handles a diamond surface. + virtual void handleDiamondSurface (const GeoDiamondSurface *surf); // Returns a pointer to the path object. GeoShapePath * getPath (); diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeIntersection.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeIntersection.h index 029b7ce78a4e060d6261fd74c4dc9da8e876fc58..78b4ea8388b87849b6b6414df4ba1d1088d21bc8 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeIntersection.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeIntersection.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPEINTERSECTION_H @@ -7,10 +7,8 @@ #include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoIntrusivePtr.h" +#include "GeoModelKernel/PersistifierFwd.h" -#ifndef _GeoShapePersistification_On_ - class Persistifier; -#endif class GeoShapeIntersection : public GeoShape { @@ -19,7 +17,7 @@ class GeoShapeIntersection : public GeoShape GeoShapeIntersection (const GeoShape* A, const GeoShape* B); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 1000000) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -38,6 +36,16 @@ class GeoShapeIntersection : public GeoShape return getClassTypeID(); } + // Returns true if the resulting shape is a polyhedron, false otherwise. + virtual bool isPolyhedron () const { + return (m_opA->isPolyhedron() && m_opB->isPolyhedron()); + } + + // Returns total number of constituents + virtual unsigned int getNoConstituents () const { + return (m_opA->getNoConstituents() + m_opB->getNoConstituents()); + } + // Returns the first operand being ANDed const GeoShape* getOpA () const { return m_opA; @@ -70,9 +78,6 @@ class GeoShapeIntersection : public GeoShape // The second shape operand in the AND operation. GeoIntrusivePtr<const GeoShape> m_opB{}; - // Cached volume - mutable std::atomic<double> fVolume{-1}; - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapePath.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapePath.h index 865b0ac6ca81a02aff19a9217a0c829dd46a2e01..d2edb52b32a29e2764869379660df34de3c8d77c 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapePath.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapePath.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPEPATH_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeShift.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeShift.h index 1274a5144dfe4cb55e8a41ce25c3e0b09af199b7..595a86752bd907a8a43a386039bc13730db6e75c 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeShift.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeShift.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPESHIFT_H @@ -8,11 +8,7 @@ #include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoIntrusivePtr.h" #include "GeoModelKernel/GeoDefinitions.h" - - -#ifndef _GeoShapePersistification_On_ - class Persistifier; -#endif +#include "GeoModelKernel/PersistifierFwd.h" class GeoShapeShift : public GeoShape { @@ -21,8 +17,8 @@ class GeoShapeShift : public GeoShape { GeoShapeShift (const GeoShape* A, const GeoTrf::Transform3D &X); // Returns the volume of the shape, for mass inventory - virtual double volume () const { - return m_op->volume(); + virtual double volume (int npoints = 1000000) const { + return m_op->volume(npoints); } // Returns the bonding box of the shape @@ -42,6 +38,16 @@ class GeoShapeShift : public GeoShape { return getClassTypeID(); } + // Returns true if OR is a polyhedron, false otherwise + virtual bool isPolyhedron () const { + return m_op->isPolyhedron(); + } + + // Returns number of constituents + virtual unsigned int getNoConstituents () const { + return m_op->getNoConstituents(); + } + // Returns the first operand being ORed const GeoShape* getOp() const { return m_op; @@ -55,13 +61,11 @@ class GeoShapeShift : public GeoShape { // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const; - static ShapeType getClassTypeID () { return s_classTypeID; } - // For type identification. static const std::string& getClassType () { return s_classType; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeSubtraction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeSubtraction.h index 2ab3e08e468fc5ff4461bf762152e6f757a57053..48367a8f8c8c93b0396ebb857e87079e00110b41 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeSubtraction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeSubtraction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPESUBTRACTION_H @@ -7,11 +7,7 @@ #include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoIntrusivePtr.h" - - -#ifndef _GeoShapePersistification_On_ - class Persistifier; -#endif +#include "GeoModelKernel/PersistifierFwd.h" class GeoShapeSubtraction : public GeoShape { @@ -20,7 +16,7 @@ class GeoShapeSubtraction : public GeoShape { GeoShapeSubtraction (const GeoShape* A, const GeoShape* B); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 1000000) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -39,6 +35,16 @@ class GeoShapeSubtraction : public GeoShape { return getClassTypeID(); } + // Returns true if the resulting shape is a polyhedron, false otherwise. + virtual bool isPolyhedron () const { + return (m_opA->isPolyhedron() && m_opB->isPolyhedron()); + } + + // Returns total number of constituents + virtual unsigned int getNoConstituents () const { + return (m_opA->getNoConstituents() + m_opB->getNoConstituents()); + } + // Returns the first operand in the subtraction const GeoShape* getOpA () const{ return m_opA; @@ -73,9 +79,6 @@ class GeoShapeSubtraction : public GeoShape { // The second shape operand in the Subtraction operation GeoIntrusivePtr<const GeoShape> m_opB{nullptr}; - // Cached volume - mutable std::atomic<double> fVolume{-1.}; - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeUnion.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeUnion.h index b712b180a3a48e8ccc474b7e267ec3c660ffb9e4..c660548d2571627de9e498cbb8a407da90b633ac 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeUnion.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoShapeUnion.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSHAPEUNION_H @@ -7,10 +7,7 @@ #include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoIntrusivePtr.h" - -#ifndef _GeoShapePersistification_On_ - class Persistifier; -#endif +#include "GeoModelKernel/PersistifierFwd.h" class GeoShapeUnion : public GeoShape { @@ -19,7 +16,7 @@ class GeoShapeUnion : public GeoShape GeoShapeUnion (const GeoShape* A, const GeoShape* B); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 1000000) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -27,8 +24,6 @@ class GeoShapeUnion : public GeoShape // Returns true if the shape contains the point, false otherwise virtual bool contains (double x, double y, double z) const; - - // Returns the OR shape type, as a string. virtual const std::string & type() const{ @@ -40,6 +35,16 @@ class GeoShapeUnion : public GeoShape return getClassTypeID(); } + // Returns true if the resulting shape is a polyhedron, false otherwise. + virtual bool isPolyhedron () const { + return (m_opA->isPolyhedron() && m_opB->isPolyhedron()); + } + + // Returns total number of constituents + virtual unsigned int getNoConstituents () const { + return (m_opA->getNoConstituents() + m_opB->getNoConstituents()); + } + // Returns the first operand being ORed const GeoShape* getOpA() const { return m_opA; @@ -67,21 +72,16 @@ class GeoShapeUnion : public GeoShape virtual ~GeoShapeUnion() = default; private: - - // The first shape operand in the OR operation GeoIntrusivePtr<const GeoShape> m_opA{}; // The second shape operand in the OR operation GeoIntrusivePtr<const GeoShape> m_opB{}; - // Cached volume - mutable std::atomic<double> fVolume{-1.}; - static const std::string s_classType; static const ShapeType s_classTypeID; - // For I/O only! + // For I/O only! GeoShapeUnion() = default; friend Persistifier; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSimplePolygonBrep.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSimplePolygonBrep.h index 6a14880915563d497d7831b12989ec8d41c4ee7f..b1671f196f3aaf97e1bb87cdf5f67f510172f004 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSimplePolygonBrep.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSimplePolygonBrep.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSIMPLEPOLYGONBREP_H @@ -27,7 +27,7 @@ class GeoSimplePolygonBrep : public GeoShape { GeoSimplePolygonBrep(double dz); // Returns the volume of the shape, for mass inventory - virtual double volume() const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -46,6 +46,11 @@ class GeoSimplePolygonBrep : public GeoShape { return getClassTypeID(); } + // Returns true as BREP is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // For type identification static const std::string& getClassType() { return s_classType; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSurfaceCursor.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSurfaceCursor.h new file mode 100644 index 0000000000000000000000000000000000000000..980ce2da65ef3d2c4fda5ff87a049915fc610a75 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoSurfaceCursor.h @@ -0,0 +1,68 @@ +#ifndef GEOMODELKERNEL_GEOSURFCURSOR_H +#define GEOMODELKERNEL_GEOSURFCURSOR_H + +#include "GeoModelKernel/GeoNodeAction.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoVSurface.h" +#include <vector> + +class GeoVAlignmentStore; + +class GeoSurfaceCursor final : public GeoNodeAction +{ + public: + + using VSConstLink = GeoIntrusivePtr<const GeoVSurface>; + + GeoSurfaceCursor (PVConstLink parent, GeoVAlignmentStore* store=nullptr); + virtual ~GeoSurfaceCursor() override; + + GeoSurfaceCursor(const GeoSurfaceCursor &right) = delete; + GeoSurfaceCursor & operator=(const GeoSurfaceCursor &right) = delete; + + void next(); + + bool atEnd() const; + + /// Returns the transformation to the surface or volume. + GeoTrf::Transform3D getTransform () const; + + /// Returns the default ransformation to the surface or volume. + GeoTrf::Transform3D getDefTransform () const; +/* + /// Returns the name of the surface. All are called VSurface for now. + std::string getName () const; +*/ + private: + /// Handles a Transform. + virtual void handleTransform (const GeoTransform *xform) override; + + /// Handles a physical volume. + virtual void handlePhysVol (const GeoPhysVol *vol) override; + + /// Handles a physical volume. + virtual void handleFullPhysVol (const GeoFullPhysVol *vol) override; + + /// Handles a rectangular virtual surface. + virtual void handleVSurface (const GeoVSurface *surf) override; + + /// Ressucitate (undo terminate) + void resuscitate(); + + PVConstLink m_parent; + PVConstLink m_volume; + VSConstLink m_surface; + GeoTrf::Transform3D m_transform; + GeoTrf::Transform3D m_defTransform; + + unsigned int m_majorIndex; + unsigned int m_volCount; + unsigned int m_surfCount; + + std::vector<const GeoTransform *> m_pendingTransformList; + + bool m_hasAlignTrans{}; + GeoVAlignmentStore *m_alignStore; +}; + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTessellatedSolid.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTessellatedSolid.h index 72850483cac4cb48b72324f9a6861ade68568aaf..f6782f9b091601d2751b5b19904360986239d720 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTessellatedSolid.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTessellatedSolid.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTESSELLATEDSOLID_H @@ -17,7 +17,7 @@ class GeoTessellatedSolid : public GeoShape { GeoTessellatedSolid(); // Returns the volume of the shape, for mass inventory - virtual double volume() const; + virtual double volume(int npoints = 0) const; // Returns the bonding box of the shape virtual void extent (double& xmin, double& ymin, double& zmin, @@ -36,6 +36,11 @@ class GeoTessellatedSolid : public GeoShape { return getClassTypeID(); } + // Returns true as TESSELLATED SOLID is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // For type identification static const std::string& getClassType(); diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTorus.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTorus.h index cbbe6fd2b0f324d60094ff0e3b2ca56cedf1ff8a..9909002325cd8b2f91ac6a815df954a8d1de978e 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTorus.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTorus.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTORUS_H @@ -13,7 +13,7 @@ class GeoTorus : public GeoShape { GeoTorus (double Rmin, double Rmax, double Rtor, double SPhi, double DPhi); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -32,6 +32,11 @@ class GeoTorus : public GeoShape { return getClassTypeID(); } + // Returns false as TORUS is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; @@ -74,8 +79,6 @@ class GeoTorus : public GeoShape { virtual ~GeoTorus() = default; private: - - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTransform.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTransform.h index d036550654e5b20853f0539c85f879397e16d60c..43e1d90197d1840e3c397722752455f54d75b54a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTransform.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTransform.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTRANSFORM_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrap.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrap.h index 3726befa69196c3789560ce0ae6d593a6bab7081..22b4cb60c90baaa5563a65504556714802aeaac5 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrap.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrap.h @@ -19,7 +19,7 @@ class GeoTrap : public GeoShape GeoTrap (double ZHalfLength, double Theta, double Phi, double Dydzn, double Dxdyndzn, double Dxdypdzn, double Angleydzn, double Dydzp, double Dxdyndzp, double Dxdypdzp, double Angleydzp); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -38,6 +38,11 @@ class GeoTrap : public GeoShape return getClassTypeID(); } + // Returns true as TRAP is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; @@ -86,7 +91,6 @@ class GeoTrap : public GeoShape private: - static const std::string s_classType; static const ShapeType s_classTypeID; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h new file mode 100644 index 0000000000000000000000000000000000000000..91a16c8dc2804c2fb2d84d0e07368693872999bc --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h @@ -0,0 +1,70 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * + * Created on: July, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + + +#ifndef GEOMODELKERNEL_GEOTRAPEZOIDSURFACE_H +#define GEOMODELKERNEL_GEOTRAPEZOIDSURFACE_H + +#include "GeoModelKernel/GeoVSurfaceShape.h" + +class GeoTrapezoidSurface : public GeoVSurfaceShape +{ + public: + // Constructor for the Trapezoid Surface + GeoTrapezoidSurface (double XHalfLengthMin, double XHalfLengthMax, double YHalfLength); + + // Returns the area of the surface + double area() const; + + // Minimum Half length in the x-direction + double getXHalfLengthMin () const + { + return m_xHalfLengthMin; + } + + // Maximum Half-length in the x direction + double getXHalfLengthMax () const + { + return m_xHalfLengthMax; + } + + // Height Half-length in the y direction + double getYHalfLength () const + { + return m_yHalfLength; + } + + virtual const std::string & type () const{ + return s_classType; + } + + virtual ShapeType typeID () const{ + return s_classTypeID; + } + + // Executes a GeoShapeAction + void exec (GeoShapeAction *action) const override final; + + // Is the point (x,y,z) inside the shape? + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; + + protected: + virtual ~GeoTrapezoidSurface() = default; + + static const std::string s_classType; + static const ShapeType s_classTypeID; + double m_xHalfLengthMin{0.}; + double m_xHalfLengthMax{0.}; + double m_yHalfLength{0.}; +}; + + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTraversalState.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTraversalState.h index 93dd009ce939bad7f8e1861b91f6142ac5b41bb7..1a084ab2cd0a3b52cf7313748ee49a56a1474e12 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTraversalState.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTraversalState.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTRAVERSALSTATE_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrd.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrd.h index 48b6759e53088042f336edbabbd3ac93f67d548a..c373377679da964ba2abec1fb42fd69a1fd18559 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrd.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrd.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTRD_H @@ -13,7 +13,7 @@ class GeoTrd : public GeoShape GeoTrd (double XHalfLength1, double XHalfLength2, double YHalfLength1, double YHalfLength2, double ZHalfLength); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -32,6 +32,11 @@ class GeoTrd : public GeoShape return getClassTypeID(); } + // Returns true as TRD is a polyhedron. + virtual bool isPolyhedron () const { + return true; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; @@ -51,10 +56,10 @@ class GeoTrd : public GeoShape // Half length in the x-direction at +dz. double getXHalfLength2 () const { return m_xHalfLength2; } - // Half-length in the y direction at +dz. + // Half-length in the y direction at -dz. double getYHalfLength1 () const { return m_yHalfLength1; } - // Half-length in the y direction at -dz. + // Half-length in the y direction at +dz. double getYHalfLength2 () const { return m_yHalfLength2; } // Half-length in the z direction. diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTube.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTube.h index f9d7e2370ab060e05bef846cb7bffd4f9645fe95..6e7f496b21934b8b3efdd3ccfeb73668cd51fd57 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTube.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTube.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTUBE_H @@ -13,7 +13,7 @@ class GeoTube : public GeoShape GeoTube (double RMin, double RMax, double ZHalfLength); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -31,6 +31,12 @@ class GeoTube : public GeoShape virtual ShapeType typeID () const{ return getClassTypeID(); } + + // Returns false as TUBE is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; @@ -60,8 +66,7 @@ class GeoTube : public GeoShape } protected: - //## Destructor (generated) - virtual ~GeoTube(); + virtual ~GeoTube() = default; private: GeoTube(const GeoTube &right); diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTubs.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTubs.h index 79d3dbf400aa5aafb242e15b775cb2771e27a338..59180eb1e61fb864a20ca586fe37b862b8fa2cc1 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTubs.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTubs.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTUBS_H @@ -13,7 +13,7 @@ class GeoTubs : public GeoShape GeoTubs (double RMin, double RMax, double ZHalfLength, double SPhi, double DPhi); // Returns the volume of the shape, for mass inventory. - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -32,6 +32,11 @@ class GeoTubs : public GeoShape return getClassTypeID(); } + // Returns false as TUBS is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction. virtual void exec (GeoShapeAction *action) const; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTwistedTrap.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTwistedTrap.h index e54dd5293512c7c5246a247d65e32c8a7bcfd694..a552821c995e96858964f340907119c512dadd79 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTwistedTrap.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTwistedTrap.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOTWISTEDTRAP_H @@ -64,7 +64,7 @@ class GeoTwistedTrap : public GeoShape ); // Returns the volume of the shape, for mass inventory - virtual double volume () const; + virtual double volume (int npoints = 0) const; // Returns the bonding box of the shape. virtual void extent (double& xmin, double& ymin, double& zmin, @@ -83,6 +83,11 @@ class GeoTwistedTrap : public GeoShape return getClassTypeID(); } + // Returns false as TWISTED TRAP is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // Executes a GeoShapeAction virtual void exec (GeoShapeAction *action) const; @@ -96,7 +101,6 @@ class GeoTwistedTrap : public GeoShape return s_classTypeID; } - inline double getY1HalfLength() const { return m_dy1 ; } inline double getX1HalfLength() const { return m_dx1 ; } inline double getX2HalfLength() const { return m_dx2 ; } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUnidentifiedShape.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUnidentifiedShape.h index 8f021aee87077af65fcf6b5bd3f4b7e9b3bd2282..47a3c5957eb48fc4b5079ed973cd56a697a7bffe 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUnidentifiedShape.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUnidentifiedShape.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ //========================================================================= // @@ -54,6 +54,11 @@ class GeoUnidentifiedShape: public GeoShape { // Returns the shape type, as an coded integer. virtual ShapeType typeID () const; + // Returns false as the shape is not a polyhedron. + virtual bool isPolyhedron () const { + return false; + } + // For type identification. static const std::string& getClassType (); diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUtilFunctions.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUtilFunctions.h index ef800864a0906163a1d7c8fe55f47fd21e6e4023..5a002731557639953d4abf1ba9bab6b647547784 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUtilFunctions.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoUtilFunctions.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOUTILFUNCTIONS_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVAlignmentStore.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVAlignmentStore.h index 2d0c8746b48e56b240e66195e8ccc9c5738c369d..a6afe8ec1e3642bf9a7ced9eef115c36f5522fce 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVAlignmentStore.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVAlignmentStore.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVALIGNMENTSTORE_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorElement.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorElement.h index cd87452a334538a8817015637cd866edd3a51a48..61876a6a374ca7a0c1969c3ef84c70041bacb703 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorElement.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorElement.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVDETECTORELEMENT_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorFactory.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorFactory.h index 55e508910360b24f67c7bf3af8a1930c4c5a8608..2d094be6d23197e2bbe436a632eccc88df289ab2 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorFactory.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorFactory.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVDETECTORFACTORY_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorManager.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorManager.h index 0526ce30954ac4461f82b74f2043f1245928c1f4..596cf01ff7078ae31a26f18a233e864429c72f13 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorManager.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVDetectorManager.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVDETECTORMANAGER_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVG4ExtensionSolid.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVG4ExtensionSolid.h index 16310586431b69afe06f322462d1c0a7d6e2d918..3e021c193f750db59f34baf367974d2050146f38 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVG4ExtensionSolid.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVG4ExtensionSolid.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVG4EXTENSIONSOLID_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVGeometryPlugin.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVGeometryPlugin.h index ec9b5aa56b815ec6cc43daaf3b01d698260c2f11..ee6ad69024c2acfca6de0cd67b510d494b9a28d5 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVGeometryPlugin.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVGeometryPlugin.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVGEOMETRYPLUGIN_H @@ -22,29 +22,30 @@ class GeoVGeometryPlugin { public: - //! Default constructor. - GeoVGeometryPlugin() : m_publisher(nullptr) {} + //! Default constructor. + GeoVGeometryPlugin() = default; - //! Parametrized constructor for plugins that publish lists of nodes - GeoVGeometryPlugin(std::string name) : m_publisher(std::make_unique<GeoPublisher>()), m_pluginName( name ) { m_publisher->setName(m_pluginName); } + //! Parametrized constructor for plugins that publish lists of nodes + GeoVGeometryPlugin(const std::string& name) : + m_pluginName{name} { m_publisher->setName(m_pluginName); } - virtual ~GeoVGeometryPlugin() {} + virtual ~GeoVGeometryPlugin() = default; - //! Create the system geometry. - /// Note: this is a pure virtual method, so you need to implement it in your derived plugin class - virtual void create ( GeoVPhysVol* world, bool publish = false ) = 0; + //! Create the system geometry. + /// Note: this is a pure virtual method, so you need to implement it in your derived plugin class + virtual void create ( GeoVPhysVol* world, bool publish = false ) = 0; - //! Returns the plugin's name - std::string getName() { return m_pluginName; } + //! Returns the plugin's name + std::string getName() const { return m_pluginName; } - //! Returns the Publisher that publishes the lists of the GeoFullPhysVol and AlignableTransform nodes - GeoPublisher* getPublisher() { return m_publisher.get(); } + //! Returns the Publisher that publishes the lists of the GeoFullPhysVol and AlignableTransform nodes + GeoPublisher* getPublisher() { return m_publisher.get(); } protected: //! A GeoPublisher instance is used to publish lists of nodes. - std::unique_ptr<GeoPublisher> m_publisher; + std::unique_ptr<GeoPublisher> m_publisher{std::make_unique<GeoPublisher>()}; private: diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h index daa7945c49c8cb859edff5775b53218d0066de57..4639844de43b95fb95d5b77d4a78a69660e16f51 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h @@ -32,7 +32,7 @@ class GeoVPhysVol: public GeoPlacement { /// Returns the index of a specific daughter volume. The Query class can be used /// just like an unsigned int, but it provides and isValid() method to determine /// whether it is valid and throws an exception if an invalid value is blithely used. - Query<unsigned int> indexOf(PVConstLink daughter) const; + Query<unsigned int> indexOf(const PVConstLink& daughter) const; /// Returns the logical volume. const GeoLogVol* getLogVol() const { @@ -73,7 +73,7 @@ class GeoVPhysVol: public GeoPlacement { const GeoGraphNode* const* findChildNode(const GeoGraphNode *n) const; /// Adds a Graph Node to the Geometry Graph - void add(GeoIntrusivePtr<GeoGraphNode> graphNode); + void add(const GeoIntrusivePtr<GeoGraphNode>& graphNode); protected: virtual ~GeoVPhysVol() = default; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurface.h index cecb1be89e740fe177404ae69b758df04de18948..c1a6f3a1b0b4ce01c204fef3ae6ff1498353d3c0 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurface.h @@ -1,6 +1,11 @@ /* Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration -*/ + * + * + * Created on: April, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ #ifndef GEOMODELKERNEL_GeoVSurface_H #define GEOMODELKERNEL_GeoVSurface_H @@ -10,26 +15,45 @@ * @brief An abstract class of virtual surfaces * */ - +#include "GeoModelKernel/GeoVSurfaceShape.h" +#include "GeoModelKernel/GeoIntrusivePtr.h" #include "GeoModelKernel/GeoPlacement.h" #include "GeoModelKernel/GeoNodePositioning.h" #include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/throwExcept.h" +#include <iostream> + +#include <exception> +#include <sstream> class GeoVSurface : public GeoPlacement, public GeoNodePositioning { public: - GeoVSurface(): - GeoNodePositioning{this}{ - } - - virtual double area() const=0; // calculate the area of a surface - - // method from GeoPlacement + using VSConstLink = GeoIntrusivePtr<const GeoVSurface>; + + GeoVSurface(const GeoVSurfaceShape *SurfShape): + GeoNodePositioning{this}, m_surfaceshape{SurfShape}{} + + // method from GeoPlacement + virtual void exec(GeoNodeAction *action) const; + /// Returns the number of child nodes, virtual surface has no child, return 0 + unsigned int getNChildVols() const {return 0;} + + // Returns the shape of the virtual surface. + const GeoVSurfaceShape* getShape () const { + return m_surfaceshape; + } + + // Justify whether the point is on the surface + bool isOnSurface(const double Px, const double Py, const double Pz) const; protected: - virtual ~GeoVSurface() = default; + virtual ~GeoVSurface() = default; + + private: + GeoIntrusivePtr<const GeoVSurfaceShape> m_surfaceshape; }; - +using VSConstLink = GeoVSurface::VSConstLink; #endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurfaceShape.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurfaceShape.h new file mode 100644 index 0000000000000000000000000000000000000000..35a2e1286019641cab31dd3febf9a448ac5c4172 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVSurfaceShape.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + * + * + * Created on: Jul, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + +#ifndef GEOMODELKERNEL_GEOVSURFACESHAPE_H +#define GEOMODELKERNEL_GEOVSURFACESHAPE_H + + +#include "GeoModelKernel/RCBase.h" +#include "GeoModelKernel/GeoShapeAction.h" +#include <GeoModelKernel/GeoDefinitions.h> +#include <GeoModelKernel/throwExcept.h> +#include <string> +#include <exception> +#include <sstream> + +using SurfaceShapeType = unsigned int; // here use decimal numbers. (why use hexadecimal int?) + +class GeoVSurfaceShape : public RCBase +{ + public: + // Constructor for shape. Must provide the name, a string to identify this shape. + GeoVSurfaceShape () = default; + + // Returns the shape type, as a string. + virtual const std::string & type () const = 0; + + // Returns the shape type, as an coded integer. + virtual SurfaceShapeType typeID () const = 0; + + // Executes a GeoShapeAction + // TODO: Introduce GeoVSurfaceShapeAction in future + virtual void exec (GeoShapeAction *action) const = 0; + + // Is the point (x,y,z) inside the shape? + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const = 0; + + protected: + virtual ~GeoVSurfaceShape() = default; +}; + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeAction.h index 9a8f387cb5562c1be87199aea6c0fba94c8b95b8..e9b24a7f169abc47b740806711ae1276812e822f 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVOLUMEACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeCursor.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeCursor.h index c694b85fbe89610baec61c33293bd551238a13a6..bdd3db174cd48e5ad6f216065035051452b0912a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeCursor.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVolumeCursor.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOVOLUMECURSOR_H @@ -7,6 +7,7 @@ #include "GeoModelKernel/GeoNodeAction.h" #include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoVSurface.h" #include <vector> class GeoVAlignmentStore; @@ -14,6 +15,7 @@ class GeoVAlignmentStore; class GeoVolumeCursor final : public GeoNodeAction { public: + using VSConstLink = GeoVSurface::VSConstLink; GeoVolumeCursor (PVConstLink parent, GeoVAlignmentStore* store=nullptr); virtual ~GeoVolumeCursor() override; @@ -29,6 +31,9 @@ class GeoVolumeCursor final : public GeoNodeAction /// Returns the selected physical volume or nullptr if not found. PVConstLink getVolume () const; + /// Returns the selected virtual surface or nullptr if not found. + VSConstLink getSurface () const; + /// Returns the transformation to the volume. GeoTrf::Transform3D getTransform () const; @@ -52,7 +57,10 @@ class GeoVolumeCursor final : public GeoNodeAction /// Handles a physical volume. virtual void handleFullPhysVol (const GeoFullPhysVol *vol) override; - + + /// Handles a virtual surface. + virtual void handleVSurface (const GeoVSurface *surf) override; + /// Handles a Name Tag. virtual void handleNameTag (const GeoNameTag *nameTag) override; @@ -74,6 +82,7 @@ class GeoVolumeCursor final : public GeoNodeAction PVConstLink m_parent; PVConstLink m_volume; + VSConstLink m_surface; GeoTrf::Transform3D m_transform; GeoTrf::Transform3D m_defTransform; @@ -90,7 +99,6 @@ class GeoVolumeCursor final : public GeoNodeAction const GeoSerialIdentifier *m_serialIdentifier; unsigned int m_serialIdentPosition; unsigned int m_volCount; - bool m_hasAlignTrans; GeoVAlignmentStore *m_alignStore; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoXF.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoXF.h index 24ec712269714eb6078bc90bc071318bf61132b1..98fd22b635a72aa8756d5b43323c443f8eb5929a 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoXF.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoXF.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ //------------------------GeoTransformFunction--------------------------// diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeometryMap.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeometryMap.h index 4f13d91e210c0293a37f19baf8f84068ce0a33fa..47f4030ae27370a3e6c113560258cf8b9a2083b6 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeometryMap.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeometryMap.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOMETRYMAP_H @@ -25,7 +25,7 @@ class GeometryMap { // Create the map; this will maintain a list of all volumes matching // the expressions under the given physical volume. - void finalize(PVConstLink pv); + void finalize(const PVConstLink& pv); // For iteration: diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/Path.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/Path.h index c9604266ef0218e0b95abc8f81d749a6f2a6313a..d7e96808f28082b0329864fec9dc48e8e8b3d8b2 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/Path.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/Path.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_PATH_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/PersistifierFwd.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/PersistifierFwd.h new file mode 100644 index 0000000000000000000000000000000000000000..025d31cc73991859a9a1f0b5a49d198bb70a4344 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/PersistifierFwd.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef GEOMODELKERNEL_PERSISTIFIERFWD_H +#define GEOMODELKERNEL_PERSISTIFIERFWD_H + +// **************************************************************** +// *** PERSISTIFICATION SETTINGS FOR GeoModel BOOLEAN SHAPES ****** +// **************************************************************** +// Note: +// -- The instructions below are needed +// -- to correctly persistify/restore boolean shapes. +// -- They must be declared before including GeoModelKernel files. +// **************************************************************** +// This variable is used by GeoModel boolean shapes to switch ON +// the persistification mode +#define _GeoShapePersistification_On_ +// fwd declaration of namespace::class we want to use to persistify +// the GeoModel boolean shapes +namespace GeoModelIO { +class ReadGeoModel; +} +// the 'Persistifier' class name is used by GeoModel boolean shapes +// to grant access to friend classes +typedef GeoModelIO::ReadGeoModel Persistifier; +// **************************************************************** +// **************************************************************** + +#endif diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/Query.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/Query.h index 34487da8bef6d2ee206ce475ddade78152b9c0d3..f3cde970c7cb54bec945d5a7bb6abd64deea6713 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/Query.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/Query.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_QUERY_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h index fb1ea2a4d49497ead58d344022957b9d16ae3a6a..6c2e8b4b6b886eff3aeeff8b719d34b011575920 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/RCBase.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/TemplateVolAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/TemplateVolAction.h index 788d81d98583a1610d57aa28707171ed866036bd..ea27c2c98d4841a14e56d475d75c886afffb7d28 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/TemplateVolAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/TemplateVolAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_TEMPLATEVOLACTION_H diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/TinyHepTransform.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/TinyHepTransform.h index d0d162fa27d9238dd0513bd67a466ac5a430720d..f815d61503e811af53694d0fc8d0d5735f98d90b 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/TinyHepTransform.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/TinyHepTransform.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef _TINYHEPTRANSFORM_H_ diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/throwExcept.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/throwExcept.h similarity index 100% rename from GeoModelCore/GeoModelHelpers/GeoModelHelpers/throwExcept.h rename to GeoModelCore/GeoModelKernel/GeoModelKernel/throwExcept.h diff --git a/GeoModelCore/GeoModelKernel/doc/packagedoc.h b/GeoModelCore/GeoModelKernel/doc/packagedoc.h index e7b866ef33c6744996982ed2b1835bb5f409af77..5491c0d28881784c2bb6c32cd5c86f9495d4a75c 100755 --- a/GeoModelCore/GeoModelKernel/doc/packagedoc.h +++ b/GeoModelCore/GeoModelKernel/doc/packagedoc.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** diff --git a/GeoModelCore/GeoModelKernel/src/CellBinning.cxx b/GeoModelCore/GeoModelKernel/src/CellBinning.cxx index b146f30ddc6184e2fe1acdc75bc51703c733b816..9aaddd2eb63509c79779c5099273a584a890e72d 100755 --- a/GeoModelCore/GeoModelKernel/src/CellBinning.cxx +++ b/GeoModelCore/GeoModelKernel/src/CellBinning.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/CellBinning.h" diff --git a/GeoModelCore/GeoModelKernel/src/CellPartitioning.cxx b/GeoModelCore/GeoModelKernel/src/CellPartitioning.cxx index f2f2fe999de845b4c7bc28bd80d948139364981c..e8d43baef83ec4f253d992cbee2c9fc0ae545966 100755 --- a/GeoModelCore/GeoModelKernel/src/CellPartitioning.cxx +++ b/GeoModelCore/GeoModelKernel/src/CellPartitioning.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/CellPartitioning.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoAccessSurfaceAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoAccessSurfaceAction.cxx new file mode 100755 index 0000000000000000000000000000000000000000..26ab0c963971dde8644861fc5a9da7dfd04e1e90 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoAccessSurfaceAction.cxx @@ -0,0 +1,108 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#include "GeoModelKernel/GeoAccessSurfaceAction.h" + +#include <string> + +GeoAccessSurfaceAction::GeoAccessSurfaceAction(unsigned int Index, const GeoVAlignmentStore* store) + : m_transform(GeoTrf::Transform3D::Identity()) + , m_defTransform(GeoTrf::Transform3D::Identity()) + , m_index(Index) + , m_alignStore(store) +{ + setDepthLimit (1); + m_pendingTransformList.reserve(1); +} + +GeoAccessSurfaceAction::~GeoAccessSurfaceAction() = default; + +void GeoAccessSurfaceAction::handleTransform (const GeoTransform *xform) +{ + m_pendingTransformList.push_back (xform); +} + + +// in this action, we only care about virtual surface +// get rid of transformations corresponding to physics volume +void GeoAccessSurfaceAction::handlePhysVol (const GeoPhysVol *vol) +{ + if(getPath()->getLength()-1 == 0) + return; + + else{ + m_pendingTransformList.erase (m_pendingTransformList.begin (), + m_pendingTransformList.end ()); + } +} + + +// in this action, we only care about virtual surface +// get rid of transformations corresponding to full physics volume +void GeoAccessSurfaceAction::handleFullPhysVol (const GeoFullPhysVol *vol) +{ + if(getPath()->getLength()-1 == 0) + return; + + else{ + m_pendingTransformList.erase (m_pendingTransformList.begin (), + m_pendingTransformList.end ()); + } +} + + +void GeoAccessSurfaceAction::handleVSurface (const GeoVSurface *surf) +{ + // Virtual Surface is the child of a Physical Volume, so no need to check. + // + /* + if(getPath()->getLength()-1 == 0) + return; + // + */ + + // check if the index equals the counter: + // + if(m_index == m_counter) { + m_surface = surf; + unsigned int listSize = m_pendingTransformList.size (); + if(listSize == 0) { + // do nothing.... + } + else if(listSize == 1) { + m_transform = m_pendingTransformList[0]->getTransform(m_alignStore); + m_defTransform = m_pendingTransformList[0]->getDefTransform(m_alignStore); + } + else { + for(unsigned int t = 0; t < m_pendingTransformList.size (); t++) { + m_transform = m_transform * m_pendingTransformList[t]->getTransform(m_alignStore); + m_defTransform = m_defTransform * m_pendingTransformList[t]->getDefTransform(m_alignStore); + } + } + terminate(); + } + else { + m_pendingTransformList.erase (m_pendingTransformList.begin (), + m_pendingTransformList.end ()); + } + // + // Increment the counter: + // + m_counter++; +} + +VSConstLink GeoAccessSurfaceAction::getSurface () const +{ + return m_surface; +} + +const GeoTrf::Transform3D & GeoAccessSurfaceAction::getTransform () const +{ + return m_transform; +} + +const GeoTrf::Transform3D & GeoAccessSurfaceAction::getDefTransform () const +{ + return m_defTransform; +} diff --git a/GeoModelCore/GeoModelKernel/src/GeoAccessVolAndSTAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoAccessVolAndSTAction.cxx index 45bee94810c8760eb1f72ed290a2781fd68e8d22..a7b1ac2a3039a1ed9a4ae2005401a309092e0b5f 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoAccessVolAndSTAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoAccessVolAndSTAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoAccessVolAndSTAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoAccessVolumeAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoAccessVolumeAction.cxx index a0af0873a9c142e3f05d658a4c2a7154d7aa2bd3..82bf0cc65a53550f99ac031c4d64bb840e7abd39 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoAccessVolumeAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoAccessVolumeAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoAccessVolumeAction.h" @@ -115,6 +115,13 @@ void GeoAccessVolumeAction::handleFullPhysVol (const GeoFullPhysVol *vol) m_counter++; } +void GeoAccessVolumeAction::handleVSurface (const GeoVSurface *surface) +{ + m_pendingTransformList.erase (m_pendingTransformList.begin (), + m_pendingTransformList.end ()); +} + + PVConstLink GeoAccessVolumeAction::getVolume () const { return m_volume; diff --git a/GeoModelCore/GeoModelKernel/src/GeoAlignableTransform.cxx b/GeoModelCore/GeoModelKernel/src/GeoAlignableTransform.cxx index e5c08560f6c06140fd153d6d733af841a993ab1c..8e41590c983b4a70de801988f3b0d49718d82557 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoAlignableTransform.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoAlignableTransform.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoAlignableTransform.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoAnnulusSurface.cxx b/GeoModelCore/GeoModelKernel/src/GeoAnnulusSurface.cxx new file mode 100644 index 0000000000000000000000000000000000000000..802a3cb071fc8b19fd9bcf6fff61144357cc8200 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoAnnulusSurface.cxx @@ -0,0 +1,97 @@ +# include "GeoModelKernel/GeoAnnulusSurface.h" + +const std::string GeoAnnulusSurface::s_classType = "AnnulusSurface"; +const ShapeType GeoAnnulusSurface::s_classTypeID = 36; + +GeoAnnulusSurface::GeoAnnulusSurface(double Ox, double Oy, double radius_in, double radius_out, double phi){ + + m_Ox = Ox; + m_Oy = Oy; + m_radius_in = radius_in; + m_radius_out = radius_out; + m_phi = phi; + + // if the deviation point is out of the inner ring, throw an error + if (Ox * Ox + Oy * Oy > radius_in * radius_in){ + THROW_EXCEPTION("\n \n ERROR!!! \n THE DEVIATION POINT IS OUT OF THE INNER RING!!! \n \n"); + } + + // if the outer ring is smaller than the inner ring, throw an error + if (radius_out < radius_in){ + THROW_EXCEPTION("\n \n ERROR!!! \n THE OUTTER RING IS SMALLER THAN THE INNER RING!!! \n \n"); + } + + // if the inner ring has negative radius, throw an error + if (radius_in < 0){ + THROW_EXCEPTION("\n \n ERROR!!! \n THE INNER RING IS NEGATIVE!!! \n \n"); + } + + // if the outer ring has non-positive radius, throw an error + if (radius_out <= 0){ + THROW_EXCEPTION("\n \n ERROR!!! \n THE OUTTER RING MUST BE POSITIVE!!! \n \n"); + } +} + +void GeoAnnulusSurface::exec(GeoShapeAction *action) const{ + action->handleAnnulusSurface(this); +} + +bool GeoAnnulusSurface::isOnSurface(const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const{ + GeoTrf::Vector3D P_prime(Px, Py, Pz); + Eigen::Vector4d P_prime_4d(Px, Py, Pz, 1.0); + P_prime_4d = trans.inverse() * P_prime_4d; + double Pp_x = P_prime_4d[0]; + double Pp_y = P_prime_4d[1]; + double Pp_z = P_prime_4d[2]; + + if(Pp_z != 0 && Pp_z > 1e-5 && Pp_z < -1e-5){ + // now I take tolerance as 1e-5 + return false; + } + + // The Annulus Shape starts from theta = 0 + double real_theta = this -> getPhi(); + int quotient = floor(real_theta/(2.0*M_PI)); + double theta = real_theta - quotient*2.0*M_PI; + + if (theta == 0.0 && real_theta > 0.0){ + theta = 2.0*M_PI; + } + // std::cout << "theta: " << theta << std::endl; + + double radius_in = this -> getRadiusIn(); + double radius_out = this -> getRadiusOut(); + double Ox = this -> getOx(); + double Oy = this -> getOy(); + + // Make sure the Point is located in the general Annulus Ring + if (Pp_x * Pp_x + Pp_y * Pp_y - radius_in * radius_in < -1e-5 || Pp_x * Pp_x + Pp_y * Pp_y - radius_out * radius_out > 1e-5){ + // std::cout << " RADIUS " << Pp_x * Pp_x + Pp_y * Pp_y << std::endl; + // std::cout << "FLAG 2" << std::endl; + return false; + } + // else if (Pp_x * Pp_x + Pp_y * Pp_y < radius_in * radius_in || Pp_x * Pp_x + Pp_y * Pp_y > radius_out * radius_out){ + // std::cout << " RADIUS QUESTIONED" << Pp_x * Pp_x + Pp_y * Pp_y << std::endl; + // } + + // Make sure the Point is located in the Deviated Circular Sector + double Dx = Pp_x - Ox; // X direction distance from the deviation center to the point + double Dy = Pp_y - Oy; // Y direction distance from the deviation center to the point + // std::cout << "Dx: " << Dx << " Dy: " << Dy << std::endl; + + double angle = atan2(Dy, Dx); // the range of atan2 is (-pi, pi] + if (angle < 0.0){ + angle += 2*M_PI; + } + // std::cout << "angle: " << angle << " theta: " << theta << std::endl; + if (angle <= theta){ + return true; + } + else{ + // std::cout << "FLAG 3" << std::endl; + return false; + } + +} + +// double GeoAnnulusSurface::area() const{} diff --git a/GeoModelCore/GeoModelKernel/src/GeoBox.cxx b/GeoModelCore/GeoModelKernel/src/GeoBox.cxx index 60b44f062aa1ccb569bc53f4cbd79ba70ef1d149..5d5ded7d12e18178e34efb61be0a801ca9737b6e 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoBox.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoBox.cxx @@ -1,20 +1,20 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoBox.h" #include "GeoModelKernel/GeoShapeAction.h" const std::string GeoBox::s_classType = "Box"; -const ShapeType GeoBox::s_classTypeID = 0x10; +const ShapeType GeoBox::s_classTypeID = 0x10; // 16 GeoBox::GeoBox (double XHalfLength, double YHalfLength, double ZHalfLength): m_xHalfLength {XHalfLength}, m_yHalfLength {YHalfLength}, - m_zHalfLength {ZHalfLength} {} + m_zHalfLength {ZHalfLength} +{} - -double GeoBox::volume () const { +double GeoBox::volume (int) const { return 8.0 * m_xHalfLength * m_yHalfLength * m_zHalfLength; } @@ -35,7 +35,6 @@ bool GeoBox::contains (double x, double y, double z) const { return (std::max(std::max(distx, disty), distz) <= 0.0); } - void GeoBox::exec (GeoShapeAction *action) const { action->handleBox(this); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoClearAbsPosAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoClearAbsPosAction.cxx index 7383e12e342f6524a8a40629729f1e311935457a..307223527d494fde348e905bdd4e407bea498fec 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoClearAbsPosAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoClearAbsPosAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoClearAbsPosAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoCons.cxx b/GeoModelCore/GeoModelKernel/src/GeoCons.cxx index 2fcad24bf54f8c73bb8db7c7b7946ee0f9a0d721..3c0f6428c6f93991b1f9129379dcb302389f6c3b 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoCons.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoCons.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoCons.h" @@ -17,11 +17,9 @@ GeoCons::GeoCons (double RMin1, double RMin2, double RMax1, double RMax2, double , m_dZ (DZ) , m_sPhi (SPhi) , m_dPhi (DPhi) -{ -} - +{} -double GeoCons::volume () const +double GeoCons::volume (int) const { return (m_dPhi * (1./3.)) * m_dZ * (m_rMax1 * m_rMax1 + m_rMax2 * m_rMax2 + m_rMax1 * m_rMax2 - @@ -59,8 +57,6 @@ bool GeoCons::contains (double x, double y, double z) const return (m_dPhi <= M_PI) ? (ds <= 0 && de <= 0) : (ds <= 0 || de <= 0); } - - void GeoCons::exec (GeoShapeAction *action) const { action->handleCons(this); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoCountSurfaceAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoCountSurfaceAction.cxx new file mode 100755 index 0000000000000000000000000000000000000000..d81389bd58a40e4a4d9999984ada6fd0ff42e3fe --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoCountSurfaceAction.cxx @@ -0,0 +1,18 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#include "GeoModelKernel/GeoCountSurfaceAction.h" + +GeoCountSurfaceAction::GeoCountSurfaceAction () +{ + setDepthLimit (1); +} + +GeoCountSurfaceAction::~GeoCountSurfaceAction() = default; + +void GeoCountSurfaceAction::handleVSurface (const GeoVSurface *) +{ + // count the number of all virtual surfaces. + m_count++; +} diff --git a/GeoModelCore/GeoModelKernel/src/GeoCountVolAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoCountVolAction.cxx index 1299bf0457591241698d5beae9416f3d6a4a9497..9d65fc51878553460eb5c95ae052456f44ab5d11 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoCountVolAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoCountVolAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoCountVolAction.h" @@ -32,6 +32,13 @@ void GeoCountVolAction::handleFullPhysVol (const GeoFullPhysVol *) m_count++; } +void GeoCountVolAction::handleVSurface (const GeoVSurface *) +{ + // Virtual Surface is always child of Physical Volume + m_count++; +} + + void GeoCountVolAction::handleSerialTransformer (const GeoSerialTransformer *st) { m_count += st->getNCopies (); diff --git a/GeoModelCore/GeoModelKernel/src/GeoCountVolAndSTAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoCountVolAndSTAction.cxx index 1bc7b55b01357eeb45cd8c2ee34e1c44e4f0c73f..cd612b29c0ff4975c0c2d32279b93751149b109a 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoCountVolAndSTAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoCountVolAndSTAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoCountVolAndSTAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx index 884503f5d984dad8ebe44c78d3d750f4dae9dd7f..8f4e43578e7c327c3abaa5141ce7d9c945ce61b3 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoCutVolAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoDefinitions.cxx b/GeoModelCore/GeoModelKernel/src/GeoDefinitions.cxx index 79dd1b7a0d867ad17ac3cd1b9bb78d90bfdb7e0d..01e49145c2881318c2e67e23a86d456c12d39e48 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoDefinitions.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoDefinitions.cxx @@ -7,7 +7,7 @@ #include <cmath> namespace { - constexpr double rotTolerance = 0.01 * GeoModelKernelUnits::deg; + constexpr double rotTolerance = 0.001 * GeoModelKernelUnits::deg; inline double cutOff(const double val, const double cutOff) { return std::abs(val) > cutOff ? val : 0.; @@ -91,6 +91,10 @@ namespace GeoTrf { EulerAngles::operator bool() const { return std::abs(phi) > rotTolerance || std::abs(theta) > rotTolerance || std::abs(psi) > rotTolerance; } + EulerAngles EulerAngles::inverse() const { + return getGeoRotationAngles(GeoRotation(*this).inverse()); + } + int CoordEulerAngles::compare(const CoordEulerAngles& other) const { if (std::abs(alpha - other.alpha) > rotTolerance) return alpha < other.alpha ? -1 : 1; @@ -104,6 +108,21 @@ namespace GeoTrf { CoordEulerAngles::operator bool() const { return std::abs(alpha) > rotTolerance || std::abs(beta) > rotTolerance || std::abs(gamma) > rotTolerance; } + CoordEulerAngles CoordEulerAngles::inverse() const { + return getCoordRotationAngles(GeoRotation(*this).inverse()); + } + + GeoTransformRT::GeoTransformRT(const EulerAngles& angles, const Vector3D& trans): + GeoTransformRT{GeoRotation{angles}, trans}{} + + + GeoTransformRT::GeoTransformRT(const CoordEulerAngles&angles, const Vector3D& trans): + GeoTransformRT{GeoRotation{angles}, trans} { + + } + + GeoTransformRT::GeoTransformRT(const GeoRotation& rot, const Vector3D& trans): + Transform3D(Translation3D(trans)*Transform3D(AngleAxis3D(rot))){} } diff --git a/GeoModelCore/GeoModelKernel/src/GeoDiamondSurface.cxx b/GeoModelCore/GeoModelKernel/src/GeoDiamondSurface.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e4d04b77c6930e3c0b191ecf3be9d3092a407c1a --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoDiamondSurface.cxx @@ -0,0 +1,51 @@ +#include "GeoModelKernel/GeoDiamondSurface.h" + +const std::string GeoDiamondSurface::s_classType = "DiamondSurface"; +const ShapeType GeoDiamondSurface::s_classTypeID = 37; // here use decimal numbers for simplicity + +GeoDiamondSurface::GeoDiamondSurface (double X_bottom_half, double X_mid_half, double X_top_half, double Y_bottom_half, double Y_top_half): + m_XbottomHalf {X_bottom_half}, + m_XmidHalf {X_mid_half}, + m_XtopHalf {X_top_half}, + m_YbottomHalf {Y_bottom_half}, + m_YtopHalf {Y_top_half} {} + + +double GeoDiamondSurface::area () const { + return (m_XmidHalf+m_XtopHalf)*m_YtopHalf + (m_XmidHalf+m_XbottomHalf)*m_YbottomHalf; +} + +void GeoDiamondSurface::exec (GeoShapeAction *action) const { + action->handleDiamondSurface(this); +} + +bool GeoDiamondSurface::isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const{ + GeoTrf::Vector3D P_prime(Px, Py, Pz); + Eigen::Vector4d P_prime_4d(Px, Py, Pz, 1.0); + P_prime_4d = trans.inverse() * P_prime_4d; + double Pp_x = P_prime_4d[0]; + double Pp_y = P_prime_4d[1]; + double Pp_z = P_prime_4d[2]; + + if(Pp_z != 0 && Pp_z > 1e-5 && Pp_z < -1e-5){ + // now I take tolerance as 1e-5 + return false; + } + + double x_bot = this -> getXbottomHalf(); double y_bot = this -> getYbottomHalf(); + double x_mid = this -> getXmidHalf(); + double x_top = this -> getXtopHalf(); double y_top = this -> getYtopHalf(); + double p1x = x_bot; double p1y = -y_bot; + double p2x = x_mid; double p2y = 0.0; + double p3x = x_top; double p3y = y_top; + double p4x = -x_top; double p4y = y_top; + double p5x = -x_mid; double p5y = 0.0; + double p6x = -x_bot; double p6y = -y_bot; + if( (p2x-p1x)*(Pp_y-p1y) - (p2y-p1y)*(Pp_x-p1x) < -1e-5 ) return false; + if( (p3x-p2x)*(Pp_y-p2y) - (p3y-p2y)*(Pp_x-p2x) < -1e-5 ) return false; + if( (p4x-p3x)*(Pp_y-p3y) - (p4y-p3y)*(Pp_x-p3x) < -1e-5 ) return false; + if( (p5x-p4x)*(Pp_y-p4y) - (p5y-p4y)*(Pp_x-p4x) < -1e-5 ) return false; + if( (p6x-p5x)*(Pp_y-p5y) - (p6y-p5y)*(Pp_x-p5x) < -1e-5 ) return false; + if( (p1x-p6x)*(Pp_y-p6y) - (p1y-p6y)*(Pp_x-p6x) < -1e-5 ) return false; + return true; +} diff --git a/GeoModelCore/GeoModelKernel/src/GeoElement.cxx b/GeoModelCore/GeoModelKernel/src/GeoElement.cxx index 5b4db7973ec723596a706918b37626162404cd54..d2225aeb4762ef514d72eded70ffd6a5342feb09 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoElement.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoElement.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoElement.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoEllipticalTube.cxx b/GeoModelCore/GeoModelKernel/src/GeoEllipticalTube.cxx index e356b15e1ac2b6c5805fe1b2f28001d0d2c741dd..4a3a0c5edbc190debdaedadf26b1b95f07ba3ae1 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoEllipticalTube.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoEllipticalTube.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPolyhedrizeAction.h" @@ -11,12 +11,12 @@ const std::string GeoEllipticalTube::s_classType = "EllipticalTube"; const ShapeType GeoEllipticalTube::s_classTypeID = 0x22; GeoEllipticalTube::GeoEllipticalTube(double XHalfLength, double YHalfLength, double ZHalfLength): - m_xHalfLength{XHalfLength}, - m_yHalfLength{YHalfLength}, - m_zHalfLength{ZHalfLength} {} + m_xHalfLength{XHalfLength}, + m_yHalfLength{YHalfLength}, + m_zHalfLength{ZHalfLength} +{} - -double GeoEllipticalTube::volume () const +double GeoEllipticalTube::volume (int) const { #ifndef M_PI constexpr double M_PI = 3.14159265358979323846; @@ -42,7 +42,6 @@ bool GeoEllipticalTube::contains (double x, double y, double z) const (y * y) / (m_yHalfLength * m_yHalfLength) <= 1.0); } - void GeoEllipticalTube::exec (GeoShapeAction *action) const { action->handleEllipticalTube(this); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoFacet.cxx b/GeoModelCore/GeoModelKernel/src/GeoFacet.cxx index b231bec81a1130d6c41ce5313fa22af70c66c239..1ddd24a6ecf01b269b59ee17ac99537c6fff4fca 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoFacet.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoFacet.cxx @@ -1,7 +1,9 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ +#include <utility> + #include "GeoModelKernel/GeoFacet.h" // ___________________ Triangular Facet ________________________ @@ -14,9 +16,9 @@ GeoTriangularFacet::GeoTriangularFacet(GeoFacetVertex v0 m_nVertices = 3; m_vertexType = type; m_vertices.reserve(3); - m_vertices[0] = v0; - m_vertices[1] = v1; - m_vertices[2] = v2; + m_vertices[0] = std::move(v0); + m_vertices[1] = std::move(v1); + m_vertices[2] = std::move(v2); } @@ -32,9 +34,9 @@ GeoQuadrangularFacet::GeoQuadrangularFacet(GeoFacetVertex v0 m_nVertices = 4; m_vertexType = type; m_vertices.reserve(4); - m_vertices[0] = v0; - m_vertices[1] = v1; - m_vertices[2] = v2; - m_vertices[3] = v3; + m_vertices[0] = std::move(v0); + m_vertices[1] = std::move(v1); + m_vertices[2] = std::move(v2); + m_vertices[3] = std::move(v3); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoFullPhysVol.cxx b/GeoModelCore/GeoModelKernel/src/GeoFullPhysVol.cxx index f1707f72d2060d34c5e357d3a98486ce87f637da..c3c09efc74e54110f526e48e44ec0d1dbf4dbd41 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoFullPhysVol.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoFullPhysVol.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoFullPhysVol.h" @@ -57,7 +57,7 @@ void GeoFullPhysVol::exec(GeoNodeAction *action) const { GeoFullPhysVol* GeoFullPhysVol::clone(bool attached) { GeoFullPhysVol* clone = new GeoFullPhysVol(this->getLogVol()); - for(auto daughter : m_daughters) { + for(const auto& daughter : m_daughters) { clone->add(daughter); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoGenericTrap.cxx b/GeoModelCore/GeoModelKernel/src/GeoGenericTrap.cxx index 31e1b31b884b2812229c554639c88a4cc4b24fcb..9cff4f84a00aa69cff421200db50b8faba9b9358 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoGenericTrap.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoGenericTrap.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoGenericTrap.h" @@ -10,10 +10,10 @@ const ShapeType GeoGenericTrap::s_classTypeID = 0x23; GeoGenericTrap::GeoGenericTrap(double ZHalfLength, const GeoGenericTrapVertices& Vertices) : m_zHalfLength(ZHalfLength) - , m_vertices(Vertices) {} + , m_vertices(Vertices) +{} - -double GeoGenericTrap::volume() const +double GeoGenericTrap::volume(int) const { // diagonals GeoTwoVector a = m_vertices[3] - m_vertices[1]; diff --git a/GeoModelCore/GeoModelKernel/src/GeoGraphNode.cxx b/GeoModelCore/GeoModelKernel/src/GeoGraphNode.cxx index d39f2cd75ba856c116642e35b83f6ffe318b1c4c..9872b364699ab030adaeaf6b0e9d3bb389ba609c 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoGraphNode.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoGraphNode.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoGraphNode.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoIdentifierTag.cxx b/GeoModelCore/GeoModelKernel/src/GeoIdentifierTag.cxx index fe6a9bf5fd6f958e503a3ab74625e40e53048cab..df18f9cceb85b188eeb42bc67ea43ad9e169646d 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoIdentifierTag.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoIdentifierTag.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoIdentifierTag.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoLogVol.cxx b/GeoModelCore/GeoModelKernel/src/GeoLogVol.cxx index 3f86839f0cb12d028b2ad3cd8f138daaf1c7c201..394b2d64d931fad8f60542f0413a1d9452618e14 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoLogVol.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoLogVol.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoLogVol.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoMaterial.cxx b/GeoModelCore/GeoModelKernel/src/GeoMaterial.cxx index bff4f32ebe1d37931205715fe18ef8a860525e62..af658278215afe4f43d93a6c18787fbb805f9e85 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoMaterial.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoMaterial.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoMaterial.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoNameTag.cxx b/GeoModelCore/GeoModelKernel/src/GeoNameTag.cxx index 1dc26acea3e08f7c0bcc7516015291edb90dcdfc..cfab262a9bcd170c00948f6e88f4577a60d04a57 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoNameTag.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoNameTag.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoNameTag.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoNodeAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoNodeAction.cxx index e4164026dad22e33deee9fa3d5a12bdc3ae80285..7732f697cdeb03dfde1ec6651862577715f87332 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoNodeAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoNodeAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoNodeAction.h" @@ -80,3 +80,18 @@ void GeoNodeAction::handleIdentifierTag (const GeoIdentifierTag *) void GeoNodeAction::handleSerialIdentifier(const GeoSerialIdentifier *) { } + +void GeoNodeAction::handleVSurface (const GeoVSurface *surface) { +} + +void GeoNodeAction::handleRectSurface (const GeoRectSurface *rect) { +} + +void GeoNodeAction::handleTrapezoidSurface (const GeoTrapezoidSurface *trapezoid) { +} + +void GeoNodeAction::handleAnnulusSurface (const GeoAnnulusSurface *annulus) { +} + +void GeoNodeAction::handleDiamondSurface (const GeoDiamondSurface *diamond) { +} \ No newline at end of file diff --git a/GeoModelCore/GeoModelKernel/src/GeoNodePositioning.cxx b/GeoModelCore/GeoModelKernel/src/GeoNodePositioning.cxx index 51914d11d9bb9850a3a767c9aff69b6f9153c3ba..dc33be766178100100d9b26cea05676e683178be 100644 --- a/GeoModelCore/GeoModelKernel/src/GeoNodePositioning.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoNodePositioning.cxx @@ -3,6 +3,7 @@ */ #include "GeoModelKernel/GeoNodePositioning.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelKernel/GeoVPhysVol.h" #include <mutex> @@ -19,7 +20,7 @@ GeoNodePositioning::GeoNodePositioning(const GeoPlacement* node): GeoTrf::Transform3D tProd{GeoTrf::Transform3D::Identity()}; if(m_node->isShared()) { - throw std::runtime_error("GeoPlacement node is shared"); + THROW_EXCEPTION("GeoPlacement node is shared"); } GeoIntrusivePtr<const GeoPlacement> child{m_node}, parent{m_node->getParent()}; while (parent) { @@ -27,7 +28,7 @@ GeoNodePositioning::GeoNodePositioning(const GeoPlacement* node): tProd = transform * tProd; child = parent; if(child->isShared()) { - throw std::runtime_error("GeoPlacement node is shared."); + THROW_EXCEPTION("GeoPlacement node is shared."); } else { parent = child->getParent(); } @@ -70,7 +71,7 @@ const GeoTrf::Transform3D& GeoNodePositioning::getCachedAbsoluteTransform(const assert(storedPos != nullptr); if(storedPos) return *storedPos; } - throw std::runtime_error("Failed to find the cached absolute transform "); + THROW_EXCEPTION("Failed to find the cached absolute transform "); } void GeoNodePositioning::clearPositionInfo() const { @@ -115,7 +116,7 @@ const GeoTrf::Transform3D& if(storedPos) return *storedPos; } - throw std::runtime_error("Failed to find the cached default absolute transform. "); + THROW_EXCEPTION("Failed to find the cached default absolute transform. "); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoPara.cxx b/GeoModelCore/GeoModelKernel/src/GeoPara.cxx index c1634dee1b6ee639b4d7da5e948d152f0d8148eb..e13e431b0c7031048b63d836d29ae57aed0b35f6 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPara.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPara.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include <cmath> @@ -19,9 +19,7 @@ m_alpha (Alpha), m_phi (Phi) {} - - -double GeoPara::volume () const +double GeoPara::volume (int) const { return 8.0 * m_xHalfLength * m_yHalfLength * m_zHalfLength; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx b/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx index 858cfdf128c828f26222d926e5e505781de77143..f294264bcc0ecb10a7541b0ae73c18b1a3ae1056 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPcon.h" #include "GeoModelKernel/GeoShapeAction.h" +#include "GeoModelKernel/throwExcept.h" #include <cmath> #include <stdexcept> @@ -13,14 +14,12 @@ const ShapeType GeoPcon::s_classTypeID = 0x13; GeoPcon::GeoPcon (double SPhi, double DPhi) : m_sPhi (SPhi) , m_dPhi (DPhi) -{ -} - +{} -double GeoPcon::volume () const +double GeoPcon::volume (int) const { if (!isValid ()) - throw std::runtime_error ("Volume requested for incomplete polycone"); + THROW_EXCEPTION("Volume requested for incomplete polycone"); double vol = 0; for (size_t k = 0; k < getNPlanes() - 1; ++k) { @@ -40,7 +39,7 @@ void GeoPcon::extent (double& xmin, double& ymin, double& zmin, double& xmax, double& ymax, double& zmax) const { if (!isValid ()) - throw std::runtime_error ("Extent requested for incomplete polycone"); + THROW_EXCEPTION("Extent requested for incomplete polycone"); double rmin = getRMinPlane(0); double rmax = getRMaxPlane(0); zmin = zmax = getZPlane(0); diff --git a/GeoModelCore/GeoModelKernel/src/GeoPerfUtils.cxx b/GeoModelCore/GeoModelKernel/src/GeoPerfUtils.cxx index 57405a2ddd4cad35317ecf829c51dc48dcc5e589..83175c1651b23e36fb9f9517b789c5bc13aa5f29 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPerfUtils.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPerfUtils.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPerfUtils.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx b/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx index dd8a2d9e6bed67008163e6c693c7317f9169bb87..1a55a617ec16bc873408dbe66a0fc1750cb3d7e3 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPgon.h" #include "GeoModelKernel/GeoShapeAction.h" +#include "GeoModelKernel/throwExcept.h" #include <cmath> #include <stdexcept> @@ -14,16 +15,12 @@ GeoPgon::GeoPgon (double SPhi, double DPhi, unsigned int NSides) : m_sPhi (SPhi) , m_dPhi (DPhi) , m_nSides (NSides) -{ -} +{} + +double GeoPgon::volume (int) const { -double GeoPgon::volume () const -{ -#ifndef M_PI - constexpr double M_PI = 3.14159265358979323846; -#endif if (!isValid ()) - throw std::runtime_error ("Volume requested for incomplete polygon"); + THROW_EXCEPTION("Volume requested for incomplete polygon"); double vol = 0.0; for (size_t k = 0; k < getNPlanes() - 1; ++k) { double z1 = getZPlane(k); @@ -46,11 +43,9 @@ double GeoPgon::volume () const void GeoPgon::extent (double& xmin, double& ymin, double& zmin, double& xmax, double& ymax, double& zmax) const { -#ifndef M_PI - constexpr double M_PI = 3.14159265358979323846; -#endif + if (!isValid ()) - throw std::runtime_error ("Extent requested for incomplete polygon"); + THROW_EXCEPTION("Extent requested for incomplete polygon"); double rmin = getRMinPlane(0); double rmax = getRMaxPlane(0); zmin = zmax = getZPlane(0); diff --git a/GeoModelCore/GeoModelKernel/src/GeoPlacement.cxx b/GeoModelCore/GeoModelKernel/src/GeoPlacement.cxx index e1d1fae373c9e6c9223f482aa3e862b09992a83a..b59161d4f437502f5cafce8ef1319eb300c58139 100644 --- a/GeoModelCore/GeoModelKernel/src/GeoPlacement.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPlacement.cxx @@ -4,6 +4,7 @@ #include "GeoModelKernel/GeoPlacement.h" #include "GeoModelKernel/GeoSerialTransformer.h" #include "GeoModelKernel/GeoVPhysVol.h" +#include "GeoModelKernel/GeoVSurface.h" #include "GeoModelKernel/GeoTransform.h" @@ -30,7 +31,7 @@ GeoTrf::Transform3D GeoPlacement::getX(const GeoVAlignmentStore* store) const { // // Check we are not shared: // - if (isShared()) throw std::runtime_error("Transform requested from shared volume"); + if (isShared()) THROW_EXCEPTION("Transform requested from shared volume"); GeoTrf::Transform3D xform{GeoTrf::Transform3D::Identity()}; if (!m_parentPtr) { @@ -49,6 +50,11 @@ GeoTrf::Transform3D GeoPlacement::getX(const GeoVAlignmentStore* store) const { if (dynamic_cast<const GeoVPhysVol *>(*current)) break; // //-------------------------------------------------------------------// + // If this happens, we are done, compute & return--------------------// + // // + if (dynamic_cast<const GeoVSurface *>(*current)) break; // + //-------------------------------------------------------------------// + // If this happens, we are done, compute & return--------------------// // // if (dynamic_cast<const GeoSerialTransformer *>(*current)) break; // @@ -68,7 +74,7 @@ GeoTrf::Transform3D GeoPlacement::getDefX(const GeoVAlignmentStore* store) const // // Check we are not shared: // - if (isShared()) throw std::runtime_error("Transform requested from shared volume"); + if (isShared()) THROW_EXCEPTION("Transform requested from shared volume"); GeoTrf::Transform3D xform{GeoTrf::Transform3D::Identity()}; if (!m_parentPtr) { @@ -88,6 +94,11 @@ GeoTrf::Transform3D GeoPlacement::getDefX(const GeoVAlignmentStore* store) const if (dynamic_cast<const GeoVPhysVol *>(*current)) break; // //-------------------------------------------------------------------// + // If this happens, we are done, compute & return--------------------// + // // + if (dynamic_cast<const GeoVSurface *>(*current)) break; // + //-------------------------------------------------------------------// + // If this happens, we are done, compute & return--------------------// // // if (dynamic_cast<const GeoSerialTransformer *>(*current)) break; // diff --git a/GeoModelCore/GeoModelKernel/src/GeoPolyhedrizeAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoPolyhedrizeAction.cxx index c4f0d8b8b67a44d140f6603176da03918e53b55c..4d07344d376721edac4eee4d39278cdf869edf9d 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPolyhedrizeAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPolyhedrizeAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPolyhedrizeAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoPolyhedron.cxx b/GeoModelCore/GeoModelKernel/src/GeoPolyhedron.cxx index 03ad65eb05a2b45272d538e73626af74c39442e5..cd5bbb2be0b24a6905cbbefd66e523400cb9afd6 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPolyhedron.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPolyhedron.cxx @@ -7,7 +7,7 @@ #define perMillion 0.000001 #define deg (M_PI/180.0) -#include <float.h> //G.Barrand : to have DBL_EPSILON on Windows. +#include <cfloat> //G.Barrand : to have DBL_EPSILON on Windows. // G.Barrand : introduce iabs to avoid a mess with cmath and some compiler. inline int @@ -413,8 +413,8 @@ GeoPolyhedron::RotateEdge (int k1, int k2, double r1, double r2, } void -GeoPolyhedron::SetSideFacets (int ii[4], int vv[4], - int *kk, double *r, +GeoPolyhedron::SetSideFacets (const int ii[4], int vv[4], + const int *kk, const double *r, double dphi, int ns, int &kface) /*********************************************************************** * * diff --git a/GeoModelCore/GeoModelKernel/src/GeoPrintGraphAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoPrintGraphAction.cxx index 7ff1252d7cb02c341205e925ef52920108ee6759..7e951a8a4e9f2d8b94412f3b7ad9f80894466ae7 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoPrintGraphAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPrintGraphAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoPrintGraphAction.h" @@ -86,6 +86,47 @@ void GeoPrintGraphAction::handleIdentifierTag (const GeoIdentifierTag *idTag) } } + +// Handle GeoVSurface +void GeoPrintGraphAction::handleVSurface (const GeoVSurface *surface) { + indent(); + m_o << " Virtual Surface" << std::endl; + m_pendingTransformList.erase(m_pendingTransformList.begin(),m_pendingTransformList.end()); + m_indented=false; +} + + // Handle GeoRectSurface +void GeoPrintGraphAction::handleRectSurface (const GeoRectSurface *surface) { + indent(); + m_o << " Rectangle Surface" << std::endl; + m_pendingTransformList.erase(m_pendingTransformList.begin(),m_pendingTransformList.end()); + m_indented=false; +} + + // Handle GeoTrapezoidSurface +void GeoPrintGraphAction::handleTrapezoidSurface (const GeoTrapezoidSurface *surface) { + indent(); + m_o << " Trapezoid Surface" << std::endl; + m_pendingTransformList.erase(m_pendingTransformList.begin(),m_pendingTransformList.end()); + m_indented=false; +} + + // Handle GeoAnnulusSurface +void GeoPrintGraphAction::handleAnnulusSurface (const GeoAnnulusSurface *surface) { + indent(); + m_o << " Annulus Surface" << std::endl; + m_pendingTransformList.erase(m_pendingTransformList.begin(),m_pendingTransformList.end()); + m_indented=false; +} + + // Handle GeoDiamondSurface +void GeoPrintGraphAction::handleDiamondSurface (const GeoDiamondSurface *surface) { + indent(); + m_o << " Diamond Surface" << std::endl; + m_pendingTransformList.erase(m_pendingTransformList.begin(),m_pendingTransformList.end()); + m_indented=false; +} + void GeoPrintGraphAction::setNotification (Type type, bool state) { if (type==TRANSFORM) { diff --git a/GeoModelCore/GeoModelKernel/src/GeoPublisher.cxx b/GeoModelCore/GeoModelKernel/src/GeoPublisher.cxx index 74b9244eec9fca348d5c5997a8515bd5498ae845..99874c512ef66a0166e14cca915a042b643a72bb 100644 --- a/GeoModelCore/GeoModelKernel/src/GeoPublisher.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoPublisher.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // Author: Riccardo Maria Bianchi @ CERN @@ -13,6 +13,7 @@ // C++ includes #include <iostream> +#include <utility> @@ -29,7 +30,7 @@ std::map<GeoAlignableTransform*, std::any> GeoPublisher::getPublishedAXF() void GeoPublisher::setName(std::string name) { - m_name = name; + m_name = std::move(name); } /* @@ -40,9 +41,9 @@ void GeoPublisher::storeDataTable( std::string tableName, std::vector<std::strin } */ -void GeoPublisher::storeDataTable( std::string tableName, std::vector<std::string> colNames, std::vector<std::string> colTypes, std::vector<std::vector<std::variant<int,long,float,double,std::string>>> tableData ) +void GeoPublisher::storeDataTable( const std::string& tableName, const std::vector<std::string>& colNames, const std::vector<std::string>& colTypes, std::vector<std::vector<std::variant<int,long,float,double,std::string>>> tableData ) { m_auxiliaryTablesVar[ tableName ] = std::make_pair(colNames, colTypes); - m_auxiliaryTablesVarData[ tableName ] = tableData; + m_auxiliaryTablesVarData[ tableName ] = std::move(tableData); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoRectSurface.cxx b/GeoModelCore/GeoModelKernel/src/GeoRectSurface.cxx index 3d267b2684941e6792d64ad984c10254542234e7..c999cb2ef5c0e3e60e0acf8c075de8f99b3a97f2 100644 --- a/GeoModelCore/GeoModelKernel/src/GeoRectSurface.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoRectSurface.cxx @@ -1,5 +1,8 @@ #include "GeoModelKernel/GeoRectSurface.h" +const std::string GeoRectSurface::s_classType = "RectangleSurface"; +const ShapeType GeoRectSurface::s_classTypeID = 34; // here use decimal numbers for simplicity + GeoRectSurface::GeoRectSurface (double XHalfLength, double YHalfLength): m_xHalfLength {XHalfLength}, m_yHalfLength {YHalfLength} {} @@ -9,3 +12,32 @@ double GeoRectSurface::area () const { return 4.0 * m_xHalfLength * m_yHalfLength; } +void GeoRectSurface::exec (GeoShapeAction *action) const { + action->handleRectSurface(this); +} + +bool GeoRectSurface::isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const{ + GeoTrf::Vector3D P_prime(Px, Py, Pz); + Eigen::Vector4d P_prime_4d(Px, Py, Pz, 1.0); + P_prime_4d = trans.inverse() * P_prime_4d; + double Pp_x = P_prime_4d[0]; + double Pp_y = P_prime_4d[1]; + double Pp_z = P_prime_4d[2]; + + if(Pp_z != 0 && Pp_z > 1e-5 && Pp_z < -1e-5){ + // now I take tolerance as 1e-5 + return false; + } + + double half_x = this -> getXHalfLength(); + double half_y = this -> getYHalfLength(); + double p1x = half_x; double p1y = -half_y; + double p2x = half_x; double p2y = half_y; + double p3x = -half_x; double p3y = half_y; + double p4x = -half_x; double p4y = -half_y; + if( (p2x-p1x)*(Pp_y-p1y) - (p2y-p1y)*(Pp_x-p1x) < -1e-5 ) return false; + if( (p3x-p2x)*(Pp_y-p2y) - (p3y-p2y)*(Pp_x-p2x) < -1e-5 ) return false; + if( (p4x-p3x)*(Pp_y-p3y) - (p4y-p3y)*(Pp_x-p3x) < -1e-5 ) return false; + if( (p1x-p4x)*(Pp_y-p4y) - (p1y-p4y)*(Pp_x-p4x) < -1e-5 ) return false; + return true; +} diff --git a/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.cxx index a1c32a6155e5614f1521547ec0f5c6af671b5e78..aa469ebbcf5ae5443b96bdadccbcf709218c5542 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoSelClearAbsPosAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.h b/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.h index 251dae80515d01ee8f32028760292c12f6f3ead2..abdcde181d02ca1d1bd69c1949bc963fdcf62ba5 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.h +++ b/GeoModelCore/GeoModelKernel/src/GeoSelClearAbsPosAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOSELCLEARABSPOSACTION_H diff --git a/GeoModelCore/GeoModelKernel/src/GeoSerialDenominator.cxx b/GeoModelCore/GeoModelKernel/src/GeoSerialDenominator.cxx index af65ced105dc4ac2cf349be0a52df970cb544240..96c1bc962d78d69eb1a9d07763ce93d12f24f5d5 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSerialDenominator.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoSerialDenominator.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoSerialDenominator.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoSerialIdentifier.cxx b/GeoModelCore/GeoModelKernel/src/GeoSerialIdentifier.cxx index c5984b9620f2e85ac4b9929a5ebf8d9d6082609e..6aa2479caab982e178d6a3b829f3219b4c56b0c1 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSerialIdentifier.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoSerialIdentifier.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoSerialIdentifier.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoSerialTransformer.cxx b/GeoModelCore/GeoModelKernel/src/GeoSerialTransformer.cxx index 99aa495ad915867c9244b7f7fa7433d685ac4dc1..dfe66684a5affa2236dca31405c6249dae78177d 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSerialTransformer.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoSerialTransformer.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoSerialTransformer.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoShape.cxx b/GeoModelCore/GeoModelKernel/src/GeoShape.cxx index 9049e957bdea100c2682bb13a9237f34745fe216..1731dc669b51827bac8be76b2492e3b55358dead 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShape.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShape.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoShape.h" @@ -7,15 +7,15 @@ #include "GeoModelKernel/GeoShapeUnion.h" #include "GeoModelKernel/GeoShapeSubtraction.h" #include "GeoModelKernel/GeoShapeShift.h" +#include <algorithm> #include <cmath> #include <cstdint> - -double GeoShape::volume () const +double GeoShape::volume (int npoints) const { - constexpr int npoints = 1000000; // number of random points constexpr double expansion = 0.001; // bounding box expansion constexpr double f = 1./4294967296.; // 2^-32 - int to double conversion + int np = std::max(npoints, 1000); // number of points is at least 1000 // set up bonding box double xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; @@ -32,7 +32,7 @@ double GeoShape::volume () const uint32_t y = 2463534242; // seed for random number generation int icount = 0; // counter of inside points - for (auto i = 0; i < npoints; ++i) + for (int i = 0; i < np; ++i) { // generate three random numbers uint32_t x = y; diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeAction.cxx index b6e7485f9511e4dd25d99881f677d8bc81d9871d..36b7f656c8d2ebd99693c3e6151a5c20a298b853 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShapeAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShapeAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoShapeAction.h" @@ -18,6 +18,10 @@ #include "GeoModelKernel/GeoTube.h" #include "GeoModelKernel/GeoTubs.h" #include "GeoModelKernel/GeoPara.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" #include "GeoModelKernel/GeoSimplePolygonBrep.h" #include "GeoModelKernel/GeoTessellatedSolid.h" @@ -64,6 +68,10 @@ void GeoShapeAction::handleShape (const GeoShape *) { } +void GeoShapeAction::handleShape (const GeoVSurfaceShape *) +{ +} + void GeoShapeAction::handleShift (const GeoShapeShift *shift) { handleShape(shift); @@ -134,6 +142,26 @@ void GeoShapeAction::handleTubs (const GeoTubs *tubs) handleShape(tubs); } +void GeoShapeAction::handleRectSurface (const GeoRectSurface *surf) +{ + handleShape(surf); +} + +void GeoShapeAction::handleTrapezoidSurface (const GeoTrapezoidSurface *surf) +{ + handleShape(surf); +} + +void GeoShapeAction::handleAnnulusSurface (const GeoAnnulusSurface *surf) +{ + handleShape(surf); +} + +void GeoShapeAction::handleDiamondSurface (const GeoDiamondSurface *surf) +{ + handleShape(surf); +} + GeoShapePath * GeoShapeAction::getPath () { return &m_path; diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeIntersection.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeIntersection.cxx index 711d2e8c7c33dde1b4bf6db3ddf1f48085ca9be2..71b9f8d75ede0d1c9c5053dba183c28b6b044206 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShapeIntersection.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShapeIntersection.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoShapeIntersection.h" @@ -15,10 +15,14 @@ GeoShapeIntersection::GeoShapeIntersection (const GeoShape* A, const GeoShape* B) : m_opA (A) , m_opB (B) {} - - -double GeoShapeIntersection::volume () const { - return fVolume < 0. ? fVolume = GeoShape::volume() : fVolume.load(); +double GeoShapeIntersection::volume (int npoints) const { + double vol = getVolumeValue(); + if (vol < 0) + { + vol = GeoShape::volume(npoints); + setVolumeValue(vol); + } + return vol; } void GeoShapeIntersection::extent (double& xmin, double& ymin, double& zmin, @@ -46,27 +50,26 @@ void GeoShapeIntersection::exec (GeoShapeAction *action) const action->getPath ()->push (this); action->handleIntersection (this); if (action->shouldTerminate ()) - { - action->getPath ()->pop (); - return; - } + { + action->getPath ()->pop (); + return; + } if (action->getDepthLimit ().isValid () && action->getPath ()->getLength () > action->getDepthLimit ()) - { - } - + { + } else { m_opA->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; - } + } m_opB->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx index 1a6072ca82f1260c0682b531177c74d925bcc90d..373a804a164f3adf6f58ce21bab64750b50d501a 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx @@ -64,24 +64,23 @@ void GeoShapeShift::exec (GeoShapeAction *action) const { action->getPath ()->push (this); action->handleShift (this); if (action->shouldTerminate ()) - { - action->getPath ()->pop (); - return; - } + { + action->getPath ()->pop (); + return; + } if (action->getDepthLimit ().isValid () && action->getPath ()->getLength () > action->getDepthLimit ()) - { - } - + { + } else - { + { m_op->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; - } + } } action->getPath()->pop(); } diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeSubtraction.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeSubtraction.cxx index 10a919f673bd1f148783bad251aecd3c530c3663..7eebbfbf23e36c0f975024e972e476d28b5f005e 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShapeSubtraction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShapeSubtraction.cxx @@ -1,8 +1,9 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeIntersection.h" #include "GeoModelKernel/GeoShapeAction.h" #include "GeoModelKernel/GeoPolyhedrizeAction.h" #include "GeoModelKernel/GeoPolyhedron.h" @@ -11,12 +12,35 @@ const std::string GeoShapeSubtraction::s_classType = "Subtraction"; const ShapeType GeoShapeSubtraction::s_classTypeID = 0x02; -GeoShapeSubtraction::GeoShapeSubtraction (const GeoShape* A, const GeoShape* B): +GeoShapeSubtraction::GeoShapeSubtraction (const GeoShape* A, const GeoShape* B): m_opA {A}, m_opB {B} {} - -double GeoShapeSubtraction::volume () const { - return (fVolume < 0.) ? (fVolume = GeoShape::volume()) : fVolume.load(); +double GeoShapeSubtraction::volume (int npoints) const { + double vol = getVolumeValue(); + if (vol < 0) + { + double xminA, yminA, zminA, xmaxA, ymaxA, zmaxA; + double xminB, yminB, zminB, xmaxB, ymaxB, zmaxB; + m_opA->extent(xminA, yminA, zminA, xmaxA, ymaxA, zmaxA); + m_opB->extent(xminB, yminB, zminB, xmaxB, ymaxB, zmaxB); + bool noIntersection = + xminA >= xmaxB || yminA >= ymaxB || zminA >= zmaxB || + xminB >= xmaxA || yminB >= ymaxA || zminB >= zmaxA; + if (noIntersection) { + vol = m_opA->volume(npoints); + } else { + if (getNoConstituents() > 10) { + vol = GeoShape::volume(npoints); + } else { + GeoIntrusivePtr<GeoShapeIntersection> tmp(new GeoShapeIntersection(m_opA, m_opB)); + double volumeA = m_opA->volume(npoints); + vol = volumeA - tmp->volume(npoints); + if (vol < 0.01*volumeA) vol = GeoShape::volume(npoints); + } + } + setVolumeValue(vol); + } + return vol; } void GeoShapeSubtraction::extent (double& xmin, double& ymin, double& zmin, @@ -30,34 +54,31 @@ bool GeoShapeSubtraction::contains (double x, double y, double z) const return (!getOpA()->contains(x, y, z)) ? false : !getOpB()->contains(x, y, z); } - - void GeoShapeSubtraction::exec (GeoShapeAction *action) const { action->getPath ()->push (this); action->handleSubtraction (this); if (action->shouldTerminate ()) - { - action->getPath ()->pop (); - return; - } + { + action->getPath ()->pop (); + return; + } if (action->getDepthLimit ().isValid () && action->getPath ()->getLength () > action->getDepthLimit ()) - { - } - + { + } else { m_opA->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; - } + } m_opB->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeUnion.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeUnion.cxx index 2acc7c70cc9dce8c03ad0313590b5650be5a84b0..f26055a03d042ee229a9f8f10d8235c74e26f423 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoShapeUnion.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoShapeUnion.cxx @@ -1,8 +1,9 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoShapeUnion.h" +#include "GeoModelKernel/GeoShapeIntersection.h" #include "GeoModelKernel/GeoShapeAction.h" #include "GeoModelKernel/GeoPolyhedron.h" #include "GeoModelKernel/GeoPolyhedrizeAction.h" @@ -11,13 +12,34 @@ const std::string GeoShapeUnion::s_classType = "Union"; const ShapeType GeoShapeUnion::s_classTypeID = 0x01; -GeoShapeUnion::GeoShapeUnion (const GeoShape* A, const GeoShape* B): +GeoShapeUnion::GeoShapeUnion (const GeoShape* A, const GeoShape* B): m_opA{A}, m_opB{B} {} - -double GeoShapeUnion::volume () const +double GeoShapeUnion::volume (int npoints) const { - return (fVolume < 0.0) ? (fVolume = GeoShape::volume()) : fVolume.load(); + double vol = getVolumeValue(); + if (vol < 0) + { + double xminA, yminA, zminA, xmaxA, ymaxA, zmaxA; + double xminB, yminB, zminB, xmaxB, ymaxB, zmaxB; + m_opA->extent(xminA, yminA, zminA, xmaxA, ymaxA, zmaxA); + m_opB->extent(xminB, yminB, zminB, xmaxB, ymaxB, zmaxB); + bool noIntersection = + xminA >= xmaxB || yminA >= ymaxB || zminA >= zmaxB || + xminB >= xmaxA || yminB >= ymaxA || zminB >= zmaxA; + if (noIntersection) { + vol = m_opA->volume(npoints) + m_opB->volume(npoints); + } else { + if (getNoConstituents() > 10) { + vol = GeoShape::volume(npoints); + } else { + GeoIntrusivePtr<GeoShapeIntersection> tmp(new GeoShapeIntersection(m_opA, m_opB)); + vol = m_opA->volume(npoints) + m_opB->volume(npoints) - tmp->volume(npoints); + } + } + setVolumeValue(vol); + } + return vol; } void GeoShapeUnion::extent (double& xmin, double& ymin, double& zmin, @@ -44,27 +66,26 @@ void GeoShapeUnion::exec (GeoShapeAction *action) const action->getPath ()->push (this); action->handleUnion (this); if (action->shouldTerminate ()) - { - action->getPath ()->pop (); - return; - } + { + action->getPath ()->pop (); + return; + } if (action->getDepthLimit ().isValid () && action->getPath ()->getLength () > action->getDepthLimit ()) - { - } - + { + } else { m_opA->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; - } + } m_opB->exec(action); if (action->shouldTerminate ()) - { + { action->getPath ()->pop (); return; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoSimplePolygonBrep.cxx b/GeoModelCore/GeoModelKernel/src/GeoSimplePolygonBrep.cxx index 2e9eb8de421bc200b92d103105fecdc83925fe85..e8c6ddfc1cac4550ed3e6eb6bd1530b29fe503f7 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoSimplePolygonBrep.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoSimplePolygonBrep.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoSimplePolygonBrep.h" #include "GeoModelKernel/GeoShapeAction.h" +#include "GeoModelKernel/throwExcept.h" #include "PolygonTriangulator.h"//For volume. #include <cmath> #include <stdexcept> @@ -12,13 +13,12 @@ const std::string GeoSimplePolygonBrep::s_classType = "SimplePolygonBrep"; const ShapeType GeoSimplePolygonBrep::s_classTypeID = 0x20; GeoSimplePolygonBrep::GeoSimplePolygonBrep(double dz) - : m_dZ(dz){} + : m_dZ(dz) +{} - - -double GeoSimplePolygonBrep::volume () const { +double GeoSimplePolygonBrep::volume (int) const { if (!isValid()) - throw std::runtime_error ("Volume requested for incomplete simple polygon brep"); + THROW_EXCEPTION("Volume requested for incomplete simple polygon brep"); int n = getNVertices(); double area = m_xVertices[n - 1] * m_yVertices[0] - m_xVertices[0] * m_yVertices[n - 1]; for (int k = 1; k < n; ++k) @@ -32,7 +32,7 @@ void GeoSimplePolygonBrep::extent (double& xmin, double& ymin, double& zmin, double& xmax, double& ymax, double& zmax) const { if (!isValid()) - throw std::runtime_error ("Extent requested for incomplete simple polygon brep"); + THROW_EXCEPTION("Extent requested for incomplete simple polygon brep"); xmin = xmax = m_xVertices[0]; ymin = ymax = m_yVertices[0]; for (size_t k = 1; k < getNVertices(); ++k) @@ -64,7 +64,6 @@ bool GeoSimplePolygonBrep::contains (double x, double y, double z) const return in; } - void GeoSimplePolygonBrep::addVertex(double XVertex, double YVertex) { m_xVertices.push_back(XVertex); diff --git a/GeoModelCore/GeoModelKernel/src/GeoSurfaceCursor.cxx b/GeoModelCore/GeoModelKernel/src/GeoSurfaceCursor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c7acd719bfd6b7043f414552dd02adb2e22275b8 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoSurfaceCursor.cxx @@ -0,0 +1,165 @@ +#include <utility> + +#include "GeoModelKernel/GeoSurfaceCursor.h" +#include "GeoModelKernel/GeoAlignableTransform.h" + +GeoSurfaceCursor::GeoSurfaceCursor (PVConstLink parent, GeoVAlignmentStore* store) + : m_parent(std::move(parent)) + , m_transform(GeoTrf::Transform3D::Identity()) + , m_defTransform(GeoTrf::Transform3D::Identity()) + , m_majorIndex(0) + , m_volCount(0) + , m_surfCount(0) + , m_alignStore(store) +{ + // depth is set to be 0, with next(), go to the child node + setDepthLimit(0); + next(); +} + +GeoSurfaceCursor::~GeoSurfaceCursor() +{ +} + +void GeoSurfaceCursor::next() { + resuscitate(); + + // not considering serial transformer + m_volume=nullptr; + m_surface=nullptr; + + m_pendingTransformList.erase (m_pendingTransformList.begin (), + m_pendingTransformList.end ()); + + int N = m_parent->getNChildNodes(); + if (N==0) return; + + const GeoGraphNode * const *node = m_parent->getChildNode(m_majorIndex); + const GeoGraphNode * const *back = m_parent->getChildNode(N-1); + const GeoGraphNode * const *end = back+1; + int i = 0;//////////// + while (node!=end) { + (*node)->exec(this); + const GeoGraphNode * const * flag = node; + + node++; + m_majorIndex++; + + if (m_terminate) { + + if (dynamic_cast<const GeoVPhysVol*> (*flag)){ + m_volCount++; + } + else if (dynamic_cast<const GeoVSurface*> (*flag)){ + m_surfCount++; + } + + break; + } + } +} + +void GeoSurfaceCursor::resuscitate() { + m_terminate = false; +} + +bool GeoSurfaceCursor::atEnd() const { + return (!m_volume and !m_surface); +} + +void GeoSurfaceCursor::handleTransform (const GeoTransform *xform) +{ + m_pendingTransformList.push_back (xform); + if(dynamic_cast<const GeoAlignableTransform*>(xform)) + m_hasAlignTrans = true; +} + +void GeoSurfaceCursor::handlePhysVol (const GeoPhysVol *vol) +{ + m_volume = vol; + + unsigned int listSize = m_pendingTransformList.size (); + if (listSize == 0) { + m_transform = GeoTrf::Transform3D::Identity(); + m_defTransform = GeoTrf::Transform3D::Identity(); + } + else { + m_transform = m_pendingTransformList[0]->getTransform(m_alignStore); + m_defTransform = m_pendingTransformList[0]->getDefTransform(m_alignStore); + for (unsigned int t = 1; t < m_pendingTransformList.size (); t++) { + m_transform = m_transform * m_pendingTransformList[t]->getTransform(m_alignStore); + m_defTransform = m_defTransform * m_pendingTransformList[t]->getDefTransform(m_alignStore); + } + } + + terminate (); +} + +void GeoSurfaceCursor::handleFullPhysVol (const GeoFullPhysVol *vol) +{ + m_volume = vol; + + unsigned int listSize = m_pendingTransformList.size (); + if (listSize == 0) { + m_transform = GeoTrf::Transform3D::Identity(); + m_defTransform = GeoTrf::Transform3D::Identity(); + } + else { + m_transform = m_pendingTransformList[0]->getTransform(m_alignStore); + m_defTransform = m_pendingTransformList[0]->getDefTransform(m_alignStore); + for (unsigned int t = 1; t < m_pendingTransformList.size (); t++) { + m_transform = m_transform * m_pendingTransformList[t]->getTransform(m_alignStore); + m_defTransform = m_defTransform * m_pendingTransformList[t]->getDefTransform(m_alignStore); + } + } + + terminate (); +} + +void GeoSurfaceCursor::handleVSurface (const GeoVSurface *surf) +{ + m_surface = surf; + + unsigned int listSize = m_pendingTransformList.size (); + if (listSize == 0) { + m_transform = GeoTrf::Transform3D::Identity(); + m_defTransform = GeoTrf::Transform3D::Identity(); + } + else { + m_transform = m_pendingTransformList[0]->getTransform(m_alignStore); + m_defTransform = m_pendingTransformList[0]->getDefTransform(m_alignStore); + for (unsigned int t = 1; t < m_pendingTransformList.size (); t++) { + m_transform = m_transform * m_pendingTransformList[t]->getTransform(m_alignStore); + m_defTransform = m_defTransform * m_pendingTransformList[t]->getDefTransform(m_alignStore); + } + } + + terminate (); +} + +GeoTrf::Transform3D GeoSurfaceCursor::getTransform () const +{ + //if (m_minorLimit) { + // return m_transform*m_serialTransformer->getTransform(m_minorIndex); + //} + //else { + return m_transform; + //} +} + +GeoTrf::Transform3D GeoSurfaceCursor::getDefTransform () const +{ + //if (m_minorLimit) { + // return m_defTransform*m_serialTransformer->getTransform(m_minorIndex); + //} + //else { + return m_defTransform; + //} +} +/* +std::string GeoSurfaceCursor::getName() const +{ + std::string name = "VSurface"; + return name; +} +*/ diff --git a/GeoModelCore/GeoModelKernel/src/GeoTessellatedSolid.cxx b/GeoModelCore/GeoModelKernel/src/GeoTessellatedSolid.cxx index 2f7a3fabcc8cd260c234e37d23480db750570662..8f1a9feffda7fbf40c016edaef2e752bda8b764e 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTessellatedSolid.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTessellatedSolid.cxx @@ -1,9 +1,9 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ - #include "GeoModelKernel/GeoTessellatedSolid.h" #include "GeoModelKernel/GeoShapeAction.h" +#include "GeoModelKernel/throwExcept.h" #include <stdexcept> const std::string GeoTessellatedSolid::s_classType = "TessellatedSolid"; @@ -13,10 +13,10 @@ GeoTessellatedSolid::GeoTessellatedSolid() { } -double GeoTessellatedSolid::volume() const +double GeoTessellatedSolid::volume(int) const { if (!isValid ()) - throw std::runtime_error ("Volume requested for incomplete tessellated solid"); + THROW_EXCEPTION("Volume requested for incomplete tessellated solid"); double v = 0.; for (size_t i = 0; i < getNumberOfFacets(); ++i) { @@ -28,7 +28,7 @@ double GeoTessellatedSolid::volume() const v += facet->getVertex(0).dot(e1.cross(e2)); } if (v < 0.) - throw std::runtime_error ("Incorrect order of vertices in tessellated solid"); + THROW_EXCEPTION("Incorrect order of vertices in tessellated solid"); return v*(1./6.); } @@ -36,7 +36,7 @@ void GeoTessellatedSolid::extent (double& xmin, double& ymin, double& zmin, double& xmax, double& ymax, double& zmax) const { if (!isValid ()) - throw std::runtime_error ("Extent requested for incomplete tessellated solid"); + THROW_EXCEPTION("Extent requested for incomplete tessellated solid"); GeoFacet* facet = getFacet(0); GeoTrf::Vector3D vertex = facet->getVertex(0); xmin = xmax = vertex.x(); @@ -63,7 +63,7 @@ void GeoTessellatedSolid::extent (double& xmin, double& ymin, double& zmin, bool GeoTessellatedSolid::contains (double x, double y, double z) const { - throw std::runtime_error ("GeoTessellatedSolid::contains(x,y,z) is not implemented"); + THROW_EXCEPTION("GeoTessellatedSolid::contains(x,y,z) is not implemented"); return false; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoTorus.cxx b/GeoModelCore/GeoModelKernel/src/GeoTorus.cxx index 717d58083cb86f0ce392077ebd7e472076a0558f..def70e3429bbc3de94b0feb3af80238133c5fb9a 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTorus.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTorus.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTorus.h" @@ -15,11 +15,9 @@ GeoTorus::GeoTorus (double Rmin, double Rmax, double Rtor, double SPhi, double D , m_rTor (Rtor) , m_sPhi (SPhi) , m_dPhi (DPhi) -{ -} - +{} -double GeoTorus::volume () const +double GeoTorus::volume (int) const { #ifndef M_PI constexpr double M_PI = 3.14159265358979323846; diff --git a/GeoModelCore/GeoModelKernel/src/GeoTransform.cxx b/GeoModelCore/GeoModelKernel/src/GeoTransform.cxx index d9543ee348bacca073c136faf8dca9d0e8b2196c..26b963e440f4ec7a6a3e27c9709bef71c6fab054 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTransform.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTransform.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTransform.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoTrap.cxx b/GeoModelCore/GeoModelKernel/src/GeoTrap.cxx index 99918eff3cb62f9a23106b61c38e940657c42b39..56adb960048a05002180cb6a47dca62d2e838321 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTrap.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTrap.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTrap.h" @@ -20,11 +20,9 @@ GeoTrap::GeoTrap (double ZHalfLength, double Theta, double Phi, double Dydzn, do , m_dxdyndzp (Dxdyndzp) , m_dxdypdzp (Dxdypdzp) , m_angleydzp (Angleydzp) -{ -} +{} - -double GeoTrap::volume () const +double GeoTrap::volume (int) const { double dz = m_zHalfLength; double dy1 = m_dydzn; @@ -108,7 +106,6 @@ bool GeoTrap::contains (double x, double y, double z) const return (std::abs(x0) - dx <= 0.0); } - void GeoTrap::exec (GeoShapeAction *action) const { action->handleTrap(this); diff --git a/GeoModelCore/GeoModelKernel/src/GeoTrapezoidSurface.cxx b/GeoModelCore/GeoModelKernel/src/GeoTrapezoidSurface.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0ce90f5bc7a2f7d8a82256a15e8b9d9d81098398 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoTrapezoidSurface.cxx @@ -0,0 +1,45 @@ +#include "GeoModelKernel/GeoTrapezoidSurface.h" + +const std::string GeoTrapezoidSurface::s_classType = "TrapezoidSurface"; +const ShapeType GeoTrapezoidSurface::s_classTypeID = 35; // here use decimal numbers for simplicity + +GeoTrapezoidSurface::GeoTrapezoidSurface (double XHalfLengthMin, double XHalfLengthMax, double YHalfLength): + m_xHalfLengthMin {XHalfLengthMin}, + m_xHalfLengthMax {XHalfLengthMax}, + m_yHalfLength {YHalfLength} {} + + +double GeoTrapezoidSurface::area () const { + return (m_xHalfLengthMin + m_xHalfLengthMax)*m_yHalfLength*2 ; +} + +void GeoTrapezoidSurface::exec (GeoShapeAction *action) const { + action->handleTrapezoidSurface(this); +} + +bool GeoTrapezoidSurface::isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const{ + GeoTrf::Vector3D P_prime(Px, Py, Pz); + Eigen::Vector4d P_prime_4d(Px, Py, Pz, 1.0); + P_prime_4d = trans.inverse() * P_prime_4d; + double Pp_x = P_prime_4d[0]; + double Pp_y = P_prime_4d[1]; + double Pp_z = P_prime_4d[2]; + + if(Pp_z != 0 && Pp_z > 1e-5 && Pp_z < -1e-5){ + // now I take tolerance as 1e-5 + return false; + } + + double half_x_max = this -> getXHalfLengthMax(); + double half_x_min = this -> getXHalfLengthMin(); + double half_y = this -> getYHalfLength(); + double p1x = half_x_min; double p1y = -half_y; + double p2x = half_x_max; double p2y = half_y; + double p3x = -half_x_max; double p3y = half_y; + double p4x = -half_x_min; double p4y = -half_y; + if( (p2x-p1x)*(Pp_y-p1y) - (p2y-p1y)*(Pp_x-p1x) < -1e-5 ) return false; + if( (p3x-p2x)*(Pp_y-p2y) - (p3y-p2y)*(Pp_x-p2x) < -1e-5 ) return false; + if( (p4x-p3x)*(Pp_y-p3y) - (p4y-p3y)*(Pp_x-p3x) < -1e-5 ) return false; + if( (p1x-p4x)*(Pp_y-p4y) - (p1y-p4y)*(Pp_x-p4x) < -1e-5 ) return false; + return true; +} diff --git a/GeoModelCore/GeoModelKernel/src/GeoTraversalState.cxx b/GeoModelCore/GeoModelKernel/src/GeoTraversalState.cxx index 644d1c9adf146c9d4fa4deeb513120b6563115c3..054f2d7eb20a99ea6b9b941282609be2fbf28bf4 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTraversalState.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTraversalState.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTraversalState.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoTrd.cxx b/GeoModelCore/GeoModelKernel/src/GeoTrd.cxx index 1e0b40c0375845a32e8bd6b198975560fdc2fb17..287e5f38f81b616e1af7ce14aaac15ae5114b808 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTrd.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTrd.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTrd.h" @@ -16,8 +16,7 @@ GeoTrd::GeoTrd (double XHalfLength1, double XHalfLength2, double YHalfLength1, d , m_zHalfLength (ZHalfLength) {} - -double GeoTrd::volume () const +double GeoTrd::volume (int) const { double fDz = m_zHalfLength; double fDy1 = m_yHalfLength1; diff --git a/GeoModelCore/GeoModelKernel/src/GeoTube.cxx b/GeoModelCore/GeoModelKernel/src/GeoTube.cxx index b05760ed7d4a8057b74829e89313ee23780580a5..431086fbd63bfeb9cc99320774a53e0add68b4dc 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTube.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTube.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTube.h" @@ -14,14 +14,9 @@ GeoTube::GeoTube (double RMin, double RMax, double ZHalfLength) : m_rMin (RMin) , m_rMax (RMax) , m_zHalfLength (ZHalfLength) -{ -} - -GeoTube::~GeoTube() -{ -} +{} -double GeoTube::volume () const +double GeoTube::volume (int) const { #ifndef M_PI constexpr double M_PI = 3.14159265358979323846; diff --git a/GeoModelCore/GeoModelKernel/src/GeoTubs.cxx b/GeoModelCore/GeoModelKernel/src/GeoTubs.cxx index 0a7776b96572a35e0a41d1795a1277265b417777..1c1a0dd9322015a5b03f7291ebf5f200b0c966c1 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTubs.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTubs.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTubs.h" @@ -15,11 +15,9 @@ GeoTubs::GeoTubs (double RMin, double RMax, double ZHalfLength, double SPhi, dou , m_zHalfLength (ZHalfLength) , m_sPhi (SPhi) , m_dPhi (DPhi) -{ -} +{} - -double GeoTubs::volume () const +double GeoTubs::volume (int) const { return m_dPhi * (m_rMax * m_rMax - m_rMin * m_rMin) * m_zHalfLength; } @@ -50,7 +48,6 @@ bool GeoTubs::contains (double x, double y, double z) const return (m_dPhi <= M_PI) ? (ds <= 0 && de <= 0) : (ds <= 0 || de <= 0); } - void GeoTubs::exec (GeoShapeAction *action) const { action->handleTubs(this); diff --git a/GeoModelCore/GeoModelKernel/src/GeoTwistedTrap.cxx b/GeoModelCore/GeoModelKernel/src/GeoTwistedTrap.cxx index 07e3c994bb8bd2d24bfba62ac458881bee417c6f..239b3d7d332d00bbafd32cf0b1813d76ddabc21e 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoTwistedTrap.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoTwistedTrap.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoTwistedTrap.h" @@ -85,7 +85,7 @@ GeoTwistedTrap(double pPhiTwist, // twist angle } -double GeoTwistedTrap::volume () const +double GeoTwistedTrap::volume (int) const { return m_dz * ((m_dx1 + m_dx2 + m_dx3 + m_dx4) * (m_dy1 + m_dy2) + (m_dx4 + m_dx3 - m_dx2 - m_dx1) * (m_dy2 - m_dy1) * (1./3.)); diff --git a/GeoModelCore/GeoModelKernel/src/GeoUnidentifiedShape.cxx b/GeoModelCore/GeoModelKernel/src/GeoUnidentifiedShape.cxx index a5292a185b981b0fdc4fec9e730c98e5ed30c02e..77433f524267cfc2934ed927f5cd6799d5941b93 100644 --- a/GeoModelCore/GeoModelKernel/src/GeoUnidentifiedShape.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoUnidentifiedShape.cxx @@ -1,14 +1,17 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ #include "GeoModelKernel/GeoUnidentifiedShape.h" #include "GeoModelKernel/Query.h" #include "GeoModelKernel/GeoShapeAction.h" +#include "GeoModelKernel/throwExcept.h" #include <stdexcept> const std::string GeoUnidentifiedShape::_classType="UnidentifiedShape"; const ShapeType GeoUnidentifiedShape::_classTypeID=0xFFFFFFFF; // Destructor: -GeoUnidentifiedShape::~GeoUnidentifiedShape() { -} +GeoUnidentifiedShape::~GeoUnidentifiedShape() = default; // Constructor: GeoUnidentifiedShape::GeoUnidentifiedShape(const std::string & name): @@ -44,14 +47,14 @@ double GeoUnidentifiedShape::volume () const { void GeoUnidentifiedShape::extent (double& xmin, double& ymin, double& zmin, double& xmax, double& ymax, double& zmax) const { - throw std::runtime_error ("GeoUndefinedShape::extent is not implemented"); + THROW_EXCEPTION("GeoUndefinedShape::extent is not implemented"); xmin = ymin = zmin = xmax = ymax = zmax = 0.; } // Returns true if the shape contains the point, false otherwise bool GeoUnidentifiedShape::contains (double x, double y, double z) const { - throw std::runtime_error ("GeoUndefinedShape::contains(x,y,z) is not implemented"); + THROW_EXCEPTION("GeoUndefinedShape::contains(x,y,z) is not implemented"); return false; } diff --git a/GeoModelCore/GeoModelKernel/src/GeoVDetectorElement.cxx b/GeoModelCore/GeoModelKernel/src/GeoVDetectorElement.cxx index d84ed8e2cbe9919920b12715da16648397711dfc..73e6ae3ddfc402d7010f1eacee8c80c2d55e5a4d 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVDetectorElement.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVDetectorElement.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVDetectorElement.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoVDetectorFactory.cxx b/GeoModelCore/GeoModelKernel/src/GeoVDetectorFactory.cxx index 25daefa33e6648875eab75b928d3063cb5d89b5c..1009fec35d8594dbdbe9707c674eff4bf0faf618 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVDetectorFactory.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVDetectorFactory.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVDetectorFactory.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoVDetectorManager.cxx b/GeoModelCore/GeoModelKernel/src/GeoVDetectorManager.cxx index c5b8370f51f351d5c763898d7c849521773754df..679dc5a0d95f3fd55690b3e5ab5147c8803e543c 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVDetectorManager.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVDetectorManager.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVDetectorManager.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoVFullPhysVol.cxx b/GeoModelCore/GeoModelKernel/src/GeoVFullPhysVol.cxx index 1c014d7ee148efe8a02dbf8bb36ed7fa8772ed37..4725709790c6ad112a4b06af8109ed47c0537cef 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVFullPhysVol.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVFullPhysVol.cxx @@ -1,9 +1,10 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVFullPhysVol.h" #include "GeoModelKernel/GeoVAlignmentStore.h" +#include "GeoModelKernel/throwExcept.h" #include <string> GeoVFullPhysVol::GeoVFullPhysVol(const GeoLogVol* logVol) : GeoVPhysVol{logVol}, @@ -16,12 +17,11 @@ const std::string & GeoVFullPhysVol::getAbsoluteName () const // // // Get ready for something to go wrong: // // // - static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); // // //------------------------------------------------------------------------------------------------// if(m_absName == "") { - if(isShared()) throw std::runtime_error(errorMessage); + if(isShared()) THROW_EXCEPTION("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); // // Check the cache. If it is empty, compute the absolute position from the @@ -37,7 +37,7 @@ const std::string & GeoVFullPhysVol::getAbsoluteName () const tProd = tProd + "/" + name; child = parent; if (child->isShared ()) { - throw std::runtime_error(errorMessage); + THROW_EXCEPTION("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); } else { parent = child->getParent (); @@ -55,12 +55,11 @@ unsigned int GeoVFullPhysVol::getId () const // // // Get ready for something to go wrong: // // // - static std::string errorMessage("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); // // //------------------------------------------------------------------------------------------------// if(!m_id) { - if(isShared()) throw std::runtime_error(errorMessage); + if(isShared()) THROW_EXCEPTION("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); // // Check the cache. If it is empty, compute the absolute position from the @@ -68,7 +67,7 @@ unsigned int GeoVFullPhysVol::getId () const // PVConstLink child = this, parent = nullptr; if(child->isShared()) { - throw std::runtime_error(errorMessage); + THROW_EXCEPTION("Full Physical Volume errroneously placed in a shared portion of a detector description graph.\nName of shared volume: "); } else { parent = child->getParent(); diff --git a/GeoModelCore/GeoModelKernel/src/GeoVPhysVol.cxx b/GeoModelCore/GeoModelKernel/src/GeoVPhysVol.cxx index ef0238e1ecc0476a944325afc70a03a33be32f03..11a554b671a2c3608cbb4d01e1080a810d3b2652 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVPhysVol.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVPhysVol.cxx @@ -15,7 +15,7 @@ GeoVPhysVol::GeoVPhysVol(const GeoLogVol* LogVol): m_logVol(LogVol) {} -Query<unsigned int> GeoVPhysVol::indexOf(PVConstLink daughter) const { +Query<unsigned int> GeoVPhysVol::indexOf(const PVConstLink& daughter) const { unsigned int nChildVols{getNChildVols()}; for(unsigned int i=0; i<nChildVols; i++) { // To Do: replace this with Volume Iterator! if(getChildVol(i) == daughter) return i; @@ -67,11 +67,11 @@ void GeoVPhysVol::apply(GeoVolumeAction *action) const { if(action->shouldTerminate()) return; // To Do: do I need this? break; default: - throw std::runtime_error("GeoVPhysVol::apply(). Unsupported GeoVolumeAction type " + std::to_string((unsigned)action->getType())); + THROW_EXCEPTION("GeoVPhysVol::apply(). Unsupported GeoVolumeAction type "<<action->getType()); } } -void GeoVPhysVol::add(GeoIntrusivePtr<GeoGraphNode> graphNode) { +void GeoVPhysVol::add(const GeoIntrusivePtr<GeoGraphNode>& graphNode) { std::unique_lock lk{m_muxVec}; m_daughters.emplace_back(graphNode); graphNode->dockTo(this); diff --git a/GeoModelCore/GeoModelKernel/src/GeoVSurface.cxx b/GeoModelCore/GeoModelKernel/src/GeoVSurface.cxx new file mode 100644 index 0000000000000000000000000000000000000000..29a918b87fc746cb70b86fea6817e7d139a7c752 --- /dev/null +++ b/GeoModelCore/GeoModelKernel/src/GeoVSurface.cxx @@ -0,0 +1,12 @@ +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/GeoNodeAction.h" + + +void GeoVSurface::exec(GeoNodeAction *action) const{ + action->handleVSurface(this); +} + +bool GeoVSurface::isOnSurface (const double Px, const double Py, const double Pz) const{ + GeoTrf::Transform3D trans = this->getX(); + return m_surfaceshape.get()->isOnSurface(Px, Py, Pz, trans); +} \ No newline at end of file diff --git a/GeoModelCore/GeoModelKernel/src/GeoVolumeAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoVolumeAction.cxx index 5dbf90ff2ce428000a758d013f10d4fa5071c55b..819f53c4caf83f40acd16a76087f3c52a75fcdca 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVolumeAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVolumeAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVolumeAction.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeoVolumeCursor.cxx b/GeoModelCore/GeoModelKernel/src/GeoVolumeCursor.cxx index 2dd81c3a6877b968ff0ce8087ae2c47338265cfb..d28c9d1c1d606f9c40e2e9788e12be92cb62fd24 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoVolumeCursor.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoVolumeCursor.cxx @@ -1,16 +1,17 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoVolumeCursor.h" +#include "GeoModelKernel/GeoAlignableTransform.h" #include "GeoModelKernel/GeoNameTag.h" #include "GeoModelKernel/GeoSerialDenominator.h" #include "GeoModelKernel/GeoSerialIdentifier.h" -#include "GeoModelKernel/GeoAlignableTransform.h" #include <string> +#include <utility> GeoVolumeCursor::GeoVolumeCursor (PVConstLink parent, GeoVAlignmentStore* store) - : m_parent(parent) + : m_parent(std::move(parent)) , m_transform(GeoTrf::Transform3D::Identity()) , m_defTransform(GeoTrf::Transform3D::Identity()) , m_majorIndex(0) @@ -58,6 +59,7 @@ void GeoVolumeCursor::next() { m_pendingTransformList.end ()); m_hasAlignTrans = false; m_volume=nullptr; + m_surface=nullptr; int N = m_parent->getNChildNodes(); if(N==0) return; @@ -66,6 +68,7 @@ void GeoVolumeCursor::next() { const GeoGraphNode * const *end = back+1; while (node!=end) { (*node)->exec(this); + const GeoGraphNode * const * flag = node; if (m_minorLimit) { // We have stepped into ST } else { // We have not stepped into ST. @@ -85,7 +88,8 @@ void GeoVolumeCursor::resuscitate() { } bool GeoVolumeCursor::atEnd() const { - return !m_volume; + //return !m_volume; + return (!m_volume and !m_surface); } void GeoVolumeCursor::handleTransform (const GeoTransform *xform) @@ -134,6 +138,27 @@ void GeoVolumeCursor::handleFullPhysVol (const GeoFullPhysVol *vol) terminate (); } +void GeoVolumeCursor::handleVSurface (const GeoVSurface *surf) +{ + m_surface = surf; + + unsigned int listSize = m_pendingTransformList.size (); + if (listSize == 0) { + m_transform = GeoTrf::Transform3D::Identity(); + m_defTransform = GeoTrf::Transform3D::Identity(); + } + else { + m_transform = m_pendingTransformList[0]->getTransform(m_alignStore); + m_defTransform = m_pendingTransformList[0]->getDefTransform(m_alignStore); + for (unsigned int t = 1; t < m_pendingTransformList.size (); t++) { + m_transform = m_transform * m_pendingTransformList[t]->getTransform(m_alignStore); + m_defTransform = m_defTransform * m_pendingTransformList[t]->getDefTransform(m_alignStore); + } + } + + terminate (); +} + void GeoVolumeCursor::handleSerialTransformer (const GeoSerialTransformer *sT) { @@ -190,6 +215,11 @@ PVConstLink GeoVolumeCursor::getVolume () const return m_volume; } +VSConstLink GeoVolumeCursor::getSurface () const +{ + return m_surface; +} + GeoTrf::Transform3D GeoVolumeCursor::getTransform () const { if (m_minorLimit) { diff --git a/GeoModelCore/GeoModelKernel/src/GeoXF.cxx b/GeoModelCore/GeoModelKernel/src/GeoXF.cxx index 23cac3f8806844d230ec637264e52b1bfcb85f0b..32b17b3993c74c96127e81e83ab27dce2f8710d0 100755 --- a/GeoModelCore/GeoModelKernel/src/GeoXF.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeoXF.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeoXF.h" diff --git a/GeoModelCore/GeoModelKernel/src/GeometryMap.cxx b/GeoModelCore/GeoModelKernel/src/GeometryMap.cxx index 5b0e9418eacb69fb47a4755da146a1131ef637a0..1dc84d971683314550bacf66ebcb4b7212c71563 100755 --- a/GeoModelCore/GeoModelKernel/src/GeometryMap.cxx +++ b/GeoModelCore/GeoModelKernel/src/GeometryMap.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/GeometryMap.h" @@ -20,7 +20,7 @@ public: std::vector<PVConstLink> physicalVolumes; unsigned int lV; - void finalize(unsigned int i, PVConstLink v); + void finalize(unsigned int i, const PVConstLink& v); }; @@ -41,11 +41,11 @@ void GeometryMap::add(const std::string & Path) { size_t pos = 0; while (1) { size_t end = path.find('/',pos); - if (end==path.npos) break; + if (end==std::string::npos) break; std::string sub0(path,pos,end-pos); pathList.push_back(sub0); - std::string sub1(path,end+1,path.npos-end-1); + std::string sub1(path,end+1,std::string::npos-end-1); path=sub1; pos=0; } @@ -58,10 +58,10 @@ void GeometryMap::add(const std::string & Path) { size_t end = path.find('*',pos); std::string sub(path,pos,end-pos); regex+=sub; - if (end==path.npos) break; + if (end==std::string::npos) break; regex+=".*"; pos=end+1; - if (pos==path.npos) break; + if (pos==std::string::npos) break; } regex+="$"; m_c->geometryRegex.push_back(regex); @@ -71,7 +71,7 @@ void GeometryMap::add(const std::string & Path) { } -void GeometryMap::finalize( PVConstLink v) { +void GeometryMap::finalize( const PVConstLink& v) { for (size_t i=0;i<m_c->pathList.size();i++) { m_c->lV=0; @@ -80,7 +80,7 @@ void GeometryMap::finalize( PVConstLink v) { } -void GeometryMap::Clockwork::finalize(unsigned int i, PVConstLink v) { +void GeometryMap::Clockwork::finalize(unsigned int i, const PVConstLink& v) { static const size_t NMATCH=11; regmatch_t pmatch[NMATCH]; diff --git a/GeoModelCore/GeoModelKernel/src/PolygonTriangulator.cxx b/GeoModelCore/GeoModelKernel/src/PolygonTriangulator.cxx index 724440107804382567cb57f5f18eb23e86646066..91761fa882c50a642789479da6b1b3a7f2d7d229 100755 --- a/GeoModelCore/GeoModelKernel/src/PolygonTriangulator.cxx +++ b/GeoModelCore/GeoModelKernel/src/PolygonTriangulator.cxx @@ -73,16 +73,16 @@ /////////////////////////////////////////////////////////////////////////////// #include <algorithm> +#include <cassert> #include <cmath> #include <cstdlib> -#include <map> +#include <iostream> #include <limits> #include <list> +#include <map> #include <queue> #include <set> -#include <iostream> #include <stack> -#include <assert.h> namespace internal_poltrig { @@ -370,7 +370,7 @@ namespace internal_poltrig { /* */ /*****************************************************************************/ - int fast_expansion_sum_zeroelim(const int& elen, REAL* e, const int& flen, REAL* f, REAL* h) + int fast_expansion_sum_zeroelim(const int& elen, const REAL* e, const int& flen, const REAL* f, REAL* h) /* h cannot be e or f. */ { REAL Q; @@ -449,7 +449,7 @@ namespace internal_poltrig { /* */ /*****************************************************************************/ - REAL estimate(const int& elen, REAL* e) + REAL estimate(const int& elen, const REAL* e) { REAL Q; int eindex; @@ -487,7 +487,7 @@ namespace internal_poltrig { /* */ /*****************************************************************************/ - REAL orient2dadapt(REAL* pa, REAL* pb, REAL* pc, const REAL& detsum) + REAL orient2dadapt(const REAL* pa, const REAL* pb, const REAL* pc, const REAL& detsum) { INEXACT REAL acx, acy, bcx, bcy; REAL acxtail, acytail, bcxtail, bcytail; @@ -706,7 +706,7 @@ namespace internal_poltrig { private: BTreeNode<T, KeyType> *m_root; - long int m_size; + long int m_size{}; void reclaimMemory( BTreeNode<T, KeyType> * t ) const; BTreeNode<T, KeyType> * clone( BTreeNode<T, KeyType> *t ) const; @@ -1337,7 +1337,7 @@ namespace internal_poltrig { //---------------------------------------------------------------------------- //square of the distance of two points; //---------------------------------------------------------------------------- - double dist_sqr(double *pa, double *pb) + double dist_sqr(const double *pa, const double *pb) { return sqr(pa[0]-pb[0])+sqr(pa[1]-pb[1]); } @@ -1480,7 +1480,7 @@ private: //angle ABC for three given points, for monotone polygon searching purpose; - double angleCosb(double *A, double *B, double *C); + double angleCosb(const double *A, const double *B, const double *C); //find the next edge, for monotone polygon searching purpose; unsigned int selectNextEdge(internal_poltrig::Linebase* edge); @@ -1867,7 +1867,7 @@ void PolygonTriangulator::Polygon::partition2Monotone() //---------------------------------------------------------------------------- //calculate angle B for A, B, C three given points //---------------------------------------------------------------------------- -double PolygonTriangulator::Polygon::angleCosb(double *pa, double *pb, double *pc) +double PolygonTriangulator::Polygon::angleCosb(const double *pa, const double *pb, const double *pc) { double dxab = pa[0] - pb[0]; double dyab = pa[1] - pb[1]; diff --git a/GeoModelCore/GeoModelKernel/src/TemplateVolAction.cxx b/GeoModelCore/GeoModelKernel/src/TemplateVolAction.cxx index e1dccfb1776c8dea10877a8c4fbc562d8864a16f..68bd840603b33cf05160aecd5e20951e236ed709 100755 --- a/GeoModelCore/GeoModelKernel/src/TemplateVolAction.cxx +++ b/GeoModelCore/GeoModelKernel/src/TemplateVolAction.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelKernel/TemplateVolAction.h" diff --git a/GeoModelCore/GeoModelKernel/tests/testEulerAngles.cxx b/GeoModelCore/GeoModelKernel/tests/testEulerAngles.cxx index bc3ed0758417c8063efe4ab890050bbc690c79da..861c1fdc65ef094cf5191570d025cc9b558e85a1 100644 --- a/GeoModelCore/GeoModelKernel/tests/testEulerAngles.cxx +++ b/GeoModelCore/GeoModelKernel/tests/testEulerAngles.cxx @@ -1,11 +1,11 @@ -// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration #include "GeoModelKernel/Units.h" #include "GeoModelKernel/GeoDefinitions.h" -#include <stdlib.h> +#include <cstdlib> #include <iostream> bool isIdentity(const GeoTrf::RotationMatrix3D& mat) { @@ -80,6 +80,12 @@ int main() { GeoTrf::get3DRotMatX(coordAngles.alpha *GeoModelKernelUnits::deg)<<std::endl; } + if (!isIdentity(coordRot * GeoTrf::GeoRotation{coordAngles.inverse()})){ + std::cout<<"testEulerAngles() "<<__LINE__<<"The inverse of "<<coordAngles<<" " + <<coordAngles.inverse()<<" does not lead to Identity rotation "<<std::endl; + return EXIT_FAILURE; + } + const GeoTrf::CoordEulerAngles calcCoordAngles = GeoTrf::getCoordRotationAngles(coordRot); const GeoTrf::GeoRotation extCoordRot{calcCoordAngles}; if (!isIdentity(extCoordRot.inverse()* coordRot)) { @@ -90,6 +96,11 @@ int main() { <<calcCoordAngles.beta*toDeg<<"/"<<calcCoordAngles.gamma*toDeg<<std::endl<<extCoordRot<<std::endl; return EXIT_FAILURE; } + if (!isIdentity(extCoordRot * GeoTrf::GeoRotation{calcCoordAngles.inverse()})){ + std::cout<<"testEulerAngles() "<<__LINE__<<"The inverse of "<<calcCoordAngles<<" " + <<calcCoordAngles.inverse()<<" does not lead to Identity rotation "<<std::endl; + return EXIT_FAILURE; + } } } } diff --git a/GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx b/GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx index 29c1a5bfd2005efbd3f105b84c9e88e8b3853186..e3c211a4b94969fc1c60a70367a01e642a801e46 100644 --- a/GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx +++ b/GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration #include <GeoModelKernel/GeoFullPhysVol.h> diff --git a/GeoModelExamples/CMakeLists.txt b/GeoModelExamples/CMakeLists.txt index b819e97a343cf5f7a5d9c693d4e68690d7fe5dcf..c3071f1505718de1180a631f789be6e23784ada1 100644 --- a/GeoModelExamples/CMakeLists.txt +++ b/GeoModelExamples/CMakeLists.txt @@ -13,15 +13,21 @@ project( "GeoModelExamples" VERSION 4.1.0 LANGUAGES CXX ) add_subdirectory( KitchenSinkPlugin ) add_subdirectory( MinimalPlugin ) add_subdirectory( SurfaceTestPlugin ) +add_subdirectory( SurfAlignTestPlugin ) +add_subdirectory( SurfAnnulusDemo ) +add_subdirectory( SiliconSystemExample ) +add_subdirectory( SurfDiamond ) add_subdirectory( HelloGeo ) -add_subdirectory( HelloGeoWrite ) -add_subdirectory( HelloGeoWriteReadWrite ) -add_subdirectory( HelloGeoRead ) -add_subdirectory( HelloGeoReadNodeAction ) +# add_subdirectory( HelloGeoWrite ) +# add_subdirectory( HelloGeoWriteReadWrite ) +# add_subdirectory( HelloGeoRead ) +# add_subdirectory( HelloGeoReadNodeAction ) +# add_subdirectory( SharedNodes ) +add_subdirectory( HelloToyWrite ) #add_subdirectory( HelloDummyMaterial ) -#add_subdirectory( HelloToy ) +add_subdirectory( HelloToy ) #add_subdirectory( HelloToyDetectorFactory ) #add_subdirectory( HelloToyXML ) # this should be moved to GeoModelATLAS, because it uses GeoModelDataManagers diff --git a/GeoModelExamples/HelloToy/CMakeLists.txt b/GeoModelExamples/HelloToy/CMakeLists.txt index 0d66f644f671b330132e5d3eacbcae9fc6168211..8bb74b077828195f11c22af3b5770dc9dfa4b88f 100644 --- a/GeoModelExamples/HelloToy/CMakeLists.txt +++ b/GeoModelExamples/HelloToy/CMakeLists.txt @@ -28,9 +28,9 @@ set(SRCS step1_create_store_geo_and_publish_nodes.cpp ) set(SRCS_READ step2_read_geo_and_published_nodes.cpp ) # Tell CMake to create the 'helloToy' executable -add_executable( helloToy ${SRCS} ) -add_executable( read_helloToy_and_publishedNodes ${SRCS_READ} ) +add_executable( helloToy_step1_write ${SRCS} ) +add_executable( helloToy_step2_read ${SRCS_READ} ) # Link all needed libraries -target_link_libraries( helloToy GeoModelCore::GeoModelKernel GeoModelIO::GeoModelWrite ) -target_link_libraries( read_helloToy_and_publishedNodes GeoModelCore::GeoModelKernel GeoModelIO::GeoModelRead ) +target_link_libraries( helloToy_step1_write GeoModelCore::GeoModelKernel GeoModelIO::GeoModelWrite GeoModelHelpers ) +target_link_libraries( helloToy_step2_read GeoModelCore::GeoModelKernel GeoModelIO::GeoModelRead ) diff --git a/GeoModelExamples/HelloToy/step1_create_store_geo_and_publish_nodes.cpp b/GeoModelExamples/HelloToy/step1_create_store_geo_and_publish_nodes.cpp index c831768c7fe53864306a31f2063802979ab7822d..87234079564b6367b7a0067f26ba56c9d6b975b3 100644 --- a/GeoModelExamples/HelloToy/step1_create_store_geo_and_publish_nodes.cpp +++ b/GeoModelExamples/HelloToy/step1_create_store_geo_and_publish_nodes.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /* @@ -16,6 +16,24 @@ #include "GeoModelKernel/GeoMaterial.h" #include "GeoModelKernel/GeoBox.h" #include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoCons.h" +#include "GeoModelKernel/GeoPara.h" +#include "GeoModelKernel/GeoTrap.h" +#include "GeoModelKernel/GeoTrd.h" +#include "GeoModelKernel/GeoTubs.h" +#include "GeoModelKernel/GeoTorus.h" +#include "GeoModelKernel/GeoTwistedTrap.h" +#include "GeoModelKernel/GeoSimplePolygonBrep.h" +#include "GeoModelKernel/GeoGenericTrap.h" +#include "GeoModelKernel/GeoPcon.h" +#include "GeoModelKernel/GeoPgon.h" +#include "GeoModelKernel/GeoUnidentifiedShape.h" + +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/GeoShapeIntersection.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeUnion.h" + #include "GeoModelKernel/GeoLogVol.h" #include "GeoModelKernel/GeoNameTag.h" #include "GeoModelKernel/GeoPhysVol.h" @@ -36,6 +54,9 @@ #include "GeoModelWrite/WriteGeoModel.h" +#include "GeoModelKernel/throwExcept.h" + + // Units #include "GeoModelKernel/Units.h" #define SYSTEM_OF_UNITS GeoModelKernelUnits // so we will get, e.g., 'SYSTEM_OF_UNITS::cm' @@ -149,9 +170,7 @@ int main(int argc, char *argv[]) std::string keyStr = "HelloToy-AXF-" + std::to_string(i+1); publisher->publishNode<GeoAlignableTransform*,std::string>(xform, keyStr); - std::cout << "step1 - FPV, key: " << keyInt - << " - xf: "; - GeoUtilFunctions::printTrf(ringPhys->getAbsoluteTransform()); + std::cout << "step1 - FPV, key: " << keyInt << std::endl; } @@ -168,6 +187,7 @@ int main(int argc, char *argv[]) //--------------------------------------// GeoBox *sPass = new GeoBox(5.0*SYSTEM_OF_UNITS::cm, 30*SYSTEM_OF_UNITS::cm, 30*SYSTEM_OF_UNITS::cm); + // GeoTube *sPass = new GeoTube(5.0*SYSTEM_OF_UNITS::cm, 10*SYSTEM_OF_UNITS::cm, 30*SYSTEM_OF_UNITS::cm); GeoLogVol *lPass = new GeoLogVol("Passive", sPass, steel); GeoPhysVol *pPass = new GeoPhysVol(lPass); @@ -204,9 +224,267 @@ int main(int argc, char *argv[]) - //------------------------------------------------------------------------------------// - // Writing the geometry to file - //------------------------------------------------------------------------------------// + // === Add single test instances for all shapes === + + // Add a test GeoBox shape + GeoBox *sBox = new GeoBox(5.0 * SYSTEM_OF_UNITS::cm, 30 * SYSTEM_OF_UNITS::cm, 30 * SYSTEM_OF_UNITS::cm); + GeoLogVol *lBox = new GeoLogVol("box", sBox, steel); + GeoPhysVol *pBox = new GeoPhysVol(lBox); + GeoNameTag *nBox = new GeoNameTag("Shape-Box"); + toyPhys->add(nBox); + toyPhys->add(pBox); + + // Add a test GeoTube shape + GeoTube *sTube = new GeoTube(5.0 * SYSTEM_OF_UNITS::cm, 10 * SYSTEM_OF_UNITS::cm, 30 * SYSTEM_OF_UNITS::cm); + GeoLogVol *lTube = new GeoLogVol("tube", sTube, steel); + GeoPhysVol *pTube = new GeoPhysVol(lTube); + GeoNameTag *nTube = new GeoNameTag("Shape-Tube"); + toyPhys->add(nTube); + toyPhys->add(pTube); + + // Add a test GeoPcon shape + GeoPcon *sPcon = new GeoPcon(0, 360 * SYSTEM_OF_UNITS::deg); + sPcon->addPlane(1 * SYSTEM_OF_UNITS::m, 1, 5); + sPcon->addPlane(2 * SYSTEM_OF_UNITS::m, 2, 3); + GeoLogVol *lPcon = new GeoLogVol("pcon", sPcon, steel); + GeoPhysVol *pPcon = new GeoPhysVol(lPcon); + GeoNameTag *nPcon = new GeoNameTag("Shape-Pcon"); + toyPhys->add(nPcon); + toyPhys->add(pPcon); + + // Add a test GeoCons shape + double rMin1 = 1 * SYSTEM_OF_UNITS::m; + double rMin2 = 1.5 * SYSTEM_OF_UNITS::m; + double rMax1 = 3 * SYSTEM_OF_UNITS::m; + double rMax2 = 3.5 * SYSTEM_OF_UNITS::m; + double zmin = 1 * SYSTEM_OF_UNITS::m; + double zmax = 10 * SYSTEM_OF_UNITS::m; + double dZnew = 0.5 * (zmax - zmin); + GeoCons *sCons = new GeoCons(rMin1, rMin2, + rMax1, rMax2, + dZnew, + 0 * SYSTEM_OF_UNITS::deg, 360 * SYSTEM_OF_UNITS::deg); + GeoLogVol *lCons = new GeoLogVol("cons", sCons, steel); + GeoPhysVol *pCons = new GeoPhysVol(lCons); + GeoNameTag *nCons = new GeoNameTag("Shape-Cons"); + toyPhys->add(nCons); + toyPhys->add(pCons); + + // Add a test GeoPara shape + double Rmax = 335. * SYSTEM_OF_UNITS::mm; + double bepo_Beta = 4.668 * SYSTEM_OF_UNITS::degree; + double Zall = (912. / 2.) * SYSTEM_OF_UNITS::mm; + double Xall = (171. / 2.) * SYSTEM_OF_UNITS::mm; + double Yall = (300. / 2.) * SYSTEM_OF_UNITS::mm; + double Rmax_1 = Rmax - 2. * Zall * tan(bepo_Beta); + GeoPara *sPara = new GeoPara(Zall, Yall, Xall, 0 * SYSTEM_OF_UNITS::degree, bepo_Beta, 0. * SYSTEM_OF_UNITS::degree); + GeoLogVol *lPara = new GeoLogVol("para", sPara, steel); + GeoPhysVol *pPara = new GeoPhysVol(lPara); + GeoNameTag *nPara = new GeoNameTag("Shape-Para"); + toyPhys->add(nPara); + toyPhys->add(pPara); + + // Add a test GeoPara shape + GeoPgon *sPgon = new GeoPgon(0., 360 * SYSTEM_OF_UNITS::degree, 6); + sPgon->addPlane(2 * SYSTEM_OF_UNITS::m, 0.2*SYSTEM_OF_UNITS::m, 0.5 * SYSTEM_OF_UNITS::m); + sPgon->addPlane(3 * SYSTEM_OF_UNITS::m, 0, 0.5 * SYSTEM_OF_UNITS::m); + GeoLogVol *lPgon = new GeoLogVol("pgon", sPgon, steel); + GeoPhysVol *pPgon = new GeoPhysVol(lPgon); + GeoNameTag *nPgon = new GeoNameTag("Shape-Pgon"); + toyPhys->add(nPgon); + toyPhys->add(pPgon); + + // Add a test GeoTrap shape + double length = 5 * SYSTEM_OF_UNITS::m; + double halflength = 0.5 * length; + double rmax = 2 * SYSTEM_OF_UNITS::m; + double rmin = 1 * SYSTEM_OF_UNITS::m; + double phiWidth = 30 * SYSTEM_OF_UNITS::degree; + double thickness = 0.5 * (rmax - rmin); + double averad = 0.5 * (rmin + rmax); + double w1 = 0.5 * phiWidth * rmin / averad; + double w2 = 0.5 * phiWidth * rmax / averad; + GeoTrap *sTrap = new GeoTrap(halflength, 0, 0, thickness, w1, w2, 0, thickness, w1, w2, 0); + GeoLogVol *lTrap = new GeoLogVol("trap", sTrap, steel); + GeoPhysVol *pTrap = new GeoPhysVol(lTrap); + GeoNameTag *nTrap = new GeoNameTag("Shape-Trap"); + toyPhys->add(nTrap); + toyPhys->add(pTrap); + + // Add a test GeoTrd shape + GeoTrd *sTrd = new GeoTrd(2*SYSTEM_OF_UNITS::m, 2*SYSTEM_OF_UNITS::m, 1*SYSTEM_OF_UNITS::m, 1*SYSTEM_OF_UNITS::m, 1*SYSTEM_OF_UNITS::m); + GeoLogVol *lTrd = new GeoLogVol("trd", sTrd, steel); + GeoPhysVol *pTrd = new GeoPhysVol(lTrd); + GeoNameTag *nTrd = new GeoNameTag("Shape-Trd"); + toyPhys->add(nTrd); + toyPhys->add(pTrd); + + // Add a test GeoTubs shape + GeoTubs *sTubs = new GeoTubs(1 * SYSTEM_OF_UNITS::m, 2 * SYSTEM_OF_UNITS::m, 4 * SYSTEM_OF_UNITS::m, 0 * SYSTEM_OF_UNITS::degree, 270 * SYSTEM_OF_UNITS::degree); + GeoLogVol *lTubs = new GeoLogVol("tubs", sTubs, steel); + GeoPhysVol *pTubs = new GeoPhysVol(lTubs); + GeoNameTag *nTubs = new GeoNameTag("Shape-Tubs"); + toyPhys->add(nTubs); + toyPhys->add(pTubs); + + // Add a test GeoTwistedTrap shape + double tw_PhiTwist = 30 * SYSTEM_OF_UNITS::deg; // twist angle + double tw_Dz = 5 * SYSTEM_OF_UNITS::m; // half z length + double tw_Theta = 30 * SYSTEM_OF_UNITS::deg; // direction between end planes + double tw_Phi = 30 * SYSTEM_OF_UNITS::deg; // defined by polar and azim. angles + double tw_Dy1 = 1 * SYSTEM_OF_UNITS::m; // half y length at -pDz + double tw_Dx1 = 1 * SYSTEM_OF_UNITS::m; // half x length at -pDz,-pDy + double tw_Dx2 = 1 * SYSTEM_OF_UNITS::m; // half x length at -pDz,+pDy + double tw_Dy2 = 1 * SYSTEM_OF_UNITS::m; // half y length at +pDz + double tw_Dx3 = 1 * SYSTEM_OF_UNITS::m; // half x length at +pDz,-pDy + double tw_Dx4 = 1 * SYSTEM_OF_UNITS::m; // half x length at +pDz,+pDy + double tw_Alph = 30 * SYSTEM_OF_UNITS::deg; // tilt angle + GeoTwistedTrap *sTwist = new GeoTwistedTrap(tw_PhiTwist, tw_Dz, tw_Theta, tw_Phi, + tw_Dy1, tw_Dx1, tw_Dx2, tw_Dy2, tw_Dx3, tw_Dx4, tw_Alph); + GeoLogVol *lTwist = new GeoLogVol("twistedtrap", sTwist, steel); + GeoPhysVol *pTwist = new GeoPhysVol(lTwist); + GeoNameTag *nTwist = new GeoNameTag("Shape-TwistedTrap"); + toyPhys->add(nTwist); + toyPhys->add(pTwist); + + // Add a test GeoSimplePolygonBrep shape + const double DZ = 1 * SYSTEM_OF_UNITS::m; + const double xV1 = 1.5 * SYSTEM_OF_UNITS::m; + const double yV1 = 1.5 * SYSTEM_OF_UNITS::m; + const double xV2 = 3 * SYSTEM_OF_UNITS::m; + const double yV2 = 3 * SYSTEM_OF_UNITS::m; + const double xV3 = 4 * SYSTEM_OF_UNITS::m; + const double yV3 = 4 * SYSTEM_OF_UNITS::m; + GeoSimplePolygonBrep* sSimplePolygonBrep = new GeoSimplePolygonBrep(DZ); + sSimplePolygonBrep->addVertex(xV1, yV1); + sSimplePolygonBrep->addVertex(xV2, yV2); + sSimplePolygonBrep->addVertex(xV3, yV3); + if (!sSimplePolygonBrep->isValid()) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep shape is not valid!!"); + } + GeoLogVol *lSimplePolygonBrep = new GeoLogVol("SimplePolygonBrep", sSimplePolygonBrep, steel); + GeoPhysVol *pSimplePolygonBrep = new GeoPhysVol(lSimplePolygonBrep); + GeoNameTag *nSimplePolygonBrep = new GeoNameTag("Shape-SimplePolygonBrep"); + toyPhys->add(nSimplePolygonBrep); + toyPhys->add(pSimplePolygonBrep); + + // Add a test *shared* GeoSimplePolygonBrep shape + GeoLogVol *lSimplePolygonBrep2 = new GeoLogVol("SimplePolygonBrepShared", sSimplePolygonBrep, steel); + GeoPhysVol *pSimplePolygonBrep2 = new GeoPhysVol(lSimplePolygonBrep2); + GeoNameTag *nSimplePolygonBrep2 = new GeoNameTag("Shape-SimplePolygonBrepShared"); + toyPhys->add(nSimplePolygonBrep2); + toyPhys->add(pSimplePolygonBrep2); + + // Add a test GeoShift boolean shape: + // a shift of a box + GeoShapeShift* sShift = new GeoShapeShift(sPass, GeoTrf::TranslateZ3D(50*SYSTEM_OF_UNITS::cm)); + GeoLogVol *lShift = new GeoLogVol("Shift", sShift, steel); + GeoPhysVol *pShift = new GeoPhysVol(lShift); + GeoNameTag *nShift = new GeoNameTag("Shape-Shift"); + toyPhys->add(nShift); + toyPhys->add(pShift); + + // Add a test GeoIntersection boolean shape + GeoShapeIntersection* sIntersection = new GeoShapeIntersection(sPass, sIPass); + GeoLogVol *lIntersection = new GeoLogVol("Intersection", sIntersection, steel); + GeoPhysVol *pIntersection = new GeoPhysVol(lIntersection); + GeoNameTag *nIntersection = new GeoNameTag("Shape-Intersection"); + toyPhys->add(nIntersection); + toyPhys->add(pIntersection); + +// Add a test GeoSubtraction boolean shape + GeoShapeSubtraction* sSubtraction = new GeoShapeSubtraction(sPass, sIPass); + GeoLogVol *lSubtraction = new GeoLogVol("Subtraction", sSubtraction, steel); + GeoPhysVol *pSubtraction = new GeoPhysVol(lSubtraction); + GeoNameTag *nSubtraction = new GeoNameTag("Shape-Subtraction"); + toyPhys->add(nSubtraction); + toyPhys->add(pSubtraction); + +// Add a test GeoSubtraction boolean shape + GeoShapeUnion* sUnion = new GeoShapeUnion(sPass, sIPass); + GeoLogVol *lUnion = new GeoLogVol("Union", sUnion, steel); + GeoPhysVol *pUnion = new GeoPhysVol(lUnion); + GeoNameTag *nUnion = new GeoNameTag("Shape-Union"); + toyPhys->add(nUnion); + toyPhys->add(pUnion); + + +// Add a test chain GeoShift operator shape: +// a shift of a shift of a box + GeoShapeShift* sShift2 = new GeoShapeShift(sShift, GeoTrf::TranslateZ3D(50*SYSTEM_OF_UNITS::cm)); + GeoLogVol *lShift2 = new GeoLogVol("Shift2", sShift2, steel); + GeoPhysVol *pShift2 = new GeoPhysVol(lShift2); + GeoNameTag *nShift2 = new GeoNameTag("Shape-Shift-2"); + toyPhys->add(nShift2); + toyPhys->add(pShift2); + +// Add a test chain & mixed GeoShift boolean shape: +// a shift of a union of two boxes + GeoShapeShift* sShiftUnion = new GeoShapeShift(sUnion, GeoTrf::TranslateZ3D(50*SYSTEM_OF_UNITS::cm)); + GeoLogVol *lShiftUnion = new GeoLogVol("Shift-Union", sShiftUnion, steel); + GeoPhysVol *pShiftUnion = new GeoPhysVol(lShiftUnion); + GeoNameTag *nShiftUnion = new GeoNameTag("Shape-Shift-Union"); + toyPhys->add(nShiftUnion); + toyPhys->add(pShiftUnion); + +// Add a test chain & mixed GeoShift boolean shape: +// a shift of a union of a subtraction of two boxes and an intersection of two boxes + GeoShapeUnion* sUnionSubInt = new GeoShapeUnion(sSubtraction, sIntersection); + GeoShapeShift* sShiftUnionSubInt = new GeoShapeShift(sUnionSubInt, GeoTrf::TranslateZ3D(50*SYSTEM_OF_UNITS::cm)); + GeoLogVol *lShiftUnionSubInt = new GeoLogVol("Shift-Union-Subtraction-Intersection", sShiftUnionSubInt, steel); + GeoPhysVol *pShiftUnionSubInt = new GeoPhysVol(lShiftUnionSubInt); + GeoNameTag *nShiftUnionSubInt = new GeoNameTag("Shape-Shift-Union-Subtraction_Intersection"); + toyPhys->add(nShiftUnionSubInt); + toyPhys->add(pShiftUnionSubInt); + + + + // Add a test "UnidentifiedShape" shape node + const std::string shapeUnidName = "LArCustomShape"; + const std::string shapeUnidAscii = "LAr::Example"; + GeoUnidentifiedShape* sUnidentifiedShape = new GeoUnidentifiedShape(shapeUnidName, shapeUnidAscii); + const GeoLogVol* lUnidentifiedShape = new GeoLogVol("UnidentifiedShape", sUnidentifiedShape, steel); + GeoPhysVol *pUnidentifiedShape = new GeoPhysVol(lUnidentifiedShape); + GeoNameTag *nUnidentifiedShape = new GeoNameTag("UnidentifiedShape"); + toyPhys->add(nUnidentifiedShape); + toyPhys->add(pUnidentifiedShape); + + + // Add a test "Torus" shape node + const GeoTorus* sTorus = new GeoTorus(2*SYSTEM_OF_UNITS::m, 1*SYSTEM_OF_UNITS::m, 10*SYSTEM_OF_UNITS::m, 0*SYSTEM_OF_UNITS::rad, 4.5*SYSTEM_OF_UNITS::rad); + const GeoLogVol* lTorus = new GeoLogVol("Torus", sTorus, steel); + GeoPhysVol* pTorus = new GeoPhysVol(lTorus); + GeoNameTag* nTorus = new GeoNameTag("Shape-Torus"); + toyPhys->add(nTorus); + toyPhys->add(pTorus); + + // Add a test GeoGenericTrap shape + const double gt_Zlength = 1 * SYSTEM_OF_UNITS::m; + const double gt_xV1 = 1.5 * SYSTEM_OF_UNITS::m; + const double gt_yV1 = 1.5 * SYSTEM_OF_UNITS::m; + const double gt_xV2 = 3 * SYSTEM_OF_UNITS::m; + const double gt_yV2 = 3 * SYSTEM_OF_UNITS::m; + const double gt_xV3 = 4 * SYSTEM_OF_UNITS::m; + const double gt_yV3 = 4 * SYSTEM_OF_UNITS::m; + GeoGenericTrapVertices gt_Vertices; + gt_Vertices.push_back(GeoTwoVector(gt_xV1, gt_yV1)); + gt_Vertices.push_back(GeoTwoVector(gt_xV2, gt_yV2)); + gt_Vertices.push_back(GeoTwoVector(gt_xV3, gt_yV3)); + GeoGenericTrap *sGenericTrap = new GeoGenericTrap(gt_Zlength, gt_Vertices); + // if (!sGenericTrap->isValid()) + // { + // THROW_EXCEPTION("ERROR! GeoGenericTrap shape is not valid!!"); + // } + GeoLogVol *lGenericTrap = new GeoLogVol("GeoGenericTrap", sGenericTrap, steel); + GeoPhysVol *pGenericTrap = new GeoPhysVol(lGenericTrap); + GeoNameTag *nGenericTrap = new GeoNameTag("Shape-GenericTrap"); + toyPhys->add(nGenericTrap); + toyPhys->add(pGenericTrap); + + //------------------------------------------------------------------------------------// + // Writing the geometry to file + //------------------------------------------------------------------------------------// std::string path = "geometry.db"; // check if DB file exists. If yes, delete it. diff --git a/GeoModelExamples/HelloToy/step2_read_geo_and_published_nodes.cpp b/GeoModelExamples/HelloToy/step2_read_geo_and_published_nodes.cpp index 28a9df0054a2d4c09fb7557d9582ac443ff3ad3e..654d70c3d0fd019e8505271a6468748cce71a2f6 100644 --- a/GeoModelExamples/HelloToy/step2_read_geo_and_published_nodes.cpp +++ b/GeoModelExamples/HelloToy/step2_read_geo_and_published_nodes.cpp @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) /* build the GeoModel tree */ - GeoPhysVol* world = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory + const GeoVPhysVol* world = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory std::cout << "ReadGeoModel::buildGeoModel() done." << std::endl; @@ -115,15 +115,17 @@ int main(int argc, char *argv[]) unsigned int nChil = world->getNChildVols(); std:: cout << "world's number of children: " << nChil << std::endl; +/* // loop over all children nodes std::cout << "Looping over all 'volume' children (i.e., GeoPhysVol and GeoFullPhysVol)..." << std::endl; for (unsigned int idx=0; idx<nChil; ++idx) { - PVConstLink nodeLink = world->getChildVol(idx); + // PVConstLink nodeLink = world->getChildVol(idx); + const GeoVPhysVol* childVolV = world->getChildVol(idx); - if ( dynamic_cast<const GeoVPhysVol*>( &(*( nodeLink ))) ) { + // if ( dynamic_cast<const GeoVPhysVol*>( &(*( nodeLink ))) ) { std::cout << "\t" << "the child n. " << idx << " "; - const GeoVPhysVol *childVolV = &(*( nodeLink )); + // const GeoVPhysVol *childVolV = &(*( nodeLink )); if ( dynamic_cast<const GeoPhysVol*>(childVolV) ) { const GeoPhysVol* childVol = dynamic_cast<const GeoPhysVol*>(childVolV); @@ -136,8 +138,9 @@ int main(int argc, char *argv[]) std::cout << " and it has "<<childVol->getNChildVols()<<" child volumes" << std::endl; std::cout << "\txf:"; GeoUtilFunctions::printTrf(childVol->getAbsoluteTransform()); } - } + // } } + */ std::cout << "We now read back from the DB the lists of published FullPhysVol and AlignableTransform nodes...\n"; @@ -151,9 +154,9 @@ int main(int argc, char *argv[]) std::map<std::string, GeoAlignableTransform*> mapAXF = readInGeo.getPublishedNodes<std::string, GeoAlignableTransform*>("HelloToyExample"); //check for a table we know doesn't exist - if (db->checkTable("PublishedFullPhysVols_HelloToyExample")) std::cout<<"We find the table that we expected - good!"<<std::endl; + if (db->checkTableFromDB("PublishedFullPhysVols_HelloToyExample")) std::cout<<"We find the table that we expected - good!"<<std::endl; else std::cout<<"Uh oh, we don't find the expected table - bad!"<<std::endl; - if(!db->checkTable("PublishedFullPhysVols_ByeByeToyExample")) std::cout<<"We don't find the table that we didn't expect - good!"<<std::endl; + if(!db->checkTableFromDB("PublishedFullPhysVols_ByeByeToyExample")) std::cout<<"We don't find the table that we didn't expect - good!"<<std::endl; else std::cout<<"Uh oh, we found a table which doesn't exist - bad!"<<std::endl; //Now test via the specific accessors with additional checks @@ -165,31 +168,43 @@ int main(int argc, char *argv[]) unsigned int ii=0; std::cout << "\n\nPublished AlignableTransforms from the DB...\n"; std::cout << "['xf' is the output of 'getTransform()']\n"; + std::cout << "(Printing the first 3 only)" << std::endl; for ( auto const& [key, xf] : mapAXF ) { - if(0==ii) std::cout << "[key type (compiler's code): '" << typeid(key).name() << "']\n"; - std::cout << "\n\t--> key: " << key - << " - AlignableTransform*: " << xf + if (0 == ii) + std::cout << "[key type (compiler's code): '" << typeid(key).name() << "']\n"; + if (ii < 3) + { + + std::cout << "\n\t--> key: " << key + << " - AlignableTransform*: " << xf << std::endl; - std::cout << "\txf:: "; GeoUtilFunctions::printTrf( xf->getTransform() ); - ++ii; - } - + std::cout << "\txf:: "; + GeoUtilFunctions::printTrf(xf->getTransform()); + } + ++ii; + } + ii=0; // reset the counter std::cout << "\n\nPublished FullPhysVols from the DB...\n"; std::cout << "['xf' is the output of 'getAbsoluteTransform()']\n"; + std::cout << "(Printing the first 3 only)" << std::endl; for ( auto const& [key, vol] : mapFPV ) { - GeoTrf::Transform3D xf = vol->getAbsoluteTransform(); - - if(0==ii) std::cout << "[key type (compiler's code): '" << typeid(key).name() << "']\n"; - std::cout << "\n\t--> key: " << key - << " - GeoFullPhysVol*: " << vol - << std::endl; - std::cout << "\txf:"; GeoUtilFunctions::printTrf(vol->getAbsoluteTransform()); + // GeoTrf::Transform3D xf = vol->getAbsoluteTransform(); // crashes + + if (0 == ii) + std::cout << "[key type (compiler's code): '" << typeid(key).name() << "']\n"; + if (ii < 3) + { + std::cout << "\n\t--> key: " << key + << " - GeoFullPhysVol*: " << vol + << std::endl; + // std::cout << "\txf:"; GeoUtilFunctions::printTrf(vol->getAbsoluteTransform()); // crashes + } ++ii; } - + std::cout << "Everything done." << std::endl; return 0; diff --git a/GeoModelExamples/HelloToyWrite/CMakeLists.txt b/GeoModelExamples/HelloToyWrite/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..63164e06728d79a3a8b6c2262066c01d03ee292e --- /dev/null +++ b/GeoModelExamples/HelloToyWrite/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +################################################################################ +# Package: HelloToy +# author: Riccardo Maria BIANCHI @ CERN - Aug, 2020 +################################################################################ + +cmake_minimum_required(VERSION 3.16...3.26) + +project(HelloToyWrite) + +# Compile with C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + +# Find the needed dependencies, when building individually +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + find_package( GeoModelCore REQUIRED ) + find_package( GeoModelIO REQUIRED ) +endif() + +# Find includes in current dir +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Populate a CMake variable with the sources +set(SRCS main.cpp ) + +# Tell CMake to create the 'helloToy' executable +add_executable( helloToyWrite ${SRCS} ) + +# Link all needed libraries +target_link_libraries( helloToyWrite GeoModelCore::GeoModelKernel GeoModelIO::GeoModelWrite ) diff --git a/GeoModelExamples/HelloToyWrite/main.cpp b/GeoModelExamples/HelloToyWrite/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f6b35e3ba9e85b85b3c236ef3bd84d2e6b7c66f --- /dev/null +++ b/GeoModelExamples/HelloToyWrite/main.cpp @@ -0,0 +1,270 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* +* author: Riccardo Maria Bianchi @ CERN - 2020 +* +* The example show how to write a more complex Toy detector geometry, +* through the use of GeoSerialTransformers. +* It also shows how to publish the list of FullPhysVol and AlignableTransform nodes, +* to be retrieved later (for example, when setting the readout geometry up). +* +*/ + +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoLogVol.h" +#include "GeoModelKernel/GeoNameTag.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoSerialDenominator.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoSerialTransformer.h" +#include "GeoModelKernel/GeoPublisher.h" +#include "GeoModelKernel/GeoUtilFunctions.h" + +#include "GeoGenericFunctions/AbsFunction.h" +#include "GeoGenericFunctions/Variable.h" +#include "GeoGenericFunctions/Sin.h" +#include "GeoGenericFunctions/Cos.h" + +#include "GeoModelDBManager/GMDBManager.h" + +#include "GeoModelWrite/WriteGeoModel.h" + +// Units +#include "GeoModelKernel/Units.h" +#define SYSTEM_OF_UNITS GeoModelKernelUnits // so we will get, e.g., 'SYSTEM_OF_UNITS::cm' + +// C++ includes +#include <iostream> +#include <fstream> +#include <cstdlib> // EXIT_FAILURE + +using namespace GeoGenfun; +using namespace GeoXF; + +int main(int argc, char *argv[]) +{ + //-----------------------------------------------------------------------------------// + // Define the materials that we shall use. // + // ----------------------------------------------------------------------------------// + + // Define the units + #define gr SYSTEM_OF_UNITS::gram + #define mole SYSTEM_OF_UNITS::mole + #define cm3 SYSTEM_OF_UNITS::cm3 + + // Define the chemical elements + GeoElement* Nitrogen = new GeoElement ("Nitrogen" ,"N" , 7.0 , 14.0067 *gr/mole); + GeoElement* Oxygen = new GeoElement ("Oxygen" ,"O" , 8.0 , 15.9995 *gr/mole); + GeoElement* Argon = new GeoElement ("Argon" ,"Ar" , 18.0 , 39.948 *gr/mole); + GeoElement* Hydrogen = new GeoElement ("Hydrogen" ,"H" , 1.0 , 1.00797 *gr/mole); + GeoElement* Iron = new GeoElement ("Iron" ,"Fe" , 26.0 , 55.847 *gr/mole); + GeoElement* Carbon = new GeoElement ("Carbon" ,"C" , 6.0 , 12.0107 *gr/mole); + GeoElement* Sillicon = new GeoElement ("Silicon" ,"Si" , 14.0 , 28.085 *gr/mole); + + // Define the materials + + // Air: Nitrogen + Oxygen + Argon + Hydrogen + double densityOfAir=0.001214 *gr/cm3; + GeoMaterial *air = new GeoMaterial("Air", densityOfAir); + air->add(Nitrogen , 0.7494); + air->add(Oxygen, 0.2369); + air->add(Argon, 0.0129); + air->add(Hydrogen, 0.0008); + air->lock(); + + // Steel: Iron + Carbon + GeoMaterial* steel = new GeoMaterial("Steel", 7.9 *gr/cm3); + steel->add(Iron , 0.98); + steel->add(Carbon, 0.02); + steel->lock(); + + // Silicon 100% (Detector) + GeoMaterial* silicon = new GeoMaterial("Silicon", 2.329 *gr/cm3); + silicon->add(const_cast<GeoElement*> (Sillicon), 1.0); + silicon->lock(); + + // Carbon + GeoMaterial* carbon = new GeoMaterial("Carbon", 2.329 *gr/cm3); + carbon->add(const_cast<GeoElement*> (Carbon), 1.0); + carbon->lock(); + + + //--------------------------------------// + // Next make the box that describes + // the shape of the toy volume: + //--------------------------------------// + const GeoBox *toyBox = new GeoBox(1200*SYSTEM_OF_UNITS::cm,1200*SYSTEM_OF_UNITS::cm, 1200*SYSTEM_OF_UNITS::cm); + + //--------------------------------------// + // Bundle this with a material + // into a logical volume: + //--------------------------------------// + const GeoLogVol *toyLog = new GeoLogVol("ToyLog", toyBox, air); // + + //--------------------------------------// + // ..And create a physical volume: + //--------------------------------------// + GeoPhysVol *toyPhys = new GeoPhysVol(toyLog); + + //--------------------------------------// + // Daughters + //--------------------------------------// + const GeoTube *ringTube = new GeoTube(500*SYSTEM_OF_UNITS::cm, 1000*SYSTEM_OF_UNITS::cm, 5.0*SYSTEM_OF_UNITS::cm); + + // Bundle this with a material // + // into a logical volume: // + const GeoLogVol *ringLog = new GeoLogVol("RingLog", ringTube, carbon); + + // Make 100 of these // + // within the volume of the toy: // + GeoSerialDenominator *ringName = new GeoSerialDenominator("RING"); + toyPhys->add(ringName); + + // Instanciate a GeoPublisher, to publish the list of FullPhysVol and AlignableTransforms nodes + GeoPublisher* publisher = new GeoPublisher; + // Optional - We set a name for the publisher: it will be appended to the name of the DB tables that host our published AXF and FPV nodes. + // Note : This is not compulsory: if not set, the default table name will be used; + // however, it helps to keep the output data well organized. + publisher->setName("HelloToyExample"); + + for (int i=0;i<100;i++) { + GeoFullPhysVol *ringPhys = new GeoFullPhysVol(ringLog); + GeoAlignableTransform *xform = new GeoAlignableTransform(GeoTrf::TranslateZ3D((i-50)*20*SYSTEM_OF_UNITS::cm)); + toyPhys->add(xform); + toyPhys->add(ringPhys); + + + // *** publish the list of FPV and AXF nodes *** + // in this example, we use integer-based keys for FullPhysVols... + unsigned int keyInt = i+1; + publisher->publishNode<GeoVFullPhysVol*,unsigned>(ringPhys, keyInt); + // ...and string-based keys for AlignableTransforms + std::string keyStr = "HelloToy-AXF-" + std::to_string(i+1); + publisher->publishNode<GeoAlignableTransform*,std::string>(xform, keyStr); + + // std::cout << "step1 - FPV, key: " << keyInt << std::endl; + // << " - xf: " // we cannot get the XF of a FPV direct;y anymore, it seems... + // GeoUtilFunctions::printTrf(ringPhys->getAbsoluteTransform()); + + } + + + //--------------------------------------// + // Now, in addition to active daughters, + // add some passive material. + // This is done here using + // the "SerialTransformer", + // our way of parameterizing volumes. + // It does not need to be done this way, + // but we want to provide an example of + // parametrizations in the Toy + //--------------------------------------// + + GeoBox *sPass = new GeoBox(5.0*SYSTEM_OF_UNITS::cm, 30*SYSTEM_OF_UNITS::cm, 30*SYSTEM_OF_UNITS::cm); + GeoLogVol *lPass = new GeoLogVol("Passive", sPass, steel); + GeoPhysVol *pPass = new GeoPhysVol(lPass); + + GeoBox *sIPass = new GeoBox(4*SYSTEM_OF_UNITS::cm, 25*SYSTEM_OF_UNITS::cm, 25*SYSTEM_OF_UNITS::cm); + GeoLogVol *lIPass = new GeoLogVol("InnerPassive", sIPass, silicon); + GeoPhysVol *pIPass = new GeoPhysVol(lIPass); + + pPass->add(pIPass); + + const unsigned int NPLATES=100; + Variable i; + Sin sin; + GENFUNCTION f = 360*SYSTEM_OF_UNITS::deg/NPLATES*i; + GENFUNCTION g = sin(4*f); + GENFUNCTION h = -g; + TRANSFUNCTION t1 = Pow(GeoTrf::RotateZ3D(1.0),f)*GeoTrf::TranslateX3D(1100*SYSTEM_OF_UNITS::cm)*Pow(GeoTrf::TranslateZ3D(800*SYSTEM_OF_UNITS::cm),g); + TRANSFUNCTION t2 = Pow(GeoTrf::RotateZ3D(1.0),f)*GeoTrf::TranslateX3D(1100*SYSTEM_OF_UNITS::cm)*Pow(GeoTrf::TranslateZ3D(800*SYSTEM_OF_UNITS::cm),h); + + //--------------------------------------// + // Inside, by the way, the serial transformer + // will evaluate the functions: + // HepTransform3D xf = t1(i), for i=1,NPLATES.... + //--------------------------------------// + + GeoSerialDenominator *pass1Name = new GeoSerialDenominator("PASSIVE-1-"); + GeoSerialTransformer *s1 = new GeoSerialTransformer(pPass,&t1, NPLATES); + toyPhys->add(pass1Name); + toyPhys->add(s1); + + GeoSerialDenominator *pass2Name = new GeoSerialDenominator("PASSIVE-2-"); + GeoSerialTransformer *s2 = new GeoSerialTransformer(pPass,&t2, NPLATES); + toyPhys->add(pass2Name); + toyPhys->add(s2); + + + + //------------------------------------------------------------------------------------// + // Writing the geometry to file + //------------------------------------------------------------------------------------// + std::string path = "geometry.db"; + + // check if DB file exists. If yes, delete it. + std::ifstream infile(path.c_str()); + if ( infile.good() ) { + if( remove( path.c_str() ) != 0 ) + perror( "Error deleting file" ); + else { + std::string msg = "Previously existing " + path + " successfully deleted"; + puts( msg.c_str() ); + } + } + infile.close(); + + // open the DB connection + GMDBManager db(path); + + // check the DB connection + if (db.checkIsDBOpen()) { + std::cout << "OK! Database is open!" << std::endl; + } else { + std::cout << "Database ERROR!! Exiting..." << std::endl; + exit(EXIT_FAILURE); + } + + // Dump the tree volumes to a local file + std::cout << "Dumping the GeoModel geometry to the DB file..." << std::endl; + GeoModelIO::WriteGeoModel dumpGeoModelGraph(db); // init the GeoModel node action + toyPhys->exec(&dumpGeoModelGraph); // visit all GeoModel nodes + + // Save the GeoModel tree to the SQlite DB file. + // We pass a pointer to the GeoPublisher as well, so the list of published + // FullPhysVol and AlignableTransform nodes will be stored into the DB too. + dumpGeoModelGraph.saveToDB( publisher ); + + std::cout << "\n-----\nDONE. Geometry saved.\n-----\n" <<std::endl; + + + //------------------------------------------------------------------------------------// + // Testing the persitified geometry + //------------------------------------------------------------------------------------// +/* + std::cout << "\nTest - list of all the GeoFullPhysVol nodes in the persistified geometry:" << std::endl; + db.printAllFullPhysVols(); + std::cout << "\nTest - list of all the GeoAlignableTransform nodes in the persistified geometry:" << std::endl; + db.printAllAlignableTransforms(); + + std::cout << "\nTest - list of all the 'published' GeoFullPhysVol nodes in the persistified geometry:" << std::endl; + db.printAllPublishedFullPhysVols( publisher->getName() ); + std::cout << "\nTest - list of all the 'published' GeoAlignableTransform nodes in the persistified geometry:" << std::endl; + db.printAllPublishedAlignableTransforms( publisher->getName() ); +*/ + // cleaning + delete publisher; + publisher = nullptr; + + + return 0; + +} + diff --git a/GeoModelExamples/KitchenSinkPlugin/CMakeLists.txt b/GeoModelExamples/KitchenSinkPlugin/CMakeLists.txt index 03fe5807050a679bbf6f2a76b9640ca601a43a27..52287268ce53399782dd25c75aa20eaf826ce014 100644 --- a/GeoModelExamples/KitchenSinkPlugin/CMakeLists.txt +++ b/GeoModelExamples/KitchenSinkPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: HelloGeo @@ -14,11 +14,11 @@ set(CMAKE_CXX_EXTENSIONS ON) # Find the needed dependencies, when building individually - message (${CMAKE_SOURCE_DIR}) + message (${CMAKE_SOURCE_DIR}) message (${PROJECT_SOURCE_DIR}) - + if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually - find_package( GeoModelCore REQUIRED ) + find_package( GeoModelCore REQUIRED ) endif() @@ -28,10 +28,6 @@ file( GLOB SOURCES src/*.cxx ) add_library( KitchenSinkPlugin SHARED ${SOURCES} ) target_link_libraries( KitchenSinkPlugin PUBLIC GeoModelCore::GeoModelKernel) -target_include_directories( KitchenSinkPlugin PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) - source_group( "src" FILES ${SOURCES} ) set_target_properties( KitchenSinkPlugin PROPERTIES @@ -44,4 +40,3 @@ install( TARGETS KitchenSinkPlugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime NAMELINK_SKIP ) - diff --git a/GeoModelExamples/MinimalPlugin/CMakeLists.txt b/GeoModelExamples/MinimalPlugin/CMakeLists.txt index f18dbe0f13576663c90929ba38bd2f2cc0ec258e..59c5a684d3e257578f154f994baabfdffc75a6b5 100644 --- a/GeoModelExamples/MinimalPlugin/CMakeLists.txt +++ b/GeoModelExamples/MinimalPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: MinimalPlugin @@ -14,11 +14,11 @@ set(CMAKE_CXX_EXTENSIONS ON) # Find the needed dependencies, when building individually - message (${CMAKE_SOURCE_DIR}) + message (${CMAKE_SOURCE_DIR}) message (${PROJECT_SOURCE_DIR}) - + if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually - find_package( GeoModelCore REQUIRED ) + find_package( GeoModelCore REQUIRED ) endif() @@ -28,10 +28,6 @@ file( GLOB SOURCES src/*.cxx ) add_library( MinimalPlugin SHARED ${SOURCES} ) target_link_libraries( MinimalPlugin PUBLIC GeoModelCore::GeoModelKernel) -target_include_directories( MinimalPlugin PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) - source_group( "src" FILES ${SOURCES} ) set_target_properties( MinimalPlugin PROPERTIES @@ -44,4 +40,3 @@ install( TARGETS MinimalPlugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime NAMELINK_SKIP ) - diff --git a/GeoModelExamples/SharedNodes/shared_serialtransformers.cpp b/GeoModelExamples/SharedNodes/shared_serialtransformers.cpp index 240a10bfb50743874d42e58153b29d4c410cc668..3e11e9c0fd25fa75dac9e07cb1da6f7227197761 100644 --- a/GeoModelExamples/SharedNodes/shared_serialtransformers.cpp +++ b/GeoModelExamples/SharedNodes/shared_serialtransformers.cpp @@ -1,12 +1,12 @@ -// Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration /* * This example tests shared GeoSerialTransformer nodes. * * It creates one single LogVol, with one Material and one Shape. * Then it creates one single PhysVol volumes using the above LogVol. - * Then it creates three SerialTrasnformers with different placing formulas, - * but which share the same PhisVol defined above. + * Then it creates two SerialTrasnformers with two different placing formulas, + * but which share the same PhysVol defined above. * * It is meant to how how to share GeoModel nodes to reduce the memory footprint * and to test the GeoModel I/O packages and methods. diff --git a/GeoModelExamples/SharedNodes/shared_serialtransformers_2.cpp b/GeoModelExamples/SharedNodes/shared_serialtransformers_2.cpp index 1f0ecc358860d092fc7507006f8f2fa610245945..a79c29d92b8c46fcdfa0ae9c6fce467095c8d8b1 100644 --- a/GeoModelExamples/SharedNodes/shared_serialtransformers_2.cpp +++ b/GeoModelExamples/SharedNodes/shared_serialtransformers_2.cpp @@ -4,7 +4,9 @@ * This example tests shared GeoSerialTransformer nodes. * * In particular, it tests three serialtransformers that share a single PhysVol - * volume and a single Function. + * volume and: + * - two of them share the same placing formula + * - one of them has its own placing formula * * Author: Riccardo Maria BIANCHI @ CERN * Created on: Feb, 2023 diff --git a/GeoModelExamples/SharedNodes/shared_serialtransformers_3.cpp b/GeoModelExamples/SharedNodes/shared_serialtransformers_3.cpp index e955bdfa4deed31f5486eb35470153fa68aaa5b3..598d0026d028fe3a4dd0eb3180a50138fd3c1922 100644 --- a/GeoModelExamples/SharedNodes/shared_serialtransformers_3.cpp +++ b/GeoModelExamples/SharedNodes/shared_serialtransformers_3.cpp @@ -4,7 +4,12 @@ * This example tests shared GeoSerialTransformer nodes. * * In particular, it tests three serialtransformers that share a single PhysVol - * volume and a single Function. + * volume and: + * - two of them share the same placing formula + * - one of them has its own placing formula + * This test also adds complexity by adding instances of IdentifierTag and SerialIdentifier nodes, + * and uses the PhysVol used by the SerialTrasnformers by placing it + * in the world with a Transform and an Indentifier. * * Author: Riccardo Maria BIANCHI @ CERN * Created on: Feb, 2023 diff --git a/GeoModelExamples/SiliconSystemExample/CMakeLists.txt b/GeoModelExamples/SiliconSystemExample/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0745122e0a7c08d34ff150ea98f1b4b08c1b966 --- /dev/null +++ b/GeoModelExamples/SiliconSystemExample/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +################################################################################ +# Package: HelloGeo +# author: Riccardo Maria BIANCHI @ CERN - Nov, 2018 +################################################################################ + +cmake_minimum_required(VERSION 3.16...3.26) + +# Compile with C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + + +# Find the needed dependencies, when building individually + message (${CMAKE_SOURCE_DIR}) + message (${PROJECT_SOURCE_DIR}) + +if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually + find_package( GeoModelCore REQUIRED ) +endif() + + +# Find the header and source files. +file( GLOB SOURCES src/*.cxx ) + +add_library( SiliconSystemPlugin SHARED ${SOURCES} ) +target_link_libraries( SiliconSystemPlugin PUBLIC GeoModelCore::GeoModelKernel) + +source_group( "src" FILES ${SOURCES} ) + +set_target_properties( SiliconSystemPlugin PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) + +# Install the library. +install( TARGETS SiliconSystemPlugin + EXPORT ${PROJECT_NAME}-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Runtime + NAMELINK_SKIP ) diff --git a/GeoModelExamples/SiliconSystemExample/src/SiliconSystemPlugin.cxx b/GeoModelExamples/SiliconSystemExample/src/SiliconSystemPlugin.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9b56e4c9f612da3238cd2a331bbd479985b78d25 --- /dev/null +++ b/GeoModelExamples/SiliconSystemExample/src/SiliconSystemPlugin.cxx @@ -0,0 +1,226 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ + +// ------------------------------------------------------------------- +// +// Kitchen Sink Plugin +// Joe Boudreau Jan 11 2021 +// +// This is an example plugin. It compiles to a shared library +// (with .so or .dylib extension) which can be viewed with gmex. +// In this example there is no "envelope", all the components of +// the kitchen sink are placed into the world. This example +// contains a geometry clash or two. Therefore it may also be +// used to test clash detection. +// +// This example illustrates the use of: +// +// --the plugin mechanism. +// --simple shapes, logical volumes, physical volumes +// --Boolean operations +// --define air +// --pure materials (aluminium) +// --mixtures (stainless steel) +// +// -------------------------------------------------------------------- + +#include "GeoModelKernel/GeoVGeometryPlugin.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoTrd.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoLogVol.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/Units.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoVSurface.h" +#include <random> +using namespace GeoModelKernelUnits; +std::mt19937 engine; +// Class Declaration +const double degrees=M_PI/180.0; +class SiliconSystemPlugin : public GeoVGeometryPlugin { + + public: + + // Constructor: + SiliconSystemPlugin(); + + // Destructor: + ~SiliconSystemPlugin(); + + // Creation of geometry: + virtual void create(GeoVPhysVol *world, bool publish=false); + + private: + + // Illegal operations: + const SiliconSystemPlugin & operator=(const SiliconSystemPlugin &right)=delete; + SiliconSystemPlugin(const SiliconSystemPlugin &right) = delete; + +}; + + +// Class definition: + +// Constructor +SiliconSystemPlugin::SiliconSystemPlugin() +{ +} + +// Destructor +SiliconSystemPlugin::~SiliconSystemPlugin() +{ +} + +// The create algorithm creates a tree of physical volumes rooted under the +// "world" physical volume. The optional flag publish is not used in this +// example (normally one may "publish" a list of FullPhysVol's and Alignable +// transforms, but this example has none such). +// +void SiliconSystemPlugin::create(GeoVPhysVol *world, bool /*publish*/) { + const double degree = M_PI / 180.0; + + // Define elements used in this example: + GeoElement *oxygen = new GeoElement("Oxygen", "O", 19, 39*gram/mole); + GeoElement *nitrogen = new GeoElement("Nitrogen", "N", 7, 14*gram/mole); + GeoElement *argon = new GeoElement("Argon", "Ar", 18, 40*gram/mole); + GeoElement *aluminium = new GeoElement("Aluminium", "Al", 13, 26*gram/mole); + GeoElement *iron = new GeoElement("Iron", "Fe", 26, 55.8*gram/mole); + GeoElement *chromium = new GeoElement("Chromium", "Cr", 24, 52*gram/mole); + + // Define materials: + + // Define Air: + double densityOfAir = 1.2E-3*gram/cm3; // g/cm^3 + GeoMaterial *Air = new GeoMaterial("Air",densityOfAir); + Air->add(oxygen,2*0.21); // diatomic oxygen 21% by volume. + Air->add(nitrogen,2*0.78); // diatomic nitrogen 78% by volume. + Air->add(argon,0.01); // monoatomic argon 78% by volume. + Air->lock(); + + std::normal_distribution<double> normal; + + // Define Aluminium + double densityOfAluminium=2.7*gram/cm3; // g/cm^3 + GeoMaterial *Aluminium = new GeoMaterial("Aluminium", densityOfAluminium); + Aluminium->add(aluminium,1.0); + Aluminium->lock(); + + GeoBox *boxShape = new GeoBox(10,10,10); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoPhysVol *worldBOX = new GeoPhysVol(boxLog); + + GeoBox *box1 = new GeoBox (0.1,1*1.7,20); + GeoLogVol *boxLog1 = new GeoLogVol("SiDet", box1, Aluminium); + + GeoBox *box2 = new GeoBox (0.1,2*1.7,20); + GeoLogVol *boxLog2 = new GeoLogVol("SiDet", box2, Aluminium); + + GeoBox *box3 = new GeoBox (0.1,3*1.7,20); + GeoLogVol *boxLog3 = new GeoLogVol("SiDet", box3, Aluminium); + + GeoRectSurface* rectSurface1 = new GeoRectSurface(1*1.9, 20.2); + GeoRectSurface* rectSurface2 = new GeoRectSurface(2*1.9, 20.2); + GeoRectSurface* rectSurface3 = new GeoRectSurface(3*1.9, 20.2); + + for (int k=0;k<3;k++) { + for (int j=0;j<3;j++) { + GeoLogVol* boxLog; + if(j==0) boxLog = boxLog1; + else if(j==1) boxLog = boxLog2; + else boxLog = boxLog3; + + GeoRectSurface* rectSurface; + if(j==0) rectSurface = rectSurface1; + else if(j==1) rectSurface = rectSurface2; + else rectSurface = rectSurface3; + + for (int i=0;i<16;i++) { + double theta = i/16.0*2*M_PI; + GeoFullPhysVol *boxPhys=new GeoFullPhysVol(boxLog); + GeoVSurface* surf = new GeoVSurface(rectSurface); + // Initial transform is very tricky. Because the Virtual surface is always facing to Z axis initially. + GeoAlignableTransform* xf0 = new GeoAlignableTransform(GeoTrf::RotateZ3D(theta)*GeoTrf::TranslateX3D((j+1)*8.0+0.4*(i%2))*GeoTrf::TranslateX3D(0.5)*GeoTrf::TranslateZ3D((k-1)*44.0)*GeoTrf::RotateX3D(M_PI/2.0)*GeoTrf::RotateY3D(M_PI/2.0)); + GeoAlignableTransform *xf = new GeoAlignableTransform(GeoTrf::RotateZ3D(theta)*GeoTrf::TranslateX3D((j+1)*8.0+0.4*(i%2))); + + double rndTheta=normal(engine)*5*degrees; + double rndPhi=normal(engine)*5*degrees; + double rndPsi=normal(engine)*5*degrees; + + // The Delta Setting is really tricky. The local axis are different because of different initialization order. + Eigen::Matrix3d m; + m = Eigen::AngleAxisd(rndTheta, Eigen::Vector3d::UnitZ()) + * Eigen::AngleAxisd(rndPhi, Eigen::Vector3d::UnitY()) + * Eigen::AngleAxisd(rndPsi, Eigen::Vector3d::UnitZ()); + + Eigen::Matrix3d m0; + m0 = Eigen::AngleAxisd(rndTheta, Eigen::Vector3d::UnitY()) + * Eigen::AngleAxisd(rndPhi, Eigen::Vector3d::UnitX()) + * Eigen::AngleAxisd(rndPsi, Eigen::Vector3d::UnitY()); + + xf0->setDelta(GeoTrf::Transform3D(m0)); + xf->setDelta(GeoTrf::Transform3D(m)); + worldBOX->add(new GeoTransform(GeoTrf::TranslateZ3D((k-1)*44.0))); + + worldBOX->add(xf); + worldBOX->add(boxPhys); + + worldBOX->add(xf0); + worldBOX->add(surf); + } + } + + } + double L=10.0; + GeoTrapezoidSurface* trapezoid = new GeoTrapezoidSurface(1.2, 5.2, L); + GeoTrd *trd=new GeoTrd(.2, .2, 1, 5, L); + GeoLogVol *trdLog=new GeoLogVol("SiDetEnd", trd,Aluminium); + + for (int j=0;j<16;j++) { + for (int i=-1;i<2;i+=2) { + GeoVSurface* surf = new GeoVSurface(trapezoid); + GeoFullPhysVol *trdPhys=new GeoFullPhysVol(trdLog); + + GeoTransform *sf0=new GeoTransform(GeoTrf::RotateY3D(j*2*M_PI/16.0)*GeoTrf::RotateX3D(M_PI/2.0)*GeoTrf::TranslateY3D(1.5*L)); + GeoAlignableTransform* sf1 = nullptr; + if(i==-1){ + std::cout << "i = -1" << std::endl; + sf1 = new GeoAlignableTransform(GeoTrf::TranslateZ3D(i*80.0+2.0*(j%2))*GeoTrf::TranslateZ3D(-1.0)*GeoTrf::RotateX3D(M_PI/2.0)*GeoTrf::RotateY3D(M_PI/2.0)); + } + else{ + std::cout << "i = 1" << std::endl; + sf1 = new GeoAlignableTransform(GeoTrf::TranslateZ3D(i*80.0+2.0*(j%2))*GeoTrf::TranslateZ3D(1.0)*GeoTrf::RotateX3D(M_PI/2.0)*GeoTrf::RotateY3D(M_PI/2.0)); + } + + GeoTransform *xf0=new GeoTransform(GeoTrf::RotateZ3D(j*2*M_PI/16.0)*GeoTrf::RotateY3D(M_PI/2.0)*GeoTrf::TranslateZ3D(1.5*L)); + GeoAlignableTransform *xf1= new GeoAlignableTransform (GeoTrf::TranslateZ3D(i*80.0+2.0*(j%2))); + + + worldBOX->add(xf1); + worldBOX->add(xf0); + worldBOX->add(trdPhys); + worldBOX->add(sf1); + worldBOX->add(sf0); + worldBOX->add(surf); + } + } + world->add(worldBOX); + //--------------------------------------// +} + +// The name of this routine must correspond to the name of the class, +// and also to the name of the source code file (this file) + +extern "C" SiliconSystemPlugin *createSiliconSystemPlugin() { + return new SiliconSystemPlugin; +} + diff --git a/GeoModelExamples/SurfAlignTestPlugin/CMakeLists.txt b/GeoModelExamples/SurfAlignTestPlugin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb011ac2aa16bea6e1c278f0e2c5f98d720dac75 --- /dev/null +++ b/GeoModelExamples/SurfAlignTestPlugin/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +################################################################################ +# Package: HelloGeo +# author: Riccardo Maria BIANCHI @ CERN - Nov, 2018 +################################################################################ + +cmake_minimum_required(VERSION 3.16...3.26) + +# Compile with C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + + +# Find the needed dependencies, when building individually + message (${CMAKE_SOURCE_DIR}) + message (${PROJECT_SOURCE_DIR}) + +if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually + find_package( GeoModelCore REQUIRED ) +endif() + + +# Find the header and source files. +file( GLOB SOURCES src/*.cxx ) + +add_library( SurfAlignTestPlugin SHARED ${SOURCES} ) +target_link_libraries( SurfAlignTestPlugin PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers) + +source_group( "src" FILES ${SOURCES} ) + +set_target_properties( SurfAlignTestPlugin PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) + +# Install the library. +install( TARGETS SurfAlignTestPlugin + EXPORT ${PROJECT_NAME}-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Runtime + NAMELINK_SKIP ) diff --git a/GeoModelExamples/SurfAlignTestPlugin/src/SurfAlignTestPlugin.cxx b/GeoModelExamples/SurfAlignTestPlugin/src/SurfAlignTestPlugin.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ddd1847772599489fe9f813083e478d6dc119da5 --- /dev/null +++ b/GeoModelExamples/SurfAlignTestPlugin/src/SurfAlignTestPlugin.cxx @@ -0,0 +1,239 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ + +// ------------------------------------------------------------------- +// +// Kitchen Sink Plugin +// Joe Boudreau Jan 11 2021 +// +// This is an example plugin. It compiles to a shared library +// (with .so or .dylib extension) which can be viewed with gmex. +// +// This plugin is used to test and develop surfaces, our first +// example of virtual geometry. +// +// +// -------------------------------------------------------------------- + +#include "GeoModelKernel/GeoVGeometryPlugin.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoPrintGraphAction.h" +#include "GeoModelKernel/GeoVolumeCursor.h" + +#include "GeoModelKernel/GeoLogVol.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/Units.h" +#include "GeoModelHelpers/defineWorld.h" + +#include "GeoModelKernel/GeoSurfaceCursor.h" +#include "GeoModelKernel/GeoCountSurfaceAction.h" +#include "GeoModelKernel/GeoCountVolAction.h" +#include "GeoModelKernel/GeoAccessSurfaceAction.h" +#include "GeoModelKernel/GeoAccessVolumeAction.h" +using namespace GeoModelKernelUnits; + +// Class Declaration + +class SurfAlignTestPlugin : public GeoVGeometryPlugin { + + public: + + // Constructor: + SurfAlignTestPlugin(); + + // Destructor: + ~SurfAlignTestPlugin(); + + // Creation of geometry: + virtual void create(GeoVPhysVol *world, bool publish=false); + + private: + + // Illegal operations: + const SurfAlignTestPlugin & operator=(const SurfAlignTestPlugin &right)=delete; + SurfAlignTestPlugin(const SurfAlignTestPlugin &right) = delete; + +}; + + +// Class definition: + +// Constructor +SurfAlignTestPlugin::SurfAlignTestPlugin() +{ +} + +// Destructor +SurfAlignTestPlugin::~SurfAlignTestPlugin() +{ +} + +// The create algorithm creates a tree of physical volumes rooted under the +// "world" physical volume. The optional flag publish is not used in this +// example (normally one may "publish" a list of FullPhysVol's and Alignable +// transforms, but this example has none such). +// +void SurfAlignTestPlugin::create(GeoVPhysVol *world, bool /*publish*/) { + // Define elements used in this example: + GeoElement *oxygen = new GeoElement("Oxygen", "O", 19, 39*gram/mole); + GeoElement *nitrogen = new GeoElement("Nitrogen", "N", 7, 14*gram/mole); + GeoElement *argon = new GeoElement("Argon", "Ar", 18, 40*gram/mole); + GeoElement *aluminium = new GeoElement("Aluminium", "Al", 13, 26*gram/mole); + + // Define materials: + + // Define Air: + double densityOfAir = 1.2E-3*gram/cm3; // g/cm^3 + GeoMaterial *Air = new GeoMaterial("Air",densityOfAir); + Air->add(oxygen,2*0.21); // diatomic oxygen 21% by volume. + Air->add(nitrogen,2*0.78); // diatomic nitrogen 78% by volume. + Air->add(argon,0.01); // monoatomic argon 78% by volume. + Air->lock(); + + // Define Aluminium + double densityOfAluminium=2.7*gram/cm3; // g/cm^3 + GeoMaterial *Aluminium = new GeoMaterial("Aluminium", densityOfAluminium); + Aluminium->add(aluminium,1.0); + Aluminium->lock(); + + GeoBox *boxShape = new GeoBox(10,15,20); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoPhysVol *boxPhys = new GeoPhysVol(boxLog); + + + { + +//////////////////////////////////////////////////////////////////////////////////////////////// + GeoBox *boxShape = new GeoBox(3,7,5); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoFullPhysVol *boxPhys1 = new GeoFullPhysVol(boxLog); + GeoRectSurface* rectSurface1 = new GeoRectSurface(5, 9); + GeoVSurface* surf1 = new GeoVSurface(rectSurface1); + GeoAlignableTransform *move_together1=new GeoAlignableTransform(GeoTrf::TranslateX3D(0)); + //GeoTransform * initial_rot = new GeoTransform(GeoTrf::RotateY3D(1.571)); + + boxPhys->add(move_together1); + boxPhys->add(boxPhys1); + + boxPhys->add(move_together1); + //boxPhys->add(initial_rot); + boxPhys->add(surf1); + move_together1->setDelta(GeoTrf::RotateZ3D(1)*GeoTrf::RotateY3D(0.5)); + + GeoBox *boxShape2 = new GeoBox(4,4,4); + GeoLogVol *boxLog2 = new GeoLogVol("BoxLog",boxShape2,Air); + GeoFullPhysVol *boxPhys4 = new GeoFullPhysVol(boxLog2); + boxPhys1->add(boxPhys4); + + //GeoRectSurface *rectSurface3 = new GeoRectSurface(7, 7); + //GeoVSurface* surf4 = new GeoVSurface(rectSurface3); + // GeoTrapezoidSurface* trapezoid = new GeoTrapezoidSurface(9, 7, 5); + // GeoVSurface* surf4 = new GeoVSurface(trapezoid); + GeoDiamondSurface* diamond = new GeoDiamondSurface(4, 6, 2, 5, 3); + GeoVSurface* surf4 = new GeoVSurface(diamond); + GeoTransform * initial_rot = new GeoTransform(GeoTrf::RotateY3D(1.571)); + boxPhys1->add(initial_rot); + boxPhys1->add(surf4); +//////////////////////////////////////////////////////////////////////////////////////////////// + + GeoFullPhysVol *boxPhys2 = new GeoFullPhysVol(boxLog); + //GeoRectSurface *rectSurface2 = new GeoRectSurface(8, 8); + //GeoVSurface* surf2 = new GeoVSurface(rectSurface2); + // GeoTrapezoidSurface* trapezoid2 = new GeoTrapezoidSurface(4, 6, 8); + // GeoVSurface* surf2 = new GeoVSurface(trapezoid2); + GeoDiamondSurface* diamond2 = new GeoDiamondSurface(8, 12, 4, 10, 6); + GeoVSurface* surf2 = new GeoVSurface(diamond2); + GeoAlignableTransform *move_together2=new GeoAlignableTransform(GeoTrf::TranslateX3D(-20)); + + boxPhys->add(move_together2); + boxPhys->add(boxPhys2); + boxPhys->add(move_together2); + boxPhys->add(surf2); + move_together2->setDelta(GeoTrf::RotateZ3D(0)); + +//////////////////////////////////////////////////////////////////////////////////////////////// + + GeoFullPhysVol *boxPhys3 = new GeoFullPhysVol(boxLog); + //GeoRectSurface *rectSurface3 = new GeoRectSurface(8, 8); + //GeoVSurface* surf3 = new GeoVSurface(rectSurface2); + GeoTrapezoidSurface* trapezoid2 = new GeoTrapezoidSurface(4, 6, 8); + GeoVSurface* surf3 = new GeoVSurface(trapezoid2); + GeoAlignableTransform *move_together3=new GeoAlignableTransform(GeoTrf::TranslateX3D(20)); + + boxPhys->add(move_together3); + boxPhys->add(boxPhys3); + boxPhys->add(move_together3); + boxPhys->add(surf3); + move_together3->setDelta(GeoTrf::RotateX3D(0)); + + } + + GeoTrapezoidSurface* trapezoid2 = new GeoTrapezoidSurface(9, 12, 8); + GeoVSurface* surf5 = new GeoVSurface(trapezoid2); + GeoAlignableTransform *move_together5=new GeoAlignableTransform(GeoTrf::TranslateX3D(40)); + + boxPhys->add(move_together5); + boxPhys->add(surf5); + move_together5->setDelta(GeoTrf::RotateX3D(1)); + + world->add(boxPhys); + GeoPrintGraphAction printGraphAction(std::cout); + world->exec(&printGraphAction);; + + { + int i = 0; + + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " cursor at i= " << i << std::endl; + GeoVolumeCursor cursor(boxPhys); + //GeoSurfaceCursor cursor(boxPhys); + + while (!cursor.atEnd()) { + i += 1; + std::cout << "!!! " << std::endl; + std::cout << cursor.getTransform().rotation() << std::endl; + std::cout << "!!! " << std::endl; + std::cout << cursor.getTransform().translation() << std::endl; + std::cout << " " << std::endl; + cursor.next(); + } + } + + + GeoCountSurfaceAction countSurface; + boxPhys->exec(&countSurface); + std::cout << "Number of Virtual Surface: " << countSurface.getCount() << std::endl; + unsigned int totalVSurface = countSurface.getCount(); + + for (unsigned int i = 0; i< totalVSurface; i++){ + GeoAccessSurfaceAction surfaceAccess (i, nullptr); + boxPhys->exec(&surfaceAccess); + std::cout << "surface transform rotation: " << surfaceAccess.getTransform().rotation() << std::endl; + std::cout << "surface transform trans: " << surfaceAccess.getTransform().translation() << std::endl; + } + std::cout << "surface5 transform trans: " << surf5->getX().rotation() << std::endl; + std::cout << "surface5 transform trans: " << surf5->getX().translation() << std::endl; + //--------------------------------------// +} + +// The name of this routine must correspond to the name of the class, +// and also to the name of the source code file (this file) + +extern "C" SurfAlignTestPlugin *createSurfAlignTestPlugin() { + return new SurfAlignTestPlugin; +} + diff --git a/GeoModelExamples/SurfAnnulusDemo/CMakeLists.txt b/GeoModelExamples/SurfAnnulusDemo/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4bb45aee0dc33122090d00049ef62c22ba55ec9f --- /dev/null +++ b/GeoModelExamples/SurfAnnulusDemo/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.16...3.26) + +# Compile with C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + + +# Find the needed dependencies, when building individually + message (${CMAKE_SOURCE_DIR}) + message (${PROJECT_SOURCE_DIR}) + +if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually + find_package( GeoModelCore REQUIRED ) +endif() + + +# Find the header and source files. +file( GLOB SOURCES src/*.cxx ) + +add_library( SurfAnnulusDemo SHARED ${SOURCES} ) +target_link_libraries( SurfAnnulusDemo PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers) + +source_group( "src" FILES ${SOURCES} ) + +set_target_properties( SurfAnnulusDemo PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) + +# Install the library. +install( TARGETS SurfAnnulusDemo + EXPORT ${PROJECT_NAME}-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Runtime + NAMELINK_SKIP ) diff --git a/GeoModelExamples/SurfAnnulusDemo/src/SurfAnnulusDemo.cxx b/GeoModelExamples/SurfAnnulusDemo/src/SurfAnnulusDemo.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1cb6cd48c6dad55bc34504f2a07cebc6ce8f99ee --- /dev/null +++ b/GeoModelExamples/SurfAnnulusDemo/src/SurfAnnulusDemo.cxx @@ -0,0 +1,275 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ + +// ------------------------------------------------------------------- +// +// Annulus Surface Demo Plugin +// Rui Xue, July 2024 +// +// +// This plugin is used to test and develop Annulus Surface +// +// +// -------------------------------------------------------------------- + +#include "GeoModelKernel/GeoVGeometryPlugin.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoPrintGraphAction.h" +#include "GeoModelKernel/GeoVolumeCursor.h" + +#include "GeoModelKernel/GeoLogVol.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/Units.h" +#include "GeoModelHelpers/defineWorld.h" + +#include "GeoModelKernel/GeoSurfaceCursor.h" +#include "GeoModelKernel/GeoCountSurfaceAction.h" +#include "GeoModelKernel/GeoCountVolAction.h" +#include "GeoModelKernel/GeoAccessSurfaceAction.h" +#include "GeoModelKernel/GeoAccessVolumeAction.h" + +#include <Eigen/Dense> +#include <Eigen/Geometry> +#include <iostream> +#include <cmath> +using namespace GeoModelKernelUnits; + +// Class Declaration + +class SurfAnnulusDemo : public GeoVGeometryPlugin { + + public: + + // Constructor: + SurfAnnulusDemo(); + + // Destructor: + ~SurfAnnulusDemo(); + + // Creation of geometry: + virtual void create(GeoVPhysVol *world, bool publish=false); + + private: + + // Illegal operations: + const SurfAnnulusDemo & operator=(const SurfAnnulusDemo &right)=delete; + SurfAnnulusDemo(const SurfAnnulusDemo &right) = delete; + +}; + + +// Class definition: + +// Constructor +SurfAnnulusDemo::SurfAnnulusDemo() +{ +} + +// Destructor +SurfAnnulusDemo::~SurfAnnulusDemo() +{ +} + +// The create algorithm creates a tree of physical volumes rooted under the +// "world" physical volume. The optional flag publish is not used in this +// example (normally one may "publish" a list of FullPhysVol's and Alignable +// transforms, but this example has none such). +// +void SurfAnnulusDemo::create(GeoVPhysVol *world, bool /*publish*/) { + // Define elements used in this example: + GeoElement *oxygen = new GeoElement("Oxygen", "O", 19, 39*gram/mole); + GeoElement *nitrogen = new GeoElement("Nitrogen", "N", 7, 14*gram/mole); + GeoElement *argon = new GeoElement("Argon", "Ar", 18, 40*gram/mole); + GeoElement *aluminium = new GeoElement("Aluminium", "Al", 13, 26*gram/mole); + + // Define materials: + + // Define Air: + double densityOfAir = 1.2E-3*gram/cm3; // g/cm^3 + GeoMaterial *Air = new GeoMaterial("Air",densityOfAir); + Air->add(oxygen,2*0.21); // diatomic oxygen 21% by volume. + Air->add(nitrogen,2*0.78); // diatomic nitrogen 78% by volume. + Air->add(argon,0.01); // monoatomic argon 78% by volume. + Air->lock(); + + // Define Aluminium + double densityOfAluminium=2.7*gram/cm3; // g/cm^3 + GeoMaterial *Aluminium = new GeoMaterial("Aluminium", densityOfAluminium); + Aluminium->add(aluminium,1.0); + Aluminium->lock(); + + GeoBox *boxShape = new GeoBox(10,15,20); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoPhysVol *boxPhys = new GeoPhysVol(boxLog); + + + { + GeoBox *point_box = new GeoBox(0.2, 0.2, 0.2); + GeoLogVol *point_log = new GeoLogVol("PointLog", point_box, Air); + GeoBox *point_box2 = new GeoBox(0.05, 0.05, 0.05); + GeoLogVol *point_log2 = new GeoLogVol("PointLog", point_box2, Air); + + GeoFullPhysVol *point_phys = new GeoFullPhysVol(point_log); + + // The point initial position, definitely on the initial surface + // after a series of transformations, the point should still be on the surface + // this part is to test the GeoVSurface::isOnSurface method + // it should return true + const double point_x = 5.66; + const double point_y = -5.66; + const double point_z = 0.0; + Eigen::Vector4d point_vec(point_x, point_y, point_z, 1.0); + Eigen::Vector4d origin_p(0.0, 0.0, 0.0, 1.0); + Eigen::Vector4d trans_point_vec; + Eigen::Vector4d trans_origin_p0; + Eigen::Vector4d trans_origin_p; + + GeoTransform * transform_point = new GeoTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)*GeoTrf::TranslateX3D(5.66)*GeoTrf::TranslateY3D(-5.66)); + + GeoBox *boxShape = new GeoBox(3,3,3); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoFullPhysVol *boxPhys3 = new GeoFullPhysVol(boxLog); + + GeoAnnulusSurface* annulus = new GeoAnnulusSurface(-4.0, -5.0, 7.0, 10.0, 0.3*M_PI); // Ox, Oy, Rin, Rout, Phi + GeoVSurface* surf3 = new GeoVSurface(annulus); + GeoAlignableTransform *move_together3=new GeoAlignableTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)); + //GeoTransform * point_trans = new GeoTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)); + + boxPhys->add(move_together3); + boxPhys->add(surf3); + // boxPhys->add(transform_point); // move the point (initially at (0,0,0)) to the starting position (5.66, -5.66, 0) + // boxPhys->add(point_phys); + move_together3->setDelta(GeoTrf::RotateY3D(0)); + + GeoFullPhysVol *point_phys2; + GeoTransform * translate_point2; + + for(int i = 0; i < 11; i++){ + for(int j = 0; j < 11; j++){ + //for(int k = 0; k < 3; k++){ + double test_x = -10.0 + i*2; + double test_y = -10.0 + j*2; + double test_z = 0.0;//-1.0 + k*1.0; + Eigen::Vector4d test_point(test_x, test_y, test_z, 1.0); + test_point = surf3->getX() * test_point; + test_x = test_point[0]; test_y = test_point[1]; test_z = test_point[2]; + + //GeoFullPhysVol *point_phys2 = new GeoFullPhysVol(point_log); + //GeoTransform * translate_point2 = new GeoTransform(GeoTrf::TranslateX3D(test_x)*GeoTrf::TranslateY3D(test_y)*GeoTrf::TranslateZ3D(test_z)); + //boxPhys->add(translate_point2); + //boxPhys->add(point_phys2); + + if (surf3->isOnSurface(test_x, test_y, test_z)) + { + point_phys2 = new GeoFullPhysVol(point_log); + std::cout << " the point is on the surface " << std::endl; + } + else{ + point_phys2 = new GeoFullPhysVol(point_log2); + std::cout << " NOT ON THE SURFACE " << std::endl; + } + translate_point2 = new GeoTransform(GeoTrf::TranslateX3D(test_x)*GeoTrf::TranslateY3D(test_y)*GeoTrf::TranslateZ3D(test_z)); + boxPhys->add(translate_point2); + boxPhys->add(point_phys2); + //} + } + } + + } + + // GeoTrapezoidSurface* trapezoid2 = new GeoTrapezoidSurface(9, 12, 8); + // GeoVSurface* surf5 = new GeoVSurface(trapezoid2); + // GeoAlignableTransform *move_together5=new GeoAlignableTransform(GeoTrf::TranslateZ3D(20)*GeoTrf::TranslateX3D(40)); + + // boxPhys->add(move_together5); + // boxPhys->add(surf5); + // move_together5->setDelta(GeoTrf::RotateX3D(1)); + + world->add(boxPhys); + GeoPrintGraphAction printGraphAction(std::cout); + world->exec(&printGraphAction);; + + { + int i = 0; + + // std::cout << " " << std::endl; + // std::cout << " " << std::endl; + // std::cout << " cursor at i= " << i << std::endl; + GeoVolumeCursor cursor(boxPhys); + //GeoSurfaceCursor cursor(boxPhys); + + while (!cursor.atEnd()) { + i += 1; + // std::cout << "!!! " << std::endl; + // std::cout << cursor.getTransform().rotation() << std::endl; + // std::cout << "!!! " << std::endl; + // std::cout << cursor.getTransform().translation() << std::endl; + // std::cout << " " << std::endl; + cursor.next(); + } + } + + GeoCountSurfaceAction countSurface; + boxPhys->exec(&countSurface); + // std::cout << "Number of Virtual Surface: " << countSurface.getCount() << std::endl; + unsigned int totalVSurface = countSurface.getCount(); + + for (unsigned int i = 0; i< totalVSurface; i++){ + GeoAccessSurfaceAction surfaceAccess (i, nullptr); + boxPhys->exec(&surfaceAccess); + // std::cout << "surface transform rotation: " << surfaceAccess.getTransform().rotation() << std::endl; + // std::cout << "surface transform trans: " << surfaceAccess.getTransform().translation() << std::endl; + } + + // // cannot use GeoNodePositioning::getAbsoluteTransform(). Is there an error in the method? + // std::cout << "surface5 transform rot: " << surf5->getX().rotation() << std::endl; + // std::cout << " " << std::endl; + // //surf5->PrintRotation(); + + // GeoTrf::Vector3D vec(0.0, 0.0, 1.0); + // std::cout << " ROTATE VECTOR " << surf5->getX().rotation()*vec << std::endl; + + // std::cout << " " << std::endl; + // std::cout << " " << std::endl; + // //surf5->PrintTranslation(); + // std::cout << "surface5 transform trans: " << surf5->getX().translation() << std::endl; + + // Eigen::Matrix4d M_4d = Eigen::Matrix4d::Identity(); + // M_4d.block<3,3>(0,0) = surf5->getX().rotation(); + // M_4d.block<3,1>(0,3) = surf5->getX().translation(); + // std::cout << " 4x4 matrix " << M_4d << std::endl; + + // Eigen::Vector4d vec_4d; + // vec_4d << vec, 1.0; + // //Eigen::Vector4d trans_vec_4d = M_4d * vec_4d; + // Eigen::Vector4d trans_vec_4d = surf5->getX() * vec_4d; + // Eigen::Vector3d trans_vec = trans_vec_4d.head<3>(); + + // Eigen::Vector4d origin_vec_4d = surf5->getX().inverse() * trans_vec_4d; + // Eigen::Vector3d origin_vec = origin_vec_4d.head<3>(); + // std::cout << " TRANS VECTOR " << trans_vec << std::endl; + // std::cout << " ORIGIN VECTOR " << origin_vec << std::endl; + + //--------------------------------------// +} + +// The name of this routine must correspond to the name of the class, +// and also to the name of the source code file (this file) + +extern "C" SurfAnnulusDemo *createSurfAnnulusDemo() { + return new SurfAnnulusDemo; +} + diff --git a/GeoModelExamples/SurfDiamond/CMakeLists.txt b/GeoModelExamples/SurfDiamond/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e69c99ef4d54cc28468dc53c0819f29e9bea1ff --- /dev/null +++ b/GeoModelExamples/SurfDiamond/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.16...3.26) + +# Compile with C++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS ON) + + +# Find the needed dependencies, when building individually + message (${CMAKE_SOURCE_DIR}) + message (${PROJECT_SOURCE_DIR}) + +if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually + find_package( GeoModelCore REQUIRED ) +endif() + + +# Find the header and source files. +file( GLOB SOURCES src/*.cxx ) + +add_library( SurfDiamond SHARED ${SOURCES} ) +target_link_libraries( SurfDiamond PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers) + +source_group( "src" FILES ${SOURCES} ) + +set_target_properties( SurfDiamond PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) + +# Install the library. +install( TARGETS SurfDiamond + EXPORT ${PROJECT_NAME}-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Runtime + NAMELINK_SKIP ) diff --git a/GeoModelExamples/SurfDiamond/src/SurfDiamond.cxx b/GeoModelExamples/SurfDiamond/src/SurfDiamond.cxx new file mode 100644 index 0000000000000000000000000000000000000000..640a6f950fe41c926032cd9ea690d985d09436c4 --- /dev/null +++ b/GeoModelExamples/SurfDiamond/src/SurfDiamond.cxx @@ -0,0 +1,204 @@ +/* + Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +*/ + +// ------------------------------------------------------------------- +// +// Diamond Surface Demo Plugin +// Rui Xue, Oct 2024 +// +// +// This plugin is used to test and develop Diamond Surface +// +// +// -------------------------------------------------------------------- + +#include "GeoModelKernel/GeoVGeometryPlugin.h" +#include "GeoModelKernel/GeoDefinitions.h" +#include "GeoModelKernel/GeoMaterial.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoPrintGraphAction.h" +#include "GeoModelKernel/GeoVolumeCursor.h" + +#include "GeoModelKernel/GeoLogVol.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/Units.h" +#include "GeoModelHelpers/defineWorld.h" + +#include "GeoModelKernel/GeoSurfaceCursor.h" +#include "GeoModelKernel/GeoCountSurfaceAction.h" +#include "GeoModelKernel/GeoCountVolAction.h" +#include "GeoModelKernel/GeoAccessSurfaceAction.h" +#include "GeoModelKernel/GeoAccessVolumeAction.h" + +#include <Eigen/Dense> +#include <Eigen/Geometry> +#include <iostream> +#include <cmath> +using namespace GeoModelKernelUnits; + +// Class Declaration + +class SurfDiamond : public GeoVGeometryPlugin { + + public: + + // Constructor: + SurfDiamond(); + + // Destructor: + ~SurfDiamond(); + + // Creation of geometry: + virtual void create(GeoVPhysVol *world, bool publish=false); + + private: + + // Illegal operations: + const SurfDiamond & operator=(const SurfDiamond &right)=delete; + SurfDiamond(const SurfDiamond &right) = delete; + +}; + + +// Class definition: + +// Constructor +SurfDiamond::SurfDiamond() +{ +} + +// Destructor +SurfDiamond::~SurfDiamond() +{ +} + +// The create algorithm creates a tree of physical volumes rooted under the +// "world" physical volume. The optional flag publish is not used in this +// example (normally one may "publish" a list of FullPhysVol's and Alignable +// transforms, but this example has none such). +// +void SurfDiamond::create(GeoVPhysVol *world, bool /*publish*/) { + // Define elements used in this example: + GeoElement *oxygen = new GeoElement("Oxygen", "O", 19, 39*gram/mole); + GeoElement *nitrogen = new GeoElement("Nitrogen", "N", 7, 14*gram/mole); + GeoElement *argon = new GeoElement("Argon", "Ar", 18, 40*gram/mole); + GeoElement *aluminium = new GeoElement("Aluminium", "Al", 13, 26*gram/mole); + + // Define materials: + + // Define Air: + double densityOfAir = 1.2E-3*gram/cm3; // g/cm^3 + GeoMaterial *Air = new GeoMaterial("Air",densityOfAir); + Air->add(oxygen,2*0.21); // diatomic oxygen 21% by volume. + Air->add(nitrogen,2*0.78); // diatomic nitrogen 78% by volume. + Air->add(argon,0.01); // monoatomic argon 78% by volume. + Air->lock(); + + // Define Aluminium + double densityOfAluminium=2.7*gram/cm3; // g/cm^3 + GeoMaterial *Aluminium = new GeoMaterial("Aluminium", densityOfAluminium); + Aluminium->add(aluminium,1.0); + Aluminium->lock(); + + GeoBox *boxShape = new GeoBox(10,15,20); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoPhysVol *boxPhys = new GeoPhysVol(boxLog); + + + { + GeoBox *point_box = new GeoBox(0.2, 0.2, 0.2); + GeoLogVol *point_log = new GeoLogVol("PointLog", point_box, Air); + GeoBox *point_box2 = new GeoBox(0.05, 0.05, 0.05); + GeoLogVol *point_log2 = new GeoLogVol("PointLog", point_box2, Air); + + GeoFullPhysVol *point_phys = new GeoFullPhysVol(point_log); + + // The point initial position, definitely on the initial surface + // after a series of transformations, the point should still be on the surface + // this part is to test the GeoVSurface::isOnSurface method + // it should return true + const double point_x = 5.66; + const double point_y = -5.66; + const double point_z = 0.0; + Eigen::Vector4d point_vec(point_x, point_y, point_z, 1.0); + Eigen::Vector4d origin_p(0.0, 0.0, 0.0, 1.0); + Eigen::Vector4d trans_point_vec; + Eigen::Vector4d trans_origin_p0; + Eigen::Vector4d trans_origin_p; + + GeoTransform * transform_point = new GeoTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)*GeoTrf::TranslateX3D(5.66)*GeoTrf::TranslateY3D(-5.66)); + + GeoBox *boxShape = new GeoBox(3,3,3); + GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); + GeoFullPhysVol *boxPhys3 = new GeoFullPhysVol(boxLog); + + // GeoAnnulusSurface* annulus = new GeoAnnulusSurface(-4.0, -5.0, 7.0, 10.0, 2*M_PI); // Ox, Oy, Rin, Rout, Phi + // GeoVSurface* surf3 = new GeoVSurface(annulus); + GeoDiamondSurface* diamond = new GeoDiamondSurface(4, 9.5, 7, 5.5, 6); + GeoVSurface* surf3 = new GeoVSurface(diamond); + // GeoRectSurface* rect = new GeoRectSurface(5, 9); + // GeoVSurface* surf3 = new GeoVSurface(rect); + // GeoTrapezoidSurface* trapezoid = new GeoTrapezoidSurface(9, 7, 5); + // GeoVSurface* surf3 = new GeoVSurface(trapezoid); + + GeoAlignableTransform *move_together3=new GeoAlignableTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)); + //GeoTransform * point_trans = new GeoTransform(GeoTrf::RotateY3D(0.4*M_PI)*GeoTrf::TranslateX3D(20)); + boxPhys->add(move_together3); + boxPhys->add(surf3); + // boxPhys->add(transform_point); // move the point (initially at (0,0,0)) to the starting position (5.66, -5.66, 0) + // boxPhys->add(point_phys); + move_together3->setDelta(GeoTrf::RotateY3D(0)); + + GeoFullPhysVol *point_phys2; + GeoTransform * translate_point2; + + for(int i = 0; i < 11; i++){ + for(int j = 0; j < 11; j++){ + //for(int k = 0; k < 3; k++){ + double test_x = -10.0 + i*2; + double test_y = -10.0 + j*2; + double test_z = 0.0;//-1.0 + k*1.0; + Eigen::Vector4d test_point(test_x, test_y, test_z, 1.0); + test_point = surf3->getX() * test_point; + test_x = test_point[0]; test_y = test_point[1]; test_z = test_point[2]; + + if (surf3->isOnSurface(test_x, test_y, test_z)) + { + point_phys2 = new GeoFullPhysVol(point_log); + // std::cout << " the point is on the surface " << std::endl; + } + else{ + point_phys2 = new GeoFullPhysVol(point_log2); + // std::cout << " NOT ON THE SURFACE " << std::endl; + } + translate_point2 = new GeoTransform(GeoTrf::TranslateX3D(test_x)*GeoTrf::TranslateY3D(test_y)*GeoTrf::TranslateZ3D(test_z)); + boxPhys->add(translate_point2); + boxPhys->add(point_phys2); + //} + } + } + + } + + world->add(boxPhys); +} + +// The name of this routine must correspond to the name of the class, +// and also to the name of the source code file (this file) + +extern "C" SurfDiamond *createSurfDiamond() { + return new SurfDiamond; +} + diff --git a/GeoModelExamples/SurfaceTestPlugin/CMakeLists.txt b/GeoModelExamples/SurfaceTestPlugin/CMakeLists.txt index 4a8db4175e3098082ccc20daf836c596771f821b..8c2f86068aa92de119fabde0933761064934a95b 100644 --- a/GeoModelExamples/SurfaceTestPlugin/CMakeLists.txt +++ b/GeoModelExamples/SurfaceTestPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: HelloGeo @@ -14,11 +14,11 @@ set(CMAKE_CXX_EXTENSIONS ON) # Find the needed dependencies, when building individually - message (${CMAKE_SOURCE_DIR}) + message (${CMAKE_SOURCE_DIR}) message (${PROJECT_SOURCE_DIR}) - + if ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR ) # when buildingindividually - find_package( GeoModelCore REQUIRED ) + find_package( GeoModelCore REQUIRED ) endif() @@ -28,10 +28,6 @@ file( GLOB SOURCES src/*.cxx ) add_library( SurfaceTestPlugin SHARED ${SOURCES} ) target_link_libraries( SurfaceTestPlugin PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers) -target_include_directories( SurfaceTestPlugin PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) - source_group( "src" FILES ${SOURCES} ) set_target_properties( SurfaceTestPlugin PROPERTIES @@ -44,4 +40,3 @@ install( TARGETS SurfaceTestPlugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime NAMELINK_SKIP ) - diff --git a/GeoModelExamples/SurfaceTestPlugin/src/SurfaceTestPlugin.cxx b/GeoModelExamples/SurfaceTestPlugin/src/SurfaceTestPlugin.cxx index 5d4bac3a2e5df4db2a2502bc1161b037c2fe5e55..34b5895237d2f9abc5b95f9015ad2f9ea8cd7382 100644 --- a/GeoModelExamples/SurfaceTestPlugin/src/SurfaceTestPlugin.cxx +++ b/GeoModelExamples/SurfaceTestPlugin/src/SurfaceTestPlugin.cxx @@ -21,15 +21,25 @@ #include "GeoModelKernel/GeoMaterial.h" #include "GeoModelKernel/GeoBox.h" #include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoPrintGraphAction.h" +#include "GeoModelKernel/GeoVolumeCursor.h" #include "GeoModelKernel/GeoLogVol.h" #include "GeoModelKernel/GeoPhysVol.h" #include "GeoModelKernel/GeoTransform.h" +#include "GeoModelKernel/GeoAlignableTransform.h" #include "GeoModelKernel/GeoShapeSubtraction.h" #include "GeoModelKernel/GeoShapeShift.h" #include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoVSurface.h" #include "GeoModelKernel/Units.h" #include "GeoModelHelpers/defineWorld.h" + +#include "GeoModelKernel/GeoSurfaceCursor.h" +#include "GeoModelKernel/GeoCountSurfaceAction.h" +#include "GeoModelKernel/GeoCountVolAction.h" +#include "GeoModelKernel/GeoAccessSurfaceAction.h" +#include "GeoModelKernel/GeoAccessVolumeAction.h" using namespace GeoModelKernelUnits; // Class Declaration @@ -101,20 +111,122 @@ void SurfaceTestPlugin::create(GeoVPhysVol *world, bool /*publish*/) { GeoPhysVol *boxPhys = new GeoPhysVol(boxLog); - GeoRectSurface *rectSurface = new GeoRectSurface(5, 7.5); - boxPhys->add(rectSurface); - { +/* +// define a virtual surface + GeoRectSurface *rectSurface = new GeoRectSurface(5, 5); + GeoAlignableTransform *surf_rot=new GeoAlignableTransform(GeoTrf::TranslateY3D(18)); + boxPhys->add(surf_rot); + boxPhys->add(rectSurface); + surf_rot->setDelta(GeoTrf::RotateX3D(1.2)); + */ +// GeoBox *boxShape = new GeoBox(5,5,5); GeoLogVol *boxLog = new GeoLogVol("BoxLog",boxShape,Air); GeoPhysVol *boxPhys2 = new GeoPhysVol(boxLog); + + GeoAlignableTransform *xf_initial=new GeoAlignableTransform(GeoTrf::TranslateZ3D(3)); + boxPhys->add(xf_initial); boxPhys->add(boxPhys2); + xf_initial->setDelta(GeoTrf::RotateX3D(1.2)); + +// define a virtual surface + GeoRectSurface* rectSurface = new GeoRectSurface(5, 5); +/* GeoVSurface* surf = new GeoVSurface(rectSurface); + GeoAlignableTransform *surf_rot=new GeoAlignableTransform(GeoTrf::TranslateY3D(10)); + boxPhys->add(surf_rot); + boxPhys->add(surf); + surf_rot->setDelta(GeoTrf::RotateY3D(1.2));*/ + + +// define a virtual surface2 + GeoRectSurface *rectSurface2 = new GeoRectSurface(5, 7.5); +/* GeoVSurface* surf2 = new GeoVSurface(rectSurface2); + GeoAlignableTransform *surf_rot2=new GeoAlignableTransform(GeoTrf::TranslateX3D(-20)); + boxPhys->add(surf_rot2); + boxPhys->add(surf2); + surf_rot2->setDelta(GeoTrf::RotateY3D(0.8));*/ +// + + GeoAlignableTransform *xf=new GeoAlignableTransform(GeoTrf::TranslateZ3D(18)); + GeoPhysVol *boxPhys3 = new GeoPhysVol(boxLog); + GeoPhysVol *boxPhys4 = new GeoPhysVol(boxLog); + + boxPhys3->add(xf); + boxPhys3->add(boxPhys4); + + GeoRectSurface *rectSurface2_2 = new GeoRectSurface(7.5, 7.5); +/* GeoVSurface* surf2_2 = new GeoVSurface(rectSurface2_2); + GeoAlignableTransform *surf_rot2_2 = new GeoAlignableTransform(GeoTrf::TranslateX3D(-10)); + boxPhys3->add(surf_rot2_2); + boxPhys3->add(surf2_2); + surf_rot2_2->setDelta(GeoTrf::RotateY3D(1.0));*/ + + boxPhys->add(xf); + boxPhys->add(boxPhys3); + xf->setDelta(GeoTrf::RotateX3D(0.1)*GeoTrf::RotateY3D(0.15)); + +// define a virtual surface3 + GeoRectSurface *rectSurface3 = new GeoRectSurface(10, 12); +/* GeoVSurface* surf3 = new GeoVSurface(rectSurface3); + GeoAlignableTransform *surf_rot3=new GeoAlignableTransform(GeoTrf::TranslateX3D(10)*GeoTrf::TranslateY3D(15)*GeoTrf::TranslateZ3D(20)); + boxPhys->add(surf_rot3); + boxPhys->add(surf3); + surf_rot3->setDelta(GeoTrf::RotateZ3D(0.9));*/ +// + } - + GeoLogVol *boxLog5 = new GeoLogVol("BoxLog5",boxShape,Air); + GeoPhysVol *boxPhys5 = new GeoPhysVol(boxLog5); world->add(boxPhys); + //world->add(boxPhys5); + GeoPrintGraphAction printGraphAction(std::cout); + world->exec(&printGraphAction);; + { + int i = 0; + + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " cursor at i= " << i << std::endl; + GeoVolumeCursor cursor(boxPhys); + //GeoSurfaceCursor cursor(boxPhys); + + while (!cursor.atEnd()) { + i += 1; + std::cout << "!!! " << std::endl; + std::cout << cursor.getTransform().rotation() << std::endl; + std::cout << "!!! " << std::endl; + std::cout << cursor.getTransform().translation() << std::endl; + std::cout << " " << std::endl; + cursor.next(); + } + } +/* + GeoCountVolAction countVol; + boxPhys->exec(&countVol); + std::cout << "Number of Physical Volume: " << countVol.getCount() << std::endl; + + unsigned int index = 2; + GeoAccessVolumeAction volumeAccess (index, nullptr); + boxPhys->exec(&volumeAccess); + std::cout << "volume transform rotation: " << volumeAccess.getTransform().rotation() << std::endl; + std::cout << "volume transform trans: " << volumeAccess.getTransform().translation() << std::endl; +*/ + + GeoCountSurfaceAction countSurface; + boxPhys->exec(&countSurface); + std::cout << "Number of Virtual Surface: " << countSurface.getCount() << std::endl; + unsigned int totalVSurface = countSurface.getCount(); + for (unsigned int i = 0; i< totalVSurface; i++){ + GeoAccessSurfaceAction surfaceAccess (i, nullptr); + boxPhys->exec(&surfaceAccess); + std::cout << "surface transform rotation: " << surfaceAccess.getTransform().rotation() << std::endl; + std::cout << "surface transform trans: " << surfaceAccess.getTransform().translation() << std::endl; + } + //--------------------------------------// } diff --git a/GeoModelG4/GeoMaterial2G4/CMakeLists.txt b/GeoModelG4/GeoMaterial2G4/CMakeLists.txt index 434517536511f6643d7b0710f41d3d909cf982fc..717e9ead384deb39c498f0ebd4ba59eb2e4178c0 100644 --- a/GeoModelG4/GeoMaterial2G4/CMakeLists.txt +++ b/GeoModelG4/GeoMaterial2G4/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: GeoMaterial2G4 @@ -18,7 +18,7 @@ add_library( GeoMaterial2G4 SHARED ${HEADERS} ${SOURCES} ) target_include_directories( GeoMaterial2G4 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) target_link_libraries( GeoMaterial2G4 PUBLIC GeoModelCore::GeoModelKernel ${Geant4_LIBRARIES} ) # Set installation of library headers @@ -30,6 +30,6 @@ set_target_properties( GeoMaterial2G4 PROPERTIES # new test GeoModelG4 install(TARGETS GeoMaterial2G4 - EXPORT GeoMaterial2G4-export + EXPORT GeoMaterial2G4-export LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoMaterial2G4 ) diff --git a/GeoModelG4/GeoModel2G4/CMakeLists.txt b/GeoModelG4/GeoModel2G4/CMakeLists.txt index 143c8f22d13601e4337dce75e1a6285378aa7727..157a3cf8841aba6b9414ec9d9ebfbe4ff048cffa 100644 --- a/GeoModelG4/GeoModel2G4/CMakeLists.txt +++ b/GeoModelG4/GeoModel2G4/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: GeoModel2G4 @@ -38,7 +38,7 @@ target_compile_definitions(GeoModel2G4 PRIVATE G4EXTENSION_SOLID_DIR=${PATHEXTEN target_include_directories(GeoModel2G4 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) target_link_libraries(GeoModel2G4 PUBLIC ${Geant4_LIBRARIES} PRIVATE GeoMaterial2G4 GeoModelCore::GeoModelKernel) @@ -52,6 +52,6 @@ set_target_properties( GeoModel2G4 PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) # Install the library. install( TARGETS GeoModel2G4 - EXPORT GeoModel2G4-export + EXPORT GeoModel2G4-export LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModel2G4 ) diff --git a/GeoModelG4/GeoModel2G4/original_GeoModel2G4/CMakeLists.txt b/GeoModelG4/GeoModel2G4/original_GeoModel2G4/CMakeLists.txt index 55c9883f6043b6465bd87306a6c547808d61c887..fafcfaeddf8110e844bb06e1a071fd44c5eac8c4 100644 --- a/GeoModelG4/GeoModel2G4/original_GeoModel2G4/CMakeLists.txt +++ b/GeoModelG4/GeoModel2G4/original_GeoModel2G4/CMakeLists.txt @@ -53,12 +53,10 @@ target_link_libraries( Geo2G4Lib target_include_directories( Geo2G4Lib SYSTEM PUBLIC ${XERCESC_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} PRIVATE ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} ) target_include_directories( Geo2G4Lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) ### TODO: do we need this from Athena? Maybe not... # atlas_add_component( Geo2G4 ... ) ### TODO: do we need this from Athena? Maybe not... # atlas_add_dictionary( LArWheelSolidCheckerDict ... ) - - diff --git a/GeoModelIO/CMakeLists.txt b/GeoModelIO/CMakeLists.txt index 013aed1eb8dfc378ef7c79e1b2beb1dbc2bb2ca5..e929b1b137e6c677462042a40b4ae7fceb98b1a6 100644 --- a/GeoModelIO/CMakeLists.txt +++ b/GeoModelIO/CMakeLists.txt @@ -47,3 +47,4 @@ install( # Set up the packaging of the project using CPack. list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) include( GeoModelIOPackaging ) + diff --git a/GeoModelIO/GeoModelDBManager/CMakeLists.txt b/GeoModelIO/GeoModelDBManager/CMakeLists.txt index 7eb42f1af7a018644585e7a19c7d59f74234d598..513943cf47bcc58dc6f8647fbe8b233c7244f0c6 100644 --- a/GeoModelIO/GeoModelDBManager/CMakeLists.txt +++ b/GeoModelIO/GeoModelDBManager/CMakeLists.txt @@ -1,10 +1,11 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: GeoModelDBManager # author: Riccardo Maria BIANCHI @ CERN - 2017 # major updates: # - R.M.Bianchi, 2018 # - R.M.Bianvhi, Nov 2020 +# - R.M.Bianvhi, Apr 2024 ################################################################################ # Find the header and source files. @@ -13,10 +14,10 @@ file( GLOB HEADERS GeoModelDBManager/*.h ) # Set up the library. add_library( GeoModelDBManager SHARED ${HEADERS} ${SOURCES} ) -target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 ) +target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 GeoModelHelpers GeoModelKernel ) target_include_directories( GeoModelDBManager PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelDBManager" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelDBManager PROPERTIES @@ -40,5 +41,5 @@ install( FILES ${HEADERS} add_executable(test_create_db_file tests/test_create_db_file.cpp) target_link_libraries( test_create_db_file GeoModelIO::GeoModelDBManager) -add_test(NAME TestCreateDBFile +add_test(NAME testCreateDBFile COMMAND test_create_db_file) diff --git a/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h index e239ec1147457e06c2da5763cb79d232a440c9e2..f0119668e52c053019140ec8bf06bff5ff92d11a 100644 --- a/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h +++ b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /* @@ -10,11 +10,16 @@ * AlignableTransform nodes * - Jun 2022 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>, * Added support for "Verbose" output + * - May 2024 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>, + * Major change: moving to a new DB schema where we use REAL values + * for numeric data instead of TEXT. */ #ifndef GMDBManager_H #define GMDBManager_H +#include "GeoModelDBManager/definitions.h" + // include C++ #include <iostream> #include <string> @@ -22,6 +27,8 @@ #include <unordered_map> #include <variant> #include <vector> +#include <deque> +#include <set> /** * \class GMDBManager @@ -90,6 +97,13 @@ class GMDBManager { * @brief Print names of all GeoShape objects in db */ void printAllShapes() const; + + /** + * @brief Print the data related to the GeoShape nodes in the DB + * with a variable number of parameters + * (for example, a variable number of planes along the Z axis) + */ + void printAllShapesData() const; /** * @brief Print names of all GeoSerialDenominator objects in db @@ -151,7 +165,7 @@ class GMDBManager { * @note The 'suffix' parameter is optional. If not provided, the default * table will be printed. */ - void printAllPublishedFullPhysVols(const std::string suffix = "") const; + void printAllPublishedFullPhysVols(const std::string& suffix = "") const; /** * @brief Print the db table storing all the 'published' @@ -167,7 +181,7 @@ class GMDBManager { * table will be printed. */ void printAllPublishedAlignableTransforms( - const std::string suffix = "") const; + const std::string& suffix = "") const; /** * @brief Print the db table storing all the children positions per parent @@ -201,13 +215,19 @@ class GMDBManager { /// and populate the cache that stores them void getAllDBTableColumns(); - int execQuery(std::string queryStr); + int execQuery(const std::string& queryStr); + + bool addListOfRecords(const std::string& geoType, + const std::vector<std::vector<std::string>>& records); + bool addListOfRecords(const std::string& geoType, + const DBRowsList& records); - bool addListOfRecords(const std::string geoType, - const std::vector<std::vector<std::string>> records); + bool addRecordsToTable( + const std::string& tableName, + const DBRowEntry& + records); - bool addListOfChildrenPositions( - const std::vector<std::vector<std::string>> &records); + bool addListOfChildrenPositions(const DBRowsList &records); /** * @brief Save the list of 'published' GeoAlignableTransform nodes to the @@ -221,7 +241,7 @@ class GMDBManager { */ bool addListOfPublishedAlignableTransforms( const std::vector<std::vector<std::string>> &records, - std::string suffix = ""); + const std::string& suffix = ""); /** * @brief Save the list of 'published' GeoVFullPhysVol nodes to the DB. @@ -234,17 +254,20 @@ class GMDBManager { */ bool addListOfPublishedFullPhysVols( const std::vector<std::vector<std::string>> &records, - std::string suffix = ""); + const std::string& suffix = ""); - bool addRootVolume(const std::vector<std::string> &values); + // bool addRootVolume(const std::vector<std::string> &values); + bool addRootVolume(const std::string_view nodeType, const unsigned nodeId); + bool addRootVolume(const std::pair<std::string, unsigned>& rootValues); // GET methods std::string getDBFilePath(); - std::vector<std::string> getRootPhysVol(); + // std::vector<std::string> getRootPhysVol(); + std::pair<unsigned, unsigned> getRootPhysVol(); - std::vector<std::string> getItemFromTableName(std::string tableName, + std::vector<std::string> getItemFromTableName(const std::string& tableName, unsigned int id); std::vector<std::string> getItemAndType(unsigned int tableId, @@ -253,7 +276,8 @@ class GMDBManager { std::string getNodeTypeFromTableId(unsigned int id); /// methods to dump the DB - std::vector<std::vector<std::string>> getChildrenTable(); + // std::vector<std::vector<std::string>> getChildrenTable(); + DBRowsList getChildrenTable(); // Table names for Aux tables are of the form prefix_suffix // where prefix depends on the type of data in the table @@ -261,23 +285,39 @@ class GMDBManager { // These two require only the suffix, the prefix is already specified based // on the table type being accessed - std::vector<std::vector<std::string>> getPublishedFPVTable( - std::string suffix = ""); - std::vector<std::vector<std::string>> getPublishedAXFTable( - std::string suffix = ""); - - std::vector<std::vector<std::string>> getTableFromNodeType( - std::string nodeType); + // std::vector<std::vector<std::string>> getPublishedFPVTable( + // std::string suffix = ""); + // std::vector<std::vector<std::string>> getPublishedAXFTable( + // std::string suffix = ""); + DBRowsList getPublishedFPVTable(const std::string_view suffix = ""); + DBRowsList getPublishedAXFTable(const std::string_view suffix = ""); + + std::vector<std::vector<std::string>> getTableFromNodeType_String( + const std::string& nodeType); + DBRowsList getTableFromNodeType_VecVecData( + const std::string& nodeType); + + DBRowEntry getTableFromTableName_VecData( + const std::string& tableName); + DBRowsList getTableFromTableName_VecVecData( + const std::string& tableName); + // specializations + std::vector<double> getTableFromTableName_VectorDouble(const std::string& tableName); + std::deque<double> getTableFromTableName_DequeDouble(std::string tableName); std::unordered_map<unsigned int, std::string> getAll_TableIDsNodeTypes(); std::unordered_map<std::string, unsigned int> getAll_NodeTypesTableIDs(); - std::vector<std::vector<std::string>> getTableRecords( - std::string tableName) const; // TODO: should be private? + std::vector<std::vector<std::string>> getTableRecords_String(const std::string_view tableName) const; + DBRowEntry getTableRecords_VecData(const std::string_view tableName) const; + DBRowsList getTableRecords_VecVecData(const std::string_view tableName) const; - // Test if a given table exists - // This requires the *full* table name (i.e. prefix_suffix) - bool checkTable(std::string tableName) const; + //! Test if a given table exists + //! This requires the *full* table name (i.e. prefix_suffix) + bool checkTableFromDB(const std::string& tableName) const; + + //! Test if a table has been loaded from a DB, that is it exists in the cache + bool checkTableFromCache(const std::string_view tableName) const; /** * @brief Create a custom DB table to store auxiliary data. @@ -290,94 +330,111 @@ class GMDBManager { * storing the table's rows' data */ bool createCustomTable( - const std::string tableName, - const std::vector<std::string> tableColNames, - const std::vector<std::string> tableColTypes, + const std::string& tableName, + const std::vector<std::string>& tableColNames, + const std::vector<std::string>& tableColTypes, const std::vector< - std::vector<std::variant<int, long, float, double, std::string>>> + DBRowEntry> &records); - unsigned int getTableIdFromNodeType(const std::string &nodeType); + unsigned int getTableIdFromNodeType(const std::string_view nodeType); // bool createCustomTable(const std::string tableName, const // std::vector<std::string> tableColNames, const std::vector<std::string> // tableColTypes, const std::vector<std::vector<std::string>> &records ); // // not used anymore!! - private: - /** - * @brief Create all the default DB tables. - */ - bool createTables(); - - /** - * @brief Create a custom DB table to store a list of published nodes. - * @param tableName The table's name. - * @param keyType The type of the 'key' that identifies the linked node. - */ - bool createTableCustomPublishedNodes(const std::string tableName, - const std::string nodeType, - const std::type_info *keyType); - bool addListOfRecordsToTable( - const std::string tableName, - const std::vector<std::vector<std::string>> records); + const std::string& tableName, + const std::vector<std::vector<std::string>>& records); bool addListOfRecordsToTable( - const std::string tableName, + const std::string& tableName, const std::vector< - std::vector<std::variant<int, long, float, double, std::string>>> + DBRowEntry>& records); // bool addListOfRecordsToTableOld(const QString tableName, const // std::vector<QStringList> records); // for the old SQlite only - void addDBversion(std::string version); - - // void loadTestData(); // for debug only - - std::string getTableNameFromTableId(unsigned int tabId); - void storeNodeType(std::string nodeType, std::string tableName); - - std::string getTableNameFromNodeType(const std::string &nodeType); - - void storeTableColumnNames(std::vector<std::string> input); - - std::vector<std::string> getTableColumnNames(const std::string &tableName); - - int getTableColIndex(const std::string &tableName, - const std::string &colName); - - bool storeRootVolume(const unsigned int &id, const std::string &nodeType); - - std::string m_dbpath; - - bool m_dbIsOK; - - bool m_debug; - - // verbosity level - int m_verbose; - - /// stores the column names for each table - std::unordered_map<std::string, std::vector<std::string>> m_tableNames; - - std::unordered_map<std::string, std::string> m_childType_tableName; - - /// cache for the list of tables in the DB - std::vector<std::string> m_cache_tables; - - std::unordered_map<unsigned int, std::string> - m_cache_tableId_tableName; /// cache for tableID-->tableName - std::unordered_map<unsigned int, std::string> - m_cache_tableId_nodeType; /// cache for tableID-->nodeType - std::unordered_map<std::string, std::string> - m_cache_nodeType_tableName; /// cache for nodeType-->tableName - std::unordered_map<std::string, unsigned int> - m_cache_nodeType_tableID; /// cache for nodeType-->tableID + private: + /* NOTE: 'sqlite3_column_type' return codes: + - 1 INT + - 2 FLOAT + - 3 TEXT + - 4 BLOB + - 5 NULL + */ + enum SQLiteColumnTypes : int + { + INT_TYPE = 1, + FLOAT_TYPE = 2, + TEXT_TYPE = 3, + BLOB_TYPE = 4, + NULL_TYPE = 5 + }; + + /** + * @brief Create all the default DB tables. + */ + bool createTables(); + + /** + * @brief Create a custom DB table to store a list of published nodes. + * @param tableName The table's name. + * @param keyType The type of the 'key' that identifies the linked node. + */ + bool createTableCustomPublishedNodes(const std::string& tableName, + const std::string& nodeType, + const std::type_info *keyType); + + void addDBversion(const std::string& version); + + // void loadTestData(); // for debug only + + std::string getTableNameFromTableId(unsigned int tabId); + + void storeNodeType(const std::string& nodeType, const std::string& tableName); + + std::string getTableNameFromNodeType(const std::string &nodeType); + + std::vector<std::string> getTableColumnNames(const std::string &tableName); + bool hasTableBeenCreatedInDB(const std::string_view tableName); + void storeTableColumnNames(std::vector<std::string> input); + + bool storeRootVolume(const unsigned &id, const std::string_view nodeType); + int getTableColIndex(const std::string &tableName, + const std::string &colName); + + std::string m_dbpath; + + bool m_debug; + + // verbosity level + int m_verbose; + + /// stores the column names for each table + std::unordered_map<std::string, std::vector<std::string>> m_tableNames; + + std::unordered_map<std::string, std::string> m_childType_tableName; + + /// cache for the list of tables in the DB + // std::vector<std::string> m_cache_tables; + std::set<std::string> m_cache_tables; + + std::unordered_map<unsigned int, std::string> + m_cache_tableId_tableName; /// cache for tableID-->tableName + std::unordered_map<unsigned int, std::string> + m_cache_tableId_nodeType; /// cache for tableID-->nodeType + std::unordered_map<std::string, std::string> + m_cache_nodeType_tableName; /// cache for nodeType-->tableName + std::unordered_map<std::string, unsigned int> + m_cache_nodeType_tableID; /// cache for nodeType-->tableID protected: class Imp; Imp *m_d; + + }; #endif // GMDBManager_H diff --git a/GeoModelIO/GeoModelDBManager/GeoModelDBManager/definitions.h b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/definitions.h new file mode 100644 index 0000000000000000000000000000000000000000..b4cf0afda6cd0e8caef769616b4edf48fa521ca6 --- /dev/null +++ b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/definitions.h @@ -0,0 +1,24 @@ +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +/* + * This header file provides global definitions used + * in the I/O of GeoModel into and from an SQLite file. + * + * Author: Riccardo Maria BIANCHI @ CERN + * Created on: May, 2024 + * + */ + + +#ifndef GEOMODELDBMANAGER_DEFINITIONS_H +#define GEOMODELDBMANAGER_DEFINITIONS_H + +#include <vector> +#include <variant> +#include <string> +// define the data types used to retrieve and store data from the DB +using DBRecordEntry = std::variant<int,long,float,double,std::string>; +using DBRowEntry = std::vector<DBRecordEntry>; +using DBRowsList = std::vector<DBRowEntry>; + +#endif diff --git a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp index 66e0218c31554d8e46673dabf9e5e073d64c1531..742eb9f3a164e9d29d9db2b79d6972633d5a30f7 100644 --- a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp +++ b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /* @@ -14,10 +14,21 @@ * - Jul 2023 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>, * Populate the caches in the constructor, so all print methods are * available as soon as the input file is opened by the GMDBManager + * - Apr 2024 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>, + * New DB format to extend the storage of numbers as REAL instead of TEXT, + * New methods to handle vector<variants> as input of records, + * Set precision to all conversions Double --> String + * - Jul 2024 - Rui Xue, <r.xue@cern.ch><rux23@pitt.edu>, + * Added support for virtual surfaces, including: + * GeoRectSurface, GeoTrapezoidSurface, GeoAnnulusSurface, GeoDiamondSurface */ #include <GeoModelDBManager/GMDBManager.h> +#include "GeoModelKernel/throwExcept.h" +#include "GeoModelHelpers/StringUtils.h" + + // include the 'fmt' library, which is hosted locally as header-only #define FMT_HEADER_ONLY 1 // to use 'fmt' header-only #include "fmt/format.h" @@ -26,51 +37,20 @@ #include <sqlite3.h> // C++ includes -#include <stdlib.h> /* exit, EXIT_FAILURE */ +#include <cstdlib> /* exit, EXIT_FAILURE */ #include <mutex> #include <sstream> +#include <utility> static std::string dbversion = - "0.6.0"; // Added new tables to store lists of published FullPhysVols and - // AlignableTransforms - -//// FIXME: move this to utility class/file -// std::vector<std::string> toStdVectorStrings(QStringList qlist) -//{ -// std::vector<std::string> vec; -// foreach(QString qstr, qlist) { -// vec.push_back(qstr.toStdString()); -// } -// return vec; -// } + "1.0.0"; // New format with REAL columns for numeric values -// FIXME: TODO: move to an utility class -std::string getEnvVar(std::string const& key) { - char* val = std::getenv(key.c_str()); - return val == NULL ? std::string("") : std::string(val); -} - -// FIXME: should go to an utility class -std::string joinVectorStrings(std::vector<std::string> vec, - std::string sep = "") { - std::string s; - unsigned int ii = 0; - for (const auto& piece : vec) { - ++ii; - if (ii == vec.size()) { - s += (piece); - } else { - s += (piece + sep); - } - } - return s; -} class GMDBManager::Imp { public: // constructor - Imp(GMDBManager* dbm) + explicit Imp(GMDBManager* dbm) : theManager(dbm), m_dbSqlite(nullptr), m_SQLiteErrMsg(0) {} // The class @@ -82,24 +62,23 @@ class GMDBManager::Imp { /// Variable to store error messages from SQLite char* m_SQLiteErrMsg; - sqlite3_stmt* selectAllFromTable(std::string tableName) const; - sqlite3_stmt* selectAllFromTableSortBy(std::string tableName, - std::string sortColumn = "") const; + sqlite3_stmt* selectAllFromTable(const std::string_view tableName) const; + sqlite3_stmt* selectAllFromTableSortBy(const std::string_view tableName, + const std::string_view sortColumn = "") const; sqlite3_stmt* selectAllFromTableChildrenPositions() const; - bool checkTable_imp(std::string tableName) const; + bool checkTableFromDB_imp(const std::string& tableName) const; }; GMDBManager::GMDBManager(const std::string& path) - : m_dbpath(path), m_dbIsOK(false), m_debug(false), m_d(new Imp(this)) { + : m_dbpath(path), m_debug(false), m_d(new Imp(this)) { // Check if the user asked for running in serial or multi-threading mode - if ("" != getEnvVar("GEOMODEL_ENV_IO_DBMANAGER_DEBUG")) { + if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_DBMANAGER_DEBUG")) { m_debug = true; - std::cout << "You defined the GEOMODEL_IO_DEBUG variable, so you will " + std::cout << "*** NOTE: You defined the GEOMODEL_IO_DEBUG variable, so you will " "see a verbose output." << std::endl; } - m_dbIsOK = false; // FIXME: TODO: we should check the existence of the file, otherwise SQLite // will create a new file from scratch @@ -111,11 +90,9 @@ GMDBManager::GMDBManager(const std::string& path) if (exit == SQLITE_OK) { std::cout << "The Geometry Database '" << path << "' has been opened successfully!" << std::endl; - m_dbIsOK = true; } else { std::cout << "DB Open Error: " << sqlite3_errmsg(m_d->m_dbSqlite) << std::endl; - m_dbIsOK = false; } // set verbosity level @@ -144,7 +121,29 @@ GMDBManager::~GMDBManager() { void GMDBManager::printAllMaterials() const { printAllRecords("Materials"); } void GMDBManager::printAllElements() const { printAllRecords("Elements"); } -void GMDBManager::printAllShapes() const { printAllRecords("Shapes"); } +void GMDBManager::printAllShapes() const { + printAllRecords("Shapes_Box"); + printAllRecords("Shapes_Tube"); + printAllRecords("Shapes_Cons"); + printAllRecords("Shapes_Para"); + printAllRecords("Shapes_Trap"); + printAllRecords("Shapes_Trd"); + printAllRecords("Shapes_Tubs"); + printAllRecords("Shapes_TwistedTrap"); + printAllRecords("Shapes_Pcon"); + printAllRecords("Shapes_Pgon"); + printAllRecords("Shapes_SimplePolygonBrep"); + printAllRecords("Shapes_Intersection"); + printAllRecords("Shapes_Shift"); + printAllRecords("Shapes_Subtraction"); + printAllRecords("Shapes_Union"); +} + +void GMDBManager::printAllShapesData() const { + printAllRecords("Shapes_Pcon_Data"); + printAllRecords("Shapes_Pgon_Data"); + printAllRecords("Shapes_SimplePolygonBrep_Data"); +} void GMDBManager::printAllSerialDenominators() const { printAllRecords("SerialDenominators"); @@ -173,7 +172,7 @@ void GMDBManager::printAllAlignableTransforms() const { } void GMDBManager::printAllNameTags() const { printAllRecords("NameTags"); } void GMDBManager::printAllPublishedFullPhysVols( - const std::string suffix) const { + const std::string& suffix) const { if ("" == suffix) printAllRecords("PublishedFullPhysVols"); else { @@ -183,7 +182,7 @@ void GMDBManager::printAllPublishedFullPhysVols( } } void GMDBManager::printAllPublishedAlignableTransforms( - const std::string suffix) const { + const std::string& suffix) const { if ("" == suffix) printAllRecords("PublishedAlignableTransforms"); else { @@ -217,12 +216,12 @@ void GMDBManager::printAllRecords(const std::string& tableName) const { return; } // --- print table column names - std::cout << "- " << joinVectorStrings(m_tableNames.at(tableName), ", ") + std::cout << "- " << GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") << std::endl; // --- print records std::vector<std::vector<std::string>> records; // std::vector<std::string> nodeParams; - records = getTableRecords(tableName); + records = getTableRecords_String(tableName); if (records.size()) { for (auto& row : records) { std::cout << "* "; @@ -237,12 +236,9 @@ void GMDBManager::printAllRecords(const std::string& tableName) const { // query gives 0 results. } -// FIXME: TODO: we now return all records as text, but should we get -// double/int instead when appropriate? In that case, we should create -// dedicated methods for all tables, I guess. -// TODO: fill a cache and returns that if asked a second time -std::vector<std::vector<std::string>> GMDBManager::getTableRecords( - std::string tableName) const { +std::vector<std::vector<std::string>> GMDBManager::getTableRecords_String( + const std::string_view tableName) const { + // container to be returned std::vector<std::vector<std::string>> records; // get the query statetement ready to be executed @@ -286,7 +282,219 @@ std::vector<std::vector<std::string>> GMDBManager::getTableRecords( if (res == SQLITE_ERROR) { std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); - throw errmsg; + THROW_EXCEPTION(errmsg); + } + break; + } + } + } + // finalize + sqlite3_finalize(stmt); + return records; +} + +// New version with variant +DBRowsList GMDBManager::getTableRecords_VecVecData( + const std::string_view tableName) const +{ + + // container to be returned + DBRowsList records; + // get the query statetement ready to be executed + sqlite3_stmt *stmt = nullptr; + + if ("ChildrenPositions" == tableName) + { + stmt = m_d->selectAllFromTableChildrenPositions(); + } + else + { + stmt = m_d->selectAllFromTable(tableName); + } + // execute the query and loop over all rows and all columuns + if (stmt) + { + int ctotal = sqlite3_column_count( + stmt); // Count the Number of Columns in the Table + int res = 0; + unsigned nRows{0}; + while (1) + { + res = sqlite3_step(stmt); // Execute SQL Statement. + if (res == SQLITE_ROW) + { + DBRowEntry + nodeParams; // stores the data items contained in a + // single row + // Loop times the number of columns in the table + for (int i = 0; i < ctotal; + i++) + { + int datacode = sqlite3_column_type(stmt, i); + // debug msg + // if (0==nRows) std::cout << "table: " << tableName << ", col " << i << "/" << ctotal << " -- typecode: " << datacode << std::endl; + + int valI{0}; + double valD{0.}; + std::string valS; + + // ** INT ** + if (SQLiteColumnTypes::INT_TYPE == datacode) + { + valI = sqlite3_column_int(stmt, i); + // if (0==nRows) std::cout << "valI: " << valI << std::endl;// debug msg + nodeParams.push_back(valI); + } + // ** FLOAT ** + else if (SQLiteColumnTypes::FLOAT_TYPE == datacode) + { + valD = sqlite3_column_double(stmt, i); + // if (0==nRows) std::cout << "valD: " << valD << std::endl;// debug msg + nodeParams.push_back(valD); + } + // ** TEXT ** + else if (SQLiteColumnTypes::TEXT_TYPE == datacode) + { + const char *cc = (char *)sqlite3_column_text(stmt, i); + if (cc == NULL) + { + valS = "NULL"; + } + else + { + valS = cc; + } + nodeParams.push_back(valS); + } + // ** BLOB ** + else if (SQLiteColumnTypes::BLOB_TYPE == datacode) + { + THROW_EXCEPTION("ERROR!!! The 'BLOB' data format is not supported yet!!"); + } + // ** NULL ** + else if (SQLiteColumnTypes::NULL_TYPE == datacode) + { + THROW_EXCEPTION("ERROR!!! 'NULL' format detected. Check that!"); + } + else + { + THROW_EXCEPTION("ERROR!!! You should NOT get here!! Unsupported SQLite data typecode: " << datacode << " -- Check this!!"); + } + } + records.push_back(nodeParams); + ++nRows; + } + + if (res == SQLITE_DONE || res == SQLITE_ERROR) + { + if (res == SQLITE_ERROR) + { + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); + sqlite3_finalize(stmt); + THROW_EXCEPTION(errmsg); + } + break; + } + } + } + // finalize + sqlite3_finalize(stmt); + return records; +} +// New version with variant +DBRowEntry GMDBManager::getTableRecords_VecData( + const std::string_view tableName) const +{ + if (!checkTableFromCache(tableName)) { + THROW_EXCEPTION("ERROR!!! Table name '" + std::string(tableName) + "' does not exist in cache! (It has not been loaded from the DB)"); + } + // container to be returned + DBRowEntry records; + // get the query statetement ready to be executed + sqlite3_stmt *stmt = nullptr; + + if ("ChildrenPositions" == tableName) + { + stmt = m_d->selectAllFromTableChildrenPositions(); + } + else + { + stmt = m_d->selectAllFromTable(tableName); + } + // execute the query and loop over all rows and all columuns + if (stmt) + { + // Count the Number of Columns in the Table + int ctotal = sqlite3_column_count(stmt); + // Note: for this case, we should have only one column of data; + // so, we throw an error if we get more than two columns in total + if (ctotal > 2) + { + THROW_EXCEPTION("ERROR! Table '" << tableName << "' is supposed to have two columns only, one for the ID and one for actual data; but it has '" + << ctotal << "' columns! Check that!!"); + } + int res = 0; + while (1) + { + res = sqlite3_step(stmt); // Execute SQL Statement. + if (res == SQLITE_ROW) + { + // NOTE: + // we are only interested in returning + // the 'data' column, that is column '1' + // (while column '0' contains the ID) + int colData = 1; + int datacode = sqlite3_column_type(stmt, 1); + // debug msg + // std::cout << "table: " << tableName << ", col " << colData << "/" << ctotal << " -- typecode: " << datacode << std::endl; + + int valI{0}; + double valD{0.}; + std::string valS; + if (SQLiteColumnTypes::INT_TYPE == datacode) + { + valI = sqlite3_column_int(stmt, colData); + records.push_back(valI); + } + else if (SQLiteColumnTypes::FLOAT_TYPE == datacode) + { + valD = sqlite3_column_double(stmt, colData); + records.push_back(valD); + } + else if (SQLiteColumnTypes::TEXT_TYPE == datacode) + { + const char *cc = (char *)sqlite3_column_text(stmt, colData); + if (cc == NULL) + { + valS = "NULL"; + } + else + { + valS = cc; + } + records.push_back(valS); + } + else if (SQLiteColumnTypes::BLOB_TYPE == datacode) + { + THROW_EXCEPTION("ERROR!!! The 'BLOB' data format is not supported yet!!"); + } + else if (SQLiteColumnTypes::NULL_TYPE == datacode) + { + std::cout << "ERROR!!! 'NULL' format detected. Check that!" << std::endl; + } + else + { + THROW_EXCEPTION("ERROR!!! You should NOT get here!! Unsupported SQLite data typecode: " << datacode << " -- Check this!!"); + } + } + + if (res == SQLITE_DONE || res == SQLITE_ERROR) + { + if (res == SQLITE_ERROR) + { + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); + sqlite3_finalize(stmt); + THROW_EXCEPTION(errmsg); } break; } @@ -297,29 +505,154 @@ std::vector<std::vector<std::string>> GMDBManager::getTableRecords( return records; } -std::vector<std::vector<std::string>> GMDBManager::getTableFromNodeType( - std::string nodeType) { +std::vector<std::vector<std::string>> GMDBManager::getTableFromNodeType_String( + const std::string& nodeType) +{ std::vector<std::vector<std::string>> out; std::string tableName = getTableNameFromNodeType(nodeType); - if (tableName.empty()) { + if (tableName.empty()) + { + std::mutex coutMutex; + coutMutex.lock(); + std::string errMsg = "\t ===> WARNING! The geometry input file does not contain a " + "table for the " + + nodeType + + " nodes. That means that you are probably using an " + + "old geometry file." + + "Unless you know exactly what you are doing, " + + "please expect to see incomplete geometries or crashes.\n"; + std::cout << errMsg << std::endl; + coutMutex.unlock(); + } + else + { + // if (!checkTable(tableName)) + if (!checkTableFromDB(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" << tableName << "' does not exist in the DB!"); + } + out = getTableRecords_String(tableName); + } + return out; +} + +DBRowsList GMDBManager::getTableFromNodeType_VecVecData( + const std::string& nodeType) +{ + DBRowsList out; + std::string tableName = getTableNameFromNodeType(nodeType); + + if (tableName.empty()) + { + std::mutex coutMutex; + coutMutex.lock(); + std::cout << + "\t ===> WARNING! The geometry input file does not contain a table for the" + << nodeType + << "nodes. That means that you are probably using an " + << "old geometry file. Unless you know exactly what you are doing, " + << "please expect to see incomplete geometries or crashes.\n" + << std::endl; + coutMutex.unlock(); + } + else + { + if (!checkTableFromDB(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" + tableName + "' does not exist in the DB!"); + } + out = getTableRecords_VecVecData(tableName); + } + return out; +} +DBRowsList GMDBManager::getTableFromTableName_VecVecData( + const std::string& tableName) +{ + DBRowsList out; + if (tableName.empty()) + { std::mutex coutMutex; coutMutex.lock(); - printf( + std::cout << "\t ===> WARNING! The geometry input file does not contain a " - "table " - "for the %s nodes. That means that you are probably using an " - "old " - "geometry file. Unless you know exactly what you are doing, " - "please " - "expect to see incomplete geometries or crashes.\n", - nodeType.c_str()); + "table for the " + << tableName + << "nodes. That means that you are probably using an " + << "old " + << "geometry file. Unless you know exactly what you are doing, " + << "please " + << "expect to see incomplete geometries or crashes.\n" + << std::endl; + coutMutex.unlock(); + } + else + { + if (!checkTableFromDB(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" + tableName + "' does not exist in the DB!"); + } + out = getTableRecords_VecVecData(tableName); + } + return out; +} +DBRowEntry GMDBManager::getTableFromTableName_VecData( + const std::string& tableName) +{ + DBRowEntry out; + if (tableName.empty()) + { + std::mutex coutMutex; + coutMutex.lock(); + std::cout << "\t ===> WARNING! The geometry input file does not contain a " + << "table " + << "for the " + << tableName + << "nodes. That means that you are probably using an " + << "old geometry file. Unless you know exactly what you are doing, " + << "please expect to see incomplete geometries or crashes.\n" + << std::endl; coutMutex.unlock(); - } else { - out = getTableRecords(tableName); + } + else + { + if (!checkTableFromDB(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" + tableName + "' does not exist in the DB!"); + } + out = getTableRecords_VecData(tableName); } return out; } +std::vector<double> GMDBManager::getTableFromTableName_VectorDouble(const std::string& tableName) +{ + DBRowEntry inputRecords = getTableFromTableName_VecData(tableName); + std::vector<double> outRecords; + for (const auto &rec : inputRecords) + { + try + { + // std::cout << "variant data: " << GeoStrUtils::to_string_with_precision(std::get<double>(rec)) << '\n'; + outRecords.push_back(std::get<double>(rec)); + } + catch (std::bad_variant_access const &ex) + { + std::cout << ex.what() << ": w contained int/text, not double\n"; + } + } + return outRecords; +} + +// TODO: make template +// from Johannes: Couldn't you declare this method as a general template method to downcast the variant? +std::deque<double> GMDBManager::getTableFromTableName_DequeDouble(std::string tableName) +{ + std::vector<double> inputRecords = getTableFromTableName_VectorDouble(std::move(tableName)); + // Initialize a deque from vector using range constructor + std::deque<double> outRecords(inputRecords.begin(), inputRecords.end()); + return outRecords; +} + // TODO: simplify error reporting for SQLite // void GMDBManager::showError(const QSqlError &err) const //{ @@ -328,101 +661,80 @@ std::vector<std::vector<std::string>> GMDBManager::getTableFromNodeType( //} bool GMDBManager::addListOfChildrenPositions( - const std::vector<std::vector<std::string>>& records) { + const DBRowsList& records) { if (records.size() > 0) { // NOTE: Choose the right function for your version of SQLite!! return addListOfRecordsToTable("ChildrenPositions", records); // needs SQLite >= 3.7.11 - // return addListOfRecordsToTableOld("ChildrenPositions", records); - // // old SQLite versions } return false; } bool GMDBManager::addListOfPublishedAlignableTransforms( const std::vector<std::vector<std::string>>& records, - std::string suffix /* optional parameter */) { + const std::string& suffix /* optional parameter */) { std::string tableName = "PublishedAlignableTransforms"; // default table name std::string nodeType = "GeoAlignableTransform"; const std::type_info& keyType( typeid(std::string)); // TODO: type should be custom too!! - if ("" != suffix) { + if ("" != suffix) + { tableName += "_"; tableName += suffix; - // debug msg - // std::cout << "\nSaving the published '"<< nodeType << "' nodes to - // the custom table: '" - // << tableName << "'." << std::endl; + if (m_debug) + { + std::cout << "\nSaving the published '" << nodeType + << "' nodes to the custom table : '" << tableName + << "'." << std::endl; + } } // create custom table first then add to it createTableCustomPublishedNodes(tableName, nodeType, &keyType); return addListOfRecordsToTable(tableName, records); // needs SQLite >= 3.7.11 - // return addListOfRecordsToTableOld( tableName, records ); // old - // SQLite versions } bool GMDBManager::addListOfPublishedFullPhysVols( const std::vector<std::vector<std::string>>& records, - std::string suffix /* optional parameter */) { + const std::string& suffix /* optional parameter */) { std::string tableName = "PublishedFullPhysVols"; // default table name std::string nodeType = "GeoFullPhysVol"; const std::type_info& keyType( typeid(std::string)); // TODO: type should be custom too!! - if ("" != suffix) { + if ("" != suffix) + { tableName += "_"; tableName += suffix; - // std::cout << "\nSaving the published '"<< nodeType << "' nodes to - // the custom table: '" - // << tableName << "'." << std::endl; + if (m_debug) + { + std::cout << "\nSaving the published '" << nodeType + << "' nodes to the custom table : '" + << tableName << "'." << std::endl; + } } // create custom table first then add to it createTableCustomPublishedNodes(tableName, nodeType, &keyType); return addListOfRecordsToTable(tableName, records); // needs SQLite >= 3.7.11 - // return addListOfRecordsToTableOld( tableName, records ); // old - // SQLite versions } -/* -bool GMDBManager::addListOfRecordsToCustomTable(const -std::vector<std::vector<std::string>> &records, std::string tableName ) -{ - std::string nodeType = "GeoFullPhysVol"; - const std::type_info &keyType(typeid(std::string));//TODO: type should -be custom too!! - // create custom table first - createTableCustomPublishedNodes( tableName, nodeType, &keyType ); - // add records to the newly-created table - return addListOfRecordsToTable( tableName, records ); // needs SQLite ->= 3.7.11 - //return addListOfRecordsToTableOld( tableName, records ); // old SQLite -versions -} -*/ bool GMDBManager::addListOfRecords( - const std::string geoType, - const std::vector<std::vector<std::string>> records) { + const std::string& geoType, + const std::vector<std::vector<std::string>>& records) { // if (m_debug) qDebug() << "GMDBManager::addListOfRecords():" << // geoType; std::string tableName = m_childType_tableName[geoType]; if (tableName.size() == 0) { - // qWarning() << "m_childType_tableName:" << m_childType_tableName; - std::cout << "ERROR!! could not retrieve tableName for node type '" - << geoType << "'!! Aborting..." << std::endl; - exit(EXIT_FAILURE); + THROW_EXCEPTION("ERROR!! could not retrieve tableName for node type '" + geoType + "'!! Aborting...\n"); } if (records.size() > 0) { - // NOTE: Choose the right function!! return addListOfRecordsToTable( - tableName, records); // better, but needs SQLite >= 3.7.11 - // return addListOfRecordsToTableOld(tableName, records); // old - // SQLite versions + tableName, records); // needs SQLite >= 3.7.11 } else { if (m_debug) std::cout << "Info: no records to save for geoType '" << geoType @@ -431,21 +743,47 @@ bool GMDBManager::addListOfRecords( return true; } +bool GMDBManager::addListOfRecords( + const std::string& geoType, + const DBRowsList& records) { + // if (m_debug) qDebug() << "GMDBManager::addListOfRecords():" << + // geoType; + std::string tableName = m_childType_tableName[geoType]; + + if (tableName.size() == 0) { + THROW_EXCEPTION("ERROR!! could not retrieve tableName for node type '" + geoType + "'!! Aborting...\n"); + } + + if (records.size() > 0) { + return addListOfRecordsToTable( + tableName, records); // needs SQLite >= 3.7.11 + } else { + if (m_debug) + std::cout << "Info: no records to save for geoType '" << geoType + << "'. Skipping..." << std::endl; + } + return true; +} + // ***Note*** // The syntax built here below is more convenient // but it is supported only in SQLite >= 3.7.11 -// (Note: old SLC6-based Athena releases uses SQLite 3.7.9 from LCG) // // Here we build a query like this: // queryStr = QString("INSERT INTO Materials (id, name) VALUES (1,'Air'), // (2,'Silicon'), (368,'ShieldSteel');"); // bool GMDBManager::addListOfRecordsToTable( - const std::string tableName, - const std::vector<std::vector<std::string>> records) { + const std::string& tableName, + const std::vector<std::vector<std::string>>& records) { + + if ( !(hasTableBeenCreatedInDB(tableName)) ) { + THROW_EXCEPTION("ERROR!!! The DB has no '" << tableName << "' table; probably, the table has not been created in the DB."); + } + // get table columns and format them for query std::string tableColString = - "(" + joinVectorStrings(m_tableNames.at(tableName), ", ") + ")"; + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; unsigned int nRecords = records.size(); @@ -459,15 +797,16 @@ bool GMDBManager::addListOfRecordsToTable( for (const std::vector<std::string>& rec : records) { ++id; std::vector<std::string> items; - for (const std::string& item : rec) { + items.reserve(rec.size()); +for (const std::string& item : rec) { items.push_back( "'" + item + "'"); // TODO: we should differentiate strings from other // values when inserting them in the table, as we now // do for the std::variant version! } - std::string values = joinVectorStrings(items, ","); - sql += " (" + std::to_string(id) + "," + values + ")"; + std::string values = GeoStrUtils::chainUp(items, ","); + sql += " (" + std::to_string(id) + "," + values + ")"; // INT if (id != nRecords) { sql += ","; } else { @@ -483,28 +822,30 @@ bool GMDBManager::addListOfRecordsToTable( return true; } -// TODO: use this with std::variant to replace the version with std::string -// only, here above, for all tables; so we can store nativel values (int, -// double, etc...) -- R.M.B. bool GMDBManager::addListOfRecordsToTable( - const std::string tableName, - const std::vector< - std::vector<std::variant<int, long, float, double, std::string>>> - records) { + const std::string& tableName, + const DBRowsList& records) { + + if ( !(hasTableBeenCreatedInDB(tableName)) ) { + THROW_EXCEPTION("ERROR!!! The DB has no '" << tableName << "' table; probably, the table has not been created in the DB."); + } + + if (records.size() > 0) { // get table columns and format them for query std::string tableColString = - "(" + joinVectorStrings(m_tableNames.at(tableName), ", ") + ")"; + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; unsigned int nRecords = records.size(); std::cout << "Info: number of " << tableName - << " records to dump into the DB:" << nRecords << std::endl; + << " records to dump into the DB: " << nRecords << std::endl; + // preparing the SQL query std::string sql = fmt::format("INSERT INTO {0} {1} VALUES ", tableName, tableColString); unsigned int id = 0; - for (const std::vector<std::variant<int, long, float, double, std::string>>& + for (const DBRowEntry& rec : records) { ++id; // a vector to store string-conversions of values, to build the SQL @@ -514,15 +855,13 @@ bool GMDBManager::addListOfRecordsToTable( for (const std::variant<int, long, float, double, std::string>& item : rec) { if (std::holds_alternative<int>(item)) - items.push_back(std::to_string(std::get<int>( - item))); // we need to encapsulate records' values into - // quotes for the SQL query string + items.push_back(std::to_string(std::get<int>(item))); // INT else if (std::holds_alternative<long>(item)) - items.push_back(std::to_string(std::get<long>(item))); + items.push_back(std::to_string(std::get<long>(item))); // INT else if (std::holds_alternative<float>(item)) - items.push_back(std::to_string(std::get<float>(item))); + items.push_back(GeoStrUtils::to_string_with_precision(std::get<float>(item))); else if (std::holds_alternative<double>(item)) - items.push_back(std::to_string(std::get<double>(item))); + items.push_back(GeoStrUtils::to_string_with_precision(std::get<double>(item))); else if (std::holds_alternative<std::string>(item)) { std::string str = std::get<std::string>(item); // NOTE: if item is a "NULL" string, we don't encapsulate it @@ -534,12 +873,11 @@ bool GMDBManager::addListOfRecordsToTable( else items.push_back("'" + str + "'"); } else - throw std::runtime_error( - "No std::variant alternative found!\n"); + THROW_EXCEPTION("No std::variant alternative found!"); } // we build the long string containing all values - std::string values = joinVectorStrings(items, ","); - sql += " (" + std::to_string(id) + "," + values + ")"; + std::string values = GeoStrUtils::chainUp(items, ","); + sql += " (" + std::to_string(id) + "," + values + ")"; // INT if (id != nRecords) { sql += ","; } else { @@ -553,242 +891,129 @@ bool GMDBManager::addListOfRecordsToTable( return false; } return true; + } + return false; } -// TODO: this is for the old SQLite. Not needed anymore, I guess. ==> Just -// put a requirement on the newer version of SQLite3 in CMakeLists.txt. -// Perhaps, also check that GeoModelIO can run smoothly on older ATLAS -// releases, like 21.9 by taking a newer SQLite3 from LCG. -// ***Note*** -// old syntax, for SQLite in SLC6 -// here below we build the syntax for multiple INSERT -// compatible with old SQLite versions -// see: stackoverflow.com/questions/1609637 -// -// we want to build a query like this: -// queryStr = QString("INSERT INTO Materials (id, name) SELECT 1 as id, -// 'Air' as name UNION ALL SELECT 2,'Silicon' UNION ALL SELECT -// 368,'ShieldSteel' ") -// -/* -bool GMDBManager::addListOfRecordsToTableOld(const QString tableName, const -std::vector<QStringList> records) +bool GMDBManager::addRecordsToTable( + const std::string& tableName, + const DBRowEntry& records) { - // get table columns and format them for query - std::string tabColNames = -joinVectorStrings(m_tableNames.at(tableName.toStdString()), ", "); QString -tableColString = "(" + QString::fromStdString(tabColNames) + ")"; - - + if (records.size() > 0) { + // get table columns and format them for query + std::string tableColString = + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; + if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; - QStringList colNames = m_tableNames.at(tableName); unsigned int nRecords = records.size(); - qInfo() << "number of " << tableName << "records to insert into the DB:" -<< nRecords; - - - // SQLite has a limit on 'union' items, set at 500. So we have to split -the items if we have more. - // See: stackoverflow.com/questions/9527851/ - - unsigned int bunchSize = 500; - if ( nRecords > bunchSize ) { - qWarning() << "WARNING! " << nRecords << " records of type " << -tableName << "to store in the DB in one call! Call limit is " << bunchSize -<< " ---> We split them in bunches..."; - - std::vector<QStringList> recordsCopy( records ); // TODO: maybe we -should use a deque or queue, which have fast pop of first element? - - std::vector<QStringList>::const_iterator first; - std::vector<QStringList>::const_iterator last; - - unsigned int start = 0; - - while ( recordsCopy.size() > 0 ) { - - // preparing the SQL query - QString queryStr("INSERT INTO %1 %2 SELECT "); - queryStr = queryStr.arg(tableName); // insert table name - queryStr = queryStr.arg(tableColString); // insert table columns - - first = recordsCopy.begin(); - last = recordsCopy.size() > bunchSize ? recordsCopy.begin() + -bunchSize : recordsCopy.end(); - - std::vector<QStringList> recordsBunch( first, last ); // we take the -first 500 records recordsCopy.erase( first, last ); // we delete the first -500 records if (m_debug) qDebug() << "start:" << start << "recordsBunch -size:" << recordsBunch.size() << "- recordsCopy size after removal:" << -recordsCopy.size(); - - // --- first record - // outcome should be like: " 1 as id, 'Air' as name " - unsigned int id = start+1; // set the first ID as 'start' - QStringList recFirst = recordsBunch.front(); // access first record -from vector recordsBunch.erase( recordsBunch.begin() ); // delete first -record if (m_debug) qDebug() << "after taking first record - recordsBunch -size:" << recordsBunch.size(); - - // first item in the first record (it is the ID) - QString firstCol = colNames[0]; - queryStr += QString::number(id) + " as " + firstCol + ", "; - - // the other items in the first record - unsigned int ii = 1; - unsigned int nRecs = recFirst.size(); - foreach (QString rec, recFirst) { - queryStr += "'" + rec + "'" + " as " + colNames[ii]; - if (ii != nRecs) - queryStr += ","; // add coma, but not on latest - queryStr += " "; // add space - //qDebug() << "first element:" << ii << nRecs << queryStr; - ++ii; - } - if (m_debug) qDebug() << "first element query:" << queryStr; - // --- other records - // outcome should be: " UNION ALL SELECT 2,'Silicon' " - - - foreach(QStringList recs, recordsBunch) { - - // DEBUG - if (tableName == -"Functions") { if (recs[1].length() > 65000) { std::cout << "LONG STRING! -size: " << recs[1].length() << std::endl; std::cout << "LONG STRING! string: -" << recs[1].toStdString() << std::endl << std::endl; - } - } - //------ - - ++id; - // put single quotes around items - QStringList items; - foreach (QString item, recs) { - items << "'" + item + "'"; - } - // join items into a string and add the SQL commands - QString itemsStr = items.join(", "); - queryStr += " UNION ALL SELECT " + QString::number(id) + ", -" + itemsStr; - } - - //qDebug() << "queryStr:" << queryStr; - - // executing the SQL query - QSqlQuery q; - if (!q.exec(queryStr)) { - qWarning() << "ERROR!!! SQL error:"; - showError(q.lastError()); - return false; - } - // JFB commented: qDebug() << bunchSize << "elements have been saved -into the DB, starting at:" << start; - - start += bunchSize; // for the next iteration - } // end of while + std::cout << "Info: number of " << tableName + << " records to dump into the DB: " << nRecords << std::endl; - } // end of if(>500) - else { // preparing the SQL query - QString queryStr("INSERT INTO %1 %2 SELECT "); - queryStr = queryStr.arg(tableName); // insert table name - queryStr = queryStr.arg(tableColString); // insert table columns - + std::string sql = + fmt::format("INSERT INTO {0} {1} VALUES ", tableName, tableColString); unsigned int id = 0; - // loop on all records - foreach(QStringList recs, records) { - - ++id; - - // first record - // outcome should be like: " 1 as id, 'Air' as name " - if (id == 1) { - - // first item if the record (it is the ID) - QString firstCol = colNames.takeFirst(); - queryStr += QString::number(id) + " as " + firstCol + ", "; - - // the other items in the record - unsigned int ii = 0; - unsigned int nRecs = recs.size(); - foreach (QString rec, recs) { - queryStr += "'" + rec + "'" + " as " + colNames[ii]; - if (ii != nRecs-1) - queryStr += ","; // add coma, but not on latest - queryStr += " "; // add space - //qDebug() << ii << nRecs << queryStr; - ++ii; - } - - } - // other records - // outcome should be: " UNION ALL SELECT 2,'Silicon' " - else { + // a vector to store string-conversions of values, to build the SQL + // query + // TODO: we should remove this TEXT-conversion + // and we should use prepared statements instead! + std::vector<std::string> items; + // loop over all entries in a row/record + for (const std::variant<int, long, float, double, std::string> &item : + records) + { + ++id; - // put single quotes around items - QStringList items; - foreach (QString item, recs) { - items << "'" + item + "'"; - } - // join items into a string and add the SQL commands - QString itemsStr = items.join(", "); - queryStr += " UNION ALL SELECT " + QString::number(id) + ", " + -itemsStr; + std::string startRow = "(" + std::to_string(id) + ", "; // INT + items.push_back(startRow); + + if (std::holds_alternative<int>(item)) + items.push_back(std::to_string(std::get<int>(item))); // INT + else if (std::holds_alternative<long>(item)) + items.push_back(std::to_string(std::get<long>(item))); // INT + else if (std::holds_alternative<float>(item)) + items.push_back(GeoStrUtils::to_string_with_precision(std::get<float>(item))); + else if (std::holds_alternative<double>(item)) + items.push_back(GeoStrUtils::to_string_with_precision(std::get<double>(item))); + else if (std::holds_alternative<std::string>(item)) + { + std::string str = std::get<std::string>(item); + // NOTE: if item is a "NULL" string, we don't encapsulate it + // into quotes, so it is taken as the SQL's NULL value in + // the SQL string, and inserted as a NULL value in the + // table, instead of as a "NULL" text string + if (str == "NULL") + { + items.push_back(str); + } + else + { + items.push_back("'" + str + "'"); + } + } + else + { + THROW_EXCEPTION("No std::variant alternative found!"); } - } // end of: foreach(QStringList recs, records) - - //qDebug() << "queryStr:" << queryStr; - - // executing the SQL query - QSqlQuery q; - if (!q.exec(queryStr)) { - qWarning() << "ERROR!!! SQL error:"; - showError(q.lastError()); - return false; + std::string endRow = ")"; + if (id != nRecords) + { + endRow += ", "; } -} // end of (else > 500) + else + { + endRow += ";"; + } + items.push_back(endRow); + } + // we build the long SQL string containing all values + std::string values = GeoStrUtils::chainUp<std::string>(items, ""); - // JFB commented: qDebug() << "DONE. The list of " << nRecords << -"records have been inserted into the DB."; return true; + sql += " " + values + ";"; + if (m_debug) + std::cout << "Query string:" << sql << std::endl; // debug + // executing the SQL query + if (!(execQuery(sql))) + { + return false; + } + return true; + } + return false; } -*/ -bool GMDBManager::addRootVolume(const std::vector<std::string>& values) { - if (values.size() > 0) { - const unsigned int volId = std::stoi(values[0]); - const std::string nodeType = values[1]; - return storeRootVolume(volId, nodeType); - } else { - std::cout << "ERROR! No records to save for RootVolume! All GeoModel " - "trees must have a 'World'/'Root' volume! Exiting..." - << std::endl; - exit(EXIT_FAILURE); - } + +// bool GMDBManager::addRootVolume(const std::vector<std::string>& values) { +bool GMDBManager::addRootVolume(const std::string_view type, const unsigned id) +{ + const std::string nodeType{type}; + const unsigned int volId{id}; + return storeRootVolume(volId, nodeType); +} +bool GMDBManager::addRootVolume(const std::pair<std::string, unsigned>& rootValues) +{ + const std::string nodeType{rootValues.first}; + const unsigned int volId{rootValues.second}; + return storeRootVolume(volId, nodeType); } -void GMDBManager::addDBversion(std::string version) { +void GMDBManager::addDBversion(const std::string& version) { checkIsDBOpen(); sqlite3_stmt* st = nullptr; int rc = -1; std::string sql = "INSERT INTO dbversion(version) VALUES(?)"; rc = sqlite3_prepare_v2(m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } rc = sqlite3_bind_text(st, 1, version.c_str(), version.length(), SQLITE_TRANSIENT); rc = sqlite3_step(st); if (rc != SQLITE_DONE) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } // finalize sqlite3_finalize(st); @@ -799,9 +1024,7 @@ bool GMDBManager::checkIsDBOpen() const { if (m_d->m_dbSqlite != nullptr) { return true; } else { - std::cout << "ERROR! The SQLite DB is not accessible! Exiting..." - << std::endl; - exit(EXIT_FAILURE); + THROW_EXCEPTION("ERROR! The SQLite DB is not accessible! Exiting..."); } } @@ -819,7 +1042,7 @@ std::vector<std::string> GMDBManager::getItemAndType(unsigned int tableId, } std::vector<std::string> GMDBManager::getItemFromTableName( - std::string tableName, unsigned int id) { + const std::string& tableName, unsigned int id) { // FIXME: when you create caches for all tables, replace this method // with a lookup action in the cache. /* @@ -834,9 +1057,7 @@ std::vector<std::string> GMDBManager::getItemFromTableName( int rc = -1; rc = sqlite3_prepare_v2(m_d->m_dbSqlite, sql.c_str(), -1, &stmt, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] 'prepare' (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] 'prepare' (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } // bind the parameters rc = sqlite3_bind_int(stmt, 1, id); @@ -863,7 +1084,7 @@ std::vector<std::string> GMDBManager::getItemFromTableName( if (res == SQLITE_ERROR) { std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); - throw errmsg; + THROW_EXCEPTION(errmsg); } break; } @@ -879,22 +1100,21 @@ std::vector<std::string> GMDBManager::getItemFromTableName( sqlite3_finalize(stmt); if (item.size() == 0) { - std::cout << "ERROR!!" - << "Item with ID:'" << id << "' does not exist in table" - << tableName << "! Exiting..."; - exit(EXIT_FAILURE); + THROW_EXCEPTION("ERROR!! Item with ID:'" << id << "' does not exist in table" + << tableName << "! Exiting..."); } return item; } // Get all parent-children data from the database in one go -std::vector<std::vector<std::string>> GMDBManager::getChildrenTable() { - return getTableRecords("ChildrenPositions"); +DBRowsList GMDBManager::getChildrenTable() { + return getTableRecords_VecVecData("ChildrenPositions"); } -unsigned int GMDBManager::getTableIdFromNodeType(const std::string& nodeType) { - return m_cache_nodeType_tableID[nodeType]; +unsigned int GMDBManager::getTableIdFromNodeType(const std::string_view nodeType) { + if (m_cache_nodeType_tableID.empty()) THROW_EXCEPTION("ERROR! Cache is empty!"); + return m_cache_nodeType_tableID[std::string(nodeType)]; } std::string GMDBManager::getTableNameFromNodeType(const std::string& nodeType) { @@ -927,9 +1147,7 @@ int GMDBManager::loadGeoNodeTypesAndBuildCache() { // prepare the query rc = sqlite3_prepare_v2(m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } // execute the statement until all selected records are processed while ((rc = sqlite3_step(st)) == SQLITE_ROW) { @@ -955,21 +1173,20 @@ int GMDBManager::loadGeoNodeTypesAndBuildCache() { if (rc != SQLITE_DONE) { std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(st); - throw errmsg; + THROW_EXCEPTION(errmsg); } // finalize sqlite3_finalize(st); return rc; } -// FIXME: should throw an error if the method -// `loadGeoNodeTypesAndBuildCache()` was not called before calling this -// method std::string GMDBManager::getTableNameFromTableId(unsigned int tabId) { + if (m_cache_tableId_tableName.empty()) THROW_EXCEPTION("ERROR! Cache is empty!"); return m_cache_tableId_tableName[tabId]; } std::string GMDBManager::getNodeTypeFromTableId(unsigned int tabId) { + if (m_cache_tableId_nodeType.empty()) THROW_EXCEPTION("ERROR! Cache is empty!"); return m_cache_tableId_nodeType[tabId]; } @@ -984,12 +1201,13 @@ GMDBManager::getAll_NodeTypesTableIDs() { } sqlite3_stmt* GMDBManager::Imp::selectAllFromTable( - std::string tableName) const { + const std::string_view tableName) const { return selectAllFromTableSortBy(tableName, "id"); } sqlite3_stmt* GMDBManager::Imp::selectAllFromTableSortBy( - std::string tableName, std::string sortColumn) const { + const std::string_view tableName, const std::string_view sortCol) const { + std::string sortColumn{sortCol}; theManager->checkIsDBOpen(); if ("" == sortColumn || 0 == sortColumn.size()) { sortColumn = "id"; @@ -1002,14 +1220,12 @@ sqlite3_stmt* GMDBManager::Imp::selectAllFromTableSortBy( // prepare the query rc = sqlite3_prepare_v2(m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_dbSqlite)); } return st; } -bool GMDBManager::Imp::checkTable_imp(std::string tableName) const { +bool GMDBManager::Imp::checkTableFromDB_imp(const std::string& tableName) const { theManager->checkIsDBOpen(); sqlite3_stmt* st = nullptr; // SQLite statement to be returned int rc = -1; // SQLite return code @@ -1032,9 +1248,7 @@ sqlite3_stmt* GMDBManager::Imp::selectAllFromTableChildrenPositions() const { // prepare the query rc = sqlite3_prepare_v2(m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_dbSqlite)); } return st; } @@ -1047,16 +1261,31 @@ bool GMDBManager::initDB() { return tablesOK; } + +bool GMDBManager::checkTableFromCache(const std::string_view tableName) const +{ + std::string tableNameStr{tableName}; + if (m_cache_tables.size() == 0) + { + return false; + } + else if (m_cache_tables.find(tableNameStr) != m_cache_tables.end()) + { + return true; + } + return false; +} + void GMDBManager::printAllDBTables() { if (m_cache_tables.size() == 0) { getAllDBTables(); // load tables and build the cache } - for (auto& str : m_cache_tables) std::cout << str << std::endl; + for (const auto& str : m_cache_tables) std::cout << str << std::endl; } void GMDBManager::getAllDBTables() { std::string tableName; - std::vector<std::string> tables; + std::set<std::string> tables; // define a query string containing the necessary SQL instructions std::string queryStr = "SELECT name FROM sqlite_master WHERE type ='table' AND name NOT " @@ -1067,19 +1296,19 @@ void GMDBManager::getAllDBTables() { int rc = sqlite3_prepare_v2(m_d->m_dbSqlite, queryStr.c_str(), -1, &stmt, NULL); if (rc != SQLITE_OK) { - throw std::string(sqlite3_errmsg(m_d->m_dbSqlite)); + THROW_EXCEPTION(std::string(sqlite3_errmsg(m_d->m_dbSqlite))); } // execute the statement until all selected records are processed while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { tableName = std::string( reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0))); // std::cout << "tableName: " << tableName << std::endl; // debug - tables.push_back(tableName); + tables.insert(tableName); } if (rc != SQLITE_DONE) { std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); - throw errmsg; + THROW_EXCEPTION(errmsg); } // finalize sqlite3_finalize(stmt); @@ -1099,7 +1328,7 @@ void GMDBManager::getAllDBTableColumns() { return; } - for (auto& tableName : m_cache_tables) { + for (const auto& tableName : m_cache_tables) { sqlite3_stmt* stmt; // get the 'name' column from the PRAGMA's table's definition // see: https://stackoverflow.com/a/54962853/320369 @@ -1126,48 +1355,54 @@ void GMDBManager::getAllDBTableColumns() { // TODO: currently, we retrieve published data as strings, but we want to // retrieve that according to the original data type -std::vector<std::vector<std::string>> GMDBManager::getPublishedFPVTable( - std::string suffix) { +// std::vector<std::vector<std::string>> GMDBManager::getPublishedFPVTable( +DBRowsList GMDBManager::getPublishedFPVTable( + const std::string_view suffix) { std::string tableName = "PublishedFullPhysVols"; // default table name - if ("" != suffix) { + if ( !suffix.empty() ) { tableName += "_"; tableName += suffix; } - - return getTableRecords(tableName); + if (!checkTableFromCache(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" + tableName + "' does not exist in the DB!"); + } + return getTableRecords_VecVecData(tableName); } // TODO: currently, we retrieve published data as strings, but we want to // retrieve that according to the original data type -std::vector<std::vector<std::string>> GMDBManager::getPublishedAXFTable( - std::string suffix) { +// std::vector<std::vector<std::string>> GMDBManager::getPublishedAXFTable( +DBRowsList GMDBManager::getPublishedAXFTable( + const std::string_view suffix) { std::string tableName = "PublishedAlignableTransforms"; // default table name - if ("" != suffix) { + if ( !suffix.empty() ) { tableName += "_"; tableName += suffix; } - - return getTableRecords(tableName); + if (!checkTableFromCache(tableName)) + { + THROW_EXCEPTION("ERROR!!! Table name '" + tableName + "' does not exist in cache! (It has not been loaded from the DB)"); + } + return getTableRecords_VecVecData(tableName); } -bool GMDBManager::checkTable(std::string tableName) const { - return m_d->checkTable_imp(tableName); +bool GMDBManager::checkTableFromDB(const std::string& tableName) const { + return m_d->checkTableFromDB_imp(tableName); } // create a user-defined custom table to store the published nodes // (usually GeoFullPhysVol and AlignableTransform nodes) and their keys. bool GMDBManager::createTableCustomPublishedNodes( - const std::string tableName, const std::string nodeType, + const std::string& tableName, const std::string& nodeType, const std::type_info* keyType) { // get the right node type and referenced table if (nodeType != "GeoFullPhysVol" && nodeType != "GeoVFullPhysVol" && nodeType != "GeoAlignableTransform") { - std::cout << "ERROR!! GeoModel node type '" << nodeType + THROW_EXCEPTION("ERROR!! GeoModel node type '" << nodeType << "' is not currently supported in " "GMDBManager::createTableCustomPublishedNodes()" - << " Please, ask to geomodel-developers@cern.ch. Exiting..." - << std::endl; - exit(EXIT_FAILURE); + << " Please, ask to geomodel-developers@cern.ch. Exiting..."); } std::string referencedTable = ""; if ("GeoFullPhysVol" == nodeType || "GeoVFullPhysVol" == nodeType) @@ -1183,12 +1418,10 @@ bool GMDBManager::createTableCustomPublishedNodes( else if (typeid(int) == *keyType || typeid(unsigned) == *keyType) keyTypeDB = "integer"; else { - std::cout << "ERROR!!! The key type '" << typeid(keyType).name() + THROW_EXCEPTION("ERROR!!! The key type '" << typeid(keyType).name() << "' is not currently supported in " "GMDBManager::createTableCustomPublishedNodes()." - << " Please, ask to 'geomodel-developers@cern.ch'. Exiting..." - << std::endl; - exit(EXIT_FAILURE); + << " Please, ask to 'geomodel-developers@cern.ch'. Exiting..."); } int rc = -1; // sqlite's return code @@ -1212,65 +1445,23 @@ bool GMDBManager::createTableCustomPublishedNodes( return rc; } -/* --- not used anymore, we now have std::variant, below --- -// create a user-defined custom table to store auxiliary data, from -vector<vector<string>> bool GMDBManager::createCustomTable(const std::string -tableName, const std::vector<std::string> tableColNames, const -std::vector<std::string> tableColTypes, const -std::vector<std::vector<std::string>> &records ) -{ - if( tableColNames.size() == 0 ) throw -std::runtime_error("GMDBManager::createCustomTable -- The list of columns' -names is empty!!"); if( tableColTypes.size() == 0 ) throw -std::runtime_error("GMDBManager::createCustomTable -- The list of columns' -types is empty!!"); - - int rc = -1; // sqlite's return code - std::string queryStr; - - std::vector<std::string> tab; - - tab.push_back(tableName); - tab.push_back( "id" ); // this is the column to store the records' IDs - for( auto& colName : tableColNames ) - tab.push_back( colName ); - - storeTableColumnNames(tab); - - // prepare the dynamic query to create the custom table - queryStr = fmt::format( "create table {0} ( id integer primary key ", -tab[0] -); for( int ii=0; ii<tableColNames.size(); ++ii) { std::string colStr = -fmt::format( ", {0} {1} ", tableColNames[ii], tableColTypes[ii] ); queryStr -+= colStr; - } - queryStr += ")"; - - rc = execQuery(queryStr); - tab.clear(); - return addListOfRecordsToTable( tableName, records ); // needs SQLite ->= 3.7.11 -} -*/ // create a user-defined custom table to store auxiliary data, from // vector<vector<variant>> bool GMDBManager::createCustomTable( - const std::string tableName, const std::vector<std::string> tableColNames, - const std::vector<std::string> tableColTypes, + const std::string& tableName, const std::vector<std::string>& tableColNames, + const std::vector<std::string>& tableColTypes, const std::vector< - std::vector<std::variant<int, long, float, double, std::string>>>& + DBRowEntry>& records) { - if (tableColNames.size() == 0) - throw std::runtime_error( - "GMDBManager::createCustomTable -- The list of columns' names " - "is " - "empty!!"); - if (tableColTypes.size() == 0) - throw std::runtime_error( - "GMDBManager::createCustomTable -- The list of columns' types " - "is " - "empty!!"); + if (tableColNames.size() == 0) { + THROW_EXCEPTION("GMDBManager::createCustomTable -- The list of columns' names " + "is empty!!"); + } + if (tableColTypes.size() == 0) { + THROW_EXCEPTION("GMDBManager::createCustomTable -- The list of columns' types " + "is empty!!"); + } std::string queryStr; @@ -1278,7 +1469,7 @@ bool GMDBManager::createCustomTable( tab.push_back(tableName); tab.push_back("id"); // this is the column to store the records' IDs - for (auto& colName : tableColNames) tab.push_back(colName); + for (const auto& colName : tableColNames) tab.push_back(colName); storeTableColumnNames(tab); @@ -1288,6 +1479,7 @@ bool GMDBManager::createCustomTable( for (size_t ii = 0; ii < tableColNames.size(); ++ii) { std::string colType = ""; + // *** NOTE: *** // -- Here we check the datum's type, which is more universal than // using string-encoded types // -- but this does not work if the first entry of a given column is @@ -1318,9 +1510,8 @@ bool GMDBManager::createCustomTable( else if (tableColTypes[ii] == "STRING") colType = "TEXT"; else - throw std::runtime_error( - "No suitable column type has been found ==> " + - tableColTypes[ii] + "\n"); + THROW_EXCEPTION("No suitable column type has been found ==> " + + tableColTypes[ii]); std::string colStr = fmt::format(", {0} {1} ", tableColNames[ii], colType); @@ -1384,17 +1575,29 @@ bool GMDBManager::createTables() { tab.push_back("childCopyNumber"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} integer, {3} " - "integer " - "not null REFERENCES GeoNodesTypes(id), {4} integer, {5} integer, " - "{6} " - "integer not null REFERENCES GeoNodesTypes(id), {7} integer not " - "null, " + "create table {0}({1} integer primary key, {2} integer, " + "{3} integer not null REFERENCES GeoNodesTypes(id), " + "{4} integer, {5} integer, " + "{6} integer not null REFERENCES GeoNodesTypes(id), " + "{7} integer not null, " "{8} integer not null)", tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8]); rc = execQuery(queryStr); tab.clear(); + + // create a table to store the numeric data used in Functions + tableName = "FuncExprData"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("data"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real not null)", + tab[0], tab[1], tab[2]); + rc = execQuery(queryStr); + tab.clear(); + // create a table to store information about the 'root' volume (also // known as the 'world' volume) tableName = "RootVolume"; @@ -1451,13 +1654,14 @@ bool GMDBManager::createTables() { tab.push_back("id"); tab.push_back("name"); tab.push_back("shape"); + tab.push_back("shapeType"); tab.push_back("material"); storeTableColumnNames(tab); queryStr = fmt::format( "create table {0}({1} integer primary key, {2} varchar, {3} " "integer " - "not null, {4} integer not null)", - tab[0], tab[1], tab[2], tab[3], tab[4]); + "not null, {4} varchar not null, {5} integer not null)", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); if (0 == (rc = execQuery(queryStr))) { storeNodeType(geoNode, tableName); } @@ -1471,20 +1675,35 @@ bool GMDBManager::createTables() { tab.push_back("id"); tab.push_back("name"); tab.push_back("density"); - tab.push_back("elements"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} varchar, {3} " - "varchar, " - "{4} varchar)", - tab[0], tab[1], tab[2], tab[3], tab[4]); + "create table {0}({1} integer primary key, {2} varchar, " + "{3} real, {4} integer, {5} integer)", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); if (0 == (rc = execQuery(queryStr))) { storeNodeType(geoNode, tableName); } tab.clear(); - // Elements table - geoNode = "GeoElement"; + // create a table to store the numeric data used in GeoPcon shapes + tableName = "Materials_Data"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("element"); + tab.push_back("fraction"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, " + "{2} integer not null, " + "{3} real )", + tab[0], tab[1], tab[2], tab[3]); + rc = execQuery(queryStr); + tab.clear(); + + // Elements table + geoNode = "GeoElement"; tableName = "Elements"; m_childType_tableName[geoNode] = tableName; tab.push_back(tableName); @@ -1495,15 +1714,16 @@ bool GMDBManager::createTables() { tab.push_back("A"); storeTableColumnNames(tab); queryStr = fmt::format( - "create table {0}({1} integer primary key, {2} varchar, {3} " - "varchar, " - "{4} varchar, {5} varchar)", + "create table {0}({1} integer primary key, {2} varchar, " + "{3} varchar, " + "{4} real, {5} real)", tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); if (0 == (rc = execQuery(queryStr))) { storeNodeType(geoNode, tableName); } tab.clear(); + // TODO: to be removed as soson as all shapes are migrated to the new DB schema // Shapes table geoNode = "GeoShape"; tableName = "Shapes"; @@ -1522,6 +1742,442 @@ bool GMDBManager::createTables() { } tab.clear(); + // Shapes-Box table + // ID, XHalfLength, YHalfLength, ZHalfLength + geoNode = "GeoBox"; + tableName = "Shapes_Box"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("XHalfLength"); + tab.push_back("YHalfLength"); + tab.push_back("ZHalfLength"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Tube table + geoNode = "GeoTube"; + tableName = "Shapes_Tube"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("RMin"); + tab.push_back("RMax"); + tab.push_back("ZHalfLength"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Cons table + geoNode = "GeoCons"; + tableName = "Shapes_Cons"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("RMin1"); + tab.push_back("RMin2"); + tab.push_back("RMax1"); + tab.push_back("RMax2"); + tab.push_back("DZ"); + tab.push_back("SPhi"); + tab.push_back("DPhi"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real, {8} real, {9} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8], tab[9]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Para table + geoNode = "GeoPara"; + tableName = "Shapes_Para"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("XHalfLength"); + tab.push_back("YHalfLength"); + tab.push_back("ZHalfLength"); + tab.push_back("Alpha"); + tab.push_back("Theta"); + tab.push_back("Phi"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real, {8} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Trap table + geoNode = "GeoTrap"; + tableName = "Shapes_Trap"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("ZHalfLength"); + tab.push_back("Theta"); + tab.push_back("Phi"); + tab.push_back("Dydzn"); + tab.push_back("Dxdyndzn"); + tab.push_back("Dxdypdzn"); + tab.push_back("Angleydzn"); + tab.push_back("Dydzp"); + tab.push_back("Dxdyndzp"); + tab.push_back("Dxdypdzp"); + tab.push_back("Angleydzp"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real, {8} real, {9} real, {10} real, {11} real, {12} real, {13} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8], tab[9], tab[10], tab[11], tab[12], tab[13] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Trd table + geoNode = "GeoTrd"; + tableName = "Shapes_Trd"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("XHalfLength1"); + tab.push_back("XHalfLength2"); + tab.push_back("YHalfLength1"); + tab.push_back("YHalfLength2"); + tab.push_back("ZHalfLength"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Tubs table + geoNode = "GeoTubs"; + tableName = "Shapes_Tubs"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("RMin"); + tab.push_back("RMax"); + tab.push_back("ZHalfLength"); + tab.push_back("SPhi"); + tab.push_back("DPhi"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Tubs table + geoNode = "GeoTorus"; + tableName = "Shapes_Torus"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("RMin"); + tab.push_back("RMax"); + tab.push_back("RTor"); + tab.push_back("SPhi"); + tab.push_back("DPhi"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-TwistedTrap table + geoNode = "GeoTwistedTrap"; + tableName = "Shapes_TwistedTrap"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("PhiTwist"); + tab.push_back("ZHalfLength"); + tab.push_back("Theta"); + tab.push_back("Phi"); + tab.push_back("Y1HalfLength"); + tab.push_back("X1HalfLength"); + tab.push_back("X2HalfLength"); + tab.push_back("Y2HalfLength"); + tab.push_back("X3HalfLength"); + tab.push_back("X4HalfLength"); + tab.push_back("TiltAngleAlpha"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real, {8} real, {9} real, {10} real, {11} real, {12} real, {13} real )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8], tab[9], tab[10], tab[11], tab[12], tab[13] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Pcon table + geoNode = "GeoPcon"; + tableName = "Shapes_Pcon"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("SPhi"); + tab.push_back("DPhi"); + tab.push_back("NZPlanes"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} integer, {6} integer, {7} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Pgon table + geoNode = "GeoPgon"; + tableName = "Shapes_Pgon"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("SPhi"); + tab.push_back("DPhi"); + tab.push_back("NSides"); + tab.push_back("NZPlanes"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} integer, {6} integer, {7} integer, {8} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7], tab[8]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-SimplePolygonBrep table + geoNode = "GeoSimplePolygonBrep"; + tableName = "Shapes_SimplePolygonBrep"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("DZ"); + tab.push_back("NVertices"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} integer, {5} integer, {6} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-SimplePolygonBrep table + geoNode = "GeoGenericTrap"; + tableName = "Shapes_GenericTrap"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("ZHalfLength"); + tab.push_back("NVertices"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} integer, {5} integer, {6} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Intersection table + geoNode = "GeoShapeIntersection"; + tableName = "Shapes_Intersection"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("shapeAType"); + tab.push_back("shapeAId"); + tab.push_back("shapeBType"); + tab.push_back("shapeBId"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} varchar, {4} integer, {5} varchar, {6} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Shift table + geoNode = "GeoShapeShift"; + tableName = "Shapes_Shift"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("shapeType"); + tab.push_back("shapeId"); + tab.push_back("transformId"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} varchar, {4} integer, {5} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Subtraction table + geoNode = "GeoShapeSubtraction"; + tableName = "Shapes_Subtraction"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("shapeAType"); + tab.push_back("shapeAId"); + tab.push_back("shapeBType"); + tab.push_back("shapeBId"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} varchar, {4} integer, {5} varchar, {6} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Union table + geoNode = "GeoShapeUnion"; + tableName = "Shapes_Union"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("shapeAType"); + tab.push_back("shapeAId"); + tab.push_back("shapeBType"); + tab.push_back("shapeBId"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} varchar, {4} integer, {5} varchar, {6} integer )", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6] ); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Shapes-Box table + // ID, XHalfLength, YHalfLength, ZHalfLength + geoNode = "GeoUnidentifiedShape"; + tableName = "Shapes_UnidentifiedShape"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedVolume"); + tab.push_back("name"); + tab.push_back("asciiData"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} varchar, {4} varchar )", + tab[0], tab[1], tab[2], tab[3], tab[4]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // create a table to store the numeric data used in GeoPcon shapes + tableName = "Shapes_Pcon_Data"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("ZPlane"); + tab.push_back("RMinPlane"); + tab.push_back("RMaxPlane"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real )", + tab[0], tab[1], tab[2], tab[3], tab[4]); + rc = execQuery(queryStr); + tab.clear(); + + // create a table to store the numeric data used in GeoPcon shapes + tableName = "Shapes_Pgon_Data"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("ZPlane"); + tab.push_back("RMinPlane"); + tab.push_back("RMaxPlane"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real )", + tab[0], tab[1], tab[2], tab[3], tab[4]); + rc = execQuery(queryStr); + tab.clear(); + + // create a table to store the numeric data used in GeoPcon shapes + tableName = "Shapes_SimplePolygonBrep_Data"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("XVertex"); + tab.push_back("YVertex"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real )", + tab[0], tab[1], tab[2], tab[3]); + rc = execQuery(queryStr); + tab.clear(); + + // create a table to store the numeric data used in GeoPcon shapes + tableName = "Shapes_GenericTrap_Data"; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("XVertex"); + tab.push_back("YVertex"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real )", + tab[0], tab[1], tab[2], tab[3]); + rc = execQuery(queryStr); + tab.clear(); + // SerialDenominators table geoNode = "GeoSerialDenominator"; tableName = "SerialDenominators"; @@ -1577,10 +2233,12 @@ bool GMDBManager::createTables() { tab.push_back(tableName); tab.push_back("id"); tab.push_back("expression"); + tab.push_back("dataStart"); + tab.push_back("dataEnd"); storeTableColumnNames(tab); queryStr = - fmt::format("create table {0}({1} integer primary key, {2} varchar)", - tab[0], tab[1], tab[2]); + fmt::format("create table {0}({1} integer primary key, {2} varchar, {3} integer, {4} integer)", + tab[0], tab[1], tab[2], tab[3], tab[4]); if (0 == (rc = execQuery(queryStr))) { storeNodeType(geoNode, tableName); } @@ -1685,7 +2343,113 @@ bool GMDBManager::createTables() { storeNodeType(geoNode, tableName); } tab.clear(); +//---------------------------------------------------------------------------- + // VSurface table + // ID = 33 in GeoNodesTypes, so that .db files introduced before Virtual Surface won't crush + geoNode = "GeoVSurface"; + tableName = "VirtualSurface"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("shapeType"); + tab.push_back("shapeId"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} varchar not null, {3} integer not null)", + tab[0], tab[1], tab[2], tab[3]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Surface-Rectangle table + // ID = 34 in GeoNodesTypes + // ID, XHalfLength, YHalfLength + geoNode = "RectangleSurface"; + tableName = "Surface_Rectangle"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedArea"); + tab.push_back("XHalfLength"); + tab.push_back("YHalfLength"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real)", + tab[0], tab[1], tab[2], tab[3], tab[4]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Surface-Trapezoid table + // ID = 35 in GeoNodesTypes + // ID, XHalfLengthMin, XHalfLengthMax, YHalfLength + geoNode = "TrapezoidSurface"; + tableName = "Surface_Trapezoid"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedArea"); + tab.push_back("XHalfLengthMin"); + tab.push_back("XHalfLengthMax"); + tab.push_back("YHalfLength"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real)", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Surface-Annulus table + // ID = 36 in GeoNodesTypes + // ID, Ox, Oy, radius_in, radius_out, phi + geoNode = "AnnulusSurface"; + tableName = "Surface_Annulus"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedArea"); + tab.push_back("Ox"); + tab.push_back("Oy"); + tab.push_back("radius_in"); + tab.push_back("radius_out"); + tab.push_back("phi"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real)", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); + + // Surface-Diamond table + // ID = 37 in GeoNodesTypes + // ID, X_bottom_half, X_mid_half, X_top_half, Y_bottom_half, Y_top_half + geoNode = "DiamondSurface"; + tableName = "Surface_Diamond"; + m_childType_tableName[geoNode] = tableName; + tab.push_back(tableName); + tab.push_back("id"); + tab.push_back("computedArea"); + tab.push_back("X_bottom_half"); + tab.push_back("X_mid_half"); + tab.push_back("X_top_half"); + tab.push_back("Y_bottom_half"); + tab.push_back("Y_top_half"); + storeTableColumnNames(tab); + queryStr = fmt::format( + "create table {0}({1} integer primary key, {2} real, {3} real, {4} real, {5} real, {6} real, {7} real)", + tab[0], tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab[7]); + if (0 == (rc = execQuery(queryStr))) { + storeNodeType(geoNode, tableName); + } + tab.clear(); +//---------------------------------------------------------------------------- if (m_debug) { std::cout << "All these tables have been successfully created:" << std::endl; // debug @@ -1698,7 +2462,7 @@ bool GMDBManager::createTables() { return false; } -int GMDBManager::execQuery(std::string queryStr) { +int GMDBManager::execQuery(const std::string& queryStr) { if (m_debug) std::cout << "queryStr to execute: " << queryStr << std::endl; // debug checkIsDBOpen(); @@ -1729,7 +2493,13 @@ std::vector<std::string> GMDBManager::getTableColumnNames( return m_tableNames.at(tableName); } -void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) { +bool GMDBManager::hasTableBeenCreatedInDB(const std::string_view tableName) { + if (m_tableNames.count(std::string(tableName)) == 0) return false; + return true; +} + + +void GMDBManager::storeNodeType(const std::string& nodeType, const std::string& tableName) { checkIsDBOpen(); std::string queryStr; sqlite3_stmt* st = nullptr; @@ -1739,9 +2509,7 @@ void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) { "INSERT INTO GeoNodesTypes(nodeType, tableName) VALUES(?, ?)"; rc = sqlite3_prepare_v2(m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } if (m_debug) std::cout << "storeNodeType - Query string:" << sql @@ -1754,15 +2522,17 @@ void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) { // execute the query rc = sqlite3_step(st); if (rc != SQLITE_DONE) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } // finalize sqlite3_finalize(st); return; } + + + + // TODO: move to sqlite3 library // void GMDBManager::loadTestData() //{ @@ -1796,8 +2566,8 @@ void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) { // QVariant childPhysId = addPhysVol(toyLogId, rootPhysId); //} -bool GMDBManager::storeRootVolume(const unsigned int& id, - const std::string& nodeType) { +bool GMDBManager::storeRootVolume(const unsigned &id, + const std::string_view nodeType) { checkIsDBOpen(); std::string tableName = "RootVolume"; @@ -1813,11 +2583,7 @@ bool GMDBManager::storeRootVolume(const unsigned int& id, int rc = -1; rc = sqlite3_prepare_v2(m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf( - "[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); // TODO: add __func__ to all - // error messages, as I did here - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } if (m_debug) std::cout << "Query string:" << sql << std::endl; // debug // bind the parameters @@ -1826,9 +2592,7 @@ bool GMDBManager::storeRootVolume(const unsigned int& id, // execute the query rc = sqlite3_step(st); if (rc != SQLITE_DONE) { - printf("[SQLite ERR] (%s) : Error msg: %s\n", __func__, - sqlite3_errmsg(m_d->m_dbSqlite)); - exit(EXIT_FAILURE); + THROW_EXCEPTION("[SQLite ERR] (" << __func__ << ") : Error msg: " << sqlite3_errmsg(m_d->m_dbSqlite)); } // finalize sqlite3_finalize(st); @@ -1839,8 +2603,9 @@ bool GMDBManager::storeRootVolume(const unsigned int& id, return true; } -std::vector<std::string> GMDBManager::getRootPhysVol() { - // get the ID of the ROOT vol from the table "RootVolume" +// std::vector<std::string> GMDBManager::getRootPhysVol() { +std::pair<unsigned, unsigned> GMDBManager::getRootPhysVol() { + // get the type and ID of the ROOT vol from the table "RootVolume" sqlite3_stmt* stmt = m_d->selectAllFromTable("RootVolume"); // declare the data we want to fetch unsigned int id = 0; @@ -1848,7 +2613,9 @@ std::vector<std::string> GMDBManager::getRootPhysVol() { // execute the statement on all rows int rc = -1; while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - // get the data + // get the data; + // we skip the SQLite record ID stored in column 0, + // because we only have one Root volume id = sqlite3_column_int(stmt, 1); typeId = sqlite3_column_int(stmt, 2); // TODO: fill a cache @@ -1856,20 +2623,20 @@ std::vector<std::string> GMDBManager::getRootPhysVol() { if (rc != SQLITE_DONE) { std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); - throw errmsg; + THROW_EXCEPTION(errmsg); } // finalize sqlite3_finalize(stmt); - std::vector<std::string> results = getItemAndType(typeId, id); - return results; + // std::vector<std::string> results = getItemAndType(typeId, id); + return std::pair<unsigned, unsigned>{typeId, id}; } std::string GMDBManager::getDBFilePath() { return m_dbpath; } // FIXME: TODO: move to an utility class -int lastIndexOf(std::vector<std::string> v, std::string str, int pos = 0) { +int lastIndexOf(std::vector<std::string> v, const std::string& str, int pos = 0) { auto it = std::find(std::next(v.rbegin(), v.size() - pos), v.rend(), str); if (it != v.rend()) { auto idx = std::distance(v.begin(), it.base() - 1); diff --git a/GeoModelIO/GeoModelErrorHandler/CMakeLists.txt b/GeoModelIO/GeoModelErrorHandler/CMakeLists.txt index 59b93fabb7b58fed2fcffd6fde97ad0f2138f953..55b7f30dce7058ddf242a2342462551dc8bb5217 100644 --- a/GeoModelIO/GeoModelErrorHandler/CMakeLists.txt +++ b/GeoModelIO/GeoModelErrorHandler/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Set up how CMake should handle file names given to target_sources(). if( POLICY CMP0076 ) @@ -13,7 +13,7 @@ add_library( GeoModelErrorHandler INTERFACE ) source_group( "GeoModelErrorHandler" FILES ${HEADERS} ) target_include_directories( GeoModelErrorHandler INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) target_link_libraries( GeoModelErrorHandler INTERFACE Qt5::Core ) if( "${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" ) diff --git a/GeoModelIO/GeoModelIOHelpers/CMakeLists.txt b/GeoModelIO/GeoModelIOHelpers/CMakeLists.txt index ca1bb3fcdabfa7b74c5501ed49682d2a25e8f24d..48dbc3ba4679c4148d7267e24c72f0f5ba160975 100644 --- a/GeoModelIO/GeoModelIOHelpers/CMakeLists.txt +++ b/GeoModelIO/GeoModelIOHelpers/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: GeoModelIOHelpers # author: Riccardo Maria BIANCHI <rbianchi@cern.ch> - 2023 Jan @@ -16,7 +16,7 @@ target_link_libraries( GeoModelIOHelpers PUBLIC # even if the latter is headers only target_include_directories( GeoModelIOHelpers PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelIOHelpers" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelIOHelpers PROPERTIES @@ -46,3 +46,16 @@ install(TARGETS GeoModelIOHelpers install( FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelIOHelpers COMPONENT Development ) + + +# global I/O tests +add_executable(test_io_shared_serialtransformers tests/test_io_shared_serialtransformers.cpp) +target_link_libraries( test_io_shared_serialtransformers GeoModelIO::GeoModelDBManager GeoModelCore::GeoModelHelpers GeoModelCore::GeoModelKernel GeoModelIO::GeoModelIOHelpers) +add_test(NAME test_IO_SharedSerialTransformers + COMMAND test_io_shared_serialtransformers) + +# I/O Unit tests +add_executable(test_io_shapes_unidentifiedshape tests/test_io_UnidentifiedShape.cpp) +target_link_libraries( test_io_shapes_unidentifiedshape GeoModelIO::GeoModelDBManager GeoModelCore::GeoModelHelpers GeoModelCore::GeoModelKernel GeoModelIO::GeoModelIOHelpers) +add_test(NAME test_IO_Shapes_UnidentifiedShape + COMMAND test_io_shapes_unidentifiedshape) diff --git a/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMIO.h b/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMIO.h index 0e4b211b5bd7cdbbd62c033f1f18beb92a637e8b..df56bc2bcb2bd775b030a4fc90c7a6118caf54ef 100644 --- a/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMIO.h +++ b/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMIO.h @@ -22,6 +22,8 @@ #include "GeoModelRead/ReadGeoModel.h" #include "GeoModelWrite/WriteGeoModel.h" +#include "GeoModelKernel/throwExcept.h" + namespace GeoModelIO { class IO { @@ -59,7 +61,7 @@ class IO { // check the DB connection if (!db.checkIsDBOpen()) { std::cout << "Database ERROR!! Exiting..." << std::endl; - exit(EXIT_FAILURE); + THROW_EXCEPTION("It was not possible to open the DB correctly!"); } // Dump the tree volumes to a local file @@ -98,7 +100,7 @@ class IO { GMDBManager* db = new GMDBManager(path); if (!db->checkIsDBOpen()) { std::cout << "ERROR!! -- Database is not open!\n"; - throw; + THROW_EXCEPTION("It was not possible to open the DB correctly!"); } /* setup the GeoModel reader */ @@ -135,7 +137,7 @@ class IO { GMDBManager* db = new GMDBManager(path); if (!db->checkIsDBOpen()) { std::cout << "ERROR!! -- Database is not open!\n"; - throw; + THROW_EXCEPTION("It was not possible to open the DB correctly!"); } /* setup the GeoModel reader */ @@ -153,24 +155,72 @@ class IO { // map to populate and return std::map<std::string, unsigned long> mmap; // get the number of all nodes in the DB from the DB manager - unsigned long nphysvols = db.getTableFromNodeType("GeoPhysVol").size(); - unsigned long nfullphysvols = - db.getTableFromNodeType("GeoFullPhysVol").size(); - unsigned long nlogvols = db.getTableFromNodeType("GeoLogVol").size(); - unsigned long nelements = db.getTableFromNodeType("GeoElement").size(); - unsigned long nmaterials = - db.getTableFromNodeType("GeoMaterial").size(); - unsigned long nalignables = - db.getTableFromNodeType("GeoAlignableTransform").size(); - unsigned long nfunctions = db.getTableFromNodeType("Function").size(); - unsigned long nserialtransformers = - db.getTableFromNodeType("GeoSerialTransformer").size(); - unsigned long nshapes = db.getTableFromNodeType("GeoShape").size(); - unsigned long nserialdenominators = - db.getTableFromNodeType("GeoSerialDenominator").size(); + unsigned long nphysvols = db.getTableFromNodeType_String("GeoPhysVol").size(); + unsigned long nfullphysvols = db.getTableFromNodeType_String("GeoFullPhysVol").size(); + unsigned long nlogvols = db.getTableFromNodeType_VecVecData("GeoLogVol").size(); + unsigned long nelements = db.getTableFromNodeType_VecVecData("GeoElement").size(); + unsigned long nmaterials = db.getTableFromNodeType_VecVecData("GeoMaterial").size(); + unsigned long nalignables = db.getTableFromNodeType_String("GeoAlignableTransform").size(); + unsigned long nfunctions = db.getTableFromNodeType_VecVecData("Function").size(); + unsigned long nserialtransformers = db.getTableFromNodeType_String("GeoSerialTransformer").size(); + unsigned long nserialdenominators = db.getTableFromNodeType_String("GeoSerialDenominator").size(); + unsigned long ntransforms = db.getTableFromNodeType_VecVecData("GeoTransform").size(); + unsigned long nserialidentifiers = db.getTableFromNodeType_VecVecData("GeoSerialIdentifier").size(); + unsigned long nidentifiertags = db.getTableFromNodeType_VecVecData("GeoIdentifierTag").size(); + unsigned long nnametags = db.getTableFromNodeType_VecVecData("GeoNameTag").size(); + // get shapes + unsigned long nshapes = db.getTableFromNodeType_String("GoShape").size(); // TODO: to be removed later + unsigned long nshapes_box = db.getTableFromNodeType_VecVecData("GeoBox").size(); + unsigned long nshapes_cons = db.getTableFromNodeType_VecVecData("GeoCons").size(); + unsigned long nshapes_para = db.getTableFromNodeType_VecVecData("GeoPara").size(); + unsigned long nshapes_pcon = db.getTableFromNodeType_VecVecData("GeoPcon").size(); + unsigned long nshapes_pgon = db.getTableFromNodeType_VecVecData("GeoPgon").size(); + unsigned long nshapes_simplepol = db.getTableFromNodeType_VecVecData("GeoSimplePolygonBrep").size(); + unsigned long nshapes_trap = db.getTableFromNodeType_VecVecData("GeoTrap").size(); + unsigned long nshapes_trd = db.getTableFromNodeType_VecVecData("GeoTrd").size(); + unsigned long nshapes_tube = db.getTableFromNodeType_VecVecData("GeoTube").size(); + unsigned long nshapes_tubs = db.getTableFromNodeType_VecVecData("GeoTubs").size(); + unsigned long nshapes_twisted = db.getTableFromNodeType_VecVecData("GeoTwistedTrap").size(); + unsigned long nshapes_unid = db.getTableFromNodeType_VecVecData("GeoUnidentifiedShape").size(); + unsigned long nshapes_shift = db.getTableFromNodeType_VecVecData("GeoShapeShift").size(); + unsigned long nshapes_union = db.getTableFromNodeType_VecVecData("GeoShapeUnion").size(); + unsigned long nshapes_intersection = db.getTableFromNodeType_VecVecData("GeoShapeIntersection").size(); + unsigned long nshapes_subtraction = db.getTableFromNodeType_VecVecData("GeoShapeSubtraction").size(); // get metadata unsigned long nchildrenconnections = db.getChildrenTable().size(); + mmap["PhysVol"] = nphysvols; + mmap["FullPhysVol"] = nfullphysvols; + mmap["LogVol"] = nlogvols; + mmap["Element"] = nelements; + mmap["Material"] = nmaterials; + mmap["Alignable"] = nalignables; + mmap["Function"] = nfunctions; + mmap["SerialTransformer"] = nserialtransformers; + mmap["SerialDenominator"] = nserialdenominators; + mmap["ChildrenConnections"] = nchildrenconnections; + mmap["Transform"] = ntransforms; + mmap["SerialIdentifier"] = nserialidentifiers; + mmap["IdentifierTag"] = nidentifiertags; + mmap["NameTag"] = nnametags; + mmap["Shape"] = nshapes; + mmap["Shape_Box"] = nshapes_box; + mmap["Shape_Cons"] = nshapes_cons; + mmap["Shape_Para"] = nshapes_para; + mmap["Shape_Pcon"] = nshapes_pcon; + mmap["Shape_Pgon"] = nshapes_pgon; + mmap["Shape_SimplePolygonBrep"] = nshapes_simplepol; + mmap["Shape_Trap"] = nshapes_trap; + mmap["Shape_Trd"] = nshapes_trd; + mmap["Shape_Tube"] = nshapes_tube; + mmap["Shape_Tubs"] = nshapes_tubs; + mmap["Shape_TwistedTrap"] = nshapes_twisted; + mmap["Shape_UnidentifiedShape"] = nshapes_unid; + mmap["Shape_Shift"] = nshapes_shift; + mmap["Shape_Union"] = nshapes_union; + mmap["Shape_Intersection"] = nshapes_intersection; + mmap["Shape_Subtraction"] = nshapes_subtraction; + return mmap; } @@ -184,7 +234,7 @@ class IO { if (loglevel > 0) { dump.setLogLevel(loglevel); } - world->exec(&dump); // visit all GeoModel nodes + world->exec(&dump); // visit all GeoModel nodes of the 'world' volume unsigned long nphysvols = dump.getNPhysVols(); unsigned long nfullphysvols = dump.getNFullPhysVols(); @@ -194,7 +244,6 @@ class IO { unsigned long nalignables = dump.getNAlignableTransforms(); unsigned long nfunctions = dump.getNFunctions(); unsigned long nserialtransformers = dump.getNSerialTransformers(); - unsigned long nshapes = dump.getNShapes(); unsigned long nserialdenominators = dump.getNSerialDenominators(); unsigned long nchildrenconnections = dump.getNChildrenConnections(); // unsigned nrootvolume = dump.getNRootVolume(); @@ -202,6 +251,24 @@ class IO { unsigned long nserialidentifiers = dump.getNSerialIdentifiers(); unsigned long nidentifiertags = dump.getNIdentifierTags(); unsigned long nnametags = dump.getNNameTags(); + // get shapes + unsigned long nshapes = dump.getNShapes(); // TODO: to be removed later + unsigned long nshapes_box = dump.getNShapes_Box(); + unsigned long nshapes_cons = dump.getNShapes_Cons(); + unsigned long nshapes_para = dump.getNShapes_Para(); + unsigned long nshapes_pcon = dump.getNShapes_Pcon(); + unsigned long nshapes_pgon = dump.getNShapes_Pgon(); + unsigned long nshapes_simplepol = dump.getNShapes_SimplePolygonBrep(); + unsigned long nshapes_trap = dump.getNShapes_Trap(); + unsigned long nshapes_trd = dump.getNShapes_Trd(); + unsigned long nshapes_tube = dump.getNShapes_Tube(); + unsigned long nshapes_tubs = dump.getNShapes_Tubs(); + unsigned long nshapes_twisted = dump.getNShapes_TwistedTrap(); + unsigned long nshapes_unid = dump.getNShapes_UnidentifiedShape(); + unsigned long nshapes_shift = dump.getNShapes_Shift(); + unsigned long nshapes_union = dump.getNShapes_Union(); + unsigned long nshapes_intersection = dump.getNShapes_Intersection(); + unsigned long nshapes_subtraction = dump.getNShapes_Subtraction(); mmap["PhysVol"] = nphysvols; mmap["FullPhysVol"] = nfullphysvols; @@ -218,6 +285,23 @@ class IO { mmap["SerialIdentifier"] = nserialidentifiers; mmap["IdentifierTag"] = nidentifiertags; mmap["NameTag"] = nnametags; + mmap["Shape"] = nshapes; + mmap["Shape_Box"] = nshapes_box; + mmap["Shape_Cons"] = nshapes_cons; + mmap["Shape_Para"] = nshapes_para; + mmap["Shape_Pcon"] = nshapes_pcon; + mmap["Shape_Pgon"] = nshapes_pgon; + mmap["Shape_SimplePolygonBrep"] = nshapes_simplepol; + mmap["Shape_Trap"] = nshapes_trap; + mmap["Shape_Trd"] = nshapes_trd; + mmap["Shape_Tube"] = nshapes_tube; + mmap["Shape_Tubs"] = nshapes_tubs; + mmap["Shape_TwistedTrap"] = nshapes_twisted; + mmap["Shape_UnidentifiedShape"] = nshapes_unid; + mmap["Shape_Shift"] = nshapes_shift; + mmap["Shape_Union"] = nshapes_union; + mmap["Shape_Intersection"] = nshapes_intersection; + mmap["Shape_Subtraction"] = nshapes_subtraction; return mmap; } @@ -233,7 +317,6 @@ class IO { unsigned long nalignables = read.getNAlignableTransforms(); unsigned long nfunctions = read.getNFunctions(); unsigned long nserialtransformers = read.getNSerialTransformers(); - unsigned long nshapes = read.getNShapes(); unsigned long nserialdenominators = read.getNSerialDenominators(); unsigned long nchildrenconnections = read.getNChildrenConnections(); // unsigned nrootvolume = read.getNRootVolume(); @@ -241,6 +324,24 @@ class IO { unsigned long nserialidentifiers = read.getNSerialIdentifiers(); unsigned long nidentifiertags = read.getNIdentifierTags(); unsigned long nnametags = read.getNNameTags(); + // get shapes + unsigned long nshapes = read.getNShapes(); // TODO: to be removed later + unsigned long nshapes_box = read.getNShapes_Box(); + unsigned long nshapes_cons = read.getNShapes_Cons(); + unsigned long nshapes_para = read.getNShapes_Para(); + unsigned long nshapes_pcon = read.getNShapes_Pcon(); + unsigned long nshapes_pgon = read.getNShapes_Pgon(); + unsigned long nshapes_simplepol = read.getNShapes_SimplePolygonBrep(); + unsigned long nshapes_trap = read.getNShapes_Trap(); + unsigned long nshapes_trd = read.getNShapes_Trd(); + unsigned long nshapes_tube = read.getNShapes_Tube(); + unsigned long nshapes_tubs = read.getNShapes_Tubs(); + unsigned long nshapes_twisted = read.getNShapes_TwistedTrap(); + unsigned long nshapes_unid = read.getNShapes_UnidentifiedShape(); + unsigned long nshapes_shift = read.getNShapes_Shift(); + unsigned long nshapes_union = read.getNShapes_Union(); + unsigned long nshapes_intersection = read.getNShapes_Intersection(); + unsigned long nshapes_subtraction = read.getNShapes_Subtraction(); mmap["PhysVol"] = nphysvols; mmap["FullPhysVol"] = nfullphysvols; @@ -257,6 +358,23 @@ class IO { mmap["SerialIdentifier"] = nserialidentifiers; mmap["IdentifierTag"] = nidentifiertags; mmap["NameTag"] = nnametags; + mmap["Shape"] = nshapes; + mmap["Shape_Box"] = nshapes_box; + mmap["Shape_Cons"] = nshapes_cons; + mmap["Shape_Para"] = nshapes_para; + mmap["Shape_Pcon"] = nshapes_pcon; + mmap["Shape_Pgon"] = nshapes_pgon; + mmap["Shape_SimplePolygonBrep"] = nshapes_simplepol; + mmap["Shape_Trap"] = nshapes_trap; + mmap["Shape_Trd"] = nshapes_trd; + mmap["Shape_Tube"] = nshapes_tube; + mmap["Shape_Tubs"] = nshapes_tubs; + mmap["Shape_TwistedTrap"] = nshapes_twisted; + mmap["Shape_UnidentifiedShape"] = nshapes_unid; + mmap["Shape_Shift"] = nshapes_shift; + mmap["Shape_Union"] = nshapes_union; + mmap["Shape_Intersection"] = nshapes_intersection; + mmap["Shape_Subtraction"] = nshapes_subtraction; return mmap; } @@ -274,7 +392,8 @@ class IO { << m2[key] << std::endl; } - static std::vector<std::string> getMapKeys() { + static std::vector<std::string> getMapKeys() + { std::vector<std::string> keys{"PhysVol", "FullPhysVol", "LogVol", @@ -283,13 +402,29 @@ class IO { "Alignable", "Function", "SerialTransformer", - "Shape", "Transform", "SerialIdentifier", "IdentifierTag", "NameTag" "SerialDenominator", - "ChildrenConnections"}; + "ChildrenConnections", + "Shape", + "Shape_Box", + "Shape_Cons", + "Shape_Para", + "Shape_Pcon", + "Shape_Pgon", + "Shape_SimplePolygonBrep", + "Shape_Trap", + "Shape_Trd", + "Shape_Tube", + "Shape_Tubs", + "Shape_TwistedTrap", + "Shape_UnidentifiedShape", + "Shape_Shift", + "Shape_Union", + "Shape_Intersection", + "Shape_Subtraction"}; return keys; } static void printCompareTwoNodesMaps( @@ -301,6 +436,22 @@ class IO { } } + static void printDifferencesBetweenTwoNodesMaps( + std::map<std::string, unsigned long> m1, + std::map<std::string, unsigned long> m2) + { + for (const auto &entry : m1) + { + const std::string key = entry.first; + const unsigned i1 = m1[key]; + const unsigned i2 = m2[key]; + if (i1 != i2) + { + std::cout << "ERROR! ==> the number of '" << key << "' are different! " << i1 << " <-> " << i2 << std::endl; + } + } + } + static std::map<std::string, unsigned long> initNodesMap() { std::map<std::string, unsigned long> nmap; std::vector<std::string> keys = getMapKeys(); @@ -310,6 +461,16 @@ class IO { } return nmap; } + + static void checkTwoNodesMapsSameSize( + std::map<std::string, unsigned long> m1, + std::map<std::string, unsigned long> m2) + { + if (m1.size() != m2.size()) + { + THROW_EXCEPTION("ERROR! Maps are not of the same size!"); + } + } }; } // namespace GeoModelIO diff --git a/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMTests_IO.h b/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMTests_IO.h index a6f3f0e901fd931b591b4447ec63f7c56ee10feb..03ffab3b5c21e2ddb15cb898911d3797928d6e78 100644 --- a/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMTests_IO.h +++ b/GeoModelIO/GeoModelIOHelpers/GeoModelIOHelpers/GMTests_IO.h @@ -41,39 +41,26 @@ class TestIO { const std::string db1_name = "geometry_db_test_1.db"; const std::string db2_name = "geometry_db_test_2.db"; - //-----------------------------------------------// - // 1 -- Writing the geometry to file - 1st time - //-----------------------------------------------// + std:: cout << "1 -- Writing the geometry to file - 1st time" << std::endl; GMDBManager db1 = GeoModelIO::IO::saveToDB(world, db1_name, loglevel, forceDelete); - //-----------------------------------------------// - // 2 -- Get number of nodes from the DB we just saved - //-----------------------------------------------// + std::cout << "2 -- Get number of nodes from the DB we just saved" << std::endl; std::map<std::string, unsigned long> mmap_1 = GeoModelIO::IO::countNodesFromDB(db1); - //-----------------------------------------------// - // 3 -- Reading back the geometry from file - //-----------------------------------------------// + std::cout << "3 -- Reading back the geometry from file" << std::endl; const GeoVPhysVol* world2 = GeoModelIO::IO::loadDB(db1_name, loglevel); - //-----------------------------------------------// - // 4 -- Writing the geometry to file - 2nd time - //-----------------------------------------------// + std::cout << "4 -- Writing the geometry to file - 2nd time" << std::endl; GMDBManager db2 = GeoModelIO::IO::saveToDB(world2, db2_name, loglevel, forceDelete); - //-----------------------------------------------// - // 5 -- Get number of nodes from the DB we created from the restored - // GeoModel tree - //-----------------------------------------------// + std::cout << "5 -- Get number of nodes from the DB we created from the restored GeoModel tree" << std::endl; std::map<std::string, unsigned long> mmap_2 = GeoModelIO::IO::countNodesFromDB(db2); - //-----------------------------------------------// - // 6 -- Comparison - //-----------------------------------------------// - + std::cout << "6 -- Comparison" << std::endl; bool testok = false; + GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_1, mmap_2); if (mmap_1 == mmap_2) { if (loglevel >= 1) { std::cout @@ -94,6 +81,7 @@ class TestIO { if (loglevel >= 2) { GeoModelIO::IO::printCompareTwoNodesMaps(mmap_1, mmap_2); } + GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_1, mmap_2); std::cout << "----\n"; } testok = false; @@ -140,6 +128,7 @@ class TestIO { // TODO: add number-by-number comparison as with the other tests!! bool testok = false; + GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_1, mmap_2); if (mmap_1 == mmap_2) { if (loglevel >= 1) { std::cout << "OK! The number of starting in-memory nodes is " @@ -151,15 +140,16 @@ class TestIO { } else { if (loglevel >= 1) { std::cout - << "!!! ERROR !!! The number of teh starting in-memory " + << "!!! ERROR !!! The number of the starting in-memory " "nodes is DIFFERENT from " "the number of the restored in-memory nodes!!!\n"; if (loglevel >= 2) { - std::cout << "Starting in-memory nodes:\n"; + std::cout << "*** Starting in-memory nodes:\n"; GeoModelIO::IO::printNodesMap(mmap_1); - std::cout << "Restored in-memory nodes:\n"; + std::cout << "*** Restored in-memory nodes:\n"; GeoModelIO::IO::printNodesMap(mmap_2); } + GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_1, mmap_2); std::cout << "----\n"; } testok = false; @@ -196,6 +186,7 @@ class TestIO { read.setLogLevel(loglevel); } // load the data from the DB + std::cout << "-- 1: load data from the DB" << std::endl; read.loadDB(); // count all nodes loaded from the DB by the Read action @@ -205,14 +196,16 @@ class TestIO { GeoModelIO::IO::countLoadedNodesFromReadAction(read); // build the GeoModel tree from the loaded nodes + std::cout << "-- 2: build the GeoModel tree and restore it into memory" << std::endl; const GeoVPhysVol* rootVolume = read.buildGeoModel(); - // count the number of all the restored nodes; + // count the number of all restored nodes; // i.e., the nodes of the restored in-memory GeoModel tree std::map<std::string, unsigned long> mmap_restored = GeoModelIO::IO::countTreeMemoryNodesFromVolume(rootVolume); bool testok = false; + GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_loaded, mmap_restored); if (mmap_loaded == mmap_restored) { if (loglevel >= 1) { std::cout << "OK! The number of loaded nodes is equal to the " @@ -225,11 +218,13 @@ class TestIO { "DIFFERENT from " "the number of restored nodes!!!\n"; if (loglevel >= 2) { - std::cout << "Loaded:\n"; + std::cout << "\n*** -- Loaded:\n"; GeoModelIO::IO::printNodesMap(mmap_loaded); - std::cout << "Restored:\n"; + std::cout << "\n*** -- Restored:\n"; GeoModelIO::IO::printNodesMap(mmap_restored); } + GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_loaded, mmap_restored); + std::cout << "----\n"; } testok = false; } @@ -275,7 +270,8 @@ class TestIO { std::cout << "Single results: \n"; for (auto& tt : tests.second) { std::cout << "test: '" << tt.first << "' ==> " << tt.second - << " [" << (testall ? "PASSED." : "FAILED!") << "]" + << " [" << (tt.second ? "PASSED." : "FAILED!") << "]" + << " -- [overall: " << (testall ? "PASSED." : "FAILED!") << "]" << std::endl; } } diff --git a/GeoModelIO/GeoModelIOHelpers/tests/test_io_UnidentifiedShape.cpp b/GeoModelIO/GeoModelIOHelpers/tests/test_io_UnidentifiedShape.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5b0ba8f3c5cd6c0fb69555fa32d621931374a90 --- /dev/null +++ b/GeoModelIO/GeoModelIOHelpers/tests/test_io_UnidentifiedShape.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +/* + * This example tests the I/O of GeoUnidentifiedShape. + * + * Author: Riccardo Maria BIANCHI @ CERN + * Created on: July, 2024 + */ + +// GeoModel includes +#include "GeoModelIOHelpers/GMTests_IO.h" +#include "GeoModelKernel/GeoUnidentifiedShape.h" +#include "GeoModelHelpers/defineWorld.h" + +// C++ includes +#include <iostream> + +// Units +#include "GeoModelKernel/Units.h" +#define SYSTEM_OF_UNITS \ + GeoModelKernelUnits // so we will get, e.g., 'GeoModelKernelUnits::cm' + +int main(int argc, char *argv[]) +{ +// Define the units +#define gr SYSTEM_OF_UNITS::gram +#define mole SYSTEM_OF_UNITS::mole + + // get the World volume, + // we build it outside the class for convenience only + GeoIntrusivePtr<GeoPhysVol> world{createGeoWorld()}; + + // Define elements used in this example: + GeoElement *elAluminum = new GeoElement("Aluminum", "Al", 13, 26 * gr / mole); + + // Define materials used in this example: + double densityOfAluminum = 2.7; // g/cm^3 + GeoMaterial *matAluminum = new GeoMaterial("Aluminum", densityOfAluminum); + matAluminum->add(elAluminum, 1.0); + matAluminum->lock(); + + // Add a test "UnidentifiedShape" shape node + const std::string shapeDataAscii = "LAr::Example"; + const std::string shapeDataName = "LArCustomShape"; + GeoUnidentifiedShape *sUnidentifiedShape = new GeoUnidentifiedShape(shapeDataName, shapeDataAscii); + const GeoLogVol *lUnidentifiedShape = new GeoLogVol("UnidentifiedShape", sUnidentifiedShape, matAluminum); + GeoPhysVol *pUnidentifiedShape = new GeoPhysVol(lUnidentifiedShape); + GeoNameTag *nUnidentifiedShape = new GeoNameTag("UnidentifiedShape"); + world->add(nUnidentifiedShape); + world->add(pUnidentifiedShape); + + // write to the test DB + std::string testDB = "test_io_unidentifiedshape.db"; + unsigned loglevel = 2; + const bool forceDelete = true; + GeoModelIO::IO::saveToDB(world, testDB, loglevel, forceDelete); + + // load from the test DB + const GeoVPhysVol *world2 = GeoModelIO::IO::loadDB(testDB); + + // get the child volume, then the shape from its logVol + GeoIntrusivePtr<const GeoVPhysVol> childVol = world2->getChildVol(0); + const GeoUnidentifiedShape *shape = dynamic_cast<const GeoUnidentifiedShape *>(childVol->getLogVol()->getShape()); + const std::string restoredShapeDataAscii = shape->asciiData(); + const std::string restoredShapeDataName = shape->name(); + + bool test = true; + if (restoredShapeDataAscii != shapeDataAscii) + { + std::cout << "\nERROR!!! The restored 'AsciiData' is different from the stored version!!!" << std::endl; + std::cout << "Stored 'AsciiData': " << shapeDataAscii << std::endl; + std::cout << "Restored 'AsciiData': " << restoredShapeDataAscii << std::endl; + test = false; + } + if (restoredShapeDataName != shapeDataName) + { + std::cout << "\nERROR!!! The restored 'name' is different from the stored version!!!" << std::endl; + std::cout << "\t==> Stored 'name': " << shapeDataName << std::endl; + std::cout << "\t==> Restored 'name': " << restoredShapeDataName << std::endl; + test = false; + } + + // Return 0 if all OK! :-) + // Return 1 otherwise... :-( + if (test) + return 0; + return 1; + // ---------------- +} diff --git a/GeoModelIO/GeoModelIOHelpers/tests/test_io_shared_serialtransformers.cpp b/GeoModelIO/GeoModelIOHelpers/tests/test_io_shared_serialtransformers.cpp new file mode 100644 index 0000000000000000000000000000000000000000..33968c5428d2a282a269e70cce793cbf63e01bef --- /dev/null +++ b/GeoModelIO/GeoModelIOHelpers/tests/test_io_shared_serialtransformers.cpp @@ -0,0 +1,167 @@ +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +/* + * This example tests shared GeoSerialTransformer and Function nodes. + * + * It creates one single LogVol, with one Material and one Shape. + * Then it creates one single PhysVol volumes using the above LogVol. + * Then it creates two SerialTrasnformers with two different placing formulas, + * but which share the same PhysVol defined above. + * + * It is meant to how how to share GeoModel nodes to reduce the memory footprint + * and to test the GeoModel I/O packages and methods. + * + * Author: Riccardo Maria BIANCHI @ CERN + * Created on: Apr, 2024 + * + */ + +// GeoModel includes +#include "GeoGenericFunctions/AbsFunction.h" +#include "GeoGenericFunctions/Cos.h" +#include "GeoGenericFunctions/Sin.h" +#include "GeoGenericFunctions/Variable.h" +#include "GeoModelDBManager/GMDBManager.h" +#include "GeoModelIOHelpers/GMIO.h" +#include "GeoModelIOHelpers/GMTests_IO.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoSerialDenominator.h" +#include "GeoModelKernel/GeoSerialTransformer.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelHelpers/defineWorld.h" + +// C++ includes +#include <cstdlib> // EXIT_FAILURE +#include <fstream> +#include <iostream> + +// Units +#include "GeoModelKernel/Units.h" +#define SYSTEM_OF_UNITS \ + GeoModelKernelUnits // so we will get, e.g., 'GeoModelKernelUnits::cm' + +using namespace GeoGenfun; +using namespace GeoXF; + +int main(int argc, char *argv[]) { +// Define the units +#define gr SYSTEM_OF_UNITS::gram +#define mole SYSTEM_OF_UNITS::mole +#define cm3 SYSTEM_OF_UNITS::cm3 +#define degree SYSTEM_OF_UNITS::degree + + // get the World volume, + // we build it outside the class for convenience only + GeoIntrusivePtr<GeoPhysVol> world{createGeoWorld()}; + + // Define elements used in this example: + GeoElement *aluminum = new GeoElement("Aluminum", "Al", 13, 26 * gr / mole); + GeoElement *iron = new GeoElement("Iron", "Fe", 26.0, 55.847 * gr / mole); + + // Define materials: + double densityOfAluminum = 2.7; // g/cm^3 + double densityOfIron = 7.87; // g/cm^3 + GeoMaterial *Aluminum = new GeoMaterial("Aluminum", densityOfAluminum); + Aluminum->add(aluminum, 1.0); + Aluminum->lock(); + GeoMaterial *Iron = new GeoMaterial("Iron", densityOfIron); + Iron->add(iron, 1.0); + Iron->lock(); + + // define a container box + const GeoBox *toyBox = + new GeoBox(1200 * SYSTEM_OF_UNITS::cm, 1200 * SYSTEM_OF_UNITS::cm, + 1200 * SYSTEM_OF_UNITS::cm); + const GeoLogVol *toyLog = new GeoLogVol("ToyLog", toyBox, Aluminum); // + GeoPhysVol *toyPhys = new GeoPhysVol(toyLog); + + //--------------------------------------// + // Define some daughters and put them in the toy volume + //--------------------------------------// + const GeoTube *ringTube = + new GeoTube(500 * SYSTEM_OF_UNITS::cm, 1000 * SYSTEM_OF_UNITS::cm, + 5.0 * SYSTEM_OF_UNITS::cm); + const GeoLogVol *ringLog = new GeoLogVol("RingLog", ringTube, Aluminum); + // define a global name for the daughters + GeoSerialDenominator *ringName = new GeoSerialDenominator("RING"); + toyPhys->add(ringName); + // Make 100 of these // + // within the volume of the toy: // + for (int i = 0; i < 100; i++) { + GeoFullPhysVol *ringPhys = new GeoFullPhysVol(ringLog); + GeoAlignableTransform *xform = new GeoAlignableTransform( + GeoTrf::TranslateZ3D((i - 50) * 20 * SYSTEM_OF_UNITS::cm)); + toyPhys->add(xform); + toyPhys->add(ringPhys); + } + + //--------------------------------------// + // Now, in addition to active daughters, + // add some passive material. + // This is done here using + // the "SerialTransformer", + // our way of parameterizing volumes. + // It does not need to be done this way, + // but we want to provide an example of + // parametrizations in the Toy + //--------------------------------------// + + GeoBox *sPass = + new GeoBox(5.0 * SYSTEM_OF_UNITS::cm, 30 * SYSTEM_OF_UNITS::cm, + 30 * SYSTEM_OF_UNITS::cm); + GeoLogVol *lPass = new GeoLogVol("Passive", sPass, Iron); + GeoPhysVol *pPass = new GeoPhysVol(lPass); + + //--------------------------------------// + // Now, define two mathematical functions, + // which are used to parametrically place the volumes + // in space. + //--------------------------------------// + const unsigned int NPLATES = 100; + Variable i; + Sin sin; + GENFUNCTION f = 360 * SYSTEM_OF_UNITS::deg / NPLATES * i; + GENFUNCTION g = sin(4 * f); + GENFUNCTION h = -g; + TRANSFUNCTION t1 = Pow(GeoTrf::RotateZ3D(1.0), f) * + GeoTrf::TranslateX3D(1100 * SYSTEM_OF_UNITS::cm) * + Pow(GeoTrf::TranslateZ3D(800 * SYSTEM_OF_UNITS::cm), g); + TRANSFUNCTION t2 = Pow(GeoTrf::RotateZ3D(1.0), f) * + GeoTrf::TranslateX3D(1100 * SYSTEM_OF_UNITS::cm) * + Pow(GeoTrf::TranslateZ3D(800 * SYSTEM_OF_UNITS::cm), h); + + //--------------------------------------// + // Inside, by the way, the serial transformer + // will evaluate the functions: + // HepTransform3D xf = t1(i), for i=1,NPLATES.... + //--------------------------------------// + + GeoSerialDenominator *pass1Name = new GeoSerialDenominator("PASSIVE-1-"); + GeoSerialTransformer *s1 = new GeoSerialTransformer(pPass, &t1, NPLATES); + toyPhys->add(pass1Name); + toyPhys->add(s1); + + GeoSerialDenominator *pass2Name = new GeoSerialDenominator("PASSIVE-2-"); + GeoSerialTransformer *s2 = new GeoSerialTransformer(pPass, &t2, NPLATES); + toyPhys->add(pass2Name); + toyPhys->add(s2); + + world->add(toyPhys); + + // --- I/O TESTS --- + std::cout << "\nTests:\n"; + unsigned loglevel = 2; + unsigned printtests = 1; + const bool forceDelete = true; + std::pair<bool, std::map<std::string, bool>> tests = + GeoModelIO::TestIO::runAllTests(world, loglevel, printtests, forceDelete); + bool testall = tests.first; + + // Return 0 if all OK! :-) + // Return 1 otherwise... :-( + if (testall) return 0; + return 1; + // ---------------- +} diff --git a/GeoModelIO/GeoModelRead/CMakeLists.txt b/GeoModelIO/GeoModelRead/CMakeLists.txt index 7a12ae38a31eb22d080296e3e4b0df3510730a0a..5ae4e4fb1878a249ab7cf847f74cb456065ccf4a 100644 --- a/GeoModelIO/GeoModelRead/CMakeLists.txt +++ b/GeoModelIO/GeoModelRead/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration ################################################################################ # Package: GeoModelRead # author: Riccardo Maria BIANCHI <rbianchi@cern.ch> - 2017 @@ -12,10 +12,10 @@ file( GLOB HEADERS GeoModelRead/*.h GeoModelRead/*.tpp ) # Set up the library. add_library( GeoModelRead SHARED ${HEADERS} ${SOURCES} ) target_link_libraries( GeoModelRead PUBLIC -GeoModelKernel GeoModelDBManager TFPersistification ) +GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers ) target_include_directories( GeoModelRead PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelRead" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelRead PROPERTIES diff --git a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h index d71a76a74b6b20ff31bfb19e9ec1f25ffc298d83..1651106ab03fbfe62650fa85d6585e066f772c64 100644 --- a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h +++ b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h @@ -26,35 +26,21 @@ * Added method to get records out of custom tables from client code. * - Feb 2023, R.M.Bianchi <riccardo.maria.bianchi@cern.ch> * Added 'setLoglevel' method, to steer output messages + * + * - Jun 2024, R.Xue <r.xue@cern.ch><rux23@pitt.edu> + * Added methods to read in virtual surfaces from .db files + * */ #ifndef GeoModelRead_ReadGeoModel_H_ #define GeoModelRead_ReadGeoModel_H_ -// **************************************************************** -// *** PERSISTIFICATION SETTINGS FOR GeoModel BOOLEAN SHAPES ****** -// **************************************************************** -// Note: -// -- The instructions below are needed -// -- to correctly persistify/restore boolean shapes. -// -- They must be declared before including GeoModelKernel files. -// **************************************************************** -// This variable is used by GeoModel boolean shapes to switch ON -// the persistification mode -#define _GeoShapePersistification_On_ -// fwd declaration of namespace::class we want to use to persistify -// the GeoModel boolean shapes -namespace GeoModelIO { -class ReadGeoModel; -} -// the 'Persistifier' class name is used by GeoModel boolean shapes -// to grant access to friend classes -typedef GeoModelIO::ReadGeoModel Persistifier; -// **************************************************************** -// **************************************************************** - -// local includes + +// GeoModel includes +#include "GeoModelKernel/PersistifierFwd.h" #include "GeoModelDBManager/GMDBManager.h" +#include "GeoModelDBManager/definitions.h" + #include "GeoModelKernel/GeoXF.h" // C++ includes @@ -71,6 +57,12 @@ typedef GeoModelIO::ReadGeoModel Persistifier; class GeoVPhysVol; class GeoPhysVol; class GeoFullPhysVol; +class GeoRectSurface; +class GeoTrapezoidSurface; +class GeoAnnulusSurface; +class GeoDiamondSurface; +class GeoVSurface; +class GeoVSurfaceShape; class GeoLogVol; class GeoShape; class GeoMaterial; @@ -86,13 +78,35 @@ class GeoGraphNode; class GeoShapeSubtraction; class GeoBox; +class BuildGeoShapes_Box; +class BuildGeoShapes_Tube; +class BuildGeoShapes_Cons; +class BuildGeoShapes_Para; +class BuildGeoShapes_Trap; +class BuildGeoShapes_Trd; +class BuildGeoShapes_Tubs; +class BuildGeoShapes_Torus; +class BuildGeoShapes_TwistedTrap; +class BuildGeoShapes_Pcon; +class BuildGeoShapes_Pgon; +class BuildGeoShapes_SimplePolygonBrep; +class BuildGeoShapes_GenericTrap; +class BuildGeoShapes_UnidentifiedShape; +class BuildGeoVSurface; // type definitions typedef const GeoXF::Function& TRANSFUNCTION; // containers for boolean shapes' information typedef std::tuple<unsigned int /*shape ID*/, GeoShape*, unsigned int /*opA ID*/, unsigned int /*opB ID*/> tuple_shapes_boolean_info; +typedef std::tuple<std::string /*shape Type*/, unsigned /*shape ID*/, GeoShape*, + std::string /*opA type*/, unsigned /*opA ID*/, std::string /*opB type*/, unsigned /*opB ID*/> + tuple_boolean_shapes_operands; + typedef std::vector<tuple_shapes_boolean_info> type_shapes_boolean_info; +typedef std::vector<tuple_boolean_shapes_operands> boolean_shapes_operands_info; + + namespace GeoModelIO { @@ -148,15 +162,50 @@ class ReadGeoModel { }; unsigned long getNFunctions() { return m_functions.size(); }; unsigned long getNNameTags() { return m_nameTags.size(); }; - unsigned long getNShapes() { return m_shapes.size(); }; unsigned long getNChildrenConnections() { return m_allchildren.size(); }; - std::vector<std::vector<std::string>> getTableFromTableName( - std::string tableName) { - return m_dbManager->getTableRecords(tableName); + std::vector<std::vector<std::string>> getTableFromTableName_String( + const std::string_view tableName) { + return m_dbManager->getTableRecords_String(tableName); }; + unsigned long getNShapes() { return m_shapes.size(); }; // TODO: to be removed later + unsigned long getNShapes_Box() { return m_shapes_Box.size(); }; + unsigned long getNShapes_Cons() { return m_shapes_Cons.size(); }; + unsigned long getNShapes_Para() { return m_shapes_Para.size(); }; + unsigned long getNShapes_Pcon() { return m_shapes_Pcon.size(); }; + unsigned long getNShapes_Pgon() { return m_shapes_Pgon.size(); }; + unsigned long getNShapes_SimplePolygonBrep() { return m_shapes_SimplePolygonBrep.size(); }; + unsigned long getNShapes_GenericTrap() { return m_shapes_GenericTrap.size(); }; + unsigned long getNShapes_Trap() { return m_shapes_Trap.size(); }; + unsigned long getNShapes_Trd() { return m_shapes_Trd.size(); }; + unsigned long getNShapes_Tube() { return m_shapes_Tube.size(); }; + unsigned long getNShapes_Tubs() { return m_shapes_Tubs.size(); }; + unsigned long getNShapes_Torus() { return m_shapes_Torus.size(); }; + unsigned long getNShapes_TwistedTrap() { return m_shapes_TwistedTrap.size(); }; + unsigned long getNShapes_UnidentifiedShape() { return m_shapes_UnidentifiedShape.size(); }; + unsigned long getNShapes_Shift() { return m_shapes_Shift.size(); }; + unsigned long getNShapes_Union() { return m_shapes_Union.size(); }; + unsigned long getNShapes_Intersection() { return m_shapes_Intersection.size(); }; + unsigned long getNShapes_Subtraction() { return m_shapes_Subtraction.size(); }; private: - void buildAllShapes(); + void buildAllShapes(); // TODO: OLD METHOD, TO BE REMOVED WHEN READY + void buildAllShapes_Box(); + void buildAllShapes_Tube(); + void buildAllShapes_Cons(); + void buildAllShapes_Para(); + void buildAllShapes_Trap(); + void buildAllShapes_Trd(); + void buildAllShapes_Tubs(); + void buildAllShapes_Torus(); + void buildAllShapes_TwistedTrap(); + void buildAllShapes_UnidentifiedShape(); + void buildAllShapes_Pcon(); + void buildAllShapes_Pgon(); + void buildAllShapes_SimplePolygonBrep(); + void buildAllShapes_GenericTrap(); + void buildAllShapes_Operators(); + + void buildAllElements(); void buildAllMaterials(); void buildAllLogVols(); @@ -171,68 +220,107 @@ class ReadGeoModel { void buildAllSerialTransformers(); void buildAllNameTags(); + void buildAllVSurfaces(); + void buildVSurface(const unsigned int id); + GeoVSurfaceShape* BuildWhichSurface(std::string_view shapeType, const unsigned int shapeId); + GeoVPhysVol* buildGeoModelPrivate(); GeoBox* buildDummyShape(); - void loopOverAllChildrenInBunches(); - void loopOverAllChildrenRecords( - std::vector<std::vector<std::string>> records); + // void loopOverAllChildrenInBunches_String(); // OLD + void loopOverAllChildrenInBunches_VecVecData(); + // void loopOverAllChildrenRecords( + // std::vector<std::vector<std::string>> records); + void loopOverAllChildrenRecords(const DBRowsList& records); void processParentChild(const std::vector<std::string>& parentchild); + void processParentChild(const DBRowEntry& parentchild); GeoVPhysVol* getRootVolume(); - GeoVPhysVol* buildVPhysVolInstance(const unsigned int id, - const unsigned int tableId, - const unsigned int copyNumber); - GeoVPhysVol* buildVPhysVol(const unsigned int id, - const unsigned int tableId, - unsigned int logVol_ID = 0); + GeoVPhysVol* buildVPhysVolInstance(const unsigned id, + const unsigned tableId, + const unsigned copyNumber); + GeoVPhysVol* buildVPhysVol(const unsigned id, + const unsigned tableId, + unsigned logVol_ID = 0); - GeoLogVol* buildLogVol(const unsigned int id); - GeoShape* buildShape(const unsigned int id, + GeoLogVol* buildLogVol(const unsigned id); + + GeoShape* buildShape(const unsigned id, type_shapes_boolean_info* shapes_info_sub); + GeoShape *buildShapeOperator(const std::string_view shapeType, const DBRowEntry& row, + boolean_shapes_operands_info *shapes_info_sub); + GeoMaterial* buildMaterial(const unsigned id); - GeoElement* buildElement(const unsigned int id); - GeoAlignableTransform* buildAlignableTransform(const unsigned int id); + GeoElement* buildElement(const unsigned id); + GeoAlignableTransform* buildAlignableTransform(const unsigned id); GeoTransform* buildTransform(const unsigned int id); - GeoSerialTransformer* buildSerialTransformer(const unsigned int id); - TRANSFUNCTION buildFunction(const unsigned int id); + GeoSerialTransformer* buildSerialTransformer(const unsigned id); + TRANSFUNCTION buildFunction(const unsigned id); - void checkNodePtr(GeoGraphNode* nodePtr, std::string varName = "", - std::string funcName = "", - std::string funcSignature = + void checkNodePtr(GeoGraphNode* nodePtr, const std::string& varName = "", + const std::string& funcName = "", + const std::string& funcSignature = ""); // TODO: to be moved to an utility class void volAddHelper(GeoVPhysVol* vol, GeoGraphNode* volChild); // methods for shapes - std::string getShapeType(const unsigned int shapeId); - bool isShapeOperator(const unsigned int shapeId); - bool isShapeOperator(const std::string type); - bool isShapeBoolean(const unsigned int shapeId); - bool isShapeBoolean(const std::string type); + std::string getShapeType(const unsigned shapeId); + bool isShapeOperator(const unsigned shapeId); + bool isShapeOperator(const std::string_view type); + bool isShapeBoolean(const unsigned shapeId); + bool isShapeBoolean(const std::string_view type); void createBooleanShapeOperands(type_shapes_boolean_info* shapes_info_sub); - std::pair<unsigned int, unsigned int> getBooleanShapeOperands( - const unsigned int shape); + void createBooleanShapeOperands(boolean_shapes_operands_info* shapes_info_sub); + std::pair<unsigned, unsigned> getBooleanShapeOperands( + const unsigned shape); + std::tuple<std::string, unsigned int, std::string, unsigned> getBooleanShapeOperands( + const std::string_view shapeType, const unsigned shapeId); + GeoShape* addEmptyBooleanShapeForCompletion( + const unsigned shapeID, type_shapes_boolean_info* shapes_info_sub); + GeoShape* getBooleanReferencedShape( + const unsigned shapeID, type_shapes_boolean_info* shapes_info_sub); GeoShape* addEmptyBooleanShapeForCompletion( - const unsigned int shapeID, type_shapes_boolean_info* shapes_info_sub); + const std::string_view shapeType, const unsigned shapeID, boolean_shapes_operands_info* shapes_info_sub); GeoShape* getBooleanReferencedShape( - const unsigned int shapeID, type_shapes_boolean_info* shapes_info_sub); + const std::string_view shapeType, const unsigned shapeID, boolean_shapes_operands_info* shapes_info_sub); // caching methods // TODO: perhaps we could merge all those 'isBuiltYYY' methods in a single // one, with the GeoModel class as a second argument ? (RMB) - bool isBuiltShape(const unsigned int id); - void storeBuiltShape(const unsigned int, GeoShape* node); - GeoShape* getBuiltShape(const unsigned int id); - - bool isBuiltTransform(const unsigned int id); + bool isBuiltVSurface(const unsigned int shapeId); + bool isBuiltRectSurface(const unsigned int shapeId); + bool isBuiltTrapezoidSurface(const unsigned int shapeId); + bool isBuiltAnnulusSurface(const unsigned int shapeId); + bool isBuiltDiamondSurface(const unsigned int shapeId); + bool isBuiltShape(const unsigned id); + bool isBuiltShape_Operators_Shift(const unsigned id); + bool isBuiltShape_Operators_Subtraction(const unsigned id); + bool isBuiltShape_Operators_Intersection(const unsigned id); + bool isBuiltShape_Operators_Union(const unsigned id); + bool isBuiltShape(std::string_view shapeType, const unsigned id); + void storeBuiltShape(const unsigned, GeoShape* node); + void storeBuiltShape(const std::string_view type, const unsigned id, GeoShape *nodePtr); + GeoShape* getBuiltShape(const unsigned shapeId, std::string_view shapeType = ""); + + void storeBuiltShapeOperators_Shift(const unsigned, GeoShape* node); + void storeBuiltShapeOperators_Subtraction(const unsigned, GeoShape* node); + void storeBuiltShapeOperators_Union(const unsigned, GeoShape* node); + void storeBuiltShapeOperators_Intersection(const unsigned, GeoShape* node); + void storeBuiltRectSurface(GeoRectSurface* nodePtr); + void storeBuiltTrapezoidSurface(GeoTrapezoidSurface* nodePtr); + void storeBuiltDiamondSurface(GeoDiamondSurface* nodePtr); + void storeBuiltAnnulusSurface(GeoAnnulusSurface* nodePtr); + void storeBuiltVSurface(GeoVSurface* nodePtr); + + bool isBuiltTransform(const unsigned id); void storeBuiltTransform(GeoTransform* node); - GeoTransform* getBuiltTransform(const unsigned int id); + GeoTransform* getBuiltTransform(const unsigned id); - bool isBuiltAlignableTransform(const unsigned int id); + bool isBuiltAlignableTransform(const unsigned id); void storeBuiltAlignableTransform(GeoAlignableTransform* node); - GeoAlignableTransform* getBuiltAlignableTransform(const unsigned int id); + GeoAlignableTransform* getBuiltAlignableTransform(const unsigned id); // void storeVPhysVol(const unsigned int id, const unsigned int tableId, // const unsigned int copyNumber, GeoGraphNode* node); GeoGraphNode* @@ -289,10 +377,9 @@ class ReadGeoModel { GeoSerialTransformer* getBuiltSerialTransformer(const unsigned int id); // Utility functions - std::string getEnvVar(std::string const& key) const; - std::vector<std::string> splitString(const std::string& s, char delimiter); + std::vector<std::string> splitString(const std::string& s, char delimiter); // TODO: move to global helpers void printStdVectorStrings( - std::vector<std::string> vec); // TODO: move it to utility class + const std::vector<std::string>& vec); // TODO: move it to utility class or move to global helpers // void printTransformationValues(QStringList t); // TODO: move to a Qt // utility class QList<double> convertQstringListToDouble(QStringList @@ -314,6 +401,24 @@ class ReadGeoModel { // callback handles unsigned long* m_progress; + //! builders + // std::unique_ptr<BuildGeoShapes_Box> m_builderShape_Box; + BuildGeoVSurface* buildsurfTool{}; + BuildGeoShapes_Box* m_builderShape_Box{}; + BuildGeoShapes_Tube* m_builderShape_Tube{}; + BuildGeoShapes_Cons* m_builderShape_Cons{}; + BuildGeoShapes_Para* m_builderShape_Para{}; + BuildGeoShapes_Trap* m_builderShape_Trap{}; + BuildGeoShapes_Trd* m_builderShape_Trd{}; + BuildGeoShapes_Tubs* m_builderShape_Tubs{}; + BuildGeoShapes_Torus* m_builderShape_Torus{}; + BuildGeoShapes_TwistedTrap* m_builderShape_TwistedTrap{}; + BuildGeoShapes_Pcon* m_builderShape_Pcon{}; + BuildGeoShapes_Pgon* m_builderShape_Pgon{}; + BuildGeoShapes_SimplePolygonBrep* m_builderShape_SimplePolygonBrep{}; + BuildGeoShapes_GenericTrap* m_builderShape_GenericTrap{}; + BuildGeoShapes_UnidentifiedShape* m_builderShape_UnidentifiedShape{}; + //! containers to store the list of GeoModel nodes coming from the DB std::vector<std::vector<std::string>> m_physVols; std::vector<std::vector<std::string>> m_fullPhysVols; @@ -324,12 +429,56 @@ class ReadGeoModel { std::vector<std::vector<std::string>> m_identifierTags; std::vector<std::vector<std::string>> m_serialTransformers; std::vector<std::vector<std::string>> m_nameTags; - std::vector<std::vector<std::string>> m_logVols; - std::vector<std::vector<std::string>> m_materials; - std::vector<std::vector<std::string>> m_elements; + // std::vector<std::vector<std::string>> m_materials; + // std::vector<std::vector<std::string>> m_elements; std::vector<std::vector<std::string>> m_shapes; - std::vector<std::vector<std::string>> m_functions; - std::vector<std::vector<std::string>> m_allchildren; + + DBRowsList m_elements; + DBRowsList m_materials; + DBRowsList m_materials_Data; + DBRowsList m_logVols; + DBRowsList m_allchildren; + + // containers to store virtual surfaces + DBRowsList m_rectangle_surface; // For Virtual Surface Shape + DBRowsList m_trapezoid_surface; + DBRowsList m_annulus_surface; + DBRowsList m_diamond_surface; + DBRowsList m_VSurface; // For Virtual Surface Abstract Class + + // containers to store shapes' parameters + DBRowsList m_shapes_Box; + DBRowsList m_shapes_Tube; + DBRowsList m_shapes_Cons; + DBRowsList m_shapes_Para; + DBRowsList m_shapes_Trap; + DBRowsList m_shapes_Trd; + DBRowsList m_shapes_Tubs; + DBRowsList m_shapes_Torus; + DBRowsList m_shapes_TwistedTrap; + DBRowsList m_shapes_Pcon; + DBRowsList m_shapes_Pgon; + DBRowsList m_shapes_SimplePolygonBrep; + DBRowsList m_shapes_GenericTrap; + DBRowsList m_shapes_UnidentifiedShape; + + // containers to store shapes' data, + // for those shapes with a variable number of build parameters + DBRowsList m_shapes_Pcon_data; + DBRowsList m_shapes_Pgon_data; + DBRowsList m_shapes_SimplePolygonBrep_data; + DBRowsList m_shapes_GenericTrap_data; + + // containers to store shape operators / boolean shapes + DBRowsList m_shapes_Shift; + DBRowsList m_shapes_Subtraction; + DBRowsList m_shapes_Intersection; + DBRowsList m_shapes_Union; + + // containers to store Functions and their related data + DBRowsList m_functions; + std::deque<double> m_funcExprData; + std::unordered_map<unsigned int, std::string> m_tableID_toTableName; // to look for node's type name starting from a @@ -338,7 +487,8 @@ class ReadGeoModel { m_tableName_toTableID; // to look for table ID starting from node's // type name - std::vector<std::string> m_root_vol_data; + // std::vector<std::string> m_root_vol_data; + std::pair<unsigned, unsigned> m_root_vol_data; //! memory chaches std::vector<GeoPhysVol*> m_memMapPhysVols; @@ -353,12 +503,22 @@ class ReadGeoModel { std::vector<GeoLogVol*> m_memMapLogVols; std::vector<GeoMaterial*> m_memMapMaterials; std::vector<GeoElement*> m_memMapElements; + std::vector<GeoRectSurface*> m_memMapRectSurface; + std::vector<GeoTrapezoidSurface*> m_memMapTrapezoidSurface; + std::vector<GeoAnnulusSurface*> m_memMapAnnulusSurface; + std::vector<GeoDiamondSurface*> m_memMapDiamondSurface; + std::vector<GeoVSurface*> m_memMapVSurface; // std::vector<GeoXF::Function*> m_memMapFunctions; // FIXME: - std::unordered_map<unsigned int, GeoShape*> - m_memMapShapes; // we need keys, because shapes are not built following - // the ID order - std::unordered_map<std::string, GeoGraphNode*> - m_memMap; // we need keys, to keep track of the volume's copyNumber + + // we need keys, because shapes are not built following the ID order + std::unordered_map<unsigned int, GeoShape*> m_memMapShapes; // OLD DB CACHE + std::unordered_map<unsigned int, GeoShape*> m_memMapShapes_Shift; + std::unordered_map<unsigned int, GeoShape*> m_memMapShapes_Subtraction; + std::unordered_map<unsigned int, GeoShape*> m_memMapShapes_Union; + std::unordered_map<unsigned int, GeoShape*> m_memMapShapes_Intersection; + + // we need keys, to keep track of the volume's copyNumber + std::unordered_map<std::string, GeoGraphNode*> m_memMap; //! container to store unknown shapes std::set<std::string> m_unknown_shapes; diff --git a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp index 82d3f4a91805c5a1f250312f71f9054630a37186..ad08d01cd330b0c2f67c4c2aa2d063a0eb4a9d51 100644 --- a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp +++ b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp @@ -1,3 +1,6 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ /* vim: set ft=cpp: */ // VIM modeline options /* * ReadGeoModel.tpp @@ -11,6 +14,10 @@ #include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" + + namespace GeoModelIO { @@ -21,19 +28,21 @@ namespace GeoModelIO { std::map<T, N> mapNodes; std::string keyType = ""; - std::vector<std::vector<std::string>> vecRecords; + // std::vector<std::vector<std::string>> vecRecords; + DBRowsList vecRecords; + static_assert(std::is_same_v<GeoFullPhysVol*, N> || std::is_same_v<GeoAlignableTransform*, N> , "ERROR! The node type is not currently supported. If in doubt, please ask to 'geomodel-developers@cern.ch'.\n"); if constexpr ( std::is_same_v<GeoFullPhysVol*, N> ) { if(doCheckTable){ - bool tableExists = m_dbManager->checkTable("PublishedFullPhysVols_"+publisherName); + bool tableExists = m_dbManager->checkTableFromDB("PublishedFullPhysVols_"+publisherName); if(!tableExists) return mapNodes; } vecRecords = m_dbManager->getPublishedFPVTable( publisherName ); } else if constexpr ( std::is_same_v<GeoAlignableTransform*, N> ) { if(doCheckTable){ - bool tableExists = m_dbManager->checkTable("PublishedAlignableTransforms_"+publisherName); + bool tableExists = m_dbManager->checkTableFromDB("PublishedAlignableTransforms_"+publisherName); if(!tableExists) return mapNodes; } vecRecords = m_dbManager->getPublishedAXFTable( publisherName ); @@ -41,15 +50,15 @@ namespace GeoModelIO { unsigned ii = 0; for( auto const &record : vecRecords ) { // record[0] is the record's ID in the DB table, we skip that. - std::string keyStr = record[1]; - std::string volID = record[2]; - if(0==ii) keyType = record[3];//this is the same for all records. TODO: it should be stored in a metadata table + const std::string keyStr = GeoModelHelpers::variantHelper::getFromVariant_String(record[1], "getPublishedNodes:keyStr"); + const unsigned volID = GeoModelHelpers::variantHelper::getFromVariant_Int(record[2], "getPublishedNodes:volID"); + if(0==ii) keyType = GeoModelHelpers::variantHelper::getFromVariant_String(record[3], "getPublishedNodes:keyType"); //this is the same for all records. TODO: it should be stored in a metadata table ++ii; N volPtr = nullptr; if constexpr ( std::is_same_v<GeoFullPhysVol*, N> ) { - volPtr = dynamic_cast<GeoFullPhysVol*>( getVPhysVol(std::stoul(volID), 2) ); //always table=2, and we should have copyN=1 because FullPhysVols are not sharable + volPtr = dynamic_cast<GeoFullPhysVol*>( getVPhysVol(volID, 2) ); //always table=2, and we should have copyN=1 because FullPhysVols are not sharable } else if constexpr ( std::is_same_v<GeoAlignableTransform*, N> ) { - volPtr = getBuiltAlignableTransform(std::stoul(volID)); + volPtr = getBuiltAlignableTransform(volID); } else { std::cout << "ERROR! The node type '" << typeid(N).name() << "' is not currently supported.\n" @@ -58,6 +67,7 @@ namespace GeoModelIO { exit(EXIT_FAILURE); } + //TODO: check if we can get rid of stoul/stoi... if constexpr ( std::is_same_v<unsigned, T> ) { unsigned int key = std::stoul( keyStr ); mapNodes.insert( {key, volPtr} ); @@ -71,10 +81,11 @@ namespace GeoModelIO { mapNodes.insert( {keyStr, volPtr} ); } else { - std::cout << "ERROR! Key type '" << keyType << "' is not currently supported.\n" - << "If in doubt, please ask to 'geomodel-developers@cern.ch'.\n" - << "Exiting...\n"; - exit(EXIT_FAILURE); + const std::string errMsg = "ERROR! Key type '" + keyType + "' is not currently supported.\n" + + "For the moment, unsigned int, int, and string are supported.\n" + + "If in doubt, please ask to 'geomodel-developers@cern.ch'.\n" + + "Exiting...\n"; + THROW_EXCEPTION(errMsg); } } return mapNodes; diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c6f31cb91edd2efdefd0ee442fdf382f5462a58 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes.cpp @@ -0,0 +1,45 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes.h" + +#include "GeoModelKernel/GeoShape.h" + +#include <vector> +#include <iostream> + +BuildGeoShapes::BuildGeoShapes(std::string_view shapeType, const unsigned size) +{ + m_shapeType = shapeType; + m_memMapShapes.reserve(size); +} + +BuildGeoShapes::BuildGeoShapes(std::string_view shapeType, const unsigned size, const DBRowsList& shapeData) +{ + m_shapeType = shapeType; + m_memMapShapes.reserve(size); + m_shape_data = shapeData; +} + +bool BuildGeoShapes::isBuiltShape(const unsigned id) { + return (!(m_memMapShapes.find(id) == m_memMapShapes.end())); +} +void BuildGeoShapes::storeBuiltShape(const unsigned id, GeoShape* nodePtr) { + m_memMapShapes[id] = nodePtr; +} +GeoShape* BuildGeoShapes::getBuiltShape(const unsigned id) { + if (!m_memMapShapes.size()) return nullptr; + return m_memMapShapes[id]; // this is a map, and 'id' is the key +} + +void BuildGeoShapes::printBuiltShapes() { + for (unsigned id{1}; id<=m_memMapShapes.size(); ++id) { + std::cout << "shape " << m_shapeType << " -- id: " << id << ", shapePtr: " << m_memMapShapes[id] << std::endl; + } +} \ No newline at end of file diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes.h new file mode 100644 index 0000000000000000000000000000000000000000..48dc90069e1d739925ffc1ab374e194f696d9602 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes.h + * + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BUILDGEOSHAPES_H +#define GEOMODELREAD_BUILDGEOSHAPES_H + +#include "GeoModelDBManager/definitions.h" + +#include <vector> +#include <variant> +#include <string> +#include <unordered_map> + +class GeoShape; + +class BuildGeoShapes +{ +protected: + std::unordered_map<unsigned, GeoShape *> m_memMapShapes{}; + std::string m_shapeType; + DBRowsList m_shape_data; + +public: + //! contructors + BuildGeoShapes(std::string_view shapeType, const unsigned size); + BuildGeoShapes(std::string_view shapeType, const unsigned size, const DBRowsList& shapesData); + + virtual void buildShape(const DBRowEntry row) = 0; + + // --- methods for caching GeoShape nodes --- + void storeBuiltShape(const unsigned id, GeoShape *nodePtr); + bool isBuiltShape(const unsigned id); + GeoShape *getBuiltShape(const unsigned id); + // --- print the list of built/cached shapes + void printBuiltShapes(); +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b76a7b19f51e7157251bb90d04a4d0e1d7d861e1 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.cpp @@ -0,0 +1,36 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Box.h" + +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Box::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const unsigned shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Box:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Box:shapeVolume"); + // shape parameters + const double XHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Box:XHalfLength"); + const double YHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Box:YHalfLength"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Box:ZHalfLength"); + + GeoBox *shape = new GeoBox(XHalfLength, YHalfLength, ZHalfLength); + + storeBuiltShape(shapeId, shape); + + // return shape; + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.h new file mode 100644 index 0000000000000000000000000000000000000000..b3f5dbab09c8948bfc8789e16f423c6b7faa0c66 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Box.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Box.h + * + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BUILDGEOSHAPES_BOX_H +#define GEOMODELREAD_BUILDGEOSHAPES_BOX_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Box : public BuildGeoShapes +{ +public: + BuildGeoShapes_Box(const unsigned size):BuildGeoShapes("Box", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e884f7f9076b903b502afc333de88d912edf54de --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.cpp @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Cons.h" + +#include "GeoModelKernel/GeoCons.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Cons::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Cons:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Cons:shapeVolume"); + // shape parameters + const double RMin1 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Cons:RMin1"); + const double RMin2 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Cons:RMin2"); + const double RMax1 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Cons:RMax1"); + const double RMax2 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Cons:RMax2"); + const double DZ = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Cons:DZ"); + const double SPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[7], "Cons:SPhi"); + const double DPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[8], "Cons:DPhi"); + + GeoCons *shape = new GeoCons(RMin1, RMin2, RMax1, RMax2, DZ, SPhi, DPhi); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.h new file mode 100644 index 0000000000000000000000000000000000000000..fdfdda6b64fedc24b88f08b39760b273673df275 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Cons.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Cons.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Cons_H +#define GEOMODELREAD_BuildGeoShapes_Cons_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> +#include <string> + +class BuildGeoShapes_Cons : public BuildGeoShapes +{ +public: + BuildGeoShapes_Cons(const unsigned size):BuildGeoShapes("Cons", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d2987dfedcfbe4b83dc2e4a1b4c19b4690e3707 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.cpp @@ -0,0 +1,84 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_GenericTrap.h" + +#include "GeoModelKernel/GeoGenericTrap.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_GenericTrap::buildShape(const DBRowEntry row) +{ + if (!(m_shape_data.size())) + { + THROW_EXCEPTION("ERROR! GeoGenericTrap shape has no ZPlanes data!! [m_shape_data.size() == 0]"); + } + + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "GenericTrap:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "GenericTrap:shapeVolume"); + // shape parameters + const double zHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "GenericTrap:ZHalfLength"); + const unsigned int NVertices = GeoModelHelpers::variantHelper::getFromVariant_Int(row[3], "GenericTrap:NVertices"); + // pointers to variable shape data stored in a separate table + const int dataStart = GeoModelHelpers::variantHelper::getFromVariant_Int(row[4], "GenericTrap:dataStart"); + const int dataEnd = GeoModelHelpers::variantHelper::getFromVariant_Int(row[5], "GenericTrap:dataEnd"); + + // and now loop over the additional shape's data, + // to get the parameters of all vertices + + //container for GenericTrap vertices + GeoGenericTrapVertices vertices; + + // extract subvector + // NOTE: we use (dataStart-1) to cope with the difference between the DB rows starting from '1', + // which is what the 'dataStart' stores, and the vector items, which start '0'; + // also, the constructor of the sub-vector takes the element from 'begin+dataStart-1' included + // and 'begin+dataEnd' excluded. + const DBRowsList thisShapeData(m_shape_data.begin() + (dataStart - 1), + m_shape_data.begin() + (dataEnd)); + if (!(thisShapeData.size())) + { + THROW_EXCEPTION("ERROR! GeoGenericTrap shape ZPlanes data have not been retrieved!!"); + } + if (!(NVertices == thisShapeData.size())) + { + THROW_EXCEPTION("ERROR! GeoGenericTrap shape : size of ZPlanes data does not correspond to the number of ZPlanes declared!!"); + } + // loop over the data defining the ZPlanes + for (const DBRowEntry &dataRow : thisShapeData) + { + const double xV = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[1], "GenericTrap:data_xV"); + const double yV = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[2], "GenericTrap:data_yV"); + // add a vertex to the collection of all GeoGenericTrap vertices + vertices.push_back(GeoTwoVector(xV, yV)); + } + + // build the basic GeoGenericTrap shape + GeoGenericTrap *shape = new GeoGenericTrap(zHalfLength, vertices); + + // sanity checks on the resulting GenericTrap shape + if (shape->getVertices().size() != NVertices) + { + THROW_EXCEPTION("ERROR! GeoGenericTrap actual number of vertices: " + std::to_string(shape->getVertices().size()) + " is not equal to the original size! --> " + std::to_string(NVertices)); + } + // if (!shape->isValid()) + // { + // THROW_EXCEPTION("ERROR! GeoGenericTrap shape is not valid!!"); + // } + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.h new file mode 100644 index 0000000000000000000000000000000000000000..5370afcf6076b8ba4c47938822ae221aacba3083 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_GenericTrap.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_GenericTrap.h + * + * Created on: June, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_GenericTrap_H +#define GEOMODELREAD_BuildGeoShapes_GenericTrap_H + +#include "BuildGeoShapes.h" + +#include "GeoModelDBManager/definitions.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_GenericTrap : public BuildGeoShapes +{ +public: + BuildGeoShapes_GenericTrap(const unsigned size, DBRowsList shapeData):BuildGeoShapes("GenericTrap", size, shapeData){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb387e2a22d43c8dc2d26857465a43877c9bfa1d --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.cpp @@ -0,0 +1,39 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Para.h" + +#include "GeoModelKernel/GeoPara.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Para::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Para:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Para:shapeVolume"); + + // shape parameters + const double XHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Para:XHalfLength"); + const double YHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Para:YHalfLength"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Para:ZHalfLength"); + const double Alpha = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Para:Alpha"); + const double Theta = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Para:Theta"); + const double Phi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[7], "Para:Phi"); + + GeoPara *shape = new GeoPara(XHalfLength, YHalfLength, ZHalfLength, Alpha, Theta, + Phi); + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.h new file mode 100644 index 0000000000000000000000000000000000000000..2a5aa78574668f79b627d4d6fc033fc9e946cdcd --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Para.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Para.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Para_H +#define GEOMODELREAD_BuildGeoShapes_Para_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> +#include <string> + +class BuildGeoShapes_Para : public BuildGeoShapes +{ +public: + BuildGeoShapes_Para(const unsigned size):BuildGeoShapes("Para", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1bd3ec5742efad79e478f44a7fee4623bdd0cf6 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.cpp @@ -0,0 +1,80 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Pcon.h" + +#include "GeoModelKernel/GeoPcon.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Pcon::buildShape(const DBRowEntry row) +{ + if (!(m_shape_data.size())) { + THROW_EXCEPTION("ERROR! GeoPcon shape has no ZPlanes data!! [m_shape_data.size() == 0]"); + } + + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Pcon:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Pcon:shapeVolume"); + // shape parameters + const double SPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Pcon:SPhi"); + const double DPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Pcon:DPhi"); + const int NZPlanes = GeoModelHelpers::variantHelper::getFromVariant_Int(row[4], "Pcon:NZPlanes"); + // pointers to variable shape data stored in a separate table + const int dataStart = GeoModelHelpers::variantHelper::getFromVariant_Int(row[5], "Pcon:dataStart"); + const int dataEnd = GeoModelHelpers::variantHelper::getFromVariant_Int(row[6], "Pcon:dataEnd"); + + // build the basic GeoPcon shape + GeoPcon *pcon = new GeoPcon(SPhi, DPhi); + + // and now loop over the additional shape's data, + // to get the parameters of all Z planes + + // get ZPlanes' data, extract subvector + // NOTE: we use (dataStart-1) to cope with the difference between the DB rows starting from '1', + // which is what the 'dataStart' stores, and the vector items, which start '0'; + // also, the constructor of the sub-vector takes the element from 'begin+dataStart-1' included + // and 'begin+dataEnd' excluded. + const DBRowsList zplanesData(m_shape_data.begin() + (dataStart-1), + m_shape_data.begin() + (dataEnd) ); + if (!(zplanesData.size())) { + THROW_EXCEPTION("ERROR! GeoPcon shape ZPlanes data have not been retrieved!!"); + } + if (!( NZPlanes == zplanesData.size())) { + THROW_EXCEPTION("ERROR! GeoPcon shape : size of ZPlanes data does not correspond to the number of ZPlanes declared!!"); + } + // loop over the data defining the ZPlanes + for (const DBRowEntry &dataRow : zplanesData) + { + const double zpos = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[1], "Pcon:data_ZPos"); + const double rmin = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[2], "Pcon:data_RMin"); + const double rmax = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[3], "Pcon:data_RMax"); + // add a Z plane to the GeoPcon + pcon->addPlane(zpos, rmin, rmax); + } + + // sanity checks on the resulting Pcon shape + if (pcon->getNPlanes() != NZPlanes) + { + THROW_EXCEPTION("ERROR! GeoPcon actual number of planes: " + std::to_string(pcon->getNPlanes()) + " is not equal to the original size! --> " + std::to_string(NZPlanes)); + } + if (!pcon->isValid()) + { + THROW_EXCEPTION("ERROR! GeoPcon shape is not valid!!"); + } + + storeBuiltShape(shapeId, pcon); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.h new file mode 100644 index 0000000000000000000000000000000000000000..5d66e1a69e792dd33350aa0d78f668e5dd0f064c --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pcon.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Pcon.h + * + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Pcon_H +#define GEOMODELREAD_BuildGeoShapes_Pcon_H + +#include "BuildGeoShapes.h" + +#include "GeoModelDBManager/definitions.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Pcon : public BuildGeoShapes +{ +public: + BuildGeoShapes_Pcon(const unsigned size, DBRowsList shapeData):BuildGeoShapes("Pcon", size, shapeData){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dcf90921b36bf9a77df7cfae246fed49a87a11e7 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.cpp @@ -0,0 +1,81 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Pgon.h" + +#include "GeoModelKernel/GeoPgon.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Pgon::buildShape(const DBRowEntry row) +{ + if (!(m_shape_data.size())) { + THROW_EXCEPTION("ERROR! GeoPgon shape has no ZPlanes data!! [m_shape_data.size() == 0]"); + } + + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Pgon:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Pgon:shapeVolume"); + // shape parameters + const double SPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Pgon:SPhi"); + const double DPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Pgon:DPhi"); + const int NSides = GeoModelHelpers::variantHelper::getFromVariant_Int(row[4], "Pgon:NSides"); + const int NZPlanes = GeoModelHelpers::variantHelper::getFromVariant_Int(row[5], "Pgon:NZPlanes"); + // pointers to variable shape data stored in a separate table + const int dataStart = GeoModelHelpers::variantHelper::getFromVariant_Int(row[6], "Pgon:dataStart"); + const int dataEnd = GeoModelHelpers::variantHelper::getFromVariant_Int(row[7], "Pgon:dataEnd"); + + // build the basic GeoPgon shape + GeoPgon *shape = new GeoPgon(SPhi, DPhi, NSides); + + // and now loop over the additional shape's data, + // to get the parameters of all Z planes + + // extract subvector + // NOTE: we use (dataStart-1) to cope with the difference between the DB rows starting from '1', + // which is what the 'dataStart' stores, and the vector items, which start '0'; + // also, the constructor of the sub-vector takes the element from 'begin+dataStart-1' included + // and 'begin+dataEnd' excluded. + const DBRowsList zplanesData(m_shape_data.begin() + (dataStart-1), + m_shape_data.begin() + (dataEnd) ); + if (!(zplanesData.size())) { + THROW_EXCEPTION("ERROR! GeoPgon shape ZPlanes data have not been retrieved!!"); + } + if (!( NZPlanes == zplanesData.size())) { + THROW_EXCEPTION("ERROR! GeoPgon shape : size of ZPlanes data does not correspond to the number of ZPlanes declared!!"); + } + // loop over the data defining the ZPlanes + for (const DBRowEntry &dataRow : zplanesData) + { + const double zpos = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[1], "Pgon:data_ZPos"); + const double rmin = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[2], "Pgon:data_ZRMin"); + const double rmax = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[3], "Pgon:data_ZRMax"); + // add a Z plane to the GeoPgon + shape->addPlane(zpos, rmin, rmax); + } + + // sanity checks on the resulting Pgon shape + if (shape->getNPlanes() != NZPlanes) + { + THROW_EXCEPTION("ERROR! GeoPgon actual number of planes: " + std::to_string(shape->getNPlanes()) + " is not equal to the original size! --> " + std::to_string(NZPlanes)); + } + if (!shape->isValid()) + { + THROW_EXCEPTION("ERROR! GeoPgon shape is not valid!!"); + } + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.h new file mode 100644 index 0000000000000000000000000000000000000000..89880b32667ea4466acfe4bad59268988e2c2c43 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Pgon.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Pgon.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Pgon_H +#define GEOMODELREAD_BuildGeoShapes_Pgon_H + +#include "BuildGeoShapes.h" + +#include "GeoModelDBManager/definitions.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Pgon : public BuildGeoShapes +{ +public: + BuildGeoShapes_Pgon(const unsigned size, DBRowsList shapeData):BuildGeoShapes("Pgon", size, shapeData){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9ba3f5b6d22fff3f65bd402c6e424159e42acbf4 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.cpp @@ -0,0 +1,81 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_SimplePolygonBrep.h" + +#include "GeoModelKernel/GeoSimplePolygonBrep.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_SimplePolygonBrep::buildShape(const DBRowEntry row) +{ + if (!(m_shape_data.size())) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep shape has no ZPlanes data!! [m_shape_data.size() == 0]"); + } + + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "SimplePolygonBrep:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "SimplePolygonBrep:shapeVolume"); + // shape parameters + const double DZ = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "SimplePolygonBrep:DZ"); + const unsigned int NVertices = GeoModelHelpers::variantHelper::getFromVariant_Int(row[3], "SimplePolygonBrep:NVertices"); + // pointers to variable shape data stored in a separate table + const int dataStart = GeoModelHelpers::variantHelper::getFromVariant_Int(row[4], "SimplePolygonBrep:dataStart"); + const int dataEnd = GeoModelHelpers::variantHelper::getFromVariant_Int(row[5], "SimplePolygonBrep:dataEnd"); + + // build the basic GeoSimplePolygonBrep shape + GeoSimplePolygonBrep *shape = new GeoSimplePolygonBrep(DZ); + + // and now loop over the additional shape's data, + // to get the parameters of all vertices + + // extract subvector + // NOTE: we use (dataStart-1) to cope with the difference between the DB rows starting from '1', + // which is what the 'dataStart' stores, and the vector items, which start '0'; + // also, the constructor of the sub-vector takes the element from 'begin+dataStart-1' included + // and 'begin+dataEnd' excluded. + const DBRowsList thisShapeData(m_shape_data.begin() + (dataStart - 1), + m_shape_data.begin() + (dataEnd)); + if (!(thisShapeData.size())) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep shape ZPlanes data have not been retrieved!!"); + } + if (!(NVertices == thisShapeData.size())) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep shape : size of ZPlanes data does not correspond to the number of ZPlanes declared!!"); + } + // loop over the data defining the ZPlanes + for (const DBRowEntry &dataRow : thisShapeData) + { + const double xV = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[1], "SimplePolygonBrep:data_xV"); + const double yV = GeoModelHelpers::variantHelper::getFromVariant_Double(dataRow[2], "SimplePolygonBrep:data_yV"); + // add a vertex to the GeoSimplePolygonBrep + shape->addVertex(xV, yV); + } + + // sanity checks on the resulting SimplePolygonBrep shape + if (shape->getNVertices() != NVertices) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep actual number of vertices: " + std::to_string(shape->getNVertices()) + " is not equal to the original size! --> " + std::to_string(NVertices)); + } + if (!shape->isValid()) + { + THROW_EXCEPTION("ERROR! GeoSimplePolygonBrep shape is not valid!!"); + } + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.h new file mode 100644 index 0000000000000000000000000000000000000000..cff630dc09a4d4c2c673879c5fcd6e4efa9636ba --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_SimplePolygonBrep.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_SimplePolygonBrep.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_SimplePolygonBrep_H +#define GEOMODELREAD_BuildGeoShapes_SimplePolygonBrep_H + +#include "BuildGeoShapes.h" + +#include "GeoModelDBManager/definitions.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_SimplePolygonBrep : public BuildGeoShapes +{ +public: + BuildGeoShapes_SimplePolygonBrep(const unsigned size, DBRowsList shapeData):BuildGeoShapes("SimplePolygonBrep", size, shapeData){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d27fe56c4d5e252115ba3f36bc711f72f55cc2f --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.cpp @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: June, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Torus.h" + +#include "GeoModelKernel/GeoTorus.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Torus::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Torus:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Torus:shapeVolume"); + // shape parameters + const double RMin = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Torus:RMin"); + const double RMax = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Torus:RMax"); + const double RTor = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Torus:RTor"); + const double SPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Torus:SPhi"); + const double DPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Torus:DPhi"); + + GeoShape *shape = new GeoTorus(RMin, RMax, RTor, SPhi, DPhi); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.h new file mode 100644 index 0000000000000000000000000000000000000000..c319276c68e9a02acecf5c444e1d14dd229c07e7 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Torus.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Torus.h + * + * Created on: June, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Torus_H +#define GEOMODELREAD_BuildGeoShapes_Torus_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Torus : public BuildGeoShapes +{ +public: + BuildGeoShapes_Torus(const unsigned size):BuildGeoShapes("Torus", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae847a0e33dae5fb2c1f04e29eb957143f7c3b58 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.cpp @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Trap.h" + +#include "GeoModelKernel/GeoTrap.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Trap::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Trap:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Trap:shapeVolume"); + // shape parameters + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Trap:ZHalfLength"); + const double Theta = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Trap:Theta"); + const double Phi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Trap:Phi"); + const double Dydzn = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Trap:Dydzn"); + const double Dxdyndzn = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Trap:Dxdyndzn"); + const double Dxdypdzn = GeoModelHelpers::variantHelper::getFromVariant_Double(row[7], "Trap:Dxdypdzn"); + const double Angleydzn = GeoModelHelpers::variantHelper::getFromVariant_Double(row[8], "Trap:Angleydzn"); + const double Dydzp = GeoModelHelpers::variantHelper::getFromVariant_Double(row[9], "Trap:Dydzp"); + const double Dxdyndzp = GeoModelHelpers::variantHelper::getFromVariant_Double(row[10], "Trap:Dxdyndzp"); + const double Dxdypdzp = GeoModelHelpers::variantHelper::getFromVariant_Double(row[11], "Trap:Dxdypdzp"); + const double Angleydzp = GeoModelHelpers::variantHelper::getFromVariant_Double(row[12], "Trap:Angleydzp"); + + GeoShape *shape = new GeoTrap(ZHalfLength, Theta, Phi, Dydzn, Dxdyndzn, Dxdypdzn, + Angleydzn, Dydzp, Dxdyndzp, Dxdypdzp, Angleydzp); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.h new file mode 100644 index 0000000000000000000000000000000000000000..1292a45c54679dbf073b05e391351278dbac7347 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trap.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Trap.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Trap_H +#define GEOMODELREAD_BuildGeoShapes_Trap_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> +#include <string> + +class BuildGeoShapes_Trap : public BuildGeoShapes +{ +public: + BuildGeoShapes_Trap(const unsigned size):BuildGeoShapes("Trap", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f81d01efa3c467f89c48982e616ad1b7a2c43266 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.cpp @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Trd.h" + +#include "GeoModelKernel/GeoTrd.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Trd::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Trd:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Trd:shapeVolume"); + // shape parameters + const double XHalfLength1 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Trd:XHalfLength1"); + const double XHalfLength2 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Trd:XHalfLength2"); + const double YHalfLength1 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Trd:YHalfLength1"); + const double YHalfLength2 = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Trd:YHalfLength2"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Trd:ZHalfLength"); + + GeoShape *shape = new GeoTrd(XHalfLength1, XHalfLength2, YHalfLength1, YHalfLength2, ZHalfLength); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.h new file mode 100644 index 0000000000000000000000000000000000000000..9625b83b31f2e04db58dff6d686f1f4e9e5f04a8 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Trd.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Trd.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Trd_H +#define GEOMODELREAD_BuildGeoShapes_Trd_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> +#include <string> + +class BuildGeoShapes_Trd : public BuildGeoShapes +{ +public: + BuildGeoShapes_Trd(const unsigned size):BuildGeoShapes("Trd", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c486e77b94146b9410234e25a61bf85c5fbdf25 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.cpp @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Tube.h" + +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Tube::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Tube:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Tube:shapeVolume"); + // shape parameters + const double RMin = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Tube:RMin"); + const double RMax = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Tube:RMax"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Tube:ZHalfLength"); + + GeoTube *shape = new GeoTube(RMin, RMax, ZHalfLength); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.h new file mode 100644 index 0000000000000000000000000000000000000000..4a8856bfaea4f6b228dde17998090a579e09e2fd --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tube.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Tube.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Tube_H +#define GEOMODELREAD_BuildGeoShapes_Tube_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Tube : public BuildGeoShapes +{ +public: + BuildGeoShapes_Tube(const unsigned size):BuildGeoShapes("Tube", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e4ada4eb0783905b336b828bcf609a79328b2897 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.cpp @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_Tubs.h" + +#include "GeoModelKernel/GeoTubs.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_Tubs::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Tubs:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Tubs:shapeVolume"); + // shape parameters + const double RMin = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "Tubs:RMin"); + const double RMax = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "Tubs:RMax"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "Tubs:ZHalfLength"); + const double SPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "Tubs:SPhi"); + const double DPhi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "Tubs:DPhi"); + + GeoShape *shape = new GeoTubs(RMin, RMax, ZHalfLength, SPhi, DPhi); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.h new file mode 100644 index 0000000000000000000000000000000000000000..eeb330db986be59d3c4f303ace459ab5aff77fd2 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_Tubs.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_Tubs.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_Tubs_H +#define GEOMODELREAD_BuildGeoShapes_Tubs_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_Tubs : public BuildGeoShapes +{ +public: + BuildGeoShapes_Tubs(const unsigned size):BuildGeoShapes("Tubs", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da3a20dc95502981a360c751092acc748c45f241 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.cpp @@ -0,0 +1,46 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_TwistedTrap.h" + +#include "GeoModelKernel/GeoTwistedTrap.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_TwistedTrap::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "TwistedTrap:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "TwistedTrap:shapeVolume"); + // shape parameters + const double PhiTwist = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "TwistedTrap:PhiTwist"); + const double ZHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "TwistedTrap:ZHalfLength"); + const double Theta = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "TwistedTrap:Theta"); + const double Phi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "TwistedTrap:Phi"); + const double DY1HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "TwistedTrap:DY1HalfLength"); + const double DX1HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[7], "TwistedTrap:DX1HalfLength"); + const double DX2HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[8], "TwistedTrap:DX2HalfLength"); + const double DY2HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[9], "TwistedTrap:DY2HalfLength"); + const double DX3HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[10], "TwistedTrap:DX3HalfLength"); + const double DX4HalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[11], "TwistedTrap:DX4HalfLength"); + const double DTiltAngleAlpha = GeoModelHelpers::variantHelper::getFromVariant_Double(row[12], "TwistedTrap:DTiltAngleAlpha"); + + GeoShape *shape = + new GeoTwistedTrap(PhiTwist, ZHalfLength, Theta, Phi, DY1HalfLength, + DX1HalfLength, DX2HalfLength, DY2HalfLength, + DX3HalfLength, DX4HalfLength, DTiltAngleAlpha); + + storeBuiltShape(shapeId, shape); + + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.h new file mode 100644 index 0000000000000000000000000000000000000000..874cca86237563a0aad9629cd0d7bb0c0a8422a3 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_TwistedTrap.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_TwistedTrap.h + * + * Created on: May, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BuildGeoShapes_TwistedTrap_H +#define GEOMODELREAD_BuildGeoShapes_TwistedTrap_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_TwistedTrap : public BuildGeoShapes +{ +public: + BuildGeoShapes_TwistedTrap(const unsigned size):BuildGeoShapes("TwistedTrap", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3bb6fd04e98b549846831f87b1db7ba3c909293c --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.cpp @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + */ + +#include "BuildGeoShapes_UnidentifiedShape.h" + +#include "GeoModelKernel/GeoUnidentifiedShape.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include <vector> +#include <iostream> + +void BuildGeoShapes_UnidentifiedShape::buildShape(const DBRowEntry row) +{ + // === get shape numeric data from the DB row + // shape ID + const unsigned shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "UnidentifiedShape:shapeID"); + // shape volume + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "UnidentifiedShape:shapeVolume"); + // shape parameters + const std::string name = GeoModelHelpers::variantHelper::getFromVariant_String(row[2], "UnidentifiedShape:name"); + const std::string asciiData = GeoModelHelpers::variantHelper::getFromVariant_String(row[3], "UnidentifiedShape:asciiData"); + + GeoUnidentifiedShape *shape = new GeoUnidentifiedShape(name, asciiData); + + storeBuiltShape(shapeId, shape); + + // return shape; + return; +} diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.h b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.h new file mode 100644 index 0000000000000000000000000000000000000000..4e277c8f63b5d0e9d7a78e4464400a87f7a5b490 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoShapes_UnidentifiedShape.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoShapes_UnidentifiedShape.h + * + * Created on: May 7, 2024 + * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> + * + */ + +#ifndef GEOMODELREAD_BUILDGEOSHAPES_UnidentifiedShape_H +#define GEOMODELREAD_BUILDGEOSHAPES_UnidentifiedShape_H + +#include "BuildGeoShapes.h" + +#include <vector> +#include <variant> + +class BuildGeoShapes_UnidentifiedShape : public BuildGeoShapes +{ +public: + BuildGeoShapes_UnidentifiedShape(const unsigned size):BuildGeoShapes("UnidentifiedShape", size){}; + void buildShape(const DBRowEntry row) override; +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.cpp b/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39f2732880ebab1a3fc31c12cb861e638ff54de5 --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.cpp @@ -0,0 +1,71 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoVSurfaces.h + * + * Created on: June, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ +#include "BuildGeoVSurface.h" + +GeoRectSurface* BuildGeoVSurface::buildRectSurface(const DBRowEntry row) +{ + // shape area + const double surfArea = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "SurfaceRect_Area"); + // shape parameters + const double XHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "SurfaceRect_XHalfLength"); + const double YHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "SurfaceRect_YHalfLength"); + + GeoRectSurface *rectsurface = new GeoRectSurface(XHalfLength, YHalfLength); + + return rectsurface; +} + +GeoTrapezoidSurface* BuildGeoVSurface::buildTrapezoidSurface(const DBRowEntry row) +{ + // shape area + const double surfArea = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "SurfaceTrapezoid_Area"); + // shape parameters + const double XHalfLengthMin = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "SurfaceTrapezoid_XHalfLengthMin"); + const double XHalfLengthMax = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "SurfaceTrapezoid_XHalfLengthMax"); + const double YHalfLength = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "SurfaceTrapezoid_YHalfLength"); + + GeoTrapezoidSurface *trapezoid = new GeoTrapezoidSurface(XHalfLengthMin, XHalfLengthMax, YHalfLength); + + return trapezoid; +} + +GeoAnnulusSurface* BuildGeoVSurface::buildAnnulusSurface(const DBRowEntry row) +{ + // shape area + const double surfArea = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "SurfaceAnnulus_Area"); + // shape parameters + const double Ox = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "SurfaceAnnulus_Ox"); + const double Oy = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "SurfaceAnnulus_Oy"); + const double radius_in = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "SurfaceAnnulus_RadiusIn"); + const double radius_out = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "SurfaceAnnulus_RadiusOut"); + const double phi = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "SurfaceAnnulus_Phi"); + + GeoAnnulusSurface *annulus = new GeoAnnulusSurface(Ox, Oy, radius_in, radius_out, phi); + + return annulus; +} + +GeoDiamondSurface* BuildGeoVSurface::buildDiamondSurface(const DBRowEntry row) +{ + // shape area + const double surfArea = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "SurfaceDiamond_Area"); + // shape parameters + const double X_bottom_half = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "SurfaceDiamond_XBottomHalf"); + const double X_mid_half = GeoModelHelpers::variantHelper::getFromVariant_Double(row[3], "SurfaceDiamond_XMidHalf"); + const double X_top_half = GeoModelHelpers::variantHelper::getFromVariant_Double(row[4], "SurfaceDiamond_XTopHalf"); + const double Y_bottom_half = GeoModelHelpers::variantHelper::getFromVariant_Double(row[5], "SurfaceDiamond_YBottomHalf"); + const double Y_top_half = GeoModelHelpers::variantHelper::getFromVariant_Double(row[6], "SurfaceDiamond_YTopHalf"); + + GeoDiamondSurface *diamond = new GeoDiamondSurface(X_bottom_half, X_mid_half, X_top_half, Y_bottom_half, Y_top_half); + + return diamond; +} \ No newline at end of file diff --git a/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.h b/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.h new file mode 100644 index 0000000000000000000000000000000000000000..8bd5e751d0f9e3a8eed20b0ef739e3aef2e1e79d --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/BuildGeoVSurface.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +/* + * BuildGeoVSurfaces.h + * + * Created on: June, 2024 + * Author: Rui XUE <r.xue@cern.ch><rux23@pitt.edu> + * + */ + +#ifndef GEOMODELREAD_BUILDGEOVSURFACE_H +#define GEOMODELREAD_BUILDGEOVSURFACE_H + +#include "GeoModelDBManager/definitions.h" +#include "GeoModelHelpers/variantHelpers.h" + +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" + +#include <iostream> +#include <vector> +#include <variant> +#include <string> + +class BuildGeoVSurface +{ +public: + + BuildGeoVSurface() = default; + GeoRectSurface* buildRectSurface(const DBRowEntry row); + GeoTrapezoidSurface* buildTrapezoidSurface(const DBRowEntry row); + GeoAnnulusSurface* buildAnnulusSurface(const DBRowEntry row); + GeoDiamondSurface* buildDiamondSurface(const DBRowEntry row); + // left for other surfaces +}; + +#endif diff --git a/GeoModelIO/GeoModelRead/src/NOTES_UPDATE.md b/GeoModelIO/GeoModelRead/src/NOTES_UPDATE.md new file mode 100644 index 0000000000000000000000000000000000000000..31527e93ff824253f0185dfb60a76d6f670dec5e --- /dev/null +++ b/GeoModelIO/GeoModelRead/src/NOTES_UPDATE.md @@ -0,0 +1,51 @@ + + +List of all Shapes + +- Box +- Tube +- Cons +- Para +- Trap +- Trd +- TwistedTrap +- Tubs +- Pcon +- Pgon +- SimplePolygonBrep + +- Torus +- GenericTrap +- TessellatedSolid +- Shift +- Subtraction || Union || Intersection +- CustomShape + + +Write + +- Box +- Tube +- Cons +- Para +- Trap +- Trd +- Tubs +- TwistedTrap +- Pcon +- Pgon +- SimplePolygonBrep + +Read + +- Box +- Tube +- Cons +- Para +- Trap +- Trd +- Tubs +- TwistedTrap +- Pcon +- Pgon +- SimplePolygonBrep diff --git a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp index 276de5430480e6bc1618cf44ae31c20ef1613f54..79461fb441313320ef29f5a2aa8a22f3034750d5 100644 --- a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp +++ b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /* @@ -8,7 +8,7 @@ * Created on: May 20, 2016 * Author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch> * - * major updates: + * Major updates: * - Feb 2019, R.M.Bianchi * - Mar 2020, R.M.Bianchi * - Mar 2020, boudreau @@ -23,9 +23,32 @@ * The copyNumber was wrongly used together with tableID and volID * For details, see: * https://gitlab.cern.ch/GeoModelDev/GeoModel/-/issues/39 + * - May 2024, R.M.Bianchi <riccardo.maria.bianchi@cern.ch> + * Major re-write: moved to the new DB schema based on numeric data + * + * - Jun 2024, R.Xue <r.xue@cern.ch><rux23@pitt.edu> + * Added methods to read in virtual surfaces from .db files + * */ // local includes +#include "BuildGeoShapes_Box.h" +#include "BuildGeoShapes_Tube.h" +#include "BuildGeoShapes_Cons.h" +#include "BuildGeoShapes_Para.h" +#include "BuildGeoShapes_Pcon.h" +#include "BuildGeoShapes_Pgon.h" +#include "BuildGeoShapes_Trap.h" +#include "BuildGeoShapes_Trd.h" +#include "BuildGeoShapes_Tubs.h" +#include "BuildGeoShapes_Torus.h" +#include "BuildGeoShapes_TwistedTrap.h" +#include "BuildGeoShapes_SimplePolygonBrep.h" +#include "BuildGeoShapes_GenericTrap.h" +#include "BuildGeoShapes_UnidentifiedShape.h" + +#include "BuildGeoVSurface.h" + #include "GeoModelRead/ReadGeoModel.h" // TFPersistification includes @@ -47,6 +70,12 @@ #include "GeoModelKernel/GeoTransform.h" #include "GeoModelKernel/GeoUtilFunctions.h" #include "GeoModelKernel/GeoVPhysVol.h" +#include "GeoModelKernel/GeoVSurface.h" +#include "GeoModelKernel/GeoVSurfaceShape.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" // GeoModel shapes #include "GeoModelKernel/GeoBox.h" @@ -70,6 +99,10 @@ #include "GeoModelKernel/GeoTwistedTrap.h" #include "GeoModelKernel/GeoUnidentifiedShape.h" +#include "GeoModelHelpers/variantHelpers.h" +#include "GeoModelKernel/throwExcept.h" +#include "GeoModelHelpers/StringUtils.h" + // Units #include "GeoModelKernel/Units.h" #define SYSTEM_OF_UNITS \ @@ -82,17 +115,18 @@ // #include "VP1Base/VP1Msg.h" // C++ includes -#include <stdlib.h> /* exit, EXIT_FAILURE */ +#include <cstdlib> /* exit, EXIT_FAILURE */ #include <chrono> /* system_clock */ -#include <cstdlib> /* std::getenv */ #include <ctime> /* std::time */ #include <future> +#include <memory> #include <mutex> #include <stdexcept> #include <thread> #include <unordered_map> #include <unordered_set> +#include <variant> #include <vector> // mutexes for synchronized access to containers and output streams in @@ -125,21 +159,21 @@ ReadGeoModel::ReadGeoModel(GMDBManager* db, unsigned long* progress) m_runMultithreaded_nThreads(0), m_progress(nullptr) { // Check if the user asked for debug messages - if ("" != getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_1")) { + if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_1")) { m_loglevel = 1; std::cout << "You defined the GEOMODEL_ENV_IO_DEBUG variable, so you " "will see a verbose output." << std::endl; } // Check if the user asked for verbose debug messages - if ("" != getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_2")) { + if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_2")) { m_loglevel = 2; std::cout << "You defined the GEOMODEL_ENV_IO_READ_DEBUG_VERBOSE " "variable, so you will see a verbose output." << std::endl; } // Check if the user asked for timing output - if ("" != getEnvVar("GEOMODEL_ENV_IO_READ_TIMING")) { + if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_READ_TIMING")) { m_timing = true; std::cout << "You defined the GEOMODEL_ENV_IO_READ_TIMING variable, so " "you will see a timing measurement in the output." @@ -162,9 +196,12 @@ ReadGeoModel::ReadGeoModel(GMDBManager* db, unsigned long* progress) m_dbManager->loadGeoNodeTypesAndBuildCache(); m_dbManager->createTableDataCaches(); + // prepare builders + // m_builderShape_Box = std::make_unique<BuildGeoShapes_Box>(); + // Check if the user asked for running in serial or multi-threading mode - if ("" != getEnvVar("GEOMODEL_ENV_IO_NTHREADS")) { - int nThreads = std::stoi(getEnvVar("GEOMODEL_ENV_IO_NTHREADS")); + if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_NTHREADS")) { + int nThreads = std::stoi(GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_NTHREADS")); if (nThreads == 0) { std::cout << "Info: You set the GEOMODEL_ENV_IO_NTHREADS to '" << nThreads @@ -201,14 +238,39 @@ ReadGeoModel::ReadGeoModel(GMDBManager* db, unsigned long* progress) } ReadGeoModel::~ReadGeoModel() { - // FIXME: some cleaning...?? -} - -// FIXME: TODO: move to an utility class -std::string ReadGeoModel::getEnvVar(std::string const& key) const { - char* val = std::getenv(key.c_str()); - return val == NULL ? std::string("") : std::string(val); -} + delete m_builderShape_Box; + delete m_builderShape_Tube; + delete m_builderShape_Pcon; + delete m_builderShape_Cons; + delete m_builderShape_Pgon; + delete m_builderShape_Trap; + delete m_builderShape_Trd; + delete m_builderShape_Tubs; + delete m_builderShape_Torus; + delete m_builderShape_TwistedTrap; + delete m_builderShape_SimplePolygonBrep; + delete m_builderShape_GenericTrap; + delete m_builderShape_UnidentifiedShape; + m_builderShape_Box = nullptr; + m_builderShape_Tube = nullptr; + m_builderShape_Pcon = nullptr; + m_builderShape_Cons = nullptr; + m_builderShape_Pgon = nullptr; + m_builderShape_Trap = nullptr; + m_builderShape_Trd = nullptr; + m_builderShape_Tubs = nullptr; + m_builderShape_Torus = nullptr; + m_builderShape_TwistedTrap = nullptr; + m_builderShape_SimplePolygonBrep = nullptr; + m_builderShape_GenericTrap = nullptr; + m_builderShape_UnidentifiedShape = nullptr; +} + +// // FIXME: TODO: move to an utility class +// std::string ReadGeoModel::getEnvVar(std::string const& key) const { +// char* val = std::getenv(key.c_str()); +// return val == NULL ? std::string("") : std::string(val); +// } const GeoVPhysVol* ReadGeoModel::buildGeoModel() { if (m_loglevel >= 2) @@ -227,33 +289,77 @@ const GeoVPhysVol* ReadGeoModel::buildGeoModel() { "cube of 30cm side length.\n\n" << std::endl; } - return rootVolume; } void ReadGeoModel::loadDB() { // *** get all data from the DB *** - std::chrono::system_clock::time_point start = - std::chrono::system_clock::now(); // timing: get start time + // timing: get start time + std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); // get all GeoModel nodes from the DB - m_logVols = m_dbManager->getTableFromNodeType("GeoLogVol"); - m_shapes = m_dbManager->getTableFromNodeType("GeoShape"); - m_materials = m_dbManager->getTableFromNodeType("GeoMaterial"); - m_elements = m_dbManager->getTableFromNodeType("GeoElement"); - m_functions = m_dbManager->getTableFromNodeType("Function"); - m_physVols = m_dbManager->getTableFromNodeType("GeoPhysVol"); - m_fullPhysVols = m_dbManager->getTableFromNodeType("GeoFullPhysVol"); - m_transforms = m_dbManager->getTableFromNodeType("GeoTransform"); + // m_shapes = m_dbManager->getTableFromNodeType("GeoShape"); + m_physVols = m_dbManager->getTableFromNodeType_String("GeoPhysVol"); + m_fullPhysVols = m_dbManager->getTableFromNodeType_String("GeoFullPhysVol"); + m_transforms = m_dbManager->getTableFromNodeType_String("GeoTransform"); m_alignableTransforms = - m_dbManager->getTableFromNodeType("GeoAlignableTransform"); + m_dbManager->getTableFromNodeType_String("GeoAlignableTransform"); m_serialDenominators = - m_dbManager->getTableFromNodeType("GeoSerialDenominator"); + m_dbManager->getTableFromNodeType_String("GeoSerialDenominator"); m_serialIdentifiers = - m_dbManager->getTableFromNodeType("GeoSerialIdentifier"); - m_identifierTags = m_dbManager->getTableFromNodeType("GeoIdentifierTag"); + m_dbManager->getTableFromNodeType_String("GeoSerialIdentifier"); + m_identifierTags = m_dbManager->getTableFromNodeType_String("GeoIdentifierTag"); m_serialTransformers = - m_dbManager->getTableFromNodeType("GeoSerialTransformer"); - m_nameTags = m_dbManager->getTableFromNodeType("GeoNameTag"); + m_dbManager->getTableFromNodeType_String("GeoSerialTransformer"); + m_nameTags = m_dbManager->getTableFromNodeType_String("GeoNameTag"); + + // containers to store data that have been moved to the new DB schema + m_functions = m_dbManager->getTableFromNodeType_VecVecData("Function"); + m_logVols = m_dbManager->getTableFromNodeType_VecVecData("GeoLogVol"); + m_elements = m_dbManager->getTableFromNodeType_VecVecData("GeoElement"); + m_materials = m_dbManager->getTableFromNodeType_VecVecData("GeoMaterial"); + m_materials_Data = m_dbManager->getTableFromTableName_VecVecData("Materials_Data"); + + // shapes from the new DB schema + m_shapes_Box = m_dbManager->getTableFromNodeType_VecVecData("GeoBox"); + m_shapes_Tube = m_dbManager->getTableFromNodeType_VecVecData("GeoTube"); + m_shapes_Cons = m_dbManager->getTableFromNodeType_VecVecData("GeoCons"); + m_shapes_Para = m_dbManager->getTableFromNodeType_VecVecData("GeoPara"); + m_shapes_Trap = m_dbManager->getTableFromNodeType_VecVecData("GeoTrap"); + m_shapes_Trd = m_dbManager->getTableFromNodeType_VecVecData("GeoTrd"); + m_shapes_Tubs = m_dbManager->getTableFromNodeType_VecVecData("GeoTubs"); + m_shapes_Torus = m_dbManager->getTableFromNodeType_VecVecData("GeoTorus"); + m_shapes_TwistedTrap = m_dbManager->getTableFromNodeType_VecVecData("GeoTwistedTrap"); + m_shapes_UnidentifiedShape = m_dbManager->getTableFromNodeType_VecVecData("GeoUnidentifiedShape"); + + // shapes with variable build parameters stored in a separate table + m_shapes_Pcon = m_dbManager->getTableFromNodeType_VecVecData("GeoPcon"); + m_shapes_Pgon = m_dbManager->getTableFromNodeType_VecVecData("GeoPgon"); + m_shapes_SimplePolygonBrep = m_dbManager->getTableFromNodeType_VecVecData("GeoSimplePolygonBrep"); + m_shapes_GenericTrap = m_dbManager->getTableFromNodeType_VecVecData("GeoGenericTrap"); + + // shapes' data, when needed by shapes that have variable numbers of build parameters + m_shapes_Pcon_data = m_dbManager->getTableFromTableName_VecVecData("Shapes_Pcon_Data"); + m_shapes_Pgon_data = m_dbManager->getTableFromTableName_VecVecData("Shapes_Pgon_Data"); + m_shapes_SimplePolygonBrep_data = m_dbManager->getTableFromTableName_VecVecData("Shapes_SimplePolygonBrep_Data"); + m_shapes_GenericTrap_data = m_dbManager->getTableFromTableName_VecVecData("Shapes_GenericTrap_Data"); + + // shape operators & boolean shapes + m_shapes_Shift = m_dbManager->getTableFromNodeType_VecVecData("GeoShapeShift"); + m_shapes_Subtraction = m_dbManager->getTableFromNodeType_VecVecData("GeoShapeSubtraction"); + m_shapes_Intersection = m_dbManager->getTableFromNodeType_VecVecData("GeoShapeIntersection"); + m_shapes_Union = m_dbManager->getTableFromNodeType_VecVecData("GeoShapeUnion"); + + // get the Function's expression data + // m_funcExprData = m_dbManager->getTableFromTableNameVecVecData("FuncExprData"); + m_funcExprData = m_dbManager->getTableFromTableName_DequeDouble("FuncExprData"); + + // get virtual surface shape and class from DB + m_rectangle_surface = m_dbManager->getTableFromNodeType_VecVecData("RectangleSurface"); + m_trapezoid_surface = m_dbManager->getTableFromNodeType_VecVecData("TrapezoidSurface"); + m_annulus_surface = m_dbManager->getTableFromNodeType_VecVecData("AnnulusSurface"); + m_diamond_surface = m_dbManager->getTableFromNodeType_VecVecData("DiamondSurface"); + m_VSurface = m_dbManager->getTableFromNodeType_VecVecData("GeoVSurface"); + // get the children table from DB m_allchildren = m_dbManager->getChildrenTable(); // get the root volume data @@ -292,14 +398,50 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { t8.join(); // ok, all Transforms have been built t9.join(); // ok, all AlignableTransforms have been built + // needs Transforms and AlignableTransforms for Shift boolean shapes - std::thread t1(&ReadGeoModel::buildAllShapes, this); + // std::thread t1(&ReadGeoModel::buildAllShapes, this); // TODO: old, to be removed + std::thread t15(&ReadGeoModel::buildAllShapes_Box, this); + std::thread t16(&ReadGeoModel::buildAllShapes_Tube, this); + std::thread t17(&ReadGeoModel::buildAllShapes_Pcon, this); + std::thread t18(&ReadGeoModel::buildAllShapes_Cons, this); + std::thread t19(&ReadGeoModel::buildAllShapes_Para, this); + std::thread t20(&ReadGeoModel::buildAllShapes_Pgon, this); + std::thread t21(&ReadGeoModel::buildAllShapes_Trap, this); + std::thread t22(&ReadGeoModel::buildAllShapes_Trd, this); + std::thread t23(&ReadGeoModel::buildAllShapes_Tubs, this); + std::thread t24(&ReadGeoModel::buildAllShapes_TwistedTrap, this); + std::thread t25(&ReadGeoModel::buildAllShapes_SimplePolygonBrep, this); + std::thread t26(&ReadGeoModel::buildAllShapes_UnidentifiedShape, this); + std::thread t27(&ReadGeoModel::buildAllShapes_Torus, this); + std::thread t28(&ReadGeoModel::buildAllShapes_GenericTrap, this); + t2.join(); // ok, all Elements have been built - // needs Elements + // This below needs Elements to be built std::thread t3(&ReadGeoModel::buildAllMaterials, this); - t1.join(); // ok, all Shapes have been built + // t1.join(); // ok, all Shapes have been built + t15.join(); // ok, all Shapes-Box have been built + t16.join(); // ok, all Shapes-Tube have been built + t17.join(); // ok, all Shapes-Pcon have been built + t18.join(); // ok, all Shapes-Cons have been built + t19.join(); // ok, all Shapes-Para have been built + t20.join(); // ok, all Shapes-Pgon have been built + t21.join(); // ok, all Shapes-Trap have been built + t22.join(); // ok, all Shapes-Trd have been built + t23.join(); // ok, all Shapes-Tubs have been built + t24.join(); // ok, all Shapes-TwistedTrap have been built + t25.join(); // ok, all Shapes-SimplePolygonBrep have been built + t26.join(); // ok, all Shapes-UnidentifiedShape have been built + t27.join(); // ok, all Shapes-Torus have been built + t28.join(); // ok, all Shapes-GenericTrap have been built + + // Build boolean shapes and shape operators, + // this needs Shapes to be built + std::thread t99(&ReadGeoModel::buildAllShapes_Operators, this); + t99.join(); // ok, all Shapes-Operators have been built + t3.join(); // ok, all Materials have been built // needs Shapes and Materials std::thread t4(&ReadGeoModel::buildAllLogVols, this); @@ -308,9 +450,11 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { // needs LogVols std::thread t5(&ReadGeoModel::buildAllPhysVols, this); std::thread t6(&ReadGeoModel::buildAllFullPhysVols, this); - + std::thread t29(&ReadGeoModel::buildAllVSurfaces, this); + t5.join(); // ok, all PhysVols have been built t6.join(); // ok, all FullPhysVols have been built + t29.join(); // t7.join(); // ok, all Functions have been built // needs Functions, PhysVols, FullPhysVols std::thread t12(&ReadGeoModel::buildAllSerialTransformers, this); @@ -333,12 +477,28 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { buildAllSerialIdentifiers(); buildAllIdentifierTags(); buildAllNameTags(); - buildAllShapes(); + // buildAllShapes(); + buildAllShapes_Box(); + buildAllShapes_Tube(); + buildAllShapes_Pcon(); + buildAllShapes_Pgon(); + buildAllShapes_SimplePolygonBrep(); + buildAllShapes_GenericTrap(); + buildAllShapes_UnidentifiedShape(); + buildAllShapes_Cons(); + buildAllShapes_Para(); + buildAllShapes_Trap(); + buildAllShapes_Trd(); + buildAllShapes_Tubs(); + buildAllShapes_Torus(); + buildAllShapes_TwistedTrap(); + buildAllShapes_Operators(); buildAllMaterials(); buildAllLogVols(); buildAllPhysVols(); buildAllFullPhysVols(); buildAllSerialTransformers(); + buildAllVSurfaces(); // Virtual Surface! } auto end = std::chrono::system_clock::now(); // timing: get end time auto diff = @@ -350,7 +510,8 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { // *** recreate all mother-daughter relatioships between nodes *** start = std::chrono::system_clock::now(); // timing: get start time - loopOverAllChildrenInBunches(); + // loopOverAllChildrenInBunches_String(); // OLD + loopOverAllChildrenInBunches_VecVecData(); //NEW end = std::chrono::system_clock::now(); // timing: get end time diff = std::chrono::duration_cast<std::chrono::seconds>(end - start).count(); @@ -366,7 +527,7 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { //---------------------------------------- // loop over parent-child relationship data void ReadGeoModel::loopOverAllChildrenRecords( - std::vector<std::vector<std::string>> records) { + const DBRowsList& records) { int nChildrenRecords = records.size(); if (m_loglevel >= 1) { @@ -376,26 +537,9 @@ void ReadGeoModel::loopOverAllChildrenRecords( << nChildrenRecords << " keys..." << std::endl; muxCout.unlock(); } - - // // Get Start Time - // std::chrono::system_clock::time_point start = - // std::chrono::system_clock::now(); - - for (auto& record : records) { + for (const auto& record : records) { processParentChild(record); } - - // // Get End Time - // auto end = std::chrono::system_clock::now(); - // auto diff = std::chrono::duration_cast < std::chrono::seconds > (end - // - start).count(); - // - // if (m_timing || (m_loglevel >= 1)) { - // muxCout.lock(); - // std::cout << "Time Taken to process " << nChildrenRecords << " - // parent-child relationships = " << diff << " Seconds" << std::endl; - // muxCout.unlock(); - // } } //! Iterate over the list of shapes, build them all, and store their @@ -403,8 +547,7 @@ void ReadGeoModel::loopOverAllChildrenRecords( void ReadGeoModel::buildAllShapes() { if (m_loglevel >= 1) std::cout << "Building all shapes...\n"; size_t nSize = m_shapes.size(); - m_memMapShapes.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapShapes.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int shapeID = std::stoi(m_shapes[ii][0]); type_shapes_boolean_info @@ -416,6 +559,342 @@ void ReadGeoModel::buildAllShapes() { if (nSize > 0) std::cout << "All " << nSize << " Shapes have been built!\n"; } +//! Iterate over the list of shapes, build them all, and store their +//! pointers +void ReadGeoModel::buildAllShapes_Operators() +{ + if (m_loglevel >= 1) + std::cout << "Building all shape operators / boolean shapes...\n"; + + // tuple to store the boolean shapes to + // complete at a second stage + boolean_shapes_operands_info shapes_info_sub; + + if (m_loglevel >= 2) + std::cout << "Building all Shift operators...\n"; + size_t nSize = m_shapes_Shift.size(); + m_memMapShapes_Shift.reserve(nSize); + for (const auto &row : m_shapes_Shift) + { + + // boolean_shapes_operands_info + // shapes_info_sub; // tuple to store the boolean shapes to + // complete at a second stage + buildShapeOperator("Shift", row, &shapes_info_sub); + } + if (nSize > 0) + std::cout << "All " << nSize << " Shape-Operators-Shift have been built!\n"; + + if (m_loglevel >= 2) + std::cout << "Building all Subtraction boolean shapes...\n"; + nSize = m_shapes_Subtraction.size(); + m_memMapShapes_Subtraction.reserve(nSize); + for (const auto &row : m_shapes_Subtraction) + { + + // boolean_shapes_operands_info + // shapes_info_sub; // tuple to store the boolean shapes to + // complete at a second stage + buildShapeOperator("Subtraction", row, &shapes_info_sub); + } + if (nSize > 0) + std::cout << "All " << nSize << " Shape-Operators-Subtraction have been built!\n"; + + if (m_loglevel >= 2) + std::cout << "Building all Intersection boolean shapes...\n"; + nSize = m_shapes_Intersection.size(); + m_memMapShapes_Intersection.reserve(nSize); + for (const auto &row : m_shapes_Intersection) + { + + // boolean_shapes_operands_info + // shapes_info_sub; // tuple to store the boolean shapes to + // complete at a second stage + buildShapeOperator("Intersection", row, &shapes_info_sub); + } + if (nSize > 0) + std::cout << "All " << nSize << " Shape-Operators-Intersection have been built!\n"; + + if (m_loglevel >= 2) + std::cout << "Building all Union boolean shapes...\n"; + nSize = m_shapes_Union.size(); + m_memMapShapes_Union.reserve(nSize); + for (const auto &row : m_shapes_Union) + { + + // boolean_shapes_operands_info + // shapes_info_sub; // tuple to store the boolean shapes to + // complete at a second stage + buildShapeOperator("Union", row, &shapes_info_sub); + } + if (nSize > 0) + std::cout << "All " << nSize << " Shape-Operators-Union have been built!\n"; + + + createBooleanShapeOperands(&shapes_info_sub); +} + +//! Iterate over the list of GeoBox shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Box() +{ + if (m_loglevel >= 1) { + std::cout << "Building all shapes -- Box ...\n"; + } + + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Box.size(); + m_builderShape_Box = new BuildGeoShapes_Box(nSize); + + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Box) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Box->buildShape(row); + } + // m_builderShape_Box->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Box have been built!\n"; + } +} +//! Iterate over the list of GeoTube shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Tube() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Tube.size(); + m_builderShape_Tube = new BuildGeoShapes_Tube(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Tube) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Tube->buildShape(row); + } + // m_builderShape_Tube->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Tube have been built!\n"; + } +} + +//! Iterate over the list of GeoCons shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Cons() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Cons.size(); + m_builderShape_Cons = new BuildGeoShapes_Cons(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Cons) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Cons->buildShape(row); + } + // m_builderShape_Cons->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Cons have been built!\n"; + } +} +//! Iterate over the list of GeoPara shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Para() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Para.size(); + m_builderShape_Para = new BuildGeoShapes_Para(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Para) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Para->buildShape(row); + } + // m_builderShape_Para->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Para have been built!\n"; + } +} +//! Iterate over the list of GeoTrap shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Trap() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Trap.size(); + m_builderShape_Trap = new BuildGeoShapes_Trap(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Trap) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Trap->buildShape(row); + } + // m_builderShape_Trap->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Trap have been built!\n"; + } +} +//! Iterate over the list of GeoTrd shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Trd() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Trd.size(); + m_builderShape_Trd = new BuildGeoShapes_Trd(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Trd) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Trd->buildShape(row); + } + // m_builderShape_Trd->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Trd have been built!\n"; + } +} +//! Iterate over the list of GeoTubs shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Tubs() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Tubs.size(); + m_builderShape_Tubs = new BuildGeoShapes_Tubs(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Tubs) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Tubs->buildShape(row); + } + // m_builderShape_Tubs->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Tubs have been built!\n"; + } +} +//! Iterate over the list of GeoTorus shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Torus() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Torus.size(); + m_builderShape_Torus = new BuildGeoShapes_Torus(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Torus) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Torus->buildShape(row); + } + // m_builderShape_Torus->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Torus have been built!\n"; + } +} +//! Iterate over the list of GeoTwistedTrap shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_TwistedTrap() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_TwistedTrap.size(); + m_builderShape_TwistedTrap = new BuildGeoShapes_TwistedTrap(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_TwistedTrap) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_TwistedTrap->buildShape(row); + } + // m_builderShape_TwistedTrap->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-TwistedTrap have been built!\n"; + } +} +//! Iterate over the list of GeoPcon shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Pcon() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Pcon.size(); + m_builderShape_Pcon = new BuildGeoShapes_Pcon(nSize, m_shapes_Pcon_data); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Pcon) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Pcon->buildShape(row); + } + // m_builderShape_Pcon->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Pcon have been built!\n"; + } +} +//! Iterate over the list of GeoPgon shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_Pgon() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_Pgon.size(); + m_builderShape_Pgon = new BuildGeoShapes_Pgon(nSize, m_shapes_Pgon_data); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_Pgon) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_Pgon->buildShape(row); + } + // m_builderShape_Pgon->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-Pgon have been built!\n"; + } +} +//! Iterate over the list of GeoSimplePolygonBrep shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_SimplePolygonBrep() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_SimplePolygonBrep.size(); + m_builderShape_SimplePolygonBrep = new BuildGeoShapes_SimplePolygonBrep(nSize, m_shapes_SimplePolygonBrep_data); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_SimplePolygonBrep) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_SimplePolygonBrep->buildShape(row); + } + // m_builderShape_SimplePolygonBrep->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-SimplePolygonBrep have been built!\n"; + } +} + +//! Iterate over the list of GeoGenericTrap shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_GenericTrap() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_GenericTrap.size(); + m_builderShape_GenericTrap = new BuildGeoShapes_GenericTrap(nSize, m_shapes_GenericTrap_data); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_GenericTrap) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_GenericTrap->buildShape(row); + } + // m_builderShape_GenericTrap->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-GenericTrap have been built!\n"; + } +} + +//! Iterate over the list of GeoTube shape nodes, build them all, +//! and store their pointers +void ReadGeoModel::buildAllShapes_UnidentifiedShape() +{ + // create a builder and reserve size of memory map + size_t nSize = m_shapes_UnidentifiedShape.size(); + m_builderShape_UnidentifiedShape = new BuildGeoShapes_UnidentifiedShape(nSize); + // loop over the DB rows and build the shapes + for (const auto &row : m_shapes_UnidentifiedShape) + { + // GeoModelIO::CppHelper::printStdVectorVariants(row); // DEBUG MSG + m_builderShape_UnidentifiedShape->buildShape(row); + } + // m_builderShape_UnidentifiedShape->printBuiltShapes(); // DEBUG MSG + if (nSize > 0) { + std::cout << "All " << nSize << " Shapes-UnidentifiedShape have been built!\n"; + } +} + //! Iterate over the list of GeoSerialDenominator nodes, build them all, and //! store their pointers void ReadGeoModel::buildAllSerialDenominators() { @@ -443,8 +922,7 @@ void ReadGeoModel::buildAllSerialIdentifiers() { if (m_loglevel >= 1) std::cout << "Building all SerialIdentifier nodes...\n"; size_t nSize = m_serialIdentifiers.size(); - m_memMapSerialIdentifiers.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... + m_memMapSerialIdentifiers.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { // const unsigned int nodeID = std::stoi(m_seriaIdentifiers[ii][0]); // // RMB: not used at the moment, commented to avoid warnings @@ -461,8 +939,7 @@ void ReadGeoModel::buildAllSerialIdentifiers() { void ReadGeoModel::buildAllIdentifierTags() { if (m_loglevel >= 1) std::cout << "Building all IdentifierTag nodes...\n"; size_t nSize = m_identifierTags.size(); - m_memMapIdentifierTags.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... + m_memMapIdentifierTags.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { // const unsigned int nodeID = std::stoi(m_identifierTags[ii][0]); // // RMB: not used at the moment, commented to avoid warnings @@ -479,8 +956,7 @@ void ReadGeoModel::buildAllIdentifierTags() { void ReadGeoModel::buildAllNameTags() { if (m_loglevel >= 1) std::cout << "Building all NameTag nodes...\n"; size_t nSize = m_nameTags.size(); - m_memMapNameTags.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapNameTags.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { // const unsigned int nodeID = std::stoi(m_nameTags[ii][0]); // RMB: // not used at teh moment, commented to avoid warnings @@ -496,10 +972,10 @@ void ReadGeoModel::buildAllNameTags() { void ReadGeoModel::buildAllElements() { if (m_loglevel >= 1) std::cout << "Building all Elements...\n"; size_t nSize = m_elements.size(); - m_memMapElements.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapElements.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int nodeID = std::stoi(m_elements[ii][0]); + // const unsigned int nodeID = std::stoi(m_elements[ii][0]); + const unsigned nodeID = GeoModelHelpers::variantHelper::getFromVariant_Int(m_elements[ii][0], "Element:ID"); buildElement(nodeID); // nodes' IDs start from 1 } if (nSize > 0) @@ -510,10 +986,9 @@ void ReadGeoModel::buildAllElements() { void ReadGeoModel::buildAllMaterials() { if (m_loglevel >= 1) std::cout << "Building all Materials...\n"; size_t nSize = m_materials.size(); - m_memMapMaterials.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapMaterials.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int nodeID = std::stoi(m_materials[ii][0]); + const unsigned nodeID = GeoModelHelpers::variantHelper::getFromVariant_Int(m_materials[ii][0], "MaterialElement:ID"); buildMaterial(nodeID); // nodes' IDs start from 1 } if (nSize > 0) @@ -521,14 +996,46 @@ void ReadGeoModel::buildAllMaterials() { } //! Iterate over the list of nodes, build them all, and store their pointers -void ReadGeoModel::buildAllLogVols() { - if (m_loglevel >= 1) std::cout << "Building all LogVols...\n"; +void ReadGeoModel::buildAllVSurfaces() +{ + if (m_loglevel >= 1) + std::cout << "Building all Virtual Surfaces...\n"; + size_t nSize = m_VSurface.size(); + BuildGeoVSurface* buildsurfTool = new BuildGeoVSurface(); // TODO: change the name of this class + for (unsigned int ii = 0; ii < nSize; ++ii) + { + try + { + const unsigned int nodeID = std::get<int>(m_VSurface[ii][0]); + buildVSurface(nodeID); + } + catch (std::bad_variant_access const &ex) + { + std::cout << ex.what() << ": Virtual Surface 'ID' is not an 'int' value!\n"; + } + } + if (nSize > 0) + std::cout << "All " << nSize << " Virtual Surface have been built!\n"; +} + +//! Iterate over the list of nodes, build them all, and store their pointers +void ReadGeoModel::buildAllLogVols() +{ + if (m_loglevel >= 1) + std::cout << "Building all LogVols...\n"; size_t nSize = m_logVols.size(); - m_memMapLogVols.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int nodeID = std::stoi(m_logVols[ii][0]); - buildLogVol(nodeID); + m_memMapLogVols.reserve(nSize); + for (unsigned int ii = 0; ii < nSize; ++ii) + { + try + { + const unsigned int nodeID = std::get<int>(m_logVols[ii][0]); + buildLogVol(nodeID); + } + catch (std::bad_variant_access const &ex) + { + std::cout << ex.what() << ": logVol 'ID' is not an 'int' value!\n"; + } } if (nSize > 0) std::cout << "All " << nSize << " LogVols have been built!\n"; @@ -552,8 +1059,7 @@ void ReadGeoModel::buildAllPhysVols() { } const unsigned int tableID = m_tableName_toTableID["GeoPhysVol"]; size_t nSize = m_physVols.size(); - m_memMapPhysVols.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapPhysVols.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int volID = std::stoi(m_physVols[ii][0]); const unsigned int logVolID = std::stoi(m_physVols[ii][1]); @@ -570,8 +1076,7 @@ void ReadGeoModel::buildAllFullPhysVols() { if (m_debug) std::cout << "Building all FullPhysVols...\n"; const unsigned int tableID = m_tableName_toTableID["GeoFullPhysVol"]; size_t nSize = m_fullPhysVols.size(); - m_memMapFullPhysVols.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... + m_memMapFullPhysVols.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int volID = std::stoi(m_fullPhysVols[ii][0]); const unsigned int logVolID = std::stoi(m_fullPhysVols[ii][1]); @@ -588,8 +1093,7 @@ void ReadGeoModel::buildAllFullPhysVols() { void ReadGeoModel::buildAllAlignableTransforms() { if (m_debug) std::cout << "Building all AlignableTransforms...\n"; size_t nSize = m_alignableTransforms.size(); - m_memMapAlignableTransforms.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... + m_memMapAlignableTransforms.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int volID = std::stoi(m_alignableTransforms[ii][0]); buildAlignableTransform(volID); @@ -604,8 +1108,7 @@ void ReadGeoModel::buildAllAlignableTransforms() { void ReadGeoModel::buildAllTransforms() { if (m_debug) std::cout << "Building all Transforms...\n"; size_t nSize = m_transforms.size(); - m_memMapTransforms.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... + m_memMapTransforms.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int volID = std::stoi(m_transforms[ii][0]); buildTransform(volID); @@ -619,116 +1122,7 @@ void ReadGeoModel::buildAllTransforms() { void ReadGeoModel::buildAllSerialTransformers() { if (m_debug) std::cout << "Building all SerialTransformers...\n"; size_t nSize = m_serialTransformers.size(); - m_memMapSerialTransformers.reserve( - nSize * 2); // TODO: check if 2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_serialTransformers[ii][0]); - buildSerialTransformer(volID); - } - if (nSize > 0) - std::cout << "All " << nSize - << " SerialTransformers have been built!\n"; -} - -// FIXME: implement build function and cache for Functions -// //! Iterate over the list of nodes, build them all, and store their pointers -// void ReadGeoModel::buildAllFunctions() -// { -// if (m_debug) std::cout << "Building all Functions...\n"; -//// if (m_serialTransformers.size() == 0) { -//// std::cout << "ERROR!!! input SerialTransformers are empty! Exiting..." -///<< std::endl; / exit(EXIT_FAILURE); / } / size_t nSize = -/// m_functions.size(); / m_memMapFunctions.reserve( nSize*2 ); // TODO: check -/// if 2 is good or redundant... / for (unsigned int ii=0; ii<nSize; ++ii) { / -/// buildFunction(ii+1); // nodes' IDs start from 1 / } -// QHash<unsigned int, QStringList>::const_iterator i = -// m_functions.constBegin(); while (i != m_functions.constEnd()) { -// unsigned int id = i.key(); -// buildFunction(id); -// ++i; -// } -// } - -/* -//! Iterate over the list of nodes, build them all, and store their pointers -void ReadGeoModel::buildAllPhysVols() { - if (m_loglevel >= 1) std::cout << "Building all PhysVols...\n"; - if (m_physVols.size() == 0) { - std::cout << "ERROR!!! No input PhysVols found! Exiting..." - << std::endl; - exit(EXIT_FAILURE); - } - const unsigned int tableID = m_tableName_toTableID["GeoPhysVol"]; - size_t nSize = m_physVols.size(); - m_memMapPhysVols.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_physVols[ii][0]); - const unsigned int logVolID = std::stoi(m_physVols[ii][1]); - // std::cout << "building PhysVol n. " << volID << " (logVol: " << - // logVolID << ")" << std::endl; - buildVPhysVol(volID, tableID, logVolID); - } - if (nSize > 0) - std::cout << "All " << nSize << " PhysVols have been built!\n"; -} - -//! Iterate over the list of nodes, build them all, and store their pointers -void ReadGeoModel::buildAllFullPhysVols() { - if (m_loglevel >= 1) std::cout << "Building all FullPhysVols...\n"; - const unsigned int tableID = m_tableName_toTableID["GeoFullPhysVol"]; - size_t nSize = m_fullPhysVols.size(); - m_memMapFullPhysVols.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_fullPhysVols[ii][0]); - const unsigned int logVolID = std::stoi(m_fullPhysVols[ii][1]); - // std::cout << "building PhysVol n. " << volID << " (logVol: " << - // logVolID << ")" << std::endl; - buildVPhysVol(volID, tableID, logVolID); - } - if (nSize > 0) - std::cout << "All " << nSize << " FullPhysVols have been built!\n"; -} - -//! Iterate over the list of GeoAlignableTransforms nodes, build them all, -//! and store their pointers -void ReadGeoModel::buildAllAlignableTransforms() { - if (m_loglevel >= 1) std::cout << "Building all AlignableTransforms...\n"; - size_t nSize = m_alignableTransforms.size(); - m_memMapAlignableTransforms.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_alignableTransforms[ii][0]); - buildAlignableTransform(volID); - } - if (nSize > 0) - std::cout << "All " << nSize - << " AlignableTransforms have been built!\n"; -} - -//! Iterate over the list of GeoTransforms nodes, build them all, and store -//! their pointers -void ReadGeoModel::buildAllTransforms() { - if (m_loglevel >= 1) std::cout << "Building all Transforms...\n"; - size_t nSize = m_transforms.size(); - m_memMapTransforms.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_transforms[ii][0]); - buildTransform(volID); - } - if (nSize > 0) - std::cout << "All " << nSize << " Transforms have been built!\n"; -} - -//! Iterate over the list of GeoTransforms nodes, build them all, and store -//! their pointers -void ReadGeoModel::buildAllSerialTransformers() { - if (m_loglevel >= 1) std::cout << "Building all SerialTransformers...\n"; - size_t nSize = m_serialTransformers.size(); - m_memMapSerialTransformers.reserve( - nSize * 2); // TODO: check if 2 is good or redundant... + m_memMapSerialTransformers.reserve(nSize); for (unsigned int ii = 0; ii < nSize; ++ii) { const unsigned int volID = std::stoi(m_serialTransformers[ii][0]); buildSerialTransformer(volID); @@ -737,8 +1131,6 @@ void ReadGeoModel::buildAllSerialTransformers() { std::cout << "All " << nSize << " SerialTransformers have been built!\n"; } -*/ - // FIXME: implement build function and cache for Functions // //! Iterate over the list of nodes, build them all, and store their @@ -761,9 +1153,7 @@ void ReadGeoModel::buildAllFunctions() { } */ - - -void ReadGeoModel::loopOverAllChildrenInBunches() { +void ReadGeoModel::loopOverAllChildrenInBunches_VecVecData() { int nChildrenRecords = m_allchildren.size(); if (m_loglevel >= 1) std::cout << "number of children to process: " << nChildrenRecords @@ -814,21 +1204,21 @@ void ReadGeoModel::loopOverAllChildrenInBunches() { std::vector<std::future<void>> futures; for (unsigned int bb = 0; bb < nThreads; ++bb) { - std::vector<std::vector<std::string>> bunch; + DBRowsList bunch; unsigned int start = nBunches * bb; int len = nBunches; const unsigned int stop = start + len; - std::vector<std::vector<std::string>>::const_iterator first = + DBRowsList::const_iterator first = m_allchildren.begin() + start; - std::vector<std::vector<std::string>>::const_iterator last = + DBRowsList::const_iterator last = m_allchildren.begin() + stop; - std::vector<std::vector<std::string>>::const_iterator end = + DBRowsList::const_iterator end = m_allchildren.end(); if (bb == (nThreads - 1)) { // last bunch - bunch = std::vector<std::vector<std::string>>(first, end); + bunch = DBRowsList(first, end); } else { // all bunches but last one - bunch = std::vector<std::vector<std::string>>(first, last); + bunch = DBRowsList(first, last); } if (m_loglevel >= 1) { @@ -879,7 +1269,7 @@ void ReadGeoModel::processParentChild( if (m_loglevel >= 2) { muxCout.lock(); std::cout << "\nReadGeoModel::processParentChild()..." << std::endl; - for (auto& rec : parentchild) std::cout << rec << "-"; + for (const auto& rec : parentchild) std::cout << rec << "-"; std::cout << std::endl; muxCout.unlock(); } @@ -921,7 +1311,7 @@ void ReadGeoModel::processParentChild( // build or get parent volume. // Using the parentCopyNumber here, to get a given instance of the // parent volume - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "build/get parent volume...\n"; muxCout.unlock(); @@ -938,6 +1328,9 @@ void ReadGeoModel::processParentChild( GeoFullPhysVol* childNode = dynamic_cast<GeoFullPhysVol*>( buildVPhysVolInstance(childId, childTableId, childCopyN)); volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoVSurface") { + GeoVSurface* childNode = m_memMapVSurface[childId-1]; + volAddHelper(parentVol, childNode); } else if (childNodeType == "GeoSerialDenominator") { GeoSerialDenominator* childNode = getBuiltSerialDenominator(childId); volAddHelper(parentVol, childNode); @@ -972,23 +1365,124 @@ void ReadGeoModel::processParentChild( exit(EXIT_FAILURE); } } +void ReadGeoModel::processParentChild( + const DBRowEntry& parentchild) { + + // if (m_loglevel >= 2) { + // muxCout.lock(); + // std::cout << "\nReadGeoModel::processParentChild()..." << std::endl; + // for (auto& rec : parentchild) std::cout << rec << "-"; + // std::cout << std::endl; + // muxCout.unlock(); + // } + // safety check + if (parentchild.size() < 8) { + std::cout << "ERROR!!! Probably you are using an old geometry file. " + "Please, get a new one. Exiting..." + << std::endl; + exit(EXIT_FAILURE); + } -void ReadGeoModel::volAddHelper(GeoVPhysVol* vol, GeoGraphNode* volChild) { - checkNodePtr(vol, "vol", __func__, __PRETTY_FUNCTION__); - checkNodePtr(volChild, "volChild", __func__, __PRETTY_FUNCTION__); - if (dynamic_cast<GeoPhysVol*>(vol)) { - GeoPhysVol* volume = dynamic_cast<GeoPhysVol*>(vol); - volume->add(volChild); - } else if (dynamic_cast<GeoFullPhysVol*>(vol)) { + // get the parent's details + const unsigned int parentId = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[1], "ParentChild:parentID"); + const unsigned int parentTableId = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[2], "ParentChild:parentID"); + const unsigned int parentCopyN = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[3], "ParentChild:parentID"); + + // get the child's position in the parent's children list + // const unsigned int position = parentchild[4]; // unused, at the moment + + // get the child's details + const unsigned int childTableId = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[5], "ParentChild:parentID"); + const unsigned int childId = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[6], "ParentChild:parentID"); + const unsigned int childCopyN = GeoModelHelpers::variantHelper::getFromVariant_Int(parentchild[7], "ParentChild:parentID"); + + // std::string childNodeType = + // m_tableID_toTableName[childTableId].toStdString(); + std::string childNodeType = m_tableID_toTableName[childTableId]; + + if ("" == childNodeType || 0 == childNodeType.size()) { + std::cout << "ReadGeoModel -- ERROR!!! childNodeType is empty!!! " + "Aborting..." + << std::endl; + exit(EXIT_FAILURE); + } + + GeoVPhysVol* parentVol = nullptr; + + // build or get parent volume. + // Using the parentCopyNumber here, to get a given instance of the + // parent volume + if (m_loglevel >= 3) { + muxCout.lock(); + std::cout << "build/get parent volume...\n"; + muxCout.unlock(); + } + parentVol = dynamic_cast<GeoVPhysVol*>( + buildVPhysVolInstance(parentId, parentTableId, parentCopyN)); + std::string parentName = parentVol->getLogVol()->getName(); + + if (childNodeType == "GeoPhysVol") { + GeoPhysVol* childNode = dynamic_cast<GeoPhysVol*>( + buildVPhysVolInstance(childId, childTableId, childCopyN)); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoFullPhysVol") { + GeoFullPhysVol* childNode = dynamic_cast<GeoFullPhysVol*>( + buildVPhysVolInstance(childId, childTableId, childCopyN)); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoVSurface") { + GeoVSurface* childNode = m_memMapVSurface[childId-1]; + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoSerialDenominator") { + GeoSerialDenominator* childNode = getBuiltSerialDenominator(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoSerialIdentifier") { + GeoSerialIdentifier* childNode = getBuiltSerialIdentifier(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoIdentifierTag") { + GeoIdentifierTag* childNode = getBuiltIdentifierTag(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoAlignableTransform") { + GeoAlignableTransform* childNode = getBuiltAlignableTransform(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoTransform") { + if (m_loglevel >= 2) { + muxCout.lock(); + std::cout << "get transform child...\n"; + muxCout.unlock(); + } + GeoTransform* childNode = getBuiltTransform(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoSerialTransformer") { + GeoSerialTransformer* childNode = getBuiltSerialTransformer(childId); + volAddHelper(parentVol, childNode); + } else if (childNodeType == "GeoNameTag") { + GeoNameTag* childNode = getBuiltNameTag(childId); + volAddHelper(parentVol, childNode); + } else { + std::cout << "[" << childNodeType + << "] ==> ERROR!!! - The conversion for this type of child " + "node needs to be implemented." + << std::endl; + exit(EXIT_FAILURE); + } +} + +void ReadGeoModel::volAddHelper(GeoVPhysVol* vol, GeoGraphNode* volChild) { + checkNodePtr(vol, "vol", __func__, __PRETTY_FUNCTION__); + checkNodePtr(volChild, "volChild", __func__, __PRETTY_FUNCTION__); + if (dynamic_cast<GeoPhysVol*>(vol)) { + GeoPhysVol* volume = dynamic_cast<GeoPhysVol*>(vol); + volume->add(volChild); + } else if (dynamic_cast<GeoFullPhysVol*>(vol)) { GeoFullPhysVol* volume = dynamic_cast<GeoFullPhysVol*>(vol); volume->add(volChild); } } // TODO: to be moved to an utility class -void ReadGeoModel::checkNodePtr(GeoGraphNode* nodePtr, std::string varName, - std::string funcName, - std::string funcSignature) { +void ReadGeoModel::checkNodePtr(GeoGraphNode* nodePtr, const std::string& varName, + const std::string& funcName, + const std::string& funcSignature) { if (!nodePtr) { muxCout.lock(); std::cout << "ERROR! A pointer to a GeoGraphNode instance is NULL {" @@ -1012,7 +1506,7 @@ void ReadGeoModel::checkNodePtr(GeoGraphNode* nodePtr, std::string varName, GeoVPhysVol* ReadGeoModel::buildVPhysVolInstance(const unsigned int id, const unsigned int tableId, const unsigned int copyN) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "ReadGeoModel::buildVPhysVolInstance() - id: " << id << ", tableId: " << tableId << ", copyN: " << copyN @@ -1023,7 +1517,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVolInstance(const unsigned int id, // A - if the instance has been previously built, return that // if ( nullptr != getVPhysVol(id, tableId, copyN)) { if (nullptr != getVPhysVol(id, tableId)) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); // std::cout << "getting the instance volume from memory... // Returning: [" << getVPhysVol(id, tableId, copyN) << "] -- @@ -1058,7 +1552,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVolInstance(const unsigned int id, if (1 == tableId) { if (isBuiltPhysVol(id)) { vol = new GeoPhysVol(getBuiltPhysVol(id)->getLogVol()); - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "PhysVol not instanced yet, building the instance now [" @@ -1095,7 +1589,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVolInstance(const unsigned int id, GeoVPhysVol* ReadGeoModel::buildVPhysVol( const unsigned int id, const unsigned int tableId, unsigned int /*defaults to "0"*/ logVol_ID) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "ReadGeoModel::buildVPhysVol() - " << id << ", " << tableId << std::endl; @@ -1108,7 +1602,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVol( // get the actual VPhysVol volume, if built already if (nodeType == "GeoPhysVol" && isBuiltPhysVol(id)) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "getting the actual PhysVol from cache...\n"; ; @@ -1116,7 +1610,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVol( } return getBuiltPhysVol(id); } else if (nodeType == "GeoFullPhysVol" && isBuiltFullPhysVol(id)) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "getting the actual FullPhysVol from cache...\n"; ; @@ -1143,7 +1637,7 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVol( std::cout << "ERROR!!! LogVol is NULL!" << std::endl; // exit(EXIT_FAILURE); } - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "using the cached LogVol [" << logVol_ID << "] w/ address: " << logVol << "...\n"; @@ -1178,17 +1672,15 @@ GeoVPhysVol* ReadGeoModel::buildVPhysVol( // Get the root volume GeoVPhysVol* ReadGeoModel::getRootVolume() { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "ReadGeoModel::getRootVolume()" << std::endl; - std::cout << "m_root_vol_data: " << m_root_vol_data[0] << ", " << m_root_vol_data[1] << ", " << m_root_vol_data[2] << std::endl; + std::cout << "m_root_vol_data: " << m_root_vol_data.first << ", " << m_root_vol_data.second << std::endl; muxCout.unlock(); } - const unsigned int id = - std::stoi(m_root_vol_data[1]); // TODO: GeoModel GetRoot() should - // return integers instead of strings... - const std::string tableName = m_root_vol_data[0]; - const unsigned int tableId = m_dbManager->getTableIdFromNodeType(tableName); + const unsigned tableId = m_root_vol_data.first; + const unsigned id = m_root_vol_data.second; + // const unsigned int tableId = m_dbManager->getTableIdFromNodeType(tableName); const unsigned int copyNumber = 1; // the Root volume has only one copy by definition GeoVPhysVol* root = buildVPhysVolInstance(id, tableId, copyNumber); @@ -1196,7 +1688,7 @@ GeoVPhysVol* ReadGeoModel::getRootVolume() { return root; } -GeoMaterial* ReadGeoModel::buildMaterial(const unsigned int id) { +GeoMaterial* ReadGeoModel::buildMaterial(const unsigned id) { if (isBuiltMaterial(id)) { return getBuiltMaterial(id); } @@ -1206,43 +1698,49 @@ GeoMaterial* ReadGeoModel::buildMaterial(const unsigned int id) { std::cout << "ReadGeoModel::buildMaterial()" << std::endl; muxCout.unlock(); } - std::vector<std::string> values = m_materials[id - 1]; - const unsigned int matId = std::stoi(values[0]); - const std::string matName = values[1]; - double matDensity = std::stod(values[2]); - std::string matElements = values[3]; + DBRowEntry values = m_materials[id - 1]; + const unsigned int matId = GeoModelHelpers::variantHelper::getFromVariant_Int(values[0], "Material:id"); + const std::string matName = GeoModelHelpers::variantHelper::getFromVariant_String(values[1], "Material:matName"); + const double matDensity = GeoModelHelpers::variantHelper::getFromVariant_Double(values[2], "Material:matDensity"); + const unsigned dataStart = GeoModelHelpers::variantHelper::getFromVariant_Int(values[3], "Material:dataStart"); + const unsigned dataEnd = GeoModelHelpers::variantHelper::getFromVariant_Int(values[4], "Material:dataEnd"); - if (m_loglevel >= 2) { + // debug msg + if (m_loglevel >= 3) { muxCout.lock(); - std::cout << "\tMaterial - ID:" << matId << ", name:" << matName + std::cout << "\tbuildMaterial() : Material - ID:" << matId << ", name:" << matName << ", density:" << matDensity << " ( " << matDensity / (SYSTEM_OF_UNITS::g / SYSTEM_OF_UNITS::cm3) << "[g/cm3] )" - << ", elements:" << matElements; + << ", elements: dataStart: " << dataStart << ", dataEnd: " << dataEnd; muxCout.unlock(); } GeoMaterial* mat = new GeoMaterial(matName, matDensity); + DBRowsList matElements(m_materials_Data.begin() + (dataStart-1), + m_materials_Data.begin() + (dataEnd) ); + if (matElements.size() > 0) { - // get parameters from DB string - const std::vector<std::string> elements = splitString(matElements, ';'); - for (auto& par : elements) { - if (m_loglevel >= 2) { - muxCout.lock(); - std::cout << "par: " << par << std::endl; - muxCout.unlock(); - } - std::vector<std::string> vars = splitString(par, ':'); - const unsigned int elId = std::stoi(vars[0]); - double elFraction = std::stod(vars[1]); + // get parameters from DB + + // const std::vector<std::string> elements = splitString(matElements, ';'); + for (const auto& row : matElements) { + // if (m_loglevel >= 2) { + // muxCout.lock(); + // std::cout << "par: " << par << std::endl; + // muxCout.unlock(); + // } + // std::vector<std::string> vars = splitString(par, ':'); + const unsigned elId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[1], "MatElement:id"); + double elFraction = GeoModelHelpers::variantHelper::getFromVariant_Double(row[2], "MatElement:fraction"); // GeoElement* el = buildElement(elId); GeoElement* el = getBuiltElement(elId); mat->add(el, elFraction); } mat->lock(); - } + } storeBuiltMaterial(mat); return mat; } @@ -1258,18 +1756,19 @@ GeoElement* ReadGeoModel::buildElement(const unsigned int id) { muxCout.unlock(); } - if (m_elements.size() == 0) - std::cout << "ERROR! 'm_elements' is empty! Did you load the " - "'Elements' table? \n\t ==> Aborting...\n" - << std::endl; + // if (m_elements.size() == 0) + // std::cout << "ERROR! 'm_elements' is empty! Did you load the " + // "'Elements' table? \n\t ==> Aborting...\n" + // << std::endl; - std::vector<std::string> values = m_elements[id - 1]; + // std::vector<std::string> values = m_elements[id - 1]; + DBRowEntry values = m_elements[id - 1]; - const unsigned int elId = std::stoi(values[0]); - std::string elName = values[1]; - std::string elSymbol = values[2]; - double elZ = std::stod(values[3]); - double elA = std::stod(values[4]); + const unsigned elId = GeoModelHelpers::variantHelper::getFromVariant_Int(values[0], "Element:ID"); //values[0]; + std::string elName = GeoModelHelpers::variantHelper::getFromVariant_String(values[1], "Element:name"); // values[1]; + std::string elSymbol = GeoModelHelpers::variantHelper::getFromVariant_String(values[2], "Element:symbol"); //values[2]; + double elZ = GeoModelHelpers::variantHelper::getFromVariant_Double(values[3], "Element:Z"); //std::stod(values[3]); + double elA = GeoModelHelpers::variantHelper::getFromVariant_Double(values[4], "Element:A"); //std::stod(values[4]); if (m_loglevel >= 2) { muxCout.lock(); @@ -1298,6 +1797,230 @@ std::string ReadGeoModel::getShapeType(const unsigned int shapeId) { return type; } +GeoShape *ReadGeoModel::buildShapeOperator(const std::string_view shapeType, const DBRowEntry& row, + boolean_shapes_operands_info *shapes_info_sub) +{ + GeoShape *shape = nullptr; + unsigned shapeId{0}; + + if ("Shift" == shapeType) + { + // metadata + shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Shift:shapeID"); + // computed volume (not defined by default) + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Shift:shapeVolume"); + // shape parameters + const std::string shapeOpType = GeoModelHelpers::variantHelper::getFromVariant_String(row[2], "Shift:shapeType"); + const unsigned shapeOpId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[3], "Shift:shapeId"); + const unsigned transfId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[4], "Shift:transformId"); + if (shapeOpId == 0 || transfId == 0) + { + THROW_EXCEPTION("ERROR!!! Shift shape - input operand shapes' IDs are empty!"); + } + + // if both operands are built already, + // then get them from cache, + // and build the operator shape with them, + if (isBuiltShape(shapeOpType, shapeOpId) && isBuiltTransform(transfId)) + { + const GeoShape *shapeOp = getBuiltShape(shapeOpId, shapeOpType); + const GeoTransform *transf = getBuiltTransform(transfId); + if( nullptr == shapeOp || nullptr == transf) { + std::cout << "'Shift' debug -- shapeOpType: " << shapeOpType << ", shapeOpId: " << shapeOpId << ", transfId: " << transfId << std::endl; + THROW_EXCEPTION("ERROR!!! Shape operand or Transformation are NULL!"); + } + // TODO: here we create a fake GeoTransform to get a + // GeoTrf::Transform3D. + // TODO: ==> Perhaps we could keep a table for bare + // GeoTrf::Transform3D transforms used in GeoShift nodes. + GeoTrf::Transform3D transfX = transf->getTransform(); + transf->unref(); // delete the transf from the heap, because we + // don't need the node, only the bare + // transformation matrix + GeoShapeShift *shapeNew = new GeoShapeShift(shapeOp, transfX); + // storeBuiltShape(shapeId, shapeNew); + shape = shapeNew; + } + // else { + // THROW_EXCEPTION("Operand shapes have not been built!"); + // } + // otherwise, build the operands + else + { + // TODO: IMPORTANT!!! --> check how the transf used in shift are + // saved into the DB, because they are bare transf and not + // GeoTransform nodes... + + // first, check if the transform is built; + // if so, use that; + // if not, build the transform + + // get the referenced Transform, then get the bare transform matrix + // from it + GeoTransform *transf = nullptr; + GeoTrf::Transform3D transfX; + // if (isBuiltTransform(transfId)) + // { + // transf = getBuiltTransform(transfId); + // } + // else + // { + transf = buildTransform(transfId); + // } + // TODO: here we create a fake GeoTransform to get a + // GeoTrf::Transform3D. + // TODO: ==> Perhaps we could keep a table for bare + // GeoTrf::Transform3D transforms used in GeoShift nodes. + transfX = transf->getTransform(); + transf->unref(); // delete the transf from the heap, because we + // don't need the GeoGraph node, only the bare + // transformation matrix + + // then, check the type of the operand shape + bool isOperatorShape = isShapeOperator(shapeOpType); + + // if operand shape is simple/actual shape (i.e., not + // boolean/operator), then build it, + // and then build the boolean shape with that + if (!isOperatorShape) + { + const GeoShape *shapeOp = + getBuiltShape(shapeOpId, shapeOpType); + + if (shapeOp == nullptr || transf == nullptr) + { + std::cout << "ERROR!!! Shift - shapeOp or transfX are " + "NULL! Exiting..." + << std::endl; + exit(EXIT_FAILURE); + } + // GeoShapeShift *shapeNew = new GeoShapeShift(shapeOp, transfX); + shape = new GeoShapeShift(shapeOp, transfX); + } + // ...otherwise, build the Shift operator shape without operands + // and save the needed pieces of information to build the actual + // operands and shape later. + else + { + GeoShapeShift *shapeNew = new GeoShapeShift(); + tuple_boolean_shapes_operands tt(std::string(shapeType), shapeId, shapeNew, shapeOpType, shapeOpId, "NULL", + transfId); // We set opBType to NULL because for Shift we don't need/use it. + shapes_info_sub->push_back( + tt); //! Push the information about the new boolean shape + //! at the end of the very same container we are + //! iterating over + shape = shapeNew; + } + } + + + //! store into the cache the shape we have just built, + //! for later use when referenced by another node + // storeBuiltShapeOperators_Shift(shapeId, shape); + } + else if ("Subtraction" == shapeType || "Union" == shapeType || + "Intersection" == shapeType) { + // Check what shapes are subtracted/united/intersected: + // - If they are actual shapes, build them and return + // - If they are boolean/operator shapes, then store the shape for later + // and continue + + // metadata + shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[0], "Boolean:shapeID"); + // computed volume (not defined by default) + const double shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(row[1], "Boolean:shapeVolume"); + // shape operands + const std::string shapeOpAType = GeoModelHelpers::variantHelper::getFromVariant_String(row[2], "Boolean:shapeType"); + const unsigned shapeOpAId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[3], "Boolean:shapeId"); + const std::string shapeOpBType = GeoModelHelpers::variantHelper::getFromVariant_String(row[4], "Boolean:shapeType"); + const unsigned shapeOpBId = GeoModelHelpers::variantHelper::getFromVariant_Int(row[5], "Boolean:shapeId"); + if ( ! shapeOpAId || ! shapeOpBId ) + { + THROW_EXCEPTION("ERROR!!! Shift shape - input operand shapes' IDs are empty!"); + } + + // if both operands are built already, + // then get them from cache, and build the operator with them + if (isBuiltShape(shapeOpAType, shapeOpAId) && isBuiltShape(shapeOpBType, shapeOpBId)) + { + GeoShape *shapeNew = nullptr; + const GeoShape *shapeA = getBuiltShape(shapeOpAId, shapeOpAType); + const GeoShape *shapeB = getBuiltShape(shapeOpBId, shapeOpBType); + if ("Subtraction" == shapeType) + shape = new GeoShapeSubtraction(shapeA, shapeB); + else if ("Union" == shapeType) + shape = new GeoShapeUnion(shapeA, shapeB); + else if ("Intersection" == shapeType) + shape = new GeoShapeIntersection(shapeA, shapeB); + } + // else { + // THROW_EXCEPTION("Operand shapes have not been built!"); + // } + + // otherwise, build the operand shapes... + else { + // first check the operands' type + bool isAOperator = isShapeOperator(shapeOpAType); + bool isBOperator = isShapeOperator(shapeOpBType); + + // if both are simple/actual shapes (i.e., not booleans), + // build them, then build the boolean shape with them, and + // store that. + // TODO: I suspect that this snippet below in the IF clause is dead code, + // it's never reached. + if (!isAOperator && !isBOperator) { + const GeoShape* shapeA = getBuiltShape(shapeOpAId, shapeOpAType); + const GeoShape* shapeB = getBuiltShape(shapeOpAId, shapeOpBType); + if (shapeA == NULL || shapeB == NULL) + { + THROW_EXCEPTION("ERROR!!! shapeA or shapeB are NULL!"); + } + + GeoShape* shapeNew = nullptr; + if ("Subtraction" == shapeType) { + shapeNew = new GeoShapeSubtraction(shapeA, shapeB); + } else if ("Union" == shapeType) { + shapeNew = new GeoShapeUnion(shapeA, shapeB); + } else if ("Intersection" == shapeType) { + shapeNew = new GeoShapeIntersection(shapeA, shapeB); + } + + shape = shapeNew; + } + // ...otherwise, build the boolean shape without + // operands and save the needed pieces of information to build the + // actual operands and shape later. + else { + GeoShape* shapeNew = nullptr; + if ("Subtraction" == shapeType) { + shapeNew = new GeoShapeSubtraction; + } else if ("Union" == shapeType) { + shapeNew = new GeoShapeUnion; + } else if ("Intersection" == shapeType) { + shapeNew = new GeoShapeIntersection; + } + + tuple_boolean_shapes_operands tt(std::string(shapeType), shapeId, shapeNew, shapeOpAType, shapeOpAId, shapeOpBType, + shapeOpBId); + //! Push the information about the new boolean shape + //! at the end of the very same container we are + //! iterating over + shapes_info_sub->push_back(tt); + shape = shapeNew; + } + } + + } + else { + THROW_EXCEPTION("ERROR!!! Shape type not defined/handled: '" + std::string(shapeType) + "'!"); + } + + //! store into the cache the shape we have just built, + //! for later use when referenced by another node + storeBuiltShape(shapeType, shapeId, shape); + return shape; +} + // TODO: move shapes in different files, so code here is more managable /// Recursive function, to build GeoShape nodes GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, @@ -1327,611 +2050,61 @@ GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, GeoShape* shape = nullptr; - if (type == "Box") { - // shape parameters - double XHalfLength = 0.; - double YHalfLength = 0.; - double ZHalfLength = 0.; - // get parameters from DB string - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "XHalfLength") - XHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "YHalfLength") - YHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoBox(XHalfLength, YHalfLength, ZHalfLength); - } else if (type == "Cons") { - // shape parameters - double RMin1 = 0.; - double RMin2 = 0.; - double RMax1 = 0.; - double RMax2 = 0.; - double DZ = 0.; - double SPhi = 0.; - double DPhi = 0.; - // get parameters from DB string - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - // std::cout << "varValue Cons:" << varValue; - if (varName == "RMin1") - RMin1 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "RMin2") - RMin2 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "RMax1") - RMax1 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "RMax2") - RMax2 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DZ") - DZ = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "SPhi") - SPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DPhi") - DPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoCons(RMin1, RMin2, RMax1, RMax2, DZ, SPhi, DPhi); - } else if (type == "Torus") { - // Member Data: - // * Rmax - outside radius of the torus tube - // * Rmin - inside radius of the torus tube (Rmin=0 if not hollow) - // * Rtor - radius of the torus itself - // * - // * SPhi - starting angle of the segment in radians - // * DPhi - delta angle of the segment in radians - // - // shape parameters - double Rmin = 0.; - double Rmax = 0.; - double Rtor = 0.; - double SPhi = 0.; - double DPhi = 0.; - // get parameters from DB string - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "Rmin") - Rmin = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Rmax") - Rmax = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Rtor") - Rtor = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "SPhi") - SPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DPhi") - DPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoTorus(Rmin, Rmax, Rtor, SPhi, DPhi); - } else if (type == "Para") { - // shape parameters - double XHalfLength = 0.; - double YHalfLength = 0.; - double ZHalfLength = 0.; - double Alpha = 0.; - double Theta = 0.; - double Phi = 0.; - // get parameters from DB string - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "XHalfLength") - XHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "YHalfLength") - YHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Alpha") - Alpha = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Theta") - Theta = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Phi") - Phi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoPara(XHalfLength, YHalfLength, ZHalfLength, Alpha, Theta, - Phi); - } else if (type == "Pcon") { + if (false) { + } + else if (type == "TessellatedSolid") { + // Tessellated pars example: + // "nFacets=1;TRI;vT=ABSOLUTE;nV=3;xV=0;yV=0;zV=1;xV=0;yV=1;zV=0;xV=1;yV=0;zV=0" + std::cout << "Reading-in: TessellatedSolid: "; // debug + // Facet type + std::string facetType = ""; // shape parameters - double SPhi = 0.; - double DPhi = 0.; - unsigned int NZPlanes = 0; + unsigned int nFacets = 0; bool error = 0; + GeoTessellatedSolid* sh = nullptr; + std::string par; std::vector<std::string> vars; std::string varName; std::string varValue; - GeoPcon* pcon = nullptr; - int sizePars = shapePars.size(); - // check if we have more than 3 parameters - if (sizePars > 3) { - // get the three first GeoPcon parameters: the SPhi and DPhi angles, - // plus the number of Z planes - for (int it = 0; it < 3; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "SPhi") SPhi = std::stod(varValue); - if (varName == "DPhi") DPhi = std::stod(varValue); - if (varName == "NZPlanes") NZPlanes = std::stoi(varValue); + // check if we have at least 13 parameters, + // which is the minimum for a shape + // with a single triangular facet + if (sizePars >= 13) { + // get the first parameter + par = shapePars[0]; + vars = splitString(par, '='); + varName = vars[0]; + varValue = vars[1]; + if (varName == "nFacets") + nFacets = std::stoi(varValue); + else { + muxCout.lock(); + // qWarning("ERROR!! - GeoTessellatedSolid - nFacets is + // not defined!!"); + muxCout.unlock(); + error = true; // TODO: check "error.h" functionalities and + // replace with that, if useful } - // build the basic GeoPcon shape - pcon = new GeoPcon(SPhi, DPhi); - // and now loop over the rest of the list, to get the parameters of - // all Z planes - for (int it = 3; it < sizePars; it++) { + // build the basic GeoTessellatedSolid shape + sh = new GeoTessellatedSolid(); + + // and now loop over the rest of the list, + // to get the parameters of the vertices of each facet + // and to build the full GeoTessellatedSolid with all the facets + for (int it = 1; it < sizePars; it++) { + // get facet type par = shapePars[it]; vars = splitString(par, '='); varName = vars[0]; - varValue = vars[1]; - - if (varName == "ZPos") { - double zpos = std::stod(varValue); - double rmin = 0., rmax = 0.; - - it++; // go to next variable - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "ZRmin") - rmin = std::stod(varValue); - else - error = 1; - it++; // go to next variable - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "ZRmax") - rmax = std::stod(varValue); - else - error = 1; - - if (error) { - muxCout.lock(); - std::cout << "ERROR! GeoPcon 'ZRmin' and 'ZRmax' " - "values are not at the right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - - // add a Z plane to the GeoPcon - pcon->addPlane(zpos, rmin, rmax); - } else { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPcon 'ZPos' value is not at the " - "right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } - - // sanity check on the resulting Pcon shape - if (pcon->getNPlanes() != NZPlanes) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPcon number of planes: " - << pcon->getNPlanes() - << " is not equal to the original size! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - if (!pcon->isValid()) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPcon shape is not valid!! -- input: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } // end if (size>3) - else { - muxCout.lock(); - std::cout << "ERROR!! GeoPcon has no Z planes!! --> shape input " - "parameters: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - error = 1; - } - - if (error) { - muxCout.lock(); - std::cout << "FATAL ERROR!!! - GeoPcon shape error!!! Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - - shape = pcon; - } else if (type == "Pgon") { - // shape parameters - double SPhi = 0.; - double DPhi = 0.; - unsigned int NSides = 0; - unsigned int NZPlanes = 0; - - bool error = false; - GeoPgon* pgon = nullptr; - - std::string par; - std::vector<std::string> vars; - std::string varName; - std::string varValue; - - int sizePars = shapePars.size(); - // check if we have more than 3 parameters - if (sizePars > 3) { - // get the first four GeoPgon parameters: the SPhi and DPhi angles, - // plus the number of Z planes - for (int it = 0; it < 4; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - // qInfo() << "vars: " << vars; // for debug only - if (varName == "SPhi") SPhi = std::stod(varValue); - if (varName == "DPhi") DPhi = std::stod(varValue); - if (varName == "NSides") NSides = std::stoi(varValue); - if (varName == "NZPlanes") NZPlanes = std::stoi(varValue); - } - // build the basic GeoPgon shape - pgon = new GeoPgon(SPhi, DPhi, NSides); - - // and now loop over the rest of the list, to get the parameters of - // all Z planes - for (int it = 4; it < sizePars; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - - if (varName == "ZPos") { - double zpos = std::stod(varValue); - double rmin = 0., rmax = 0.; - - it++; // go to next variable - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "ZRmin") - rmin = std::stod(varValue); - else - error = 1; - it++; // go to next variable - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "ZRmax") - rmax = std::stod(varValue); - else - error = 1; - - if (error) { - muxCout.lock(); - std::cout << "ERROR! GeoPgon 'ZRmin' and 'ZRmax' " - "values are not at the right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - - // add a Z plane to the GeoPgon - pgon->addPlane(zpos, rmin, rmax); - } else { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPgon 'ZPos' value is not at the " - "right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } - - // sanity check on the resulting Pgon shape - if (pgon->getNPlanes() != NZPlanes) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPgon number of planes: " - << pgon->getNPlanes() - << " is not equal to the original size! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - if (!pgon->isValid()) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoPgon shape is not valid!! -- input: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } // end if (size>3) - else { - muxCout.lock(); - std::cout << "ERROR!! GeoPgon has no Z planes!! --> shape input " - "parameters: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - error = 1; - } - if (error) { - muxCout.lock(); - std::cout << "FATAL ERROR!!! - GeoPgon shape error!!! Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = pgon; - } else if (type == "GenericTrap") { - // shape parameters - double ZHalfLength = 0.; - unsigned int NVertices = 0; - GeoGenericTrapVertices Vertices; - bool error = false; - GeoGenericTrap* gTrap = nullptr; - - std::string par; - std::vector<std::string> vars; - std::string varName; - std::string varValue; - - int sizePars = shapePars.size(); - // check if we have more than 3 parameters - if (sizePars > 3) { - // get the two GeoGenericTrap parameters: the ZHalfLength plus the - // number of vertices - for (int it = 0; it < 2; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - // qInfo() << "vars: " << vars; // for debug only - if (varName == "ZHalfLength") ZHalfLength = std::stod(varValue); - if (varName == "NVertices") NVertices = std::stoi(varValue); - } - - // and now loop over the rest of the list, to get the parameters of - // all Z planes - for (unsigned it = 2; it < NVertices * 2 + 1; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - - if (varName == "X") { - double x = std::stod(varValue); - - it++; // go to next variable - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "Y") { - double y = std::stod(varValue); - Vertices.push_back(GeoTwoVector(x, y)); - } else { - error = 1; - } - if (error) { - muxCout.lock(); - std::cout << "ERROR! GeoGenericTrap 'X' and 'Y' values " - "are not at the right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } else { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoGenericTrap 'ZPos' value is not at " - "the right place! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } - if (error) { - muxCout.lock(); - std::cout << "FATAL ERROR!!! - GeoGenericTrap shape error!!! " - "Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - // build the basic GenericTrap shape - gTrap = new GeoGenericTrap(ZHalfLength, Vertices); - } // end if (size>3) - else { - muxCout.lock(); - std::cout << "ERROR!! GeoGenericTrap has no Z vertices!! --> shape " - "input parameters: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - error = 1; - } - if (error) { - muxCout.lock(); - std::cout - << "FATAL ERROR!!! - GeoGenericTrap shape error!!! Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = gTrap; - } else if (type == "SimplePolygonBrep") { - // shape parameters - double DZ = 0.; - unsigned int NVertices = 0; - double xV = 0.; - double yV = 0.; - - bool error = 0; - GeoSimplePolygonBrep* sh = nullptr; - - std::string par; - std::vector<std::string> vars; - std::string varName; - std::string varValue; - - int sizePars = shapePars.size(); - // check if we have more than 2 parameters - if (sizePars > 2) { - // get the first two GeoSimplePolygonBrep parameters: DZ and the - // number of vertices. - for (int it = 0; it < 2; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "DZ") DZ = std::stod(varValue); - if (varName == "NVertices") NVertices = std::stoi(varValue); - // else if (varName == "NVertices") NVertices = - // varValue.toDouble(); else error = 1; if(error) std::cout << - // "ERROR! GeoSimplePolygonBrep parameters are not correctly - // stored! -->" << vars; - } - // build the basic GeoSimplePolygonBrep shape - sh = new GeoSimplePolygonBrep(DZ); - - // and now loop over the rest of the list, to get the parameters of - // all vertices - for (int it = 2; it < sizePars; it++) { - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "xV") - xV = std::stod(varValue); - else - error = 1; - - it++; // go to next variable (they come in pairs) - - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "yV") - yV = std::stod(varValue); - else - error = 1; - - if (error) { - muxCout.lock(); - std::cout << "ERROR! GeoSimplePolygonBrep 'xVertex' and " - "'yVertex' values are not at the right place! " - "--> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - - // add a Z plane to the GeoSimplePolygonBrep - sh->addVertex(xV, yV); - } - // sanity check on the resulting shape - if (sh->getNVertices() != NVertices) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoSimplePolygonBrep number of planes: " - << sh->getNVertices() - << " is not equal to the original size! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - if (!sh->isValid()) { - error = 1; - muxCout.lock(); - std::cout << "ERROR! GeoSimplePolygonBrep shape is not valid!! " - "-- input: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - } // end if (size>3) - else { - muxCout.lock(); - std::cout << "ERROR!! GeoSimplePolygonBrep has no vertices!! --> " - "shape input parameters: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - error = 1; - } - if (error) { - muxCout.lock(); - std::cout << "FATAL ERROR!!! - GeoSimplePolygonBrep shape error!!! " - "Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = sh; - - } else if (type == "TessellatedSolid") { - // Tessellated pars example: - // "nFacets=1;TRI;vT=ABSOLUTE;nV=3;xV=0;yV=0;zV=1;xV=0;yV=1;zV=0;xV=1;yV=0;zV=0" - std::cout << "Reading-in: TessellatedSolid: "; // debug - // Facet type - std::string facetType = ""; - // shape parameters - unsigned int nFacets = 0; - - bool error = 0; - GeoTessellatedSolid* sh = nullptr; - - std::string par; - std::vector<std::string> vars; - std::string varName; - std::string varValue; - - int sizePars = shapePars.size(); - // check if we have at least 13 parameters, - // which is the minimum for a shape - // with a single triangular facet - if (sizePars >= 13) { - // get the first parameter - par = shapePars[0]; - vars = splitString(par, '='); - varName = vars[0]; - varValue = vars[1]; - if (varName == "nFacets") - nFacets = std::stoi(varValue); - else { - muxCout.lock(); - // qWarning("ERROR!! - GeoTessellatedSolid - nFacets is - // not defined!!"); - muxCout.unlock(); - error = true; // TODO: check "error.h" functionalities and - // replace with that, if useful - } - - // build the basic GeoTessellatedSolid shape - sh = new GeoTessellatedSolid(); - - // and now loop over the rest of the list, - // to get the parameters of the vertices of each facet - // and to build the full GeoTessellatedSolid with all the facets - for (int it = 1; it < sizePars; it++) { - // get facet type - par = shapePars[it]; - vars = splitString(par, '='); - varName = vars[0]; - if (varName == "QUAD") { - facetType = "QUAD"; - } else if (varName == "TRI") { - facetType = "TRI"; + if (varName == "QUAD") { + facetType = "QUAD"; + } else if (varName == "TRI") { + facetType = "TRI"; } else { muxCout.lock(); std::cout << "ERROR!! - GeoTessellatedSolid - Facet type " @@ -2146,486 +2319,39 @@ GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, error = 1; muxCout.lock(); std::cout << "ERROR! GeoTessellatedSolid number of facets: " - << sh->getNumberOfFacets() - << " is not equal to the original size! --> "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - } - /* - * TODO: uncomment it, when the isValid() method will be implemented - for GeoTessellatedSolid if(!sh->isValid()) { error = 1; std::cout << - "ERROR! GeoTessellatedSolid shape is not valid!! -- input: " << - shapePars; - } - */ - } // END OF if (size>13) - else { - muxCout.lock(); - std::cout << "ERROR!! GeoTessellatedSolid has no facets!! --> " - "shape input parameters: "; - printStdVectorStrings(shapePars); - muxCout.unlock(); - error = 1; - } - if (error) { - muxCout.lock(); - std::cout << "GeoTessellatedSolid shape error!!! Aborting..." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = sh; - - } else if (type == "Trap") { - // shape constructor parameters - double ZHalfLength = 0.; - double Theta = 0.; - double Phi = 0.; - double Dydzn = 0.; - double Dxdyndzn = 0.; - double Dxdypdzn = 0.; - double Angleydzn = 0.; - double Dydzp = 0.; - double Dxdyndzp = 0.; - double Dxdypdzp = 0.; - double Angleydzp = 0.; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Theta") - Theta = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Phi") - Phi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dydzn") - Dydzn = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dxdyndzn") - Dxdyndzn = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dxdypdzn") - Dxdypdzn = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Angleydzn") - Angleydzn = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dydzp") - Dydzp = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dxdyndzp") - Dxdyndzp = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Dxdypdzp") - Dxdypdzp = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Angleydzp") - Angleydzp = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoTrap(ZHalfLength, Theta, Phi, Dydzn, Dxdyndzn, Dxdypdzn, - Angleydzn, Dydzp, Dxdyndzp, Dxdypdzp, Angleydzp); - } else if (type == "TwistedTrap") { - // shape constructor parameters - double PhiTwist = 0; - double ZHalfLength = 0.; - double Theta = 0.; - double Phi = 0.; - double DY1HalfLength = 0.; - double DX1HalfLength = 0.; - double DX2HalfLength = 0.; - double DY2HalfLength = 0.; - double DX3HalfLength = 0.; - double DX4HalfLength = 0.; - double DTiltAngleAlpha = 0.; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "PhiTwist") PhiTwist = std::stod(varValue); // angle - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "Theta") Theta = std::stod(varValue); // angle - if (varName == "Phi") Phi = std::stod(varValue); // angle - if (varName == "DY1HalfLength") - DY1HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DX1HalfLength") - DX1HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DX2HalfLength") - DX2HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DY2HalfLength") - DY2HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DX3HalfLength") - DX3HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DX4HalfLength") - DX4HalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DTiltAngleAlpha") - DTiltAngleAlpha = std::stod(varValue); // angle - } - shape = - new GeoTwistedTrap(PhiTwist, ZHalfLength, Theta, Phi, DY1HalfLength, - DX1HalfLength, DX2HalfLength, DY2HalfLength, - DX3HalfLength, DX4HalfLength, DTiltAngleAlpha); - } else if (type == "Trd") { - // shape constructor parameters - double XHalfLength1 = 0.; - double XHalfLength2 = 0.; - double YHalfLength1 = 0.; - double YHalfLength2 = 0.; - double ZHalfLength = 0.; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - // std::cout << "varValue:" << varValue; - if (varName == "XHalfLength1") - XHalfLength1 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "XHalfLength2") - XHalfLength2 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "YHalfLength1") - YHalfLength1 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "YHalfLength2") - YHalfLength2 = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoTrd(XHalfLength1, XHalfLength2, YHalfLength1, - YHalfLength2, ZHalfLength); - } else if (type == "Tube") { - // shape parameters - double RMin = 0.; - double RMax = 0.; - double ZHalfLength = 0.; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "RMin") - RMin = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "RMax") - RMax = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoTube(RMin, RMax, ZHalfLength); - } else if (type == "Tubs") { - // shape parameters - double RMin = 0.; - double RMax = 0.; - double ZHalfLength = 0.; - double SPhi = 0.; - double DPhi = 0.; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "RMin") - RMin = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "RMax") - RMax = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "ZHalfLength") - ZHalfLength = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "SPhi") - SPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - if (varName == "DPhi") - DPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - } - shape = new GeoTubs(RMin, RMax, ZHalfLength, SPhi, DPhi); - } else if (type == "Shift") { - // shape parameters - unsigned int shapeOpId = 0; - unsigned int transfId = 0; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "A") shapeOpId = std::stoi(varValue); - if (varName == "X") transfId = std::stoi(varValue); - } - if (shapeOpId == 0 || transfId == 0) { - std::cout << "ERROR! Shift shape - input operand shapes' IDs are " - "empty! (shapeId: " - << shapeOpId << ", transfId:" << transfId << ")" - << std::endl; - exit(EXIT_FAILURE); - } - - // if both operands are built already, - // then get them from cache, - // and build the operator shape with them, - if (isBuiltShape(shapeOpId) && isBuiltTransform(transfId)) { - const GeoShape* shapeOp = getBuiltShape(shapeOpId); - const GeoTransform* transf = getBuiltTransform(transfId); - // TODO: here we create a fake GeoTransform to get a - // GeoTrf::Transform3D. - // TODO: ==> Perhaps we could keep a table for bare - // GeoTrf::Transform3D transforms used in GeoShift nodes. - GeoTrf::Transform3D transfX = transf->getTransform(); - transf->unref(); // delete the transf from the heap, because we - // don't need the node, only the bare - // transformation matrix - GeoShapeShift* shapeNew = new GeoShapeShift(shapeOp, transfX); - storeBuiltShape(shapeId, shapeNew); - shape = shapeNew; - } - // otherwise, build the operands - else { - // TODO: IMPORTANT!!! --> check how the transf used in shift are - // saved into the DB, because they are bare transf and not - // GeoTransform nodes... - - // first, check if the transform is built; - // if so, use that; - // if not, build the transform - - // get the referenced Transform, then get the bare transform matrix - // from it - GeoTransform* transf = nullptr; - GeoTrf::Transform3D transfX; - if (isBuiltTransform(transfId)) { - transf = getBuiltTransform(transfId); - } else { - transf = buildTransform(transfId); - } - // TODO: here we create a fake GeoTransform to get a - // GeoTrf::Transform3D. - // TODO: ==> Perhaps we could keep a table for bare - // GeoTrf::Transform3D transforms used in GeoShift nodes. - transfX = transf->getTransform(); - transf->unref(); // delete the transf from the heap, because we - // don't need the node, only the bare - // transformation matrix - - // then, check the type of the operand shape - bool isAOperator = isShapeOperator(shapeOpId); - - // if operand shape is simple/actual shape (i.e., not - // boolean/operator), then build it, then build the boolean shape - // with that - if (!isAOperator) { - const GeoShape* shapeOp = - buildShape(shapeOpId, shapes_info_sub); - - if (shapeOp == nullptr || transf == nullptr) { - std::cout << "ERROR!!! Shift - shapeOp or transfX are " - "NULL! Exiting..." - << std::endl; - exit(EXIT_FAILURE); - } - GeoShapeShift* shapeNew = new GeoShapeShift(shapeOp, transfX); - shape = shapeNew; - } - // ...otherwise, build the Shift operator shape without operands - // and save the needed pieces of information to build the actual - // operands and shape later. - else { - GeoShapeShift* shapeNew = new GeoShapeShift(); - tuple_shapes_boolean_info tt(shapeId, shapeNew, shapeOpId, - transfId); - shapes_info_sub->push_back( - tt); //! Push the information about the new boolean shape - //! at the end of the very same container we are - //! iterating over - shape = shapeNew; - } - } - } else if (type == "Subtraction" || type == "Union" || - type == "Intersection") { - // Check what shapes are subtracted/united/intersected: - // - If they are actual shapes, build them and return - // - If they are boolean/operator shapes, then store the shape for later - // and continue - - // shape's operands - unsigned int opA = 0; - unsigned int opB = 0; - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "opA") opA = std::stoi(varValue); - if (varName == "opB") opB = std::stoi(varValue); - } - if (opA == 0 || opB == 0) { - std::cout << "ERROR! Subtraction/Union/Intersection shape - input " - "operand shapes' IDs are empty! (opA: " - << opA << ", opB:" << opB << ")" << std::endl; - exit(EXIT_FAILURE); - } - - // if both operands are built already, - // then get them from cache, - // and build the operator with them - if (isBuiltShape(opA) && isBuiltShape(opB)) { - // std::cout << "both operand shapes are built, build the operator - // shape..." << std::endl; - GeoShape* shapeNew = nullptr; - const GeoShape* shapeA = getBuiltShape(opA); - const GeoShape* shapeB = getBuiltShape(opB); - if ("Subtraction" == type) { - shapeNew = new GeoShapeSubtraction(shapeA, shapeB); - } else if ("Union" == type) { - shapeNew = new GeoShapeUnion(shapeA, shapeB); - } else if ("Intersection" == type) { - shapeNew = new GeoShapeIntersection(shapeA, shapeB); - } - shape = shapeNew; - } - // otherwise, build the operand shapes... - else { - // first check the operands' type - bool isAOperator = isShapeOperator(opA); - bool isBOperator = isShapeOperator(opB); - - // if both are simple/actual shapes (i.e., not booleans), - // then build them, then build the boolean shape with them, and - // store that. - if (!isAOperator && !isBOperator) { - const GeoShape* shapeA = buildShape(opA, shapes_info_sub); - const GeoShape* shapeB = buildShape(opB, shapes_info_sub); - if (shapeA == NULL || shapeB == NULL) { - std::cout << "ERROR!!! shapeA or shapeB are NULL!" - << std::endl; - exit(EXIT_FAILURE); - } - - GeoShape* shapeNew = nullptr; - if ("Subtraction" == type) { - shapeNew = new GeoShapeSubtraction(shapeA, shapeB); - } else if ("Union" == type) { - shapeNew = new GeoShapeUnion(shapeA, shapeB); - } else if ("Intersection" == type) { - shapeNew = new GeoShapeIntersection(shapeA, shapeB); - } - - shape = shapeNew; - } - // ...otherwise, build the Subtraction operator shape without - // operands and save the needed pieces of information to build the - // actual operands and shape later. - else { - GeoShape* shapeNew = nullptr; - if ("Subtraction" == type) { - shapeNew = new GeoShapeSubtraction; - } else if ("Union" == type) { - shapeNew = new GeoShapeUnion; - } else if ("Intersection" == type) { - shapeNew = new GeoShapeIntersection; - } - - tuple_shapes_boolean_info tt(shapeId, shapeNew, opA, opB); - shapes_info_sub->push_back( - tt); //! Push the information about the new boolean shape - //! at the end of the very same container we are - //! iterating over - - shape = shapeNew; - } - } - } - // LAr custom shape - else if (type == "CustomShape") { - std::string name = ""; - // check parameters - // this complex test is needed to handle null strings in the DB records - bool okPars = false; - for (auto& par : shapePars) { - std::string str = - par.substr(par.find("=")); // get from "=" to the end - if (str.size() > 0) okPars = true; - } - // if ( shapePars.size() > 0 && ((shapePars.filter("=")).size() > 0) ) - // // this complex test is needed to handle null strings - if (shapePars.size() > 0 && okPars) { - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "name") name = varValue; - } - } else { - muxCout.lock(); - // throw std::invalid_argument("CustomShape parameters' list is - // empty!!"); - std::cout - << "ERROR!!! --> CustomShape parameters' list is empty!! It " - "seems the geometry file you are running on is corrupted." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = new GeoUnidentifiedShape("LArCustomShape", name); - } else if (type == "UnidentifiedShape") { - std::string name = ""; - std::string asciiData = ""; - - // debug - muxCout.lock(); - if (m_loglevel >= 2) - std::cout - << "GeoModelRead - loading 'UnidentifiedShape' - parameters: " - << parameters << std::endl; - muxCout.unlock(); - - // check parameters - // this complex test is needed to handle null strings in the DB records - bool okPars = false; - for (auto& par : shapePars) { - std::string str = - par.substr(par.find("=")); // get from "=" to the end - if (str.size() > 0) okPars = true; - } - if (shapePars.size() > 0 && okPars) { - // get parameters - for (auto& par : shapePars) { - // debug - muxCout.lock(); - if (m_loglevel >= 2) - std::cout - << "GeoModelRead - loading 'UnidentifiedShape' - par: " - << par << std::endl; + << sh->getNumberOfFacets() + << " is not equal to the original size! --> "; + printStdVectorStrings(shapePars); muxCout.unlock(); - - std::vector<std::string> vars = splitString(par, '='); - if (vars.size() > 1) { - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "name") name = varValue; - if (varName == "asciiData") asciiData = varValue; - } else { - okPars = false; - } } - } else { - okPars = false; + /* + * TODO: uncomment it, when the isValid() method will be implemented + for GeoTessellatedSolid if(!sh->isValid()) { error = 1; std::cout << + "ERROR! GeoTessellatedSolid shape is not valid!! -- input: " << + shapePars; + } + */ + } // END OF if (size>13) + else { + muxCout.lock(); + std::cout << "ERROR!! GeoTessellatedSolid has no facets!! --> " + "shape input parameters: "; + printStdVectorStrings(shapePars); + muxCout.unlock(); + error = 1; } - if (!okPars) { - // throw std::invalid_argument("UnidentifiedShape parameters' list - // is empty!!"); + if (error) { muxCout.lock(); - std::cout << "\n\n\tERROR!!! --> UnidentifiedShape is not properly " - "defined!! It seems the geometry file you are running " - "on is corrupted." - << std::endl; - std::cout - << "\tINFO --> UnidentifiedShape should be defined from two " - "strings: a string defining its type/name; and a ASCII data " - "string defining its parameters. The latter can be set to " - "an empty string if not used/needed." - << std::endl; - std::cout << "\tINFO --> UnidentifiedShape parameters' list is " - "empty or one datum is missing!! --> parameters: " - << parameters << std::endl; - std::cout << "\tINFO --> parameters: " << parameters << std::endl + std::cout << "GeoTessellatedSolid shape error!!! Aborting..." << std::endl; muxCout.unlock(); - std::runtime_error( - "UnidentifiedShape parameters' list are empty or incomplete!!"); + exit(EXIT_FAILURE); } - shape = new GeoUnidentifiedShape(name, asciiData); + shape = sh; - } else { + } + + else { m_unknown_shapes.insert( type); // save unknwon shapes for later warning message shape = buildDummyShape(); @@ -2649,21 +2375,31 @@ GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, } // TODO: move to an untilities file/class -void printTuple(tuple_shapes_boolean_info tuple) { +// void printTuple(tuple_shapes_boolean_info tuple) { +template<typename T> void printTuple(T tuple) { std::apply([](auto&&... args) { ((std::cout << args << ", "), ...); }, tuple); // needs C++17 std::cout << std::endl; } // TODO: move to an untilities file/class -void inspectListShapesToBuild(type_shapes_boolean_info list) { +void inspectListShapesToBuild(type_shapes_boolean_info& list) { for (auto tuple : list) { printTuple(tuple); std::cout << std::endl; } } +// TODO: move to an untilities file/class +void inspectListShapesToBuild(boolean_shapes_operands_info& list) { + for (const auto& tuple : list) { + printTuple(tuple); + std::cout << std::endl; + } +} +// OLD VERSION, REMOVE IT WHEN THE NEW DB SCHEMA IS IN PRODUCTION void ReadGeoModel::createBooleanShapeOperands( type_shapes_boolean_info* shapes_info_sub) { + std::cout << "OLD VERSION" << std::endl; if (shapes_info_sub->size() == 0) return; // debug @@ -2786,6 +2522,122 @@ void ReadGeoModel::createBooleanShapeOperands( } } +// NEW VERSION FOR THE NEW DB SCHEMA! +void ReadGeoModel::createBooleanShapeOperands(boolean_shapes_operands_info* shapes_info_sub) { + if (shapes_info_sub->size() == 0) return; + + // debug + if (m_loglevel >= 3) + { + std::cout << "\ncreateBooleanShapeOperands() - start..." << std::endl; + inspectListShapesToBuild(*shapes_info_sub); + std::cout << std::endl; + } + + // Iterate over the list. The size may be incremented while iterating + // (therefore, we cannot use iterators) + for (boolean_shapes_operands_info::size_type ii = 0; + ii < shapes_info_sub->size(); ++ii) { + // get the tuple containing the data about the operand shapes to + // build + tuple_boolean_shapes_operands tuple = (*shapes_info_sub)[ii]; + // std::cout << "tuple: "; printTuple(tuple); // debug + + // Initializing variables for unpacking + std::string shapeType; + unsigned shapeID{0}; + GeoShape* boolShPtr{nullptr}; + std::string typeA; + unsigned idA{0}; + std::string typeB; + unsigned idB{0}; + // use 'tie' to unpack the tuple values into separate variables + std::tie(shapeType, shapeID, boolShPtr, typeA, idA, typeB, idB) = tuple; + + if (shapeID == 0 || boolShPtr == nullptr || idA == 0 || idB == 0) { + THROW_EXCEPTION("ERROR! Boolean/Operator shape - shape is NULL or operands' IDs are not defined!"); + } + + if (isShapeBoolean(shapeType)) { + GeoShape* shapeA = nullptr; + GeoShape* shapeB = nullptr; + + // if both operands are built already... + if (isBuiltShape(typeA, idA) && isBuiltShape(typeB, idB)) { + // then build the operator shape... + shapeA = getBuiltShape(idA, typeA); + shapeB = getBuiltShape(idB, typeB); + } else { + // otherwise, build the operand shapes + shapeA = getBooleanReferencedShape(typeA, idA, shapes_info_sub); + shapeB = getBooleanReferencedShape(typeB, idB, shapes_info_sub); + } + // Now, assign the new shapes to the boolean shape we're + // building + if (dynamic_cast<GeoShapeIntersection*>(boolShPtr)) { + GeoShapeIntersection* ptr = + dynamic_cast<GeoShapeIntersection*>(boolShPtr); + ptr->m_opA = shapeA; + ptr->m_opB = shapeB; + ptr->m_opA->ref(); + ptr->m_opB->ref(); + } else if (dynamic_cast<GeoShapeSubtraction*>(boolShPtr)) { + GeoShapeSubtraction* ptr = + dynamic_cast<GeoShapeSubtraction*>(boolShPtr); + ptr->m_opA = shapeA; + ptr->m_opB = shapeB; + ptr->m_opA->ref(); + ptr->m_opB->ref(); + } else if (dynamic_cast<GeoShapeUnion*>(boolShPtr)) { + GeoShapeUnion* ptr = dynamic_cast<GeoShapeUnion*>(boolShPtr); + ptr->m_opA = shapeA; + ptr->m_opB = shapeB; + ptr->m_opA->ref(); + ptr->m_opB->ref(); + } else { + THROW_EXCEPTION("ERROR!!! shape is not boolean/operator! Write to 'geomodel-developers@cern.ch'..."); + } + } else if ("Shift" == shapeType) { + GeoShape* opShape = nullptr; + GeoTrf::Transform3D shiftX; + GeoTransform* shiftTransf = + nullptr; // TODO: remove the need for a temp GeoTransform, + // store the bare transforms as well... + + // if both operands are built already... + if (isBuiltShape(typeA, idA) && isBuiltTransform(idB)) { + // then build the operator shape... + opShape = getBuiltShape(idA, typeA); + shiftTransf = getBuiltTransform(idB); + } else { + // otherwise, build the operand shapes + opShape = getBooleanReferencedShape(typeA, idA, shapes_info_sub); + shiftTransf = buildTransform(idB); + } + shiftX = shiftTransf->getTransform(); + shiftTransf->unref(); // delete from heap, we only needed to get + // the bare transform // TODO: remove that + // need, store the bare transforms as well... + + if (dynamic_cast<GeoShapeShift*>(boolShPtr)) { + GeoShapeShift* ptr = dynamic_cast<GeoShapeShift*>(boolShPtr); + ptr->m_op = opShape; + ptr->m_shift = shiftX; + ptr->m_op->ref(); + } else { + std::cout + << "ERROR!!! shape is not a Shift operator! Exiting..." + << std::endl; + exit(EXIT_FAILURE); + } + } else { + THROW_EXCEPTION("ERROR! Undefined operator shape! This part of the code should not be reached!"); + } + // then, store the now completed shape and continue to the next item + storeBuiltShape(shapeType, shapeID, boolShPtr); + } +} + GeoShape* ReadGeoModel::getBooleanReferencedShape( const unsigned int shapeID, type_shapes_boolean_info* shapes_info_sub) { if (0 == shapeID) { @@ -2827,6 +2679,50 @@ GeoShape* ReadGeoModel::getBooleanReferencedShape( // inspectListShapesToBuild(m_shapes_info_sub); // debug return shape; } +GeoShape* ReadGeoModel::getBooleanReferencedShape( + const std::string_view shapeType, const unsigned shapeID, boolean_shapes_operands_info* shapes_info_sub) { + if (0 == shapeID || "" == shapeType) { + THROW_EXCEPTION("ERROR!! ShapeID == 0 or shapeType == NULL !"); + } + + GeoShape* shape{nullptr}; + // if A is built already, then take it from cache + if (isBuiltShape(shapeID)) { + if (m_loglevel >= 2) + std::cout << "operandA is built, taking it from cache..." + << std::endl; // debug + shape = getBuiltShape(shapeID, shapeType); + } else { + // // if not a boolean shape, then build it + // if (!isShapeOperator(shapeType)) { + // if (m_loglevel >= 2) + // std::cout << "operandA is not built and not an operator, " + // "build it..." + // << std::endl; // debug + // shape = getBuiltShape(shapeID, shapeType); + // if ( nullptr == shape ) { + // THROW_EXCEPTION("ERROR!!! shape is NULL!"); + // } + // } + // if A is a boolean shape, then create an empty shape, + // store it for later completion, and use that + if (isShapeOperator(shapeType)) { + if (m_loglevel >= 2) + std::cout << "operandA is not built and it is an operator, add " + "it to build it later..." + << std::endl; // debug + shape = addEmptyBooleanShapeForCompletion(shapeType, shapeID, shapes_info_sub); + } else { + THROW_EXCEPTION("Undefined behavior... Check the shape operand!"); + } + } + if ( nullptr == shape ) { + THROW_EXCEPTION("ERROR!!! shape is NULL!"); + } + + // inspectListShapesToBuild(m_shapes_info_sub); // debug + return shape; +} GeoShape* ReadGeoModel::addEmptyBooleanShapeForCompletion( const unsigned int shapeID, type_shapes_boolean_info* shapes_info_sub) { @@ -2859,6 +2755,46 @@ GeoShape* ReadGeoModel::addEmptyBooleanShapeForCompletion( return shape; } +GeoShape *ReadGeoModel::addEmptyBooleanShapeForCompletion( + const std::string_view shapeType, const unsigned shapeID, boolean_shapes_operands_info *shapes_info_sub) +{ + // get the operands' IDs, + // build an empty instance of the appropriate boolean/operator shape, + // and store all of that together, by appending to this same container, + // so it will be visited at a later time during this very same loop + std::tuple<std::string, unsigned int, std::string, unsigned int> ops = + getBooleanShapeOperands(shapeType, shapeID); + std::string opAType; + unsigned opAId{0}; + std::string opBType; + unsigned opBId{0}; + std::tie(opAType, opAId, opBType, opBId) = ops; + + GeoShape *shape = nullptr; + if (shapeType == "Intersection") + { + shape = new GeoShapeIntersection(); + } + else if (shapeType == "Shift") + { + shape = new GeoShapeShift(); + } + else if (shapeType == "Subtraction") + { + shape = new GeoShapeSubtraction(); + } + else if (shapeType == "Union") + { + shape = new GeoShapeUnion(); + } + + tuple_boolean_shapes_operands tt(shapeType, shapeID, shape, opAType, opAId, opBType, opBId); + shapes_info_sub->push_back( + tt); //! Push the information about the new boolean shape at the + //! end of the very same container we are iterating over + + return shape; +} // TODO: move this to utility class/file std::vector<std::string> ReadGeoModel::splitString(const std::string& s, @@ -2893,7 +2829,7 @@ std::vector<std::string> ReadGeoModel::splitString(const std::string& s, // } // TODO: move this to utility class/file -void ReadGeoModel::printStdVectorStrings(std::vector<std::string> vec) { +void ReadGeoModel::printStdVectorStrings(const std::vector<std::string>& vec) { for (const auto& str : vec) { std::cout << str << " "; } @@ -2924,7 +2860,7 @@ std::pair<unsigned int, unsigned int> ReadGeoModel::getBooleanShapeOperands( // std::cout << "shapePars size: " << shapePars.size() << std::endl; // // debug only - for (auto par : shapePars) { + for (const auto& par : shapePars) { std::vector<std::string> vars = splitString(par, '='); std::string varName = vars[0]; std::string varValue = vars[1]; @@ -2953,23 +2889,68 @@ std::pair<unsigned int, unsigned int> ReadGeoModel::getBooleanShapeOperands( return pair; } +std::tuple<std::string, unsigned int, std::string, unsigned int> ReadGeoModel::getBooleanShapeOperands( + const std::string_view shapeType, const unsigned int shapeID) +{ + + DBRowEntry record; + if ("Shift" == shapeType) + record = m_shapes_Shift[shapeID - 1]; + else if ("Subtraction" == shapeType) + record = m_shapes_Subtraction[shapeID - 1]; + else if ("Intersection" == shapeType) + record = m_shapes_Intersection[shapeID - 1]; + else if ("Union" == shapeType) + record = m_shapes_Union[shapeID - 1]; + + unsigned shapeId{0}; + double shapeVolume{0}; + std::string shapeOpAType; + unsigned shapeOpAId{0}; + std::string shapeOpBType; + unsigned shapeOpBId{0}; + + shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(record[0], "Boolean:shapeID"); + // computed volume (not defined by default) + shapeVolume = GeoModelHelpers::variantHelper::getFromVariant_Double(record[1], "Boolean:shapeVolume"); + // shape operands + shapeOpAType = GeoModelHelpers::variantHelper::getFromVariant_String(record[2], "Boolean:shapeType"); + shapeOpAId = GeoModelHelpers::variantHelper::getFromVariant_Int(record[3], "Boolean:shapeId"); + if ("Shift" == shapeType) + { + shapeOpBType = "NULL"; + shapeOpBId = GeoModelHelpers::variantHelper::getFromVariant_Int(record[4], "Boolean:shapeId"); + } + else + { + shapeOpBType = GeoModelHelpers::variantHelper::getFromVariant_String(record[4], "Boolean:shapeType"); + shapeOpBId = GeoModelHelpers::variantHelper::getFromVariant_Int(record[5], "Boolean:shapeId"); + } + + if (shapeOpAId == 0 || shapeOpBId == 0 || shapeOpAType.empty() || shapeOpBType.empty()) + { + THROW_EXCEPTION("ERROR! Intersection/Subtraction/Union/Shift shape operands' info are empty!"); + } + + return std::make_tuple(shapeOpAType, shapeOpAId, shapeOpBType, shapeOpBId); +} bool ReadGeoModel::isShapeOperator(const unsigned int shapeId) { return isShapeOperator(getShapeType(shapeId)); } -bool ReadGeoModel::isShapeOperator(const std::string type) { +bool ReadGeoModel::isShapeOperator(const std::string_view type) { std::unordered_set<std::string> opShapes = {"Intersection", "Shift", "Subtraction", "Union"}; - return (opShapes.find(type) != opShapes.end()); + return (opShapes.find(std::string(type)) != opShapes.end()); } bool ReadGeoModel::isShapeBoolean(const unsigned int shapeId) { return isShapeBoolean(getShapeType(shapeId)); } -bool ReadGeoModel::isShapeBoolean(const std::string type) { +bool ReadGeoModel::isShapeBoolean(const std::string_view type) { std::unordered_set<std::string> opShapes = {"Intersection", "Subtraction", "Union"}; - return (opShapes.find(type) != opShapes.end()); + return (opShapes.find(std::string(type)) != opShapes.end()); } GeoBox* ReadGeoModel::buildDummyShape() { @@ -2977,8 +2958,28 @@ GeoBox* ReadGeoModel::buildDummyShape() { 30 * SYSTEM_OF_UNITS::cm); } +void ReadGeoModel::buildVSurface(const unsigned int id) { + if (m_loglevel >= 3) { + muxCout.lock(); + std::cout << "buildVSurface(), testing VSurface id: " << id << "...\n"; + ; + muxCout.unlock(); + } + + if(!isBuiltVSurface(id)){ // the VSurface hasnt been built yet + DBRowEntry values = m_VSurface[id - 1]; + const std::string shapeType = GeoModelHelpers::variantHelper::getFromVariant_String(values[1], "VSurf_shapeType"); + const unsigned int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(values[2], "VSurf_shapeID"); + GeoVSurfaceShape* buildVSurfShape = BuildWhichSurface(shapeType, shapeId); // build the shape of surface + GeoVSurface* buildVSurf = new GeoVSurface(buildVSurfShape); // build the virtual surface class itself + storeBuiltVSurface(buildVSurf); + } + // else do nothing +} +//----------------------------------------------------------------------- + GeoLogVol* ReadGeoModel::buildLogVol(const unsigned int id) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "buildLogVol(), testing LogVol id: " << id << "...\n"; ; @@ -2986,7 +2987,7 @@ GeoLogVol* ReadGeoModel::buildLogVol(const unsigned int id) { } if (isBuiltLog(id)) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "getting the LogVol from cache...\n"; ; @@ -2995,46 +2996,44 @@ GeoLogVol* ReadGeoModel::buildLogVol(const unsigned int id) { return getBuiltLog(id); } - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "ReadGeoModel::buildLogVol()" << std::endl; muxCout.unlock(); } // get logVol properties from the DB - std::vector<std::string> values = m_logVols[id - 1]; - - // get the parameters to build the GeoLogVol node - std::string logVolName = values[1]; - - // build the referenced GeoShape node - const unsigned int shapeId = std::stoi(values[2]); - GeoShape* shape = getBuiltShape(shapeId); + // std::vector<std::string> values = m_logVols[id - 1]; + DBRowEntry values = m_logVols[id - 1]; + + // --- get the parameters to build the GeoLogVol node + // get the name of the LogVol + const std::string logVolName = GeoModelHelpers::variantHelper::getFromVariant_String(values[1], "LogVol_name"); + // get the ID and the type of the referenced GeoShape node + const int shapeId = GeoModelHelpers::variantHelper::getFromVariant_Int(values[2], "LogVol_shapeID"); + const std::string shapeType = GeoModelHelpers::variantHelper::getFromVariant_String(values[3], "LogVol_shapeType"); + GeoShape* shape = getBuiltShape(shapeId, shapeType); if (!shape) { - std::cout - << "ERROR!! While building a LogVol, Shape is NULL! Exiting..." - << std::endl; - exit(EXIT_FAILURE); + THROW_EXCEPTION("ERROR!! While building the LogVol '" + logVolName + "', shape of type '" + shapeType + "' is NULL! Exiting..."); } // build the referenced GeoMaterial node - const unsigned int matId = std::stoi(values[3]); - if (m_loglevel >= 2) { + // const unsigned int matId = std::stoi(values[3]); + const int matId = GeoModelHelpers::variantHelper::getFromVariant_Int(values[4], "LogVol_MaterialID"); + + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "buildLogVol() - material Id:" << matId << std::endl; muxCout.unlock(); } GeoMaterial* mat = getBuiltMaterial(matId); if (!mat) { - std::cout - << "ERROR!! While building a LogVol, Material is NULL! Exiting..." - << std::endl; - exit(EXIT_FAILURE); + THROW_EXCEPTION("ERROR!! While building the LogVol '" + logVolName + "', Material of ID '" + std::to_string(matId) + "' is NULL! Exiting..."); } GeoLogVol* logPtr = new GeoLogVol(logVolName, shape, mat); storeBuiltLog(logPtr); - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { muxCout.lock(); std::cout << "buildLogVol() - address of the stored LogVol:" << logPtr << std::endl; @@ -3043,6 +3042,7 @@ GeoLogVol* ReadGeoModel::buildLogVol(const unsigned int id) { return logPtr; } + //// TODO: should go in a QtUtils header-only class, to be used in other /// packages // QList<double> ReadGeoModel::convertQstringListToDouble(QStringList listin) { @@ -3220,18 +3220,28 @@ TRANSFUNCTION ReadGeoModel::buildFunction(const unsigned int id) { } */ - std::string expr = m_functions[id - 1][1]; // nodes' IDs start from 1 + std::string expr = std::get<std::string>(m_functions[id - 1][1]); // nodes' IDs start from 1 + unsigned dataStart = std::get<int>(m_functions[id - 1][2]); + unsigned dataEnd = std::get<int>(m_functions[id - 1][3]); + // debug msg + // std::cout << "expr:" << expr << " -- dataStart,End: " << dataStart << ", " << dataEnd << std::endl; if (0 == expr.size()) { muxCout.lock(); - std::cout << "FATAL ERROR!! Function expression is empty!! Aborting..." - << std::endl; + THROW_EXCEPTION("FATAL ERROR!! Function expression is empty!! Aborting..."); muxCout.unlock(); - exit(EXIT_FAILURE); } + // get exprData, extract subvector + // NOTE: we use (dataStart-1) to cope with the difference between the DB rows starting from '1', + // which is what the 'dataStart' stores, and the vector items, which start '0'; + // also, the constructor of the sub-vector takes the element from 'begin+dataStart-1' included + // and 'begin+dataEnd' excluded. + std::deque<double> sub_vector(m_funcExprData.begin() + (dataStart-1), + m_funcExprData.begin() + (dataEnd) ); + TransFunctionInterpreter interpreter; - TFPTR func = interpreter.interpret(expr); + TFPTR func = interpreter.interpret(expr, &sub_vector); TRANSFUNCTION tf = *(func.release()); // make func returns a pointer to the managed // object and releases the ownership, then get @@ -3253,13 +3263,349 @@ TRANSFUNCTION ReadGeoModel::buildFunction(const unsigned int id) { } // --- methods for caching GeoShape nodes --- bool ReadGeoModel::isBuiltShape(const unsigned int id) { - return (!(m_memMapShapes.find(id) == m_memMapShapes.end())); +return (!(m_memMapShapes.find(id) == m_memMapShapes.end())); +} +bool ReadGeoModel::isBuiltShape_Operators_Shift(const unsigned int id) { +return (!(m_memMapShapes_Shift.find(id) == m_memMapShapes_Shift.end())); +} +bool ReadGeoModel::isBuiltShape_Operators_Subtraction(const unsigned int id) { +return (!(m_memMapShapes_Subtraction.find(id) == m_memMapShapes_Subtraction.end())); +} +bool ReadGeoModel::isBuiltShape_Operators_Intersection(const unsigned int id) { +return (!(m_memMapShapes_Intersection.find(id) == m_memMapShapes_Intersection.end())); +} +bool ReadGeoModel::isBuiltShape_Operators_Union(const unsigned int id) { +return (!(m_memMapShapes_Union.find(id) == m_memMapShapes_Union.end())); } -void ReadGeoModel::storeBuiltShape(const unsigned int id, GeoShape* nodePtr) { +// --- methods for caching GeoShape nodes --- +bool ReadGeoModel::isBuiltShape(std::string_view shapeType, const unsigned shapeId) { +const std::set<std::string> shapesNewDB{"Box", "Tube", "Pcon", "Cons", "Para", "Pgon", "Trap", "Trd", "Tubs", "Torus", "TwistedTrap", "SimplePolygonBrep", "GenericTrap", "Shift", "Subtraction", "Intersection", "Union"}; + // get shape parameters + if (std::count(shapesNewDB.begin(), shapesNewDB.end(), shapeType)) + { + if ("Box" == shapeType) + { + return m_builderShape_Box->isBuiltShape(shapeId); + } + else if ("Tube" == shapeType) + { + return m_builderShape_Tube->isBuiltShape(shapeId); + } + else if ("Pcon" == shapeType) + { + return m_builderShape_Pcon->isBuiltShape(shapeId); + } + else if ("Cons" == shapeType) + { + return m_builderShape_Cons->isBuiltShape(shapeId); + } + else if ("Para" == shapeType) + { + return m_builderShape_Para->isBuiltShape(shapeId); + } + else if ("Pgon" == shapeType) + { + return m_builderShape_Pgon->isBuiltShape(shapeId); + } + else if ("Trap" == shapeType) + { + return m_builderShape_Trap->isBuiltShape(shapeId); + } + else if ("Trd" == shapeType) + { + return m_builderShape_Trd->isBuiltShape(shapeId); + } + else if ("Tubs" == shapeType) + { + return m_builderShape_Tubs->isBuiltShape(shapeId); + } + else if ("Torus" == shapeType) + { + return m_builderShape_Torus->isBuiltShape(shapeId); + } + else if ("TwistedTrap" == shapeType) + { + return m_builderShape_TwistedTrap->isBuiltShape(shapeId); + } + else if ("SimplePolygonBrep" == shapeType) + { + return m_builderShape_SimplePolygonBrep->isBuiltShape(shapeId); + } + else if ("GenericTrap" == shapeType) + { + return m_builderShape_GenericTrap->isBuiltShape(shapeId); + } + else if ("Shift" == shapeType) + { + return isBuiltShape_Operators_Shift(shapeId); + } + else if ("Intersection" == shapeType) + { + return isBuiltShape_Operators_Intersection(shapeId); + } + else if ("Subtraction" == shapeType) + { + return isBuiltShape_Operators_Subtraction(shapeId); + } + else if ("Union" == shapeType) + { + return isBuiltShape_Operators_Union(shapeId); + } + else { + THROW_EXCEPTION("ERROR!!! Shape '" + std::string(shapeType) + "' is not handled correctly!"); + } + } + std::cout << "WARNING! 'isBuiltShape' - For the shape '" << shapeType << "' we're using the old DB schema..." << std::endl; + return isBuiltShape(shapeId); +} +void ReadGeoModel::storeBuiltShape(const unsigned id, GeoShape* nodePtr) { m_memMapShapes[id] = nodePtr; } -GeoShape* ReadGeoModel::getBuiltShape(const unsigned int id) { - return m_memMapShapes[id]; // this is a map, and 'id' is the key + +void ReadGeoModel::storeBuiltShape(const std::string_view type, const unsigned id, GeoShape *nodePtr) +{ + if ("Shift" == type) + storeBuiltShapeOperators_Shift(id, nodePtr); + else if ("Subtraction" == type) + storeBuiltShapeOperators_Subtraction(id, nodePtr); + else if ("Intersection" == type) + storeBuiltShapeOperators_Intersection(id, nodePtr); + else if ("Union" == type) + storeBuiltShapeOperators_Union(id, nodePtr); + else + THROW_EXCEPTION("ERROR!!! Undefined operator type!"); +} + +void ReadGeoModel::storeBuiltShapeOperators_Shift(const unsigned id, GeoShape* nodePtr) { + m_memMapShapes_Shift[id] = nodePtr; +} +void ReadGeoModel::storeBuiltShapeOperators_Subtraction(const unsigned id, GeoShape* nodePtr) { + m_memMapShapes_Subtraction[id] = nodePtr; +} +void ReadGeoModel::storeBuiltShapeOperators_Intersection(const unsigned id, GeoShape* nodePtr) { + m_memMapShapes_Intersection[id] = nodePtr; +} +void ReadGeoModel::storeBuiltShapeOperators_Union(const unsigned id, GeoShape* nodePtr) { + m_memMapShapes_Union[id] = nodePtr; +} + +//------------------------------------------------------------------------------------------ + +GeoVSurfaceShape* ReadGeoModel::BuildWhichSurface(std::string_view shapeType, const unsigned int shapeId) +{ + + if ("RectangleSurface" == shapeType){ + m_memMapRectSurface.reserve(m_rectangle_surface.size()); + if(!isBuiltRectSurface(shapeId)){ + // Not built yet + DBRowEntry row = m_rectangle_surface[shapeId - 1]; + GeoRectSurface* builtSurface = buildsurfTool->buildRectSurface(row); + storeBuiltRectSurface(builtSurface); + return builtSurface; + } + else{ + GeoRectSurface* builtSurface = m_memMapRectSurface[shapeId - 1]; + return builtSurface; + } + + } + else if ("TrapezoidSurface" == shapeType){ + m_memMapTrapezoidSurface.reserve(m_trapezoid_surface.size()); + if(!isBuiltTrapezoidSurface(shapeId)){ + // Not built yet + DBRowEntry row = m_trapezoid_surface[shapeId - 1]; + GeoTrapezoidSurface* builtSurface = buildsurfTool->buildTrapezoidSurface(row); + storeBuiltTrapezoidSurface(builtSurface); + return builtSurface; + } + else{ + GeoTrapezoidSurface* builtSurface = m_memMapTrapezoidSurface[shapeId - 1]; + return builtSurface; + } + + } + else if ("AnnulusSurface" == shapeType){ + m_memMapAnnulusSurface.reserve(m_annulus_surface.size()); + if(!isBuiltAnnulusSurface(shapeId)){ + // Not built yet + DBRowEntry row = m_annulus_surface[shapeId - 1]; + GeoAnnulusSurface* builtSurface = buildsurfTool->buildAnnulusSurface(row); + storeBuiltAnnulusSurface(builtSurface); + return builtSurface; + } + else{ + GeoAnnulusSurface* builtSurface = m_memMapAnnulusSurface[shapeId - 1]; + return builtSurface; + } + + } + else if ("DiamondSurface" == shapeType){ + m_memMapDiamondSurface.reserve(m_diamond_surface.size()); + if(!isBuiltDiamondSurface(shapeId)){ + // Not built yet + DBRowEntry row = m_diamond_surface[shapeId - 1]; + GeoDiamondSurface* builtSurface = buildsurfTool->buildDiamondSurface(row); + storeBuiltDiamondSurface(builtSurface); + return builtSurface; + } + else{ + GeoDiamondSurface* builtSurface = m_memMapDiamondSurface[shapeId - 1]; + return builtSurface; + } + + } + else{ + THROW_EXCEPTION("ERROR!!! VSurface '" + std::string(shapeType) + "' is not built correctly!"); + } +} + +bool ReadGeoModel::isBuiltVSurface(const unsigned int shapeId) { + return (shapeId <= m_memMapVSurface.size()); +} + +//------------------------------------------------------------------------------------------ + +bool ReadGeoModel::isBuiltRectSurface(const unsigned int shapeId) { + return (shapeId <= m_memMapRectSurface.size()); +} + +void ReadGeoModel::storeBuiltRectSurface(GeoRectSurface* nodePtr) { + if (!nodePtr) + THROW_EXCEPTION(" RECTANGLE SURFACE POINTER IS NULL, NO RECT SURFS ARE BUILT YET "); + m_memMapRectSurface.push_back(nodePtr); +} + +//------------------------------------------------------------------------------------------ + +bool ReadGeoModel::isBuiltTrapezoidSurface(const unsigned int shapeId) { + return (shapeId <= m_memMapTrapezoidSurface.size()); +} + +void ReadGeoModel::storeBuiltTrapezoidSurface(GeoTrapezoidSurface* nodePtr) { + if (!nodePtr) + THROW_EXCEPTION(" TRAPEZOID SURFACE POINTER IS NULL, NO TRAPE SURFS ARE BUILT YET "); + m_memMapTrapezoidSurface.push_back(nodePtr); +} + +//------------------------------------------------------------------------------------------ + +bool ReadGeoModel::isBuiltAnnulusSurface(const unsigned int shapeId) { + return (shapeId <= m_memMapAnnulusSurface.size()); +} + +void ReadGeoModel::storeBuiltAnnulusSurface(GeoAnnulusSurface* nodePtr) { + if (!nodePtr) + THROW_EXCEPTION(" ANNULUS SURFACE POINTER IS NULL, NO ANNULUS SURFS ARE BUILT YET "); + m_memMapAnnulusSurface.push_back(nodePtr); +} + +//------------------------------------------------------------------------------------------ + +bool ReadGeoModel::isBuiltDiamondSurface(const unsigned int shapeId) { + return (shapeId <= m_memMapDiamondSurface.size()); +} + +void ReadGeoModel::storeBuiltDiamondSurface(GeoDiamondSurface* nodePtr) { + if (!nodePtr) + THROW_EXCEPTION(" DIAMOND SURFACE POINTER IS NULL, NO DIAMOND SURFS ARE BUILT YET "); + m_memMapDiamondSurface.push_back(nodePtr); +} + +//------------------------------------------------------------------------------------------ + +void ReadGeoModel::storeBuiltVSurface(GeoVSurface* nodePtr) { + if (!nodePtr) + THROW_EXCEPTION(" VIRTUAL SURFACE POINTER IS NULL, NO VSURFS ARE BUILT YET "); + m_memMapVSurface.push_back(nodePtr); +} + +//------------------------------------------------------------------------------------------ + +GeoShape *ReadGeoModel::getBuiltShape(const unsigned shapeId, std::string_view shapeType) +{ + + const std::set<std::string> shapesNewDB{"Box", "Tube", "Pcon", "Cons", "Para", "Pgon", "Trap", "Trd", "Tubs", "Torus", "TwistedTrap", "SimplePolygonBrep", "GenericTrap", "Shift", "Intersection", "Subtraction", "Union", "UnidentifiedShape"}; + // get shape parameters + if (std::count(shapesNewDB.begin(), shapesNewDB.end(), shapeType)) + { + if ("Box" == shapeType) + { + return m_builderShape_Box->getBuiltShape(shapeId); + } + else if ("Tube" == shapeType) + { + return m_builderShape_Tube->getBuiltShape(shapeId); + } + else if ("Pcon" == shapeType) + { + return m_builderShape_Pcon->getBuiltShape(shapeId); + } + else if ("Cons" == shapeType) + { + return m_builderShape_Cons->getBuiltShape(shapeId); + } + else if ("Para" == shapeType) + { + return m_builderShape_Para->getBuiltShape(shapeId); + } + else if ("Pgon" == shapeType) + { + return m_builderShape_Pgon->getBuiltShape(shapeId); + } + else if ("Trap" == shapeType) + { + return m_builderShape_Trap->getBuiltShape(shapeId); + } + else if ("Trd" == shapeType) + { + return m_builderShape_Trd->getBuiltShape(shapeId); + } + else if ("Tubs" == shapeType) + { + return m_builderShape_Tubs->getBuiltShape(shapeId); + } + else if ("Torus" == shapeType) + { + return m_builderShape_Torus->getBuiltShape(shapeId); + } + else if ("TwistedTrap" == shapeType) + { + return m_builderShape_TwistedTrap->getBuiltShape(shapeId); + } + else if ("SimplePolygonBrep" == shapeType) + { + return m_builderShape_SimplePolygonBrep->getBuiltShape(shapeId); + } + else if ("GenericTrap" == shapeType) + { + return m_builderShape_GenericTrap->getBuiltShape(shapeId); + } + else if ("UnidentifiedShape" == shapeType) + { + return m_builderShape_UnidentifiedShape->getBuiltShape(shapeId); + } + else if ("Shift" == shapeType) + { + return m_memMapShapes_Shift[shapeId]; + } + else if ("Intersection" == shapeType) + { + return m_memMapShapes_Intersection[shapeId]; + } + else if ("Subtraction" == shapeType) + { + return m_memMapShapes_Subtraction[shapeId]; + } + else if ("Union" == shapeType) + { + return m_memMapShapes_Union[shapeId]; + } + else { + THROW_EXCEPTION("ERROR!!! Shape '" + std::string(shapeType) + "' is not handled correctly!"); + } + } + std::cout << "WARNING! 'getBuiltShape' - For the shape '" << shapeType << "' we're using the old DB schema..." << std::endl; + return m_memMapShapes[shapeId]; // this is a map, and 'id' is the key } // --- methods for caching GeoLogVol nodes --- diff --git a/GeoModelIO/GeoModelWrite/CMakeLists.txt b/GeoModelIO/GeoModelWrite/CMakeLists.txt index b29f91d60af20e1a43b1f0e89b9bde41d5937995..cfc7e08da38185f7a5c43d64c974757590cfe450 100644 --- a/GeoModelIO/GeoModelWrite/CMakeLists.txt +++ b/GeoModelIO/GeoModelWrite/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cpp ) @@ -7,10 +7,10 @@ file( GLOB HEADERS GeoModelWrite/*.h ) # Set up the library. add_library( GeoModelWrite SHARED ${HEADERS} ${SOURCES} ) target_link_libraries( GeoModelWrite PUBLIC - GeoModelKernel GeoModelDBManager TFPersistification ) + GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers) target_include_directories( GeoModelWrite PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelWrite" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelWrite PROPERTIES diff --git a/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h b/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h index 3d35b90630de97e5e81f9379c566c4f4dcca6826..192082eb6cab842fab2e4080278ff970d1664f9b 100644 --- a/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h +++ b/GeoModelIO/GeoModelWrite/GeoModelWrite/WriteGeoModel.h @@ -20,6 +20,9 @@ * Also added methods to get the numbers of visited nodes. * - Feb 2023 - R.M.Bianchi <riccardo.maria.bianchi@cern.ch> * Added 'setLoglevel' method, to steer output messages + * + * - Jun 2024 - R.Xue <r.xue@cern.ch><rux23@pitt.edu> + * Added methods to write out virtual surfaces to .db files */ #ifndef GeoModelWrite_WriteGeoModel_H @@ -27,6 +30,8 @@ // local includes #include "GeoModelDBManager/GMDBManager.h" +#include "GeoModelDBManager/definitions.h" + // GeoModel includes #include "GeoModelKernel/GeoAlignableTransform.h" @@ -38,9 +43,11 @@ #include "GeoModelKernel/GeoNodeAction.h" #include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoXF.h" +#include "GeoModelKernel/GeoVSurfaceShape.h" // C++ includes #include <set> +#include <deque> #include <string> #include <unordered_map> #include <utility> @@ -92,12 +99,15 @@ class WriteGeoModel : public GeoNodeAction { /// - 0 : Default /// - 1 : Verbose /// - 2 : Debug + /// - 3 : Deep Debug void setLogLevel(unsigned loglevel) { m_loglevel = loglevel; }; virtual void handlePhysVol( const GeoPhysVol *vol); // Handles a physical volume. virtual void handleFullPhysVol( const GeoFullPhysVol *vol); // Handles a full physical volume. + virtual void handleVSurface( + const GeoVSurface* surf); // Handles a virtual surface. virtual void handleSerialDenominator( const GeoSerialDenominator *sD); // Handles a Serial Denominator. virtual void handleSerialTransformer( @@ -114,10 +124,9 @@ class WriteGeoModel : public GeoNodeAction { // colNames, std::vector<std::string> colTypes, // std::vector<std::vector<std::string>> tableData ); void storeDataTable( - std::string tableName, std::vector<std::string> colNames, - std::vector<std::string> colTypes, - std::vector< - std::vector<std::variant<int, long, float, double, std::string>>> + const std::string& tableName, const std::vector<std::string>& colNames, + const std::vector<std::string>& colTypes, + DBRowsList tableData); void saveToDB(GeoPublisher *store = nullptr); @@ -144,10 +153,28 @@ class WriteGeoModel : public GeoNodeAction { }; unsigned long getNFunctions() { return m_functions.size(); }; unsigned long getNNameTags() { return m_nameTags.size(); }; - unsigned long getNShapes() { return m_shapes.size(); }; unsigned long getNChildrenConnections() { return m_childrenPositions.size(); }; + unsigned long getNShapes() { return m_shapes.size(); }; // TODO: to be removed later + unsigned long getNShapes_Box() { return m_shapes_Box.size(); }; + unsigned long getNShapes_Cons() { return m_shapes_Cons.size(); }; + unsigned long getNShapes_Para() { return m_shapes_Para.size(); }; + unsigned long getNShapes_Pcon() { return m_shapes_Pcon.size(); }; + unsigned long getNShapes_Pgon() { return m_shapes_Pgon.size(); }; + unsigned long getNShapes_SimplePolygonBrep() { return m_shapes_SimplePolygonBrep.size(); }; + unsigned long getNShapes_GenericTrap() { return m_shapes_GenericTrap.size(); }; + unsigned long getNShapes_Trap() { return m_shapes_Trap.size(); }; + unsigned long getNShapes_Trd() { return m_shapes_Trd.size(); }; + unsigned long getNShapes_Tube() { return m_shapes_Tube.size(); }; + unsigned long getNShapes_Tubs() { return m_shapes_Tubs.size(); }; + unsigned long getNShapes_Torus() { return m_shapes_Torus.size(); }; + unsigned long getNShapes_TwistedTrap() { return m_shapes_TwistedTrap.size(); }; + unsigned long getNShapes_UnidentifiedShape() { return m_shapes_UnidentifiedShape.size(); }; + unsigned long getNShapes_Shift() { return m_shapes_Shift.size(); }; + unsigned long getNShapes_Union() { return m_shapes_Union.size(); }; + unsigned long getNShapes_Intersection() { return m_shapes_Intersection.size(); }; + unsigned long getNShapes_Subtraction() { return m_shapes_Subtraction.size(); }; private: // define copy constructor, needed for the GeoModelAction subclass @@ -157,7 +184,7 @@ class WriteGeoModel : public GeoNodeAction { WriteGeoModel &operator=(const WriteGeoModel &right); void handleVPhysVolObjects(const GeoVPhysVol *vol); - + void handleVSurfaceObjects(const GeoVSurface *surf); /// Handles a physical volume referenced by a SerialTrasformer void handleReferencedVPhysVol(const GeoVPhysVol *vol); @@ -165,20 +192,34 @@ class WriteGeoModel : public GeoNodeAction { std::vector<std::string> getParentNode(); - unsigned int storeShape(const GeoShape *shape); + std::pair<std::string, unsigned> storeShape(const GeoShape *shape); unsigned int storeMaterial(const GeoMaterial *mat); unsigned int storeElement(const GeoElement *el); unsigned int storeTranform(const GeoTransform *node); - + + // virtual surface --------------------------------------------------------------------- + unsigned int storeSurfaceShape(const GeoVSurfaceShape* surf); + std::pair<DBRowEntry, DBRowsList> getSurfaceParameters(const GeoVSurfaceShape* surf_shape); + unsigned int addSurfaceShape(const std::string &type, const DBRowEntry ¶meters); + unsigned int storeVSurface(const GeoVSurface* pointer, const unsigned int& surfShapeId, const std::string& surfShapeType); + unsigned int addVSurface(const std::string &type, const unsigned int& surfShapeId); + unsigned int storeObj(const GeoVSurfaceShape* pointer, const std::string& shapeName, + DBRowEntry& parameters, const DBRowsList &shapeData); + unsigned int setSurfaceCopyNumber(const unsigned int& VSurfaceId, const std::string& surfType); + //-------------------------------------------------------------------------------------- + unsigned int storeObj(const GeoMaterial *pointer, const std::string &name, - const double &density, const std::string &elements); + const double &density, const DBRowsList &materialData); unsigned int storeObj(const GeoElement *pointer, const std::string &name, const std::string &symbol, const double &elZ, const double &elA); unsigned int storeObj(const GeoShape *pointer, const std::string &type, const std::string ¶meters); + std::pair<std::string, unsigned> storeObj(const GeoShape *pointer, const std::string &type, + DBRowEntry ¶meters, + const DBRowsList &shapeData); unsigned int storeObj(const GeoLogVol *pointer, const std::string &name, - const unsigned int &shapeId, + const unsigned int &shapeId, std::string_view shapeType, const unsigned int &materialId); unsigned int storeObj(const GeoPhysVol *pointer, const unsigned int &logvolId, @@ -198,31 +239,50 @@ class WriteGeoModel : public GeoNodeAction { const unsigned int &functionId, const unsigned int &volId, const std::string &volType, const unsigned int &copies); - unsigned int storeObj(const GeoXF::Function *pointer, - const std::string &expression); + unsigned int storeObj(const GeoXF::Function *pointer); + // const std::string &expression, + // const std::deque<double> &exprData); unsigned int storeObj(const GeoTransform *pointer, const std::vector<double> ¶meters); unsigned int storeObj(const GeoAlignableTransform *pointer, const std::vector<double> ¶meters); unsigned int storeObj(const GeoNameTag *pointer, const std::string &name); + // void storeExprData(const unsigned funcId, std::deque<double> exprData); + std::vector<unsigned> addExprData(const std::deque<double> &exprData) ; + unsigned int addRecord(std::vector<std::vector<std::string>> *container, - const std::vector<std::string> values) const; + const std::vector<std::string>& values) const; + unsigned int addRecord(DBRowsList *container, + const DBRowEntry& values) const; + + std::pair<unsigned, unsigned> addRecordData( + DBRowsList *container, + const DBRowsList& values) const; - unsigned int addMaterial(const std::string &name, const double &density, - const std::string &elements); unsigned int addElement(const std::string &name, const std::string &symbol, const double &elZ, const double &elA); + + unsigned int addMaterial(const std::string &name, const double &density, + const unsigned &dataStart, const unsigned &dataEnd); + std::pair<unsigned, unsigned> addMaterialData(const DBRowsList &matElementFraction); + unsigned int addNameTag(const std::string &name); unsigned int addAlignableTransform(const std::vector<double> ¶ms); unsigned int addTransform(const std::vector<double> ¶ms); - unsigned int addFunction(const std::string &expression); - unsigned int addSerialTransformer(const unsigned int &funcId, - const unsigned int &physvolId, - const std::string volType, - const unsigned int &copies); + unsigned int addFunction(const std::string &expression, const unsigned &dataStart, const unsigned &dataEnd); + unsigned int addSerialTransformer(const unsigned &funcId, + const unsigned &physvolId, + const std::string& volType, + const unsigned &copies); + unsigned int addShape(const std::string &type, const std::string ¶meters); + unsigned int addShape(const std::string &type, + const DBRowEntry ¶meters); + std::pair<unsigned, unsigned> addShapeData(const std::string& type, + const DBRowsList &shapeData); + unsigned int addSerialDenominator(const std::string &baseName); unsigned int addSerialIdentifier(const int &baseId); unsigned int addIdentifierTag(const int &identifier); @@ -233,7 +293,7 @@ class WriteGeoModel : public GeoNodeAction { const unsigned int &parentPhysVolId, const bool &isRootVolume); unsigned int addLogVol(const std::string &name, const unsigned int &shapeId, - const unsigned int &materialId); + std::string_view shapeType, const unsigned int &materialId); void addChildPosition(const unsigned int &parentId, const std::string &parentType, const unsigned int &childId, @@ -270,6 +330,8 @@ class WriteGeoModel : public GeoNodeAction { std::string getAddressStringFromPointer(const GeoLogVol *pointer); std::string getAddressStringFromPointer(const GeoPhysVol *pointer); std::string getAddressStringFromPointer(const GeoVPhysVol *pointer); + std::string getAddressStringFromPointer(const GeoVSurface *pointer); + std::string getAddressStringFromPointer(const GeoVSurfaceShape *pointer); std::string getAddressStringFromPointer( const GeoSerialDenominator *pointer); std::string getAddressStringFromPointer(const GeoSerialIdentifier *pointer); @@ -287,6 +349,9 @@ class WriteGeoModel : public GeoNodeAction { // moved to an Utility class, so we can use it // from TransFunctionRecorder as well. std::string getShapeParameters(const GeoShape *); + std::pair<DBRowEntry, + DBRowsList> + getShapeParametersV(const GeoShape *, const bool data = false); std::string getGeoTypeFromVPhysVol(const GeoVPhysVol *vol); @@ -307,6 +372,7 @@ class WriteGeoModel : public GeoNodeAction { std::set<std::string> m_linkSet; std::unordered_map<std::string, unsigned int> m_parentChildrenMap; std::unordered_map<std::string, unsigned int> m_volumeCopiesMap; + std::unordered_map<std::string, unsigned int> m_surfaceCopiesMap; std::unordered_map<std::string, unsigned int> m_memMap; std::unordered_map<std::string, unsigned int> m_memMap_Tables; @@ -321,25 +387,73 @@ class WriteGeoModel : public GeoNodeAction { // (for example, one used in a GeoSerialTransformer) bool m_unconnectedTree; + // chaches in the new DB schema + DBRowsList m_logVols; + // caches for GeoModel nodes to be saved into the DB - std::vector<std::vector<std::string>> m_logVols; + // std::vector<std::vector<std::string>> m_logVols; std::vector<std::vector<std::string>> m_physVols; std::vector<std::vector<std::string>> m_fullPhysVols; - std::vector<std::vector<std::string>> m_materials; - std::vector<std::vector<std::string>> m_elements; + // std::vector<std::vector<std::string>> m_materials; + // std::vector<std::vector<std::string>> m_elements; std::vector<std::vector<std::string>> m_transforms; std::vector<std::vector<std::string>> m_alignableTransforms; std::vector<std::vector<std::string>> m_serialDenominators; std::vector<std::vector<std::string>> m_serialIdentifiers; std::vector<std::vector<std::string>> m_identifierTags; std::vector<std::vector<std::string>> m_serialTransformers; - std::vector<std::vector<std::string>> m_functions; std::vector<std::vector<std::string>> m_nameTags; std::vector<std::vector<std::string>> m_shapes; + DBRowsList m_elements; + DBRowsList m_materials; + DBRowsList m_materials_Data; + + DBRowsList m_shapes_Box; + DBRowsList m_shapes_Tube; + DBRowsList m_shapes_Cons; + DBRowsList m_shapes_Para; + DBRowsList m_shapes_Trap; + DBRowsList m_shapes_Trd; + DBRowsList m_shapes_Tubs; + DBRowsList m_shapes_Torus; + DBRowsList m_shapes_TwistedTrap; + + DBRowsList m_shapes_Pcon; + DBRowsList m_shapes_Pgon; + DBRowsList m_shapes_SimplePolygonBrep; + DBRowsList m_shapes_GenericTrap; + DBRowsList m_shapes_Pcon_Data; + DBRowsList m_shapes_Pgon_Data; + DBRowsList m_shapes_SimplePolygonBrep_Data; + DBRowsList m_shapes_GenericTrap_Data; + + DBRowsList m_shapes_Shift; + DBRowsList m_shapes_Intersection; + DBRowsList m_shapes_Subtraction; + DBRowsList m_shapes_Union; + + DBRowsList m_shapes_UnidentifiedShape; + + DBRowsList m_rectangle_surface; // For Virtual Surface Shape + DBRowsList m_trapezoid_surface; + DBRowsList m_annulus_surface; + DBRowsList m_diamond_surface; + DBRowsList m_VSurface; // For Virtual Surface Abstract Class + + // std::vector<std::vector<std::string>> m_functions; + DBRowsList m_functions; // operators used in Function's expression + + // caches for additional data to be saved into the DB + DBRowEntry m_exprData; // numbers used in Function's expression + // caches for Metadata to be saved into the DB - std::vector<std::string> m_rootVolume; - std::vector<std::vector<std::string>> m_childrenPositions; + // std::vector<std::string> m_rootVolume; + std::pair<std::string, unsigned> m_rootVolume; + + // std::vector<std::vector<std::string>> m_childrenPositions; + DBRowsList m_childrenPositions; + std::vector<std::vector<std::string>> m_publishedAlignableTransforms_String; std::vector<std::vector<std::string>> m_publishedFullPhysVols_String; diff --git a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp index bb89ccaad0a12b0ff46fdc68afbbb00ad2cb32fd..b0c362b01968479b68de418862bc975414207784 100644 --- a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp +++ b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // author: Riccardo.Maria.Bianchi@cern.ch, 2017 @@ -22,6 +22,10 @@ // Updated to use the AlignableTransform 'default position', // which does not include alignment constants // +// - May 2024 - Major change: we move to the new DB schema that uses numerical data +// instead of strings/TEXT +// - Jun 2024 - R.Xue <r.xue@cern.ch><rux23@pitt.edu> +// Added methods to write out virtual surfaces to .db files // local includes #include "GeoModelWrite/WriteGeoModel.h" @@ -56,16 +60,24 @@ #include "GeoModelKernel/GeoTubs.h" #include "GeoModelKernel/GeoTwistedTrap.h" #include "GeoModelKernel/GeoUnidentifiedShape.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" + +#include "GeoModelKernel/throwExcept.h" +#include "GeoModelHelpers/StringUtils.h" // C++ includes #include <sstream> +#include <utility> namespace GeoModelIO { // TODO: should go to an utility class // FIXME: should go to an utility class -std::string joinVectorStrings(std::vector<std::string> vec, - std::string sep = "") { +std::string joinVectorStrings(const std::vector<std::string>& vec, + const std::string& sep = "") { std::string s; unsigned int ii = 0; for (const auto& piece : vec) { @@ -79,23 +91,7 @@ std::string joinVectorStrings(std::vector<std::string> vec, return s; } -// TODO: move this to utility class/file -void printStdVectorStrings(std::vector<std::string> vec) { - for (const auto& str : vec) { - std::cout << str << " "; - } - std::cout << std::endl; - return; -} -// Function to increase the precision of the conversion from double to string - -// used in the write operation -std::string to_string_with_precision(const double a_value, const int n = 16) { - std::ostringstream out; - out.precision(n); - out << std::fixed << a_value; - return out.str(); -} /// Get next child position available, given the parent type, id and copy number unsigned int WriteGeoModel::getChildPosition(const unsigned int& parentId, @@ -135,6 +131,22 @@ unsigned int WriteGeoModel::setVolumeCopyNumber(const unsigned int& volId, return m_volumeCopiesMap[key]; } +unsigned int WriteGeoModel::setSurfaceCopyNumber(const unsigned int& VSurfaceId, + const std::string& surfType) { + const unsigned int tableId = getIdFromNodeType(surfType); // deal with DBManager + std::string key = + std::to_string(tableId) + ":" + std::to_string(VSurfaceId); // INT + + std::unordered_map<std::string, unsigned int>::iterator it = + m_surfaceCopiesMap.find(key); + if (it == m_surfaceCopiesMap.end()) { + m_surfaceCopiesMap[key] = 1; // if not found, copy number is 1 + } else { + ++m_surfaceCopiesMap[key]; // if found, copy number increase by 1 + } + return m_surfaceCopiesMap[key]; +} + unsigned int WriteGeoModel::getLatestParentCopyNumber( const unsigned int& parentId, const std::string& parentType) { const unsigned int tableId = getIdFromNodeType(parentType); @@ -159,20 +171,77 @@ void WriteGeoModel::handleFullPhysVol(const GeoFullPhysVol* vol) { handleVPhysVolObjects(vol); } +//------------------------------------------------------------------------ + +void WriteGeoModel::handleVSurface(const GeoVSurface* surf) { + handleVSurfaceObjects(surf); +} + +void WriteGeoModel::handleVSurfaceObjects(const GeoVSurface* surf) { + if (m_loglevel >= 3) { + std::cout << "WriteGeoModel::handleVSurfaceObjects() -- visiting... " + << surf << std::endl; + } + + std::string address = getAddressStringFromPointer(surf); + unsigned int surfShapeId; + std::string surfShapeType; + unsigned int VSurfaceId; + std::string surfTypeStr = "GeoVSurface"; + GeoNodePath* path = getPath(); + unsigned int len = path->getLength() + 1; // VS must have parent node and must not have child node, and is never added to GeoNodePath + const GeoVPhysVol* upperVol = nullptr; + upperVol = path->getItem(len - 2); // VS definitely has NodePath lenghth larger than 1 + + /* + * VSurface features: + * - 1 parent VPhysVol (definitely) // add at ChildPosition member function + * - 1 Shape + */ + + unsigned int parentId = 0; + const GeoVPhysVol* parentNode = upperVol; + std::string parentAddress = getAddressStringFromPointer(parentNode); + parentId = getStoredIdFromAddress(parentAddress); + + if (!isAddressStored(address)) { // The VSurface is new, needs to store + const GeoVSurfaceShape* surf_shape = surf->getShape(); + surfShapeId = storeSurfaceShape(surf_shape); // surfShapeId is given by the size of container named "&m_(shape)_surface" + surfShapeType = surf_shape->type(); + VSurfaceId = storeVSurface(surf, surfShapeId, surfShapeType); // VSurfaceId is given by the size of container named "&m_VSurface" + + } else { + VSurfaceId = getStoredIdFromAddress(address); + } + const unsigned int surfCopyN = setSurfaceCopyNumber(VSurfaceId, surfTypeStr); + + // store the parent-child relationship in the DB + std::string parentType = getGeoTypeFromVPhysVol(parentNode); + + // get the copy number of the parent + // virtual surfaces always have PV as parents + const unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); + storeChildPosition(parentId, parentType, VSurfaceId, parentCopyN, + getChildPosition(parentId, parentType, parentCopyN), + surfTypeStr, surfCopyN); +} + +//------------------------------------------------------------------------ + void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { std::cout << "WriteGeoModel::handleVPhysVolObjects() -- visiting... " << vol << std::endl; } // get the address string for the current volume std::string address = getAddressStringFromPointer(vol); - // variables used to persistify the object unsigned int physId; // check the volume position in the geometry tree GeoNodePath* path = getPath(); unsigned int len = path->getLength(); + // const GeoVPhysVol* tailVol = path->getTail(); // const GeoVPhysVol* headVol = path->getHead(); const GeoVPhysVol* upperVol = nullptr; @@ -182,9 +251,6 @@ void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { // when visiting a VPhysVol node else upperVol = path->getItem(len - 1); // ROOT volume - // JFB Commented out: qDebug() << "path: " << path << " - length: " << len - // << " - upper vol: " << upperVol << " - tail vol: " << tailVol << " - head - // vol: " << headVol; std::cout << "path: " << path << std::endl; // this below is performed until the root volume is found, then "length" is // not used anymore, because not updated when recursively visiting children @@ -312,13 +378,13 @@ void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { matId = storeMaterial(mat); // store/get the Shape object into/from the DB - unsigned int shapeId; - shapeId = storeShape(shape); + const unsigned shapeId = storeShape(shape).second; + std::string_view shapeType = shape->type(); // shapeId = storeObj(shape, shapeType, shapePars); // store/get the LogVol object into/from the DB unsigned int logvolId; - logvolId = storeObj(logVol, logName, shapeId, matId); + logvolId = storeObj(logVol, logName, shapeId, shapeType, matId); if (dynamic_cast<const GeoPhysVol*>(vol)) { const GeoPhysVol* physVol = dynamic_cast<const GeoPhysVol*>(vol); @@ -351,7 +417,7 @@ void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { const unsigned int volCopyN = setVolumeCopyNumber(physId, volTypeStr); // debug msg - if (m_loglevel >= 2) { + if (m_loglevel >= 3) { std::cout << "WriteGeoModel -- physId: " << physId << "- volume copy number : " << volCopyN << std::endl; } @@ -366,7 +432,7 @@ void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { // get the copy number of the parent const unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); - std::string childType = getGeoTypeFromVPhysVol(vol); + std::string childType = getGeoTypeFromVPhysVol(vol); // TODO: dummy variable, same as volTypeStr storeChildPosition(parentId, parentType, physId, parentCopyN, getChildPosition(parentId, parentType, parentCopyN), childType, volCopyN); @@ -404,7 +470,7 @@ void WriteGeoModel::handleIdentifierTag(const GeoIdentifierTag* node) { // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; const unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); @@ -439,7 +505,7 @@ void WriteGeoModel::handleSerialIdentifier(const GeoSerialIdentifier* node) { // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; const unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); @@ -470,7 +536,7 @@ void WriteGeoModel::handleSerialDenominator(const GeoSerialDenominator* node) { // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; const unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); @@ -494,17 +560,23 @@ void WriteGeoModel::handleSerialDenominator(const GeoSerialDenominator* node) { void WriteGeoModel::handleSerialTransformer(const GeoSerialTransformer* node) { std::string address = getAddressStringFromPointer(node); - // variables used to persistify the object + //============================ + //==== variables used to persistify the object + // ID of the function used in the SerialTransformator + // when stored in the Functions table unsigned int functionId; + // ID of the PhysVol used in the SerialTransformator + // as stored in the PhysVols table unsigned int physvolId; // unsigned int physvolTable; unsigned int nCopies; unsigned int stId; + //============================ // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); // check if this object has been stored already @@ -535,31 +607,12 @@ void WriteGeoModel::handleSerialTransformer(const GeoSerialTransformer* node) { std::cout << "ERROR!!! Unknown VPhysVol type!!" << std::endl; } - /* - * Persistify the Function - */ - TransFunctionPersistifier persistifier; - try { - persistifier.persistify(*func); - } catch (const std::runtime_error& error) { - std::cout << "GeoModelWrite -- SEVERE WARNING!! Handling " - "std::runtime_error! -->" - << error.what() << std::endl; - } - std::string expression = persistifier.getCodedString(); - - if (expression.size() == 0) { - std::cout - << "FATAL ERROR!! Function expression is empty!! Aborting...\n"; - exit(EXIT_FAILURE); - } - /* * STORE/GET THE INNER OBJECTS IN THE DB */ - - // store/get the Function object in the DB - functionId = storeObj(func, expression); + + // store/get the Function's text expression in the DB + functionId = storeObj(func); // store/get the PhysVol volume in the DB @@ -602,7 +655,7 @@ void WriteGeoModel::handleTransform(const GeoTransform* node) { // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); @@ -641,7 +694,7 @@ void WriteGeoModel::handleNameTag(const GeoNameTag* node) { // get the parent volume const std::vector<std::string> parentList = getParentNode(); const unsigned int parentId = std::stoi(parentList[0]); - const std::string parentType = parentList[1]; + const std::string& parentType = parentList[1]; unsigned int parentCopyN = getLatestParentCopyNumber(parentId, parentType); // FIXME: TODO: add "if stored"... @@ -698,7 +751,7 @@ std::vector<std::string> WriteGeoModel::getParentNode() { parentId = getStoredIdFromAddress(parentAddress); } else { std::cout - << "The parent node of this child node seems to not having " + << "The parent node of this child node seems not to having " "be stored in the DB yet! [It is normal if it is the " "root volume or a transformation node used for example " "only in the definition of a 'GeoShapeShift' instance]" @@ -719,31 +772,72 @@ std::vector<std::string> WriteGeoModel::getParentNode() { } //__________________________________________________________________ -unsigned int WriteGeoModel::storeShape(const GeoShape* shape) { +std::pair<std::string, unsigned> WriteGeoModel::storeShape(const GeoShape* shape) { // QString shapeType = QString::fromStdString(shape->type()); std::string shapeType = shape->type(); // LArCustomShape is deprecated. Write it out as a GeoUnidentifiedShape; if (shapeType == "CustomShape") shapeType = "UnidentifiedShape"; + const std::set<std::string> shapesNewDB{"Box", "Tube", "Cons", "Para", "Trap", "Trd", "Tubs", "Torus", "TwistedTrap", "Pcon", "Pgon", "SimplePolygonBrep", "GenericTrap", "Intersection", "Shift", "Subtraction", "Union", "UnidentifiedShape"}; + // get shape parameters - std::string shapePars = getShapeParameters(shape); + if (shapesNewDB.count(shapeType)) + { + std::pair<DBRowEntry, DBRowsList> + shapePair = getShapeParametersV(shape); + + DBRowEntry shapePars = shapePair.first; + DBRowsList shapeData = shapePair.second; + + // DEBUG MSGS + // std::cout << "shape: " << shapeType << std::endl; + // GeoModelIO::CppHelper::printStdVectorVariants(shapePars); + // std::cout << std::endl; + + // store the shape in the DB and returns the ID + return storeObj(shape, shapeType, shapePars, shapeData); - // store the shape in the DB and returns the ID - return storeObj(shape, shapeType, shapePars); + } + else + { + std::cout << "\nWARNING! The shape '" << shapeType + << "' has not been ported to the new DB schema yet, so the old schema will be used to dump it.\n" + << std::endl; + std::string shapePars = getShapeParameters(shape); + // store the shape in the DB and returns the ID + unsigned shapeID = storeObj(shape, shapeType, shapePars); + return std::pair<std::string, unsigned>{shapeType, shapeID}; + } + return std::pair<std::string, unsigned>{}; // you should not get here } //______________________________________________________________________ unsigned int WriteGeoModel::storeMaterial(const GeoMaterial* mat) { - const std::string matName = mat->getName(); // The name of the material. - const double matDensity = mat->getDensity(); // The density of the - // material. - const unsigned int numElements = mat->getNumElements(); + const std::string matName = mat->getName(); // The name of the material + const double matDensity = mat->getDensity(); // The density of the material + const unsigned numElements = mat->getNumElements(); // The number of elements composing the material + + if (m_loglevel >= 3) { + std::cout << "mat: " << matName << " -- get n elems: " << numElements << std::endl; + } + + if (0 == numElements) { + THROW_EXCEPTION("ERROR!!! The material '" << matName << "' has zero elements!"); + } + + // std::string matElements; + // std::vector<std::string> matElementsList; + + DBRowEntry matData_ElementFraction; + DBRowsList matData_List; // loop over the elements composing the material - std::string matElements; - std::vector<std::string> matElementsList; for (unsigned int i = 0; i < numElements; i++) { + + // clear the container for the row (elemnt,fraction) + matData_ElementFraction.clear(); + // Gets the i-th element. const GeoElement* element = mat->getElement(i); std::string elName = element->getName(); @@ -752,16 +846,24 @@ unsigned int WriteGeoModel::storeMaterial(const GeoMaterial* mat) { unsigned int elementId = storeElement(element); // Gets the fraction by weight of the i-th element - const std::string elementFraction = - to_string_with_precision(mat->getFraction(i)); + const double elementFraction = mat->getFraction(i); + + // Build one row for a single element that compose + // the material: (element, fraction) + matData_ElementFraction.push_back(elementId); + matData_ElementFraction.push_back(elementFraction); - matElementsList.push_back(std::to_string(elementId) + ":" + - elementFraction); // INT+string + // matElementsList.push_back(std::to_string(elementId) + ":" + + // elementFraction); // INT+string + + // Add the (element,fraction) + // to the list of all elements for the given material + matData_List.push_back(matData_ElementFraction); } - matElements = joinVectorStrings(matElementsList, ";"); + // matElements = joinVectorStrings(matElementsList, ";"); // store the material in the DB and returns the ID - return storeObj(mat, matName, matDensity, matElements); + return storeObj(mat, matName, matDensity, matData_List); } //_______________________________________________________________________ @@ -953,35 +1055,159 @@ void WriteGeoModel::handleReferencedVPhysVol(const GeoVPhysVol* vol) { } // Get shape parameters -std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { - const std::string shapeType = shape->type(); - std::string shapePars = ""; - std::vector<std::string> pars; + +std::pair<DBRowEntry, DBRowsList> WriteGeoModel::getSurfaceParameters(const GeoVSurfaceShape* surf_shape) +{ + const std::string shapeType = surf_shape->type(); + + DBRowEntry shapePars; + DBRowsList shapeData; + std::pair<DBRowEntry, DBRowsList> shapePair; + DBRowEntry dataRow; + + double computedAreaDummy = -1; + shapePars.push_back(computedAreaDummy); + + if ("RectangleSurface" == shapeType){ + const GeoRectSurface* rect_surf = dynamic_cast<const GeoRectSurface*>(surf_shape); + shapePars.push_back(rect_surf->getXHalfLength()); + shapePars.push_back(rect_surf->getYHalfLength()); + } + else if ("TrapezoidSurface" == shapeType){ + const GeoTrapezoidSurface* trapezoid = dynamic_cast<const GeoTrapezoidSurface*>(surf_shape); + shapePars.push_back(trapezoid->getXHalfLengthMin()); + shapePars.push_back(trapezoid->getXHalfLengthMax()); + shapePars.push_back(trapezoid->getYHalfLength()); + } + else if ("AnnulusSurface" == shapeType){ + const GeoAnnulusSurface* annulus = dynamic_cast<const GeoAnnulusSurface*>(surf_shape); + shapePars.push_back(annulus->getOx()); + shapePars.push_back(annulus->getOy()); + shapePars.push_back(annulus->getRadiusIn()); + shapePars.push_back(annulus->getRadiusOut()); + shapePars.push_back(annulus->getPhi()); + } + else if ("DiamondSurface" == shapeType){ + const GeoDiamondSurface* diamond = dynamic_cast<const GeoDiamondSurface*>(surf_shape); + shapePars.push_back(diamond->getXbottomHalf()); + shapePars.push_back(diamond->getXmidHalf()); + shapePars.push_back(diamond->getXtopHalf()); + shapePars.push_back(diamond->getYbottomHalf()); + shapePars.push_back(diamond->getYtopHalf()); + } + else + { + std::cout << "\n\tGeoModelWrite -- WARNING!!! - Shape '" << shapeType + << "' is not supported in the new DB format, yet.\n\n"; + } + + shapePair.first = shapePars; + shapePair.second = shapeData; + return shapePair; +} + +std::pair<DBRowEntry, DBRowsList> WriteGeoModel::getShapeParametersV(const GeoShape *shape, const bool data) +{ + const std::string shapeType = shape->type(); - if (shapeType == "Box") { - const GeoBox* box = dynamic_cast<const GeoBox*>(shape); - pars.push_back("XHalfLength=" + - to_string_with_precision(box->getXHalfLength())); - pars.push_back("YHalfLength=" + - to_string_with_precision(box->getYHalfLength())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(box->getZHalfLength())); - shapePars = joinVectorStrings(pars, ";"); - } else if (shapeType == "Cons") { + DBRowEntry shapePars; + DBRowsList shapeData; + std::pair<DBRowEntry, DBRowsList> shapePair; + DBRowEntry dataRow; + + // init the 'computedVolume' column with a dummy value: '-1' + // the real value will be added later, when the DB will be passed throug + // the tool to compute the volume for the shapes and store them + double computedVolumeDummy = -1; + shapePars.push_back(computedVolumeDummy); + + if ("Box" == shapeType) + { + const GeoBox *box = dynamic_cast<const GeoBox *>(shape); + shapePars.push_back(box->getXHalfLength()); + shapePars.push_back(box->getYHalfLength()); + shapePars.push_back(box->getZHalfLength()); + } + else if ("Tube" == shapeType) + { + const GeoTube *tube = dynamic_cast<const GeoTube *>(shape); + shapePars.push_back(tube->getRMin()); + shapePars.push_back(tube->getRMax()); + shapePars.push_back(tube->getZHalfLength()); + } + else if (shapeType == "Cons") + { const GeoCons* shapeIn = dynamic_cast<const GeoCons*>(shape); - pars.push_back("RMin1=" + - to_string_with_precision(shapeIn->getRMin1())); - pars.push_back("RMin2=" + - to_string_with_precision(shapeIn->getRMin2())); - pars.push_back("RMax1=" + - to_string_with_precision(shapeIn->getRMax1())); - pars.push_back("RMax2=" + - to_string_with_precision(shapeIn->getRMax2())); - pars.push_back("DZ=" + to_string_with_precision(shapeIn->getDZ())); - pars.push_back("SPhi=" + to_string_with_precision(shapeIn->getSPhi())); - pars.push_back("DPhi=" + to_string_with_precision(shapeIn->getDPhi())); - } else if (shapeType == "Torus") { + shapePars.push_back(shapeIn->getRMin1()); + shapePars.push_back(shapeIn->getRMin2()); + shapePars.push_back(shapeIn->getRMax1()); + shapePars.push_back(shapeIn->getRMax2()); + shapePars.push_back(shapeIn->getDZ()); + shapePars.push_back(shapeIn->getSPhi()); + shapePars.push_back(shapeIn->getDPhi()); + } + else if (shapeType == "Para") + { + const GeoPara* shapeIn = dynamic_cast<const GeoPara*>(shape); + shapePars.push_back(shapeIn->getXHalfLength()); + shapePars.push_back(shapeIn->getYHalfLength()); + shapePars.push_back(shapeIn->getZHalfLength()); + shapePars.push_back(shapeIn->getAlpha()); + shapePars.push_back(shapeIn->getTheta()); + shapePars.push_back(shapeIn->getPhi()); + } + else if (shapeType == "Trap") + { + const GeoTrap* shapeIn = dynamic_cast<const GeoTrap*>(shape); + shapePars.push_back(shapeIn->getZHalfLength()); + shapePars.push_back(shapeIn->getTheta()); + shapePars.push_back(shapeIn->getPhi()); + shapePars.push_back(shapeIn->getDydzn()); + shapePars.push_back(shapeIn->getDxdyndzn()); + shapePars.push_back(shapeIn->getDxdypdzn()); + shapePars.push_back(shapeIn->getAngleydzn()); + shapePars.push_back(shapeIn->getDydzp()); + shapePars.push_back(shapeIn->getDxdyndzp()); + shapePars.push_back(shapeIn->getDxdypdzp()); + shapePars.push_back(shapeIn->getAngleydzp()); + } + else if (shapeType == "Trd") + { + const GeoTrd* shapeIn = dynamic_cast<const GeoTrd*>(shape); + shapePars.push_back(shapeIn->getXHalfLength1()); + shapePars.push_back(shapeIn->getXHalfLength2()); + shapePars.push_back(shapeIn->getYHalfLength1()); + shapePars.push_back(shapeIn->getYHalfLength2()); + shapePars.push_back(shapeIn->getZHalfLength()); + } + else if (shapeType == "TwistedTrap") + { + const GeoTwistedTrap *shapeIn = + dynamic_cast<const GeoTwistedTrap *>(shape); + shapePars.push_back(shapeIn->getPhiTwist()); + shapePars.push_back(shapeIn->getZHalfLength()); + shapePars.push_back(shapeIn->getTheta()); + shapePars.push_back(shapeIn->getPhi()); + shapePars.push_back(shapeIn->getY1HalfLength()); + shapePars.push_back(shapeIn->getX1HalfLength()); + shapePars.push_back(shapeIn->getX2HalfLength()); + shapePars.push_back(shapeIn->getY2HalfLength()); + shapePars.push_back(shapeIn->getX3HalfLength()); + shapePars.push_back(shapeIn->getX4HalfLength()); + shapePars.push_back(shapeIn->getTiltAngleAlpha()); + } + else if (shapeType == "Tubs") + { + const GeoTubs *shapeIn = dynamic_cast<const GeoTubs *>(shape); + shapePars.push_back(shapeIn->getRMin()); + shapePars.push_back(shapeIn->getRMax()); + shapePars.push_back(shapeIn->getZHalfLength()); + shapePars.push_back(shapeIn->getSPhi()); + shapePars.push_back(shapeIn->getDPhi()); + } + else if (shapeType == "Torus") + { // Member Data: // * Rmax - outside radius of the torus tube // * Rmin - inside radius of the torus tube (Rmin=0 if not hollow) @@ -991,144 +1217,183 @@ std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { // * DPhi - delta angle of the segment in radians // const GeoTorus* shapeIn = dynamic_cast<const GeoTorus*>(shape); - pars.push_back("Rmin=" + to_string_with_precision(shapeIn->getRMin())); - pars.push_back("Rmax=" + to_string_with_precision(shapeIn->getRMax())); - pars.push_back("Rtor=" + to_string_with_precision(shapeIn->getRTor())); - pars.push_back("SPhi=" + to_string_with_precision(shapeIn->getSPhi())); - pars.push_back("DPhi=" + to_string_with_precision(shapeIn->getDPhi())); - } else if (shapeType == "Para") { - const GeoPara* shapeIn = dynamic_cast<const GeoPara*>(shape); - pars.push_back("XHalfLength=" + - to_string_with_precision(shapeIn->getXHalfLength())); - pars.push_back("YHalfLength=" + - to_string_with_precision(shapeIn->getYHalfLength())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("Alpha=" + - to_string_with_precision(shapeIn->getAlpha())); - pars.push_back("Theta=" + - to_string_with_precision(shapeIn->getTheta())); - pars.push_back("Phi=" + to_string_with_precision(shapeIn->getPhi())); - } else if (shapeType == "Pcon") { + shapePars.push_back(shapeIn->getRMin()); + shapePars.push_back(shapeIn->getRMax()); + shapePars.push_back(shapeIn->getRTor()); + shapePars.push_back(shapeIn->getSPhi()); + shapePars.push_back(shapeIn->getDPhi()); + } + else if (shapeType == "Pcon") + { const GeoPcon* shapeIn = dynamic_cast<const GeoPcon*>(shape); - pars.push_back("SPhi=" + to_string_with_precision(shapeIn->getSPhi())); - pars.push_back("DPhi=" + to_string_with_precision(shapeIn->getDPhi())); + shapePars.push_back(shapeIn->getSPhi()); + shapePars.push_back(shapeIn->getDPhi()); // get number of Z planes and loop over them const int nZplanes = shapeIn->getNPlanes(); - pars.push_back("NZPlanes=" + std::to_string(nZplanes)); // INT + shapePars.push_back(nZplanes); for (int i = 0; i < nZplanes; ++i) { - pars.push_back("ZPos=" + - to_string_with_precision(shapeIn->getZPlane(i))); - pars.push_back("ZRmin=" + - to_string_with_precision(shapeIn->getRMinPlane(i))); - pars.push_back("ZRmax=" + - to_string_with_precision(shapeIn->getRMaxPlane(i))); + dataRow.push_back(shapeIn->getZPlane(i)); + dataRow.push_back(shapeIn->getRMinPlane(i)); + dataRow.push_back(shapeIn->getRMaxPlane(i)); + shapeData.push_back(dataRow); + dataRow.clear(); } - } else if (shapeType == "Pgon") { + } + else if (shapeType == "Pgon") + { const GeoPgon* shapeIn = dynamic_cast<const GeoPgon*>(shape); - pars.push_back("SPhi=" + to_string_with_precision(shapeIn->getSPhi())); - pars.push_back("DPhi=" + to_string_with_precision(shapeIn->getDPhi())); - pars.push_back("NSides=" + - std::to_string(shapeIn->getNSides())); // INT + shapePars.push_back(shapeIn->getSPhi()); + shapePars.push_back(shapeIn->getDPhi()); + shapePars.push_back(shapeIn->getNSides()); // get number of Z planes and loop over them const int nZplanes = shapeIn->getNPlanes(); - pars.push_back("NZPlanes=" + std::to_string(nZplanes)); // INT + shapePars.push_back(nZplanes); for (int i = 0; i < nZplanes; ++i) { - pars.push_back("ZPos=" + - to_string_with_precision(shapeIn->getZPlane(i))); - pars.push_back("ZRmin=" + - to_string_with_precision(shapeIn->getRMinPlane(i))); - pars.push_back("ZRmax=" + - to_string_with_precision(shapeIn->getRMaxPlane(i))); + dataRow.push_back(shapeIn->getZPlane(i)); + dataRow.push_back(shapeIn->getRMinPlane(i)); + dataRow.push_back(shapeIn->getRMaxPlane(i)); + shapeData.push_back(dataRow); + dataRow.clear(); } - } else if (shapeType == "SimplePolygonBrep") { - const GeoSimplePolygonBrep* shapeIn = - dynamic_cast<const GeoSimplePolygonBrep*>(shape); - pars.push_back("DZ=" + to_string_with_precision(shapeIn->getDZ())); - // get number of vertices and loop over them + } + else if (shapeType == "SimplePolygonBrep") + { + const GeoSimplePolygonBrep* shapeIn = dynamic_cast<const GeoSimplePolygonBrep*>(shape); + shapePars.push_back(shapeIn->getDZ()); + // get number of Z planes and loop over them const int nVertices = shapeIn->getNVertices(); - pars.push_back("NVertices=" + std::to_string(nVertices)); // INT + shapePars.push_back(nVertices); for (int i = 0; i < nVertices; ++i) { - pars.push_back("xV=" + - to_string_with_precision(shapeIn->getXVertex(i))); - pars.push_back("yV=" + - to_string_with_precision(shapeIn->getYVertex(i))); + dataRow.push_back(shapeIn->getXVertex(i)); + dataRow.push_back(shapeIn->getYVertex(i)); + shapeData.push_back(dataRow); + dataRow.clear(); } - } else if (shapeType == "Trap") { - const GeoTrap* shapeIn = dynamic_cast<const GeoTrap*>(shape); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("Theta=" + - to_string_with_precision(shapeIn->getTheta())); - pars.push_back("Phi=" + to_string_with_precision(shapeIn->getPhi())); - pars.push_back("Dydzn=" + - to_string_with_precision(shapeIn->getDydzn())); - pars.push_back("Dxdyndzn=" + - to_string_with_precision(shapeIn->getDxdyndzn())); - pars.push_back("Dxdypdzn=" + - to_string_with_precision(shapeIn->getDxdypdzn())); - pars.push_back("Angleydzn=" + - to_string_with_precision(shapeIn->getAngleydzn())); - pars.push_back("Dydzp=" + - to_string_with_precision(shapeIn->getDydzp())); - pars.push_back("Dxdyndzp=" + - to_string_with_precision(shapeIn->getDxdyndzp())); - pars.push_back("Dxdypdzp=" + - to_string_with_precision(shapeIn->getDxdypdzp())); - pars.push_back("Angleydzp=" + - to_string_with_precision(shapeIn->getAngleydzp())); - } else if (shapeType == "TwistedTrap") { - const GeoTwistedTrap* shapeIn = - dynamic_cast<const GeoTwistedTrap*>(shape); - pars.push_back("PhiTwist=" + - to_string_with_precision(shapeIn->getPhiTwist())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("Theta=" + - to_string_with_precision(shapeIn->getTheta())); - pars.push_back("Phi=" + to_string_with_precision(shapeIn->getPhi())); - pars.push_back("DY1HalfLength=" + - to_string_with_precision(shapeIn->getY1HalfLength())); - pars.push_back("DX1HalfLength=" + - to_string_with_precision(shapeIn->getX1HalfLength())); - pars.push_back("DX2HalfLength=" + - to_string_with_precision(shapeIn->getX2HalfLength())); - pars.push_back("DY2HalfLength=" + - to_string_with_precision(shapeIn->getY2HalfLength())); - pars.push_back("DX3HalfLength=" + - to_string_with_precision(shapeIn->getX3HalfLength())); - pars.push_back("DX4HalfLength=" + - to_string_with_precision(shapeIn->getX4HalfLength())); - pars.push_back("DTiltAngleAlpha=" + - to_string_with_precision(shapeIn->getTiltAngleAlpha())); - - } else if (shapeType == "Trd") { - const GeoTrd* shapeIn = dynamic_cast<const GeoTrd*>(shape); - pars.push_back("XHalfLength1=" + - to_string_with_precision(shapeIn->getXHalfLength1())); - pars.push_back("XHalfLength2=" + - to_string_with_precision(shapeIn->getXHalfLength2())); - pars.push_back("YHalfLength1=" + - to_string_with_precision(shapeIn->getYHalfLength1())); - pars.push_back("YHalfLength2=" + - to_string_with_precision(shapeIn->getYHalfLength2())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - } else if (shapeType == "Tube") { - const GeoTube* tube = dynamic_cast<const GeoTube*>(shape); - pars.push_back("RMin=" + to_string_with_precision(tube->getRMin())); - pars.push_back("RMax=" + to_string_with_precision(tube->getRMax())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(tube->getZHalfLength())); - } else if (shapeType == "Tubs") { - const GeoTubs* shapeIn = dynamic_cast<const GeoTubs*>(shape); - pars.push_back("RMin=" + to_string_with_precision(shapeIn->getRMin())); - pars.push_back("RMax=" + to_string_with_precision(shapeIn->getRMax())); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("SPhi=" + to_string_with_precision(shapeIn->getSPhi())); - pars.push_back("DPhi=" + to_string_with_precision(shapeIn->getDPhi())); - } else if (shapeType == "TessellatedSolid") { + } + else if (shapeType == "GenericTrap") { + const GeoGenericTrap* shapeIn = dynamic_cast<const GeoGenericTrap*>(shape); + + shapePars.push_back(shapeIn->getZHalfLength()); + // get number of Z planes and loop over them + const int nVertices = shapeIn->getVertices().size(); + shapePars.push_back(nVertices); + for (int i = 0; i < nVertices; ++i) { + dataRow.push_back(shapeIn->getVertices()[i](0)); + dataRow.push_back(shapeIn->getVertices()[i](1)); + shapeData.push_back(dataRow); + dataRow.clear(); + } + } + else if (shapeType == "Intersection") + { + const GeoShapeIntersection* shapeIn = dynamic_cast<const GeoShapeIntersection*>(shape); + + // get the two referenced Shape nodes used in the 'Intersection' operation, + // then store them in the DB + const GeoShape* shapeOpA = shapeIn->getOpA(); + const std::pair<std::string, unsigned> shapeStoredA = storeShape(shapeOpA); + const std::string shapeTypeA = shapeStoredA.first; + const unsigned int shapeIdA = shapeStoredA.second; + + const GeoShape* shapeOpB = shapeIn->getOpB(); + const std::pair<std::string, unsigned> shapeStoredB = storeShape(shapeOpB); + const std::string shapeTypeB = shapeStoredB.first; + const unsigned int shapeIdB = shapeStoredB.second; + + shapePars.push_back(shapeTypeA); + shapePars.push_back(shapeIdA); + shapePars.push_back(shapeTypeB); + shapePars.push_back(shapeIdB); + } + else if (shapeType == "Shift") + { + const GeoShapeShift* shapeIn = dynamic_cast<const GeoShapeShift*>(shape); + + // get the referenced Shape used in the 'shift' operation, + // then store it in the DB + const GeoShape* shapeOp = shapeIn->getOp(); + const std::pair<std::string, unsigned> shapeStored = storeShape(shapeOp); + const std::string shapeType = shapeStored.first; + const unsigned int shapeId = shapeStored.second; + // get the Transformation, then store it in the DB + GeoTransform* transf = new GeoTransform(shapeIn->getX()); + const unsigned int transfId = storeTranform(transf); + + shapePars.push_back(shapeType); + shapePars.push_back(shapeId); + shapePars.push_back(transfId); + } + else if (shapeType == "Subtraction") + { + const GeoShapeSubtraction* shapeIn = dynamic_cast<const GeoShapeSubtraction*>(shape); + + // get the two referenced Shape nodes used in the 'Subtraction' operation, + // then store them in the DB + const GeoShape* shapeOpA = shapeIn->getOpA(); + const std::pair<std::string, unsigned> shapeStoredA = storeShape(shapeOpA); + const std::string shapeTypeA = shapeStoredA.first; + const unsigned int shapeIdA = shapeStoredA.second; + + const GeoShape* shapeOpB = shapeIn->getOpB(); + const std::pair<std::string, unsigned> shapeStoredB = storeShape(shapeOpB); + const std::string shapeTypeB = shapeStoredB.first; + const unsigned int shapeIdB = shapeStoredB.second; + + shapePars.push_back(shapeTypeA); + shapePars.push_back(shapeIdA); + shapePars.push_back(shapeTypeB); + shapePars.push_back(shapeIdB); + + } + else if (shapeType == "Union") + { + const GeoShapeUnion* shapeIn = dynamic_cast<const GeoShapeUnion*>(shape); + + // get the two referenced Shape nodes used in the 'Subtraction' operation, + // then store them in the DB + const GeoShape* shapeOpA = shapeIn->getOpA(); + const std::pair<std::string, unsigned> shapeStoredA = storeShape(shapeOpA); + const std::string shapeTypeA = shapeStoredA.first; + const unsigned int shapeIdA = shapeStoredA.second; + + const GeoShape* shapeOpB = shapeIn->getOpB(); + const std::pair<std::string, unsigned> shapeStoredB = storeShape(shapeOpB); + const std::string shapeTypeB = shapeStoredB.first; + const unsigned int shapeIdB = shapeStoredB.second; + + shapePars.push_back(shapeTypeA); + shapePars.push_back(shapeIdA); + shapePars.push_back(shapeTypeB); + shapePars.push_back(shapeIdB); + + } else if (shapeType == "UnidentifiedShape") { + const GeoUnidentifiedShape* shapeIn = dynamic_cast<const GeoUnidentifiedShape*>(shape); + shapePars.push_back(shapeIn->name()); + shapePars.push_back(shapeIn->asciiData()); + } + else + { + std::cout << "\n\tGeoModelWrite -- WARNING!!! - Shape '" << shapeType + << "' is not supported in the new DB format, yet.\n\n"; + // CppHelper::printStdVectorStrings(m_objectsNotPersistified); + } + + shapePair.first = shapePars; + shapePair.second = shapeData; + return shapePair; +} + + +// OLD VERSIONS!!!! TO BE REMOVED WHEN ALL SHAPES ARE MIGRATED!! +// Get shape parameters +std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { + const std::string shapeType = shape->type(); + + std::string shapePars = ""; + std::vector<std::string> pars; + + if (false) {} + else if (shapeType == "TessellatedSolid") { const GeoTessellatedSolid* shapeIn = dynamic_cast<const GeoTessellatedSolid*>(shape); // get number of facets @@ -1155,96 +1420,20 @@ std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { for (size_t i = 0; i < nVertices; ++i) { GeoFacetVertex facetVertex = facet->getVertex(i); pars.push_back("xV=" + - to_string_with_precision(facetVertex[0])); + GeoStrUtils::to_string_with_precision(facetVertex[0])); pars.push_back("yV=" + - to_string_with_precision(facetVertex[1])); + GeoStrUtils::to_string_with_precision(facetVertex[1])); pars.push_back("zV=" + - to_string_with_precision(facetVertex[2])); + GeoStrUtils::to_string_with_precision(facetVertex[2])); } } - } else if (shapeType == "Intersection") { - const GeoShapeIntersection* shapeIn = - dynamic_cast<const GeoShapeIntersection*>(shape); - // get the referenced Shape used in the 'union' operation, store it in - // the DB - const GeoShape* shapeOpA = shapeIn->getOpA(); - const unsigned int shapeIdA = storeShape(shapeOpA); - const GeoShape* shapeOpB = shapeIn->getOpB(); - const unsigned int shapeIdB = storeShape(shapeOpB); - pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - } else if (shapeType == "Shift") { - const GeoShapeShift* shapeIn = - dynamic_cast<const GeoShapeShift*>(shape); - - // get the referenced Shape used in the 'shift' operation, store it in - // the DB - const GeoShape* shapeOp = shapeIn->getOp(); - const unsigned int shapeId = storeShape(shapeOp); - - // get the Transformation, store it in the DB - GeoTransform* transf = new GeoTransform(shapeIn->getX()); - const unsigned int trId = storeTranform(transf); - - pars.push_back("A=" + std::to_string(shapeId)); // INT - pars.push_back("X=" + std::to_string(trId)); // INT - } else if (shapeType == "Subtraction") { - const GeoShapeSubtraction* shapeIn = - dynamic_cast<const GeoShapeSubtraction*>(shape); - // get the referenced Shape used in the 'union' operation, store it in - // the DB - const GeoShape* shapeOpA = shapeIn->getOpA(); - const unsigned int shapeIdA = storeShape(shapeOpA); - const GeoShape* shapeOpB = shapeIn->getOpB(); - const unsigned int shapeIdB = storeShape(shapeOpB); - pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - } else if (shapeType == "Union") { - const GeoShapeUnion* shapeIn = - dynamic_cast<const GeoShapeUnion*>(shape); - - // get the referenced Shape used in the 'union' operation, store it in - // the DB - const GeoShape* shapeOpA = shapeIn->getOpA(); - unsigned int shapeIdA = storeShape(shapeOpA); - const GeoShape* shapeOpB = shapeIn->getOpB(); - unsigned int shapeIdB = storeShape(shapeOpB); - - pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - } else if (shapeType == "GenericTrap") { - const GeoGenericTrap* shapeIn = - dynamic_cast<const GeoGenericTrap*>(shape); - pars.push_back("ZHalfLength=" + - to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("NVertices=" + - to_string_with_precision(shapeIn->getVertices().size())); - for (unsigned long i = 0; i < shapeIn->getVertices().size(); ++i) { - pars.push_back( - "X=" + to_string_with_precision(shapeIn->getVertices()[i](0))); - pars.push_back( - "Y=" + to_string_with_precision(shapeIn->getVertices()[i](1))); - } - } else if (shapeType == "UnidentifiedShape") { - const GeoUnidentifiedShape* shapeIn = - dynamic_cast<const GeoUnidentifiedShape*>(shape); - pars.push_back("name=" + shapeIn->name()); - pars.push_back("asciiData=" + shapeIn->asciiData()); - } - // LAr custom shape - // else if(shapeType == "CustomShape") { - // std::cout << "\n\tWARNING!!! - Use of LArCustomShape is deprecated, - // translating to GeoUnidentifiedShape representation!!\n\n"; const - // LArCustomShape* shapeIn = dynamic_cast<const LArCustomShape*> (shape); - // QStringList pars; - // pars << "name=LArCustomShape"; - // pars << "asciiData="+QString::fromStdString(shapeIn->name()); - // shapePars=pars.join(";"); - // } + } else { - std::cout << "\n\tGeoModelWrite -- WARNING!!! - Shape '" << shapeType - << "' needs to be persistified!!\n\n"; - printStdVectorStrings(m_objectsNotPersistified); + std::string errMsg = "GeoModelWrite -- ERROR!!! - Shape '" + shapeType + + "' needs to be persistified!!"; + std::cout << "\n\nobject to be persistified:" << std::endl; + GeoStrUtils::printStdVectorStrings(m_objectsNotPersistified); + THROW_EXCEPTION(errMsg); } shapePars = joinVectorStrings(pars, ";"); @@ -1331,13 +1520,18 @@ void WriteGeoModel::showMemoryMap() { unsigned int WriteGeoModel::storeObj(const GeoMaterial* pointer, const std::string& name, - const double& density, - const std::string& elements) { + const double &density, + const DBRowsList &materialData) { std::string address = getAddressStringFromPointer(pointer); unsigned int materialId; if (!isAddressStored(address)) { - materialId = addMaterial(name, density, elements); + // Store the material's additional data, + // that is, the list of the elements that compose the material and their fraction + std::pair<unsigned, unsigned> dataRows = addMaterialData(materialData); + unsigned dataStart = dataRows.first; + unsigned dataEnd = dataRows.second; + materialId = addMaterial(name, density, dataStart, dataEnd); storeAddress(address, materialId); } else { materialId = getStoredIdFromAddress(address); @@ -1349,42 +1543,77 @@ unsigned int WriteGeoModel::storeObj(const GeoElement* pointer, const std::string& name, const std::string& symbol, const double& elZ, const double& elA) { + if(m_loglevel>=3) std::cout << "storing " << name << std::endl; std::string address = getAddressStringFromPointer(pointer); unsigned int elementId; if (!isAddressStored(address)) { elementId = addElement(name, symbol, elZ, elA); storeAddress(address, elementId); + if(m_loglevel>=3) std::cout << "stored\n"; } else { elementId = getStoredIdFromAddress(address); + if(m_loglevel>=3) std::cout << "retrieved from cache\n"; } return elementId; } unsigned int WriteGeoModel::storeObj(const GeoShape* pointer, - const std::string& name, + const std::string& shapeName, const std::string& parameters) { std::string address = getAddressStringFromPointer(pointer); unsigned int shapeId; if (!isAddressStored(address)) { - shapeId = addShape(name, parameters); + shapeId = addShape(shapeName, parameters); storeAddress(address, shapeId); } else { shapeId = getStoredIdFromAddress(address); } return shapeId; } +std::pair<std::string, unsigned> WriteGeoModel::storeObj(const GeoShape* pointer, + const std::string& shapeName, + DBRowEntry& parameters, + const DBRowsList &shapeData) { + std::string address = getAddressStringFromPointer(pointer); + + unsigned int shapeId; + if (!isAddressStored(address)) { + + // if the shape has additional data, store them in the DB, + // get the start and end rows, then add those to the shape + // parameters to be stored with the shape + if (shapeData.size() > 0) + { + // Store the node's additional data + // (e.g., the numeric values of a Function, or the ZPlanes of a GeoPcon shape node) + std::pair<unsigned, unsigned> dataRows = addShapeData(shapeName, shapeData); + unsigned dataStart = dataRows.first; + unsigned dataEnd = dataRows.second; + parameters.push_back(dataStart); + parameters.push_back(dataEnd); + } + shapeId = addShape(shapeName, parameters); + storeAddress(address, shapeId); // TODO: check if this step of storing the address and the ID is still used/needed. + } else { + // TODO: check if that is still needed/used! And if it's consistent with the new DB schema. + shapeId = getStoredIdFromAddress(address); // TODO: check if this step of getting the ID from the address is still used/needed. + } + std::pair<std::string, unsigned> ret{shapeName, shapeId}; + return ret; +} unsigned int WriteGeoModel::storeObj(const GeoLogVol* pointer, const std::string& name, const unsigned int& shapeId, + std::string_view shapeType, const unsigned int& materialId) { std::string address = getAddressStringFromPointer(pointer); unsigned int logvolId; if (!isAddressStored(address)) { - logvolId = addLogVol(name, shapeId, materialId); + logvolId = addLogVol(name, shapeId, shapeType, materialId); storeAddress(address, logvolId); } else { logvolId = getStoredIdFromAddress(address); @@ -1428,6 +1657,54 @@ unsigned int WriteGeoModel::storeObj(const GeoFullPhysVol* pointer, return physvolId; } +//__________________________________________________________________ + +unsigned int WriteGeoModel::storeVSurface(const GeoVSurface* pointer, const unsigned int& surfShapeId, const std::string& surfShapeType) { + // SurfaceShape address is different from VSurface address + // VSurface has position info, similar to GeoFullPhysVol + unsigned int VSurfaceId; + std::string address = getAddressStringFromPointer(pointer); + VSurfaceId = addVSurface(surfShapeType, surfShapeId); + storeAddress(address, VSurfaceId); + return VSurfaceId; +} + + +unsigned int WriteGeoModel::storeSurfaceShape(const GeoVSurfaceShape* surf_shape) { + + std::string shapeType = surf_shape->type(); + std::pair<DBRowEntry, DBRowsList> shapePair = getSurfaceParameters(surf_shape); + DBRowEntry shapePars = shapePair.first; + DBRowsList shapeData = shapePair.second; + return storeObj(surf_shape, shapeType, shapePars, shapeData); // return surfShapeId +} + +unsigned int WriteGeoModel::storeObj(const GeoVSurfaceShape* pointer, const std::string& shapeName, DBRowEntry& parameters, const DBRowsList &shapeData) { + + std::string address = getAddressStringFromPointer(pointer); + unsigned int surfShapeId; + if (!isAddressStored(address)) { + //if (shapeData.size() > 0) + //{ + // Store the node's additional data + // Rectangualr Virtual Surface now doesn't need to do this + // std::pair<unsigned, unsigned> dataRows = addShapeData(shapeName, shapeData); //TODO: need to be revised for more complicated surfaces in future + // unsigned dataStart = dataRows.first; + // unsigned dataEnd = dataRows.second; + // parameters.push_back(dataStart); + // parameters.push_back(dataEnd); + //} + surfShapeId = addSurfaceShape(shapeName, parameters); // store parameters for surfaceShape + storeAddress(address, surfShapeId); // TODO: check if this step of storing the address and the ID is still used/needed. + } else { + // TODO: check if that is still needed/used! And if it's consistent with the new DB schema. + surfShapeId = getStoredIdFromAddress(address); // TODO: this is needed, because we need to check whether the surface shape could be shared, + } // then return ID to VSurface, and VSurface cannot be shared + return surfShapeId; +} + +//__________________________________________________________________ + unsigned int WriteGeoModel::storeObj(const GeoSerialIdentifier* pointer, const int& baseId) { const std::string address = getAddressStringFromPointer(pointer); @@ -1494,13 +1771,39 @@ unsigned int WriteGeoModel::storeObj(const GeoSerialTransformer* pointer, return id; } -unsigned int WriteGeoModel::storeObj(const GeoXF::Function* pointer, - const std::string& expression) { +unsigned int WriteGeoModel::storeObj(const GeoXF::Function* pointer) { + // const std::string& expression, + // const std::deque<double>& exprData) { const std::string address = getAddressStringFromPointer(pointer); unsigned int id = 0; if (!isAddressStored(address)) { - id = addFunction(expression); + /* + * Persistify the Function + */ + TransFunctionPersistifier persistifier; + try { + persistifier.persistify(*pointer); + } catch (const std::runtime_error& error) { + std::cout << "GeoModelWrite -- SEVERE WARNING!! Handling " + "std::runtime_error! -->" + << error.what() << std::endl; + } + const std::string& expression = persistifier.getCodedString(); + std::deque<double> exprData = persistifier.getFloatingPointData(); + + if (expression.size() == 0) { + std::cout + << "FATAL ERROR!! Function expression is empty!! Aborting...\n"; + exit(EXIT_FAILURE); + } + // Store the Function's numbers + std::vector<unsigned> dataRows = addExprData(exprData); + unsigned dataStart = dataRows[0]; + unsigned dataEnd = dataRows[1]; + + // store the Function + id = addFunction(expression, dataStart, dataEnd); storeAddress(address, id); } else { @@ -1514,6 +1817,24 @@ unsigned int WriteGeoModel::storeObj(const GeoXF::Function* pointer, return id; } +// unsigned int WriteGeoModel::storeExprData(const unsigned funcId, std::deque exprData) { +// // store/get the Function's data numbers in the DB +// std::cout << "\n\n********** storing Func's data...\n"; +// // start and end row numbers for the Function's data +// // as stored in the ExpData tables +// unsigned dataStartRow = 0; +// unsigned dataEndRow = 0; +// unsigned ii = 0; +// unsigned nNums = exprData.size(); +// for (const auto &num : exprData) +// { +// std::cout << "num: " << num << std::endl; +// unsigned row = storeExprData(num); +// if (0 == ii) dataStartRow = row; +// else if ( (nNums - 1) == ii ) dataEndRow = row; +// } +// } + unsigned int WriteGeoModel::storeObj(const GeoTransform* pointer, const std::vector<double>& parameters) { const std::string address = getAddressStringFromPointer(pointer); @@ -1594,7 +1915,7 @@ void WriteGeoModel::storeChildPosition(const unsigned int& parentId, unsigned int WriteGeoModel::addRecord( std::vector<std::vector<std::string>>* container, - const std::vector<std::string> values) const { + const std::vector<std::string>& values) const { container->push_back(values); unsigned int idx = container->size(); // index of pushed element = size after pushing, to @@ -1602,24 +1923,122 @@ unsigned int WriteGeoModel::addRecord( return idx; } +unsigned int WriteGeoModel::addRecord( + DBRowsList* container, + const DBRowEntry& values) const { + container->push_back(values); + unsigned int idx = + container->size(); // index of pushed element = size after pushing, to + // match ID starting at 1 in the DB + return idx; +} + +std::pair<unsigned, unsigned> WriteGeoModel::addRecordData( + DBRowsList *container, + const DBRowsList& values) const +{ + const unsigned dataStart = container->size() + 1; + // Note: ^ we add +1 because start filling the table + // from a new row with respect to what we currently have + + for (const auto &val : values) + { + container->push_back(val); + } + unsigned dataEnd = + container->size(); // index of pushed element = size after pushing, to + // match ID starting at 1 in the DB + std::pair<unsigned, unsigned> ret{dataStart, dataEnd}; + return ret; +} + +std::vector<unsigned> WriteGeoModel::addExprData( + const std::deque<double>& exprData) +{ + DBRowEntry *container = &m_exprData; + const unsigned dataStart = container->size() + 1; + // Note: ^ we add +1 because start filling the table + // from a new row with respect to what we currently have + + for (const auto& num : exprData) { + // std::cout << "num: " << GeoModelIO::GeoStrUtils::to_string_with_precision(num) << std::endl; // DEBUG MSG + container->push_back(num); + } + unsigned dataEnd = + container->size(); // index of pushed element = size after pushing, to + // match ID starting at 1 in the DB + + std::vector<unsigned> dataRows; + dataRows.push_back(dataStart); + dataRows.push_back(dataEnd); + return dataRows; +} + +std::pair<unsigned, unsigned> WriteGeoModel::addShapeData(const std::string& type, + const DBRowsList& shapeData) +{ + DBRowsList *container = nullptr; + + if ("Pcon" == type) { + container = &m_shapes_Pcon_Data; + } + else if ("Pgon" == type) { + container = &m_shapes_Pgon_Data; + } + else if ("SimplePolygonBrep" == type) { + container = &m_shapes_SimplePolygonBrep_Data; + } + else if ("GenericTrap" == type) { + container = &m_shapes_GenericTrap_Data; + } + else { + std::cout << "\nERROR!!! Shape data for shape '" << type << "' have not been set, yet!\n" << std::endl; + } + + std::pair<unsigned, unsigned> dataPair = addRecordData(container, shapeData); + return dataPair; +} +std::pair<unsigned, unsigned> WriteGeoModel::addMaterialData(const DBRowsList& matListElementFraction) +{ + DBRowsList *container = &m_materials_Data; + std::pair<unsigned, unsigned> dataPair = addRecordData(container, matListElementFraction); + return dataPair; +} + + + unsigned int WriteGeoModel::addMaterial(const std::string& name, const double& density, - const std::string& elements) { - std::vector<std::vector<std::string>>* container = &m_materials; - std::vector<std::string> values; + const unsigned &dataStart, + const unsigned &dataEnd) { + // std::vector<std::vector<std::string>>* container = &m_materials; + // std::vector<std::string> values; + DBRowsList* container = &m_materials; + DBRowEntry values; values.push_back(name); - values.push_back(to_string_with_precision(density)); - values.push_back(elements); + values.push_back(density); + values.push_back(dataStart); + values.push_back(dataEnd); return addRecord(container, values); } + + unsigned int WriteGeoModel::addElement(const std::string& name, const std::string& symbol, const double& elZ, const double& elA) { - std::vector<std::vector<std::string>>* container = &m_elements; - std::vector<std::string> values; - values.insert(values.begin(), {name, symbol, to_string_with_precision(elZ), - to_string_with_precision(elA)}); + // std::vector<std::vector<std::string>>* container = &m_elements; + // std::vector<std::string> values; + // values.insert(values.begin(), {name, symbol, CppHelper::to_string_with_precision(elZ), + // CppHelper::to_string_with_precision(elA)}); + + DBRowsList* container = &m_elements; + DBRowEntry values; + values.push_back(name); + values.push_back(symbol); + values.push_back(elZ); + values.push_back(elA); + return addRecord(container, values); } @@ -1642,9 +2061,6 @@ unsigned int WriteGeoModel::addSerialIdentifier(const int& baseId) { std::vector<std::string> values; values.push_back(std::to_string(baseId)); return addRecord(container, values); - -/* -<<<<<<< HEAD } unsigned int WriteGeoModel::addIdentifierTag(const int& identifier) { @@ -1654,10 +2070,13 @@ unsigned int WriteGeoModel::addIdentifierTag(const int& identifier) { return addRecord(container, values); } -unsigned int WriteGeoModel::addFunction(const std::string& expression) { - std::vector<std::vector<std::string>>* container = &m_functions; - std::vector<std::string> values; +unsigned int WriteGeoModel::addFunction(const std::string& expression, const unsigned &dataStart, const unsigned &dataEnd) { + // std::vector<std::vector<std::string>>* container = &m_functions; + DBRowsList* container = &m_functions; + DBRowEntry values; values.push_back(expression); + values.push_back(dataStart); + values.push_back(dataEnd); return addRecord(container, values); } @@ -1665,8 +2084,9 @@ unsigned int WriteGeoModel::addAlignableTransform( const std::vector<double>& params) { std::vector<std::vector<std::string>>* container = &m_alignableTransforms; std::vector<std::string> values; - for (const double& par : params) { - values.push_back(to_string_with_precision(par)); + values.reserve(params.size()); +for (const double& par : params) { + values.push_back(GeoStrUtils::to_string_with_precision(par)); } return addRecord(container, values); } @@ -1674,8 +2094,9 @@ unsigned int WriteGeoModel::addAlignableTransform( unsigned int WriteGeoModel::addTransform(const std::vector<double>& params) { std::vector<std::vector<std::string>>* container = &m_transforms; std::vector<std::string> values; - for (const double& par : params) { - values.push_back(to_string_with_precision(par)); + values.reserve(params.size()); +for (const double& par : params) { + values.push_back(GeoStrUtils::to_string_with_precision(par)); } return addRecord(container, values); } @@ -1691,7 +2112,7 @@ unsigned int WriteGeoModel::getIdFromNodeType(const std::string& nodeType) { unsigned int WriteGeoModel::addSerialTransformer(const unsigned int& funcId, const unsigned int& physvolId, - const std::string volType, + const std::string& volType, const unsigned int& copies) { std::vector<std::vector<std::string>>* container = &m_serialTransformers; const unsigned int volTypeID = getIdFromNodeType(volType); @@ -1713,278 +2134,89 @@ unsigned int WriteGeoModel::addShape(const std::string& type, return addRecord(container, values); } -unsigned int WriteGeoModel::addPhysVol(const unsigned int& logVolId, - const unsigned int& //parentPhysVolId - , - const bool& isRootVolume) { - std::vector<std::vector<std::string>>* container = &m_physVols; - std::vector<std::string> values; - values.push_back(std::to_string(logVolId)); // INT - unsigned int idx = addRecord(container, values); - - if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoPhysVol"}); // INT - m_rootVolume = rootValues; +unsigned int WriteGeoModel::addShape(const std::string &type, + const DBRowEntry ¶meters) +{ + DBRowsList *container = nullptr; + if ("Box" == type) + { + container = &m_shapes_Box; } - - return idx; -} - -unsigned int WriteGeoModel::addFullPhysVol( - const unsigned int& logVolId, const unsigned int& //parentPhysVolId// -, - const bool& isRootVolume) { - std::vector<std::vector<std::string>>* container = &m_fullPhysVols; - std::vector<std::string> values; - values.push_back(std::to_string(logVolId)); // INT - unsigned int idx = addRecord(container, values); - - if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoFullPhysVol"}); // INT - m_rootVolume = rootValues; + else if ("Tube" == type) + { + container = &m_shapes_Tube; } - - return idx; -} - -unsigned int WriteGeoModel::addLogVol(const std::string& name, - const unsigned int& shapeId, - const unsigned int& materialId) { - std::vector<std::vector<std::string>>* container = &m_logVols; - std::vector<std::string> values; - values.insert(values.begin(), {name, std::to_string(shapeId), - std::to_string(materialId)}); // INT - return addRecord(container, values); -} - -void WriteGeoModel::addChildPosition(const unsigned int& parentId, - const std::string& parentType, - const unsigned int& childId, - const unsigned int& parentCopyN, - const unsigned int& childPos, - const std::string& childType, - const unsigned int& childCopyN) { - std::vector<std::vector<std::string>>* container = &m_childrenPositions; - const unsigned int parentTableID = getIdFromNodeType(parentType); - const unsigned int childTableID = getIdFromNodeType(childType); - - std::vector<std::string> values; - // values << parentId.toString() << parentTableID << - // QString::number(parentCopyN) << QString::number(childPos) << - // childTableID << childId.toString() << QString::number(childCopyN); - values.insert(values.begin(), - {std::to_string(parentId), std::to_string(parentTableID), - std::to_string(parentCopyN), std::to_string(childPos), - std::to_string(childTableID), std::to_string(childId), - std::to_string(childCopyN)}); // INT - addRecord(container, values); - return; -} - -// -// The 'publisher' parameter is optional, by default it is set to 'nullptr' in -// the header. -void WriteGeoModel::saveToDB(GeoPublisher* publisher) { - if (!m_inspect) { - std::vector<GeoPublisher*> vec; - if (publisher) vec.push_back(publisher); - saveToDB(vec); - } else { - std::cerr - << "\n\nWARNING! You called the 'saveToDB' method, but " - "WriteGeoModel has been constructed by calling the 'inspect' " - "contructor! Use the 'db' constructor, instead.\n\n" - << std::endl; - exit(EXIT_FAILURE); + else if ("Cons" == type) + { + container = &m_shapes_Cons; } -} -// -// Note: The vector of GeoPublishers is completely optional, it is empty by -// default and not handled. -void WriteGeoModel::saveToDB(std::vector<GeoPublisher*>& publishers) { - if (!m_inspect) { - std::cout << "Saving the GeoModel tree to file: '" << m_dbpath << "'" - << std::endl; - - m_dbManager->addListOfRecords("GeoMaterial", m_materials); - m_dbManager->addListOfRecords("GeoElement", m_elements); - m_dbManager->addListOfRecords("GeoNameTag", m_nameTags); - m_dbManager->addListOfRecords("GeoAlignableTransform", - m_alignableTransforms); - m_dbManager->addListOfRecords("GeoTransform", m_transforms); - m_dbManager->addListOfRecords("Function", m_functions); - m_dbManager->addListOfRecords("GeoSerialTransformer", - m_serialTransformers); - m_dbManager->addListOfRecords("GeoShape", m_shapes); - m_dbManager->addListOfRecords("GeoSerialDenominator", - m_serialDenominators); - m_dbManager->addListOfRecords("GeoSerialIdentifier", - m_serialIdentifiers); - m_dbManager->addListOfRecords("GeoIdentifierTag", m_identifierTags); - m_dbManager->addListOfRecords("GeoPhysVol", m_physVols); - m_dbManager->addListOfRecords("GeoFullPhysVol", m_fullPhysVols); - m_dbManager->addListOfRecords("GeoLogVol", m_logVols); - - m_dbManager->addListOfChildrenPositions(m_childrenPositions); - m_dbManager->addRootVolume(m_rootVolume); - - // save data stored in instances of GeoPublisher - if (publishers.size()) { - std::cout - << "\nINFO: A pointer to a GeoPublisher instance has been " - "provided, " - << "so we dump the published list of FullPhysVol and " - "AlignableTransforms nodes and auxiliary data, if any.\n" - << std::endl; - for (GeoPublisher* publisher : publishers) { - storePublishedNodes(publisher); - storePublishedAuxiliaryData(publisher); - } - } - - // save auxiliary data stored through WriteGeoModel directly - //if ( m_auxiliaryTablesStr.size() ) { - // std::cout << "\nINFO: Custom tables to store auxiliary data - //have been added, " - // << "so we create these custom tables in the DB:" - // << std::endl; - // for ( auto& tableData : m_auxiliaryTablesStr ) { - // std::cout << "\tsaving table: " << tableData.first << std::endl; - // m_dbManager->createCustomTable( tableData.first, - //(tableData.second).first, (tableData.second).second, - //m_auxiliaryTablesStrData[ tableData.first ] ); - // } - //} - if (m_auxiliaryTablesVar.size()) { - if (m_loglevel > 0) { - std::cout - << "\nINFO: Custom tables to store auxiliary data have " - "been added, " - << "so we create these custom tables in the DB:" - << std::endl; - } - for (auto& tableData : m_auxiliaryTablesVar) { - if (m_loglevel > 0) { - std::cout << "\nsaving table: " << tableData.first - << std::endl; - } - m_dbManager->createCustomTable( - tableData.first, (tableData.second).first, - (tableData.second).second, - m_auxiliaryTablesVarData[tableData.first]); - } - } - - if (!m_objectsNotPersistified.empty()) { - std::cout - << "\n\tGeoModelWrite -- WARNING!! There are shapes/nodes " - "which need to be persistified! --> "; - printStdVectorStrings(m_objectsNotPersistified); - std::cout << "\n\n"; - } - - return; - - } else { - std::cerr - << "\n\nWARNING! You called the 'saveToDB' method, but " - "WriteGeoModel has been constructed by calling the 'inspect' " - "contructor! Use the 'db' constructor, instead.\n\n" - << std::endl; - exit(EXIT_FAILURE); + else if ("Para" == type) + { + container = &m_shapes_Para; } -} - -void WriteGeoModel::storePublishedAuxiliaryData(GeoPublisher* publisher) { - AuxTableDefs tableDefs = publisher->getPublishedAuxData().first; - AuxTableData tableAuxData = publisher->getPublishedAuxData().second; - if (tableDefs.size()) { - std::cout << "\nINFO: Custom tables to store auxiliary data have been " - "added to an instance of GeoPublisher, " - << "so we create these custom tables in the DB:" << std::endl; - for (auto& tableData : tableDefs) { - if (m_loglevel > 0) { - std::cout << "\nsaving table: " << tableData.first << std::endl; - } - m_dbManager->createCustomTable( - tableData.first, (tableData.second).first, - (tableData.second).second, tableAuxData[tableData.first]); - } + else if ("Trap" == type) + { + container = &m_shapes_Trap; } -} - -======= -*/ -} - -unsigned int WriteGeoModel::addIdentifierTag(const int& identifier) { - std::vector<std::vector<std::string>>* container = &m_identifierTags; - std::vector<std::string> values; - values.push_back(std::to_string(identifier)); - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addFunction(const std::string& expression) { - std::vector<std::vector<std::string>>* container = &m_functions; - std::vector<std::string> values; - values.push_back(expression); - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addAlignableTransform( - const std::vector<double>& params) { - std::vector<std::vector<std::string>>* container = &m_alignableTransforms; - std::vector<std::string> values; - for (const double& par : params) { - values.push_back(to_string_with_precision(par)); + else if ("Trd" == type) + { + container = &m_shapes_Trd; } - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addTransform(const std::vector<double>& params) { - std::vector<std::vector<std::string>>* container = &m_transforms; - std::vector<std::string> values; - for (const double& par : params) { - values.push_back(to_string_with_precision(par)); + else if ("Tubs" == type) + { + container = &m_shapes_Tubs; } - return addRecord(container, values); -} - -unsigned int WriteGeoModel::getIdFromNodeType(const std::string& nodeType) { - std::unordered_map<std::string, unsigned int>::iterator it = - m_memMap_Tables.find(nodeType); - if (it != m_memMap_Tables.end()) { // item found - return m_memMap_Tables.at(nodeType); + else if ("Torus" == type) + { + container = &m_shapes_Torus; } - return 0; // item not found -} - -unsigned int WriteGeoModel::addSerialTransformer(const unsigned int& funcId, - const unsigned int& physvolId, - const std::string volType, - const unsigned int& copies) { - std::vector<std::vector<std::string>>* container = &m_serialTransformers; - const unsigned int volTypeID = getIdFromNodeType(volType); - - std::vector<std::string> values; - values.insert(values.begin(), - {std::to_string(funcId), std::to_string(physvolId), - std::to_string(volTypeID), std::to_string(copies)}); // INT - - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addShape(const std::string& type, - const std::string& parameters) { - std::vector<std::vector<std::string>>* container = &m_shapes; - std::vector<std::string> values; - values.push_back(type); - values.push_back(parameters); - return addRecord(container, values); + else if ("TwistedTrap" == type) + { + container = &m_shapes_TwistedTrap; + } + else if ("Pcon" == type) + { + container = &m_shapes_Pcon; + } + else if ("Pgon" == type) + { + container = &m_shapes_Pgon; + } + else if ("SimplePolygonBrep" == type) + { + container = &m_shapes_SimplePolygonBrep; + } + else if ("GenericTrap" == type) + { + container = &m_shapes_GenericTrap; + } + else if ("Intersection" == type) + { + container = &m_shapes_Intersection; + } + else if ("Subtraction" == type) + { + container = &m_shapes_Subtraction; + } + else if ("Union" == type) + { + container = &m_shapes_Union; + } + else if ("Shift" == type) + { + container = &m_shapes_Shift; + } + else if ("UnidentifiedShape" == type) + { + container = &m_shapes_UnidentifiedShape; + } + else + { + const std::string errMsg = "ERROR!!! Shape type '" + type + + "' still needs to be ported to the new DB schema. Ask to 'geomodel-developers@cern.ch."; + THROW_EXCEPTION(errMsg); + } + return addRecord(container, parameters); } unsigned int WriteGeoModel::addPhysVol(const unsigned int& logVolId, @@ -1995,9 +2227,10 @@ unsigned int WriteGeoModel::addPhysVol(const unsigned int& logVolId, values.push_back(std::to_string(logVolId)); // INT unsigned int idx = addRecord(container, values); if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoPhysVol"}); // INT + // std::vector<std::string> rootValues; + // rootValues.insert(rootValues.begin(), + // {std::to_string(idx), "GeoPhysVol"}); // INT + std::pair<std::string, unsigned> rootValues{"GeoPhysVol", idx}; m_rootVolume = rootValues; } return idx; @@ -2011,21 +2244,63 @@ unsigned int WriteGeoModel::addFullPhysVol( values.push_back(std::to_string(logVolId)); // INT unsigned int idx = addRecord(container, values); if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoFullPhysVol"}); // INT + // std::vector<std::string> rootValues; + // rootValues.insert(rootValues.begin(), + // {std::to_string(idx), "GeoFullPhysVol"}); // INT + std::pair<std::string, unsigned> rootValues{"GeoFullPhysVol", idx}; m_rootVolume = rootValues; } return idx; } +//------------------------------------------------------------------------ +unsigned int WriteGeoModel::addVSurface(const std::string &type, const unsigned int& surfShapeId) { + DBRowsList* container = &m_VSurface; + DBRowEntry values; + values.push_back(type); + values.push_back(surfShapeId); // INT + unsigned int idx = addRecord(container, values); + return idx; +} + +unsigned int WriteGeoModel::addSurfaceShape(const std::string &type, + const DBRowEntry ¶meters) +{ + DBRowsList *container = nullptr; + if ("RectangleSurface" == type) + { + container = &m_rectangle_surface; + } + else if ("TrapezoidSurface" == type) + { + container = &m_trapezoid_surface; + } + else if ("AnnulusSurface" == type) + { + container = &m_annulus_surface; + } + else if ("DiamondSurface" == type) + { + container = &m_diamond_surface; + } + else{ + THROW_EXCEPTION("ERROR!!! Cannot recognize '" << type << "' while adding the surface shape!"); + } + unsigned int idx = addRecord(container, parameters); + return idx; +} +//------------------------------------------------------------------------ + unsigned int WriteGeoModel::addLogVol(const std::string& name, const unsigned int& shapeId, + std::string_view shapeType, const unsigned int& materialId) { - std::vector<std::vector<std::string>>* container = &m_logVols; - std::vector<std::string> values; - values.insert(values.begin(), {name, std::to_string(shapeId), - std::to_string(materialId)}); // INT + DBRowsList* container = &m_logVols; + DBRowEntry values; + values.push_back(name); + values.push_back(shapeId); + values.push_back(std::string(shapeType)); + values.push_back(materialId); return addRecord(container, values); } @@ -2035,20 +2310,25 @@ void WriteGeoModel::addChildPosition(const unsigned int& parentId, const unsigned int& parentCopyN, const unsigned int& childPos, const std::string& childType, - const unsigned int& childCopyN) { - std::vector<std::vector<std::string>>* container = &m_childrenPositions; + const unsigned int& childCopyN) +{ + // std::vector<std::vector<std::string>>* container = &m_childrenPositions; + DBRowsList* container = &m_childrenPositions; + const unsigned int parentTableID = getIdFromNodeType(parentType); const unsigned int childTableID = getIdFromNodeType(childType); - std::vector<std::string> values; + // std::vector<std::string> values; + DBRowEntry values; + // values << parentId.toString() << parentTableID << // QString::number(parentCopyN) << QString::number(childPos) << // childTableID << childId.toString() << QString::number(childCopyN); values.insert(values.begin(), - {std::to_string(parentId), std::to_string(parentTableID), - std::to_string(parentCopyN), std::to_string(childPos), - std::to_string(childTableID), std::to_string(childId), - std::to_string(childCopyN)}); // INT + {parentId, parentTableID, + parentCopyN, childPos, + childTableID, childId, + childCopyN}); addRecord(container, values); return; } @@ -2070,22 +2350,60 @@ void WriteGeoModel::saveToDB(std::vector<GeoPublisher*>& publishers) { std::cout << "Saving the GeoModel tree to file: '" << m_dbpath << "'" << std::endl; - m_dbManager->addListOfRecords("GeoMaterial", m_materials); m_dbManager->addListOfRecords("GeoElement", m_elements); + m_dbManager->addListOfRecords("GeoMaterial", m_materials); + m_dbManager->addListOfRecordsToTable("Materials_Data", m_materials_Data); // new version, with list of (element,fraction) stored separately + m_dbManager->addListOfRecords("GeoNameTag", m_nameTags); m_dbManager->addListOfRecords("GeoAlignableTransform", m_alignableTransforms); m_dbManager->addListOfRecords("GeoTransform", m_transforms); m_dbManager->addListOfRecords("Function", m_functions); m_dbManager->addListOfRecords("GeoSerialTransformer", m_serialTransformers); - m_dbManager->addListOfRecords("GeoShape", m_shapes); m_dbManager->addListOfRecords("GeoSerialDenominator", m_serialDenominators); m_dbManager->addListOfRecords("GeoSerialIdentifier", m_serialIdentifiers); m_dbManager->addListOfRecords("GeoIdentifierTag", m_identifierTags); m_dbManager->addListOfRecords("GeoPhysVol", m_physVols); m_dbManager->addListOfRecords("GeoFullPhysVol", m_fullPhysVols); + m_dbManager->addListOfRecords("GeoVSurface", m_VSurface); m_dbManager->addListOfRecords("GeoLogVol", m_logVols); - + + m_dbManager->addRecordsToTable("FuncExprData", m_exprData); + + m_dbManager->addListOfRecords("GeoShape", m_shapes); // OLD version, with shape's parameters as strings + m_dbManager->addListOfRecords("GeoBox", m_shapes_Box); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTube", m_shapes_Tube); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoCons", m_shapes_Cons); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoPara", m_shapes_Para); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTrap", m_shapes_Trap); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTrd", m_shapes_Trd); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTubs", m_shapes_Tubs); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTorus", m_shapes_Torus); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoTwistedTrap", m_shapes_TwistedTrap); // new version, with shape's parameters as numbers + + // store shapes' data // TODO: maybe this should be encapsulated with shapes? + // FIXME: To do this, I moved addListOfRecordsToTable() from private to public, maybe I could add a method to store shapes with data and put back that into private + m_dbManager->addListOfRecords("GeoPcon", m_shapes_Pcon); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoPgon", m_shapes_Pgon); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoSimplePolygonBrep", m_shapes_SimplePolygonBrep); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoGenericTrap", m_shapes_GenericTrap); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecordsToTable("Shapes_Pcon_Data", m_shapes_Pcon_Data); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecordsToTable("Shapes_Pgon_Data", m_shapes_Pgon_Data); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecordsToTable("Shapes_SimplePolygonBrep_Data", m_shapes_SimplePolygonBrep_Data); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecordsToTable("Shapes_GenericTrap_Data", m_shapes_GenericTrap_Data); // new version, with shape's parameters as numbers + + m_dbManager->addListOfRecords("GeoShapeShift", m_shapes_Shift); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoShapeIntersection", m_shapes_Intersection); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoShapeSubtraction", m_shapes_Subtraction); // new version, with shape's parameters as numbers + m_dbManager->addListOfRecords("GeoShapeUnion", m_shapes_Union); // new version, with shape's parameters as numbers + + m_dbManager->addListOfRecords("GeoUnidentifiedShape", m_shapes_UnidentifiedShape); // new version, with shape's parameters as numbers + + m_dbManager->addListOfRecords("RectangleSurface", m_rectangle_surface); + m_dbManager->addListOfRecords("TrapezoidSurface", m_trapezoid_surface); + m_dbManager->addListOfRecords("AnnulusSurface", m_annulus_surface); + m_dbManager->addListOfRecords("DiamondSurface", m_diamond_surface); + m_dbManager->addListOfChildrenPositions(m_childrenPositions); m_dbManager->addRootVolume(m_rootVolume); @@ -2137,7 +2455,7 @@ void WriteGeoModel::saveToDB(std::vector<GeoPublisher*>& publishers) { if (!m_objectsNotPersistified.empty()) { std::cout << "\n\tGeoModelWrite -- WARNING!! There are shapes/nodes " "which need to be persistified! --> "; - printStdVectorStrings(m_objectsNotPersistified); + GeoStrUtils::printStdVectorStrings(m_objectsNotPersistified); std::cout << "\n\n"; } @@ -2162,7 +2480,6 @@ void WriteGeoModel::storePublishedAuxiliaryData(GeoPublisher* publisher) { } } -//>>>>>>> origin void WriteGeoModel::storePublishedNodes(GeoPublisher* store) { @@ -2226,10 +2543,10 @@ void WriteGeoModel::storeRecordPublishedNodes( keyStr = std::any_cast<std::string>(key); } else if (typeid(int) == keyType) { keyTypeStr = "int"; - keyStr = std::to_string(std::any_cast<int>(key)); + keyStr = std::to_string(std::any_cast<int>(key)); // INT } else if (typeid(unsigned) == keyType) { keyTypeStr = "uint"; - keyStr = std::to_string(std::any_cast<unsigned>(key)); + keyStr = std::to_string(std::any_cast<unsigned>(key)); // INT } else { std::cout << "ERROR! The type of the key used to publish FPV and AXF " @@ -2265,7 +2582,7 @@ void WriteGeoModel::storeRecordPublishedNodes( // in the DB table std::vector<std::string> values; values.push_back(keyStr); - values.push_back(std::to_string(volID)); + values.push_back(std::to_string(volID)); // INT values.push_back(keyTypeStr); // TODO: store the key type in a metadata // table, not in the records' table; so // it can be stored once only. @@ -2276,24 +2593,12 @@ void WriteGeoModel::storeRecordPublishedNodes( } } -/* -void WriteGeoModel::storeDataTable( std::string tableName, -std::vector<std::string> colNames, std::vector<std::string> colTypes, -std::vector<std::vector<std::string>> tableData ) -{ - m_auxiliaryTablesStr[ tableName ] = std::make_pair(colNames, colTypes); - m_auxiliaryTablesStrData[ tableName ] = tableData; -} -*/ - void WriteGeoModel::storeDataTable( - std::string tableName, std::vector<std::string> colNames, - std::vector<std::string> colTypes, - std::vector< - std::vector<std::variant<int, long, float, double, std::string>>> - tableData) { + const std::string& tableName, const std::vector<std::string>& colNames, + const std::vector<std::string>& colTypes, + DBRowsList tableData) { m_auxiliaryTablesVar[tableName] = std::make_pair(colNames, colTypes); - m_auxiliaryTablesVarData[tableName] = tableData; + m_auxiliaryTablesVarData[tableName] = std::move(tableData); } void WriteGeoModel::storeAddress(const std::string& address, @@ -2303,12 +2608,14 @@ void WriteGeoModel::storeAddress(const std::string& address, bool WriteGeoModel::isAddressStored(const std::string& address) { // showMemoryMap(); // only for Debug + // std::cout << "DEBUG: calling isAddressStored()..." << std::endl; std::unordered_map<std::string, unsigned int>::iterator it = m_memMap.find(address); return (it != m_memMap.end()); } unsigned int WriteGeoModel::getStoredIdFromAddress(const std::string& address) { + // std::cout << "DEBUG: calling getStoredIdFromAddress()..." << std::endl; return m_memMap.at(address); } @@ -2353,6 +2660,18 @@ std::string WriteGeoModel::getAddressStringFromPointer( oss << pointer; return getQStringFromOss(oss); } +std::string WriteGeoModel::getAddressStringFromPointer( + const GeoVSurface* pointer) { + std::ostringstream oss; + oss << pointer; + return getQStringFromOss(oss); +} +std::string WriteGeoModel::getAddressStringFromPointer( + const GeoVSurfaceShape* pointer) { + std::ostringstream oss; + oss << pointer; + return getQStringFromOss(oss); +} // get pointer string std::string WriteGeoModel::getAddressStringFromPointer( const GeoSerialDenominator* pointer) { diff --git a/GeoModelIO/TFPersistification/CMakeLists.txt b/GeoModelIO/TFPersistification/CMakeLists.txt index 0589986f4a8e121eb74566debb67f0d62c0b217d..85f185a09aba90fc276efe0e64273d6bc641a12b 100644 --- a/GeoModelIO/TFPersistification/CMakeLists.txt +++ b/GeoModelIO/TFPersistification/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cpp ) @@ -10,7 +10,7 @@ target_link_libraries( TFPersistification PUBLIC GeoGenericFunctions GeoModelKernel ) target_include_directories( TFPersistification PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "TFPersistification" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( TFPersistification PROPERTIES diff --git a/GeoModelIO/TFPersistification/TFPersistification/ACosIO.h b/GeoModelIO/TFPersistification/TFPersistification/ACosIO.h index 9c0c574c2c2291ea22ef982f0eb827818bf81aef..603bc762b887e8bed0716b803ca729375634b353 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/ACosIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/ACosIO.h @@ -11,7 +11,7 @@ class ACosReader: public GenFunctionReader { public: ACosReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/ASinIO.h b/GeoModelIO/TFPersistification/TFPersistification/ASinIO.h index dedc5ff8ac9ac1e5b109288eff77044df9a0484a..ea620489229aa83bb1d241edc6df298b10cc52d9 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/ASinIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/ASinIO.h @@ -10,7 +10,7 @@ class ASinReader: public GenFunctionReader { public: ASinReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/ATanIO.h b/GeoModelIO/TFPersistification/TFPersistification/ATanIO.h index 526d8b66f727fafa4021f065833179e1db9a98b0..094ecc6910a821b4d9933ee8041497c4d6567d8b 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/ATanIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/ATanIO.h @@ -10,7 +10,7 @@ class ATanReader: public GenFunctionReader { public: ATanReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/AbsIO.h b/GeoModelIO/TFPersistification/TFPersistification/AbsIO.h index 09b351c5c6257a134a3ac169dee572d3715ec794..c8e71c3d0db45e479ec89eef81a797b379d95c28 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/AbsIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/AbsIO.h @@ -10,7 +10,7 @@ class AbsReader: public GenFunctionReader { public: AbsReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/ArrayFunctionIO.h b/GeoModelIO/TFPersistification/TFPersistification/ArrayFunctionIO.h index f5ff56c25d5085abcbbb3371dd16a0c81a377426..5ebaf1d8e0c7c653e08720e974b1faf875afecb8 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/ArrayFunctionIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/ArrayFunctionIO.h @@ -10,7 +10,7 @@ class ArrayFunctionReader: public GenFunctionReader { public: ArrayFunctionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/CosIO.h b/GeoModelIO/TFPersistification/TFPersistification/CosIO.h index b507f13e17a63f9aac4b84b3c94d672ecc790719..a91e3a86543e845a0aba61176d9bc1f9bbd130c9 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/CosIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/CosIO.h @@ -11,7 +11,7 @@ class CosReader: public GenFunctionReader { public: CosReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/FixedConstantIO.h b/GeoModelIO/TFPersistification/TFPersistification/FixedConstantIO.h index 84ecbe10e6f6eb23a671b9256eb22e6eee1fe426..1bed916385c8e83618c0625ea7d15ce1a761d1de 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/FixedConstantIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/FixedConstantIO.h @@ -10,7 +10,7 @@ class FixedConstantReader: public GenFunctionReader { public: FixedConstantReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionInterpreter.h b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionInterpreter.h index de38528620ed660061abe44be12e1dc6a750745d..a5d9afd2f410dd99cd1dc0c5a9379cd033b9fb8e 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionInterpreter.h +++ b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionInterpreter.h @@ -5,7 +5,7 @@ #include <typeinfo> #include <sstream> #include <memory> - +#include <deque> // // Forward definition of "Genfunction" // @@ -35,8 +35,11 @@ class GenFunctionInterpreter { // Interprets a string. GFPTR interpret(std::string::const_iterator begin, - std::string::const_iterator end ) const; + std::string::const_iterator end, + std::deque<double> *fpData) const; + + private: // Store the actual interpreters, map them into the type name diff --git a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionPersistifier.h b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionPersistifier.h index 0a6629c89d62ac2dae8305aa42ea343bda8c0a4a..9a857c74afb44e353d5437ed15d5b0d1a33f9a9c 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionPersistifier.h +++ b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionPersistifier.h @@ -4,7 +4,7 @@ #include <string> #include <typeinfo> #include <sstream> - +#include <deque> // // Forward declaration of GeoGenfun::AbsFunction // @@ -40,14 +40,19 @@ class GenFunctionPersistifier { // Retrieves the stream used to build the expression: std::ostringstream & getStream() const; - private: + // Retreive floating point data + std::deque<double> & getFloatingPointData() const; + +private: // Store the actual recorders, map them into the type name std::map<std::string, const GenFunctionRecorder *> recorderMap; // Here is the result: - mutable std::string codedString; + mutable std::string codedString; + mutable std::deque<double> floatingPointData; + // An ostringstream is used to build the coded string: mutable std::ostringstream *stream; diff --git a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionReader.h b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionReader.h index 18183d62a9ac3fc63e1b25789eb8c0dec1e68df3..a1fdb2f8938fb481125ad281c23427d0fad38f0d 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/GenFunctionReader.h +++ b/GeoModelIO/TFPersistification/TFPersistification/GenFunctionReader.h @@ -26,7 +26,7 @@ class GenFunctionReader { virtual ~GenFunctionReader(); // Execute - virtual GFPTR execute(std::string::const_iterator , std::string::const_iterator) const=0; + virtual GFPTR execute(std::string::const_iterator , std::string::const_iterator, std::deque<double> *fpData=nullptr) const=0; // Access to the interpreter: const GenFunctionInterpreter *getInterpreter() const; diff --git a/GeoModelIO/TFPersistification/TFPersistification/GenfunIO.h b/GeoModelIO/TFPersistification/TFPersistification/GenfunIO.h index 05f8e41f51915cdebf69044288ed19b196f81b04..fae8b60b2e82433bc7c546c270e103825cae38d0 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/GenfunIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/GenfunIO.h @@ -10,7 +10,7 @@ class ConstTimesFunctionReader: public GenFunctionReader { public: ConstTimesFunctionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr ) const; }; @@ -29,7 +29,7 @@ class ConstPlusFunctionReader: public GenFunctionReader { public: ConstPlusFunctionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr ) const; }; @@ -48,7 +48,7 @@ class ConstMinusFunctionReader: public GenFunctionReader { public: ConstMinusFunctionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr ) const; }; @@ -67,7 +67,7 @@ class ConstOverFunctionReader: public GenFunctionReader { public: ConstOverFunctionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr ) const; }; @@ -87,7 +87,7 @@ class FunctionCompositionReader: public GenFunctionReader { public: FunctionCompositionReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -107,7 +107,7 @@ class FunctionNegationReader: public GenFunctionReader { public: FunctionNegationReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -126,7 +126,7 @@ class FunctionNoopReader: public GenFunctionReader { public: FunctionNoopReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -145,7 +145,7 @@ class FunctionProductReader: public GenFunctionReader { public: FunctionProductReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -164,7 +164,7 @@ class FunctionQuotientReader: public GenFunctionReader { public: FunctionQuotientReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -184,7 +184,7 @@ class FunctionSumReader: public GenFunctionReader { public: FunctionSumReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -203,7 +203,7 @@ class FunctionDifferenceReader: public GenFunctionReader { public: FunctionDifferenceReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end ) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData ) const; }; @@ -223,7 +223,7 @@ class VariableReader: public GenFunctionReader { public: VariableReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/ModIO.h b/GeoModelIO/TFPersistification/TFPersistification/ModIO.h index cec3e1057b3a64f977d9066018782159e40fd69e..bb30523f417af79a38ef6dc479ec18a8e4a51cd8 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/ModIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/ModIO.h @@ -11,7 +11,7 @@ class ModReader: public GenFunctionReader { public: ModReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/RectangularIO.h b/GeoModelIO/TFPersistification/TFPersistification/RectangularIO.h index dd68430562e09e9dc6b0f25e43589aaaa1d2baaf..3d9beef9ac8bb6949917ca19c2ee7c455c58a5dd 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/RectangularIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/RectangularIO.h @@ -11,7 +11,7 @@ class RectangularReader: public GenFunctionReader { public: RectangularReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/SinIO.h b/GeoModelIO/TFPersistification/TFPersistification/SinIO.h index 02990ca51672d08ea3647ec8a205d5cd19f86c1c..ffaed09d7193caeec450c5d42f78f5cb7a8e8d57 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/SinIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/SinIO.h @@ -12,7 +12,7 @@ class SinReader: public GenFunctionReader { public: SinReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/SqrtIO.h b/GeoModelIO/TFPersistification/TFPersistification/SqrtIO.h index 7c7f9ecc09d82be0cf4428472fcfa0f1574fe42d..a30e3bed9332ac00ef75af75dee8bf649833f29c 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/SqrtIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/SqrtIO.h @@ -11,7 +11,7 @@ class SqrtReader: public GenFunctionReader { public: SqrtReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/SquareIO.h b/GeoModelIO/TFPersistification/TFPersistification/SquareIO.h index 082a62c3e5201fd6806196b861a593de6ae31d08..35471b6814c74192fca6f3203d473e2e2e82870b 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/SquareIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/SquareIO.h @@ -11,7 +11,7 @@ class SquareReader: public GenFunctionReader { public: SquareReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/TanIO.h b/GeoModelIO/TFPersistification/TFPersistification/TanIO.h index 5d1dcf59667be1cbb2760d242bae27f93b123ae2..7d65621da2d84dddf3bb1c9667e7aa285a8b04f0 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/TanIO.h +++ b/GeoModelIO/TFPersistification/TFPersistification/TanIO.h @@ -11,7 +11,7 @@ class TanReader: public GenFunctionReader { public: TanReader(GenFunctionInterpreter * interpreter); - virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end) const; + virtual GFPTR execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData=nullptr) const; }; diff --git a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionInterpreter.h b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionInterpreter.h index a67c505d12817616793905498c0db321142a0b02..3ffe41c52849612e40357e7037d33973533a1df2 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionInterpreter.h +++ b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionInterpreter.h @@ -34,7 +34,7 @@ class TransFunctionInterpreter { void add(const std::string &str, const TransFunctionReader * reader); // Interprets a string. - TFPTR interpret(const std::string & str) const; + TFPTR interpret(const std::string & str, std::deque<double> *fpData) const; // Retrieves the genfunction persistitier: const GenFunctionInterpreter * getGenFunctionInterpreter() const; diff --git a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionPersistifier.h b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionPersistifier.h index 1ff9abeae07359ab03aadf6ba94a8c6d81a8fd41..96cc16eaee1064cc11caf9d17ebf3d0fea8719fe 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionPersistifier.h +++ b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionPersistifier.h @@ -39,6 +39,9 @@ class TransFunctionPersistifier { // Retrieves the coded string after the persistify operation: const std::string & getCodedString() const; + // Retrieves floating point data + std::deque<double> & getFloatingPointData() const; + // Retrieves the stream used to build the expression: std::ostringstream & getStream() const; @@ -50,9 +53,12 @@ class TransFunctionPersistifier { // Store the actual recorders, map them into the type name std::map<std::string, const TransFunctionRecorder *> recorderMap; - // Here is the result: + // Here is the result (character string data) mutable std::string codedString; + // Here is the result (floating point data) + mutable std::deque<double> floatingPointData; + // An ostringstream is used to build the coded string: mutable std::ostringstream *stream; diff --git a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionReader.h b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionReader.h index 7e5bdfaa5c96714d34a4095feb4d25930d861a69..bad04ea4a61d0ab86539bdceb3187f72b3285ccf 100644 --- a/GeoModelIO/TFPersistification/TFPersistification/TransFunctionReader.h +++ b/GeoModelIO/TFPersistification/TFPersistification/TransFunctionReader.h @@ -4,6 +4,7 @@ #include "GeoModelKernel/GeoXF.h" #include <memory> +#include <deque> // @@ -32,7 +33,7 @@ class TransFunctionReader { virtual ~TransFunctionReader(); // Execute - virtual TFPTR execute(const std::string & arg) const=0; + virtual TFPTR execute(const std::string & arg, std::deque<double> *fpData) const=0; // Access to the interpreter: const TransFunctionInterpreter *getInterpreter() const; @@ -44,7 +45,7 @@ class TransFunctionReader { std::pair<std::string, std::string> split(const std::string & arg) const; // Help scan transforms - GeoTrf::Transform3D scanT(const std::string & exprString) const; + GeoTrf::Transform3D scanT(const std::string & exprString, std::deque<double> * fpData) const; private: @@ -67,7 +68,7 @@ class ProductReader: public TransFunctionReader { public: ProductReader(TransFunctionInterpreter * interpreter); - virtual TFPTR execute(const std::string & arg) const; + virtual TFPTR execute(const std::string & arg, std::deque<double> *fpData) const; }; @@ -77,7 +78,7 @@ class PreMultReader: public TransFunctionReader { public: PreMultReader(TransFunctionInterpreter * interpreter); - virtual TFPTR execute(const std::string & arg) const; + virtual TFPTR execute(const std::string & arg, std::deque<double> *fpData) const; }; @@ -86,7 +87,7 @@ class PostMultReader: public TransFunctionReader { public: PostMultReader(TransFunctionInterpreter * interpreter); - virtual TFPTR execute(const std::string & arg) const; + virtual TFPTR execute(const std::string & arg, std::deque<double> *fpData) const; }; @@ -96,7 +97,7 @@ class PowReader: public TransFunctionReader { public: PowReader(TransFunctionInterpreter * interpreter); - virtual TFPTR execute(const std::string & arg) const; + virtual TFPTR execute(const std::string & arg, std::deque<double> *fpData) const; }; diff --git a/GeoModelIO/TFPersistification/src/ACosIO.cpp b/GeoModelIO/TFPersistification/src/ACosIO.cpp index 6679930302c4d300017e137305a1c45c670158f2..74b487fdc4e581d61419767a3f93a22c00b0df6f 100644 --- a/GeoModelIO/TFPersistification/src/ACosIO.cpp +++ b/GeoModelIO/TFPersistification/src/ACosIO.cpp @@ -7,7 +7,7 @@ ACosReader::ACosReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ACos", interpreter) {} -GFPTR ACosReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR ACosReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::ACos()); } diff --git a/GeoModelIO/TFPersistification/src/ASinIO.cpp b/GeoModelIO/TFPersistification/src/ASinIO.cpp index c4a2e0c14543473dcbf9669a6546c7925d94457b..d67ccd6136dce31cb4aecece228ccc1cd4443406 100644 --- a/GeoModelIO/TFPersistification/src/ASinIO.cpp +++ b/GeoModelIO/TFPersistification/src/ASinIO.cpp @@ -7,7 +7,7 @@ ASinReader::ASinReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ASin", interpreter) {} -GFPTR ASinReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR ASinReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::ASin()); } diff --git a/GeoModelIO/TFPersistification/src/ATanIO.cpp b/GeoModelIO/TFPersistification/src/ATanIO.cpp index 33df878f45ba9167f4d356dea3ba9c03690d11fd..fcd94ee130cec51227c9c39856dca3183a83e84f 100644 --- a/GeoModelIO/TFPersistification/src/ATanIO.cpp +++ b/GeoModelIO/TFPersistification/src/ATanIO.cpp @@ -7,7 +7,7 @@ ATanReader::ATanReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ATan", interpreter) {} -GFPTR ATanReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR ATanReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::ATan()); } diff --git a/GeoModelIO/TFPersistification/src/AbsIO.cpp b/GeoModelIO/TFPersistification/src/AbsIO.cpp index cb8039fca032ba61f3b57ab5e1861f3913b2252c..50e2dd4886384aeb122fc82bb905d9eadbca9b4f 100644 --- a/GeoModelIO/TFPersistification/src/AbsIO.cpp +++ b/GeoModelIO/TFPersistification/src/AbsIO.cpp @@ -7,7 +7,7 @@ AbsReader::AbsReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Abs", interpreter) {} -GFPTR AbsReader::execute(std::string::const_iterator, std::string::const_iterator) const { +GFPTR AbsReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> *fpData=nullptr) const { return GFPTR(new GeoGenfun::Abs()); } diff --git a/GeoModelIO/TFPersistification/src/ArrayFunctionIO.cpp b/GeoModelIO/TFPersistification/src/ArrayFunctionIO.cpp index de725f013fb49377823ecc5826a3260fe6d80407..78de2456c14f6f9d4ccadc9a83a83c050a16f1c4 100644 --- a/GeoModelIO/TFPersistification/src/ArrayFunctionIO.cpp +++ b/GeoModelIO/TFPersistification/src/ArrayFunctionIO.cpp @@ -2,27 +2,23 @@ #include "TFPersistification/GenFunctionPersistifier.h" #include "TFPersistification/GenFunctionInterpreter.h" #include "TFPersistification/ArrayFunctionIO.h" +#include <algorithm> ArrayFunctionReader::ArrayFunctionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ArrayFunction", interpreter) {} -GFPTR ArrayFunctionReader::execute(std::string::const_iterator cStart, std::string::const_iterator cEnd) const { +GFPTR ArrayFunctionReader::execute(std::string::const_iterator cStart, std::string::const_iterator cEnd, std::deque<double> *fpData) const { + std::string aNumberStr(cStart,cEnd); + std::istringstream stream(aNumberStr); + std::string real; + unsigned int len; + stream >> real >> len; + if (real != "REAL" || !stream) { + throw std::runtime_error ("Parse error in ArrayFunctionReader"); + } std::vector<double> elements; - auto cNext=std::find(cStart, cEnd,','); - while (cNext!=cEnd) { - std::string aNumberStr(cStart,cNext); - std::istringstream stream(aNumberStr); - double d; - stream >> d; - elements.push_back(d); - cStart=cNext+1; - cNext=std::find(cStart, cEnd,','); + for (int i=0;i<len;i++) { + elements.push_back(fpData->back()); fpData->pop_back(); } - - std::string aNumberStr(cStart,cNext); - std::istringstream stream(aNumberStr); - double d; - stream >> d; - elements.push_back(d); return GFPTR(new GeoGenfun::ArrayFunction(&elements.front(), &elements.back() + 1)); } @@ -36,10 +32,8 @@ void ArrayFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const { if (!ptr) throw std::runtime_error("Error in ArrayFunctionRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); stream << "ArrayFunction"; - stream << "("; - for (size_t i=0;i<ptr->values().size();i++){ - stream<<ptr->values()[i]; - if (i!=ptr->values().size()-1) stream << ","; - } + stream << "(REAL "; + stream << ptr->values().size(); stream << ")"; + std::copy(ptr->values().begin(), ptr->values().end(), std::front_inserter(getPersistifier()->getFloatingPointData())); } diff --git a/GeoModelIO/TFPersistification/src/CosIO.cpp b/GeoModelIO/TFPersistification/src/CosIO.cpp index 15c055a8991f5f632cfe03e6d9ffcb0d850fdd0e..cec81c4eae1efef2940ed0cc442239a71fad8dd1 100644 --- a/GeoModelIO/TFPersistification/src/CosIO.cpp +++ b/GeoModelIO/TFPersistification/src/CosIO.cpp @@ -7,7 +7,7 @@ CosReader::CosReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Cos",interpreter) {} -GFPTR CosReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR CosReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::Cos()); } diff --git a/GeoModelIO/TFPersistification/src/FixedConstantIO.cpp b/GeoModelIO/TFPersistification/src/FixedConstantIO.cpp index 22d5474999eacaea9f4b94865e00314e39d99a86..a366719c03d9069e61a520f366588e79bc1307db 100644 --- a/GeoModelIO/TFPersistification/src/FixedConstantIO.cpp +++ b/GeoModelIO/TFPersistification/src/FixedConstantIO.cpp @@ -5,11 +5,12 @@ FixedConstantReader::FixedConstantReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FixedConstant", interpreter) {} -GFPTR FixedConstantReader::execute(std::string::const_iterator begin, std::string::const_iterator end) const { - double v; +GFPTR FixedConstantReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData) const { std::string aNumberStr(begin,end); - std::istringstream stream(aNumberStr); - stream >> v; + if (aNumberStr!="REAL") { + throw std::runtime_error ("Parse error in FixedConstantReader"); + } + double v=fpData->back();fpData->pop_back(); return GFPTR(new GeoGenfun::FixedConstant(v)); } @@ -21,8 +22,7 @@ void FixedConstantRecorder::execute(const GeoGenfun::AbsFunction & F) const { const GeoGenfun::FixedConstant * ptr = dynamic_cast<const GeoGenfun::FixedConstant *> (&F); if (!ptr) throw std::runtime_error("Error in FixedConstantRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); + getPersistifier()->getFloatingPointData().push_front((*ptr)(0)); stream << "FixedConstant"; - stream << "("; - stream<< (*ptr) (0); - stream << ")"; + stream << "(REAL)"; } diff --git a/GeoModelIO/TFPersistification/src/GenFunctionInterpreter.cpp b/GeoModelIO/TFPersistification/src/GenFunctionInterpreter.cpp index f0d16e7667e1042f47a39c28232891cd3ab310f5..2468ebb8b3aeb5e355fb21b62197f38d5233d265 100644 --- a/GeoModelIO/TFPersistification/src/GenFunctionInterpreter.cpp +++ b/GeoModelIO/TFPersistification/src/GenFunctionInterpreter.cpp @@ -59,7 +59,8 @@ void GenFunctionInterpreter::add(const std::string & str, const GenFunctionReade } -GFPTR GenFunctionInterpreter::interpret(std::string::const_iterator sBegin, std::string::const_iterator sEnd) const { +GFPTR GenFunctionInterpreter::interpret(std::string::const_iterator sBegin, std::string::const_iterator sEnd, + std::deque<double> * fpData) const { auto begin=std::find(sBegin, sEnd, '('); std::reverse_iterator<std::string::const_iterator> rBegin(sEnd); @@ -77,7 +78,7 @@ GFPTR GenFunctionInterpreter::interpret(std::string::const_iterator sBegin, std: throw std::runtime_error (stream.str()); } const GenFunctionReader *reader = (*rIter).second; - return reader->execute(begin,begin);//exec w/null expression + return reader->execute(begin,begin,fpData);//exec w/null expression } std::string op(sBegin,begin); auto argBegin=begin+1, argEnd=end-1; @@ -88,5 +89,5 @@ GFPTR GenFunctionInterpreter::interpret(std::string::const_iterator sBegin, std: throw std::runtime_error (stream.str()); } const GenFunctionReader *reader = (*rIter).second; - return reader->execute(argBegin,argEnd); + return reader->execute(argBegin,argEnd,fpData); } diff --git a/GeoModelIO/TFPersistification/src/GenFunctionPersistifier.cpp b/GeoModelIO/TFPersistification/src/GenFunctionPersistifier.cpp index a0853724802a4114253db1d6b8951245e5c55361..20077bd4d70ee792f855ce1499327d4d056c9033 100644 --- a/GeoModelIO/TFPersistification/src/GenFunctionPersistifier.cpp +++ b/GeoModelIO/TFPersistification/src/GenFunctionPersistifier.cpp @@ -20,6 +20,7 @@ #include <sstream> #include <iomanip> + const std::string & GenFunctionPersistifier::getCodedString() const { codedString=getStream().str(); delete stream; @@ -27,6 +28,10 @@ const std::string & GenFunctionPersistifier::getCodedString() const { return codedString; } +std::deque<double> & GenFunctionPersistifier::getFloatingPointData() const { + return floatingPointData; +} + GenFunctionPersistifier::~GenFunctionPersistifier() { delete stream; diff --git a/GeoModelIO/TFPersistification/src/GenfunIO.cpp b/GeoModelIO/TFPersistification/src/GenfunIO.cpp index 748c88c63dd15576c0c8e63bc5f10710902b5c57..1a4a129dde9a284a9fcf7cfa0b9476e978bdac77 100644 --- a/GeoModelIO/TFPersistification/src/GenfunIO.cpp +++ b/GeoModelIO/TFPersistification/src/GenfunIO.cpp @@ -2,27 +2,20 @@ #include "TFPersistification/GenFunctionInterpreter.h" #include "TFPersistification/GenFunctionPersistifier.h" #include "TFPersistification/GenfunIO.h" - #include "GeoGenericFunctions/Variable.h" - +#include <stdexcept> #include <sstream> ConstTimesFunctionReader::ConstTimesFunctionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ConstTimesFunction", interpreter) {} -inline double atof(std::string::const_iterator begin, std::string::const_iterator end) { - - std::string atom(begin,end); - std::istringstream stream(atom); - double x=0; - stream >> x; - return x; +GFPTR ConstTimesFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData) const { + std::string::const_iterator sep=split(begin,end); + double c=fpData->back(); fpData->pop_back(); //Was: atof(begin,sep); + if (std::string(begin,sep)!="REAL") { + throw std::runtime_error ("Parse error in ConstTimesFunctionReader"); + } -} - -GFPTR ConstTimesFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end) const { - auto sep=split(begin,end); - double c=atof(begin,sep); - return GFPTR(new GeoGenfun::ConstTimesFunction(c,getInterpreter()->interpret(sep+1,end).get())); + return GFPTR(new GeoGenfun::ConstTimesFunction(c,getInterpreter()->interpret(sep+1,end,fpData).get())); } @@ -34,8 +27,9 @@ void ConstTimesFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const if (!ptr) throw std::runtime_error("Error in ConstTimesFunctionRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); double c1=ptr->_constant; + getPersistifier()->getFloatingPointData().push_front(c1); stream << "ConstTimesFunction" << "("; - stream << c1; + stream << "REAL"; stream << ","; getPersistifier()->persistify(*ptr->_arg); stream << ")"; @@ -44,10 +38,13 @@ void ConstTimesFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const ConstPlusFunctionReader::ConstPlusFunctionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ConstPlusFunction", interpreter) {} -GFPTR ConstPlusFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR ConstPlusFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin, end); - double c=atof(begin,sep); - return GFPTR(new GeoGenfun::ConstPlusFunction(c,getInterpreter()->interpret(sep+1,end).get())); + double c=fpData->back(); fpData->pop_back(); //Was: atof(begin,sep); + if (std::string(begin,sep)!="REAL") { + throw std::runtime_error ("Parse error in ConstPlusFunctionReader"); + } + return GFPTR(new GeoGenfun::ConstPlusFunction(c,getInterpreter()->interpret(sep+1,end,fpData).get())); } ConstPlusFunctionRecorder::ConstPlusFunctionRecorder(GenFunctionPersistifier *persistifier): @@ -58,8 +55,9 @@ void ConstPlusFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const if (!ptr) throw std::runtime_error("Error in ConstPlusFunctionRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); double c1=ptr->_constant; + getPersistifier()->getFloatingPointData().push_front(c1); stream << "ConstPlusFunction" << "("; - stream << c1; + stream << "REAL"; stream << ","; getPersistifier()->persistify(*ptr->_arg); stream << ")"; @@ -68,10 +66,13 @@ void ConstPlusFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const ConstMinusFunctionReader::ConstMinusFunctionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ConstMinusFunction", interpreter) {} -GFPTR ConstMinusFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR ConstMinusFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - double c=atof(begin,sep); - return GFPTR(new GeoGenfun::ConstMinusFunction(c,getInterpreter()->interpret(sep+1,end).get())); + double c=fpData->back(); fpData->pop_back(); //Was: atof(begin,sep); + if (std::string(begin,sep)!="REAL") { + throw std::runtime_error ("Parse error in ConstMinusFunctionReader"); + } + return GFPTR(new GeoGenfun::ConstMinusFunction(c,getInterpreter()->interpret(sep+1,end,fpData).get())); } ConstMinusFunctionRecorder::ConstMinusFunctionRecorder(GenFunctionPersistifier *persistifier): @@ -82,8 +83,9 @@ void ConstMinusFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const if (!ptr) throw std::runtime_error("Error in ConstMinusFunctionRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); double c1=ptr->_constant; + getPersistifier()->getFloatingPointData().push_front(c1); stream << "ConstMinusFunction" << "("; - stream << c1; + stream << "REAL"; stream << ","; getPersistifier()->persistify(*ptr->_arg); stream << ")"; @@ -92,10 +94,13 @@ void ConstMinusFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const ConstOverFunctionReader::ConstOverFunctionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("ConstOverFunction", interpreter) {} -GFPTR ConstOverFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR ConstOverFunctionReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - double c=atof(begin,sep); - return GFPTR(new GeoGenfun::ConstOverFunction(c,getInterpreter()->interpret(sep+1,end).get())); + double c=fpData->back(); fpData->pop_back(); //Was: atof(begin,sep); + if (std::string(begin,sep)!="REAL") { + throw std::runtime_error ("Parse error in ConstOverFunctionReader"); + } + return GFPTR(new GeoGenfun::ConstOverFunction(c,getInterpreter()->interpret(sep+1,end,fpData).get())); } ConstOverFunctionRecorder::ConstOverFunctionRecorder(GenFunctionPersistifier *persistifier): @@ -106,8 +111,9 @@ void ConstOverFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const if (!ptr) throw std::runtime_error("Error in ConstOverFunctionRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); double c1=ptr->_constant; + getPersistifier()->getFloatingPointData().push_front(c1); stream << "ConstOverFunction" << "("; - stream << c1; + stream << "REAL"; stream << ","; getPersistifier()->persistify(*ptr->_arg); stream << ")"; @@ -116,9 +122,12 @@ void ConstOverFunctionRecorder::execute(const GeoGenfun::AbsFunction & F) const FunctionCompositionReader::FunctionCompositionReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionComposition", interpreter) {} -GFPTR FunctionCompositionReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR FunctionCompositionReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - return GFPTR(new GeoGenfun::FunctionComposition(getInterpreter()->interpret(begin,sep).get(),getInterpreter()->interpret(sep+1,end).get())); + GFPTR f1=getInterpreter()->interpret(begin,sep,fpData); + GFPTR f2=getInterpreter()->interpret(sep+1,end,fpData); + + return GFPTR(new GeoGenfun::FunctionComposition(f1.get(),f2.get())); } FunctionCompositionRecorder::FunctionCompositionRecorder(GenFunctionPersistifier *persistifier): @@ -138,8 +147,8 @@ void FunctionCompositionRecorder::execute(const GeoGenfun::AbsFunction & F) cons FunctionNegationReader::FunctionNegationReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionNegation",interpreter) {} -GFPTR FunctionNegationReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { - return GFPTR(new GeoGenfun::FunctionNegation(getInterpreter()->interpret(begin,end).get())); +GFPTR FunctionNegationReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { + return GFPTR(new GeoGenfun::FunctionNegation(getInterpreter()->interpret(begin,end,fpData).get())); } FunctionNegationRecorder::FunctionNegationRecorder(GenFunctionPersistifier *persistifier): @@ -157,8 +166,8 @@ void FunctionNegationRecorder::execute(const GeoGenfun::AbsFunction & F) const { FunctionNoopReader::FunctionNoopReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionNoop",interpreter) {} -GFPTR FunctionNoopReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { - return GFPTR(new GeoGenfun::FunctionNoop(getInterpreter()->interpret(begin,end).get())); +GFPTR FunctionNoopReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { + return GFPTR(new GeoGenfun::FunctionNoop(getInterpreter()->interpret(begin,end,fpData).get())); } FunctionNoopRecorder::FunctionNoopRecorder(GenFunctionPersistifier *persistifier): @@ -176,9 +185,11 @@ void FunctionNoopRecorder::execute(const GeoGenfun::AbsFunction & F) const { FunctionProductReader::FunctionProductReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionProduct",interpreter) {} -GFPTR FunctionProductReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR FunctionProductReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - return GFPTR(new GeoGenfun::FunctionProduct(getInterpreter()->interpret(begin,sep).get(),getInterpreter()->interpret(sep+1,end).get())); + GFPTR f1=getInterpreter()->interpret(begin,sep,fpData); + GFPTR f2=getInterpreter()->interpret(sep+1,end,fpData); + return GFPTR(new GeoGenfun::FunctionProduct(f1.get(),f2.get())); } FunctionProductRecorder::FunctionProductRecorder(GenFunctionPersistifier *persistifier): @@ -198,9 +209,11 @@ void FunctionProductRecorder::execute(const GeoGenfun::AbsFunction & F) const { FunctionSumReader::FunctionSumReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionSum",interpreter) {} -GFPTR FunctionSumReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR FunctionSumReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - return GFPTR(new GeoGenfun::FunctionSum(getInterpreter()->interpret(begin,sep).get(),getInterpreter()->interpret(sep+1,end).get())); + GFPTR f1=getInterpreter()->interpret(begin,sep,fpData); + GFPTR f2=getInterpreter()->interpret(sep+1,end,fpData); + return GFPTR(new GeoGenfun::FunctionSum(f1.get(),f2.get())); } FunctionSumRecorder::FunctionSumRecorder(GenFunctionPersistifier *persistifier): @@ -225,9 +238,11 @@ void FunctionSumRecorder::execute(const GeoGenfun::AbsFunction & F) const { FunctionQuotientReader::FunctionQuotientReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionQuotient",interpreter) {} -GFPTR FunctionQuotientReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR FunctionQuotientReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - return GFPTR(new GeoGenfun::FunctionQuotient(getInterpreter()->interpret(begin,sep).get(),getInterpreter()->interpret(sep+1,end).get())); + GFPTR f1=getInterpreter()->interpret(begin,sep,fpData); + GFPTR f2=getInterpreter()->interpret(sep+1,end,fpData); + return GFPTR(new GeoGenfun::FunctionQuotient(f1.get(),f2.get())); } FunctionQuotientRecorder::FunctionQuotientRecorder(GenFunctionPersistifier *persistifier): @@ -247,9 +262,12 @@ void FunctionQuotientRecorder::execute(const GeoGenfun::AbsFunction & F) const { FunctionDifferenceReader::FunctionDifferenceReader(GenFunctionInterpreter *interpreter):GenFunctionReader("FunctionDifference",interpreter) {} -GFPTR FunctionDifferenceReader::execute(std::string::const_iterator begin, std::string::const_iterator end ) const { +GFPTR FunctionDifferenceReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> * fpData ) const { auto sep=split(begin,end); - return GFPTR(new GeoGenfun::FunctionDifference(getInterpreter()->interpret(begin,sep).get(),getInterpreter()->interpret(sep+1,end).get())); + + GFPTR f1=getInterpreter()->interpret(begin,sep,fpData); + GFPTR f2=getInterpreter()->interpret(sep+1,end,fpData); + return GFPTR(new GeoGenfun::FunctionDifference(f1.get(),f2.get())); } FunctionDifferenceRecorder::FunctionDifferenceRecorder(GenFunctionPersistifier *persistifier): @@ -273,7 +291,7 @@ void FunctionDifferenceRecorder::execute(const GeoGenfun::AbsFunction & F) const VariableReader::VariableReader(GenFunctionInterpreter *interpreter):GenFunctionReader("X",interpreter) {} -GFPTR VariableReader::execute(std::string::const_iterator, std::string::const_iterator) const { +GFPTR VariableReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> *) const { return GFPTR(new GeoGenfun::Variable()); } diff --git a/GeoModelIO/TFPersistification/src/ModIO.cpp b/GeoModelIO/TFPersistification/src/ModIO.cpp index 99df3526d4ec9fae421d6de5b0a0cc3571444595..e4f63678b9c2d2a7e1a0303de150f3eead54892d 100644 --- a/GeoModelIO/TFPersistification/src/ModIO.cpp +++ b/GeoModelIO/TFPersistification/src/ModIO.cpp @@ -6,11 +6,13 @@ ModReader::ModReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Mod", interpreter) {} -GFPTR ModReader::execute(std::string::const_iterator begin, std::string::const_iterator end) const { - double y; +GFPTR ModReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData) const { + std::string aNumberStr(begin,end); - std::istringstream stream(aNumberStr); - stream >> y; + if (aNumberStr!="REAL") { + throw std::runtime_error ("Parse error in ModReader"); + } + double y=fpData->back();fpData->pop_back(); return GFPTR(new GeoGenfun::Mod(y)); } @@ -22,8 +24,9 @@ void ModRecorder::execute(const GeoGenfun::AbsFunction & F) const { const GeoGenfun::Mod * ptr = dynamic_cast<const GeoGenfun::Mod *> (&F); if (!ptr) throw std::runtime_error("Error in ModRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); + getPersistifier()->getFloatingPointData().push_front(ptr->modulus()); stream << "Mod"; stream << "("; - stream<<ptr->modulus(); + stream<<"REAL"; stream << ")"; } diff --git a/GeoModelIO/TFPersistification/src/RectangularIO.cpp b/GeoModelIO/TFPersistification/src/RectangularIO.cpp index eb521dad9aae6127dad68f8bb5bd54fee572fd9b..e841fa6d0c7d94ae4f7ab85ebe3c22717520557e 100644 --- a/GeoModelIO/TFPersistification/src/RectangularIO.cpp +++ b/GeoModelIO/TFPersistification/src/RectangularIO.cpp @@ -6,31 +6,16 @@ RectangularReader::RectangularReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Rectangular", interpreter) {} -GFPTR RectangularReader::execute(std::string::const_iterator begin, std::string::const_iterator end) const { - std::vector<double> elements; - auto cStart=begin; - auto cNext=std::find(cStart, end,','); - while (cNext!=end) { - std::string aNumberStr(cStart,cNext); - std::istringstream stream(aNumberStr); - double d; - stream >> d; - elements.push_back(d); - cStart=cNext+1; - cNext=std::find(cStart, end,','); +GFPTR RectangularReader::execute(std::string::const_iterator begin, std::string::const_iterator end, std::deque<double> *fpData) const { + std::string aNumberStr(begin,end); + if (aNumberStr!=("REAL,REAL,REAL,REAL")) { + throw std::runtime_error("Parse error in RectangularReader"); } - std::string aNumberStr(cStart,cNext); - std::istringstream stream(aNumberStr); - double d; - stream >> d; - elements.push_back(d); - if (elements.size()!=4) throw std::runtime_error("Error in Rectangular: illegal value list"); - GeoGenfun::Rectangular *ptr=new GeoGenfun::Rectangular(); - ptr->x0().setValue(elements[0]); - ptr->x1().setValue(elements[1]); - ptr->baseline().setValue(elements[2]); - ptr->height().setValue(elements[3]); + ptr->x0().setValue(fpData->back()); fpData->pop_back(); + ptr->x1().setValue(fpData->back()); fpData->pop_back(); + ptr->baseline().setValue(fpData->back()); fpData->pop_back(); + ptr->height().setValue(fpData->back()); fpData->pop_back(); return GFPTR(ptr); } @@ -42,14 +27,11 @@ void RectangularRecorder::execute(const GeoGenfun::AbsFunction & F) const { const GeoGenfun::Rectangular * ptr = dynamic_cast<const GeoGenfun::Rectangular *> (&F); if (!ptr) throw std::runtime_error("Error in RectangularRecorder:: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); + getPersistifier()->getFloatingPointData().push_front(ptr->x0().getValue()); + getPersistifier()->getFloatingPointData().push_front(ptr->x1().getValue()); + getPersistifier()->getFloatingPointData().push_front(ptr->baseline().getValue()); + getPersistifier()->getFloatingPointData().push_front(ptr->height().getValue()); stream << "Rectangular"; - stream << "("; - stream << ptr->x0().getValue(); - stream << ","; - stream << ptr->x1().getValue(); - stream << ","; - stream << ptr->baseline().getValue(); - stream << ","; - stream << ptr->height().getValue(); - stream << ")"; + stream << "(REAL,REAL,REAL,REAL)"; + } diff --git a/GeoModelIO/TFPersistification/src/SinIO.cpp b/GeoModelIO/TFPersistification/src/SinIO.cpp index 4a450d3af62f93d6eaa6c26df67732251eb2a700..e30116ae9dee20e03ee2c2f3e86ba88b1eaab378 100644 --- a/GeoModelIO/TFPersistification/src/SinIO.cpp +++ b/GeoModelIO/TFPersistification/src/SinIO.cpp @@ -7,7 +7,7 @@ SinReader::SinReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Sin", interpreter) {} -GFPTR SinReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR SinReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::Sin()); } diff --git a/GeoModelIO/TFPersistification/src/SqrtIO.cpp b/GeoModelIO/TFPersistification/src/SqrtIO.cpp index a06a58e10519551179a1febe1f1bf87ea123e05e..e0c21fd91d35cfc1a0308972d1fad02ab22f31e8 100644 --- a/GeoModelIO/TFPersistification/src/SqrtIO.cpp +++ b/GeoModelIO/TFPersistification/src/SqrtIO.cpp @@ -7,7 +7,7 @@ SqrtReader::SqrtReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Sqrt", interpreter) {} -GFPTR SqrtReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR SqrtReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::Sqrt()); } diff --git a/GeoModelIO/TFPersistification/src/SquareIO.cpp b/GeoModelIO/TFPersistification/src/SquareIO.cpp index 1f70c16e042d55e38f1d353d2d59ddb468fb533e..9c0607dcd8019715b275a40dc5a10397c7b111ef 100644 --- a/GeoModelIO/TFPersistification/src/SquareIO.cpp +++ b/GeoModelIO/TFPersistification/src/SquareIO.cpp @@ -7,7 +7,7 @@ SquareReader::SquareReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Square", interpreter) {} -GFPTR SquareReader::execute(std::string::const_iterator, std::string::const_iterator ) const { +GFPTR SquareReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> * ) const { return GFPTR(new GeoGenfun::Square()); } diff --git a/GeoModelIO/TFPersistification/src/TanIO.cpp b/GeoModelIO/TFPersistification/src/TanIO.cpp index ad57db23d0dbb142ea6322fe0b7602718acc4022..3c0fb7a3233351cfb0f28c0c8e431cb184e98a3f 100644 --- a/GeoModelIO/TFPersistification/src/TanIO.cpp +++ b/GeoModelIO/TFPersistification/src/TanIO.cpp @@ -7,7 +7,7 @@ TanReader::TanReader(GenFunctionInterpreter *interpreter):GenFunctionReader("Tan", interpreter) {} -GFPTR TanReader::execute(std::string::const_iterator, std::string::const_iterator) const { +GFPTR TanReader::execute(std::string::const_iterator, std::string::const_iterator, std::deque<double> *) const { return GFPTR(new GeoGenfun::Tan()); } diff --git a/GeoModelIO/TFPersistification/src/TransFunctionInterpreter.cpp b/GeoModelIO/TFPersistification/src/TransFunctionInterpreter.cpp index a1f8b7ba6b2f675d36c6ca1b50d09499e6dd0a09..d053299537f9652f4b849cd721103cc6c315ba78 100644 --- a/GeoModelIO/TFPersistification/src/TransFunctionInterpreter.cpp +++ b/GeoModelIO/TFPersistification/src/TransFunctionInterpreter.cpp @@ -26,9 +26,9 @@ void TransFunctionInterpreter::add(const std::string & str, const TransFunctionR } -TFPTR TransFunctionInterpreter::interpret(const std::string &exprString) const { - size_t begin = exprString.find_first_of("{"); - size_t end = exprString.find_last_of("}"); +TFPTR TransFunctionInterpreter::interpret(const std::string &exprString, std::deque<double> *fpData) const { + size_t begin = exprString.find_first_of('{'); + size_t end = exprString.find_last_of('}'); if (!((begin!=std::string::npos) && (end!=std::string::npos))) { throw std::runtime_error ("Ominous warning in TransFunctionPersistier: cannot parse function"); } @@ -47,5 +47,5 @@ TFPTR TransFunctionInterpreter::interpret(const std::string &exprString) const { throw std::runtime_error ("Ominous warning in TransFunctionPersistier: cannot interpret function"); } const TransFunctionReader *reader = (*rIter).second; - return reader->execute(argument); + return reader->execute(argument,fpData); } diff --git a/GeoModelIO/TFPersistification/src/TransFunctionPersistifier.cpp b/GeoModelIO/TFPersistification/src/TransFunctionPersistifier.cpp index ec4024f5fd955f1ab35f12eb631f9e3d60ccb72b..b5e85c2e492a6b95573176b717483c70c78b705c 100644 --- a/GeoModelIO/TFPersistification/src/TransFunctionPersistifier.cpp +++ b/GeoModelIO/TFPersistification/src/TransFunctionPersistifier.cpp @@ -15,6 +15,11 @@ const std::string & TransFunctionPersistifier::getCodedString() const { } +std::deque<double> & TransFunctionPersistifier::getFloatingPointData() const { + return floatingPointData; +} + + TransFunctionPersistifier::~TransFunctionPersistifier() { delete stream; for (auto i=recorderMap.begin(); i!=recorderMap.end();i++) { diff --git a/GeoModelIO/TFPersistification/src/TransFunctionReader.cpp b/GeoModelIO/TFPersistification/src/TransFunctionReader.cpp index fe7399c86fd70ee18269eea9725c191822d141a5..afd7c9f7f43b0cd00b4233a82e828553f163e30b 100644 --- a/GeoModelIO/TFPersistification/src/TransFunctionReader.cpp +++ b/GeoModelIO/TFPersistification/src/TransFunctionReader.cpp @@ -37,7 +37,6 @@ std::pair<std::string, std::string> TransFunctionReader::split(const std::string } TransFunctionReader::~TransFunctionReader () {} -#include "GeoModelKernel/GeoXF.h" #include "GeoModelKernel/GeoDefinitions.h" #include <iostream> @@ -51,63 +50,51 @@ PostMultReader::PostMultReader(TransFunctionInterpreter *interpreter):TransFunct PowReader::PowReader(TransFunctionInterpreter *interpreter):TransFunctionReader("GeoXF::Pow", interpreter) {} -TFPTR ProductReader::execute(const std::string & arg) const { +TFPTR ProductReader::execute(const std::string & arg, std::deque<double> *fpData) const { auto pair=split(arg); - return TFPTR(GeoXF::Product(getInterpreter()->interpret(pair.first).get(), getInterpreter()->interpret(pair.second).get()).clone()); + TFPTR t1=getInterpreter()->interpret(pair.first,fpData); + TFPTR t2= getInterpreter()->interpret(pair.second,fpData); + + return TFPTR(GeoXF::Product(t1.get(), t2.get()).clone()); } -TFPTR PreMultReader::execute(const std::string & arg ) const { +TFPTR PreMultReader::execute(const std::string & arg, std::deque<double> *fpData) const { auto pair=split(arg); - TFPTR p2=getInterpreter()->interpret(pair.second); - GeoTrf::Transform3D t1 = scanT(pair.first); + GeoTrf::Transform3D t1 = scanT(pair.first,fpData); + TFPTR p2=getInterpreter()->interpret(pair.second,fpData); return TFPTR(GeoXF::PreMult(t1, p2.get()).clone()); } -TFPTR PostMultReader::execute(const std::string & arg) const { +TFPTR PostMultReader::execute(const std::string & arg, std::deque<double> *fpData) const { auto pair=split(arg); - TFPTR p1=getInterpreter()->interpret(pair.first); - GeoTrf::Transform3D t2=scanT(pair.second); + TFPTR p1=getInterpreter()->interpret(pair.first,fpData); + GeoTrf::Transform3D t2=scanT(pair.second,fpData); return TFPTR(GeoXF::PostMult(p1.get(), t2).clone()); } -TFPTR PowReader::execute(const std::string & arg) const { +TFPTR PowReader::execute(const std::string & arg, std::deque<double> *fpData) const { auto pair=split(arg); - return TFPTR(GeoXF::Pow((scanT(pair.first)),*getInterpreter()->getGenFunctionInterpreter()->interpret(pair.second.begin(), pair.second.end())).clone()); + GeoTrf::Transform3D t1=scanT(pair.first,fpData); + GFPTR f1 = getInterpreter()->getGenFunctionInterpreter()->interpret(pair.second.begin(), pair.second.end(),fpData); + + return TFPTR(GeoXF::Pow(t1,*f1).clone()); } GeoTrf::Transform3D -TransFunctionReader::scanT(const std::string & exprString) const { - size_t start = exprString.find_first_of("["); - double x[12]; - int i=0; - while (1) { - size_t end = exprString.find_first_of(";",start+1); - std::string atomic=exprString.substr(start+1,end-start); - std::istringstream stream(atomic.substr(0,atomic.size()-1)); - stream >> x[i]; - start=end; - if (atomic.find("]")!=std::string::npos) break; - i++; - } - double & xx=x[0], & xy=x[1], & xz=x[2]; - double & yx=x[3], & yy=x[4], & yz=x[5]; - double & zx=x[6], & zy=x[7], & zz=x[8]; - double & dx=x[9], & dy=x[10], & dz=x[11]; +TransFunctionReader::scanT(const std::string & exprString, std::deque<double> *fpData) const { + if (exprString!="Transform[XF]") { + throw std::runtime_error("Error in restoration of a TransFunction"); + } + GeoTrf::Transform3D t; - t(0, 0) = xx; //xf(0, 0); - t(0, 1) = xy; //xf(0, 1); - t(0, 2) = xz; //xf(0, 2); - t(1, 0) = yx; //xf(1, 0); - t(1, 1) = yy; //xf(1, 1); - t(1, 2) = yz; //xf(1, 2); - t(2, 0) = zx; //xf(2, 0); - t(2, 1) = zy; //xf(2, 1); - t(2, 2) = zz; //xf(2, 2); - t(0, 3) = dx; //xf(0, 3); - t(1, 3) = dy; //xf(1, 3); - t(2, 3) = dz; //xf(2, 3); + for (int i=0;i<3;i++) { + for (int j=0;j<4;j++) { + t(i,j) = (*fpData).back(); + fpData->pop_back(); + } + } return t; } diff --git a/GeoModelIO/TFPersistification/src/TransFunctionRecorder.cpp b/GeoModelIO/TFPersistification/src/TransFunctionRecorder.cpp index 3154bbeea556797bc4291449009a84f25c69134e..ebf3bae2033a648ee2b4102b846aab073e474a0b 100644 --- a/GeoModelIO/TFPersistification/src/TransFunctionRecorder.cpp +++ b/GeoModelIO/TFPersistification/src/TransFunctionRecorder.cpp @@ -19,7 +19,6 @@ const TransFunctionPersistifier *TransFunctionRecorder::getPersistifier() const TransFunctionRecorder::~TransFunctionRecorder () {} -#include "GeoModelKernel/GeoXF.h" // #include "GeoModelKernel/GeoDefinitions.h" @@ -52,11 +51,12 @@ void PreMultRecorder::execute( const GeoXF::Function & function) const { if (!ptr) throw std::runtime_error("Error in PreMultRecorder: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); stream << "GeoXF::PreMult" << "{"; - stream << "Transform[" - << ptr->arg1()(0,0) << ";" << ptr->arg1()(0,1) << ";" << ptr->arg1()(0,2) << ";" - << ptr->arg1()(1,0) << ";" << ptr->arg1()(1,1) << ";" << ptr->arg1()(1,2) << ";" - << ptr->arg1()(2,0) << ";" << ptr->arg1()(2,1) << ";" << ptr->arg1()(2,2) << ";" - << ptr->arg1()(0,3) << ";" << ptr->arg1()(1,3) << ";" << ptr->arg1()(2,3) << "]"; + stream << "Transform[XF]"; + for (int i=0;i<3;i++) { + for (int j=0;j<4;j++) { + getPersistifier()->getFloatingPointData().push_front(ptr->arg1()(i,j)); + } + } stream << "|"; getPersistifier()->persistify(*ptr->arg2()); stream << "}"; @@ -71,11 +71,12 @@ void PostMultRecorder::execute( const GeoXF::Function & function) const { stream << "GeoXF::PostMult" << "{"; getPersistifier()->persistify(*ptr->arg1()); stream << "|"; - stream << "Transform[" - << ptr->arg2()(0,0) << ";" << ptr->arg2()(0,1) << ";" << ptr->arg2()(0,2) << ";" - << ptr->arg2()(1,0) << ";" << ptr->arg2()(1,1) << ";" << ptr->arg2()(1,2) << ";" - << ptr->arg2()(2,0) << ";" << ptr->arg2()(2,1) << ";" << ptr->arg2()(2,2) << ";" - << ptr->arg2()(0,3) << ";" << ptr->arg2()(1,3) << ";" << ptr->arg2()(2,3) << "]"; + stream << "Transform[XF]"; + for (int i=0;i<3;i++) { + for (int j=0;j<4;j++) { + getPersistifier()->getFloatingPointData().push_front(ptr->arg2()(i,j)); + } + } stream << "}"; return; } @@ -87,14 +88,23 @@ void PowRecorder::execute( const GeoXF::Function & function) const { if (!ptr) throw std::runtime_error("Error in PowRecorder: wrong function type"); std::ostringstream & stream = getPersistifier()->getStream(); stream << "GeoXF::Pow" << "{"; - stream << "Transform[" - << ptr->transform()(0,0) << ";" << ptr->transform()(0,1) << ";" << ptr->transform()(0,2) << ";" - << ptr->transform()(1,0) << ";" << ptr->transform()(1,1) << ";" << ptr->transform()(1,2) << ";" - << ptr->transform()(2,0) << ";" << ptr->transform()(2,1) << ";" << ptr->transform()(2,2) << ";" - << ptr->transform()(0,3) << ";" << ptr->transform()(1,3) << ";" << ptr->transform()(2,3) << "]"; + stream << "Transform[XF]"; + for (int i=0;i<3;i++) { + for (int j=0;j<4;j++) { + getPersistifier()->getFloatingPointData().push_front(ptr->transform()(i,j)); + } + } stream << "|"; getPersistifier()->getGenFunctionPersistifier()->persistify(*ptr->function()); stream << getPersistifier()->getGenFunctionPersistifier()->getCodedString(); stream << "}"; + + std::deque<double> & floatingPointData=getPersistifier()->getGenFunctionPersistifier()->getFloatingPointData(); + while (!floatingPointData.empty()) { + getPersistifier()->getFloatingPointData().push_front(floatingPointData.back()); + floatingPointData.pop_back(); + } + + return; } diff --git a/GeoModelTools/CMakeLists.txt b/GeoModelTools/CMakeLists.txt index bed80fb75f6f943b19353885f3239e9281857724..1f7861e775cd44706a8c2957b54673b7bc8cf4f8 100644 --- a/GeoModelTools/CMakeLists.txt +++ b/GeoModelTools/CMakeLists.txt @@ -48,6 +48,7 @@ include( GNUInstallDirs ) # Set up the build of the libraries of the project. add_subdirectory( GeoModelXML ) add_subdirectory( GeoModelXMLParser ) +add_subdirectory( GeoModelXMLDumper ) add_subdirectory( GeoModelJSONParser ) add_subdirectory( ExpressionEvaluator ) add_subdirectory( GMCAT ) diff --git a/GeoModelTools/GDMLtoGM/src/elementHandler.cxx b/GeoModelTools/GDMLtoGM/src/elementHandler.cxx index 89321d4128abe659e59383eaf217ba550d019603..d146b5c62e1ff8dce6f28044e836be149ddf82e5 100644 --- a/GeoModelTools/GDMLtoGM/src/elementHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/elementHandler.cxx @@ -42,7 +42,7 @@ void elementHandler::ElementHandle() { } break; } - else if (nH=="fraction") { + else if (nH=="fraction" || nH=="composite") { fractionHandler* fH=dynamic_cast<fractionHandler*>(h); if (!fH) std::cout<<" something is wrong! can not retrieve fractionHandler!!!"<<std::endl; e.addIsotope(fH->getFraction()); diff --git a/GeoModelTools/GDMLtoGM/src/materialHandler.cxx b/GeoModelTools/GDMLtoGM/src/materialHandler.cxx index 7a20179ece0cd453c6f79e56b36b4e4149a23911..ccfbf6171374dfe55997cf54e243441821ec9ce3 100644 --- a/GeoModelTools/GDMLtoGM/src/materialHandler.cxx +++ b/GeoModelTools/GDMLtoGM/src/materialHandler.cxx @@ -36,7 +36,7 @@ void materialHandler::ElementHandle() { std::string nH=h->GetName(); //std::cout<<" handler name "<<nH<<std::endl; - if (nH=="fraction") + if (nH=="fraction" || nH=="composite") { fractionHandler* fH=dynamic_cast<fractionHandler*>(h); if (!fH) std::cout<<" something is wrong! can not retrieve fractionHandler!!!"<<std::endl; diff --git a/GeoModelTools/GMCAT/CMakeLists.txt b/GeoModelTools/GMCAT/CMakeLists.txt index 2347c8588443e18daa07f73ef027bd528ce8a71d..91b601917a235e2cbdcd068aa4955a7ea4733e1d 100644 --- a/GeoModelTools/GMCAT/CMakeLists.txt +++ b/GeoModelTools/GMCAT/CMakeLists.txt @@ -1,5 +1,8 @@ # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + +file( GLOB MANPAGES man/man1/* ) + # Declare the package's executable. add_executable( gmcat src/gmcat.cxx src/publishMetaData.cpp) target_link_libraries( gmcat PRIVATE GeoModelCore::GeoModelKernel @@ -21,3 +24,7 @@ install( TARGETS gmcat EXPORT ${PROJECT_NAME}-export RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) + +install( FILES ${MANPAGES} + DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 + COMPONENT Runtime ) diff --git a/GeoModelTools/GMCAT/man/man1/gmcat.1 b/GeoModelTools/GMCAT/man/man1/gmcat.1 new file mode 100644 index 0000000000000000000000000000000000000000..ad092e2c36e1c53cca12e778a44ef1b0a5e7d919 --- /dev/null +++ b/GeoModelTools/GMCAT/man/man1/gmcat.1 @@ -0,0 +1,44 @@ +.\" Manpage for gmcat +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "gmex man page" +.SH NAME +gmcat \- Write geomodel data to an SQLite file +.SH SYNOPSIS +gmcat [inputFile1] [InputFile2] ... [Plugin1] [Plugin2] ... -o outputFile [-v] [-g Repository] +.SH DESCRIPTION +gmcat takes one or more input files containing a GeoModel description in SQLite format, one or more plugins which construct the GeoModel description, or a mix of files and plugins, and outputs the GeoModel description to an SQLite file, along with metadata. +.SH OPTIONS + +.TP +.BI \-g \ Repository +Record information about an external git-managed repository in the metadata. Default is current working directory. +.TP +.BI \-v +Print verbose output to the screen (default: direct verbose output to /tmp) + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmex(1), sqlitebrowser(1), gmstatistics(1) + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite +. + +.SH BUGS +There are no known bugs. +.SH AUTHORS +Primary authors are +.MT riccardomariabianchi@\:pitt\:.edu +Riccardo Maria Bianchi +.ME , +.MT boudreau@\:pitt\:.edu +Joe Boudreau +.ME +and +.MT Vakhtang.Tsulaia@\:cern\:.ch +Vakho Tsulaia +.ME diff --git a/GeoModelTools/GMCAT/src/gmcat.cxx b/GeoModelTools/GMCAT/src/gmcat.cxx index 301a534ac7e9c6a910c8d381b79f05feb6f9fb80..4fa4f097380b8d314e723fe365318393d4795f4a 100644 --- a/GeoModelTools/GMCAT/src/gmcat.cxx +++ b/GeoModelTools/GMCAT/src/gmcat.cxx @@ -35,10 +35,11 @@ const std::string shared_obj_extension=".so"; void publishMetaData( GMDBManager & db, - const std::string& repoPath, - std::vector<std::string> &inputFiles, - std::vector<std::string> &inputPlugins, - std::string &outputFile); + const std::string& repoPath, + const std::vector<std::string> &inputFiles, + const std::vector<std::string> &inputPlugins, + const std::vector<std::string> &pluginNames, + const std::string &outputFile); int main(int argc, char ** argv) { @@ -65,8 +66,7 @@ int main(int argc, char ** argv) { // // Parse the command line: // - std::vector<std::string> inputFiles; - std::vector<std::string> inputPlugins; + std::vector<std::string> inputFiles{}, inputPlugins{}; std::string outputFile; std::string gmAtlasDir{"."}; bool outputFileSet = false; @@ -86,7 +86,7 @@ int main(int argc, char ** argv) { verbose=true; } else if (argument.find("-g")!=std::string::npos) { - gmAtlasDir = std::string(argv[++argi]); + gmAtlasDir = std::string(argv[++argi]); } else if (argument.find(shared_obj_extension)!=std::string::npos) { inputPlugins.push_back(argument); @@ -112,8 +112,8 @@ int main(int argc, char ** argv) { if (access(outputFile.c_str(),F_OK)==0) { if (!access(outputFile.c_str(),W_OK)) { if (system(("rm -f "+ outputFile).c_str())) { - std::cerr << "gmcat -- Error, cannot overwrite existing file " << outputFile << std::endl; - return 3; + std::cerr << "gmcat -- Error, cannot overwrite existing file " << outputFile << std::endl; + return 3; } } else { @@ -142,6 +142,7 @@ int main(int argc, char ** argv) { } std::vector<GeoPublisher*> vecPluginsPublishers; // caches the stores from all plugins + std::vector<std::unique_ptr<GeoVGeometryPlugin>> pluginInstances{}; for (const std::string & plugin : inputPlugins) { GeoGeometryPluginLoader loader; @@ -151,7 +152,7 @@ int main(int argc, char ** argv) { std::cout.rdbuf(fileBuff); } - GeoVGeometryPlugin *factory=loader.load(plugin); + std::unique_ptr<GeoVGeometryPlugin> factory{loader.load(plugin)}; if (!factory) { std::cerr << "gmcat -- Could not load plugin " << plugin << std::endl; return 5; @@ -172,6 +173,7 @@ int main(int argc, char ** argv) { std::cout << "\t ... DONE!" << std::endl; std::cout.rdbuf(fileBuff); } + pluginInstances.emplace_back(std::move(factory)); } // @@ -184,41 +186,35 @@ int main(int argc, char ** argv) { std::cout.rdbuf(fileBuff); } - GMDBManager* db = new GMDBManager(file); + auto db = std::make_unique<GMDBManager>(file); if (!db->checkIsDBOpen()){ std::cerr << "gmcat -- Error opening the input file: " << file << std::endl; return 6; } /* set the GeoModel reader */ - GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db); + GeoModelIO::ReadGeoModel readInGeo = GeoModelIO::ReadGeoModel(db.get()); /* build the GeoModel geometry */ - const GeoVPhysVol* dbPhys = readInGeo.buildGeoModel(); // builds the whole GeoModel tree in memory + PVConstLink dbPhys{readInGeo.buildGeoModel()}; // builds the whole GeoModel tree in memory /* get an handle on a Volume Cursor, to traverse the whole set of Volumes */ GeoVolumeCursor aV(dbPhys); /* loop over the Volumes in the tree */ while (!aV.atEnd()) { - - if (aV.getName()!="ANON") { - GeoNameTag *nameTag=new GeoNameTag(aV.getName()); - world->add(nameTag); - } - GeoTransform *transform= new GeoTransform(aV.getTransform()); - world->add(transform); - world->add((GeoVPhysVol *) &*aV.getVolume()); - aV.next(); + if (aV.getName()!="ANON") { + world->add(make_intrusive<GeoNameTag>(aV.getName())); + } + world->add(make_intrusive<GeoTransform>(aV.getTransform())); + world->add(const_pointer_cast(aV.getVolume())); + aV.next(); } - - delete db; if(!verbose) { std::cout.rdbuf(coutBuff); std::cout << "\t ... DONE!" << std::endl; std::cout.rdbuf(fileBuff); } - } // // Open a new database: @@ -259,10 +255,17 @@ int main(int argc, char ** argv) { std::cout << "Writing metadata to the output database ..." << std::endl; std::cout.rdbuf(fileBuff); } - try { - publishMetaData(db,gmAtlasDir,inputFiles,inputPlugins,outputFile); + std::vector<std::string> systemNames{}; + for (auto& plugin : pluginInstances) { + if(plugin->getName().size()){ + systemNames.push_back(plugin->getName()); + } } - catch(std::runtime_error& e) { + std::sort(systemNames.begin(), systemNames.end()); + + try { + publishMetaData(db, gmAtlasDir, inputFiles, inputPlugins, systemNames, outputFile); + } catch(const std::runtime_error& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } diff --git a/GeoModelTools/GMCAT/src/publishMetaData.cpp b/GeoModelTools/GMCAT/src/publishMetaData.cpp index edce9cb89a19b3350c0bc1695672fb70bd1ecffc..5b973046e149e59aa9c7ca23a4ddf823fe7aeb36 100644 --- a/GeoModelTools/GMCAT/src/publishMetaData.cpp +++ b/GeoModelTools/GMCAT/src/publishMetaData.cpp @@ -1,4 +1,5 @@ #include "GeoModelDBManager/GMDBManager.h" +#include <GeoModelHelpers/StringUtils.h> #include <string> #include <iostream> #include <unistd.h> @@ -10,11 +11,12 @@ #define STR_VALUE(arg) #arg #define STR_NAME(name) STR_VALUE(name) -std::string resolveVariable(const std::string& varName) { - const char* var = std::getenv(varName.c_str()); - if (!var) return std::string{}; - return std::string(var); +namespace{ + static const std::string tableName{"AAHEADER"}; } + +using tableVariant = std::variant<int,long,float,double,std::string>; + std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false) { std::string response; @@ -33,19 +35,20 @@ std::string getCommandOutput(const std::string & cmd, bool firstLineOnly=false) } void publishMetaData( GMDBManager & db, - const std::string& repoPath, - std::vector<std::string> &inputFiles, - std::vector<std::string> &inputPlugins, - std::string &outputFile) { + const std::string& repoPath, + const std::vector<std::string> &inputFiles, + const std::vector<std::string> &inputPlugins, + const std::vector<std::string> &pluginNames, + const std::string &outputFile) { struct Metadata { std::string dateString=getCommandOutput("date -Iminutes"); - std::string username{resolveVariable("USER")}; + std::string username{GeoStrUtils::resolveEnviromentVariables("${USER}")}; std::string hostname{}; - std::string os; - std::string wd; + std::string os{}; + std::string wd{}; std::string gmversion=STR_NAME(GMVERSION); - std::string outputFile; + std::string outputFile{}; std::string geoModelDataBranch="Undefined"; // or overwritten below std::string gmdataIsClean ="Not applicable"; // or overwritten below std::string gmdataCommitHash ="Undefined"; // or overwritten below @@ -64,7 +67,7 @@ void publishMetaData( GMDBManager & db, char wdbuff[1024]; metadata.wd=std::string(getcwd(wdbuff,1024)); #else - metadata.wd= resolveVariable("PWD"); + metadata.wd= GeoStrUtils::resolveEnviromentVariables("${PWD}"); #endif metadata.outputFile=outputFile; @@ -78,24 +81,22 @@ void publishMetaData( GMDBManager & db, if (gethostname (hn,1024)==0) metadata.hostname=std::string(hn); } - std::string geomodel_xml_dir=resolveVariable("GEOMODEL_XML_DIR"); + std::string geomodel_xml_dir=GeoStrUtils::resolveEnviromentVariables("${GEOMODEL_XML_DIR}"); if (!geomodel_xml_dir.empty()) { { metadata.geoModelDataBranch=getCommandOutput("git -C "+ geomodel_xml_dir + " rev-parse --abbrev-ref HEAD"); std::string shortGitStatus=getCommandOutput("git -C "+ geomodel_xml_dir + " status -s "); if (shortGitStatus!="") { - metadata.gmdataIsClean="no"; - } - else { - std::string synchedToOrigin=getCommandOutput("git -C "+ std::string(geomodel_xml_dir) + " diff origin/"+metadata.geoModelDataBranch,true); - if (synchedToOrigin!="") { - metadata.gmdataIsClean="no"; - } - else { - metadata.gmdataIsClean="yes"; - metadata.gmdataCommitHash=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " log -1 --format=format:\"%H\""); - metadata.gmdataAssociatedTag=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " describe --tag " + metadata.gmdataCommitHash+ " 2> /dev/null"); - } + metadata.gmdataIsClean="no"; + } else { + std::string synchedToOrigin=getCommandOutput("git -C "+ std::string(geomodel_xml_dir) + " diff origin/"+metadata.geoModelDataBranch,true); + if (synchedToOrigin.size()) { + metadata.gmdataIsClean="no"; + }else { + metadata.gmdataIsClean="yes"; + metadata.gmdataCommitHash=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " log -1 --format=format:\"%H\""); + metadata.gmdataAssociatedTag=getCommandOutput("git -C " + std::string(geomodel_xml_dir) + " describe --tag " + metadata.gmdataCommitHash+ " 2> /dev/null"); + } } } } @@ -109,59 +110,46 @@ void publishMetaData( GMDBManager & db, } else { std::string synchedToOrigin=getCommandOutput("git -C " + repoPath + " diff origin/"+xtraMetadata.branch,true); - if (synchedToOrigin!="") { - xtraMetadata.isClean="no"; - } - else { - xtraMetadata.isClean="yes"; - xtraMetadata.commitHash=getCommandOutput("git -C " + repoPath + " log -1 --format=format:\"%H\""); - xtraMetadata.associatedTag=getCommandOutput("git -C " + repoPath + " describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null"); + xtraMetadata.isClean = synchedToOrigin.empty() ? "yes" : "no"; + if (synchedToOrigin.empty()){ + xtraMetadata.commitHash=getCommandOutput("git -C " + repoPath + " log -1 --format=format:\"%H\""); + xtraMetadata.associatedTag=getCommandOutput("git -C " + repoPath + " describe --tag " + xtraMetadata.commitHash+ " 2> /dev/null"); } } - } - else { + } else { std::cerr << std::endl << "WARNING: no information on User repository will be written to metadata. " << std::endl; } // // Fill the header file with metadata // - std::vector<std::string> gmcatColNames={"Date", - "GeoModelDataBranch", - "Username", - "Hostname", - "OS", - "WorkingDirectory", - "GeoModelVersion", - "OutputFile", - "GeoModelDataIsClean", - "GeoModelDataCommitHash", - "GeoModelDataAssociatedTag" - }; - std::vector<std::string> gmcatColTypes={"STRING", - "STRING" , - "STRING", - "STRING", - "STRING", - "STRING", - "STRING", - "STRING", - "STRING", - "STRING", - "STRING" - }; - + std::vector<std::string> gmcatColNames={"Date", + "GeoModelDataBranch", + "Username", + "Hostname", + "OS", + "WorkingDirectory", + "GeoModelVersion", + "OutputFile", + "PluginNames", + "PluginLibs", + "DataBaseFiles", + "GeoModelDataIsClean", + "GeoModelDataCommitHash", + "GeoModelDataAssociatedTag", + tableName + "_DATA_ID" + }; + std::vector<std::string> gmcatColTypes(gmcatColNames.size(), "STRING"); + gmcatColTypes[gmcatColTypes.size() - 1] = "INT"; // Strip extraneous \n - for (std::string * s : { - &metadata.geoModelDataBranch, - &metadata.dateString, - &metadata.gmdataAssociatedTag}) { - s->erase(std::remove(s->begin(), s->end(), '\n'), s->end()); + for (std::string * s : {&metadata.geoModelDataBranch, &metadata.dateString, + &metadata.gmdataAssociatedTag, &xtraMetadata.repo, &xtraMetadata.branch}) { + s->erase(std::remove(s->begin(), s->end(), '\n'), s->end()); } - - + + - std::vector<std::vector<std::variant<int,long,float,double,std::string>>> gmcatData ={{ + std::vector<std::vector<tableVariant>> gmcatData ={{ metadata.dateString, metadata.geoModelDataBranch, metadata.username, @@ -170,59 +158,32 @@ void publishMetaData( GMDBManager & db, metadata.wd, metadata.gmversion, metadata.outputFile, + GeoStrUtils::chainUp(pluginNames,";"), + GeoStrUtils::chainUp(inputPlugins,";"), + GeoStrUtils::chainUp(inputFiles,";"), metadata.gmdataIsClean, metadata.gmdataCommitHash, - metadata.gmdataAssociatedTag + metadata.gmdataAssociatedTag, + 0 }}; - unsigned int pcounter(0); - for (std::string plugin : inputPlugins) { - gmcatColNames.push_back("P"+std::to_string(pcounter++)); - gmcatColTypes.push_back("STRING"); - gmcatData[0].push_back((plugin)); - } - unsigned int fcounter(0); - for (std::string file : inputFiles) { - gmcatColNames.push_back("F"+std::to_string(fcounter++)); - gmcatColTypes.push_back("STRING"); - gmcatData[0].push_back(file); - } - - // Strip extraneous \n - for (std::string * s : { - &xtraMetadata.repo, - &xtraMetadata.branch }) { - s->erase(std::remove(s->begin(), s->end(), '\n'), s->end()); - } - - - if (xtraMetadata.branch!="Undefined") { - std::vector<std::string> xtraColNames={ - "UserCodeGitRepository", - "UserCodeGitBranch", - "UserCodeRepoIsClean", - "UserCodeRepoCommitHash", - "UserCodeAssociatedTag"}; - std::vector<std::string> xtraColTypes={"STRING", - "STRING", - "STRING", - "STRING", - "STRING"}; - std::vector<std::vector<std::variant<int,long,float,double,std::string>>> xtraData ={{ - xtraMetadata.repo, - xtraMetadata.branch, - xtraMetadata.isClean, - xtraMetadata.commitHash, - xtraMetadata.associatedTag - }}; - using std::begin, std::end; - gmcatColNames.insert(end(gmcatColNames), begin(xtraColNames), end(xtraColNames)); - gmcatColTypes.insert(end(gmcatColTypes), begin(xtraColTypes), end(xtraColTypes)); - gmcatData[0].insert(end(gmcatData[0]), begin(xtraData[0]), end(xtraData[0])); - db.createCustomTable("AAHEADER", gmcatColNames,gmcatColTypes,gmcatData); - } - else { - db.createCustomTable("AAHEADER", gmcatColNames,gmcatColTypes,gmcatData); + std::vector<std::string> xtraColNames={"UserCodeGitRepository", + "UserCodeGitBranch", + "UserCodeRepoIsClean", + "UserCodeRepoCommitHash", + "UserCodeAssociatedTag"}; + std::vector<std::string> xtraColTypes(xtraColNames.size(), "STRING"); + std::vector<std::vector<tableVariant>> xtraData ={{xtraMetadata.repo, + xtraMetadata.branch, + xtraMetadata.isClean, + xtraMetadata.commitHash, + xtraMetadata.associatedTag }}; + gmcatColNames.insert(std::end(gmcatColNames), std::begin(xtraColNames), std::end(xtraColNames)); + gmcatColTypes.insert(std::end(gmcatColTypes), std::begin(xtraColTypes), std::end(xtraColTypes)); + gmcatData[0].insert(std::end(gmcatData[0]), std::begin(xtraData[0]), std::end(xtraData[0])); + } + db.createCustomTable(tableName, gmcatColNames,gmcatColTypes,gmcatData); + } diff --git a/GeoModelTools/GMSTATISTICS/CMakeLists.txt b/GeoModelTools/GMSTATISTICS/CMakeLists.txt index f371c62d1d82a0db547f3cab6d5a745a9779c293..a41f639b584baca8728a05a57205d9482130c0e5 100644 --- a/GeoModelTools/GMSTATISTICS/CMakeLists.txt +++ b/GeoModelTools/GMSTATISTICS/CMakeLists.txt @@ -1,5 +1,9 @@ # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + + +file( GLOB MANPAGES man/man1/* ) + # Declare the package's executable. add_executable( gmstatistics src/gmstatistics.cxx src/GeoInventoryGraphAction.cxx ) target_link_libraries( gmstatistics PRIVATE GeoModelCore::GeoModelKernel @@ -20,3 +24,8 @@ install( TARGETS gmstatistics EXPORT ${PROJECT_NAME}-export RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) + + +install( FILES ${MANPAGES} + DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 + COMPONENT Runtime ) diff --git a/GeoModelTools/GMSTATISTICS/man/man1/gmstatistics.1 b/GeoModelTools/GMSTATISTICS/man/man1/gmstatistics.1 new file mode 100644 index 0000000000000000000000000000000000000000..c9bdb8b85865d43091159776e362de18f8765c84 --- /dev/null +++ b/GeoModelTools/GMSTATISTICS/man/man1/gmstatistics.1 @@ -0,0 +1,45 @@ +.\" Manpage for gmstatistics +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "gmex man page" +.SH NAME +gmstatistics \- Print memory consumption and other information about GeoModel plugins +.SH SYNOPSIS +gmstatistics [Plugin1] [Plugin2] ... -o outputFile [-v] [-g Repository] +.SH DESCRIPTION +gmstatistics takes one or more plugins which construct the GeoModel description and prints an informative message about resource usage. The information available depends on the platform, since different platforms provide different system calls for resource monitoring. On linux, the program reports the total memory as well as the memory consumed exclusively by the geometry data (ie. the geomodel tree). On the macintosh, a detailed report containing the number of allocated objects by class and the total memory footprint of the allocated objects is also printed. With the -p option, a dump of the geometry tree is also printed. + +gmstatistics only works with plugins, it does not accept input files in SQLite format. + +.SH OPTIONS + +.TP +.BI \-p +Prints the geometry tree. + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmex(1), sqlitebrowser(1), gmcat (1) + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite +. + +.SH BUGS +There are no known bugs. +.SH AUTHORS +Primary authors are +.MT riccardomariabianchi@\:pitt\:.edu +Riccardo Maria Bianchi +.ME , +.MT boudreau@\:pitt\:.edu +Joe Boudreau +.ME +and +.MT Vakhtang.Tsulaia@\:cern\:.ch +Vakho Tsulaia +.ME + diff --git a/GeoModelTools/GeoModelXML/GMXPlugin/CMakeLists.txt b/GeoModelTools/GeoModelXML/GMXPlugin/CMakeLists.txt index b3b922ecc2c5ea7eab9f5269cc76c9364559ce73..1792afc76e1eda961eb3ac89743113fd08e891d7 100644 --- a/GeoModelTools/GeoModelXML/GMXPlugin/CMakeLists.txt +++ b/GeoModelTools/GeoModelXML/GMXPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -6,10 +6,6 @@ file( GLOB SOURCES src/*.cxx ) # Create the library. add_library( GMXPlugin SHARED ${SOURCES} ) target_link_libraries( GMXPlugin PUBLIC GeoModelCore::GeoModelKernel XercesC::XercesC GeoModelXml ) -target_include_directories( GMXPlugin PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) -source_group( "GMXPlugin" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GMXPlugin PROPERTIES VERSION ${PROJECT_VERSION} @@ -33,12 +29,3 @@ install(TARGETS GMXPlugin COMPONENT Development INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - -install( FILES ${HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GMXPlugin - COMPONENT Development ) - -# set ( PLUGIN_NAME "GMXPlugin.so" ) -# ADD_CUSTOM_TARGET( GMX_plugin ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ${GMXPlugin} ${PLUGIN_NAME} ) - - diff --git a/GeoModelTools/GeoModelXML/GMXPlugin/src/GMXPlugin.cxx b/GeoModelTools/GeoModelXML/GMXPlugin/src/GMXPlugin.cxx index 2c4e93db39a8611dec8bb7dd3ffd8230e03b848b..df8b57edbcb11f8243f8527ac632406f0e0aaa1a 100644 --- a/GeoModelTools/GeoModelXML/GMXPlugin/src/GMXPlugin.cxx +++ b/GeoModelTools/GeoModelXML/GMXPlugin/src/GMXPlugin.cxx @@ -6,7 +6,7 @@ #include "GeoModelHelpers/StringUtils.h" #include "GeoModelHelpers/FileUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "GeoModelKernel/GeoPhysVol.h" #include "GeoModelXml/GmxInterface.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/CMakeLists.txt b/GeoModelTools/GeoModelXML/GeoModelXml/CMakeLists.txt index 8e9375ae0f4dc9b84b49efe26f725828f165c63b..04e036d519935202088717d42ba80c30f108df97 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/CMakeLists.txt +++ b/GeoModelTools/GeoModelXML/GeoModelXml/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -14,9 +14,9 @@ find_package( ZLIB REQUIRED ) add_library( GeoModelXml SHARED ${HEADERS} ${SOURCES} ) # link libraries target_link_libraries( GeoModelXml PUBLIC GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers GeoModelTools::ExpressionEvaluator XercesC::XercesC PRIVATE ZLIB::ZLIB ) -target_include_directories( GeoModelXml PUBLIC +target_include_directories( GeoModelXml PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GeoModelXml" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) set_target_properties( GeoModelXml PROPERTIES diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/ElementProcessor.h b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/ElementProcessor.h index e295b4c7c244101821cffc386cb7b0c58a053d7a..7128cdbe4aac22750d945c72cb2712fec7f6bc56 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/ElementProcessor.h +++ b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/ElementProcessor.h @@ -22,6 +22,7 @@ class ElementProcessor: public GeoDeDuplicator { public: ElementProcessor() = default; + virtual ~ElementProcessor() = default; virtual void process(const xercesc::DOMElement *element, GmxUtil &gmxUtil, GeoNodeList &toBeAdded); }; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h index c14562e5a153ba24134759e110fad815e428a4f4..bcbb3f5d27ccd8560e32396350a76c0c748a6b3d 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h +++ b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxInterface.h @@ -21,7 +21,7 @@ #include <variant> #include "GeoModelKernel/GeoVFullPhysVol.h" #include "GeoModelKernel/GeoAlignableTransform.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" class GeoPublisher; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxUtil.h b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxUtil.h index e149501c677c4f71a229f77a360f80f347a525c8..9e44cd9d99e2484f3771f9798c9ed44ad813060f 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxUtil.h +++ b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/GmxUtil.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef GEO_MODEL_XML_GMXUTIL_H @@ -54,6 +54,8 @@ #include "GeoModelXml/shape/MakeSubtraction.h" #include "GeoModelXml/shape/MakeShaperef.h" #include "GeoModelXml/shape/AddPlane.h" +#include "GeoModelXml/shape/MakeShapeShift.h" + #include "GeoModelXml/PositionIndex.h" //#include "GeoModelXml/SensitiveId.h" @@ -114,6 +116,7 @@ public: MakeUnion onion; // union is reserved MakeSubtraction subtraction; MakeShaperef shaperef; + MakeShapeShift shapeshift; MakeTransformation transformation; MakeTransformationref transformationref; // diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/shape/MakeShapeShift.h b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/shape/MakeShapeShift.h new file mode 100644 index 0000000000000000000000000000000000000000..c13c214c730b63c58e0f70a3f08d1313cd142d11 --- /dev/null +++ b/GeoModelTools/GeoModelXML/GeoModelXml/GeoModelXml/shape/MakeShapeShift.h @@ -0,0 +1,28 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef GEO_MODEL_XML_MAKE_SHAPESHIFT_H +#define GEO_MODEL_XML_MAKE_SHAPESHIFT_H +#include <xercesc/util/XercesDefs.hpp> + +#include "GeoModelXml/Element2GeoItem.h" +// +// Create and return a HepRotation3d. Caller must delete it. +// + +XERCES_CPP_NAMESPACE_BEGIN +class DOMElement; +XERCES_CPP_NAMESPACE_END + + + +class GmxUtil; + +class MakeShapeShift: public Element2GeoItem { +public: + MakeShapeShift() = default; + virtual GeoIntrusivePtr<RCBase> make(const xercesc::DOMElement *element, GmxUtil &gmxUtil) const override; +}; + +#endif // MAKE_ROTATION_H diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/data/geomodel_v0.dtd b/GeoModelTools/GeoModelXML/GeoModelXml/data/geomodel_v0.dtd index dd3443183937b493945eb4d9e777814864e709fb..90bb859d8269990966d7307ba1bf640600ffc7b1 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/data/geomodel_v0.dtd +++ b/GeoModelTools/GeoModelXML/GeoModelXml/data/geomodel_v0.dtd @@ -65,7 +65,7 @@ <!ELEMENT addindex EMPTY> <!ATTLIST addindex name ID #REQUIRED> - <!ELEMENT shapes ((box|cons|generictrap|para|pcon|pgon|trap|tube|tubs|trd|intersection|subtraction|union|simplepolygonbrep|ellipticaltube|twistedtrap|torus)+)> + <!ELEMENT shapes ((box|cons|generictrap|para|pcon|pgon|trap|tube|tubs|trd|intersection|subtraction|union|simplepolygonbrep|ellipticaltube|twistedtrap|torus|shapeshift)+)> <!-- All shapes allowed in GeoModel manual. Same name, parameters, parameter order, but always lower case --> <!ELEMENT box EMPTY> @@ -168,6 +168,9 @@ <!ELEMENT intersection (shaperef, (transformation|transformationref), shaperef)> <!ATTLIST intersection name ID #REQUIRED> + <!ELEMENT shapeshift ( (shaperef|transformation|transformationref)+)> + <!ATTLIST shapeshift name ID #REQUIRED> + <!ELEMENT subtraction (shaperef, (transformation|transformationref), shaperef)> <!ATTLIST subtraction name ID #REQUIRED> @@ -268,7 +271,7 @@ <!ATTLIST assemblyref ref IDREF #REQUIRED zeroid (true|false) "false"> - <!ELEMENT multicopy (transformation, (transform|logvolref|assemblyref))> + <!ELEMENT multicopy ( (transformation|transformationref), (transform|logvolref|assemblyref))> <!-- Removed logvol and assembly from multicopy content. There is no particular reason why they shouldn't be allowed there. But in practice one uses refs, and forbidding them simplifies coding the index stuff. If you need them, put them back. Got rid of transformref; never used. --> diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/AssemblyrefProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/AssemblyrefProcessor.cxx index 455526fcd4eca5a6730a7552016e6163c757adeb..399751f213a37147ee73343a3ed8acedc01dfe20 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/AssemblyrefProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/AssemblyrefProcessor.cxx @@ -7,7 +7,7 @@ // #include "OutputDirector.h" #include "GeoModelXml/AssemblyrefProcessor.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XercesDefs.hpp" #include <xercesc/dom/DOM.hpp> diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/Element2GeoItem.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/Element2GeoItem.cxx index 09c48a79f4c58ee1bd2b3c6fc25680311c4ac624..e780aac181bb9f70f5b98e1ef4bf1bbedf557d74 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/Element2GeoItem.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/Element2GeoItem.cxx @@ -12,7 +12,7 @@ #include "GeoModelXml/GmxUtil.h" #include "GeoModelKernel/RCBase.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" using namespace std; using namespace xercesc; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx index faba526488e15cc10da6faf13f814a0f511d001b..875861a56b30f6290ec3cc7547eb247a8abb322c 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx @@ -29,7 +29,7 @@ #include "GeoModelXml/GmxInterface.h" #include "GeoModelXml/createdomdocument.h" #include "GeoModelHelpers/MaterialManager.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" using namespace std; using namespace xercesc; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/GmxUtil.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/GmxUtil.cxx index f9e5ff1d31d488c5b1b92d1d5126818fc935449d..5e173dca07eb58df61934b03cefffdcad64eb149 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/GmxUtil.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/GmxUtil.cxx @@ -11,7 +11,7 @@ #include "GeoModelKernel/GeoBox.h" #include "GeoModelKernel/GeoLogVol.h" #include "GeoModelXml/GmxInterface.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include <cstdlib> #include <sstream> @@ -85,7 +85,8 @@ GmxUtil::GmxUtil(GmxInterface &gmxInterface): geoItemRegistry.enregister("shaperef", &tagHandler.shaperef); geoItemRegistry.enregister("transformation", &tagHandler.transformation); geoItemRegistry.enregister("transformationref", &tagHandler.transformationref); - + geoItemRegistry.enregister("shapeshift", &tagHandler.shapeshift); + tagHandler.addplane.gmxUtil=this; } diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/LogvolProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/LogvolProcessor.cxx index bd4850c4131f4f35eabb1ab4b2408b5ca7dc4f06..8638d8794b97c7fac71807f571d0f1882025c21e 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/LogvolProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/LogvolProcessor.cxx @@ -35,7 +35,7 @@ #include "GeoModelXml/GeoNodeList.h" #include "xercesc/util/XMLString.hpp" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" // using namespace CLHEP; using namespace std; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeIntersection.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeIntersection.cxx index d047d0ea30eb7b95ee2e6d0251ea87d8210b05f7..310772468b5f6a0822ea4bad313ebab585a0ea3d 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeIntersection.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeIntersection.cxx @@ -14,7 +14,7 @@ #include "GeoModelHelpers/TransformSorter.h" #include "GeoModelHelpers/GeoShapeUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeMaterial.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeMaterial.cxx index 32fb289568d8b38ea26eb92ce1375ec392d414e9..1ae9b3f6d5574122dc5689f614946ffac8f90558 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeMaterial.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeMaterial.cxx @@ -11,7 +11,7 @@ #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" #include "GeoModelKernel/Units.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" using namespace xercesc; using namespace std; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakePcon.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakePcon.cxx index e1129d4c948fbed34d46626e9e056928fbbe982d..c23c58dba85d255e9dd746e93525753a0a0d5ffa 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakePcon.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakePcon.cxx @@ -8,7 +8,7 @@ #include <xercesc/dom/DOM.hpp> #include "GeoModelKernel/GeoPcon.h" #include "GeoModelHelpers/GeoShapeUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeShapeShift.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeShapeShift.cxx new file mode 100644 index 0000000000000000000000000000000000000000..973c274616e2841666f90085cc4e6a37344fd05e --- /dev/null +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeShapeShift.cxx @@ -0,0 +1,62 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ +#include "GeoModelXml/shape/MakeShapeShift.h" + +#include "OutputDirector.h" +#include <string> +#include <xercesc/dom/DOM.hpp> + +#include "GeoModelKernel/GeoShapeShift.h" +#include "GeoModelKernel/GeoTransform.h" + +#include "xercesc/util/XMLString.hpp" +#include "GeoModelXml/GmxUtil.h" + +#include "GeoModelHelpers/TransformSorter.h" +#include "GeoModelKernel/throwExcept.h" +#include "GeoModelHelpers/GeoShapeUtils.h" + +#include "xercesc/util/XMLString.hpp" +#include "GeoModelXml/GmxUtil.h" + +using namespace xercesc; + +GeoIntrusivePtr<RCBase> MakeShapeShift::make(const xercesc::DOMElement *element, GmxUtil &gmxUtil) const { + + unsigned int elementIndex = 0; + GeoShape* shape{nullptr}; + GeoTrf::Transform3D hepXf{GeoTrf::Transform3D::Identity()}; + for (DOMNode *child = element->getFirstChild(); child != nullptr; child = child->getNextSibling()) { + if (child->getNodeType() != DOMNode::ELEMENT_NODE) { + continue; + } + switch (elementIndex) { + case 0: { // First element is first shaperef + shape = dynamic_pointer_cast<GeoShape>(gmxUtil.tagHandler.shaperef.process(dynamic_cast<DOMElement*> (child), gmxUtil)); + break; + } case 1: { // Second element is transformation or transformationref + char *toRelease = XMLString::transcode(child->getNodeName()); + std::string nodeName{toRelease}; + XMLString::release(&toRelease); + const GeoTransform *geoXf = (nodeName == "transformation") + ? dynamic_pointer_cast<const GeoTransform>( gmxUtil.tagHandler.transformation.process(dynamic_cast<DOMElement *>(child), gmxUtil)) + : dynamic_pointer_cast<const GeoTransform>( gmxUtil.tagHandler.transformationref.process(dynamic_cast<DOMElement *>(child), gmxUtil)); + hepXf = geoXf->getTransform(); + break; + } default: // More than 3 elements? + THROW_EXCEPTION("Only transofrmation & geoshaperef are accepted"); + } + ++elementIndex; + } + if (!shape) { + THROW_EXCEPTION("No shape has been given"); + } + + static const GeoTrf::TransformSorter sorter{}; + if (!sorter.compare(GeoTrf::Transform3D::Identity(), hepXf)) { + return shape; + } + return const_pointer_cast(cacheShape(make_intrusive<GeoShapeShift>(shape, hepXf))); +} + diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSimplePolygonBrep.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSimplePolygonBrep.cxx index 7f0411cfff83a036241e1463cdc146888e689662..c2a8bc71367757f958ed11bc18267152af1dafe4 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSimplePolygonBrep.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSimplePolygonBrep.cxx @@ -10,7 +10,7 @@ #include "GeoModelXml/shape/MakeSimplePolygonBrep.h" #include "GeoModelKernel/GeoSimplePolygonBrep.h" #include <xercesc/dom/DOM.hpp> -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSubtraction.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSubtraction.cxx index 9fa649711cab302fb014c05c60676583fcabd92e..144378430f23c7344118b29c59fed9c5973499dc 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSubtraction.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeSubtraction.cxx @@ -11,7 +11,7 @@ #include "GeoModelKernel/GeoShapeSubtraction.h" #include "GeoModelKernel/GeoShapeShift.h" #include "GeoModelKernel/GeoTransform.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeUnion.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeUnion.cxx index 6ad32a0c25185a39557c43dec4aa65d147cebf61..459fb00983ed9087271118ba6a0a0f73569c0b2e 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeUnion.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MakeUnion.cxx @@ -8,7 +8,7 @@ #include <xercesc/dom/DOM.hpp> #include "GeoModelKernel/GeoShapeUnion.h" #include "GeoModelKernel/GeoShapeShift.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" #include "GeoModelXml/GmxUtil.h" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx index 4401360d1741b32446c385779983cafa2ace29e5..127732a4f64d1c34ac3c8746136696b3a0a70310 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/MulticopyProcessor.cxx @@ -37,7 +37,7 @@ #include "GeoModelXml/ProcessorRegistry.h" #include "GeoModelXml/GmxUtil.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" using namespace xercesc; using namespace std; diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/ReplicaZProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/ReplicaZProcessor.cxx index 5c493bbbd06e369e14dc5ac35588f6cac413575e..840fb2f46162cf5e3f968012e5e17b1fc8c74699 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/ReplicaZProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/ReplicaZProcessor.cxx @@ -19,7 +19,7 @@ #include "GeoModelKernel/GeoNameTag.h" #include "GeoModelKernel/GeoDefinitions.h" #include "GeoModelHelpers/StringUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "xercesc/util/XMLString.hpp" diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/TransformrefProcessor.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/TransformrefProcessor.cxx index a0e57980f2748fee4b76cb12398f5d5a41b55b39..38705480130fc4a09fb3d51c1f3c05857dec2ac2 100644 --- a/GeoModelTools/GeoModelXML/GeoModelXml/src/TransformrefProcessor.cxx +++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/TransformrefProcessor.cxx @@ -12,7 +12,7 @@ #include "GeoModelXml/GmxUtil.h" #include "GeoModelXml/GeoNodeList.h" #include "xercesc/util/XMLString.hpp" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" using namespace std; using namespace xercesc; diff --git a/GeoModelTools/GeoModelXMLDumper/CMakeLists.txt b/GeoModelTools/GeoModelXMLDumper/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7d6408c99f18dc7385b594d3820d907171409f8 --- /dev/null +++ b/GeoModelTools/GeoModelXMLDumper/CMakeLists.txt @@ -0,0 +1,63 @@ +# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + +# Find the header and source files. +file( GLOB SOURCES src/*.cxx ) +file( GLOB HEADERS GeoModelXMLDumper/*.h GeoModelXMLDumper/*.icc ) + +# Create the library. +add_library( GeoModelXMLDumper SHARED ${HEADERS} ${SOURCES} ) +target_link_libraries( GeoModelXMLDumper PUBLIC GeoModelCore::GeoModelKernel + GeoModelCore::GeoModelHelpers ) +target_include_directories( GeoModelXMLDumper PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) +source_group( "GeoModelXMLDumper" FILES ${HEADERS} ) +source_group( "src" FILES ${SOURCES} ) +set_target_properties( GeoModelXMLDumper PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} ) + +# Set up an alias with the same name that you would get by "finding" a pre-built +# version of the library. +add_library( GeoModelTools::GeoModelXMLDumper ALIAS GeoModelXMLDumper ) + +# Install the library. +install(TARGETS GeoModelXMLDumper + EXPORT ${PROJECT_NAME}-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT Runtime + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Runtime + NAMELINK_COMPONENT Development # Requires CMake 3.12 + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT Development + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelXMLDumper + COMPONENT Development + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install( FILES ${HEADERS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelXMLDumper + COMPONENT Development ) + + + +# Declare the package's executable. +add_executable( dumpGeoXML util/main.cxx) +target_link_libraries( dumpGeoXML PRIVATE GeoModelCore::GeoModelKernel + GeoModelCore::GeoModelHelpers + GeoModelIO::GeoModelRead + GeoModelTools::GeoModelXMLDumper) + +# Tweak how debug information should be attached to the executable, in Debug +# builds. +if( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND + "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) + target_compile_options( dumpGeoXML PRIVATE "-gdwarf-2" ) +endif() + +# Install the executable. +install( TARGETS dumpGeoXML + EXPORT ${PROJECT_NAME}-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT Runtime ) diff --git a/GeoModelTools/GeoModelXMLDumper/GeoModelXMLDumper/GeoXMLDumper.h b/GeoModelTools/GeoModelXMLDumper/GeoModelXMLDumper/GeoXMLDumper.h new file mode 100644 index 0000000000000000000000000000000000000000..f5e3dd0bf95d9683552d41375fe8676486f9afdf --- /dev/null +++ b/GeoModelTools/GeoModelXMLDumper/GeoModelXMLDumper/GeoXMLDumper.h @@ -0,0 +1,93 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef GEOMODELXMLDUMPER_GEOXMLDUMPER_H +#define GEOMODELXMLDUMPER_GEOXMLDUMPER_H + +#include "GeoModelKernel/GeoVPhysVol.h" +#include "GeoModelKernel/GeoTransform.h" + +#include "GeoModelKernel/GeoIntrusivePtr.h" +#include "GeoModelHelpers/GeoShapeSorter.h" +#include "GeoModelHelpers/GeoPhysVolSorter.h" +#include "GeoModelHelpers/TransformSorter.h" + + +#include <string> +#include <map> + +/** @brief: The GeoXmlDumper class traverses the GeoModel tree and translates its content + * into plain GeoModelXML + * +*/ + +class GeoXMLDumper { +public: + GeoXMLDumper(const std::string& outDir, + const std::string& systemName, + const std::string& xmlLayoutFile); + + bool publishWorld(PVConstLink world); + + + + +private: + std::string m_outDir{}; + std::string m_systemName{}; + std::string m_xmlLayoutFile{}; + + void countVolume(PVConstLink volume); + +private: + /// @brief + /// @param outStream + /// @param physVol + /// @param volName + /// @param indentation + /// @return + std::string publishPhysVol(std::ostream& outStream, + PVConstLink physVol, + const std::string& volName, + unsigned int indentation = 0); + + std::string publishShape(std::ostream& shapeStream, + GeoIntrusivePtr<const GeoShape> shape, + const std::string& shapeName); + + /// @brief Creates the actual header file of the GeoModel description + /// @param ostr + using topVolWithPathList = std::vector<std::pair<std::string, std::string>>; + void dumpGeoModelHeader(std::ostream& ostr, + const topVolWithPathList& pubVolsWithFiles) const; + + void writeMaterials(std::ostream& ostr, + unsigned int indentation = 0) const; + + + void dumpTransform(std::ostream& ostr, + const GeoTrf::Transform3D& trans, + const std::string& refName, + unsigned int indentation = 0); + + std::string uniqueNameTag(std::string nameTag, + const std::string_view idToken); + + using shapeMap = std::map<GeoIntrusivePtr<const GeoShape>, std::string, GeoShapeSorter>; + using physVolMap = std::map<PVConstLink, std::string, GeoPhysVolSorter>; + using transformMap = std::map<GeoTrf::Transform3D, std::string, GeoTrf::TransformSorter>; + + + using physVolCounter = std::map<PVConstLink, unsigned int, GeoPhysVolSorter>; + using nameTagCounter = std::map<std::string, unsigned int>; + + physVolMap m_physVolNameTags{}; + shapeMap m_shapeNameTags{}; + transformMap m_transformNameTags{}; + + nameTagCounter m_nameTagCounts{}; + physVolCounter m_physVolCounts{}; + +}; + +#endif \ No newline at end of file diff --git a/GeoModelTools/GeoModelXMLDumper/src/GeoXMLDumper.cxx b/GeoModelTools/GeoModelXMLDumper/src/GeoXMLDumper.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6d220d674ac43c8425f3bab96c6d9db366e33978 --- /dev/null +++ b/GeoModelTools/GeoModelXMLDumper/src/GeoXMLDumper.cxx @@ -0,0 +1,539 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ +#include "GeoModelXMLDumper/GeoXMLDumper.h" +#include "GeoModelKernel/Units.h" +#include "GeoModelKernel/GeoVolumeCursor.h" + +#include "GeoModelKernel/GeoShapeUnion.h" +#include "GeoModelKernel/GeoShapeSubtraction.h" +#include "GeoModelKernel/GeoShapeIntersection.h" +#include "GeoModelKernel/GeoShapeShift.h" + + +#include "GeoModelKernel/GeoCons.h" +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoEllipticalTube.h" +#include "GeoModelKernel/GeoGenericTrap.h" +#include "GeoModelKernel/GeoPara.h" +#include "GeoModelKernel/GeoPcon.h" +#include "GeoModelKernel/GeoPgon.h" +#include "GeoModelKernel/GeoTorus.h" +#include "GeoModelKernel/GeoTrap.h" +#include "GeoModelKernel/GeoTrd.h" +#include "GeoModelKernel/GeoTube.h" +#include "GeoModelKernel/GeoTubs.h" +#include "GeoModelKernel/GeoSimplePolygonBrep.h" + +#include "GeoModelHelpers/GeoShapeUtils.h" +#include "GeoModelHelpers/getChildNodesWithTrf.h" +#include "GeoModelKernel/throwExcept.h" +#include "GeoModelHelpers/TransformToStringConverter.h" +#include "GeoModelHelpers/StringUtils.h" +#include "GeoModelHelpers/FileUtils.h" + +#include <iomanip> +#include <iostream> +#include <limits> +#include <fstream> +#include <string_view> +#include <functional> + + +using namespace GeoStrUtils; +using namespace GeoFileUtils; +namespace { + constexpr unsigned int stdIndent = 4; + constexpr double transTolerance = 0.1 * GeoModelKernelUnits::micrometer; + constexpr double toDeg = 1./ GeoModelKernelUnits::deg; + + std::string shapeRefTag(const std::string& shapeName, unsigned int nWhite) { + std::stringstream sstr{}; + sstr<<whiteSpaces(nWhite)<<"<shaperef ref=\""<<shapeName<<"\" />"; + return sstr.str(); + } + + std::string fileNameBody(const std::string_view path) { + const unsigned slashPos = path.rfind("/") + 1; + return std::string{path.substr(slashPos, path.rfind(".") - slashPos)}; + } + static const GeoTrf::TransformSorter transformSorter{}; +} + + +GeoXMLDumper::GeoXMLDumper(const std::string& outDir, + const std::string& systemName, + const std::string& xmlLayoutFile): + m_outDir{outDir}, + m_systemName{systemName}, + m_xmlLayoutFile{xmlLayoutFile} { + if (m_outDir.size() && m_outDir[m_outDir.size() -1] != '/') { + m_outDir+="/"; + } +} + +void GeoXMLDumper::countVolume(PVConstLink volume){ + ++(m_physVolCounts[volume]); + GeoVolumeCursor cursor{volume}; + while (!cursor.atEnd()) { + countVolume(cursor.getVolume()); + cursor.next(); + } +} + +bool GeoXMLDumper::publishWorld(PVConstLink world) { + if (m_outDir.empty()) { + std::cerr<<"Please define an output directory "<<std::endl; + return false; + } + /// Count how many distinct volumes are in the world and also at how many nodes each volume appears + std::cout<<"Traverse the GeoModel tree to count the different physical volumes "<<std::endl; + countVolume(world); + { + unsigned int counts{0}; + for (const auto& [vol, c] : m_physVolCounts) counts+=c; + std::cout<<"Found in total "<<m_physVolCounts.size()<<" different volumes used in "<<counts<<" nodes."<<std::endl; + } + /// If the world only has one volume get to its child + while (world->getNChildVols() == 1) { + world = world->getChildVol(0); + } + + GeoVolumeCursor cursor{world}; + + topVolWithPathList publishedTops{}; + while (!cursor.atEnd()) { + PVConstLink worldNode{cursor.getVolume()}; + const std::string out_xmlDir = m_outDir + "volumes/"; + if (!mkdir(out_xmlDir)) { + std::cerr<<"Failed to create directory "<<out_xmlDir<<std::endl; + return false; + } + const std::string out_xmlFile = out_xmlDir + + replaceExpInString(cursor.getName()," ", "_") + ".xml"; + + std::ofstream outFile{out_xmlFile}; + if (!outFile.good()) { + std::cerr<<"Failed to open "<<out_xmlFile<<std::endl; + return false; + } + const std::string pubVolume{publishPhysVol(outFile, cursor.getVolume(), cursor.getName())}; + publishedTops.emplace_back(std::make_pair(out_xmlFile, pubVolume)); + cursor.next(); + } + + const std::string out_xmlFile = m_outDir+ m_systemName +".xml"; + + std::ofstream outFile{out_xmlFile}; + if (!outFile.good()) { + std::cerr<<"Failed to open "<<out_xmlFile<<std::endl; + return false; + } + dumpGeoModelHeader(outFile, publishedTops); + return true; +} +std::string GeoXMLDumper::uniqueNameTag(std::string nameTag, + const std::string_view idToken) { + nameTag = replaceExpInString(nameTag, " ", "_"); + unsigned int& nameTagCounts{m_nameTagCounts[nameTag]}; + if (nameTagCounts> 0) { + nameTag += std::string{idToken}+"No"+std::to_string(nameTagCounts); + } + ++nameTagCounts; + return nameTag; +} +std::string GeoXMLDumper::publishPhysVol(std::ostream& outStream, + PVConstLink physVol, + const std::string& volName, + unsigned int indentation) { + + physVolMap::const_iterator itr = m_physVolNameTags.find(physVol); + if (itr != m_physVolNameTags.end()) return itr->second; + + std::string nameTag{volName}; + + std::stringstream shapeStream{}, childStream{}; + + /// Retrieve the children together with their transformations + std::vector<GeoChildNodeWithTrf> children = getChildrenWithRef(physVol, true); + for (const GeoChildNodeWithTrf& child : children) { + /// Dump the transformation + + unsigned int childIndent = indentation + stdIndent; + + const bool dumpTrf{child.isAlignable || transformSorter.compare(GeoTrf::Transform3D::Identity(), child.transform)}; + + if (dumpTrf) { + childStream<<whiteSpaces(indentation + stdIndent) + <<"<transform name=\""<<uniqueNameTag(child.nodeName, "VolTrf")<<"\" "; + if (child.isAlignable)childStream<<"alignable=\"true\" "; + childStream<<">"<<std::endl; + + childIndent += stdIndent; + dumpTransform(childStream, child.transform, child.nodeName, childIndent); + } + if (child.nCopies > 1) { + childStream<<whiteSpaces(childIndent)<<"<assembly name=\"" + <<uniqueNameTag(child.nodeName, "Assembly")<<"\">"<<std::endl; + childIndent +=stdIndent; + childStream<<whiteSpaces(childIndent)<<"<multicopy n=\""<<child.nCopies<<"\" " + <<"name=\""<<uniqueNameTag(child.nodeName, "MultiCopy")<<"\">"<<std::endl; + childIndent+=stdIndent; + dumpTransform(childStream, child.inductionRule, child.nodeName, childIndent); + } + childStream<<whiteSpaces(childIndent)<<"<logvolref ref=\""<<publishPhysVol(outStream, child.volume, child.nodeName)<<"\" />"<<std::endl; + if (child.nCopies > 1) { + childIndent-=stdIndent; + childStream<<whiteSpaces(childIndent)<<"</multicopy>"<<std::endl; + childIndent-=stdIndent; + childStream<<whiteSpaces(childIndent)<<"</assembly>"<<std::endl; + } + if (dumpTrf) { + childStream<<whiteSpaces(childIndent - stdIndent)<<"</transform>"<<std::endl; + } + childStream<<std::endl; + } + + const std::string shapeName = publishShape(shapeStream, physVol->getLogVol()->getShape(), nameTag); + const std::string pubShapes{shapeStream.str()}; + if (pubShapes.size()) { + outStream<<"<shapes>"<<std::endl; + outStream<<pubShapes; + outStream<<"</shapes>"<<std::endl; + } + nameTag = uniqueNameTag(nameTag, "logVol"); + + outStream<<whiteSpaces(indentation)<<"<logvol name=\""<<nameTag<<"\" "; + const std::string matName = replaceExpInString(physVol->getLogVol()->getMaterial()->getName(), "::", "__dColon__"); + + outStream<<"shape=\""<<shapeName<<"\" material=\""<<matName<<"\" "; + if (children.empty()) { + outStream<<"/>"<<std::endl; + } else { + outStream<<">"<<std::endl; + outStream<<childStream.str(); + outStream<<whiteSpaces(indentation)<<"</logvol>"<<std::endl; + } + outStream<<std::endl<<std::endl; + + auto insert_itr = m_physVolNameTags.insert(std::make_pair(physVol, nameTag)); + if (!insert_itr.second) { + THROW_EXCEPTION("Failed to cache physical volume "<<physVol.get()<<" with shape "<<printGeoShape(physVol->getLogVol()->getShape()) + <<" as "<<nameTag<<std::endl<<"The volume "<<insert_itr.first->first.get()<<" with shape " + <<printGeoShape(insert_itr.first->first->getLogVol()->getShape())<<" as "<<insert_itr.first->second + <<" is blocking the way"); + } + + return insert_itr.first->second; +} + +std::string GeoXMLDumper::publishShape(std::ostream& shapeStream, + GeoIntrusivePtr<const GeoShape> shape, + const std::string& shapeName) { + + /// The Volume has been already published before refer to it + shapeMap::const_iterator itr = m_shapeNameTags.find(shape); + if (itr != m_shapeNameTags.end()) return itr->second; + + + std::pair<const GeoShape*, const GeoShape*> operands = getOps(shape); + /// The shape is a boolean volume (GeoShapeUnion, Subtraction, Intersection) + if (operands.first && operands.second) { + publishShape(shapeStream, operands.first, shapeName); + publishShape(shapeStream, operands.second, shapeName); + } + /// The shape is a GeoShapeShift + else if (operands.first) { + /// In fact there might be several Shape shifts in a row. Collapse them into a single shift + /// and publish the underlying shape + operands = getOps(compressShift(shape)); + publishShape(shapeStream, operands.first, shapeName); + } + + /// Create a unique name tag + const std::string nameTag{uniqueNameTag(shapeName.size() ? shapeName : shape->type(), "Shape")}; + /// Register the shape + const auto insert_itr = m_shapeNameTags.insert(std::make_pair(shape, nameTag)); + if (!insert_itr.second) { + THROW_EXCEPTION("The insertion of shape "<<printGeoShape(shape)<<" as "<<nameTag<<" failed."<<std::endl<< + "The shape "<<printGeoShape(insert_itr.first->first)<<" as "<<insert_itr.first->second + << " has been added before. "); + } + + auto dumpParameter = [&shapeStream](const std::string_view parName, + const double value, + bool isAngle = false) { + + shapeStream<<parName<<"=\""; + if (isAngle) { + shapeStream<<value*toDeg<<"*deg\" "; + } else { + shapeStream<<value<<"\" "; + } + }; + + constexpr unsigned int indentation = stdIndent; + const unsigned int shapeID = shape->typeID(); + shapeStream<<whiteSpaces(indentation); + if (shapeID == GeoShapeUnion::getClassTypeID() || + shapeID == GeoShapeSubtraction::getClassTypeID() || + shapeID == GeoShapeIntersection::getClassTypeID()) { + + const std::string xmlField = shapeID == GeoShapeUnion::getClassTypeID() ? "union" : + shapeID == GeoShapeSubtraction::getClassTypeID()? "subtraction" : "intersection"; + shapeStream<<"<"<<xmlField<<" name=\""<<nameTag<<"\" >"<<std::endl; + shapeStream<<shapeRefTag(publishShape(shapeStream, operands.first, shapeName), indentation + stdIndent)<<std::endl; + if (operands.second->typeID() == GeoShapeShift::getClassTypeID()) { + GeoIntrusivePtr<const GeoShape> collapsedShift = compressShift(operands.second); + const GeoShapeShift* shift = dynamic_cast<const GeoShapeShift*>(collapsedShift.get()); + dumpTransform(shapeStream, shift->getX(), shapeName, indentation + stdIndent); + shapeStream<<shapeRefTag(publishShape(shapeStream, shift->getOp(), shapeName), indentation + stdIndent)<<std::endl; + } else{ + shapeStream<<shapeRefTag(publishShape(shapeStream, operands.second, shapeName), indentation + stdIndent)<<std::endl; + } + shapeStream<<whiteSpaces(indentation)<<"</"<<xmlField<<">"<<std::endl; + } else if (shapeID == GeoShapeShift::getClassTypeID()) { + shapeStream<<"<shapeshift name=\""<<nameTag<<"\" >"<<std::endl; + GeoIntrusivePtr<const GeoShape> collapsedShift = compressShift(shape); + const GeoShapeShift* shift = dynamic_cast<const GeoShapeShift*>(collapsedShift.get()); + dumpTransform(shapeStream, shift->getX(), shapeName, indentation + stdIndent); + shapeStream<<shapeRefTag(publishShape(shapeStream, operands.first, shapeName), + indentation + stdIndent)<<std::endl; + shapeStream<<whiteSpaces(indentation)<<"</shapeshift>"<<std::endl; + + } else if (shapeID == GeoBox::getClassTypeID()) { + shapeStream<<"<box name=\""<<nameTag<<"\" "; + const GeoBox* box = dynamic_cast<const GeoBox*>(shape.get()); + dumpParameter("xhalflength", box->getXHalfLength()); + dumpParameter("yhalflength", box->getYHalfLength()); + dumpParameter("zhalflength", box->getZHalfLength()); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoCons::getClassTypeID()) { + const GeoCons* cons = static_cast<const GeoCons*>(shape.get()); + shapeStream<<"<cons name=\""<<nameTag<<"\" "; + dumpParameter("rmin1", cons->getRMin1()); + dumpParameter("rmin2", cons->getRMin2()); + dumpParameter("rmax1", cons->getRMax1()); + dumpParameter("rmax2", cons->getRMax2()); + dumpParameter("dz", cons->getDZ()); + dumpParameter("sphi", cons->getSPhi(), true); + dumpParameter("dphi", cons->getDPhi(), true); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoEllipticalTube::getClassTypeID()) { + const GeoEllipticalTube* tube = static_cast<const GeoEllipticalTube*>(shape.get()); + shapeStream<<"<ellipticaltube name=\""<<nameTag<<"\" "; + dumpParameter("xhalflength", tube->getXHalfLength()); + dumpParameter("yhalflength", tube->getYHalfLength()); + dumpParameter("zhalflength", tube->getZHalfLength()); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoGenericTrap::getClassTypeID()) { + const GeoGenericTrap* trap = static_cast<const GeoGenericTrap*>(shape.get()); + shapeStream<<"<generictrap name=\""<<nameTag<<"\" "; + dumpParameter("zhalflength", trap->getZHalfLength()); + for (unsigned int v = 0; v < std::min(8lu, trap->getVertices().size()); ++v){ + shapeStream<<"x"<<v<<"=\""<<trap->getVertices()[v].x()<<"\" "; + shapeStream<<"y"<<v<<"=\""<<trap->getVertices()[v].y()<<"\" "; + } + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoPara::getClassTypeID()) { + const GeoPara* para = dynamic_cast<const GeoPara*>(shape.get()); + shapeStream<<"<para name=\""<<nameTag<<"\" "; + dumpParameter("xhalflength", para->getXHalfLength()); + dumpParameter("yhalflength", para->getYHalfLength()); + dumpParameter("zhalflength", para->getZHalfLength()); + dumpParameter("alpha", para->getAlpha(), true); + dumpParameter("theta", para->getTheta(), true); + dumpParameter("phi", para->getPhi(), true); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoPcon::getClassTypeID()) { + const GeoPcon* pcon = dynamic_cast<const GeoPcon*>(shape.get()); + shapeStream<<"<pcon name=\""<<nameTag<<"\" "; + dumpParameter("sphi", pcon->getSPhi(), true); + dumpParameter("dphi", pcon->getSPhi(), true); + shapeStream<<">"<<std::endl; + for (unsigned int plane = 0 ; plane < pcon->getNPlanes(); ++plane) { + shapeStream<<whiteSpaces(indentation + stdIndent); + shapeStream<<"<addplane "; + dumpParameter("zplane", pcon->getZPlane(plane)); + dumpParameter("rminplane", pcon->getRMinPlane(plane)); + dumpParameter("rmaxplane", pcon->getRMaxPlane(plane)); + shapeStream<<"/>"<<std::endl; + } + shapeStream<<whiteSpaces(indentation)<<"</pcon>"<<std::endl; + } else if (shapeID == GeoPgon::getClassTypeID()) { + const GeoPgon* pgon = dynamic_cast<const GeoPgon*>(shape.get()); + shapeStream<<"<pgon name=\""<<nameTag<<"\" "; + dumpParameter("sphi", pgon->getSPhi(), true); + dumpParameter("dphi", pgon->getSPhi(), true); + dumpParameter("nsides", pgon->getNSides()); + for (unsigned int plane = 0 ; plane < pgon->getNPlanes(); ++plane) { + shapeStream<<whiteSpaces(indentation + stdIndent); + shapeStream<<"<plane "; + dumpParameter("zplane", pgon->getZPlane(plane)); + dumpParameter("rminplane", pgon->getRMinPlane(plane)); + dumpParameter("rmaxplane", pgon->getRMaxPlane(plane)); + shapeStream<<"/>"<<std::endl; + } + shapeStream<<whiteSpaces(indentation)<<"</pgon>"<<std::endl; + } else if (shapeID == GeoTorus::getClassTypeID()) { + shapeStream<<"<torus name=\""<<nameTag<<"\" "; + const GeoTorus* torus{dynamic_cast<const GeoTorus*>(shape.get())}; + dumpParameter("rmin", torus->getRMin()); + dumpParameter("rmax", torus->getRMax()); + dumpParameter("rtor", torus->getRTor()); + dumpParameter("sphi", torus->getSPhi(), true); + dumpParameter("dphi", torus->getDPhi(), true); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoTrap::getClassTypeID()) { + shapeStream<<"<trap name=\""<<nameTag<<"\" "; + const GeoTrap* trap{dynamic_cast<const GeoTrap*>(shape.get())}; + dumpParameter("zhalflength", trap->getZHalfLength()); + dumpParameter("theta", trap->getTheta(), true); + dumpParameter("phi", trap->getPhi(), true); + dumpParameter("dydzn", trap->getDydzn()); + dumpParameter("dxdyndzn", trap->getDxdyndzn()); + dumpParameter("dxdypdzn", trap->getDxdypdzn()); + dumpParameter("angleydzn", trap->getAngleydzn(), true); + dumpParameter("dydzp", trap->getDydzn()); + dumpParameter("dxdyndzp", trap->getDxdyndzp()); + dumpParameter("dxdypdzp", trap->getDxdypdzp()); + dumpParameter("angleydzp", trap->getAngleydzp()); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoTrd::getClassTypeID()) { + shapeStream<<"<trd name=\""<<nameTag<<"\" "; + const GeoTrd* trd = dynamic_cast<const GeoTrd*>(shape.get()); + dumpParameter("xhalflength1", trd->getXHalfLength1()); + dumpParameter("xhalflength2", trd->getXHalfLength2()); + dumpParameter("yhalflength1", trd->getYHalfLength1()); + dumpParameter("yhalflength2", trd->getYHalfLength2()); + dumpParameter("zhalflength", trd->getZHalfLength()); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoTube::getClassTypeID()) { + const GeoTube* tube = dynamic_cast<const GeoTube*>(shape.get()); + shapeStream<<"<tube name=\""<<nameTag<<"\" "; + dumpParameter("rmin", tube->getRMin()); + dumpParameter("rmax", tube->getRMax()); + dumpParameter("zhalflength", tube->getZHalfLength()); + shapeStream<<"/>"<<std::endl; + } else if (shapeID == GeoTubs::getClassTypeID()) { + const GeoTubs* tube = dynamic_cast<const GeoTubs*>(shape.get()); + shapeStream<<"<tubs name=\""<<nameTag<<"\" "; + dumpParameter("rmin", tube->getRMin()); + dumpParameter("rmax", tube->getRMax()); + dumpParameter("zhalflength", tube->getZHalfLength()); + dumpParameter("sphi", tube->getSPhi(), true); + dumpParameter("dphi", tube->getDPhi(), true); + shapeStream<<"/>"<<std::endl; + } else if(shapeID == GeoSimplePolygonBrep::getClassTypeID()) { + const GeoSimplePolygonBrep* brep = dynamic_cast<const GeoSimplePolygonBrep*>(shape.get()); + shapeStream<<"<simplepolygonbrep name=\""<<nameTag<<"\" "; + dumpParameter("zhalflength" , brep->getDZ()); + const unsigned int N = brep->getNVertices(); + shapeStream<<"xpoints=\""<<chainUp<double>(N, [brep](unsigned int v){return brep->getXVertex(v); }, ";")<<"\" "; + shapeStream<<"ypoints=\""<<chainUp<double>(N, [brep](unsigned int v){return brep->getYVertex(v); }, ";")<<"\" "; + shapeStream<<"/>"<<std::endl; + } else { + THROW_EXCEPTION("The shape "<<printGeoShape(shape)<<"is not implemented."); + } + return nameTag; +} + +void GeoXMLDumper::dumpTransform(std::ostream& ostr, + const GeoTrf::Transform3D& trans, + const std::string& name, + unsigned int indentation) { + + + transformMap::const_iterator itr = m_transformNameTags.find(trans); + if (!name.empty() && itr != m_transformNameTags.end()) { + ostr<<whiteSpaces(indentation)<<"<transformationref ref=\""<<itr->second<<"\" />"<<std::endl; + return; + } + + + std::stringstream transstr{}; + transstr<< std::setiosflags(std::ios::fixed) << std::setprecision(3); + std::string nameTag{replaceExpInString(name," ","_")}; + if (nameTag.size()) { + nameTag = uniqueNameTag(nameTag, "Trf"); + auto insert_itr = m_transformNameTags.insert(std::make_pair(trans, nameTag)); + if(!insert_itr.second) { + THROW_EXCEPTION("Failed to insert transformation "<<GeoTrf::toString(trans)); + } + } + transstr<<whiteSpaces(indentation)<<"<transformation "; + if (nameTag.size()) transstr<<"name=\""<<nameTag<<"\" "; + transstr<<">"<<std::endl; + + if (!transformSorter.compare(trans, GeoTrf::Transform3D::Identity())) { + transstr<<whiteSpaces(indentation + stdIndent) + <<"<translation x=\"0\" y=\"0\" z=\"0\" />"<<std::endl; + } else { + const GeoTrf::CoordEulerAngles angles = GeoTrf::getCoordRotationAngles(trans); + const GeoTrf::Vector3D translation = trans.translation(); + /// Dump the translation + if (translation.dot(translation) > transTolerance) { + transstr<<whiteSpaces(indentation +stdIndent)<<"<translation "; + if (std::abs(translation.x()) > transTolerance) { + transstr<<"x=\""<<translation.x()<<"\" "; + } + if (std::abs(translation.y()) > transTolerance) { + transstr<<"y=\""<<translation.y()<<"\" "; + } + if (std::abs(translation.z()) > transTolerance) { + transstr<<"z=\""<<translation.z()<<"\" "; + } + transstr<<"/>"<<std::endl; + } + transstr<<std::setiosflags(std::ios::fixed) << std::setprecision(2); + + + /// Dump the rotations + if (angles.alpha) { + transstr<<whiteSpaces(indentation+stdIndent)<<"<rotation xcos=\"1\" angle=\"" + <<angles.alpha*toDeg<<"*deg\" />"<<std::endl; + } + if (angles.beta) { + transstr<<whiteSpaces(indentation+stdIndent) + <<"<rotation ycos=\"1\" angle=\""<<angles.beta*toDeg<<"*deg\" />"<<std::endl; + } + if (angles.gamma) { + transstr<<whiteSpaces(indentation+stdIndent) + <<"<rotation zcos=\"1\" angle=\""<<angles.gamma*toDeg<<"*deg\" />"<<std::endl; + } + } + transstr<<whiteSpaces(indentation)<<"</transformation>"<<std::endl; + ostr<<transstr.str(); +} +void GeoXMLDumper::dumpGeoModelHeader(std::ostream& fileStream, + const topVolWithPathList& pubVolsWithFiles) const { + + fileStream<<"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"<<std::endl; + fileStream<<"<!DOCTYPE geomodel SYSTEM \""<<m_xmlLayoutFile<<"\" [ "<<std::endl; + + std::vector<std::string> entities{}; + for (const auto& [fileName, pubVolName] : pubVolsWithFiles) { + entities.emplace_back(fileNameBody(fileName)); + fileStream<<whiteSpaces(stdIndent)<<"<!ENTITY "<<entities.back(); + fileStream<<" SYSTEM \""<<fileName<<"\" >"<<std::endl; + } + + fileStream<<"]>"<<std::endl<<std::endl<<std::endl; + + fileStream<<"<geomodel name=\""<<m_systemName<<"\" version=\"1.0\" >"<<std::endl; + fileStream<<whiteSpaces(stdIndent)<<"<defines>"<<std::endl; + fileStream<<whiteSpaces(2*stdIndent)<<"<var name =\"deg\" value=\""<<GeoModelKernelUnits::deg<<"\" />"<<std::endl; + fileStream<<whiteSpaces(stdIndent)<<"</defines>"<<std::endl<<std::endl<<std::endl; + + for (const std::string& entity : entities) { + fileStream<<whiteSpaces(stdIndent)<<"&"<<entity<<";"<<std::endl; + } + fileStream<<std::endl<<std::endl; + + fileStream<<whiteSpaces(stdIndent)<<"<addbranch>"<<std::endl; + for (const auto& [fileName, pubVolName] : pubVolsWithFiles) { + fileStream<<whiteSpaces(2*stdIndent)<<"<logvolref ref=\""<<pubVolName<<"\" />"<<std::endl; + } + fileStream<<whiteSpaces(stdIndent)<<"</addbranch>"<<std::endl; + fileStream<<"</geomodel>"<<std::endl; +} \ No newline at end of file diff --git a/GeoModelTools/GeoModelXMLDumper/util/main.cxx b/GeoModelTools/GeoModelXMLDumper/util/main.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3b37523d430e3e785dbe8cf3a522bf60ce530f73 --- /dev/null +++ b/GeoModelTools/GeoModelXMLDumper/util/main.cxx @@ -0,0 +1,105 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ + +#include "GeoModelHelpers/defineWorld.h" +#include "GeoModelKernel/GeoGeometryPluginLoader.h" +#include "GeoModelXMLDumper/GeoXMLDumper.h" +#include "GeoModelHelpers/FileUtils.h" +#include "GeoModelHelpers/StringUtils.h" + + +#include <vector> +#include <string> +#include <iostream> + +using namespace GeoFileUtils; +using namespace GeoStrUtils; + + +int main(int argc, char ** argv) { + const std::string stdDtdFile{"geomodel_v0.dtd"}; + + std::vector<std::string> plugins{}; + std::string outDir{}; + std::string detectorName{"ForkLiftGarage"}; + std::string xmlLayoutFile{}; + + for (int k =1 ; k < argc; ++k) { + const std::string the_arg{argv[k]}; + if (the_arg=="-p" || the_arg=="--plugin") { + bool added{false}; + while (k+1 < argc) { + const std::string toLoad{argv[k+1]}; + if (toLoad[0] == '-') break; + plugins.push_back(toLoad); + ++k; + added = true; + } + if (!added) { + std::cerr<<"Please give at least one follow-up argument to "<<the_arg<<std::endl; + return EXIT_FAILURE; + } + } else if (the_arg == "-o" || the_arg=="--outDir"){ + if (k+1 < argc) { + outDir = argv[k+1]; + ++k; + } else { + std::cerr<<"Please give one follow-up argument to "<<the_arg<<std::endl; + return EXIT_FAILURE; + } + } else { + std::cerr<<"Unknown argument "<<the_arg<<std::endl; + return EXIT_FAILURE; + } + } + if(plugins.empty()) { + std::cerr<<"Please specify at least one plugin via -p / --plugin "<<std::endl; + return EXIT_FAILURE; + } + + if (outDir.empty()) { + std::cerr<<"Please specify an output file via -o "<<std::endl; + return EXIT_FAILURE; + } + if (!mkdir(outDir)) { + std::cerr<<"Failed to create directory "<<outDir<<std::endl; + return EXIT_FAILURE; + } + if (xmlLayoutFile.empty()) { + const std::string ldEnvVar = resolveEnviromentVariables("${LD_LIBRARY_PATH}"); + const std::vector<std::string> ldLibPaths{tokenize(ldEnvVar, ":")}; + for (const std::string& ld_lib : ldLibPaths){ + const std::string sharePath{ld_lib+"/../share/"}; + if (!doesDirectoryExist(sharePath)) { + continue; + } + // + const std::vector<std::string> dtdPaths{findFile(sharePath, stdDtdFile)}; + + if (dtdPaths.size() && !copyFile(dtdPaths[0], outDir + "/" + stdDtdFile)) { + return EXIT_FAILURE; + } + xmlLayoutFile = stdDtdFile; + } + if (xmlLayoutFile.empty()) { + return EXIT_FAILURE; + } + } + GeoIntrusivePtr<GeoVPhysVol> world{createGeoWorld()}; + + for (const std::string& load_me : plugins) { + std::cout<<"Load plugin "<<load_me<<std::endl; + GeoGeometryPluginLoader loader; + std::unique_ptr<GeoVGeometryPlugin> factory{loader.load(load_me)}; + if (!factory) { + std::cerr << "Could not load plugin " << load_me << std::endl; + return EXIT_FAILURE; + } + factory->create(world); + } + GeoXMLDumper dumper{outDir, detectorName, xmlLayoutFile}; + dumper.publishWorld(world); + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/GeoModelTools/GeoModelXMLParser/CMakeLists.txt b/GeoModelTools/GeoModelXMLParser/CMakeLists.txt index 1b98523de4ef4b6c374e7b8e299170a49848ab33..6f68ec6a81a568b0d10234cbc6f6e2af7f247968 100644 --- a/GeoModelTools/GeoModelXMLParser/CMakeLists.txt +++ b/GeoModelTools/GeoModelXMLParser/CMakeLists.txt @@ -21,7 +21,7 @@ set_target_properties( GeoModelXMLParser PROPERTIES # version of the library. add_library( GeoModelTools::GeoModelXMLParser ALIAS GeoModelXMLParser ) -target_link_libraries( GeoModelXMLParser PRIVATE GeoModelCore::GeoModelHelpers ) +target_link_libraries( GeoModelXMLParser PRIVATE GeoModelCore::GeoModelKernel GeoModelCore::GeoModelHelpers ) # Install the library. install(TARGETS GeoModelXMLParser diff --git a/GeoModelTools/GeoModelXMLParser/src/XMLHandler.cxx b/GeoModelTools/GeoModelXMLParser/src/XMLHandler.cxx index 9351563030386ef4e22171d8e0ce83d83339fa0b..c82f54be192304b757fc7cfa80204d91d6bc3b16 100644 --- a/GeoModelTools/GeoModelXMLParser/src/XMLHandler.cxx +++ b/GeoModelTools/GeoModelXMLParser/src/XMLHandler.cxx @@ -5,7 +5,7 @@ #include "GeoModelXMLParser/XMLHandler.h" #include "GeoModelXMLParser/XMLHandlerStore.h" #include "GeoModelHelpers/StringUtils.h" -#include "GeoModelHelpers/throwExcept.h" +#include "GeoModelKernel/throwExcept.h" #include "ExpressionEvaluator/ExpressionEvaluator.h" #include <vector> diff --git a/GeoModelVisualization/CMakeLists.txt b/GeoModelVisualization/CMakeLists.txt index bd48e96958c9c4e4cf1bba3f72538118a08fc38e..135776857a257a2112f43b2113495b40707f246f 100644 --- a/GeoModelVisualization/CMakeLists.txt +++ b/GeoModelVisualization/CMakeLists.txt @@ -82,7 +82,7 @@ add_subdirectory(GXClashPointSystems) add_subdirectory(GeoModelExplorer) add_subdirectory(VP1Gui) add_subdirectory(VP1Base) -add_subdirectory(VP1HEPVis) +add_subdirectory(GXHepVis) add_subdirectory(VP1GuideLineSystems) add_subdirectory(GXHitDisplaySystems) add_subdirectory(GXTrackDisplaySystems) diff --git a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt index 33c91f302076873b65ae865c164fe8ce28036cf8..733a2ff3ce0d688fa12abe0b7bed772ae6873047 100644 --- a/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt +++ b/GeoModelVisualization/GXClashPointSystems/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -12,7 +12,7 @@ target_link_libraries( GXClashPointSystems PRIVATE Qt${QT_VERSION}::Core Qt${QT_VERSION}::Widgets nlohmann_json::nlohmann_json ) target_include_directories( GXClashPointSystems PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GXClashPointSystems" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ${RCS} ) set_target_properties( GXClashPointSystems PROPERTIES diff --git a/GeoModelVisualization/VP1HEPVis/CMakeLists.txt b/GeoModelVisualization/GXHepVis/CMakeLists.txt similarity index 56% rename from GeoModelVisualization/VP1HEPVis/CMakeLists.txt rename to GeoModelVisualization/GXHepVis/CMakeLists.txt index d75338ba7a63d24740083a24e7a36923babb76e8..aa1006ccd2331729e791eac5c3b7f4c212ee759c 100644 --- a/GeoModelVisualization/VP1HEPVis/CMakeLists.txt +++ b/GeoModelVisualization/GXHepVis/CMakeLists.txt @@ -1,35 +1,35 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) -file( GLOB HEADERS VP1HEPVis/*.h ) +file( GLOB HEADERS GXHepVis/*.h ) # Add the library. -add_library( GXHEPVis SHARED ${SOURCES} ${HEADERS} ) -target_include_directories( GXHEPVis PUBLIC +add_library( GXHepVis SHARED ${SOURCES} ${HEADERS} ) +target_include_directories( GXHepVis PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) -target_link_libraries( GXHEPVis + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) +target_link_libraries( GXHepVis PUBLIC Coin::Coin OpenGL::GL GeoModelCore::GeoModelKernel) -source_group( "VP1HEPVis" FILES ${HEADERS} ) +source_group( "GXHepVis" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ) -set_target_properties( GXHEPVis PROPERTIES +set_target_properties( GXHepVis PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) if( GEOMODEL_USE_BUILTIN_COIN3D ) - add_dependencies( GXHEPVis Coin3DBuiltIn ) + add_dependencies( GXHepVis Coin3DBuiltIn ) endif() # Set up an alias with the same name that you would get by "finding" a pre-built # version of the library. -add_library( GeoModelVisualization::GXHEPVis ALIAS GXHEPVis ) +add_library( GeoModelVisualization::GXHepVis ALIAS GXHepVis ) # Install the library. -install( TARGETS GXHEPVis +install( TARGETS GXHepVis EXPORT ${PROJECT_NAME}-export LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime NAMELINK_COMPONENT Development ) -install( DIRECTORY VP1HEPVis +install( DIRECTORY GXHepVis DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT Development ) diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/VP1HEPVisUtils.h b/GeoModelVisualization/GXHepVis/GXHepVis/GXHepVisUtils.h similarity index 58% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/VP1HEPVisUtils.h rename to GeoModelVisualization/GXHepVis/GXHepVis/GXHepVisUtils.h index ebda823a1bbbe67adec0cc8845596252ed9227c8..c898a69605b54ad1f4363a57d5bb06adc97ad4bd 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/VP1HEPVisUtils.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/GXHepVisUtils.h @@ -5,9 +5,9 @@ //////////////////////////////////////////////////////////////// // // -// Header file for class VP1HEPVisUtils // +// Header file for class GXHepVisUtils // // // -// Description: Utilities connected to the VP1HEPVis // +// Description: Utilities connected to the GXHepVis // // classes. // // // // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) // @@ -15,30 +15,23 @@ // // //////////////////////////////////////////////////////////////// -#ifndef VP1HEPVISUTILS_H -#define VP1HEPVISUTILS_H +#ifndef GXHEPVISUTILS_H +#define GXHEPVISUTILS_H class SoGroup; class SoNode; -class VP1HEPVisUtils { +class GXHepVisUtils { public: static void initAllCustomClasses();//calls ::initClass() on all custom classes. - static SoGroup* convertToStandardScene(SoGroup*); - static bool isCustomNode(SoNode*); - static SoNode * convertCustomNodeToAlternateRep(SoNode*);//Returns empty group node if not custom or without alternate rep. - - static void updateAllAlternativeReps(SoGroup*); - static void clearAllAlternativeReps(SoGroup*); - + private: - VP1HEPVisUtils(); - ~VP1HEPVisUtils(); + GXHepVisUtils(); + ~GXHepVisUtils(); - class Imp; }; #endif diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbPlane.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbPlane.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbPlane.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbPlane.h diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbPolyhedron.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbPolyhedron.h similarity index 99% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbPolyhedron.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbPolyhedron.h index 3d4628711939ff9f9383d4ea7d8378697e4fce28..397f4ad3f17ba6a8912f798f5de289334eb9a708 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbPolyhedron.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/SbPolyhedron.h @@ -176,8 +176,8 @@ // VP1 change -#include <VP1HEPVis/SbRotation.h> //using doubles instead of floats. -#include <VP1HEPVis/SbTwistSurface.h> +#include <GXHepVis/SbRotation.h> //using doubles instead of floats. +#include <GXHepVis/SbTwistSurface.h> //--- @@ -210,7 +210,7 @@ typedef HVPoint3D HVVector3D; // rbianchi change //typedef SbPlane HVPlane3D; //typedef SbPlane HVPlane3D; -#include <VP1HEPVis/SbPlane.h> +#include <GXHepVis/SbPlane.h> typedef HEPVis::SbPlane HVPlane3D; //--- typedef SbRotation HVRotation; diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbRotation.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbRotation.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbRotation.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbRotation.h diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistSurface.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistSurface.h similarity index 98% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistSurface.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbTwistSurface.h index 87a088057cebb019115b97228fd54f568ed7fcb9..1b3c46a5575c019cef85a462dc99a8e57d4e01cb 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistSurface.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistSurface.h @@ -17,7 +17,7 @@ #include <string> #include "GeoModelKernel/GeoDefinitions.h" -#include <VP1HEPVis/SbRotation.h> +#include <GXHepVis/SbRotation.h> #include <Inventor/SbVec4d.h> #define SBSURFACENXX 10 diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapAlphaSide.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapAlphaSide.h similarity index 98% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapAlphaSide.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapAlphaSide.h index e6898a4b84a975717ae3b9074dd84401f80c22e3..c2bde0b60e90bf19f1f5917bce5155442cb6e948 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapAlphaSide.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapAlphaSide.h @@ -12,7 +12,7 @@ #ifndef SBTWISTTRAPALPHASIDE_HH #define SBTWISTTRAPALPHASIDE_HH -#include "VP1HEPVis/SbTwistSurface.h" +#include "GXHepVis/SbTwistSurface.h" #include <vector> diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapFlatSide.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapFlatSide.h similarity index 98% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapFlatSide.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapFlatSide.h index a00c768775e09f9908d188872b513e51675ca7dd..954b019a556ce90dee27ea62df66bcf6cbf417f6 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapFlatSide.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapFlatSide.h @@ -12,7 +12,7 @@ #ifndef SBTWISTTRAPFLATSIDE_HH #define SBTWISTTRAPFLATSIDE_HH -#include "VP1HEPVis/SbTwistSurface.h" +#include "GXHepVis/SbTwistSurface.h" #include <string> class SbTwistTrapFlatSide : public SbTwistSurface diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapParallelSide.h b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapParallelSide.h similarity index 98% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapParallelSide.h rename to GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapParallelSide.h index 9b8c0ebcd068be3186bc498434d3c0e6827e62f8..42d5bd185c54fa75ef23260d1036bb0bae4c0226 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/SbTwistTrapParallelSide.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/SbTwistTrapParallelSide.h @@ -12,8 +12,8 @@ #ifndef SBTWISTTRAPPARALLELSIDE_HH #define SBTWISTTRAPPARALLELSIDE_HH -#include "VP1HEPVis/SbTwistSurface.h" -#include "VP1HEPVis/SbPolyhedron.h" +#include "GXHepVis/SbTwistSurface.h" +#include "GXHepVis/SbPolyhedron.h" #include <vector> #include <cmath> diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/actions/SoGL2PSAction.h b/GeoModelVisualization/GXHepVis/GXHepVis/actions/SoGL2PSAction.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/actions/SoGL2PSAction.h rename to GeoModelVisualization/GXHepVis/GXHepVis/actions/SoGL2PSAction.h diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/gl2ps.h b/GeoModelVisualization/GXHepVis/GXHepVis/gl2ps.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/gl2ps.h rename to GeoModelVisualization/GXHepVis/GXHepVis/gl2ps.h diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoCons.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoCons.h similarity index 86% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoCons.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoCons.h index 893a3267c14b085d29d8b0be5660fcdbc573d1a3..c7ceb1ad4a54c608655084ac4f5f2e73ae1338ff 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoCons.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoCons.h @@ -91,11 +91,6 @@ public: //! Put field to 0 (the default) to ignore it. // SoSFInt32 pOverrideNPhi; - // - //! Alternate rep required - for use by users without HEPVis shared objects - // - SoSFNode alternateRep; - // //! Constructor, required // @@ -106,20 +101,6 @@ public: // static void initClass(); - // - //! Generate AlternateRep, required. Generating an alternate representation - //! must be done upon users request. It allows an Inventor program to read - //! back the file without requiring *this* code to be dynamically linked. - //! If the users expects that *this* code will be dynamically linked, he - //! need not invoke this method. - // - virtual void generateAlternateRep(); - - // - //! We better be able to clear it, too! - // - virtual void clearAlternateRep(); - protected: // diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoGenericBox.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoGenericBox.h similarity index 97% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoGenericBox.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoGenericBox.h index 895c7d2514a4a60fd25a8682ff88bf7a73103205..a7c3ba154bc32c0d4f780121716a90a394a907dd 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoGenericBox.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoGenericBox.h @@ -32,7 +32,6 @@ public: //Fields: SoSFBool drawEdgeLines;//Default: False SoSFBool forceEdgeLinesInBaseColour;//Default: True - SoSFNode alternateRep; //NB: For performance reason we deviate from the standard Inventor //way here. We keep the points in an array, and the user must use @@ -78,6 +77,7 @@ public: float x6, float y6, float z6, float x7, float y7, float z7 ); + //Todo: We could even add a transformation for the TRD (or anything //else... perhaps an "applyTransform" method to call after the first //setParameters...?) @@ -87,8 +87,6 @@ public: //Required stuff: SoGenericBox(); static void initClass();//You can call this as many times as you like - virtual void generateAlternateRep(); - virtual void clearAlternateRep(); protected: diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoLAr.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoLAr.h similarity index 84% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoLAr.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoLAr.h index 081be90ea07a095f7391deac0b1e260dc8765724..0a5ca8b4b76e7afbaa054a627623be2f37cd3d6b 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoLAr.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoLAr.h @@ -69,10 +69,6 @@ public: //! Put field to 0 (the default) to ignore it. // SoSFInt32 pOverrideNPhi; - // - //! Alternate rep required - for use by users without HEPVis shared objects - // - SoSFNode alternateRep; // //! Constructor, required @@ -84,20 +80,6 @@ public: // static void initClass(); - // - //! Generate AlternateRep, required. Generating an alternate representation - //! must be done upon users request. It allows an Inventor program to read - //! back the file without requiring *this* code to be dynamically linked. - //! If the users expects that *this* code will be dynamically linked, he - //! need not invoke this method. - // - virtual void generateAlternateRep(); - - // - //! We better be able to clear it, too! - // - virtual void clearAlternateRep(); - protected: // diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPcons.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPcons.h similarity index 84% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPcons.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPcons.h index 282934279c6a28dd204da0e907492ff3d5f7c975..c66b289f3ee591e859de2c21e14ea6554b0013e1 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPcons.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPcons.h @@ -73,9 +73,6 @@ public: // SoSFInt32 pOverrideNPhi; // - //! Alternate rep required - for use by users without HEPVis shared objects - // - SoSFNode alternateRep;//FIXED SoSFBool drawEdgeLines;//Default: False @@ -89,20 +86,6 @@ public: // static void initClass(); - // - //! Generate AlternateRep, required. Generating an alternate representation - //! must be done upon users request. It allows an Inventor program to read - //! back the file without requiring *this* code to be dynamically linked. - //! If the users expects that *this* code will be dynamically linked, he - //! need not invoke this method. - // - virtual void generateAlternateRep();//FIXME: NOT IMPLEMENTED - - // - //! We better be able to clear it, too! - // - virtual void clearAlternateRep();//FIXME: NOT IMPLEMENTED - protected: // diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPolyhedron.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPolyhedron.h similarity index 95% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPolyhedron.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPolyhedron.h index fe940ddfb546431f3302d87b3ee9eb479c9f52c1..d783570a9a43d03d9403a52e1c3dc6445cff93c0 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoPolyhedron.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoPolyhedron.h @@ -51,7 +51,6 @@ class SoPolyhedron : public SoShape { public: //SoSFBool solid; //SoSFBool reducedWireFrame; - SoSFNode alternateRep; public: SoPolyhedron(); SoPolyhedron(const SbPolyhedron&); @@ -82,10 +81,7 @@ public: long m_icount; long hasVertex(Vertex* vertices, long len, Vertex& v); void makeShape(SbPolyhedron*); -public: - virtual void generateAlternateRep(); - virtual void clearAlternateRep(); - //---------------------// + }; #endif diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTessellated.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTessellated.h similarity index 95% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTessellated.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTessellated.h index c148e7274ec77e16babb526ea15199e16373fcc1..7ee8ca9f7b418f0bc8543d2009c4ba915c38af5f 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTessellated.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTessellated.h @@ -30,7 +30,6 @@ class SoTessellated : public SoShape //Fields: SoSFBool drawEdgeLines; //Default: False SoSFBool forceEdgeLinesInBaseColour; //Default: True - SoSFNode alternateRep; // Following two methods add facets to the solid // @@ -56,8 +55,6 @@ class SoTessellated : public SoShape //_____ Required stuff _____ SoTessellated(); static void initClass(); - virtual void generateAlternateRep(); - virtual void clearAlternateRep(); protected: diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTorus.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTorus.h similarity index 92% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTorus.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTorus.h index e002505bc568652c301c948aee0332500ed410c8..223c82f22c078eb99f21ae7adf723f73da0ecbfc 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTorus.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTorus.h @@ -103,10 +103,6 @@ public: // SoSFInt32 pOverrideNPhi; // - //! Alternate rep required - for use by users without HEPVis shared objects - // - SoSFNode alternateRep; - // //! Constructor, required // @@ -117,20 +113,6 @@ public: // static void initClass(); - // - //! Generate AlternateRep, required. Generating an alternate representation - //! must be done upon users request. It allows an Inventor program to read - //! back the file without requiring *this* code to be dynamically linked. - //! If the users expects that *this* code will be dynamically linked, he - //! need not invoke this method. - // - virtual void generateAlternateRep(); - - // - //! We better be able to clear it, too! - // - virtual void clearAlternateRep(); - protected: // diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTransparency.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTransparency.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTransparency.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTransparency.h diff --git a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTubs.h b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTubs.h similarity index 87% rename from GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTubs.h rename to GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTubs.h index 88d23be808741d06420ebd1e837c7b8db5f5079d..b2083153af925d4f487148306e8e4519eaa93769 100644 --- a/GeoModelVisualization/VP1HEPVis/VP1HEPVis/nodes/SoTubs.h +++ b/GeoModelVisualization/GXHepVis/GXHepVis/nodes/SoTubs.h @@ -79,10 +79,6 @@ public: //! Put field to 0 (the default) to ignore it. // SoSFInt32 pOverrideNPhi; - // - //! Alternate rep - required - // - SoSFNode alternateRep; SoSFBool drawEdgeLines;//Default: False @@ -96,20 +92,6 @@ public: // static void initClass(); - // - //! Generate AlternateRep, required. Generating an alternate representation - //! must be done upon users request. It allows an Inventor program to read - //! back the file without requiring *this* code to be dynamically linked. - //! If the users expects that *this* code will be dynamically linked, he - //! need not invoke this method. - // - virtual void generateAlternateRep(); - - // - //! We better be able to clear it, too! - // - virtual void clearAlternateRep(); - protected: // diff --git a/GeoModelVisualization/VP1HEPVis/src/BooleanProcessor.h b/GeoModelVisualization/GXHepVis/src/BooleanProcessor.h similarity index 99% rename from GeoModelVisualization/VP1HEPVis/src/BooleanProcessor.h rename to GeoModelVisualization/GXHepVis/src/BooleanProcessor.h index ec3782dd695b3c7324acc87b203f6301f3d8f923..999c3441c73da45377578c8675662163593618dc 100644 --- a/GeoModelVisualization/VP1HEPVis/src/BooleanProcessor.h +++ b/GeoModelVisualization/GXHepVis/src/BooleanProcessor.h @@ -15,7 +15,7 @@ * NOTES: * * =================== - * VP1 Customization: + * VP1/GMEX Customization: * * - look into the code for comments "// VP1 change" * @@ -63,7 +63,7 @@ typedef G4Normal3D HVNormal3D; // VP1 change //#include <HEPVis/SbPlane.h> -#include <VP1HEPVis/SbPlane.h> +#include <GXHepVis/SbPlane.h> typedef HEPVis::SbPlane HVPlane3D; //--- @@ -2071,14 +2071,14 @@ HepPolyhedron BooleanProcessor::execute(int op, case OP_UNION: return b; case OP_INTERSECTION: - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "BooleanProcessor: intersection with empty polyhedron" << std::endl; } return HepPolyhedron(); case OP_SUBTRACTION: - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "BooleanProcessor: subtraction from empty polyhedron" << std::endl; @@ -2092,7 +2092,7 @@ HepPolyhedron BooleanProcessor::execute(int op, case OP_UNION: return a; case OP_INTERSECTION: - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "BooleanProcessor: intersection with empty polyhedron" << std::endl; diff --git a/GeoModelVisualization/VP1HEPVis/src/BooleanProcessor.h.original b/GeoModelVisualization/GXHepVis/src/BooleanProcessor.h.original similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/BooleanProcessor.h.original rename to GeoModelVisualization/GXHepVis/src/BooleanProcessor.h.original diff --git a/GeoModelVisualization/GXHepVis/src/GXHepVisUtils.cxx b/GeoModelVisualization/GXHepVis/src/GXHepVisUtils.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e0eb6c5ad07db24d42dfd2d255d6acd58ea639c9 --- /dev/null +++ b/GeoModelVisualization/GXHepVis/src/GXHepVisUtils.cxx @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + + +//////////////////////////////////////////////////////////////// +// // +// Implementation of class GXHepVisUtils // +// // +// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) // +// Initial version: November 2008 // +// Update: Giorgi Gvaberidze (ggvaberi@cern.ch) // +// Update version: November 2010 // +// Truncated to almost zero: J. Boudreau June 2024 // +// // +//////////////////////////////////////////////////////////////// + +#include "GXHepVis/GXHepVisUtils.h" + +#include "GXHepVis/nodes/SoCons.h" +#include "GXHepVis/nodes/SoGenericBox.h" +#include "GXHepVis/nodes/SoLAr.h" +#include "GXHepVis/nodes/SoPcons.h" +#include "GXHepVis/nodes/SoPolyhedron.h" +#include "GXHepVis/nodes/SoTransparency.h" +#include "GXHepVis/nodes/SoTubs.h" +#include "GXHepVis/nodes/SoTessellated.h" + +//____________________________________________________________________ +void GXHepVisUtils::initAllCustomClasses() +{ + SoCons::initClass(); + SoGenericBox::initClass(); + SoLAr::initClass(); + SoPcons::initClass(); + SoPolyhedron::initClass(); + SoTransparency::initClass(); + SoTubs::initClass(); + SoTessellated::initClass(); +} diff --git a/GeoModelVisualization/VP1HEPVis/src/PolygonTriangulator.cxx b/GeoModelVisualization/GXHepVis/src/PolygonTriangulator.cxx similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/PolygonTriangulator.cxx rename to GeoModelVisualization/GXHepVis/src/PolygonTriangulator.cxx diff --git a/GeoModelVisualization/VP1HEPVis/src/PolygonTriangulator.h b/GeoModelVisualization/GXHepVis/src/PolygonTriangulator.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/PolygonTriangulator.h rename to GeoModelVisualization/GXHepVis/src/PolygonTriangulator.h diff --git a/GeoModelVisualization/VP1HEPVis/src/RevolutionSurfaceUtil.h b/GeoModelVisualization/GXHepVis/src/RevolutionSurfaceUtil.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/RevolutionSurfaceUtil.h rename to GeoModelVisualization/GXHepVis/src/RevolutionSurfaceUtil.h diff --git a/GeoModelVisualization/VP1HEPVis/src/SbMath.h b/GeoModelVisualization/GXHepVis/src/SbMath.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/SbMath.h rename to GeoModelVisualization/GXHepVis/src/SbMath.h diff --git a/GeoModelVisualization/VP1HEPVis/src/SbPlane.cxx b/GeoModelVisualization/GXHepVis/src/SbPlane.cxx similarity index 97% rename from GeoModelVisualization/VP1HEPVis/src/SbPlane.cxx rename to GeoModelVisualization/GXHepVis/src/SbPlane.cxx index ba6c2b1152318ef9b1dc3d59ab35e35ff265022a..0fb67714cef6d3bc43eccbe0ebe1d0c52728fe1a 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbPlane.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbPlane.cxx @@ -3,7 +3,7 @@ */ /* - * VP1HEPVis + * GXHepVis * SbPlane.cxx * * Created on: Dec 13, 2012 @@ -35,7 +35,7 @@ // this : // VP1 change //#include <HEPVis/SbPlane.h> -#include <VP1HEPVis/SbPlane.h> +#include <GXHepVis/SbPlane.h> //--- diff --git a/GeoModelVisualization/VP1HEPVis/src/SbPolyhedron.cxx b/GeoModelVisualization/GXHepVis/src/SbPolyhedron.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SbPolyhedron.cxx rename to GeoModelVisualization/GXHepVis/src/SbPolyhedron.cxx index 5b389bf629a0b3c9ddb1f0870bae911c5830c432..2c46f719126406831a1d921d079cdb93078bb4d9 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbPolyhedron.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbPolyhedron.cxx @@ -11,10 +11,10 @@ //////////////////////////////////////////////////////////////// -#include <VP1HEPVis/SbPolyhedron.h> -#include <VP1HEPVis/SbTwistTrapAlphaSide.h> -#include <VP1HEPVis/SbTwistTrapParallelSide.h> -#include <VP1HEPVis/SbTwistTrapFlatSide.h> +#include <GXHepVis/SbPolyhedron.h> +#include <GXHepVis/SbTwistTrapAlphaSide.h> +#include <GXHepVis/SbTwistTrapParallelSide.h> +#include <GXHepVis/SbTwistTrapFlatSide.h> #include "GeoModelKernel/Units.h" @@ -1769,7 +1769,7 @@ SbPolyhedronCons::SbPolyhedronCons(double Rmn1, if (dphi > wholeCircle) k += 4; if (k != 0) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronCone(s)/Tube(s): error in input parameters"; if ((k & 1) != 0) std::cerr << " (radiuses)"; if ((k & 2) != 0) std::cerr << " (half-length)"; @@ -1850,7 +1850,7 @@ SbPolyhedronPgon::SbPolyhedronPgon(double phi, // C H E C K I N P U T P A R A M E T E R S if (dphi <= 0. || dphi > 2*M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronPgon/Pcon: wrong delta phi = " << dphi << std::endl; @@ -1859,7 +1859,7 @@ SbPolyhedronPgon::SbPolyhedronPgon(double phi, } if (nz < 2) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronPgon/Pcon: number of z-planes less than two = " << nz << std::endl; @@ -1868,7 +1868,7 @@ SbPolyhedronPgon::SbPolyhedronPgon(double phi, } if (npdv < 0) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronPgon/Pcon: error in number of phi-steps =" << npdv << std::endl; @@ -1879,7 +1879,7 @@ SbPolyhedronPgon::SbPolyhedronPgon(double phi, int i; for (i=0; i<nz; i++) { if (rmin[i] < 0. || rmax[i] < 0. || rmin[i] > rmax[i]) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronPgon: error in radiuses rmin[" << i << "]=" << rmin[i] << " rmax[" << i << "]=" << rmax[i] @@ -1952,7 +1952,7 @@ SbPolyhedronSphere::SbPolyhedronSphere(double rmin, double rmax, // C H E C K I N P U T P A R A M E T E R S if (dphi <= 0. || dphi > 2*M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronSphere: wrong delta phi = " << dphi << std::endl; @@ -1961,7 +1961,7 @@ SbPolyhedronSphere::SbPolyhedronSphere(double rmin, double rmax, } if (the < 0. || the > M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronSphere: wrong theta = " << the << std::endl; @@ -1970,7 +1970,7 @@ SbPolyhedronSphere::SbPolyhedronSphere(double rmin, double rmax, } if (dthe <= 0. || dthe > M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronSphere: wrong delta theta = " << dthe << std::endl; @@ -1982,7 +1982,7 @@ SbPolyhedronSphere::SbPolyhedronSphere(double rmin, double rmax, dthe = M_PI - the; //G.Barrand : coming from LHCb/S.Ponce. if (the+dthe > M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronSphere: wrong theta + delta theta = " << the << " " << dthe @@ -1992,7 +1992,7 @@ SbPolyhedronSphere::SbPolyhedronSphere(double rmin, double rmax, } if (rmin < 0. || rmin >= rmax) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronSphere: error in radiuses" << " rmin=" << rmin << " rmax=" << rmax @@ -2063,7 +2063,7 @@ SbPolyhedronTorus::SbPolyhedronTorus(double rmin, // C H E C K I N P U T P A R A M E T E R S if (dphi <= 0. || dphi > 2*M_PI) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronTorus: wrong delta phi = " << dphi << std::endl; @@ -2072,7 +2072,7 @@ SbPolyhedronTorus::SbPolyhedronTorus(double rmin, } if (rmin < 0. || rmin >= rmax || rmax >= rtor) { - if ( getenv("VP1MSG_DEBUG_OUTPUT") ) { // TODO: to be replaced by VP1Msg::debug(), when moved outside of VP1Base + if ( getenv("GMXMSG_DEBUG_OUTPUT") ) { std::cerr << "SbPolyhedronTorus: error in radiuses" << " rmin=" << rmin << " rmax=" << rmax << " rtorus=" << rtor diff --git a/GeoModelVisualization/VP1HEPVis/src/SbRotation.cxx b/GeoModelVisualization/GXHepVis/src/SbRotation.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SbRotation.cxx rename to GeoModelVisualization/GXHepVis/src/SbRotation.cxx index 24427bdc02ffb2f6a30813b45a9f1537127cb24a..ba72e42b6955c5db79f6866ccc00b3caace1ed90 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbRotation.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbRotation.cxx @@ -3,7 +3,7 @@ */ /* - * VP1HEPVis + * GXHepVis * SbRotation.cxx * * Created on: Dec 13, 2012 @@ -36,7 +36,7 @@ // this : // VP1 change -#include <VP1HEPVis/SbRotation.h> +#include <GXHepVis/SbRotation.h> //--- #include <math.h> diff --git a/GeoModelVisualization/VP1HEPVis/src/SbStringHelpers.cxx b/GeoModelVisualization/GXHepVis/src/SbStringHelpers.cxx similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/SbStringHelpers.cxx rename to GeoModelVisualization/GXHepVis/src/SbStringHelpers.cxx diff --git a/GeoModelVisualization/VP1HEPVis/src/SbStringHelpers.h b/GeoModelVisualization/GXHepVis/src/SbStringHelpers.h similarity index 100% rename from GeoModelVisualization/VP1HEPVis/src/SbStringHelpers.h rename to GeoModelVisualization/GXHepVis/src/SbStringHelpers.h diff --git a/GeoModelVisualization/VP1HEPVis/src/SbTwistSurface.cxx b/GeoModelVisualization/GXHepVis/src/SbTwistSurface.cxx similarity index 99% rename from GeoModelVisualization/VP1HEPVis/src/SbTwistSurface.cxx rename to GeoModelVisualization/GXHepVis/src/SbTwistSurface.cxx index 112fa234a0b280c294448069fe0b07e287d95d8a..89fa5f4eee38bc9414dfb2999847e900a0890f8f 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbTwistSurface.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbTwistSurface.cxx @@ -11,7 +11,7 @@ #include <iomanip> #include <iostream> -#include "VP1HEPVis/SbTwistSurface.h" +#include "GXHepVis/SbTwistSurface.h" //===================================================================== //* constructors ------------------------------------------------------ diff --git a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapAlphaSide.cxx b/GeoModelVisualization/GXHepVis/src/SbTwistTrapAlphaSide.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SbTwistTrapAlphaSide.cxx rename to GeoModelVisualization/GXHepVis/src/SbTwistTrapAlphaSide.cxx index a88642542d2ea1ee93f8b280955f78b4551629ac..62cb98c1d3b279b32c416d83c19d58d723a006b7 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapAlphaSide.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbTwistTrapAlphaSide.cxx @@ -9,7 +9,7 @@ #include <cmath> #include <iostream> -#include "VP1HEPVis/SbTwistTrapAlphaSide.h" +#include "GXHepVis/SbTwistTrapAlphaSide.h" //===================================================================== //* constructors ------------------------------------------------------ diff --git a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapFlatSide.cxx b/GeoModelVisualization/GXHepVis/src/SbTwistTrapFlatSide.cxx similarity index 99% rename from GeoModelVisualization/VP1HEPVis/src/SbTwistTrapFlatSide.cxx rename to GeoModelVisualization/GXHepVis/src/SbTwistTrapFlatSide.cxx index 7f63c25c1fefcf71e5b41575f1b1d01b60354b99..092216fabce80578e87c1148061e99c1bf3c0ccf 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapFlatSide.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbTwistTrapFlatSide.cxx @@ -6,7 +6,7 @@ // Adapted from Geant4 to GMEX // -------------------------------------------------------------------- -#include "VP1HEPVis/SbTwistTrapFlatSide.h" +#include "GXHepVis/SbTwistTrapFlatSide.h" #include <cmath> #include <iostream> diff --git a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapParallelSide.cxx b/GeoModelVisualization/GXHepVis/src/SbTwistTrapParallelSide.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SbTwistTrapParallelSide.cxx rename to GeoModelVisualization/GXHepVis/src/SbTwistTrapParallelSide.cxx index bc20ad016e99a9ebc8c4e462af6ea5f2334327e0..fc33b511727b9a40be1603c9856e6d71b66603de 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SbTwistTrapParallelSide.cxx +++ b/GeoModelVisualization/GXHepVis/src/SbTwistTrapParallelSide.cxx @@ -9,7 +9,7 @@ #include <cmath> #include <iostream> -#include "VP1HEPVis/SbTwistTrapParallelSide.h" +#include "GXHepVis/SbTwistTrapParallelSide.h" //===================================================================== //* constructors ------------------------------------------------------ diff --git a/GeoModelVisualization/VP1HEPVis/src/SoCons.cxx b/GeoModelVisualization/GXHepVis/src/SoCons.cxx similarity index 96% rename from GeoModelVisualization/VP1HEPVis/src/SoCons.cxx rename to GeoModelVisualization/GXHepVis/src/SoCons.cxx index 9e46376af03bb5d264e6bc4a9cbbf39abd08211f..52219f4f14c8b948f7841f5b8e4ca96b2355a06d 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoCons.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoCons.cxx @@ -11,7 +11,7 @@ /*--------------------------------------------------------------------------*/ // this : -#include <VP1HEPVis/nodes/SoCons.h> +#include <GXHepVis/nodes/SoCons.h> #include "RevolutionSurfaceUtil.h" #include <cassert> @@ -48,7 +48,6 @@ SoCons::SoCons() { SO_NODE_ADD_FIELD(fDPhi, ((float)(2*M_PI))); SO_NODE_ADD_FIELD(smoothDraw, (TRUE)); SO_NODE_ADD_FIELD(pOverrideNPhi, (0)); - SO_NODE_ADD_FIELD(alternateRep, (NULL)); m_children = new SoChildList(this); setNodeType(EXTENSION); @@ -429,18 +428,3 @@ void SoCons::generateChildren() { m_children->append(sep); } -// generateAlternateRep -void SoCons::generateAlternateRep() { - - // This routine sets the alternate representation to the child - // list of this mode. - - if (m_children->getLength() == 0) generateChildren(); - updateChildren(); - alternateRep.setValue((SoSeparator *) ( *m_children)[0]); -} - -// clearAlternateRep -void SoCons::clearAlternateRep() { - alternateRep.setValue(NULL); -} diff --git a/GeoModelVisualization/VP1HEPVis/src/SoGL2PSAction.cxx b/GeoModelVisualization/GXHepVis/src/SoGL2PSAction.cxx similarity index 99% rename from GeoModelVisualization/VP1HEPVis/src/SoGL2PSAction.cxx rename to GeoModelVisualization/GXHepVis/src/SoGL2PSAction.cxx index 07a2dba0fe042edbc3f1ac46b10003f2dd244a62..e5ca272f3b66796573e2f8c79f08818835f2de36 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoGL2PSAction.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoGL2PSAction.cxx @@ -3,7 +3,7 @@ */ // this : -#include <VP1HEPVis/actions/SoGL2PSAction.h> +#include <GXHepVis/actions/SoGL2PSAction.h> // Inventor : #include <Inventor/nodes/SoDrawStyle.h> @@ -15,7 +15,7 @@ //LD HEPVis specific #include <HEPVis/SbStyles.h> #include "SbStringHelpers.h" -#include "VP1HEPVis/gl2ps.h" +#include "GXHepVis/gl2ps.h" #include <stdio.h> diff --git a/GeoModelVisualization/VP1HEPVis/src/SoGenericBox.cxx b/GeoModelVisualization/GXHepVis/src/SoGenericBox.cxx similarity index 89% rename from GeoModelVisualization/VP1HEPVis/src/SoGenericBox.cxx rename to GeoModelVisualization/GXHepVis/src/SoGenericBox.cxx index 3def8d508e27e0f4a3591daebb6e2b0a08b7e66b..70ccc7a3be9074e176b861e534c1735506c5019c 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoGenericBox.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoGenericBox.cxx @@ -12,7 +12,7 @@ // // //////////////////////////////////////////////////////////////// -#include "VP1HEPVis/nodes/SoGenericBox.h" +#include "GXHepVis/nodes/SoGenericBox.h" #include <Inventor/SbBox.h> #include <Inventor/actions/SoPickAction.h> @@ -75,7 +75,6 @@ SoGenericBox::SoGenericBox() SO_NODE_CONSTRUCTOR(SoGenericBox); SO_NODE_ADD_FIELD(drawEdgeLines, (false)); SO_NODE_ADD_FIELD(forceEdgeLinesInBaseColour, (true)); - SO_NODE_ADD_FIELD(alternateRep,(NULL)); setNodeType(EXTENSION); } @@ -88,7 +87,6 @@ SoGenericBox::~SoGenericBox() //____________________________________________________________________ void SoGenericBox::generatePrimitives(SoAction *action) { - if (!m_points) setupDefaultPoints(); @@ -349,7 +347,6 @@ void SoGenericBox::setParametersForTrapezoid( float dz, float theta, float phi, pointsUpdated(); } - //____________________________________________________________________ void SoGenericBox::setGenericParameters( float x0, float y0, float z0, float x1, float y1, float z1, @@ -376,22 +373,24 @@ void SoGenericBox::setGenericParameters( float x0, float y0, float z0, void SoGenericBox::pointsUpdated() { //Normals: - if (!m_normals) + //if (!m_normals) m_normals = new float[SOGENERICBOX_NFACES*3]; + + std::cout << " " << std::endl; for (int iface = 0; iface < SOGENERICBOX_NFACES; ++iface) { const int index_v1 = sogenericbox_vindices[iface*4+0]; const int index_v2 = sogenericbox_vindices[iface*4+1]; const int index_v3 = sogenericbox_vindices[iface*4+2]; - - //Figure out normal: (v2-v1)(x)(v3-v1) + + //Figure out normal: (v2-v1)(x)(v3-v1) // Use cross-product to find out norm of a plane const double v1X(m_points[index_v1*3+0]), v1Y(m_points[index_v1*3+1]), v1Z(m_points[index_v1*3+2]); const double edge1X(m_points[index_v2*3+0]-v1X), edge1Y(m_points[index_v2*3+1]-v1Y), edge1Z(m_points[index_v2*3+2]-v1Z); const double edge2X(m_points[index_v3*3+0]-v1X), edge2Y(m_points[index_v3*3+1]-v1Y), edge2Z(m_points[index_v3*3+2]-v1Z); - double nx(edge1Y*edge2Z-edge1Z*edge2Y); - double ny(edge1Z*edge2X-edge1X*edge2Z); - double nz(edge1X*edge2Y-edge1Y*edge2X); - double nl(nx*nx+ny*ny+nz*nz); + double nx(edge1Y*edge2Z-edge1Z*edge2Y); // x component of norm + double ny(edge1Z*edge2X-edge1X*edge2Z); // y component of norm + double nz(edge1X*edge2Y-edge1Y*edge2X); // z component of norm + double nl(nx*nx+ny*ny+nz*nz); // length of norm if (nl<=0) { std::cout<<"SoGenericBox::Error Could not calculate normal due to degenerate face edge"<<std::endl; nx=1.0;ny=0.0;nz=0.0;nl=1; @@ -404,6 +403,7 @@ void SoGenericBox::pointsUpdated() m_normals[iface*3+0] = nx*s; m_normals[iface*3+1] = ny*s; m_normals[iface*3+2] = nz*s; + } //BBox: @@ -421,49 +421,3 @@ void SoGenericBox::pointsUpdated() drawEdgeLines.touch(); } - -/////////////////////////////// -// Stuff for alternate rep // -/////////////////////////////// - -//____________________________________________________________________ -void SoGenericBox::generateAlternateRep() -{ - if (!m_points) - setupDefaultPoints(); - if (alternateRep.getValue()) - clearAlternateRep(); - SoSeparator * sep = new SoSeparator; - - //Vertice coordinates: - SoVertexProperty *vertices = new SoVertexProperty(); - for (int i=0;i<SOGENERICBOX_NPOINTS;++i) - vertices->vertex.set1Value ( i, m_points[i*3+0],m_points[i*3+1],m_points[i*3+2] ); - SoIndexedFaceSet * faceset = new SoIndexedFaceSet; - faceset->coordIndex.setValues(0,5*6, sogenericbox_vindices_foraltrepfaces); - faceset->vertexProperty = vertices; - sep->addChild(faceset); - - if (drawEdgeLines.getValue()) { -//Disable the lightmodel now since we in any case gets baselightning with the lineset defined this way... -// if (forceEdgeLinesInBaseColour.getValue()) { -// SoLightModel * lm = new SoLightModel;//Fixme: share -// lm->model = SoLightModel::BASE_COLOR; -// sep->addChild(lm); -// } - SoIndexedLineSet * lineset = new SoIndexedLineSet; - lineset->coordIndex.setValues(0,20,sogenericbox_vindices_foraltreplines); - lineset->vertexProperty = vertices; - sep->addChild(lineset); - } - - alternateRep.setValue(sep); - -} - -//____________________________________________________________________ -void SoGenericBox::clearAlternateRep() -{ - alternateRep.setValue(NULL); - //Hmm... no ref/unref?? -} diff --git a/GeoModelVisualization/VP1HEPVis/src/SoLAr.cxx b/GeoModelVisualization/GXHepVis/src/SoLAr.cxx similarity index 97% rename from GeoModelVisualization/VP1HEPVis/src/SoLAr.cxx rename to GeoModelVisualization/GXHepVis/src/SoLAr.cxx index c661e0c28d8a712fafe4cb3c300e75302b27525f..bd283a1992681f000ed9fa5119ba4d21a201697f 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoLAr.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoLAr.cxx @@ -10,7 +10,7 @@ /* */ /*--------------------------------------------------------------------------*/ -#include <VP1HEPVis/nodes/SoLAr.h> +#include <GXHepVis/nodes/SoLAr.h> #include "RevolutionSurfaceUtil.h" #include <iostream> @@ -44,7 +44,6 @@ SoLAr::SoLAr() { SO_NODE_ADD_FIELD(fDPhi, ((float)(2*M_PI))); SO_NODE_ADD_FIELD(smoothDraw, (TRUE)); SO_NODE_ADD_FIELD(pOverrideNPhi, (0)); - SO_NODE_ADD_FIELD(alternateRep, (NULL)); m_children = new SoChildList(this); float rMinDef[]={10.0, 15.0, 10.0}; @@ -490,18 +489,3 @@ void SoLAr::generateChildren() { #endif } -// generateAlternateRep -void SoLAr::generateAlternateRep() { - - // This routine sets the alternate representation to the child - // list of this mode. - - if (m_children->getLength() == 0) generateChildren(); - updateChildren(); - alternateRep.setValue((SoSeparator *) ( *m_children)[0]); -} - -// clearAlternateRep -void SoLAr::clearAlternateRep() { - alternateRep.setValue(NULL); -} diff --git a/GeoModelVisualization/VP1HEPVis/src/SoPcons.cxx b/GeoModelVisualization/GXHepVis/src/SoPcons.cxx similarity index 69% rename from GeoModelVisualization/VP1HEPVis/src/SoPcons.cxx rename to GeoModelVisualization/GXHepVis/src/SoPcons.cxx index 658b9afc64e18e1e492f1a0cd1da42ea1d7c1592..3d45e584e0bd9ae87262e84aa76ffdfedcf07627 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoPcons.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoPcons.cxx @@ -7,12 +7,8 @@ /* Node: SoPcons */ /* Description: Represents the G4Pcons Geant Geometry entity */ /* Author: Joe Boudreau Nov 11 1996 */ -/* Update: Giorgi Gvaberidze (ggvaberi@cern.ch) */ -/* April 2011 */ -/* Fixed: Generating of alternate rep, for export in *.iv file */ -/* */ /*--------------------------------------------------------------------------*/ -#include <VP1HEPVis/nodes/SoPcons.h> +#include <GXHepVis/nodes/SoPcons.h> #include "RevolutionSurfaceUtil.h" #include <cassert> @@ -47,7 +43,6 @@ SoPcons::SoPcons() { SO_NODE_ADD_FIELD(fDPhi, ((float)(2*M_PI))); SO_NODE_ADD_FIELD(smoothDraw, (TRUE)); SO_NODE_ADD_FIELD(pOverrideNPhi, (0)); - SO_NODE_ADD_FIELD(alternateRep, (NULL)); SO_NODE_ADD_FIELD(drawEdgeLines, (false)); m_children = new SoChildList(this); @@ -576,261 +571,3 @@ void SoPcons::generateChildren() { #endif } -// generateAlternateRep -#include <vector> - -void SoPcons::generateAlternateRep() { - - // This routine sets the alternate representation to the child - // list of this mode. - - //if (m_children->getLength() == 0) generateChildren(); - //updateChildren(); - // alternateRep.setValue((SoSeparator *) ( *m_children)[0]); - - - /* updated for generate fullfill alternaterep - *********************************************** - As First we collect point and triangle strip - bounds same as in draw function. - there is copied draw function contents and - replased unused part; - - Source code was taked from render part, and modified - for collect nessesary information, and build alternate - geometry. - ********************************************** - */ - const int NPHI = 96; - - // This variable is used to store each vertex - SoPrimitiveVertex pv; - - //For collect points in Pcon geometry chunk - std::vector<SoPrimitiveVertex> vls; //Vertex List - - //For collect all triangles - std::vector<SoPrimitiveVertex> fls; //Face list. face here is qudrangle - - // See if we have to use a texture coordinate function, - // rather than generating explicit texture coordinates. - - SbVec4f texCoord; - texCoord[2] = 0.0; - texCoord[3] = 1.0; - SbVec3f point, normal; - - /////////////////////////////////////////////////////// - //----------------------------------------------------- -#define N_GEN_VERTEX(ls, pv,x,y,z,s,t,nx,ny,nz) \ - point.setValue((float)(x),(float)(y),(float)(z)); \ - normal.setValue((float)(nx),(float)(ny),(float)(nz)); \ - texCoord[0]=(float)(s); \ - texCoord[1]=(float)(t); \ - pv.setPoint(point); \ - pv.setNormal(normal); \ - pv.setTextureCoords(texCoord); \ - ls.push_back(pv); - //----------------------------------------------------- - /////////////////////////////////////////////////////// - if (fRmin.getNum()!=fRmax.getNum() || fRmax.getNum() != fDz.getNum()) { - return; - } - - int nSeg = fRmin.getNum()-1; - if (nSeg<1) { - return; - } - - for (int p=0;p<nSeg;p++) { - - double rMin1= fRmin[p]; - double rMin2= fRmin[p+1]; - - double rMax1= fRmax[p]; - double rMax2= fRmax[p+1]; - - double zMin = fDz[p]; - double zMax= fDz[p+1]; - - double deltaPhi = fDPhi.getValue()/NPHI; - double phi0 = fSPhi.getValue(); - double phi1 = phi0 + fDPhi.getValue(); - double cosPhi0 = cos(phi0); - double sinPhi0 = sin(phi0); - double cosPhi1 = cos(phi1); - double sinPhi1 = sin(phi1); - double cosDeltaPhi = cos(deltaPhi); - double sinDeltaPhi = sin(deltaPhi); - - int i; - double sinPhi; - double cosPhi; - - const bool noPhiCutout=fabs(fDPhi.getValue())==0.F || fabs(fabs(fDPhi.getValue())-2.0*M_PI)<0.01; // FIXME - better way to do this? - - // - // The outer surface! - // - double dR =rMax2-rMax1; - double dZ =zMax-zMin; - double cosTheta = -dR/sqrt(dR*dR+dZ*dZ); - double sinTheta = dZ/sqrt(dR*dR+dZ*dZ); - - sinPhi=sinPhi0; - cosPhi=cosPhi0; - for (i = 0; i<=NPHI; i++) { - N_GEN_VERTEX(vls,pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta); - N_GEN_VERTEX(vls,pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinTheta*cosPhi,sinTheta*sinPhi,cosTheta); - inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi); - } - - for(i = 0; i < ((int)vls.size() - 2); i += 2){ - fls.push_back(vls[i + 0]); - fls.push_back(vls[i + 1]); - fls.push_back(vls[i + 3]); - fls.push_back(vls[i + 2]); - } - vls.clear(); - - // - // The inner surface! - // - sinPhi=sinPhi0; - cosPhi=cosPhi0; - - dR =rMin2-rMin1; - dZ =zMax-zMin; - cosTheta = -dR/sqrt(dR*dR+dZ*dZ); - sinTheta = dZ/sqrt(dR*dR+dZ*dZ); - - for (i = 0; i<=NPHI; i++) { - N_GEN_VERTEX(vls,pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,-cosPhi*sinTheta,-sinPhi*sinTheta,-cosTheta); - N_GEN_VERTEX(vls,pv,rMin1*cosPhi,rMin1*sinPhi,zMin,1.0,1.0,-cosPhi*sinTheta,-sinPhi*sinTheta,-cosTheta); - inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi); - } - for(i = 0; i < ((int)vls.size() - 2); i += 2){ - fls.push_back(vls[i + 1]); - fls.push_back(vls[i + 0]); - fls.push_back(vls[i + 2]); - fls.push_back(vls[i + 3]); - } - vls.clear(); - - - if (!noPhiCutout) { - // - // The end - // - sinPhi=sinPhi0; - cosPhi=cosPhi0; - N_GEN_VERTEX(vls, pv,rMax2*cosPhi,rMax2*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0); - N_GEN_VERTEX(vls, pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0); - N_GEN_VERTEX(vls, pv,rMin2*cosPhi,rMin2*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0); - N_GEN_VERTEX(vls, pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0); - fls.push_back(vls[1]); - fls.push_back(vls[0]); - fls.push_back(vls[2]); - fls.push_back(vls[3]); - vls.clear(); - - // - // The other end - // - sinPhi=sinPhi1; - cosPhi=cosPhi1; - N_GEN_VERTEX(vls, pv,rMax2*cosPhi,rMax2*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0); - N_GEN_VERTEX(vls, pv,rMax1*cosPhi,rMax1*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0); - N_GEN_VERTEX(vls, pv,rMin2*cosPhi,rMin2*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0); - N_GEN_VERTEX(vls, pv,rMin1*cosPhi,rMin1*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0); - fls.push_back(vls[0]); - fls.push_back(vls[1]); - fls.push_back(vls[3]); - fls.push_back(vls[2]); - vls.clear(); - } - if (p==(nSeg-1)) { - // - // The outer surface at z=+PDZ - // - sinPhi=sinPhi0; - cosPhi=cosPhi0; - for (i = 0; i<=NPHI; i++) { - N_GEN_VERTEX(vls, pv,rMin2*cosPhi,rMin2*sinPhi,zMax,0.0,0.0,0,0,1); - N_GEN_VERTEX(vls, pv,rMax2*cosPhi,rMax2*sinPhi,zMax,1.0,1.0,0,0,1); - inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi); - } - for(i = 0; i < ((int)vls.size() - 2); i += 2){ - fls.push_back(vls[i + 0]); - fls.push_back(vls[i + 1]); - fls.push_back(vls[i + 3]); - fls.push_back(vls[i + 2]); - } - vls.clear(); - } - if (p==0) { - // - // The outer surface at z=-PDZ - // - sinPhi=sinPhi0; - cosPhi=cosPhi0; - for (i = 0; i<=NPHI; i++) { - N_GEN_VERTEX(vls, pv,rMin1*cosPhi,rMin1*sinPhi,zMin,0.0,0.0,0,0,-1); - N_GEN_VERTEX(vls, pv,rMax1*cosPhi,rMax1*sinPhi,zMin,1.0,1.0,0,0,-1); - inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi); - } - for(i = 0; i < ((int)vls.size() - 2); i += 2){ - fls.push_back(vls[i + 1]); - fls.push_back(vls[i + 0]); - fls.push_back(vls[i + 2]); - fls.push_back(vls[i + 3]); - } - vls.clear(); - } - } - /* - ********************************************* - After finish colecting points of quadrangles, - must be builded one monolit geometry, - with indexed triangles - ********************************************* - */ - int numFaces = fls.size() / 4; //Becouse used quadrangular primitives - if(numFaces < 0) - numFaces = 0; - - SoVertexProperty *vertices = new SoVertexProperty(); - for(int i = 0; i < (int)fls.size(); i++){ - vertices->vertex.set1Value (i, fls[i].getPoint()[0], - fls[i].getPoint()[1], - fls[i].getPoint()[2]); - } - fls.clear(); //clearing collected vertices - - int* faces = new int[5 * numFaces]; - fprintf(stderr, "\nallocate Faces: %i", numFaces); - for(int i = 0; i < numFaces; i++){ - faces[5 * i] = 4 * i; - faces[5 * i + 1] = 4 * i + 1; - faces[5 * i + 2] = 4 * i + 2; - faces[5 * i + 3] = 4 * i + 3; - faces[5 * i + 4] = -1; - } - - SoIndexedFaceSet * faceset = new SoIndexedFaceSet; - faceset->coordIndex.setValues(0, 5 * numFaces, faces); - delete [] faces; - faceset->vertexProperty = vertices; - alternateRep.setValue(faceset); - fprintf(stderr, "\n"); - /* - ********************************************* - Finish - ********************************************* - */ -} - -// clearAlternateRep -void SoPcons::clearAlternateRep() { - alternateRep.setValue(NULL); -} diff --git a/GeoModelVisualization/VP1HEPVis/src/SoPolyhedron.cxx b/GeoModelVisualization/GXHepVis/src/SoPolyhedron.cxx similarity index 90% rename from GeoModelVisualization/VP1HEPVis/src/SoPolyhedron.cxx rename to GeoModelVisualization/GXHepVis/src/SoPolyhedron.cxx index e49ebd5741dd6babc3b4ede902cddbbc5fce1abc..42c18a02f80bcdde6702888a031c22056545840f 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoPolyhedron.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoPolyhedron.cxx @@ -18,7 +18,7 @@ // // //////////////////////////////////////////////////////////////// -#include <VP1HEPVis/nodes/SoPolyhedron.h> +#include <GXHepVis/nodes/SoPolyhedron.h> #include <Inventor/SbBox.h> #include <Inventor/actions/SoAction.h> @@ -34,11 +34,7 @@ #include <Inventor/C/glue/gl.h> #include "SbMath.h" -#include <VP1HEPVis/SbPolyhedron.h> - -//// debug messages -//#include "VP1Base/VP1Msg.h" -//#include <QString> +#include <GXHepVis/SbPolyhedron.h> SO_NODE_SOURCE(SoPolyhedron) @@ -63,7 +59,6 @@ SoPolyhedron::SoPolyhedron( SO_NODE_CONSTRUCTOR(SoPolyhedron); // SO_NODE_ADD_FIELD(solid,(TRUE)); // SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE)); - SO_NODE_ADD_FIELD(alternateRep,(NULL)); setNodeType(EXTENSION); } ////////////////////////////////////////////////////////////////////////////// @@ -77,7 +72,6 @@ SoPolyhedron::SoPolyhedron( SO_NODE_CONSTRUCTOR(SoPolyhedron); // SO_NODE_ADD_FIELD(solid,(TRUE)); // SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE)); - SO_NODE_ADD_FIELD(alternateRep,(NULL)); m_polyhedron = new SbPolyhedron(aPolyhedron); setNodeType(EXTENSION); @@ -94,7 +88,6 @@ SoPolyhedron::SoPolyhedron( SO_NODE_CONSTRUCTOR(SoPolyhedron); // SO_NODE_ADD_FIELD(solid,(TRUE)); // SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE)); - SO_NODE_ADD_FIELD(alternateRep,(NULL)); m_polyhedron = new SbPolyhedron(*aPolyhedron); setNodeType(EXTENSION); @@ -374,55 +367,6 @@ void SoPolyhedron::getPrimitiveCount(SoGetPrimitiveCountAction * action) } //*/ -///* -void SoPolyhedron::generateAlternateRep() -{ - if (alternateRep.getValue()) - clearAlternateRep(); - if( m_polyhedron && ( m_polyhedron->GetNoFacets() > 0 ) ){ - //SoSeparator *sep = new SoSeparator; - SoVertexProperty *vertices = new SoVertexProperty(); - - //Retreive geometry from polyhedron - int vno = m_polyhedron->GetNoVertices(); - for(int i = 0; i < vno; i++){ - HVPoint3D vertex; - vertex = m_polyhedron->GetVertex(i + 1); - vertices->vertex.set1Value (i, vertex[0], vertex[1], vertex[2]); - } - - int fno = m_polyhedron->GetNoFacets(); - int fcr = 0; - int* aface = new int[8 * fno]; - for(int i = 0; i < fno; i++){ - int n, inodes[4]; - //SbVec3d nr = m_polyhedron->GetNormal(i + 1); // not used, gives warning, commenting out: - //--- - m_polyhedron->GetFacet(i + 1, n, inodes); - aface[fcr] = (inodes[0] <= vno) ? (inodes[0] - 1) : (0); fcr++; - aface[fcr] = (inodes[1] <= vno) ? (inodes[1] - 1) : (0); fcr++; - aface[fcr] = (inodes[2] <= vno) ? (inodes[2] - 1) : (0); fcr++; - if(n == 4) { aface[fcr] = (inodes[3] <= vno) ? (inodes[3] - 1) : (0); fcr++; } - aface[fcr] = -1; fcr++; - } - SoIndexedFaceSet * faceset = new SoIndexedFaceSet; - faceset->coordIndex.setValues(0, fcr, aface); - delete [] aface; - faceset->vertexProperty = vertices; - //sep->addChild(faceset); - alternateRep.setValue(faceset); - } -} -//*/ - -//____________________________________________________________________ -///* -void SoPolyhedron::clearAlternateRep() -{ - alternateRep.setValue(NULL); - //Hmm... no ref/unref?? -} -//*/ //____________________________________________________________________ ///* diff --git a/GeoModelVisualization/VP1HEPVis/src/SoTessellated.cxx b/GeoModelVisualization/GXHepVis/src/SoTessellated.cxx similarity index 72% rename from GeoModelVisualization/VP1HEPVis/src/SoTessellated.cxx rename to GeoModelVisualization/GXHepVis/src/SoTessellated.cxx index 343500effff8a45f862f84a93183fd11d3d50fde..5863d7a54e4d9e16b09222aa07872c0f6f28a446 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoTessellated.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoTessellated.cxx @@ -2,7 +2,7 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "VP1HEPVis/nodes/SoTessellated.h" +#include "GXHepVis/nodes/SoTessellated.h" #include <Inventor/SbBox.h> #include <Inventor/actions/SoPickAction.h> @@ -31,7 +31,6 @@ SoTessellated::SoTessellated() SO_NODE_CONSTRUCTOR(SoTessellated); SO_NODE_ADD_FIELD(drawEdgeLines, (false)); SO_NODE_ADD_FIELD(forceEdgeLinesInBaseColour, (true)); - SO_NODE_ADD_FIELD(alternateRep,(NULL)); setNodeType(EXTENSION); } @@ -193,65 +192,3 @@ void SoTessellated::computeBBox(SoAction *, SbBox3f &box, SbVec3f ¢er ){ center = m_center; } -//____________________________________________________________________ -void SoTessellated::generateAlternateRep() -{ - if(m_points.size()==0) - setupDefaultPoints(); - if (alternateRep.getValue()) - clearAlternateRep(); - - SoSeparator * sep = new SoSeparator; - - // Faceset representing the shape - SoVertexProperty* vertices = new SoVertexProperty(); - vertices->normalBinding.setValue( SoVertexProperty::PER_VERTEX ); - vertices->materialBinding.setValue( SoVertexProperty::OVERALL ); // so the face is enlightened on both face - for(size_t i=0;i<m_normals.size();++i) - vertices->vertex.set1Value(i,m_points[i*3+0],m_points[i*3+1],m_points[i*3+2]); - SoIndexedFaceSet* faceset = new SoIndexedFaceSet; - int j=0; - for(size_t i=0;i<m_normals.size();++i) { - faceset->coordIndex.set1Value(j++,i); - if((i>1) && ((i-2)%3==0)) { - faceset->coordIndex.set1Value(j++,SO_END_FACE_INDEX); - } - } - - faceset->vertexProperty = vertices; - sep->addChild(faceset); - - // Lineset representing the outline - // - // -- ToDo: this can be optimized. We are currently drawing edges twice - // -- and we could also eliminate 'diagonal' lines coming from - // -- quadrangular shapes - // - if (drawEdgeLines.getValue()) { - SoVertexProperty* verticesL = new SoVertexProperty(); - SoIndexedLineSet* lineset = new SoIndexedLineSet; - int kk=0, jj=0; - for(size_t i=0;i<m_points.size()-9;i+=9) { - verticesL->vertex.set1Value(kk,m_points[i],m_points[i+1],m_points[i+2]); - lineset->coordIndex.set1Value(jj++,kk++); - verticesL->vertex.set1Value(kk,m_points[i+3],m_points[i+4],m_points[i+5]); - lineset->coordIndex.set1Value(jj++,kk++); - verticesL->vertex.set1Value(kk,m_points[i+6],m_points[i+7],m_points[i+8]); - lineset->coordIndex.set1Value(jj++,kk++); - verticesL->vertex.set1Value(kk,m_points[i],m_points[i+1],m_points[i+2]); - lineset->coordIndex.set1Value(jj++,kk++); - lineset->coordIndex.set1Value(jj++,SO_END_LINE_INDEX); - } - lineset->vertexProperty = verticesL; - sep->addChild(lineset); - } - - alternateRep.setValue(sep); -} - -//____________________________________________________________________ -void SoTessellated::clearAlternateRep() -{ - alternateRep.setValue(NULL); -} - diff --git a/GeoModelVisualization/VP1HEPVis/src/SoTorus.cxx b/GeoModelVisualization/GXHepVis/src/SoTorus.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SoTorus.cxx rename to GeoModelVisualization/GXHepVis/src/SoTorus.cxx index 26faa10750a1d180a36443e428e32bd7b480e1d2..19714a2adaefffa459760d7e82c657a0640d42b5 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoTorus.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoTorus.cxx @@ -11,7 +11,7 @@ /*--------------------------------------------------------------------------*/ // this : -#include <VP1HEPVis/nodes/SoTorus.h> +#include <GXHepVis/nodes/SoTorus.h> #include "RevolutionSurfaceUtil.h" #include <cassert> @@ -80,7 +80,6 @@ SoTorus::SoTorus() SO_NODE_ADD_FIELD(fDPhi, ((float)(2*M_PI))); SO_NODE_ADD_FIELD(smoothDraw, (TRUE)); SO_NODE_ADD_FIELD(pOverrideNPhi, (0)); - SO_NODE_ADD_FIELD(alternateRep, (NULL)); m_children = new SoChildList(this); setNodeType(EXTENSION); @@ -792,22 +791,6 @@ void SoTorus::generateChildren() { */ } -// generateAlternateRep -void SoTorus::generateAlternateRep() { - - // This routine sets the alternate representation to the child - // list of this mode. - - if (m_children->getLength() == 0) generateChildren(); - updateChildren(); - alternateRep.setValue((SoSeparator *) ( *m_children)[0]); -} - -// clearAlternateRep -void SoTorus::clearAlternateRep() { - alternateRep.setValue(NULL); -} - // #undef SPHERE_NUM_SLICES // #undef SPHERE_NUM_STACKS diff --git a/GeoModelVisualization/VP1HEPVis/src/SoTransparency.cxx b/GeoModelVisualization/GXHepVis/src/SoTransparency.cxx similarity index 98% rename from GeoModelVisualization/VP1HEPVis/src/SoTransparency.cxx rename to GeoModelVisualization/GXHepVis/src/SoTransparency.cxx index ac1a86dda98903e2e81bb50fe78f3abce1daa022..2b4fa5d99b7e9b4d8b504c2dc14c917561af63ff 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoTransparency.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoTransparency.cxx @@ -16,7 +16,7 @@ // // //////////////////////////////////////////////////////////////// -#include "VP1HEPVis/nodes/SoTransparency.h" +#include "GXHepVis/nodes/SoTransparency.h" #include <Inventor/actions/SoCallbackAction.h> #include <Inventor/actions/SoGLRenderAction.h> #include <Inventor/bundles/SoMaterialBundle.h> diff --git a/GeoModelVisualization/VP1HEPVis/src/SoTubs.cxx b/GeoModelVisualization/GXHepVis/src/SoTubs.cxx similarity index 97% rename from GeoModelVisualization/VP1HEPVis/src/SoTubs.cxx rename to GeoModelVisualization/GXHepVis/src/SoTubs.cxx index e945d4f388e55d5dfe746e183a3cb4ea7b7dcaff..d01baad39d545647967ff773c10ec33a196fe588 100644 --- a/GeoModelVisualization/VP1HEPVis/src/SoTubs.cxx +++ b/GeoModelVisualization/GXHepVis/src/SoTubs.cxx @@ -10,7 +10,7 @@ /* */ /*--------------------------------------------------------------------------*/ -#include <VP1HEPVis/nodes/SoTubs.h> +#include <GXHepVis/nodes/SoTubs.h> #include "RevolutionSurfaceUtil.h" #include <cassert> @@ -50,7 +50,6 @@ SoTubs::SoTubs() { SO_NODE_ADD_FIELD(pSPhi, (0)); SO_NODE_ADD_FIELD(pDPhi, ((float)(2*M_PI))); SO_NODE_ADD_FIELD(pOverrideNPhi, (0)); - SO_NODE_ADD_FIELD(alternateRep, (NULL)); SO_NODE_ADD_FIELD(drawEdgeLines, (false)); m_children = new SoChildList(this); @@ -559,18 +558,3 @@ void SoTubs::generateChildren() { m_children->append(sep); } -// generateAlternateRep -void SoTubs::generateAlternateRep() { - - // This routine sets the alternate representation to the child - // list of this mode. - - if (m_children->getLength() == 0) generateChildren(); - updateChildren(); - alternateRep.setValue((SoSeparator *) ( *m_children)[0]); -} - -// clearAlternateRep -void SoTubs::clearAlternateRep() { - alternateRep.setValue(NULL); -} diff --git a/GeoModelVisualization/VP1HEPVis/src/gl2ps.cxx b/GeoModelVisualization/GXHepVis/src/gl2ps.cxx similarity index 99% rename from GeoModelVisualization/VP1HEPVis/src/gl2ps.cxx rename to GeoModelVisualization/GXHepVis/src/gl2ps.cxx index c2834d5ddebf5a3a6e8f174ad89ba4e185cda416..696dc4df83239a860f850ca044b30407f6d8fc57 100644 --- a/GeoModelVisualization/VP1HEPVis/src/gl2ps.cxx +++ b/GeoModelVisualization/GXHepVis/src/gl2ps.cxx @@ -37,7 +37,7 @@ // #define GL2PS_HAVE_ZLIB -#include "VP1HEPVis/gl2ps.h" +#include "GXHepVis/gl2ps.h" #include <math.h> #include <string.h> diff --git a/GeoModelVisualization/GXHitDisplaySystems/CMakeLists.txt b/GeoModelVisualization/GXHitDisplaySystems/CMakeLists.txt index e1e2c7d83af1ec32068af5a2fb2726219f93bd0f..09d9d8a87af0d190f6424dca3868dcdb44b1227b 100644 --- a/GeoModelVisualization/GXHitDisplaySystems/CMakeLists.txt +++ b/GeoModelVisualization/GXHitDisplaySystems/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -8,12 +8,12 @@ find_package (HDF5 REQUIRED) # Add the library. add_library( GXHitDisplaySystems SHARED ${SOURCES} ${HEADERS} ${UIS} ) target_link_libraries( GXHitDisplaySystems - PUBLIC Coin::Coin GXBase + PUBLIC Coin::Coin GXBase PRIVATE Qt${QT_VERSION}::Core Qt${QT_VERSION}::Widgets ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES} ) target_include_directories( GXHitDisplaySystems PUBLIC - ${HDF5_CXX_INCLUDE_DIRS} + ${HDF5_CXX_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GXHitDisplaySystems" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ${RCS} ) set_target_properties( GXHitDisplaySystems PROPERTIES diff --git a/GeoModelVisualization/GXTrackDisplaySystems/CMakeLists.txt b/GeoModelVisualization/GXTrackDisplaySystems/CMakeLists.txt index bc690cd322d977679d27a1ff98a6734f35dc6c00..690c605d6bad0cc2a928b1cd2777f5d65588b303 100644 --- a/GeoModelVisualization/GXTrackDisplaySystems/CMakeLists.txt +++ b/GeoModelVisualization/GXTrackDisplaySystems/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -8,12 +8,12 @@ file( GLOB UIS src/*.ui ) # Add the library. add_library( GXTrackDisplaySystems SHARED ${SOURCES} ${HEADERS} ${UIS} ) target_link_libraries( GXTrackDisplaySystems - PUBLIC Coin::Coin GXBase + PUBLIC Coin::Coin GXBase PRIVATE Qt${QT_VERSION}::Core Qt${QT_VERSION}::Widgets ${HDF5_LIBRARIES} ) target_include_directories( GXTrackDisplaySystems PUBLIC - ${HDF5_CXX_INCLUDE_DIRS} + ${HDF5_CXX_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "GXTrackDisplaySystems" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ${RCS} ) set_target_properties( GXTrackDisplaySystems PROPERTIES diff --git a/GeoModelVisualization/GeoModelExplorer/CMakeLists.txt b/GeoModelVisualization/GeoModelExplorer/CMakeLists.txt index 695376de66e41b81e109f7e6d6b10e884b1497c2..8243ed77fba0e770be78c9f9d59b67194b690107 100644 --- a/GeoModelVisualization/GeoModelExplorer/CMakeLists.txt +++ b/GeoModelVisualization/GeoModelExplorer/CMakeLists.txt @@ -1,5 +1,7 @@ # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +file( GLOB MANPAGES man/man1/* ) + # Add the executable. add_executable( gmex src/main.cxx ) @@ -15,3 +17,7 @@ install( TARGETS gmex EXPORT ${PROJECT_NAME}-export LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) + +install( FILES ${MANPAGES} + DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1 + COMPONENT Runtime ) diff --git a/GeoModelVisualization/GeoModelExplorer/man/man1/gmex.1 b/GeoModelVisualization/GeoModelExplorer/man/man1/gmex.1 new file mode 100644 index 0000000000000000000000000000000000000000..3c80de087689b6b0cb2b50638b616e27b30ba371 --- /dev/null +++ b/GeoModelVisualization/GeoModelExplorer/man/man1/gmex.1 @@ -0,0 +1,59 @@ +.\" Manpage for gmex. +.\" Contact geomodel-core-team@cern.ch to correct errors or typos. +.TH man 1 "01 Nov 2024" "6.5" "gmex man page" +.SH NAME +gmex \- The Geometry Explorer +.SH SYNOPSIS +gmex [input-file-1] [input-file-2] ... [plugin-1] [plugin-2] ... +.SH DESCRIPTION +gmex, the geometry explorer, is an interactive 3D graphics program which +renders geometry from plugins (shared object libraries which produce and +publish geometry in GeoModel format) or GeoModel geometries stored in +SQLite files (see gmcat(1)). Multiple files, multiple plugins, or a mix +can be provided to gmcat on the command line. + +Gmex is controlled by buttons on the right hand side of the display. +The most important of these are those displaying a hand, an arrow, and +an eye. The "eye" button brings the scene into scope. The arrow and hand +buttons toggle between interaction mode in which the mouse modifies +the camera position and angle, and selection mode in which the mouse +buttons select geometry. Geometry selection can trigger various actions, +depending on selected options. + +Gmex can co-display the results of gmclash, the clash detection system +(see gmclash(1)). To enable, launch the "clash point" system from the +main menu. + + + +.\" ==================================================================== +.SH "SEE ALSO" +.\" ==================================================================== +. +gmcat(1), gmclash(1), gmstatistics(1) + +.IR "geomodel.web.cern.ch" +is the location of the main documentation for the GeoModel Tools Suite +. +.SH BUGS +There are no known bugs, however gmex does rely on graphics acceleration +so the performance depends upon the windowing system, the GPU, the graphics +drivers, and their configuration. Performance under the Wayland flavor +of window manager on linux systems is poor, and the X-windows manager is +preferred. Users with NVidia GPUs should use the nvidia-settings utility +(see nvidia-settings(1)). +.SH AUTHORS +Primary authors are +.MT boudreau@\:pitt\:.edu +Joe Boudreau +.ME , +.MT Vakhtang.Tsulaia@\:cern\:.ch +Vakho Tsulaia +.ME , +.MT riccardomariabianchi@\:pitt\:.edu +Riccardo Maria Bianchi, +.ME +Thomas Kittelman, and +.MT edward.moyse@\:cern\:.ch +Edward Moyse +.ME . diff --git a/GeoModelVisualization/VP1Base/CMakeLists.txt b/GeoModelVisualization/VP1Base/CMakeLists.txt index ca2b6aba0e2e94d3986fa6d37a0d12773f78334c..acb7e4d3a38b17ba92f712f418b9f10046e77f30 100644 --- a/GeoModelVisualization/VP1Base/CMakeLists.txt +++ b/GeoModelVisualization/VP1Base/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -8,19 +8,19 @@ file( GLOB RCS src/*.qrc ) # Add the library. add_library( GXBase SHARED ${SOURCES} ${HEADERS} ${UIS} ${RCS} ) -if (GEOMODEL_USE_QT6) +if (GEOMODEL_USE_QT6) target_link_libraries( GXBase PUBLIC Coin::Coin Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::Core5Compat SoQt::SoQt - PRIVATE Qt${QT_VERSION}::PrintSupport Qt${QT_VERSION}::OpenGL GXHEPVis ) + PRIVATE Qt${QT_VERSION}::PrintSupport Qt${QT_VERSION}::OpenGL GXHepVis ) else() target_link_libraries( GXBase PUBLIC Coin::Coin Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets SoQt::SoQt - PRIVATE Qt${QT_VERSION}::PrintSupport Qt${QT_VERSION}::OpenGL GXHEPVis ) + PRIVATE Qt${QT_VERSION}::PrintSupport Qt${QT_VERSION}::OpenGL GXHepVis ) endif() target_include_directories( GXBase PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) target_compile_definitions( GXBase PUBLIC -DQT_NO_DEBUG_OUTPUT -DQT_NO_INFO_OUTPUT ) source_group( "VP1Base" FILES ${HEADERS} ) diff --git a/GeoModelVisualization/VP1Base/VP1Base/VP1ExaminerViewer.h b/GeoModelVisualization/VP1Base/VP1Base/VP1ExaminerViewer.h index 89ec8ac52672ed30cc311673699afdb905ebc8bb..bd2c7a55305b640db13fce0454fe2b258fc95dd1 100644 --- a/GeoModelVisualization/VP1Base/VP1Base/VP1ExaminerViewer.h +++ b/GeoModelVisualization/VP1Base/VP1Base/VP1ExaminerViewer.h @@ -71,8 +71,6 @@ public: void startTour(); bool startTourEachEvent() const; void startCustomTour(); - void dumpSceneToFile(QString filename="");//empty file names causes file dialog to be launched - void dumpSceneToVRMLFile(QString filename="");//empty file names causes file dialog to be launched void produceSVGImage(QString filename="");//empty file names causes file dialog to be launched void produceEPSImage(QString filename="");//empty file names causes file dialog to be launched diff --git a/GeoModelVisualization/VP1Base/src/VP1ExaminerViewer.cxx b/GeoModelVisualization/VP1Base/src/VP1ExaminerViewer.cxx index ed7847e276297cde379a6930d1f980f305800235..36d26574539a2a9b6fddf6a73fde562da1fcf669 100644 --- a/GeoModelVisualization/VP1Base/src/VP1ExaminerViewer.cxx +++ b/GeoModelVisualization/VP1Base/src/VP1ExaminerViewer.cxx @@ -27,9 +27,9 @@ #include "VP1Base/VP1Settings.h" #include "VP1Base/VP1CustomTourEditor.h" #include "VP1Base/VP1CustomStereoEditor.h" -#include "VP1HEPVis/VP1HEPVisUtils.h" -#include "VP1HEPVis/actions/SoGL2PSAction.h" -#include "VP1HEPVis/gl2ps.h" +#include "GXHepVis/GXHepVisUtils.h" +#include "GXHepVis/actions/SoGL2PSAction.h" +#include "GXHepVis/gl2ps.h" #include <Inventor/nodes/SoSphere.h> #include <Inventor/nodes/SoGroup.h> @@ -83,8 +83,6 @@ public: popup_bgdColAction(0), popup_ambientLightAction(0), popup_focalLengthAction(0), - popup_dumpSceneAction(0), - popup_dumpSceneVRMLAction(0), popup_toSVGAction(0), popup_toEPSAction(0), popup_resetCameraAction(0), @@ -217,8 +215,6 @@ public: QAction* popup_bgdColAction; QAction* popup_ambientLightAction; QAction* popup_focalLengthAction; - QAction* popup_dumpSceneAction; - QAction* popup_dumpSceneVRMLAction; QAction* popup_toSVGAction; QAction* popup_toEPSAction; QAction* popup_resetCameraAction; @@ -1932,8 +1928,6 @@ bool VP1ExaminerViewer::Imp::ensureMenuInit() popup_hidedecorationsaction = advancedmenu->addAction("Hide &controls"); popup_headLightAction = advancedmenu->addAction("&Headlight"); popup_ambientLightAction = advancedmenu->addAction("dummy"); - popup_dumpSceneAction = advancedmenu->addAction("Dump &scene to file"); - popup_dumpSceneVRMLAction = advancedmenu->addAction("Dump &scene to VRML file"); popup_toSVGAction = advancedmenu->addAction("Produce SV&G image"); popup_toEPSAction = advancedmenu->addAction("Produce &EPS image"); @@ -2255,78 +2249,6 @@ void VP1ExaminerViewer::Imp::updatePopupMenuStates() } -//____________________________________________________________________ -void VP1ExaminerViewer::dumpSceneToFile(QString filename) -{ - VP1Msg::messageVerbose("VP1ExaminerViewer::dumpSceneToFile()"); - - SoNode * rootnode = getSceneGraph(); - if (!rootnode) - return; - - QWidget * w = getWidget(); - if (!w) - return; - - if(filename.isEmpty()) { - if (isAnimating()) - stopAnimating(); - filename = QFileDialog::getSaveFileName(w, "Select output file", - (m_d->lastDumpFile.isEmpty()?VP1Settings::defaultFileSelectDirectory():m_d->lastDumpFile), - "Inventor files (*.iv)",0,QFileDialog::DontResolveSymlinks); - if(filename.isEmpty()) - return; - if (!filename.endsWith(".iv")) - filename += ".iv"; - m_d->lastDumpFile=filename; - } - - SoGroup * standardisedRoot(0); - if ( rootnode->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) - standardisedRoot = VP1HEPVisUtils::convertToStandardScene(static_cast<SoGroup*>(rootnode)); - - if (standardisedRoot&&VP1QtInventorUtils::writeGraphToFile(standardisedRoot, filename)) - VP1Msg::messageDebug("VP1ExaminerViewer: Dumped scene to file "+filename); - else - VP1Msg::messageDebug("VP1ExaminerViewer: Error: Problems dumping scene to file "+filename); - -} - -void VP1ExaminerViewer::dumpSceneToVRMLFile(QString filename){ - VP1Msg::messageVerbose("VP1ExaminerViewer::dumpSceneToVRMLFile()"); - - SoNode * rootnode = getSceneGraph(); - if (!rootnode) - return; - - QWidget * w = getWidget(); - if (!w) - return; - - if(filename.isEmpty()) { - if (isAnimating()) - stopAnimating(); - filename = QFileDialog::getSaveFileName(w, "Select output file", - (m_d->lastDumpFile.isEmpty()?VP1Settings::defaultFileSelectDirectory():m_d->lastDumpFile), - "VRML2.0/X3D files (*.wrl)",0,QFileDialog::DontResolveSymlinks); - if(filename.isEmpty()) - return; - if (!filename.endsWith(".wrl")) - filename += ".wrl"; - m_d->lastDumpFile=filename; - } - - SoGroup * standardisedRoot(0); - if ( rootnode->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) - standardisedRoot = VP1HEPVisUtils::convertToStandardScene(static_cast<SoGroup*>(rootnode)); - - if (standardisedRoot&&VP1QtInventorUtils::writeGraphToVRMLFile(standardisedRoot, filename)) - VP1Msg::messageDebug("VP1ExaminerViewer: Dumped scene to VRML file "+filename); - else - VP1Msg::messageDebug("VP1ExaminerViewer: Error: Problems dumping scene to VRML file "+filename); - -} - //____________________________________________________________________ void VP1ExaminerViewer::produceSVGImage(QString filename) { @@ -2494,17 +2416,6 @@ void VP1ExaminerViewer::showPopupMenu() VP1Msg::messageVerbose("Anti-aliasing, done."); return; } - if ( selAct == m_d->popup_dumpSceneAction ) { - VP1Msg::messageVerbose("VP1ExaminerViewer::showPopupMenu Dump scene to an *.iv (OpenInventor) file"); - dumpSceneToFile(); - return; - } - if ( selAct == m_d->popup_dumpSceneVRMLAction ) { - VP1Msg::messageVerbose("VP1ExaminerViewer::showPopupMenu Dump scene to a *.wrl (VRML) file"); - dumpSceneToVRMLFile(); - return; - } - if ( selAct == m_d->popup_toSVGAction ) { VP1Msg::messageVerbose("VP1ExaminerViewer::showPopupMenu Produce SVG image"); produceSVGImage(); diff --git a/GeoModelVisualization/VP1Base/src/VP1MaterialButton.cxx b/GeoModelVisualization/VP1Base/src/VP1MaterialButton.cxx index 69cbbcf17c06e671a9a133690c136e00cfffde0b..2cc465e7d27ad1a4c0a9af6d92c2db27c574a016 100644 --- a/GeoModelVisualization/VP1Base/src/VP1MaterialButton.cxx +++ b/GeoModelVisualization/VP1Base/src/VP1MaterialButton.cxx @@ -248,10 +248,12 @@ void VP1MaterialButton::copyValuesFromMaterial(SoMaterial*m) } m->ref(); if (m->ambientColor.getNum()!=1 - ||m->diffuseColor.getNum()!=1 + ||(m->diffuseColor.getNum()!=1 + &&m->diffuseColor.getNum()!=2) ||m->specularColor.getNum()!=1 ||m->emissiveColor.getNum()!=1 - ||m->transparency.getNum()!=1 + ||(m->transparency.getNum()!=1 + &&m->transparency.getNum()!=2) ||m->shininess.getNum()!=1) { message("VP1MaterialButton::copyValuesFromMaterial Error: Passed material must have exactly one value in each of the 6 fields!!"); m->unrefNoDelete(); diff --git a/GeoModelVisualization/VP1GeometryPlugin/CMakeLists.txt b/GeoModelVisualization/VP1GeometryPlugin/CMakeLists.txt index 488841c6cf9c6a1a9bc195155b330ef233ad21b4..027c4f5cd2172cdafed26333617a51e83569f163 100644 --- a/GeoModelVisualization/VP1GeometryPlugin/CMakeLists.txt +++ b/GeoModelVisualization/VP1GeometryPlugin/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -11,7 +11,7 @@ target_link_libraries( GXGeometryPlugin PRIVATE GXGeometrySystems GXGuideLineSystems GXClashPointSystems GXHitDisplaySystems GXTrackDisplaySystems) target_include_directories( GXGeometryPlugin PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "VP1GeometryPlugin" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ) @@ -23,7 +23,8 @@ add_library( GeoModelVisualization::GXGeometryPlugin ALIAS GXGeometryPlugin ) install( TARGETS GXGeometryPlugin EXPORT ${PROJECT_NAME}-export LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/gxplugins - COMPONENT Runtime ) + COMPONENT Runtime + NAMELINK_COMPONENT Development ) install( FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/VP1GeometryPlugin COMPONENT Development ) diff --git a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt index a912560a308193c94e82447bcd5d3dc301478962..4c176d359ff44005d0e01ed97f8efce8380c7be4 100644 --- a/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt +++ b/GeoModelVisualization/VP1GeometrySystems/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -12,10 +12,10 @@ target_link_libraries( GXGeometrySystems PUBLIC Coin::Coin Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets GeoModelCore::GeoModelKernel GXBase PRIVATE nlohmann_json::nlohmann_json GeoModelIO::GeoModelRead - GeoModelIO::GeoModelWrite GeoModelIO::GeoModelDBManager GXHEPVis ) + GeoModelIO::GeoModelWrite GeoModelIO::GeoModelDBManager GXHepVis ) target_include_directories( GXGeometrySystems PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) target_compile_definitions( GXGeometrySystems PRIVATE GEOMODEL_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" ) source_group( "VP1GeometrySystems" FILES ${HEADERS} ) diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/DumpShape.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/DumpShape.h index 0e6c30ccc16612203c39661b544b78e578d423a2..3a00473826a988740b968b76d6ae86c95c2b5e20 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/DumpShape.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/DumpShape.h @@ -13,16 +13,24 @@ // Original code by Joe Boudreau, adapted // // in the present form by T. Kittelmann // // // +// Updates: // +// Jun 2024, Rui Xue // +// Add new method for Virtual Surface. // +// // +// // /////////////////////////////////////////////////////////////////////// #include <QStringList> class GeoShape; +class GeoVSurfaceShape; class DumpShape { public: static QStringList shapeToStringList(const GeoShape* shape); + static QStringList shapeToStringList(const GeoVSurfaceShape* surf_shape); + private: DumpShape(){}; diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/PhiSectorManager.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/PhiSectorManager.h index 896f9e11021a9b0c823fffbd9cf2a103a0ce3fa1..4d380652f28ff91425446e72d5218c7ca2fdf88d 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/PhiSectorManager.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/PhiSectorManager.h @@ -41,6 +41,8 @@ public: //Volume handles first call this method to figure out what kind of volume they are: int getVolumeType(const SbMatrix& transform, SoNode * shape) const; + + int getSurfaceType(const SbMatrix& transform, SoNode * shape) const; //The return value, iphi, indicates the type: // 0...(nphi-1): Volume with a bounding box not around the Z axis. // -1: Volume has bounding box around Z-axis, but can not be dynamically altered (probably boolean) diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/SoVisualizeAction.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/SoVisualizeAction.h index 247d8ca6cff9b83d5b7ffa3b4aa660fa132d0913..4ca3f7994a0423e98d51a149da1ddb6cf740cc81 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/SoVisualizeAction.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/SoVisualizeAction.h @@ -15,6 +15,12 @@ #include "GeoModelKernel/GeoShapeAction.h" class SoShape; +#include <Inventor/nodes/SoSeparator.h> +#include <Inventor/nodes/SoMaterialBinding.h> +#include <Inventor/nodes/SoNormal.h> +#include <Inventor/nodes/SoNormalBinding.h> +#include <Inventor/nodes/SoCoordinate3.h> +#include <Inventor/nodes/SoFaceSet.h> class SoVisualizeAction : public GeoShapeAction { @@ -49,9 +55,23 @@ public: virtual void handleTessellatedSolid (const GeoTessellatedSolid *); virtual void handleGenericTrap (const GeoGenericTrap *); + + virtual void handleRectSurface (const GeoRectSurface *); + + virtual void handleTrapezoidSurface (const GeoTrapezoidSurface *); + + virtual void handleAnnulusSurface (const GeoAnnulusSurface *); + + virtual void handleDiamondSurface (const GeoDiamondSurface *); SoShape * getShape() { return m_shape; } void reset() { m_shape = 0; } + void reset_separator() { vs_shape = new SoSeparator; } + SoNormal * getNormal() { return surfaceNorms; } + SoNormalBinding * getNormalBinding() { return surfBinding; } + SoMaterialBinding * getMaterialBinding() { return surfMaterialBinding; } + SoCoordinate3 * getCoords() { return coords; } + SoSeparator * getVSurfaceShape() { return vs_shape; } private: @@ -59,11 +79,13 @@ private: const SoVisualizeAction & operator=(const SoVisualizeAction &); SoShape *m_shape; -}; - - - - + SoNormal *surfaceNorms = new SoNormal; + SoNormalBinding* surfBinding = new SoNormalBinding; + SoMaterialBinding* surfMaterialBinding = new SoMaterialBinding; + SoCoordinate3 *coords; + SoSeparator* vs_shape = new SoSeparator; + +}; #endif diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VP1GeometrySystem.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VP1GeometrySystem.h index 139ac0f36f770adc46807d4ab7c1bc65f4002f68..4f11ebb4b73c7cd1621fa24294373f8f34f48e04 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VP1GeometrySystem.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VP1GeometrySystem.h @@ -18,7 +18,8 @@ // - Jul 2021, Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> // * Added the 'filter volumes' tool // * Added signal/slot to update transparency type in the 3D window -// +// - Jun 2024, Rui Xue <r.xue@cern.ch><rux23@pitt.edu> +// * Added methods to print out virtual surface information ///////////////////////////////////////////////////////////////////////// #include "VP1Base/IVP13DSystemSimple.h" @@ -26,12 +27,24 @@ #include "VP1GeometrySystems/VolumeHandle.h"//fixme #include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelKernel/GeoVSurface.h" #include <set> #include <map> #include <QStack> #include <QString> +#include <iostream> +#include <exception> +#include <sstream> + +#define THROW_EXCEPTION(MESSAGE) \ + { \ + std::stringstream except_str{}; \ + except_str<<__FILE__<<":"<<__LINE__<<" --- "; \ + except_str<<MESSAGE; \ + throw std::runtime_error(except_str.str()); \ + } diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandle.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandle.h index f21666c222b015f96787e75adceaed78229a53df..3a1d2de18fd0e4a76b78be79d5ec3ba272fc583b 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandle.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandle.h @@ -9,6 +9,7 @@ #include "VP1GeometrySystems/VP1GeoFlags.h" #include "GeoModelKernel/GeoVPhysVol.h" +#include "GeoModelKernel/GeoVSurface.h" #include <QString> //Only initialises child classes on demand. And even then their SoNodes are not initialised until they must be shown. @@ -16,6 +17,7 @@ class VolumeHandleSharedData; class SoMaterial; class SoSeparator; class GeoMaterial; +class SoMaterialBinding; #include <Inventor/C/errors/debugerror.h> #include <Inventor/SbMatrix.h> @@ -26,6 +28,9 @@ public: VolumeHandle(VolumeHandleSharedData * ,VolumeHandle * parent, const PVConstLink&,int childNumber, const SbMatrix& accumTrans = SbMatrix() ); + VolumeHandle(VolumeHandleSharedData * ,VolumeHandle * parent, const VSConstLink&,int childNumber, + const SbMatrix& accumTrans = SbMatrix() ); + virtual ~VolumeHandle();//lots of stuff to do here! //Used (recursively) upon deletion (never delete before children are deleted). void initialiseChildren(); @@ -40,6 +45,7 @@ public: quint32 hashID() const;//For vp1 persistification PVConstLink geoPVConstLink() const; + VSConstLink geoVSConstLink() const; const GeoMaterial * geoMaterial() const; std::string getNameStdString() const; @@ -121,6 +127,7 @@ private: bool haveParentsNotExpanded() const; void attachAllContractedChildren();//also checks children of expanded children (recursively). void detachAllContractedChildren();//also checks children of expanded children (recursively). + //SoMaterial * SurfaceMaterial() const; }; ///////////////// diff --git a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandleSharedData.h b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandleSharedData.h index 1ca256c3953fdb6b265bf36b7c2f6021df584343..1acd7d0db3e12e4280370af79355fcec2a3ffeda 100644 --- a/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandleSharedData.h +++ b/GeoModelVisualization/VP1GeometrySystems/VP1GeometrySystems/VolumeHandleSharedData.h @@ -9,8 +9,11 @@ //for all volume handle nodes under a given top-level handle. #include "GeoModelKernel/GeoVPhysVol.h" +#include "GeoModelKernel/GeoVSurface.h" #include "VP1GeometrySystems/VP1GeoFlags.h" +#include <Inventor/nodes/SoShape.h> #include <map> + class SoNode; class SoGroup; class SoSeparator; @@ -32,7 +35,7 @@ public: ~VolumeHandleSharedData(); void ref(); void unref(); - + //Fixme: Inline? PVConstLink geoPVConstLinkOfTreeTopsMother() const; PhiSectorManager* phiSectorManager() const; @@ -47,6 +50,8 @@ public: void removeZappedVolumesFromGui(VolumeHandle*); SoNode * toShapeNode(const PVConstLink& pV, bool *shapeIsKnown=nullptr);//Returns shape of pV->getLogVol() (uses shared instancing as appropriate) + + SoNode * toShapeNode(const VSConstLink& vS, SoSeparator* nodesep); SoNode * getSoCylinderOrientedLikeGeoTube(const double& radius, const double& halfLength);//(uses shared instancing as appropriate) void registerNodeSepForVolumeHandle(SoSeparator*,VolumeHandle*); diff --git a/GeoModelVisualization/VP1GeometrySystems/src/DumpShape.cxx b/GeoModelVisualization/VP1GeometrySystems/src/DumpShape.cxx index c505cbd1331712e31a04ae4d15b71587e6f0714b..18b48ee43e49f82eaa939783d46149e0f324ae13 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/DumpShape.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/DumpShape.cxx @@ -20,7 +20,13 @@ #include "GeoModelKernel/GeoShapeIntersection.h" #include "GeoModelKernel/GeoShapeSubtraction.h" #include "GeoModelKernel/GeoGenericTrap.h" +#include "GeoModelKernel/GeoVSurfaceShape.h" +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" +#include "GeoModelKernel/throwExcept.h" #include "Inventor/SbMatrix.h" #include <cassert> @@ -29,6 +35,57 @@ //TODO: Add support for the SimpleBREP GeoShape. //TODO: Add GeoTorus +QStringList DumpShape::shapeToStringList(const GeoVSurfaceShape* surf_shape) +{ + QStringList out; + static const double mm=1.0; + if(surf_shape->type() == "RectangleSurface"){ + const GeoRectSurface* rectsurf = dynamic_cast<const GeoRectSurface*>(surf_shape); + if(rectsurf){ + out << " =========> Rectangle Surface:"; + out << " X = "+QString::number(rectsurf->getXHalfLength()/mm)+" mm"; + out << " Y = "+QString::number(rectsurf->getYHalfLength()/mm)+" mm"; + } + } + else if(surf_shape->type() == "TrapezoidSurface"){ + const GeoTrapezoidSurface* trapezoid = dynamic_cast<const GeoTrapezoidSurface*>(surf_shape); + if(trapezoid){ + out << " =========> Trapezoid Surface:"; + out << " Short Half Base = "+QString::number(trapezoid->getXHalfLengthMin()/mm)+" mm"; + out << " Long Half Base = "+QString::number(trapezoid->getXHalfLengthMax()/mm)+" mm"; + out << " Height = "+QString::number(trapezoid->getYHalfLength()/mm)+" mm"; + } + } + else if(surf_shape->type() == "AnnulusSurface"){ + const GeoAnnulusSurface* annulus = dynamic_cast<const GeoAnnulusSurface*>(surf_shape); + if(annulus){ + out << " =========> Annulus Surface:"; + out << " Ox (Deviation in X-direction) = "+QString::number(annulus->getOx()/mm)+" mm"; + out << " Oy (Deviation in Y-direction) = "+QString::number(annulus->getOy()/mm)+" mm"; + out << " Inner Radius = "+QString::number(annulus->getRadiusIn()/mm)+" mm"; + out << " Outer Radius = "+QString::number(annulus->getRadiusOut()/mm)+" mm"; + out << " Phi (Span Angle) = "+QString::number(annulus->getPhi())+" rad"; + } + } + else if(surf_shape->type() == "DiamondSurface"){ + const GeoDiamondSurface* diamond = dynamic_cast<const GeoDiamondSurface*>(surf_shape); + if(diamond){ + out << " =========> Diamond Surface:"; + out << " X1 = "+QString::number(diamond->getXbottomHalf()/mm)+" mm"; + out << " X2 = "+QString::number(diamond->getXmidHalf()/mm)+" mm"; + out << " X3 = "+QString::number(diamond->getXtopHalf()/mm)+" mm"; + out << " Y1 = "+QString::number(diamond->getYbottomHalf()/mm)+" mm"; + out << " Y2 = "+QString::number(diamond->getYtopHalf()/mm)+" mm"; + } + } + else{ + //out << " =========> Unknown surface..."; + THROW_EXCEPTION("ERROR!!! VSurfaceShape is Unknown, cannot print out shape information!"); + } + + return out; +} + //____________________________________________________________________ QStringList DumpShape::shapeToStringList(const GeoShape* shape) { diff --git a/GeoModelVisualization/VP1GeometrySystems/src/PhiSectorManager.cxx b/GeoModelVisualization/VP1GeometrySystems/src/PhiSectorManager.cxx index cdd5f4f0894bc0f98a4ff4350dd455846de7d0cd..54a11293eac5580e00397bf87dadf756ab85abd3 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/PhiSectorManager.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/PhiSectorManager.cxx @@ -18,10 +18,10 @@ #include "VP1Base/VP1Msg.h" #include "VP1Base/IVP1System.h" -#include <VP1HEPVis/nodes/SoTubs.h> -#include "VP1HEPVis/nodes/SoPcons.h" -#include "VP1HEPVis/nodes/SoCons.h" -#include "VP1HEPVis/nodes/SoLAr.h" +#include <GXHepVis/nodes/SoTubs.h> +#include "GXHepVis/nodes/SoPcons.h" +#include "GXHepVis/nodes/SoCons.h" +#include "GXHepVis/nodes/SoLAr.h" #include <Inventor/nodes/SoSwitch.h> #include <Inventor/nodes/SoSeparator.h> @@ -261,6 +261,36 @@ int PhiSectorManager::getVolumeType(const SbMatrix& transform, SoNode * shape) c } +//____________________________________________________________________ + +int PhiSectorManager::getSurfaceType(const SbMatrix& transform, SoNode * shape) const { + + int iphi; + + float x = 0.0; + float y = 0.0; + float z = 0.0; + + float a = 0.0; + float b = 0.0; + float c = 0.0; + + a = x*transform[0][0] + y*transform[1][0] + z*transform[2][0] + transform[3][0]; + b = x*transform[0][1] + y*transform[1][1] + z*transform[2][1] + transform[3][1]; + c = x*transform[0][2] + y*transform[1][2] + z*transform[2][2] + transform[3][2]; + + if ( a == 0 && b == 0){ + iphi = -1; + } + else{ + double angle = atan2(b,a); + while (angle<0) angle+=(2*M_PI); + while (angle>=(2*M_PI)) angle-=(2*M_PI); + if (angle<0.0) angle=0.0; + iphi = static_cast<int>(36*angle/((2*M_PI))); + } + return iphi; +} //____________________________________________________________________ PhiSectorManager::PhiSectorManager(PhiSectionWidget * psw, IVP1System * sys, QObject*parent) : QObject(parent), m_d(new Imp) diff --git a/GeoModelVisualization/VP1GeometrySystems/src/SbPolyhedrizeAction.cxx b/GeoModelVisualization/VP1GeometrySystems/src/SbPolyhedrizeAction.cxx index 3f013f02df59fdd022991fad9d5ea2a4c69ad7a7..d392f748918b39fb2c0166f5f23142e94e4a5a47 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/SbPolyhedrizeAction.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/SbPolyhedrizeAction.cxx @@ -24,7 +24,7 @@ #include "GeoModelKernel/GeoDefinitions.h" #include "VP1GeometrySystems/SbPolyhedrizeAction.h" -#include "VP1HEPVis/SbPolyhedron.h" +#include "GXHepVis/SbPolyhedron.h" #include <map> @@ -53,7 +53,7 @@ void SbPolyhedrizeAction::handleShift(const GeoShapeShift *shift) // rotation.xz(),rotation.yz(),rotation.zz(),0, // 0,0,0,1)); SbVec3d trx(translation.x(),translation.y(),translation.z()); - #include <VP1HEPVis/SbRotation.h> //using doubles instead of floats. + #include <GXHepVis/SbRotation.h> //using doubles instead of floats. HEPVis::SbRotation rot(rotation(0,0),rotation(1,0),rotation(2,0),0, rotation(0,1),rotation(1,1),rotation(2,1),0, rotation(0,2),rotation(1,2),rotation(2,2),0, diff --git a/GeoModelVisualization/VP1GeometrySystems/src/SoVisualizeAction.cxx b/GeoModelVisualization/VP1GeometrySystems/src/SoVisualizeAction.cxx index f94ba74b92b306628ad8f67c64a5e69df778a02a..fe805f19576a8f09016621abc2901462b855c105 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/SoVisualizeAction.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/SoVisualizeAction.cxx @@ -16,42 +16,44 @@ #include "GeoModelKernel/GeoTessellatedSolid.h" #include "GeoModelKernel/GeoFacet.h" #include "GeoModelKernel/GeoGenericTrap.h" -#include "VP1HEPVis/nodes/SoTubs.h" -#include "VP1HEPVis/nodes/SoCons.h" -#include "VP1HEPVis/nodes/SoTorus.h" -#include "VP1HEPVis/nodes/SoGenericBox.h" -#include "VP1HEPVis/nodes/SoPcons.h" -#include "VP1HEPVis/nodes/SoTessellated.h" -#include "VP1HEPVis/SbPolyhedron.h" -#include "VP1HEPVis/nodes/SoLAr.h" -#include "VP1HEPVis/nodes/SoPolyhedron.h" -#include "VP1HEPVis/VP1HEPVisUtils.h" +#include "GXHepVis/nodes/SoTubs.h" +#include "GXHepVis/nodes/SoCons.h" +#include "GXHepVis/nodes/SoTorus.h" +#include "GXHepVis/nodes/SoGenericBox.h" +#include "GXHepVis/nodes/SoPcons.h" +#include "GXHepVis/nodes/SoTessellated.h" +#include "GXHepVis/SbPolyhedron.h" +#include "GXHepVis/nodes/SoLAr.h" +#include "GXHepVis/nodes/SoPolyhedron.h" +#include "GXHepVis/GXHepVisUtils.h" #include "VP1GeometrySystems/SbPolyhedrizeAction.h" #include <Inventor/nodes/SoSphere.h> + +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/GeoTrapezoidSurface.h" +#include "GeoModelKernel/GeoAnnulusSurface.h" +#include "GeoModelKernel/GeoDiamondSurface.h" // System of units #include "GeoModelKernel/Units.h" #define SYSTEM_OF_UNITS GeoModelKernelUnits // --> 'GeoModelKernelUnits::cm' #include <iostream> - - - +#include <cmath> SoVisualizeAction::SoVisualizeAction() : m_shape(0) { - VP1HEPVisUtils::initAllCustomClasses(); + GXHepVisUtils::initAllCustomClasses(); setDepthLimit(0); } SoVisualizeAction::~SoVisualizeAction() { - // Don't delete. Let ref count take care of the memory. + // NOTE: Don't delete. Let ref count take care of the memory. } void SoVisualizeAction::handleShape(const GeoShape *shape) { - //qDebug() << "SoVisualizeAction::handleShape"; // We don't recognize it. Try to polyhedrize it! SbPolyhedrizeAction a; shape->exec(&a); @@ -65,7 +67,6 @@ void SoVisualizeAction::handleShape(const GeoShape *shape) void SoVisualizeAction::handleBox(const GeoBox *box) { - //qDebug() << "SoVisualizeAction::handleBox"; SoGenericBox * gb = new SoGenericBox; gb->setParametersForBox( box->getXHalfLength(),box->getYHalfLength(),box->getZHalfLength() ); m_shape=gb; @@ -73,7 +74,6 @@ void SoVisualizeAction::handleBox(const GeoBox *box) void SoVisualizeAction::handleCons(const GeoCons *cons) { - //qDebug() << "SoVisualizeAction::handleCons"; SoCons::initClass(); SoCons *socons= new SoCons; socons->fRmin1 =cons->getRMin1(); @@ -89,7 +89,6 @@ void SoVisualizeAction::handleCons(const GeoCons *cons) void SoVisualizeAction::handleTorus(const GeoTorus *torus) { - //qDebug() << "SoVisualizeAction::handleTorus"; SoTorus::initClass(); SoTorus *sotorus= new SoTorus; sotorus->fRInner = torus->getRMin(); @@ -103,9 +102,6 @@ void SoVisualizeAction::handleTorus(const GeoTorus *torus) void SoVisualizeAction::handlePcon(const GeoPcon *pcon) { - - //qDebug() << "SoVisualizeAction::handlePcon"; - //Set up temporary data arrays for profile: float *z = new float[pcon->getNPlanes()]; float *rmn= new float[pcon->getNPlanes()]; @@ -136,7 +132,6 @@ void SoVisualizeAction::handlePcon(const GeoPcon *pcon) void SoVisualizeAction::handleTrap(const GeoTrap *trap) { - //qDebug() << "SoVisualizeAction::handleTrap"; SoGenericBox * gb = new SoGenericBox; gb->setParametersForTrapezoid(trap->getZHalfLength(), trap->getTheta(), trap->getPhi(), trap->getDydzn(), trap->getDxdyndzn(), trap->getDxdypdzn(), @@ -158,7 +153,6 @@ void SoVisualizeAction::handleTwistedTrap(const GeoTwistedTrap *twistedtrap) void SoVisualizeAction::handleTrd(const GeoTrd *trd) { - //qDebug() << "SoVisualizeAction::handleTrd"; SoGenericBox * gb = new SoGenericBox; gb->setParametersForTrd( trd->getXHalfLength1(), trd->getXHalfLength2(), trd->getYHalfLength1(), trd->getYHalfLength2(), @@ -168,7 +162,6 @@ void SoVisualizeAction::handleTrd(const GeoTrd *trd) void SoVisualizeAction::handleTube(const GeoTube *tube) { - //qDebug() << "SoVisualizeAction::handleTube"; SoTubs *sotubs= new SoTubs; sotubs->pRMin= tube->getRMin(); sotubs->pRMax= tube->getRMax(); @@ -180,7 +173,6 @@ void SoVisualizeAction::handleTube(const GeoTube *tube) void SoVisualizeAction::handleTubs(const GeoTubs *tubs) { - //qDebug() << "SoVisualizeAction::handleTubs"; SoTubs *sotubs= new SoTubs; sotubs->pRMin= tubs->getRMin(); sotubs->pRMax= tubs->getRMax(); @@ -192,9 +184,7 @@ void SoVisualizeAction::handleTubs(const GeoTubs *tubs) void SoVisualizeAction::handleSimplePolygonBrep(const GeoSimplePolygonBrep *brep) { - //qDebug() << "SoVisualizeAction::handleSimplePolygonBrep"; //Fixme: Detect if order of vertices is the wrong way around... and reorder if necessary. - double dz = brep->getDZ(); std::vector<double> x, y; for(unsigned int i=0; i<brep->getNVertices(); ++i) @@ -210,8 +200,6 @@ void SoVisualizeAction::handleSimplePolygonBrep(const GeoSimplePolygonBrep *brep void SoVisualizeAction::handleTessellatedSolid (const GeoTessellatedSolid* geoTessellated) { - //std::cout << "SoVisualizeAction::handleTessellatedSolid" << std::endl; - SoTessellated * soTessellated = new SoTessellated; //std::cout << "\tn. facets: " << geoTessellated->getNumberOfFacets() << std::endl; @@ -270,7 +258,6 @@ void SoVisualizeAction::handleTessellatedSolid (const GeoTessellatedSolid* geoTe void SoVisualizeAction::handleGenericTrap(const GeoGenericTrap *gentrap) { - //qDebug() << "SoVisualizeAction::handleGenericTrap"; SoGenericBox * gb = new SoGenericBox; const GeoGenericTrapVertices& trapVertices = gentrap->getVertices(); double dZ = gentrap->getZHalfLength(); @@ -284,3 +271,289 @@ void SoVisualizeAction::handleGenericTrap(const GeoGenericTrap *gentrap) trapVertices[0].x(),trapVertices[0].y(),dZ); m_shape=gb; } + +// In the near future, I should separate those handle VS methods from SoVisualizationAction + +void SoVisualizeAction::handleRectSurface(const GeoRectSurface *surf) +{ + static float norms[2][3]={ + {0.0, 0.0, -1.0}, {0.0, 0.0, 1.0} + }; + surfaceNorms->vector.setValues(0, 2, norms); + surfBinding->value = SoNormalBinding::PER_FACE; + surfMaterialBinding->value = SoMaterialBinding::PER_FACE; + + float dx = surf->getXHalfLength(); + float dy = surf->getYHalfLength(); + + float vertices[8][3]={ + {dx,dy,0}, {-dx,dy,0},{-dx,-dy,0}, {dx,-dy,0}, + {dx,dy,0}, {-dx,dy,0},{-dx,-dy,0}, {dx,-dy,0} + }; + SoCoordinate3 *coords_ = new SoCoordinate3; + coords_->point.setValues(0,8, vertices); + coords = coords_; + + int32_t numvertices[2] = {4, 4}; + SoFaceSet * faceset = new SoFaceSet; + faceset->numVertices.setValues(0, 2, numvertices); + m_shape = faceset; + + vs_shape->addChild(surfaceNorms); + vs_shape->addChild(surfBinding); + vs_shape->addChild(surfMaterialBinding); + vs_shape->addChild(coords); + vs_shape->addChild(m_shape); + +} + +void SoVisualizeAction::handleTrapezoidSurface(const GeoTrapezoidSurface *surf) +{ + static float norms[2][3]={ + {0.0, 0.0, -1.0}, {0.0, 0.0, 1.0} + }; + surfaceNorms->vector.setValues(0, 2, norms); + surfBinding->value = SoNormalBinding::PER_FACE; + surfMaterialBinding->value = SoMaterialBinding::PER_FACE; + + float dx_min = surf->getXHalfLengthMin(); + float dx_max = surf->getXHalfLengthMax(); + float dy = surf->getYHalfLength(); + + float vertices[8][3]={ + {dx_max,dy,0}, {-dx_max,dy,0},{-dx_min,-dy,0}, {dx_min,-dy,0}, + {dx_max,dy,0}, {-dx_max,dy,0},{-dx_min,-dy,0}, {dx_min,-dy,0} + }; + SoCoordinate3 *coords_ = new SoCoordinate3; + coords_->point.setValues(0,8, vertices); + coords = coords_; + + int32_t numvertices[2] = {4, 4}; + SoFaceSet * faceset = new SoFaceSet; + faceset->numVertices.setValues(0, 2, numvertices); + m_shape = faceset; + + vs_shape->addChild(surfaceNorms); + vs_shape->addChild(surfBinding); + vs_shape->addChild(surfMaterialBinding); + vs_shape->addChild(coords); + vs_shape->addChild(m_shape); +} + +// Here I'm working on AnnulusSurface, also, this part should be separated from SoVisualizationAction + +// use static keyword to make the function private +static int initialize_N(double theta){ + int N; + + if (theta <= 0.0){ + throw std::runtime_error("Theta cannot be zero or negative"); + } + else{ + double phi = 2.0*M_PI; + double angle = fmod(theta, phi); // make sure that angle is between 0 and 2*pi + if (angle != 0.0){ + N = 4*std::ceil(360*angle/phi); // 360 is the number of rectangles in the circle + // 4 is the number of vertices in each rectangle + } + else{ + N = 360; + } + } + return N; +} + +static int which_quadrant(double theta){ + double phi = 2.0*M_PI; + double angle = fmod(theta, phi); + if (angle < phi/4.0){ + return 0; + } else if (angle < 2.0*phi/4.0){ + return 1; + } else if (angle < 3.0*phi/4.0){ + return 2; + } else { + return 3; + } +} + +static double solve_X(double k, double Ox, double Oy, double radius, double theta){ + if(std::isinf(k) || k > 1e5 || k < -1e5){ + return Ox; + } + else{ + double a = 1.0 + k*k; + double b = 2*k*Oy - 2*k*k*Ox; + double c = k*k*Ox*Ox - 2*k*Ox*Oy + Oy*Oy - radius*radius; + double delta = b*b - 4*a*c; + + if (delta < 0){ + throw std::runtime_error("No solution for X"); + } + + double X1 = (-b + sqrt(delta))/(2*a); + double X2 = (-b - sqrt(delta))/(2*a); + + int quadrant = which_quadrant(theta); + if (quadrant == 0 || quadrant == 3){ + return X1; + } else { + return X2; + } + } +} + +static double solve_Y(double X, double k, double Ox, double Oy, double radius, double theta){ + if(std::isinf(k)){ + int quadrant = which_quadrant(theta); + if (quadrant == 0 || quadrant == 1){ + return sqrt(radius*radius - X*X); + } else { + return -sqrt(radius*radius - X*X); + } + } + else if (k > 1e5 || k < -1e5){ + int quadrant = which_quadrant(theta); + if (quadrant == 0 || quadrant == 1){ + return sqrt(radius*radius - X*X); + } else { + return -sqrt(radius*radius - X*X); + } + } + else{ + return k*X + Oy - k*Ox; + } +} + +static void tiny_rect( double Ox, double Oy, double radius_in, double radius_out, double angle, double delta_angle, float **rect_vertices ){ + + double X1, X2, X3, X4, Y1, Y2, Y3, Y4; + double k = tan(angle); + double k_plus = tan(angle + delta_angle); + + X1 = solve_X(k, Ox, Oy, radius_out, angle); + Y1 = solve_Y(X1, k, Ox, Oy, radius_out, angle); + + X2 = solve_X(k_plus, Ox, Oy, radius_out, angle + delta_angle); + Y2 = solve_Y(X2, k_plus, Ox, Oy, radius_out, angle + delta_angle); + + X3 = solve_X(k_plus, Ox, Oy, radius_in, angle + delta_angle); + Y3 = solve_Y(X3, k_plus, Ox, Oy, radius_in, angle + delta_angle); + + X4 = solve_X(k, Ox, Oy, radius_in, angle); + Y4 = solve_Y(X4, k, Ox, Oy, radius_in, angle); + + // generate vertices for the tiny rectangle + rect_vertices[0][0] = static_cast<float>(X1); + rect_vertices[0][1] = static_cast<float>(Y1); + rect_vertices[0][2] = 0.0f; + + rect_vertices[1][0] = static_cast<float>(X2); + rect_vertices[1][1] = static_cast<float>(Y2); + rect_vertices[1][2] = 0.0f; + + rect_vertices[2][0] = static_cast<float>(X3); + rect_vertices[2][1] = static_cast<float>(Y3); + rect_vertices[2][2] = 0.0f; + + rect_vertices[3][0] = static_cast<float>(X4); + rect_vertices[3][1] = static_cast<float>(Y4); + rect_vertices[3][2] = 0.0f; +} + +void SoVisualizeAction::handleAnnulusSurface(const GeoAnnulusSurface *surf) +{ + + double real_theta = surf->getPhi(); + double Ox = surf->getOx(); + double Oy = surf->getOy(); + double radius_in = surf->getRadiusIn(); + double radius_out = surf->getRadiusOut(); + double angle; + int n = initialize_N(real_theta); // initialize the number of rectangles, also make sure that real theta is positive + + int quotient = floor(real_theta/(2.0*M_PI)); + double theta = real_theta - quotient*2.0*M_PI; + if (theta == 0.0){ + theta = 2.0*M_PI; + } + double delta_angle = theta/n; + + // size of rect_vertices is 4x3 + float **rect_vertices = new float*[4]; + for (int i = 0; i < 4; ++i) { + rect_vertices[i] = new float[3]; + } + + float vertices[8][3]; + + // add material (fake material, for drawing purposes) bindings to the surface + surfMaterialBinding->value = SoMaterialBinding::PER_FACE; + vs_shape->addChild(surfMaterialBinding); + + // set the surface normal properties + static float norms[2][3]={ + {0.0, 0.0, -1.0}, {0.0, 0.0, 1.0} + }; + surfaceNorms->vector.setValues(0, 2, norms); + surfBinding->value = SoNormalBinding::PER_FACE; + vs_shape->addChild(surfaceNorms); + vs_shape->addChild(surfBinding); + SoCoordinate3 *coords = new SoCoordinate3; + // Add coordinates & faceSet child for each rectangle + for(int i = 0; i < n; i++){ + angle = 0.0 + i*delta_angle; + tiny_rect(Ox, Oy, radius_in, radius_out, angle, delta_angle, rect_vertices); + + SoCoordinate3 *coords = new SoCoordinate3; + SoFaceSet *faceSet= new SoFaceSet; + + for (int i = 0; i < 2; i++){ + for (int j = 0; j < 4; j++){ + for (int k = 0; k < 3; k++){ + vertices[i*4 + j][k] = rect_vertices[j][k]; + } + } + } + coords->point.setValues(0, 8, vertices); // front side + back side = 8 vertices + int32_t numvertices[2] = {4, 4}; + faceSet->numVertices.setValues(0, 2, numvertices); + vs_shape->addChild(coords); + vs_shape->addChild(faceSet); + } +} + +void SoVisualizeAction::handleDiamondSurface(const GeoDiamondSurface *surf) +{ + static float norms[2][3]={ + {0.0, 0.0, -1.0}, {0.0, 0.0, 1.0} + }; + surfaceNorms->vector.setValues(0, 2, norms); + surfBinding->value = SoNormalBinding::PER_FACE; + surfMaterialBinding->value = SoMaterialBinding::PER_FACE; + + float dx1 = surf->getXbottomHalf(); + float dx2 = surf->getXmidHalf(); + float dx3 = surf->getXtopHalf(); + float dy1 = surf->getYbottomHalf(); + float dy2 = surf->getYtopHalf(); + + float vertices[12][3]={ + {dx3,dy2,0}, {-dx3,dy2,0},{-dx2,0,0}, {-dx1,-dy1,0}, {dx1,-dy1,0}, {dx2,0,0}, + {dx3,dy2,0}, {-dx3,dy2,0},{-dx2,0,0}, {-dx1,-dy1,0}, {dx1,-dy1,0}, {dx2,0,0} + }; + SoCoordinate3 *coords_ = new SoCoordinate3; + coords_->point.setValues(0,12, vertices); + coords = coords_; + + int32_t numvertices[2] = {6, 6}; + SoFaceSet * faceset = new SoFaceSet; + faceset->numVertices.setValues(0, 2, numvertices); + m_shape = faceset; + + vs_shape->addChild(surfaceNorms); + vs_shape->addChild(surfBinding); + vs_shape->addChild(surfMaterialBinding); + vs_shape->addChild(coords); + vs_shape->addChild(m_shape); +} \ No newline at end of file diff --git a/GeoModelVisualization/VP1GeometrySystems/src/VP1GeometrySystem.cxx b/GeoModelVisualization/VP1GeometrySystems/src/VP1GeometrySystem.cxx index 6b4b49449017df47475b96e9c820b8da52031d3a..e6402e77ca0b23fe466bc658f12d46c8daf33292 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/VP1GeometrySystem.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/VP1GeometrySystem.cxx @@ -19,7 +19,8 @@ // - Jul 2021, Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> // * Added the 'filter volumes' tool // * Added signal/slot to update transparency type in the 3D window -// +// - Jun 2024, Rui Xue <r.xue@cern.ch><rux23@pitt.edu> +// * Added methods to print out virtual surface information ///////////////////////////////////////////////////////////////////////// // local includes @@ -59,7 +60,8 @@ #include <Inventor/nodes/SoLightModel.h> #include <Inventor/nodes/SoTransform.h> #include <Inventor/nodes/SoScale.h> - +#include <Inventor/nodes/SoSelection.h> +#include <Inventor/nodes/SoFaceSet.h> // GeoModelCore includes #include "GeoModelKernel/GeoVolumeCursor.h" #include "GeoModelKernel/GeoPrintGraphAction.h" @@ -398,6 +400,9 @@ void VP1GeometrySystem::buildPermanentSceneGraph(StoreGateSvc*/*detstore*/, SoSe found = true; //We did... now, time to extract info: + if(av.getVolume() == nullptr) { + THROW_EXCEPTION(" \n \n ERROR!!! \n Virtual Surface Cannot Serve As TreeTop Info \n \n"); + } subsys->treetopinfo.resize(subsys->treetopinfo.size()+1); subsys->treetopinfo.back().pV = av.getVolume(); subsys->treetopinfo.back().xf = av.getTransform(); @@ -703,7 +708,6 @@ void VP1GeometrySystem::userPickedNode(SoNode* , SoPath *pickedPath) // all phi-slices of the part gets highlighted (since more than one // soshape node represents the volume). - VP1Msg::messageDebug("VP1GeometrySystem::userPickedNode()"); if (pickedPath->getNodeFromTail(0)->getTypeId()==SoCylinder::getClassTypeId()) @@ -715,8 +719,18 @@ void VP1GeometrySystem::userPickedNode(SoNode* , SoPath *pickedPath) } SoSeparator * nodesep(0); - - if (pickedPath->getNodeFromTail(1)->getTypeId()==SoSeparator::getClassTypeId() + + if (pickedPath->getNodeFromTail(0)->getTypeId()==SoFaceSet::getClassTypeId() + && pickedPath->getNodeFromTail(1)->getTypeId()==SoSeparator::getClassTypeId() + && pickedPath->getNodeFromTail(2)->getTypeId()==SoSelection::getClassTypeId()){ + + //Scenario 0: this is a virtual surface + nodesep = static_cast<SoSeparator*>(pickedPath->getNodeFromTail(3)); + pickedPath->pop(); + pickedPath->pop(); + pickedPath->pop(); + } + else if (pickedPath->getNodeFromTail(1)->getTypeId()==SoSeparator::getClassTypeId() && pickedPath->getNodeFromTail(2)->getTypeId()==SoSwitch::getClassTypeId() && pickedPath->getNodeFromTail(3)->getTypeId()==SoSeparator::getClassTypeId()) { @@ -883,13 +897,19 @@ void VP1GeometrySystem::userPickedNode(SoNode* , SoPath *pickedPath) message("===> Selected Node: "+volhandle->getName()); if (m_d->controller->printInfoOnClick_Shape()) { - foreach (QString str, DumpShape::shapeToStringList(volhandle->geoPVConstLink()->getLogVol()->getShape())) - message(str); - } + if(volhandle->geoPVConstLink()){ + foreach (QString str, DumpShape::shapeToStringList(volhandle->geoPVConstLink()->getLogVol()->getShape())) + message(str);} + else{ + foreach (QString str, DumpShape::shapeToStringList(volhandle->geoVSConstLink()->getShape())) + message(str);} + } if (m_d->controller->printInfoOnClick_Material()) { + message("===> Material:"); + if(volhandle->geoPVConstLink()){ const GeoMaterial* mat = volhandle->geoMaterial(); - message("===> Material:"); + QStringList out; out << VP1GeomUtils::geoMaterialToStringList(mat); message(" "+out.join(" ")); @@ -905,6 +925,10 @@ void VP1GeometrySystem::userPickedNode(SoNode* , SoPath *pickedPath) } else { message(" (the material has no elements defined)"); } + } + else{ + message(" Virtual Surface has no material."); + } } if ( m_d->controller->printInfoOnClick_CopyNumber() ) { @@ -966,21 +990,32 @@ void VP1GeometrySystem::userPickedNode(SoNode* , SoPath *pickedPath) } if (m_d->controller->printInfoOnClick_Tree()) { - std::ostringstream str; - GeoPrintGraphAction pg(str); - volhandle->geoPVConstLink()->exec(&pg); message("===> Tree:"); - foreach (QString line, QString(str.str().c_str()).split("\n")) - message(" "+line); + if(volhandle->geoPVConstLink()){ + std::ostringstream str; + GeoPrintGraphAction pg(str); + volhandle->geoPVConstLink()->exec(&pg); + foreach (QString line, QString(str.str().c_str()).split("\n")) + message(" "+line); + } + else{ + message(" Virtual Surface has no child node."); + } } if (m_d->controller->printInfoOnClick_Mass()) { //FIXME: Move the mass calculations to the volume handles, and let //the common data cache some of the volume information by //logVolume). - message("===> Total Mass <==="); - message("Inclusive "+QString::number(Imp::inclusiveMass(volhandle->geoPVConstLink())/SYSTEM_OF_UNITS::kilogram)+" kg"); - message("Exclusive "+QString::number(Imp::exclusiveMass(volhandle->geoPVConstLink())/SYSTEM_OF_UNITS::kilogram)+" kg"); + if(volhandle->geoPVConstLink()){ + message("===> Total Mass <==="); + message("Inclusive "+QString::number(Imp::inclusiveMass(volhandle->geoPVConstLink())/SYSTEM_OF_UNITS::kilogram)+" kg"); + message("Exclusive "+QString::number(Imp::exclusiveMass(volhandle->geoPVConstLink())/SYSTEM_OF_UNITS::kilogram)+" kg"); + } + else{ + message("===> Total Mass: "); + message(" Virtual Surface has no mass."); + } } } @@ -1120,15 +1155,16 @@ double VP1GeometrySystem::Imp::inclusiveMass(const PVConstLink& pv) { GeoVolumeCursor av(pv); while (!av.atEnd()) { - std::string materialName=av.getVolume()->getLogVol()->getMaterial()->getName(); - - if (QString(materialName.c_str()).endsWith("Ether") || QString(materialName.c_str()).endsWith("HyperUranium")) { - // Do nothing. These are not real volumes. - } - else { - double delta = inclusiveMass(av.getVolume()) - (volume(av.getVolume())*density); - mass += delta; - } + if(av.getVolume()){ + std::string materialName=av.getVolume()->getLogVol()->getMaterial()->getName(); + if (QString(materialName.c_str()).endsWith("Ether") || QString(materialName.c_str()).endsWith("HyperUranium")) { + // Do nothing. These are not real volumes. + } + else { + double delta = inclusiveMass(av.getVolume()) - (volume(av.getVolume())*density); + mass += delta; + } + } av.next(); } return mass; diff --git a/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandle.cxx b/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandle.cxx index 804eede1d8bfb26f859b79a8b0f86ad50a5b51f0..5187866794cf130d9e4f52538479fa9135266f51 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandle.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandle.cxx @@ -13,12 +13,13 @@ #include "VP1Base/VP1Msg.h" // #include "VP1Base/VP1QtInventorUtils.h" //#include "VP1Utils/VP1LinAlgUtils.h" -#include "VP1HEPVis/nodes/SoTransparency.h" -#include "VP1HEPVis/nodes/SoPolyhedron.h" -#include "VP1HEPVis/nodes/SoPcons.h" -#include "VP1HEPVis/VP1HEPVisUtils.h" +#include "GXHepVis/nodes/SoTransparency.h" +#include "GXHepVis/nodes/SoPolyhedron.h" +#include "GXHepVis/nodes/SoPcons.h" +#include "GXHepVis/GXHepVisUtils.h" #include "GeoModelKernel/GeoVolumeCursor.h" +#include "GeoModelKernel/GeoSurfaceCursor.h" #include "GeoModelKernel/GeoShapeShift.h" #include "GeoModelKernel/GeoTube.h" #include "GeoModelKernel/GeoTubs.h" @@ -40,14 +41,22 @@ #include <QMap> #include <QDataStream> #include <unistd.h> +#include "GeoModelKernel/GeoRectSurface.h" +#include "GeoModelKernel/Units.h" +using namespace GeoModelKernelUnits; //____________________________________________________________________ class VolumeHandle::Imp { public: Imp(VolumeHandleSharedData * the_cd, const PVConstLink& the_pV, const SbMatrix& the_ac) : commondata(the_cd), pV(the_pV),accumTrans(the_ac),attachsepHelper(0),attachlabelSepHelper(0),nodesep(0), material(0), label_sep(0), labels(0), isattached(false) {} - + //overload Imp constructor + Imp(VolumeHandleSharedData * the_cd, const VSConstLink& the_vS, const SbMatrix& the_ac) + : commondata(the_cd), vS(the_vS),accumTrans(the_ac),attachsepHelper(0),attachlabelSepHelper(0),nodesep(0), material(0), label_sep(0), labels(0), isattached(false) {} + VolumeHandleSharedData * commondata; PVConstLink pV; + VSConstLink vS; + const SbMatrix accumTrans;//FIXME: Use pointer - and free once children are created AND nodesep has been build. Or just construct on the fly! VP1ExtraSepLayerHelper * attachsepHelper; @@ -91,8 +100,9 @@ QDataStream & operator>> ( QDataStream & in, VolumeHandle::Imp::VolState & vs ) //____________________________________________________________________ VolumeHandle::VolumeHandle(VolumeHandleSharedData * cd,VolumeHandle * parent, const PVConstLink& pV, int childNumber, const SbMatrix& accumTrans) - : m_d(new Imp(cd,pV,accumTrans)), m_childNumber(childNumber), m_nchildren(childNumber>=0?pV->getNChildVols():0), m_parent(parent), - m_state(VP1GeoFlags::CONTRACTED) +: m_d(new Imp(cd,pV,accumTrans)), m_childNumber(childNumber), m_nchildren(childNumber>=0?pV->getNChildVols():0), m_parent(parent), + //m_d(new Imp(cd,pV,accumTrans)), m_childNumber(childNumber), m_nchildren(childNumber>=0?3:0), m_parent(parent), + m_state(VP1GeoFlags::CONTRACTED) { if (cd) { cd->ref(); @@ -101,6 +111,17 @@ VolumeHandle::VolumeHandle(VolumeHandleSharedData * cd,VolumeHandle * parent, co } } +//overload VolumeHandle +VolumeHandle::VolumeHandle(VolumeHandleSharedData * cd,VolumeHandle * parent, const VSConstLink& vS, int childNumber, const SbMatrix& accumTrans) +: m_d(new Imp(cd,vS,accumTrans)), m_childNumber(childNumber), m_nchildren(childNumber>=0?vS->getNChildVols():0), m_parent(parent), + m_state(VP1GeoFlags::CONTRACTED) +{ + if (cd) { + cd->ref(); + if (!haveParentsNotExpanded()) + m_d->attach(this); + } +} //____________________________________________________________________ VolumeHandle::~VolumeHandle() { @@ -131,10 +152,11 @@ void VolumeHandle::initialiseChildren() return; assert(m_nchildren); - + //Loop over children: m_children.reserve(m_nchildren); unsigned ichild(0); + GeoVolumeCursor av(m_d->pV); while (!av.atEnd()) { @@ -146,13 +168,20 @@ void VolumeHandle::initialiseChildren() mtx(0,3),mtx(1,3),mtx(2,3),mtx(3,3)); matr.multRight(m_d->accumTrans); - m_children.push_back(new VolumeHandle(m_d->commondata,this,av.getVolume(),ichild++,matr)); + + if(av.getVolume()){ + //cursor at physics volume + m_children.push_back(new VolumeHandle(m_d->commondata,this,av.getVolume(),ichild++,matr)); + } + else{ + //cursor at virtual surface volume + m_children.push_back(new VolumeHandle(m_d->commondata,this,av.getSurface(),ichild++,matr)); + } m_children.back()->expandMothersRecursivelyToNonEther(); - av.next(); + av.next(); } - + assert(ichild==m_nchildren&&m_children.size()==m_nchildren); - } //____________________________________________________________________ @@ -161,10 +190,20 @@ PVConstLink VolumeHandle::geoPVConstLink() const return m_d->pV; } +VSConstLink VolumeHandle::geoVSConstLink() const +{ + return m_d->vS; +} + //____________________________________________________________________ QString VolumeHandle::getName() const { - return m_d->pV->getLogVol()->getName().c_str(); + if(m_d->pV){ + return m_d->pV->getLogVol()->getName().c_str(); + } + else{ + return m_d->vS->getShape()->type().c_str(); + } } //____________________________________________________________________ @@ -182,15 +221,32 @@ bool VolumeHandle::hasName(const std::string& n) const //____________________________________________________________________ SoMaterial * VolumeHandle::material() { + if(m_d->pV){ VP1Msg::messageDebug2("VolumeHandle::material() - LogVol name: " + QString::fromStdString(m_d->pV->getLogVol()->getName())); + } // if it's not the first time here and // the material has been assigned already, then return that if (m_d->material) return m_d->material; - // if it's the first timne here, the material has not been assigned yet, then... - //Then, see if the "databases" of defined volumes/material know about this volume: + + if(!m_d->pV){ + SoMaterial *surf_material = new SoMaterial; + static float colors[2][3] = { + {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0} + }; + static float transps[2] = {0.6, 0.6}; + + surf_material->diffuseColor.setValues(0, 2, colors); + surf_material->transparency.setValues(0, 2, transps); + m_d->material = surf_material; +// m_d->material = SurfaceMaterial(); + assert(m_d->material); + m_d->material->ref(); + return m_d->material; + } + SoMaterial * mat = m_d->commondata->volVisAttributes()->get(m_d->pV->getLogVol()->getName()); if (mat) { m_d->material = mat; @@ -216,7 +272,7 @@ SoMaterial * VolumeHandle::material() m_d->material->ref(); return m_d->material; } - + if (m_parent) { m_d->material = m_parent->material(); assert(m_d->material); @@ -229,6 +285,7 @@ SoMaterial * VolumeHandle::material() m_d->material->ref(); return m_d->material; } + //____________________________________________________________________ SoSeparator * VolumeHandle::nodeSoSeparator() const @@ -238,7 +295,7 @@ SoSeparator * VolumeHandle::nodeSoSeparator() const //____________________________________________________________________ void VolumeHandle::ensureBuildNodeSep() -{ +{ VP1Msg::messageDebug3("VolumeHandle::ensureBuildNodeSep()"); if (m_d->nodesep && m_d->label_sep) return; @@ -250,7 +307,7 @@ void VolumeHandle::ensureBuildNodeSep() // m_d->nodesep->renderCaching.setValue(SoSeparator::ON); // m_d->nodesep->boundingBoxCaching.setValue(SoSeparator::ON); m_d->nodesep->ref();//Since we are keeping it around irrespective of whether it is attached or not. - + //Transform: { SoTransform *xf=new SoTransform(); @@ -258,10 +315,18 @@ void VolumeHandle::ensureBuildNodeSep() m_d->nodesep->addChild(xf); } - //VP1Msg::messageDebug("calling toShapeNode()..."); - bool shapeIsKnown; - SoNode * shape = m_d->commondata->toShapeNode(m_d->pV, &shapeIsKnown);//NB: Ignore contained transformation of GeoShapeShifts. + bool shapeIsKnown=true; + + SoNode * shape = nullptr; + if(m_d->pV){ + shape = m_d->commondata->toShapeNode(m_d->pV, &shapeIsKnown);//NB: Ignore contained transformation of GeoShapeShifts. + } + else{ + shape = m_d->commondata->toShapeNode(m_d->vS, m_d->nodesep); + shapeIsKnown = true; + } + static const char *unknownShapeTextureFile[]={"/usr/share/gmex/unknownShape.jpg","/usr/local/share/gmex/unknownShape.jpg"}; SoTexture2 *skin=nullptr; if (!shapeIsKnown) { @@ -281,40 +346,50 @@ void VolumeHandle::ensureBuildNodeSep() } //What phi sector do we belong in? - int iphi = m_d->commondata->phiSectorManager()->getVolumeType(m_d->accumTrans, shape); - - if (iphi >= -1 ) { - //VP1Msg::messageDebug("Cylinders [iphi >= -1]..."); - //Substitute shapes that are essentially cylinders with such. This - //can be done safely since this tube won't need - //phi-slicing and is done to gain render performance. - if ( m_d->pV->getLogVol()->getShape()->typeID()==GeoTube::getClassTypeID() ) - { - //VP1Msg::messageDebug("GeoTube..."); - const GeoTube * geotube = static_cast<const GeoTube*>(m_d->pV->getLogVol()->getShape()); - if (geotube->getRMin()==0.0) - shape = m_d->commondata->getSoCylinderOrientedLikeGeoTube(geotube->getRMax(),geotube->getZHalfLength()); - } - else if ( m_d->pV->getLogVol()->getShape()->typeID()==GeoTubs::getClassTypeID() ) - { - //VP1Msg::messageDebug("GeoTubs..."); - const GeoTubs * geotubs = static_cast<const GeoTubs*>(m_d->pV->getLogVol()->getShape()); - if (geotubs->getRMin()==0.0 && geotubs->getDPhi() >= 2*M_PI-1.0e-6) - shape = m_d->commondata->getSoCylinderOrientedLikeGeoTube(geotubs->getRMax(),geotubs->getZHalfLength()); - } + int iphi; + if (m_d -> pV){ + iphi = m_d->commondata->phiSectorManager()->getVolumeType(m_d->accumTrans, shape); } + else{ + iphi = m_d->commondata->phiSectorManager()->getSurfaceType(m_d->accumTrans, shape); + } + // SKIP FOR VIRTUAL SURFACE + if(m_d->pV){ + if (iphi >= -1 ) { + //VP1Msg::messageDebug("Cylinders [iphi >= -1]..."); + //Substitute shapes that are essentially cylinders with such. This + //can be done safely since this tube won't need + //phi-slicing and is done to gain render performance. + + if ( m_d->pV->getLogVol()->getShape()->typeID()==GeoTube::getClassTypeID() ) + { + //VP1Msg::messageDebug("GeoTube..."); + const GeoTube * geotube = static_cast<const GeoTube*>(m_d->pV->getLogVol()->getShape()); + if (geotube->getRMin()==0.0) + shape = m_d->commondata->getSoCylinderOrientedLikeGeoTube(geotube->getRMax(),geotube->getZHalfLength()); + } + else if ( m_d->pV->getLogVol()->getShape()->typeID()==GeoTubs::getClassTypeID() ) + { + //VP1Msg::messageDebug("GeoTubs..."); + const GeoTubs * geotubs = static_cast<const GeoTubs*>(m_d->pV->getLogVol()->getShape()); + if (geotubs->getRMin()==0.0 && geotubs->getDPhi() >= 2*M_PI-1.0e-6) + shape = m_d->commondata->getSoCylinderOrientedLikeGeoTube(geotubs->getRMax(),geotubs->getZHalfLength()); + } + } + //In the case of a GeoShapeShift we add its contained transformation here: //Fixme: Remember to use this extra transformation for phisector cuts also! - if (m_d->pV->getLogVol()->getShape()->typeID()==GeoShapeShift::getClassTypeID()) { - const GeoTrf::Transform3D::MatrixType &mtx=dynamic_cast<const GeoShapeShift*>(m_d->pV->getLogVol()->getShape())->getX().matrix(); - SbMatrix matr(mtx(0,0),mtx(1,0),mtx(2,0),mtx(3,0), // Beware, conventions - mtx(0,1),mtx(1,1),mtx(2,1),mtx(3,1), // differ! - mtx(0,2),mtx(1,2),mtx(2,2),mtx(3,2), - mtx(0,3),mtx(1,3),mtx(2,3),mtx(3,3)); - SoTransform *xf=new SoTransform(); - m_d->nodesep->addChild(xf); - xf->setMatrix(matr); + if (m_d->pV->getLogVol()->getShape()->typeID()==GeoShapeShift::getClassTypeID()) { + const GeoTrf::Transform3D::MatrixType &mtx=dynamic_cast<const GeoShapeShift*>(m_d->pV->getLogVol()->getShape())->getX().matrix(); + SbMatrix matr(mtx(0,0),mtx(1,0),mtx(2,0),mtx(3,0), // Beware, conventions + mtx(0,1),mtx(1,1),mtx(2,1),mtx(3,1), // differ! + mtx(0,2),mtx(1,2),mtx(2,2),mtx(3,2), + mtx(0,3),mtx(1,3),mtx(2,3),mtx(3,3)); + SoTransform *xf=new SoTransform(); + m_d->nodesep->addChild(xf); + xf->setMatrix(matr); + } } //Add shape child(ren) and get the separator (helper) where we attach the nodesep when volume is visible: if (iphi >= -1) { @@ -344,7 +419,7 @@ void VolumeHandle::ensureBuildNodeSep() //____________________________________________________________________ void VolumeHandle::Imp::attach(VolumeHandle*vh) -{ +{ VP1Msg::messageDebug3("VolumeHandle::Imp::attach() - name: " + vh->getName()); if (!isattached) { vh->ensureBuildNodeSep(); @@ -473,9 +548,9 @@ bool VolumeHandle::haveParentsNotExpanded() const //____________________________________________________________________ void VolumeHandle::attachAllContractedChildren() { - if (!m_nchildren) return; + if (!childrenAreInitialised()) initialiseChildren(); @@ -558,23 +633,42 @@ bool VolumeHandle::isAttached() const //____________________________________________________________________ const GeoMaterial * VolumeHandle::geoMaterial() const { + if(!geoPVConstLink()){ + + GeoElement *oxygen = new GeoElement("Oxygen", "O", 19, 39*gram/mole); + GeoElement *nitrogen = new GeoElement("Nitrogen", "N", 7, 14*gram/mole); + GeoElement *argon = new GeoElement("Argon", "Ar", 18, 40*gram/mole); + GeoElement *aluminium = new GeoElement("Aluminium", "Al", 13, 26*gram/mole); + + // Define Air: + double densityOfAir = 1.2E-3*gram/cm3; // g/cm^3 + GeoMaterial *Air = new GeoMaterial("Air",densityOfAir); + Air->add(oxygen,2*0.21); // diatomic oxygen 21% by volume. + Air->add(nitrogen,2*0.78); // diatomic nitrogen 78% by volume. + Air->add(argon,0.01); // monoatomic argon 78% by volume. + Air->lock(); + + return Air; + } return geoPVConstLink()->getLogVol()->getMaterial(); } //____________________________________________________________________ bool VolumeHandle::isEther() const { + if(!m_d->pV){ + return false; + } return QString(geoMaterial()->getName().c_str()).endsWith("Ether") || QString(geoMaterial()->getName().c_str()).endsWith("HyperUranium"); } //____________________________________________________________________ void VolumeHandle::expandMothersRecursivelyToNonEther() { - if (!nChildren()||!isEther()) { return; } - + setState(VP1GeoFlags::ZAPPED); initialiseChildren(); VolumeHandleListItr childItrE = m_children.end(); @@ -655,7 +749,7 @@ VolumeHandle::Imp::VolState VolumeHandle::Imp::getChildStates(const VolumeHandle //____________________________________________________________________ void VolumeHandle::Imp::applyChildStates(const VolState& vs,VolumeHandle*theclass) -{ +{ bool hasExpandedChildren = !vs.m_expandedChildren.isEmpty(); bool hasZappedChildren = !vs.m_zappedChildren.isEmpty(); if (!hasExpandedChildren&&!hasZappedChildren) @@ -665,6 +759,7 @@ void VolumeHandle::Imp::applyChildStates(const VolState& vs,VolumeHandle*theclas QSet<quint32>::const_iterator zapItr, zapItrEnd = vs.m_zappedChildren.end(); theclass->initialiseChildren(); + VolumeHandleListConstItr it, itE = theclass->m_children.end(); for (it = theclass->m_children.begin(); it!=itE; ++it) { quint32 id = (*it)->hashID(); @@ -705,7 +800,7 @@ bool VolumeHandle::Imp::hasNonStandardShapeChildren(const SoGroup*g) //____________________________________________________________________ bool VolumeHandle::isInitialisedAndHasNonStandardShape() const { - VP1HEPVisUtils::initAllCustomClasses(); + GXHepVisUtils::initAllCustomClasses(); return m_d->nodesep ? Imp::hasNonStandardShapeChildren(m_d->nodesep) : false; } diff --git a/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandleSharedData.cxx b/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandleSharedData.cxx index 0ff86e8b5382444c4e2b2d758dacb57d0e4ac2a2..211d8af01d0f54a147606d489521444d42529715 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandleSharedData.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/VolumeHandleSharedData.cxx @@ -9,17 +9,19 @@ #include "GeoModelKernel/GeoVPhysVol.h" #include "GeoModelKernel/GeoShapeShift.h" -#include "VP1HEPVis/nodes/SoGenericBox.h" -#include "VP1HEPVis/nodes/SoTubs.h" -#include "VP1HEPVis/nodes/SoPcons.h" -#include "VP1HEPVis/nodes/SoTessellated.h" +#include "GXHepVis/nodes/SoGenericBox.h" +#include "GXHepVis/nodes/SoTubs.h" +#include "GXHepVis/nodes/SoPcons.h" +#include "GXHepVis/nodes/SoTessellated.h" #include <Inventor/nodes/SoCylinder.h> #include <Inventor/nodes/SoRotationXYZ.h> #include <Inventor/nodes/SoSeparator.h> +#include <Inventor/nodes/SoSelection.h> -#include <map> +#include <map> +#include <iostream> //____________________________________________________________________ class VolumeHandleSharedData::Imp { public: @@ -136,25 +138,38 @@ void VolumeHandleSharedData::registerNodeSepForVolumeHandle(SoSeparator*n,Volume //_____________________________________________________________________________________ void VolumeHandleSharedData::setShowVolumeOutlines(SoGroup*nodegroup,bool showvol) { - for (int i = 0; i<nodegroup->getNumChildren();++i) { - SoNode * n = nodegroup->getChild(i); - if (n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId())) { - if (static_cast<SoGenericBox*>(n)->drawEdgeLines.getValue()!=showvol) - static_cast<SoGenericBox*>(n)->drawEdgeLines.setValue(showvol); - } else if (n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId())) { - if (static_cast<SoTubs*>(n)->drawEdgeLines.getValue()!=showvol){ - static_cast<SoTubs*>(n)->drawEdgeLines.setValue(showvol); + for (int i = 0; i < nodegroup->getNumChildren(); ++i) + { + SoNode *n = nodegroup->getChild(i); + if (n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId())) + { + if (static_cast<SoGenericBox *>(n)->drawEdgeLines.getValue() != showvol) + static_cast<SoGenericBox *>(n)->drawEdgeLines.setValue(showvol); + } + else if (n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId())) + { + if (static_cast<SoTubs *>(n)->drawEdgeLines.getValue() != showvol) + { + static_cast<SoTubs *>(n)->drawEdgeLines.setValue(showvol); } - } else if (n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId())) { - if (static_cast<SoPcons*>(n)->drawEdgeLines.getValue()!=showvol){ - static_cast<SoPcons*>(n)->drawEdgeLines.setValue(showvol); + } + else if (n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId())) + { + if (static_cast<SoPcons *>(n)->drawEdgeLines.getValue() != showvol) + { + static_cast<SoPcons *>(n)->drawEdgeLines.setValue(showvol); } - } else if (n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId())) { - if (static_cast<SoTessellated*>(n)->drawEdgeLines.getValue()!=showvol){ - static_cast<SoTessellated*>(n)->drawEdgeLines.setValue(showvol); + } + else if (n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId())) + { + if (static_cast<SoTessellated *>(n)->drawEdgeLines.getValue() != showvol) + { + static_cast<SoTessellated *>(n)->drawEdgeLines.setValue(showvol); } - } else if (n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) { - setShowVolumeOutlines(static_cast<SoGroup*>(n),showvol); + } + else if (n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) + { + setShowVolumeOutlines(static_cast<SoGroup *>(n), showvol); } } } @@ -196,6 +211,23 @@ SoNode * VolumeHandleSharedData::toShapeNode(const PVConstLink& pV, bool * shape return shape; } + +//____________________________________________________________________ +SoNode * VolumeHandleSharedData::toShapeNode(const VSConstLink& vS, SoSeparator* nodesep) +{ + SoSelection * integrate_shape = new SoSelection; + SoSeparator * shape = new SoSeparator; + //SoGroup * shape = new SoGroup; + m_d->visaction.reset_separator(); + const GeoVSurfaceShape* surf_shape = vS->getShape(); + surf_shape->exec(&(m_d->visaction)); + shape = m_d->visaction.getVSurfaceShape(); + integrate_shape->addChild(shape); + //shape->ref(); + integrate_shape->ref(); + return integrate_shape; +} + //____________________________________________________________________ SoNode * VolumeHandleSharedData::getSoCylinderOrientedLikeGeoTube(const double& radius, const double& halfLength) { diff --git a/GeoModelVisualization/VP1GeometrySystems/src/VolumeTreeModel.cxx b/GeoModelVisualization/VP1GeometrySystems/src/VolumeTreeModel.cxx index 511b78df6106ff80ca3846c4f57768c0bf2fc96f..37c1c66d60c55edd8c8d092f7f0cdcd807b66529 100644 --- a/GeoModelVisualization/VP1GeometrySystems/src/VolumeTreeModel.cxx +++ b/GeoModelVisualization/VP1GeometrySystems/src/VolumeTreeModel.cxx @@ -346,8 +346,12 @@ QVariant VolumeTreeModel::data(const QModelIndex& index, int role) const if (volumeHandle->nChildren()>0) return volumeHandle->getName() + " (" + QString::fromStdString(volumeHandle->geoMaterial()->getName()) + ") [" + QString::number(volumeHandle->nChildren())+"] ("+ volState + ")" ; - else - return volumeHandle->getName() + " (" + QString::fromStdString(volumeHandle->geoMaterial()->getName()) + ") ("+ volState + ")" ; + else{ + if (volumeHandle->geoVSConstLink()) + return volumeHandle->getName(); + else + return volumeHandle->getName() + " (" + QString::fromStdString(volumeHandle->geoMaterial()->getName()) + ") ("+ volState + ")" ; + } } if (role==Qt::ForegroundRole) diff --git a/GeoModelVisualization/VP1Gui/CMakeLists.txt b/GeoModelVisualization/VP1Gui/CMakeLists.txt index 6cc53cc91b5f5cd6b66b40b36d8d9e610e442989..3fdcfe6a2c031f5d7dfc132cc4049764f892a0e6 100644 --- a/GeoModelVisualization/VP1Gui/CMakeLists.txt +++ b/GeoModelVisualization/VP1Gui/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -13,7 +13,7 @@ target_link_libraries( GXGui PRIVATE Qt${QT_VERSION}::PrintSupport Qt${QT_VERSION}::OpenGL ) target_include_directories( GXGui PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "VP1Gui" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ${RCS} ) set_target_properties( GXGui PROPERTIES diff --git a/GeoModelVisualization/VP1GuideLineSystems/CMakeLists.txt b/GeoModelVisualization/VP1GuideLineSystems/CMakeLists.txt index 100e56767a93500eba655ffca38b6ce7b69346c0..ef5110d66d647816b71e96d1b5d7033ec5101646 100644 --- a/GeoModelVisualization/VP1GuideLineSystems/CMakeLists.txt +++ b/GeoModelVisualization/VP1GuideLineSystems/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration # Find the header and source files. file( GLOB SOURCES src/*.cxx ) @@ -9,10 +9,10 @@ file( GLOB UIS src/*.ui ) add_library( GXGuideLineSystems SHARED ${SOURCES} ${HEADERS} ${UIS} ) target_link_libraries( GXGuideLineSystems PUBLIC Coin::Coin Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets GXBase - PRIVATE GeoModelCore::GeoModelKernel GXHEPVis ) + PRIVATE GeoModelCore::GeoModelKernel GXHepVis ) target_include_directories( GXGuideLineSystems PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) source_group( "VP1GuideLineSystems" FILES ${HEADERS} ) source_group( "src" FILES ${SOURCES} ${UIS} ) set_target_properties( GXGuideLineSystems PROPERTIES diff --git a/GeoModelVisualization/VP1GuideLineSystems/src/VP1Letters.cxx b/GeoModelVisualization/VP1GuideLineSystems/src/VP1Letters.cxx index 569885f71b0cc163488c0fdf3fe9531117087d77..6ae75015000163eb253f2862144ebf70173eda14 100644 --- a/GeoModelVisualization/VP1GuideLineSystems/src/VP1Letters.cxx +++ b/GeoModelVisualization/VP1GuideLineSystems/src/VP1Letters.cxx @@ -13,8 +13,8 @@ //////////////////////////////////////////////////////////////// #include "VP1GuideLineSystems/VP1Letters.h" -#include "VP1HEPVis/SbPolyhedron.h" -#include "VP1HEPVis/nodes/SoPolyhedron.h" +#include "GXHepVis/SbPolyhedron.h" +#include "GXHepVis/nodes/SoPolyhedron.h" #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoCube.h> #include <Inventor/nodes/SoSeparator.h> diff --git a/GeoModelVisualization/VP1HEPVis/src/VP1HEPVisUtils.cxx b/GeoModelVisualization/VP1HEPVis/src/VP1HEPVisUtils.cxx deleted file mode 100644 index d8cdf1297a0bd3a32ee2b7d59b0c4ae0cddf23ab..0000000000000000000000000000000000000000 --- a/GeoModelVisualization/VP1HEPVis/src/VP1HEPVisUtils.cxx +++ /dev/null @@ -1,328 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - - -//////////////////////////////////////////////////////////////// -// // -// Implementation of class VP1HEPVisUtils // -// // -// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) // -// Initial version: November 2008 // -// Update: Giorgi Gvaberidze (ggvaberi@cern.ch) // -// Update version: November 2010 // -// // -//////////////////////////////////////////////////////////////// - -#include "VP1HEPVis/VP1HEPVisUtils.h" - -#include <Inventor/C/errors/debugerror.h> -#include <Inventor/nodes/SoSelection.h> -#include <Inventor/nodes/SoSeparator.h> -#include <Inventor/nodes/SoSwitch.h> -//--- -#include <Inventor/nodes/SoSphere.h> - -#include "VP1HEPVis/nodes/SoCons.h" -#include "VP1HEPVis/nodes/SoGenericBox.h" -#include "VP1HEPVis/nodes/SoLAr.h" -#include "VP1HEPVis/nodes/SoPcons.h" -#include "VP1HEPVis/nodes/SoPolyhedron.h" -#include "VP1HEPVis/nodes/SoTransparency.h" -#include "VP1HEPVis/nodes/SoTubs.h" -#include "VP1HEPVis/nodes/SoTessellated.h" - -#include <Inventor/nodes/SoSeparator.h> -#include <Inventor/nodes/SoIndexedFaceSet.h> -#include <Inventor/nodes/SoVertexProperty.h> -#include <VP1HEPVis/SbPolyhedron.h> - -#include <iostream>//fixme - -//____________________________________________________________________ -class VP1HEPVisUtils::Imp { -public: - template <class T> - static SoNode * convertToAlternateRep(SoNode *); - - template <class T> - static void clearAlternateRep(SoNode *); - - template <class T> - static void updateAlternateRepIfNull(SoNode *); - - static bool isGroup(SoNode* n); - static bool isNonCustomTree(SoGroup* g); - static SoGroup * convertToStandardGroupNode(SoGroup* g,bool transferChildren); - static SoGroup * convertToStandardScene(SoGroup* g); - static void updateAllNullAlternativeReps(SoGroup*g); -}; - -//____________________________________________________________________ -bool VP1HEPVisUtils::Imp::isNonCustomTree(SoGroup* g) -{ - if (!g) - return true;//well... - - if (isCustomNode(g)) - return false; - - for (int i = 0; i<g->getNumChildren();++i) { - SoNode * n = g->getChild(i); - if ( Imp::isGroup(n) ) { - if (!isNonCustomTree(static_cast<SoGroup*>(n))) - return false; - } else { - if (isCustomNode(n)) - return false; - } - } - return true; -} - -//____________________________________________________________________ -SoGroup * VP1HEPVisUtils::Imp::convertToStandardGroupNode(SoGroup* g,bool transferChildren) -{ - //Create new non-custom node and transfer relevant fields: - SoGroup * newgroup(0); - if ( g->getTypeId().isDerivedFrom(SoSeparator::getClassTypeId()) && - ! g->getTypeId().isDerivedFrom(SoSelection::getClassTypeId()) ) { - SoSeparator * sep = new SoSeparator; - SoSeparator * origsep = static_cast<SoSeparator*>(g); - sep->renderCaching.setValue(origsep->renderCaching.getValue()); - sep->boundingBoxCaching.setValue(origsep->boundingBoxCaching.getValue()); - sep->renderCulling.setValue(origsep->renderCulling.getValue()); - sep->pickCulling.setValue(origsep->pickCulling.getValue()); - newgroup = sep; - } else if ( g->getTypeId().isDerivedFrom(SoSelection::getClassTypeId()) ) { - SoSelection * sel = new SoSelection; - SoSelection * origsel = static_cast<SoSelection*>(g); - sel->renderCaching.setValue(origsel->renderCaching.getValue()); - sel->boundingBoxCaching.setValue(origsel->boundingBoxCaching.getValue()); - sel->renderCulling.setValue(origsel->renderCulling.getValue()); - sel->pickCulling.setValue(origsel->pickCulling.getValue()); - sel->policy.setValue(origsel->policy.getValue()); - newgroup = sel; - } else if ( g->getTypeId().isDerivedFrom(SoSwitch::getClassTypeId()) ) { - SoSwitch *sw = new SoSwitch; - sw->whichChild.setValue(static_cast<SoSwitch*>(g)->whichChild.getValue()); - newgroup = sw; - } else { - //Everything else is just treated like a group (we could add more specialisations): - newgroup = new SoGroup; - } - - //Transfer name: - newgroup->setName(g->getName()); - - //Transfer children: - if (transferChildren) - for (int i = 0; i<g->getNumChildren();++i) - newgroup->addChild(g->getChild(i)); - - return newgroup; -} - -//____________________________________________________________________ -SoGroup * VP1HEPVisUtils::Imp::convertToStandardScene(SoGroup* g) -{ - if (Imp::isNonCustomTree(g)) - return g; - - //We have to change something underneath, so we must get a new (and non-custom) group node: - SoGroup * thegroup = convertToStandardGroupNode(g,false/*don't transfer children*/); - if (!thegroup) - std::cout <<"BAAAAAAAAAD!"<<std::endl; - for (int i = 0; i<g->getNumChildren();++i) { - SoNode * n = g->getChild(i); - if (isGroup(n)) { - SoGroup * standard = convertToStandardScene(static_cast<SoGroup*>(n)); - if (standard) - thegroup->addChild(standard); - else - std::cout <<"BAD 1"<<std::endl; - } else { - SoNode * ntoadd = isCustomNode(n)?convertCustomNodeToAlternateRep(n):n; - if (ntoadd) - thegroup->addChild(isCustomNode(n)?convertCustomNodeToAlternateRep(n):n); - else - std::cout <<"BAD 2"<<std::endl; - } - } - - return thegroup; -} - - -//____________________________________________________________________ -SoGroup * VP1HEPVisUtils::convertToStandardScene(SoGroup* g) -{ - if (!g) - return 0; - - initAllCustomClasses(); - - if (Imp::isNonCustomTree(g)) - return g; - - - g->ref(); - - updateAllAlternativeReps(g); - - SoGroup* thegroup = Imp::convertToStandardScene(g); - thegroup->ref(); - - clearAllAlternativeReps(g); - - g->unrefNoDelete(); - thegroup->unrefNoDelete(); - return thegroup; -} - -//____________________________________________________________________ -bool VP1HEPVisUtils::isCustomNode(SoNode* n) -{ - if (!n) - return false; - - return n->getNodeType() & SoNode::EXTENSION; -} - -//____________________________________________________________________ -template <class T> -SoNode * VP1HEPVisUtils::Imp::convertToAlternateRep(SoNode * n) -{ - if (!n) - return 0; - T * t = static_cast<T*>(n); - SoNode * n_alt = t->alternateRep.getValue(); - if (n_alt) { - //Don't clear the alternateRep, since it was there before. - } else { - t->generateAlternateRep(); - n_alt = t->alternateRep.getValue(); - if (n_alt) { - //Clear the alternateRep, since it was not there before. - n_alt->ref(); - t->clearAlternateRep(); - n_alt->unrefNoDelete(); - } else { - return 0; - } - } - n_alt->setName(n->getName()); - return n_alt; -} - -//____________________________________________________________________ -template <class T> -void VP1HEPVisUtils::Imp::clearAlternateRep(SoNode * n) -{ - T * t = static_cast<T*>(n); - if (t&&t->alternateRep.getValue()) - t->clearAlternateRep(); -} - -//____________________________________________________________________ -template <class T> -void VP1HEPVisUtils::Imp::updateAlternateRepIfNull(SoNode * n) -{ - T * t = static_cast<T*>(n); - if (t&&!t->alternateRep.getValue()) { - t->generateAlternateRep(); - t->clearAlternateRep(); - } -} - -//____________________________________________________________________ -SoNode * VP1HEPVisUtils::convertCustomNodeToAlternateRep(SoNode*n) -{ - if (!n) - return 0; - - initAllCustomClasses(); - - if ( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) ) return Imp::convertToAlternateRep<SoCons>(n); - if ( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) ) return Imp::convertToAlternateRep<SoLAr>(n); -//NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::convertToAlternateRep<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::convertToAlternateRep<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) ) return Imp::convertToAlternateRep<SoGenericBox>(n); - if ( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) ) return Imp::convertToAlternateRep<SoTubs>(n); - if ( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) ) return Imp::convertToAlternateRep<SoPolyhedron>(n); - if ( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) ) return Imp::convertToAlternateRep<SoTessellated>(n); - - //A bit special. Probably should not get called here. - if ( Imp::isGroup(n) ) return Imp::convertToStandardGroupNode(static_cast<SoGroup*>(n),false /*transferChildren*/); - SoGroup * g = new SoGroup; - return g;//fixme: share this -} - -//____________________________________________________________________ -bool VP1HEPVisUtils::Imp::isGroup(SoNode* n) -{ - return n->getTypeId().isDerivedFrom(SoGroup::getClassTypeId()); -} - -//____________________________________________________________________ -void VP1HEPVisUtils::Imp::updateAllNullAlternativeReps(SoGroup*g) -{ - for (int i = 0; i<g->getNumChildren();++i) { - SoNode * n = g->getChild(i); - if ( Imp::isGroup(n) ) { - updateAllNullAlternativeReps(static_cast<SoGroup*>(n)); - } else if (VP1HEPVisUtils::isCustomNode(n)) { - if ( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoCons>(n); - if ( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoLAr>(n); - //NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoGenericBox>(n); - if ( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoTubs>(n); - if ( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoPolyhedron>(n); - if ( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) ) return Imp::updateAlternateRepIfNull<SoTessellated>(n); - } - } -} - -//____________________________________________________________________ -void VP1HEPVisUtils::updateAllAlternativeReps(SoGroup*g) -{ - clearAllAlternativeReps(g);//To make sure all altReps. are NULL - //(thus, we only update those with null, - //avoiding repeated updates on shared - //instances) - Imp::updateAllNullAlternativeReps(g); -} - -//____________________________________________________________________ -void VP1HEPVisUtils::clearAllAlternativeReps(SoGroup*g) -{ - for (int i = 0; i<g->getNumChildren();++i) { - SoNode * n = g->getChild(i); - if ( Imp::isGroup(n) ) { - clearAllAlternativeReps(static_cast<SoGroup*>(n)); - } else if (isCustomNode(n)) { - if ( n->getTypeId().isDerivedFrom(SoCons::getClassTypeId()) ) return Imp::clearAlternateRep<SoCons>(n); - if ( n->getTypeId().isDerivedFrom(SoLAr::getClassTypeId()) ) return Imp::clearAlternateRep<SoLAr>(n); - //NOT IMPLEMENTED if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::clearAlternateRep<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoPcons::getClassTypeId()) ) return Imp::clearAlternateRep<SoPcons>(n); - if ( n->getTypeId().isDerivedFrom(SoGenericBox::getClassTypeId()) ) return Imp::clearAlternateRep<SoGenericBox>(n); - if ( n->getTypeId().isDerivedFrom(SoTubs::getClassTypeId()) ) return Imp::clearAlternateRep<SoTubs>(n); - if ( n->getTypeId().isDerivedFrom(SoPolyhedron::getClassTypeId()) ) return Imp::clearAlternateRep<SoPolyhedron>(n); - if ( n->getTypeId().isDerivedFrom(SoTessellated::getClassTypeId()) ) return Imp::clearAlternateRep<SoTessellated>(n); - } - } -} - -//____________________________________________________________________ -void VP1HEPVisUtils::initAllCustomClasses() -{ - SoCons::initClass(); - SoGenericBox::initClass(); - SoLAr::initClass(); - SoPcons::initClass(); - SoPolyhedron::initClass(); - SoTransparency::initClass(); - SoTubs::initClass(); - SoTessellated::initClass(); -} diff --git a/athena_ci/apply_patches.sh b/athena_ci/apply_patches.sh index 2582d3a4b71b7fde84aae77448dd7fc5ab530f44..0a1ecd28bd9a3befd8b49cb21492c4341d77f875 100755 --- a/athena_ci/apply_patches.sh +++ b/athena_ci/apply_patches.sh @@ -25,14 +25,16 @@ fill_line "-" git checkout $NIGHTLY_COMMIT -for p in "$SCRIPT_DIR"/patches/*.patch; do - echo "---- Applying ${p} ----" - patch -p1 < ${p} - #cat "${p}" | git am -3 - #git --no-pager log -1 $sha - - fill_line "-" -done +if compgen -G "${SCRIPT_DIR}/patches/*.patch" > /dev/null; then + for p in "$SCRIPT_DIR"/patches/*.patch; do + echo "---- Applying ${p} ----" + patch -p1 < ${p} + #cat "${p}" | git am -3 + #git --no-pager log -1 $sha + + fill_line "-" + done +fi #git diff HEAD ${NIGHTLY_COMMIT} diff --git a/athena_ci/athena_build.sh b/athena_ci/athena_build.sh index 220a60ad087242e45cf42260a7632789956bf359..8a0c34aa2aede7ef4c04c1717b723fe29f37130c 100755 --- a/athena_ci/athena_build.sh +++ b/athena_ci/athena_build.sh @@ -96,10 +96,6 @@ echo "LCG_PLATFORM: ${LCG_PLATFORM}" lsetup "views ${LCG_RELEASE} ${LCG_PLATFORM}" || true -CCACHE=$(command -v ccache) -$CCACHE -z - - export if [ "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" == "main" ];then @@ -126,14 +122,12 @@ cmake -S "${SCRIPT_DIR}/.." -B geomodel-build \ -DCMAKE_MAKE_PROGRAM="$NINJA" \ -DCMAKE_CXX_FLAGS="$EXTRA_FLAGS" \ -DCMAKE_INSTALL_PREFIX=$gm_install_dir \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_BUILD_TYPE=Release \ -DGEOMODEL_BUILD_TOOLS=ON \ - -DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE \ heading "Build GeoModel" cmake --build geomodel-build -$CCACHE -s echo "Installing GeoModel" cmake --install geomodel-build > gm_install.log @@ -155,14 +149,8 @@ popd > /dev/null echo fill_line "=" -echo "$CCACHE -z" -$CCACHE -z - -echo "$CCACHE -C" -$CCACHE -C export CMAKE_PREFIX_PATH="${gm_install_dir}:$CMAKE_PREFIX_PATH" - heading "Configure Athena" full_package_filters=$SCRIPT_DIR/package_filters.txt @@ -208,7 +196,7 @@ cmake "$ATHENA_SOURCE/Projects/WorkDir" \ -DCMAKE_MAKE_PROGRAM="$NINJA" \ -DCMAKE_CXX_FLAGS="$EXTRA_FLAGS -isystem ${gm_install_dir}/include" \ -DATLAS_PACKAGE_FILTER_FILE="$package_filters" \ - -DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE \ + -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$install_dir popd @@ -222,15 +210,11 @@ echo "export LD_LIBRARY_PATH=\"${gm_install_dir}/lib64:\${LD_LIBRARY_PATH}\"" >> echo "export PATH=\"${gm_install_dir}/share:\${PATH}\"" >> athena-build/*/env_setup.sh echo "export ROOT_INCLUDE_PATH=\"${gm_install_dir}/include:\${ROOT_INCLUDE_PATH}\"" >> athena-build/*/env_setup.sh - - heading "Build Athena" - if [ -z "$CI" ]; then - heading "Interactive mode, dropping into shell" - bash + heading "Interactive mode, dropping into shell" + bash else - VERBOSE=1 cmake --build athena-build -- -j3 - $CCACHE -s - cmake --install athena-build > athena_install.log + cmake --build athena-build -- -j5 + cmake --install athena-build > athena_install.log fi diff --git a/athena_ci/ci.yml b/athena_ci/ci.yml index 4730fbd21e36295f4da8914cfb7e0f4948171987..0018dd39359da82511bc07854cb942de47e2f0ef 100644 --- a/athena_ci/ci.yml +++ b/athena_ci/ci.yml @@ -2,6 +2,8 @@ build_geomodel_athena: image: gitlab-registry.cern.ch/atlas-sit/docker/alma9-atlasos-dev stage: step-A + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" variables: CCACHE_KEY_SUFFIX: r2 @@ -48,6 +50,9 @@ build_geomodel_athena: .run_base: stage: step-B + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + # This image sould work, but it seems it doesn't. Using my derivative until # I figure out what the difference is. # image: gitlab-registry.cern.ch/atlas-sit/docker/alma9-atlasos-dev @@ -119,7 +124,7 @@ simulation_tests_run3: extends: .run_base script: - cd run - - RunWorkflowTests_Run3.py --CI -s -w FullSim --threads 4 -e '--maxEvents 50' --detailed-comparison + - RunWorkflowTests_Run3.py --CI -s -w FullSim --threads 4 -e '--maxEvents 20' --run-only - mv run_s4006/log.EVNTtoHITS ./ - mv run_s4006/myHITS.pool.root ./ artifacts: @@ -150,13 +155,13 @@ run_workflow_tests_run2_mc: extends: .run_base script: - cd run - - RunWorkflowTests_Run2.py --CI -r -w MCReco --threads 0 -e '--CA "all:True" "RDOtoRDOTrigger:False" --conditionsTag "default:OFLCOND-MC16-SDR-RUN2-11" "RDOtoRDOTrigger:OFLCOND-MC16-SDR-RUN2-08-02" --maxEvents 25' --detailed-comparison + - RunWorkflowTests_Run2.py --CI -r -w MCReco --threads 0 -e '--maxEvents 25 --conditionsTag OFLCOND-MC16-SDR-RUN2-12' --detailed-comparison run_workflow_tests_run3_mc: extends: .run_base script: - cd run - - RunWorkflowTests_Run3.py --CI -r -w MCReco -e '--maxEvents 25' --detailed-comparison + - RunWorkflowTests_Run3.py --CI -r -w MCReco -e '--maxEvents 25 --conditionsTag OFLCOND-MC23-SDR-RUN3-05' --detailed-comparison run_workflow_tests_run4_reco: extends: .run_base @@ -165,7 +170,7 @@ run_workflow_tests_run4_reco: - build_geomodel_athena script: - cd run - - RunWorkflowTests_Run4.py --CI -r -w MCReco -e '--maxEvents 5 --inputHITSFile=../../myHITS.pool.root' --no-output-checks + - RunWorkflowTests_Run4.py --CI -r -w MCReco -e '--conditionsTag OFLCOND-MC21-SDR-RUN4-01 --maxEvents 5 --inputHITSFile=../../myHITS.pool.root' --no-output-checks ################################################### diff --git a/athena_ci/package_filters.txt b/athena_ci/package_filters.txt index 2d1a916e48e9cdc6a364f8ae1248090225aa2192..aa6c0bd86c210047d7b2de81915c8a756c53f2ab 100644 --- a/athena_ci/package_filters.txt +++ b/athena_ci/package_filters.txt @@ -18,6 +18,7 @@ + DetectorDescription/GeoModel/GeoModelSvc + DetectorDescription/GeoModel/GeoModelUtilities + DetectorDescription/GeoModel/GeoSpecialShapes ++ DetectorDescription/GeoModel/DumpGeo + DetectorDescription/IdDictDetDescrCnv + DetectorDescription/ReadoutGeometryBase + ForwardDetectors/AFP/AFP_GeoModel @@ -44,6 +45,7 @@ + InnerDetector/InDetDetDescr/InDetTrackingGeometry + InnerDetector/InDetDetDescr/PixelGeoModel + InnerDetector/InDetDetDescr/PixelGeoModelXml ++ InnerDetector/InDetDetDescr/PixelReadoutDefinitions + InnerDetector/InDetDetDescr/PixelReadoutGeometry + InnerDetector/InDetDetDescr/SCT_GeoModel + InnerDetector/InDetDetDescr/SCT_ReadoutGeometry @@ -76,10 +78,6 @@ + LArCalorimeter/LArGeoModel/LArGeoCode + LArCalorimeter/LArGeoModel/LArGeoEndcap + LArCalorimeter/LArGeoModel/LArGeoFcal -+ LArCalorimeter/LArGeoModel/LArGeoH62002Algs -+ LArCalorimeter/LArGeoModel/LArGeoH62003Algs -+ LArCalorimeter/LArGeoModel/LArGeoH62004Algs -+ LArCalorimeter/LArGeoModel/LArGeoH6Cryostats + LArCalorimeter/LArGeoModel/LArGeoHec + LArCalorimeter/LArGeoModel/LArGeoRAL + LArCalorimeter/LArGeoModel/LArGeoTBBarrel @@ -88,7 +86,6 @@ + LArCalorimeter/LArGeoModel/LArReadoutGeometry + LArCalorimeter/LArROD + LArCalorimeter/LArTrackingGeometry -+ MuonSpectrometer/Amdcsimrec/AmdcAth + MuonSpectrometer/MuonAlignment/MuonAlignmentData + MuonSpectrometer/MuonCablings/CSCcabling + MuonSpectrometer/MuonCnv/MuonEventTPCnv @@ -103,8 +100,8 @@ + MuonSpectrometer/MuonDetDescr/MuonTrackingGeometry + MuonSpectrometer/MuonDigitization/RPC_Digitization + MuonSpectrometer/MuonDigitization/TGC_Digitization -+ MuonSpectrometer/MuonGeoModel -+ MuonSpectrometer/MuonGeoModelTest ++ MuonSpectrometer/MuonDetDescr/MuonGeoModel ++ MuonSpectrometer/MuonDetDescr/MuonGeoModelTest + MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelR4 + MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4 + MuonSpectrometer/MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4 @@ -115,6 +112,7 @@ + Simulation/G4Utilities/Geo2G4 + Simulation/G4Utilities/GeoMaterial2G4 + Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization ++ Simulation/AtlasGeant4 + TileCalorimeter/TileConditions + TileCalorimeter/TileDetDescr + TileCalorimeter/TileFastCaloSim @@ -133,14 +131,3 @@ + Tracking/TrkDetDescr/TrkDetDescrGeoModelCnv + Tracking/TrkDetDescr/TrkDetElementBase + Trigger/TrigAlgorithms/TrigL2MuonSA -+ graphics/GeometryJiveXML -+ graphics/VP1/VP1Base -+ graphics/VP1/VP1Systems/VP1AODSystems -+ graphics/VP1/VP1Systems/VP1CaloSystems -+ graphics/VP1/VP1Systems/VP1GeometrySystems -+ graphics/VP1/VP1Systems/VP1GuideLineSystems -+ graphics/VP1/VP1Systems/VP1PRDSystems -+ graphics/VP1/VP1Systems/VP1RawDataSystems -+ graphics/VP1/VP1Systems/VP1TrackSystems -+ graphics/VP1/VP1Systems/VP1TrackingGeometrySystems -+ graphics/VP1/VP1Utils diff --git a/athena_ci/patch_package_filters.txt b/athena_ci/patch_package_filters.txt index 1af0733cac65957da6adfc15366c248b1a153f26..f5d158999179ac28adc33cf4b7ca20d8ad3100e4 100644 --- a/athena_ci/patch_package_filters.txt +++ b/athena_ci/patch_package_filters.txt @@ -1,3 +1,2 @@ # These Athena packages need to be rebuilt # due to patches in the `patches` directory - diff --git a/athena_ci/patches/0001-Adapt-to-interface-change-using-GeoPositioning-objec.patch b/athena_ci/patches/0001-Adapt-to-interface-change-using-GeoPositioning-objec.patch deleted file mode 100644 index c5ee80b5cae38032cabe2c632c047d337c08014b..0000000000000000000000000000000000000000 --- a/athena_ci/patches/0001-Adapt-to-interface-change-using-GeoPositioning-objec.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 2404442b4ba8f6dbc92f0b0f25e201317ec2c141 Mon Sep 17 00:00:00 2001 -From: Johannes Josef Junggeburth <johannes.josef.junggeburth@cern.ch> -Date: Tue, 30 Apr 2024 09:41:11 +0200 -Subject: [PATCH] Adapt to interface change using GeoPositioning objects - ---- - .../GeoModelUtilities/GeoAlignmentStore.h | 14 +++++++------- - .../GeoModelUtilities/src/GeoAlignmentStore.cxx | 4 ++-- - 2 files changed, 9 insertions(+), 9 deletions(-) - -diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoAlignmentStore.h b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoAlignmentStore.h -index 4756f948abc..da2b126bd4b 100755 ---- a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoAlignmentStore.h -+++ b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoAlignmentStore.h -@@ -49,19 +49,19 @@ public: - /// full physical volume. - /// @param fullPhysVol: Full physical volume in the GeoModel tree to which the transforms belongs to - /// @param physVolTrf: Aligned placement of the physical volume in space -- virtual void setAbsPosition(const GeoVFullPhysVol* fullPhysVol, -+ virtual void setAbsPosition(const GeoNodePositioning* fullPhysVol, - const GeoTrf::Transform3D& physVolTrf) override final; - /// @brief: Returns the aligned transform associated with the full physical volume. Returns a - /// nullptr if the physical volume has not been added before -- virtual const GeoTrf::Transform3D* getAbsPosition(const GeoVFullPhysVol* fullPhysVol) const override final; -+ virtual const GeoTrf::Transform3D* getAbsPosition(const GeoNodePositioning* fullPhysVol) const override final; - /// @brief: Caches the aboslute transform of the perfectly aligned physical volume. - /// @param fullPhysVol: Full physical volume in the GeoModel tree to which the transforms belongs to - /// @param unAlignedTrf: Nominal placement of the full physical volume. -- virtual void setDefAbsPosition(const GeoVFullPhysVol* fullPhysVol, -+ virtual void setDefAbsPosition(const GeoNodePositioning* fullPhysVol, - const GeoTrf::Transform3D& unAlignedTrf) override final; - /// @brief: Returns the nominal position of the full phyiscal volume. Returns a nullptr if the - /// nominal position of the full physical volume has not been added before to the map -- virtual const GeoTrf::Transform3D* getDefAbsPosition(const GeoVFullPhysVol* fullPhysVol) const override final; -+ virtual const GeoTrf::Transform3D* getDefAbsPosition(const GeoNodePositioning* fullPhysVol) const override final; - - /// @brief: Copies, the deltas, the absolute and the nominal positions of the other map - /// to this object. Returns false if the two maps partially overlap. -@@ -76,7 +76,7 @@ public: - using DeltaMap = TransformMap<GeoAlignableTransform, GeoTrf::Transform3D>; - using DeltaMapPtr = GeoModel::TransientConstSharedPtr<DeltaMap>; - -- using PositioningMap = TransformMap<GeoVFullPhysVol, GeoTrf::Transform3D>; -+ using PositioningMap = TransformMap<GeoNodePositioning, GeoTrf::Transform3D>; - using PositioningMapPtr = GeoModel::TransientConstSharedPtr<PositioningMap>; - private: - DeltaMapPtr m_deltas{std::make_unique<DeltaMap>()}; -@@ -92,10 +92,10 @@ public: - inline const GeoTrf::Transform3D* GeoAlignmentStore::getDelta(const GeoAlignableTransform* axf) const { - return m_deltas->getTransform(axf); - } --inline const GeoTrf::Transform3D* GeoAlignmentStore::getAbsPosition(const GeoVFullPhysVol* fpv) const { -+inline const GeoTrf::Transform3D* GeoAlignmentStore::getAbsPosition(const GeoNodePositioning* fpv) const { - return m_absPositions->getTransform(fpv); - } --inline const GeoTrf::Transform3D* GeoAlignmentStore::getDefAbsPosition(const GeoVFullPhysVol* fpv) const { -+inline const GeoTrf::Transform3D* GeoAlignmentStore::getDefAbsPosition(const GeoNodePositioning* fpv) const { - return m_defAbsPositions->getTransform(fpv); - } - -diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoAlignmentStore.cxx b/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoAlignmentStore.cxx -index f0865e42b55..b9282562062 100644 ---- a/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoAlignmentStore.cxx -+++ b/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoAlignmentStore.cxx -@@ -11,10 +11,10 @@ void GeoAlignmentStore::setDelta(const GeoAlignableTransform* axf, const GeoTrf: - void GeoAlignmentStore::setDelta(const GeoAlignableTransform* axf, std::shared_ptr<const GeoTrf::Transform3D> trans) { - m_deltas->setTransform(axf, std::move(trans)); - } --void GeoAlignmentStore::setAbsPosition(const GeoVFullPhysVol* fpv, const GeoTrf::Transform3D& xf) { -+void GeoAlignmentStore::setAbsPosition(const GeoNodePositioning* fpv, const GeoTrf::Transform3D& xf) { - m_absPositions->setTransform(fpv, xf); - } --void GeoAlignmentStore::setDefAbsPosition(const GeoVFullPhysVol* fpv, const GeoTrf::Transform3D& xf) { -+void GeoAlignmentStore::setDefAbsPosition(const GeoNodePositioning* fpv, const GeoTrf::Transform3D& xf) { - m_defAbsPositions->setTransform(fpv, xf); - } - void GeoAlignmentStore::lockDelta() { --- -2.34.1 - diff --git a/athena_ci/patches/0001-Move-throw-except.patch b/athena_ci/patches/0001-Move-throw-except.patch new file mode 100644 index 0000000000000000000000000000000000000000..36cec4b22e9602972f11d0befd4da29ae73def80 --- /dev/null +++ b/athena_ci/patches/0001-Move-throw-except.patch @@ -0,0 +1,584 @@ +From eca80303324ee9b19f75dd507a7d13da0fbe6b2c Mon Sep 17 00:00:00 2001 +From: Johannes Josef Junggeburth <johannes.josef.junggeburth@cern.ch> +Date: Thu, 24 Oct 2024 10:06:45 +0200 +Subject: [PATCH] Move throw except + +--- + .../GeoModelUtilities/GeoModelUtilities/TransformMap.icc | 2 +- + .../MuonCablings/MuonCablingData/src/MuonMDT_CablingMap.cxx | 2 +- + .../MuonCalib/MdtCalib/MdtCalibData/src/BFieldCorFunc.cxx | 2 +- + .../MuonCalib/MdtCalib/MdtCalibData/src/RtChebyshev.cxx | 2 +- + .../MdtCalib/MdtCalibData/src/RtResolutionChebyshev.cxx | 2 +- + .../MuonCalib/MdtCalib/MdtCalibInterfaces/src/MdtCalibInput.cxx | 2 +- + .../MuonCalib/MdtCalib/MdtCalibSvc/src/MdtCalibrationTool.cxx | 2 +- + .../MuonCalibUtils/MuonCalibMath/src/BaseFunctionFitter.cxx | 2 +- + .../MuonCalib/MuonCalibUtils/MuonCalibMath/src/PolygonBase.cxx | 2 +- + .../MuonCnv/MuonRPC_CnvTools/src/RpcRdoToPrepDataToolMT.cxx | 2 +- + .../MuonCondGeneral/MuonCondAlg/src/MdtAsBuiltCondAlg.cxx | 2 +- + .../MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx | 2 +- + .../MuonCondGeneral/MuonCondAlg/src/NswCalibDbAlg.cxx | 2 +- + .../MuonCondGeneral/MuonCondAlg/src/NswDcsDbAlg.cxx | 2 +- + .../MuonCondGeneral/MuonCondData/src/DigitEffiData.cxx | 2 +- + .../MuonCondGeneral/MuonCondData/src/MdtCondDbData.cxx | 2 +- + .../MuonCondData/src/NswCalibDbTimeChargeData.cxx | 2 +- + .../MuonCondGeneral/MuonCondData/src/NswDcsDbData.cxx | 2 +- + .../MuonCondGeneral/MuonCondData/src/NswErrorCalibData.cxx | 2 +- + .../MuonCondGeneral/MuonCondData/src/NswT0Data.cxx | 2 +- + .../MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx | 2 +- + .../MuonReadoutGeometry/src/MuonDetectorManager.cxx | 2 +- + .../RPC_Digitization/src/RpcDigitizationTool.cxx | 2 +- + .../MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx | 2 +- + .../Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx | 2 +- + .../xAODMuonPrepData/xAODMuonPrepData/versions/AccessorMacros.h | 2 +- + .../Event/xAOD/xAODMuonViews/xAODMuonViews/ChamberViewer.h | 2 +- + .../MuonAlignmentDataR4/src/MdtAlignmentStore.cxx | 2 +- + .../MuonDigitizationR4/src/MuonDigitizationTool.cxx | 2 +- + .../MuonSensitiveDetectorsR4/src/MdtSensitiveDetector.cxx | 2 +- + .../MuonG4/MuonSensitiveDetectorsR4/src/MmSensitiveDetector.cxx | 2 +- + .../MuonSensitiveDetectorsR4/src/RpcSensitiveDetector.cxx | 2 +- + .../MuonSensitiveDetectorsR4/src/TgcSensitiveDetector.cxx | 2 +- + .../MuonSensitiveDetectorsR4/src/sTgcSensitiveDetector.cxx | 2 +- + .../MuonPatternHelpers/Root/SegmentFitHelperFunctions.cxx | 2 +- + .../MuonValidation/MuonPRDTestR4/Root/TesterModuleBase.cxx | 2 +- + .../MuonStationIntersectCond/src/MdtIntersectGeometry.cxx | 2 +- + Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx | 2 +- + Tracking/Acts/ActsGeoUtils/src/SurfaceCache.cxx | 2 +- + Tracking/Acts/ActsGeometry/src/ActsDetectorElement.cxx | 2 +- + .../TrkDriftCircleMath/src/MdtChamberGeometry.cxx | 2 +- + 41 files changed, 41 insertions(+), 41 deletions(-) + +diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/TransformMap.icc b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/TransformMap.icc +index 9d71a8653a2..45134100c37 100755 +--- a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/TransformMap.icc ++++ b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/TransformMap.icc +@@ -5,7 +5,7 @@ + #ifndef GEOMODELUTILITIES_TRANSFORMMAP_ICC + #define GEOMODELUTILITIES_TRANSFORMMAP_ICC + +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "CxxUtils/inline_hints.h" + + +diff --git a/MuonSpectrometer/MuonCablings/MuonCablingData/src/MuonMDT_CablingMap.cxx b/MuonSpectrometer/MuonCablings/MuonCablingData/src/MuonMDT_CablingMap.cxx +index 6796d45aa05..5d83f76571a 100644 +--- a/MuonSpectrometer/MuonCablings/MuonCablingData/src/MuonMDT_CablingMap.cxx ++++ b/MuonSpectrometer/MuonCablings/MuonCablingData/src/MuonMDT_CablingMap.cxx +@@ -11,7 +11,7 @@ + #include "CxxUtils/ArrayHelper.h" + #include "StoreGate/StoreGateSvc.h" + #include "Identifier/Identifier.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + namespace { + /// Four mezzanine channels explicitly break the cabling schema in the legacy +diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/BFieldCorFunc.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/BFieldCorFunc.cxx +index c991661e9c3..c481008c31e 100644 +--- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/BFieldCorFunc.cxx ++++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/BFieldCorFunc.cxx +@@ -9,7 +9,7 @@ + #include "MdtCalibData/IRtRelation.h" + #include "MuonCalibMath/BaseFunctionFitter.h" + #include "MuonCalibMath/LegendrePolynomial.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "cmath" + + using namespace MuonCalib; +diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtChebyshev.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtChebyshev.cxx +index 6a75398569e..813dc50bfd5 100644 +--- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtChebyshev.cxx ++++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtChebyshev.cxx +@@ -3,7 +3,7 @@ + */ + #include "MdtCalibData/RtChebyshev.h" + #include "MuonCalibMath/ChebychevPoly.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + using namespace MuonCalib; + + RtChebyshev::RtChebyshev(const ParVec& vec) : +diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtResolutionChebyshev.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtResolutionChebyshev.cxx +index 111b63529c1..24e70884ff4 100644 +--- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtResolutionChebyshev.cxx ++++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibData/src/RtResolutionChebyshev.cxx +@@ -3,7 +3,7 @@ + */ + #include "MdtCalibData/RtResolutionChebyshev.h" + #include "MuonCalibMath/ChebychevPoly.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using namespace MuonCalib; + +diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibInterfaces/src/MdtCalibInput.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibInterfaces/src/MdtCalibInput.cxx +index a1862fa9c16..e9643299143 100644 +--- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibInterfaces/src/MdtCalibInput.cxx ++++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibInterfaces/src/MdtCalibInput.cxx +@@ -16,7 +16,7 @@ + #include <MuonDigitContainer/MdtDigit.h> + #include <MuonPrepRawData/MdtPrepData.h> + #include <TrkSurfaces/StraightLineSurface.h> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + + std::ostream& operator<<(std::ostream& ostr, const MdtCalibInput& input){ + ostr<<"adc: "<<input.adc()<<", "; +diff --git a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibSvc/src/MdtCalibrationTool.cxx b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibSvc/src/MdtCalibrationTool.cxx +index e556c062c44..88903fcbf18 100644 +--- a/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibSvc/src/MdtCalibrationTool.cxx ++++ b/MuonSpectrometer/MuonCalib/MdtCalib/MdtCalibSvc/src/MdtCalibrationTool.cxx +@@ -23,7 +23,7 @@ + #include "MagFieldElements/AtlasFieldCache.h" + #include "MuonCalibEvent/MdtCalibHit.h" + +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + namespace { + static double const twoBySqrt12 = 2/std::sqrt(12); + } +diff --git a/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/BaseFunctionFitter.cxx b/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/BaseFunctionFitter.cxx +index 641e9aca192..1a52a629edb 100644 +--- a/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/BaseFunctionFitter.cxx ++++ b/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/BaseFunctionFitter.cxx +@@ -3,7 +3,7 @@ + */ + + #include "MuonCalibMath/BaseFunctionFitter.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include <cmath> + + namespace MuonCalib { +diff --git a/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/PolygonBase.cxx b/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/PolygonBase.cxx +index 14143d0b8c3..876165a4aa0 100644 +--- a/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/PolygonBase.cxx ++++ b/MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/src/PolygonBase.cxx +@@ -5,7 +5,7 @@ + #include <iostream> + #include <cstdlib> + #include "MuonCalibMath/PolygonBase.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + using namespace MuonCalib; + + PolygonBase::PolygonBase(const std::vector<double> & x) { +diff --git a/MuonSpectrometer/MuonCnv/MuonRPC_CnvTools/src/RpcRdoToPrepDataToolMT.cxx b/MuonSpectrometer/MuonCnv/MuonRPC_CnvTools/src/RpcRdoToPrepDataToolMT.cxx +index 3c3b0aadfef..714c9adc230 100755 +--- a/MuonSpectrometer/MuonCnv/MuonRPC_CnvTools/src/RpcRdoToPrepDataToolMT.cxx ++++ b/MuonSpectrometer/MuonCnv/MuonRPC_CnvTools/src/RpcRdoToPrepDataToolMT.cxx +@@ -13,7 +13,7 @@ + #include "TrkSurfaces/Surface.h" + #include "xAODMuonPrepData/RpcStripAuxContainer.h" + #include "MuonIdHelpers/IdentifierByDetElSorter.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + using namespace MuonGM; + using namespace Trk; + namespace Muon{ +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtAsBuiltCondAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtAsBuiltCondAlg.cxx +index 4c64dca466f..0f2b2e2486d 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtAsBuiltCondAlg.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtAsBuiltCondAlg.cxx +@@ -8,7 +8,7 @@ + #include <AthenaKernel/IOVInfiniteRange.h> + #include <PathResolver/PathResolver.h> + #include <CxxUtils/StringUtils.h> +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + MdtAsBuiltCondAlg::MdtAsBuiltCondAlg(const std::string& name, ISvcLocator* pSvcLocator): + AthReentrantAlgorithm{name, pSvcLocator} {} +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx +index c55a2f88544..01816d4ced2 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx +@@ -41,7 +41,7 @@ + + #include "TFile.h" + #include "TSpline.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using namespace MuonCalib; + using namespace CxxUtils; +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswCalibDbAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswCalibDbAlg.cxx +index 9511c7aee35..50dbfd82214 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswCalibDbAlg.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswCalibDbAlg.cxx +@@ -15,7 +15,7 @@ + #include "MuonNSWCommonDecode/NSWResourceId.h" + #include "MuonNSWCommonDecode/NSWOfflineHelper.h" + #include "AthenaKernel/IOVInfiniteRange.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + #include<ctime> + +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswDcsDbAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswDcsDbAlg.cxx +index 1e678614884..4178c37054a 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswDcsDbAlg.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/NswDcsDbAlg.cxx +@@ -10,7 +10,7 @@ + #include <regex> + #include "nlohmann/json.hpp" + #include "MuonIdHelpers/IMuonIdHelperSvc.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + // Initialize + StatusCode +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/DigitEffiData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/DigitEffiData.cxx +index 762b59cb827..b5b5eeadd53 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/DigitEffiData.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/DigitEffiData.cxx +@@ -2,7 +2,7 @@ + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + */ + #include "MuonCondData/DigitEffiData.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + namespace Muon{ + DigitEffiData::DigitEffiData(const Muon::IMuonIdHelperSvc* idHelperSvc, double defaultEffi): +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/MdtCondDbData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/MdtCondDbData.cxx +index 7749ba87665..10629c98e83 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/MdtCondDbData.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/MdtCondDbData.cxx +@@ -4,7 +4,7 @@ + + #include "MuonCondData/MdtCondDbData.h" + #include "MuonIdHelpers/MdtIdHelper.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using DcsConstants = MdtCondDbData::DcsConstants; + // --- writing identifiers ------- +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswCalibDbTimeChargeData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswCalibDbTimeChargeData.cxx +index ca2082f1832..97d5dd92a42 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswCalibDbTimeChargeData.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswCalibDbTimeChargeData.cxx +@@ -5,7 +5,7 @@ + #include "MuonCondData/NswCalibDbTimeChargeData.h" + #include "MuonIdHelpers/IMuonIdHelperSvc.h" + #include "Identifier/Identifier.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + std::ostream& operator<<(std::ostream& ostr, const NswCalibDbTimeChargeData::CalibConstants& obj) { + ostr<<"slope: "<<std::setprecision(15)<<obj.slope;//<<" pm "<<std::setprecision(15)<<obj.slopeError; +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswDcsDbData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswDcsDbData.cxx +index ed816396bcb..17fcf8345e6 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswDcsDbData.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswDcsDbData.cxx +@@ -14,7 +14,7 @@ + #include "MuonNSWCommonDecode/MapperSTG.h" + #include "MuonNSWCommonDecode/MapperMMG.h" + +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + + +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswErrorCalibData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswErrorCalibData.cxx +index e56a569c825..b9c76271b03 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswErrorCalibData.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswErrorCalibData.cxx +@@ -1,6 +1,6 @@ + #include "MuonCondData/NswErrorCalibData.h" + #include <sstream> +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using errorParametrizer = NswErrorCalibData::errorParametrizer; + using Input = NswErrorCalibData::Input; +diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswT0Data.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswT0Data.cxx +index cd09fe770c1..54b03336b10 100644 +--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswT0Data.cxx ++++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondData/src/NswT0Data.cxx +@@ -6,7 +6,7 @@ + #include "MuonIdHelpers/sTgcIdHelper.h" + #include "Identifier/Identifier.h" + #include "AthenaKernel/IOVInfiniteRange.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + + NswT0Data::NswT0Data(const Muon::IMuonIdHelperSvc* idHelperSvc): +diff --git a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx +index 77af374334f..ac8a3342658 100644 +--- a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx ++++ b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx +@@ -17,7 +17,7 @@ + #include "GeoModelUtilities/GeoGetIds.h" + #include "GeoPrimitives/GeoPrimitivesHelpers.h" + #include "GeoPrimitives/GeoPrimitivesToStringConverter.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "GeoModelHelpers/TransformToStringConverter.h" + #include "GeoModelHelpers/GeoShapeUtils.h" + +diff --git a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx +index 2e1ba678861..2db3e773178 100644 +--- a/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx ++++ b/MuonSpectrometer/MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx +@@ -8,7 +8,7 @@ + #include <utility> + + #include "GeoPrimitives/GeoPrimitivesHelpers.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "MuonAlignmentData/ALinePar.h" + #include "MuonAlignmentData/BLinePar.h" + #include "MuonReadoutGeometry/CscReadoutElement.h" +diff --git a/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx b/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx +index b1628ab290f..a9b640dbdf8 100644 +--- a/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx ++++ b/MuonSpectrometer/MuonDigitization/RPC_Digitization/src/RpcDigitizationTool.cxx +@@ -39,7 +39,7 @@ + #include "AtlasHepMC/GenParticle.h" + #include "TruthUtils/HepMCHelpers.h" + #include "GeneratorObjects/HepMcParticleLink.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + // Random Numbers + #include "AthenaKernel/RNGWrapper.h" + #include "CLHEP/Random/RandExponential.h" +diff --git a/MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx b/MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx +index 95f2a7f5780..e8e72592e8c 100644 +--- a/MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx ++++ b/MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx +@@ -2,7 +2,7 @@ + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + */ + #include <MuonSpacePoint/UtilFunctions.h> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + #include <GeoPrimitives/GeoPrimitivesToStringConverter.h> + #include <GaudiKernel/SystemOfUnits.h> + namespace MuonR4{ +diff --git a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx +index cefb331b5ad..77bdddfb10f 100644 +--- a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx ++++ b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx +@@ -2,7 +2,7 @@ + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + */ + #include "xAODMuonPrepData/UtilFunctions.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + #include "MuonReadoutGeometryR4/MdtReadoutElement.h" + #include "MuonReadoutGeometryR4/RpcReadoutElement.h" +diff --git a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/versions/AccessorMacros.h b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/versions/AccessorMacros.h +index 275e9350f11..9756d6fd564 100644 +--- a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/versions/AccessorMacros.h ++++ b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/versions/AccessorMacros.h +@@ -3,7 +3,7 @@ + */ + #ifndef XAODMUONPREPDATA_ACCESSOR_MACROS_H + #define XAODMUONPREPDATA_ACCESSOR_MACROS_H +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + /** + * Macros to implement the scalar variables of the xAOD::MuonPrepData objects + */ +diff --git a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonViews/xAODMuonViews/ChamberViewer.h b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonViews/xAODMuonViews/ChamberViewer.h +index 0f6933d6ecc..ef944aa67cb 100644 +--- a/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonViews/xAODMuonViews/ChamberViewer.h ++++ b/MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonViews/xAODMuonViews/ChamberViewer.h +@@ -8,7 +8,7 @@ + + #include <xAODMeasurementBase/MeasurementDefs.h> + #include <MuonIdHelpers/IMuonIdHelperSvc.h> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + + #define BUILD_TRAIT(traitName, conceptPass) \ + template <typename T> struct traitName{}; \ +diff --git a/MuonSpectrometer/MuonPhaseII/MuonConditions/MuonAlignmentDataR4/src/MdtAlignmentStore.cxx b/MuonSpectrometer/MuonPhaseII/MuonConditions/MuonAlignmentDataR4/src/MdtAlignmentStore.cxx +index c27ed232615..6ef58b6ec92 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonConditions/MuonAlignmentDataR4/src/MdtAlignmentStore.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonConditions/MuonAlignmentDataR4/src/MdtAlignmentStore.cxx +@@ -3,7 +3,7 @@ + */ + #include <MuonAlignmentDataR4/MdtAlignmentStore.h> + +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + MdtAlignmentStore::MdtAlignmentStore(const Muon::IMuonIdHelperSvc* idHelperSvc): + m_idHelperSvc{idHelperSvc}{ + /// Reserve enough space in the vector +diff --git a/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx b/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx +index 3f30fa61b65..e3c11c9ee49 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonDigitization/MuonDigitizationR4/src/MuonDigitizationTool.cxx +@@ -5,7 +5,7 @@ + + #include <xAODMuonSimHit/MuonSimHitAuxContainer.h> + #include <AthenaKernel/RNGWrapper.h> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + + namespace MuonR4{ + +diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MdtSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MdtSensitiveDetector.cxx +index 78daca7ed52..01e8f3b2893 100755 +--- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MdtSensitiveDetector.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MdtSensitiveDetector.cxx +@@ -13,7 +13,7 @@ + #include <limits> + #include <iostream> + #include <GeoPrimitives/CLHEPtoEigenConverter.h> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + #include <xAODMuonSimHit/MuonSimHitAuxContainer.h> + #include <GaudiKernel/SystemOfUnits.h> + #include <StoreGate/ReadHandle.h> +diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MmSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MmSensitiveDetector.cxx +index 32d6995e9df..92de5defbec 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MmSensitiveDetector.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/MmSensitiveDetector.cxx +@@ -14,7 +14,7 @@ + + #include "GeoPrimitives/CLHEPtoEigenConverter.h" + #include "xAODMuonSimHit/MuonSimHitAuxContainer.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "GaudiKernel/SystemOfUnits.h" + + +diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/RpcSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/RpcSensitiveDetector.cxx +index 9692f835173..8d4f974a8ae 100755 +--- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/RpcSensitiveDetector.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/RpcSensitiveDetector.cxx +@@ -15,7 +15,7 @@ + #include "GeoPrimitives/CLHEPtoEigenConverter.h" + #include "xAODMuonSimHit/MuonSimHitAuxContainer.h" + #include "GaudiKernel/SystemOfUnits.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using namespace MuonGMR4; + using namespace CxxUtils; +diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/TgcSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/TgcSensitiveDetector.cxx +index 06563ce7cbb..48ecda92fed 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/TgcSensitiveDetector.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/TgcSensitiveDetector.cxx +@@ -16,7 +16,7 @@ + #include "GeoPrimitives/CLHEPtoEigenConverter.h" + #include "xAODMuonSimHit/MuonSimHitAuxContainer.h" + #include "GaudiKernel/SystemOfUnits.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + using namespace ActsTrk; + +diff --git a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/sTgcSensitiveDetector.cxx b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/sTgcSensitiveDetector.cxx +index 66bab981140..9631290cc90 100755 +--- a/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/sTgcSensitiveDetector.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/src/sTgcSensitiveDetector.cxx +@@ -15,7 +15,7 @@ + #include "GeoPrimitives/CLHEPtoEigenConverter.h" + #include "xAODMuonSimHit/MuonSimHitAuxContainer.h" + #include "GaudiKernel/SystemOfUnits.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + + using namespace MuonGMR4; +diff --git a/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonPatternHelpers/Root/SegmentFitHelperFunctions.cxx b/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonPatternHelpers/Root/SegmentFitHelperFunctions.cxx +index f8bb93dade5..397a74a1862 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonPatternHelpers/Root/SegmentFitHelperFunctions.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonPatternHelpers/Root/SegmentFitHelperFunctions.cxx +@@ -8,7 +8,7 @@ + #include "GeoPrimitives/GeoPrimitivesHelpers.h" + #include "AthenaBaseComps/AthMessaging.h" + #include "GaudiKernel/PhysicalConstants.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "xAODMuonPrepData/MdtDriftCircle.h" + #include "MuonSpacePoint/UtilFunctions.h" + +diff --git a/MuonSpectrometer/MuonPhaseII/MuonValidation/MuonPRDTestR4/Root/TesterModuleBase.cxx b/MuonSpectrometer/MuonPhaseII/MuonValidation/MuonPRDTestR4/Root/TesterModuleBase.cxx +index f4014b412d7..a783fb300bf 100644 +--- a/MuonSpectrometer/MuonPhaseII/MuonValidation/MuonPRDTestR4/Root/TesterModuleBase.cxx ++++ b/MuonSpectrometer/MuonPhaseII/MuonValidation/MuonPRDTestR4/Root/TesterModuleBase.cxx +@@ -3,7 +3,7 @@ + */ + + #include "MuonPRDTestR4/TesterModuleBase.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + #include "StoreGate/ReadHandle.h" + #include "StoreGate/StoreGateSvc.h" + +diff --git a/MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonStationIntersectCond/src/MdtIntersectGeometry.cxx b/MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonStationIntersectCond/src/MdtIntersectGeometry.cxx +index 58da3a4c40c..9d79d6073a3 100755 +--- a/MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonStationIntersectCond/src/MdtIntersectGeometry.cxx ++++ b/MuonSpectrometer/MuonReconstruction/MuonRecUtils/MuonStationIntersectCond/src/MdtIntersectGeometry.cxx +@@ -15,7 +15,7 @@ + #include "MuonReadoutGeometry/MuonDetectorManager.h" + #include "TrkDriftCircleMath/MdtChamberGeometry.h" + #include "TrkDriftCircleMath/MdtId.h" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + // maxNTubesPerLayer is included via MdtChamberGeometry.h -> DriftCircle.h + + namespace Muon { +diff --git a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx +index f0cf086271e..70c3bf4be2d 100644 +--- a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx ++++ b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx +@@ -23,7 +23,7 @@ + #include "G4ReflectionFactory.hh" + #include "G4LogicalBorderSurface.hh" + #include "G4OpticalSurface.hh" +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + #include <map> + #include <iostream> +diff --git a/Tracking/Acts/ActsGeoUtils/src/SurfaceCache.cxx b/Tracking/Acts/ActsGeoUtils/src/SurfaceCache.cxx +index fe3cd686a02..ce0e87c38e4 100644 +--- a/Tracking/Acts/ActsGeoUtils/src/SurfaceCache.cxx ++++ b/Tracking/Acts/ActsGeoUtils/src/SurfaceCache.cxx +@@ -5,7 +5,7 @@ + #include <ActsGeoUtils/SurfaceCache.h> + #ifndef SIMULATIONBASE + #include <Acts/Surfaces/Surface.hpp> +-#include <GeoModelHelpers/throwExcept.h> ++#include <GeoModelKernel/throwExcept.h> + + namespace ActsTrk{ + +diff --git a/Tracking/Acts/ActsGeometry/src/ActsDetectorElement.cxx b/Tracking/Acts/ActsGeometry/src/ActsDetectorElement.cxx +index 73a6866b88b..d02b6374f4a 100644 +--- a/Tracking/Acts/ActsGeometry/src/ActsDetectorElement.cxx ++++ b/Tracking/Acts/ActsGeometry/src/ActsDetectorElement.cxx +@@ -4,7 +4,7 @@ + + #include "ActsGeometry/ActsDetectorElement.h" + +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + // ATHENA + #include "ActsInterop/IdentityHelper.h" +diff --git a/Tracking/TrkUtilityPackages/TrkDriftCircleMath/src/MdtChamberGeometry.cxx b/Tracking/TrkUtilityPackages/TrkDriftCircleMath/src/MdtChamberGeometry.cxx +index 22ef92a3ca6..b39defbc350 100644 +--- a/Tracking/TrkUtilityPackages/TrkDriftCircleMath/src/MdtChamberGeometry.cxx ++++ b/Tracking/TrkUtilityPackages/TrkDriftCircleMath/src/MdtChamberGeometry.cxx +@@ -10,7 +10,7 @@ + #include "TrkDriftCircleMath/SortDcsByY.h" + #include <AthenaKernel/getMessageSvc.h> + #include <MuonReadoutGeometry/MdtReadoutElement.h> +-#include "GeoModelHelpers/throwExcept.h" ++#include "GeoModelKernel/throwExcept.h" + + namespace { + constexpr int maxNTubesPerLayer = MdtIdHelper::maxNTubesPerLayer; +-- +2.34.1 + diff --git a/athena_ci/patches/0002-Reshuffle-includes-to-have-GeoModel-first.patch b/athena_ci/patches/0002-Reshuffle-includes-to-have-GeoModel-first.patch deleted file mode 100644 index 413a5974799763f0f994b301503a61baf704856c..0000000000000000000000000000000000000000 --- a/athena_ci/patches/0002-Reshuffle-includes-to-have-GeoModel-first.patch +++ /dev/null @@ -1,446 +0,0 @@ -From ee9db39e73abc903bae4246bbc26e2bf77e6100a Mon Sep 17 00:00:00 2001 -From: Johannes Josef Junggeburth <johannes.josef.junggeburth@cern.ch> -Date: Wed, 1 May 2024 08:01:52 +0200 -Subject: [PATCH] Reshuffle includes to have GeoModel first - -Add debug mesage ---- - .../GeoModel/GeoModelUtilities/CMakeLists.txt | 17 ++++++++--------- - .../GeoModel/GeoSpecialShapes/CMakeLists.txt | 2 +- - .../ReadoutGeometryBase/CMakeLists.txt | 10 ++++------ - .../AFP/AFP_GeoModel/CMakeLists.txt | 2 +- - .../HGTD_GeoModelXml/CMakeLists.txt | 2 +- - .../HGTD_ReadoutGeometry/CMakeLists.txt | 2 +- - .../HGTD_G4/HGTD_G4_SD/CMakeLists.txt | 3 ++- - .../BCMPrimeGeoModelXml/CMakeLists.txt | 2 +- - .../InDetGeoModelUtils/CMakeLists.txt | 2 +- - .../InDetDetDescr/PLRGeoModelXml/CMakeLists.txt | 2 +- - .../PixelGeoModelXml/CMakeLists.txt | 2 +- - .../ServiceExtensionGeoModelXml/CMakeLists.txt | 2 +- - .../StripGeoModelXml/CMakeLists.txt | 2 +- - InnerDetector/InDetG4/PixelG4_SD/CMakeLists.txt | 2 +- - InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt | 2 +- - .../LArG4/LArG4FastSimulation/CMakeLists.txt | 2 +- - .../LArGeoH6Cryostats/CMakeLists.txt | 5 ++--- - Simulation/G4Utilities/Geo2G4/CMakeLists.txt | 2 +- - .../G4Utilities/GeoMaterial2G4/CMakeLists.txt | 2 +- - .../CombinedScintillator/CMakeLists.txt | 2 +- - .../TileAncillary/DeadMaterial/CMakeLists.txt | 2 +- - .../TileAncillary/LarCrate/CMakeLists.txt | 2 +- - .../TileAncillary/MuonWall/CMakeLists.txt | 2 +- - .../PhantomCalorimeter/CMakeLists.txt | 2 +- - Tracking/Acts/ActsGeometry/CMakeLists.txt | 2 +- - graphics/GeometryJiveXML/CMakeLists.txt | 2 +- - graphics/VP1/VP1Base/CMakeLists.txt | 2 +- - 27 files changed, 39 insertions(+), 42 deletions(-) - -diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/CMakeLists.txt b/DetectorDescription/GeoModel/GeoModelUtilities/CMakeLists.txt -index c0207a69420..0eeeb55dcb5 100644 ---- a/DetectorDescription/GeoModel/GeoModelUtilities/CMakeLists.txt -+++ b/DetectorDescription/GeoModel/GeoModelUtilities/CMakeLists.txt -@@ -4,7 +4,6 @@ - atlas_subdir( GeoModelUtilities ) - - # External dependencies. --find_package( Eigen ) # Needed by GeoModelKernel - find_package( GeoModel COMPONENTS GeoGenericFunctions GeoModelKernel GeoModelHelpers ) - find_package( ROOT COMPONENTS Core ) - # The list of sources, and list of linked libraries depends on what project is -@@ -26,23 +25,23 @@ endif() - atlas_add_library( GeoModelUtilities - GeoModelUtilities/*.h ${sources} - PUBLIC_HEADERS GeoModelUtilities -- INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -- LINK_LIBRARIES GeoPrimitives ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} ${libraries} ) -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} ${libraries} GeoPrimitives ) - - atlas_add_test( GeoGetIds_test - SOURCES test/GeoGetIds_test.cxx -- INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -- LINK_LIBRARIES ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} GeoModelUtilities ) -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} GeoModelUtilities ) - - atlas_add_test( GeoVisitVolumes_test - SOURCES test/GeoVisitVolumes_test.cxx -- INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -- LINK_LIBRARIES ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} GeoModelUtilities ) -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} GeoModelUtilities ) - - atlas_add_test( GeoAlignStore_test - SOURCES test/testAlignStore.cxx -- INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} -- LINK_LIBRARIES ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} ${ROOT_LIBRARIES} GeoModelUtilities -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} ${ROOT_LIBRARIES} GeoModelUtilities - PROPERTIES TIMEOUT 600 - POST_EXEC_SCRIPT nopost.sh) - # Code in this file makes heavy use of eigen and runs orders of magnitude -diff --git a/DetectorDescription/GeoModel/GeoSpecialShapes/CMakeLists.txt b/DetectorDescription/GeoModel/GeoSpecialShapes/CMakeLists.txt -index 91d77688c3a..26487c7e6ac 100644 ---- a/DetectorDescription/GeoModel/GeoSpecialShapes/CMakeLists.txt -+++ b/DetectorDescription/GeoModel/GeoSpecialShapes/CMakeLists.txt -@@ -21,7 +21,7 @@ endif() - atlas_add_library( GeoSpecialShapes - GeoSpecialShapes/*.h src/*.cxx src/LArWheelCalculator_Impl/*.cxx - PUBLIC_HEADERS GeoSpecialShapes -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} - DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} ${extra_public_libs} -diff --git a/DetectorDescription/ReadoutGeometryBase/CMakeLists.txt b/DetectorDescription/ReadoutGeometryBase/CMakeLists.txt -index 3cf36a780ef..f5859272d71 100644 ---- a/DetectorDescription/ReadoutGeometryBase/CMakeLists.txt -+++ b/DetectorDescription/ReadoutGeometryBase/CMakeLists.txt -@@ -5,18 +5,16 @@ atlas_subdir( ReadoutGeometryBase ) - - # External dependencies: - find_package( CLHEP ) --find_package( Eigen ) # Needed by GeoModelKernel - find_package( GeoModel COMPONENTS GeoModelKernel ) - - # Component(s) in the package: - atlas_add_library( ReadoutGeometryBase - ReadoutGeometryBase/*.h ReadoutGeometryBase/*.icc src/*.cxx - PUBLIC_HEADERS ReadoutGeometryBase -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} -- ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} -+ - DEFINITIONS ${CLHEP_DEFINITIONS} -- LINK_LIBRARIES ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} ${CLHEP_LIBRARIES} - CxxUtils AthenaKernel AtlasDetDescr GeoPrimitives Identifier -- GaudiKernel InDetCondTools TrkDetElementBase -- TrkEventPrimitives AthenaBaseComps -+ GaudiKernel InDetCondTools TrkDetElementBase AthenaBaseComps - PRIVATE_LINK_LIBRARIES GeoModelUtilities TrkSurfaces ) -diff --git a/ForwardDetectors/AFP/AFP_GeoModel/CMakeLists.txt b/ForwardDetectors/AFP/AFP_GeoModel/CMakeLists.txt -index d69c92a3e11..a4660c7abe6 100644 ---- a/ForwardDetectors/AFP/AFP_GeoModel/CMakeLists.txt -+++ b/ForwardDetectors/AFP/AFP_GeoModel/CMakeLists.txt -@@ -11,6 +11,6 @@ find_package( GeoModel COMPONENTS GeoModelKernel ) - atlas_add_component( AFP_GeoModel - src/*.cxx - src/components/*.cxx -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} AFP_Geometry AthenaKernel GeoModelUtilities AthenaPoolUtilities GaudiKernel GeoModelInterfaces GeoPrimitives StoreGateLib ) - -diff --git a/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_GeoModelXml/CMakeLists.txt b/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_GeoModelXml/CMakeLists.txt -index de95fea19f2..25eccf0043f 100644 ---- a/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_GeoModelXml/CMakeLists.txt -+++ b/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_GeoModelXml/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_component( HGTD_GeoModelXml - src/*.cxx - src/components/*.cxx -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} - GaudiKernel DetDescrConditions HGTD_ReadoutGeometry InDetGeoModelUtils InDetSimEvent ) - -diff --git a/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_ReadoutGeometry/CMakeLists.txt b/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_ReadoutGeometry/CMakeLists.txt -index a41dad238f1..80bf8b685a6 100644 ---- a/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_ReadoutGeometry/CMakeLists.txt -+++ b/HighGranularityTimingDetector/HGTD_DetDescr/HGTD_ReadoutGeometry/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( GeoModel COMPONENTS GeoPrimitives GeoModelKernel ) - atlas_add_library( HGTD_ReadoutGeometry - HGTD_ReadoutGeometry/*.h src/*.cxx - PUBLIC_HEADERS HGTD_ReadoutGeometry -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} Identifier - ReadoutGeometryBase TrkEventPrimitives HGTD_Identifier AthenaBaseComps -diff --git a/HighGranularityTimingDetector/HGTD_G4/HGTD_G4_SD/CMakeLists.txt b/HighGranularityTimingDetector/HGTD_G4/HGTD_G4_SD/CMakeLists.txt -index 75c3426473f..e4e434fa019 100644 ---- a/HighGranularityTimingDetector/HGTD_G4/HGTD_G4_SD/CMakeLists.txt -+++ b/HighGranularityTimingDetector/HGTD_G4/HGTD_G4_SD/CMakeLists.txt -@@ -8,12 +8,13 @@ find_package( CLHEP ) - find_package( Geant4 ) - find_package( GeoModel COMPONENTS GeoModelKernel GeoModelRead GeoModelDBManager ) - -+message (INFO "Include dirs are ${GEOMODEL_INCLUDE_DIRS} ${GEOMODEL_LIBRARIES}") - # Component(s) in the package: - atlas_add_library( HGTD_G4_SD - src/*.h src/*.cxx src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEANT4_LIBRARIES} ${GEOMODEL_LIBRARIES} StoreGateLib - HGTD_Identifier InDetSimEvent G4AtlasToolsLib MCTruth GeoModelInterfaces GeoPrimitives ) - set_target_properties( HGTD_G4_SD PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) -diff --git a/InnerDetector/InDetDetDescr/BCMPrimeGeoModelXml/CMakeLists.txt b/InnerDetector/InDetDetDescr/BCMPrimeGeoModelXml/CMakeLists.txt -index 41804d56745..badee4918f4 100644 ---- a/InnerDetector/InDetDetDescr/BCMPrimeGeoModelXml/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/BCMPrimeGeoModelXml/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_component( BCMPrimeGeoModelXml - src/*.cxx - src/components/*.cxx -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} CxxUtils - GaudiKernel DetDescrConditions InDetGeoModelUtils InDetSimEvent BCMPrimeReadoutGeometry ) - -diff --git a/InnerDetector/InDetDetDescr/InDetGeoModelUtils/CMakeLists.txt b/InnerDetector/InDetDetDescr/InDetGeoModelUtils/CMakeLists.txt -index 6baf3845eea..ab60dc23a2d 100644 ---- a/InnerDetector/InDetDetDescr/InDetGeoModelUtils/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/InDetGeoModelUtils/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( XercesC ) - atlas_add_library( InDetGeoModelUtils - src/*.cxx - PUBLIC_HEADERS InDetGeoModelUtils -- INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - LINK_LIBRARIES ${GEOMODEL_LIBRARIES} ${XERCESC_LIBRARIES} - AthenaKernel AthenaBaseComps CxxUtils GaudiKernel - GeoModelInterfaces GeoModelUtilities GeoPrimitives RDBAccessSvcLib -diff --git a/InnerDetector/InDetDetDescr/PLRGeoModelXml/CMakeLists.txt b/InnerDetector/InDetDetDescr/PLRGeoModelXml/CMakeLists.txt -index cbaf2526464..d432b3f1c55 100644 ---- a/InnerDetector/InDetDetDescr/PLRGeoModelXml/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/PLRGeoModelXml/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_component( PLRGeoModelXml - src/*.cxx - src/components/*.cxx -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} - GaudiKernel DetDescrConditions InDetGeoModelUtils InDetSimEvent PixelGeoModelXmlLib PixelReadoutGeometryLib ) - -diff --git a/InnerDetector/InDetDetDescr/PixelGeoModelXml/CMakeLists.txt b/InnerDetector/InDetDetDescr/PixelGeoModelXml/CMakeLists.txt -index 6d46ceea828..c0a17e98543 100644 ---- a/InnerDetector/InDetDetDescr/PixelGeoModelXml/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/PixelGeoModelXml/CMakeLists.txt -@@ -11,7 +11,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_library( PixelGeoModelXmlLib - src/*.cxx - PUBLIC_HEADERS PixelGeoModelXml -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - LINK_LIBRARIES InDetGeoModelUtils PixelReadoutGeometryLib GeometryDBSvcLib - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} - GaudiKernel DetDescrConditions InDetSimEvent ) -diff --git a/InnerDetector/InDetDetDescr/ServiceExtensionGeoModelXml/CMakeLists.txt b/InnerDetector/InDetDetDescr/ServiceExtensionGeoModelXml/CMakeLists.txt -index 4afc7c816fc..2cc077f882f 100644 ---- a/InnerDetector/InDetDetDescr/ServiceExtensionGeoModelXml/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/ServiceExtensionGeoModelXml/CMakeLists.txt -@@ -10,7 +10,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_component( ServiceExtensionGeoModelXml - src/*.cxx - src/components/*.cxx -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} - GaudiKernel InDetGeoModelUtils ) - -diff --git a/InnerDetector/InDetDetDescr/StripGeoModelXml/CMakeLists.txt b/InnerDetector/InDetDetDescr/StripGeoModelXml/CMakeLists.txt -index 4f3dcab75a2..d96e9ef0c4b 100644 ---- a/InnerDetector/InDetDetDescr/StripGeoModelXml/CMakeLists.txt -+++ b/InnerDetector/InDetDetDescr/StripGeoModelXml/CMakeLists.txt -@@ -10,7 +10,7 @@ find_package( GeoModel COMPONENTS GeoModelKernel GeoModelXml ExpressionEvaluator - atlas_add_component( StripGeoModelXml - src/*.cxx - src/components/*.cxx -- PRIVATE_INCLUDE_DIRS ${XERCESC_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${XERCESC_LIBRARIES} ${GEOMODEL_LIBRARIES} CxxUtils - GaudiKernel DetDescrConditions InDetGeoModelUtils InDetSimEvent SCT_ReadoutGeometry GeometryDBSvcLib ) - -diff --git a/InnerDetector/InDetG4/PixelG4_SD/CMakeLists.txt b/InnerDetector/InDetG4/PixelG4_SD/CMakeLists.txt -index af77794fdab..e887345439e 100644 ---- a/InnerDetector/InDetG4/PixelG4_SD/CMakeLists.txt -+++ b/InnerDetector/InDetG4/PixelG4_SD/CMakeLists.txt -@@ -14,7 +14,7 @@ atlas_add_library( PixelG4_SDLib - src/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEANT4_LIBRARIES} ${GTEST_LIBRARIES} ${GEOMODEL_LIBRARIES} G4AtlasToolsLib InDetSimEvent MCTruth StoreGateLib GeoModelInterfaces GeoPrimitives) - set_target_properties( PixelG4_SDLib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt -index e3834fd4d81..2eac87ad8d7 100644 ---- a/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt -+++ b/InnerDetector/InDetG4/SCT_G4_SD/CMakeLists.txt -@@ -14,7 +14,7 @@ atlas_add_library( SCT_G4_SDLib - src/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEANT4_LIBRARIES} ${GTEST_LIBRARIES} ${GEOMODEL_LIBRARIES} G4AtlasToolsLib InDetSimEvent MCTruth StoreGateLib GeoModelInterfaces GeoPrimitives ) - set_target_properties( SCT_G4_SDLib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/LArCalorimeter/LArG4/LArG4FastSimulation/CMakeLists.txt b/LArCalorimeter/LArG4/LArG4FastSimulation/CMakeLists.txt -index 11056af7c88..0b6e52e3ddd 100644 ---- a/LArCalorimeter/LArG4/LArG4FastSimulation/CMakeLists.txt -+++ b/LArCalorimeter/LArG4/LArG4FastSimulation/CMakeLists.txt -@@ -14,7 +14,7 @@ atlas_add_library( LArG4FastSimulation - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${CLHEP_LIBRARIES} AtlasHepMCLib ${GEOMODEL_LIBRARIES} GaudiKernel StoreGateLib GeoSpecialShapes LArG4Code LArReadoutGeometry LArSimEvent G4AtlasToolsLib GeoPrimitives LArG4ShowerLibSvcLib RDBAccessSvcLib GeoModelInterfaces GeoModelUtilities) - set_target_properties( LArG4FastSimulation PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/LArCalorimeter/LArGeoModel/LArGeoH6Cryostats/CMakeLists.txt b/LArCalorimeter/LArGeoModel/LArGeoH6Cryostats/CMakeLists.txt -index db16b4839cc..415f9c53238 100644 ---- a/LArCalorimeter/LArGeoModel/LArGeoH6Cryostats/CMakeLists.txt -+++ b/LArCalorimeter/LArGeoModel/LArGeoH6Cryostats/CMakeLists.txt -@@ -4,14 +4,13 @@ - atlas_subdir( LArGeoH6Cryostats ) - - # External dependencies: --find_package( Eigen ) - find_package( GeoModel COMPONENTS GeoModelKernel GeoGenericFunctions ) - - # Component(s) in the package: - atlas_add_library( LArGeoH6Cryostats - src/*.cxx - PUBLIC_HEADERS LArGeoH6Cryostats -- PRIVATE_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -- LINK_LIBRARIES ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} StoreGateLib -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} -+ LINK_LIBRARIES ${GEOMODEL_LIBRARIES} StoreGateLib GeoPrimitives - PRIVATE_LINK_LIBRARIES GaudiKernel GeoModelInterfaces RDBAccessSvcLib ) - -diff --git a/Simulation/G4Utilities/Geo2G4/CMakeLists.txt b/Simulation/G4Utilities/Geo2G4/CMakeLists.txt -index b3b21d94e97..1d778261270 100644 ---- a/Simulation/G4Utilities/Geo2G4/CMakeLists.txt -+++ b/Simulation/G4Utilities/Geo2G4/CMakeLists.txt -@@ -15,7 +15,7 @@ atlas_add_library( Geo2G4Lib - src/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - PRIVATE_DEFINITIONS ${CLHEP_DEFINITIONS} - LINK_LIBRARIES ${GEANT4_LIBRARIES} ${GEOMODEL_LIBRARIES} ${ROOT_LIBRARIES} AthenaBaseComps GaudiKernel G4AtlasInterfaces G4AtlasToolsLib GeoModelUtilities GeoPrimitives -diff --git a/Simulation/G4Utilities/GeoMaterial2G4/CMakeLists.txt b/Simulation/G4Utilities/GeoMaterial2G4/CMakeLists.txt -index 7ca779f2507..ed156a98236 100644 ---- a/Simulation/G4Utilities/GeoMaterial2G4/CMakeLists.txt -+++ b/Simulation/G4Utilities/GeoMaterial2G4/CMakeLists.txt -@@ -12,7 +12,7 @@ atlas_add_library( GeoMaterial2G4 - src/*.cxx - OBJECT - PUBLIC_HEADERS GeoMaterial2G4 -- INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} - LINK_LIBRARIES ${GEANT4_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaBaseComps - PRIVATE_LINK_LIBRARIES CxxUtils GeoModelUtilities ) - set_target_properties( GeoMaterial2G4 PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) -diff --git a/TileCalorimeter/TileG4/TileAncillary/CombinedScintillator/CMakeLists.txt b/TileCalorimeter/TileG4/TileAncillary/CombinedScintillator/CMakeLists.txt -index 35200501be8..2b29e3fb3a2 100644 ---- a/TileCalorimeter/TileG4/TileAncillary/CombinedScintillator/CMakeLists.txt -+++ b/TileCalorimeter/TileG4/TileAncillary/CombinedScintillator/CMakeLists.txt -@@ -19,7 +19,7 @@ atlas_add_library( CombinedScintillator - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} CaloIdentifier StoreGateLib GaudiKernel G4AtlasToolsLib GeoMaterial2G4 GeoModelInterfaces TileSimEvent ) - set_target_properties( CombinedScintillator PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/TileCalorimeter/TileG4/TileAncillary/DeadMaterial/CMakeLists.txt b/TileCalorimeter/TileG4/TileAncillary/DeadMaterial/CMakeLists.txt -index 8c0a71b66eb..d7532619444 100644 ---- a/TileCalorimeter/TileG4/TileAncillary/DeadMaterial/CMakeLists.txt -+++ b/TileCalorimeter/TileG4/TileAncillary/DeadMaterial/CMakeLists.txt -@@ -19,7 +19,7 @@ atlas_add_library( DeadMaterial - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} StoreGateLib GaudiKernel G4AtlasToolsLib GeoMaterial2G4 GeoModelInterfaces ) - set_target_properties( DeadMaterial PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/TileCalorimeter/TileG4/TileAncillary/LarCrate/CMakeLists.txt b/TileCalorimeter/TileG4/TileAncillary/LarCrate/CMakeLists.txt -index e670527a2d5..80449318f5b 100644 ---- a/TileCalorimeter/TileG4/TileAncillary/LarCrate/CMakeLists.txt -+++ b/TileCalorimeter/TileG4/TileAncillary/LarCrate/CMakeLists.txt -@@ -19,7 +19,7 @@ atlas_add_library( LarCrate - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} StoreGateLib GaudiKernel G4AtlasToolsLib GeoMaterial2G4 GeoModelInterfaces ) - set_target_properties( LarCrate PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/TileCalorimeter/TileG4/TileAncillary/MuonWall/CMakeLists.txt b/TileCalorimeter/TileG4/TileAncillary/MuonWall/CMakeLists.txt -index aa54c9bb927..195db78b95e 100644 ---- a/TileCalorimeter/TileG4/TileAncillary/MuonWall/CMakeLists.txt -+++ b/TileCalorimeter/TileG4/TileAncillary/MuonWall/CMakeLists.txt -@@ -19,7 +19,7 @@ atlas_add_library( MuonWall - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} CaloIdentifier StoreGateLib GaudiKernel G4AtlasToolsLib GeoModelInterfaces GeoMaterial2G4 TileSimEvent ) - set_target_properties( MuonWall PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/TileCalorimeter/TileG4/TileAncillary/PhantomCalorimeter/CMakeLists.txt b/TileCalorimeter/TileG4/TileAncillary/PhantomCalorimeter/CMakeLists.txt -index 4c6a4dbf265..8d52fe491b9 100644 ---- a/TileCalorimeter/TileG4/TileAncillary/PhantomCalorimeter/CMakeLists.txt -+++ b/TileCalorimeter/TileG4/TileAncillary/PhantomCalorimeter/CMakeLists.txt -@@ -19,7 +19,7 @@ atlas_add_library( PhantomCalorimeter - src/components/*.cxx - OBJECT - NO_PUBLIC_HEADERS -- PRIVATE_INCLUDE_DIRS ${GEANT4_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ PRIVATE_INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${GEANT4_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${XERCESC_INCLUDE_DIRS} - PRIVATE_LINK_LIBRARIES ${GEANT4_LIBRARIES} ${XERCESC_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} CaloIdentifier StoreGateLib GaudiKernel G4AtlasToolsLib GeoMaterial2G4 GeoModelInterfaces TileSimEvent ) - set_target_properties( PhantomCalorimeter PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ATLAS_GEANT4_USE_LTO} ) - -diff --git a/Tracking/Acts/ActsGeometry/CMakeLists.txt b/Tracking/Acts/ActsGeometry/CMakeLists.txt -index 0b8b3661e18..fd1f4f9eb5a 100644 ---- a/Tracking/Acts/ActsGeometry/CMakeLists.txt -+++ b/Tracking/Acts/ActsGeometry/CMakeLists.txt -@@ -68,7 +68,7 @@ atlas_add_component( ActsGeometry - src/ActsPropStepRootWriterSvc.cxx - src/ActsCaloTrackingVolumeBuilder.cxx - src/components/*.cxx -- INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} ${ROOT_LIBRARIES} - ActsGeometryInterfacesLib - ActsGeometryLib -diff --git a/graphics/GeometryJiveXML/CMakeLists.txt b/graphics/GeometryJiveXML/CMakeLists.txt -index 95d7e159bcc..48410c04df8 100644 ---- a/graphics/GeometryJiveXML/CMakeLists.txt -+++ b/graphics/GeometryJiveXML/CMakeLists.txt -@@ -11,5 +11,5 @@ find_package( CLHEP ) - atlas_add_component( GeometryJiveXML - src/*.cxx - src/components/*.cxx -- INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaBaseComps CaloDetDescrLib CaloDetDescrUtils GaudiKernel InDetIdentifier InDetReadoutGeometry JiveXMLLib LArReadoutGeometry MuonIdHelpersLib MuonReadoutGeometry PixelReadoutGeometryLib SCT_ReadoutGeometry StoreGateLib TRT_ReadoutGeometry TileDetDescr ) -diff --git a/graphics/VP1/VP1Base/CMakeLists.txt b/graphics/VP1/VP1Base/CMakeLists.txt -index 0bda34efb86..987c26dca95 100644 ---- a/graphics/VP1/VP1Base/CMakeLists.txt -+++ b/graphics/VP1/VP1Base/CMakeLists.txt -@@ -33,7 +33,7 @@ set( CMAKE_AUTORCC TRUE ) - # declaration of PRIVATE_INCLUDE_DIRS. - atlas_add_library( VP1Base VP1Base/*.h src/*.cxx src/*.qrc - PUBLIC_HEADERS VP1Base -- INCLUDE_DIRS ${QT5_INCLUDE_DIRS} ${SOQT_INCLUDE_DIRS} ${COIN3D_INCLUDE_DIRS} ${GEOMODEL_INCLUDE_DIRS} -+ INCLUDE_DIRS ${GEOMODEL_INCLUDE_DIRS} ${QT5_INCLUDE_DIRS} ${SOQT_INCLUDE_DIRS} ${COIN3D_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} - LINK_LIBRARIES ${QT5_LIBRARIES} ${SOQT_LIBRARIES} ${COIN3D_LIBRARIES} ${GEOMODEL_LIBRARIES} GeoPrimitives xAODBase - PRIVATE_LINK_LIBRARIES VP1HEPVis ) --- -2.34.1 - diff --git a/athena_ci/test_athena.sh b/athena_ci/test_athena.sh index 406930c7d12502fd1b42c4606be1df0102f8759c..c3cbc378807d977129671e0022151f3641175de5 100755 --- a/athena_ci/test_athena.sh +++ b/athena_ci/test_athena.sh @@ -12,9 +12,6 @@ export ATHENA_REF=main _pwd=$PWD -export ATHENA_SOURCE=$PWD/athena - - tmp=/tmp/ath_build rm -rf $tmp mkdir -p $tmp diff --git a/cmake/GeoModel-version.cmake b/cmake/GeoModel-version.cmake index ab98dd532b3bf3d1dbc39c6af6ad71b1829b7dd1..80eb7d554e0435b1d28188d4f45cec1c832493ce 100644 --- a/cmake/GeoModel-version.cmake +++ b/cmake/GeoModel-version.cmake @@ -1,5 +1,5 @@ # Set up the version of GeoModel as a cache variable, so that other # sub-projects could use this value. -set( GeoModel_VERSION "5.6.0" CACHE STRING +set( GeoModel_VERSION "6.6.0" CACHE STRING "Version of the GeoModel project" ) diff --git a/cmake/SetupCoin3D.cmake b/cmake/SetupCoin3D.cmake index 98d818f55d62689c87acbffa67c1077e43d6a3dc..5d13fc81d931d621689b267a02000a0d00823d4f 100644 --- a/cmake/SetupCoin3D.cmake +++ b/cmake/SetupCoin3D.cmake @@ -82,8 +82,8 @@ if( GEOMODEL_USE_BUILTIN_COIN3D ) ExternalProject_Add( SoQtBuiltIn PREFIX "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SoQtBuild" INSTALL_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SoQtInstall" - URL "https://github.com/coin3d/soqt/releases/download/SoQt-1.6.0/soqt-1.6.0-src.tar.gz" - URL_MD5 "724996aedad2a33760dc36f08ceeda22" + URL "https://github.com/coin3d/soqt/releases/download/v1.6.2/soqt-1.6.2-src.tar.gz" + URL_MD5 "70ef0990e009d806c59941d819a62c98" CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Coin3DInstall -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SoQtInstall diff --git a/documentation/docs/components/geomodeltools/gmcat/index.md b/documentation/docs/components/geomodeltools/gmcat/index.md new file mode 100644 index 0000000000000000000000000000000000000000..79e75363eb22c9b4616e4d4cc96dd7809cf33f97 --- /dev/null +++ b/documentation/docs/components/geomodeltools/gmcat/index.md @@ -0,0 +1,34 @@ +# GeoModelCat + +GeoModelCat (`gmcat`) is a command line tool that allows to concatenate different geometry files into a single final SQLite file. It is possible to concatenate plugins (.dylib/.so) and/or SQLite (.db) files. + +*gmcat* has the following parameters: + +``` bash +-o [MANDATORY] Name of the output .db file +-v [OPTIONAL] Print verbose output to the screen (default: direct verbose output to /tmp) +-g [OPTIONAL] Path to the local GeoModelATLAS repository (default: .) + +``` + +## Examples + +In order to combine three different plugins into one single detector file one need to call gmcat in the following way: + +```bash + +./gmcat libPixelGeoPlugin.0.0.1.dylib libSCTGeoPlugin.0.0.1.dylib libTRTGeoPlugin.0.0.1.dylib -o InnerDetector.db + +``` + +<!--To convert a GDML geometry and save it in SQLite format with *gdml2gm* :--> +<!--``` bash--> +<!--./gdml2gm -f myGeometry.gdml -o myGeometry.db--> +<!--``` --> +<!----> +<!--To visualize a GDML geometry with *gmex*, the user has to set the following environment variable: GDML_FILE_NAME. It has to point to the GDML file that the user wants to plug into *gmex*. Then it is sufficient to call gmex together with the *libGDMLtoGM.dylib/so* library:--> +<!----> +<!--``` bash--> +<!--export GDML_FILE_NAME=<path-to-my-geometry-file>/myGeometry.gdml--> +<!--./gmex ../lib/libGDMLtoGM.dylib --> +<!--``` --> diff --git a/documentation/docs/components/geomodeltools/gmstatistics/index.md b/documentation/docs/components/geomodeltools/gmstatistics/index.md new file mode 100644 index 0000000000000000000000000000000000000000..87fde0f53b1b424733a0c67335629cac1c1d7a08 --- /dev/null +++ b/documentation/docs/components/geomodeltools/gmstatistics/index.md @@ -0,0 +1,87 @@ +# GeoModelStatistics + +GeoModelStatistics (`gmstatistics`) is a command line tool that allows to extract information on the memory footprint of your detector description code. It takes one or more plugins (.dylib/.so) as input. + +*gmstatistics* has the following parameters: + +``` bash +./gmstatistics [-p] [plugin1.dylib] [plugin2.dylib] + +``` + +## Examples + +If you want to analyse the memory occupancy of your plugin (i.e. PixelGeoPlugin) you can type: + +```bash +./gmstatistics ../lib/libPixelGeoPlugin.0.dylib + +``` + +This is the output retrieved by gmstatistics: + +```bash + GeoLogVol 9998 instances 2239552 bytes + GeoTransform 9856 instances 1419264 bytes + GeoBox 9835 instances 472080 bytes + GeoPhysVol 7941 instances 1905840 bytes + GeoNameTag 4904 instances 235392 bytes + GeoIdentifierTag 4293 instances 68688 bytes + GeoFullPhysVol 4088 instances 1896832 bytes + GeoAlignableTransform 2059 instances 494160 bytes + GeoAlignableTransform[216] 2058 instances 32928 bytes + GeoShapeShift 1914 instances 306240 bytes + GeoShapeSubtraction 1190 instances 57120 bytes + GeoMaterial 812 instances 116928 bytes + GeoMaterial[56] 794 instances 48752 bytes + GeoTube 746 instances 35808 bytes + GeoMaterial[120] 571 instances 25408 bytes + GeoShapeUnion 492 instances 23616 bytes + GeoMaterial[72] 447 instances 35904 bytes + GeoTubs 190 instances 12160 bytes + GeoMaterial[64] 167 instances 5280 bytes + GeoLogVol[32] 132 instances 4544 bytes + GeoElement 97 instances 7760 bytes + GeoMaterial[128] 87 instances 2080 bytes + GeoPhysVol[48] 71 instances 2720 bytes + GeoMaterial[32] 60 instances 1920 bytes + GeoPhysVol[40] 49 instances 3392 bytes + GeoSimplePolygonBrep 45 instances 3600 bytes + GeoTrap 44 instances 4928 bytes + GeoMaterial[136] 36 instances 2144 bytes + GeoSimplePolygonBrep[40] 29 instances 960 bytes + GeoSimplePolygonBrep[64] 29 instances 960 bytes + GeoPhysVol[56] 22 instances 2560 bytes + GeoTrd 20 instances 1280 bytes + GeoSimplePolygonBrep[32] 16 instances 1120 bytes + GeoCons 15 instances 1200 bytes + GeoSimplePolygonBrep[48] 11 instances 832 bytes + GeoFullPhysVol[56] 10 instances 17408 bytes + GeoPgon 10 instances 1280 bytes + GeoSimplePolygonBrep[56] 9 instances 576 bytes + GeoPgon[48] 9 instances 144 bytes + GeoPgon[56] 9 instances 144 bytes + GeoPara 8 instances 640 bytes + GeoFullPhysVol[40] 7 instances 20992 bytes + GeoPgon[104] 7 instances 112 bytes + GeoSimplePolygonBrep[72] 3 instances 192 bytes + GeoPgon[72] 2 instances 32 bytes + GeoPgon[80] 2 instances 32 bytes + GeoNameTag[32] 1 instances 32 bytes + GeoElement[56] 1 instances 16 bytes + GeoPgon[96] 1 instances 16 bytes +Total GeoModel object allocation: 9.51557MB + +``` + +<!--To analyse a GDML geometry and save it in SQLite format with *gdml2gm* :--> +<!--``` bash--> +<!--./gdml2gm -f myGeometry.gdml -o myGeometry.db--> +<!--``` --> +<!----> +<!--To visualize a GDML geometry with *gmex*, the user has to set the following environment variable: GDML_FILE_NAME. It has to point to the GDML file that the user wants to plug into *gmex*. Then it is sufficient to call gmex together with the *libGDMLtoGM.dylib/so* library:--> +<!----> +<!--``` bash--> +<!--export GDML_FILE_NAME=<path-to-my-geometry-file>/myGeometry.gdml--> +<!--./gmex ../lib/libGDMLtoGM.dylib --> +<!--``` --> diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 1.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 1.png new file mode 100644 index 0000000000000000000000000000000000000000..96dc92a81ef75a0bdd0187636bd9f5307c666f51 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 1.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 2.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 2.png new file mode 100644 index 0000000000000000000000000000000000000000..35a95c10f30bd9998c178c982a4447a8b3639e96 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 2.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 3.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 3.png new file mode 100644 index 0000000000000000000000000000000000000000..cc0265d4141a1b2dd13eefd49594e47c36b9e800 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 3.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 4.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 4.png new file mode 100644 index 0000000000000000000000000000000000000000..7aa8a388a9ec3ee04c4fa5547e50591a925bb0f8 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 4.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 4a.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 4a.png new file mode 100644 index 0000000000000000000000000000000000000000..db4b53355cde7abd92d486b8836aec3c836a8da7 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 4a.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 5.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 5.png new file mode 100644 index 0000000000000000000000000000000000000000..5f83e3a3360c255c59954013945d0b3e3f7414b1 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 5.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/Fig 6.png b/documentation/docs/components/geomodelvisualization/gmex/Fig 6.png new file mode 100644 index 0000000000000000000000000000000000000000..319345cb10008fbdd70a04cde11b656975f19bd8 Binary files /dev/null and b/documentation/docs/components/geomodelvisualization/gmex/Fig 6.png differ diff --git a/documentation/docs/components/geomodelvisualization/gmex/index.md b/documentation/docs/components/geomodelvisualization/gmex/index.md index d763d21f90266e86aa616de37ca2ed26c2ca3efe..7981c5991179b9f8ceaf95187c538f4dab987ccd 100644 --- a/documentation/docs/components/geomodelvisualization/gmex/index.md +++ b/documentation/docs/components/geomodelvisualization/gmex/index.md @@ -1,12 +1,71 @@ # GeoModelVisualization -GeoModelVisualization (gmex) +GeoModelVisualization (gmex) is a 3D interactive visualization tool that allows you to display, navigate and debug complex detector geometries as the HEP experiments ones. + +## Examples + +In order to launch gmex you could simply type: ``` bash ./gmex ``` +This will open a dialogue window where you will be able to select a SQLite (.db) file that you want to display (see Figure 1). -## Examples +{{ imgutils_image_caption('Fig 1.png', + alt='GmexGui', + cap='Figure 1: Gmex GUI with dialogue window to select the geometry to be visualized.', + urlFix=False) +}} + +Alternatively you can feed the geometry to `gmex` directly via the command line. For example: + +``` bash +./gmex myGeometry.db +``` + +Once the geometry is selected, by clicking on the `Geo`tab on the left, gmex will diplay a list of all the subdetectors present in the loaded geometry, as shown in Figure 2 +{{ imgutils_image_caption('Fig 2.png', + alt='Subdetectors', + cap='Figure 2: List of all the subdetectors present in the loaded geometry.', + urlFix=False) +}} + +In order to visualize all or some of them you have to click on the respective checkbox and click on the `eye icon` on the right (3rd icon from the top, in the right panel). + +{{ imgutils_image_caption('Fig 3.png', + alt='SelectedGeometry', + cap='Figure 3: Visualization of the selected geometry.', + urlFix=False) +}} + +Now that you have loaded your geometry you can start investigating it. A good way to improve the visualization experience is to apply Phi sector cutouts. To do that you have to click on the `Display` tab under `Geo` (Figure 4), unselect a few of the `phi sector cutaways` (Fig 4a) and then click `Close`. + +{{ imgutils_image_caption('Fig 4.png', + alt='DisplayTab', + cap='Figure 4: `Display` tab under `Geo`.', + urlFix=False) +}} + +{{ imgutils_image_caption('Fig 4a.png', + alt='PhiSector', + cap='Figure 4a: Select/unselect the `phi sector cutaways`.', + urlFix=False) +}} + +At this point you have a cutaway view of your detector (Fig 5) and you can start investigating it by "opening" it. + +{{ imgutils_image_caption('Fig 5.png', + alt='Cutaway', + cap='Figure 5: Cutaway view of the ATLAS detector.', + urlFix=False) +}} + +In order to do so you can follow the instructions written on the bottom part of the left panel. For instance, if you want to expand to child volumes you will have to use the following combination 'Ctrl/Cmd'+click. In this way you will remove the first layer of your geometry and be able to inspect its content (see Fig. 6). -To run *gmex* +{{ imgutils_image_caption('Fig 6.png', + alt='TrackDisplay', + cap='Figure 6: Cutaway view of the ATLAS detector without the first mother volume layer.', + urlFix=False) +}} + diff --git a/documentation/docs/components/kernel/overview/MaterialGeometry.md b/documentation/docs/components/kernel/overview/MaterialGeometry.md index a94751a87e126ccd999554c77da97343ef9a9d53..1aee36f31594fb8868d703ec61934d7b11d86410 100644 --- a/documentation/docs/components/kernel/overview/MaterialGeometry.md +++ b/documentation/docs/components/kernel/overview/MaterialGeometry.md @@ -1,17 +1,17 @@ ## Material Geometry -Material geometry consists of a set of classes that bears a large resemblance to the material geometry within GEANT4. These classes, however, are designed to take a minimal size in memory. This requirement determines the basic data structure used to hold the data for the geometry description. That structure is a graph of nodes consisting of both volumes and their properties. The tree is built directly and accessed in a way that provides users access to volumes and, simultaneously, to the properties accumulated during graph traversal that apply to the volumes. See the [Actions](/components/kernel/overview/#actions) section, below. +Material geometry consists of a set of classes that bears a large resemblance to the material geometry within GEANT4. These classes, however, are designed to take a minimal size in memory. This requirement determines the basic data structure used to hold the data for the geometry description. That structure is a graph of nodes consisting of both volumes and their properties. The tree is built directly and accessed in a way that provides users access to volumes and, simultaneously, to the properties accumulated during graph traversal that apply to the volumes. See the [Actions](#actions) section, below. -The requirement of minimizing the memory consumption has led us to foresee a system in which objects (as well as classes) in the detector description can be re-used. This is called shared instancing and is described below. It essentially means that an element, compound, volume, or entire tree of volumes may be referenced by more than one object in the detector description. Shared instancing can make the deletion of objects difficult unless special measures are taken. We have used reference counting in order to facilitate clean-up and make it less error prone. See the section [How Objects are Created and Destroyed](/components/kernel/overview/#how-objects-are-created-and-destroyed). +The requirement of minimizing the memory consumption has led us to foresee a system in which objects (as well as classes) in the detector description can be re-used. This is called shared instancing and is described below. It essentially means that an element, compound, volume, or entire tree of volumes may be referenced by more than one object in the detector description. Shared instancing can make the deletion of objects difficult unless special measures are taken. We have used reference counting in order to facilitate clean-up and make it less error prone. See the section [How Objects are Created and Destroyed](#how-objects-are-created-and-destroyed). Before creating hierarchies of volumes representing positioned pieces of detectors, we need to create lower-level primitives, such as elements, materials, and shapes. So, we will discuss these first. ### Materials -Materials are represented within the geometry kernel class library by the class [GeoMaterial](/components/kernel/reference/#geomaterial), and are built up by combining different elements, specifying each element and its fraction-by-mass. Material constants such as the radiation length and the interaction length, as well as constants for ionization energy loss, are available through the interface but do not need to be provided to the constructor. Instead, they are computed from the material’s element list. +Materials are represented within the geometry kernel class library by the class [GeoMaterial](../reference/#geomaterial), and are built up by combining different elements, specifying each element and its fraction-by-mass. Material constants such as the radiation length and the interaction length, as well as constants for ionization energy loss, are available through the interface but do not need to be provided to the constructor. Instead, they are computed from the material’s element list. -The class [GeoElement](/components/kernel/reference/#geoelement) is used to represent elements. Their constructor requires a name, symbol, and effective Z and A. These properties can also be retrieved from the element. +The class [GeoElement](../reference/#geoelement) is used to represent elements. Their constructor requires a name, symbol, and effective Z and A. These properties can also be retrieved from the element. `GeoMaterial` objects are created by specifying a name and a density. The material is “empty†until elements are added, one by one, using the `GeoMaterial::add()` method, which is overloaded so that one may provide either elements or prebuilt materials. After all materials are added, the `GeoMaterial::lock()` method must be called, which prevents further elements or materials from being added. @@ -21,20 +21,15 @@ Material classes, as well as all other classes, use the units defined in `GeoMod #include "GeoModelKernel/Units.h" #define SYSTEM_OF_UNITS GeoModelKernelUnits ... -GeoMaterial *water = new GeoMaterial(“H20â€, 1.0*SYSTEM_OF_UNITS::gram/SYSTEM_OF_UNITS::cm3); +GeoIntrusivePtr<GeoMaterial> water{new GeoMaterial(“H20â€, 1.0*SYSTEM_OF_UNITS::gram/SYSTEM_OF_UNITS::cm3)}; ``` To finish constructing this material, water, one needs to follow the constructor with the following lines ```cpp -GeoElement *hydrogen = new GeoElement("Hydrogen", - "H", - 1.0, - 1.010); -GeoElement *oxygen = new GeoElement("Oxygen", - "O", - 8.0, - 16.0); +GeoIntrusivePtr<GeoElement> hydrogen{new GeoElement("Hydrogen", "H", 1.0, 1.010)}; +GeoIntrusivePtr<GeoElement> oxygen{new GeoElement("Oxygen", "O", 8.0, 16.0)}; + water->add(hydrogen,0.11); water->add(oxygen,0.89); water->lock(); @@ -44,7 +39,7 @@ The materials are then used to together with shapes to form logical volumes, dis ### Shapes -Shapes are created using the new operator. Essentially, shapes within this system are required to store and provide access to the geometrical constants that describe their geometrical form. This data is, insofar as possible, to be specified on the constructor. +Essentially, shapes within this system are required to store and provide access to the geometrical constants that describe their geometrical form. This data is, insofar as possible, to be specified on the constructor. Shapes are extensible and custom shapes can be built. @@ -55,7 +50,7 @@ double length = 100*SYSTEM_OF_UNITS::cm; double width = 200*SYSTEM_OF_UNITS::cm; double depth = 33*SYSTEM_OF_UNITS::cm; -GeoBox* box = new GeoBox(length, width, depth); +GeoIntrusivePtr<GeoBox> box{new GeoBox(length, width, depth)}; ``` Most objects can be constructed along similar lines; exceptions are objects with multiple planes such as polycones and polygons; their interface allows one to add planes successively. For the polycone, for example, the shape is built as follows: @@ -65,7 +60,7 @@ double dphi = 10*SYSTEM_OF_UNITS::deg; double sphi = 40*SYSTEM_OF_UNITS::deg; // Create polycone object -GeoPcon* polycone = new GeoPcon(dphi,sphi); +GeoIntrusivePtr<GeoPcon> polycone{new GeoPcon(dphi,sphi)}; // Add planes successively double z0 = 0.; @@ -86,12 +81,14 @@ polycone->addPlane(z2, rmin2, rmax2); This creates a polycone whose projection subtends an angle of 10 degrees between 40 degrees and 50 degrees, with planes at z=0, z=10, and z=15, with minimum and maximum radii there of (5,10), (6, 12), and (5,10). -The shapes can provide their data to a client through their accessors, and in addition support several other operations. Boolean operations on shapes are possible. They can be accomplished through Boolean operators in class [GeoShape](/components/kernel/reference/#introduction_1): +The shapes can provide their data to a client through their accessors, and in addition support several other operations. Boolean operations on shapes are possible. They can be accomplished through Boolean operators in class [GeoShape](../reference/#introduction_1): ```cpp -GeoShape * donut = new GeoTube(); -GeoShape * hole = new GeoTube(); -const GeoShape & result = (donut->subtract(*hole)); +#include "GeoModelKernel/GeoShapeSubtraction.h" +... +GeoIntrusivePtr<GeoShape> donut{new GeoTube(.....)}; +GeoIntrusivePtr<GeoShape> hole{new GeoTube(.....)}; +const GeoShape & result = donut->subtract(*hole); ``` The result of a Boolean operation is a shape in a boolean expression tree that can, for example, be decoded when the geometry is declared to GEANT4. @@ -114,9 +111,7 @@ The methods `typeId()` and `classTypeId()` return unsigned integers, making the Logical volumes represent, conceptually, a specific manufactured piece that can be placed in one or more locations around the detector. A logical volume is created by specifying a name tag for the volume, a shape, and a material: ```cpp -const GeoLogVol *myLog = new GeoLogVol("MyLogVol", - myShape, - gNitrogen); +GeoIntrusivePtr<const GeoLogVol> myLog{GeoLogVol("MyLogVol", myShape, myMaterial)}; ``` ### Physical Volumes and the Geometry Graph @@ -126,17 +121,17 @@ Having created elements, materials, shapes, and logical volumes, you are now rea * Regular Physical Volumes, designed to be small. * Full Physical Volumes, designed to hold in cache complete information about how the volume is located with respect to the world volume, its formatted name string and other important information. -There is a common abstract [base class](/components/kernel/overview/#geomodel-kernel-overview) for all of these: `GeoVPhysVol`. In addition both the full physical volumes have another layer of abstraction, `GeoVFullPhysVol`. All physical volumes allow access to their children. +There is a common abstract [base class](#geomodel-kernel-overview) for all of these: `GeoVPhysVol`. In addition the full physical volumes have another layer of abstraction, `GeoVFullPhysVol`. All physical volumes allow access to their children. -The concrete subclasses that you have at your disposition for detector description are called [GeoPhysVol](/components/kernel/reference/#geophysvol) and [GeoFullPhysVol](/components/kernel/reference/#geofullphysvol). Both of these have a method to add either volumes or volume properties: +The concrete subclasses that you have at your disposition for detector description are called [GeoPhysVol](../reference/#geophysvol) and [GeoFullPhysVol](../reference/#geofullphysvol). Both of these have a method to add either volumes or volume properties: ```cpp -GeoPhysVol* myVol; +GeoIntrusivePtr<GeoPhysVol> myVol{new GeoPhysVol(myLog)}; myVol->add(aTransformation); myVol->add(anotherVolume); ``` -When you add a transformation, you change the position of the subsequent volume with respect to the parent. If you add no transformation, you will not shift the daughter relative to the parent and commonly will create a daughter which is centered directly in the parent. If you add more than one transformation to the volume before adding a parent, they will be multiplied. The last transformation to be added is applied first to the child. Transformations are discussed next. Like logical volumes, they may be shared. +When you add a transformation, you change the position of the subsequent volume with respect to the parent. If you add no transformation, you will not shift the daughter relative to the parent and commonly will create a daughter which is centered directly in the parent. If you add more than one transformation to the volume before adding a child volume, they will be multiplied. The last transformation to be added is applied first to the child. Transformations are discussed next. Like logical volumes, they may be shared. Like physical volumes, transformations come in two types: @@ -145,31 +140,31 @@ Like physical volumes, transformations come in two types: When you create a transformation, you must choose the type. -The model of the raw geometry is a tree of nodes, property nodes and volume nodes. The tree can be thought of as a tree of volumes, each one “having†a set of properties (inherited from property nodes throughout the tree). The subsystem engineer judiciously chooses which of the volumes are to contain full, cached, position information – usually, these first-class volumes are to be associated with a detector. He or she also judiciously decides which of the transformations are to be alignable—usually these are the transformations which position something that ultimately has a detector bolted, glued, riveted or otherwise clamped onto a sensitive piece. Then, the developer can apply several techniques for keeping track of these pointers so that the important volumes can later be connected to detector elements, and the alignable transformations can be connected to the alignment database for periodic updating. +The model of the raw geometry is a tree of nodes, property nodes and volume nodes. The tree can be thought of as a tree of volumes, each one “having†a set of properties (inherited from property nodes throughout the tree). The subsystem engineer judiciously chooses which of the volumes are to contain full, cached, position information – usually, these first-class volumes are to be associated with a detector. The subsystem engineer also judiciously decides which of the transformations are to be alignable—usually these are the transformations which position something that ultimately has a detector bolted, glued, riveted or otherwise clamped onto a sensitive piece. Then, the developer can apply several techniques for keeping track of these pointers so that the important volumes can later be connected to detector elements, and the alignable transformations can be connected to the alignment database for periodic updating. Finally, we provide three mechanisms for giving names to volumes: * Do nothing. The volume will be called "ANON". -* Add a [GeoNameTag](/components/kernel/reference/#geonametag) object to the graph before adding a volume. The next volume to be added will be given the `GeoNameTag`’s name. -* Add a [GeoSerialDenominator](/components/kernel/reference/#geoserialdenominator) object to the graph before adding more volumes. The volumes will be named according to the base name of the `GeoSerialDenominator`, plus given a serial number: 0, 1, 2, 3, ... +* Add a [GeoNameTag](../reference/#geonametag) object to the graph before adding a volume. The next volume to be added will be given the `GeoNameTag`’s name. +* Add a [GeoSerialDenominator](../reference/#geoserialdenominator) object to the graph before adding more volumes. The volumes will be named according to the base name of the `GeoSerialDenominator`, plus given a serial number: 0, 1, 2, 3, ... In effect this last method can be thought of as a way of parametrizing the name of the volume. ### Actions -There are two ways of getting raw geometry information out of the model. Suppose that one has access to a particular physical volume (it could be the “World†physical volume). One can access its children, there names, and their transformations with respect to the parent in the following way: +There are two ways of getting raw geometry information out of the model. Suppose that one has access to a particular physical volume (it could be the “World†physical volume). One can access its children, their names, and their transformations with respect to the parent in the following way: ```cpp -PVConstLink myVol; +PVConstLink myVol; // PVConstLink is a typedef to GeoIntrusivePtr<const GeoVPhysVol> for(int c=0; c<myVol->getNChildVols(); ++c) { PVConstLink child = myVol->getChildVol(c); GeoTrf::Transform3D xf = getXToChildVol(c); } ``` -One could then iterate in a similar way over the grand children, by using a double loop. Ultimately one would probably to visit all the volumes, whatever their depth in the tree, so probably this would call on some form of recursion. An easy way would be to embed the small sample of code shown above in a recursive subroutine or method. That would be fine and is conceptually simple. However, within the geometry model’s kernel, we have provided an alternate, probably better way to visit the entire tree. +One could then iterate in a similar way over the grand children, by using a double loop. Ultimately one would probably want to visit all the volumes, whatever their depth in the tree, so probably this would call on some form of recursion. An easy way would be to embed the small sample of code shown above in a recursive subroutine or method. That would be fine and is conceptually simple. However, within the geometry model’s kernel, we have provided an alternate, probably better way to visit the entire tree. -That mechanism involves a [GeoVolumeAction](). A `GeoVolumeAction` is a way (for applications programmers) to obtain recursive behavior without writing any recursive routines. It’s a class with a handler routine (`handleVPhysVol()`) which is called for each node before (or after) it is called on its children. This can descend to an arbitrary depth in the tree. The `GeoVolumeAction` is an abstract base class and should be subclassed by programmers to suit their needs. Another class `TemplateVolAction` is provided as a template that one can take and modify. To run it, one does this: +That mechanism involves a `GeoVolumeAction`. A `GeoVolumeAction` is a way (for applications programmers) to obtain recursive behavior without writing any recursive routines. It’s a class with a handler routine (`handleVPhysVol()`) which is called for each node before (or after) it is called on its children. This can descend to an arbitrary depth in the tree. The `GeoVolumeAction` is a base class and should be subclassed by programmers to suit their needs. Another class `TemplateVolAction` is provided as a template that one can take and modify. To run it, one does this: ```cpp PVConstLink myVol; @@ -179,13 +174,13 @@ myVol->apply(tempVolAction); The `handleVPhysVol()` function within the `TemplateVolAction` is where the work is supposed to get done. It will be invoked repeatedly, once for each node in the tree. Within that routine, one can access the physical volume as a subroutine parameter, and information about the transformation and the path to the node through the base class for actions, `GeoVolumeAction`. The action can be designed to run from the bottom up or from the top down. -Incidentally, there is another kind of action in the library called [GeoNodeAction](). `GeoNodeActions` visit all nodes in the geometry tree, including naming nodes, transformation nodes, and perhaps other property nodes that may be added later to the model. Since usually an application programmer wants to see volumes and their properties, the `GeoVolumeAction` is more suited to casual users than the `GeoNodeAction`, which is considered mostly internal. However the usage is similar, except that node actions are “exec’d†while volume actions are “appliedâ€. Here for example is how we can rewrite the loop over children using volume actions: +Incidentally, there is another kind of action in the library called `GeoNodeAction`. `GeoNodeActions` visit all nodes in the geometry tree, including naming nodes, transformation nodes, and perhaps other property nodes that may be added later to the model. Since usually an application programmer wants to see volumes and their properties, the `GeoVolumeAction` is more suited to casual users than the `GeoNodeAction`, which is considered mostly internal. However the usage is similar, except that node actions are “exec’d†while volume actions are “appliedâ€. Here for example is how we can rewrite the loop over children using volume actions: ```cpp PVConstLink myVol; for(int c=0; c<myVol->getNChildVols(); ++c) { - GeoAccessVolumeAction av(c); - myVol->exec(&ac); + GeoAccessVolumeAction av(c,nullptr); + myVol->exec(&av); PVConstLink child = av.getVolume(); GeoTrf::Transform3D xf = av.getTransform(); } @@ -197,7 +192,7 @@ This, it turns out, will execute faster than the loop shown above, which (intern We now come to the important topic of how objects in this system are created and destroyed. The geometry kernel uses a technique called reference counting. Reference counting, shortly stated, is a way to perform an automatic garbage collection of nodes that are no longer in use. This is important when describing a large tree of information, much of which is ideally to be shared — used again and again in many places. -You may have noticed, in several code examples used throughout the GeoModel Kernel Overview section many of the objects have been created using operator `new`. You may have also noticed, if you’ve tried to play around with the kernel classes, that statements which allocate most kernel classes on the stack, such as +You may have noticed, in several code examples used throughout the GeoModel Kernel Overview section many of the objects have been created using operator `new`, and the resulting pointers were never used directly. Instead they have always been wrapped into objects of a special smart pointer class `GeoIntrusivePtr`. You may have also noticed, if you’ve tried to play around with the kernel classes, that statements which allocate most kernel classes on the stack, such as ```cpp GeoBox box(100*SYSTEM_OF_UNITS::cm @@ -210,13 +205,13 @@ are not allowed. Who is going to clean up the memory after all these `new `opera Let's consider this example: ```cpp -const GeoBox* worldBox = new GeoBox(100*SYSTEM_OF_UNITS::cm - , 100*SYSTEM_OF_UNITS::cm - , 100*SYSTEM_OF_UNITS::cm); -const GeoLogVol* worldLog = new GeoLogVol("WorldLog" - , worldBox - , worldMaterial); -GeoPhysVol* worldPhys = new GeoPhysVol(worldLog); +GeoIntrusivePtr<const GeoBox> worldBox{new GeoBox(100*SYSTEM_OF_UNITS::cm + , 100*SYSTEM_OF_UNITS::cm + , 100*SYSTEM_OF_UNITS::cm)}; +GeoIntrusivePtr<const GeoLogVol> worldLog{new GeoLogVol("WorldLog" + , worldBox + , worldMaterial)}; +GeoIntrusivePtr<GeoPhysVol> worldPhys{new GeoPhysVol(worldLog)}; ``` Each of the three objects (`worldBox`, `worldLog`, and `worldPhys`) are created with a reference count. `worldBox`’s is initially zero, at the time it is created. `worldLog`’s is also zero when it is created. However, when `worldLog` is created, the reference count of `worldBox` increases to one, since now it is referenced somewhere — namely by the logcal volume `worldLog`. Now, when the physical volume `worldPhys` is created, the reference count of the logical volume will increase to one — since it is used once by a single physical volume. @@ -225,22 +220,6 @@ Each time a physical volume is positioned within another physical volume, its re When the very last node referencing the physical volume is destroyed, this means that the physical volume itself has outlived its usefulness and *should disappear*. And that is what happens. The destruction of objects is carried out automatically when the reference count falls to zero. And in fact, the only way to delete an object is to arrange for all of its references to disappear. This is because the destructor of all reference counted objects is private. -This scheme applies to elements, materials, shapes, logical volumes, physical volumes, full physical volumes, and instances of all other classes which also inherit from the `RCBase` class. - -So far, we have described what happens to an object when it is no longer used by any other node in the tree. However, what about the top of the tree, which has no nodes that refer to it? Since the destructors of our physical volumes are private, how do you arrange to get it to go away? - -Reference counts can also be manipulated manually, by using the methods `ref()` and `unref()`. The physical volume at the head of the tree, often known as the “world†physical volume, can be referenced manually using this call: - -```cpp -worldPhys->ref(); // increments reference count by one -``` - -Later, you can destroy the world volume and trigger a global collection of garbage by using this call: - -```cpp -worldPhys->unref() // decrements reference count by one -``` - -When the reference count becomes 0, the world physical volume deletes itself, decreasing the reference counts of its logical volume and any children. These will then begin dereferencing and possibly deleting their own children, until all the memory has been freed. +This scheme applies to elements, materials, shapes, logical volumes, physical volumes, full physical volumes, and instances of all other classes which also inherit from the `RCBase` class. The reference counting machanism described above is implemented automatically by the smart pointer class `GeoIntrusivePtr` (which works similarly to [Boost intrusive_ptr](https://www.boost.org/doc/libs/1_86_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr)). While in theory it is possible to operate GeoModel objects by using bare pointers and manual handling of reference counting (by calling `ref()` and `unref()` methods of the `RCBase` base class), it is *not recommended* to do that as this approach is error-prone, and it can easily lead to memory leaks and other memory access problems. -Suppose now that you want to arrange for a node to not be deleted automatically in this fashion — even when nobody references it any more. In order to do this, simply call the `ref()` method on this object. That way, the reference counts starts at 1 and will not fall to zero until you call `unref()`, manually. +So far, we have described what happens to an object when it is no longer used by any other node in the tree. However, what about the top of the tree, which has no nodes that refer to it? How do you arrange to get it to go away? Well, the answer on this question is pretty simple: it is enough for all corresponding instances of the `GeoIntrusivePtr` to go out of scope. This will bring the embedded reference count of the tree top object to 0 and the object will delete itself, decreasing the reference counts of its logical volume and any children. These will then begin dereferencing and possibly deleting their own children, until all the memory has been freed. diff --git a/documentation/docs/components/kernel/overview/Overview.md b/documentation/docs/components/kernel/overview/Overview.md index 446fd4014a1c468f08853cbb3416c5241775e9ac..a7d22a471ad0d48c91c02402c02a54e5b5b32b6a 100644 --- a/documentation/docs/components/kernel/overview/Overview.md +++ b/documentation/docs/components/kernel/overview/Overview.md @@ -1,7 +1,7 @@ ## GeoModel Kernel Overview -In this section we give a short overview of all of the pieces of the GeoModel Kernel. These pieces are described in detail in the kernel [Class Reference](/components/kernel/reference). In this section our goal is to describe the “big pictureâ€. A subset of the GeoModel kernel class tree is shown on the diagram below. +In this section we give a short overview of all of the pieces of the GeoModel Kernel. These pieces are described in detail in the kernel [Class Reference](../reference). In this section our goal is to describe the “big pictureâ€. A subset of the GeoModel kernel class tree is shown on the diagram below. ```mermaid classDiagram diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Annulus.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Annulus.png new file mode 100644 index 0000000000000000000000000000000000000000..d21fbb3db11f1afc5ff4518480f23d79dcd52931 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Annulus.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo.png new file mode 100644 index 0000000000000000000000000000000000000000..9a9826b16a555bb28c6d1383df83cd87604759e6 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo2.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo2.png new file mode 100644 index 0000000000000000000000000000000000000000..e26e38f03c1546a914f4244162b2aa2c161ec278 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/AnnulusDemo2.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Diamond.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Diamond.png new file mode 100644 index 0000000000000000000000000000000000000000..348e347132f0a3a2cf5952adb087a77ddc5c68fc Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Diamond.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/DiamondDemo.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/DiamondDemo.png new file mode 100644 index 0000000000000000000000000000000000000000..9736ca97c6e52551ab135fd35c5a912867bca645 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/DiamondDemo.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoAnnulusSurface.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoAnnulusSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..d27674bea68ec8522656c08e6324d9114e6309b6 --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoAnnulusSurface.md @@ -0,0 +1,33 @@ +### GeoAnnulusSurface + + +```cpp +// === GeoAnnulusSurface === + + // Constructor: + // The default position of the cylinder center is at (0,0,0) + // Ox, Oy: the deviation of the focusing point from the default position + // radius_in: the inner radius of the annulus + // radius_out: the outer radius of the annulus + // phi: the span angle of the deviated circular sector, when phi = 2*PI, it is an annulus + GeoAnnulusSurface(double Ox, double Oy, double radius_in, double radius_out, double phi); + + + // Public Methods: + double getOx() const; + double getOy() const; + double getRadiusIn() const; + double getRadiusOut() const; + double getPhi() const; + void exec (GeoShapeAction *action) const override final; + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; +``` + +A `GeoAnnulusSurface` represents an annulus (or circular sector) virtual surface initialized at XOY plane. It is specified by *Ox (X-position of deviated center)*, *Oy (Y-position of deviated center)*, *Inner Radius*, *Outer Radius*, and *Span Angle $\Phi$*, all input parameters of the constructor. The methods `getOx()`, `getOy()`, `getRadiusIn()`, `getRadiusOut()`, and `getPhi()` return the shape boundaries of the surface. When $\phi = 2\pi$, the circular section returns to an annulus. + + +{{ imgutils_image_caption('RCBase/GeoVSurfaceShape/Annulus.png', + alt='The GeoAnnulusSurface shape', + cap='Figure: Shape boundaries of annulus surface.', + urlFix=False) +}} diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoDiamondSurface.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoDiamondSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..7cdcc792b33673f470833d5ce7deec534bc27d8e --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoDiamondSurface.md @@ -0,0 +1,31 @@ +### GeoDiamondSurface + + +```cpp +// === GeoDiamondSurface === + + // Constructor: + GeoDiamondSurface (double X_bottom_half, double X_mid_half, double X_top_half, double Y_bottom_half, double Y_top_half); + + + // Public Methods: + double area() const; + + double getXbottomHalf () const; + double getXmidHalf () const; + double getXtopHalf () const; + double getYbottomHalf () const; + double getYtopHalf () const; + void exec (GeoShapeAction *action) const override final; + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; +``` + +A `GeoDiamondSurface` represents a diamond virtual surface initialized at XOY plane. It is specified by *X half-length bottom*, *X half-length middle*, *X half-length top* in X-direction and *Y half-length bottom*, *Y half-length top* in Y-direction, which are input parameters of the constructor. The public methods `exec` and `isOnSurface` inherits methods from `GeoVSurfaceShape`, methods `getXbottomHalf()`, `getXmidHalf()`, `getXtopHalf()`, `getYbottomHalf()`, and `getYtopHalf()` return the shape boundaries of the surface. `area()` returns the area of the diamond. + + +{{ imgutils_image_caption('RCBase/GeoVSurfaceShape/Diamond.png', + alt='The GeoDiamondSurface shape', + cap='Figure: Shape boundaries of diamond surface.', + urlFix=False) +}} + diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoRectSurface.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoRectSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..c225fd08347c7ca0ae02182dc45ac429ea081629 --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoRectSurface.md @@ -0,0 +1,27 @@ +### GeoRectSurface + + +```cpp +// === GeoRectSurface === + + // Constructor: + GeoRectSurface (double XHalfLength, double YHalfLength); + + + // Public Methods: + double area() const; + double getXHalfLength () const; + double getYHalfLength () const; + void exec (GeoShapeAction *action) const override final; + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; +``` + +A `GeoRectSurface` represents a rectangle virtual surface initialized at the XOY plane. It is specified by a *half-length* in X-direction and a *half-length* in Y-direction, which are input parameters of the constructor. Methods `getXHalfLength()`, `getYHalfLength()` return the shape boundaries of the surface. `area()` returns the area. + + +{{ imgutils_image_caption('RCBase/GeoVSurfaceShape/Rect.png', + alt='The GeoRectSurface shape', + cap='Figure: Shape boundaries of rectangle surface.', + urlFix=False) +}} + diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoTrapezoidSurface.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoTrapezoidSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..0f8793bd50fb3247bc98278530976b732e2dad7b --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoTrapezoidSurface.md @@ -0,0 +1,27 @@ +### GeoTrapezoidSurface + + +```cpp +// === GeoTrapezoidSurface === + + // Constructor: + GeoTrapezoidSurface (double XHalfLengthMin, double XHalfLengthMax, double YHalfLength); + + + // Public Methods: + double area() const; + double getXHalfLengthMin () const; + double getXHalfLengthMax () const; + double getYHalfLength () const; + void exec (GeoShapeAction *action) const override final; + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const override final; +``` + +A `GeoTrapezoidSurface` represents a trapezoid virtual surface initialized at XOY plane. It is specified by *X half-length minimum* (or bottom half-length) and *X half-length maximum* (or top half-length) in X-direction and *Y half-length* in Y-direction, which are input parameters of the constructor. The methods `getXHalfLengthMin()`, `getXHalfLengthMax`, and `getYHalfLength()` return the shape boundaries of the surface. `area()` returns the area of the trapezoid. + + +{{ imgutils_image_caption('RCBase/GeoVSurfaceShape/Trapezoid.png', + alt='The GeoTrapezoidSurface shape', + cap='Figure: Shape boundaries of trapezoid surface.', + urlFix=False) +}} diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurface.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..fc766ba8e2bae75b5783b08af9ccfe4e4338db84 --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurface.md @@ -0,0 +1,23 @@ +### GeoVSurface + + +The class GeoVSurface takes [Virtual Surface Shape](#geovsurfaceshape) as input to the constructor, and is used to embed the shape within the geometry tree. It provides access to the SurfaceShape and can determine whether a triplet of coordinates lies on and within the surface. + + +```cpp +// === GeoVSurface === + + //Constructor: + GeoVSurface(const GeoVSurfaceShape *SurfShape); + + //Public Methods: + const GeoVSurfaceShape* getShape () const + virtual void exec(GeoNodeAction *action) const; + bool isOnSurface(const double Px, const double Py, const double Pz) const; +``` +For example, if we want to construct a rectangle virtual surface node, we just need to first construct the surface shape and then construct the virtual surface node: + +```cpp + GeoRectSurface* rectangle = new GeoRectSurface(5, 9); // 5 is X half length and 9 is Y half length + GeoVSurface* surface = new GeoVSurface(rectangle); // construct a virtual surface node in rectangle shape +``` \ No newline at end of file diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurfaceShape.md b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurfaceShape.md new file mode 100644 index 0000000000000000000000000000000000000000..46ed45d46d2574464124522c2ed690b42d27b151 --- /dev/null +++ b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurfaceShape.md @@ -0,0 +1,19 @@ +### GeoVSurfaceShape + + +The abstract class GeoVSurfaceShape defines the interface for subclasses, specifically the `isOnSurface` method. + +```cpp +// === GeoVSurfaceShape === + + //Constructor: + GeoVSurfaceShape () = default; + + //Public Methods: + //Executes a GeoShapeAction on the surface shape + virtual void exec (GeoShapeAction *action) const = 0; + //Determines whether the point(Px,Py,Pz) is on the surface, can be overriden by child methods + virtual bool isOnSurface (const double Px, const double Py, const double Pz, const GeoTrf::Transform3D & trans) const = 0; +``` + +All surface shapes are initialized at X-O-Y plane. In *gmex* when visualized, the side initially facing at +Z direction is in red color, while the side initially facing at -Z direction is in green color. The following subsections show specific examples of virtual surface shapes. \ No newline at end of file diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Rect.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Rect.png new file mode 100644 index 0000000000000000000000000000000000000000..21ae1c57a0d18f6df62f9ba97ab1da915052c3c6 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Rect.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/RectDemo.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/RectDemo.png new file mode 100644 index 0000000000000000000000000000000000000000..82796f1e0c82c7bfe8887df86da60fbf08892139 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/RectDemo.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/SurfaceClassRef.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/SurfaceClassRef.png new file mode 100644 index 0000000000000000000000000000000000000000..9d42ba7aa6a92752c85ca076975e0904e2548175 Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/SurfaceClassRef.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Trapezoid.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Trapezoid.png new file mode 100644 index 0000000000000000000000000000000000000000..deb177c9ecf1fc22e06efa7fe06f338ac7b0d25b Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/Trapezoid.png differ diff --git a/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/TrapezoidDemo.png b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/TrapezoidDemo.png new file mode 100644 index 0000000000000000000000000000000000000000..da24d089cece86b0b68ddb735bbea22238fddd7c Binary files /dev/null and b/documentation/docs/components/kernel/reference/RCBase/GeoVSurfaceShape/TrapezoidDemo.png differ diff --git a/documentation/docs/components/kernel/reference/ReferenceCounting.md b/documentation/docs/components/kernel/reference/ReferenceCounting.md index 2d8ee898a090e9a66efdd22fc00473b788b7b6bd..f9259e1b8256c9bfa7807a97316aa8b04de70f86 100644 --- a/documentation/docs/components/kernel/reference/ReferenceCounting.md +++ b/documentation/docs/components/kernel/reference/ReferenceCounting.md @@ -1,14 +1,8 @@ - - - ## Reference counting +Many objects need to be allocated in the description of a complicated geometry. For efficient use of memory, these should be shared as often as possible. The extensive sharing of objects in a geometry system calls for a way of destroying the objects as soon as they are not used by any other object that references them. The scheme for doing this is called reference counting. In the GeoModelKernel classes, it is achieved by mixing in a abstract base class, `RCBase`. -!!! warning - The custom reference counting used in GeoModel was developed when no smart pointers were available for C++. That part will be the object of a major refactoring in the near future. - - -Many objects need to be allocated in the description of a complicated geometry. For efficient use of memory, these should be shared as often as possible. The extensive sharing of objects in a geometry system calls for a way of destroying the objects as soon as they are not used—by any other object that references them. The scheme for doing this is called reference counting. In the GeoModelKernel classes, it is achieved by mixing in a abstract base class, RCBase: +### RCBase ```cpp //RCBase @@ -20,7 +14,52 @@ Many objects need to be allocated in the description of a complicated geometry. unsigned int refCount () ``` -`RCBase` is inherited by many of the classes in the geometry system. Reference-counted objects can only be created using operator new, and cannot be created on the stack. The methods `ref()` and `unref()` can be called to increase or decrease the reference count of an object. When the reference count decreases to zero, the object deletes itself. The accessor `refCount()` returns the current reference count. +`RCBase` is inherited by many of the classes in the geometry system. Reference-counted objects can only be created using operator `new` (i.e. they cannot be created on stack). The methods `ref()` and `unref()` can be called to increase or decrease the reference count of an object. When the reference count decreases to zero, the object deletes itself. The accessor `refCount()` returns the current reference count. +While it is possible for the client code to operate with `RCBase` API directly, doing so is **not recommended**. Instead it is advisable to wrap the pointers to reference-counted objects into special smart pointers: `GeoIntrusivePtr`. +### GeoIntrusivePtr + +`GeoIntrusivePtr` implements smart pointer semantics for objects with embedded reference counts similarly to how it is implemented by Boost [`intrusive_ptr`](https://www.boost.org/doc/libs/1_86_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr). + +```cpp +template<typename GeoType> class GeoIntrusivePtr{ + public: + // Standard constructor taking a bare pointer + GeoIntrusivePtr(GeoType* obj) noexcept; + // Copy constructor + GeoIntrusivePtr(const GeoIntrusivePtr& other) noexcept; + // Move constructor + GeoIntrusivePtr(GeoIntrusivePtr&& other) noexcept; + // Assignment operator + GeoIntrusivePtr& operator=(const GeoIntrusivePtr& other) noexcept; + GeoIntrusivePtr& operator=(GeoType* other) noexcept; + // Move assignment operator + GeoIntrusivePtr& operator=(GeoIntrusivePtr&& other) noexcept; + // Reset the pointer + void reset(GeoType* ptr = nullptr); + // Destructor + ~GeoIntrusivePtr(); + // Implicit conversion + operator GeoType*() const; + operator GeoType* const*() const; + // Pointer access + GeoType* operator->() const; + // Dereference the pointer + GeoType& operator*() const; + // Getter methods + GeoType* get() const; + // Validity operator + operator bool() const; + // Comparison operator + template <class GeoTypeGrp> + bool operator==(const GeoIntrusivePtr<GeoTypeGrp>& other) const; + bool operator==(GeoType* other) const; + // Odering operator + bool operator<(const GeoIntrusivePtr& other) const; + +... +}; +``` +The objects of the class `GeoIntrusivePtr` increase the reference count of the managed `RCBase` object at the construction and decrease it at the destruction. Hence, intrusive pointers provide a mechanism for automatic memory management for reference-counted GeoModel objects, and eliminate the need for the client code to call the `ref()` and `unref()` methods explicitly. \ No newline at end of file diff --git a/documentation/docs/components/kernel/reference/VirtualSurface.md b/documentation/docs/components/kernel/reference/VirtualSurface.md new file mode 100644 index 0000000000000000000000000000000000000000..d2c2b184e7cd52616973aa1ea7e8ad19a9ab753e --- /dev/null +++ b/documentation/docs/components/kernel/reference/VirtualSurface.md @@ -0,0 +1,14 @@ + +## Virtual Surfaces + +### Introduction + +Virtual surface classes are light weight classes describing geometrical objects devoid of any material properties. They are introduced for particle tracking and fast simulation purposes. Like `GeoVFullPhysVol`, the `GeoVSurface` class caches its absolute position locally and responds to alignment updates further up the tree. Virtual surface nodes may be parented within *physical volumes*, but they do not have any child nodes of any kind. The node actions are adapted to work with surface classes as well. + +{{ imgutils_image_caption('RCBase/GeoVSurfaceShape/SurfaceClassRef.png', + alt='The GeoVSurface inheritance', + cap='Figure: GeoVSurface inheritance relations.', + urlFix=False) +}} + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurface.md' %} \ No newline at end of file diff --git a/documentation/docs/components/kernel/reference/VirtualSurfaceShape.md b/documentation/docs/components/kernel/reference/VirtualSurfaceShape.md new file mode 100644 index 0000000000000000000000000000000000000000..3eca9cdd3192f1a9bc162a2025241612e10f86dd --- /dev/null +++ b/documentation/docs/components/kernel/reference/VirtualSurfaceShape.md @@ -0,0 +1,35 @@ + + +## Virtual Surface Shape + + +### Introduction + +The virtual surface shape classes are designed to describe the geometry of two dimensional virtual surfaces. The specific surface shape classes are used as input variables of `GeoVSurface`, as described in section [GeoVSurface](#geovsurface). The set of surfaces is extensible. + + + +In the table here below, a list of the existing virtual surface shapes in the GeoModelKernel package is given: + + +| Class | Virtual Surface Shape | +| ------- | ----- | +| [GeoRectSurface](#georectsurface) | Rectangle | +| [GeoTrapezoidSurface](#geotrapezoidsurface) | Trapezoid | +| [GeoDiamondSurface](#geodiamondsurface) | Diamond | +| [GeoAnnulusSurface](#geoannulussurface) | Annulus / Circular Sector | + +The surface shapes can be visualized by *gmex*, and some screenshots appear in the following documentation. + + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoVSurfaceShape.md' %} + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoRectSurface.md' %} + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoTrapezoidSurface.md' %} + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoDiamondSurface.md' %} + +{% include 'components/kernel/reference/RCBase/GeoVSurfaceShape/GeoAnnulusSurface.md' %} + + diff --git a/documentation/docs/components/kernel/reference/index.md b/documentation/docs/components/kernel/reference/index.md index 3914f0ebd38ec659685ce16fce1d9b856323b4c1..87594f4a02bcfd700abd486c8771edf4b5ff4101 100644 --- a/documentation/docs/components/kernel/reference/index.md +++ b/documentation/docs/components/kernel/reference/index.md @@ -1,12 +1,10 @@ # GeoModel Kernel Class Reference -This section describes in more detail the classes in the geometry kernel. In most cases we provide the class interface. In cases where part of the interface is used only internally by the geometry kernel itself and not by other users. In such cases we present a simplified picture of the interfaces. +This section describes in more detail the classes in the geometry kernel. In most cases we provide the class interface. In cases where part of the interface is used only internally by the geometry kernel itself and not by other users we present a simplified picture of the interfaces. Detailed descriptions of the geometry kernel classes follow. - - {% include 'components/kernel/reference/ReferenceCounting.md' %} {% include 'components/kernel/reference/Materials_Elements.md' %} @@ -15,6 +13,10 @@ Detailed descriptions of the geometry kernel classes follow. {% include 'components/kernel/reference/LogicalVolumes.md' %} +{% include 'components/kernel/reference/VirtualSurfaceShape.md' %} + +{% include 'components/kernel/reference/VirtualSurface.md' %} + {% include 'components/kernel/reference/PhysicalVolumes.md' %} {% include 'components/kernel/reference/Transformations.md' %} diff --git a/documentation/docs/dev/build_fullsimlight.md b/documentation/docs/dev/build_fullsimlight.md index 7d64c71599abc2887ba18e05d2ec78e80f579733..c71ee1fc19b982ad7fa9f2821db48d1791c5b095 100644 --- a/documentation/docs/dev/build_fullsimlight.md +++ b/documentation/docs/dev/build_fullsimlight.md @@ -1,24 +1,24 @@ -# FullSimLight and FSL installation from source +# FullSimLight and fsl installation from source -FullSimLight and its graphical user interface FSL, are experiment agnostic detector simulation tools that have been implemented and are mantained by the [ATLAS](https://atlas.cern) collaboration. In what follows you will find instructions on how to build and install FullSimLight and FSL from the source code. If you are interested in testing FullSimLight and FSL with the ATLAS experiment configuration please refer to the ATLAS Extensions section below. +`fullSimLight` and its graphical user interface `fsl`, are experiment agnostic detector simulation tools that have been implemented and are mantained by the [ATLAS](https://atlas.cern) collaboration. In what follows you will find instructions on how to build and install `fullSimLight` and `fsl` from the source code. If you are interested in testing `fullSimLight` and `fsl` with the ATLAS experiment configuration please refer to the [ATLAS Extensions](#how-to-build-the-atlas-extensions-submodule) section below. # Prerequisites -Before proceeding with this section please make sure that you visited the GeoModel installation instructions page to check the prerequisites list and install all the dependencies of GeoModel. +Before proceeding with this section please make sure that you visited the `GeoModel` installation instructions [page]{https://geomodel.web.cern.ch/home/dev/#system-dependencies} to check the prerequisites list and install all the dependencies of `GeoModel`. -FullSimLight and its tools depend on Geant4, Xerces-C and HDF5. Additionally, the user might want to install [Pythia8](http://home.thep.lu.se/Pythia/) and [HepMC3](https://gitlab.cern.ch/hepmc/HepMC3) as optional dependencies. +`fullSimLight` and its tools depend on `Geant4`, `Xerces-C` and `HDF5`. Additionally, the user might want to install [Pythia8](http://home.thep.lu.se/Pythia/) and [HepMC3](https://gitlab.cern.ch/hepmc/HepMC3) as optional dependencies. ## Geant4 installation -There is no specific requirement for the version of Geant4 to use with FullSimLight. Our team tries to keep FullSimLight compatible with the most recent Geant4 versions. If you have any issues with a specific Geant4 version please open a ticket at the following [link](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/issues). +There is no specific requirement for the version of `Geant4` to use with `fullSimLight`. Our team tries to keep `fullSimLight` compatible with the most recent `Geant4` versions. If you have any issues with a specific `Geant4` version please open a ticket at the following [link](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/issues). -Before installing Geant4, check at the [Geant4 website](http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/gettingstarted.html) the pre-requisites needed and install them. +Before installing `Geant4`, check at the [Geant4 website](http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/InstallationGuide/html/gettingstarted.html) the pre-requisites needed and install them. !!! note - Please note that an installation of Geant4 including the GDML extension (which requires the XercesC version >=3 package installed in the system) is required, i.e. the Geant4 toolkit must be built with the `-DGEANT4_USE_GDML=ON` CMake option. + Please note that an installation of `Geant4` including the `GDML` extension (which requires the Xerces-C version >=3 package installed in the system) is required, i.e. the `Geant4` toolkit must be built with the `-DGEANT4_USE_GDML=ON` CMake option. ###Xerces-C installation -Please choose the Xerces-C installation that is required by the Geant4 version that you are installing. As an example here we show how to install xerces-c 3.2.2. +Please choose the `Xerces-C` installation that is required by the `Geant4` version that you are installing. As an example here we show how to install `xerces-c 3.2.2`. ```bash wget https://archive.apache.org/dist/xerces/c/3/sources/xerces-c-3.2.2.tar.gz @@ -28,7 +28,7 @@ cmake -DCMAKE_INSTALL_PREFIX=../../install ../ make -j8 ; make install ``` -Now that you have installed xerces-c, you are ready to install Geant4. Clone the [Geant4 repository](https://gitlab.cern.ch/geant4/geant4.git), then: +Now that you have installed `Xerces-C`, you are ready to install `Geant4`. Clone the [Geant4 repository](https://gitlab.cern.ch/geant4/geant4.git), then: ```bash git clone https://gitlab.cern.ch/geant4/geant4.git @@ -36,12 +36,12 @@ cd geant4 git tag ``` -Choose the release you want to use amongst the listed ones (i.e. Geant4-11.2.1), and checkout the corresponding tag: +Choose the release you want to use amongst the listed ones (i.e. `Geant4-11.2.2`), and checkout the corresponding tag: ```bash -git checkout tags/v11.2.1 +git checkout tags/v11.2.2 ``` -We recommend to build Geant4 with the multithreading support on, so that you can take advantage of it and run your simulation in multithreaded mode. +We recommend to build `Geant4` with the multithreading support on, so that you can take advantage of it and run your simulation in multithreaded mode. !!! note @@ -60,28 +60,29 @@ cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Release ../ -DGEA make -j8 ; make install ``` - -Before running FullSimLight and all the tools that depend on Geant4 please make sure to source the geant4.sh file to set correctly all the Geant4 environment variables. +!!! Note + + Before running `fullSimLight` and all the tools that depend on `Geant4` please make sure to source the `geant4.sh` file to set correctly all the `Geant4` environment variables. ##Pythia installation -If you wish to run FullSimLight with Pythia events you will need to install Pythia in your system. Follow the instructions at the [official website](http://home.thep.lu.se/Pythia/) for that. -In order to build FullSimLight and FSL with Pythia you should then use the following flag: `-DGEOMODEL_USE_PYTHIA=ON` (see the following section for more details). +If you wish to run `fullSimLight` with `Pythia` events you will need to install `Pythia` in your system. Follow the instructions at the [official website](http://home.thep.lu.se/Pythia/) for that. +In order to build `fullSimLight` and `fsl` with `Pythia` you should then use the following flag: `-DGEOMODEL_USE_PYTHIA=ON` (see the following section for more details). ##HepMC3 installation -If you wish to run FullSimLight with HepMC3 events you will need to install HepMC3 in your system. Follow the instructions at the [official repository](https://gitlab.cern.ch/hepmc/HepMC3) for that. -In order to build FullSimLight and FSL with HepMC3 you should then use the following flag: `-DGEOMODEL_USE_HEPCM3=ON`(see the following section for more details). +If you wish to run `fullSimLight` with `HepMC3` events you will need to install `HepMC3` in your system. Follow the instructions at the [official repository](https://gitlab.cern.ch/hepmc/HepMC3) for that. +In order to build `fullSimLight` and `fsl` with `HepMC3` you should then use the following flag: `-DGEOMODEL_USE_HEPCM3=ON`(see the following section for more details). -# How to build FullSimLight and FSL +# How to build fullSimLight and fsl -FullSimLight and FSL can be built as part of the GeoModel build, by enabling the related configuration flags `GEOMODEL_BUILD_FULLSIMLIGHT` and `GEOMODEL_BUILD_FSL`. +`fullSimLight` and `fsl` can be built as part of the `GeoModel` build, by enabling the related configuration flags `GEOMODEL_BUILD_FULLSIMLIGHT` and `GEOMODEL_BUILD_FSL`. ## Standard installation -If you want to install FullSimLight in the standard installation path you can follow the instructions below: +If you want to install `fullSimLight` in the standard installation path you can follow the instructions below: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -92,9 +93,9 @@ make -j make install ``` -That will compile the base GeoModel packages (*i.e.*, `GeoModelCore`, `GeoModelIO`, and `GeoModelTools`), the GeoModel<->Geant4 interface package `GeoModelG4`, and the application `FullSimLight`. +That will compile the base `GeoModel` packages (i.e., `GeoModelCore`, `GeoModelIO`, and `GeoModelTools`), the GeoModel<->Geant4 interface package `GeoModelG4`, and the application `fullSimLight`. -This will install all the base libraries and the `fullSimLight` executable in the standard installation path (*e.g.*, `/usr/local` on macOS). If you want to have a local installation, see below. +This will install all the base libraries and the `fullSimLight` executable in the standard installation path (e.g., `/usr/local` on macOS). If you want to have a local installation, see below. !!! note @@ -103,9 +104,9 @@ This will install all the base libraries and the `fullSimLight` executable in th ## Local installation -You can install FullSimLight in a local folder as well. This let you remove everything by simply deleting the local folder, and lets you have multiple versions of the packages installed. +You can install `fullSimLight` in a local folder as well. This let you remove everything by simply deleting the local folder, and lets you have multiple versions of the packages installed. -You can install FullSimLight locally by using the `CMAKE_INSTALL_PREFIX` option. In the example below, we instruct CMake to install everything inside a local folder named `install` besides the `GeoModel` folder: +You can install `fullSimLight` locally by using the `CMAKE_INSTALL_PREFIX` option. In the example below, we instruct CMake to install everything inside a local folder named `install` besides the `GeoModel` folder: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -122,9 +123,9 @@ At the end, you will find all the libraries and executables installed under: ls ../../install ``` -## Build FSL +## Build fsl -FSL is the graphical user interface to FullSimLight. It allows you to configure your simulation and run it by using a json configuration file. Similarly to what said above, if you want to build FSL, you will have to enable the related configuration flag `GEOMODEL_BUILD_FSL`. If you enable the build of FSL automatically also FullSimLight will be built. +`fsl` is the graphical user interface to `fullSimLight`. It allows you to configure your simulation and run it by using a `json` configuration file. Similarly to what said above, if you want to build `fsl`, you will have to enable the related configuration flag `GEOMODEL_BUILD_FSL`. If you enable the build of `fsl` automatically also `fullSimLight` will be built. ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -135,9 +136,9 @@ make -j make install ``` -## How to build FullSimLight and FSL with Pythia +## How to build fullSimLight and fsl with Pythia -In order to build FullSimLight and FSL with Pythia you will need to activate the appropriate flag `GEOMODEL_USE_PYTHIA`: +In order to build `fullSimLight` and `fsl` with `Pythia` you will need to activate the appropriate flag `GEOMODEL_USE_PYTHIA`: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -148,7 +149,7 @@ make -j make install ``` -If you installed Pythia in a local folder, CMake might not be able to find it. In this case you should specify manually the path to the include directory and to the library. +If you installed `Pythia` in a local folder, `CMake` might not be able to find it. In this case you should specify manually the path to the include directory and to the library. ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -159,9 +160,9 @@ make -j make install ``` -## How to build FullSimLight and FSL with HepMC3 +## How to build fullSimLight and fsl with HepMC3 -In order to build FullSimLight and FSL with HepMC3 you will need to activate the appropriate flag: +In order to build `fullSimLight` and `fsl` with `HepMC3` you will need to activate the appropriate flag: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git cd GeoModel @@ -171,7 +172,7 @@ make -j make install ``` -If you installed HepMC3 in a local folder, CMake might not be able to find it. In this case you should specify manually the path to the include directory and to the library. +If you installed `HepMC3` in a local folder, `CMake` might not be able to find it. In this case you should specify manually the path to the include directory and to the library. ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -184,9 +185,9 @@ make install ## How to use a custom version of Xerces-C -The Geant4 GDML format depends on the Xerces-C library. Therefore, different Geant4 releases can use different versions of the Xerces-C library. +The `Geant4 GDML` format depends on the `Xerces-C` library. Therefore, different `Geant4` releases can use different versions of the `Xerces-C` library. -If you want to build FullSimLight with a custom, locally installed Xerces-C library, you can pass the `XercesC_INCLUDE_DIR` and `XercesC_LIBRARY` variable to CMake while configuring the build of FullSimLight: +If you want to build `fullSimLight` with a custom, locally installed `Xerces-C` library, you can pass the `XercesC_INCLUDE_DIR` and `XercesC_LIBRARY` variable to `CMake` while configuring the build of `fullSimLight`: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -197,7 +198,7 @@ cmake -DGEOMODEL_BUILD_FULLSIMLIGHT=1 -DXercesC_INCLUDE_DIR=<path-to-local-Xerc !!! note - When setting the path of the local installation of Xerces-C, please be sure to use a full path or a local path related to the `$PWD` environment variable For example, those are valid examples: + When setting the path of the local installation of `Xerces-C`, please be sure to use a full path or a local path related to the `$PWD` environment variable For example, those are valid examples: ```bash -DXercesC_INCLUDE_DIR=/opt/myXercesC/include # using a full 'full path' @@ -206,17 +207,17 @@ cmake -DGEOMODEL_BUILD_FULLSIMLIGHT=1 -DXercesC_INCLUDE_DIR=<path-to-local-Xerc !!! note - If you installed Geant4 on myour machine with a package manager (*e.g.*, Homebrew on macOS) the version used by the Geant4 package built by the package manager could be hardcoded in the package configuration itself. That could cause the output of warning messages by CMake, of which thev one below is an example: + If you installed `Geant4` on myour machine with a package manager (*e.g.*, Homebrew on macOS) the version used by the `Geant4` package built by the package manager could be hardcoded in the package configuration itself. That could cause the output of warning messages by `CMake`, of which thev one below is an example: ```bash Value of 'XercesC_INCLUDE_DIR' is already set and does not match value set at Geant4 build-time ``` - Normally, those warnings do not harm the build. But please judge by yourself if the difference isn the Xerces-C library can affect the project you are working on. + Normally, those warnings do not harm the build. But please judge by yourself if the difference in the `Xerces-C` library can affect the project you are working on. ## Combining different configuration/build options -You can also combine different configuration options. For example, here below we build FullsimLight by using the built-in `nlohmann-json` library together with the custom Xerces-C library, and we install the outcome in a local `../install` folder: +You can also combine different configuration options. For example, here below we build `fullsimLight` by using the built-in `nlohmann-json` library together with the custom `Xerces-C `library, and we install the outcome in a local `../install` folder: ```bash git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git @@ -228,7 +229,7 @@ cmake -DCMAKE_INSTALL_PREFIX=../install -DGEOMODEL_USE_BUILTIN_JSON=1 -DGEOMODE # How to build the ATLAS Extensions submodule -FullSimLight is an experiment agnostic detector simulation tool that has been implemented and is mantained by the [ATLAS](https://atlas.cern) collaboration. Its initial goal was to make it possible to simulate the full ATLAS detector with the real magnetic field map in full standalone mode. All the ATLAS specific customizations are available at the [ATLAS Extensions](https://gitlab.cern.ch/atlas/geomodelatlas/ATLASExtensions) repository that is linked to the GeoModel repository as a git submodule. In order to have the corresponding code cloned inside the GeoModel repository the user would need to clone recursively the main repository. +`fullSimLight` initial goal was to make it possible to simulate the full [ATLAS](https://atlas.cern) detector with the real magnetic field map in full standalone mode. All the ATLAS specific customizations are now available at the [ATLAS Extensions](https://gitlab.cern.ch/atlas/geomodelatlas/ATLASExtensions) repository that is linked to the `GeoModel` repository as a git submodule. In order to have the corresponding code cloned inside the `GeoModel` repository the user would need to clone recursively the main repository. If you didn't clone the GeoModel repository, you can clone it recursively: @@ -236,7 +237,7 @@ If you didn't clone the GeoModel repository, you can clone it recursively: git clone --recursive https://gitlab.cern.ch/GeoModelDev/GeoModel.git ``` -Alternatively, if you already cloned the GeoModel repository, it will be sufficient to type the following commands from the main `GeoModel` repository folder: +Alternatively, if you already cloned the `GeoModel` repository, it will be sufficient to type the following commands from the main `GeoModel` repository folder: ```c++ cd GeoModel @@ -244,7 +245,7 @@ git submodule init git submodule update ``` -A flag **GEOMODEL_BUILD_ATLASEXTENSIONS** is available to build the ATLAS extentions (by default OFF) and it should be turned ON in order to build all the extensions. If you want to build the ATLAS Extensions and FullSimLight you should then: +A flag `GEOMODEL_BUILD_ATLASEXTENSIONS` is available to build the ATLAS extentions (by default `OFF`) and it should be turned `ON` in order to build all the extensions. If you want to build the ATLAS Extensions and `fullSimLight` you should then: ```c++ cd GeoModel @@ -254,7 +255,7 @@ make -j make install ``` -A configuration file **atlas-conf.json** with all the ATLAS specific customizations is provided with the ATLASExtensions and will be installed under **<install>/share/FullSimLight/ATLAS**. In order to run a Geant4 simulation with the ATLAS configuration please visit the [ATLAS Extensions page](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/). +A configuration file `atlas-conf.json` with all the ATLAS specific customizations is provided with the `ATLASExtensions` and will be installed under `<install>/share/FullSimLight/ATLAS`. In order to run a `Geant4` simulation with the ATLAS configuration please visit the [ATLAS Extensions page](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/). diff --git a/documentation/docs/fullsimlight/atlas-extensions/index.md b/documentation/docs/fullsimlight/atlas-extensions/index.md index 5beb7f8c1b6736344ba859789d612e8fd9e4f56a..c568ba7bdd9597dcde043f750d5a07c06fabad44 100644 --- a/documentation/docs/fullsimlight/atlas-extensions/index.md +++ b/documentation/docs/fullsimlight/atlas-extensions/index.md @@ -1,55 +1,67 @@ # ATLAS Extensions -FullSimLight is an experiment agnostic detector simulation tool that has been implemented and is mantained by the [ATLAS](https://atlas.cern) collaboration. All the ATLAS specific customizations are available at the [ATLAS Extensions](https://gitlab.cern.ch/atlas/geomodelatlas/ATLASExtensions) repository that is linked to the GeoModel repository as a git submodule. In order to have the corresponding code cloned inside the GeoModel repository the user would need to clone recursively the main repository. +`fullSimLight` is an experiment agnostic detector simulation tool that has been implemented and is mantained by the [ATLAS](https://atlas.cern) collaboration. All the ATLAS specific customizations are available at the [ATLAS Extensions](https://gitlab.cern.ch/atlas/geomodelatlas/ATLASExtensions) repository that is linked to the `GeoModel` repository as a git submodule. -If you still didn't clone the repository you can clone it recursively: -```c++ -git clone --recursive https://gitlab.cern.ch/GeoModelDev/GeoModel.git -``` +!!! Note -Alternatively, if you already cloned the GeoModel repository, it will be sufficient to type the following commands from the main repository folder: + In order to have the corresponding code cloned inside the `GeoModel` repository, you would need to clone recursively the main repository. -```c++ -git submodule init -git submodule update -``` + If you didn't clone the repository yet you can clone it recursively with: + + ```bash + git clone --recursive https://gitlab.cern.ch/GeoModelDev/GeoModel.git + ``` -A flag is available to build the ATLAS extentions (by default OFF) and it should be turned ON in order to build all the extensions: + Alternatively, if you already cloned the `GeoModel` repository, it will be sufficient to type the following commands from the main repository folder: -```c++ + ```bash + git submodule init + git submodule update + ``` + +A flag is available to build the `ATLAS extensions` (by default `OFF`) and it should be turned `ON` in order to build all the extensions: + +```bash cmake ../ -DGEOMODEL_BUILD_ATLASEXTENSIONS=ON -DGEOMODEL_BUILD_FULLSIMLIGHT=ON ``` -A configuration file **atlas-conf.json** with all the ATLAS specific customizations is provided with the ATLASExtensions and will be installed under **<install>/share/FullSimLight/ATLAS**. +A configuration file `atlas-conf.json` with all the ATLAS specific customizations is provided with the `ATLASExtensions` and will be installed under `<install>/share/FullSimLight/ATLAS`. -To run FullSimLight with the ATLAS experiment settings you need a geometry file describing the full ATLAS detector and the ATLAS magnetic field map. These files can be downloaded as explained in the following sections. However please note that they are available only under CERN SSO. If you experience problems with downloading those files please contact the [geomodel-core-team](mailto:geomodel-core-team@cern.ch) +To run `fullSimLight` with the ATLAS experiment settings you need a geometry file describing the full ATLAS detector and the ATLAS magnetic field map. These files can be downloaded as explained in the following sections. However please note that they are available only under CERN SSO. If you experience problems with downloading those files please contact the [geomodel-core-team](mailto:geomodel-core-team@cern.ch) ## ATLAS Geometry File <!----> Some ATLAS geometry SQLite and .gdml files are available at the following [link](https://geomodel.web.cern.ch/atlas-geometry-data/), only working under CERN SSO. -They describe the whole geometry tree of different tags used during the different LHC runs. You can select your favourite one and use it with fullSimLight! For example: +They describe the whole geometry tree of different tags used during the different LHC runs. You can select your favourite one and use it with `fullSimLight`! For example: -```c++ -wget https://geomodel.web.cern.ch/atlas-geometry-data/geometry-ATLAS-R3S-2021-03-02-00.db +```bash +wget https://geomodel.web.cern.ch/atlas-geometry-data/geometry_atlas.db +./fullSimLigth -g geometry_atlas.db ``` ## ATLAS Magnetic Field Map and plugin <!----> -This folder contains the ATLAS magnetic field map implementation. It uses a magnetic field map data file that is available at the following [link](https://geomodel.web.cern.ch/atlas-magnetic-field/) and can be downloaded with wget: -```c++ +This folder contains the ATLAS magnetic field map implementation. It uses a magnetic field map data file that can be downloaded with: + +```bash + wget https://geomodel.web.cern.ch/atlas-magnetic-field/bmagatlas_09_fullAsym20400.data + ``` + ## LAr Custom Solid Extension <!----> -This folder contains the LArCustomSolid Extension that describes the ATLAS LAr EMEC custom shape. The LAr EMEC custom shape extension is build starting from a copy of the corresponding code in the Athena repository. -To keep the code of the LArCustomSolid Extention synchronized with the latest available version in the Athena repository, just run the autonomous-lar.sh script. +This folder contains the `LArCustomSolid Extension` that describes the ATLAS LAr EMEC custom shape. The LAr EMEC custom shape extension is build starting from a copy of the corresponding code in the Athena repository. +To keep the code of the LArCustomSolid Extention synchronized with the latest available version in the Athena repository, just run the `autonomous-lar.sh` script. ## Run ATLAS Simulation! Now you're ready to simulate the ATLAS detector in Geant4 with its real magnetic field map. You only have to run the following: -```c++ -./fullSimLight -g geometry-ATLAS-R3S-2021-03-02-00.db -c atlas-conf.json +```bash + +./fullSimLight -g geometry_atlas.db -c ../share/FullSimLight/ATLAS/atlas-conf.json + ``` diff --git a/documentation/docs/fullsimlight/fsl/fslDemo.mov b/documentation/docs/fullsimlight/fsl/fslDemo.mov new file mode 100644 index 0000000000000000000000000000000000000000..8824532d7c1a22b4ab774bb1d14703223ef142d0 Binary files /dev/null and b/documentation/docs/fullsimlight/fsl/fslDemo.mov differ diff --git a/documentation/docs/fullsimlight/fsl/fsl_gmclashDemo.mov b/documentation/docs/fullsimlight/fsl/fsl_gmclashDemo.mov new file mode 100644 index 0000000000000000000000000000000000000000..8c5da98ebcd2f174899e67540dc17d5b03c781a6 Binary files /dev/null and b/documentation/docs/fullsimlight/fsl/fsl_gmclashDemo.mov differ diff --git a/documentation/docs/fullsimlight/fsl/index.md b/documentation/docs/fullsimlight/fsl/index.md index 8e842685904ee679a8fdf86a8749e53354b55be7..bc233d04be117b5c11921694cd7949fe971fac73 100644 --- a/documentation/docs/fullsimlight/fsl/index.md +++ b/documentation/docs/fullsimlight/fsl/index.md @@ -1,24 +1,28 @@ -# fsl +# FullSimLight GUI: fsl -fsl is a GUI for FullSimLight introduced in GeoModel release 4.3.0. It allows users to configure their simulations in FullSimLight easily and without conflicts by providing a series of tabs which offer various configuration options. It can be ran from the command line through the fsl command. +`fsl` is a GUI for `fullSimLight` introduced in `GeoModel` release `4.3.0`. It allows users to configure their simulations in `fullSimLight` easily and without conflicts by providing a series of tabs which offer various configuration options. It can be ran from the command line through the `fsl` command. ```bash ./fsl ``` - Compatibility of the simulation is ensured by the fsl interface by enabling and disabling options based on the selections made. Once the user has configured the simulation to their desire, they can save the configuration in a json file that can be used to run FullSimLight through the -c flag. + Compatibility of the simulation is ensured by the `fsl` interface by enabling and disabling options based on the selections made. Once the user has configured the simulation to their desire, they can save the configuration in a json file that can be used to run `fullSimLight` through the `-c` flag. ```bash ./fullSimLight -c /path/to/config.json ``` -Alternatively the user can run FullSimLight at any time within fsl itself with the current configuration. fsl also allows users to load in previously saved configurations through the **Open Configuration** option. -One can also load in a configuration by running fsl with the -c flag. +Alternatively, the user can run `fullSimLight` at any time within `fsl` itself with the current configuration. `fsl` also allows users to load in previously saved configurations through the `Open Configuration` option. +One can also load in a configuration by running `fsl` with the `-c` flag. ```bash ./fsl -c /path/to/config.json ``` +!!! Tip "Watch!" + Watch the following video for a quick demo on how to configure and launch `fullSimLight` with its GUI `fsl`! + <video src="../fsl/fslDemo.mov" width="720" height="540" controls></video> + ## Main Tab @@ -36,9 +40,13 @@ The main tab allows configuration of the following parameters: - Physics List - Number of Threads - Number of Events -- G4UI Verbosity Commands +- `G4UI` Verbosity Commands + +It also contains the view button which shows the current configuration on the main display. The user can also run `fullSimLight` in the main display at any time with the current configuration by clicking on the `fullSimLight` button in the main tab. `fsl` provides similar buttons to run `gmex` and `gmclash` once a geometry input has been selected through the interface. -It also contains the view button which shows the current configuration on the main display. The user can also run FullSimLight in the main display at any time with the current configuration by clicking on the FullSimLight button in the main tab. fsl provides similar buttons to run gmex and gmclash once a geometry input has been selected through the interface. +!!! Tip "Watch!" + Watch the following video for a demo on how to easily run clash detection and visualize the clashing point together with the 3D geometry directly within `fsl`! + <video src="../fsl/fsl_gmclashDemo.mov" width="720" height="540" controls></video> ## Generator Tab @@ -54,28 +62,28 @@ It also contains the view button which shows the current configuration on the ma The generator tab shown above contains a list of event generators that can be selected for event generation. The options provided are: - Particle Gun -- Pythia -- HepMC3 File +- `Pythia` +- `HepMC3` File - Generator Plugin ### 1. Particle Gun -To use a Geant4 particle gun, the user must specify the particle type and the momentum vector. +To use a `Geant4` particle gun, the user must specify the particle type and the momentum vector. ### 2. Pythia -To use Pythia one can select one of the pre-customized options which are +To use `Pythia` one can select one of the pre-customized options which are - ttbar - higgs - minbias Details about the default options can be found in the `PythiaPrimaryGeneratorAction` [class](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/blob/main/FullSimLight/src/PythiaPrimaryGeneratorAction.cc). -Alternatively one can also provide a custom Pythia configuration input file. +Alternatively one can also provide a custom `Pythia` configuration input file. ### 3. HepMC3 File -HepMC3 files containing events can be used in FullSimLight in both the standard Asciiv3 format (introduced in HepMC3) as well as the old Ascii format (used in HepMC and HepMC2). +`HepMC3` files containing events can be used in `fullSimLight` in both the standard `Asciiv3` format (introduced in `HepMC3`) as well as the old `Ascii` format (used in `HepMC` and `HepMC2`). ### 4. Generator Plugin @@ -91,7 +99,7 @@ In order to generate events one can also specify a plugin. Visit the [Plugin Sup urlFix=False) }} -To set a Magnetic Field, there are two options +To set a Magnetic Field, there are two options: - Fixed Axial - Magnetic Field Plugin @@ -103,7 +111,13 @@ Sets a constant Magnetic field in the z-direction at the specified magnitude. ### 2. Magnetic Field Plugin -In order to generate a Magnetic Field one can also specify a plugin. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. A custom ATLAS Magnetic Field Plugin comes with the GeoModel package ready to use. This is automatically contained in the atlas-conf.json configuration file provided by GeoModel. ***Warning: This Plugin requires the ATLAS Magnetic Field Map to be installed in a standard location. This Map is available to all ATLAS users on request.*** +In order to generate a Magnetic Field one can also specify a plugin. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. + +A custom ATLAS Magnetic Field Plugin comes with the `GeoModel` package ready to use with the ATLAS Extensions package. This is automatically contained in the `atlas-conf.json` configuration file provided by GeoModel. + +!!! Warning + + This Plugin requires the ATLAS Magnetic Field Map to be installed in a standard location. For more info visit the [Atlas Extensions](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/) page. ## Regions Tab @@ -116,7 +130,7 @@ In order to generate a Magnetic Field one can also specify a plugin. Visit the [ urlFix=False) }} -Geant4 regions can be added through the regions tab in FSL as shown above. For each region one must specify +`Geant4` regions can be added through the regions tab in `fsl` as shown above. For each region one must specify - Region name - Root Logical Volumes @@ -125,7 +139,7 @@ Geant4 regions can be added through the regions tab in FSL as shown above. For e - Positron cut (GeV) - Gamma cut (GeV) -A list of ATLAS specific regions comes in the atlas-conf.json configuration file provided by GeoModel. +A list of ATLAS specific regions comes in the `atlas-conf.json` configuration file provided by GeoModel. ## Sensitive Detectors Tab @@ -137,7 +151,7 @@ A list of ATLAS specific regions comes in the atlas-conf.json configuration file urlFix=False) }} -In order to add Geant4 Sensitive Detectors one can create plugins which can then be added to the simulation through the menu shown above. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. +In order to add `Geant4` Sensitive Detectors one can create plugins which can then be added to the simulation through the menu shown above. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. ## User Actions Tab @@ -150,4 +164,4 @@ In order to add Geant4 Sensitive Detectors one can create plugins which can then urlFix=False) }} -In order to add Geant4 User Actions one can create plugins which can then be added to the simulation through the menu shown above. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. +In order to add `Geant4` User Actions one can create plugins which can then be added to the simulation through the menu shown above. Visit the [Plugin Support page](https://geomodel.web.cern.ch/home/fullsimlight/plugin-support/) for more details. diff --git a/documentation/docs/fullsimlight/fullsimlight/StepDisplay.png b/documentation/docs/fullsimlight/fullsimlight/StepDisplay.png new file mode 100644 index 0000000000000000000000000000000000000000..314f96c709a5d52c90769a869914f2c666be96fd Binary files /dev/null and b/documentation/docs/fullsimlight/fullsimlight/StepDisplay.png differ diff --git a/documentation/docs/fullsimlight/fullsimlight/TrackDisplay.png b/documentation/docs/fullsimlight/fullsimlight/TrackDisplay.png new file mode 100644 index 0000000000000000000000000000000000000000..82473bbd216972be35add8fd39974b00ba997379 Binary files /dev/null and b/documentation/docs/fullsimlight/fullsimlight/TrackDisplay.png differ diff --git a/documentation/docs/fullsimlight/fullsimlight/index.md b/documentation/docs/fullsimlight/fullsimlight/index.md index 10b3a15edeaf06d493307adbd52249bc2ba9d56d..c5d7fb4c2b227b66bb06d8a0f126383082e741df 100644 --- a/documentation/docs/fullsimlight/fullsimlight/index.md +++ b/documentation/docs/fullsimlight/fullsimlight/index.md @@ -1,113 +1,194 @@ # FullSimLight -FullSimLight package consists of different tools based on [Geant4](https://geant4.web.cern.ch) toolkit, that can be run on multiple geometries: +FullSimLight package consists of different tools based on the [Geant4](https://geant4.web.cern.ch) toolkit, that can be run on multiple geometries. It contains: -- fullSimLight: a light particle transport simulation (geometry, transport in magnetic field and basic physics scoring) -- fsl: GUI for fullSimLight configuration -- gmclash: a tool that runs clash detection on your input geometry, producing a json file report -- gmgeantino: a tool to generate geantino maps from your input geometry -- gm2gdml: a tool to convert geometries and dump them in gdml format. +- **fullSimLight**: a light `Geant4` particle transport simulation (geometry, transport in magnetic field and basic physics scoring) +- **fsl**: GUI for fullSimLight configuration +- **gmclash**: a tool that runs clash detection on your input geometry, producing a json file report +- **gmgeantino**: a tool to generate geantino maps from your input geometry +- **gmmasscalc**: a tool to compute the mass of a given piece of detector geometry +- **gm2gdml**: a tool to convert geometries and dump them in gdml format. -For instructions on how to build FullSimLight, please refer to the [Build FullSimLight ](https://geomodel.web.cern.ch/home/dev/build_fullsimlight/) page. +For instructions on how to install FullSimLight from development kits please refer to the [Install library and tools section](https://geomodel.web.cern.ch/home/start/install/). If you are a developer and want to build FullSimLight from source code, please refer to the [Build FullSimLight ](https://geomodel.web.cern.ch/home/dev/build_fullsimlight/) page. +For information on the specific tool please refer to the relevant section. -## Detector Construction +## FullSimLight: an experiment agnostic simulation tool -### Geometry: +`fullSimLight` is an experiment agnostic simulation tool that allows to easily run `Geant4` simulations by supporting multiple detector description formats (SQLite `.db`, `.gdml`, plugins `.dylib/.so`). It provides extended functionality by allowing the user to customise their simulation adding customized `Geant4` User Actions, Sensitive Detectors, specialised Physics Lists, custom particle generators, etc. These flexibility is provided through the mechanism of plugins which come in the form of shared libraries (`.dylib` or `.so`) containing user custom code. -The supported geometry formats are SQLite (.db), GDML (.gdml) and plugins that build from scratch a GeoModel geometry (.dylib/.so). An example of geometry plugins can be found in the [GeoModelExamples folder](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/GeoModelExamples/KitchenSinkPlugin). -Use the -g flag to specify the name of the input geometry file. +Two plugins that implement User Actions are available as examples for the users: the [Hits](https://geomodel.web.cern.ch/home/fullsimlight/plugins/#hits-plugin) plugin and the [Tracks](https://geomodel.web.cern.ch/home/fullsimlight/plugins/#tracks-plugin) plugin. -### ATLAS Geometry Files: +A built-in visualization for `fullSimLight` output is available in [gmex](https://geomodel.web.cern.ch/home/components/geomodelvisualization/gmex/) (the interactive 3D geometry visualization tool which is part of GeoModel). Hits steps and tracks generated with `fullSimLight` can be fed into `gmex`and consequently visualised. As an example the following figures can be seen. Figure 1 shows a Hits steps display of events transported with `fullSimLight` in the full ATLAS detector. -If you are interested in running with the ATLAS geometry files, please refer to the [ATLAS Extensions](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/) page. +{{ imgutils_image_caption('StepDisplay.png', + alt='StepDisplay', + cap='Figure 1: Steps display of events transported with fullSimLight in the full ATLAS detector.', + urlFix=False) +}} +Figure 2 shows a HITS tracks display of events transported with `fullSimLight` in the full ATLAS detector. -## FullSimLight: run and options +{{ imgutils_image_caption('TrackDisplay.png', + alt='TrackDisplay', + cap='Figure 2: Track display of primaries transported with fullSimLight in the full ATLAS detector.', + urlFix=False) +}} -The fullSimLight application can be built and used both with sequential and multithreaded Geant4 builds. In case of multithreaded Geant4 toolkit, the applications will run in proper multithreaded mode. You can find the executables under the build/bin directory and/or under the *< path-to-install > /bin* dir. -NB: Before running fullSimLight make sure to source the *geant4.sh* file to set correctly all the Geant4 environment variables. +## FullSimLight: run and main components -```bash -source <path_to_geant4_install_dir>/bin/geant4.sh -``` -To run FullSimLight you can specify a json configuration file (generated with fsl) with the -c flag or use the following command line parameters. Run the executable with the --help option to see the available options: +`fullSimLight` can be built and used both with sequential and multithreaded `Geant4` builds. In case of multithreaded installation of `Geant4`, the application will run in proper multithreaded mode. You can find the executables under the `build/bin` directory and/or under the `<path-to-install>/bin` dir. + +!!! note + + Before running fullSimLight make sure to source the *geant4.sh* file to set correctly all the Geant4 environment variables. + + ``` + source <path_to_geant4_install_dir>/bin/geant4.sh + ``` + + +`fullSimLight` can be configured in multiple ways (using `fsl` generated json configuration files or the `Geant4` macro files) and run either from the command line or within `fsl`. + + +## Configure and run fullSimLigth with its GUI fsl + +`fullSimLight` can be very easily configured and run via `fsl`, both from within the GUI or from the command-line, passing a json configuration file with the `-c` flag. Watch the following video for a quick demo on how to configure and launch `fullSimLight` with its GUI `fsl`! + +<video src="../fsl/fslDemo.mov" width="720" height="540" controls></video> + +For details on how to configure your simulation with `fsl` GUI, please refer to the [fsl page](https://geomodel.web.cern.ch/home/fullsimlight/fsl). + +## Run fullSimLigth from the command line + +Alternatively, `fullSimLight` can be executed via command line using the basic available flags. The only mandatory parameter necessary for starting a simulation is the geometry file. It can be specified inside the config file or with the `-g` flag. + +Run the executable with the --help option to see the available options: ``` bash --c : json configuration file generated with fsl +-c : [OPTIONAL] : json configuration file generated with fsl -g : [REQUIRED] : the Geometry file name - if not specified in the configuration file -m : [OPTIONAL] : the standard Geant4 macro file name -o : flag ==> run the geometry overlap check (default: FALSE) -f : physics list name (default: FTFP_BERT) --P : use Pythia primary generator [config. available: ttbar/higgs/minbias or use a Pythia command input file] --p : flag ==> run the application in performance mode i.e. no user actions - : - ==> run the application in NON performance mode i.e. with user actions (default) +-P : [OPTIONAL] :use Pythia primary generator [config. available: ttbar/higgs/minbias or use a Pythia command input file] ``` +Please refer to the [Command line examples](#command-line-examples) section for some examples that illustrate the different possibilities. -FullSimLight uses by default the Geant4 particle gun as primary generator, but it supports also -input events from the Pythia generator (see the Primary generator section below for more details), HepMC3 formats or custom generators plugins. +### Parameters configuration via Geant4 macro (disfauvored) -A minimal set of "observables" is collected during the simulation per-primary -particle type: mean energy deposit, mean charged and neutral step lengths, -mean number of steps made by charged and neutral particles, mean number of -secondary e-, e+ and gamma particles. The result is reported at the end of -each event for each primary particle that was transported in the given event. -At the end of the simulation a final report is printed showing the run time, -the primary generator and magnetic field settings used during the run, the -total number of events and primary particles transported and the per-primary -type simulation statistics of the above-mentioned quantities. +`fullSimLight` and in general `Geant4` based simulations, need a `Geant4` macro to inject some input parameters. The default macro used by `fullSimLight` is called `macro.g4` and it should be found under the `<install-path>/share/FullSimLight` directory. The macro can be edited to change some parameters, i.e the `Geant4` verbosity, the number of threads, or to tune the simulation. The most relevant macro commands are explained in the sections [Particle gun](#particle-gun) and [Magnetic field](#magnetic-field). -The simulation can be executed in "performance" mode by providing the -p -input flag. No any user actions are created in this case beyond the -only one RunAction (only for the Master-thread in case of MT) that will -start and stop a timer at the beginning and the end of the simulation -(initialization time won't be included). Therefore, there is no scoring -in this case. +Please note that this option is deprecated, as it doesn't allow full flexibility, and we suggest to configure your simulation via `fsl`. -## Examples -`FullSimLight` can be very easily configured and run via `fsl`, both from within the GUI or from the command-line, passing the configuration file with the -c flag. Alternatively, `FullSimLight` can be executed via command line using the basic available flags. The only mandatory parameter necessary for starting a simulation is the geometry file (can be specified inside the config file or with the -g flag). Following are some examples that illustrates the different possibilities. +## Detector Construction -If you have created your custom configuration file <myconfig.json> with fsl, you can simply run fullSimLight as follows: +The supported geometry formats are SQLite (.db), GDML (.gdml) and plugins compiled as shared libraries (.dylib/.so) that contains the C++ code that builds from scratch a GeoModel geometry. An example of geometry plugin can be found in the GeoModelExamples folder and it is the so-called [KitchenSinkPlugin](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/GeoModelExamples/KitchenSinkPlugin). -``` bash -./fullSimLight -c myconfig.json -``` -This is the best and more complete way of configuring FullSimLight because it allows you to customize also the use of plugins and to use all the different primary particles generation methods. +Use the `-g` flag to specify the name of the input geometry file. -As an alternative to using the json configuration file, one can use the available command line options and a classical geant4 macro to configure fullsimlight. +### ATLAS Geometry Files -During the installation a default macro file *<macro.g4>* will be installed in your *< install-path >/share/FullSimLight* directory. So the macro file doesn't need to be specified if you intend to use the default one. +If you are interested in running with the ATLAS geometry files, please refer to the [ATLAS Extensions](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/) page. + +## Event generation -To execute the application using the default < macro.g4 > macro file, with the default FTFP_BERT -Physics List, not in performance mode and building the detector from < mygeometry.db > file: +`fullSimLight` uses by default the `Geant4` particle gun as primary generator. In addition, it supports also +input events from the [Pythia](http://home.thep.lu.se/Pythia/) generator, [HepMC3](https://gitlab.cern.ch/hepmc/HepMC3) formats or custom event generators plugins. + + +### Particle gun + +The particle gun can be tuned either via `fsl` or by editing the `Geant4` macro file. The default configuration of the `macro.g4` file will generate 10 GeV primary particles (randomly chosen between e-,e+ and gammas) at the (0,0,0) position with isotropic momentum direction. + +Following are the UI commands that can be used to tune the `fullSimLight` particle gun. + +#### Number of primaries per event: +The number of primary particles per event can be set through the macro +command: ``` bash -./fullSimLight -g mygeometry.db +/FSLgun/primaryPerEvt <number> ``` -To execute the application using the default < macro.g4 > macro file and building the detector with a geometry described in one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/geomodelatlas/GeoModelATLAS/-/tree/master/GeoModelPlugins?ref_type=heads), i.e. *PixelPlugin* : +By default, i.e. if it is not specified by the above command, the number of primary particles will be randomly selected for each individual event from the [1, 10] interval uniformly. + +#### Primary particle energy: +The primary particle energy can be set through the macro command: ``` bash -./fullSimLight -g libPixePlugin.1.0.0.dylib/.so +/FSLgun/energy <energy-value> <unit> +``` +By default, i.e. if it is not specified by the above command, the kinetic energy will be randomly selected for each individual primary particle from the [1 GeV, 100 GeV] uniformly. + +#### Primary particle direction: +The primary particle momentum direction can be set through the macro command: + +``` bash +/FSLgun/direction <xdir-value> <ydir-value> <zdir-value> ``` +By default, i.e. if it is not specified by the above command, the momentum direction will be randomly selected for each individual primary particle from isotropic distribution. -To execute the application using a custom <mymacro.g4> macro file, with the ATLAS FTFP_BERT_ATL Physics List, in performance mode and building the detector from the geometry-ATLAS-R2-2016-01-00-01.db file : +#### Primary particle type: +The primary particle type can be set through the macro command: ``` bash -./fullSimLight -m mymacro.g4 -f FTFP_BERT_ATL -p -g geometry-ATLAS-R2-2016-01-00-01.db +/FSLgun/particle <particle-name> ``` +By default, i.e. if it is not specified by the above command, the type will be randomly selected from a pre-defined list for each individual primary particle uniformly. The current list of particles includes e-, e+ and gamma particles. It can be extended by adding more particles to the list in the `FSLPrimaryGeneratorAction` class. -Please note that the last option is deprecated, as it doesn't allow full flexibility, and we suggest to configure your simulation via `fsl`. +### Pythia generator + + `fullSimLight` supports `Pythia` as primary particles generator. In order to use `Pythia`, the user should have it installed in their system and if `Pythia` is found `fullSimLight` will be compiled with its support activated. + + In order to specify that `fullSimLight` has o run with `Pythia` event, the `-P` or `--pythia` flag has to be used. + Three different default options are available to run with `Pythia` events: `ttbar`, `higgs` and `minbias`: + +``` bash + -P : generate events with Pythia [config. available: ttbar/higgs/minbias or use ascii input file] +``` -## Parameters configuration via fsl (suggested) -For details on how to configure your simulation with fsl, please refer to the [fsl page](https://geomodel.web.cern.ch/home/fullsimlight/fsl). +The default configurations are currently defined as follows: +``` bash -## Parameters configuration via Geant4 macro (deprecated) +static const char *pythia_minbias[] = { + "HardQCD:all = on", + "Beams:eCM = 13000.0", + "PhaseSpace:pTHatMin = 20.0", +}; + +static const char *pythia_higgs[] = { + "HiggsSM:all = on", + "Beams:eCM = 13000.0", + "PhaseSpace:pTHatMin = 20.0", +}; + +static const char *pythia_ttbar[] = { + "Top:gg2ttbar = on", + "Top:qqbar2ttbar = on", + "Beams:eCM = 13000.0", + "PhaseSpace:pTHatMin = 20.0", +}; -FullSimLight and in general Geant4 based simulations, need a Geant4 macro to read some input parameters. The default macro used by fullSimLight is called 'macro.g4' and it should be found under the *< install-path > /share/FullSimLight* directory. The macro can be edited to change some parameters, i.e the verbosity, the number of threads, or to tune the simulation. The most relevant macro commands are explained in what follows. +``` +For example, in order to simulate the default *ttbar* events, the command to be run is the following: + +```bash + +./fullSimLight -m ../share/FullSimLight/pythia.g4 -P ttbar -g mygeometry.db + +``` + +Alternatively, the user can plug their own Pythia configuration file to simulate the desired events. + + The number of events that the user wants to simulate must be specified in a `Geant4` macro file. A specific `pythia.g4` macro file can be found in the `<path-to-install>/share/FullSimLight` directory. It should be used when simulating `Pythia` events and can be edited according to the user needs. + +### HepMC3 events input + +`fullSimLight` supports reading events in `HepMC3` format both the standard Asciiv3 format (introduced in `HepMC3`) as well as the old `Ascii` format (used in `HepMC` and `HepMC2`). This option is only available when configuring `fullSimLight` with `fsl` and the json configuration file. Please refer to the [FSL](https://geomodel.web.cern.ch/home/fullsimlight/fsl/) section for more info. ## Magnetic field @@ -119,111 +200,130 @@ FullSimLight and in general Geant4 based simulations, need a Geant4 macro to rea The default value is a uniform magnetic field of 4 Tesla. -## ATLAS Magnetic Field +### ATLAS Magnetic Field + +If you are interested in running with the ATLAS magnetic field map, please refer to the [ATLAS Extensions](https://geomodel.web.cern.ch/home/fullsimlight/atlas-extensions/) page. + +<!--- full_bfieldmap_7730_20400_14m_version5.root--> +<!--- solenoid_bfieldmap_7730_0_14m_version5.root--> +<!--- toroid_bfieldmap_0_20400_14m_version5.root--> +<!--- bmagatlas_09_fullAsym20400.data--> +<!----> +<!--If the magnetic field maps are not available to the user, a constant magnetic field can be set through the macro file. The test application "testMagneticField" can be used to test the different magnetic field maps and produce Maps in 2D histograms that are saved in a ROOT file (i.e 'ATLAS_BField_default.root') .--> +<!--Please notice that no dependency on ROOT is introduced, because the histograms are created, filled and saved using the `G4AnalysisManager`.--> +<!----> +<!--### testMagneticField examples:--> +<!--Run the application with the --help flag to see the options:--> +<!----> +<!--``` bash--> +<!--./testMagneticField --help--> +<!----> +<!---f : OPTIONAL: magnetic field filename [.data/.root] (default : use ATLAS magnetic field maps)--> +<!---r : FLAG: use root field map (default : false, use .data file)--> +<!---s : FLAG: set Solenoid Off --> +<!---t : FLAG: set Toroids Off --> +<!--```--> +<!----> +<!--By default the file tested is the *bmagatlas_09_fullAsym20400.data*. Use the -r option to test the ROOT file maps, add the -s flag to set the solenoid off and use the *toroid_bfieldmap_0_20400_14m_version5.root*:--> +<!----> +<!--``` bash--> +<!--./testMagneticField -r -s --> +<!--```--> +<!----> +<!--Use the -t to set the Toroids off, and test the *solenoid_bfieldmap_7730_0_14m_version5.root* file. --> +<!----> +<!--``` bash--> +<!--./testMagneticField -r -t --> +<!--```--> + +## Physics List -The ATLAS magnetic field is integrated in FullSimLight and can be used from it. The magnetic field map file used and supported are: + The Physics List can be specified as an input argument with the `-f` flag + (e.g. `-f FTFP_BERT_ATL`). Notice that the name of the `Geant4` built in Physics List + must be in upper case, exactly as the corresponding header file. By default, + i.e. if the Physics List name is not provided as an input argument, the `FTFP_BERT` + Physics List will be used. -- full_bfieldmap_7730_20400_14m_version5.root -- solenoid_bfieldmap_7730_0_14m_version5.root -- toroid_bfieldmap_0_20400_14m_version5.root -- bmagatlas_09_fullAsym20400.data +## Scoring -If the magnetic field maps are not available to the user, a constant magnetic field can be set through the macro file. The test application "testMagneticField" can be used to test the different magnetic field maps and produce Maps in 2D histograms that are saved in a ROOT file (i.e 'ATLAS_BField_default.root') . -Please notice that no dependency on ROOT is introduced, because the histograms are created, filled and saved using the *G4AnalysisManager*. +A minimal set of "observables" is collected during the simulation per-primary +particle type: mean energy deposit, mean charged and neutral step lengths, +mean number of steps made by charged and neutral particles, mean number of +secondary e-, e+ and gamma particles. The result is reported at the end of +each event for each primary particle that was transported in the given event. -### testMagneticField examples: -Run the application with the --help flag to see the options: +At the end of the simulation a final report is printed showing the run time, +the primary generator and magnetic field settings used during the run, the +total number of events and primary particles transported and the per-primary +type simulation statistics of the above-mentioned quantities. +Please see the following output as an example: + ``` bash -./testMagneticField --help +======================================================================================= + Run terminated: + Number of events transported = 10 + Time: User=0.020000s Real=0.021719s Sys=0.000000s [Cpu=92.1%] + ======================================================================================= + + ================================== Run summary ===================================== --f : OPTIONAL: magnetic field filename [.data/.root] (default : use ATLAS magnetic field maps) --r : FLAG: use root field map (default : false, use .data file) --s : FLAG: set Solenoid Off --t : FLAG: set Toroids Off -``` + Number of events = 10 + + ---------------------------------------------------------------------------------------- -By default the file tested is the *bmagatlas_09_fullAsym20400.data*. Use the -r option to test the ROOT file maps, add the -s flag to set the solenoid off and use the *toroid_bfieldmap_0_20400_14m_version5.root*: + Mean energy deposit per event = 0.01572 +- 0.01243 [GeV] -``` bash -./testMagneticField -r -s -``` + Mean track length (charged) per event = 67.77 +- 43.66 [cm] + Mean track length (neutral) per event = 154.9 +- 113.1 [cm] -Use the -t to set the Toroids off, and test the *solenoid_bfieldmap_7730_0_14m_version5.root* file. + Number of steps (charged) per event = 303.2 +- 215.3 + Number of steps (neutral) per event = 348.3 +- 255.9 -``` bash -./testMagneticField -r -t + Number of secondaries per event : + Gammas = 5.3 +- 4.649 + Electrons = 11.4 +- 9.78 + Positrons = 0.3 +- 0.4583 ``` -## Primary Generators -The primary generator used by default is the Geant4 particle gun, but FullSimLight also supports the [Pythia generator](http://home.thep.lu.se/Pythia/) and HepMC3 format. +<!--The simulation can be executed in "performance" mode by providing the -p--> +<!--input flag. No any user actions are created in this case beyond the--> +<!--only one RunAction (only for the Master-thread in case of MT) that will--> +<!--start and stop a timer at the beginning and the end of the simulation--> +<!--(initialization time won't be included). Therefore, there is no scoring--> +<!--in this case.--> -## Particle gun - - The particle gun used by default will generate primary particles - at the (0,0,0) position with the following options: -### Number of primaries per event: -The number of primary particles per event can be set through the macro -command: + +## Command line examples + +If you have created your custom configuration file `myconfig.json` with `fsl`, you can simply run fullSimLight as it follows: ``` bash -/FSLgun/primaryPerEvt <number> -``` +./fullSimLight -c myconfig.json +``` +This is the best and more complete way of configuring `fullSimLight` because it allows you to customize also the use of plugins and to use all the different primary particles generation methods. -By default, i.e. if it is not specified by the above command, the number of primary particles will be randomly selected for each individual event from the [1, 10] interval uniformly. +As an alternative to using the json configuration file, one can use the available command line options and a classical geant4 macro to configure `fullSimLight`. -### Primary particle energy: -The primary particle energy can be set through the macro command: +During the installation of FullSimLight a default macro file `macro.g4` will be installed in your `<install-path >/share/FullSimLight` directory. The macro file doesn't need to be specified if you intend to use the default one. + +To execute the application using the default `macro.g4` macro file, with the default FTFP_BERT +Physics List, building the detector from `mygeometry.db` file: ``` bash -/FSLgun/energy <energy-value> <unit> +./fullSimLight -g mygeometry.db ``` -By default, i.e. if it is not specified by the above command, the kinetic energy will be randomly selected for each individual primary particle from the [1 GeV, 100 GeV] uniformly. -### Primary particle direction: -The primary particle momentum direction can be set through the macro command: +To execute the application using the default `macro.g4` macro file and building the detector with a geometry described in one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/geomodelatlas/GeoModelATLAS/-/tree/master/GeoModelPlugins?ref_type=heads), i.e. `PixelPlugin` : ``` bash -/FSLgun/direction <xdir-value> <ydir-value> <zdir-value> +./fullSimLight -g libPixePlugin.1.0.0.dylib/.so ``` -By default, i.e. if it is not specified by the above command, the momentum direction will be randomly selected for each individual primary particle from isotropic distribution. -### Primary particle type: -The primary particle type can be set through the macro command: +To execute the application using a custom `mymacro.g4` macro file, with the ATLAS `FTFP_BERT_ATL` Physics List, with `Pythia` ttbar as primary events and building the detector from the `mygeometry.db` file : ``` bash -/FSLgun/particle <particle-name> -``` -By default, i.e. if it is not specified by the above command, the type will be randomly selected from a pre-defined list for each individual primary particle uniformly. The current list of particles includes e-, e+ and gamma particles. It can be extended by adding more particles to the list in the FSLPrimaryGeneratorAction class. - - -## Pythia generator - - FullSimLight supports Pythia as primary particles generator. In order to use Pythia, the user should have it installed in their system and if Pythia is found FullSimLight will be compiled with the support on. There are three different default options available when using the -P or --pythia flag (i.e. *ttbar*, *higgs* and *minbias*): - - ``` bash - -P : generate events with Pythia [config. available: ttbar/higgs/minbias or use ascii input file] - ``` - - Alternatively the user can plug their own Pythia configuration file to simulate the desired events. - For example, in order to simulate the default *ttbar* events, the command to be run is the following: - - ``` bash -./fullSimLight -m ../share/FullSimLight/pythia.g4 -P ttbar -g geometry-ATLAS-R2-2016-01-00-01.db - ``` - - The number of events that the user wants to simulate must be specified in the Geant4 macro file. A specific *pythia.g4* macro file can be found in the *< path-to-install >/share/FullSimLight* directory, that should be used when simulating Pythia events and can be edited according to the user needs. - -## HepMC3 events input - -FullSimLight supports reading events in HepMC3 format both the standard Asciiv3 format (introduced in HepMC3) as well as the old Ascii format (used in HepMC and HepMC2). This option is only available when configuring fullSimLight with FSL and the json configuration file. Please refer to the [FSL section](https://geomodel.web.cern.ch/home/fullsimlight/fsl/) for more info. - -## Physics List - - The Physics List can be specified as an input argument with the -f flag - (e.g. -f FTFP_BERT). Notice that the name of the Geant4 built in Physics List - must be in upper case, exactly as the corresponding header file. By default, - i.e. if the Physics List name is not provided as an input argument, the FTFP_BERT - Physics List will be used. +./fullSimLight -m mymacro.g4 -f FTFP_BERT_ATL -P ttbar -g mygeometry.db +``` diff --git a/documentation/docs/fullsimlight/gm2gdml/index.md b/documentation/docs/fullsimlight/gm2gdml/index.md index 14b708066115c1b73c39a6df500868f3f5f98cf9..2b1b149943c7e01b1d47e25237bffad781daba8a 100644 --- a/documentation/docs/fullsimlight/gm2gdml/index.md +++ b/documentation/docs/fullsimlight/gm2gdml/index.md @@ -1,10 +1,10 @@ # GeoModel2GDML -GeoModel2GDML (gm2gdml) is a command line tool based on Geant4, to convert geometries and dump them in gdml. -The geometry is first built in GeoModel, converted in Geant4 and dumped in gdml format. -The supported input geometries are : sqlite (.db), plugin (.so/dylib) and gdml. +GeoModel2GDML (`gm2gdml`) is a command line tool based on Geant4, to convert geometries and dump them in gdml. +The geometry is first built in `GeoModel`, converted in `Geant4` and dumped in gdml format. +The supported input geometries are : SQlite (.db), plugin (.so/dylib) and gdml. Before the dump operation the geometry is revised and the unidentified volumes are pulled out from the geometry. -Run the executable with the --help option to see the available options: +Run the executable with the `--help` option to see the available options: ``` bash ./gm2gdml --help @@ -18,13 +18,13 @@ Run the executable with the --help option to see the available options: ## Examples -To run *gm2gdml* one has to specify with the -g flag the geometry file (mandatory option). By default a 'geometry.gdml' output file is created, but the name of the file can be changed using the -o option. -To run gm2gdml on *LArBarrel.db* geometry, and dump the output gdml file in the *LArBarrel.gdml* file: +To run `gm2gdml` one has to specify with the `-g` flag the geometry file (mandatory option). By default a `geometry.gdml` output file is created, but the name of the file can be changed using the `-o` option. +To run `gm2gdml` on `LArBarrel.db` geometry, and dump the output gdml file in the `LArBarrel.gdml` file: ``` bash ./gm2gdml -g LArBarrel.db -o LArBarrel.gdml ``` -To dump your geometry described with a plugin, i.e. *HGTDPlugin*, and write out the geometry file in the *HGTDPlugin.gdml* file : +To dump your geometry described with a plugin, i.e. `HGTDPlugin`, and write out the geometry file in the `HGTDPlugin.gdml` file : ``` bash ./gm2gdml -g libHGTDPlugin.1.0.0.dylib -o HGTDPlugin.gdml ``` diff --git a/documentation/docs/fullsimlight/gmclash/gmclashDemo.mov b/documentation/docs/fullsimlight/gmclash/gmclashDemo.mov new file mode 100644 index 0000000000000000000000000000000000000000..e97219b44f3b031ae1dfebf59427caa61286300c Binary files /dev/null and b/documentation/docs/fullsimlight/gmclash/gmclashDemo.mov differ diff --git a/documentation/docs/fullsimlight/gmclash/index.md b/documentation/docs/fullsimlight/gmclash/index.md index 607a5aa97ac9902fd7b645446a0cd453ae42dbec..863a0d78b9953524f2bfd4df07995d0a16ecdbf5 100644 --- a/documentation/docs/fullsimlight/gmclash/index.md +++ b/documentation/docs/fullsimlight/gmclash/index.md @@ -1,13 +1,21 @@ # GeoModelClash -GeoModelClash (gmclash) allows to run geometry overlap checks on a geometry file specified as input with the -g flag. The clashes report is given in an output json file (default: *gmclash_report.json*). +GeoModelClash (`gmclash`) allows to run geometry overlap checks on a geometry file specified as input with the `-g` flag. The clashes report is given in an output json file (default: `gmclash_report.json`). -Run the executable with the --help option to see the available options: +Run the executable with the `--help` option to see the available options: ``` bash --g : MANDATORY: the Geometry file name [.db/.gdml/.dylib/.so] --o : OPTIONAL : clashes report file name (default: gmclash_report.json) -``` +-g : [MANDATORY] the Geometry file name [.db/.gdml/.dylib/.so] +-r : [OPTIONAL] root volume name (default: the Geometry top volume) +-o : [OPTIONAL] clashes report file name (default: gmclash_report.json) +-t : [OPTIONAL] tolerance threshold value in mm (default: 0) +-n : [OPTIONAL] number of random points (default: 1000) +-v : [OPTIONAL] verbose output (default: off) +``` + +By default `gmclash` starts the analysis from the Geometry top volume. Alternatively the user can specify a different root volume name by using the `-r` option. The tolerance threshold value is by default zero, but that value can be modified with the `-t` option. Another parameter that can be tuned is the number of random points that are shoot by `gmclash` to determine the overlapping points. By default it is set to 1000, but if the user wants to increase the precision of the report, this number can be increased with the `-n` option. + + The output json file format is the following: ``` bash @@ -25,29 +33,44 @@ The output json file format is the following: ``` where: -- *distance* is the minimum estimated distance of the overlap -- *typeOfClash* can be 0 for *withMother*, 1 for *withSister*, 2 for *fullyEncapsSister*, 3 for *invalidSolid* -- *x,y,z* are the global coordinates of the point of impact in cm +- `distance` is the minimum estimated distance of the overlap +- `typeOfClash` can be `0` for `withMother`, `1` for `withSister`, `2` for `fullyEncapsSister`, `3` for `invalidSolid` +- `x,y,z` are the global coordinates of the point of impact in cm + + +!!! note + + A solid is considered invalid, when it is the results of boolean operations that are "not safe" or wrong (i.e. summing up two solids that do not share any portion of their volumes). Usually an invalid solid is a solid for which it is not possible to correctly generate points on the surface. One example can be of a `solidC` that is the result of the subtraction of `solidA - solidB`, where `solidB` is bigger than `solidA`. This operation leads to a `NULL` volume that is considered as an invalid solid by `gmclash`. -N.B. A solid is considered invalid, when it is the results of boolean operations that are "not safe"or wrong (i.e. summing up two solids that do not share any portion of their volumes). Usually an invalid solid is a solid for which it is not possible to correctly generate points on the surface. One example can be of a *solidC* that is the result of the subtraction of *solidA* - *solidB*, where *solidB* is bigger than *solidA*. This operation leads to a *NULL* volume that is considered as an invalid solid by *gmclash*. +The clash points can then be inspected and visualized together with the geometry in `gmex`. + +!!! Tip "Watch!" + Watch the following video for a quick demo on how to visualize and debug clash points produced with `gmclash`in `gmex`! + <video src="gmclashDemo.mov" width="720" height="540" controls></video> ## Examples -To run GeoModelClash one has to specify with the -g flag the geometry file (this is mandatory). By default gmclash writes out the clashes report in the *gmclash_report.json* file: +To run `gmclash` one has to specify with the `-g` flag the geometry file (this is mandatory). By default `gmclash` writes out the clashes report in the `gmclash_report.json` file: ``` bash -./gmclash -g geometry-ATLAS-R2-2016-01-00-01_wSPECIALSHAPE.db +./gmclash -g mygeometry.db ``` -To execute a clash detection on a geometry described with the SQLite file *LArBarrel.db* and write out the clashes report in the *cr_LArBarrel.json* file : +To execute a clash detection on a geometry described with the SQLite file `LArBarrel.db` and write out the clashes report in the `cr_LArBarrel.json` file : ``` bash ./gmclash -g LArBarrel.db -o cr_LArBarrel.json ``` -To execute a clash detection on a geometry described with one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/GeoModelPlugins), i.e. *HGTDPlugin* and write out the clashes report in the *cr_HGTD.json* file : +To execute a clash detection on a geometry described with one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/GeoModelPlugins), i.e. `HGTDPlugin` and write out the clashes report in the `cr_HGTD.json` file : ``` bash ./gmclash -g libHGTDPlugin.1.0.0.dylib -o cr_HGTD.json ``` + +To execute a clash detection on `mygeometry.db` starting from the root volume `EndCap` and increasing the number of random points to 10k: +``` bash +./gmclash -g mygeometry.db -n 10000 -r EndCap -o cr_mygeometry_EndCap.json +``` + ## How to visualize the gmclash clashes report in gmex -Once the json clashes report has been produced, it can be plugged into *gmex* together with the geometry file that it's been inspected and visualized. In order to do that, it is sufficient to open the inspected geometry with *gmex* and then click on the *Clash Points* tab, push the *Open* button, and select the corresponding clash report file, as it can be seen in the Figure 1. +Once the json clashes report has been produced, it can be plugged into `gmex` together with the geometry file that it's been inspected and visualized. In order to do that, it is sufficient to open the inspected geometry with `gmex` and then click on the `Clash Points` tab, push the `Open` button, and select the corresponding clash report file, as it can be seen in Figure 1. {{ imgutils_image_caption('gmclash_1.png', alt='ClashPoints in gmex', diff --git a/documentation/docs/fullsimlight/gmgeantino/index.md b/documentation/docs/fullsimlight/gmgeantino/index.md index c357b794b1e7dd42efa244c95fb5515225053ad6..62e1db733db081a0c2eabab5d926c9857026c957 100644 --- a/documentation/docs/fullsimlight/gmgeantino/index.md +++ b/documentation/docs/fullsimlight/gmgeantino/index.md @@ -1,6 +1,6 @@ # GeoModelGeantino -GeoModelGeantino (gmgeantino) is a Geant4 based application that allows you to produce geantino maps for the geometry specified as input. It supports .db/.gdml/.dylib/.so geometry formats and it writes out the geantino maps in a ROOT file. However, it does not depend on ROOT, cause it uses the G4AnalysisManager to create/fill/write 1D and 2D Profiles. Examples of 1D and 2D profiles can be seen in Figure 1 and Figure 2, respectively. +GeoModelGeantino (`gmgeantino`) is a `Geant4` based application that allows you to produce geantino maps for the geometry specified as input. It supports `.db/.gdml/.dylib/.so` geometry formats and it writes out the geantino maps in a `ROOT` file. However, it does not depend on `ROOT`, cause it uses the `G4AnalysisManager` to create/fill/write 1D and 2D Profiles. Examples of 1D and 2D profiles can be seen in Figure 1 and Figure 2, respectively. {{ imgutils_image_caption('1D_profile.png', alt='1Dprofile', @@ -18,7 +18,7 @@ GeoModelGeantino (gmgeantino) is a Geant4 based application that allows you to p The 1D and 2D profiles are filled during the simulation, per Event or per Step. The creation of different profiles can be tuned with command line flags. In general X-Y, Z-R, eta, phi RadiationLength/InteractionLength profiles can be created per DetectorVolume/Material/Element. -*gmgeantino* can be run on different subdetectors and the results be combined to obtain plots like the one in Figure 3, that represents the material distribution expressed in units of *X0* as a function of *η* for the ATLAS Inner Detector. The breakdown indicates the contributions of external services and of individual sub-detectors, including services in their active volume. +`gmgeantino` can be run on different subdetectors and the results be combined to obtain plots like the one in Figure 3, that represents the material distribution expressed in units of `X0` as a function of `η` for the ATLAS Inner Detector. The breakdown indicates the contributions of external services and of individual sub-detectors, including services in their active volume. {{ imgutils_image_caption('MaterialDistribution.png', alt='materialDistr', @@ -26,36 +26,22 @@ The 1D and 2D profiles are filled during the simulation, per Event or per Step. urlFix=False) }} -gmgeantino uses a default geant4 macro, called *geantino.g4*, to take some input parameters. You should find this macro under your *< install-path > /share/FullSimLight* directory. You can edit this macro to change some parameters, like the verbosity, the n. of threads, the n. of primaries per event, the primary particle energy.. etc. +`gmgeantino` uses a default `Geant4` macro, called `geantino.g4`, to take some input parameters. You should find this macro under your `<install-path> /share/FullSimLight` directory. You can edit this macro to change some parameters, like the verbosity, the n. of threads, the n. of primaries per event, the primary particle energy.. etc. -By default the primary particles shot by 'gmgeantino' are geantinos (this parameter should not be changed). The default number of simulated geantinos is set to 1000. To increase the resolution of the maps, the n. of simulated events can be increased, editing the macro and changing the value at the following line: +By default the primary particles shot by `gmgeantino` are geantinos (this parameter should not be changed). The default number of simulated geantinos is set to 1000. To increase the resolution of the maps, the n. of simulated events can be increased, editing the macro and changing the value at the following line: ```bash /run/beamOn <n. of events> ``` +!!! note + + Before running gmgeantino make sure to source the `geant4.sh` file to set correctly all the Geant4 environment variables. + ```bash + source <path_to_geant4_install_dir>/bin/geant4.sh + ``` -NB: Before running gmgeantino make sure to source the *geant4.sh* file to set correctly all the Geant4 environment variables. -```bash -source <path_to_geant4_install_dir>/bin/geant4.sh -``` -Alternatively, you can modifiy the .bash_profile file in the following way: -```bash -#GEANT4 -export G4INSTALL=<full_path_to_Geant4_install_dir> -export G4NEUTRONHPDATA=$G4INSTALL/data/G4NDL4.6 -export G4LEDATA=$G4INSTALL/data/G4EMLOW7.9.1 -export G4LEVELGAMMADATA=$G4INSTALL/data/PhotonEvaporation5.5 -export G4RADIOACTIVEDATA=$G4INSTALL/data/RadioactiveDecay5.4 -export G4PARTICLEXSDATA=$G4INSTALL/data/G4PARTICLEXS2.1 -export G4PIIDATA=$G4INSTALL/data/G4PII1.3 -export G4REALSURFACEDATA=$G4INSTALL/data/RealSurface2.1.1 -export G4SAIDXSDATA=$G4INSTALL/data/G4SAIDDATA2.0 -export G4ABLADATA=$G4INSTALL/data/G4ABLA3.1 -export G4INCLDATA=$G4INSTALL/data/G4INCL1.0 -export G4ENSDFSTATEDATA=$G4INSTALL/data/G4ENSDFSTATE2.2 -``` -Run the executable with the --help option to see the available options: +Run the executable with the `--help` option to see the available options: ``` bash ./gmgeantino --help @@ -76,13 +62,14 @@ Run the executable with the --help option to see the available options: ## Examples -To run *gmgeantino* one has to specify with the -g flag the input geometry file (mandatory option). By default a 'geantinoMaps.root' file is created as output and it contains R-Z RadiationLenght and Interaction Lenght 2D profiles. To run gmgeantino on *LArBarrel.db* geometry, with the default *geantino.g4* macro file, and producing eta-phi maps and detector maps: +To run `gmgeantino` one has to specify with the `-g` flag the input geometry file (mandatory option). By default a `geantinoMaps.root` file is created as output and it contains R-Z RadiationLenght and Interaction Lenght 2D profiles. To run gmgeantino on `LArBarrel.db` geometry, with the default `geantino.g4` macro file, and producing eta-phi maps and detector maps: ``` bash ./gmgeantino -m ../share/FullSimLight/geantino.g4 -g LArBarrel.db -e -d ``` -To produce geantino maps of a geometry described by one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/GeoModelPlugins), i.e. *AGDDPlugin*, using a custom macro file *mymacro.g4*, activate detectors/materials and elements maps, and write out the geantino maps in the *geantinoMaps_AGDD.root* file : +To produce geantino maps of a geometry described by one of the [GeoModelPlugins repo](https://gitlab.cern.ch/atlas/GeoModelPlugins), i.e. `AGDDPlugin`, using a custom macro file `mymacro.g4`, activate detectors/materials and elements maps, and write out the geantino maps in the `geantinoMaps_AGDD.root` file : + ``` bash ./gmgeantino -m mymacro.g4 -g libAGDDPlugin.1.0.0.dylib -d -a -l -o geantinoMaps_AGDD.root ``` diff --git a/documentation/docs/fullsimlight/plugin-support/index.md b/documentation/docs/fullsimlight/plugin-support/index.md index 1943fc80f63069b36a0eb6d8efc2c4a1ebb13715..715bfd9e5d179ad41026454042c28e783c8c4e9b 100644 --- a/documentation/docs/fullsimlight/plugin-support/index.md +++ b/documentation/docs/fullsimlight/plugin-support/index.md @@ -1,6 +1,6 @@ # Plugin Support -FullSimLight provides the user support with writing plugins by providing the abstract classes which one has to override. These abstract classes serve as a link to interface various Geant4 functionality with simulation using FullSimLight. Header files containing these abstract classes are automatically installed with FullSimLight installation. +`fullSimLight` provides the user support with writing plugins by providing the abstract classes which one has to override. These abstract classes serve as a link to interface various `Geant4` functionality with simulation using FullSimLight. Header files containing these abstract classes are automatically installed with FullSimLight installation. ## User Actions & Event Generators <!----> diff --git a/documentation/docs/fullsimlight/plugins/index.md b/documentation/docs/fullsimlight/plugins/index.md index 8d72c03f925d7ff61bafc9e31cb71fc79ab9313d..3cf7ba8e7aa011c8fb88e3bf87f5b0aad80a3b48 100644 --- a/documentation/docs/fullsimlight/plugins/index.md +++ b/documentation/docs/fullsimlight/plugins/index.md @@ -1,6 +1,6 @@ # Plugins Examples -FullSimLight provides a convenient mechanism for users to extend their simulations through plugins in the form of shared libraries. Plugins can be used to add: +`fullSimLight` provides a convenient mechanism for users to extend their simulations through plugins in the form of shared libraries. Plugins can be used to add: - Geometry description - User Actions @@ -21,15 +21,15 @@ You can find some example user actions plugins under the FullSimLight/Plugins fo ###Hits Plugin -The [Hits plugin](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/FullSimLight/Plugins/HitsPlugin) implements both `G4UserSteppingAction` and `G4UserEventAction`. At each step the particle position (x,y,z coordinates) is saved and at the end of the event the hits are saved into a HDF5 output file. The same file can be in a second step visualized in `gmex`. +The [Hits plugin](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/FullSimLight/Plugins/HitsPlugin) implements both `G4UserSteppingAction` and `G4UserEventAction`. At each step the particle position (x,y,z coordinates) is saved and at the end of the event the hits are saved into a `HDF5` output file. The same file can be in a second step visualized in `gmex`. ###Tracks Plugin -The [Tracks Plugin](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/FullSimLight/Plugins/TracksPlugin) implements `G4UserRunAction`, `G4UserEventAction`, `G4UserSteppingAction`, `G4UserTrackingAction`. For each track at each step the position is recorded and mapped into a map. At the end of the event the information is saved into a HDF5 output file (the default name is Tracks_data.h5). The tracks file data can be in a second step visualized in `gmex`. +The [Tracks Plugin](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/tree/main/FullSimLight/Plugins/TracksPlugin) implements `G4UserRunAction`, `G4UserEventAction`, `G4UserSteppingAction`, `G4UserTrackingAction`. For each track at each step the position is recorded and mapped into a map. At the end of the event the information is saved into a `HDF5` output file (the default name is `Tracks_data.h5`). The tracks file data can be in a second step visualized in `gmex`. ##Sensitive Detectors plugins -One sensitive detectors example plugin is provided [here](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/blob/main/FullSimLight/Plugins/Examples/SensitiveDetectorPlugins/SDPlugin/src/SDPlugin.cxx). It's a dummy plugin that serves the purpose of showing how to implement the corresponding FullSimLight abstract interface. +One sensitive detectors example plugin is provided [here](https://gitlab.cern.ch/GeoModelDev/GeoModel/-/blob/main/FullSimLight/Plugins/Examples/SensitiveDetectorPlugins/SDPlugin/src/SDPlugin.cxx). It's a dummy plugin that serves the purpose of showing how to implement the corresponding `fullSimLight` abstract interface. ##Magnetic Field plugins @@ -119,7 +119,7 @@ extern "C" GenerateHitsPlugin * createGenerateHitsPlugin(); - The first two classes `GenerateHitsStep` & `GenerateHitsEvent` will inherit from `G4UserSteppingAction` and `G4UserEventAction` respectively, since these contain the methods that are relevant for our purpose as discussed earlier. In general you will need one class for every type of User Action you decide to use. -- The final class `GenerateHitsPlugin` is neccesary for defining the plugin and ***must have the same name as the name specified within the add_library command in the CMakeLists.txt file.*** This class will inherit from the `FSLUserActionPlugin` class, which is the abstract class provided by FullSimLight to allow it to interface with our custom defined User Actions. This class must always be defined. +- The final class `GenerateHitsPlugin` is necessary for defining the plugin and ***must have the same name as the name specified within the add_library command in the CMakeLists.txt file.*** This class will inherit from the `FSLUserActionPlugin` class, which is the abstract class provided by FullSimLight to allow it to interface with our custom defined User Actions. This class must always be defined. - Finally the function `createGenerateHitsPlugin` is neccesary for properly loading in the plugin to FullSimLight and ***must always have the name create + name of plugin class.*** This function must always be defined. diff --git a/documentation/docs/index.md b/documentation/docs/index.md index 167cff67b423618f63b42bbc1223dc0015949fe8..c0c23e59728cd057a6d249f199ca58f417e76aa9 100755 --- a/documentation/docs/index.md +++ b/documentation/docs/index.md @@ -3,15 +3,104 @@ # GeoModel - A Detector Description Toolkit for HEP experiments +GeoModel is a **complete toolkit** to write and manage the **detector description** for High Energy Physics experiments. -The GeoModel Toolkit offers classes that provide geometrical primitives for describing detectors, and a set of tools for accessing, handling, manipulating, dumping, restoring, visualizing, inspecting, and debugging the detector geometry. -The external dependencies are minimal: +## Intro -- The Eigen math library for the core packages -- The `Xerces-C` XML parser and the `nlohmann_json` JSON parser to import external data -- The Qt framework for the visualization -- The `fmt` formatting library +The GeoModel Toolkit offers classes that provide geometrical primitives for describing detectors, as well as a set of tools for writing, accessing, handling, manipulating, dumping, restoring, visualizing, inspecting, and debugging the detector geometry. + +GeoModel also offers many **memory-saving techniques** which lets developers to optimally describe their detectors while keeping the memory footprint very low. + +GeoModel is a **pure C++ toolkit** with only **minimal and ligthweight external dependencies**. + +The GeoModel Toolkit is also **highly modular**: + +you can pick the modules and tools you need, and **you will use only what you really need**, without the fear of introducing extra external potentially heavyweight dependencies when not needed. + +## Features + +### Geometry Description + +A complete set of shapes and geometrical primitives to describe your detector's geometry + +A set of 'nodes' to build your detector tree + +### Alignment + +A smart mechanism to handle detector alignment, with multiple alignment costants kept in cache and synchronized + + +### Virtual Geometry / Surfaces + +Tools to describe and handle 2D surfaces as part of a Virtual Geometry, which can be placed and misaligned alongside the regular, full geometry + +Very useful to describe a simplified Tracking Geometry and still move and handle together with the full geometry + +### Visualization + +A complete, **interactive visualization** tool to check, inspect, debug your detector geometry in an easy way + +### GDML support + +An **exporter** to export a GeoModel geometry into GDML + +An **importer** to import a GDML geometry into GeoModel *(work in progress)* + +### Standalone Detector Simulation + +#### Easy Geant4-based simulation + +An **interactive graphical interface** to steer a standalone Geant4-based simulation of your detector, to get quick feedback on your detector while you're still working on it + +#### Clash Detection & Visualization + +Standalone tools to identify clash points and overlaps between geometry volumes with a fast Geant4-based algorithm + +Interactive visualization of clash points in the standalone GeoModel visualization module + +#### Volume Computation + +Methods to compute the volume of all shapes, included Boolean shapes, and store it in the GeoModel I/O file for later use + +#### Mass calculation + +A standalone **mass calculator tool**, to quickly compute the masses of your detector from the command line + +#### Geantino Maps + +A standalone tool to **generate geantino maps** of your newly built detector + + + +The GeoModel Toolkit includes: + +* **gmex**, the geometry explorer, an interactive 3D geometry visualizer +* **gmstatistics**, tool to monitor the memory consumption +* **fullsimlight**, a command-line tool to run experiment agnostic Geant4 simulation, and its graphical user interface, *fsl*. +* **gmclash**, a Geant4 based command-line tool to perform clash detection +* **gmgeantino**, a Geant4 based command-line tool to generate geantino maps +* **gmmasscalc**, a Geant4 based command-line tool to compute the mass of a given piece of detector geometry +* **gm2gdml** and **gdml2gm**, command line tools to convert GeoModel to and from GDML +* **gmcat**, a command line tool to assemble geometry from multiple inputs + +---- + +## External Dependencies + +The GeoModel Toolkit offers C++ classes that provide geometrical primitives for describing detector geometry (e.g., shapes, logical/physical volumes, transformations), as well as a set of tools for writing, accessing, handling, manipulating, dumping, restoring, visualizing, inspecting, and debugging detector geometries. + +- The [Eigen](https://eigen.tuxfamily.org) math library for the core packages + +Additional external dependencies: + +- The lighweight [SQLite](https://www.sqlite.org/) file-based database for I/O, when the `I/O` module is used +- The [`nlohmann_json`](https://github.com/nlohmann/json) JSON parser library to import external data, when the `Visualization` and `Tools` modules are used +- The Apache [`Xerces-C`](https://xerces.apache.org/xerces-c/) XML parser library, when the XML interface of the `Tools` module is used +- The open-source ("Community") version of the [Qt graphics framework](https://www.qt.io/) for the GUI, when the `Visualization` module is used +- The [Coin](https://github.com/coin3d/coin) and [SoQt](https://github.com/coin3d/soqt) libraries for 3D graphics, when the `Visualization` module is used +- The [Geant4](https://geant4.web.cern.ch/) detector simulation toolkit, when the standalone detector simulation module `FullSimLight` is used +- The [`fmt`](https://github.com/fmtlib/fmt) formatting library for advanced string formatting, when the `I/O` module is used ---- diff --git a/documentation/docs/start/install.md b/documentation/docs/start/install.md index d732d634bed00fa7b2492032561cfde2399adeda..1a59c69bffec957a31c33eab2f521297bb16bcc1 100644 --- a/documentation/docs/start/install.md +++ b/documentation/docs/start/install.md @@ -2,17 +2,6 @@ In this section, you will find instructions on how to **install** the latest **stable** version of GeoModel applications and development kits on different platforms. If you are a developer and would like to install the GeoModel toolkit from source, please refer to the [Developers installation instructions](../dev/index.md). -The GeoModel applications include: - -* **gmex**, the geometry explorer, an interactive 3d geometry visualizer -* **gmstatistics**, tool to monitor the memory consumption -* **fullsimlight**, a command-line tool to run Geant4 simulation, and its graphical user interface, *fsl*. -* **gmclash**, a Geant4 based command-line tool to perform clash detection -* **gmgeantino**, a Geant4 based command-line tool to generate geantino maps -* **gmmasscalc**, a Geant4 based command-line tool to compute the mass of a given piece of detector geometry -* **gm2gdml** and **gdml2gm**, command line tools to convert GeoModel to and from GDML -* **gmcat**, a command line tool to assemble geometry from multiple inputs - The development kits include header files and precompiled libraries for the development of detector description code. On some platforms (macOS) the development environment is installed together with the prebuild applications and libraries. @@ -23,6 +12,8 @@ Add the geomodel repository to your source list: ``` sudo add-apt-repository ppa:kaktusjoe/geomodel +sudo add-apt-repository ppa:kaktusjoe/coingraphics +sudo add-apt-repository ppa:kaktusjoe/g4dist sudo apt-get update ``` @@ -47,8 +38,9 @@ If you have outdated packages, these commands will replace those packages with t The GeoModelExplorer (GMEX) application appears to crash when run on the latest version of the Ubuntu "Wayland" window manager. The problem is that the SoQt/Coin third-party packages we use in GMEX have not been ported to work to the latest Wayland yet. As far as we know, all applications that use the Coin/SoQt graphics layers as their graphics interface crash on the latest Wayland. The Coin3D community is aware of the problem but there are no fixes, yet. - We strongly suggest to use the alternative X11 window manager when running GEMX (or all other SoQt/Coin3D-based applications) on Ubuntu, for the time being. + We strongly suggest to use the alternative X11 window manager when running GMEX (or all other SoQt/Coin3D-based applications) on Ubuntu, for the time being. + Note also: hardware acceleration is required for the GMEX application to work properly. On computers with NVidia graphics, install and run the `nvidia-settings` application; go into the `PRIME Profiles` section and choose performance mode. ## How to install GeoModel on macOS diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index a1e7b923e42fc87fa6a99e4951aff00f140d483b..5442752406e0e11770540be763340b7111896865 100755 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -27,7 +27,9 @@ nav: - 'Overview': 'components/kernel/overview/index.md' - 'Class Reference': 'components/kernel/reference/index.md' - GeoModelTools: - - 'GDML2GeoModel': 'components/geomodeltools/gdml2gm/index.md' + - 'GeoModelCat (gmcat)': 'components/geomodeltools/gmcat/index.md' + - 'GeoModelStatistics (gmstatistics)': 'components/geomodeltools/gmstatistics/index.md' + - 'GDML2GeoModel (gdml2gm)': 'components/geomodeltools/gdml2gm/index.md' - GeoModelXML: - 'GeoModelXML Overview' : 'components/geomodelxml/index.md' - 'Building a geometry' : 'components/geomodelxml/buildinggeometry.md' @@ -40,18 +42,18 @@ nav: - 'Troubleshooting' : 'components/geomodelxml/troubleshooting.md' - 'User Guide (old, ATLAS specific)' : 'components/geomodelxml/old.md' - GeoModelVisualization: - - 'GeoModelExplorer': 'components/geomodelvisualization/gmex/index.md' + - 'GeoModelExplorer (gmex)': 'components/geomodelvisualization/gmex/index.md' - FullSimLight tools: - 'FullSimLight': 'fullsimlight/fullsimlight/index.md' - - 'GeoModelClash': 'fullsimlight/gmclash/index.md' - - 'GeoModelGeantino': 'fullsimlight/gmgeantino/index.md' - - 'GeoModelMassCalculator': 'fullsimlight/gmmasscalc/index.md' - - 'GeoModel2GDML': 'fullsimlight/gm2gdml/index.md' - - 'fsl': 'fullsimlight/fsl/index.md' + - 'fsl GUI': 'fullsimlight/fsl/index.md' + - 'GeoModelClash (gmclash)': 'fullsimlight/gmclash/index.md' + - 'GeoModelGeantino (gmgeantino)': 'fullsimlight/gmgeantino/index.md' + - 'GeoModelMassCalculator (gmmasscalc)': 'fullsimlight/gmmasscalc/index.md' + - 'GeoModel2GDML (gm2gdml)': 'fullsimlight/gm2gdml/index.md' + - 'Plugin Examples': 'fullsimlight/plugins/index.md' - 'Plugin Support': 'fullsimlight/plugin-support/index.md' - 'ATLAS Extensions': 'fullsimlight/atlas-extensions/index.md' - - FAQ: 'faq.md' - For Developers: - 'Build the Libraries and Tools': 'dev/index.md' - 'Build FullSimLight': 'dev/build_fullsimlight.md' @@ -60,6 +62,7 @@ nav: - 'Doxygen documentation': https://cern.ch/geomodel/doxygen - 'Contributing to the Documentation': 'dev/docs-contrib.md' - 'Dev FAQ': 'dev/dev-faq.md' + - FAQ: 'faq.md' - Papers & Presentations: 'papers.md' # - 'Public': 'papers/public.md' # - 'Internal': 'papers/internal.md'