2 #include <QApplication> 3 #include <QSplashScreen> 13 #include "G4UnitsTable.hh" 21 qt = (bool) opts.
optMap[
"USE_GUI"].arg;
22 header =
" >> gemc Init: ";
24 string guistyle = opts.
optMap[
"QTSTYLE"].args;
38 QFont sansFont(
"Helvetica", 10);
42 qApp->processEvents();
65 splash->showMessage(msg.c_str(), Qt::AlignLeft, Qt::white );
66 qApp->processEvents();
69 cout <<
header << msg << endl;
75 void mergeMaps(map<string, string>& lhs,
const map<string, string>& rhs)
77 for(map<string, string>::const_iterator it = rhs.begin(); it != rhs.end(); it++)
79 lhs[it->first] = it->second;
87 G4RotationMatrix rot(G4ThreeVector(1, 0, 0),
88 G4ThreeVector(0, 1, 0),
89 G4ThreeVector(0, 0, 1));
113 else if(order ==
"yxz")
119 else if(order ==
"yzx")
125 else if(order ==
"zxy")
131 else if(order ==
"zyx")
139 cout <<
" >> ERROR: Ordered rotation <" << order <<
"> for " << dname <<
" is wrong, it's none of the following:" 140 <<
" xzy, yxz, yzx, zxy or zyx. Exiting." << endl;
154 G4ThreeVector pos(0, 0, 0);
155 stringstream vars(v);
173 thisCol = G4Colour(strtol(cvar.substr(0, 2).c_str(), NULL, 16)/255.0,
174 strtol(cvar.substr(2, 2).c_str(), NULL, 16)/255.0,
175 strtol(cvar.substr(4, 2).c_str(), NULL, 16)/255.0,
179 else if(cvar.size() == 7)
180 thisCol = G4Colour(strtol(cvar.substr(0, 2).c_str(), NULL, 16)/255.0,
181 strtol(cvar.substr(2, 2).c_str(), NULL, 16)/255.0,
182 strtol(cvar.substr(4, 2).c_str(), NULL, 16)/255.0,
190 int getLastId(QSqlDatabase db,
string t,
string v,
int run)
192 string dbexecute =
" select max(id) from " + t ;
193 dbexecute +=
" where variation = '" + v ;
197 if(!q.exec(dbexecute.c_str()))
199 cout <<
" !!! Failed to execute MYSQL query " << dbexecute <<
". This is a fatal error. Exiting." << endl;
200 qDebug() << q.lastError();
206 cout << endl <<
" >> WARNING: nothing found on \"" << t
207 <<
"\" with variation \"" << v <<
"\" for run number " << run << endl << endl;
222 string database = gemcOpt.
optMap[
"DATABASE"].args;
223 string dbhost = gemcOpt.
optMap[
"DBHOST"].args;
224 string dbUser = gemcOpt.
optMap[
"DBUSER"].args;
225 string dbPswd = gemcOpt.
optMap[
"DBPSWD"].args;
226 int dbPort = (int) gemcOpt.
optMap[
"DBPORT"].arg;
230 QSqlDatabase db = QSqlDatabase::database();
232 db = QSqlDatabase::addDatabase(
"QMYSQL");
234 db.setHostName(dbhost.c_str());
235 db.setDatabaseName(database.c_str());
236 db.setUserName( dbUser.c_str() );
237 if(dbPort) db.setPort(dbPort);
239 if(dbPswd !=
"no") db.setPassword( dbPswd.c_str() );
245 cout <<
" Error! Cannot connect to database " << database <<
". Exiting." << endl;
259 QSqlDatabase::removeDatabase(
"QMYSQL");
266 map<string, string> filesMap;
270 dir = opendir(directory.c_str());
274 while ((ent = readdir (dir)) != NULL)
276 len = strlen(ent->d_name);
279 if(strcmp(
".dat", &(ent->d_name[len - 4])) == 0)
280 filesMap[directory +
"/" + ent->d_name] =
"ASCII" ;
282 if(strcmp(
".txt", &(ent->d_name[len - 4])) == 0)
283 filesMap[directory +
"/" + ent->d_name] =
"ASCII" ;
290 cout <<
" Error: directory " << directory <<
" could not be opened." << endl;
298 if(e.attributeNode(attribute.c_str()).isAttr())
299 return TrimSpaces(e.attributeNode(attribute.c_str()).value().toStdString());
306 if(e.attributeNode(attribute.c_str()).isAttr())
313 if(e.attributeNode(attribute.c_str()).isAttr())
323 time_t now = time(NULL);
324 struct tm * ptm = localtime(&now);
327 strftime (buffer, 32,
"%a, %m.%d.%Y %H:%M:%S", ptm);
329 return string(buffer);
338 bestVU << G4BestUnit(value, unitType);
340 bestVU >> var >> uni;
342 return var +
"*" + uni;
352 for(
unsigned i=0; i<gt.
data.size(); i++)
353 cout <<
" data # " << i <<
": " << gt.
data[i] << endl;
368 for(
unsigned i=0; i<input.size(); i++)
369 out.push_back(input[i]);
void closeGdb(QSqlDatabase db)
QSqlDatabase openGdb(goptions gemcOpt)
int getLastId(QSqlDatabase db, string t, string v, int run)
vector< double > convertVintVdouble(vector< int > input)
string qv_tostring(QVariant input)
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
G4ThreeVector calc_position(string v)
string assignAttribute(QDomElement e, string attribute, string defaultValue)
string bestValueUnits(double value, string unitType)
G4RotationMatrix calc_rotation(string r, string dname)
string stringify(double x)
map< string, aopt > optMap
Options map.
G4Colour gcol(string cvar)
double stringToDouble(string v)
ostream & operator<<(ostream &stream, gtable gt)
string TrimSpaces(string in)
Removes leading and trailing spaces.
void mergeMaps(map< string, string > &lhs, const map< string, string > &rhs)
map< string, string > getFilesInDirectory(string directory)