rivet is hosted by Hepforge, IPPP Durham

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

#include <AnalysisLoader.hh>

List of all members.

Static Public Member Functions

static vector< string > analysisNames ()
 Get all the available analyses' names.
static set< string > getAllAnalysisNames ()
static unique_ptr< AnalysisgetAnalysis (const string &analysisname)
static vector< unique_ptr
< 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 83 of file AnalysisLoader.cc.

                                            {
    // 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.

                                                                     {
    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;
    }

    const string aname = ab->alias();
    if (!aname.empty()) {
      //MSG_WARNING("ALIAS!!! " << aname);
      if (_ptrs.find(aname) != _ptrs.end()) {
        MSG_WARNING("Ignoring duplicate plugin analysis alias '" << aname << "'");
      } else {
        MSG_TRACE("Registering a plugin analysis via alias '" << aname << "'");
        _ptrs[aname] = ab;
      }
    }
  }
vector< string > analysisNames ( ) [static]

Get all the available analyses' names.

Definition at line 22 of file AnalysisLoader.cc.

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

Get all the available analyses.

Definition at line 48 of file AnalysisLoader.cc.

                                                              {
    _loadAnalysisPlugins();
    vector<unique_ptr<Analysis>> analyses;
    foreach (const auto & p, _ptrs) {
      analyses.emplace_back( p.second->mkAnalysis() );
    }
    return analyses;
  }
set< string > getAllAnalysisNames ( ) [static]

Definition at line 30 of file AnalysisLoader.cc.

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

                                                                             {
    _loadAnalysisPlugins();
    AnalysisBuilderMap::const_iterator ai = _ptrs.find(analysisname);
    if (ai == _ptrs.end()) return nullptr;
    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

Definition at line 47 of file AnalysisLoader.hh.


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