00001 // -*- C++ -*- 00002 #ifndef RIVET_RivetHandler_HH 00003 #define RIVET_RivetHandler_HH 00004 00005 #include "Rivet/Rivet.hh" 00006 #include "Rivet/Tools/Logging.fhh" 00007 #include "Rivet/RivetAIDA.fhh" 00008 #include "Rivet/AnalysisHandler.fhh" 00009 #include "Rivet/Event.hh" 00010 #include "Rivet/Analysis.hh" 00011 #include "Rivet/AnalysisLoader.hh" 00012 00013 00014 namespace Rivet { 00015 00016 00017 /// A class which handles a number of analysis objects to be applied to 00018 /// generated events. An {@link Analysis}' AnalysisHandler is also responsible 00019 /// for handling the final writing-out of histograms. 00020 class AnalysisHandler { 00021 00022 public: 00023 00024 /// @name Standard constructors and destructors. */ 00025 //@{ 00026 /// The standard constructor. 00027 /// @param filename the name of the file (no extension) where histograms are to be stored. 00028 /// @param storetype a string indicating to the AIDA analysis factory 00029 /// how to store the histograms. Which strings are allowed depends on 00030 /// actual AIDA implementation used. To output in standard AIDA XML the 00031 /// string is typically "xml". 00032 /// @param afac an AIDA analysis factory object. The caller must make 00033 /// sure that the lifetime of the factory object exceeds the AnalysisHandler 00034 /// object. 00035 AnalysisHandler(AIDA::IAnalysisFactory& afac, string basefilename="Rivet", HistoFormat storetype=AIDAML); 00036 00037 /// Make a Rivet handler with a set base filename and store type. 00038 AnalysisHandler(string basefilename="Rivet", HistoFormat storetype=AIDAML); 00039 00040 /// The destructor is not virtual as this class should not be inherited from. 00041 ~AnalysisHandler(); 00042 //@} 00043 00044 private: 00045 00046 /// Do the initialisation of the AIDA analysis factories. 00047 void setupFactories(string basefilename, HistoFormat storetype); 00048 00049 /// Convert any IHistogram1D objects in the AIDA tree to IDataPointSet objects. 00050 void normalizeTree(AIDA::ITree& tree); 00051 00052 /// Get a logger object. 00053 Log& getLog(); 00054 00055 public: 00056 00057 00058 /// Add an analysis to the run list using its name. The actual Analysis 00059 /// to be used will be obtained via AnalysisHandler::getAnalysis(string). 00060 /// If no matching analysis is found, no analysis is added (i.e. the 00061 /// null pointer is checked and discarded. 00062 AnalysisHandler& addAnalysis(const string& analysisname); 00063 00064 00065 /// Add an analysis to the run list by supplying a "template" analysis. 00066 /// @todo Is there a good reason to not allow "direct" submission? 00067 template <typename A> 00068 inline AnalysisHandler& addAnalysis(const A& analysis) { 00069 A* a = new A(analysis); 00070 a->_theHandler = this; 00071 _analyses.insert(a); 00072 return *this; 00073 } 00074 00075 00076 /// Initialize a run. If this run is to be joined together with other 00077 /// runs, \a N should be set to the total number of runs to be 00078 /// combined, and \a i should be the index of this run. This function 00079 /// will initialize the histogram factory and then call the 00080 /// AnalysisBase::init() function of all included analysis objects. 00081 void init(int i=0, int N=0); 00082 00083 00084 /// Analyze the given \a event. This function will call the 00085 /// AnalysisBase::analyze() function of all included analysis objects. 00086 void analyze(const GenEvent& event); 00087 00088 00089 /// Finalize a run. This function first calls the 00090 /// AnalysisBase::finalize() functions of all included analysis 00091 /// objects and then writes out all histograms to a file. 00092 void finalize(); 00093 00094 00095 /// The AIDA analysis factory. 00096 inline AIDA::IAnalysisFactory& analysisFactory() { 00097 return *_theAnalysisFactory; 00098 } 00099 00100 00101 /// The AIDA tree object. 00102 inline AIDA::ITree& tree() { 00103 return *_theTree; 00104 } 00105 00106 00107 /// The AIDA histogram factory. 00108 inline AIDA::IHistogramFactory& histogramFactory() { 00109 return *_theHistogramFactory; 00110 } 00111 00112 00113 /// The AIDA histogram factory. 00114 inline AIDA::IDataPointSetFactory& datapointsetFactory() { 00115 return *_theDataPointSetFactory; 00116 } 00117 00118 00119 00120 private: 00121 00122 /// The collection of Analysis objects to be used. 00123 set<Analysis*> _analyses; 00124 00125 /// If non-zero the number of runs to be combined into one analysis. 00126 int _nRun; 00127 00128 /// If non-zero, the index of this run, if a part of several runs to 00129 /// be combined into one. 00130 int _iRun; 00131 00132 /// The AIDA analysis factory. 00133 AIDA::IAnalysisFactory* _theAnalysisFactory; 00134 00135 /// The AIDA tree object. 00136 AIDA::ITree* _theTree; 00137 00138 /// The AIDA histogram factory. 00139 AIDA::IHistogramFactory* _theHistogramFactory; 00140 00141 /// The AIDA data point set factory. 00142 AIDA::IDataPointSetFactory* _theDataPointSetFactory; 00143 00144 private: 00145 00146 /// The assignment operator is private and must never be called. 00147 /// In fact, it should not even be implemented. 00148 AnalysisHandler& operator=(const AnalysisHandler&); 00149 00150 /// The copy constructor is private and must never be called. In 00151 /// fact, it should not even be implemented. 00152 AnalysisHandler(const AnalysisHandler&); 00153 00154 }; 00155 00156 00157 } 00158 00159 #endif