CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

cond::Utilities Class Reference

#include <Utilities.h>

Inheritance diagram for cond::Utilities:
cond::AlignSplitIOV cond::ExportIOVUtilities

List of all members.

Public Member Functions

void addAuthenticationOptions ()
void addConfigFileOption ()
void addConnectOption ()
void addConnectOption (const std::string &connectionOptionName, const std::string &shortName, const std::string &helpEntry)
void addDictionaryOption ()
void addLogDBOption ()
template<typename T >
void addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry)
void addSQLOutputOption ()
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 ()
cond::DbSession openDbSession (const std::string &connectionParameterName, const std::string &role, bool readOnly=false)
cond::DbSession openDbSession (const std::string &connectionParameterName, bool readOnly=false)
void parseCommand (int argc, char **argv)
int run (int argc, char **argv)
 Utilities (const std::string &commandName, std::string positionalParameter=std::string(""))
virtual ~Utilities ()

Private Member Functions

std::string getValueIfExists (const std::string &fullName)
void initializeForDbConnection ()
void sendError (const std::string &message)
void sendException (const std::string &message)

Private Attributes

cond::DbConnectionm_dbConnection
std::set< std::string > m_dbSessions
std::string m_name
boost::program_options::options_description m_options
bool m_pluginMgrInitialized
boost::program_options::positional_options_description m_positionalOptions
boost::program_options::variables_map m_values

Detailed Description

Definition at line 19 of file Utilities.h.


Constructor & Destructor Documentation

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

Definition at line 25 of file Utilities.cc.

References m_options, and m_positionalOptions.

                                                          :m_name(commandName),
                                                             m_options(std::string("Usage: ")+m_name+
                                                                       std::string(" [options] ")+positionalParameter
                                                                       +std::string(" \n")),
                                                             m_positionalOptions(),
                                                             m_values(),
                                                             m_dbConnection(0),
                                                             m_pluginMgrInitialized(false),
                                                             m_dbSessions(){
  m_options.add_options()
    ("debug","switch on debug mode")
    ("help,h", "help message")
    ;
  if(!positionalParameter.empty()) {
    m_positionalOptions.add( positionalParameter.c_str(), -1);
    addOption<std::string>(positionalParameter,"",positionalParameter);
  }
}
cond::Utilities::~Utilities ( ) [virtual]

Definition at line 46 of file Utilities.cc.

                         {
  if(m_dbConnection) delete m_dbConnection;
}

Member Function Documentation

void cond::Utilities::addAuthenticationOptions ( )

Definition at line 94 of file Utilities.cc.

Referenced by cond::AlignSplitIOV::AlignSplitIOV(), and cond::ExportIOVUtilities::ExportIOVUtilities().

                                       {
  addOption<std::string>("authPath","P","path to authentication xml");
  addOption<std::string>("user","u","user name");
  addOption<std::string>("pass","p","password");
}
void cond::Utilities::addConfigFileOption ( )

Definition at line 126 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

                                  {
  addOption<std::string>("configFile","f","configuration file(optional)");
}
void cond::Utilities::addConnectOption ( )

Definition at line 101 of file Utilities.cc.

Referenced by cond::AlignSplitIOV::AlignSplitIOV(), and cond::ExportIOVUtilities::ExportIOVUtilities().

                               {
  addOption<std::string>("connect","c","connection string (required)");
  m_dbSessions.insert("connect");
}
void cond::Utilities::addConnectOption ( const std::string &  connectionOptionName,
const std::string &  shortName,
const std::string &  helpEntry 
)

Definition at line 107 of file Utilities.cc.

                                                              {
  addOption<std::string>(connectionOptionName,shortName,helpEntry);
  m_dbSessions.insert(connectionOptionName);
}
void cond::Utilities::addDictionaryOption ( )

Definition at line 121 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

                                  {
  addOption<std::vector<std::string> >("dictionary","D","data dictionaries (required if no plugin available)");
}
void cond::Utilities::addLogDBOption ( )

Definition at line 116 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

                             {
  addConnectOption("logDB","l","logDB(optional");
}
void cond::Utilities::addOption< bool > ( const std::string &  fullName,
const std::string &  shortName,
const std::string &  helpEntry 
) [inline]

Definition at line 78 of file Utilities.h.

References newFWLiteAna::fullName, and m_options.

                                                                                 {
  std::stringstream optInfo;
  optInfo << fullName;
  if(!shortName.empty()) optInfo << ","<<shortName;
  m_options.add_options()
    (optInfo.str().c_str(),boost::program_options::value<T>(),helpEntry.c_str());
}
void cond::Utilities::addSQLOutputOption ( )

Definition at line 131 of file Utilities.cc.

Referenced by cond::ExportIOVUtilities::ExportIOVUtilities().

                                 {
  addOption<bool>("sql","S","dump the sql output (optional)");  
}
int cond::Utilities::execute ( ) [virtual]

Reimplemented in cond::AlignSplitIOV, and cond::ExportIOVUtilities.

Definition at line 50 of file Utilities.cc.

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

Definition at line 149 of file Utilities.cc.

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

Definition at line 173 of file Utilities.cc.

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

Definition at line 161 of file Utilities.cc.

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

Definition at line 169 of file Utilities.cc.

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

Definition at line 165 of file Utilities.cc.

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

Definition at line 101 of file Utilities.h.

References newFWLiteAna::found, newFWLiteAna::fullName, m_options, m_values, python::rootplot::argparse::message, sendError(), and sendException().

                                                                                     {
  const void* found = m_options.find_nothrow(fullName, false);
  if(!found){
    std::stringstream message;
    message << "Utilities::getOptionValue: option \"" << fullName << "\" is not known by the command.";
    sendException(message.str());
  } 
  
  if (!m_values.count(fullName)) {
    std::stringstream message;
    message << "Error: Option \"" << fullName << "\" has not been provided.";
    sendError(message.str());
  }
  return m_values[fullName].as<T>();
}
std::string cond::Utilities::getPasswordValue ( )

Definition at line 157 of file Utilities.cc.

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

Definition at line 153 of file Utilities.cc.

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

Definition at line 267 of file Utilities.cc.

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

                                                                  {
  std::string val("");
  if(m_values.count(fullName)){
    val = m_values[fullName].as<std::string>();
  }
  return val;
}
bool cond::Utilities::hasDebug ( )

Definition at line 188 of file Utilities.cc.

                            {
  return m_values.count("debug");  
}
bool cond::Utilities::hasOptionValue ( const std::string &  fullName)

Definition at line 178 of file Utilities.cc.

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

                                                           {
  const void* found = m_options.find_nothrow(fullName, false);
  if(!found){
    std::stringstream message;
    message << "Utilities::hasOptionValue: option \"" << fullName << "\" is not known by the command.";
    sendException(message.str());
  }
  return m_values.count(fullName);
}
void cond::Utilities::initializeForDbConnection ( ) [private]

Definition at line 208 of file Utilities.cc.

References builder_last_value_cfg::authPath, Debug, AlCaHLTBitMon_QueryRunRegistry::string, and hcal_dqm_sourceclient-file_cfg::user.

                                             {
  if(!m_dbConnection){
    initializePluginManager();
    m_dbConnection = new cond::DbConnection();
    if( hasDebug() ){
      m_dbConnection->configuration().setMessageLevel(coral::Debug);
    } else {
      m_dbConnection->configuration().setMessageLevel(coral::Error);
    }
    m_dbConnection->configuration().setPoolAutomaticCleanUp( false );
    m_dbConnection->configuration().setConnectionTimeOut(0);

    if(m_options.find_nothrow("authPath", false) &&
       m_options.find_nothrow("user",false) &&
       m_options.find_nothrow("pass",false)){
      std::string authPath = getValueIfExists("authPath");
      std::string user = getValueIfExists("user");
      std::string pass = getValueIfExists("pass");
      if( !authPath.empty() ){
        m_dbConnection->configuration().setAuthenticationPath(authPath);
      } else {
        if( !user.empty()  && !pass.empty() ){
          std::string userenv(std::string("CORAL_AUTH_USER=")+user);
          std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
          ::putenv(const_cast<char*>(userenv.c_str()));
          ::putenv(const_cast<char*>(passenv.c_str()));
        }
      }
    }
    if(m_options.find_nothrow("sql",false)){
      if(m_values.count("sql")) {
        m_dbConnection->configuration().setSQLMonitoring( true );
      } 
    }
    m_dbConnection->configure();
    
  }
  
}
void cond::Utilities::initializePluginManager ( )
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
bool  readOnly = false 
)

Definition at line 258 of file Utilities.cc.

References python::CommonUtils::session, and AlCaHLTBitMon_QueryRunRegistry::string.

                                                               {
  initializeForDbConnection();
  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
  cond::DbSession session = m_dbConnection->createSession();
  session.open( connectionString, readOnly );
  return session;
}
cond::DbSession cond::Utilities::openDbSession ( const std::string &  connectionParameterName,
const std::string &  role,
bool  readOnly = false 
)

Definition at line 248 of file Utilities.cc.

References python::CommonUtils::session, and AlCaHLTBitMon_QueryRunRegistry::string.

                                                               {
  initializeForDbConnection();
  std::string connectionString = getOptionValue<std::string>( connectionParameterName );
  cond::DbSession session = m_dbConnection->createSession();
  session.open( connectionString, role, readOnly );
  return session;
}
void cond::Utilities::parseCommand ( int  argc,
char **  argv 
)

Definition at line 135 of file Utilities.cc.

References HDQMDatabaseProducer::configFile, recoMuon::in, AlCaHLTBitMon_ParallelJobs::options, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

                                                       {
  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(m_options).positional(m_positionalOptions).run(), m_values);
  if(m_options.find_nothrow("configFile",false)){
    std::string configFileName = getValueIfExists("configFile");
    if (! configFileName.empty()){
      std::fstream configFile;
      configFile.open(configFileName.c_str(), std::fstream::in);
      boost::program_options::store(boost::program_options::parse_config_file(configFile,m_options), m_values);
      configFile.close();
    }
  }
  boost::program_options::notify(m_values);
}
int cond::Utilities::run ( int  argc,
char **  argv 
)

Definition at line 54 of file Utilities.cc.

References gather_cfg::cout, python::multivaluedict::dict, exception, cmsIgProf_Analysis::execute(), cond::SQLReport::putOnFile(), zeeHLT_cff::report, cond::SQLReport::reportForConnection(), run_regression::ret, AlCaHLTBitMon_QueryRunRegistry::string, and cms::Exception::what().

Referenced by main().

                                             {
  int ret = 0;
  try{
    parseCommand( argc, argv );
    if (m_values.count("help")) {
      std::cout << m_options <<std::endl;;
      return 0;
    }
    if(m_options.find_nothrow("dictionary",false)&& m_values.count("dictionary")){
      std::vector<std::string> dictionaries =
        m_values["dictionary"].as<std::vector<std::string> >();
      if(!dictionaries.empty()){
        initializePluginManager();
        ora::SharedLibraryName libName;
        BOOST_FOREACH(std::string const & dict, dictionaries)
          edmplugin::SharedLibrary( libName(dict) );
      }
    }
    ret = execute();
    if(m_dbConnection){
      if(m_options.find_nothrow("sql",false) && m_values.count("sql")){
        cond::SQLReport report(*m_dbConnection);
        for(std::set<std::string>::const_iterator iSess = m_dbSessions.begin();
            iSess != m_dbSessions.end();
            iSess++) report.reportForConnection(*iSess);
        report.putOnFile();
      }
    }
    
  }catch( cond::Exception& err ){
    std::cout << err.what() << std::endl;
    ret = 1;
  }catch( const std::exception& exc ){
    std::cout << exc.what() << std::endl;
    ret = 1;
  }
  return ret;
}
void cond::Utilities::sendError ( const std::string &  message) [private]

Definition at line 275 of file Utilities.cc.

Referenced by getOptionValue().

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

Definition at line 279 of file Utilities.cc.

References Exception.

Referenced by getOptionValue().

                                                           {
  throw cond::Exception(message);
}

Member Data Documentation

Definition at line 72 of file Utilities.h.

std::set<std::string> cond::Utilities::m_dbSessions [private]

Definition at line 74 of file Utilities.h.

std::string cond::Utilities::m_name [private]

Definition at line 67 of file Utilities.h.

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

Definition at line 69 of file Utilities.h.

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

Definition at line 73 of file Utilities.h.

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

Definition at line 70 of file Utilities.h.

Referenced by Utilities().

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

Definition at line 71 of file Utilities.h.

Referenced by getOptionValue().