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.

References m_options, and m_positionalOptions.

26  :m_name(commandName),
27  m_options(std::string("Usage: ")+m_name+
28  std::string(" [options] ")+positionalParameter
29  +std::string(" \n")),
31  m_values(){
32  m_options.add_options()
33  ("debug","switch on debug mode")
34  ("help,h", "help message")
35  ;
36  if(!positionalParameter.empty()) {
37  m_positionalOptions.add( positionalParameter.c_str(), -1);
38  addOption<std::string>(positionalParameter,"",positionalParameter);
39  }
40 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
std::string m_name
Definition: Utilities.h:71
boost::program_options::options_description m_options
Definition: Utilities.h:73
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:74
cond::Utilities::~Utilities ( )
virtual

Definition at line 43 of file Utilities.cc.

43  {
44 }

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 89 of file Utilities.cc.

89  {
90  addOption<std::string>("authPath","P","path to authentication xml");
91  addOption<std::string>("user","u","user name");
92  addOption<std::string>("pass","p","password");
93 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 96 of file Utilities.cc.

96  {
97  addOption<std::string>("configFile","f","configuration file(optional)");
98 }
void cond::Utilities::addConnectOption ( std::string const &  fullName,
std::string const &  shortName,
std::string const &  helpEntry 
)

Definition at line 82 of file Utilities.cc.

84  {
85  addOption<std::string>(connectionOptionName,shortName,helpEntry);
86 }
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.

46  {
47  return 0;
48 }
std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 114 of file Utilities.cc.

114  {
115  return getOptionValue<std::string>("authPath");
116 }
std::string cond::Utilities::getConfigFileValue ( )

Definition at line 138 of file Utilities.cc.

138  {
139  return getOptionValue<std::string>("configFile");
140 }
std::string cond::Utilities::getConnectValue ( )

Definition at line 126 of file Utilities.cc.

126  {
127  return getOptionValue<std::string>("connect");
128 }
std::string cond::Utilities::getDictionaryValue ( )

Definition at line 134 of file Utilities.cc.

134  {
135  return getOptionValue<std::string>("dictionary");
136 }
std::string cond::Utilities::getLogDBValue ( )

Definition at line 130 of file Utilities.cc.

130  {
131  return getOptionValue<std::string>("logDB");
132 }
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.

122  {
123  return getOptionValue<std::string>("pass");
124 }
std::string cond::Utilities::getUserValue ( )

Definition at line 118 of file Utilities.cc.

118  {
119  return getOptionValue<std::string>("user");
120 }
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.

References newFWLiteAna::fullName, and AlCaHLTBitMon_QueryRunRegistry::string.

230  {
231  std::string val("");
232  if(m_values.count(fullName)){
233  val = m_values[fullName].as<std::string>();
234  }
235  return val;
236 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:75
bool cond::Utilities::hasDebug ( )

Definition at line 153 of file Utilities.cc.

153  {
154  return m_values.count("debug");
155 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 143 of file Utilities.cc.

References newFWLiteAna::found, and python.rootplot.argparse::message.

143  {
144  const void* found = m_options.find_nothrow(fullName, false);
145  if(!found){
146  std::stringstream message;
147  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
148  sendException(message.str());
149  }
150  return m_values.count(fullName);
151 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendException(const std::string &message)
Definition: Utilities.cc:242
boost::program_options::options_description m_options
Definition: Utilities.h:73
void cond::Utilities::initializePluginManager ( )

Definition at line 157 of file Utilities.cc.

157  {
158  // dummy, to avoid to adapt non-CondCore clients
159 }
void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 100 of file Utilities.cc.

References HDQMDatabaseProducer::configFile, recoMuon::in, AlCaHLTBitMon_ParallelJobs::options, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

100  {
101  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
102  if(m_options.find_nothrow("configFile",false)){
103  std::string configFileName = getValueIfExists("configFile");
104  if (! configFileName.empty()){
105  std::fstream configFile;
106  configFile.open(configFileName.c_str(), std::fstream::in);
107  boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
108  configFile.close();
109  }
110  }
111  boost::program_options::notify(m_values);
112 }
int run(int argc, char **argv)
Definition: Utilities.cc:50
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:230
tuple argc
Definition: dir2webdir.py:38
boost::program_options::variables_map m_values
Definition: Utilities.h:75
boost::program_options::options_description m_options
Definition: Utilities.h:73
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:74
int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 50 of file Utilities.cc.

References edm::ParameterSet::addParameter(), edmplugin::standard::config(), mps_alisetup::config, edmplugin::PluginManager::configure(), gather_cfg::cout, edm::ServiceRegistry::createSet(), cppFunctionSkipper::exception, cmsIgProf_Analysis::execute(), cmsPerfStripChart::operate(), runTheMatrix::ret, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

Referenced by Types.EventID::cppID(), and Types.LuminosityBlockID::cppID().

50  {
53 
54  std::vector<edm::ParameterSet> psets;
55  edm::ParameterSet pSet;
56  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
57  psets.push_back(pSet);
59  m_currentToken = &servToken;
61 
62  int ret = 0;
63  try{
65  if (m_values.count("help")) {
66  std::cout << m_options <<std::endl;;
67  return 0;
68  }
69  ret = execute();
70  }catch( cond::Exception& err ){
71  std::cout << err.what() << std::endl;
72  ret = 1;
73  }catch( const std::exception& exc ){
74  std::cout << exc.what() << std::endl;
75  ret = 1;
76  }
77  m_currentToken = nullptr;
78  return ret;
79 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:100
virtual char const * what() const
Definition: Exception.cc:141
tuple ret
prodAgent to be discontinued
Base exception class for the object to relational access.
Definition: Exception.h:11
static PluginManager & configure(const Config &)
edm::ServiceToken * m_currentToken
Definition: Utilities.h:67
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
static ServiceToken createSet(std::vector< ParameterSet > &)
tuple argc
Definition: dir2webdir.py:38
boost::program_options::variables_map m_values
Definition: Utilities.h:75
tuple cout
Definition: gather_cfg.py:145
boost::program_options::options_description m_options
Definition: Utilities.h:73
virtual int execute()
Definition: Utilities.cc:46
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 238 of file Utilities.cc.

Referenced by getOptionValue().

238  {
240 }
void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 242 of file Utilities.cc.

Referenced by getOptionValue().

242  {
243  throw cond::Exception(message);
244 }
persistency::Exception Exception
Definition: Exception.h:25

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(), getOptionValue(), and Utilities().

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

Definition at line 74 of file Utilities.h.

Referenced by Utilities().

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

Definition at line 75 of file Utilities.h.

Referenced by getOptionValue().