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); }
47 if (!table_exists(db,
"mirrors") || !mirrors_column_exists(db,
"name")) {
48 log->info(2,
"No usable 'mirrors' table in the database. This is ok if no system defines mirrors.");
54 const std::string transmittance_column = mirrors_column_exists(db,
"transmittance")
56 :
"NULL AS transmittance";
57 const std::string sql_query =
58 "SELECT name, description, type, finish, model, border, matOptProps, photonEnergy, "
59 "indexOfRefraction, reflectivity, efficiency, specularlobe, specularspike, backscatter, "
60 + transmittance_column +
61 ", sigmaAlpha FROM mirrors WHERE experiment = ? AND system = ? AND variation = ? AND run = ?";
62 sqlite3_stmt* stmt =
nullptr;
63 int rc = sqlite3_prepare_v2(db, sql_query.c_str(), -1, &stmt,
nullptr);
64 if (rc != SQLITE_OK) {
66 sqlite3_errmsg(db),
" (", rc,
") using query: ", sql_query);
71 std::string system_name = system->
getName();
75 sqlite3_bind_text(stmt, 1, experiment.c_str(), -1, SQLITE_STATIC);
76 sqlite3_bind_text(stmt, 2, system_name.c_str(), -1, SQLITE_STATIC);
77 sqlite3_bind_text(stmt, 3, variation.c_str(), -1, SQLITE_STATIC);
78 sqlite3_bind_int(stmt, 4, runno);
81 if (
auto sql = sqlite3_expanded_sql(stmt)) {
86 std::vector<std::string> gmirrorPars;
87 while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
88 const int ncols = sqlite3_column_count(stmt);
89 for (
int i = 0; i < ncols; ++i) {
90 const char* cname = sqlite3_column_name(stmt, i);
94 (sqlite3_column_type(stmt, i) == SQLITE_NULL)
96 : reinterpret_cast<const char*>(sqlite3_column_text(stmt, i));
98 log->info(2,
"<sqlite> column: ", cname,
" = ", ctext);
100 gmirrorPars.emplace_back(ctext);
106 if (rc != SQLITE_DONE) {
108 sqlite3_errmsg(db),
" (", rc,
")");
111 sqlite3_finalize(stmt);
std::shared_ptr< GLogger > log
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.
constexpr int ERR_GSQLITEERROR
constexpr char ROOTWORLDGVOLUMENAME[]
Canonical name for the ROOT/world gvolume entry.