#include #include #include #include #include #include #include #include #include #include #include "ICOMETLog.hxx" /// The static member pointer to the singleton. ISlowControlDatabase* ISlowControlDatabase::fTSlowControlDatabase = NULL; ISlowControlDatabase::ISlowControlDatabase(){ // Get environment variables to define which database to query GSC information. TString url = getenv("ENV_GSC_TSQL_URL"); TString user = getenv("ENV_GSC_TSQL_USER"); TString pswd = getenv("ENV_GSC_TSQL_PSWD"); COMETLog("Initializing MySQL Slow Control Database. Using parameters: \n" << "ENV_GSC_TSQL_URL = " << url.Data() << "\n" << "ENV_GSC_TSQL_USER = " << user.Data() << "\n" << "ENV_GSC_TSQL_PSWD = " << pswd.Data()); // Use handy ROOT class to interpret URL. TUrl url_obj(url.Data()); int port = url_obj.GetPort(); if(port == 0) // Probably no port set; use default 3306. port = 3306; fGSCInterface = new ISlowControlMySQLInterface(user.Data(), pswd.Data(), url_obj); // Open up the ODB database connection. // Catch the exception if this fails, since this might not be important to some people. url_obj.SetFile("t2kodb"); COMETVerbose("Initializing MySQL ODB Database."); try{ fODBInterface = new ISlowControlMySQLInterface(user.Data(), pswd.Data(), url_obj); }catch (COMET::ELostGSCDatabaseConnection e) { COMETLog("ODB Database not available. " << "Attempting to access ODB information will cause exception. "); fODBInterface = 0; } } ISlowControlDatabase::~ISlowControlDatabase(){;} ISlowControlMySQLInterface& ISlowControlDatabase::Get(void){ if (!fTSlowControlDatabase) { fTSlowControlDatabase = new ISlowControlDatabase(); } return *(fTSlowControlDatabase->fGSCInterface); } ISlowControlMySQLInterface& ISlowControlDatabase::ODB(void){ if (!fTSlowControlDatabase) { fTSlowControlDatabase = new ISlowControlDatabase(); } if(!fTSlowControlDatabase->fODBInterface){ throw COMET::ELostGSCDatabaseConnection(); } return *(fTSlowControlDatabase->fODBInterface); }