From 3aac9e99d61fc3eca4829ce7d7cb44e60d192c46 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 09:24:29 +0100
Subject: [PATCH 01/20] Creation of unit Creator files as copy from BoxSetter

---
 CMakeLists.txt     |   2 +
 apdUnitCreator.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
 create mode 100644 apdUnitCreator.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2b2a84..9d8f504 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,7 @@ add_executable(getU100 "getu100.cxx")
 add_executable(makeSerialList "makeseriallist.cxx")
 add_executable(makeGridList "makeGridList.cxx")
 add_executable(getIrradiationDose "getirradiationstatus.cxx")
+add_executable(apdUnitCreator "apdUnitCreator.cpp")
 
 add_executable(testXmlStructure "testxmlstructure.cxx")
 
@@ -35,6 +36,7 @@ target_link_libraries(proddbaccess Qt5::Network Qt5::Core Qt5::Xml)
 target_link_libraries(apdBatchSetter proddbaccess proddbclient boost_program_options)
 target_link_libraries(apdBoxSetter proddbaccess proddbclient boost_program_options)
 target_link_libraries(apdUnavailableSetter proddbaccess proddbclient boost_program_options)
+target_link_libraries(apdUnitCreator)
 target_link_libraries(getLocations proddbaccess boost_program_options)
 target_link_libraries(getBatch proddbaccess boost_program_options)
 target_link_libraries(getIrradiationDose proddbaccess boost_program_options)
diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
new file mode 100644
index 0000000..4574470
--- /dev/null
+++ b/apdUnitCreator.cpp
@@ -0,0 +1,138 @@
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <vector>
+
+#include <productiondatabaseclient.h>
+#include <boost/program_options.hpp>
+
+using namespace std;
+using namespace ProductionDatabase;
+namespace po = boost::program_options;
+
+static string fileName = "serials.dat";
+static int boxNo = 0;
+static bool debug = false;
+static string username = "";
+static string password = "";
+
+static vector<string> apdSerials;
+static std::vector<int> boxes;
+static std::vector<int> positions;
+
+void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]);
+void loadSerialsFromFileName(string m_fileName, bool m_debug = false);
+
+int main(int argc, char* argv[]) {
+    ProductionDatabaseClient *proddb = new ProductionDatabaseClient();
+    processArgumentsAndQueryMissing(argc, argv);
+
+    if (debug) cout << "Intitialized apdBoxSetter with version " << proddb->getVersion() << " of the database access libraries." << endl << endl
+                    << "Now trying to set Batch number " << boxNo << " for ADPs from serial file " << fileName << endl;
+
+    loadSerialsFromFileName(fileName);
+
+    if (username == "" || password == "") proddb->queryCredentials();
+    else proddb->setCredentials(username, password);
+    DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
+    if (response != Successful ) {
+        cerr << "Connection to database failed because of error: " << response << endl;
+        return response;
+    }
+    if (debug) cout << "Connection successful!" << endl;
+
+    proddb->storeApdBoxNumber(apdSerials,boxes,positions);
+
+    cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
+         << "\nThank you for using apdBoxSetter! :)" << endl << endl;
+
+    return (-apdSerials.empty());
+}
+
+void processArgumentsAndQueryMissing(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]")
+            ("box", po::value<int>(), "(required) box number to be assigned")
+            ("fileName", po::value<string>(), "file name or serial numbers [serials.dat]")
+            ("debug", "emit additional messages for debugging purposes")
+            ("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!")
+            ;
+    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("box")) {
+        boxNo = int(vm["box"].as<int>());
+    } else {
+        cout << "Which box should these APDs be assigned to?" << endl;
+        try {
+            cin >> boxNo;
+            cout << endl;
+        } catch (...) {
+            boxNo = 0;
+        }
+        if (boxNo <= 0) {
+            cerr << "Invalid batch number!" << endl;
+            exit(-1);
+        }
+    }
+    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;
+    }
+}
+
+void loadSerialsFromFileName(string m_fileName, bool m_debug) {
+    ifstream in(m_fileName.c_str());
+    if (!in.good()) {
+        cerr << "Could not load serials. Does the input file exist?" << endl;
+        exit(0);
+    }
+
+    apdSerials.clear();
+    positions.clear();
+    boxes.clear();
+
+    int pos = 1;
+
+    string line = "";
+    while (in.good()) {
+        getline(in,line);
+        if (line.length() == 0 || !isdigit(line[0])) {
+          pos++;
+          continue;
+        }
+        apdSerials.push_back(line);
+        boxes.push_back(boxNo);
+        positions.push_back(pos++);
+        if (m_debug) cout << "Found serial: " << line << endl;
+    }
+    if (apdSerials.size() != positions.size() || apdSerials.size() != boxes.size()) {
+      cerr << "ERROR: Array sizes don't match!" << endl;
+      apdSerials.clear();
+      boxes.clear();
+      positions.clear();
+      return;
+    }
+    cerr << "Found " << apdSerials.size() << " APDs" << endl;
+    return;
+}
+
+
-- 
GitLab


From 325a1f443103fb1f6142ababe16859646e2b16b9 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 09:42:44 +0100
Subject: [PATCH 02/20] Implemented reading of csv config file in test mode
 (very verbose).

---
 CMakeLists.txt     |  1 +
 apdUnitCreator.cpp | 77 +++++++++++++++++++---------------------------
 2 files changed, 32 insertions(+), 46 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9d8f504..3e18e0f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,7 @@ find_package(Qt5 COMPONENTS Core Gui Widgets Network Xml)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/includes/)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/proddb/)
 INCLUDE_DIRECTORIES($ENV{proddb_clientlib_includes})
+INCLUDE_DIRECTORIES("/home/tau/jreher/git/proddb-clientlib")
 LINK_DIRECTORIES($ENV{proddb_clientlib_libpath})
 
 add_library(toolbox "toolbox.cpp" "serialListReader.h" "serialListReader.cxx" "gridListReader.h" "gridListReader.cxx")
diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 4574470..e2274b8 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -11,15 +11,20 @@ using namespace std;
 using namespace ProductionDatabase;
 namespace po = boost::program_options;
 
+struct unitInfo {
+    std::string redSerial = "";
+    std::string blueSerial = "";
+    std::string crystalSerial = "";
+    std::string barCode = "";
+};
+
 static string fileName = "serials.dat";
 static int boxNo = 0;
 static bool debug = false;
 static string username = "";
 static string password = "";
 
-static vector<string> apdSerials;
-static std::vector<int> boxes;
-static std::vector<int> positions;
+static vector<unitInfo> newUnits;
 
 void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]);
 void loadSerialsFromFileName(string m_fileName, bool m_debug = false);
@@ -33,29 +38,27 @@ int main(int argc, char* argv[]) {
 
     loadSerialsFromFileName(fileName);
 
-    if (username == "" || password == "") proddb->queryCredentials();
-    else proddb->setCredentials(username, password);
-    DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
-    if (response != Successful ) {
-        cerr << "Connection to database failed because of error: " << response << endl;
-        return response;
-    }
-    if (debug) cout << "Connection successful!" << endl;
+//    if (username == "" || password == "") proddb->queryCredentials();
+//    else proddb->setCredentials(username, password);
+//    DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
+//    if (response != Successful ) {
+//        cerr << "Connection to database failed because of error: " << response << endl;
+//        return response;
+//    }
+//    if (debug) cout << "Connection successful!" << endl;
+
 
-    proddb->storeApdBoxNumber(apdSerials,boxes,positions);
 
-    cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
-         << "\nThank you for using apdBoxSetter! :)" << endl << endl;
+//    cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
+//         << "\nThank you for using apdBoxSetter! :)" << endl << endl;
 
-    return (-apdSerials.empty());
+    return (-newUnits.empty());
 }
 
 void processArgumentsAndQueryMissing(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]")
-            ("box", po::value<int>(), "(required) box number to be assigned")
             ("fileName", po::value<string>(), "file name or serial numbers [serials.dat]")
             ("debug", "emit additional messages for debugging purposes")
             ("user", po::value<string>(), "User name to connect to DB. Only used when combined with pass!")
@@ -69,21 +72,6 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
         cout << desc << "\n";
         exit(0);
     }
-    if (vm.count("box")) {
-        boxNo = int(vm["box"].as<int>());
-    } else {
-        cout << "Which box should these APDs be assigned to?" << endl;
-        try {
-            cin >> boxNo;
-            cout << endl;
-        } catch (...) {
-            boxNo = 0;
-        }
-        if (boxNo <= 0) {
-            cerr << "Invalid batch number!" << endl;
-            exit(-1);
-        }
-    }
     if (vm.count("fileName")) {
         fileName = vm["fileName"].as<string>();
         cout << "Reading serials from " << fileName << endl;
@@ -106,9 +94,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         exit(0);
     }
 
-    apdSerials.clear();
-    positions.clear();
-    boxes.clear();
+    newUnits.clear();
 
     int pos = 1;
 
@@ -119,19 +105,18 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
           pos++;
           continue;
         }
-        apdSerials.push_back(line);
-        boxes.push_back(boxNo);
-        positions.push_back(pos++);
+        unitInfo newUnit;
+
+        std::stringstream linestream(line);
+        linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> newUnit.barCode;
+
+        std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
+        newUnits.push_back(newUnit);
+
         if (m_debug) cout << "Found serial: " << line << endl;
     }
-    if (apdSerials.size() != positions.size() || apdSerials.size() != boxes.size()) {
-      cerr << "ERROR: Array sizes don't match!" << endl;
-      apdSerials.clear();
-      boxes.clear();
-      positions.clear();
-      return;
-    }
-    cerr << "Found " << apdSerials.size() << " APDs" << endl;
+
+    cerr << "Found " << newUnits.size() << " new Units to be entered." << endl;
     return;
 }
 
-- 
GitLab


From 703c269fa2e41542e790f83eebf7d6c3fb0ec4e5 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 09:46:14 +0100
Subject: [PATCH 03/20] Fixed linking for unitCreator

---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e18e0f..347952f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,7 +37,7 @@ target_link_libraries(proddbaccess Qt5::Network Qt5::Core Qt5::Xml)
 target_link_libraries(apdBatchSetter proddbaccess proddbclient boost_program_options)
 target_link_libraries(apdBoxSetter proddbaccess proddbclient boost_program_options)
 target_link_libraries(apdUnavailableSetter proddbaccess proddbclient boost_program_options)
-target_link_libraries(apdUnitCreator)
+target_link_libraries(apdUnitCreator proddbclient boost_program_options)
 target_link_libraries(getLocations proddbaccess boost_program_options)
 target_link_libraries(getBatch proddbaccess boost_program_options)
 target_link_libraries(getIrradiationDose proddbaccess boost_program_options)
-- 
GitLab


From 1c6a127e171155f7a8b584a1648f0b5449adccc3 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 10:13:36 +0100
Subject: [PATCH 04/20] Extension of apdUnitCreator

---
 apdUnitCreator.cpp | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index e2274b8..735e553 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -30,24 +30,29 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]);
 void loadSerialsFromFileName(string m_fileName, bool m_debug = false);
 
 int main(int argc, char* argv[]) {
-    ProductionDatabaseClient *proddb = new ProductionDatabaseClient();
     processArgumentsAndQueryMissing(argc, argv);
+    ProductionDatabaseClient *proddb = new ProductionDatabaseClient();
 
     if (debug) cout << "Intitialized apdBoxSetter with version " << proddb->getVersion() << " of the database access libraries." << endl << endl
                     << "Now trying to set Batch number " << boxNo << " for ADPs from serial file " << fileName << endl;
 
     loadSerialsFromFileName(fileName);
 
-//    if (username == "" || password == "") proddb->queryCredentials();
-//    else proddb->setCredentials(username, password);
-//    DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
-//    if (response != Successful ) {
-//        cerr << "Connection to database failed because of error: " << response << endl;
-//        return response;
-//    }
-//    if (debug) cout << "Connection successful!" << endl;
-
+    if (username == "" || password == "") proddb->queryCredentials();
+    else proddb->setCredentials(username, password);
+    DatabaseClientResponse response = proddb->checkConnectivityAndCredentials();
+    if (response != Successful ) {
+        cerr << "Connection to database failed because of error: " << response << endl;
+        return response;
+    }
+    if (debug) cout << "Connection successful!" << endl;
 
+    for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
+        //proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
+        std::string capsuleSerial = newUnit->redSerial + "/" + newUnit->blueSerial;
+        std::cerr << "Capsule serial should be " << capsuleSerial << std::endl;
+        //proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
+    }
 
 //    cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
 //         << "\nThank you for using apdBoxSetter! :)" << endl << endl;
-- 
GitLab


From fdc7ad946ebaed472795513e75423fb458a92c95 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 10:24:28 +0100
Subject: [PATCH 05/20] Commented in the lines in apdUnitCreator.cpp that do
 the actual database work. Test on test DB!

---
 apdUnitCreator.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 735e553..96cbfe8 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -48,14 +48,12 @@ int main(int argc, char* argv[]) {
     if (debug) cout << "Connection successful!" << endl;
 
     for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
-        //proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
+        proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
         std::string capsuleSerial = newUnit->redSerial + "/" + newUnit->blueSerial;
-        std::cerr << "Capsule serial should be " << capsuleSerial << std::endl;
-        //proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
+        proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
     }
 
-//    cout << "\nBox " << boxNo << " was successfully assigned to APDs from serial file " << fileName << ". At least I hope so. In any case, something happened for " << apdSerials.size() << " APDs."
-//         << "\nThank you for using apdBoxSetter! :)" << endl << endl;
+    cout << "Created " << newUnits.size() << " APD Capsules and assigned them to Units.";
 
     return (-newUnits.empty());
 }
-- 
GitLab


From e9d93e9a535237f6ac5775a7267fdc1e39295123 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 10:33:16 +0100
Subject: [PATCH 06/20] Fixed the way the capsule serial is created.

---
 apdUnitCreator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 96cbfe8..7953e1e 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -49,7 +49,7 @@ int main(int argc, char* argv[]) {
 
     for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
         proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
-        std::string capsuleSerial = newUnit->redSerial + "/" + newUnit->blueSerial;
+        std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
         proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
     }
 
-- 
GitLab


From 9e8fa62347fe9f8246df4b9cdbecc949a31bfb2b Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 11:08:58 +0100
Subject: [PATCH 07/20] Added exception handling to process further APDs if one
 step fails.

---
 apdUnitCreator.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 7953e1e..ed0b068 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -48,9 +48,16 @@ int main(int argc, char* argv[]) {
     if (debug) cout << "Connection successful!" << endl;
 
     for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
-        proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
-        std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
-        proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
+        try {
+            proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
+            std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
+            proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
+        }
+        catch (exception e) {
+            std::cerr << "An error occurred on APD paid with red APD " << newUnit->redSerial << " and blue APD " << newUnit->blueSerial << "!" << std::endl;
+            std::cerr << e.what();
+            continue;
+        }
     }
 
     cout << "Created " << newUnits.size() << " APD Capsules and assigned them to Units.";
-- 
GitLab


From 3341e4612ba38e4dcfc855d26c983236b0db22e6 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 11:20:10 +0100
Subject: [PATCH 08/20] Cleaner error handling? Maybe?

---
 apdUnitCreator.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index ed0b068..be132ef 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -47,20 +47,24 @@ int main(int argc, char* argv[]) {
     }
     if (debug) cout << "Connection successful!" << endl;
 
+    int nFailed = 0;
     for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
         try {
             proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
             std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
             proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
         }
-        catch (exception e) {
+        catch (std::exception e) {
+            nFailed++;
             std::cerr << "An error occurred on APD paid with red APD " << newUnit->redSerial << " and blue APD " << newUnit->blueSerial << "!" << std::endl;
-            std::cerr << e.what();
+            std::cerr << e.what() << std::endl << std::endl;
             continue;
         }
     }
 
-    cout << "Created " << newUnits.size() << " APD Capsules and assigned them to Units.";
+    cout << "Created " << newUnits.size() << " APD Capsules and assigned them to Units." << std::endl;
+    if (nFailed > 0)
+        cerr << "Data entry failed for " << nFailed << " entries!" << std::endl;
 
     return (-newUnits.empty());
 }
-- 
GitLab


From 685a9659d2604a67ea3b04ff34e519d3c2f4b266 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 27 Mar 2020 11:22:41 +0100
Subject: [PATCH 09/20] Fixed problem with exception handling

---
 apdUnitCreator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index be132ef..80443da 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
             std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
             proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
         }
-        catch (std::exception e) {
+        catch (std::exception &e) {
             nFailed++;
             std::cerr << "An error occurred on APD paid with red APD " << newUnit->redSerial << " and blue APD " << newUnit->blueSerial << "!" << std::endl;
             std::cerr << e.what() << std::endl << std::endl;
-- 
GitLab


From 6fd05479015f2c55e56f9ec1ee239ba9116e71f9 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Mon, 30 Mar 2020 11:31:23 +0200
Subject: [PATCH 10/20] Implemented more comfortable way of entering barcodes
 (as short). Disabled database connection for testing.

---
 apdUnitCreator.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 80443da..3c0857d 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -121,11 +121,17 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         }
         unitInfo newUnit;
 
+        uint barCode;
+
         std::stringstream linestream(line);
-        linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> newUnit.barCode;
+        linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> barCode;
+
+        if (barCode <1000000 )
+        barCode += 1909000000;
+        newUnit.barCode = std::to_string(barCode);
 
         std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
-        newUnits.push_back(newUnit);
+        //newUnits.push_back(newUnit);
 
         if (m_debug) cout << "Found serial: " << line << endl;
     }
-- 
GitLab


From 908f483ce51f3b8eb2fdaffcbc039025e4a7e1d7 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Mon, 30 Mar 2020 11:56:57 +0200
Subject: [PATCH 11/20] Temporarily disabling CI/CD until I can fix issues with
 runner

---
 .gitlab-ci.yml => .gitlab-ci.yml.tempoff | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename .gitlab-ci.yml => .gitlab-ci.yml.tempoff (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml.tempoff
similarity index 100%
rename from .gitlab-ci.yml
rename to .gitlab-ci.yml.tempoff
-- 
GitLab


From 19da1033735296b952b4f549addb9f5302f286ac Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 08:41:48 +0200
Subject: [PATCH 12/20] Re-enabling database connection after successful tests.

---
 apdUnitCreator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index 3c0857d..c12cfdb 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -131,7 +131,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         newUnit.barCode = std::to_string(barCode);
 
         std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
-        //newUnits.push_back(newUnit);
+        newUnits.push_back(newUnit);
 
         if (m_debug) cout << "Found serial: " << line << endl;
     }
-- 
GitLab


From cc311d87b9853f20b52be1eb6311ec389028bf43 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 08:44:58 +0200
Subject: [PATCH 13/20] Fixed incorrect number for barcodes

---
 apdUnitCreator.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index c12cfdb..b62f936 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -127,7 +127,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> barCode;
 
         if (barCode <1000000 )
-        barCode += 1909000000;
+        barCode += 1309000000;
         newUnit.barCode = std::to_string(barCode);
 
         std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
-- 
GitLab


From 6042d45cc2e1dd978d1e6a64481c90cbc9a8ca2a Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 10:51:50 +0200
Subject: [PATCH 14/20] Changed TestXmlStructure.cxx to output a structure for
 unit assignment to module

---
 testxmlstructure.cxx | 49 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/testxmlstructure.cxx b/testxmlstructure.cxx
index f696d32..e1fb364 100644
--- a/testxmlstructure.cxx
+++ b/testxmlstructure.cxx
@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include <QtCore/QString>
-#include <QtXml/QXmlStreamWriter>
+#include <QXML/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
 #include "productiondatabaseclient.h"
 
 ProductionDatabase::ProductionDatabaseClient *proddbclient;
@@ -11,13 +11,20 @@ void initialize();
 void screeningInfo();
 void assignApds(std::string redSerial, std::string blueSerial);
 void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode);
+void assignToModule(std::vector<uint> barcodes, std::string moduleSN);
 
 int main() {
   initialize();
-  assignApds("0607004597", "0607004598" );
-  assignApds("0607004600", "0607004601" );
-  assignUnit("0607004598/0607004597","790","1309009220");
-  assignUnit("0607004601/0607004600","790","1309009237");
+  std::vector<uint> barcodes;
+  barcodes.push_back(1309009619);
+  barcodes.push_back(1309009602);
+  barcodes.push_back(1309009633);
+  barcodes.push_back(1309009664);
+  barcodes.push_back(1309009657);
+  barcodes.push_back(1309009696);
+  barcodes.push_back(1309009640);
+  barcodes.push_back(1309009626);
+  assignToModule(barcodes, "29012015-9");
   return 0;
 }
 
@@ -28,6 +35,38 @@ void initialize() {
   proddbclient->checkConnectivityAndCredentials();
 }
 
+void assignToModule(std::vector<uint> barcodes, std::string moduleSN) {
+  QString buffer;
+  QXmlStreamWriter xml ( &buffer );
+
+  xml.setAutoFormatting(true);
+  xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
+  xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
+  xml.writeTextElement("moduleSN",QString::fromStdString(moduleSN));
+  xml.writeEmptyElement("Slot0");
+  xml.writeEmptyElement("Slot1");
+  xml.writeEmptyElement("Slot2");
+  xml.writeEmptyElement("Slot3");
+  xml.writeEmptyElement("Slot4");
+  xml.writeEmptyElement("Slot5");
+  xml.writeEmptyElement("Slot6");
+  xml.writeEmptyElement("Slot7");
+  xml.writeTextElement("Slot8",QString::number(barcodes[0]));
+  xml.writeTextElement("Slot9",QString::number(barcodes[1] ));
+  xml.writeTextElement("SlotA",QString::number(barcodes[2] ));
+  xml.writeTextElement("SlotB",QString::number(barcodes[3] ));
+  xml.writeTextElement("SlotC",QString::number(barcodes[4] ));
+  xml.writeTextElement("SlotD",QString::number(barcodes[5] ));
+  xml.writeTextElement("SlotE",QString::number(barcodes[6] ));
+  xml.writeTextElement("SlotF",QString::number(barcodes[7] ));
+  xml.writeEndDocument();
+
+  std::string xmlRequest = buffer.toStdString();
+  std::cerr << xmlRequest << std::endl;
+
+  //proddbclient->postXmlRequest("",xmlRequest);
+}
+
 void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode) {
   QString buffer;
   QXmlStreamWriter xml ( &buffer );
-- 
GitLab


From 5b1ea4dbd90caea7cc166f763edc0f8be13348d8 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 10:53:31 +0200
Subject: [PATCH 15/20] Fixed #include error

---
 testxmlstructure.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testxmlstructure.cxx b/testxmlstructure.cxx
index e1fb364..15f33d9 100644
--- a/testxmlstructure.cxx
+++ b/testxmlstructure.cxx
@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include <QtCore/QString>
-#include <QXML/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
+#include <QXml/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
 #include "productiondatabaseclient.h"
 
 ProductionDatabase::ProductionDatabaseClient *proddbclient;
-- 
GitLab


From 428ea06dff0573ad3b0a7129cc1dd9b61d4a8131 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 10:59:25 +0200
Subject: [PATCH 16/20] Me DumDum

---
 testxmlstructure.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testxmlstructure.cxx b/testxmlstructure.cxx
index 15f33d9..54dc9f3 100644
--- a/testxmlstructure.cxx
+++ b/testxmlstructure.cxx
@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include <QtCore/QString>
-#include <QXml/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
+#include <QtXml/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
 #include "productiondatabaseclient.h"
 
 ProductionDatabase::ProductionDatabaseClient *proddbclient;
-- 
GitLab


From a485021421da6d64c4bf5a4bf8455df43e7fceb5 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Tue, 31 Mar 2020 11:25:49 +0200
Subject: [PATCH 17/20] Testing TestXmlStructure

---
 testxmlstructure.cxx | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/testxmlstructure.cxx b/testxmlstructure.cxx
index 54dc9f3..6846eb2 100644
--- a/testxmlstructure.cxx
+++ b/testxmlstructure.cxx
@@ -16,6 +16,14 @@ void assignToModule(std::vector<uint> barcodes, std::string moduleSN);
 int main() {
   initialize();
   std::vector<uint> barcodes;
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
+  barcodes.push_back(0);
   barcodes.push_back(1309009619);
   barcodes.push_back(1309009602);
   barcodes.push_back(1309009633);
@@ -36,6 +44,10 @@ void initialize() {
 }
 
 void assignToModule(std::vector<uint> barcodes, std::string moduleSN) {
+  if (barcodes.size() != 16) {
+    throw "Vector with barcodes must contain exactly 16 elements!";
+  }
+
   QString buffer;
   QXmlStreamWriter xml ( &buffer );
 
@@ -43,22 +55,15 @@ void assignToModule(std::vector<uint> barcodes, std::string moduleSN) {
   xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
   xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
   xml.writeTextElement("moduleSN",QString::fromStdString(moduleSN));
-  xml.writeEmptyElement("Slot0");
-  xml.writeEmptyElement("Slot1");
-  xml.writeEmptyElement("Slot2");
-  xml.writeEmptyElement("Slot3");
-  xml.writeEmptyElement("Slot4");
-  xml.writeEmptyElement("Slot5");
-  xml.writeEmptyElement("Slot6");
-  xml.writeEmptyElement("Slot7");
-  xml.writeTextElement("Slot8",QString::number(barcodes[0]));
-  xml.writeTextElement("Slot9",QString::number(barcodes[1] ));
-  xml.writeTextElement("SlotA",QString::number(barcodes[2] ));
-  xml.writeTextElement("SlotB",QString::number(barcodes[3] ));
-  xml.writeTextElement("SlotC",QString::number(barcodes[4] ));
-  xml.writeTextElement("SlotD",QString::number(barcodes[5] ));
-  xml.writeTextElement("SlotE",QString::number(barcodes[6] ));
-  xml.writeTextElement("SlotF",QString::number(barcodes[7] ));
+
+  for (size_t i = 0; i < 16; i++) {
+    std::string entryname = std::string("Slot") + std::to_string(i);
+    if (barcodes[i]==0)
+        xml.writeEmptyElement(QString::fromStdString(entryname));
+    else
+        xml.writeTextElement(QString::fromStdString(entryname),QString::number(barcodes[i]));
+  }
+
   xml.writeEndDocument();
 
   std::string xmlRequest = buffer.toStdString();
-- 
GitLab


From e8475a188d89957aa9057ba514b916a0d2ebd231 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Wed, 1 Apr 2020 12:02:45 +0200
Subject: [PATCH 18/20] Implemented piece to option units to submodule.

---
 apdUnitCreator.cpp | 70 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 12 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index b62f936..de153d5 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -15,7 +15,7 @@ struct unitInfo {
     std::string redSerial = "";
     std::string blueSerial = "";
     std::string crystalSerial = "";
-    std::string barCode = "";
+    uint barCode = 0;
 };
 
 static string fileName = "serials.dat";
@@ -24,6 +24,11 @@ static bool debug = false;
 static string username = "";
 static string password = "";
 
+std::string moduleSN;
+static bool makeCapsules = true;
+static bool makeUnits = true;
+static bool assignToModule = false;
+
 static vector<unitInfo> newUnits;
 
 void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]);
@@ -48,11 +53,24 @@ int main(int argc, char* argv[]) {
     if (debug) cout << "Connection successful!" << endl;
 
     int nFailed = 0;
+
+    std::vector<uint> barcodes;
+    if (assignToModule && newUnits.size() == 8)
+        for (size_t i = 0; i < 8; i++)
+            barcodes.push_back(0);
+
     for (auto newUnit = newUnits.begin(); newUnit < newUnits.end(); newUnit++) {
         try {
-            proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
-            std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
-            proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, newUnit->barCode);
+            if (makeCapsules) {
+                proddb->createApdCapsule(newUnit->redSerial, newUnit->blueSerial);
+            }
+            if (makeUnits) {
+                std::string capsuleSerial = newUnit->blueSerial + "/" + newUnit->redSerial;
+                proddb->createApdUnit(capsuleSerial, newUnit->crystalSerial, std::to_string(newUnit->barCode));
+            }
+            if (assignToModule) {
+                barcodes.push_back(newUnit->barCode);
+            }
         }
         catch (std::exception &e) {
             nFailed++;
@@ -62,6 +80,20 @@ int main(int argc, char* argv[]) {
         }
     }
 
+    if (assignToModule) {
+        if (barcodes.size() != 16)
+            cerr << "Assignments are only possible if there are 8 or 16 Units in file!" << std::endl;
+        else {
+            try {
+                proddb->assignUnitToModule(moduleSN, barcodes);
+            }
+            catch (std::exception &e) {
+                std::cerr << "An error occurred while assigning APDs to Module " << moduleSN << std::endl;
+                std::cerr << e.what() << std::endl << std::endl;
+            }
+        }
+    }
+
     cout << "Created " << newUnits.size() << " APD Capsules and assigned them to Units." << std::endl;
     if (nFailed > 0)
         cerr << "Data entry failed for " << nFailed << " entries!" << std::endl;
@@ -74,6 +106,9 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
     desc.add_options()
             ("help", "produce help message")
             ("fileName", po::value<string>(), "file name or serial numbers [serials.dat]")
+            ("noMakeCapsules", "Skip the step of creating capsules from APDs")
+            ("noMakeUnits", "Skip the step of creating units from capsules")
+            ("assignToModule", po::value<string>(), "Skip the step of assigning units to submodules")
             ("debug", "emit additional messages for debugging purposes")
             ("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!")
@@ -90,6 +125,19 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
         fileName = vm["fileName"].as<string>();
         cout << "Reading serials from " << fileName << endl;
     }
+    if (vm.count("noMakeCapsules")) {
+        cout << "Skipping capsule creation. Only works if capsules already exist!";
+        makeCapsules = false;
+    }
+    if (vm.count("noMakeUnits")) {
+        cout << "Skipping unit creation. Module assignment only works if units already exist!";
+        makeUnits= false;
+    }
+    if (vm.count("assignToModule")) {
+        moduleSN = vm["assignToModule"].as<string>();
+        cout << "Will assign units to submodule " << moduleSN << std::endl;
+        assignToModule = true;
+    }
     if (vm.count("user")) {
         username = vm["user"].as<string>();
     }
@@ -121,19 +169,17 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         }
         unitInfo newUnit;
 
-        uint barCode;
+        uint barcode;
 
         std::stringstream linestream(line);
-        linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> barCode;
+        linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> barcode;
 
-        if (barCode <1000000 )
-        barCode += 1309000000;
-        newUnit.barCode = std::to_string(barCode);
+        if (barcode <1000000 )
+        barcode += 1309000000;
+        newUnit.barCode = barcode;
 
-        std::cerr << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
+        if (m_debug) std::cout << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
         newUnits.push_back(newUnit);
-
-        if (m_debug) cout << "Found serial: " << line << endl;
     }
 
     cerr << "Found " << newUnits.size() << " new Units to be entered." << endl;
-- 
GitLab


From eda4e93c5fa32e0820bdee64e71a1b134c7fe9f5 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Wed, 1 Apr 2020 12:25:30 +0200
Subject: [PATCH 19/20] Added safeguards for wrong file names. No more default
 file name!

---
 apdUnitCreator.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index de153d5..c313742 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -125,12 +125,15 @@ void processArgumentsAndQueryMissing(int m_argc, char* m_argv[]) {
         fileName = vm["fileName"].as<string>();
         cout << "Reading serials from " << fileName << endl;
     }
+    else {
+        throw "Please enter a file name!";
+    }
     if (vm.count("noMakeCapsules")) {
-        cout << "Skipping capsule creation. Only works if capsules already exist!";
+        cout << "Skipping capsule creation. Only works if capsules already exist!" << endl;
         makeCapsules = false;
     }
     if (vm.count("noMakeUnits")) {
-        cout << "Skipping unit creation. Module assignment only works if units already exist!";
+        cout << "Skipping unit creation. Module assignment only works if units already exist!" << endl;
         makeUnits= false;
     }
     if (vm.count("assignToModule")) {
@@ -174,6 +177,7 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         std::stringstream linestream(line);
         linestream >> newUnit.redSerial >> newUnit.blueSerial >> newUnit.crystalSerial >> barcode;
 
+        if (barcode == 0) continue;
         if (barcode <1000000 )
         barcode += 1309000000;
         newUnit.barCode = barcode;
-- 
GitLab


From a71fd1c8f7f933bb4d773d6e2728d5da779a5670 Mon Sep 17 00:00:00 2001
From: Jan Reher <jreher@ep1.rub.de>
Date: Fri, 16 Apr 2021 10:00:46 +0200
Subject: [PATCH 20/20] neglected updates

---
 .gitignore                                |  2 +
 apdSetAnnealingInfo.cpp                   |  2 +-
 apdSetIrradiationInfo.cpp                 |  2 +-
 apdSetSentForAnalysisAfterIrradiation.cpp |  2 +-
 apdUnitCreator.cpp                        |  3 +-
 apdlocationsetter.cpp                     |  5 +-
 apdsetarrivalforirradiation.cpp           |  2 +-
 makeseriallist.cxx                        | 32 +++++++---
 makeseriallist2.cxx                       | 77 +++++++++++++++++++++++
 proddb/AbsDbAccess.h                      |  1 +
 proddb/BulkDbAccess.cxx                   |  2 +-
 proddb/BulkDbAccess.h                     |  2 +-
 proddb/ProdDbAccess.cxx                   |  2 +-
 proddb/ProdDbAccess.h                     |  2 +-
 proddb/ProductionDatabase.cxx             |  2 +-
 proddb/ProductionDatabase.h               |  2 +-
 proddb/ProductionDatabaseApdStorage.cxx   |  2 +-
 proddb/ProductionDatabaseApdStorage.h     |  2 +-
 testxmlstructure.cxx                      |  2 +-
 19 files changed, 123 insertions(+), 23 deletions(-)
 create mode 100644 makeseriallist2.cxx
 create mode 120000 proddb/AbsDbAccess.h

diff --git a/.gitignore b/.gitignore
index b41bd80..3922bd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,8 @@
 # This file is used to ignore files which are generated
 # ----------------------------------------------------------------------------
 
+CMakeFiles/
+
 *~
 *.autosave
 *.a
diff --git a/apdSetAnnealingInfo.cpp b/apdSetAnnealingInfo.cpp
index 52a9987..a7e54e1 100644
--- a/apdSetAnnealingInfo.cpp
+++ b/apdSetAnnealingInfo.cpp
@@ -9,7 +9,7 @@
 #include "toolbox.cpp"
 #include "BulkDbAccess.h"
 
-#include "QtGui/QApplication"
+#include "QApplication"
 
 namespace po=boost::program_options;
 using namespace std;
diff --git a/apdSetIrradiationInfo.cpp b/apdSetIrradiationInfo.cpp
index ddc40a1..b206c91 100644
--- a/apdSetIrradiationInfo.cpp
+++ b/apdSetIrradiationInfo.cpp
@@ -9,7 +9,7 @@
 #include "toolbox.cpp"
 #include "BulkDbAccess.h"
 
-#include "QtGui/QApplication"
+#include "QApplication"
 
 namespace po=boost::program_options;
 using namespace std;
diff --git a/apdSetSentForAnalysisAfterIrradiation.cpp b/apdSetSentForAnalysisAfterIrradiation.cpp
index 89d1ac8..8d139da 100644
--- a/apdSetSentForAnalysisAfterIrradiation.cpp
+++ b/apdSetSentForAnalysisAfterIrradiation.cpp
@@ -9,7 +9,7 @@
 #include "toolbox.cpp"
 #include "BulkDbAccess.h"
 
-#include "QtGui/QApplication"
+#include "QApplication"
 
 namespace po=boost::program_options;
 using namespace std;
diff --git a/apdUnitCreator.cpp b/apdUnitCreator.cpp
index c313742..10095d9 100644
--- a/apdUnitCreator.cpp
+++ b/apdUnitCreator.cpp
@@ -182,7 +182,8 @@ void loadSerialsFromFileName(string m_fileName, bool m_debug) {
         barcode += 1309000000;
         newUnit.barCode = barcode;
 
-        if (m_debug) std::cout << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
+        std::cout << "Found new unit with RS = " << newUnit.redSerial << ", BS = " << newUnit.blueSerial << ", CS = " << newUnit.crystalSerial << ", BC = " << newUnit.barCode << std::endl;
+        
         newUnits.push_back(newUnit);
     }
 
diff --git a/apdlocationsetter.cpp b/apdlocationsetter.cpp
index 876d5db..03cb467 100644
--- a/apdlocationsetter.cpp
+++ b/apdlocationsetter.cpp
@@ -3,13 +3,14 @@
 #include <iomanip>
 #include <string>
 #include <vector>
+#include <regex>
 
 #include <productiondatabaseclient.h>
 #include <boost/program_options.hpp>
 #include "toolbox.cpp"
 #include "BulkDbAccess.h"
 
-#include "QtGui/QApplication"
+#include "QApplication"
 
 namespace po=boost::program_options;
 using namespace std;
@@ -100,7 +101,7 @@ int main(int argc, char* argv[]) {
   for ( size_t i = 0 ; i < allApdSerials.size() ; i++ ) {
     string existinglocation = _proddb->location( uint( stoul( allApdSerials[i] ) ) );
     if ( existinglocation != newLocation && ( !unknownonly || existinglocation == "unknown" || existinglocation == "Bochum" || existinglocation == change ) )
-          apdSerials.push_back(allApdSerials[i]);
+          apdSerials.push_back(std::regex_replace(allApdSerials[i],std::regex(R"([\D])"), ""));
   }
 
   if ( apdSerials.size() == 0 ) {
diff --git a/apdsetarrivalforirradiation.cpp b/apdsetarrivalforirradiation.cpp
index 26ca5fc..e7a416f 100644
--- a/apdsetarrivalforirradiation.cpp
+++ b/apdsetarrivalforirradiation.cpp
@@ -9,7 +9,7 @@
 #include "toolbox.cpp"
 #include "BulkDbAccess.h"
 
-#include "QtGui/QApplication"
+#include "QApplication"
 
 namespace po=boost::program_options;
 using namespace std;
diff --git a/makeseriallist.cxx b/makeseriallist.cxx
index fe66366..f0e6f23 100644
--- a/makeseriallist.cxx
+++ b/makeseriallist.cxx
@@ -13,6 +13,7 @@ void convertStringListToNumbers();
 void outputApdsInRange();
 
 static bool debug = false;
+static bool backwards = false;
 static vector<string> serialListString;
 static vector<unsigned long> serialList;
 static unsigned long serialMin;
@@ -31,17 +32,31 @@ int main(int argc, char *argv[]) {
 }
 
 void processParameters(int argc, char *argv[]) {
-  if ( argc == 4 && entryExistsInArgList(argc, argv, "debug")) {
+  size_t validargs = 0;
+  if (entryExistsInArgList(argc, argv, "debug")) {
     debug = true;
+    validargs++;
   }
-  else if (argc != 3 ) {
-    cerr << "Too few or too many parameters!\n"
-         << "Pass first and last serial of range." << endl;
-    exit(1);
+  if (entryExistsInArgList(argc, argv, "backwards")) {
+    backwards = true;
+    validargs++;
+  }
+  if (argc != validargs+3 ) {
+      cerr << "Too few or too many parameters!\n"
+          << "Pass first and last serial of range." << endl;
+      exit(1);
   }
 
   serialMin = stoul(argv[1]);
   serialMax = stoul(argv[2]);
+
+  if (serialMin > serialMax) {
+      unsigned long oldMin = serialMin;
+      serialMin = serialMax;
+      serialMax = oldMin;
+      cerr << "Warning; Minimum is greater than Maximum, switching them and turning on backwards mode!" << endl;
+      backwards = true;
+  }
 }
 
 int entryExistsInArgList(int argc, char *argv[], std::string parameterName) {
@@ -68,8 +83,11 @@ void convertStringListToNumbers() {
 void outputApdsInRange() {
   int numOut = 0;
   for ( size_t i = 0 ; i < serialList.size() ; i++) {
-    if ( serialList [i] >= serialMin && serialList [i] <= serialMax ) {
-      cout << serialListString[i] << endl;
+    size_t j = i;
+    if (backwards) 
+      j = serialList.size() - (i+1);
+    if ( serialList [j] >= serialMin && serialList [j] <= serialMax ) {
+      cout << serialListString[j] << endl;
       numOut++;
     }
   }
diff --git a/makeseriallist2.cxx b/makeseriallist2.cxx
new file mode 100644
index 0000000..fe66366
--- /dev/null
+++ b/makeseriallist2.cxx
@@ -0,0 +1,77 @@
+#include "serialListReader.h"
+#include "QtCore/QCoreApplication"
+#include <vector>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+void processParameters(int argc, char *argv[]);
+int entryExistsInArgList(int argc, char *argv[], std::string parameterName);
+void getSerialListAsStringsFromDatabase();
+void convertStringListToNumbers();
+void outputApdsInRange();
+
+static bool debug = false;
+static vector<string> serialListString;
+static vector<unsigned long> serialList;
+static unsigned long serialMin;
+static unsigned long serialMax;
+
+int main(int argc, char *argv[]) {
+  processParameters(argc, argv);
+  QCoreApplication *_app = new QCoreApplication(argc,argv);
+
+  getSerialListAsStringsFromDatabase();
+  convertStringListToNumbers();
+  outputApdsInRange();
+
+  _app->exit(0);
+  return 0;
+}
+
+void processParameters(int argc, char *argv[]) {
+  if ( argc == 4 && entryExistsInArgList(argc, argv, "debug")) {
+    debug = true;
+  }
+  else if (argc != 3 ) {
+    cerr << "Too few or too many parameters!\n"
+         << "Pass first and last serial of range." << endl;
+    exit(1);
+  }
+
+  serialMin = stoul(argv[1]);
+  serialMax = stoul(argv[2]);
+}
+
+int entryExistsInArgList(int argc, char *argv[], std::string parameterName) {
+  for (int i = 0; i < argc; i++) {
+    if (argv[i] == parameterName) return true;
+  }
+  return false;
+}
+
+void getSerialListAsStringsFromDatabase() {
+  serialListReader *_reader = new serialListReader(debug);
+  serialListString = _reader->getListOfSerials();
+}
+
+void convertStringListToNumbers() {
+  serialList.clear();
+  for ( size_t i = 0 ; i < serialListString.size() ; i++) serialList.push_back( stoul( serialListString[i] ) );
+  if ( serialListString.size() != serialList.size() ) {
+    cerr << "ERROR: Sizes don't match!" << endl;
+    exit(2);
+  }
+}
+
+void outputApdsInRange() {
+  int numOut = 0;
+  for ( size_t i = 0 ; i < serialList.size() ; i++) {
+    if ( serialList [i] >= serialMin && serialList [i] <= serialMax ) {
+      cout << serialListString[i] << endl;
+      numOut++;
+    }
+  }
+  cerr << "Found " << numOut << " APDs in the given range." << endl;
+}
diff --git a/proddb/AbsDbAccess.h b/proddb/AbsDbAccess.h
new file mode 120000
index 0000000..38f3f60
--- /dev/null
+++ b/proddb/AbsDbAccess.h
@@ -0,0 +1 @@
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/AbsDbAccess.h
\ No newline at end of file
diff --git a/proddb/BulkDbAccess.cxx b/proddb/BulkDbAccess.cxx
index ac6f43d..ce93c98 120000
--- a/proddb/BulkDbAccess.cxx
+++ b/proddb/BulkDbAccess.cxx
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/BulkDbAccess.cxx
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/BulkDbAccess.cxx
\ No newline at end of file
diff --git a/proddb/BulkDbAccess.h b/proddb/BulkDbAccess.h
index ac1ded2..c1a16e4 120000
--- a/proddb/BulkDbAccess.h
+++ b/proddb/BulkDbAccess.h
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/BulkDbAccess.h
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/BulkDbAccess.h
\ No newline at end of file
diff --git a/proddb/ProdDbAccess.cxx b/proddb/ProdDbAccess.cxx
index 4f9fae5..2805947 120000
--- a/proddb/ProdDbAccess.cxx
+++ b/proddb/ProdDbAccess.cxx
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProdDbAccess.cxx
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProdDbAccess.cxx
\ No newline at end of file
diff --git a/proddb/ProdDbAccess.h b/proddb/ProdDbAccess.h
index 94b012d..4046fec 120000
--- a/proddb/ProdDbAccess.h
+++ b/proddb/ProdDbAccess.h
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProdDbAccess.h
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProdDbAccess.h
\ No newline at end of file
diff --git a/proddb/ProductionDatabase.cxx b/proddb/ProductionDatabase.cxx
index 614b263..a9a096c 120000
--- a/proddb/ProductionDatabase.cxx
+++ b/proddb/ProductionDatabase.cxx
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProductionDatabase.cxx
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProductionDatabase.cxx
\ No newline at end of file
diff --git a/proddb/ProductionDatabase.h b/proddb/ProductionDatabase.h
index 0aefe0e..1479557 120000
--- a/proddb/ProductionDatabase.h
+++ b/proddb/ProductionDatabase.h
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProductionDatabase.h
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProductionDatabase.h
\ No newline at end of file
diff --git a/proddb/ProductionDatabaseApdStorage.cxx b/proddb/ProductionDatabaseApdStorage.cxx
index e4453cc..94a251d 120000
--- a/proddb/ProductionDatabaseApdStorage.cxx
+++ b/proddb/ProductionDatabaseApdStorage.cxx
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProductionDatabaseApdStorage.cxx
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProductionDatabaseApdStorage.cxx
\ No newline at end of file
diff --git a/proddb/ProductionDatabaseApdStorage.h b/proddb/ProductionDatabaseApdStorage.h
index bbb8183..071a5c9 120000
--- a/proddb/ProductionDatabaseApdStorage.h
+++ b/proddb/ProductionDatabaseApdStorage.h
@@ -1 +1 @@
-/home/tau/jreher/git/ProtoSoft/DAQ/ApdCurves/ProductionDatabaseApdStorage.h
\ No newline at end of file
+/home/tau/jreher/git/ProtoSoft/DAQ/ProductionDatabase/ProductionDatabaseApdStorage.h
\ No newline at end of file
diff --git a/testxmlstructure.cxx b/testxmlstructure.cxx
index 6846eb2..98ed621 100644
--- a/testxmlstructure.cxx
+++ b/testxmlstructure.cxx
@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include <QtCore/QString>
-#include <QtXml/QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
+#include <QtXml> ///QXmlStreamWriter> // For Compilation: QXml/QXmlStreamWriter
 #include "productiondatabaseclient.h"
 
 ProductionDatabase::ProductionDatabaseClient *proddbclient;
-- 
GitLab