rivet is hosted by Hepforge, IPPP Durham

Internal class which loads and registers analyses from plugin libs. More...

#include <AnalysisLoader.hh>

Collaboration diagram for AnalysisLoader:

List of all members.

Static Public Member Functions

static vector< string > analysisNames ()
 Get all the available analyses' names.
static set< string > getAllAnalysisNames ()
static AnalysisgetAnalysis (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.

Detailed Description

Internal class which loads and registers analyses from plugin libs.

Definition at line 19 of file AnalysisLoader.hh.


Member Typedef Documentation

typedef map<string, const AnalysisBuilderBase*> AnalysisBuilderMap [private]

Definition at line 46 of file AnalysisLoader.hh.


Member Function Documentation

void _loadAnalysisPlugins ( ) [static, private]

Load the available analyses at runtime.

Todo:
Make sure this is an abs path
Todo:
Sys-dependent path separator instead of "/"

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().

                                            {
    // Only run once
    if (!_ptrs.empty()) return;

    // Build the list of directories to search
    const vector<string> dirs = getAnalysisLibPaths();

    // Find plugin module library files
    const string libsuffix = ".so";
    vector<string> pluginfiles;
    foreach (const string& d, dirs) {
      if (d.empty()) continue;
      oslink::directory dir(d);
      while (dir) {
        string filename = dir.next();
        // Require that plugin lib name starts with 'Rivet'
        if (filename.find("Rivet") != 0) continue;
        size_t posn = filename.find(libsuffix);
        if (posn == string::npos || posn != filename.length()-libsuffix.length()) continue;
        /// @todo Make sure this is an abs path
        /// @todo Sys-dependent path separator instead of "/"
        const string path = d + "/" + filename;
        // Ensure no duplicate paths
        if (find(pluginfiles.begin(), pluginfiles.end(), path) == pluginfiles.end()) {
          pluginfiles += path;
        }
      }
    }

    // Load the plugin files
    MSG_TRACE("Candidate analysis plugin libs: " << pluginfiles);
    foreach (const string& pf, pluginfiles) {
      MSG_TRACE("Trying to load plugin analyses from file " << pf);
      void* handle = dlopen(pf.c_str(), RTLD_LAZY);
      if (!handle) {
        MSG_WARNING("Cannot open " << pf << ": " << dlerror());
        continue;
      }
    }
  }
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.

                                                                     {
    if (!ab) return;
    const string name = ab->name();
    if (_ptrs.find(name) != _ptrs.end()) {
      // Duplicate analyses will be ignored... loudly
      //cerr << "Ignoring duplicate plugin analysis called '" << name << "'" << endl;
      MSG_WARNING("Ignoring duplicate plugin analysis called '" << name << "'");
    } else {
      MSG_TRACE("Registering a plugin analysis called '" << name << "'");
      _ptrs[name] = ab;
    }
  }
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().

                                               {
    _loadAnalysisPlugins();
    vector<string> names;
    foreach (const AnalysisBuilderMap::value_type& p, _ptrs) names += p.first;
    return names;
  }
vector< Analysis * > getAllAnalyses ( ) [static]

Get all the available analyses.

Definition at line 48 of file AnalysisLoader.cc.

References AnalysisLoader::_loadAnalysisPlugins(), and AnalysisLoader::_ptrs.

                                                   {
    _loadAnalysisPlugins();
    vector<Analysis*> analyses;
    foreach (const AnalysisBuilderMap::value_type& p, _ptrs) {
      analyses += p.second->mkAnalysis();
    }
    return analyses;
  }
set< string > getAllAnalysisNames ( ) [static]

Definition at line 30 of file AnalysisLoader.cc.

References AnalysisLoader::analysisNames().

                                                  {
    set<string> anaset;
    vector<string> anas = analysisNames();
    foreach (const string &ana, anas) {
      anaset.insert(ana);
    }
    return anaset;
  }
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().

                                                                  {
    _loadAnalysisPlugins();
    AnalysisBuilderMap::const_iterator ai = _ptrs.find(analysisname);
    if (ai == _ptrs.end()) return 0;
    return ai->second->mkAnalysis();
  }

Friends And Related Function Documentation

friend class AnalysisBuilderBase [friend]

Allow the analysis builders to call the private _registerBuilder function.

Definition at line 38 of file AnalysisLoader.hh.


Member Data Documentation


The documentation for this class was generated from the following files: