16void GSystemSQLiteFactory::loadMaterials(
GSystem* system) {
21 if (db ==
nullptr) { initialize_sqlite_db(system); }
29 const char* count_query =
"SELECT COUNT(*) FROM materials";
30 sqlite3_stmt* count_stmt =
nullptr;
31 int rc = sqlite3_prepare_v2(db, count_query, -1, &count_stmt,
nullptr);
32 if (rc != SQLITE_OK) {
34 sqlite3_errmsg(db),
" (", rc,
") using query: ", count_query);
36 if (sqlite3_step(count_stmt) == SQLITE_ROW) { count = sqlite3_column_int(count_stmt, 0); }
37 sqlite3_finalize(count_stmt);
40 log->
info(2,
"Table 'materials' is empty for system <", system_name,
">, variation <", variation,
">, "
41 "run ", runno,
". This may be ok if the materials are from the Geant4 database.");
47 const char* sql_query =
"SELECT DISTINCT * FROM materials WHERE system = ? AND variation = ? AND run = ?";
48 sqlite3_stmt* stmt =
nullptr;
49 rc = sqlite3_prepare_v2(db, sql_query, -1, &stmt,
nullptr);
50 if (rc != SQLITE_OK) {
52 sqlite3_errmsg(db),
" (", rc,
") using query: ", sql_query);
56 string system_name = system->
getName();
60 sqlite3_bind_text(stmt, 1, system_name.c_str(), -1, SQLITE_STATIC);
61 sqlite3_bind_text(stmt, 2, variation.c_str(), -1, SQLITE_STATIC);
62 sqlite3_bind_int(stmt, 3, runno);
65 vector<string> gmaterialPars;
66 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
67 const int ncols = sqlite3_column_count(stmt);
68 for (
int i = 0; i < ncols; ++i) {
69 const char* cname = sqlite3_column_name(stmt, i);
73 (sqlite3_column_type(stmt, i) == SQLITE_NULL)
75 : reinterpret_cast<const char*>(sqlite3_column_text(stmt, i));
77 log->
info(2,
"<sqlite> column: ", cname,
" = ", ctext);
82 gmaterialPars.emplace_back(ctext);
86 gmaterialPars.clear();
90 if (rc != SQLITE_DONE) {
92 sqlite3_errmsg(db),
" (", rc,
")");
96 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 getVariation() const
void addGMaterial(std::vector< std::string > pars)
Build and add a material from a serialized parameter list.
std::string getName() const
Conventions and shared constants for the detector-system module.
#define ROOTWORLDGVOLUMENAME
Canonical name for the ROOT/world gvolume entry.