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 72 of file Utilities.cc.

References m_options, and m_positionalOptions.

73  : m_name(commandName),
74  m_options(std::string("Usage: ") + m_name + std::string(" [options] ") + positionalParameter +
75  std::string(" \n")),
77  m_values() {
78  m_options.add_options()("debug", "switch on debug mode")("help,h", "help message");
79  if (!positionalParameter.empty()) {
80  m_positionalOptions.add(positionalParameter.c_str(), -1);
81  addOption<std::string>(positionalParameter, "", positionalParameter);
82  }
83 }
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 85 of file Utilities.cc.

85 {}

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 127 of file Utilities.cc.

127  {
128  addOption<std::string>("authPath", "P", "path to the authentication key");
129  addOption<std::string>("user", "u", "user name");
130  addOption<std::string>("pass", "p", "password");
131 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 133 of file Utilities.cc.

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

Definition at line 121 of file Utilities.cc.

123  {
124  addOption<std::string>(connectionOptionName, shortName, helpEntry);
125 }
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.

83  {
84  std::stringstream optInfo;
85  optInfo << fullName;
86  if (!shortName.empty())
87  optInfo << "," << shortName;
88  m_options.add_options()(optInfo.str().c_str(), boost::program_options::value<T>(), helpEntry.c_str());
89  }
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())
98  optInfo << "," << shortName;
99  m_options.add_options()(optInfo.str().c_str(), helpEntry.c_str());
100  }
boost::program_options::options_description m_options
Definition: Utilities.h:73
int cond::Utilities::execute ( )
virtual

Definition at line 87 of file Utilities.cc.

Referenced by run().

87 { return 0; }
std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 153 of file Utilities.cc.

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

Definition at line 165 of file Utilities.cc.

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

Definition at line 159 of file Utilities.cc.

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

Definition at line 163 of file Utilities.cc.

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

Definition at line 161 of file Utilities.cc.

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

Definition at line 105 of file Utilities.h.

References newFWLiteAna::found, and newFWLiteAna::fullName.

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 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendError(const std::string &message)
Definition: Utilities.cc:191
void sendException(const std::string &message)
Definition: Utilities.cc:193
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 { return getOptionValue<std::string>("pass"); }
std::string cond::Utilities::getUserValue ( )

Definition at line 155 of file Utilities.cc.

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

Definition at line 183 of file Utilities.cc.

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

Referenced by parseCommand().

183  {
184  std::string val("");
185  if (m_values.count(fullName)) {
186  val = m_values[fullName].as<std::string>();
187  }
188  return val;
189 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
bool cond::Utilities::hasDebug ( )

Definition at line 177 of file Utilities.cc.

References m_values.

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

Definition at line 167 of file Utilities.cc.

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

167  {
168  const void* found = m_options.find_nothrow(fullName, false);
169  if (!found) {
170  std::stringstream message;
171  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
172  sendException(message.str());
173  }
174  return m_values.count(fullName);
175 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendException(const std::string &message)
Definition: Utilities.cc:193
boost::program_options::options_description m_options
Definition: Utilities.h:73
void cond::Utilities::initializePluginManager ( )

Definition at line 179 of file Utilities.cc.

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

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

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

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

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

89  {
92 
93  std::vector<edm::ParameterSet> psets;
94  edm::ParameterSet pSet;
95  pSet.addParameter("@service_type", std::string("SiteLocalConfigService"));
96  psets.push_back(pSet);
98  m_currentToken = &servToken;
99  edm::ServiceRegistry::Operate operate(servToken);
100 
101  int ret = 0;
102  try {
104  if (m_values.count("help")) {
105  std::cout << m_options << std::endl;
106  ;
107  return 0;
108  }
109  ret = execute();
110  } catch (cond::Exception& err) {
111  std::cout << err.what() << std::endl;
112  ret = 1;
113  } catch (const std::exception& exc) {
114  std::cout << exc.what() << std::endl;
115  ret = 1;
116  }
117  m_currentToken = nullptr;
118  return ret;
119 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:137
Base exception class for the object to relational access.
Definition: Exception.h:11
static PluginManager & configure(const Config &)
ret
prodAgent to be discontinued
char const * what() const override
Definition: Exception.cc:103
edm::ServiceToken * m_currentToken
Definition: Utilities.h:68
config
Definition: looper.py:291
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
static ServiceToken createSet(std::vector< ParameterSet > &)
boost::program_options::variables_map m_values
Definition: Utilities.h:75
boost::program_options::options_description m_options
Definition: Utilities.h:73
virtual int execute()
Definition: Utilities.cc:87
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 191 of file Utilities.cc.

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

Definition at line 193 of file Utilities.cc.

Referenced by hasOptionValue().

193 { throw cond::Exception(message); }
persistency::Exception Exception
Definition: Exception.h:25

Member Data Documentation

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

Definition at line 68 of file Utilities.h.

Referenced by run().

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 hasOptionValue(), parseCommand(), run(), and Utilities().

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

Definition at line 74 of file Utilities.h.

Referenced by parseCommand(), and Utilities().

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

Definition at line 75 of file Utilities.h.

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