From 2ce6691fe46862df3905f0414ae9d941d7b990e4 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Tue, 3 Jun 2014 13:28:20 +0000
Subject: [PATCH] Fix scope problems.

---
 DDCore/include/DD4hep/DD4hepRootPersistency.h | 25 ++++++++
 DDCore/include/DD4hep/Dictionary.h            |  2 +
 DDCore/include/DD4hep/IDDescriptor.h          |  5 +-
 DDCore/include/DD4hep/LCDDData.h              |  1 +
 DDCore/include/DD4hep/Primitives.h            | 14 +++++
 DDCore/include/DD4hep/Segmentations.h         |  4 +-
 .../include/DD4hep/objects/ObjectsInterna.h   |  6 +-
 DDCore/src/DD4hepRootPersistency.cpp          | 60 +++++++++++++++++++
 DDCore/src/IDDescriptor.cpp                   |  2 -
 DDCore/src/LCDDImp.cpp                        |  2 +-
 DDCore/src/plugins/StandardPlugins.cpp        | 34 ++++++++---
 DDG4/include/DDG4/Geant4GeometryInfo.h        | 16 ++---
 DDG4/include/DDG4/Geant4HitCollection.h       |  2 +
 DDG4/include/DDG4/Geant4Hits.h                |  4 ++
 DDG4/src/Geant4HitCollection.cpp              |  4 ++
 15 files changed, 153 insertions(+), 28 deletions(-)
 create mode 100644 DDCore/include/DD4hep/DD4hepRootPersistency.h
 create mode 100644 DDCore/src/DD4hepRootPersistency.cpp

diff --git a/DDCore/include/DD4hep/DD4hepRootPersistency.h b/DDCore/include/DD4hep/DD4hepRootPersistency.h
new file mode 100644
index 000000000..51a0bc0e6
--- /dev/null
+++ b/DDCore/include/DD4hep/DD4hepRootPersistency.h
@@ -0,0 +1,25 @@
+// $Id: Handle.h 570 2013-05-17 07:47:11Z markus.frank $
+//====================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------
+//
+//  Author     : M.Frank
+//
+//====================================================================
+
+#ifndef DD4HEP_DD4HEPROOTPERSISTENCY_H
+#define DD4HEP_DD4HEPROOTPERSISTENCY_H
+
+// Framework include files
+#include "DD4hep/LCDDData.h"
+
+class DD4hepRootPersistency : public TNamed, public DD4hep::Geometry::LCDDData  {
+ public:
+ DD4hepRootPersistency() : TNamed() {}
+  virtual ~DD4hepRootPersistency() {}
+  static int save(DD4hep::Geometry::LCDD& lcdd, const char* fname, const char* instance = "Geometry");
+  static int load(DD4hep::Geometry::LCDD& lcdd, const char* fname, const char* instance = "Geometry");
+  ClassDef(DD4hepRootPersistency,1);
+};
+
+#endif    /* DD4HEP_DD4HEPROOTPERSISTENCY_H         */
diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h
index 37320bbee..85634278a 100644
--- a/DDCore/include/DD4hep/Dictionary.h
+++ b/DDCore/include/DD4hep/Dictionary.h
@@ -12,6 +12,7 @@
 #include "DD4hep/LCDDData.h"
 #include "DD4hep/Conditions.h"
 #include "DD4hep/FieldTypes.h"
+#include "DD4hep/DD4hepRootPersistency.h"
 #include "DD4hep/objects/ObjectsInterna.h"
 #include "DD4hep/objects/DetectorInterna.h"
 #include "DD4hep/objects/ConditionsInterna.h"
@@ -55,6 +56,7 @@ template class DD4hep::Geometry::Handle<TNamed>;
 #pragma link C++ class DD4hep::Geometry::LCDDData::ObjectHandleMap+;
 #pragma link C++ class DD4hep::Geometry::LCDD::PropertyValues+;
 #pragma link C++ class DD4hep::Geometry::LCDD::Properties+;
+#pragma link C++ class DD4hepRootPersistency+;
 
 // These below are the Namedobject instances to be generated ....
 //#pragma link C++ class DD4hep::Geometry::LCDD::HandleMap+;
diff --git a/DDCore/include/DD4hep/IDDescriptor.h b/DDCore/include/DD4hep/IDDescriptor.h
index 9be33e24d..433e087c7 100644
--- a/DDCore/include/DD4hep/IDDescriptor.h
+++ b/DDCore/include/DD4hep/IDDescriptor.h
@@ -12,7 +12,6 @@
 
 // Framework include files
 #include "DD4hep/Handle.h"
-#include "DD4hep/Primitives.h"
 #include "DDSegmentation/BitField64.h"
 
 // C++ include files
@@ -41,7 +40,7 @@ namespace DD4hep {
     class IDDescriptor: public Handle<IDDescriptorObject> {
     public:
       typedef IDDescriptorObject Object;
-      typedef DDSegmentation::BitFieldValue* Field;
+      typedef BitFieldValue* Field;
       typedef std::vector<std::pair<std::string, Field> > FieldMap;
       typedef std::vector<std::pair<size_t, std::string> > FieldIDs;
       typedef std::pair<Field, VolumeID> VolIDField;
@@ -82,7 +81,7 @@ namespace DD4hep {
       /// Access string representation
       std::string toString() const;
       /// Access the BitField64 object
-      DDSegmentation::BitField64* decoder();
+      BitField64* decoder();
     };
   } /* End namespace Geometry    */
 } /* End namespace DD4hep      */
diff --git a/DDCore/include/DD4hep/LCDDData.h b/DDCore/include/DD4hep/LCDDData.h
index 46c1ac27d..538a8d973 100644
--- a/DDCore/include/DD4hep/LCDDData.h
+++ b/DDCore/include/DD4hep/LCDDData.h
@@ -104,6 +104,7 @@ namespace DD4hep {
       LCDDData();
       /// Default destructor
       virtual ~LCDDData();
+    public:
       /// Clear data content: releases all allocated resources
       void destroyData();
       /// Clear data content: DOES NOT RELEASEW ALLOCATED RESOURCES!
diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h
index 9fd951604..fb7ba3c83 100644
--- a/DDCore/include/DD4hep/Primitives.h
+++ b/DDCore/include/DD4hep/Primitives.h
@@ -19,6 +19,11 @@
  */
 namespace DD4hep {
 
+  namespace DDSegmentation  {
+    class BitField64;
+    class BitFieldValue;
+  }
+
   /// We need it so often: one-at-time 32 bit hash function
   inline unsigned int hash32(const char* key) {
     unsigned int hash = 0;
@@ -97,8 +102,17 @@ namespace DD4hep {
 
 
   // Put here global basic type definitions derived from primitive types of the DD4hep namespace
+#ifdef __CINT__
   typedef DDSegmentation::CellID CellID;
   typedef DDSegmentation::VolumeID VolumeID;
+  typedef DDSegmentation::BitField64 BitField64;
+  typedef DDSegmentation::BitFieldValue BitFieldValue;
+#else
+  using DDSegmentation::CellID;
+  using DDSegmentation::VolumeID;
+  using DDSegmentation::BitField64;
+  using DDSegmentation::BitFieldValue;
+#endif
 
   /// Helper to copy objects.
   template <typename T> inline void copyObject(void* target,const void* source)  {
diff --git a/DDCore/include/DD4hep/Segmentations.h b/DDCore/include/DD4hep/Segmentations.h
index 4590ba362..c97d12881 100644
--- a/DDCore/include/DD4hep/Segmentations.h
+++ b/DDCore/include/DD4hep/Segmentations.h
@@ -30,8 +30,6 @@ namespace DD4hep {
    */
   namespace Geometry {
 
-    typedef DDSegmentation::BitField64 BitField64;
-
     /** @class Segmentation::Object Segmentations.h DD4hep/Segmentations.h
      *
      * @author  M.Frank
@@ -40,8 +38,8 @@ namespace DD4hep {
     class SegmentationObject : public DDSegmentation::Segmentation {
     public:
       typedef DDSegmentation::Segmentation BaseSegmentation;
-      typedef DDSegmentation::Parameter Parameter;
       typedef DDSegmentation::Parameters Parameters;
+      typedef DDSegmentation::Parameter Parameter;
     public:
       /// Magic word to check object integrity
       unsigned long magic;
diff --git a/DDCore/include/DD4hep/objects/ObjectsInterna.h b/DDCore/include/DD4hep/objects/ObjectsInterna.h
index ee8a59eb6..11796be87 100644
--- a/DDCore/include/DD4hep/objects/ObjectsInterna.h
+++ b/DDCore/include/DD4hep/objects/ObjectsInterna.h
@@ -136,9 +136,9 @@ namespace DD4hep {
      *  @version 1.0
      *  @date    2012/07/31
      */
-    class IDDescriptorObject: public NamedObject, public DDSegmentation::BitField64 {
+    class IDDescriptorObject: public NamedObject, public BitField64 {
     public:
-      typedef DDSegmentation::BitFieldValue* Field;
+      typedef BitFieldValue* Field;
       typedef std::vector<std::pair<std::string, Field> > FieldMap;
       typedef std::vector<std::pair<size_t, std::string> > FieldIDs;
       FieldMap fieldMap; //! not ROOT-persistent
@@ -152,7 +152,7 @@ namespace DD4hep {
       virtual ~IDDescriptorObject();
 #ifndef __CINT__
       /// Access to the field container of the BitField64
-      const std::vector<DDSegmentation::BitFieldValue*> fields() const {
+      const std::vector<BitFieldValue*> fields() const {
 	return _fields;
       }
 #endif
diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp
new file mode 100644
index 000000000..e3c684c82
--- /dev/null
+++ b/DDCore/src/DD4hepRootPersistency.cpp
@@ -0,0 +1,60 @@
+// $Id: Detector.cpp 1087 2014-04-09 12:25:51Z markus.frank@cern.ch $
+//====================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------
+//
+//  Author     : M.Frank
+//
+//====================================================================
+
+// Framework include files
+#include "DD4hep/Printout.h"
+#include "DD4hep/DD4hepRootPersistency.h"
+
+// ROOT include files
+#include "TFile.h"
+
+ClassImp(DD4hepRootPersistency)
+
+typedef DD4hep::Geometry::LCDD LCDD;
+typedef DD4hep::Geometry::LCDDData LCDDData;
+
+int DD4hepRootPersistency::save(DD4hep::Geometry::LCDD& lcdd, const char* fname, const char* instance)   {
+  TFile* f = TFile::Open(fname,"RECREATE");
+  if ( f && !f->IsZombie()) {
+    DD4hepRootPersistency* persist = new DD4hepRootPersistency();
+    persist->adoptData(dynamic_cast<LCDDData&>(lcdd));
+    int nBytes = persist->Write(instance);
+    f->Close();
+    DD4hep::printout(DD4hep::ALWAYS,"DD4hepRootPersistency",
+		     "+++ Wrote %d Bytes of geometry data '%s' to '%s'.",
+		     nBytes, instance, fname);
+    delete f;
+    delete persist;
+    return nBytes;
+  }
+  DD4hep::printout(DD4hep::ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname);
+  return 0;
+}
+
+int DD4hepRootPersistency::load(DD4hep::Geometry::LCDD& lcdd, const char* fname, const char* instance)  {
+  TFile* f = TFile::Open(fname);
+  if ( f && !f->IsZombie()) {
+    DD4hepRootPersistency* persist = (DD4hepRootPersistency*)f->Get(instance);
+    if ( persist )   {
+      LCDDData& data = dynamic_cast<LCDDData&>(lcdd);
+      data.adoptData(*persist);
+      persist->clearData();
+      delete persist;
+      return 1;
+    }
+    DD4hep::printout(DD4hep::ERROR,"DD4hepRootPersistency",
+		     "+++ Cannot Cannot load instance '%s' from file '%s'.",
+		     instance, fname);
+    f->ls();
+    delete f;
+    return 0;
+  }
+  DD4hep::printout(DD4hep::ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname);
+  return 0;
+}
diff --git a/DDCore/src/IDDescriptor.cpp b/DDCore/src/IDDescriptor.cpp
index f27921ce6..67888bd7f 100644
--- a/DDCore/src/IDDescriptor.cpp
+++ b/DDCore/src/IDDescriptor.cpp
@@ -17,8 +17,6 @@
 using namespace std;
 using namespace DD4hep;
 using namespace DD4hep::Geometry;
-using DDSegmentation::BitField64;
-using DDSegmentation::BitFieldValue;
 
 namespace {
   void _construct(IDDescriptor::Object* o, const string& dsc) {
diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp
index e3e71bbb8..fa4c1e270 100644
--- a/DDCore/src/LCDDImp.cpp
+++ b/DDCore/src/LCDDImp.cpp
@@ -77,7 +77,7 @@ void lcdd_unexpected(){
 }
 
 /// Disable copy constructor
-LCDDImp::LCDDImp(const LCDDImp&) : LCDDData(), m_volManager(), m_buildType(BUILD_NONE)  {
+LCDDImp::LCDDImp(const LCDDImp&) : LCDD(), LCDDData(), m_volManager(), m_buildType(BUILD_NONE)  {
 }
 
 /// Disable assignment operator
diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp
index cbadfeb40..16a867e64 100644
--- a/DDCore/src/plugins/StandardPlugins.cpp
+++ b/DDCore/src/plugins/StandardPlugins.cpp
@@ -13,6 +13,8 @@
 #include "DD4hep/LCDD.h"
 #include "DD4hep/Factories.h"
 #include "DD4hep/Printout.h"
+#include "DD4hep/DetectorTools.h"
+#include "DD4hep/DD4hepRootPersistency.h"
 #include "../LCDDImp.h"
 
 // ROOT includes
@@ -123,17 +125,33 @@ static long load_volmgr(LCDD& lcdd, int, char**) {
 }
 DECLARE_APPLY(DD4hepVolumeManager,load_volmgr)
 
-static long dump_geometry(LCDD& lcdd, int argc, char** argv) {
-  if ( argc > 1 )   {
-    string output = argv[1];
-    printout(INFO,"Geometry2Root","+++ Dump geometry to root file:%s",output.c_str());
-    lcdd.manager().Export(output.c_str()+1);
-    return 1;
+static long dump_geometry2root(LCDD& lcdd, int argc, char** argv) {
+  if ( argc > 0 )   {
+    string output = argv[0];
+    printout(INFO,"Geometry2ROOT","+++ Dump geometry to root file:%s",output.c_str());
+    //lcdd.manager().Export(output.c_str()+1);
+    if ( DD4hepRootPersistency::save(lcdd,output.c_str(),"Geometry") > 1 )  {
+      return 1;
+    }
   }
+  printout(ERROR,"Geometry2ROOT","+++ No output file name given.");
   return 0;
 }
-DECLARE_APPLY(DD4hepGeometry2Root,dump_geometry)
-#include "DD4hep/DetectorTools.h"
+DECLARE_APPLY(DD4hepGeometry2ROOT,dump_geometry2root)
+
+static long load_geometryFromroot(LCDD& lcdd, int argc, char** argv) {
+  if ( argc > 0 )   {
+    string input = argv[0];
+    printout(INFO,"DD4hepRootLoader","+++ Read geometry from root file:%s",input.c_str());
+    if ( 1 == DD4hepRootPersistency::load(lcdd,input.c_str(),"Geometry") )  {
+      return 1;
+    }
+  }
+  printout(ERROR,"DD4hepRootLoader","+++ No input file name given.");
+  return 0;
+}
+DECLARE_APPLY(DD4hepRootLoader,load_geometryFromroot)
+
 /** Basic entry point to print out the volume hierarchy
  *
  *  @author  M.Frank
diff --git a/DDG4/include/DDG4/Geant4GeometryInfo.h b/DDG4/include/DDG4/Geant4GeometryInfo.h
index 6c024e053..9e999e91c 100644
--- a/DDG4/include/DDG4/Geant4GeometryInfo.h
+++ b/DDG4/include/DDG4/Geant4GeometryInfo.h
@@ -51,14 +51,14 @@ namespace DD4hep {
     class Geant4AssemblyVolume;
 
     namespace Geant4GeometryMaps  {
-      typedef Geometry::Atom Atom;
-      typedef Geometry::Material Material;
-      typedef Geometry::VisAttr VisAttr;
-      typedef Geometry::Volume Volume;
-      typedef Geometry::PlacedVolume PlacedVolume;
-      typedef Geometry::Region Region;
-      typedef Geometry::LimitSet LimitSet;
-      typedef Geometry::SensitiveDetector SensitiveDetector;
+      using Geometry::Atom;
+      using Geometry::Material;
+      using Geometry::VisAttr;
+      using Geometry::Volume;
+      using Geometry::PlacedVolume;
+      using Geometry::Region;
+      using Geometry::LimitSet;
+      using Geometry::SensitiveDetector;
 
       typedef std::vector<const G4VPhysicalVolume*> Geant4PlacementPath;
       typedef std::map<Atom, G4Element*> ElementMap;
diff --git a/DDG4/include/DDG4/Geant4HitCollection.h b/DDG4/include/DDG4/Geant4HitCollection.h
index f48db4dd2..5f8b0a728 100644
--- a/DDG4/include/DDG4/Geant4HitCollection.h
+++ b/DDG4/include/DDG4/Geant4HitCollection.h
@@ -177,6 +177,8 @@ namespace DD4hep {
        * @version 1.0
        */
       struct Compare {
+	/// Default destructor
+	virtual ~Compare();
         /// Comparison function
         virtual void* operator()(const Geant4HitWrapper& w) const = 0;
       };
diff --git a/DDG4/include/DDG4/Geant4Hits.h b/DDG4/include/DDG4/Geant4Hits.h
index b3512c6cf..9a389e0ea 100644
--- a/DDG4/include/DDG4/Geant4Hits.h
+++ b/DDG4/include/DDG4/Geant4Hits.h
@@ -43,6 +43,8 @@ namespace DD4hep {
      * @version 1.0
      */
     template <class HIT> struct HitCompare {
+      /// Default destructor
+      virtual ~HitCompare() {}
       /// Comparison function
       virtual bool operator()(const HIT* h) const = 0;
     };
@@ -60,6 +62,8 @@ namespace DD4hep {
       HitPositionCompare(const Position& p)
           : pos(p) {
       }
+      /// Default destructor
+      virtual ~HitPositionCompare() {}
       /// Comparison function
       virtual bool operator()(const HIT* h) const {
         return pos == h->position;
diff --git a/DDG4/src/Geant4HitCollection.cpp b/DDG4/src/Geant4HitCollection.cpp
index 6a4eb0c05..3d805840c 100644
--- a/DDG4/src/Geant4HitCollection.cpp
+++ b/DDG4/src/Geant4HitCollection.cpp
@@ -65,6 +65,10 @@ Geant4HitWrapper::Wrapper Geant4HitWrapper::releaseData() {
   return w;
 }
 
+/// Default destructor
+Geant4HitCollection::Compare::~Compare()  {
+}
+
 /// Default destructor
 Geant4HitCollection::~Geant4HitCollection() {
   m_hits.clear();
-- 
GitLab