GEMC  1.8
Geant4 Monte-Carlo Framework
MBankdefs.cc
Go to the documentation of this file.
1 
8 // %%%%%%%%%%
9 // Qt headers
10 // %%%%%%%%%%
11 #include <QtSql>
12 
13 // %%%%%%%%%%%%%
14 // gemc headers
15 // %%%%%%%%%%%%%
16 #include "detector.h"
17 #include "MBankdefs.h"
18 #include "string_utilities.h"
19 
20 
21 map<string, MBank> read_banks(gemc_opts gemcOpt, map<string, MPHB_Factory> Map)
22 {
23  string hd_msg = gemcOpt.args["LOG_MSG"].args + " Bank Map >> " ;
24  double OUT_VERBOSITY = gemcOpt.args["OUT_VERBOSITY"].arg;
25  string database = gemcOpt.args["BANK_DATABASE"].args;
26  string dbhost = gemcOpt.args["DBHOST"].args;
27 
28  string dbUser = gemcOpt.args["DBUSER"].args;
29  string dbPswd = gemcOpt.args["DBPSWD"].args;
30 
31 
32  map<string, MBank> banks;
33 
34  QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
35  db.setHostName(dbhost.c_str());
36  db.setDatabaseName(database.c_str());
37  db.setUserName( dbUser.c_str() );
38  db.setPassword( dbPswd.c_str() );
39  bool ok = db.open();
40 
41  if(!ok)
42  {
43  cout << hd_msg << " Database not connected. Exiting." << endl;
44  exit(-1);
45  }
46 
47  else
48  for(map<string, MPHB_Factory>::iterator it=Map.begin(); it!=Map.end(); it++)
49  {
50  MBank mbank;
51  string dbtable = it->first;
52  QSqlQuery q;
53  string dbexecute = "select name,id, type, activated, description from " + dbtable ;
54  q.exec(dbexecute.c_str());
55 
56  while (q.next())
57  {
58  mbank.name.push_back(TrimSpaces(gemc_tostring(q.value(0).toString())));
59  mbank.id.push_back(q.value(1).toInt());
60  mbank.type.push_back(q.value(2).toInt());
61  mbank.activated.push_back(q.value(3).toInt());
62  mbank.description.push_back(gemc_tostring(q.value(4).toString()));
63  }
64  banks[dbtable] = mbank;
65  }
66 
67  if(OUT_VERBOSITY>2)
68  {
69  for(map<string, MBank>::iterator it=banks.begin(); it!=banks.end(); it++)
70  {
71  cout << hd_msg << " bank: <" << it->first << ">" << endl;
72  for(unsigned int i=0; i<it->second.name.size(); i++)
73  {
74  cout << " variable: " ;
75  cout.width(12);
76  cout << it->second.name[i];
77  cout << " | id: " ;
78  cout.width(2);
79  cout << it->second.id[i] ;
80  cout << " | " ;
81  cout.width(8);
82  cout << (it->second.type[i] ? "double |" : "int |");
83  cout.width(13);
84  cout << (it->second.activated[i] ? "present |" : "not present |");
85  cout << it->second.description[i] << endl ;
86  }
87  cout << endl;
88  }
89  }
90  db = QSqlDatabase();
91  db.removeDatabase("qt_sql_default_connection");
92 
93  return banks;
94 }
95 
96 
97 
98 
99 
map< string, MBank > read_banks(gemc_opts gemcOpt, map< string, MPHB_Factory > Map)
Fills bank maps according to Hit Process Map.
Definition: MBankdefs.cc:21
string gemc_tostring(QString input)
vector< int > id
Output variable identifier.
Definition: MBankdefs.h:36
vector< string > name
Variable name.
Definition: MBankdefs.h:35
vector< string > description
Variable description.
Definition: MBankdefs.h:39
vector< int > type
Type of variable: 0=int, 1=double.
Definition: MBankdefs.h:37
map< string, opts > args
Options map.
Definition: usage.h:68
vector< int > activated
Activated means this variable will be written to the output.
Definition: MBankdefs.h:38
string TrimSpaces(string in)
Removes leading and trailing spaces.