GEMC  2.2
Geant4 Monte-Carlo Framework
mysql_mirrors.cc
Go to the documentation of this file.
1 // Qt headers
2 #include <QtSql>
3 
4 // gemc headers
5 #include "mirrors_factory.h"
6 #include "mysql_mirrors.h"
7 #include "string_utilities.h"
8 #include "utils.h"
9 
10 
11 map<string, mirror*> mysql_mirrors::initMirrors(runConditions rc, goptions opts)
12 {
13 
14  string hd_msg = opts.optMap["LOG_MSG"].args + " MYSQL mirrors Factory: >> ";
15  double verbosity = opts.optMap["MIRROR_VERBOSITY"].arg;
16 
17  map<string, mirror*> mymirs; // mirror map
18 
19  // first check if there's at least one detector with MYSQL factory
21  return mymirs;
22 
23  // connection to the DB
24  QSqlDatabase db = openGdb(opts);
25 
26  // Looping over detectorConditionsMap for detector names
27  // To each detector is associated a mirror table and an opt properties table
28  for(map<string, detectorCondition>::iterator it=rc.detectorConditionsMap.begin(); it != rc.detectorConditionsMap.end(); it++)
29  {
30  // building mirrors belonging to detectors that are tagged with MYSQL factory
31  if(it->second.get_factory() != "MYSQL")
32  continue;
33 
34  if(verbosity)
35  cout << hd_msg << " Initializing " << it->second.get_factory() << " for detector " << it->first << endl;
36 
37  // only add "main" if it's the main variation
38  string dname = it->first ;
39  string tname = dname + "__mirrors";
40  string variation = get_variation(it->second.get_variation());
41  if(is_main_variation(it->second.get_variation()))
42  tname += "_main";
43 
44  string dbexecute = "select name, desc, type, finish, model, border, maptOptProps, photonEnergy, indexOfRefraction, reflectivity, efficiency, specularlobe, specularspike, backscatter from " + tname;
45  dbexecute += " where variation ='" + variation + "'";
46 
47  // executing query - will exit if not successfull.
48  QSqlQuery q;
49  if(!q.exec(dbexecute.c_str()))
50  {
51  cout << hd_msg << " Failed to execute MYSQL query " << dbexecute << ". This is a fatal error. Exiting." << endl;
52  qDebug() << q.lastError();
53  exit(0);
54  }
55  // Warning if nothing is found
56  if(q.size() == 0 && verbosity)
57  {
58  cout << " ** WARNING: mirror for system \"" << dname << "\" not found with variation \"" << variation << endl << endl;
59  }
60 
61  while (q.next())
62  {
63  mirror *thisMir = new mirror(TrimSpaces(qv_tostring( q.value(0)))); // name
64  thisMir->desc = qv_tostring(q.value(1)); // description
65  thisMir->type = qv_tostring(q.value(2)); // type
66  thisMir->finish = qv_tostring(q.value(3)); // finish
67  thisMir->model = qv_tostring(q.value(4)); // model
68  thisMir->border = qv_tostring(q.value(5)); // border
69  thisMir->maptOptProps = qv_tostring(q.value(6)); // maptOptProps
70  thisMir->opticalsFromString(qv_tostring( q.value(7)), "photonEnergy");
71  thisMir->opticalsFromString(qv_tostring( q.value(8)), "indexOfRefraction");
72  thisMir->opticalsFromString(qv_tostring( q.value(9)), "reflectivity");
73  thisMir->opticalsFromString(qv_tostring( q.value(10)), "efficiency");
74  thisMir->opticalsFromString(qv_tostring( q.value(11)), "specularlobe");
75  thisMir->opticalsFromString(qv_tostring( q.value(12)), "specularspike");
76  thisMir->opticalsFromString(qv_tostring( q.value(13)), "backscatter");
77 
78  mymirs[thisMir->name] = thisMir;
79 
80  }
81  }
82 
83  // closing DB connection
84  closeGdb(db);
85  cout << endl;
86 
87  if(verbosity>0) printMirrors(mymirs);
88 
89  return mymirs;
90 }
91 
92 
93 
94 
int check_if_factory_is_needed(map< string, detectorCondition > dcon, string factory)
void closeGdb(QSqlDatabase db)
Definition: utils.cc:254
QSqlDatabase openGdb(goptions gemcOpt)
Definition: utils.cc:220
double verbosity
string get_variation(string var)
parse variation name from string
string qv_tostring(QVariant input)
string desc
void opticalsFromString(string, string)
Overloaded "<<" for mirror class. Dumps infos on screen.
map< string, detectorCondition > detectorConditionsMap
string model
string finish
map< string, aopt > optMap
Options map.
Definition: options.h:71
map< string, mirror * > initMirrors(runConditions, goptions)
string type
void printMirrors(map< string, mirror * > mirMap)
bool is_main_variation(string var)
returns 1 if the string "main:" is found on the input
string TrimSpaces(string in)
Removes leading and trailing spaces.
string name
string border
string maptOptProps