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

First version of the PrintTree (plus update gitignore)

parent e46ec154
No related branches found
No related tags found
No related merge requests found
Pipeline #8519417 failed
......@@ -7,3 +7,8 @@
build
.vscode
install
#in-source build
CMakeFiles/
CMakeCache.txt
build
\ No newline at end of file
# macOS stuff
.DS_Store
# Eclipse IDE
......
......@@ -17,14 +17,17 @@
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelRead/ReadGeoModel.h"
#include "GeoModelKernel/GeoPrintGraphAction.h"
// C++ includes
#include <cstdlib> // EXIT_FAILURE
#include <cstdlib> // EXIT_FAILURE
#include <fstream>
#include <iostream>
int main(int argc, char* argv[]) {
if (argc != 2) {
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "\nERROR!\nUsage: %s <geometry.db>\n\n", argv[0]);
return 1;
}
......@@ -34,26 +37,30 @@ int main(int argc, char* argv[]) {
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) {
if (world == nullptr)
{
std::cout << "---ERROR! 'World' is a 'nullptr'! exiting...\n\n";
exit(1);
} else {
}
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();
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
......@@ -64,43 +71,70 @@ int main(int argc, char* argv[]) {
std::cout << "Looping over all 'volume' children (i.e., GeoPhysVol and "
"GeoFullPhysVol)..."
<< std::endl;
for (unsigned int idx = 0; idx < nChil; ++idx) {
for (unsigned int idx = 0; idx < nChil; ++idx)
{
PVConstLink nodeLink = 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);
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);
}
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 << "===> Tree:" << std::endl;
std::vector<std::string> nodes{};
std::ostringstream ostr;
GeoPrintGraphAction pg(ostr);
childVolV->exec(&pg);
int pos = 0;
std::string ostrstring = ostr.str();
while (pos < ostrstring.size())
{
pos = ostrstring.find("\n");
nodes.push_back(ostrstring.substr(0, pos));
ostrstring.erase(0, pos + 2); // 2 is the length of the delimiter, "\n"
}
std::cout << ostr.str();
for (const auto &node : nodes )
std::cout << "***" << node << 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)));
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)))) {
}
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)));
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: "
......
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