CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public 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 ()
 

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:73
std::set< std::string > m_dbSessions
Definition: Utilities.h:74
cond::DbConnection * m_dbConnection
Definition: Utilities.h:72
boost::program_options::variables_map m_values
Definition: Utilities.h:71
std::string m_name
Definition: Utilities.h:67
boost::program_options::options_description m_options
Definition: Utilities.h:69
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:70
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:72

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:74
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:74
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 78 of file Utilities.h.

References newFWLiteAna::fullName, and m_options.

80  {
81  std::stringstream optInfo;
82  optInfo << fullName;
83  if(!shortName.empty()) optInfo << ","<<shortName;
84  m_options.add_options()
85  (optInfo.str().c_str(),boost::program_options::value<T>(),helpEntry.c_str());
86 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:69
template<>
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.

90  {
91  std::stringstream optInfo;
92  optInfo << fullName;
93  if(!shortName.empty()) optInfo << ","<<shortName;
94  m_options.add_options()
95  (optInfo.str().c_str(),helpEntry.c_str());
96 }
string fullName
boost::program_options::options_description m_options
Definition: Utilities.h:69
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 101 of file Utilities.h.

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

101  {
102  const void* found = m_options.find_nothrow(fullName, false);
103  if(!found){
104  std::stringstream message;
105  message << "Utilities::getOptionValue: option \"" << fullName << "\" is not known by the command.";
106  sendException(message.str());
107  }
108 
109  if (!m_values.count(fullName)) {
110  std::stringstream message;
111  message << "Error: Option \"" << fullName << "\" has not been provided.";
112  sendError(message.str());
113  }
114  return m_values[fullName].as<T>();
115 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:71
void sendError(const std::string &message)
Definition: Utilities.cc:275
void sendException(const std::string &message)
Definition: Utilities.cc:279
boost::program_options::options_description m_options
Definition: Utilities.h:69
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 267 of file Utilities.cc.

References newFWLiteAna::fullName.

267  {
268  std::string val("");
269  if(m_values.count(fullName)){
270  val = m_values[fullName].as<std::string>();
271  }
272  return val;
273 }
string fullName
boost::program_options::variables_map m_values
Definition: Utilities.h:71
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:71
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:71
void sendException(const std::string &message)
Definition: Utilities.cc:279
boost::program_options::options_description m_options
Definition: Utilities.h:69
void cond::Utilities::initializeForDbConnection ( )
private

Definition at line 208 of file Utilities.cc.

References builder_last_value_cfg::authPath, Debug, 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");
224  std::string user = getValueIfExists("user");
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:267
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
cond::DbConnection * m_dbConnection
Definition: Utilities.h:72
void initializePluginManager()
Definition: Utilities.cc:192
boost::program_options::variables_map m_values
Definition: Utilities.h:71
void setAuthenticationPath(const std::string &p)
boost::program_options::options_description m_options
Definition: Utilities.h:69
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(), and cmsPerfStripChart::operate().

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 edm::ServiceToken services(edm::ServiceRegistry::createSet(psets));
202  static edm::ServiceRegistry::Operate operate(services);
203 
204  m_pluginMgrInitialized = true;
205  }
206 }
static PluginManager & configure(const Config &)
bool m_pluginMgrInitialized
Definition: Utilities.h:73
PluginManager::Config config()
Definition: standard.cc:22
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
static ServiceToken createSet(std::vector< ParameterSet > &)
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
bool  readOnly = false 
)

Definition at line 258 of file Utilities.cc.

References python.CommonUtils::session.

259  {
261  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
263  session.open( connectionString, readOnly );
264  return session;
265 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
cond::DbConnection * m_dbConnection
Definition: Utilities.h:72
DbSession createSession() const
Definition: DbConnection.cc:72
void initializeForDbConnection()
Definition: Utilities.cc:208
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
const std::string &  role,
bool  readOnly = false 
)

Definition at line 248 of file Utilities.cc.

References python.CommonUtils::session.

250  {
252  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
254  session.open( connectionString, role, readOnly );
255  return session;
256 }
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
cond::DbConnection * m_dbConnection
Definition: Utilities.h:72
DbSession createSession() const
Definition: DbConnection.cc:72
void initializeForDbConnection()
Definition: Utilities.cc:208
void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 135 of file Utilities.cc.

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

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:267
tuple argc
Definition: dir2webdir.py:41
boost::program_options::variables_map m_values
Definition: Utilities.h:71
boost::program_options::options_description m_options
Definition: Utilities.h:69
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:70
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, and cms::Exception::what().

Referenced by 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:74
cond::DbConnection * m_dbConnection
Definition: Utilities.h:72
void initializePluginManager()
Definition: Utilities.cc:192
tuple argc
Definition: dir2webdir.py:41
boost::program_options::variables_map m_values
Definition: Utilities.h:71
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:121
boost::program_options::options_description m_options
Definition: Utilities.h:69
virtual int execute()
Definition: Utilities.cc:50
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 275 of file Utilities.cc.

Referenced by getOptionValue().

275  {
277 }
void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 279 of file Utilities.cc.

References edm::hlt::Exception.

Referenced by getOptionValue().

279  {
280  throw cond::Exception(message);
281 }

Member Data Documentation

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

Definition at line 72 of file Utilities.h.

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

Definition at line 74 of file Utilities.h.

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

Definition at line 67 of file Utilities.h.

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

Definition at line 69 of file Utilities.h.

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

bool cond::Utilities::m_pluginMgrInitialized
private

Definition at line 73 of file Utilities.h.

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

Definition at line 70 of file Utilities.h.

Referenced by Utilities().

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

Definition at line 71 of file Utilities.h.

Referenced by getOptionValue().