#include <AnalysisLoader.hh>
Definition at line 18 of file 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. |
typedef map<string, const AnalysisBuilderBase*> AnalysisBuilderMap [private] |
Definition at line 44 of file AnalysisLoader.hh.
vector< string > analysisNames | ( | ) | [static] |
Get all the available analyses' names.
Definition at line 16 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
Referenced by AnalysisLoader::getAllAnalysisNames().
00016 { 00017 _loadAnalysisPlugins(); 00018 vector<string> names; 00019 foreach (const AnalysisBuilderMap::value_type& p, _ptrs) names += p.first; 00020 return names; 00021 }
set< string > getAllAnalysisNames | ( | ) | [static] |
Definition at line 24 of file AnalysisLoader.cc.
References AnalysisLoader::analysisNames().
00024 { 00025 set<string> anaset; 00026 vector<string> anas = analysisNames(); 00027 foreach (const string &ana, anas) { 00028 anaset.insert(ana); 00029 } 00030 return anaset; 00031 }
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 34 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
00034 { 00035 _loadAnalysisPlugins(); 00036 AnalysisBuilderMap::const_iterator ai = _ptrs.find(analysisname); 00037 if (ai == _ptrs.end()) return 0; 00038 return ai->second->mkAnalysis(); 00039 }
vector< Analysis * > getAllAnalyses | ( | ) | [static] |
Get all the available analyses.
Definition at line 42 of file AnalysisLoader.cc.
References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.
00042 { 00043 _loadAnalysisPlugins(); 00044 vector<Analysis*> analyses; 00045 foreach (const AnalysisBuilderMap::value_type& p, _ptrs) { 00046 analyses += p.second->mkAnalysis(); 00047 } 00048 return analyses; 00049 }
void _registerBuilder | ( | const AnalysisBuilderBase * | a | ) | [static, private] |
Register a new analysis builder.
Definition at line 52 of file AnalysisLoader.cc.
References AnalysisLoader::_ptrs, Log::ERROR, Log::getLog(), and Log::TRACE.
00052 { 00053 if (!ab) return; 00054 const string name = ab->name(); 00055 if (_ptrs.find(name) != _ptrs.end()) { 00056 // Protect against overwriting analyses by throwing an error 00057 /// @todo Tidy this up! 00058 Log::getLog("Rivet.AnalysisLoader") << Log::ERROR << "Tried to register a second plugin analysis called '" << name << "'" << endl; 00059 exit(1); 00060 } 00061 Log::getLog("Rivet.AnalysisLoader") << Log::TRACE << "Registering a plugin analysis called '" << name << "'" << endl; 00062 _ptrs[name] = ab; 00063 }
void _loadAnalysisPlugins | ( | ) | [static, private] |
Load the available analyses at runtime.
Definition at line 66 of file AnalysisLoader.cc.
References AnalysisLoader::_ptrs, Rivet::getAnalysisLibPaths(), Log::getLog(), Log::TRACE, and Log::WARN.
Referenced by AnalysisLoader::analysisNames(), AnalysisLoader::getAllAnalyses(), and AnalysisLoader::getAnalysis().
00066 { 00067 // Only run once 00068 if (!_ptrs.empty()) return; 00069 00070 // Build the list of directories to search 00071 const vector<string> dirs = getAnalysisLibPaths(); 00072 00073 // Find plugin module library files 00074 const string libsuffix = ".so"; 00075 vector<string> pluginfiles; 00076 foreach (const string& d, dirs) { 00077 if (d.empty()) continue; 00078 oslink::directory dir(d); 00079 while (dir) { 00080 string filename = dir.next(); 00081 // Require that name *starts* with 'Rivet' with new loader 00082 if (filename.find("Rivet") != 0) continue; 00083 size_t posn = filename.find(libsuffix); 00084 if (posn == string::npos || posn != filename.length()-libsuffix.length()) continue; 00085 /// @todo Make sure this is an abs path 00086 /// @todo Sys-dependent path separator instead of "/" 00087 const string path = d + "/" + filename; 00088 // Ensure no duplicate paths 00089 if (find(pluginfiles.begin(), pluginfiles.end(), path) == pluginfiles.end()) { 00090 pluginfiles += path; 00091 } 00092 } 00093 } 00094 00095 // Load the plugin files 00096 Log::getLog("Rivet.AnalysisLoader") << Log::TRACE << "Candidate analysis plugin libs: " << pluginfiles << endl; 00097 foreach (const string& pf, pluginfiles) { 00098 Log::getLog("Rivet.AnalysisLoader") << Log::TRACE << "Trying to load plugin analyses from file " << pf << endl; 00099 void* handle = dlopen(pf.c_str(), RTLD_LAZY); 00100 if (!handle) { 00101 Log::getLog("Rivet.AnalysisLoader") << Log::WARN << "Cannot open " << pf << ": " << dlerror() << endl; 00102 continue; 00103 } 00104 } 00105 }
friend class AnalysisBuilderBase [friend] |
Allow the analysis builders to call the private _registerBuilder function.
Definition at line 36 of file AnalysisLoader.hh.
AnalysisLoader::AnalysisBuilderMap _ptrs [static, private] |
Definition at line 45 of file AnalysisLoader.hh.
Referenced by AnalysisLoader::_loadAnalysisPlugins(), AnalysisLoader::_registerBuilder(), AnalysisLoader::analysisNames(), AnalysisLoader::getAllAnalyses(), and AnalysisLoader::getAnalysis().