Index: trunk/source/persistency/gdml/History
===================================================================
--- trunk/source/persistency/gdml/History	(revision 1202)
+++ trunk/source/persistency/gdml/History	(revision 1228)
@@ -1,3 +1,3 @@
-$Id: History,v 1.101 2009/02/26 10:13:49 gcosmo Exp $
+$Id: History,v 1.116 2009/12/04 13:59:05 gcosmo Exp $
 -------------------------------------------------------------------
 
@@ -17,4 +17,70 @@
      * Reverse chronological order (last date on top), please *
      ----------------------------------------------------------
+
+04 Dec 2009 Gabriele Cosmo (gdml-V09-02-18)
+- Updated list of optical properties in G4GDMLReadSolid according to
+  last changes to G4OpticalSurface and G4SurfaceProperty.
+
+14 Oct 2009 Gabriele Cosmo (gdml-V09-02-17)
+- Added support for GDML 'expression' tag, implementing generic expressions
+  stored as literal constants.
+- Corrected handling of 'quantity' tag; added missing caching of evaluation. 
+
+24 Sep 2009 Gabriele Cosmo (gdml-V09-02-16)
+- Added support for the GDML 'assembly' tag, implementing assemblies of
+  simple placements through G4AssemblyVolume.
+
+12 May 2009 Gabriele Cosmo (gdml-V09-02-15)
+- Restricted usage of loops only for placement of volumes. Now correctly
+  handling most common use-case of multiple copies of the same volume/solid
+  through loop statement. Addressing problem report #1063.
+
+11 May 2009 Gabriele Cosmo (gdml-V09-02-14)
+- Allow for name stripping of volumes which are included in loops; do not
+  store appended internal counter reference.
+
+27 April 2009 Gabriele Cosmo (gdml-V09-02-13)
+- Get rid of unused parameter in G4GDMLWriteMaterials::PropertyVectorWrite().
+
+24 April 2009 Gabriele Cosmo (gdml-V09-02-12)
+- Some code cleanup: rationalised inclusion of headers, replacing them
+  with forward declarations where possible.
+
+24 April 2009 Gabriele Cosmo (gdml-V09-02-11)
+- Allow for reading/writing of constant material properties.
+- Implemented ability to write surface properties associated to volumes
+  and material properties.
+
+17 April 2009 Gabriele Cosmo (gdml-V09-02-10)
+- Defined missing copy constructor and operator=() to G4GDMLMatrix
+  internal class, to avoid cases of memory corruption when handling matrices.
+
+15 April 2009 Gabriele Cosmo (gdml-V09-02-09)
+- Completed virtual layer for allowing customisation of the writer for
+  user-extended schemas.
+
+09 April 2009 Gabriele Cosmo (gdml-V09-02-08)
+- Correction in G4GDMLWriteSolids::BooleanWrite() in order to handle
+  cases of nested displaced solids given to both operands in a Boolean
+  operation (ATLAS use case).
+- Renamed flag for maximum number of transformations applied to a solid
+  and moved to G4GDMLWriteSolids base class.
+- First virtual layer for custom writer classes G4GDMLWriteSolids and
+  G4GDMLWriteStructure.
+
+03 April 2009 Tatiana Nikitina (gdml-V09-02-07)
+- Correction in materials and solids tags for allowing parsing of
+  definitions within the tag scope; possibility foreseen by the schema.
+
+24 March 2009 Gabriele Cosmo (gdml-V09-02-06)
+- Added empty default constructor and virtual destructor to classes in the
+  inheritance chain.
+
+02 March 2009 Gabriele Cosmo (gdml-V09-02-05)
+- Fixed association of entities in nested loops for solids and materials.
+  Definitions of materials are not supposed to be included in loops being
+  therefore repeated...
+- Strip off white spaces from names G4GDMLWrite::GenerateName(), to avoid
+  parsing problems in imported files.
 
 26 February 2009 Tatiana Nikitina (gdml-V09-02-04)
Index: trunk/source/persistency/gdml/include/G4GDMLEvaluator.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLEvaluator.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLEvaluator.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLEvaluator.hh,v 1.16 2008/07/16 15:46:33 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLEvaluator.hh,v 1.17 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -45,5 +45,5 @@
 #include <vector>
 
-#include "globals.hh"
+#include "G4Types.hh"
 
 class G4GDMLEvaluator
Index: trunk/source/persistency/gdml/include/G4GDMLParameterisation.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLParameterisation.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLParameterisation.hh	(revision 1228)
@@ -26,5 +26,5 @@
 //
 // $Id: G4GDMLParameterisation.hh,v 1.10 2008/07/16 15:46:33 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
Index: trunk/source/persistency/gdml/include/G4GDMLParser.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLParser.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLParser.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLParser.hh,v 1.57 2009/01/22 11:02:07 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLParser.hh,v 1.58 2009/04/15 13:29:30 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -54,4 +54,5 @@
    G4GDMLParser();
    G4GDMLParser(G4GDMLReadStructure*);
+   G4GDMLParser(G4GDMLReadStructure*, G4GDMLWriteStructure*);
   ~G4GDMLParser();
      //
@@ -113,5 +114,5 @@
    G4GDMLReadStructure* reader;
    G4GDMLWriteStructure* writer;
-   G4bool ucode;
+   G4bool urcode, uwcode;
 
 };
Index: trunk/source/persistency/gdml/include/G4GDMLParser.icc
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLParser.icc	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLParser.icc	(revision 1228)
@@ -26,5 +26,5 @@
 //
 // $Id: G4GDMLParser.icc,v 1.8 2009/01/22 11:02:07 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
Index: trunk/source/persistency/gdml/include/G4GDMLRead.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLRead.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLRead.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLRead.hh,v 1.27 2009/01/22 11:02:07 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLRead.hh,v 1.31 2009/05/12 15:46:43 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLRead
@@ -47,11 +47,10 @@
 #include <xercesc/dom/DOM.hpp>
 
+#include "G4Types.hh"
+
 #include "G4GDMLEvaluator.hh"
 
-#include "G4LogicalVolume.hh"
-#include "G4VisAttributes.hh"
-#include "G4PVPlacement.hh"
-
-#include <sstream>
+class G4LogicalVolume;
+class G4VPhysicalVolume;
 
 class G4GDMLErrorHandler : public xercesc::ErrorHandler
@@ -149,5 +148,5 @@
  private:
 
-   G4int inLoop;
+   G4int inLoop, loopCount;
 
 };
Index: trunk/source/persistency/gdml/include/G4GDMLReadDefine.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadDefine.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadDefine.hh	(revision 1228)
@@ -41,4 +41,6 @@
 
 #include "G4ThreeVector.hh"
+#include "G4RotationMatrix.hh"
+
 #include "G4GDMLRead.hh"
 
@@ -50,5 +52,7 @@
    G4GDMLMatrix();
    G4GDMLMatrix(size_t rows0,size_t cols0);
-   ~G4GDMLMatrix();
+   G4GDMLMatrix(const G4GDMLMatrix& rhs);
+   G4GDMLMatrix& operator=(const G4GDMLMatrix& rhs); 
+  ~G4GDMLMatrix();
 
    void Set(size_t r,size_t c,G4double a);
@@ -80,4 +84,7 @@
  protected:
 
+   G4GDMLReadDefine();
+   virtual ~G4GDMLReadDefine();
+
    G4RotationMatrix GetRotationMatrix(const G4ThreeVector&);
    void VectorRead(const xercesc::DOMElement* const,G4ThreeVector&);
@@ -90,5 +97,6 @@
    void ScaleRead(const xercesc::DOMElement* const);
    void VariableRead(const xercesc::DOMElement* const); 
-   void QuantityRead(const xercesc::DOMElement* const); 
+   void QuantityRead(const xercesc::DOMElement* const);
+   void ExpressionRead(const xercesc::DOMElement* const);
 
  protected:
Index: trunk/source/persistency/gdml/include/G4GDMLReadMaterials.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadMaterials.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadMaterials.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLReadMaterials.hh,v 1.9 2008/11/20 15:33:52 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadMaterials.hh,v 1.11 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -43,10 +43,10 @@
 #define _G4GDMLREADMATERIALS_INCLUDED_
 
-#include "G4Element.hh"
-#include "G4Isotope.hh"
-#include "G4Material.hh"
-#include "G4NistManager.hh"
+#include "G4Types.hh"
+#include "G4GDMLReadDefine.hh"
 
-#include "G4GDMLReadDefine.hh"
+class G4Element;
+class G4Isotope;
+class G4Material;
 
 class G4GDMLReadMaterials : public G4GDMLReadDefine 
@@ -62,4 +62,7 @@
 
  protected:
+
+   G4GDMLReadMaterials();
+   virtual ~G4GDMLReadMaterials();
 
    G4double AtomRead(const xercesc::DOMElement* const);
Index: trunk/source/persistency/gdml/include/G4GDMLReadParamvol.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadParamvol.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadParamvol.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLReadParamvol.hh,v 1.6 2008/11/20 15:33:52 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadParamvol.hh,v 1.8 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,11 +42,8 @@
 #define _G4GDMLREADPARAMVOL_INCLUDED_
 
-#include "G4LogicalVolume.hh"
-#include "G4PVParameterised.hh"
-#include "G4PVPlacement.hh"
-#include "G4VPhysicalVolume.hh"
+#include "G4GDMLReadSetup.hh"
+#include "G4GDMLParameterisation.hh"
 
-#include "G4GDMLParameterisation.hh"
-#include "G4GDMLReadSetup.hh"
+class G4LogicalVolume;
 
 class G4GDMLReadParamvol : public G4GDMLReadSetup
@@ -60,4 +57,7 @@
 
  protected:
+
+   G4GDMLReadParamvol();
+   virtual ~G4GDMLReadParamvol();
 
    void Box_dimensionsRead(const xercesc::DOMElement* const,
Index: trunk/source/persistency/gdml/include/G4GDMLReadSetup.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadSetup.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadSetup.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLReadSetup.hh,v 1.5 2008/11/20 15:33:52 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadSetup.hh,v 1.6 2009/03/24 15:47:33 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -58,4 +58,9 @@
  protected:
 
+   G4GDMLReadSetup();
+   virtual ~G4GDMLReadSetup();
+
+ protected:
+
    std::map<G4String,G4String> setupMap;
 };
Index: trunk/source/persistency/gdml/include/G4GDMLReadSolids.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadSolids.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadSolids.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLReadSolids.hh,v 1.12 2008/11/21 09:32:46 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadSolids.hh,v 1.15 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,39 +42,12 @@
 #define _G4GDMLREADSOLIDS_INCLUDED_
 
-#include "G4Box.hh"
-#include "G4Cons.hh"
-#include "G4Ellipsoid.hh"
-#include "G4EllipticalCone.hh"
-#include "G4EllipticalTube.hh"
+#include "G4Types.hh"
+#include "G4GDMLReadMaterials.hh"
 #include "G4ExtrudedSolid.hh"
-#include "G4Hype.hh"
-#include "G4IntersectionSolid.hh"
-#include "G4Orb.hh"
-#include "G4Para.hh"
-#include "G4Paraboloid.hh"
-#include "G4Polycone.hh"
-#include "G4Polyhedra.hh"
-#include "G4QuadrangularFacet.hh"
-#include "G4ReflectedSolid.hh"
-#include "G4Sphere.hh"
-#include "G4SolidStore.hh"
-#include "G4SubtractionSolid.hh"
-#include "G4TessellatedSolid.hh"
-#include "G4Tet.hh"
-#include "G4Torus.hh"
-#include "G4Transform3D.hh"
-#include "G4Trap.hh"
-#include "G4Trd.hh"
-#include "G4TriangularFacet.hh"
-#include "G4Tubs.hh"
-#include "G4TwistedBox.hh"
-#include "G4TwistedTrap.hh"
-#include "G4TwistedTrd.hh"
-#include "G4TwistedTubs.hh"
-#include "G4UnionSolid.hh"
-#include "G4OpticalSurface.hh"
-#include "G4SurfaceProperty.hh"
 
-#include "G4GDMLReadMaterials.hh"
+class G4VSolid;
+class G4QuadrangularFacet;
+class G4TriangularFacet;
+class G4SurfaceProperty;
 
 class G4GDMLReadSolids : public G4GDMLReadMaterials
@@ -91,4 +64,7 @@
 
  protected:
+
+   G4GDMLReadSolids();
+   virtual ~G4GDMLReadSolids();
 
    void BooleanRead(const xercesc::DOMElement* const,const BooleanOp);
@@ -122,5 +98,5 @@
    G4TwoVector TwoDimVertexRead(const xercesc::DOMElement* const,G4double);
    zplaneType ZplaneRead(const xercesc::DOMElement* const);
-   void OpticalsurfaceRead(const xercesc::DOMElement* const);
+   void OpticalSurfaceRead(const xercesc::DOMElement* const);
 };
 
Index: trunk/source/persistency/gdml/include/G4GDMLReadStructure.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLReadStructure.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLReadStructure.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLReadStructure.hh,v 1.24 2009/02/24 17:41:44 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadStructure.hh,v 1.28 2009/09/24 15:04:34 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,20 +42,12 @@
 #define _G4GDMLREADSTRUCTURE_INCLUDED_
 
-#include "G4AssemblyVolume.hh"
-#include "G4LogicalVolume.hh"
-#include "G4LogicalVolumeStore.hh"
-#include "G4PhysicalVolumeStore.hh"
-#include "G4PVDivision.hh"
-#include "G4PVPlacement.hh"
-#include "G4PVReplica.hh"
-#include "G4SolidStore.hh"
-#include "G4VPhysicalVolume.hh"
-#include "G4ReflectionFactory.hh"
-#include "G4PhysicalVolumeStore.hh"
-#include "G4LogicalSkinSurface.hh"
-#include "G4LogicalBorderSurface.hh"
-#include "G4PVDivisionFactory.hh"
+#include "G4Types.hh"
+#include "geomdefs.hh"
 
 #include "G4GDMLReadParamvol.hh"
+
+class G4AssemblyVolume;
+class G4LogicalVolume;
+class G4VPhysicalVolume;
 
 struct G4GDMLAuxPairType
@@ -67,4 +59,5 @@
 typedef std::vector<G4GDMLAuxPairType> G4GDMLAuxListType;
 typedef std::map<const G4LogicalVolume*,G4GDMLAuxListType> G4GDMLAuxMapType;
+typedef std::map<G4String, G4AssemblyVolume*> G4GDMLAssemblyMapType;
 
 class G4GDMLReadStructure : public G4GDMLReadParamvol
@@ -73,6 +66,10 @@
  public:
 
+   G4GDMLReadStructure();
+   virtual ~G4GDMLReadStructure();
+
    G4VPhysicalVolume* GetPhysvol(const G4String&) const;
    G4LogicalVolume* GetVolume(const G4String&) const;
+   G4AssemblyVolume* GetAssembly(const G4String&) const;
    G4GDMLAuxListType GetVolumeAuxiliaryInformation(const G4LogicalVolume* const);
    G4VPhysicalVolume* GetWorldVolume(const G4String&);
@@ -86,8 +83,9 @@
 
    G4GDMLAuxPairType AuxiliaryRead(const xercesc::DOMElement* const);
-   void BordersurfaceRead(const xercesc::DOMElement* const);
+   void AssemblyRead(const xercesc::DOMElement* const);
    void DivisionvolRead(const xercesc::DOMElement* const);
    G4LogicalVolume* FileRead(const xercesc::DOMElement* const);
-   void PhysvolRead(const xercesc::DOMElement* const);
+   void PhysvolRead(const xercesc::DOMElement* const,
+                    G4AssemblyVolume* assembly=0);
    void ReplicavolRead(const xercesc::DOMElement* const, G4int number);
    void ReplicaRead(const xercesc::DOMElement* const replicaElement,
@@ -95,9 +93,11 @@
    EAxis AxisRead(const xercesc::DOMElement* const axisElement);
    G4double QuantityRead(const xercesc::DOMElement* const readElement);
-   void SkinsurfaceRead(const xercesc::DOMElement* const);
+   void BorderSurfaceRead(const xercesc::DOMElement* const);
+   void SkinSurfaceRead(const xercesc::DOMElement* const);
 
  protected:
 
    G4GDMLAuxMapType auxMap;
+   G4GDMLAssemblyMapType assemblyMap;
    G4LogicalVolume *pMotherLogical;
 
Index: trunk/source/persistency/gdml/include/G4GDMLWrite.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWrite.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWrite.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWrite.hh,v 1.37 2008/08/19 15:03:17 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWrite.hh,v 1.41 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,6 +42,5 @@
 #define _G4GDMLWRITE_INCLUDED_
 
-#include <sys/stat.h>
-#include <iostream>
+#include <map>
 
 #include <xercesc/dom/DOM.hpp>
@@ -50,56 +49,80 @@
 #include <xercesc/framework/LocalFileFormatTarget.hpp>
 
-#include "G4LogicalVolume.hh"
 #include "G4Transform3D.hh"
-#include "G4PVDivision.hh"
+
+class G4LogicalVolume;
+class G4VPhysicalVolume;
 
 class G4GDMLWrite
 {
-   typedef std::map<const G4LogicalVolume*,G4Transform3D> VolumeMapType;
-   typedef std::map<const G4VPhysicalVolume*,G4String> PhysVolumeMapType;
-   typedef std::map<G4int,G4int> DepthMapType;
+  typedef std::map<const G4LogicalVolume*,G4Transform3D> VolumeMapType;
+  typedef std::map<const G4VPhysicalVolume*,G4String> PhysVolumeMapType;
+  typedef std::map<G4int,G4int> DepthMapType;
 
- public:  // without description
+  public:  // with description
 
-   G4Transform3D Write(const G4String& filename,
-                       const G4LogicalVolume* const topLog,
-                       const G4String& schemaPath,
-                       const G4int depth, G4bool storeReferences=true);
-   void AddModule(const G4VPhysicalVolume* const topVol);
-   void AddModule(const G4int depth);
-   static void SetAddPointerToName(G4bool);
+    G4Transform3D Write(const G4String& filename,
+                        const G4LogicalVolume* const topLog,
+                        const G4String& schemaPath,
+                        const G4int depth, G4bool storeReferences=true);
+      //
+      // Main method for writing GDML files.
 
- protected:
+    void AddModule(const G4VPhysicalVolume* const topVol);
+    void AddModule(const G4int depth);
+      //
+      // Split geometry structure in modules, by volume subtree or level
 
-   G4String SchemaLocation;
+    static void SetAddPointerToName(G4bool);
+      //
+      // Specify if to add or not memory addresses to IDs.
 
-   VolumeMapType& VolumeMap();
+    virtual void DefineWrite(xercesc::DOMElement*)=0;
+    virtual void MaterialsWrite(xercesc::DOMElement*)=0;
+    virtual void SolidsWrite(xercesc::DOMElement*)=0;
+    virtual void StructureWrite(xercesc::DOMElement*)=0;
+    virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume* const,
+                                             const G4int)=0;
+    virtual void SurfacesWrite()=0;
+    virtual void SetupWrite(xercesc::DOMElement*,
+                            const G4LogicalVolume* const)=0;
+      //
+      // Pure virtual methods implemented in concrete writer plugin's classes
 
-   G4String GenerateName(const G4String&,const void* const);
-   xercesc::DOMAttr* NewAttribute(const G4String&, const G4String&);
-   xercesc::DOMAttr* NewAttribute(const G4String&, const G4double&);
-   xercesc::DOMElement* NewElement(const G4String&);
-   virtual void DefineWrite(xercesc::DOMElement*)=0;
-   virtual void MaterialsWrite(xercesc::DOMElement*)=0;
-   virtual void SolidsWrite(xercesc::DOMElement*)=0;
-   virtual void StructureWrite(xercesc::DOMElement*)=0;
-   virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume* const,
-                                            const G4int)=0;
-   virtual void SetupWrite(xercesc::DOMElement*,
-                           const G4LogicalVolume* const)=0;
-   G4String Modularize(const G4VPhysicalVolume* const topvol,
-                       const G4int depth);
+    virtual void ExtensionWrite(xercesc::DOMElement*);
+    virtual void AddExtension(xercesc::DOMElement*,
+                              const G4LogicalVolume* const);
+      //
+      // To be implemented in the client code for handling extensions
+      // to the GDML schema, identified with the tag "extension".
+      // The implementation should be placed inside a user-class
+      // inheriting from G4GDMLWriteStructure and being registered
+      // as argument to G4GDMLParser.
 
- private:
+  protected:
 
-   G4bool FileExists(const G4String&) const;
-   PhysVolumeMapType& PvolumeMap();
-   DepthMapType& DepthMap();
+    G4GDMLWrite();
+    virtual ~G4GDMLWrite();
 
- private:
+    VolumeMapType& VolumeMap();
 
-   static G4bool addPointerToName;
-   xercesc::DOMDocument* doc;
-   XMLCh tempStr[100];
+    G4String GenerateName(const G4String&,const void* const);
+    xercesc::DOMAttr* NewAttribute(const G4String&, const G4String&);
+    xercesc::DOMAttr* NewAttribute(const G4String&, const G4double&);
+    xercesc::DOMElement* NewElement(const G4String&);
+    G4String Modularize(const G4VPhysicalVolume* const topvol,
+                        const G4int depth);
+
+    G4bool FileExists(const G4String&) const;
+    PhysVolumeMapType& PvolumeMap();
+    DepthMapType& DepthMap();
+
+  protected:
+
+    G4String SchemaLocation;
+    static G4bool addPointerToName;
+    xercesc::DOMDocument* doc;
+    xercesc::DOMElement* extElement;
+    XMLCh tempStr[100];
 
 };
Index: trunk/source/persistency/gdml/include/G4GDMLWriteDefine.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteDefine.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteDefine.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteDefine.hh,v 1.11 2008/07/16 15:46:33 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteDefine.hh,v 1.14 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,51 +42,55 @@
 #define _G4GDMLWRITEDEFINE_INCLUDED_
 
+#include "G4Types.hh"
+#include "G4ThreeVector.hh"
+#include "G4RotationMatrix.hh"
+
 #include "G4GDMLWrite.hh"
-#include <sstream>
 
 class G4GDMLWriteDefine : public G4GDMLWrite
 {
 
- protected:
+  public:
 
-   G4ThreeVector GetAngles(const G4RotationMatrix&);
-   void ScaleWrite(xercesc::DOMElement* element, const G4String& name,
-                    const G4ThreeVector& scl)
-     { Scale_vectorWrite(element,"scale",name,scl); }
-   void RotationWrite(xercesc::DOMElement* element, const G4String& name,
-                    const G4ThreeVector& rot)
-     { Rotation_vectorWrite(element,"rotation",name,rot); }
-   void PositionWrite(xercesc::DOMElement* element, const G4String& name,
-                    const G4ThreeVector& pos)
-     { Position_vectorWrite(element,"position",name,pos); }
-   void FirstrotationWrite(xercesc::DOMElement* element, const G4String& name,
-                    const G4ThreeVector& rot)
-     { Rotation_vectorWrite(element,"firstrotation",name,rot); }
-   void FirstpositionWrite(xercesc::DOMElement* element, const G4String& name,
-                    const G4ThreeVector& pos)
-     { Position_vectorWrite(element,"firstposition",name,pos); }
-   void AddPosition(const G4String& name,
-                    const G4ThreeVector& pos)
-     { Position_vectorWrite(defineElement,"position",name,pos); }
+    G4ThreeVector GetAngles(const G4RotationMatrix&);
+    void ScaleWrite(xercesc::DOMElement* element,
+                    const G4String& name, const G4ThreeVector& scl)
+         { Scale_vectorWrite(element,"scale",name,scl); }
+    void RotationWrite(xercesc::DOMElement* element,
+                    const G4String& name, const G4ThreeVector& rot)
+         { Rotation_vectorWrite(element,"rotation",name,rot); }
+    void PositionWrite(xercesc::DOMElement* element,
+                    const G4String& name, const G4ThreeVector& pos)
+         { Position_vectorWrite(element,"position",name,pos); }
+    void FirstrotationWrite(xercesc::DOMElement* element,
+                    const G4String& name, const G4ThreeVector& rot)
+         { Rotation_vectorWrite(element,"firstrotation",name,rot); }
+    void FirstpositionWrite(xercesc::DOMElement* element,
+                    const G4String& name, const G4ThreeVector& pos)
+         { Position_vectorWrite(element,"firstposition",name,pos); }
+    void AddPosition(const G4String& name, const G4ThreeVector& pos)
+         { Position_vectorWrite(defineElement,"position",name,pos); }
 
- protected:
+    virtual void DefineWrite(xercesc::DOMElement*);
 
-   static const G4double kRelativePrecision;
-   static const G4double kAngularPrecision;
-   static const G4double kLinearPrecision;
+  protected:
+
+    G4GDMLWriteDefine();
+    virtual ~G4GDMLWriteDefine();
+
+    void Scale_vectorWrite(xercesc::DOMElement*, const G4String&,
+                              const G4String&, const G4ThreeVector&);
+    void Rotation_vectorWrite(xercesc::DOMElement*, const G4String&,
+                              const G4String&, const G4ThreeVector&);
+    void Position_vectorWrite(xercesc::DOMElement*, const G4String&,
+                              const G4String&, const G4ThreeVector&);
+
+  protected:
+
+    static const G4double kRelativePrecision;
+    static const G4double kAngularPrecision;
+    static const G4double kLinearPrecision;
   
- private:
-
-   void Scale_vectorWrite(xercesc::DOMElement*, const G4String&,
-                             const G4String&, const G4ThreeVector&);
-   void Rotation_vectorWrite(xercesc::DOMElement*, const G4String&,
-                             const G4String&, const G4ThreeVector&);
-   void Position_vectorWrite(xercesc::DOMElement*, const G4String&,
-                             const G4String&, const G4ThreeVector&);
-   void DefineWrite(xercesc::DOMElement*);
-
- private:
-
-   xercesc::DOMElement* defineElement;
+    xercesc::DOMElement* defineElement;
 
 };
Index: trunk/source/persistency/gdml/include/G4GDMLWriteMaterials.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteMaterials.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteMaterials.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteMaterials.hh,v 1.12 2008/07/16 15:46:33 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteMaterials.hh,v 1.17 2009/04/27 07:22:36 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,14 +42,18 @@
 #define _G4GDMLWRITEMATERIALS_INCLUDED_
 
-#include "G4Element.hh"
-#include "G4Isotope.hh"
-#include "G4Material.hh"
+#include "G4Types.hh"
+#include <vector>
 
 #include "G4GDMLWriteDefine.hh"
+
+class G4Isotope;
+class G4Element;
+class G4Material;
+class G4MaterialPropertyVector;
 
 class G4GDMLWriteMaterials : public G4GDMLWriteDefine
 {
 
- protected:
+ public:
 
    void AddIsotope(const G4Isotope* const);
@@ -57,5 +61,10 @@
    void AddMaterial(const G4Material* const);
 
- private:
+   virtual void MaterialsWrite(xercesc::DOMElement*);
+
+ protected:
+
+   G4GDMLWriteMaterials();
+   virtual ~G4GDMLWriteMaterials();
 
    void AtomWrite(xercesc::DOMElement*,const G4double&);
@@ -66,7 +75,8 @@
    void ElementWrite(const G4Element* const);
    void MaterialWrite(const G4Material* const);
-   void MaterialsWrite(xercesc::DOMElement*);
-
- private:
+   void PropertyWrite(xercesc::DOMElement*, const G4Material* const);
+   void PropertyVectorWrite(const G4String&,
+                            const G4MaterialPropertyVector* const);
+ protected:
 
    std::vector<const G4Isotope*> isotopeList;
Index: trunk/source/persistency/gdml/include/G4GDMLWriteParamvol.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteParamvol.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteParamvol.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteParamvol.hh,v 1.10 2008/08/13 13:58:53 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteParamvol.hh,v 1.13 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,17 +42,32 @@
 #define _G4GDMLWRITEPARAMVOL_INCLUDED_
 
-#include "G4PVParameterised.hh"
-#include "G4VPhysicalVolume.hh"
+#include "G4GDMLWriteSetup.hh"
 
-#include "G4GDMLWriteSetup.hh"
+class G4Box;
+class G4Trd;
+class G4Trap;
+class G4Tubs;
+class G4Cons;
+class G4Sphere;
+class G4Orb;
+class G4Torus;
+class G4Para;
+class G4Hype;
+class G4VPhysicalVolume;
 
 class G4GDMLWriteParamvol : public G4GDMLWriteSetup
 {
 
+ public:
+
+   virtual void ParamvolWrite(xercesc::DOMElement*,
+                              const G4VPhysicalVolume* const);
+   virtual void ParamvolAlgorithmWrite(xercesc::DOMElement* paramvolElement,
+                              const G4VPhysicalVolume* const paramvol);
+
  protected:
 
-   void ParamvolWrite(xercesc::DOMElement*, const G4VPhysicalVolume* const);
-
- private:
+   G4GDMLWriteParamvol();
+   virtual ~G4GDMLWriteParamvol();
 
    void Box_dimensionsWrite(xercesc::DOMElement*, const G4Box* const);
@@ -68,6 +83,4 @@
    void ParametersWrite(xercesc::DOMElement*,
                         const G4VPhysicalVolume* const, const G4int&);
-   void ParamvolAlgorithmWrite(xercesc::DOMElement* paramvolElement,
-                               const G4VPhysicalVolume* const paramvol);
 
 };
Index: trunk/source/persistency/gdml/include/G4GDMLWriteSetup.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteSetup.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteSetup.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteSetup.hh,v 1.7 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteSetup.hh,v 1.9 2009/04/15 13:29:30 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -46,7 +46,13 @@
 class G4GDMLWriteSetup : public G4GDMLWriteSolids
 {
- private:
+  public:
 
-   void SetupWrite(xercesc::DOMElement*, const G4LogicalVolume* const);
+    virtual void SetupWrite(xercesc::DOMElement*, const G4LogicalVolume* const);
+
+ protected:
+
+   G4GDMLWriteSetup();
+   virtual ~G4GDMLWriteSetup();
+
 };
 
Index: trunk/source/persistency/gdml/include/G4GDMLWriteSolids.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteSolids.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteSolids.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteSolids.hh,v 1.32 2008/11/21 09:32:46 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteSolids.hh,v 1.38 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,43 +42,46 @@
 #define _G4GDMLWRITESOLIDS_INCLUDED_
 
-#include "G4BooleanSolid.hh"
-#include "G4Box.hh"
-#include "G4Cons.hh"
-#include "G4Ellipsoid.hh"
-#include "G4EllipticalCone.hh"
-#include "G4EllipticalTube.hh"
-#include "G4ExtrudedSolid.hh"
-#include "G4Hype.hh"
-#include "G4Orb.hh"
-#include "G4Para.hh"
-#include "G4Paraboloid.hh"
-#include "G4IntersectionSolid.hh"
-#include "G4Polycone.hh"
-#include "G4Polyhedra.hh"
-#include "G4ReflectedSolid.hh"
-#include "G4Sphere.hh"
-#include "G4SubtractionSolid.hh"
-#include "G4TessellatedSolid.hh"
-#include "G4Tet.hh"
-#include "G4Torus.hh"
-#include "G4Trap.hh"
-#include "G4Trd.hh"
-#include "G4Tubs.hh"
-#include "G4TwistedBox.hh"
-#include "G4TwistedTrap.hh"
-#include "G4TwistedTrd.hh"
-#include "G4TwistedTubs.hh"
-#include "G4UnionSolid.hh"
+#include "G4Types.hh"
 
 #include "G4GDMLWriteMaterials.hh"
 
+class G4BooleanSolid;
+class G4Box;
+class G4Cons;
+class G4EllipticalCone;
+class G4Ellipsoid;
+class G4EllipticalTube;
+class G4ExtrudedSolid;
+class G4Hype;
+class G4Orb;
+class G4Para;
+class G4Paraboloid;
+class G4Polycone;
+class G4Polyhedra;
+class G4Sphere;
+class G4TessellatedSolid;
+class G4Tet;
+class G4Torus;
+class G4Trap;
+class G4Trd;
+class G4Tubs;
+class G4TwistedBox;
+class G4TwistedTrap;
+class G4TwistedTrd;
+class G4TwistedTubs;
+class G4VSolid;
+class G4OpticalSurface;
+
 class G4GDMLWriteSolids : public G4GDMLWriteMaterials
 {
+  public:
 
- protected:
+   virtual void AddSolid(const G4VSolid* const);
+   virtual void SolidsWrite(xercesc::DOMElement*);
 
-   void AddSolid(const G4VSolid* const);
+  protected:
 
- private:
+   G4GDMLWriteSolids();
+   virtual ~G4GDMLWriteSolids();
 
    void BooleanWrite(xercesc::DOMElement*, const G4BooleanSolid* const);
@@ -108,10 +111,14 @@
    void ZplaneWrite(xercesc::DOMElement*, const G4double&,
                     const G4double&, const G4double&);
-   void SolidsWrite(xercesc::DOMElement*);
+   void OpticalSurfaceWrite(xercesc::DOMElement*,
+                    const G4OpticalSurface* const);
 
- private:
+  protected:
 
    std::vector<const G4VSolid*> solidList;
    xercesc::DOMElement* solidsElement;
+   static const G4int maxTransforms = 8; // Constant for limiting the number
+                                         // of displacements/reflections
+                                         // applied to a single solid
 };
 
Index: trunk/source/persistency/gdml/include/G4GDMLWriteStructure.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4GDMLWriteStructure.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4GDMLWriteStructure.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteStructure.hh,v 1.34 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteStructure.hh,v 1.39 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -42,34 +42,51 @@
 #define _G4GDMLWRITESTRUCTURE_INCLUDED_
 
-#include "G4LogicalVolumeStore.hh"
-#include "G4PhysicalVolumeStore.hh"
-#include "G4Material.hh"
-#include "G4PVDivision.hh"
-#include "G4PVReplica.hh"
-#include "G4VPhysicalVolume.hh"
-#include "G4ReflectedSolid.hh"
+#include "G4Types.hh"
 #include "G4Transform3D.hh"
 
 #include "G4GDMLWriteParamvol.hh"
 
+class G4LogicalVolume;
+class G4VPhysicalVolume;
+class G4PVDivision;
+class G4LogicalBorderSurface;
+class G4LogicalSkinSurface;
+class G4OpticalSurface;
+class G4SurfaceProperty;
+
 class G4GDMLWriteStructure : public G4GDMLWriteParamvol
 {
 
- private:
+ public:
 
-   void DivisionvolWrite(xercesc::DOMElement*,const G4PVDivision* const);
+   G4GDMLWriteStructure();
+   virtual ~G4GDMLWriteStructure();
+
+   virtual void StructureWrite(xercesc::DOMElement*);
+
+ protected:
+
+   void DivisionvolWrite(xercesc::DOMElement*, const G4PVDivision* const);
    void PhysvolWrite(xercesc::DOMElement*,const G4VPhysicalVolume* const topVol,
-                                          const G4Transform3D& transform,
-                                          const G4String& moduleName);
-   void ReplicavolWrite(xercesc::DOMElement*,const G4VPhysicalVolume* const);
-   void StructureWrite(xercesc::DOMElement*);
+                   const G4Transform3D& transform, const G4String& moduleName);
+   void ReplicavolWrite(xercesc::DOMElement*, const G4VPhysicalVolume* const);
    G4Transform3D TraverseVolumeTree(const G4LogicalVolume* const topVol,
                                     const G4int depth);
- private:
+   void SurfacesWrite();
+   void BorderSurfaceCache(const G4LogicalBorderSurface* const);
+   void SkinSurfaceCache(const G4LogicalSkinSurface* const);
+   const G4LogicalBorderSurface* GetBorderSurface(const G4VPhysicalVolume* const);
+   const G4LogicalSkinSurface* GetSkinSurface(const G4LogicalVolume* const);
+   G4bool FindOpticalSurface(const G4SurfaceProperty*);
+
+ protected:
 
    xercesc::DOMElement* structureElement;
-   static const int maxReflections = 8; // Constant for limiting the number
-                                        // of displacements/reflections applied
-                                        // to a single solid
+   std::vector<xercesc::DOMElement*> borderElementVec;
+   std::vector<xercesc::DOMElement*> skinElementVec;
+
+ private:  // cache for optical surfaces...
+
+   std::vector<const G4OpticalSurface*> opt_vec;
 };
 
Index: trunk/source/persistency/gdml/include/G4STRead.hh
===================================================================
--- trunk/source/persistency/gdml/include/G4STRead.hh	(revision 1202)
+++ trunk/source/persistency/gdml/include/G4STRead.hh	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4STRead.hh,v 1.3 2008/07/17 14:05:50 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4STRead.hh,v 1.4 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -44,15 +44,13 @@
 #define _G4STREAD_INCLUDED_
 
-#include <fstream>
 #include <vector>
 #include <map>
 
-#include "G4TessellatedSolid.hh"
-#include "G4QuadrangularFacet.hh"
-#include "G4TriangularFacet.hh"
-#include "G4LogicalVolume.hh"
-#include "G4PVPlacement.hh"
-#include "G4Material.hh"
-#include "G4Box.hh"
+#include "G4ThreeVector.hh"
+
+class G4Material;
+class G4Box;
+class G4TessellatedSolid;
+class G4LogicalVolume;
 
 class G4STRead
Index: trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLEvaluator.cc	(revision 1228)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4GDMLEvaluator.cc,v 1.22 2009/02/26 10:13:35 gcosmo Exp $
+// $Id: G4GDMLEvaluator.cc,v 1.23 2009/04/24 15:34:20 gcosmo Exp $
 // GEANT4 tag $ Name:$
 //
@@ -35,4 +35,7 @@
 
 #include <sstream>
+
+#include "globals.hh"
+
 #include "G4GDMLEvaluator.hh"
 
Index: trunk/source/persistency/gdml/src/G4GDMLParameterisation.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLParameterisation.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLParameterisation.cc	(revision 1228)
@@ -25,5 +25,5 @@
 //
 // $Id: G4GDMLParameterisation.cc,v 1.11 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLParameterisation Implementation
Index: trunk/source/persistency/gdml/src/G4GDMLParser.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLParser.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLParser.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLParser.cc,v 1.13 2008/11/20 15:33:52 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-cand-01 $
+// $Id: G4GDMLParser.cc,v 1.14 2009/04/15 13:29:30 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 //
@@ -36,5 +36,5 @@
 
 G4GDMLParser::G4GDMLParser()
-  : ucode(false)
+  : urcode(false), uwcode(false)
 {
   reader = new G4GDMLReadStructure;
@@ -43,9 +43,18 @@
 }
 
-G4GDMLParser::G4GDMLParser(G4GDMLReadStructure* ext)
-  : ucode(true)
+G4GDMLParser::G4GDMLParser(G4GDMLReadStructure* extr)
+  : urcode(true), uwcode(false)
 {
-  reader = ext;
+  reader = extr;
   writer = new G4GDMLWriteStructure;
+  xercesc::XMLPlatformUtils::Initialize();
+}
+
+G4GDMLParser::G4GDMLParser(G4GDMLReadStructure* extr,
+                           G4GDMLWriteStructure* extw)
+  : urcode(true), uwcode(true)
+{
+  reader = extr;
+  writer = extw;
   xercesc::XMLPlatformUtils::Initialize();
 }
@@ -54,5 +63,5 @@
 {
   xercesc::XMLPlatformUtils::Terminate();
-  delete writer;
-  if (!ucode) { delete reader; }
+  if (!urcode) { delete reader; }
+  if (!uwcode) { delete writer; }
 }
Index: trunk/source/persistency/gdml/src/G4GDMLRead.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLRead.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLRead.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLRead.cc,v 1.41 2009/01/22 11:02:07 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLRead.cc,v 1.47 2009/05/12 15:46:43 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLRead Implementation
@@ -33,5 +33,9 @@
 // -------------------------------------------------------------------------
 
+#include "globals.hh"
+
 #include "G4GDMLRead.hh"
+
+#include "G4UnitsTable.hh"
 #include "G4Element.hh"
 #include "G4Material.hh"
@@ -39,8 +43,7 @@
 #include "G4LogicalVolumeStore.hh"
 #include "G4PhysicalVolumeStore.hh"
-#include "G4UnitsTable.hh"
 
 G4GDMLRead::G4GDMLRead()
-  : validate(true), check(false)
+  : validate(true), check(false), inLoop(0), loopCount(0)
 {
    G4UnitDefinition::BuildUnitsTable();
@@ -68,5 +71,11 @@
    G4String nameOut(nameIn);
 
-   if (inLoop>0) { nameOut = eval.SolveBrackets(nameOut); }
+   if (inLoop>0)
+   {
+     nameOut = eval.SolveBrackets(nameOut);
+//     std::stringstream stream;
+//     stream << "0x" << loopCount;
+//     nameOut = nameOut + stream.str();
+   }
    if (strip) { StripName(nameOut); }
 
@@ -235,14 +244,15 @@
 
    inLoop++;
-   
+
    while (_var <= _to)
    {
       eval.SetVariable(var,_var);
       (this->*func)(element);
-
       _var += _step;
+      loopCount++;
    }
 
    inLoop--;
+   if (!inLoop) { loopCount = 0; }
 }
 
Index: trunk/source/persistency/gdml/src/G4GDMLReadDefine.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadDefine.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadDefine.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLReadDefine.cc,v 1.20 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadDefine.cc,v 1.24 2009/10/14 13:10:18 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLReadDefine Implementation
@@ -36,12 +36,15 @@
 
 G4GDMLMatrix::G4GDMLMatrix()
-{
-   rows = 0;
-   cols = 0;
-   m = 0;
-}
-
-G4GDMLMatrix::G4GDMLMatrix(size_t rows0,size_t cols0)
+  : m(0), rows(0), cols(0)
+{
+}
+
+G4GDMLMatrix::G4GDMLMatrix(size_t rows0, size_t cols0)
 {   
+   if ((rows<=0) || (cols<=0))
+   {
+     G4Exception("G4GDMLMatrix::G4GDMLMatrix(r,c)", "InvalidSetup",
+                 FatalException, "Zero indeces as arguments!?");
+   }
    rows = rows0;
    cols = cols0;
@@ -49,7 +52,42 @@
 }
 
+G4GDMLMatrix::G4GDMLMatrix(const G4GDMLMatrix& rhs)
+  : m(0), rows(0), cols(0)
+{
+   if (rhs.m)
+   {
+     rows = rhs.rows;
+     cols = rhs.cols;
+     m = new G4double[rows*cols];
+     for (size_t i=0; i<rows*cols; i++)  { m[i] = rhs.m[i]; }
+   }
+}
+
+G4GDMLMatrix& G4GDMLMatrix::operator=(const G4GDMLMatrix& rhs)
+{
+   // Check assignment to self
+   //
+   if (this == &rhs)  { return *this; }
+
+   // Copy data
+   //
+   rows = rhs.rows;
+   cols = rhs.cols;
+   if (rhs.m)
+   {
+     m = new G4double[rows*cols];
+     for (size_t i=0; i<rows*cols; i++)  { m[i] = rhs.m[i]; }
+   }
+   else
+   {
+     m = 0;
+   }
+
+   return *this;
+}
+
 G4GDMLMatrix::~G4GDMLMatrix()
 {
-   if (m) { delete [] m; }
+   delete [] m;
 }
 
@@ -84,4 +122,12 @@
 }
 
+G4GDMLReadDefine::G4GDMLReadDefine() : G4GDMLRead()
+{
+}
+
+G4GDMLReadDefine::~G4GDMLReadDefine()
+{
+}
+
 G4RotationMatrix
 G4GDMLReadDefine::GetRotationMatrix(const G4ThreeVector& angles)
@@ -122,4 +168,34 @@
    }
 
+   eval.DefineConstant(name,value);
+}
+
+void
+G4GDMLReadDefine::ExpressionRead(const xercesc::DOMElement* const expElement)
+{
+   G4String name  = "";
+   G4double value = 0.0;
+
+   const xercesc::DOMNamedNodeMap* const attributes
+         = expElement->getAttributes();
+   XMLSize_t attributeCount = attributes->getLength();
+
+   for (XMLSize_t attribute_index=0;
+        attribute_index<attributeCount; attribute_index++)
+   {
+      xercesc::DOMNode* node = attributes->item(attribute_index);
+
+      if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; }
+
+      const xercesc::DOMAttr* const attribute
+            = dynamic_cast<xercesc::DOMAttr*>(node);   
+      const G4String attName = Transcode(attribute->getName());
+      const G4String attValue = Transcode(attribute->getValue());
+
+      if (attName=="name")  { name = attValue; }
+   }
+
+   const G4String expValue = Transcode(expElement->getTextContent());
+   value = eval.Evaluate(expValue);
    eval.DefineConstant(name,value);
 }
@@ -328,4 +404,5 @@
 
    quantityMap[name] = value*unit;
+   eval.DefineConstant(name,value*unit);
 }
 
@@ -350,5 +427,6 @@
       if (tag=="scale")    { ScaleRead(child); }    else
       if (tag=="variable") { VariableRead(child); } else
-      if (tag=="quantity") { QuantityRead(child); }
+      if (tag=="quantity") { QuantityRead(child); } else
+      if (tag=="expression") { ExpressionRead(child); }
       else
       {
Index: trunk/source/persistency/gdml/src/G4GDMLReadMaterials.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadMaterials.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadMaterials.cc	(revision 1228)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4GDMLReadMaterials.cc,v 1.16 2008/08/22 10:00:20 gcosmo Exp $
+// $Id: G4GDMLReadMaterials.cc,v 1.20 2009/04/24 15:34:20 gcosmo Exp $
 // GEANT4 tag $ Name:$
 //
@@ -35,4 +35,17 @@
 
 #include "G4GDMLReadMaterials.hh"
+
+#include "G4Element.hh"
+#include "G4Isotope.hh"
+#include "G4Material.hh"
+#include "G4NistManager.hh"
+
+G4GDMLReadMaterials::G4GDMLReadMaterials() : G4GDMLReadDefine()
+{
+}
+
+G4GDMLReadMaterials::~G4GDMLReadMaterials()
+{
+}
 
 G4double
@@ -497,16 +510,23 @@
    if (matrix.GetRows() == 0) { return; }
 
-   G4MaterialPropertiesTable* matprop = material->GetMaterialPropertiesTable();
+   G4MaterialPropertiesTable* matprop=material->GetMaterialPropertiesTable();
    if (!matprop)
    {
-     material->SetMaterialPropertiesTable(
-               matprop = new G4MaterialPropertiesTable());
-   }
-   G4MaterialPropertyVector* propvect = new G4MaterialPropertyVector(0,0,0);
-   for (size_t i=0; i<matrix.GetRows(); i++)
-   {
-     propvect->AddElement(matrix.Get(i,0),matrix.Get(i,1));
-   }
-   matprop->AddProperty(Strip(name),propvect);
+     matprop = new G4MaterialPropertiesTable();
+     material->SetMaterialPropertiesTable(matprop);
+   }
+   if (matrix.GetCols() == 1)  // constant property assumed
+   {
+     matprop->AddConstProperty(Strip(name), matrix.Get(0,0));
+   }
+   else  // build the material properties vector
+   {
+     G4MaterialPropertyVector* propvect = new G4MaterialPropertyVector(0,0,0);
+     for (size_t i=0; i<matrix.GetRows(); i++)
+     {
+       propvect->AddElement(matrix.Get(i,0),matrix.Get(i,1));
+     }
+     matprop->AddProperty(Strip(name),propvect);
+   }
 }
 
@@ -524,5 +544,6 @@
             = dynamic_cast<xercesc::DOMElement*>(iter);
       const G4String tag = Transcode(child->getTagName());
-
+      
+      if (tag=="define")   { DefineRead(child);  }  else 
       if (tag=="element")  { ElementRead(child); }  else 
       if (tag=="isotope")  { IsotopeRead(child); }  else 
Index: trunk/source/persistency/gdml/src/G4GDMLReadParamvol.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadParamvol.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadParamvol.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLReadParamvol.cc,v 1.11 2009/01/22 11:02:07 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadParamvol.cc,v 1.13 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLReadParamvol Implementation
@@ -34,4 +34,17 @@
 
 #include "G4GDMLReadParamvol.hh"
+
+#include "G4LogicalVolume.hh"
+#include "G4PVParameterised.hh"
+#include "G4PVPlacement.hh"
+#include "G4VPhysicalVolume.hh"
+
+G4GDMLReadParamvol::G4GDMLReadParamvol() : G4GDMLReadSetup()
+{
+}
+
+G4GDMLReadParamvol::~G4GDMLReadParamvol()
+{
+}
 
 void G4GDMLReadParamvol::
Index: trunk/source/persistency/gdml/src/G4GDMLReadSetup.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadSetup.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadSetup.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLReadSetup.cc,v 1.9 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadSetup.cc,v 1.10 2009/03/24 15:47:33 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLReadSetup Implementation
@@ -34,4 +34,12 @@
 
 #include "G4GDMLReadSetup.hh"
+
+G4GDMLReadSetup::G4GDMLReadSetup() : G4GDMLReadSolids()
+{
+}
+
+G4GDMLReadSetup::~G4GDMLReadSetup()
+{
+}
 
 G4String G4GDMLReadSetup::GetSetup(const G4String& ref)
Index: trunk/source/persistency/gdml/src/G4GDMLReadSolids.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadSolids.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadSolids.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLReadSolids.cc,v 1.22 2008/11/21 09:32:46 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadSolids.cc,v 1.27 2009/12/04 13:58:51 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLReadSolids Implementation
@@ -34,4 +34,45 @@
 
 #include "G4GDMLReadSolids.hh"
+
+#include "G4Box.hh"
+#include "G4Cons.hh"
+#include "G4Ellipsoid.hh"
+#include "G4EllipticalCone.hh"
+#include "G4EllipticalTube.hh"
+#include "G4Hype.hh"
+#include "G4IntersectionSolid.hh"
+#include "G4Orb.hh"
+#include "G4Para.hh"
+#include "G4Paraboloid.hh"
+#include "G4Polycone.hh"
+#include "G4Polyhedra.hh"
+#include "G4QuadrangularFacet.hh"
+#include "G4ReflectedSolid.hh"
+#include "G4Sphere.hh"
+#include "G4SolidStore.hh"
+#include "G4SubtractionSolid.hh"
+#include "G4TessellatedSolid.hh"
+#include "G4Tet.hh"
+#include "G4Torus.hh"
+#include "G4Transform3D.hh"
+#include "G4Trap.hh"
+#include "G4Trd.hh"
+#include "G4TriangularFacet.hh"
+#include "G4Tubs.hh"
+#include "G4TwistedBox.hh"
+#include "G4TwistedTrap.hh"
+#include "G4TwistedTrd.hh"
+#include "G4TwistedTubs.hh"
+#include "G4UnionSolid.hh"
+#include "G4OpticalSurface.hh"
+#include "G4SurfaceProperty.hh"
+
+G4GDMLReadSolids::G4GDMLReadSolids() : G4GDMLReadMaterials()
+{
+}
+
+G4GDMLReadSolids::~G4GDMLReadSolids()
+{
+}
 
 void G4GDMLReadSolids::
@@ -1478,5 +1519,5 @@
 
 void G4GDMLReadSolids::
-OpticalsurfaceRead(const xercesc::DOMElement* const opticalsurfaceElement)
+OpticalSurfaceRead(const xercesc::DOMElement* const opticalsurfaceElement)
 {
    G4String name;
@@ -1514,5 +1555,7 @@
    G4SurfaceType type;   
    
-   if (smodel="unified") { model = unified; } else { model = glisur; }
+   if (smodel="unified") { model = unified; } else
+   if (smodel="glisur") { model = glisur; }
+   else { model = LUT; }
 
    if (sfinish=="polishedfrontpainted") { finish = polishedfrontpainted; } else
@@ -1520,9 +1563,36 @@
    if (sfinish=="groundfrontpainted") { finish = groundfrontpainted; } else
    if (sfinish=="groundbackpainted") { finish = groundbackpainted; } else
-   if (sfinish=="ground") { finish = ground; } else { finish = polished; }
+   if (sfinish=="ground") { finish = ground; } else
+   if (sfinish=="polished") { finish = polished; } else
+   if (sfinish=="polishedlumirrorair") { finish = polishedlumirrorair; } else
+   if (sfinish=="polishedlumirrorglue") { finish = polishedlumirrorglue; } else
+   if (sfinish=="polishedair") { finish = polishedair; } else
+   if (sfinish=="polishedteflonair") { finish = polishedteflonair; } else
+   if (sfinish=="polishedtioair") { finish = polishedtioair; } else
+   if (sfinish=="polishedtyvekair") { finish = polishedtyvekair; } else
+   if (sfinish=="polishedvm2000air") { finish = polishedvm2000air; } else
+   if (sfinish=="polishedvm2000glue") { finish = polishedvm2000glue; } else
+   if (sfinish=="etchedlumirrorair") { finish = etchedlumirrorair; } else
+   if (sfinish=="etchedlumirrorglue") { finish = etchedlumirrorglue; } else
+   if (sfinish=="etchedair") { finish = etchedair; } else
+   if (sfinish=="etchedteflonair") { finish = etchedteflonair; } else
+   if (sfinish=="etchedtioair") { finish = etchedtioair; } else
+   if (sfinish=="etchedtyvekair") { finish = etchedtyvekair; } else
+   if (sfinish=="etchedvm2000air") { finish = etchedvm2000air; } else
+   if (sfinish=="etchedvm2000glue") { finish = etchedvm2000glue; } else
+   if (sfinish=="groundlumirrorair") { finish = groundlumirrorair; } else
+   if (sfinish=="groundlumirrorglue") { finish = groundlumirrorglue; } else
+   if (sfinish=="groundair") { finish = groundair; } else
+   if (sfinish=="groundteflonair") { finish = groundteflonair; } else
+   if (sfinish=="groundtioair") { finish = groundtioair; } else
+   if (sfinish=="groundtyvekair") { finish = groundtyvekair; } else
+   if (sfinish=="groundvm2000air") { finish = groundvm2000air; }
+   else { finish = groundvm2000glue; }
 
    if (stype=="dielectric_metal") { type = dielectric_metal; } else
-   if (stype=="x_ray") { type = x_ray; } else
-   if (stype=="firsov") { type = firsov; } else { type = dielectric_dielectric; }
+   if (stype=="dielectric_dielectric") { type = dielectric_dielectric; } else
+   if (stype=="dielectric_LUT") { type = dielectric_LUT; } else
+   if (stype=="x_ray") { type = x_ray; }
+   else { type = firsov; }
 
    new G4OpticalSurface(name,model,finish,type,value);
@@ -1541,7 +1611,7 @@
             = dynamic_cast<xercesc::DOMElement*>(iter);
       const G4String tag = Transcode(child->getTagName());
-
-      if (tag=="box") { BoxRead(child); } else
-      if (tag=="cone") { ConeRead(child); } else
+      if (tag=="define") { DefineRead(child);  }  else 
+      if (tag=="box")    { BoxRead(child); } else
+      if (tag=="cone")   { ConeRead(child); } else
       if (tag=="elcone") { ElconeRead(child); } else
       if (tag=="ellipsoid") { EllipsoidRead(child); }else
@@ -1569,5 +1639,5 @@
       if (tag=="twistedtubs") { TwistedtubsRead(child); } else
       if (tag=="union") { BooleanRead(child,UNION); } else
-      if (tag=="opticalsurface") { OpticalsurfaceRead(child); } else
+      if (tag=="opticalsurface") { OpticalSurfaceRead(child); } else
       if (tag=="loop") { LoopRead(child,&G4GDMLRead::SolidsRead); }
       else
Index: trunk/source/persistency/gdml/src/G4GDMLReadStructure.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLReadStructure.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLReadStructure.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4GDMLReadStructure.cc,v 1.56 2009/02/24 17:41:44 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLReadStructure.cc,v 1.62 2009/09/24 15:04:34 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLReadStructure Implementation
@@ -35,4 +35,24 @@
 #include "G4GDMLReadStructure.hh"
 
+#include "G4LogicalVolume.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4PVPlacement.hh"
+#include "G4LogicalVolumeStore.hh"
+#include "G4PhysicalVolumeStore.hh"
+#include "G4AssemblyVolume.hh"
+#include "G4ReflectionFactory.hh"
+#include "G4PVDivisionFactory.hh"
+#include "G4LogicalBorderSurface.hh"
+#include "G4LogicalSkinSurface.hh"
+#include "G4VisAttributes.hh"
+
+G4GDMLReadStructure::G4GDMLReadStructure() : G4GDMLReadParamvol()
+{
+}
+
+G4GDMLReadStructure::~G4GDMLReadStructure()
+{
+}
+
 G4GDMLAuxPairType G4GDMLReadStructure::
 AuxiliaryRead(const xercesc::DOMElement* const auxiliaryElement)
@@ -65,5 +85,5 @@
 
 void G4GDMLReadStructure::
-BordersurfaceRead(const xercesc::DOMElement* const bordersurfaceElement)
+BorderSurfaceRead(const xercesc::DOMElement* const bordersurfaceElement)
 {
    G4String name;
@@ -255,8 +275,10 @@
 
 void G4GDMLReadStructure::
-PhysvolRead(const xercesc::DOMElement* const physvolElement)
+PhysvolRead(const xercesc::DOMElement* const physvolElement,
+            G4AssemblyVolume* pAssembly)
 {
    G4String name;
    G4LogicalVolume* logvol = 0;
+   G4AssemblyVolume* assembly = 0;
    G4ThreeVector position(0.0,0.0,0.0);
    G4ThreeVector rotation(0.0,0.0,0.0);
@@ -270,15 +292,15 @@
         attribute_index<attributeCount; attribute_index++)
    {
-      xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
-
-      if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
-        { continue; }
-
-      const xercesc::DOMAttr* const attribute
-            = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
-      const G4String attName = Transcode(attribute->getName());
-      const G4String attValue = Transcode(attribute->getValue());
-
-      if (attName=="name") { name = attValue; }
+     xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
+
+     if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
+       { continue; }
+
+     const xercesc::DOMAttr* const attribute
+           = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
+     const G4String attName = Transcode(attribute->getName());
+     const G4String attValue = Transcode(attribute->getValue());
+
+     if (attName=="name") { name = attValue; }
    }
 
@@ -286,32 +308,36 @@
         iter != 0; iter = iter->getNextSibling())
    {
-      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)  { continue; }
-
-      const xercesc::DOMElement* const child
-            = dynamic_cast<xercesc::DOMElement*>(iter);
-      const G4String tag = Transcode(child->getTagName());
-
-      if (tag=="file")
-        { logvol = FileRead(child); } else
-      if (tag=="volumeref")
-        { logvol = GetVolume(GenerateName(RefRead(child))); } else
-      if (tag=="position")
-        { VectorRead(child,position); } else
-      if (tag=="rotation")
-        { VectorRead(child,rotation); } else
-      if (tag=="scale")
-        { VectorRead(child,scale); } else
-      if (tag=="positionref")
-        { position = GetPosition(GenerateName(RefRead(child))); } else
-      if (tag=="rotationref")
-        { rotation = GetRotation(GenerateName(RefRead(child))); } else
-      if (tag=="scaleref")
+     if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)  { continue; }
+
+     const xercesc::DOMElement* const child
+           = dynamic_cast<xercesc::DOMElement*>(iter);
+     const G4String tag = Transcode(child->getTagName());
+
+     if (tag=="volumeref")
+       {
+         const G4String& child_name = GenerateName(RefRead(child));
+         assembly = GetAssembly(child_name);
+         if (!assembly) { logvol = GetVolume(child_name); }
+       }
+     else if (tag=="file")
+       { logvol = FileRead(child); }
+     else if (tag=="position")
+       { VectorRead(child,position); }
+     else if (tag=="rotation")
+       { VectorRead(child,rotation); }
+     else if (tag=="scale")
+       { VectorRead(child,scale); }
+     else if (tag=="positionref")
+       { position = GetPosition(GenerateName(RefRead(child))); }
+     else if (tag=="rotationref")
+        { rotation = GetRotation(GenerateName(RefRead(child))); }
+     else if (tag=="scaleref")
         { scale = GetScale(GenerateName(RefRead(child))); }
-      else
-      {
-        G4String error_msg = "Unknown tag in physvol: " + tag;
-        G4Exception("G4GDMLReadStructure::PhysvolRead()", "ReadError",
-                    FatalException, error_msg);
-      }
+     else
+        {
+          G4String error_msg = "Unknown tag in physvol: " + tag;
+          G4Exception("G4GDMLReadStructure::PhysvolRead()", "ReadError",
+                      FatalException, error_msg);
+        }
    }
 
@@ -319,10 +345,24 @@
    transform = transform*G4Scale3D(scale.x(),scale.y(),scale.z());
 
-   G4String pv_name = logvol->GetName() + "_PV";
-   G4PhysicalVolumesPair pair = G4ReflectionFactory::Instance()
-     ->Place(transform,pv_name,logvol,pMotherLogical,false,0,check);
-
-   if (pair.first != 0) { GeneratePhysvolName(name,pair.first); }
-   if (pair.second != 0) { GeneratePhysvolName(name,pair.second); }
+   if (pAssembly)   // Fill assembly structure
+   {
+     pAssembly->AddPlacedVolume(logvol, transform);
+   }
+   else             // Generate physical volume tree or do assembly imprint
+   {
+     if (assembly)
+     {
+       assembly->MakeImprint(pMotherLogical, transform, 0, check);
+     }
+     else
+     {
+       G4String pv_name = logvol->GetName() + "_PV";
+       G4PhysicalVolumesPair pair = G4ReflectionFactory::Instance()
+         ->Place(transform,pv_name,logvol,pMotherLogical,false,0,check);
+
+       if (pair.first != 0) { GeneratePhysvolName(name,pair.first); }
+       if (pair.second != 0) { GeneratePhysvolName(name,pair.second); }
+     }
+   }
 }
 
@@ -510,5 +550,35 @@
 
 void G4GDMLReadStructure::
-SkinsurfaceRead(const xercesc::DOMElement* const skinsurfaceElement)
+AssemblyRead(const xercesc::DOMElement* const assemblyElement)
+{
+   XMLCh *name_attr = xercesc::XMLString::transcode("name");
+   const G4String name = Transcode(assemblyElement->getAttribute(name_attr));
+   xercesc::XMLString::release(&name_attr);
+
+   G4AssemblyVolume* pAssembly = new G4AssemblyVolume();
+   assemblyMap.insert(std::make_pair(GenerateName(name), pAssembly));
+
+   for (xercesc::DOMNode* iter = assemblyElement->getFirstChild();
+        iter != 0; iter = iter->getNextSibling())
+   {
+      if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
+      const xercesc::DOMElement* const child
+            = dynamic_cast<xercesc::DOMElement*>(iter);
+      const G4String tag = Transcode(child->getTagName());
+
+      if (tag=="physvol")
+      {
+        PhysvolRead(child, pAssembly);
+      }
+      else
+      {
+        G4cout << "Unsupported GDML tag '" << tag
+               << "' for Geant4 assembly structure !" << G4endl;
+      }
+   }
+}
+
+void G4GDMLReadStructure::
+SkinSurfaceRead(const xercesc::DOMElement* const skinsurfaceElement)
 {
    G4String name;
@@ -643,7 +713,8 @@
       const G4String tag = Transcode(child->getTagName());
 
-      if (tag=="bordersurface") { BordersurfaceRead(child); } else
-      if (tag=="skinsurface") { SkinsurfaceRead(child); } else
+      if (tag=="bordersurface") { BorderSurfaceRead(child); } else
+      if (tag=="skinsurface") { SkinSurfaceRead(child); } else
       if (tag=="volume") { VolumeRead(child); } else
+      if (tag=="assembly") { AssemblyRead(child); } else
       if (tag=="loop") { LoopRead(child,&G4GDMLRead::StructureRead); }
       else
@@ -688,8 +759,17 @@
 }
 
+G4AssemblyVolume* G4GDMLReadStructure::
+GetAssembly(const G4String& ref) const
+{
+   G4GDMLAssemblyMapType::const_iterator pos = assemblyMap.find(ref);
+   if (pos != assemblyMap.end()) { return pos->second; }
+   return 0;
+}
+
 G4GDMLAuxListType G4GDMLReadStructure::
 GetVolumeAuxiliaryInformation(const G4LogicalVolume* const logvol)
 {
-   if (auxMap.find(logvol) != auxMap.end()) { return auxMap[logvol]; }
+   G4GDMLAuxMapType::const_iterator pos = auxMap.find(logvol);
+   if (pos != auxMap.end()) { return pos->second; }
    else { return G4GDMLAuxListType(); }
 }
Index: trunk/source/persistency/gdml/src/G4GDMLWrite.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWrite.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWrite.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWrite.cc,v 1.50 2008/11/13 17:00:50 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWrite.cc,v 1.55 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWrite Implementation
@@ -34,7 +34,22 @@
 // --------------------------------------------------------------------
 
+#include <sys/stat.h>
+#include <iostream>
+
 #include "G4GDMLWrite.hh"
 
+#include "G4LogicalVolume.hh"
+#include "G4Transform3D.hh"
+#include "G4PVDivision.hh"
+
 G4bool G4GDMLWrite::addPointerToName = true;
+
+G4GDMLWrite::G4GDMLWrite() : extElement(0)
+{
+}
+
+G4GDMLWrite::~G4GDMLWrite()
+{
+}
 
 G4bool G4GDMLWrite::FileExists(const G4String& fname) const
@@ -62,9 +77,27 @@
 }
 
+void G4GDMLWrite::AddExtension(xercesc::DOMElement*,
+                               const G4LogicalVolume* const)
+{
+   // Empty implementation. To be overwritten by user for specific extensions
+   // related to attributes associated to volumes
+}
+
+void G4GDMLWrite::ExtensionWrite(xercesc::DOMElement*)
+{
+   // Empty implementation. To be overwritten by user for specific extensions
+}
+
 G4String G4GDMLWrite::GenerateName(const G4String& name, const void* const ptr)
 {
+   G4String nameOut;
    std::stringstream stream; stream << name;
-   if (addPointerToName) { stream << ptr; }
-   return G4String(stream.str());
+   if (addPointerToName) { stream << ptr; };
+
+   nameOut=G4String(stream.str());
+   if(nameOut.contains(' '))
+   nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),' '),nameOut.end());
+
+   return nameOut;
 }
 
@@ -153,4 +186,5 @@
                           SchemaLocation));
 
+   ExtensionWrite(gdml);
    DefineWrite(gdml);
    MaterialsWrite(gdml);
@@ -161,4 +195,5 @@
    G4Transform3D R = TraverseVolumeTree(logvol,depth);
 
+   SurfacesWrite();
    xercesc::XMLFormatTarget *myFormTarget =
      new xercesc::LocalFileFormatTarget(fname.c_str());
Index: trunk/source/persistency/gdml/src/G4GDMLWriteDefine.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteDefine.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteDefine.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteDefine.cc,v 1.18 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteDefine.cc,v 1.19 2009/03/24 15:47:33 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWriteDefine Implementation
@@ -39,4 +39,12 @@
 const G4double G4GDMLWriteDefine::kAngularPrecision = DBL_EPSILON;
 const G4double G4GDMLWriteDefine::kLinearPrecision = DBL_EPSILON;
+
+G4GDMLWriteDefine::G4GDMLWriteDefine() : G4GDMLWrite()
+{
+}
+
+G4GDMLWriteDefine::~G4GDMLWriteDefine()
+{
+}
 
 G4ThreeVector G4GDMLWriteDefine::GetAngles(const G4RotationMatrix& mat)
Index: trunk/source/persistency/gdml/src/G4GDMLWriteMaterials.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteMaterials.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteMaterials.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteMaterials.cc,v 1.20 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteMaterials.cc,v 1.24 2009/04/27 07:22:36 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWriteMaterials Implementation
@@ -34,5 +34,20 @@
 // --------------------------------------------------------------------
 
+#include <sstream>
 #include "G4GDMLWriteMaterials.hh"
+
+#include "G4Element.hh"
+#include "G4Isotope.hh"
+#include "G4Material.hh"
+
+G4GDMLWriteMaterials::
+G4GDMLWriteMaterials() : G4GDMLWriteDefine()
+{
+}
+
+G4GDMLWriteMaterials::
+~G4GDMLWriteMaterials()
+{
+}
 
 void G4GDMLWriteMaterials::
@@ -134,4 +149,11 @@
    materialElement->setAttributeNode(NewAttribute("state",state_str));
 
+   // Write any property attached to the material...
+   //
+   if (materialPtr->GetMaterialPropertiesTable())
+   {
+     PropertyWrite(materialElement, materialPtr);
+   }
+
    if (materialPtr->GetTemperature() != STP_Temperature)
      { TWrite(materialElement,materialPtr->GetTemperature()); }
@@ -165,6 +187,59 @@
    }
 
+   // Append the material AFTER all the possible components are appended!
+   //
    materialsElement->appendChild(materialElement);
-     // Append the material AFTER all the possible components are appended!
+}
+
+void G4GDMLWriteMaterials::PropertyVectorWrite(const G4String& key,
+                           const G4MaterialPropertyVector* const pvec)
+{
+   xercesc::DOMElement* matrixElement = NewElement("matrix");
+   matrixElement->setAttributeNode(NewAttribute("name", key));
+   matrixElement->setAttributeNode(NewAttribute("coldim", "2"));
+   std::ostringstream pvalues;
+   for (G4int i=0; i<pvec->Entries(); i++)
+   {
+     G4MPVEntry cval = pvec->GetEntry(i);
+     if (i!=0)  { pvalues << " "; }
+     pvalues << cval.GetPhotonEnergy() << " " << cval.GetProperty();
+   }
+   matrixElement->setAttributeNode(NewAttribute("values", pvalues.str()));
+
+   defineElement->appendChild(matrixElement);
+}
+
+void G4GDMLWriteMaterials::PropertyWrite(xercesc::DOMElement* matElement,
+                                         const G4Material* const mat)
+{
+   xercesc::DOMElement* propElement;
+   G4MaterialPropertiesTable* ptable = mat->GetMaterialPropertiesTable();
+   const std::map< G4String, G4MaterialPropertyVector*,
+                 std::less<G4String> >* pmap = ptable->GetPropertiesMap();
+   const std::map< G4String, G4double,
+                 std::less<G4String> >* cmap = ptable->GetPropertiesCMap();
+   std::map< G4String, G4MaterialPropertyVector*,
+                 std::less<G4String> >::const_iterator mpos;
+   std::map< G4String, G4double,
+                 std::less<G4String> >::const_iterator cpos;
+   for (mpos=pmap->begin(); mpos!=pmap->end(); mpos++)
+   {
+      propElement = NewElement("property");
+      propElement->setAttributeNode(NewAttribute("name", mpos->first));
+      propElement->setAttributeNode(NewAttribute("ref", mpos->first));
+      PropertyVectorWrite(mpos->first, mpos->second);
+      matElement->appendChild(propElement);
+   }
+   for (cpos=cmap->begin(); cpos!=cmap->end(); cpos++)
+   {
+      propElement = NewElement("property");
+      propElement->setAttributeNode(NewAttribute("name", cpos->first));
+      propElement->setAttributeNode(NewAttribute("ref", cpos->first));
+      xercesc::DOMElement* constElement = NewElement("constant");
+      constElement->setAttributeNode(NewAttribute("name", cpos->first));
+      constElement->setAttributeNode(NewAttribute("value", cpos->second));
+      defineElement->appendChild(constElement);
+      matElement->appendChild(propElement);
+   }
 }
 
Index: trunk/source/persistency/gdml/src/G4GDMLWriteParamvol.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteParamvol.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteParamvol.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteParamvol.cc,v 1.23 2008/08/20 08:56:32 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteParamvol.cc,v 1.25 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLParamVol Implementation
@@ -35,5 +35,29 @@
 
 #include "G4GDMLWriteParamvol.hh"
-#include <sstream>
+
+#include "G4Box.hh"
+#include "G4Trd.hh"
+#include "G4Trap.hh"
+#include "G4Tubs.hh"
+#include "G4Cons.hh"
+#include "G4Sphere.hh"
+#include "G4Orb.hh"
+#include "G4Torus.hh"
+#include "G4Para.hh"
+#include "G4Hype.hh"
+#include "G4LogicalVolume.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4PVParameterised.hh"
+#include "G4VPVParameterisation.hh"
+
+G4GDMLWriteParamvol::
+G4GDMLWriteParamvol() : G4GDMLWriteSetup()
+{
+}
+
+G4GDMLWriteParamvol::
+~G4GDMLWriteParamvol()
+{
+}
 
 void G4GDMLWriteParamvol::
Index: trunk/source/persistency/gdml/src/G4GDMLWriteSetup.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteSetup.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteSetup.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteSetup.cc,v 1.11 2008/07/16 15:46:34 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteSetup.cc,v 1.13 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWriteSetup Implementation
@@ -35,4 +35,14 @@
 
 #include "G4GDMLWriteSetup.hh"
+
+#include "G4LogicalVolume.hh"
+
+G4GDMLWriteSetup::G4GDMLWriteSetup() : G4GDMLWriteSolids()
+{
+}
+
+G4GDMLWriteSetup::~G4GDMLWriteSetup()
+{
+}
 
 void G4GDMLWriteSetup::SetupWrite(xercesc::DOMElement* gdmlElement,
Index: trunk/source/persistency/gdml/src/G4GDMLWriteSolids.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteSolids.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteSolids.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteSolids.cc,v 1.59 2008/11/21 09:32:46 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteSolids.cc,v 1.65 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWriteSolids Implementation
@@ -36,8 +36,51 @@
 #include "G4GDMLWriteSolids.hh"
 
+#include "G4BooleanSolid.hh"
+#include "G4Box.hh"
+#include "G4Cons.hh"
+#include "G4Ellipsoid.hh"
+#include "G4EllipticalCone.hh"
+#include "G4EllipticalTube.hh"
+#include "G4ExtrudedSolid.hh"
+#include "G4Hype.hh"
+#include "G4Orb.hh"
+#include "G4Para.hh"
+#include "G4Paraboloid.hh"
+#include "G4IntersectionSolid.hh"
+#include "G4Polycone.hh"
+#include "G4Polyhedra.hh"
+#include "G4ReflectedSolid.hh"
+#include "G4Sphere.hh"
+#include "G4SubtractionSolid.hh"
+#include "G4TessellatedSolid.hh"
+#include "G4Tet.hh"
+#include "G4Torus.hh"
+#include "G4Trap.hh"
+#include "G4Trd.hh"
+#include "G4Tubs.hh"
+#include "G4TwistedBox.hh"
+#include "G4TwistedTrap.hh"
+#include "G4TwistedTrd.hh"
+#include "G4TwistedTubs.hh"
+#include "G4UnionSolid.hh"
+#include "G4OpticalSurface.hh"
+#include "G4SurfaceProperty.hh"
+
+G4GDMLWriteSolids::
+G4GDMLWriteSolids() : G4GDMLWriteMaterials()
+{
+}
+
+G4GDMLWriteSolids::
+~G4GDMLWriteSolids()
+{
+}
+
 void G4GDMLWriteSolids::
 BooleanWrite(xercesc::DOMElement* solidsElement,
              const G4BooleanSolid* const boolean)
 {
+   G4int displaced=0;
+
    G4String tag("undefined");
    if (dynamic_cast<const G4IntersectionSolid*>(boolean))
@@ -53,18 +96,52 @@
    G4ThreeVector firstpos,firstrot,pos,rot;
 
-   if (const G4DisplacedSolid* disp
-       = dynamic_cast<const G4DisplacedSolid*>(firstPtr))
-   {   
-      firstpos = disp->GetObjectTranslation();
-      firstrot = GetAngles(disp->GetObjectRotation());
-      firstPtr = disp->GetConstituentMovedSolid();
-   }
-
-   if (const G4DisplacedSolid* disp
-       = dynamic_cast<const G4DisplacedSolid*>(secondPtr))
-   {
-      pos = disp->GetObjectTranslation();
-      rot = GetAngles(disp->GetObjectRotation());
-      secondPtr = disp->GetConstituentMovedSolid();
+   // Solve possible displacement of referenced solids!
+   //
+   while (true)
+   {
+      if ( displaced>8 )
+      {
+        G4String ErrorMessage = "The referenced solid '"
+                              + firstPtr->GetName() +
+                              + "in the Boolean shape '" +
+                              + boolean->GetName() +
+                              + "' was displaced too many times!";
+        G4Exception("G4GDMLWriteSolids::BooleanWrite()",
+                    "InvalidSetup", FatalException, ErrorMessage);
+      }
+
+      if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(firstPtr))
+      {
+         firstpos += disp->GetObjectTranslation();
+         firstrot += firstrot + GetAngles(disp->GetObjectRotation());
+         firstPtr = disp->GetConstituentMovedSolid();
+         displaced++;
+         continue;
+      }
+      break;
+   }
+   displaced = 0;
+   while (true)
+   {
+      if ( displaced>maxTransforms )
+      {
+        G4String ErrorMessage = "The referenced solid '"
+                              + secondPtr->GetName() +
+                              + "in the Boolean shape '" +
+                              + boolean->GetName() +
+                              + "' was displaced too many times!";
+        G4Exception("G4GDMLWriteSolids::BooleanWrite()",
+                    "InvalidSetup", FatalException, ErrorMessage);
+      }
+
+      if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(secondPtr))
+      {
+         pos += disp->GetObjectTranslation();
+         rot += GetAngles(disp->GetObjectRotation());
+         secondPtr = disp->GetConstituentMovedSolid();
+         displaced++;
+         continue;
+      }
+      break;
    }
 
@@ -727,4 +804,21 @@
    zplaneElement->setAttributeNode(NewAttribute("rmax",rmax/mm));
    element->appendChild(zplaneElement);
+}
+
+void G4GDMLWriteSolids::
+OpticalSurfaceWrite(xercesc::DOMElement* solidsElement,
+                    const G4OpticalSurface* const surf)
+{
+   xercesc::DOMElement* optElement = NewElement("opticalsurface");
+   G4OpticalSurfaceModel smodel = surf->GetModel();
+   G4double sval = (smodel==glisur) ? surf->GetPolish() : surf->GetSigmaAlpha();
+
+   optElement->setAttributeNode(NewAttribute("name", surf->GetName()));
+   optElement->setAttributeNode(NewAttribute("model", smodel));
+   optElement->setAttributeNode(NewAttribute("finish", surf->GetFinish()));
+   optElement->setAttributeNode(NewAttribute("type", surf->GetType()));
+   optElement->setAttributeNode(NewAttribute("value", sval));
+
+   solidsElement->appendChild(optElement);
 }
 
@@ -822,6 +916,7 @@
    else
    {
-     G4String error_msg = "Unknown solid: " + solidPtr->GetName();
-     G4Exception("G4GDMLWriteSolids::AddSolid()", "ReadError",
+     G4String error_msg = "Unknown solid: " + solidPtr->GetName()
+                        + "; Type: " + solidPtr->GetEntityType();
+     G4Exception("G4GDMLWriteSolids::AddSolid()", "WriteError",
                  FatalException, error_msg);
    }
Index: trunk/source/persistency/gdml/src/G4GDMLWriteStructure.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4GDMLWriteStructure.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4GDMLWriteStructure.cc	(revision 1228)
@@ -25,6 +25,6 @@
 //
 //
-// $Id: G4GDMLWriteStructure.cc,v 1.74 2008/11/13 16:48:19 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4GDMLWriteStructure.cc,v 1.80 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4GDMLWriteStructure Implementation
@@ -35,4 +35,24 @@
 
 #include "G4GDMLWriteStructure.hh"
+
+#include "G4Material.hh"
+#include "G4ReflectedSolid.hh"
+#include "G4DisplacedSolid.hh"
+#include "G4LogicalVolumeStore.hh"
+#include "G4PhysicalVolumeStore.hh"
+#include "G4PVDivision.hh"
+#include "G4PVReplica.hh"
+#include "G4OpticalSurface.hh"
+#include "G4LogicalSkinSurface.hh"
+#include "G4LogicalBorderSurface.hh"
+
+G4GDMLWriteStructure::G4GDMLWriteStructure()
+  : G4GDMLWriteParamvol()
+{
+}
+
+G4GDMLWriteStructure::~G4GDMLWriteStructure()
+{
+}
 
 void
@@ -50,9 +70,9 @@
    G4String unitString("mm");
    G4String axisString("kUndefined");
-   if (axis==kXAxis) { axisString = "kXAxis"; } else
-   if (axis==kYAxis) { axisString = "kYAxis"; } else
-   if (axis==kZAxis) { axisString = "kZAxis"; } else
-   if (axis==kRho) { axisString = "kRho";     } else
-   if (axis==kPhi) { axisString = "kPhi"; unitString = "degree"; }
+   if (axis==kXAxis) { axisString = "kXAxis"; }
+   else if (axis==kYAxis) { axisString = "kYAxis"; }
+   else if (axis==kZAxis) { axisString = "kZAxis"; }
+   else if (axis==kRho)   { axisString = "kRho";     }
+   else if (axis==kPhi)   { axisString = "kPhi"; unitString = "degree"; }
 
    const G4String name
@@ -154,14 +174,18 @@
    volumerefElement->setAttributeNode(NewAttribute("ref",volumeref));
    replicavolElement->appendChild(volumerefElement);
-
    xercesc::DOMElement* replicateElement = NewElement("replicate_along_axis");
    replicavolElement->appendChild(replicateElement);
 
    xercesc::DOMElement* dirElement = NewElement("direction");
-   if(axis==kXAxis)dirElement->setAttributeNode(NewAttribute("x","1"));
-   if(axis==kYAxis)dirElement->setAttributeNode(NewAttribute("y","1"));
-   if(axis==kZAxis)dirElement->setAttributeNode(NewAttribute("z","1"));
-   if(axis==kRho)dirElement->setAttributeNode(NewAttribute("rho","1"));
-   if(axis==kPhi)dirElement->setAttributeNode(NewAttribute("phi","1"));
+   if(axis==kXAxis)
+     { dirElement->setAttributeNode(NewAttribute("x","1")); }
+   else if(axis==kYAxis)
+     { dirElement->setAttributeNode(NewAttribute("y","1")); }
+   else if(axis==kZAxis)
+     { dirElement->setAttributeNode(NewAttribute("z","1")); }
+   else if(axis==kRho)
+     { dirElement->setAttributeNode(NewAttribute("rho","1")); }
+   else if(axis==kPhi)
+     { dirElement->setAttributeNode(NewAttribute("phi","1")); }
    replicateElement->appendChild(dirElement);
 
@@ -179,4 +203,135 @@
 }
 
+void G4GDMLWriteStructure::
+BorderSurfaceCache(const G4LogicalBorderSurface* const bsurf)
+{
+   if (!bsurf)  { return; }
+
+   const G4SurfaceProperty* psurf = bsurf->GetSurfaceProperty();
+
+   // Generate the new element for border-surface
+   //
+   xercesc::DOMElement* borderElement = NewElement("bordersurface");
+   borderElement->setAttributeNode(NewAttribute("name", bsurf->GetName()));
+   borderElement->setAttributeNode(NewAttribute("surfaceproperty",
+                                                psurf->GetName()));
+
+   const G4String volumeref1 = GenerateName(bsurf->GetVolume1()->GetName(),
+                                            bsurf->GetVolume1());
+   const G4String volumeref2 = GenerateName(bsurf->GetVolume2()->GetName(),
+                                            bsurf->GetVolume2());
+   xercesc::DOMElement* volumerefElement1 = NewElement("physvolref");
+   xercesc::DOMElement* volumerefElement2 = NewElement("physvolref");
+   volumerefElement1->setAttributeNode(NewAttribute("ref",volumeref1));
+   volumerefElement2->setAttributeNode(NewAttribute("ref",volumeref2));
+   borderElement->appendChild(volumerefElement1);
+   borderElement->appendChild(volumerefElement2);
+
+   if (FindOpticalSurface(psurf))
+   {
+     OpticalSurfaceWrite(solidsElement,
+                         dynamic_cast<const G4OpticalSurface*>(psurf));
+   }
+
+   borderElementVec.push_back(borderElement);
+}
+
+void G4GDMLWriteStructure::
+SkinSurfaceCache(const G4LogicalSkinSurface* const ssurf)
+{
+   if (!ssurf)  { return; }
+
+   const G4SurfaceProperty* psurf = ssurf->GetSurfaceProperty();
+
+   // Generate the new element for border-surface
+   //
+   xercesc::DOMElement* skinElement = NewElement("skinsurface");
+   skinElement->setAttributeNode(NewAttribute("name", ssurf->GetName()));
+   skinElement->setAttributeNode(NewAttribute("surfaceproperty",
+                                              psurf->GetName()));
+
+   const G4String volumeref = GenerateName(ssurf->GetLogicalVolume()->GetName(),
+                                           ssurf->GetLogicalVolume());
+   xercesc::DOMElement* volumerefElement = NewElement("volumeref");
+   volumerefElement->setAttributeNode(NewAttribute("ref",volumeref));
+   skinElement->appendChild(volumerefElement);
+
+   if (FindOpticalSurface(psurf))
+   {
+     OpticalSurfaceWrite(solidsElement,
+                         dynamic_cast<const G4OpticalSurface*>(psurf));
+   }
+
+   skinElementVec.push_back(skinElement);
+}
+
+G4bool G4GDMLWriteStructure::FindOpticalSurface(const G4SurfaceProperty* psurf)
+{
+   const G4OpticalSurface* osurf = dynamic_cast<const G4OpticalSurface*>(psurf);
+   std::vector<const G4OpticalSurface*>::const_iterator pos;
+   pos = std::find(opt_vec.begin(), opt_vec.end(), osurf);
+   if (pos != opt_vec.end()) { return false; }  // item already created!
+
+   opt_vec.push_back(osurf);              // cache it for future reference
+   return true;
+}
+
+const G4LogicalSkinSurface*
+G4GDMLWriteStructure::GetSkinSurface(const G4LogicalVolume* const lvol)
+{
+  G4LogicalSkinSurface* surf = 0;
+  G4int nsurf = G4LogicalSkinSurface::GetNumberOfSkinSurfaces();
+  if (nsurf)
+  {
+    const G4LogicalSkinSurfaceTable* stable =
+          G4LogicalSkinSurface::GetSurfaceTable();
+    std::vector<G4LogicalSkinSurface*>::const_iterator pos;
+    for (pos = stable->begin(); pos != stable->end(); pos++)
+    {
+      if (lvol == (*pos)->GetLogicalVolume())
+      {
+        surf = *pos; break;
+      }
+    }
+  }
+  return surf;
+}
+
+const G4LogicalBorderSurface*
+G4GDMLWriteStructure::GetBorderSurface(const G4VPhysicalVolume* const pvol)
+{
+  G4LogicalBorderSurface* surf = 0;
+  G4int nsurf = G4LogicalBorderSurface::GetNumberOfBorderSurfaces();
+  if (nsurf)
+  {
+    const G4LogicalBorderSurfaceTable* btable =
+          G4LogicalBorderSurface::GetSurfaceTable();
+    std::vector<G4LogicalBorderSurface*>::const_iterator pos;
+    for (pos = btable->begin(); pos != btable->end(); pos++)
+    {
+      if (pvol == (*pos)->GetVolume1())  // just the first in the couple 
+      {                                  // is enough
+        surf = *pos; break;
+      }
+    }
+  }
+  return surf;
+}
+
+void G4GDMLWriteStructure::SurfacesWrite()
+{
+   G4cout << "G4GDML: Writing surfaces..." << G4endl;
+
+   std::vector<xercesc::DOMElement*>::const_iterator pos;
+   for (pos = skinElementVec.begin(); pos != skinElementVec.end(); pos++)
+   {
+     structureElement->appendChild(*pos);
+   }
+   for (pos = borderElementVec.begin(); pos != borderElementVec.end(); pos++)
+   {
+     structureElement->appendChild(*pos);
+   }
+}
+
 void G4GDMLWriteStructure::StructureWrite(xercesc::DOMElement* gdmlElement)
 {
@@ -197,9 +352,9 @@
    G4VSolid* solidPtr = volumePtr->GetSolid();
    G4Transform3D R,invR;
-   G4int reflected = 0;
+   G4int trans=0;
 
    while (true) // Solve possible displacement/reflection
    {            // of the referenced solid!
-      if (reflected>maxReflections)
+      if (trans>maxTransforms)
       {
         G4String ErrorMessage = "Referenced solid in volume '"
@@ -214,5 +369,5 @@
          R = R*refl->GetTransform3D();
          solidPtr = refl->GetConstituentMovedSolid();
-         reflected++;
+         trans++;
          continue;
       }
@@ -223,5 +378,5 @@
                              disp->GetObjectTranslation());
          solidPtr = disp->GetConstituentMovedSolid();
-         reflected++;
+         trans++;
          continue;
       }
@@ -230,6 +385,7 @@
    }
 
-   if (reflected>0) { invR = R.inverse(); }
-     // Only compute the inverse when necessary!
+   // Only compute the inverse when necessary!
+   //
+   if (trans>0) { invR = R.inverse(); }
 
    const G4String name
@@ -318,4 +474,5 @@
          PhysvolWrite(volumeElement,physvol,invR*P*daughterR,ModuleName);
       }
+      BorderSurfaceCache(GetBorderSurface(physvol));
    }
 
@@ -326,8 +483,13 @@
    VolumeMap()[volumePtr] = R;
 
-   G4GDMLWriteMaterials::AddMaterial(volumePtr->GetMaterial());
+   AddExtension(volumeElement, volumePtr);
+     // Add any possible user defined extension attached to a volume
+
+   AddMaterial(volumePtr->GetMaterial());
      // Add the involved materials and solids!
 
-   G4GDMLWriteSolids::AddSolid(solidPtr);
+   AddSolid(solidPtr);
+
+   SkinSurfaceCache(GetSkinSurface(volumePtr));
 
    return R;
Index: trunk/source/persistency/gdml/src/G4STRead.cc
===================================================================
--- trunk/source/persistency/gdml/src/G4STRead.cc	(revision 1202)
+++ trunk/source/persistency/gdml/src/G4STRead.cc	(revision 1228)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4STRead.cc,v 1.3 2008/07/17 14:05:50 gcosmo Exp $
-// GEANT4 tag $Name: geant4-09-02-ref-02 $
+// $Id: G4STRead.cc,v 1.4 2009/04/24 15:34:20 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-03 $
 //
 // class G4STRead Implementation
@@ -33,5 +33,15 @@
 // -------------------------------------------------------------------------
 
+#include <fstream>
+
 #include "G4STRead.hh"
+
+#include "G4Material.hh"
+#include "G4Box.hh"
+#include "G4QuadrangularFacet.hh"
+#include "G4TriangularFacet.hh"
+#include "G4TessellatedSolid.hh"
+#include "G4LogicalVolume.hh"
+#include "G4PVPlacement.hh"
 
 void G4STRead::TessellatedRead(const std::string& line)
