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));
111 else if(order ==
"yxz")
117 else if(order ==
"yzx")
123 else if(order ==
"zxy")
129 else if(order ==
"zyx")
137 cout <<
" >> ERROR: Ordered rotation <" << order <<
"> for " << dname <<
" is wrong, it's none of the following:" 138 <<
" xzy, yxz, yzx, zxy or zyx. Exiting." << endl;
152 G4ThreeVector pos(0, 0, 0);
153 stringstream vars(v);
171 thisCol = G4Colour(strtol(cvar.substr(0, 2).c_str(), NULL, 16)/255.0,
172 strtol(cvar.substr(2, 2).c_str(), NULL, 16)/255.0,
173 strtol(cvar.substr(4, 2).c_str(), NULL, 16)/255.0,
177 else if(cvar.size() == 7)
178 thisCol = G4Colour(strtol(cvar.substr(0, 2).c_str(), NULL, 16)/255.0,
179 strtol(cvar.substr(2, 2).c_str(), NULL, 16)/255.0,
180 strtol(cvar.substr(4, 2).c_str(), NULL, 16)/255.0,
188 int getLastId(QSqlDatabase db,
string t,
string v,
int run)
190 string dbexecute =
" select max(id) from " + t ;
191 dbexecute +=
" where variation = '" + v ;
195 if(!q.exec(dbexecute.c_str()))
197 cout <<
" !!! Failed to execute MYSQL query " << dbexecute <<
". This is a fatal error. Exiting." << endl;
198 qDebug() << q.lastError();
204 cout << endl <<
" >> WARNING: nothing found on \"" << t
205 <<
"\" with variation \"" << v <<
"\" for run number " << run << endl << endl;
220 string database = gemcOpt.
optMap[
"DATABASE"].args;
221 string dbhost = gemcOpt.
optMap[
"DBHOST"].args;
222 string dbUser = gemcOpt.
optMap[
"DBUSER"].args;
223 string dbPswd = gemcOpt.
optMap[
"DBPSWD"].args;
224 int dbPort = (int) gemcOpt.
optMap[
"DBPORT"].arg;
228 QSqlDatabase db = QSqlDatabase::database();
230 db = QSqlDatabase::addDatabase(
"QMYSQL");
232 db.setHostName(dbhost.c_str());
233 db.setDatabaseName(database.c_str());
234 db.setUserName( dbUser.c_str() );
235 if(dbPort) db.setPort(dbPort);
237 if(dbPswd !=
"no") db.setPassword( dbPswd.c_str() );
243 cout <<
" Error! Cannot connect to database " << database <<
". Exiting." << endl;
257 QSqlDatabase::removeDatabase(
"QMYSQL");
264 map<string, string> filesMap;
268 dir = opendir(directory.c_str());
272 while ((ent = readdir (dir)) != NULL)
274 len = strlen(ent->d_name);
277 if(strcmp(
".dat", &(ent->d_name[len - 4])) == 0)
278 filesMap[directory +
"/" + ent->d_name] =
"ASCII" ;
280 if(strcmp(
".txt", &(ent->d_name[len - 4])) == 0)
281 filesMap[directory +
"/" + ent->d_name] =
"ASCII" ;
288 cout <<
" Error: directory " << directory <<
" could not be opened." << endl;
296 if(e.attributeNode(attribute.c_str()).isAttr())
297 return TrimSpaces(e.attributeNode(attribute.c_str()).value().toStdString());
304 if(e.attributeNode(attribute.c_str()).isAttr())
311 if(e.attributeNode(attribute.c_str()).isAttr())
321 time_t now = time(NULL);
322 struct tm * ptm = localtime(&now);
325 strftime (buffer, 32,
"%a, %m.%d.%Y %H:%M:%S", ptm);
327 return string(buffer);
336 bestVU << G4BestUnit(value, unitType);
338 bestVU >> var >> uni;
340 return var +
"*" + uni;
350 for(
unsigned i=0; i<gt.
data.size(); i++)
351 cout <<
" data # " << i <<
": " << gt.
data[i] << endl;
366 for(
unsigned i=0; i<input.size(); i++)
367 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)