16void GSystemSQLiteFactory::loadMaterials(
GSystem* system) {
21 if (db ==
nullptr) { initialize_sqlite_db(system); }
31 const char* count_query =
"SELECT COUNT(*) FROM materials";
32 sqlite3_stmt* count_stmt =
nullptr;
33 int rc = sqlite3_prepare_v2(db, count_query, -1, &count_stmt,
nullptr);
34 if (rc != SQLITE_OK) {
37 "Sqlite error preparing count query in loadMaterials: %1 (%2) using query: %3", sqlite3_errmsg(db),
40 if (sqlite3_step(count_stmt) == SQLITE_ROW) { count = sqlite3_column_int(count_stmt, 0); }
41 sqlite3_finalize(count_stmt);
46 "Table 'materials' is empty for system <%1>, variation <%2>, run %3. This may be ok if the "
47 "materials are from the Geant4 database.", system_name, variation, runno);
53 const char* sql_query =
"SELECT DISTINCT * FROM materials WHERE system = ? AND variation = ? AND run = ?";
54 sqlite3_stmt* stmt =
nullptr;
55 rc = sqlite3_prepare_v2(db, sql_query, -1, &stmt,
nullptr);
56 if (rc != SQLITE_OK) {
59 sqlite3_errmsg(db), rc, sql_query);
63 string system_name = system->
getName();
67 sqlite3_bind_text(stmt, 1, system_name.c_str(), -1, SQLITE_STATIC);
68 sqlite3_bind_text(stmt, 2, variation.c_str(), -1, SQLITE_STATIC);
69 sqlite3_bind_int(stmt, 3, runno);
72 vector<string> gmaterialPars;
73 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
74 const int ncols = sqlite3_column_count(stmt);
75 for (
int i = 0; i < ncols; ++i) {
76 const char* cname = sqlite3_column_name(stmt, i);
80 (sqlite3_column_type(stmt, i) == SQLITE_NULL)
82 : reinterpret_cast<const char*>(sqlite3_column_text(stmt, i));
84 log->info(2,
"<sqlite> column: %1 = %2", cname, ctext);
89 gmaterialPars.emplace_back(ctext);
93 gmaterialPars.clear();
97 if (rc != SQLITE_DONE) {
104 sqlite3_finalize(stmt);
std::shared_ptr< GLogger > log
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.
constexpr int ERR_GSQLITEERROR
constexpr char ROOTWORLDGVOLUMENAME[]
Canonical name for the ROOT/world gvolume entry.