From 9bafa72e7c229261b80557d8cb1a94b59db48a6f Mon Sep 17 00:00:00 2001 From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch> Date: Wed, 3 Jul 2024 00:14:46 +0200 Subject: [PATCH] Remove obsolete GeoModelCppHelpers package and clean code --- .../GeoModelHelpers/StringUtils.icc | 6 +- GeoModelIO/CMakeLists.txt | 1 - GeoModelIO/GeoModelCppHelpers/CMakeLists.txt | 49 -- .../GeoModelCppHelpers/GMCppHelpers.h | 58 -- GeoModelIO/GeoModelCppHelpers/README.md | 4 - GeoModelIO/GeoModelDBManager/CMakeLists.txt | 2 +- .../GeoModelDBManager/src/GMDBManager.cpp | 34 +- GeoModelIO/GeoModelRead/CMakeLists.txt | 2 +- GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp | 691 +----------------- GeoModelIO/GeoModelWrite/CMakeLists.txt | 2 +- .../GeoModelWrite/src/WriteGeoModel.cpp | 557 +------------- 11 files changed, 22 insertions(+), 1384 deletions(-) delete mode 100644 GeoModelIO/GeoModelCppHelpers/CMakeLists.txt delete mode 100644 GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h delete mode 100644 GeoModelIO/GeoModelCppHelpers/README.md diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc index 04c7d2e17..f5c659d8b 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/StringUtils.icc @@ -10,16 +10,16 @@ namespace GeoStrUtils { template <class ObjType> std::string chainUp(const std::vector<ObjType>& vector, const std::string_view glue) { - return chainUp(vector.size(), [&vector](const unsigned int ele)->ObjType { + return chainUp<ObjType>(vector.size(), [&vector](const unsigned int ele)->ObjType { return vector.at(ele); }, glue); } template <class ObjType> std::string chainUp(unsigned int numEles, - const std::function<ObjType(unsigned int)>& func, + const std::function<ObjType(const unsigned int)>& func, const std::string_view glue) { std::stringstream chain{}; - for (unsigned int k =0; k < numEles; ++k) { + for (unsigned int k=0; k < numEles; ++k) { chain<<func(k); if (k + 1 < numEles)chain<<glue; } diff --git a/GeoModelIO/CMakeLists.txt b/GeoModelIO/CMakeLists.txt index 1443b11c7..9d2e6bdc2 100644 --- a/GeoModelIO/CMakeLists.txt +++ b/GeoModelIO/CMakeLists.txt @@ -10,7 +10,6 @@ add_subdirectory( TFPersistification ) add_subdirectory( GeoModelRead ) add_subdirectory( GeoModelWrite ) add_subdirectory( GeoModelIOHelpers ) -add_subdirectory( GeoModelCppHelpers ) # Create and install the version description of the project. include( CMakePackageConfigHelpers ) diff --git a/GeoModelIO/GeoModelCppHelpers/CMakeLists.txt b/GeoModelIO/GeoModelCppHelpers/CMakeLists.txt deleted file mode 100644 index 9a8262afa..000000000 --- a/GeoModelIO/GeoModelCppHelpers/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration -################################################################################ -# Package: GeoModelCppHelpers -# author: Riccardo Maria BIANCHI <rbianchi@cern.ch> - 2024 Apr -################################################################################ - -# Find the header and source files. -file( GLOB SOURCES src/*.cpp ) -file( GLOB HEADERS GeoModelCppHelpers/*.h ) - -# Set up the library. -add_library( GeoModelCppHelpers SHARED ${HEADERS} ${SOURCES} ) -# target_link_libraries( GeoModelCppHelpers PUBLIC -# GeoModelHelpers ) - -# We link those to carry on the needed libs when including GeoModelCppHelpers, -# even if the latter is headers only -target_include_directories( GeoModelCppHelpers PUBLIC - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> - $<INSTALL_INTERFACE:include> ) -source_group( "GeoModelCppHelpers" FILES ${HEADERS} ) -source_group( "src" FILES ${SOURCES} ) -set_target_properties( GeoModelCppHelpers PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} ) -set_target_properties(GeoModelCppHelpers PROPERTIES LINKER_LANGUAGE CXX) - -# Set up custom build flags for the library. -foreach( _flag GEOMODEL_IO_READ_DEBUG GEOMODEL_IO_DEBUG_VERBOSE - GEOMODEL_IO_READ_TIMING ) - if( ${${_flag}} ) - target_compile_definitions( GeoModelCppHelpers PRIVATE ${_flag}=true ) - endif() -endforeach() - -# Set up an alias with the same name that you would get by "finding" a pre-built -# version of the library. -add_library( GeoModelIO::GeoModelCppHelpers ALIAS GeoModelCppHelpers ) - -# Install the library. -install(TARGETS GeoModelCppHelpers - EXPORT ${PROJECT_NAME}-export - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT Runtime - NAMELINK_COMPONENT Development # Requires CMake 3.12 -) -install( FILES ${HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelCppHelpers - COMPONENT Development ) diff --git a/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h b/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h deleted file mode 100644 index 08285c4ef..000000000 --- a/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h +++ /dev/null @@ -1,58 +0,0 @@ - -// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration - -/* - * This header file provides helper C++ functions used in GeoModel IO code. - * - * Author: Riccardo Maria BIANCHI @ CERN - * Created on: Apr, 2024 - * - */ - - -#ifndef GMCPPHelper_H -#define GMCPPHelper_H - - -// C++ includes -#include <cstdlib> // EXIT_FAILURE -#include <fstream> -#include <string> -#include <sstream> -#include <iostream> -#include <variant> -#include <type_traits> - -namespace GeoModelIO { - - class CppHelper - { - public: - // dummy constructor - CppHelper(){}; - - // FIXME: should go to an utility class - static std::string joinVectorStrings(std::vector<std::string> vec, - std::string sep = "") - { - std::string s; - unsigned int ii = 0; - for (const auto &piece : vec) - { - ++ii; - if (ii == vec.size()) - { - s += (piece); - } - else - { - s += (piece + sep); - } - } - return s; - } - - }; -} // namespace GeoModelIO - -#endif diff --git a/GeoModelIO/GeoModelCppHelpers/README.md b/GeoModelIO/GeoModelCppHelpers/README.md deleted file mode 100644 index b12f7a2b4..000000000 --- a/GeoModelIO/GeoModelCppHelpers/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# GeoModelCppHelpers - -This package contains C++ helper functions for IO operations. - diff --git a/GeoModelIO/GeoModelDBManager/CMakeLists.txt b/GeoModelIO/GeoModelDBManager/CMakeLists.txt index d9f6d548f..52ee219c2 100644 --- a/GeoModelIO/GeoModelDBManager/CMakeLists.txt +++ b/GeoModelIO/GeoModelDBManager/CMakeLists.txt @@ -14,7 +14,7 @@ file( GLOB HEADERS GeoModelDBManager/*.h ) # Set up the library. add_library( GeoModelDBManager SHARED ${HEADERS} ${SOURCES} ) -target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 GeoModelHelpers GeoModelCppHelpers ) +target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 GeoModelHelpers ) target_include_directories( GeoModelDBManager PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) diff --git a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp index f9322a493..91e033551 100644 --- a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp +++ b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp @@ -22,8 +22,6 @@ #include <GeoModelDBManager/GMDBManager.h> -#include "GeoModelCppHelpers/GMCppHelpers.h" - #include "GeoModelHelpers/throwExcept.h" #include "GeoModelHelpers/StringUtils.h" @@ -214,7 +212,7 @@ void GMDBManager::printAllRecords(const std::string& tableName) const { return; } // --- print table column names - std::cout << "- " << GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + std::cout << "- " << GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") << std::endl; // --- print records std::vector<std::vector<std::string>> records; @@ -782,7 +780,7 @@ bool GMDBManager::addListOfRecordsToTable( // get table columns and format them for query std::string tableColString = - "(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")"; + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; unsigned int nRecords = records.size(); @@ -803,7 +801,7 @@ bool GMDBManager::addListOfRecordsToTable( // values when inserting them in the table, as we now // do for the std::variant version! } - std::string values = GeoModelIO::CppHelper::joinVectorStrings(items, ","); + std::string values = GeoStrUtils::chainUp(items, ","); sql += " (" + std::to_string(id) + "," + values + ")"; // INT if (id != nRecords) { sql += ","; @@ -831,7 +829,7 @@ bool GMDBManager::addListOfRecordsToTable( if (records.size() > 0) { // get table columns and format them for query std::string tableColString = - "(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")"; + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; unsigned int nRecords = records.size(); @@ -874,7 +872,7 @@ bool GMDBManager::addListOfRecordsToTable( THROW_EXCEPTION("No std::variant alternative found!"); } // we build the long string containing all values - std::string values = GeoModelIO::CppHelper::joinVectorStrings(items, ","); + std::string values = GeoStrUtils::chainUp(items, ","); sql += " (" + std::to_string(id) + "," + values + ")"; // INT if (id != nRecords) { sql += ","; @@ -893,19 +891,15 @@ bool GMDBManager::addListOfRecordsToTable( return false; } - - bool GMDBManager::addRecordsToTable( const std::string tableName, - const DBRowEntry - records) + const DBRowEntry records) { if (records.size() > 0) { // get table columns and format them for query std::string tableColString = - "(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")"; - if (m_debug) - std::cout << "tableColString:" << tableColString << std::endl; + "(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")"; + if (m_debug) std::cout << "tableColString:" << tableColString << std::endl; unsigned int nRecords = records.size(); @@ -918,6 +912,8 @@ bool GMDBManager::addRecordsToTable( unsigned int id = 0; // a vector to store string-conversions of values, to build the SQL // query + // TODO: we should remove this TEXT-conversion + // and we should use prepared statements instead! std::vector<std::string> items; // loop over all entries in a row/record for (const std::variant<int, long, float, double, std::string> &item : @@ -968,14 +964,8 @@ bool GMDBManager::addRecordsToTable( } items.push_back(endRow); } - // we build the long string containing all values - std::string values = GeoModelIO::CppHelper::joinVectorStrings(items); - - // // TODO: replace CppHelper with global Helpers - // std::string valuesTest = GeoStrUtils::chainUp(items, ","); - // std::cout << "values: " << values << std::endl; - // std::cout << "valuesTest: " << valuesTest << std::endl; - + // we build the long SQL string containing all values + std::string values = GeoStrUtils::chainUp<std::string>(items, ""); sql += " " + values + ";"; if (m_debug) diff --git a/GeoModelIO/GeoModelRead/CMakeLists.txt b/GeoModelIO/GeoModelRead/CMakeLists.txt index 5db6153b0..5ae4e4fb1 100644 --- a/GeoModelIO/GeoModelRead/CMakeLists.txt +++ b/GeoModelIO/GeoModelRead/CMakeLists.txt @@ -12,7 +12,7 @@ file( GLOB HEADERS GeoModelRead/*.h GeoModelRead/*.tpp ) # Set up the library. add_library( GeoModelRead SHARED ${HEADERS} ${SOURCES} ) target_link_libraries( GeoModelRead PUBLIC -GeoModelKernel GeoModelDBManager TFPersistification GeoModelCppHelpers GeoModelHelpers ) +GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers ) target_include_directories( GeoModelRead PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) diff --git a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp index 43259148c..95f0a56f1 100644 --- a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp +++ b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp @@ -506,43 +506,6 @@ GeoVPhysVol* ReadGeoModel::buildGeoModelPrivate() { return getRootVolume(); } -// OLD method -//---------------------------------------- -// loop over parent-child relationship data -// void ReadGeoModel::loopOverAllChildrenRecords( -// std::vector<std::vector<std::string>> records) { -// int nChildrenRecords = records.size(); - -// if (m_loglevel >= 1) { -// muxCout.lock(); -// std::cout << "\nReadGeoModel::loopOverAllChildrenRecords -- Thread " -// << std::this_thread::get_id() << " - processing " -// << nChildrenRecords << " keys..." << std::endl; -// muxCout.unlock(); -// } - -// // // Get Start Time -// // std::chrono::system_clock::time_point start = -// // std::chrono::system_clock::now(); - -// for (auto& record : records) { -// processParentChild(record); -// } - -// // // Get End Time -// // auto end = std::chrono::system_clock::now(); -// // auto diff = std::chrono::duration_cast < std::chrono::seconds > (end -// // - start).count(); -// // -// // if (m_timing || (m_loglevel >= 1)) { -// // muxCout.lock(); -// // std::cout << "Time Taken to process " << nChildrenRecords << " -// // parent-child relationships = " << diff << " Seconds" << std::endl; -// // muxCout.unlock(); -// // } -// } - -// NEW method //---------------------------------------- // loop over parent-child relationship data void ReadGeoModel::loopOverAllChildrenRecords( @@ -1128,116 +1091,6 @@ void ReadGeoModel::buildAllSerialTransformers() { << " SerialTransformers have been built!\n"; } -// FIXME: implement build function and cache for Functions -// //! Iterate over the list of nodes, build them all, and store their pointers -// void ReadGeoModel::buildAllFunctions() -// { -// if (m_debug) std::cout << "Building all Functions...\n"; -//// if (m_serialTransformers.size() == 0) { -//// std::cout << "ERROR!!! input SerialTransformers are empty! Exiting..." -///<< std::endl; / exit(EXIT_FAILURE); / } / size_t nSize = -/// m_functions.size(); / m_memMapFunctions.reserve( nSize*2 ); // TODO: check -/// if 2 is good or redundant... / for (unsigned int ii=0; ii<nSize; ++ii) { / -/// buildFunction(ii+1); // nodes' IDs start from 1 / } -// QHash<unsigned int, QStringList>::const_iterator i = -// m_functions.constBegin(); while (i != m_functions.constEnd()) { -// unsigned int id = i.key(); -// buildFunction(id); -// ++i; -// } -// } - -/* -//! Iterate over the list of nodes, build them all, and store their pointers -void ReadGeoModel::buildAllPhysVols() { - if (m_loglevel >= 1) std::cout << "Building all PhysVols...\n"; - if (m_physVols.size() == 0) { - std::cout << "ERROR!!! No input PhysVols found! Exiting..." - << std::endl; - exit(EXIT_FAILURE); - } - const unsigned int tableID = m_tableName_toTableID["GeoPhysVol"]; - size_t nSize = m_physVols.size(); - m_memMapPhysVols.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_physVols[ii][0]); - const unsigned int logVolID = std::stoi(m_physVols[ii][1]); - // std::cout << "building PhysVol n. " << volID << " (logVol: " << - // logVolID << ")" << std::endl; - buildVPhysVol(volID, tableID, logVolID); - } - if (nSize > 0) - std::cout << "All " << nSize << " PhysVols have been built!\n"; -} - -//! Iterate over the list of nodes, build them all, and store their pointers -void ReadGeoModel::buildAllFullPhysVols() { - if (m_loglevel >= 1) std::cout << "Building all FullPhysVols...\n"; - const unsigned int tableID = m_tableName_toTableID["GeoFullPhysVol"]; - size_t nSize = m_fullPhysVols.size(); - m_memMapFullPhysVols.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_fullPhysVols[ii][0]); - const unsigned int logVolID = std::stoi(m_fullPhysVols[ii][1]); - // std::cout << "building PhysVol n. " << volID << " (logVol: " << - // logVolID << ")" << std::endl; - buildVPhysVol(volID, tableID, logVolID); - } - if (nSize > 0) - std::cout << "All " << nSize << " FullPhysVols have been built!\n"; -} - -//! Iterate over the list of GeoAlignableTransforms nodes, build them all, -//! and store their pointers -void ReadGeoModel::buildAllAlignableTransforms() { - if (m_loglevel >= 1) std::cout << "Building all AlignableTransforms...\n"; - size_t nSize = m_alignableTransforms.size(); - m_memMapAlignableTransforms.reserve( - nSize * 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_alignableTransforms[ii][0]); - buildAlignableTransform(volID); - } - if (nSize > 0) - std::cout << "All " << nSize - << " AlignableTransforms have been built!\n"; -} - -//! Iterate over the list of GeoTransforms nodes, build them all, and store -//! their pointers -void ReadGeoModel::buildAllTransforms() { - if (m_loglevel >= 1) std::cout << "Building all Transforms...\n"; - size_t nSize = m_transforms.size(); - m_memMapTransforms.reserve(nSize * - 2); // TODO: check if *2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_transforms[ii][0]); - buildTransform(volID); - } - if (nSize > 0) - std::cout << "All " << nSize << " Transforms have been built!\n"; -} - -//! Iterate over the list of GeoTransforms nodes, build them all, and store -//! their pointers -void ReadGeoModel::buildAllSerialTransformers() { - if (m_loglevel >= 1) std::cout << "Building all SerialTransformers...\n"; - size_t nSize = m_serialTransformers.size(); - m_memMapSerialTransformers.reserve( - nSize * 2); // TODO: check if 2 is good or redundant... - for (unsigned int ii = 0; ii < nSize; ++ii) { - const unsigned int volID = std::stoi(m_serialTransformers[ii][0]); - buildSerialTransformer(volID); - } - if (nSize > 0) - std::cout << "All " << nSize - << " SerialTransformers have been built!\n"; -} -*/ - - // FIXME: implement build function and cache for Functions // //! Iterate over the list of nodes, build them all, and store their // pointers @@ -1259,118 +1112,6 @@ void ReadGeoModel::buildAllFunctions() { } */ - - -// void ReadGeoModel::loopOverAllChildrenInBunches_String() { -// int nChildrenRecords = m_allchildren.size(); -// if (m_loglevel >= 1) -// std::cout << "number of children to process: " << nChildrenRecords -// << std::endl; - -// // If we have a few children, then process them serially -// // std::cout << "Running concurrently? " << m_runMultithreaded << -// // std::endl; -// if (true) // !(m_runMultithreaded) || nChildrenRecords <= 500) // TODO: -// // test if you can optimize, then revert to if()...else() -// { -// // std::cout << "Running serially...\n"; -// loopOverAllChildrenRecords(m_allchildren); -// } -// // ...otherwise, let's spawn some threads to process them in bunches, -// // parallelly! -// else { -// // std::cout << "Running concurrently...\n"; - -// std::chrono::system_clock::time_point start, end; -// if (m_timing || (m_loglevel >= 1)) { -// // Get Start Time -// start = std::chrono::system_clock::now(); -// } - -// // set number of worker threads -// unsigned int nThreads = 0; -// if (m_runMultithreaded_nThreads > 0) { -// nThreads = m_runMultithreaded_nThreads; -// } else if (m_runMultithreaded_nThreads == -1) { -// unsigned int nThreadsPlatform = std::thread::hardware_concurrency(); -// nThreads = nThreadsPlatform; -// if (m_loglevel >= 1) -// std::cout << "INFO - You have asked for hardware native " -// "parellelism. On this platform, " -// << nThreadsPlatform -// << " concurrent threads are supported. Thus, using " -// << nThreads << " threads.\n"; -// } - -// unsigned int nBunches = nChildrenRecords / nThreads; -// if (m_loglevel >= 1) -// std::cout << "Processing " << nThreads << " bunches, with " -// << nBunches << " children each, plus the remainder." -// << std::endl; - -// // a vector to store the "futures" of async calls -// std::vector<std::future<void>> futures; - -// for (unsigned int bb = 0; bb < nThreads; ++bb) { -// std::vector<std::vector<std::string>> bunch; - -// unsigned int start = nBunches * bb; -// int len = nBunches; -// const unsigned int stop = start + len; -// std::vector<std::vector<std::string>>::const_iterator first = -// m_allchildren.begin() + start; -// std::vector<std::vector<std::string>>::const_iterator last = -// m_allchildren.begin() + stop; -// std::vector<std::vector<std::string>>::const_iterator end = -// m_allchildren.end(); -// if (bb == (nThreads - 1)) { // last bunch -// bunch = std::vector<std::vector<std::string>>(first, end); -// } else { // all bunches but last one -// bunch = std::vector<std::vector<std::string>>(first, last); -// } - -// if (m_loglevel >= 1) { -// muxCout.lock(); -// std::cout << "Thread " << bb + 1 << " - Start: " << start -// << ", len: " << len -// << " ['len=-1' = all remaining items]" << std::endl; -// muxCout.unlock(); -// } - -// if (m_loglevel >= 1) { -// muxCout.lock(); -// std::cout << "'bunch' size: " << bunch.size() << std::endl; -// muxCout.unlock(); -// } - -// futures.push_back(std::async( -// std::launch::async, &ReadGeoModel::loopOverAllChildrenRecords, -// this, bunch)); -// } - -// // wait for all async calls to complete -// // retrieve and print the value stored in the 'std::future' -// if (m_loglevel >= 1) -// std::cout << "Waiting for the threads to finish...\n" << std::flush; -// for (auto& e : futures) { -// e.wait(); -// } -// if (m_loglevel >= 1) std::cout << "Done!\n"; - -// if (m_timing || (m_loglevel >= 1)) { -// // Get End Time -// end = std::chrono::system_clock::now(); -// auto diff = -// std::chrono::duration_cast<std::chrono::seconds>(end - start) -// .count(); -// std::cout << "(Total time taken to recreate all " -// << nChildrenRecords -// << " mother-children relationships: " << diff -// << " seconds)" << std::endl; -// } -// } -// return; -// } void ReadGeoModel::loopOverAllChildrenInBunches_VecVecData() { int nChildrenRecords = m_allchildren.size(); if (m_loglevel >= 1) @@ -2265,135 +2006,6 @@ GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, if (false) { } - // else if (type == "Torus") { - // // Member Data: - // // * Rmax - outside radius of the torus tube - // // * Rmin - inside radius of the torus tube (Rmin=0 if not hollow) - // // * Rtor - radius of the torus itself - // // * - // // * SPhi - starting angle of the segment in radians - // // * DPhi - delta angle of the segment in radians - // // - // // shape parameters - // double Rmin = 0.; - // double Rmax = 0.; - // double Rtor = 0.; - // double SPhi = 0.; - // double DPhi = 0.; - // // get parameters from DB string - // for (auto& par : shapePars) { - // std::vector<std::string> vars = splitString(par, '='); - // std::string varName = vars[0]; - // std::string varValue = vars[1]; - // if (varName == "Rmin") - // Rmin = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - // if (varName == "Rmax") - // Rmax = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - // if (varName == "Rtor") - // Rtor = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - // if (varName == "SPhi") - // SPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - // if (varName == "DPhi") - // DPhi = std::stod(varValue); // * SYSTEM_OF_UNITS::mm; - // } - // shape = new GeoTorus(Rmin, Rmax, Rtor, SPhi, DPhi); - // } - // else if (type == "GenericTrap") { - // // shape parameters - // double ZHalfLength = 0.; - // unsigned int NVertices = 0; - // GeoGenericTrapVertices Vertices; - // bool error = false; - // GeoGenericTrap* gTrap = nullptr; - - // std::string par; - // std::vector<std::string> vars; - // std::string varName; - // std::string varValue; - - // int sizePars = shapePars.size(); - // // check if we have more than 3 parameters - // if (sizePars > 3) { - // // get the two GeoGenericTrap parameters: the ZHalfLength plus the - // // number of vertices - // for (int it = 0; it < 2; it++) { - // par = shapePars[it]; - // vars = splitString(par, '='); - // varName = vars[0]; - // varValue = vars[1]; - // // qInfo() << "vars: " << vars; // for debug only - // if (varName == "ZHalfLength") ZHalfLength = std::stod(varValue); - // if (varName == "NVertices") NVertices = std::stoi(varValue); - // } - - // // and now loop over the rest of the list, to get the parameters of - // // all Z planes - // for (unsigned it = 2; it < NVertices * 2 + 1; it++) { - // par = shapePars[it]; - // vars = splitString(par, '='); - // varName = vars[0]; - // varValue = vars[1]; - - // if (varName == "X") { - // double x = std::stod(varValue); - - // it++; // go to next variable - - // par = shapePars[it]; - // vars = splitString(par, '='); - // varName = vars[0]; - // varValue = vars[1]; - // if (varName == "Y") { - // double y = std::stod(varValue); - // Vertices.push_back(GeoTwoVector(x, y)); - // } else { - // error = 1; - // } - // if (error) { - // muxCout.lock(); - // std::cout << "ERROR! GeoGenericTrap 'X' and 'Y' values " - // "are not at the right place! --> "; - // printStdVectorStrings(shapePars); - // muxCout.unlock(); - // } - // } else { - // error = 1; - // muxCout.lock(); - // std::cout << "ERROR! GeoGenericTrap 'ZPos' value is not at " - // "the right place! --> "; - // printStdVectorStrings(shapePars); - // muxCout.unlock(); - // } - // } - // if (error) { - // muxCout.lock(); - // std::cout << "FATAL ERROR!!! - GeoGenericTrap shape error!!! " - // "Aborting..." - // << std::endl; - // muxCout.unlock(); - // exit(EXIT_FAILURE); - // } - // // build the basic GenericTrap shape - // gTrap = new GeoGenericTrap(ZHalfLength, Vertices); - // } // end if (size>3) - // else { - // muxCout.lock(); - // std::cout << "ERROR!! GeoGenericTrap has no Z vertices!! --> shape " - // "input parameters: "; - // printStdVectorStrings(shapePars); - // muxCout.unlock(); - // error = 1; - // } - // if (error) { - // muxCout.lock(); - // std::cout - // << "FATAL ERROR!!! - GeoGenericTrap shape error!!! Aborting..." - // << std::endl; - // muxCout.unlock(); - // exit(EXIT_FAILURE); - // } - // shape = gTrap; - // } else if (type == "TessellatedSolid") { // Tessellated pars example: // "nFacets=1;TRI;vT=ABSOLUTE;nV=3;xV=0;yV=0;zV=1;xV=0;yV=1;zV=0;xV=1;yV=0;zV=0" @@ -2692,308 +2304,7 @@ GeoShape* ReadGeoModel::buildShape(const unsigned int shapeId, shape = sh; } - // else if (type == "Shift") { - - - // // shape parameters - // unsigned int shapeOpId = 0; - // unsigned int transfId = 0; - // // get parameters - // for (auto& par : shapePars) { - // std::vector<std::string> vars = splitString(par, '='); - // std::string varName = vars[0]; - // std::string varValue = vars[1]; - // if (varName == "A") shapeOpId = std::stoi(varValue); - // if (varName == "X") transfId = std::stoi(varValue); - // } - // if (shapeOpId == 0 || transfId == 0) { - // std::cout << "ERROR! Shift shape - input operand shapes' IDs are " - // "empty! (shapeId: " - // << shapeOpId << ", transfId:" << transfId << ")" - // << std::endl; - // exit(EXIT_FAILURE); - // } - - // // if both operands are built already, - // // then get them from cache, - // // and build the operator shape with them, - // if (isBuiltShape(shapeOpId) && isBuiltTransform(transfId)) { - // const GeoShape* shapeOp = getBuiltShape(shapeOpId); - // const GeoTransform* transf = getBuiltTransform(transfId); - // // TODO: here we create a fake GeoTransform to get a - // // GeoTrf::Transform3D. - // // TODO: ==> Perhaps we could keep a table for bare - // // GeoTrf::Transform3D transforms used in GeoShift nodes. - // GeoTrf::Transform3D transfX = transf->getTransform(); - // transf->unref(); // delete the transf from the heap, because we - // // don't need the node, only the bare - // // transformation matrix - // GeoShapeShift* shapeNew = new GeoShapeShift(shapeOp, transfX); - // storeBuiltShape(shapeId, shapeNew); - // shape = shapeNew; - // } - // // otherwise, build the operands - // else { - // // TODO: IMPORTANT!!! --> check how the transf used in shift are - // // saved into the DB, because they are bare transf and not - // // GeoTransform nodes... - - // // first, check if the transform is built; - // // if so, use that; - // // if not, build the transform - - // // get the referenced Transform, then get the bare transform matrix - // // from it - // GeoTransform* transf = nullptr; - // GeoTrf::Transform3D transfX; - // if (isBuiltTransform(transfId)) { - // transf = getBuiltTransform(transfId); - // } else { - // transf = buildTransform(transfId); - // } - // // TODO: here we create a fake GeoTransform to get a - // // GeoTrf::Transform3D. - // // TODO: ==> Perhaps we could keep a table for bare - // // GeoTrf::Transform3D transforms used in GeoShift nodes. - // transfX = transf->getTransform(); - // transf->unref(); // delete the transf from the heap, because we - // // don't need the node, only the bare - // // transformation matrix - - // // then, check the type of the operand shape - // bool isAOperator = isShapeOperator(shapeOpId); - - // // if operand shape is simple/actual shape (i.e., not - // // boolean/operator), then build it, then build the boolean shape - // // with that - // if (!isAOperator) { - // const GeoShape* shapeOp = - // buildShape(shapeOpId, shapes_info_sub); - - // if (shapeOp == nullptr || transf == nullptr) { - // std::cout << "ERROR!!! Shift - shapeOp or transfX are " - // "NULL! Exiting..." - // << std::endl; - // exit(EXIT_FAILURE); - // } - // GeoShapeShift* shapeNew = new GeoShapeShift(shapeOp, transfX); - // shape = shapeNew; - // } - // // ...otherwise, build the Shift operator shape without operands - // // and save the needed pieces of information to build the actual - // // operands and shape later. - // else { - // GeoShapeShift* shapeNew = new GeoShapeShift(); - // tuple_shapes_boolean_info tt(shapeId, shapeNew, shapeOpId, - // transfId); - // shapes_info_sub->push_back( - // tt); //! Push the information about the new boolean shape - // //! at the end of the very same container we are - // //! iterating over - // shape = shapeNew; - // } - // } - // } - // else if (type == "Subtraction" || type == "Union" || - // type == "Intersection") { - // // Check what shapes are subtracted/united/intersected: - // // - If they are actual shapes, build them and return - // // - If they are boolean/operator shapes, then store the shape for later - // // and continue - - // // shape's operands - // unsigned int opA = 0; - // unsigned int opB = 0; - // // get parameters - // for (auto& par : shapePars) { - // std::vector<std::string> vars = splitString(par, '='); - // std::string varName = vars[0]; - // std::string varValue = vars[1]; - // if (varName == "opA") opA = std::stoi(varValue); - // if (varName == "opB") opB = std::stoi(varValue); - // } - // if (opA == 0 || opB == 0) { - // std::cout << "ERROR! Subtraction/Union/Intersection shape - input " - // "operand shapes' IDs are empty! (opA: " - // << opA << ", opB:" << opB << ")" << std::endl; - // exit(EXIT_FAILURE); - // } - - // // if both operands are built already, - // // then get them from cache, - // // and build the operator with them - // if (isBuiltShape(opA) && isBuiltShape(opB)) { - // // std::cout << "both operand shapes are built, build the operator - // // shape..." << std::endl; - // GeoShape* shapeNew = nullptr; - // const GeoShape* shapeA = getBuiltShape(opA); - // const GeoShape* shapeB = getBuiltShape(opB); - // if ("Subtraction" == type) { - // shapeNew = new GeoShapeSubtraction(shapeA, shapeB); - // } else if ("Union" == type) { - // shapeNew = new GeoShapeUnion(shapeA, shapeB); - // } else if ("Intersection" == type) { - // shapeNew = new GeoShapeIntersection(shapeA, shapeB); - // } - // shape = shapeNew; - // } - // // otherwise, build the operand shapes... - // else { - // // first check the operands' type - // bool isAOperator = isShapeOperator(opA); - // bool isBOperator = isShapeOperator(opB); - - // // if both are simple/actual shapes (i.e., not booleans), - // // build them, then build the boolean shape with them, and - // // store that. - // if (!isAOperator && !isBOperator) { - // const GeoShape* shapeA = buildShape(opA, shapes_info_sub); - // const GeoShape* shapeB = buildShape(opB, shapes_info_sub); - // if (shapeA == NULL || shapeB == NULL) { - // std::cout << "ERROR!!! shapeA or shapeB are NULL!" - // << std::endl; - // exit(EXIT_FAILURE); - // } - - // GeoShape* shapeNew = nullptr; - // if ("Subtraction" == type) { - // shapeNew = new GeoShapeSubtraction(shapeA, shapeB); - // } else if ("Union" == type) { - // shapeNew = new GeoShapeUnion(shapeA, shapeB); - // } else if ("Intersection" == type) { - // shapeNew = new GeoShapeIntersection(shapeA, shapeB); - // } - - // shape = shapeNew; - // } - // // ...otherwise, build the Subtraction operator shape without - // // operands and save the needed pieces of information to build the - // // actual operands and shape later. - // else { - // GeoShape* shapeNew = nullptr; - // if ("Subtraction" == type) { - // shapeNew = new GeoShapeSubtraction; - // } else if ("Union" == type) { - // shapeNew = new GeoShapeUnion; - // } else if ("Intersection" == type) { - // shapeNew = new GeoShapeIntersection; - // } - - // tuple_shapes_boolean_info tt(shapeId, shapeNew, opA, opB); - // shapes_info_sub->push_back( - // tt); //! Push the information about the new boolean shape - // //! at the end of the very same container we are - // //! iterating over - - // shape = shapeNew; - // } - // } - // } - // LAr custom shape - /* - else if (type == "CustomShape") { - std::string name = ""; - // check parameters - // this complex test is needed to handle null strings in the DB records - bool okPars = false; - for (auto& par : shapePars) { - std::string str = - par.substr(par.find("=")); // get from "=" to the end - if (str.size() > 0) okPars = true; - } - // if ( shapePars.size() > 0 && ((shapePars.filter("=")).size() > 0) ) - // // this complex test is needed to handle null strings - if (shapePars.size() > 0 && okPars) { - // get parameters - for (auto& par : shapePars) { - std::vector<std::string> vars = splitString(par, '='); - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "name") name = varValue; - } - } else { - muxCout.lock(); - // throw std::invalid_argument("CustomShape parameters' list is - // empty!!"); - std::cout - << "ERROR!!! --> CustomShape parameters' list is empty!! It " - "seems the geometry file you are running on is corrupted." - << std::endl; - muxCout.unlock(); - exit(EXIT_FAILURE); - } - shape = new GeoUnidentifiedShape("LArCustomShape", name); - } - else if (type == "UnidentifiedShape") { - std::string name = ""; - std::string asciiData = ""; - - // debug - muxCout.lock(); - if (m_loglevel >= 2) - std::cout - << "GeoModelRead - loading 'UnidentifiedShape' - parameters: " - << parameters << std::endl; - muxCout.unlock(); - - // check parameters - // this complex test is needed to handle null strings in the DB records - bool okPars = false; - for (auto& par : shapePars) { - std::string str = - par.substr(par.find("=")); // get from "=" to the end - if (str.size() > 0) okPars = true; - } - if (shapePars.size() > 0 && okPars) { - // get parameters - for (auto& par : shapePars) { - // debug - muxCout.lock(); - if (m_loglevel >= 2) - std::cout - << "GeoModelRead - loading 'UnidentifiedShape' - par: " - << par << std::endl; - muxCout.unlock(); - - std::vector<std::string> vars = splitString(par, '='); - if (vars.size() > 1) { - std::string varName = vars[0]; - std::string varValue = vars[1]; - if (varName == "name") name = varValue; - if (varName == "asciiData") asciiData = varValue; - } else { - okPars = false; - } - } - } else { - okPars = false; - } - if (!okPars) { - // throw std::invalid_argument("UnidentifiedShape parameters' list - // is empty!!"); - muxCout.lock(); - std::cout << "\n\n\tERROR!!! --> UnidentifiedShape is not properly " - "defined!! It seems the geometry file you are running " - "on is corrupted." - << std::endl; - std::cout - << "\tINFO --> UnidentifiedShape should be defined from two " - "strings: a string defining its type/name; and a ASCII data " - "string defining its parameters. The latter can be set to " - "an empty string if not used/needed." - << std::endl; - std::cout << "\tINFO --> UnidentifiedShape parameters' list is " - "empty or one datum is missing!! --> parameters: " - << parameters << std::endl; - std::cout << "\tINFO --> parameters: " << parameters << std::endl - << std::endl; - muxCout.unlock(); - std::runtime_error( - "UnidentifiedShape parameters' list are empty or incomplete!!"); - } - shape = new GeoUnidentifiedShape(name, asciiData); - - }*/ + else { m_unknown_shapes.insert( type); // save unknwon shapes for later warning message diff --git a/GeoModelIO/GeoModelWrite/CMakeLists.txt b/GeoModelIO/GeoModelWrite/CMakeLists.txt index 9ac2827fc..cfc7e08da 100644 --- a/GeoModelIO/GeoModelWrite/CMakeLists.txt +++ b/GeoModelIO/GeoModelWrite/CMakeLists.txt @@ -7,7 +7,7 @@ file( GLOB HEADERS GeoModelWrite/*.h ) # Set up the library. add_library( GeoModelWrite SHARED ${HEADERS} ${SOURCES} ) target_link_libraries( GeoModelWrite PUBLIC - GeoModelKernel GeoModelDBManager TFPersistification GeoModelCppHelpers GeoModelHelpers) + GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers) target_include_directories( GeoModelWrite PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) diff --git a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp index b6d33c58c..0354bb402 100644 --- a/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp +++ b/GeoModelIO/GeoModelWrite/src/WriteGeoModel.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // author: Riccardo.Maria.Bianchi@cern.ch, 2017 @@ -21,6 +21,8 @@ // - Nov 2023 - R.M.Bianchi <riccardo.maria.bianchi@cern.ch> // Updated to use the AlignableTransform 'default position', // which does not include alignment constants +// - May 2024 - Major change: we move to the new DB schema that uses numerical data +// instead of strings/TEXT // // local includes @@ -171,9 +173,6 @@ void WriteGeoModel::handleVPhysVolObjects(const GeoVPhysVol* vol) { // when visiting a VPhysVol node else upperVol = path->getItem(len - 1); // ROOT volume - // JFB Commented out: qDebug() << "path: " << path << " - length: " << len - // << " - upper vol: " << upperVol << " - tail vol: " << tailVol << " - head - // vol: " << headVol; std::cout << "path: " << path << std::endl; // this below is performed until the root volume is found, then "length" is // not used anymore, because not updated when recursively visiting children @@ -1266,186 +1265,6 @@ std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { std::vector<std::string> pars; if (false) {} - // if (shapeType == "Box") { - // const GeoBox* box = dynamic_cast<const GeoBox*>(shape); - // pars.push_back("XHalfLength=" + - // GeoStrUtils::to_string_with_precision(box->getXHalfLength())); - // pars.push_back("YHalfLength=" + - // GeoStrUtils::to_string_with_precision(box->getYHalfLength())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(box->getZHalfLength())); - // } - // else if (shapeType == "Cons") { - // const GeoCons* shapeIn = dynamic_cast<const GeoCons*>(shape); - // pars.push_back("RMin1=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMin1())); - // pars.push_back("RMin2=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMin2())); - // pars.push_back("RMax1=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMax1())); - // pars.push_back("RMax2=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMax2())); - // pars.push_back("DZ=" + GeoStrUtils::to_string_with_precision(shapeIn->getDZ())); - // pars.push_back("SPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getSPhi())); - // pars.push_back("DPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getDPhi())); - // } - // else if (shapeType == "Torus") { - // // Member Data: - // // * Rmax - outside radius of the torus tube - // // * Rmin - inside radius of the torus tube (Rmin=0 if not hollow) - // // * Rtor - radius of the torus itself - // // * - // // * SPhi - starting angle of the segment in radians - // // * DPhi - delta angle of the segment in radians - // // - // const GeoTorus* shapeIn = dynamic_cast<const GeoTorus*>(shape); - // pars.push_back("Rmin=" + GeoStrUtils::to_string_with_precision(shapeIn->getRMin())); - // pars.push_back("Rmax=" + GeoStrUtils::to_string_with_precision(shapeIn->getRMax())); - // pars.push_back("Rtor=" + GeoStrUtils::to_string_with_precision(shapeIn->getRTor())); - // pars.push_back("SPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getSPhi())); - // pars.push_back("DPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getDPhi())); - // } - // else if (shapeType == "Para") { - // const GeoPara* shapeIn = dynamic_cast<const GeoPara*>(shape); - // pars.push_back("XHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getXHalfLength())); - // pars.push_back("YHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getYHalfLength())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - // pars.push_back("Alpha=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getAlpha())); - // pars.push_back("Theta=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getTheta())); - // pars.push_back("Phi=" + GeoStrUtils::to_string_with_precision(shapeIn->getPhi())); - // } - // else if (shapeType == "Pcon") { - // const GeoPcon* shapeIn = dynamic_cast<const GeoPcon*>(shape); - // pars.push_back("SPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getSPhi())); - // pars.push_back("DPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getDPhi())); - // // get number of Z planes and loop over them - // const int nZplanes = shapeIn->getNPlanes(); - // pars.push_back("NZPlanes=" + std::to_string(nZplanes)); // INT - // for (int i = 0; i < nZplanes; ++i) { - // pars.push_back("ZPos=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZPlane(i))); - // pars.push_back("ZRmin=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMinPlane(i))); - // pars.push_back("ZRmax=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMaxPlane(i))); - // } - // } - // else if (shapeType == "Pgon") { - // const GeoPgon* shapeIn = dynamic_cast<const GeoPgon*>(shape); - // pars.push_back("SPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getSPhi())); - // pars.push_back("DPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getDPhi())); - // pars.push_back("NSides=" + - // std::to_string(shapeIn->getNSides())); // INT - // // get number of Z planes and loop over them - // const int nZplanes = shapeIn->getNPlanes(); - // pars.push_back("NZPlanes=" + std::to_string(nZplanes)); // INT - // for (int i = 0; i < nZplanes; ++i) { - // pars.push_back("ZPos=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZPlane(i))); - // pars.push_back("ZRmin=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMinPlane(i))); - // pars.push_back("ZRmax=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getRMaxPlane(i))); - // } - // } - // else if (shapeType == "SimplePolygonBrep") { - // const GeoSimplePolygonBrep* shapeIn = - // dynamic_cast<const GeoSimplePolygonBrep*>(shape); - // pars.push_back("DZ=" + GeoStrUtils::to_string_with_precision(shapeIn->getDZ())); - // // get number of vertices and loop over them - // const int nVertices = shapeIn->getNVertices(); - // pars.push_back("NVertices=" + std::to_string(nVertices)); // INT - // for (int i = 0; i < nVertices; ++i) { - // pars.push_back("xV=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getXVertex(i))); - // pars.push_back("yV=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getYVertex(i))); - // } - // } - // else if (shapeType == "Trap") { - // const GeoTrap* shapeIn = dynamic_cast<const GeoTrap*>(shape); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - // pars.push_back("Theta=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getTheta())); - // pars.push_back("Phi=" + GeoStrUtils::to_string_with_precision(shapeIn->getPhi())); - // pars.push_back("Dydzn=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDydzn())); - // pars.push_back("Dxdyndzn=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDxdyndzn())); - // pars.push_back("Dxdypdzn=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDxdypdzn())); - // pars.push_back("Angleydzn=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getAngleydzn())); - // pars.push_back("Dydzp=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDydzp())); - // pars.push_back("Dxdyndzp=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDxdyndzp())); - // pars.push_back("Dxdypdzp=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getDxdypdzp())); - // pars.push_back("Angleydzp=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getAngleydzp())); - // } - // else if (shapeType == "TwistedTrap") { - // const GeoTwistedTrap* shapeIn = - // dynamic_cast<const GeoTwistedTrap*>(shape); - // pars.push_back("PhiTwist=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getPhiTwist())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - // pars.push_back("Theta=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getTheta())); - // pars.push_back("Phi=" + GeoStrUtils::to_string_with_precision(shapeIn->getPhi())); - // pars.push_back("DY1HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getY1HalfLength())); - // pars.push_back("DX1HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getX1HalfLength())); - // pars.push_back("DX2HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getX2HalfLength())); - // pars.push_back("DY2HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getY2HalfLength())); - // pars.push_back("DX3HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getX3HalfLength())); - // pars.push_back("DX4HalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getX4HalfLength())); - // pars.push_back("DTiltAngleAlpha=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getTiltAngleAlpha())); - - // } - // else if (shapeType == "Trd") { - // const GeoTrd* shapeIn = dynamic_cast<const GeoTrd*>(shape); - // pars.push_back("XHalfLength1=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getXHalfLength1())); - // pars.push_back("XHalfLength2=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getXHalfLength2())); - // pars.push_back("YHalfLength1=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getYHalfLength1())); - // pars.push_back("YHalfLength2=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getYHalfLength2())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - // } - // else if (shapeType == "Tube") { - // const GeoTube* tube = dynamic_cast<const GeoTube*>(shape); - // pars.push_back("RMin=" + GeoStrUtils::to_string_with_precision(tube->getRMin())); - // pars.push_back("RMax=" + GeoStrUtils::to_string_with_precision(tube->getRMax())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(tube->getZHalfLength())); - // } - // else if (shapeType == "Tubs") { - // const GeoTubs* shapeIn = dynamic_cast<const GeoTubs*>(shape); - // pars.push_back("RMin=" + GeoStrUtils::to_string_with_precision(shapeIn->getRMin())); - // pars.push_back("RMax=" + GeoStrUtils::to_string_with_precision(shapeIn->getRMax())); - // pars.push_back("ZHalfLength=" + - // GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - // pars.push_back("SPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getSPhi())); - // pars.push_back("DPhi=" + GeoStrUtils::to_string_with_precision(shapeIn->getDPhi())); - // } else if (shapeType == "TessellatedSolid") { const GeoTessellatedSolid* shapeIn = dynamic_cast<const GeoTessellatedSolid*>(shape); @@ -1481,90 +1300,6 @@ std::string WriteGeoModel::getShapeParameters(const GeoShape* shape) { } } } - // else if (shapeType == "Intersection") { - // const GeoShapeIntersection* shapeIn = - // dynamic_cast<const GeoShapeIntersection*>(shape); - // // get the referenced Shape used in the 'union' operation, store it in - // // the DB - // const GeoShape* shapeOpA = shapeIn->getOpA(); - // const unsigned int shapeIdA = storeShape(shapeOpA); - // const GeoShape* shapeOpB = shapeIn->getOpB(); - // const unsigned int shapeIdB = storeShape(shapeOpB); - // pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - // pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - // } - // else if (shapeType == "Shift") { - // const GeoShapeShift* shapeIn = - // dynamic_cast<const GeoShapeShift*>(shape); - - // // get the referenced Shape used in the 'shift' operation, store it in - // // the DB - // const GeoShape* shapeOp = shapeIn->getOp(); - // const unsigned int shapeId = storeShape(shapeOp).second; - - // // get the Transformation, store it in the DB - // GeoTransform* transf = new GeoTransform(shapeIn->getX()); - // const unsigned int trId = storeTranform(transf); - - // pars.push_back("A=" + std::to_string(shapeId)); // INT - // pars.push_back("X=" + std::to_string(trId)); // INT - // } - // else if (shapeType == "Subtraction") { - // const GeoShapeSubtraction* shapeIn = - // dynamic_cast<const GeoShapeSubtraction*>(shape); - // // get the referenced Shape used in the 'union' operation, store it in - // // the DB - // const GeoShape* shapeOpA = shapeIn->getOpA(); - // const unsigned int shapeIdA = storeShape(shapeOpA).second; - // const GeoShape* shapeOpB = shapeIn->getOpB(); - // const unsigned int shapeIdB = storeShape(shapeOpB).second; - // pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - // pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - // } - // else if (shapeType == "Union") { - // const GeoShapeUnion* shapeIn = - // dynamic_cast<const GeoShapeUnion*>(shape); - - // // get the referenced Shape used in the 'union' operation, store it in - // // the DB - // const GeoShape* shapeOpA = shapeIn->getOpA(); - // unsigned int shapeIdA = storeShape(shapeOpA).second; - // const GeoShape* shapeOpB = shapeIn->getOpB(); - // unsigned int shapeIdB = storeShape(shapeOpB).second; - - // pars.push_back("opA=" + std::to_string(shapeIdA)); // INT - // pars.push_back("opB=" + std::to_string(shapeIdB)); // INT - // } - else if (shapeType == "GenericTrap") { - const GeoGenericTrap* shapeIn = - dynamic_cast<const GeoGenericTrap*>(shape); - pars.push_back("ZHalfLength=" + - GeoStrUtils::to_string_with_precision(shapeIn->getZHalfLength())); - pars.push_back("NVertices=" + - GeoStrUtils::to_string_with_precision(shapeIn->getVertices().size())); - for (unsigned long i = 0; i < shapeIn->getVertices().size(); ++i) { - pars.push_back( - "X=" + GeoStrUtils::to_string_with_precision(shapeIn->getVertices()[i](0))); - pars.push_back( - "Y=" + GeoStrUtils::to_string_with_precision(shapeIn->getVertices()[i](1))); - } - } - // else if (shapeType == "UnidentifiedShape") { - // const GeoUnidentifiedShape* shapeIn = - // dynamic_cast<const GeoUnidentifiedShape*>(shape); - // pars.push_back("name=" + shapeIn->name()); - // pars.push_back("asciiData=" + shapeIn->asciiData()); - // } - // LAr custom shape - // else if(shapeType == "CustomShape") { - // std::cout << "\n\tWARNING!!! - Use of LArCustomShape is deprecated, - // translating to GeoUnidentifiedShape representation!!\n\n"; const - // LArCustomShape* shapeIn = dynamic_cast<const LArCustomShape*> (shape); - // QStringList pars; - // pars << "name=LArCustomShape"; - // pars << "asciiData="+QString::fromStdString(shapeIn->name()); - // shapePars=pars.join(";"); - // } else { std::string errMsg = "GeoModelWrite -- ERROR!!! - Shape '" + shapeType + "' needs to be persistified!!"; @@ -2150,282 +1885,6 @@ unsigned int WriteGeoModel::addSerialIdentifier(const int& baseId) { std::vector<std::string> values; values.push_back(std::to_string(baseId)); return addRecord(container, values); - -/* -} - -unsigned int WriteGeoModel::addIdentifierTag(const int& identifier) { - std::vector<std::vector<std::string>>* container = &m_identifierTags; - std::vector<std::string> values; - values.push_back(std::to_string(identifier)); - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addFunction(const std::string& expression) { - std::vector<std::vector<std::string>>* container = &m_functions; - std::vector<std::string> values; - values.push_back(expression); - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addAlignableTransform( - const std::vector<double>& params) { - std::vector<std::vector<std::string>>* container = &m_alignableTransforms; - std::vector<std::string> values; - for (const double& par : params) { - values.push_back(GeoStrUtils::to_string_with_precision(par)); - } - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addTransform(const std::vector<double>& params) { - std::vector<std::vector<std::string>>* container = &m_transforms; - std::vector<std::string> values; - for (const double& par : params) { - values.push_back(GeoStrUtils::to_string_with_precision(par)); - } - return addRecord(container, values); -} - -unsigned int WriteGeoModel::getIdFromNodeType(const std::string& nodeType) { - std::unordered_map<std::string, unsigned int>::iterator it = - m_memMap_Tables.find(nodeType); - if (it != m_memMap_Tables.end()) { // item found - return m_memMap_Tables.at(nodeType); - } - return 0; // item not found -} - -unsigned int WriteGeoModel::addSerialTransformer(const unsigned int& funcId, - const unsigned int& physvolId, - const std::string volType, - const unsigned int& copies) { - std::vector<std::vector<std::string>>* container = &m_serialTransformers; - const unsigned int volTypeID = getIdFromNodeType(volType); - - std::vector<std::string> values; - values.insert(values.begin(), - {std::to_string(funcId), std::to_string(physvolId), - std::to_string(volTypeID), std::to_string(copies)}); // INT - - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addShape(const std::string& type, - const std::string& parameters) { - std::vector<std::vector<std::string>>* container = &m_shapes; - std::vector<std::string> values; - values.push_back(type); - values.push_back(parameters); - return addRecord(container, values); -} - -unsigned int WriteGeoModel::addPhysVol(const unsigned int& logVolId, - const unsigned int& //parentPhysVolId - , - const bool& isRootVolume) { - std::vector<std::vector<std::string>>* container = &m_physVols; - std::vector<std::string> values; - values.push_back(std::to_string(logVolId)); // INT - unsigned int idx = addRecord(container, values); - - if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoPhysVol"}); // INT - m_rootVolume = rootValues; - } - - return idx; -} - -unsigned int WriteGeoModel::addFullPhysVol( - const unsigned int& logVolId, const unsigned int& //parentPhysVolId// -, - const bool& isRootVolume) { - std::vector<std::vector<std::string>>* container = &m_fullPhysVols; - std::vector<std::string> values; - values.push_back(std::to_string(logVolId)); // INT - unsigned int idx = addRecord(container, values); - - if (isRootVolume) { - std::vector<std::string> rootValues; - rootValues.insert(rootValues.begin(), - {std::to_string(idx), "GeoFullPhysVol"}); // INT - m_rootVolume = rootValues; - } - - return idx; -} - -unsigned int WriteGeoModel::addLogVol(const std::string& name, - const unsigned int& shapeId, - const unsigned int& materialId) { - std::vector<std::vector<std::string>>* container = &m_logVols; - std::vector<std::string> values; - values.insert(values.begin(), {name, std::to_string(shapeId), - std::to_string(materialId)}); // INT - return addRecord(container, values); -} - -void WriteGeoModel::addChildPosition(const unsigned int& parentId, - const std::string& parentType, - const unsigned int& childId, - const unsigned int& parentCopyN, - const unsigned int& childPos, - const std::string& childType, - const unsigned int& childCopyN) { - std::vector<std::vector<std::string>>* container = &m_childrenPositions; - const unsigned int parentTableID = getIdFromNodeType(parentType); - const unsigned int childTableID = getIdFromNodeType(childType); - - std::vector<std::string> values; - // values << parentId.toString() << parentTableID << - // QString::number(parentCopyN) << QString::number(childPos) << - // childTableID << childId.toString() << QString::number(childCopyN); - values.insert(values.begin(), - {std::to_string(parentId), std::to_string(parentTableID), - std::to_string(parentCopyN), std::to_string(childPos), - std::to_string(childTableID), std::to_string(childId), - std::to_string(childCopyN)}); // INT - addRecord(container, values); - return; -} - -// -// The 'publisher' parameter is optional, by default it is set to 'nullptr' in -// the header. -void WriteGeoModel::saveToDB(GeoPublisher* publisher) { - if (!m_inspect) { - std::vector<GeoPublisher*> vec; - if (publisher) vec.push_back(publisher); - saveToDB(vec); - } else { - std::cerr - << "\n\nWARNING! You called the 'saveToDB' method, but " - "WriteGeoModel has been constructed by calling the 'inspect' " - "contructor! Use the 'db' constructor, instead.\n\n" - << std::endl; - exit(EXIT_FAILURE); - } -} -// -// Note: The vector of GeoPublishers is completely optional, it is empty by -// default and not handled. -void WriteGeoModel::saveToDB(std::vector<GeoPublisher*>& publishers) { - if (!m_inspect) { - std::cout << "Saving the GeoModel tree to file: '" << m_dbpath << "'" - << std::endl; - - m_dbManager->addListOfRecords("GeoMaterial", m_materials); - m_dbManager->addListOfRecords("GeoElement", m_elements); - m_dbManager->addListOfRecords("GeoNameTag", m_nameTags); - m_dbManager->addListOfRecords("GeoAlignableTransform", - m_alignableTransforms); - m_dbManager->addListOfRecords("GeoTransform", m_transforms); - m_dbManager->addListOfRecords("Function", m_functions); - m_dbManager->addListOfRecords("GeoSerialTransformer", - m_serialTransformers); - m_dbManager->addListOfRecords("GeoShape", m_shapes); - m_dbManager->addListOfRecords("GeoSerialDenominator", - m_serialDenominators); - m_dbManager->addListOfRecords("GeoSerialIdentifier", - m_serialIdentifiers); - m_dbManager->addListOfRecords("GeoIdentifierTag", m_identifierTags); - m_dbManager->addListOfRecords("GeoPhysVol", m_physVols); - m_dbManager->addListOfRecords("GeoFullPhysVol", m_fullPhysVols); - m_dbManager->addListOfRecords("GeoLogVol", m_logVols); - - m_dbManager->addListOfChildrenPositions(m_childrenPositions); - m_dbManager->addRootVolume(m_rootVolume); - - // save data stored in instances of GeoPublisher - if (publishers.size()) { - std::cout - << "\nINFO: A pointer to a GeoPublisher instance has been " - "provided, " - << "so we dump the published list of FullPhysVol and " - "AlignableTransforms nodes and auxiliary data, if any.\n" - << std::endl; - for (GeoPublisher* publisher : publishers) { - storePublishedNodes(publisher); - storePublishedAuxiliaryData(publisher); - } - } - - // save auxiliary data stored through WriteGeoModel directly - //if ( m_auxiliaryTablesStr.size() ) { - // std::cout << "\nINFO: Custom tables to store auxiliary data - //have been added, " - // << "so we create these custom tables in the DB:" - // << std::endl; - // for ( auto& tableData : m_auxiliaryTablesStr ) { - // std::cout << "\tsaving table: " << tableData.first << std::endl; - // m_dbManager->createCustomTable( tableData.first, - //(tableData.second).first, (tableData.second).second, - //m_auxiliaryTablesStrData[ tableData.first ] ); - // } - //} - if (m_auxiliaryTablesVar.size()) { - if (m_loglevel > 0) { - std::cout - << "\nINFO: Custom tables to store auxiliary data have " - "been added, " - << "so we create these custom tables in the DB:" - << std::endl; - } - for (auto& tableData : m_auxiliaryTablesVar) { - if (m_loglevel > 0) { - std::cout << "\nsaving table: " << tableData.first - << std::endl; - } - m_dbManager->createCustomTable( - tableData.first, (tableData.second).first, - (tableData.second).second, - m_auxiliaryTablesVarData[tableData.first]); - } - } - - if (!m_objectsNotPersistified.empty()) { - std::cout - << "\n\tGeoModelWrite -- WARNING!! There are shapes/nodes " - "which need to be persistified! --> "; - printStdVectorStrings(m_objectsNotPersistified); - std::cout << "\n\n"; - } - - return; - - } else { - std::cerr - << "\n\nWARNING! You called the 'saveToDB' method, but " - "WriteGeoModel has been constructed by calling the 'inspect' " - "contructor! Use the 'db' constructor, instead.\n\n" - << std::endl; - exit(EXIT_FAILURE); - } -} - -void WriteGeoModel::storePublishedAuxiliaryData(GeoPublisher* publisher) { - AuxTableDefs tableDefs = publisher->getPublishedAuxData().first; - AuxTableData tableAuxData = publisher->getPublishedAuxData().second; - if (tableDefs.size()) { - std::cout << "\nINFO: Custom tables to store auxiliary data have been " - "added to an instance of GeoPublisher, " - << "so we create these custom tables in the DB:" << std::endl; - for (auto& tableData : tableDefs) { - if (m_loglevel > 0) { - std::cout << "\nsaving table: " << tableData.first << std::endl; - } - m_dbManager->createCustomTable( - tableData.first, (tableData.second).first, - (tableData.second).second, tableAuxData[tableData.first]); - } - } -} - -======= -*/ } unsigned int WriteGeoModel::addIdentifierTag(const int& identifier) { @@ -2912,16 +2371,6 @@ void WriteGeoModel::storeRecordPublishedNodes( } } -/* -void WriteGeoModel::storeDataTable( std::string tableName, -std::vector<std::string> colNames, std::vector<std::string> colTypes, -std::vector<std::vector<std::string>> tableData ) -{ - m_auxiliaryTablesStr[ tableName ] = std::make_pair(colNames, colTypes); - m_auxiliaryTablesStrData[ tableName ] = tableData; -} -*/ - void WriteGeoModel::storeDataTable( std::string tableName, std::vector<std::string> colNames, std::vector<std::string> colTypes, -- GitLab