CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
cond::Utilities Class Reference

#include <Utilities.h>

Public Member Functions

void addAuthenticationOptions ()
 
void addConfigFileOption ()
 
void addConnectOption (std::string const &fullName, std::string const &shortName, std::string const &helpEntry)
 
template<typename T >
void addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry)
 
template<>
void addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry)
 
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 ()
 
void parseCommand (int argc, char **argv)
 
int run (int argc, char **argv)
 
 Utilities (const std::string &commandName, std::string positionalParameter=std::string(""))
 
virtual ~Utilities ()
 

Protected Attributes

edm::ServiceTokenm_currentToken = 0
 

Private Member Functions

std::string getValueIfExists (const std::string &fullName)
 
void sendError (const std::string &message)
 
void sendException (const std::string &message)
 

Private Attributes

std::string m_name
 
boost::program_options::options_description m_options
 
boost::program_options::positional_options_description m_positionalOptions
 
boost::program_options::variables_map m_values
 

Detailed Description

Definition at line 22 of file Utilities.h.

Constructor & Destructor Documentation

cond::Utilities::Utilities ( const std::string &  commandName,
std::string  positionalParameter = std::string("") 
)

Definition at line 25 of file Utilities.cc.

cond::Utilities::~Utilities ( )
virtual

Definition at line 43 of file Utilities.cc.

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 89 of file Utilities.cc.

void cond::Utilities::addConfigFileOption ( )

Definition at line 96 of file Utilities.cc.

void cond::Utilities::addConnectOption ( std::string const &  fullName,
std::string const &  shortName,
std::string const &  helpEntry 
)

Definition at line 82 of file Utilities.cc.

template<typename T >
void cond::Utilities::addOption ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
)
inline

Definition at line 81 of file Utilities.h.

References newFWLiteAna::fullName, and m_options.

83  {
84  std::stringstream optInfo;
85  optInfo << fullName;
86  if(!shortName.empty()) optInfo << ","<<shortName;
87  m_options.add_options()
88  (optInfo.str().c_str(),boost::program_options::value<T>(),helpEntry.c_str());
89 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:73
template<>
void cond::Utilities::addOption ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
)
inline

Definition at line 91 of file Utilities.h.

References newFWLiteAna::fullName.

93  {
94  std::stringstream optInfo;
95  optInfo << fullName;
96  if(!shortName.empty()) optInfo << ","<<shortName;
97  m_options.add_options()
98  (optInfo.str().c_str(),helpEntry.c_str());
99 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:73
int cond::Utilities::execute ( )
virtual

Definition at line 46 of file Utilities.cc.

std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 114 of file Utilities.cc.

std::string cond::Utilities::getConfigFileValue ( )

Definition at line 138 of file Utilities.cc.

std::string cond::Utilities::getConnectValue ( )

Definition at line 126 of file Utilities.cc.

std::string cond::Utilities::getDictionaryValue ( )

Definition at line 134 of file Utilities.cc.

std::string cond::Utilities::getLogDBValue ( )

Definition at line 130 of file Utilities.cc.

template<typename T >
T cond::Utilities::getOptionValue ( const std::string &  fullName)
inline

Definition at line 104 of file Utilities.h.

References newFWLiteAna::found, newFWLiteAna::fullName, m_options, m_values, python.rootplot.argparse::message, sendError(), and sendException().

104  {
105  const void* found = m_options.find_nothrow(fullName, false);
106  if(!found){
107  std::stringstream message;
108  message << "Utilities::getOptionValue: option \"" << fullName << "\" is not known by the command.";
109  sendException(message.str());
110  }
111 
112  if (!m_values.count(fullName)) {
113  std::stringstream message;
114  message << "Error: Option \"" << fullName << "\" has not been provided.";
115  sendError(message.str());
116  }
117  return m_values[fullName].as<T>();
118 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendError(const std::string &message)
Definition: Utilities.cc:238
void sendException(const std::string &message)
Definition: Utilities.cc:242
boost::program_options::options_description m_options
Definition: Utilities.h:73
long double T
std::string cond::Utilities::getPasswordValue ( )

Definition at line 122 of file Utilities.cc.

std::string cond::Utilities::getUserValue ( )

Definition at line 118 of file Utilities.cc.

std::string cond::Utilities::getValueIfExists ( const std::string &  fullName)
private

void cond::Utilities::initializeForDbConnection(){ if(!m_dbConnection){ 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();

}

}

cond::DbSession cond::Utilities::newDbSession( const std::string& connectionString, bool readOnly ){ initializeForDbConnection(); cond::DbSession session = m_dbConnection->createSession(); session.open( connectionString, readOnly ); return session; } cond::DbSession cond::Utilities::newDbSession( const std::string& connectionString, const std::string& role, bool readOnly ){ initializeForDbConnection(); cond::DbSession session = m_dbConnection->createSession(); session.open( connectionString, role, readOnly ); return session; } cond::DbSession cond::Utilities::openDbSession( const std::string& connectionParameterName, const std::string& role, bool readOnly ){ std::string connectionString = getOptionValue<std::string>( connectionParameterName ); return newDbSession( connectionString, role, readOnly ); }

cond::DbSession cond::Utilities::openDbSession( const std::string& connectionParameterName, bool readOnly ){ std::string connectionString = getOptionValue<std::string>( connectionParameterName ); return newDbSession( connectionString, readOnly ); }

Definition at line 230 of file Utilities.cc.

bool cond::Utilities::hasDebug ( )

Definition at line 153 of file Utilities.cc.

bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 143 of file Utilities.cc.

void cond::Utilities::initializePluginManager ( )

Definition at line 157 of file Utilities.cc.

void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 100 of file Utilities.cc.

int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 50 of file Utilities.cc.

void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 238 of file Utilities.cc.

Referenced by getOptionValue().

void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 242 of file Utilities.cc.

Referenced by getOptionValue().

Member Data Documentation

edm::ServiceToken* cond::Utilities::m_currentToken = 0
protected

Definition at line 67 of file Utilities.h.

std::string cond::Utilities::m_name
private

Definition at line 71 of file Utilities.h.

boost::program_options::options_description cond::Utilities::m_options
private

Definition at line 73 of file Utilities.h.

Referenced by addOption(), and getOptionValue().

boost::program_options::positional_options_description cond::Utilities::m_positionalOptions
private

Definition at line 74 of file Utilities.h.

boost::program_options::variables_map cond::Utilities::m_values
private

Definition at line 75 of file Utilities.h.

Referenced by getOptionValue().