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

Havent commited changes in a while, so this is probably a lot...

parent 4b7743fd
No related branches found
No related tags found
1 merge request!4Many proven updates being brought into stable branch.
Pipeline #1584 failed with stages
in 1 second
......@@ -10,7 +10,7 @@ INCLUDE_DIRECTORIES($ENV{proddb_clientlib_includes})
LINK_DIRECTORIES($ENV{proddb_clientlib_libpath})
add_library(toolbox "toolbox.cpp" "serialListReader.h" "serialListReader.cxx" "gridListReader.h" "gridListReader.cxx")
add_library(proddbaccess "proddb/ProdDbAccess.cxx" "proddb/ProdDbAccess.h" "proddb/ProductionDatabase.cxx" "proddb/ProductionDatabase.h" "proddb/ProductionDatabaseApdStorage.cxx" "proddb/ProductionDatabaseApdStorage.h" "proddb/BulkDbAccess.h" "proddb/BulkDbAccess.cxx")
add_library(proddbaccess "proddb/ProdDbAccess.cxx" "proddb/ProdDbAccess.h" "proddb/ProductionDatabase.cxx" "proddb/ProductionDatabase.h" "proddb/ProductionDatabaseApdStorage.cxx" "proddb/ProductionDatabaseApdStorage.h" "proddb/BulkDbAccess.h" "proddb/BulkDbAccess.cxx" "proddb/AbsDbAccess.h")
add_executable(apdBatchSetter "apdbatchsetter.cpp")
add_executable(apdLocationSetter "apdlocationsetter.cpp")
......@@ -19,6 +19,7 @@ add_executable(setSentForAnalysisAfterIrradiation "apdSetSentForAnalysisAfterIrr
add_executable(setIrradiationInfo "apdSetIrradiationInfo.cpp")
add_executable(setAnnealingInfo "apdSetAnnealingInfo.cpp")
add_executable(apdBoxSetter "apdboxsetter.cpp")
add_executable(apdUnavailableSetter "apdunavailablesetter.cpp")
add_executable(getLocations "getlocations.cpp")
add_executable(getBatch "getbatch.cpp")
add_executable(getU100 "getu100.cxx")
......@@ -33,6 +34,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(getLocations proddbaccess boost_program_options)
target_link_libraries(getBatch proddbaccess boost_program_options)
target_link_libraries(getIrradiationDose proddbaccess boost_program_options)
......
#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 bool unavailable = true;
static bool debug = false;
static string username = "";
static string password = "";
static vector<string> apdSerials;
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 apdUnavailableSetter with version " << proddb->getVersion() << " of the database access libraries." << endl << endl
<< "Now trying to set tempUnavailable to " << unavailable << " 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->setApdTempUnavailable(apdSerials,unavailable);
cout << "\nTemporary unavailability" << unavailable << " 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 apdUnavailableSetter! :)" << 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")
("available", "Set temporary unavailability to false instead of true")
("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("available"))
unavailable = false;
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();
string line = "";
while (in.good()) {
getline(in,line);
if (line.length() == 0 || !isdigit(line[0]))
continue;
while (line.length() != 10)
line = std::string("0")+ line;
apdSerials.push_back(line);
if (m_debug) cout << "Found serial: " << line << endl;
}
cerr << "Found " << apdSerials.size() << " APDs" << endl;
return;
}
......@@ -35,7 +35,10 @@ int main(int argc, char* argv[]) {
for (size_t i = 0 ; i < apdSerials.size() ; i++ ) {
if (apdSerials[i].size() == 9) apdSerials[i] = "0" + apdSerials[i];
cout << "S/N " << apdSerials[i] << " is in Box " << _dba->box( uint( stoul( apdSerials[i] ) ) ) << " on position " << _dba->pos_in_box( uint( stoul( apdSerials[i] ) ) ) << ", Location: '" << _dba->location( uint( stoul( apdSerials[i] ) ) ) << "'" << endl;
if (_dba->apdAvailable( uint( stoul ( apdSerials[i] ) ) ) )
cout << "S/N " << apdSerials[i] << " is in Box " << _dba->box( uint( stoul( apdSerials[i] ) ) ) << " on position " << _dba->pos_in_box( uint( stoul( apdSerials[i] ) ) ) << ", Location: '" << _dba->location( uint( stoul( apdSerials[i] ) ) ) << "'" << endl;
else
cout << "UNAVAILABLE S/N " << apdSerials[i] << " was assigned to Box " << _dba->box( uint( stoul( apdSerials[i] ) ) ) << " on position " << _dba->pos_in_box( uint( stoul( apdSerials[i] ) ) ) << ", Location: '" << _dba->location( uint( stoul( apdSerials[i] ) ) ) << "'" << endl;
}
return 0;
......
......@@ -5,7 +5,65 @@
#include <QtXml/QXmlStreamWriter>
#include "productiondatabaseclient.h"
ProductionDatabase::ProductionDatabaseClient *proddbclient;
void initialize();
void screeningInfo();
void assignApds(std::string redSerial, std::string blueSerial);
void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode);
int main() {
initialize();
assignApds("0607004597", "0607004598" );
assignApds("0607004600", "0607004601" );
assignUnit("0607004598/0607004597","790","1309009220");
assignUnit("0607004601/0607004600","790","1309009237");
return 0;
}
void initialize() {
proddbclient = new ProductionDatabase::ProductionDatabaseClient();
std::cerr << proddbclient->getVersionShort() << std::endl;
proddbclient->queryCredentials();
proddbclient->checkConnectivityAndCredentials();
}
void assignUnit(std::string detectorSerial, std::string crystalSerial, std::string barcode) {
QString buffer;
QXmlStreamWriter xml ( &buffer );
xml.setAutoFormatting(true);
xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
xml.writeTextElement( QString::fromUtf8( "detectorSerial" ), QString::fromStdString( detectorSerial ) );
xml.writeTextElement( QString::fromUtf8( "crystalSerial" ), QString::fromStdString( crystalSerial ) );
xml.writeTextElement( QString::fromUtf8( "barcode" ), QString::fromStdString( barcode ) );
xml.writeEndDocument();
std::string xmlRequest = buffer.toStdString();
std::cerr << xmlRequest << std::endl;
proddbclient->postXmlRequest("unit_assemble.php", xmlRequest);
}
void assignApds(std::string redSerial, std::string blueSerial) {
QString buffer;
QXmlStreamWriter xml ( &buffer );
xml.setAutoFormatting(true);
xml.writeStartDocument( QString::fromUtf8( "1.0" ) );
xml.writeStartElement( QString::fromUtf8( "productiondb" ) ) ;
xml.writeTextElement( QString::fromUtf8( "redSerial" ), QString::fromStdString( redSerial ) );
xml.writeTextElement( QString::fromUtf8( "blueSerial" ), QString::fromStdString( blueSerial ) );
xml.writeEndDocument();
std::string xmlRequest = buffer.toStdString();
std::cerr << xmlRequest << std::endl;
proddbclient->postXmlRequest("detector_assemble.php", xmlRequest);
}
void screeningInfo() {
std::vector<QString> apds;
apds.push_back(QString::fromUtf8("0608004648"));
apds.push_back(QString::fromUtf8("APD123"));
......
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