| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | // %%%%%%%%%%
|
|---|
| 9 | // Qt headers
|
|---|
| 10 | // %%%%%%%%%%
|
|---|
| 11 | #include <QtSql>
|
|---|
| 12 |
|
|---|
| 13 | // %%%%%%%%%%%%%
|
|---|
| 14 | // gemc headers
|
|---|
| 15 | // %%%%%%%%%%%%%
|
|---|
| 16 | #include "detector.h"
|
|---|
| 17 | #include "MBankdefs.h"
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | map<string, MBank> read_banks(gemc_opts gemcOpt, map<string, MPHB_Factory> Map)
|
|---|
| 21 | {
|
|---|
| 22 | string hd_msg = gemcOpt.args["LOG_MSG"].args + " Bank Map >> " ;
|
|---|
| 23 | double OUT_VERBOSITY = gemcOpt.args["OUT_VERBOSITY"].arg;
|
|---|
| 24 | string database = gemcOpt.args["BANK_DATABASE"].args;
|
|---|
| 25 |
|
|---|
| 26 | map<string, MBank> banks;
|
|---|
| 27 |
|
|---|
| 28 | QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
|
|---|
| 29 | db.setHostName("clasdb.jlab.org");
|
|---|
| 30 | db.setDatabaseName(database.c_str());
|
|---|
| 31 | db.setUserName("clasuser");
|
|---|
| 32 | bool ok = db.open();
|
|---|
| 33 |
|
|---|
| 34 | if(!ok)
|
|---|
| 35 | {
|
|---|
| 36 | cout << hd_msg << " Database not connected. Exiting." << endl;
|
|---|
| 37 | exit(-1);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | else
|
|---|
| 41 | for(map<string, MPHB_Factory>::iterator it=Map.begin(); it!=Map.end(); it++)
|
|---|
| 42 | {
|
|---|
| 43 | MBank mbank;
|
|---|
| 44 | string dbtable = it->first;
|
|---|
| 45 | QSqlQuery q;
|
|---|
| 46 | string dbexecute = "select name,id, type, activated, description from " + dbtable ;
|
|---|
| 47 | q.exec(dbexecute.c_str());
|
|---|
| 48 |
|
|---|
| 49 | while (q.next())
|
|---|
| 50 | {
|
|---|
| 51 | mbank.name.push_back(TrimSpaces(q.value(0).toString().toStdString()));
|
|---|
| 52 | mbank.id.push_back(q.value(1).toInt());
|
|---|
| 53 | mbank.type.push_back(q.value(2).toInt());
|
|---|
| 54 | mbank.activated.push_back(q.value(3).toInt());
|
|---|
| 55 | mbank.description.push_back(q.value(4).toString().toStdString());
|
|---|
| 56 | }
|
|---|
| 57 | banks[dbtable] = mbank;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | if(OUT_VERBOSITY>2)
|
|---|
| 61 | {
|
|---|
| 62 | for(map<string, MBank>::iterator it=banks.begin(); it!=banks.end(); it++)
|
|---|
| 63 | {
|
|---|
| 64 | cout << hd_msg << " bank: <" << it->first << ">" << endl;
|
|---|
| 65 | for(int i=0; i<it->second.name.size(); i++)
|
|---|
| 66 | {
|
|---|
| 67 | cout << " variable: " ;
|
|---|
| 68 | cout.width(12);
|
|---|
| 69 | cout << it->second.name[i];
|
|---|
| 70 | cout << " | id: " ;
|
|---|
| 71 | cout.width(2);
|
|---|
| 72 | cout << it->second.id[i] ;
|
|---|
| 73 | cout << " | " ;
|
|---|
| 74 | cout.width(8);
|
|---|
| 75 | cout << (it->second.type[i] ? "double |" : "int |");
|
|---|
| 76 | cout.width(13);
|
|---|
| 77 | cout << (it->second.activated[i] ? "present |" : "not present |");
|
|---|
| 78 | cout << it->second.description[i] << endl ;
|
|---|
| 79 | }
|
|---|
| 80 | cout << endl;
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | db = QSqlDatabase();
|
|---|
| 84 | db.removeDatabase("qt_sql_default_connection");
|
|---|
| 85 |
|
|---|
| 86 | return banks;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|