[Rivet-svn] r2188 - in trunk: . include/Rivet src/Core

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Mon Dec 14 16:02:28 GMT 2009


Author: buckley
Date: Mon Dec 14 16:02:28 2009
New Revision: 2188

Log:
Make AnalysisHandler::execute call AnalysisHandler::init(event) on first event, if it has not already been called.

Modified:
   trunk/ChangeLog
   trunk/include/Rivet/AnalysisHandler.hh
   trunk/src/Core/AnalysisHandler.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Mon Dec 14 14:42:56 2009	(r2187)
+++ trunk/ChangeLog	Mon Dec 14 16:02:28 2009	(r2188)
@@ -1,5 +1,8 @@
 2009-12-14  Andy Buckley  <andy at insectnation.org>
 
+	* AnalysisHandler::execute now calls AnalysisHandler::init(event)
+	if it has not yet been initialised.
+
 	* Adding more beam configuration features to Beam and
 	AnalysisHandler: the setRunBeams(...) methods on the latter now
 	allows a beam configuration for the run to be specified without

Modified: trunk/include/Rivet/AnalysisHandler.hh
==============================================================================
--- trunk/include/Rivet/AnalysisHandler.hh	Mon Dec 14 14:42:56 2009	(r2187)
+++ trunk/include/Rivet/AnalysisHandler.hh	Mon Dec 14 16:02:28 2009	(r2188)
@@ -98,7 +98,7 @@
 
 
     /// Set beams for this run (as determined from first event)
-    AnalysisHandler& setRunBeams(const Event& event) { 
+    AnalysisHandler& setRunBeams(const GenEvent& event) { 
       return setRunBeams(Rivet::beams(event));
     }
 
@@ -167,6 +167,7 @@
     }
 
     /// Remove beam-incompatible analyses from the run list.
+    /// @todo Do this automatically in the init phase (including energies) and deprecate explicit use
     AnalysisHandler& removeIncompatibleAnalyses(const BeamPair& beams);
 
     //@}
@@ -201,6 +202,7 @@
 
 
     /// @name AIDA factories etc.
+    /// @deprecated All this will be removed when histogramming is overhauled
     //@{
 
     /// The AIDA analysis factory.
@@ -248,7 +250,10 @@
 
     /// Beams used by this run.
     ParticlePair _beams;
-    
+
+    /// Flag to check if init has been called
+    bool _initialised;
+
     //@}
 
 

Modified: trunk/src/Core/AnalysisHandler.cc
==============================================================================
--- trunk/src/Core/AnalysisHandler.cc	Mon Dec 14 14:42:56 2009	(r2187)
+++ trunk/src/Core/AnalysisHandler.cc	Mon Dec 14 16:02:28 2009	(r2188)
@@ -13,7 +13,7 @@
   AnalysisHandler::AnalysisHandler(string basefilename,
                                    string runname, HistoFormat storetype)
     : _runname(runname), _numEvents(0), 
-      _sumOfWeights(0.0), _xs(-1.0)
+      _sumOfWeights(0.0), _xs(-1.0), _initialised(false)
   {
     _theAnalysisFactory = createAnalysisFactory();
     _setupFactories(basefilename, storetype);
@@ -23,7 +23,7 @@
   AnalysisHandler::AnalysisHandler(IAnalysisFactory& afac, string basefilename,
                                    string runname, HistoFormat storetype)
     : _runname(runname), _numEvents(0), 
-      _sumOfWeights(0.0), _xs(-1.0),
+      _sumOfWeights(0.0), _xs(-1.0), _initialised(false), 
       _theAnalysisFactory(&afac) 
   {
     _setupFactories(basefilename, storetype);
@@ -40,6 +40,7 @@
 
 
   void AnalysisHandler::init() {
+    assert(!_initialised);
     getLog() << Log::DEBUG << "Initialising the analysis handler" << endl;
     _numEvents = 0;
     _sumOfWeights = 0.0;
@@ -52,11 +53,18 @@
       //a->checkConsistency();
       getLog() << Log::DEBUG << "Done initialising analysis: " << a->name() << endl;
     }
+    _initialised = true;
     getLog() << Log::DEBUG << "Analysis handler initialised" << endl;
   }
 
 
   void AnalysisHandler::analyze(const GenEvent& ge) {
+    // Call init with event as template if not already initialised
+    if (!_initialised) {
+      init(ge);
+    }
+    // Proceed with event analysis
+    assert(_initialised);
     Event event(ge);
     _numEvents++;
     // Weights
@@ -78,6 +86,7 @@
 
 
   void AnalysisHandler::finalize() {
+    assert(_initialised);
     getLog() << Log::INFO << "Finalising analyses" << endl;
     foreach (Analysis* a, _analyses) {
       a->finalize();
@@ -133,7 +142,6 @@
   }
 
 
-  /// Remove beam-incompatible analyses from the run list.
   AnalysisHandler& AnalysisHandler::removeIncompatibleAnalyses(const BeamPair& beams) {
     vector<Analysis*> todelete;
     foreach (Analysis* a, _analyses) {


More information about the Rivet-svn mailing list