Skip to content
Snippets Groups Projects
Commit d3a5a1de authored by Jan Reher's avatar Jan Reher
Browse files

implemented and tested actual function of software. Seems to be working, has...

implemented and tested actual function of software. Seems to be working, has to be cross-checked with DB online interface though.
parent d0bfd3ed
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,9 @@ Thumbs.db
# qtcreator generated files
*.pro.user*
*.txt.user*
build/
# xemacs temporary files
*.flc
......
......@@ -6,4 +6,4 @@ LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/libs)
project(apdBatchSetter)
add_executable(${PROJECT_NAME} "main.cxx")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ProductionDatabase)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ProductionDatabase boost_program_options)
......@@ -2,21 +2,38 @@
#include <vector>
#include <fstream>
#include <productiondatabaseclient.h>
#include <boost/program_options.hpp>
using namespace std;
using namespace ProductionDatabase;
namespace po = boost::program_options;
int main()
static bool irradiatedAPDs = false;
static bool demoMode = false;
static string fileName = "serials.dat";
static uint batchNo = 0;
static bool debug = false;
void readArguments(int m_argc, char* m_argv[]);
int main(int argc, char* argv[])
{
ProductionDatabaseClient *proddb = new ProductionDatabaseClient();
cout << "Intitializing apdBatchSetter with version " << proddb->getVersion() << " of the database access libraries.";
if (debug) cout << "Intitializing apdBatchSetter with version " << proddb->getVersion() << " of the database access libraries." << endl << endl;
readArguments(argc, argv);
if (debug) cout << "Trying to set Batch number " << batchNo << "for ADPs from serial file " << fileName << endl;
vector<string> apdSerials;
string fileName = "serials.dat";
int nAPDs = 0;
ifstream in(fileName.c_str());
if (!in.good()) cerr << "Could not load serials. Does the input file exist?" << endl;
if (!in.good()) {
cerr << "Could not load serials. Does the input file exist?" << endl;
exit(0);
}
apdSerials.clear();
while(in.good()) {
......@@ -25,7 +42,7 @@ int main()
if (!isdigit(newEntry[0])) continue;
nAPDs++;
apdSerials.push_back(newEntry);
cout << "Found APD no. " << nAPDs << ": " << newEntry << endl;
if (debug) cout << "Found APD no. " << nAPDs << ": " << newEntry << endl;
}
proddb->queryCredentials();
......@@ -34,7 +51,80 @@ int main()
cerr << "Connection to database failed because of error: " << response << endl;
return response;
}
cout << "Connection successful!" << endl;
if (debug) cout << "Connection successful!" << endl;
proddb->assignBatchNumberToAPDs(apdSerials,batchNo,irradiatedAPDs);
cout << "\nSuccessfully assigned Batch " << batchNo << " to APDs from serial file " << fileName << "!\n\nThank you for using apdBatchSetter :)" << endl << endl;
return (-apdSerials.empty());
}
void readArguments(int m_argc, char* m_argv[]) {
po::options_description desc("Available options");
desc.add_options()
("help", "produce help message")
("type", po::value<string>(), "(required) type of APDs [new, irr]")
("batch", po::value<int>(), "(required) batch number to be set")
("fileName", po::value<string>(), "file name or serial numbers [serials.dat]")
("demo", "check connectivity without writing any data")
("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("type")) {
if (vm["type"].as<string>() == "new") {
irradiatedAPDs = false;
}
else if (vm["type"].as<string>() == "irr") {
irradiatedAPDs = true;
} else {
cerr << "Invalid type! Possible APD types: 'new' or 'irr'" << endl;
exit(0);
}
} else {
string temp = "";
cout << "Have these APDs been irradiated? (yes / no)" << endl;
cin >> temp;
if (temp == "yes" || temp == "y") {
irradiatedAPDs = true;
}
else if (temp == "no" || temp == "n") {
irradiatedAPDs = false;
}
else {
cerr << "Come on, you can't even give me a straight answer on that one? I'm sick of this. I'm leaving. Try again when you have the information you need." << endl;
exit(0);
}
}
if (vm.count("batch")) {
batchNo = uint(vm["batch"].as<int>());
} else {
cout << "Which Batch do these APDs belong to?" << endl;
try {
cin >> batchNo;
} catch (...) {
batchNo = 0;
}
if (batchNo <= 0) {
cerr << "Invalid batch number!" << endl;
}
}
if (vm.count("fileName")) {
fileName = vm["fileName"].as<string>();
cout << "Reading serials from " << fileName << endl;
}
if (vm.count("demo")) {
cout << "Running in demo mode. No data will be written!" << endl;
demoMode = true;
}
if (vm.count("debug")) {
debug = true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment