#include <Utilities.h>
Public Member Functions | |
void | addAuthenticationOptions () |
void | addConfigFileOption () |
void | addConnectOption () |
void | addConnectOption (const std::string &connectionOptionName, const std::string &shortName, const std::string &helpEntry) |
void | addDictionaryOption () |
void | addLogDBOption () |
template<typename T > | |
void | addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry) |
void | addSQLOutputOption () |
virtual int | execute () |
std::string | getAuthenticationPathValue () |
std::string | getConfigFileValue () |
std::string | getConnectValue () |
std::string | getDictionaryValue () |
std::string | getLogDBValue () |
template<typename T > | |
T | getOptionValue (const std::string &fullName) |
std::string | getPasswordValue () |
std::string | getUserValue () |
bool | hasDebug () |
bool | hasOptionValue (const std::string &fullName) |
void | initializePluginManager () |
cond::DbSession | openDbSession (const std::string &connectionParameterName, bool readOnly=false) |
void | parseCommand (int argc, char **argv) |
int | run (int argc, char **argv) |
Utilities (const std::string &commandName, std::string positionalParameter=std::string("")) | |
virtual | ~Utilities () |
Private Member Functions | |
std::string | getValueIfExists (const std::string &fullName) |
void | initializeForDbConnection () |
void | sendError (const std::string &message) |
void | sendException (const std::string &message) |
Private Attributes | |
cond::DbConnection * | m_dbConnection |
std::set< std::string > | m_dbSessions |
std::string | m_name |
boost::program_options::options_description | m_options |
bool | m_pluginMgrInitialized |
boost::program_options::positional_options_description | m_positionalOptions |
boost::program_options::variables_map | m_values |
Definition at line 19 of file Utilities.h.
cond::Utilities::Utilities | ( | const std::string & | commandName, |
std::string | positionalParameter = std::string("") |
||
) |
cond::Utilities::Utilities( const std::string& commandName):m_name(commandName), m_options(std::string("Usage: ")+m_name+std::string(" [options] \n")), m_positionalOptions(), m_values(), m_dbConnection(0), m_pluginMgrInitialized(false), m_dbSessions(){ m_options.add_options() ("debug","switch on debug mode") ("help,h", "help message") ; }
Definition at line 35 of file Utilities.cc.
References m_options, and m_positionalOptions.
:m_name(commandName), m_options(std::string("Usage: ")+m_name+ std::string(" [options] ")+positionalParameter +std::string(" \n")), m_positionalOptions(), m_values(), m_dbConnection(0), m_pluginMgrInitialized(false), m_dbSessions(){ m_options.add_options() ("debug","switch on debug mode") ("help,h", "help message") ; if(!positionalParameter.empty()) { m_positionalOptions.add( positionalParameter.c_str(), -1); addOption<std::string>(positionalParameter,"",positionalParameter); } }
cond::Utilities::~Utilities | ( | ) | [virtual] |
Definition at line 56 of file Utilities.cc.
{ if(m_dbConnection) delete m_dbConnection; }
void cond::Utilities::addAuthenticationOptions | ( | ) |
Definition at line 104 of file Utilities.cc.
Referenced by cond::AlignSplitIOV::AlignSplitIOV().
{ addOption<std::string>("authPath","P","path to authentication xml(default .)"); addOption<std::string>("user","u","user name (default \"\")"); addOption<std::string>("pass","p","password (default \"\")"); }
void cond::Utilities::addConfigFileOption | ( | ) |
Definition at line 136 of file Utilities.cc.
{ addOption<std::string>("configFile","f","configuration file(optional)"); }
void cond::Utilities::addConnectOption | ( | ) |
Definition at line 111 of file Utilities.cc.
Referenced by cond::AlignSplitIOV::AlignSplitIOV().
{ addOption<std::string>("connect","c","connection string(required)"); m_dbSessions.insert("connect"); }
void cond::Utilities::addConnectOption | ( | const std::string & | connectionOptionName, |
const std::string & | shortName, | ||
const std::string & | helpEntry | ||
) |
Definition at line 117 of file Utilities.cc.
{ addOption<std::string>(connectionOptionName,shortName,helpEntry); m_dbSessions.insert(connectionOptionName); }
void cond::Utilities::addDictionaryOption | ( | ) |
Definition at line 131 of file Utilities.cc.
{ addOption<std::vector<std::string> >("dictionary","D","data dictionaries (required if no plugin available)"); }
void cond::Utilities::addLogDBOption | ( | ) |
Definition at line 126 of file Utilities.cc.
{ addConnectOption("logDB","l","logDB(optional"); }
void cond::Utilities::addOption< bool > | ( | const std::string & | fullName, |
const std::string & | shortName, | ||
const std::string & | helpEntry | ||
) | [inline] |
Definition at line 79 of file Utilities.h.
References newFWLiteAna::fullName, and m_options.
void cond::Utilities::addSQLOutputOption | ( | ) |
Definition at line 141 of file Utilities.cc.
{ addOption<bool>("sql","S","dump the sql output (optional)"); }
int cond::Utilities::execute | ( | ) | [virtual] |
std::string cond::Utilities::getAuthenticationPathValue | ( | ) |
Definition at line 159 of file Utilities.cc.
{ return getOptionValue<std::string>("authPath"); }
std::string cond::Utilities::getConfigFileValue | ( | ) |
Definition at line 183 of file Utilities.cc.
{ return getOptionValue<std::string>("configFile"); }
std::string cond::Utilities::getConnectValue | ( | ) |
Definition at line 171 of file Utilities.cc.
{ return getOptionValue<std::string>("connect"); }
std::string cond::Utilities::getDictionaryValue | ( | ) |
Definition at line 179 of file Utilities.cc.
{ return getOptionValue<std::string>("dictionary"); }
std::string cond::Utilities::getLogDBValue | ( | ) |
Definition at line 175 of file Utilities.cc.
{ return getOptionValue<std::string>("logDB"); }
T cond::Utilities::getOptionValue | ( | const std::string & | fullName | ) | [inline] |
Definition at line 102 of file Utilities.h.
References newFWLiteAna::found, newFWLiteAna::fullName, m_options, m_values, argparse::message, sendError(), and sendException().
{ const void* found = m_options.find_nothrow(fullName, false); if(!found){ std::stringstream message; message << "Utilities::getOptionValue: option \"" << fullName << "\" is not known by the command."; sendException(message.str()); } if (!m_values.count(fullName)) { std::stringstream message; message << "Error: Option \"" << fullName << "\" has not been provided."; sendError(message.str()); } return m_values[fullName].as<T>(); }
std::string cond::Utilities::getPasswordValue | ( | ) |
Definition at line 167 of file Utilities.cc.
{ return getOptionValue<std::string>("pass"); }
std::string cond::Utilities::getUserValue | ( | ) |
Definition at line 163 of file Utilities.cc.
{ return getOptionValue<std::string>("user"); }
std::string cond::Utilities::getValueIfExists | ( | const std::string & | fullName | ) | [private] |
Definition at line 264 of file Utilities.cc.
References newFWLiteAna::fullName.
bool cond::Utilities::hasDebug | ( | ) |
Definition at line 198 of file Utilities.cc.
{ return m_values.count("debug"); }
bool cond::Utilities::hasOptionValue | ( | const std::string & | fullName | ) |
Definition at line 188 of file Utilities.cc.
References newFWLiteAna::found, and argparse::message.
void cond::Utilities::initializeForDbConnection | ( | ) | [private] |
Definition at line 218 of file Utilities.cc.
References builder_last_value_cfg::authPath, Debug, and hcal_dqm_sourceclient-file_cfg::user.
{ if(!m_dbConnection){ initializePluginManager(); m_dbConnection = new cond::DbConnection(); if( hasDebug() ){ m_dbConnection->configuration().setMessageLevel(coral::Debug); } else { m_dbConnection->configuration().setMessageLevel(coral::Error); } m_dbConnection->configuration().setPoolAutomaticCleanUp( false ); m_dbConnection->configuration().setConnectionTimeOut(0); if(m_options.find_nothrow("authPath", false) && m_options.find_nothrow("user",false) && m_options.find_nothrow("pass",false)){ std::string authPath = getValueIfExists("authPath"); std::string user = getValueIfExists("user"); std::string pass = getValueIfExists("pass"); if( !authPath.empty() ){ m_dbConnection->configuration().setAuthenticationPath(authPath); } else { if( !user.empty() && !pass.empty() ){ std::string userenv(std::string("CORAL_AUTH_USER=")+user); std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass); ::putenv(const_cast<char*>(userenv.c_str())); ::putenv(const_cast<char*>(passenv.c_str())); } } } if(m_options.find_nothrow("sql",false)){ if(m_values.count("sql")) m_dbConnection->configuration().setSQLMonitoring( true ); } m_dbConnection->configure(); } }
void cond::Utilities::initializePluginManager | ( | ) |
Definition at line 202 of file Utilities.cc.
References edm::ParameterSet::addParameter(), HDQMDatabaseProducer::config, edmplugin::standard::config(), edmplugin::PluginManager::configure(), and edm::ServiceRegistry::createSet().
{ if(!m_pluginMgrInitialized){ edmplugin::PluginManager::Config config; edmplugin::PluginManager::configure(edmplugin::standard::config()); std::vector<edm::ParameterSet> psets; edm::ParameterSet pSet; pSet.addParameter("@service_type",std::string("SiteLocalConfigService")); psets.push_back(pSet); static edm::ServiceToken services(edm::ServiceRegistry::createSet(psets)); static edm::ServiceRegistry::Operate operate(services); m_pluginMgrInitialized = true; } }
cond::DbSession cond::Utilities::openDbSession | ( | const std::string & | connectionParameterName, |
bool | readOnly = false |
||
) |
Definition at line 256 of file Utilities.cc.
References python::CommonUtils::session.
{ initializeForDbConnection(); std::string connectionString = getOptionValue<std::string>( connectionParameterName ); cond::DbSession session = m_dbConnection->createSession(); session.open( connectionString, readOnly ); return session; }
void cond::Utilities::parseCommand | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 145 of file Utilities.cc.
References HDQMDatabaseProducer::configFile, recoMuon::in, loadConditions::options, and DTTTrigCorrFirst::run.
{ boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values); if(m_options.find_nothrow("configFile",false)){ std::string configFileName = getValueIfExists("configFile"); if (! configFileName.empty()){ std::fstream configFile; configFile.open(configFileName.c_str(), std::fstream::in); boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values); configFile.close(); } } boost::program_options::notify(m_values); }
int cond::Utilities::run | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 64 of file Utilities.cc.
References gather_cfg::cout, python::multivaluedict::dict, exception, cmsIgProf_Analysis::execute(), cond::SQLReport::putOnFile(), zeeHLT_cff::report, cond::SQLReport::reportForConnection(), runTheMatrix::ret, and cms::Exception::what().
Referenced by main().
{ int ret = 0; try{ parseCommand( argc, argv ); if (m_values.count("help")) { std::cout << m_options <<std::endl;; return 0; } if(m_options.find_nothrow("dictionary",false)&& m_values.count("dictionary")){ std::vector<std::string> dictionaries = m_values["dictionary"].as<std::vector<std::string> >(); if(!dictionaries.empty()){ initializePluginManager(); cond::SharedLibraryName libName; BOOST_FOREACH(std::string const & dict, dictionaries) edmplugin::SharedLibrary( libName(dict) ); } } ret = execute(); if(m_dbConnection){ if(m_options.find_nothrow("sql",false) && m_values.count("sql")){ cond::SQLReport report(*m_dbConnection); for(std::set<std::string>::const_iterator iSess = m_dbSessions.begin(); iSess != m_dbSessions.end(); iSess++) report.reportForConnection(*iSess); report.putOnFile(); } } }catch( cond::Exception& err ){ std::cout << err.what() << std::endl; ret = 1; }catch( const std::exception& exc ){ std::cout << exc.what() << std::endl; ret = 1; } return ret; }
void cond::Utilities::sendError | ( | const std::string & | message | ) | [private] |
Definition at line 272 of file Utilities.cc.
Referenced by getOptionValue().
{ throw cond::UtilitiesError(message); }
void cond::Utilities::sendException | ( | const std::string & | message | ) | [private] |
Definition at line 276 of file Utilities.cc.
References Exception.
Referenced by getOptionValue().
{ throw cond::Exception(message); }
Definition at line 73 of file Utilities.h.
std::set<std::string> cond::Utilities::m_dbSessions [private] |
Definition at line 75 of file Utilities.h.
std::string cond::Utilities::m_name [private] |
Definition at line 68 of file Utilities.h.
boost::program_options::options_description cond::Utilities::m_options [private] |
Definition at line 70 of file Utilities.h.
Referenced by addOption(), getOptionValue(), and Utilities().
bool cond::Utilities::m_pluginMgrInitialized [private] |
Definition at line 74 of file Utilities.h.
boost::program_options::positional_options_description cond::Utilities::m_positionalOptions [private] |
Definition at line 71 of file Utilities.h.
Referenced by Utilities().
boost::program_options::variables_map cond::Utilities::m_values [private] |
Definition at line 72 of file Utilities.h.
Referenced by getOptionValue().