Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:56

0001 // -*- C++ -*-
0002 #ifndef RIVET_AnalysisBuilder_HH
0003 #define RIVET_AnalysisBuilder_HH
0004 
0005 #include "Rivet/Config/RivetCommon.hh"
0006 #include "Rivet/AnalysisLoader.hh"
0007 #include "Rivet/Tools/Logging.hh"
0008 
0009 namespace Rivet {
0010 
0011 
0012   // Forward declaration
0013   class Analysis;
0014 
0015 
0016   /// @cond ANALYSIS_PLUGIN_DETAILS
0017 
0018   /// @brief Interface for analysis builders
0019   class AnalysisBuilderBase {
0020   public:
0021 
0022     /// Default constructor
0023     AnalysisBuilderBase() = default;
0024 
0025     /// Constructor with alias name
0026     AnalysisBuilderBase(const string& alias)
0027       : _alias(alias) {   }
0028 
0029     /// Destructor
0030     virtual ~AnalysisBuilderBase() = default;
0031 
0032     /// Factory method, to be implemented by the analysis-specific derived class
0033     virtual unique_ptr<Analysis> mkAnalysis() const = 0;
0034 
0035     /// Get the analysis' name, by asking it directly
0036     string name() const {
0037       auto a = mkAnalysis();
0038       return a->name();
0039     }
0040 
0041     /// @brief Get any optional alias name attached to this builder
0042     ///
0043     /// @note An empty string is returned if there is no alias
0044     const string& alias() const {
0045       return _alias;
0046     }
0047 
0048   protected:
0049 
0050     /// The trick: the builder is able to register itself with Rivet's loader
0051     void _register() {
0052       AnalysisLoader::_registerBuilder(this);
0053     }
0054 
0055   private:
0056 
0057     /// Optional alias name
0058     string _alias;
0059 
0060   };
0061 
0062 
0063   /// @brief Self-registering analysis plugin builder
0064   template <typename T>
0065   class AnalysisBuilder : public AnalysisBuilderBase {
0066   public:
0067 
0068     AnalysisBuilder() {
0069       _register();
0070     }
0071 
0072     AnalysisBuilder(const string& alias)
0073       : AnalysisBuilderBase(alias)
0074     {
0075       _register();
0076     }
0077 
0078     unique_ptr<Analysis> mkAnalysis() const {
0079       return unique_ptr<T>(new T);
0080     }
0081 
0082   };
0083 
0084   /// @endcond
0085 
0086 }
0087 
0088 #endif