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 Member Functions | Protected Attributes | Private Member Functions | Private Attributes
cond::Utilities Class Reference

#include <Utilities.h>

Inheritance diagram for cond::Utilities:
cond::AlignSplitIOV cond::ExportIOVUtilities

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)
 
template<>
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)
 
cond::DbSession openDbSession (const std::string &connectionParameterName, const std::string &role, 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 ()
 

Protected Member Functions

void initializeForDbConnection ()
 
cond::DbSession newDbSession (const std::string &connectionString, bool readOnly=false)
 
cond::DbSession newDbSession (const std::string &connectionString, const std::string &role, bool readOnly=false)
 

Protected Attributes

edm::ServiceTokenm_currentToken = nullptr
 

Private Member Functions

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

Private Attributes

cond::DbConnectionm_dbConnection
 
std::set< std::string > m_dbSessions
 
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 23 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_dbConnection(0),
33  m_dbSessions(){
34  m_options.add_options()
35  ("debug","switch on debug mode")
36  ("help,h", "help message")
37  ;
38  if(!positionalParameter.empty()) {
39  m_positionalOptions.add( positionalParameter.c_str(), -1);
40  addOption<std::string>(positionalParameter,"",positionalParameter);
41  }
42 }
std::set< std::string > m_dbSessions
Definition: Utilities.h:84
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83
boost::program_options::variables_map m_values
Definition: Utilities.h:82
std::string m_name
Definition: Utilities.h:78
boost::program_options::options_description m_options
Definition: Utilities.h:80
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:81
cond::Utilities::~Utilities ( )
virtual

Definition at line 45 of file Utilities.cc.

45  {
46  if(m_dbConnection) delete m_dbConnection;
47 }
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 104 of file Utilities.cc.

Referenced by cond::AlignSplitIOV::AlignSplitIOV(), and cond::ExportIOVUtilities::ExportIOVUtilities().

104  {
105  addOption<std::string>("authPath","P","path to authentication xml");
106  addOption<std::string>("user","u","user name");
107  addOption<std::string>("pass","p","password");
108 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 136 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

136  {
137  addOption<std::string>("configFile","f","configuration file(optional)");
138 }
void cond::Utilities::addConnectOption ( )

Definition at line 111 of file Utilities.cc.

Referenced by cond::AlignSplitIOV::AlignSplitIOV(), and cond::ExportIOVUtilities::ExportIOVUtilities().

111  {
112  addOption<std::string>("connect","c","connection string (required)");
113  m_dbSessions.insert("connect");
114 }
std::set< std::string > m_dbSessions
Definition: Utilities.h:84
void cond::Utilities::addConnectOption ( const std::string &  connectionOptionName,
const std::string &  shortName,
const std::string &  helpEntry 
)

Definition at line 117 of file Utilities.cc.

119  {
120  addOption<std::string>(connectionOptionName,shortName,helpEntry);
121  m_dbSessions.insert(connectionOptionName);
122 }
std::set< std::string > m_dbSessions
Definition: Utilities.h:84
void cond::Utilities::addDictionaryOption ( )

Definition at line 131 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

131  {
132  addOption<std::vector<std::string> >("dictionary","D","data dictionaries (required if no plugin available)");
133 }
void cond::Utilities::addLogDBOption ( )

Definition at line 126 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

126  {
127  addConnectOption("logDB","l","logDB(optional");
128 }
void addConnectOption()
Definition: Utilities.cc:111
template<typename T >
void cond::Utilities::addOption ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
)
inline

Definition at line 88 of file Utilities.h.

References newFWLiteAna::fullName, and m_options.

90  {
91  std::stringstream optInfo;
92  optInfo << fullName;
93  if(!shortName.empty()) optInfo << ","<<shortName;
94  m_options.add_options()
95  (optInfo.str().c_str(),boost::program_options::value<T>(),helpEntry.c_str());
96 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:80
template<>
void cond::Utilities::addOption ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
)
inline

Definition at line 98 of file Utilities.h.

References newFWLiteAna::fullName.

100  {
101  std::stringstream optInfo;
102  optInfo << fullName;
103  if(!shortName.empty()) optInfo << ","<<shortName;
104  m_options.add_options()
105  (optInfo.str().c_str(),helpEntry.c_str());
106 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:80
void cond::Utilities::addSQLOutputOption ( )

Definition at line 141 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

141  {
142  addOption<bool>("sql","S","dump the sql output (optional)");
143 }
int cond::Utilities::execute ( )
virtual

Reimplemented in cond::AlignSplitIOV, and cond::ExportIOVUtilities.

Definition at line 49 of file Utilities.cc.

49  {
50  return 0;
51 }
std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 159 of file Utilities.cc.

159  {
160  return getOptionValue<std::string>("authPath");
161 }
std::string cond::Utilities::getConfigFileValue ( )

Definition at line 183 of file Utilities.cc.

183  {
184  return getOptionValue<std::string>("configFile");
185 }
std::string cond::Utilities::getConnectValue ( )

Definition at line 171 of file Utilities.cc.

171  {
172  return getOptionValue<std::string>("connect");
173 }
std::string cond::Utilities::getDictionaryValue ( )

Definition at line 179 of file Utilities.cc.

179  {
180  return getOptionValue<std::string>("dictionary");
181 }
std::string cond::Utilities::getLogDBValue ( )

Definition at line 175 of file Utilities.cc.

175  {
176  return getOptionValue<std::string>("logDB");
177 }
template<typename T >
T cond::Utilities::getOptionValue ( const std::string &  fullName)
inline

Definition at line 111 of file Utilities.h.

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

111  {
112  const void* found = m_options.find_nothrow(fullName, false);
113  if(!found){
114  std::stringstream message;
115  message << "Utilities::getOptionValue: option \"" << fullName << "\" is not known by the command.";
116  sendException(message.str());
117  }
118 
119  if (!m_values.count(fullName)) {
120  std::stringstream message;
121  message << "Error: Option \"" << fullName << "\" has not been provided.";
122  sendError(message.str());
123  }
124  return m_values[fullName].as<T>();
125 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:82
void sendError(const std::string &message)
Definition: Utilities.cc:281
void sendException(const std::string &message)
Definition: Utilities.cc:285
boost::program_options::options_description m_options
Definition: Utilities.h:80
long double T
std::string cond::Utilities::getPasswordValue ( )

Definition at line 167 of file Utilities.cc.

167  {
168  return getOptionValue<std::string>("pass");
169 }
std::string cond::Utilities::getUserValue ( )

Definition at line 163 of file Utilities.cc.

163  {
164  return getOptionValue<std::string>("user");
165 }
std::string cond::Utilities::getValueIfExists ( const std::string &  fullName)
private

Definition at line 273 of file Utilities.cc.

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

273  {
274  std::string val("");
275  if(m_values.count(fullName)){
276  val = m_values[fullName].as<std::string>();
277  }
278  return val;
279 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:82
bool cond::Utilities::hasDebug ( )

Definition at line 198 of file Utilities.cc.

198  {
199  return m_values.count("debug");
200 }
boost::program_options::variables_map m_values
Definition: Utilities.h:82
bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 188 of file Utilities.cc.

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

188  {
189  const void* found = m_options.find_nothrow(fullName, false);
190  if(!found){
191  std::stringstream message;
192  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
193  sendException(message.str());
194  }
195  return m_values.count(fullName);
196 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:82
void sendException(const std::string &message)
Definition: Utilities.cc:285
boost::program_options::options_description m_options
Definition: Utilities.h:80
void cond::Utilities::initializeForDbConnection ( )
protected

Definition at line 206 of file Utilities.cc.

References builder_last_value_cfg::authPath, Debug, AlCaHLTBitMon_QueryRunRegistry::string, and hcal_dqm_sourceclient-file_cfg::user.

206  {
207  if(!m_dbConnection){
209  if( hasDebug() ){
211  } else {
213  }
216 
217  if(m_options.find_nothrow("authPath", false) &&
218  m_options.find_nothrow("user",false) &&
219  m_options.find_nothrow("pass",false)){
220  std::string authPath = getValueIfExists("authPath");
222  std::string pass = getValueIfExists("pass");
223  if( !authPath.empty() ){
225  } else {
226  if( !user.empty() && !pass.empty() ){
227  std::string userenv(std::string("CORAL_AUTH_USER=")+user);
228  std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
229  ::putenv(const_cast<char*>(userenv.c_str()));
230  ::putenv(const_cast<char*>(passenv.c_str()));
231  }
232  }
233  }
234  if(m_options.find_nothrow("sql",false)){
235  if(m_values.count("sql")) {
237  }
238  }
240 
241  }
242 
243 }
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:273
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83
boost::program_options::variables_map m_values
Definition: Utilities.h:82
void setAuthenticationPath(const std::string &p)
boost::program_options::options_description m_options
Definition: Utilities.h:80
const bool Debug
void cond::Utilities::initializePluginManager ( )

Definition at line 202 of file Utilities.cc.

202  {
203  // dummy, to avoid to adapt non-CondCore clients
204 }
cond::DbSession cond::Utilities::newDbSession ( const std::string &  connectionString,
bool  readOnly = false 
)
protected

Definition at line 245 of file Utilities.cc.

References cond::DbSession::open(), and python.CommonUtils::session.

246  {
249  session.open( connectionString, readOnly );
250  return session;
251 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83
DbSession createSession() const
Definition: DbConnection.cc:66
void initializeForDbConnection()
Definition: Utilities.cc:206
cond::DbSession cond::Utilities::newDbSession ( const std::string &  connectionString,
const std::string &  role,
bool  readOnly = false 
)
protected

Definition at line 252 of file Utilities.cc.

References cond::DbSession::open(), and python.CommonUtils::session.

254  {
257  session.open( connectionString, role, readOnly );
258  return session;
259 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83
DbSession createSession() const
Definition: DbConnection.cc:66
void initializeForDbConnection()
Definition: Utilities.cc:206
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
bool  readOnly = false 
)

Definition at line 267 of file Utilities.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

268  {
269  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
270  return newDbSession( connectionString, readOnly );
271 }
cond::DbSession newDbSession(const std::string &connectionString, bool readOnly=false)
Definition: Utilities.cc:245
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
const std::string &  role,
bool  readOnly = false 
)

Definition at line 260 of file Utilities.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

262  {
263  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
264  return newDbSession( connectionString, role, readOnly );
265 }
cond::DbSession newDbSession(const std::string &connectionString, bool readOnly=false)
Definition: Utilities.cc:245
void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 145 of file Utilities.cc.

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

145  {
146  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
147  if(m_options.find_nothrow("configFile",false)){
148  std::string configFileName = getValueIfExists("configFile");
149  if (! configFileName.empty()){
150  std::fstream configFile;
151  configFile.open(configFileName.c_str(), std::fstream::in);
152  boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
153  configFile.close();
154  }
155  }
156  boost::program_options::notify(m_values);
157 }
int run(int argc, char **argv)
Definition: Utilities.cc:53
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:273
tuple argc
Definition: dir2webdir.py:38
boost::program_options::variables_map m_values
Definition: Utilities.h:82
boost::program_options::options_description m_options
Definition: Utilities.h:80
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:81
int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 53 of file Utilities.cc.

References edm::ParameterSet::addParameter(), HDQMDatabaseProducer::config, edmplugin::standard::config(), edmplugin::PluginManager::configure(), gather_cfg::cout, edm::ServiceRegistry::createSet(), python.multivaluedict::dict, cppFunctionSkipper::exception, cmsIgProf_Analysis::execute(), cmsPerfStripChart::operate(), cond::SQLReport::putOnFile(), zeeHLT_cff::report, cond::SQLReport::reportForConnection(), run_regression::ret, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

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

53  {
56 
57  std::vector<edm::ParameterSet> psets;
58  edm::ParameterSet pSet;
59  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
60  psets.push_back(pSet);
62  m_currentToken = &servToken;
64 
65  int ret = 0;
66  try{
68  if (m_values.count("help")) {
69  std::cout << m_options <<std::endl;;
70  return 0;
71  }
72  if(m_options.find_nothrow("dictionary",false)&& m_values.count("dictionary")){
73  std::vector<std::string> dictionaries =
74  m_values["dictionary"].as<std::vector<std::string> >();
75  if(!dictionaries.empty()){
76  ora::SharedLibraryName libName;
77  BOOST_FOREACH(std::string const & dict, dictionaries)
78  edmplugin::SharedLibrary( libName(dict) );
79  }
80  }
81  ret = execute();
83  if(m_options.find_nothrow("sql",false) && m_values.count("sql")){
84  cond::SQLReport report(*m_dbConnection);
85  for(std::set<std::string>::const_iterator iSess = m_dbSessions.begin();
86  iSess != m_dbSessions.end();
87  iSess++) report.reportForConnection(*iSess);
88  report.putOnFile();
89  }
90  }
91 
92  }catch( cond::Exception& err ){
93  std::cout << err.what() << std::endl;
94  ret = 1;
95  }catch( const std::exception& exc ){
96  std::cout << exc.what() << std::endl;
97  ret = 1;
98  }
99  m_currentToken = nullptr;
100  return ret;
101 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:145
virtual char const * what() const
Definition: Exception.cc:141
static PluginManager & configure(const Config &)
edm::ServiceToken * m_currentToken
Definition: Utilities.h:74
tuple report
Definition: zeeHLT_cff.py:9
std::set< std::string > m_dbSessions
Definition: Utilities.h:84
cond::DbConnection * m_dbConnection
Definition: Utilities.h:83
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:142
static ServiceToken createSet(std::vector< ParameterSet > &)
tuple argc
Definition: dir2webdir.py:38
boost::program_options::variables_map m_values
Definition: Utilities.h:82
if(dp >Float(M_PI)) dp-
tuple cout
Definition: gather_cfg.py:121
boost::program_options::options_description m_options
Definition: Utilities.h:80
virtual int execute()
Definition: Utilities.cc:49
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 281 of file Utilities.cc.

Referenced by getOptionValue().

281  {
283 }
void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 285 of file Utilities.cc.

References edm::hlt::Exception.

Referenced by getOptionValue().

285  {
286  throw cond::Exception(message);
287 }

Member Data Documentation

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

Definition at line 74 of file Utilities.h.

cond::DbConnection* cond::Utilities::m_dbConnection
private

Definition at line 83 of file Utilities.h.

std::set<std::string> cond::Utilities::m_dbSessions
private

Definition at line 84 of file Utilities.h.

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

Definition at line 78 of file Utilities.h.

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

Definition at line 80 of file Utilities.h.

Referenced by addOption(), getOptionValue(), and Utilities().

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

Definition at line 81 of file Utilities.h.

Referenced by Utilities().

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

Definition at line 82 of file Utilities.h.

Referenced by getOptionValue().