00001 #ifndef CAFE_PLUGINS_HPP__
00002 #define CAFE_PLUGINS_HPP__
00003
00004 #include "TPluginManager.h"
00005 #include "TROOT.h"
00006
00007 #include <stdexcept>
00008
00009 namespace cafe {
00010
00016 class Plugins {
00017 public:
00018 static Plugins *instance();
00019
00020
00021
00022 template<class T>
00023 T *load(const std::string& type, const std::string& url, const std::string& arg);
00024 private:
00025 Plugins();
00026 ~Plugins();
00027 static Plugins *s_instance;
00028 };
00029
00030
00031
00032 template<class T>
00033 T *Plugins::load(const std::string& type, const std::string& url, const std::string& arg)
00034 {
00035 TPluginManager *mgr = gROOT->GetPluginManager();
00036 if(TPluginHandler *handler = mgr->FindHandler(type.c_str(), url.c_str())) {
00037 if(handler->LoadPlugin() == 0) {
00038 return reinterpret_cast<T*>(handler->ExecPlugin(1, arg.c_str()));
00039 } else {
00040 throw std::runtime_error("Plugin not found: " + type);
00041 }
00042 }
00043 return 0;
00044 }
00045 }
00046
00047 #endif // CAFE_PLUGINS_HPP__