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

Update the HelloGeoRead example with the use of the new I/O helpers.

The example now compiles three executables:

1) main1, which uses the loadDB helper to pick the 'world' volume from
   the input .db and loop over its children;

2) main2, which uses the 'getReaderDB' helper to get a reader object,
   with which it reads data rows from the input .db file. It then picks
the 'world' volume from the same .db file with the 'loadDB' helper and
loops over its children;

3) main3, which performs the same operations than main2 but without
   using the new helper functions. It uses the lower-level GMDBManager
and GeoModelRead directly. That shows how to use those to users who
need to perform lower-level operations.
parent 6f1e9238
No related branches found
No related tags found
1 merge request!217Fix the compilation of I/O helpers
......@@ -7,7 +7,7 @@
cmake_minimum_required(VERSION 3.16...3.26)
#project(HelloGeoRead)
project(HelloGeoRead)
# Compile with C++17
set(CMAKE_CXX_STANDARD 17)
......@@ -24,10 +24,16 @@ endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Populate a CMake variable with the sources
set(SRCS main.cpp )
set(SRCS1 main1.cpp )
set(SRCS2 main2.cpp )
set(SRCS3 main3.cpp )
# Tell CMake to create the helloworld executable
add_executable( hellogeoRead ${SRCS} )
add_executable( hellogeoRead_1 ${SRCS1} )
add_executable( hellogeoRead_2 ${SRCS2} )
add_executable( hellogeoRead_3 ${SRCS3} )
# Link all needed libraries
target_link_libraries( hellogeoRead GeoModelIO::GeoModelRead GeoModelCore::GeoModelKernel)
target_link_libraries( hellogeoRead_1 GeoModelIO::GeoModelRead GeoModelCore::GeoModelKernel)
target_link_libraries( hellogeoRead_2 GeoModelIO::GeoModelRead GeoModelCore::GeoModelKernel)
target_link_libraries( hellogeoRead_3 GeoModelIO::GeoModelRead GeoModelCore::GeoModelKernel)
......@@ -10,7 +10,9 @@
*/
// GeoModel includes
#include "GeoModelDBManager/GMDBManager.h"
//#include "GeoModelDBManager/GMDBManager.h"
#include "GeoModelIOHelpers/GMIO.h"
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelKernel/GeoFullPhysVol.h"
#include "GeoModelKernel/GeoNameTag.h"
......@@ -78,29 +80,46 @@ int main(int argc, char* argv[]) {
fileName = argv[1];
std::cout << "Using this SQLite '.db' file:" << fileName << std::endl;
// check if DB file exists. If not, return.
// FIXME: TODO: this check should go in the 'GMDBManager' constructor.
std::ifstream infile(fileName.c_str());
if (!infile.good()) {
std::cout << "\n\tERROR!! A '" << fileName
<< "' file does not exist!! Please, check the path of the "
"input file before running this program. Exiting...";
exit(EXIT_FAILURE);
}
infile.close();
// GET GEOMETRY FROM LOCAL DB
// open the DB
GMDBManager* db = new GMDBManager(fileName);
/* Open database */
if (db->checkIsDBOpen()) {
std::cout << "OK! Database is open!\n";
} else {
std::cout << "Database is not open!\n";
// return;
throw;
}
//// check if DB file exists. If not, return.
//std::ifstream infile(fileName.c_str());
//if (!infile.good()) {
//std::cout << "\n\tERROR!! A '" << fileName
//<< "' file does not exist!! Please, check the path of the "
//"input file before running this program. Exiting...";
//exit(EXIT_FAILURE);
//}
//infile.close();
// Get a reader to explore/print the tables in the GeoModel DB
GeoModelIO::ReadGeoModel geoReader = GeoModelIO::IO::getReaderDB(fileName);
std::cout << "Reading records from the imported geometry DB file..."
<< std::endl;
geoReader.printDBTable("SerialIdentifiers");
geoReader.printDBTable("IdentifierTags");
// Get the 'world' volume from the GeoModel DB
std::cout << "Picking the 'World' volume from the geometry DB file..."
<< std::endl;
GeoVPhysVol *world = GeoModelIO::IO::loadDB(fileName);
std::cout << "'World' volume loaded." << std::endl;
//// open the DB
//GMDBManager* db = new GMDBManager(fileName);
//[> Open database <]
//if (db->checkIsDBOpen()) {
//std::cout << "OK! Database is open!\n";
//} else {
//std::cout << "Database is not open!\n";
//// return;
//throw;
//}
// -- testing the input database
// std::cout << "Printing the list of all GeoMaterial nodes" << std::endl;
......@@ -108,27 +127,26 @@ int main(int argc, char* argv[]) {
// std::cout << "Printing the list of all GeoElement nodes" << std::endl;
// db->printAllElements();
/* setup the GeoModel reader */
GeoModelIO::ReadGeoModel geoReader = GeoModelIO::ReadGeoModel(db);
std::cout << "OK! ReadGeoModel is set." << std::endl;
//[> setup the GeoModel reader <]
//GeoModelIO::ReadGeoModel geoReader = GeoModelIO::ReadGeoModel(db);
//std::cout << "OK! ReadGeoModel is set." << std::endl;
/* build the GeoModel geometry */
GeoVPhysVol* dbPhys =
geoReader.buildGeoModel(); // builds the whole GeoModel tree in memory
std::cout << "ReadGeoModel::buildGeoModel() done." << std::endl;
//[> build the GeoModel geometry <]
//GeoVPhysVol* dbPhys =
//geoReader.buildGeoModel(); // builds the whole GeoModel tree in memory
std::cout << "Reading records from the imported geometry DB file..."
<< std::endl;
geoReader.printDBTable("SerialIdentifiers");
geoReader.printDBTable("IdentifierTags");
// create the world volume container and
// get the 'world' volume, i.e. the root volume of the GeoModel tree
std::cout << "Getting the 'world' GeoVPhysVol, i.e. the root volume of the "
"GeoModel tree, which can be either a GeoPhysVol or a "
"GeoFullPhysVol (both inherit from GeoVPhysVol)"
<< std::endl;
GeoVPhysVol* world = createTheWorld(dbPhys);
//// create the world volume container and
//// get the 'world' volume, i.e. the root volume of the GeoModel tree
//std::cout << "Getting the 'world' GeoVPhysVol, i.e. the root volume of the "
//"GeoModel tree, which can be either a GeoPhysVol or a "
//"GeoFullPhysVol (both inherit from GeoVPhysVol)"
//<< std::endl;
//GeoVPhysVol* world = createTheWorld(dbPhys);
std::cout << "Getting the GeoLogVol used by the 'world' volume"
<< std::endl;
const GeoLogVol* logVol = world->getLogVol();
......
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
/*
* HelloGeoRead_1
*
* Author: Riccardo Maria BIANCHI @ CERN
* Created on: Nov, 2018
* Updated on: Oct, 2023
*
*/
// 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;
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;
}
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
/*
* HelloGeoRead_2
*
* Author: Riccardo Maria BIANCHI @ CERN
* Created on: Nov, 2018
* Updated on: Oct, 2023
*
*/
// 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 line;
std::string fileName;
fileName = argv[1];
std::cout << "Using this SQLite '.db' file:" << fileName << std::endl;
// Get a reader to explore/print the tables in the GeoModel DB
GeoModelIO::ReadGeoModel geoReader = GeoModelIO::IO::getReaderDB(fileName);
std::cout << "Reading records from the imported geometry DB file..."
<< std::endl;
geoReader.printDBTable("NameTags");
geoReader.printDBTable("Elements");
// Get the 'world' volume from the GeoModel DB
std::cout << "Picking the 'World' volume from the geometry DB file..."
<< std::endl;
GeoVPhysVol *world = GeoModelIO::IO::loadDB(fileName);
std::cout << "'World' volume loaded." << std::endl;
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;
}
// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
/*
* HelloGeoRead_3
*
* Author: Riccardo Maria BIANCHI @ CERN
* Created on: Nov, 2018
* Updated on: Oct, 2023
*
*/
// GeoModel includes
#include "GeoModelDBManager/GMDBManager.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 line;
std::string fileName;
fileName = argv[1];
std::cout << "Using this SQLite '.db' file:" << fileName << std::endl;
// check if DB file exists. If not, return.
std::ifstream inputfile(fileName.c_str());
if (!inputfile.good()) {
std::cout << "\n\tERROR!! A '" << fileName
<< "' file does not exist!! Please, check the path of the "
"input file before running this program. Exiting...";
exit(EXIT_FAILURE);
}
inputfile.close();
// open the DB
GMDBManager* db = new GMDBManager(fileName);
/* Open database */
if (db->checkIsDBOpen()) {
std::cout << "OK! Database is open!\n";
} else {
std::cout << "Database is not open!\n";
// return;
throw;
}
/* testing the input database */
std::cout << "Reading records from the database..." << std::endl;
std::cout << "Printing the list of all GeoMaterial nodes" << std::endl;
db->printAllMaterials();
std::cout << "Printing the list of all GeoElement nodes" << std::endl;
db->printAllElements();
/* set the GeoModel reader */
GeoModelIO::ReadGeoModel geoReader = GeoModelIO::ReadGeoModel(db);
std::cout << "OK! ReadGeoModel is set." << std::endl;
/* reading data from the imported .db file by usinhg the reader object */
std::cout << "Reading the same records from the imported geometry DB file..."
<< std::endl;
geoReader.printDBTable("Materials");
geoReader.printDBTable("Elements");
/* build the GeoModel tree and load it in memory */
GeoVPhysVol* world = geoReader.buildGeoModel();
// --- 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