diff --git a/GeoModelIO/CMakeLists.txt b/GeoModelIO/CMakeLists.txt index fb4ac93e4853f04b52f6b69e0c6ec4bf944fa5ad..013aed1eb8dfc378ef7c79e1b2beb1dbc2bb2ca5 100644 --- a/GeoModelIO/CMakeLists.txt +++ b/GeoModelIO/CMakeLists.txt @@ -10,6 +10,7 @@ add_subdirectory( TFPersistification ) add_subdirectory( GeoModelRead ) add_subdirectory( GeoModelWrite ) add_subdirectory( GeoModelIOHelpers ) +add_subdirectory( GeoModelIOTools ) # Create and install the version description of the project. include( CMakePackageConfigHelpers ) diff --git a/GeoModelIO/GeoModelIOTools/CMakeLists.txt b/GeoModelIO/GeoModelIOTools/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec770e70b5f64461cfb8492c154181161ca0ed5d --- /dev/null +++ b/GeoModelIO/GeoModelIOTools/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +################################################################################ +# Package: GeoModelIOTools +# author: Riccardo Maria BIANCHI @ CERN - Nov, 2024 +################################################################################ + +cmake_minimum_required(VERSION 3.16...3.26) + +project(GeoModelIOTools) + +# 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 ) + find_package( GeoModelIOHelpers REQUIRED ) +endif() + +# Find includes in current dir +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Populate a CMake variable with the sources +set(SRC_PRINTTREE printTree.cpp ) + +# Tell CMake to create the helloworld executable +add_executable( printTree ${SRC_PRINTTREE} ) + +# Link all needed libraries +target_link_libraries( printTree GeoModelCore::GeoModelKernel GeoModelIO::GeoModelIOHelpers) diff --git a/GeoModelIO/GeoModelIOTools/printTree.cpp b/GeoModelIO/GeoModelIOTools/printTree.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3650736ffac09c7d653fd28cac232d7054ff826a --- /dev/null +++ b/GeoModelIO/GeoModelIOTools/printTree.cpp @@ -0,0 +1,115 @@ +// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + +/* + * printTree + * + * Author: Riccardo Maria BIANCHI @ CERN + * Created on: Nov, 2024 + * + */ + +// GeoModel includes +#include "GeoModelIOHelpers/GMIO.h" + +#include "GeoModelKernel/GeoBox.h" +#include "GeoModelKernel/GeoFullPhysVol.h" +#include "GeoModelKernel/GeoNameTag.h" +#include "GeoModelKernel/GeoPhysVol.h" +#include "GeoModelRead/ReadGeoModel.h" + +// C++ includes +#include <cstdlib> // EXIT_FAILURE +#include <fstream> +#include <iostream> + + +int main(int argc, char* argv[]) { + if (argc != 2) { + fprintf(stderr, "\nERROR!\nUsage: %s <geometry.db>\n\n", argv[0]); + return 1; + } + + // Get from command-line the input SQLite '.db' file containing the geometry + std::string fileName; + fileName = argv[1]; + std::cout << "Using this SQLite '.db' file:" << fileName << std::endl; + + + // Get the 'world' volume from the GeoModel DB + std::cout << "Picking the 'World' volume from the geometry DB file..." + << std::endl; + const GeoVPhysVol *world = GeoModelIO::IO::loadDB(fileName); + if(world == nullptr) { + std::cout << "---ERROR! 'World' is a 'nullptr'! exiting...\n\n"; + exit(1); + } else { + std::cout << "'World' volume loaded." << std::endl; + } + + // --- Reading the properties of the 'world' volume retrieved from the .db file + std::cout << "Getting the GeoLogVol used by the 'world' volume" + << std::endl; + const GeoLogVol* logVol = world->getLogVol(); + std::cout << "'world' GeoLogVol name: " << logVol->getName() << std::endl; + std::cout << "'world' GeoMaterial name: " + << logVol->getMaterial()->getName() << std::endl; + + // --- Reading the imported Geometry + + // get number of children volumes + unsigned int nChil = world->getNChildVols(); + std::cout << "'world' 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); + + if (dynamic_cast<const GeoVPhysVol*>(&(*(nodeLink)))) { + std::cout << "\t" + << "the child n. " << idx << " "; + const GeoVPhysVol* childVolV = &(*(nodeLink)); + + if (dynamic_cast<const GeoPhysVol*>(childVolV)) { + const GeoPhysVol* childVol = + dynamic_cast<const GeoPhysVol*>(childVolV); + std::cout << "is a GeoPhysVol, whose GeoLogVol name is: " + << childVol->getLogVol()->getName(); + std::cout << " and it has " << childVol->getNChildVols() + << " child volumes" << std::endl; + } else if (dynamic_cast<const GeoFullPhysVol*>(childVolV)) { + const GeoFullPhysVol* childVol = + dynamic_cast<const GeoFullPhysVol*>(childVolV); + std::cout << "is a GeoFullPhysVol, whose GeoLogVol name is: " + << childVol->getLogVol()->getName(); + std::cout << " and it has " << childVol->getNChildVols() + << " child volumes" << std::endl; + } + } else if (dynamic_cast<const GeoNameTag*>(&(*(nodeLink)))) { + std::cout << "\t" + << "the child n. " << idx << " is a GeoNameTag" + << std::endl; + const GeoNameTag* childVol = + dynamic_cast<const GeoNameTag*>(&(*(nodeLink))); + std::cout << "\t\t GeoNameTag's name: " << childVol->getName() + << std::endl; + } else if (dynamic_cast<const GeoMaterial*>(&(*(nodeLink)))) { + std::cout << "\t" + << "the child n. " << idx << " is a GeoMaterial" + << std::endl; + const GeoMaterial* childVol = + dynamic_cast<const GeoMaterial*>(&(*(nodeLink))); + std::cout << "\t\t GeoMaterial's name: " << childVol->getName() + << std::endl; + std::cout << "\t\t GeoMaterial's number of elements: " + << childVol->getNumElements() << std::endl; + } + } + + std::cout << "Everything done." << std::endl; + + // return app.exec(); + return 0; +}