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 | 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

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

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::DbConnectionm_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
 

Detailed Description

Definition at line 19 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),
34  m_dbSessions(){
35  m_options.add_options()
36  ("debug","switch on debug mode")
37  ("help,h", "help message")
38  ;
39  if(!positionalParameter.empty()) {
40  m_positionalOptions.add( positionalParameter.c_str(), -1);
41  addOption<std::string>(positionalParameter,"",positionalParameter);
42  }
43 }
bool m_pluginMgrInitialized
Definition: Utilities.h:77
std::set< std::string > m_dbSessions
Definition: Utilities.h:78
cond::DbConnection * m_dbConnection
Definition: Utilities.h:76
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 46 of file Utilities.cc.

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

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 94 of file Utilities.cc.

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

94  {
95  addOption<std::string>("authPath","P","path to authentication xml");
96  addOption<std::string>("user","u","user name");
97  addOption<std::string>("pass","p","password");
98 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 126 of file Utilities.cc.

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

126  {
127  addOption<std::string>("configFile","f","configuration file(optional)");
128 }
void cond::Utilities::addConnectOption ( )

Definition at line 101 of file Utilities.cc.

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

101  {
102  addOption<std::string>("connect","c","connection string (required)");
103  m_dbSessions.insert("connect");
104 }
std::set< std::string > m_dbSessions
Definition: Utilities.h:78
void cond::Utilities::addConnectOption ( const std::string &  connectionOptionName,
const std::string &  shortName,
const std::string &  helpEntry 
)

Definition at line 107 of file Utilities.cc.

109  {
110  addOption<std::string>(connectionOptionName,shortName,helpEntry);
111  m_dbSessions.insert(connectionOptionName);
112 }
std::set< std::string > m_dbSessions
Definition: Utilities.h:78
void cond::Utilities::addDictionaryOption ( )

Definition at line 121 of file Utilities.cc.

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

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

Definition at line 116 of file Utilities.cc.

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

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

Definition at line 82 of file Utilities.h.

References newFWLiteAna::fullName, and m_options.

84  {
85  std::stringstream optInfo;
86  optInfo << fullName;
87  if(!shortName.empty()) optInfo << ","<<shortName;
88  m_options.add_options()
89  (optInfo.str().c_str(),boost::program_options::value<T>(),helpEntry.c_str());
90 }
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 92 of file Utilities.h.

References newFWLiteAna::fullName.

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

Definition at line 131 of file Utilities.cc.

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

131  {
132  addOption<bool>("sql","S","dump the sql output (optional)");
133 }
int cond::Utilities::execute ( )
virtual

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

Definition at line 50 of file Utilities.cc.

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

Definition at line 149 of file Utilities.cc.

149  {
150  return getOptionValue<std::string>("authPath");
151 }
std::string cond::Utilities::getConfigFileValue ( )

Definition at line 173 of file Utilities.cc.

173  {
174  return getOptionValue<std::string>("configFile");
175 }
std::string cond::Utilities::getConnectValue ( )

Definition at line 161 of file Utilities.cc.

161  {
162  return getOptionValue<std::string>("connect");
163 }
std::string cond::Utilities::getDictionaryValue ( )

Definition at line 169 of file Utilities.cc.

169  {
170  return getOptionValue<std::string>("dictionary");
171 }
std::string cond::Utilities::getLogDBValue ( )

Definition at line 165 of file Utilities.cc.

165  {
166  return getOptionValue<std::string>("logDB");
167 }
template<typename T >
T cond::Utilities::getOptionValue ( const std::string &  fullName)
inline

Definition at line 105 of file Utilities.h.

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

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

Definition at line 157 of file Utilities.cc.

157  {
158  return getOptionValue<std::string>("pass");
159 }
std::string cond::Utilities::getUserValue ( )

Definition at line 153 of file Utilities.cc.

153  {
154  return getOptionValue<std::string>("user");
155 }
std::string cond::Utilities::getValueIfExists ( const std::string &  fullName)
private

Definition at line 276 of file Utilities.cc.

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

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

Definition at line 188 of file Utilities.cc.

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

Definition at line 178 of file Utilities.cc.

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

178  {
179  const void* found = m_options.find_nothrow(fullName, false);
180  if(!found){
181  std::stringstream message;
182  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
183  sendException(message.str());
184  }
185  return m_values.count(fullName);
186 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendException(const std::string &message)
Definition: Utilities.cc:288
boost::program_options::options_description m_options
Definition: Utilities.h:73
void cond::Utilities::initializeForDbConnection ( )
private

Definition at line 208 of file Utilities.cc.

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

208  {
209  if(!m_dbConnection){
212  if( hasDebug() ){
214  } else {
216  }
219 
220  if(m_options.find_nothrow("authPath", false) &&
221  m_options.find_nothrow("user",false) &&
222  m_options.find_nothrow("pass",false)){
223  std::string authPath = getValueIfExists("authPath");
225  std::string pass = getValueIfExists("pass");
226  if( !authPath.empty() ){
228  } else {
229  if( !user.empty() && !pass.empty() ){
230  std::string userenv(std::string("CORAL_AUTH_USER=")+user);
231  std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
232  ::putenv(const_cast<char*>(userenv.c_str()));
233  ::putenv(const_cast<char*>(passenv.c_str()));
234  }
235  }
236  }
237  if(m_options.find_nothrow("sql",false)){
238  if(m_values.count("sql")) {
240  }
241  }
243 
244  }
245 
246 }
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:276
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:83
cond::DbConnection * m_dbConnection
Definition: Utilities.h:76
void initializePluginManager()
Definition: Utilities.cc:192
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void setAuthenticationPath(const std::string &p)
boost::program_options::options_description m_options
Definition: Utilities.h:73
const bool Debug
void cond::Utilities::initializePluginManager ( )

Definition at line 192 of file Utilities.cc.

References edm::ParameterSet::addParameter(), HDQMDatabaseProducer::config, edmplugin::standard::config(), edmplugin::PluginManager::configure(), edm::ServiceRegistry::createSet(), cmsPerfStripChart::operate(), and AlCaHLTBitMon_QueryRunRegistry::string.

192  {
196 
197  std::vector<edm::ParameterSet> psets;
198  edm::ParameterSet pSet;
199  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
200  psets.push_back(pSet);
201  static const edm::ServiceToken services(edm::ServiceRegistry::createSet(psets));
202  static const edm::ServiceRegistry::Operate operate(services);
203 
204  m_pluginMgrInitialized = true;
205  }
206 }
static PluginManager & configure(const Config &)
bool m_pluginMgrInitialized
Definition: Utilities.h:77
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 > &)
cond::DbSession cond::Utilities::newDbSession ( const std::string &  connectionString,
bool  readOnly = false 
)
protected

Definition at line 248 of file Utilities.cc.

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

249  {
252  session.open( connectionString, readOnly );
253  return session;
254 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
cond::DbConnection * m_dbConnection
Definition: Utilities.h:76
DbSession createSession() const
Definition: DbConnection.cc:66
void initializeForDbConnection()
Definition: Utilities.cc:208
cond::DbSession cond::Utilities::newDbSession ( const std::string &  connectionString,
const std::string &  role,
bool  readOnly = false 
)
protected

Definition at line 255 of file Utilities.cc.

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

257  {
260  session.open( connectionString, role, readOnly );
261  return session;
262 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:159
cond::DbConnection * m_dbConnection
Definition: Utilities.h:76
DbSession createSession() const
Definition: DbConnection.cc:66
void initializeForDbConnection()
Definition: Utilities.cc:208
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
bool  readOnly = false 
)

Definition at line 270 of file Utilities.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

271  {
272  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
273  return newDbSession( connectionString, readOnly );
274 }
cond::DbSession newDbSession(const std::string &connectionString, bool readOnly=false)
Definition: Utilities.cc:248
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
const std::string &  role,
bool  readOnly = false 
)

Definition at line 263 of file Utilities.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 135 of file Utilities.cc.

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

135  {
136  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
137  if(m_options.find_nothrow("configFile",false)){
138  std::string configFileName = getValueIfExists("configFile");
139  if (! configFileName.empty()){
140  std::fstream configFile;
141  configFile.open(configFileName.c_str(), std::fstream::in);
142  boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
143  configFile.close();
144  }
145  }
146  boost::program_options::notify(m_values);
147 }
int run(int argc, char **argv)
Definition: Utilities.cc:54
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:276
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 54 of file Utilities.cc.

References gather_cfg::cout, python.multivaluedict::dict, cppFunctionSkipper::exception, cmsIgProf_Analysis::execute(), 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().

54  {
55  int ret = 0;
56  try{
58  if (m_values.count("help")) {
59  std::cout << m_options <<std::endl;;
60  return 0;
61  }
62  if(m_options.find_nothrow("dictionary",false)&& m_values.count("dictionary")){
63  std::vector<std::string> dictionaries =
64  m_values["dictionary"].as<std::vector<std::string> >();
65  if(!dictionaries.empty()){
67  ora::SharedLibraryName libName;
68  BOOST_FOREACH(std::string const & dict, dictionaries)
69  edmplugin::SharedLibrary( libName(dict) );
70  }
71  }
72  ret = execute();
74  if(m_options.find_nothrow("sql",false) && m_values.count("sql")){
75  cond::SQLReport report(*m_dbConnection);
76  for(std::set<std::string>::const_iterator iSess = m_dbSessions.begin();
77  iSess != m_dbSessions.end();
78  iSess++) report.reportForConnection(*iSess);
79  report.putOnFile();
80  }
81  }
82 
83  }catch( cond::Exception& err ){
84  std::cout << err.what() << std::endl;
85  ret = 1;
86  }catch( const std::exception& exc ){
87  std::cout << exc.what() << std::endl;
88  ret = 1;
89  }
90  return ret;
91 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:135
virtual char const * what() const
Definition: Exception.cc:141
tuple report
Definition: zeeHLT_cff.py:9
std::set< std::string > m_dbSessions
Definition: Utilities.h:78
cond::DbConnection * m_dbConnection
Definition: Utilities.h:76
void initializePluginManager()
Definition: Utilities.cc:192
tuple argc
Definition: dir2webdir.py:38
boost::program_options::variables_map m_values
Definition: Utilities.h:75
if(dp >Float(M_PI)) dp-
tuple cout
Definition: gather_cfg.py:121
boost::program_options::options_description m_options
Definition: Utilities.h:73
virtual int execute()
Definition: Utilities.cc:50
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 284 of file Utilities.cc.

Referenced by getOptionValue().

284  {
286 }
void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 288 of file Utilities.cc.

References edm::hlt::Exception.

Referenced by getOptionValue().

288  {
289  throw cond::Exception(message);
290 }

Member Data Documentation

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

Definition at line 76 of file Utilities.h.

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

Definition at line 78 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().

bool cond::Utilities::m_pluginMgrInitialized
private

Definition at line 77 of file Utilities.h.

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().