#include <AnalysisLoader.hh>
Definition at line 17 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 43 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(), AnalysisBuilderBase::name(), and Log::TRACE.
Referenced by AnalysisBuilderBase::_register().
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::getLibPath(), Log::getLog(), directory::next(), Rivet::split(), 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 vector<string> dirs; 00072 char* env = 0; 00073 env = getenv("RIVET_ANALYSIS_PATH"); 00074 if (env) { 00075 // Use the Rivet analysis path variable if set... 00076 dirs += split(env); 00077 } else { 00078 // ... otherwise fall back to the Rivet library install path 00079 dirs += getLibPath(); 00080 } 00081 00082 // Find plugin module library files 00083 const string libsuffix = ".so"; 00084 vector<string> pluginfiles; 00085 foreach (const string& d, dirs) { 00086 if (d.empty()) continue; 00087 oslink::directory dir(d); 00088 while (dir) { 00089 string filename = dir.next(); 00090 // Require that name *starts* with 'Rivet' with new loader 00091 if (filename.find("Rivet") != 0) continue; 00092 size_t posn = filename.find(libsuffix); 00093 if (posn == string::npos || posn != filename.length()-libsuffix.length()) continue; 00094 /// @todo Make sure this is an abs path 00095 /// @todo Sys-dependent path separator instead of "/" 00096 const string path = d + "/" + filename; 00097 // Ensure no duplicate paths 00098 if (find(pluginfiles.begin(), pluginfiles.end(), path) == pluginfiles.end()) { 00099 pluginfiles += path; 00100 } 00101 } 00102 } 00103 00104 // Load the plugin files 00105 Log::getLog("Rivet.AnalysisLoader") << Log::TRACE << "Candidate analysis plugin libs: " << pluginfiles << endl; 00106 foreach (const string& pf, pluginfiles) { 00107 Log::getLog("Rivet.AnalysisLoader") << Log::TRACE << "Trying to load plugin analyses from file " << pf << endl; 00108 void* handle = dlopen(pf.c_str(), RTLD_LAZY); 00109 if (!handle) { 00110 Log::getLog("Rivet.AnalysisLoader") << Log::WARN << "Cannot open " << pf << ": " << dlerror() << endl; 00111 continue; 00112 } 00113 } 00114 }
friend class AnalysisBuilderBase [friend] |
Allow the analysis builders to call the private _registerBuilder function.
Definition at line 35 of file AnalysisLoader.hh.
AnalysisLoader::AnalysisBuilderMap _ptrs [static, private] |
Definition at line 44 of file AnalysisLoader.hh.
Referenced by AnalysisLoader::_loadAnalysisPlugins(), AnalysisLoader::_registerBuilder(), AnalysisLoader::analysisNames(), AnalysisLoader::getAllAnalyses(), and AnalysisLoader::getAnalysis().