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

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

◆ Utilities()

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

◆ ~Utilities()

cond::Utilities::~Utilities ( )
virtual

Definition at line 85 of file Utilities.cc.

85 {}

Member Function Documentation

◆ addAuthenticationOptions()

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 }

◆ addConfigFileOption()

void cond::Utilities::addConfigFileOption ( )

Definition at line 133 of file Utilities.cc.

133  {
134  addOption<std::string>("configFile", "f", "configuration file(optional)");
135 }

◆ addConnectOption()

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 }

◆ addOption() [1/2]

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, and m_options.

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

◆ addOption() [2/2]

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

◆ execute()

int cond::Utilities::execute ( )
virtual

Definition at line 87 of file Utilities.cc.

87 { return 0; }

◆ getAuthenticationPathValue()

std::string cond::Utilities::getAuthenticationPathValue ( )

Definition at line 153 of file Utilities.cc.

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

◆ getConfigFileValue()

std::string cond::Utilities::getConfigFileValue ( )

Definition at line 165 of file Utilities.cc.

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

◆ getConnectValue()

std::string cond::Utilities::getConnectValue ( )

Definition at line 159 of file Utilities.cc.

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

◆ getDictionaryValue()

std::string cond::Utilities::getDictionaryValue ( )

Definition at line 163 of file Utilities.cc.

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

◆ getLogDBValue()

std::string cond::Utilities::getLogDBValue ( )

Definition at line 161 of file Utilities.cc.

161 { return getOptionValue<std::string>("logDB"); }

◆ getOptionValue()

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

◆ getPasswordValue()

std::string cond::Utilities::getPasswordValue ( )

Definition at line 157 of file Utilities.cc.

157 { return getOptionValue<std::string>("pass"); }

◆ getUserValue()

std::string cond::Utilities::getUserValue ( )

Definition at line 155 of file Utilities.cc.

155 { return getOptionValue<std::string>("user"); }

◆ getValueIfExists()

std::string cond::Utilities::getValueIfExists ( const std::string &  fullName)
private

Definition at line 183 of file Utilities.cc.

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

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

◆ hasDebug()

bool cond::Utilities::hasDebug ( )

Definition at line 177 of file Utilities.cc.

177 { return m_values.count("debug"); }
boost::program_options::variables_map m_values
Definition: Utilities.h:75

◆ hasOptionValue()

bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 167 of file Utilities.cc.

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

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

◆ initializePluginManager()

void cond::Utilities::initializePluginManager ( )

Definition at line 179 of file Utilities.cc.

179  {
180  // dummy, to avoid to adapt non-CondCore clients
181 }

◆ parseCommand()

void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 137 of file Utilities.cc.

References dir2webdir::argc, GCPpyPlots::argv, GCPpyPlots::configFile, recoMuon::in, AlcaSiPixelAliHarvester0T_cff::options, writedatasetfile::run, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ run()

int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 89 of file Utilities.cc.

References edm::ParameterSet::addParameter(), dir2webdir::argc, GCPpyPlots::argv, DMR_cfg::config, edmplugin::standard::config(), edmplugin::PluginManager::configure(), gather_cfg::cout, edm::ServiceRegistry::createSet(), submitPVResolutionJobs::err, cppFunctionSkipper::exception, runTheMatrix::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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
dictionary config
Read in AllInOne config in JSON format.
Definition: DMR_cfg.py:21
edm::ServiceToken * m_currentToken
Definition: Utilities.h:68
PluginManager::Config config()
Definition: standard.cc:21
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
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

◆ sendError()

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

Definition at line 191 of file Utilities.cc.

Referenced by getOptionValue().

191 { throw cond::UtilitiesError(message); }

◆ sendException()

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

Definition at line 193 of file Utilities.cc.

Referenced by getOptionValue().

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

Member Data Documentation

◆ m_currentToken

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

Definition at line 68 of file Utilities.h.

◆ m_name

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

Definition at line 71 of file Utilities.h.

◆ m_options

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

Definition at line 73 of file Utilities.h.

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

◆ m_positionalOptions

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

Definition at line 74 of file Utilities.h.

Referenced by Utilities().

◆ m_values

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

Definition at line 75 of file Utilities.h.

Referenced by getOptionValue().