CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends

edmplugin::PluginCapabilities Class Reference

#include <PluginCapabilities.h>

Inheritance diagram for edmplugin::PluginCapabilities:
edmplugin::PluginFactoryBase

List of all members.

Public Member Functions

virtual std::vector< PluginInfoavailable () const
 return info about all plugins which are already available in the program
virtual const std::string & category () const
 returns the name of the category to which this plugin factory belongs
void load (const std::string &iName)
bool tryToFind (const SharedLibrary &iLoadable)
 Check to see if any capabilities are in the file, returns 'true' if found.
bool tryToLoad (const std::string &iName)
virtual ~PluginCapabilities ()

Static Public Member Functions

static PluginCapabilitiesget ()

Private Member Functions

const PluginCapabilitiesoperator= (const PluginCapabilities &)
 PluginCapabilities ()
 PluginCapabilities (const PluginCapabilities &)

Private Attributes

std::map< std::string,
boost::filesystem::path > 
classToLoadable_

Friends

class DummyFriend

Detailed Description

Definition at line 33 of file PluginCapabilities.h.


Constructor & Destructor Documentation

PluginCapabilities::~PluginCapabilities ( ) [virtual]

Definition at line 44 of file PluginCapabilities.cc.

{
}
PluginCapabilities::PluginCapabilities ( ) [private]
edmplugin::PluginCapabilities::PluginCapabilities ( const PluginCapabilities ) [private]

Member Function Documentation

std::vector< PluginInfo > PluginCapabilities::available ( ) const [virtual]

return info about all plugins which are already available in the program

Reimplemented from edmplugin::PluginFactoryBase.

Definition at line 139 of file PluginCapabilities.cc.

References classToLoadable_, info, benchmark_cfg::infos, edmplugin::PluginInfo::loadable_, and edmplugin::PluginInfo::name_.

{
  PluginInfo info;
  std::vector<PluginInfo> infos;
  infos.reserve(classToLoadable_.size());
  
  for(std::map<std::string, boost::filesystem::path>::const_iterator it = classToLoadable_.begin();
      it != classToLoadable_.end();
      ++it) {
    info.name_ = it->first;
    info.loadable_ = it->second;
    infos.push_back(info);
  }
  return infos;
}
const std::string & PluginCapabilities::category ( ) const [virtual]

returns the name of the category to which this plugin factory belongs

Implements edmplugin::PluginFactoryBase.

Definition at line 156 of file PluginCapabilities.cc.

Referenced by load(), tryToFind(), and tryToLoad().

{
  static const std::string s_cat("Capability");
  return s_cat;
}
PluginCapabilities * PluginCapabilities::get ( void  ) [static]

Definition at line 166 of file PluginCapabilities.cc.

Referenced by load(), and tryToLoad().

                        {
  static PluginCapabilities s_instance;
  return &s_instance;
}
void PluginCapabilities::load ( const std::string &  iName)

Definition at line 91 of file PluginCapabilities.cc.

References category(), classToLoadable_, Exception, get(), load(), edmplugin::SharedLibrary::path(), and tryToFind().

Referenced by load().

{
  if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
    const SharedLibrary& lib = PluginManager::get()->load(category(),
                                                          iName);
    //read the items from the 'capabilities' symbol
    if(not tryToFind(lib) ) {
      throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
      <<lib.path().string()<<"'\n but no dictionaries are in that file.\n"
      "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
    }
    
    if(classToLoadable_.end() == classToLoadable_.find(iName)) {
      throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
      <<lib.path().string()<<"'\n but was not found.\n"
      "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
    }
  }
}
const PluginCapabilities& edmplugin::PluginCapabilities::operator= ( const PluginCapabilities ) [private]
bool PluginCapabilities::tryToFind ( const SharedLibrary iLoadable)

Check to see if any capabilities are in the file, returns 'true' if found.

Definition at line 64 of file PluginCapabilities.cc.

References category(), classToLoadable_, i, info, edmplugin::PluginInfo::loadable_, mergeVDriftHistosByStation::name, edmplugin::PluginInfo::name_, h::names, edmplugin::PluginFactoryBase::newPluginAdded_, edmplugin::SharedLibrary::path(), findQualityFiles::size, and edmplugin::SharedLibrary::symbol().

Referenced by load(), and tryToLoad().

{
  void* sym;
  if( not iLoadable.symbol("SEAL_CAPABILITIES",sym) ) {
    return false;
  }
  
  const char** names;
  int size;
  //reinterpret_cast<void (*)(const char**&,int&)>(sym)(names,size);
  reinterpret_cast<void (*)(const char**&,int&)>(reinterpret_cast<unsigned long>(sym))(names,size);

  PluginInfo info;
  for(int i=0; i < size; ++i) {
    std::string name(names[i]);
    classToLoadable_[name]=iLoadable.path();
    
    //NOTE: can't use newPlugin(name) to do the work since it assumes
    //  we haven't yet returned from PluginManager::load method
    info.name_ = name;
    info.loadable_ = iLoadable.path();
    this->newPluginAdded_(category(),info);
  }
  return true;
}
bool PluginCapabilities::tryToLoad ( const std::string &  iName)

Definition at line 112 of file PluginCapabilities.cc.

References category(), classToLoadable_, Exception, get(), edmplugin::SharedLibrary::path(), tryToFind(), and tryToLoad().

Referenced by tryToLoad().

{
  if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
    const SharedLibrary* lib = PluginManager::get()->tryToLoad(category(),
                                                          iName);
    if( 0 == lib) {
      return false;
    }
    //read the items from the 'capabilities' symbol
    if(not tryToFind(*lib) ) {
      throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
      <<lib->path().string()<<"'\n but no dictionaries are in that file.\n"
      "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
    }
    
    if(classToLoadable_.end() == classToLoadable_.find(iName)) {
      throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
      <<lib->path().string()<<"'\n but was not found.\n"
      "It appears like the cache is wrong.  Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
    }
  }
  return true;
}

Friends And Related Function Documentation

friend class DummyFriend [friend]

Definition at line 35 of file PluginCapabilities.h.


Member Data Documentation

std::map<std::string, boost::filesystem::path> edmplugin::PluginCapabilities::classToLoadable_ [private]

Definition at line 62 of file PluginCapabilities.h.

Referenced by available(), load(), tryToFind(), and tryToLoad().