AnalysisLoader.hh

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef RIVET_AnalysisLoader_HH
00003 #define RIVET_AnalysisLoader_HH 1
00004 
00005 #include "Rivet/Rivet.hh"
00006 
00007 // Forward declaration
00008 namespace Rivet {  
00009   class Analysis;
00010 }
00011 
00012 // Typedefs for dlopen() magic
00013 #include <map>
00014 #include <string>
00015 typedef Rivet::Analysis* (*anabuilder_fn)();
00016 typedef std::map<std::string,anabuilder_fn> AnalysisBuilders;
00017 typedef AnalysisBuilders (*anabuilders_fn)();
00018 
00019 
00020 namespace Rivet {  
00021 
00022   class AnalysisLoader {
00023   public:
00024     
00025     /// Get all the available analyses' names.
00026     static set<string> getAllAnalysisNames();
00027 
00028     /// Get an analysis by name. The returned Analysis object will be obtained 
00029     /// from the Analysis::create() factory method via some dlopen() magic.
00030     /// Warning: a name arg which matches no known analysis will return a null
00031     /// pointer. Check your return values before using them!
00032     static Analysis* getAnalysis(const string& analysisname);
00033 
00034     /// Get all the available analyses.
00035     static set<Analysis*> getAllAnalyses();
00036 
00037     /// Load the analysis builder functions from a named shared object file.
00038     static AnalysisBuilders& loadAnalysisBuildersFromFile(const string& filename, AnalysisBuilders& builders);
00039 
00040     /// Close the dlopen()ed libraries.    
00041     static void closeAnalysisBuilders();
00042 
00043     /// Load the analysis builder functions from shared object files in a named directory.
00044     static AnalysisBuilders& loadAnalysisBuildersFromDir(const string& dirname, AnalysisBuilders& builders); 
00045 
00046     /// Load the analysis builder functions from shared object files in named directories. 
00047     static AnalysisBuilders& loadAnalysisBuildersFromDirs(const vector<string>& dirnames, AnalysisBuilders& builders);
00048 
00049   private:
00050     /// Load the available analyses at runtime.
00051     static void loadAnalyses();
00052     
00053     /// Static flag for determining when to run the load method.
00054     static bool _loaded;
00055     
00056     /// The named factory functions of all available analyses.
00057     static AnalysisBuilders _analysisbuilders;
00058 
00059     /// The named factory functions of all available analyses.
00060     static set<void*> _handles;
00061     
00062   };
00063   
00064 }
00065 
00066 #endif