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.

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 }

References m_options, and m_positionalOptions.

◆ ~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.

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  }

References newFWLiteAna::fullName, and m_options.

◆ 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.

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  }

References newFWLiteAna::fullName, and m_options.

◆ 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.

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 }

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

◆ 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.

183  {
184  std::string val("");
185  if (m_values.count(fullName)) {
186  val = m_values[fullName].as<std::string>();
187  }
188  return val;
189 }

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

◆ hasDebug()

bool cond::Utilities::hasDebug ( )

Definition at line 177 of file Utilities.cc.

177 { return m_values.count("debug"); }

◆ hasOptionValue()

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

Definition at line 167 of file Utilities.cc.

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 }

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

◆ 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.

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 }

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

◆ run()

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

Definition at line 89 of file Utilities.cc.

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 }

References edm::ParameterSet::addParameter(), dir2webdir::argc, cmsBatch::argv, edmplugin::standard::config(), submitPVResolutionJobs::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().

◆ sendError()

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

Definition at line 191 of file Utilities.cc.

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

Referenced by getOptionValue().

◆ sendException()

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

Definition at line 193 of file Utilities.cc.

193 { throw cond::Exception(message); }

Referenced by getOptionValue().

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().

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
cmsBatch.argv
argv
Definition: cmsBatch.py:279
cond::Utilities::m_values
boost::program_options::variables_map m_values
Definition: Utilities.h:75
cond::Utilities::run
int run(int argc, char **argv)
Definition: Utilities.cc:89
dir2webdir.argc
argc
Definition: dir2webdir.py:39
cond::Utilities::sendError
void sendError(const std::string &message)
Definition: Utilities.cc:191
cond::Utilities::m_currentToken
edm::ServiceToken * m_currentToken
Definition: Utilities.h:68
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ServiceRegistry::createSet
static ServiceToken createSet(std::vector< ParameterSet > &)
Definition: ServiceRegistry.cc:75
edmplugin::PluginManager::Config
Definition: PluginManager.h:53
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
cond::Utilities::sendException
void sendException(const std::string &message)
Definition: Utilities.cc:193
edm::ServiceToken
Definition: ServiceToken.h:42
submitPVResolutionJobs.config
config
parse the configuration file
Definition: submitPVResolutionJobs.py:281
cond::Utilities::parseCommand
void parseCommand(int argc, char **argv)
Definition: Utilities.cc:137
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
newFWLiteAna.fullName
fullName
Definition: newFWLiteAna.py:122
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
cond::Utilities::m_name
std::string m_name
Definition: Utilities.h:71
edm::ParameterSet
Definition: ParameterSet.h:47
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:315
cond::Utilities::m_options
boost::program_options::options_description m_options
Definition: Utilities.h:73
recoMuon::in
Definition: RecoMuonEnumerators.h:6
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
cond::Utilities::execute
virtual int execute()
Definition: Utilities.cc:87
cond::persistency::Exception
Base exception class for the object to relational access.
Definition: Exception.h:11
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
cond::UtilitiesError
Definition: Utilities.h:18
edmplugin::standard::config
PluginManager::Config config()
Definition: standard.cc:21
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
heppy_batch.val
val
Definition: heppy_batch.py:351
cond::Utilities::m_positionalOptions
boost::program_options::positional_options_description m_positionalOptions
Definition: Utilities.h:74
T
long double T
Definition: Basic3DVectorLD.h:48
AlcaSiPixelAliHarvester0T_cff.options
options
Definition: AlcaSiPixelAliHarvester0T_cff.py:42
cond::Utilities::getValueIfExists
std::string getValueIfExists(const std::string &fullName)
Definition: Utilities.cc:183
edm::ServiceRegistry::Operate
Definition: ServiceRegistry.h:40