diff --git a/src/blackdynamite.hh b/src/blackdynamite.hh index 1eaca45..a519ec1 100644 --- a/src/blackdynamite.hh +++ b/src/blackdynamite.hh @@ -1,97 +1,91 @@ /* author : Nicolas RICHART author : Guillaume ANCIAUX (anciaux@labri.fr, g.anciaux@laposte.net) author : Till JUNGE */ /* -------------------------------------------------------------------------- */ #ifndef __BLACKDYNAMITE_PUSHER_HH__ #define __BLACKDYNAMITE_PUSHER_HH__ #include /* -------------------------------------------------------------------------- */ namespace BlackDynamite { typedef unsigned int UInt; typedef double Real; class SQLConnectionManager; class StateManager; class QuantitiesManager; class RunManager { /* ------------------------------------------------------------------------ */ /* Typedefs */ /* ------------------------------------------------------------------------ */ public: /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: RunManager(); RunManager(const std::string & dbname, const std::string & user, const std::string & host, const std::string & schema, UInt run_id); virtual ~RunManager(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ - //! say wether the pusher was initialized or not - bool isInitialized(); - //! function to be called to update the state of the job at the begining of the run void startRun(); //! function to be called to update the state of the job at the end of the run void endRun(); //! change the state of a run void changeState(const std::string & state); //! template method that pushes a value associated with a quantity at a particular timestep template void push(const T & value, const std::string & quantity, const UInt& step); //! template method that pushes a string to a given run column void push(const std::string & value, const std::string & quantity); //! give the number of instance of blackdynamite UInt getInstanceCounter(); protected: //! initialisation method void init(const std::string & dbname, const std::string & user, const std::string & host, const std::string & schema, UInt run_id); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: UInt run_id; std::string sql_schema; SQLConnectionManager * sql_connection_manager; StateManager * state_manager; QuantitiesManager * quantities_manager; - //! initialisation method - bool is_initialized; - }; /* -------------------------------------------------------------------------- */ } #endif /* __BLACKDYNAMITE_PUSHER_HH__ */ diff --git a/src/run_manager.cc b/src/run_manager.cc index 568043c..e03ba25 100644 --- a/src/run_manager.cc +++ b/src/run_manager.cc @@ -1,149 +1,142 @@ /* author : Nicolas RICHART author : Guillaume ANCIAUX (anciaux@labri.fr, g.anciaux@laposte.net) author : Till JUNGE */ /* -------------------------------------------------------------------------- */ #include #include "blackdynamite.hh" #include "sql_connection_manager.hh" #include "state_manager.hh" #include "quantities_manager.hh" #include #include /* -------------------------------------------------------------------------- */ 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() : is_initialized(false) { + 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; } - /* ------------------------------------------------------------------------ */ - bool RunManager::isInitialized() { - return this->is_initialized; - } - /* ------------------------------------------------------------------------ */ 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); - - this->is_initialized = true; } /* ------------------------------------------------------------------------ */ 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 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 (const int & value, const std::string & quantity, const UInt & step); template void RunManager::push (const UInt & value, const std::string & quantity, const UInt & step); template void RunManager::push (const Real & value, const std::string & quantity, const UInt & step); template void RunManager::push>(const std::vector & value, const std::string & quantity, const UInt & step); template void RunManager::push> (const std::vector & value, const std::string & quantity, const UInt & step); /* ------------------------------------------------------------------------ */ unsigned int SQLConnectionManager::connection_counter = 0; pqxx::connection * SQLConnectionManager::sql_connection = NULL; /* ------------------------------------------------------------------------ */ }