Skip to content
Snippets Groups Projects
Commit c2745942 authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny:
Browse files

Add new IOTools package and a draft exec to print the tree

parent cec37d3c
No related branches found
No related tags found
No related merge requests found
......@@ -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 )
......
# 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)
// 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment