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

Implemented piece to option units to submodule.

parent a4850214
No related branches found
No related tags found
2 merge requests!4Many proven updates being brought into stable branch.,!3Commented in the lines in apdUnitCreator.cpp that do the actual database
......@@ -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;
......
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