make_dune_gdml.pl
Go to the documentation of this file.
1 #!/usr/bin/perl
2 #
3 # Build a description of the detectors from gdml fragments
4 #
5 
6 #
7 # List all the files that need to be glomed together
8 #
9 
10 
11 @defFile = qw(global-defs.gdml dune/dune-defs.gdml);
12 @gdmlFile = qw(dune/dune-rotations.gdml
13  materials.gdml
14  dune/dune-vertplane.gdml
15  dune/dune-plane.gdml
16  dune/dune-tpc.gdml
17  dune/dune-cryostat.gdml
18  dune/dune-enclosure.gdml
19  dune/dune-world.gdml
20  );
21 
22 
23 #
24 # Build the table of variable replacements
25 #
26 
27 $ikey=0;
28 for ($ifile=0; $ifile<@defFile; ++$ifile) {
29 
30  $DEFINES = @defFile[$ifile];
31  open(DEFINES) or die("Could not open file $DEFINES");
32  foreach $line (<DEFINES>) {
33  chomp($line);
34  ($key,$name,$value) = split(' ',$line);
35  if ($key eq "<constant") {
36  $name =~ tr/ //d;
37  $value =~ tr/ //d;
38  ($tmp,$name) = split('=',$name);
39  ($tmp,$value) = split('=',$value);
40  ($tmp,$name, $tmp) = split('"',$name);
41  ($tmp,$value,$tmp) = split('"',$value);
42  $value =~ tr/\"//d;
43  @defNAME[$ikey] = $name;
44  @defVALUE[$ikey] = "($value)";
45  print @defName[$ikey];
46  ++$ikey;
47  }
48  }
49  close(DEFINES);
50 }
51 
52 #
53 # Open each file in turn, read line-by-line making variable
54 # substitutions, and write to standard output
55 #
56 
57 print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
58 print "<gdml xmlns:gdml=\"http://cern.ch/2001/Schemas/GDML\"\n";
59 print " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
60 print " xsi:noNamespaceSchemaLocation=\"GDMLSchema/gdml.xsd\">\n";
61 for ($i=0; $i<@gdmlFile; ++$i)
62 {
63  $FILE = @gdmlFile[$i];
64  open(FILE) or die("Could not open file @gdmlFile[$i] for read.");
65  foreach $line (<FILE>) {
66  #
67  # Work backwards to keep dependency order correct
68  #
69  for ($j=@defNAME-1; $j>=0; --$j) {
70  $line =~ s/@defNAME[$j]/@defVALUE[$j]/g;
71  }
72  print $line;
73  }
74  close(FILE);
75 }
76 print "\n<setup name=\"Default\" version=\"1.0\">\n";
77 print " <world ref=\"volWorld\" />\n";
78 print "</setup>\n\n";
79 print "</gdml>\n";