13bool mirrors_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('mirrors')", -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::loadMirrors(
GSystem* system) {
37 if (db ==
nullptr) { initialize_sqlite_db(system); }
45 if (!table_exists(db,
"mirrors") || !mirrors_column_exists(db,
"name")) {
46 log->
info(2,
"No usable 'mirrors' table in the database. This is ok if no system defines mirrors.");
52 const std::string transmittance_column = mirrors_column_exists(db,
"transmittance")
54 :
"NULL AS transmittance";
55 const std::string sql_query =
56 "SELECT name, description, type, finish, model, border, matOptProps, photonEnergy, "
57 "indexOfRefraction, reflectivity, efficiency, specularlobe, specularspike, backscatter, "
58 + transmittance_column +
59 ", sigmaAlpha FROM mirrors WHERE experiment = ? AND system = ? AND variation = ? AND run = ?";
60 sqlite3_stmt* stmt =
nullptr;
61 int rc = sqlite3_prepare_v2(db, sql_query.c_str(), -1, &stmt,
nullptr);
62 if (rc != SQLITE_OK) {
64 sqlite3_errmsg(db),
" (", rc,
") using query: ", sql_query);
69 std::string system_name = system->
getName();
73 sqlite3_bind_text(stmt, 1, experiment.c_str(), -1, SQLITE_STATIC);
74 sqlite3_bind_text(stmt, 2, system_name.c_str(), -1, SQLITE_STATIC);
75 sqlite3_bind_text(stmt, 3, variation.c_str(), -1, SQLITE_STATIC);
76 sqlite3_bind_int(stmt, 4, runno);
79 if (
auto sql = sqlite3_expanded_sql(stmt)) {
84 std::vector<std::string> gmirrorPars;
85 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
86 const int ncols = sqlite3_column_count(stmt);
87 for (
int i = 0; i < ncols; ++i) {
88 const char* cname = sqlite3_column_name(stmt, i);
92 (sqlite3_column_type(stmt, i) == SQLITE_NULL)
94 : reinterpret_cast<const char*>(sqlite3_column_text(stmt, i));
96 log->
info(2,
"<sqlite> column: ", cname,
" = ", ctext);
98 gmirrorPars.emplace_back(ctext);
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
std::string getName() const
void addGMirror(std::vector< std::string > pars)
Build and add a mirror (optical surface) from a serialized parameter list.
Conventions and shared constants for the detector-system module.
#define ROOTWORLDGVOLUMENAME
Canonical name for the ROOT/world gvolume entry.