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

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue May 10 14:25:20 BST 2011


Author: buckley
Date: Tue May 10 14:25:20 2011
New Revision: 3093

Log:
Internal minor changes to the ProjectionHandler and ProjectionApplier
interfaces, in particular changing the ProjectionHandler::create() function to
be called getInstance and to return a reference rather than a pointer. The
reference change is to make way for an improved singleton implementation, which
cannot yet be used due to a bug in projection memory management. The code of the
improved singleton is available, but commented out, in ProjectionManager.hh to
allow for easier migration and to avoid branching.

Modified:
   trunk/ChangeLog
   trunk/include/Rivet/HistoHandler.hh
   trunk/include/Rivet/ProjectionApplier.hh
   trunk/include/Rivet/ProjectionHandler.hh
   trunk/src/Core/ProjectionApplier.cc
   trunk/src/Core/ProjectionHandler.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/ChangeLog	Tue May 10 14:25:20 2011	(r3093)
@@ -1,3 +1,15 @@
+2011-05-10  Andy Buckley  <andy at insectnation.org>
+
+	* Internal minor changes to the ProjectionHandler and
+	ProjectionApplier interfaces, in particular changing the
+	ProjectionHandler::create() function to be called getInstance and
+	to return a reference rather than a pointer. The reference change
+	is to make way for an improved singleton implementation, which
+	cannot yet be used due to a bug in projection memory
+	management. The code of the improved singleton is available, but
+	commented out, in ProjectionManager.hh to allow for easier
+	migration and to avoid branching.
+
 2011-05-08  Andy Buckley  <andy at insectnation.org>
 
 	* Extending flat2aida to be able to read from and write to

Modified: trunk/include/Rivet/HistoHandler.hh
==============================================================================
--- trunk/include/Rivet/HistoHandler.hh	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/include/Rivet/HistoHandler.hh	Tue May 10 14:25:20 2011	(r3093)
@@ -28,9 +28,9 @@
 
     /// @name Construction. */
     //@{
+
     /// The standard constructor.
     HistoHandler() { }
-    //@}
 
     /// Private destructor means no inheritance from this class.
     ~HistoHandler();
@@ -41,6 +41,8 @@
     /// The copy constructor is hidden.
     HistoHandler(const HistoHandler&);
 
+    //@}
+
 
   public:
 

Modified: trunk/include/Rivet/ProjectionApplier.hh
==============================================================================
--- trunk/include/Rivet/ProjectionApplier.hh	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/include/Rivet/ProjectionApplier.hh	Tue May 10 14:25:20 2011	(r3093)
@@ -20,7 +20,7 @@
   public:
 
     // The proj handler needs access to reset the _allowProjReg flag before calling a.init()
-    friend class Projectionhandler;
+    // friend class ProjectionHandler;
 
     /// Constructor
     ProjectionApplier();
@@ -93,8 +93,7 @@
 
     /// Get a reference to the ProjectionHandler for this thread.
     ProjectionHandler& getProjHandler() const {
-      assert(_projhandler);
-      return *_projhandler;
+      return _projhandler;
     }
 
 
@@ -145,7 +144,7 @@
   private:
 
     /// Pointer to projection handler.
-    ProjectionHandler* _projhandler;
+    ProjectionHandler& _projhandler;
 
   };
 

Modified: trunk/include/Rivet/ProjectionHandler.hh
==============================================================================
--- trunk/include/Rivet/ProjectionHandler.hh	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/include/Rivet/ProjectionHandler.hh	Tue May 10 14:25:20 2011	(r3093)
@@ -73,6 +73,9 @@
 
   private:
 
+    /// @name Construction. */
+    //@{
+
     /// Private destructor means no inheritance from this class.
     ~ProjectionHandler();
 
@@ -82,27 +85,24 @@
     /// The copy constructor is hidden.
     ProjectionHandler(const ProjectionHandler&);
 
-
-  private:
-
-    /// @name Construction. */
-    //@{
     /// The standard constructor.
     ProjectionHandler() { }
-    //@}
 
-    /// Singleton instance
-    /// @todo Threading?
+    /// @todo Remove in favour of the static singleton function
     static ProjectionHandler* _instance;
 
+    //@}
+
 
   public:
 
     /// Singleton creation function
-    static ProjectionHandler* create();
-
-    /// Singleton deletion function
-    static void destroy();
+    static ProjectionHandler& getInstance(); // {
+    /// @todo This is a better form of singleton, which cleans up properly... but it can't
+    /// yet be used as it highlights a projection memory problem. Please fix so we can use this!
+    //   static ProjectionHandler _instance;
+    //   return _instance;
+    // }
 
 
   public:

Modified: trunk/src/Core/ProjectionApplier.cc
==============================================================================
--- trunk/src/Core/ProjectionApplier.cc	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/src/Core/ProjectionApplier.cc	Tue May 10 14:25:20 2011	(r3093)
@@ -9,7 +9,7 @@
   // NB. Allow proj registration in constructor by default -- explicitly disable for Analysis
   ProjectionApplier::ProjectionApplier()
     : _allowProjReg(true),
-      _projhandler(ProjectionHandler::create())
+      _projhandler(ProjectionHandler::getInstance())
   {  }
 
 

Modified: trunk/src/Core/ProjectionHandler.cc
==============================================================================
--- trunk/src/Core/ProjectionHandler.cc	Tue May 10 13:15:05 2011	(r3092)
+++ trunk/src/Core/ProjectionHandler.cc	Tue May 10 14:25:20 2011	(r3093)
@@ -11,24 +11,16 @@
   // Initialize instance pointer to null.
   ProjectionHandler* ProjectionHandler::_instance = 0;
 
-
-  //int Log_TRACE = Log::INFO;
-
-
-  ProjectionHandler* ProjectionHandler::create() {
+  ProjectionHandler& ProjectionHandler::getInstance() {
     if (!_instance) {
       _instance = new ProjectionHandler();
       Log::getLog("Rivet.ProjectionHandler")
         << Log::TRACE << "Created new ProjectionHandler at " << _instance << endl;
     }
-    return _instance;
+    return *_instance;
   }
 
 
-  void ProjectionHandler::destroy() {
-    delete _instance;
-  }
-
 
   // Get a logger.
   Log& ProjectionHandler::getLog() const {
@@ -36,14 +28,12 @@
   }
 
 
-
   void ProjectionHandler::clear() {
     _projs.clear();
     _namedprojs.clear();
   }
 
 
-
   // Delete contained pointers.
   ProjectionHandler::~ProjectionHandler() {
     clear();


More information about the Rivet-svn mailing list