From e00ca011e710172cd5e9842745b542a67b04d0d1 Mon Sep 17 00:00:00 2001
From: Eoin Clerkin <e.clerkin@gsi.de>
Date: Fri, 22 Sep 2023 11:47:32 +0200
Subject: [PATCH] Provide GDML to ROOT macro

---
 .../cad2root/make_TGeoVolumeAssembly.C        | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 macro/geometry/cad2root/make_TGeoVolumeAssembly.C

diff --git a/macro/geometry/cad2root/make_TGeoVolumeAssembly.C b/macro/geometry/cad2root/make_TGeoVolumeAssembly.C
new file mode 100644
index 0000000000..acc3dd924c
--- /dev/null
+++ b/macro/geometry/cad2root/make_TGeoVolumeAssembly.C
@@ -0,0 +1,57 @@
+/* Copyright (C) 2023 Facility for AntiProton and Ion Research in Europe, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Eoin Clerkin [committer] */
+
+/* Macro converts a gdml script to root binary */
+
+#include "TROOT.h"
+#include "TSystem.h"
+
+#include "TGeoVolume.h"
+//#include "TGeoVolumeAssembly.h"
+
+#include "TGeoManager.h"
+#include "TGeoSystemOfUnits.h"
+#include "TGeoTube.h"
+
+#include "TFile.h"
+#include "TGeoCompositeShape.h"
+#include "TGeoMaterial.h"
+#include "TGeoMatrix.h"
+#include "TGeoMedium.h"
+#include "TGeoPgon.h"
+#include "TList.h"
+#include "TROOT.h"
+#include "TString.h"
+#include "TSystem.h"
+
+#include <iostream>
+#include <sstream>
+
+#include <strings.h>
+
+void make_TGeoVolumeAssembly(const char* gdml_file){
+
+char vol_file[200]; 
+char basename[200]; 
+
+strcpy(basename,gdml_file);
+char* c = strstr(basename,".gdml");
+*c='\0';
+
+strcpy(vol_file,gdml_file);
+strcpy(strstr(vol_file,".gdml"),".root");
+
+TGeoManager::Import(gdml_file);
+
+TGeoVolumeAssembly* top = (TGeoVolumeAssembly *) gGeoManager->GetTopVolume();
+
+TFile* output_file = TFile::Open(vol_file,"RECREATE");
+
+top->Write();
+
+output_file->Close();
+
+printf("Successfully completed. \n");
+
+}
-- 
GitLab