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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Sat Nov 7 16:58:04 GMT 2009


Author: buckley
Date: Sat Nov  7 16:58:03 2009
New Revision: 2038

Log:
Adding a checking system which ensures that analyses don't register projections in their constructors

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

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Sat Nov  7 16:56:46 2009	(r2037)
+++ trunk/ChangeLog	Sat Nov  7 16:58:03 2009	(r2038)
@@ -1,5 +1,8 @@
 2009-11-07  Andy Buckley  <andy at insectnation.org>
 
+	* Adding checking system to ensure that Projections aren't
+	registered before the init phase of analyses.
+
 	* Now that the ProjHandler isn't full of defunct pointers (which
 	tend to coincidentally point to *new* Projection pointers rather
 	than undefined memory, hence it wasn't noticed until recently!),

Modified: trunk/include/Rivet/ProjectionApplier.hh
==============================================================================
--- trunk/include/Rivet/ProjectionApplier.hh	Sat Nov  7 16:56:46 2009	(r2037)
+++ trunk/include/Rivet/ProjectionApplier.hh	Sat Nov  7 16:58:03 2009	(r2038)
@@ -18,9 +18,14 @@
   /// same container (used by the ProjectionHandler)
   class ProjectionApplier {
   public:
+
+    // The proj handler needs access to reset the _allowProjReg flag before calling a.init()
+    friend class Projectionhandler;
+
+    /// Constructor
     ProjectionApplier();
 
-    // Ensure that inheritance is possible.
+    // Virtual destructor: ensure that inheritance is possible.
     virtual ~ProjectionApplier();
 
 
@@ -128,6 +133,12 @@
     /// Non-templated version of proj-based applyProjection, to work around
     /// header dependency issue.
     const Projection& _applyProjection(const Event& evt, const Projection& proj) const;
+
+
+  protected:
+
+    /// Flag to forbid projection registration in analyses until the init phase
+    bool _allowProjReg;
     
     
   private:

Modified: trunk/src/Analysis.cc
==============================================================================
--- trunk/src/Analysis.cc	Sat Nov  7 16:56:46 2009	(r2037)
+++ trunk/src/Analysis.cc	Sat Nov  7 16:58:03 2009	(r2038)
@@ -17,14 +17,15 @@
       _analysishandler(0),
       _madeHistoDir(false)
   {
+    ProjectionApplier::_allowProjReg = false;
     _defaultname = name;
     _info.reset( AnalysisInfo::make(name) );
     setBeams(ANY, ANY);
   }
+
   
   Analysis::~Analysis()
-  {
-  }
+  {  }
   
 
   IAnalysisFactory& Analysis::analysisFactory() {

Modified: trunk/src/AnalysisHandler.cc
==============================================================================
--- trunk/src/AnalysisHandler.cc	Sat Nov  7 16:56:46 2009	(r2037)
+++ trunk/src/AnalysisHandler.cc	Sat Nov  7 16:58:03 2009	(r2038)
@@ -44,6 +44,8 @@
     _sumOfWeights = 0.0;
     foreach (Analysis* a, _analyses) {
       getLog() << Log::DEBUG << "Initialising analysis: " << a->name() << endl;
+      // Allow projection registration in the init phase onwards
+      a->_allowProjReg = true;
       a->init();
       //getLog() << Log::DEBUG << "Checking consistency of analysis: " << a->name() << endl;
       //a->checkConsistency();

Modified: trunk/src/ProjectionApplier.cc
==============================================================================
--- trunk/src/ProjectionApplier.cc	Sat Nov  7 16:56:46 2009	(r2037)
+++ trunk/src/ProjectionApplier.cc	Sat Nov  7 16:58:03 2009	(r2038)
@@ -6,9 +6,11 @@
 namespace Rivet {
 
 
+  // NB. Allow proj registration in constructor by default -- explicitly disable for Analysis 
   ProjectionApplier::ProjectionApplier()
-    : _projhandler(ProjectionHandler::create())
-  { }
+    : _allowProjReg(true),
+      _projhandler(ProjectionHandler::create())
+  {  }
 
 
   ProjectionApplier::~ProjectionApplier() {
@@ -30,6 +32,11 @@
 
   const Projection& ProjectionApplier::_addProjection(const Projection& proj, 
                                                       const std::string& name) {
+    if (!_allowProjReg) {
+      getLog() << Log::ERROR << "Trying to register projection '" 
+               << proj.name() << "' before init phase in '" << this->name() << "'." << endl;
+      exit(2);
+    }
     const Projection& reg = getProjHandler().registerProjection(*this, proj, name);
     return reg;
   }


More information about the Rivet-svn mailing list