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

Constructor & Destructor Documentation

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

Definition at line 22 of file Utilities.cc.

References m_options, and m_positionalOptions.

23  :m_name(commandName),
24  m_options(std::string("Usage: ")+m_name+
25  std::string(" [options] ")+positionalParameter
26  +std::string(" \n")),
28  m_values(){
29  m_options.add_options()
30  ("debug","switch on debug mode")
31  ("help,h", "help message")
32  ;
33  if(!positionalParameter.empty()) {
34  m_positionalOptions.add( positionalParameter.c_str(), -1);
35  addOption<std::string>(positionalParameter,"",positionalParameter);
36  }
37 }
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 40 of file Utilities.cc.

40  {
41 }

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 86 of file Utilities.cc.

86  {
87  addOption<std::string>("authPath","P","path to the authentication key");
88  addOption<std::string>("user","u","user name");
89  addOption<std::string>("pass","p","password");
90 }
void cond::Utilities::addConfigFileOption ( )

Definition at line 93 of file Utilities.cc.

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

Definition at line 79 of file Utilities.cc.

81  {
82  addOption<std::string>(connectionOptionName,shortName,helpEntry);
83 }
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.

83  {
84  std::stringstream optInfo;
85  optInfo << fullName;
86  if(!shortName.empty()) optInfo << ","<<shortName;
87  m_options.add_options()
88  (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 91 of file Utilities.h.

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

Definition at line 43 of file Utilities.cc.

Referenced by run().

43  {
44  return 0;
45 }
std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 111 of file Utilities.cc.

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

Definition at line 135 of file Utilities.cc.

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

Definition at line 123 of file Utilities.cc.

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

Definition at line 131 of file Utilities.cc.

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

Definition at line 127 of file Utilities.cc.

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

Definition at line 104 of file Utilities.h.

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

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

Definition at line 119 of file Utilities.cc.

119  {
120  return getOptionValue<std::string>("pass");
121 }
std::string cond::Utilities::getUserValue ( )

Definition at line 115 of file Utilities.cc.

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

Definition at line 158 of file Utilities.cc.

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

Referenced by parseCommand().

158  {
159  std::string val("");
160  if(m_values.count(fullName)){
161  val = m_values[fullName].as<std::string>();
162  }
163  return val;
164 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
bool cond::Utilities::hasDebug ( )

Definition at line 150 of file Utilities.cc.

References m_values.

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

Definition at line 140 of file Utilities.cc.

References runEdmFileComparison::found, m_options, m_values, python.rootplot.argparse::message, and sendException().

140  {
141  const void* found = m_options.find_nothrow(fullName, false);
142  if(!found){
143  std::stringstream message;
144  message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
145  sendException(message.str());
146  }
147  return m_values.count(fullName);
148 }
boost::program_options::variables_map m_values
Definition: Utilities.h:75
void sendException(const std::string &message)
Definition: Utilities.cc:170
boost::program_options::options_description m_options
Definition: Utilities.h:73
void cond::Utilities::initializePluginManager ( )

Definition at line 154 of file Utilities.cc.

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

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

97  {
98  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
99  if(m_options.find_nothrow("configFile",false)){
100  std::string configFileName = getValueIfExists("configFile");
101  if (! configFileName.empty()){
102  std::fstream configFile;
103  configFile.open(configFileName.c_str(), std::fstream::in);
104  boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
105  configFile.close();
106  }
107  }
108  boost::program_options::notify(m_values);
109 }
int run(int argc, char **argv)
Definition: Utilities.cc:47
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:158
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 47 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().

47  {
50 
51  std::vector<edm::ParameterSet> psets;
52  edm::ParameterSet pSet;
53  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
54  psets.push_back(pSet);
56  m_currentToken = &servToken;
58 
59  int ret = 0;
60  try{
62  if (m_values.count("help")) {
63  std::cout << m_options <<std::endl;;
64  return 0;
65  }
66  ret = execute();
67  }catch( cond::Exception& err ){
68  std::cout << err.what() << std::endl;
69  ret = 1;
70  }catch( const std::exception& exc ){
71  std::cout << exc.what() << std::endl;
72  ret = 1;
73  }
74  m_currentToken = nullptr;
75  return ret;
76 }
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:97
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:67
config
Definition: looper.py:287
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
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:43
def operate(timelog, memlog, json_f, num)
void cond::Utilities::sendError ( const std::string &  message)
private

Definition at line 166 of file Utilities.cc.

void cond::Utilities::sendException ( const std::string &  message)
private

Definition at line 170 of file Utilities.cc.

Referenced by hasOptionValue().

170  {
171  throw cond::Exception(message);
172 }
persistency::Exception Exception
Definition: Exception.h:25

Member Data Documentation

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

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