Internal class which loads and registers analyses from plugin libs. More...
#include <AnalysisLoader.hh>
Static Public Member Functions | |
static vector< string > | analysisNames () |
Get all the available analyses' names. | |
static set< string > | getAllAnalysisNames () |
static Analysis * | getAnalysis (const string &analysisname) |
static vector< Analysis * > | getAllAnalyses () |
Get all the available analyses. | |
Private Types | |
typedef map< string, const AnalysisBuilderBase * > | AnalysisBuilderMap |
Static Private Member Functions | |
static void | _registerBuilder (const AnalysisBuilderBase *a) |
Register a new analysis builder. | |
static void | _loadAnalysisPlugins () |
Load the available analyses at runtime. | |
Static Private Attributes | |
static AnalysisBuilderMap | _ptrs |
Friends | |
class | AnalysisBuilderBase |
Allow the analysis builders to call the private _registerBuilder function. |
Internal class which loads and registers analyses from plugin libs.
Definition at line 19 of file AnalysisLoader.hh.
typedef map<string, const AnalysisBuilderBase*> AnalysisBuilderMap [private] |
Definition at line 46 of file AnalysisLoader.hh.
void _loadAnalysisPlugins | ( | ) | [static, private] |
Load the available analyses at runtime.
Definition at line 72 of file AnalysisLoader.cc.
References AnalysisLoader::_ptrs, Rivet::getAnalysisLibPaths(), MSG_TRACE, and MSG_WARNING.
Referenced by AnalysisLoader::analysisNames(), AnalysisLoader::getAllAnalyses(), and AnalysisLoader::getAnalysis().
00072 { 00073 // Only run once 00074 if (!_ptrs.empty()) return; 00075 00076 // Build the list of directories to search 00077 const vector<string> dirs = getAnalysisLibPaths(); 00078 00079 // Find plugin module library files 00080 const string libsuffix = ".so"; 00081 vector<string> pluginfiles; 00082 foreach (const string& d, dirs) { 00083 if (d.empty()) continue; 00084 oslink::directory dir(d); 00085 while (dir) { 00086 string filename = dir.next(); 00087 // Require that plugin lib name starts with 'Rivet' 00088 if (filename.find("Rivet") != 0) continue; 00089 size_t posn = filename.find(libsuffix); 00090 if (posn == string::npos || posn != filename.length()-libsuffix.length()) continue; 00091 /// @todo Make sure this is an abs path 00092 /// @todo Sys-dependent path separator instead of "/" 00093 const string path = d + "/" + filename; 00094 // Ensure no duplicate paths 00095 if (find(pluginfiles.begin(), pluginfiles.end(), path) == pluginfiles.end()) { 00096 pluginfiles += path; 00097 } 00098 } 00099 } 00100 00101 // Load the plugin files 00102 MSG_TRACE("Candidate analysis plugin libs: " << pluginfiles); 00103 foreach (const string& pf, pluginfiles) { 00104 MSG_TRACE("Trying to load plugin analyses from file " << pf); 00105 void* handle = dlopen(pf.c_str(), RTLD_LAZY); 00106 if (!handle) { 00107 MSG_WARNING("Cannot open " << pf << ": " << dlerror()); 00108 continue; 00109 } 00110 } 00111 }
void _registerBuilder | ( | const AnalysisBuilderBase * | a | ) | [static, private] |
Register a new analysis builder.
Definition at line 58 of file AnalysisLoader.cc.
References AnalysisLoader::_ptrs, MSG_TRACE, and MSG_WARNING.
00058 { 00059 if (!ab) return; 00060 const string name = ab->name(); 00061 if (_ptrs.find(name) != _ptrs.end()) { 00062 // Duplicate analyses will be ignored... loudly 00063 //cerr << "Ignoring duplicate plugin analysis called '" << name << "'" << endl; 00064 MSG_WARNING("Ignoring duplicate plugin analysis called '" << name << "'"); 00065 } else { 00066 MSG_TRACE("Registering a plugin analysis called '" << name << "'"); 00067 _ptrs[name] = ab; 00068 } 00069 }
vector< string > analysisNames | ( | ) | [static] |
Get all the available analyses' names.
Definition at line 22 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
Referenced by AnalysisLoader::getAllAnalysisNames().
00022 { 00023 _loadAnalysisPlugins(); 00024 vector<string> names; 00025 foreach (const AnalysisBuilderMap::value_type& p, _ptrs) names += p.first; 00026 return names; 00027 }
vector< Analysis * > getAllAnalyses | ( | ) | [static] |
Get all the available analyses.
Definition at line 48 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
00048 { 00049 _loadAnalysisPlugins(); 00050 vector<Analysis*> analyses; 00051 foreach (const AnalysisBuilderMap::value_type& p, _ptrs) { 00052 analyses += p.second->mkAnalysis(); 00053 } 00054 return analyses; 00055 }
set< string > getAllAnalysisNames | ( | ) | [static] |
Definition at line 30 of file AnalysisLoader.cc.
References AnalysisLoader::analysisNames().
00030 { 00031 set<string> anaset; 00032 vector<string> anas = analysisNames(); 00033 foreach (const string &ana, anas) { 00034 anaset.insert(ana); 00035 } 00036 return anaset; 00037 }
Analysis * getAnalysis | ( | const string & | analysisname | ) | [static] |
Get an analysis by name. Warning: a name arg which matches no known analysis will return a null pointer. Check your return values before using them!
Definition at line 40 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
Referenced by AnalysisHandler::addAnalysis().
00040 { 00041 _loadAnalysisPlugins(); 00042 AnalysisBuilderMap::const_iterator ai = _ptrs.find(analysisname); 00043 if (ai == _ptrs.end()) return 0; 00044 return ai->second->mkAnalysis(); 00045 }
friend class AnalysisBuilderBase [friend] |
Allow the analysis builders to call the private _registerBuilder function.
Definition at line 38 of file AnalysisLoader.hh.
AnalysisLoader::AnalysisBuilderMap _ptrs [static, private] |
Definition at line 47 of file AnalysisLoader.hh.
Referenced by AnalysisLoader::_loadAnalysisPlugins(), AnalysisLoader::_registerBuilder(), AnalysisLoader::analysisNames(), AnalysisLoader::getAllAnalyses(), and AnalysisLoader::getAnalysis().