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

Add support for the export of XML tables to SQLite

parent 2abd73aa
Branches
No related tags found
No related merge requests found
......@@ -45,6 +45,8 @@ public:
bool initDB();
void setLogLevel(const unsigned int level) {m_logLevel = level;}
int loadGeoNodeTypesAndBuildCache();
......@@ -269,7 +271,8 @@ private:
bool m_dbIsOK;
bool m_debug;
bool m_debug; //TODO: merge m_debug and m_logLevel...
unsigned int m_logLevel;
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;
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
/*
* author: Riccardo Maria Bianchi @ CERN - 2017
* author: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch>
* first version: 2017
*
* major updates:
* - Aug 2018, R.M.Bianchi
* - Jun 2020, R.M.Bianchi
* - Aug 2020, R.M.Bianchi - Added support to publish lists of FullPhysVol and AlignableTransform nodes
* - May 2021, R.M.Bianchi - Added support for the publication of standalone tabular data,
* needed for an export of XML tables to SQLite
*/
#include <GeoModelDBManager/GMDBManager.h>
......@@ -90,7 +94,10 @@ GMDBManager::GMDBManager(const std::string &path) : m_dbpath(path), m_dbIsOK(fal
m_debug = true;
std::cout << "You defined the GEOMODEL_IO_DEBUG variable, so you will see a verbose output." << std::endl;
}
// set default logLevel
m_logLevel = 0;
m_dbIsOK = false;
// FIXME: TODO: we should check the existence of the file, otherwise SQLite will create a new file from scratch
......@@ -413,8 +420,9 @@ bool GMDBManager::addListOfRecordsToTable(const std::string tableName, const std
if(m_debug) std::cout << "tableColString:" << tableColString << std::endl;
unsigned int nRecords = records.size();
std::cout << "Info: number of " << tableName << " records to dump into the DB:" << nRecords << std::endl;
if (m_logLevel > 0) {
std::cout << "Info: number of " << tableName << " records to dump into the DB:" << nRecords << std::endl;
}
// preparing the SQL query
std::string sql = fmt::format("INSERT INTO {0} {1} VALUES ", tableName, tableColString);
unsigned int id = 0;
......@@ -450,7 +458,9 @@ bool GMDBManager::addListOfRecordsToTable(const std::string tableName, const std
if(m_debug) std::cout << "tableColString:" << tableColString << std::endl;
unsigned int nRecords = records.size();
std::cout << "Info: number of " << tableName << " records to dump into the DB:" << nRecords << std::endl;
if (m_logLevel > 0) {
std::cout << "Info: number of " << tableName << " records to dump into the DB:" << nRecords << std::endl;
}
// preparing the SQL query
std::string sql = fmt::format("INSERT INTO {0} {1} VALUES ", tableName, tableColString);
......@@ -696,6 +706,7 @@ bool GMDBManager::addRootVolume(const std::vector<std::string> &values)
std::cout << "ERROR! No records to save for RootVolume! All GeoModel trees must have a 'World'/'Root' volume! Exiting..." << std::endl;
exit(EXIT_FAILURE);
}
return false;
}
......@@ -1183,7 +1194,7 @@ bool GMDBManager::createCustomTable(const std::string tableName, const std::vect
queryStr += colStr;
}
queryStr += ")";
std::cout << "- table definition: " << queryStr << std::endl;
//std::cout << "- table definition: " << queryStr << std::endl; // //TODO: it should be printed with a 'verbose' mode.
rc = execQuery(queryStr);
tab.clear();
......
......@@ -78,6 +78,8 @@ public:
void saveToDB(GeoPublisher* store = nullptr);
void saveToDB( std::vector<GeoPublisher*>& vecStores);
void setLogLevel(const unsigned int level) {m_logLevel = level; m_dbManager->setLogLevel(m_logLevel);}
private:
// define copy constructor, needed for the GeoModelAction subclass
......@@ -168,6 +170,8 @@ private:
std::string m_dbpath;
GMDBManager* m_dbManager;
unsigned int m_logLevel;
// work caches
std::unordered_map<std::string, unsigned int> m_parentChildrenMap;
std::unordered_map<std::string, unsigned int> m_volumeCopiesMap;
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
// author: Riccardo.Maria.Bianchi@cern.ch, 2017
//
// author: Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch>, 2017
//
// First version: 2017
// major updates:
// - Aug 2018 - Riccardo Maria Bianchi
// - Feb 2019 - Riccardo Maria Bianchi
......@@ -10,7 +12,8 @@
// - Aug 2020 - Riccardo Maria Bianchi - Added support to publish lists of FPV and AXF nodes
// - Aug 2020 - Marilena Bandieramonte (e-mail: marilena.bandieramonte@cern.ch)
// - Jan 2021 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch> - Added support for custom tables, to store auxiliary data
// - May 2021 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch> - Added support for standalone export of XML tables into SQLite, needed for the IdDict tables.
//
// local includes
#include "GeoModelWrite/WriteGeoModel.h"
......@@ -1121,6 +1124,9 @@ WriteGeoModel::WriteGeoModel(GMDBManager &db)
// get DB metadata
m_memMap_Tables = m_dbManager->getAll_NodeTypesTableIDs();
// set default logLevel
m_logLevel = 0;
}
WriteGeoModel::~WriteGeoModel()
......@@ -1537,6 +1543,7 @@ void WriteGeoModel::saveToDB( GeoPublisher* publisher )
void WriteGeoModel::saveToDB( std::vector<GeoPublisher*>& publishers )
{
std::cout << "Saving the GeoModel tree to file: '" << m_dbpath << "'" << std::endl;
m_dbManager->addListOfRecords("GeoMaterial", m_materials);
m_dbManager->addListOfRecords("GeoElement", m_elements);
......@@ -1551,14 +1558,27 @@ void WriteGeoModel::saveToDB( std::vector<GeoPublisher*>& publishers )
m_dbManager->addListOfRecords("GeoFullPhysVol", m_fullPhysVols);
m_dbManager->addListOfRecords("GeoLogVol", m_logVols);
m_dbManager->addListOfChildrenPositions(m_childrenPositions);
m_dbManager->addRootVolume(m_rootVolume);
if ( m_childrenPositions.size() ) {
m_dbManager->addListOfChildrenPositions(m_childrenPositions);
}
if ( m_rootVolume.size() ) {
m_dbManager->addRootVolume(m_rootVolume);
}
// safety check
if ( ( m_physVols.size() || m_fullPhysVols.size() ) && m_rootVolume.size()==0 ) {
std::cout << "*** ERROR!!! There are PhysVol and/or FullPhysVol instances to save into the DB, but there is no RootVolume"
<< std::endl;
exit(EXIT_FAILURE);
}
// save data stored in instances of GeoPublisher
if(publishers.size()) {
std::cout << "\nINFO: A pointer to a GeoPublisher instance has been provided, "
if (m_logLevel > 0) {
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);
......@@ -1581,7 +1601,9 @@ void WriteGeoModel::saveToDB( std::vector<GeoPublisher*>& publishers )
<< "so we create these custom tables in the DB:"
<< std::endl;
for ( auto& tableData : m_auxiliaryTablesVar ) {
std::cout << "\nsaving table: " << tableData.first << std::endl;
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 ] );
}
}
......@@ -1601,11 +1623,15 @@ void WriteGeoModel::storePublishedAuxiliaryData(GeoPublisher* publisher)
AuxTableDefs tableDefs = publisher->getPublishedAuxData().first;
AuxTableData tableAuxData = publisher->getPublishedAuxData().second;
if ( tableDefs.size() ) {
if (m_logLevel > 0) {
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;
<< std::endl;
}
for ( auto& tableData : tableDefs ) {
std::cout << "\nsaving table: " << tableData.first << std::endl;
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 ] );
}
}
......@@ -1627,12 +1653,16 @@ void WriteGeoModel::storePublishedNodes(GeoPublisher* store)
if (mapAXF.size() > 0) {
m_dbManager->addListOfPublishedAlignableTransforms(m_publishedAlignableTransforms_String, storeName);
} else {
if (m_logLevel > 0) {
std::cout << "\nWARNING! A pointer to a GeoPublisher was provided, but no GeoAlignableTransform nodes have been published. Please, check if that was intended. (If in doubt, please ask to 'geomodel-developers@cern.ch')\n" << std::endl;
}
}
if (mapFPV.size() > 0) {
m_dbManager->addListOfPublishedFullPhysVols(m_publishedFullPhysVols_String, storeName);
} else {
std::cout << "\nWARNING! A pointer to a GeoPublisher was provided, but no GeoFullPhysVol nodes have been published. Please, check if that was intended. (If in doubt, please ask to 'geomodel-developers@cern.ch')\n" << std::endl;
if (m_logLevel > 0) {
std::cout << "\nWARNING! A pointer to a GeoPublisher was provided, but no GeoFullPhysVol nodes have been published. Please, check if that was intended. (If in doubt, please ask to 'geomodel-developers@cern.ch')\n" << std::endl;
}
}
// clear the caches
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment