19 string database = opts.
args[
"DATABASE"].args;
20 string dbhost = opts.
args[
"DBHOST"].args;
21 string dbUser = opts.
args[
"DBUSER"].args;
22 string dbPswd = opts.
args[
"DBPSWD"].args;
23 string hd_msg = opts.
args[
"LOG_MSG"].args +
" MYSQL Parameters: >> ";
24 double verbos = opts.
args[
"PARAMETER_VERBOSITY"].arg;
28 QSqlDatabase db = QSqlDatabase::addDatabase(
"QMYSQL");
29 db.setHostName(dbhost.c_str());
30 db.setDatabaseName(database.c_str());
31 db.setUserName( dbUser.c_str() );
32 db.setPassword( dbPswd.c_str() );
37 cout << hd_msg <<
" Cannot connect to database " << database <<
". Exiting." << endl;
42 map<string, double> GParameters;
43 string dbtable = opts.
args[
"GT"].args;
45 if(runConditions.
gTab_Vec.size() == 0 && dbtable !=
"no")
46 runConditions.
gTab_Vec.push_back(dbtable);
51 for(
unsigned int sql_t=0; sql_t< runConditions.
gTab_Vec.size(); sql_t++)
53 string parameter_table = runConditions.
gTab_Vec[sql_t] +
"__parameters";
54 string dbexecute =
"select name, value, units, description from " + parameter_table;
58 if(!q.exec(dbexecute.c_str()))
60 cout << hd_msg <<
" WARNING! Failed to access DB for table: " << parameter_table <<
". Maybe the table doesn't exist? " << endl;
66 double pvalue = q.value(1).toDouble();
70 if( punits ==
"m") pvalue *= m;
71 else if( punits ==
"inches") pvalue *= 2.54*cm;
72 else if( punits ==
"cm") pvalue *= cm;
73 else if( punits ==
"mm") pvalue *= mm;
74 else if( punits ==
"um") pvalue *= 1E-6*m;
75 else if( punits ==
"fm") pvalue *= 1E-15*m;
76 else if( punits ==
"deg") pvalue *= deg;
77 else if( punits ==
"arcmin") pvalue = pvalue/60.0*deg;
78 else if( punits ==
"rad") pvalue *= rad;
79 else if( punits ==
"mrad") pvalue *= mrad;
80 else if( punits ==
"eV") pvalue *= eV;
81 else if( punits ==
"MeV") pvalue *= MeV;
82 else if( punits ==
"KeV") pvalue *= 0.001*MeV;
83 else if( punits ==
"GeV") pvalue *= GeV;
84 else if( punits ==
"T") pvalue *= tesla;
85 else if( punits ==
"Tesla") pvalue *= tesla;
86 else if( punits ==
"ns") pvalue *= ns;
87 else if( punits ==
"na") pvalue *= 1;
88 else cout << punits <<
": unit not recognized!!" << endl;
90 GParameters[pname] = pvalue;
94 cout << hd_msg <<
" Parameter: " << pname <<
" with value " << pvalue <<
" ";
95 if(punits !=
"na") cout << punits ;
96 cout <<
" : " << pdescr << endl;
108 db.removeDatabase(
"qt_sql_default_connection");
vector< string > gTab_Vec
Vector of SQL tables names.
string gemc_tostring(QString input)
map< string, opts > args
Options map.
map< string, double > initParameters(run_conditions, gemc_opts)
string TrimSpaces(string in)
Removes leading and trailing spaces.