CMS 3D CMS Logo

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 24 of file Utilities.h.

Constructor & Destructor Documentation

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

Definition at line 75 of file Utilities.cc.

References m_options, and m_positionalOptions.

76  :m_name(commandName),
77  m_options(std::string("Usage: ")+m_name+
78  std::string(" [options] ")+positionalParameter
79  +std::string(" \n")),
81  m_values(){
82  m_options.add_options()
83  ("debug","switch on debug mode")
84  ("help,h", "help message")
85  ;
86  if(!positionalParameter.empty()) {
87  m_positionalOptions.add( positionalParameter.c_str(), -1);
88  addOption<std::string>(positionalParameter,"",positionalParameter);
89  }
90 }
boost::program_options::variables_map m_values
Definition: Utilities.h:77
std::string m_name
Definition: Utilities.h:73
boost::program_options::options_description m_options
Definition: Utilities.h:75
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:76
cond::Utilities::~Utilities ( )
virtual

Definition at line 93 of file Utilities.cc.

93  {
94 }

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 139 of file Utilities.cc.

139  {
140  addOption<std::string>("authPath","P","path to the authentication key");
141  addOption<std::string>("user","u","user name");
142  addOption<std::string>("pass","p","password");
143 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 146 of file Utilities.cc.

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

Definition at line 132 of file Utilities.cc.

134  {
135  addOption<std::string>(connectionOptionName,shortName,helpEntry);
136 }
template<typename T >
void cond::Utilities::addOption ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
)
inline

Definition at line 83 of file Utilities.h.

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

Definition at line 93 of file Utilities.h.

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

Definition at line 96 of file Utilities.cc.

Referenced by run().

96  {
97  return 0;
98 }
std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 164 of file Utilities.cc.

164  {
165  return getOptionValue<std::string>("authPath");
166 }
std::string cond::Utilities::getConfigFileValue ( )

Definition at line 188 of file Utilities.cc.

188  {
189  return getOptionValue<std::string>("configFile");
190 }
std::string cond::Utilities::getConnectValue ( )

Definition at line 176 of file Utilities.cc.

176  {
177  return getOptionValue<std::string>("connect");
178 }
std::string cond::Utilities::getDictionaryValue ( )

Definition at line 184 of file Utilities.cc.

184  {
185  return getOptionValue<std::string>("dictionary");
186 }
std::string cond::Utilities::getLogDBValue ( )

Definition at line 180 of file Utilities.cc.

180  {
181  return getOptionValue<std::string>("logDB");
182 }
template<typename T >
T cond::Utilities::getOptionValue ( const std::string &  fullName)
inline

Definition at line 106 of file Utilities.h.

References runEdmFileComparison::found.

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

Definition at line 172 of file Utilities.cc.

172  {
173  return getOptionValue<std::string>("pass");
174 }
std::string cond::Utilities::getUserValue ( )

Definition at line 168 of file Utilities.cc.

168  {
169  return getOptionValue<std::string>("user");
170 }
std::string cond::Utilities::getValueIfExists ( const std::string &  fullName)
private

Definition at line 211 of file Utilities.cc.

References m_values, AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

Referenced by parseCommand().

211  {
212  std::string val("");
213  if(m_values.count(fullName)){
214  val = m_values[fullName].as<std::string>();
215  }
216  return val;
217 }
boost::program_options::variables_map m_values
Definition: Utilities.h:77
bool cond::Utilities::hasDebug ( )

Definition at line 203 of file Utilities.cc.

References m_values.

203  {
204  return m_values.count("debug");
205 }
boost::program_options::variables_map m_values
Definition: Utilities.h:77
bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 193 of file Utilities.cc.

References runEdmFileComparison::found, m_options, m_values, and sendException().

193  {
194  const void* found = m_options.find_nothrow(fullName, false);
195  if(!found){
196  std::stringstream message;
197  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
198  sendException(message.str());
199  }
200  return m_values.count(fullName);
201 }
boost::program_options::variables_map m_values
Definition: Utilities.h:77
void sendException(const std::string &message)
Definition: Utilities.cc:223
boost::program_options::options_description m_options
Definition: Utilities.h:75
void cond::Utilities::initializePluginManager ( )

Definition at line 207 of file Utilities.cc.

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

Definition at line 150 of file Utilities.cc.

References getValueIfExists(), recoMuon::in, m_options, m_positionalOptions, m_values, AlcaSiPixelAliHarvester0T_cff::options, run(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by run().

150  {
151  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
152  if(m_options.find_nothrow("configFile",false)){
153  std::string configFileName = getValueIfExists("configFile");
154  if (! configFileName.empty()){
155  std::fstream configFile;
156  configFile.open(configFileName.c_str(), std::fstream::in);
157  boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
158  configFile.close();
159  }
160  }
161  boost::program_options::notify(m_values);
162 }
int run(int argc, char **argv)
Definition: Utilities.cc:100
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:211
boost::program_options::variables_map m_values
Definition: Utilities.h:77
boost::program_options::options_description m_options
Definition: Utilities.h:75
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:76
int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 100 of file Utilities.cc.

References edm::ParameterSet::addParameter(), edmplugin::standard::config(), looper::config, edmplugin::PluginManager::configure(), gather_cfg::cout, edm::ServiceRegistry::createSet(), cppFunctionSkipper::exception, execute(), m_currentToken, m_options, m_values, cmsPerfStripChart::operate(), parseCommand(), AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

Referenced by Types.EventID::cppID(), Types.LuminosityBlockID::cppID(), o2olib.O2OTool::execute(), and parseCommand().

100  {
103 
104  std::vector<edm::ParameterSet> psets;
105  edm::ParameterSet pSet;
106  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
107  psets.push_back(pSet);
109  m_currentToken = &servToken;
111 
112  int ret = 0;
113  try{
114  parseCommand( argc, argv );
115  if (m_values.count("help")) {
116  std::cout << m_options <<std::endl;;
117  return 0;
118  }
119  ret = execute();
120  }catch( cond::Exception& err ){
121  std::cout << err.what() << std::endl;
122  ret = 1;
123  }catch( const std::exception& exc ){
124  std::cout << exc.what() << std::endl;
125  ret = 1;
126  }
127  m_currentToken = nullptr;
128  return ret;
129 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:150
Base exception class for the object to relational access.
Definition: Exception.h:11
static PluginManager & configure(const Config &)
char const * what() const override
Definition: Exception.cc:141
edm::ServiceToken * m_currentToken
Definition: Utilities.h:69
config
Definition: looper.py:289
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:143
static ServiceToken createSet(std::vector< ParameterSet > &)
boost::program_options::variables_map m_values
Definition: Utilities.h:77
boost::program_options::options_description m_options
Definition: Utilities.h:75
virtual int execute()
Definition: Utilities.cc:96
def operate(timelog, memlog, json_f, num)
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 219 of file Utilities.cc.

219  {
220  throw cond::UtilitiesError(message);
221 }
void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 223 of file Utilities.cc.

Referenced by hasOptionValue().

223  {
224  throw cond::Exception(message);
225 }
persistency::Exception Exception
Definition: Exception.h:25

Member Data Documentation

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

Definition at line 69 of file Utilities.h.

Referenced by run().

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

Definition at line 73 of file Utilities.h.

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

Definition at line 75 of file Utilities.h.

Referenced by hasOptionValue(), parseCommand(), run(), and Utilities().

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

Definition at line 76 of file Utilities.h.

Referenced by parseCommand(), and Utilities().

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

Definition at line 77 of file Utilities.h.

Referenced by getValueIfExists(), hasDebug(), hasOptionValue(), parseCommand(), and run().