diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8492617e314c9e914318e4ea678817fab46d6ac..0b5085c54eaea7cef1cf86b86cfd94eb5c342c97 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -332,7 +332,7 @@ ubu-gm-fullsimlight-customxercesc-builtinjson: XERCESC_VERSION: 3.2.3 CMAKE_ARGS: ${CMAKE_BASE_ARGS} CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_FULLSIMLIGHT=TRUE - CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DXercesC_INCLUDE_DIR=./install/xerces-c-${XERCESC_VERSION}/include -DXercesC_LIBRARY=./install/xerces-c-${XERCESC_VERSION}/lib/libxerces-c.dylib + CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DXercesC_INCLUDE_DIR=../install/xerces-c-${XERCESC_VERSION}/include -DXercesC_LIBRARY=../install/xerces-c-${XERCESC_VERSION}/lib/libxerces-c.dylib allow_failure: true diff --git a/FullSimLight/CMakeLists.txt b/FullSimLight/CMakeLists.txt index ac33977af2a5fca2560f1e6b366ebc65a6f7a560..653a43da17f95762c78f98b9c9502a7172177e7a 100644 --- a/FullSimLight/CMakeLists.txt +++ b/FullSimLight/CMakeLists.txt @@ -19,8 +19,12 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) "Framework finding behaviour on macOS" ) # Set up how the project handle some of its dependenices. Either by picking them # up from the environment, or building them itself. - include( SetupJSON ) - include( SetupXercesC ) + if( NOT TARGET JSONExt ) + include( SetupJSON ) + endif() + if( NOT TARGET XercesCBuiltIn ) + include( SetupXercesC ) + endif() # Find the base GeoModel packages, which must be installed on the target system already find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder find_package( GeoModelIO REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder @@ -180,6 +184,7 @@ endif() set(FULLSIMLIGHT_SCRIPTS geantino.g4 macro.g4 + pythia.g4 drawMagField.C ) diff --git a/FullSimLight/README.md b/FullSimLight/README.md index bb8c93853ede1df1b5865c099e5ee8535ff5169f..d95dd5a585e56d9001b45f8102e14a88a3b8d8b4 100644 --- a/FullSimLight/README.md +++ b/FullSimLight/README.md @@ -94,7 +94,7 @@ Clone the new GeoModel monorepository at [GeoModel repo](https://gitlab.cern.ch/ git clone https://gitlab.cern.ch/GeoModelDev/GeoModel.git cd GeoModel mkdir build ; cd build -cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Release ../ -DGEOMODEL_BUILD_FULLSIMLIGHT=TRUE -DGEOMODEL_BUILD_GEOMODELG4=TRUE ../ +cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Release ../ -DGEOMODEL_BUILD_FULLSIMLIGHT=1 ../ make -j8 ; make install ``` @@ -115,6 +115,14 @@ Alternatively, you can source the Geant4 setup, before running cmake: source <path_to_geant4_install_dir>/bin/geant4.sh cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Release ../ ``` + +### How to use a custom version of Xerces-C + +The Geant4 GDML format depends on the Xerces-C library. Therefore, different Geant4 releases can use different versions of the Xerces-C library. If you want to build FullSimLight with a custom, locally installed Xerces-C library, you can pass the XercesC_INCLUDE_DIR and XercesC_LIBRARY variable to CMake while configuring the build of FullSimLight: + +```bash +cmake -DGEOMODEL_BUILD_FULLSIMLIGHT=1 -DXercesC_INCLUDE_DIR=<path-to-local-XercesC-installation>/include -DXercesC_LIBRARY=<path-to-local-XercesC-installation>/lib/libxerces-c.dylib ../../install +``` # Detector Construction @@ -171,12 +179,16 @@ export G4ENSDFSTATEDATA=$G4INSTALL/data/G4ENSDFSTATE2.2 Run the executable with the --help option to see the available options: ``` bash --m <Geant4-Macro-File> [MANDATORY; a standard Geant4 macro file name] --g <Geometry-File-Name> [MANDATORY; the Geometry file name] --f <Physics-List-Name> [OPTIONAL; physics list name (default: FTFP_BERT)] --p <NO-ARGUMENT> [OPTIONAL; run in performance mode (default: false)] --o : <NO-ARGUMENT> [OPTIONAL; run the geometry overlap check (default: false)] +-m : REQUIRED : the standard Geant4 macro file name +-g : REQUIRED : the Geometry file name +-o : flag ==> run the geometry overlap check (default: FALSE) +-f : physics list name (default: FTFP_BERT) +-P : generate events with Pythia [config. available: ttbar/higgs/minbias or use ascii input file] +-p : flag ==> run the application in performance mode i.e. no user actions + : - ==> run the application in NON performance mode i.e. with user actions (default) ``` +FullSimLight uses by default the Geant4 particle gun as primary generator, but it supports also +input events from the Pythia generator (see the Primary generator section for more details) A minimal set of "observable" is collected during the simulation per-primary particle type: mean energy deposit, mean charged and neutral step lengths, mean number of steps made by charged and neutral particles, mean number of @@ -262,7 +274,10 @@ Use the -t to set the Toroids off, and test the solenoid_bfieldmap_7730_0_14m_ve ## Primary Generator - The primary generator is a particle gun that will generate primary particles +The primary generator used by default is the Geant4 particle gun, but FullSimLight also supports the [Pythia generator](http://home.thep.lu.se/Pythia/) + + ## Particle gun + The particle gun used by default will generate primary particles at the (0,0,0) position with the following options: ### Number of primaries per event: @@ -299,6 +314,19 @@ The primary particle type can be set through the macro command: ``` By default, i.e. if it is not specified by the above command, the type will be randomly selected from a pre-defined list for each individual primary particle uniformly. The current list of particles includes e-, e+ and gamma particles. It can be extended by adding more particles to the list in the MyPrimaryGeneratorAction class. + ## Pythia generator + + FullSimLight supports Pythia as primary particles generator. In order to use Pythia, the user should have it installed in their system and if Pythia is found FullSImLight will be compiled with the support on. There are three different default options available when using the -P or --pythia flag (i.e. ttbar, higgs and minbias): + ``` bash + -P : generate events with Pythia [config. available: ttbar/higgs/minbias or use ascii input file] + ``` + Alternatively the user can plug their own Pythia configuration file to simulate the desired events. + For example, in order to simulate the default *ttbar* events, the command to be run is the following: + + ``` bash +./fullSimLight -m ../share/FullSimLight/pythia.g4 -P ttbar -g geometry-ATLAS-R2-2016-01-00-01_wSPECIALSHAPE.db + ``` + The number of events that the user wants to simulate must be specified in the g4 macro file. A specific *pythia.g4* macro file can be found in the *share* directory, that should be used when simulating Pythia events and can be edited according to the user needs. ## Physics List diff --git a/FullSimLight/fullSimLight.cc b/FullSimLight/fullSimLight.cc index 668c229eb0c6592c72cec6955b30364fe4f9819b..ae22f2545b92c6b3e0e229cab8466224c94931fa 100644 --- a/FullSimLight/fullSimLight.cc +++ b/FullSimLight/fullSimLight.cc @@ -118,13 +118,13 @@ int main(int argc, char** argv) { } static struct option options[] = { - {"macro file " , required_argument, 0, 'm'}, - {"physics list name " , required_argument, 0, 'f'}, - {"performance flag " , no_argument , 0, 'p'}, - {"geometry file name " , required_argument, 0, 'g'}, - {"pythia" , required_argument, 0, 'P'}, - {"overlap geometry check" , no_argument , 0, 'o'}, - {"help" , no_argument , 0, 'h'}, + {"macro file " , required_argument, 0, 'm'}, + {"physics list name " , required_argument, 0, 'f'}, + {"performance flag " , no_argument , 0, 'p'}, + {"geometry file name " , required_argument, 0, 'g'}, + {"pythia primary generator " , required_argument, 0, 'P'}, + {"overlap geometry check " , no_argument , 0, 'o'}, + {"help" , no_argument , 0, 'h'}, {0, 0, 0, 0} }; @@ -138,7 +138,7 @@ void Help() { <<" -g : REQUIRED : the Geometry file name \n" <<" -o : flag ==> run the geometry overlap check (default: FALSE)\n" <<" -f : physics list name (default: FTFP_BERT) \n" - <<" -P : generate events with Pythia [config. available: ttbar/higgs/minbias or use .txt input file]\n" + <<" -P : use Pythia primary generator [config. available: ttbar/higgs/minbias or use a Pythia command input file]\n" <<" -p : flag ==> run the application in performance mode i.e. no user actions \n" <<" : - ==> run the application in NON performance mode i.e. with user actions (default) \n"<< std::endl; @@ -172,7 +172,7 @@ void GetInputArguments(int argc, char** argv) { // Need to enable performance mode, as user actions require particle gun setup parIsPerformance = true; #else - std::cerr << "Support for Pythia is not available." << std::endl; + std::cerr << "Support for Pythia is not available. \nPlease visit the website http://home.thep.lu.se/Pythia/ to install it in your system." << std::endl; exit(1); #endif break; diff --git a/FullSimLight/pythia.g4 b/FullSimLight/pythia.g4 new file mode 100644 index 0000000000000000000000000000000000000000..bca523f1d67636cc467990da1f37dd8951aaf609 --- /dev/null +++ b/FullSimLight/pythia.g4 @@ -0,0 +1,29 @@ +######################################################################## +## SET ALL VERBOSE LEVELS TO 0 +## --------------------------------------------------------------------- +/control/verbose 0 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +######################################################################## +## SET NUMBER OF THREADS (will be ignored in case of sequential Geant4) +## --------------------------------------------------------------------- +/run/numberOfThreads 1 +/control/cout/prefixString G4Worker_ +######################################################################## +## DETECTOR AND MAGNETIC FIELD +## --------------------------------------------------------------------- +###/mydet/setGdmlFile atlas2018.gdml +## --------------------------------------------------------------------- +## To Switch off the field set it to 0 tesla +/mydet/setField 4.0 tesla +######################################################################## +## INIT +## --------------------------------------------------------------------- +/run/initialize +######################################################################## +## EXECUTE with 10 events and print the list of processes at the end +## --------------------------------------------------------------------- +/run/beamOn 10 +## --------------------------------------------------------------------- +/process/list diff --git a/GeoModelG4/GeoModel2G4/src/ExtParameterisedVolumeBuilder.cxx b/GeoModelG4/GeoModel2G4/src/ExtParameterisedVolumeBuilder.cxx index b5af51bb087b3a3b393f796bbc73393499258500..9ba77d970e345c0b81be05262ff2d621980f6605 100644 --- a/GeoModelG4/GeoModel2G4/src/ExtParameterisedVolumeBuilder.cxx +++ b/GeoModelG4/GeoModel2G4/src/ExtParameterisedVolumeBuilder.cxx @@ -24,6 +24,14 @@ #include "GeoModel2G4/CLHEPtoEigenConverter.h" +bool hasEnding (std::string const &fullString, std::string const &ending) { + if (fullString.length() >= ending.length()) { + return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); + } else { + return false; + } +} + ExtParameterisedVolumeBuilder::ExtParameterisedVolumeBuilder(std::string n): VolumeBuilder(n), m_getMatEther(true), @@ -125,8 +133,7 @@ G4LogicalVolume* ExtParameterisedVolumeBuilder::Build(const PVConstLink theGeoPh Query<int> Qint = av.getId(); if(Qint.isValid()) id = Qint; - - if(m_matEther->getName() == theGeoPhysChild->getLogVol()->getMaterial()->getName() ) + if(m_matEther->getName() == theGeoPhysChild->getLogVol()->getMaterial()->getName() || hasEnding(theGeoPhysChild->getLogVol()->getMaterial()->getName(), "Ether")) { Geo2G4AssemblyVolume* assembly = BuildAssembly(theGeoPhysChild); @@ -174,6 +181,8 @@ G4LogicalVolume* ExtParameterisedVolumeBuilder::Build(const PVConstLink theGeoPh return theG4LogVolume; } + + Geo2G4AssemblyVolume* ExtParameterisedVolumeBuilder::BuildAssembly(PVConstLink pv) const { PVConstLink theGeoPhysChild; @@ -201,7 +210,9 @@ Geo2G4AssemblyVolume* ExtParameterisedVolumeBuilder::BuildAssembly(PVConstLink p // Check if it is an assembly if(m_matEther->getName() == theGeoPhysChild->getLogVol()->getMaterial()->getName() || - m_matHypUr->getName() == theGeoPhysChild->getLogVol()->getMaterial()->getName() ) + m_matHypUr->getName() == theGeoPhysChild->getLogVol()->getMaterial()->getName() || + hasEnding(theGeoPhysChild->getLogVol()->getMaterial()->getName(), "Ether")|| + hasEnding(theGeoPhysChild->getLogVol()->getMaterial()->getName(), "HyperUranium")) { // Build the child assembly if(!(theG4AssemblyChild = BuildAssembly(theGeoPhysChild))) return 0; @@ -254,10 +265,10 @@ void ExtParameterisedVolumeBuilder::getMatEther() const { GeoElement* ethElement = new GeoElement("EtherEl","ET",500.0,0.0); ethElement->ref(); - GeoMaterial* ether = new GeoMaterial("Ether",0.0); + GeoMaterial* ether = new GeoMaterial("special::Ether",0.0); ether->add(ethElement,1.); // "Alternative" assembly material - GeoMaterial* hyperUranium = new GeoMaterial("HyperUranium",0.0); + GeoMaterial* hyperUranium = new GeoMaterial("special::HyperUranium",0.0); hyperUranium->add(ethElement,1.); m_matEther = ether; m_matHypUr = hyperUranium; diff --git a/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h index 3214b428fbf354a9701fd9d2cf9d4496c664093b..6c4733c8326d55a8df0e70b29533c2de189c4d96 100644 --- a/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h +++ b/GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h @@ -1,12 +1,11 @@ // author: Riccardo.Maria.Bianchi@cern.ch - 2017 -// major updates: Aug 2018 +// major updates: +// - Aug 2018, R.M.Bianchi +// - Nov 2020, R.M.Bianchi #ifndef GMDBManager_H #define GMDBManager_H -// include SQLite -#include <sqlite3.h> - // include C++ #include <iostream> #include <unordered_map> @@ -14,6 +13,7 @@ #include <string> #include <typeindex> // std::type_index, needs C++11 + /** * \class GMDBManager * @@ -169,6 +169,7 @@ public: * @note The 'suffix' parameter is optional. If not provided, the records will be saved in the default table. */ bool addListOfPublishedAlignableTransforms(const std::vector<std::vector<std::string>> &records, std::string suffix = ""); + /** * @brief Save the list of 'published' GeoVFullPhysVol nodes to the DB. * @details The method gets a list of records and stores them in the default table 'PublishedFullPhysVols". @@ -237,10 +238,6 @@ private: std::string getTableNameFromNodeType(const std::string &nodeType); - sqlite3_stmt* selectAllFromTable(std::string tableName) const; - sqlite3_stmt* selectAllFromTableSortBy(std::string tableName, std::string sortColumn="") const; - sqlite3_stmt* selectAllFromTableChildrenPositions() const; - void storeTableColumnNames(std::vector<std::string> input); std::vector<std::string> getTableColumnNames(const std::string &tableName); @@ -251,20 +248,11 @@ private: bool storeRootVolume(const unsigned int &id, const std::string &nodeType); -// void showError(const QSqlError &err) const; - std::string m_dbpath; -// QSqlDatabase m_db; - /// Pointer to SQLite connection - sqlite3* m_dbSqlite; - /// Variable to store error messages from SQLite - char *m_SQLiteErrMsg; + bool m_dbIsOK; - - bool m_dbIsOK; - - bool m_debug; + bool m_debug; std::unordered_map<std::string, std::vector<std::string>> m_tableNames; /// stores the column names for each table std::unordered_map<std::string, std::string> m_childType_tableName; @@ -274,6 +262,12 @@ private: std::unordered_map<unsigned int, std::string> m_cache_tableId_nodeType; /// cache for tableID-->nodeType std::unordered_map<std::string, std::string> m_cache_nodeType_tableName; /// cache for nodeType-->tableName std::unordered_map<std::string, unsigned int> m_cache_nodeType_tableID; /// cache for nodeType-->tableID + +protected: + class Imp; + Imp * m_d; + }; + #endif // GMDBManager_H diff --git a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp index f0256010d77b74ee84b15546713c1bba7e28563f..21651a252935a9b9a2b56f39e691b009f2dbc4cd 100644 --- a/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp +++ b/GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp @@ -17,6 +17,9 @@ #define FMT_HEADER_ONLY 1 // to use 'fmt' header-only #include "fmt/format.h" +// include SQLite +#include <sqlite3.h> + // C++ includes #include <stdlib.h> /* exit, EXIT_FAILURE */ #include <sstream> @@ -58,7 +61,29 @@ std::string joinVectorStrings(std::vector<std::string> vec, std::string sep="") } -GMDBManager::GMDBManager(const std::string &path) : m_dbpath(path), m_dbSqlite(nullptr), m_SQLiteErrMsg(0), m_dbIsOK(false), m_debug(false) + +class GMDBManager::Imp { +public: + // constructor + Imp (GMDBManager* dbm) + : theManager(dbm), m_dbSqlite(nullptr), m_SQLiteErrMsg(0) {} + + // The class + GMDBManager* theManager; + + // Pointer to SQLite connection + sqlite3* m_dbSqlite; + + /// Variable to store error messages from SQLite + char *m_SQLiteErrMsg; + + sqlite3_stmt* selectAllFromTable(std::string tableName) const; + sqlite3_stmt* selectAllFromTableSortBy(std::string tableName, std::string sortColumn="") const; + sqlite3_stmt* selectAllFromTableChildrenPositions() const; + +}; + +GMDBManager::GMDBManager(const std::string &path) : m_dbpath(path), m_dbIsOK(false), m_debug(false), m_d(new Imp(this)) { // Check if the user asked for running in serial or multi-threading mode if ( "" != getEnvVar("GEOMODEL_ENV_IO_DBMANAGER_DEBUG")) { @@ -70,14 +95,14 @@ GMDBManager::GMDBManager(const std::string &path) : m_dbpath(path), m_dbSqlite(n // FIXME: TODO: we should check the existence of the file, otherwise SQLite will create a new file from scratch // Save the connection result - int exit = sqlite3_open(path.c_str(), &m_dbSqlite); + int exit = sqlite3_open(path.c_str(), &m_d->m_dbSqlite); // Test if there was an error if (exit == SQLITE_OK) { std::cout << "The Geometry Database '"<< path << "' has been opened successfully!" << std::endl; m_dbIsOK = true; } else { - std::cout << "DB Open Error: " << sqlite3_errmsg(m_dbSqlite) << std::endl; + std::cout << "DB Open Error: " << sqlite3_errmsg(m_d->m_dbSqlite) << std::endl; m_dbIsOK = false; } @@ -95,8 +120,8 @@ GMDBManager::GMDBManager(const std::string &path) : m_dbpath(path), m_dbSqlite(n GMDBManager::~GMDBManager() { - sqlite3_close(m_dbSqlite); - m_dbSqlite = nullptr; + sqlite3_close(m_d->m_dbSqlite); + m_d->m_dbSqlite = nullptr; } @@ -220,10 +245,10 @@ std::vector<std::vector<std::string>> GMDBManager::getTableRecords(std::string t // get the query statetement ready to be executed sqlite3_stmt* stmt = nullptr; if ("ChildrenPositions" == tableName) { - stmt = selectAllFromTableChildrenPositions(); + stmt = m_d->selectAllFromTableChildrenPositions(); } else { - stmt = selectAllFromTable(tableName); + stmt = m_d->selectAllFromTable(tableName); } // execute the query and loop over all rows and all columuns if ( stmt ) @@ -247,7 +272,7 @@ std::vector<std::vector<std::string>> GMDBManager::getTableRecords(std::string t if ( res == SQLITE_DONE || res==SQLITE_ERROR) { if (res == SQLITE_ERROR) { - std::string errmsg(sqlite3_errmsg(m_dbSqlite)); + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); throw errmsg; } @@ -592,15 +617,15 @@ void GMDBManager::addDBversion(std::string version) sqlite3_stmt * st = nullptr; int rc = -1; std::string sql = "INSERT INTO dbversion(version) VALUES(?)"; - rc = sqlite3_prepare_v2( m_dbSqlite, sql.c_str(), -1, &st, NULL); + rc = sqlite3_prepare_v2( m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } rc = sqlite3_bind_text(st, 1, version.c_str(), version.length(), SQLITE_TRANSIENT); rc = sqlite3_step( st ); if (rc != SQLITE_DONE) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } // finalize @@ -610,7 +635,7 @@ void GMDBManager::addDBversion(std::string version) bool GMDBManager::checkIsDBOpen() const { - if(m_dbSqlite != nullptr) { + if(m_d->m_dbSqlite != nullptr) { return true; } else { std::cout << "ERROR! The SQLite DB is not accessible! Exiting..." << std::endl; @@ -645,9 +670,9 @@ std::vector<std::string> GMDBManager::getItemFromTableName(std::string tableName // prepare the query sqlite3_stmt * stmt = nullptr; int rc = -1; - rc = sqlite3_prepare_v2( m_dbSqlite, sql.c_str(), -1, &stmt, NULL); + rc = sqlite3_prepare_v2( m_d->m_dbSqlite, sql.c_str(), -1, &stmt, NULL); if (rc != SQLITE_OK) { - printf( "[SQLite ERR] 'prepare' (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] 'prepare' (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } // bind the parameters @@ -671,7 +696,7 @@ std::vector<std::string> GMDBManager::getItemFromTableName(std::string tableName if ( res == SQLITE_DONE || res==SQLITE_ERROR) { if (res == SQLITE_ERROR) { - std::string errmsg(sqlite3_errmsg(m_dbSqlite)); + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); throw errmsg; } @@ -681,7 +706,7 @@ std::vector<std::string> GMDBManager::getItemFromTableName(std::string tableName } // TODO: do we need that error check here?? // if (rc != SQLITE_DONE) { -// printf( "[SQLite ERR] 'step' (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); +// printf( "[SQLite ERR] 'step' (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); //// exit(EXIT_FAILURE); // } // finalize @@ -730,9 +755,9 @@ int GMDBManager::loadGeoNodeTypesAndBuildCache() std::string nodeType = ""; std::string tableName = ""; // prepare the query - rc = sqlite3_prepare_v2( m_dbSqlite, sql.c_str(), -1, &st, NULL); + rc = sqlite3_prepare_v2( m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } // execute the statement until all selected records are processed @@ -749,7 +774,7 @@ int GMDBManager::loadGeoNodeTypesAndBuildCache() m_cache_nodeType_tableID.insert( std::pair<std::string, unsigned int>(nodeType, id)); } if (rc != SQLITE_DONE) { - std::string errmsg(sqlite3_errmsg(m_dbSqlite)); + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(st); throw errmsg; } @@ -781,15 +806,15 @@ std::unordered_map<std::string, unsigned int> GMDBManager::getAll_NodeTypesTable -sqlite3_stmt* GMDBManager::selectAllFromTable(std::string tableName) const +sqlite3_stmt* GMDBManager::Imp::selectAllFromTable(std::string tableName) const { return selectAllFromTableSortBy(tableName, "id"); } -sqlite3_stmt* GMDBManager::selectAllFromTableSortBy(std::string tableName, std::string sortColumn) const +sqlite3_stmt* GMDBManager::Imp::selectAllFromTableSortBy(std::string tableName, std::string sortColumn) const { - checkIsDBOpen(); + theManager->checkIsDBOpen(); if ("" == sortColumn || 0 == sortColumn.size()) { sortColumn = "id"; } @@ -807,9 +832,9 @@ sqlite3_stmt* GMDBManager::selectAllFromTableSortBy(std::string tableName, std:: } -sqlite3_stmt* GMDBManager::selectAllFromTableChildrenPositions() const +sqlite3_stmt* GMDBManager::Imp::selectAllFromTableChildrenPositions() const { - checkIsDBOpen(); + theManager->checkIsDBOpen(); sqlite3_stmt * st = nullptr; int rc = -1; //set the SQL query string @@ -856,9 +881,9 @@ void GMDBManager::getAllDBTables() std::string queryStr = "SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%';"; // prepare the query with the query string sqlite3_stmt *stmt; - int rc = sqlite3_prepare_v2(m_dbSqlite, queryStr.c_str(), -1, &stmt, NULL); + int rc = sqlite3_prepare_v2(m_d->m_dbSqlite, queryStr.c_str(), -1, &stmt, NULL); if (rc != SQLITE_OK) { - throw std::string(sqlite3_errmsg(m_dbSqlite)); + throw std::string(sqlite3_errmsg(m_d->m_dbSqlite)); } // execute the statement until all selected records are processed while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { @@ -867,7 +892,7 @@ void GMDBManager::getAllDBTables() tables.push_back(tableName); } if (rc != SQLITE_DONE) { - std::string errmsg(sqlite3_errmsg(m_dbSqlite)); + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); throw errmsg; } @@ -1211,13 +1236,13 @@ int GMDBManager::execQuery(std::string queryStr) if(m_debug) std::cout << "queryStr to execute: " << queryStr << std::endl; // debug checkIsDBOpen(); int result = -1; - if( (result = sqlite3_exec(m_dbSqlite, queryStr.c_str(), NULL, 0, &m_SQLiteErrMsg)) ) + if( (result = sqlite3_exec(m_d->m_dbSqlite, queryStr.c_str(), NULL, 0, &m_d->m_SQLiteErrMsg)) ) { printf( "[ERR] : \t> CMD: %s , Error: %d\n" , queryStr.c_str() , result ); - if ( m_SQLiteErrMsg ) + if ( m_d->m_SQLiteErrMsg ) { - printf( "[ERR] : Error msg: %s\n", m_SQLiteErrMsg ); - sqlite3_free(m_SQLiteErrMsg); + printf( "[ERR] : Error msg: %s\n", m_d->m_SQLiteErrMsg ); + sqlite3_free(m_d->m_SQLiteErrMsg); } } return result; @@ -1249,9 +1274,9 @@ void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) int rc = -1; // preparing the SQL query std::string sql = "INSERT INTO GeoNodesTypes(nodeType, tableName) VALUES(?, ?)"; - rc = sqlite3_prepare_v2( m_dbSqlite, sql.c_str(), -1, &st, NULL); + rc = sqlite3_prepare_v2( m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } if(m_debug) std::cout << "storeNodeType - Query string:" << sql << std::endl; // debug @@ -1261,7 +1286,7 @@ void GMDBManager::storeNodeType(std::string nodeType, std::string tableName) // execute the query rc = sqlite3_step( st ); if (rc != SQLITE_DONE) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } // finalize @@ -1314,9 +1339,9 @@ bool GMDBManager::storeRootVolume(const unsigned int &id, const std::string &nod // preparing the SQL query sqlite3_stmt * st = nullptr; int rc = -1; - rc = sqlite3_prepare_v2( m_dbSqlite, sql.c_str(), -1, &st, NULL); + rc = sqlite3_prepare_v2( m_d->m_dbSqlite, sql.c_str(), -1, &st, NULL); if (rc != SQLITE_OK) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); // TODO: add __func__ to all error messages, as I did here + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); // TODO: add __func__ to all error messages, as I did here exit(EXIT_FAILURE); } if(m_debug) std::cout << "Query string:" << sql << std::endl; // debug @@ -1326,7 +1351,7 @@ bool GMDBManager::storeRootVolume(const unsigned int &id, const std::string &nod // execute the query rc = sqlite3_step( st ); if (rc != SQLITE_DONE) { - printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_dbSqlite) ); + printf( "[SQLite ERR] (%s) : Error msg: %s\n", __func__, sqlite3_errmsg(m_d->m_dbSqlite) ); exit(EXIT_FAILURE); } // finalize @@ -1343,7 +1368,7 @@ bool GMDBManager::storeRootVolume(const unsigned int &id, const std::string &nod std::vector<std::string> GMDBManager::getRootPhysVol() { // get the ID of the ROOT vol from the table "RootVolume" - sqlite3_stmt* stmt = selectAllFromTable("RootVolume"); + sqlite3_stmt* stmt = m_d->selectAllFromTable("RootVolume"); // declare the data we want to fetch unsigned int id; unsigned int typeId; @@ -1356,7 +1381,7 @@ std::vector<std::string> GMDBManager::getRootPhysVol() // TODO: fill a cache } if (rc != SQLITE_DONE) { - std::string errmsg(sqlite3_errmsg(m_dbSqlite)); + std::string errmsg(sqlite3_errmsg(m_d->m_dbSqlite)); sqlite3_finalize(stmt); throw errmsg; } diff --git a/GeoModelVisualization/CMakeLists.txt b/GeoModelVisualization/CMakeLists.txt index 52f5200f76f19a17f9e0d16c8b578737ef896c51..92888e94dcd323174c90fbd801fd5c8da58be830 100644 --- a/GeoModelVisualization/CMakeLists.txt +++ b/GeoModelVisualization/CMakeLists.txt @@ -19,9 +19,11 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) include( configure_cpp_options ) set( CMAKE_FIND_FRAMEWORK "LAST" CACHE STRING "Framework finding behaviour on macOS" ) - # Set up how the project handle some of its dependenices. Either by picking them - # up from the environment, or building them itself. - include( SetupJSON ) + if( NOT TARGET JSONExt ) + # Set up how the project handle some of its dependenices. Either by picking them + # up from the environment, or building them itself. + include( SetupJSON ) + endif() # Find the base GeoModel packages, which must be installed on the target system already find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder find_package( GeoModelIO REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder