13 bool geometry_column_exists(sqlite3* db,
const std::string& column_name) {
14 sqlite3_stmt* stmt =
nullptr;
15 int rc = sqlite3_prepare_v2(db,
"SELECT name FROM PRAGMA_TABLE_INFO('geometry')", -1, &stmt,
nullptr);
16 if (rc != SQLITE_OK) {
return false; }
19 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
20 const unsigned char* colText = sqlite3_column_text(stmt, 0);
21 if (colText !=
nullptr && column_name ==
reinterpret_cast<const char*
>(colText)) {
27 sqlite3_finalize(stmt);
32void GSystemSQLiteFactory::loadGeometry(
GSystem* system) {
37 if (db ==
nullptr) { initialize_sqlite_db(system); }
43 const std::string placement_column = geometry_column_exists(db,
"g4placement_type")
46 const std::string sql_query =
47 "SELECT DISTINCT name, solid, parameters, material, mother, position, rotations, " +
49 ", mfield, visible, style, color, opacity, digitization, identifier, copyOf, solidsOpr, mirror, "
50 "exist, description FROM geometry WHERE experiment = ? AND system = ? AND variation = ? AND run = ?";
51 sqlite3_stmt* stmt =
nullptr;
52 int rc = sqlite3_prepare_v2(db, sql_query.c_str(), -1, &stmt,
nullptr);
53 if (rc != SQLITE_OK) {
55 sqlite3_errmsg(db),
" (", rc,
") using query: ", sql_query);
60 std::string system_name = system->
getName();
64 rc = sqlite3_bind_text(stmt, 1, experiment.c_str(), -1, SQLITE_STATIC);
65 if (rc != SQLITE_OK) {
68 rc = sqlite3_bind_text(stmt, 2, system_name.c_str(), -1, SQLITE_STATIC);
69 if (rc != SQLITE_OK) {
72 rc = sqlite3_bind_text(stmt, 3, variation.c_str(), -1, SQLITE_STATIC);
73 if (rc != SQLITE_OK) {
76 rc = sqlite3_bind_int(stmt, 4, runno);
77 if (rc != SQLITE_OK) {
82 if (
auto sql = sqlite3_expanded_sql(stmt)) {
88 std::vector<std::string> gvolumePars;
89 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
90 int colCount = sqlite3_column_count(stmt);
91 for (
int i = 0; i < colCount; i++) {
92 const char* colName = sqlite3_column_name(stmt, i);
93 const unsigned char* colText = sqlite3_column_text(stmt, i);
95 log->
info(2,
"<sqlite> column: ", (colName ? colName :
"NULL"),
" = ",
96 (colText ? reinterpret_cast<const char*>(colText) :
"NULL"),
" (column ", i,
")");
98 gvolumePars.emplace_back(colText ?
reinterpret_cast<const char*
>(colText) :
"");
104 if (rc != SQLITE_DONE) {
106 sqlite3_errmsg(db),
" (", rc,
")");
109 sqlite3_finalize(stmt);
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Represents a single detector system (e.g., calorimeter, tracker).
std::string getExperiment() const
std::string getVariation() const
void addGVolume(std::vector< std::string > pars)
Build and add a volume from a serialized parameter list.
std::string getName() const
Conventions and shared constants for the detector-system module.
#define DEFAULTG4PLACEMENTTYPE
#define ROOTWORLDGVOLUMENAME
Canonical name for the ROOT/world gvolume entry.