diff --git a/.gitignore b/.gitignore index 913334569d20d6c815183ecf4914132677e2141b..7240a723893fd77ff9e8f1de7e29842fd4b5af27 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ build .vscode install + +#in-source build +CMakeFiles/ +CMakeCache.txt +build \ No newline at end of file diff --git a/GeoModelIO/.gitignore b/GeoModelIO/.gitignore index a281625af985578351f9a2c799ab986f1e032e46..f1f924d8e385260d5ea26c48c9a1116c656aafb4 100644 --- a/GeoModelIO/.gitignore +++ b/GeoModelIO/.gitignore @@ -1,3 +1,4 @@ +# macOS stuff .DS_Store # Eclipse IDE diff --git a/GeoModelIO/GeoModelIOTools/printTree.cpp b/GeoModelIO/GeoModelIOTools/printTree.cpp index 3650736ffac09c7d653fd28cac232d7054ff826a..9180a566de482e44e26827bf2cf0ddeee6bfc017 100644 --- a/GeoModelIO/GeoModelIOTools/printTree.cpp +++ b/GeoModelIO/GeoModelIOTools/printTree.cpp @@ -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: "