Page MenuHomec4science

run_manager.cc
No OneTemporary

File Metadata

Created
Sat, Jun 22, 10:21

run_manager.cc

/*
author : Nicolas RICHART <nicolas.richart@epfl.ch>
author : Guillaume ANCIAUX (anciaux@labri.fr, g.anciaux@laposte.net)
author : Till JUNGE <till.junge@epfl.ch>
*/
/* -------------------------------------------------------------------------- */
#include <pqxx/pqxx>
#include "blackdynamite.hh"
#include "sql_connection_manager.hh"
#include "state_manager.hh"
#include "quantities_manager.hh"
#include <sstream>
#include <cmath>
/* -------------------------------------------------------------------------- */
namespace BlackDynamite {
/* ------------------------------------------------------------------------ */
static std::string getenv(const std::string & var, std::string & default_val) {
char * ptr = ::getenv(var.c_str());
if (!ptr) return default_val;
return std::string(ptr);
}
static std::string getenv(const std::string & var) {
char * ptr = ::getenv(var.c_str());
if (!ptr) FATAL("Undefined environment variable " + var);
return std::string(ptr);
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
RunManager::RunManager() {
std::string user = getenv("BLACKDYNAMITE_USER");
std::string dbname = getenv("BLACKDYNAMITE_DBNAME", user);
std::string host = getenv("BLACKDYNAMITE_HOST");
std::string schema = getenv("BLACKDYNAMITE_SCHEMA");
UInt run_id = atoi(getenv("BLACKDYNAMITE_RUN_ID").c_str());
init(dbname, user, host, schema, run_id);
}
/* ------------------------------------------------------------------------ */
RunManager::RunManager(const std::string & dbname,
const std::string & user,
const std::string & host,
const std::string & schema,
UInt run_id) {
init(dbname, user, host, schema, run_id);
}
/* ------------------------------------------------------------------------ */
RunManager::~RunManager() {
delete quantities_manager;
delete state_manager;
}
/* ------------------------------------------------------------------------ */
void RunManager::init(const std::string & dbname,
const std::string & user,
const std::string & host,
const std::string & schema,
UInt run_id) {
this->run_id = run_id;
if (this->run_id <1) {
FATAL("The run id required for the sql dumps has not been specified");
}
this->sql_connection_manager = new SQLConnectionManager(dbname,
user,
host,
schema);
this->sql_schema = schema;
this->quantities_manager = new QuantitiesManager(*this->sql_connection_manager,
this->sql_schema,
this->run_id);
this->state_manager = new StateManager(*this->sql_connection_manager,
this->sql_schema,
this->run_id);
}
/* ------------------------------------------------------------------------ */
void RunManager::startRun(){
this->state_manager->changeState("START");
}
/* ------------------------------------------------------------------------ */
void RunManager::endRun(){
this->state_manager->changeState("FINISHED");
}
/* ------------------------------------------------------------------------ */
void RunManager::changeState(const std::string & state){
this->state_manager->changeState(state);
}
/* ------------------------------------------------------------------------ */
UInt RunManager::getInstanceCounter() {
return this->sql_connection_manager->getInstanceCounter();
}
/* ------------------------------------------------------------------------ */
template<typename T>
void RunManager::push(const T & value, const std::string & quantity, const UInt& step) {
this->quantities_manager->pushQuantity(quantity, value, step);
}
/*------------------------------------------------------------------------- */
void RunManager::push(const std::string & value, const std::string & quantity) {
this->quantities_manager->pushQuantity(quantity, value);
}
/* ------------------------------------------------------------------------ */
template void RunManager::push<int> (const int & value,
const std::string & quantity,
const UInt & step);
template void RunManager::push<UInt> (const UInt & value,
const std::string & quantity,
const UInt & step);
template void RunManager::push<Real> (const Real & value,
const std::string & quantity,
const UInt & step);
template void RunManager::push<std::vector<Real>>(const std::vector<Real> & value,
const std::string & quantity,
const UInt & step);
template void RunManager::push<std::vector<int>> (const std::vector<int> & value,
const std::string & quantity,
const UInt & step);
/* ------------------------------------------------------------------------ */
unsigned int SQLConnectionManager::connection_counter = 0;
pqxx::connection * SQLConnectionManager::sql_connection = NULL;
/* ------------------------------------------------------------------------ */
}

Event Timeline