-
Jan Reher authoreda819eb04
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <productiondatabaseclient.h>
#include <boost/program_options.hpp>
#include "toolbox.cpp"
#include "BulkDbAccess.h"
#include "QtGui/QApplication"
namespace po=boost::program_options;
using namespace std;
using namespace ProductionDatabase;
static string fileName = "serials.dat";
static string username = "";
static string password = "";
static string arrivalDate = "1970-01-01";
static string irradiationDate = "1970-01-01";
static string annealingDate = "1970-01-01";
static string sentBackDate = "1970-01-01";
static double irradiationDose = -1;
static double irradiationTemp = -300;
static double annealingTemp = -300;
static double annealingTime = -1;
static string change = "";
static bool debug = false;
void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
po::options_description desc("Available options");
desc.add_options()
("help", "produce help message")
("fileName", po::value<string>(), "file name for serial numbers [serials.dat]")
("user", po::value<string>(), "User name to connect to DB. Only used when combined with pass!")
("pass", po::value<string>(), "Password to connect to DB. Only used when combined with user!")
("day", po::value<short>(), "Day of arrival")
("month", po::value<short>(), "Month of arrival")
("year", po::value<short>(), "Year of arrival")
("dose", po::value<double>(), "Irradiation dose to enter")
("temp", po::value<double>(), "Temperature during irradiation")
("debug", "emit additional messages for debugging purposes")
;
po::variables_map vm;
po::store(po::parse_command_line(m_argc, m_argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
exit(0);
}
if (vm.count("fileName")) {
fileName = vm["fileName"].as<string>();
cout << "Reading serials from " << fileName << endl;
}
if (vm.count("user")) {
username = vm["user"].as<string>();
}
if (vm.count("pass")) {
password = vm["pass"].as<string>();
}
if (vm.count("debug")) {
debug = true;
}
}
int main(int argc, char* argv[]) {
QApplication *_app = new QApplication(argc, argv);
processArgumentsAndQueryMissing(argc, argv);
vector<string> apdSerials;
apdSerials = loadSerialsFromFileName(fileName);
if ( apdSerials.size() == 0 ) {
cout << "No data to write! Exiting." << endl;
return 0;
}
cout << "Data will be written for " << apdSerials.size() << " APDs." << endl;
ProductionDatabaseClient *_proddbclient = new ProductionDatabaseClient();
if (username == "" || password == "") _proddbclient->queryCredentials();
else _proddbclient->setCredentials(username, password);
DatabaseClientResponse response = _proddbclient->checkConnectivityAndCredentials();
if (response != Successful ) {
cerr << "Connection to database failed because of error: " << response << endl;
return response;
}
if (debug) cout << "Connection successful!" << endl;
_proddbclient->storeApdIrradiationInfo(apdSerials,dose, temp, irradiationDay,irradiationMonth,irradiationYear);
cout << "\nSuccessfully entered irradiation with " << dose << " Gy at " << temp << "degrees celsius on " << irradiationDay << "." << irradiationMonth << "." << irradiationYear << " to APDs from serial file " << fileName << "!\n\nThank you for using the ApdToolbox! :)" << endl << endl;
_app->exit(0);
return (-apdSerials.empty());
}