~chris-rogers/maus/emr_mc_digitization

« back to all changes in this revision

Viewing changes to src/common_py/geometry/GDMLtoMAUSModule.py

  • Committer: Chris Rogers
  • Date: 2014-04-16 11:48:45 UTC
  • mfrom: (707 merge)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: chris.rogers@stfc.ac.uk-20140416114845-h3u3q7pdcxkxvovs
Update to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
CONFIGXSL = os.environ["MAUS_ROOT_DIR"] + \
23
23
        "/src/common_py/geometry/xsltScripts/ParentFileTranlsation.xsl"
24
 
ROTATEDXSL = os.environ["MAUS_ROOT_DIR"] + \
25
 
        "/src/common_py/geometry/xsltScripts/RotatedGeometryFileTranslation.xsl"
 
24
#  TRACKERXSL = os.environ["MAUS_ROOT_DIR"] + \
 
25
#         "/src/common_py/geometry/xsltScripts/TrackerTranslation.xsl"
26
26
MM_XSL = os.environ["MAUS_ROOT_DIR"] + \
27
27
                         "/src/common_py/geometry/xsltScripts/MMTranslation.xsl"
 
28
DET_GDML = ['TOF0.gdml', 'TOF1.gdml', 'TOF2.gdml', \
 
29
            'Tracker0.gdml', 'Tracker1.gdml',\
 
30
            'KL.gdml', 'Ckov1.gdml', 'Ckov2.gdml', 'Disk_LiH.gdml',\
 
31
            'Wedge_LiH_90.gdml', 'Wedge_LiH_45.gdml', 'LH2.gdml']
28
32
 
29
33
class GDMLtomaus(): #pylint: disable = R0903
30
34
    """
51
55
        self.config_file = None
52
56
        self.material_file = None
53
57
        self.material_file_path = None
 
58
        self.tracker_file = None
54
59
        file_list = []
55
60
        self.step_files = file_list
56
61
        if os.path.exists(path) == False:
58
63
        else:
59
64
            self.path = path
60
65
        gdmls = os.listdir(self.path)
 
66
        # print gdmls
61
67
        for fname in gdmls:
62
68
            if fname.find('materials') >= 0:
63
 
                found_file = self.path + '/' + fname
 
69
                found_file = os.path.join(self.path, fname)
64
70
                self.material_file = found_file
65
71
                self.material_file_path = os.path.abspath(self.material_file)
66
 
            if fname == 'fastradModel.gdml' or fname == 'FastradModel.gdml':
67
 
                found_file = self.path + '/' + fname
 
72
            if fname == 'fastradModel.gdml' or \
 
73
                   fname == 'FastradModel.gdml' or \
 
74
                   fname == 'Step_IV.gdml':
 
75
                found_file = os.path.join(self.path, fname)
68
76
                self.config_file = found_file
69
77
            if fname.find('Maus_Information') >= 0:
70
 
                found_file = self.path + '/' + fname
 
78
                found_file = os.path.join(self.path, fname)
71
79
                self.maus_information_file = found_file
 
80
            # if fname == 'Tracker.gdml':
 
81
            #     found_file = os.path.join(self.path, fname)
 
82
            #     self.tracker_file = found_file
72
83
            if fname.find('materials') < 0 \
73
84
               and fname.find('fastrad') < 0 \
74
85
               and fname.find('Fastrad') < 0 \
75
86
               and fname.find('Maus_Information') < 0 \
76
87
               and fname.find('Beamline') < 0 \
77
 
               and fname[-5:] == '.gdml':
78
 
                stepfile = self.path + '/' + fname
 
88
               and fname[-5:] == '.gdml' \
 
89
               and fname.find('Step_IV') < 0:
 
90
            
 
91
                stepfile = os.path.join(self.path, fname)
79
92
                self.step_files.append(stepfile)
80
93
 
81
94
    def convert_to_maus(self, output):
94
107
            raise IOError('Output path doesnt exist '+str(output))
95
108
        else:
96
109
            outputfile1 = os.path.join(output, "ParentGeometryFile.dat")
97
 
            outputfile2 = os.path.join(output, "RotatedGeometryFile.dat")
 
110
            # outputfile2 = os.path.join(output, "TrackerGeometryFile.dat")
 
111
            # outputfile3 = os.path.join(output, "RotatedGeometryFile.dat")
98
112
            config_file = CADImport(xmlin1 = str(self.config_file), \
99
113
                           xsl = str(CONFIGXSL), output = str(outputfile1))
100
114
            config_file.parse_xslt()
101
 
            rotated_file = CADImport(xmlin1 = str(self.config_file), \
102
 
                           xsl = str(ROTATEDXSL), output = str(outputfile2))
103
 
            rotated_file.parse_xslt()
 
115
            # tracker_file = CADImport(xmlin1 = str(self.config_file), \
 
116
            #                xsl = str(TRACKERXSL), output = str(outputfile2))
 
117
            # tracker_file.parse_xslt()
 
118
            # rotated_file = CADImport(xmlin1 = str(self.config_file), \
 
119
            #         xsl = str(ROTATEDXSL), output = str(outputfile3))
 
120
            # rotated_file.parse_xslt()
 
121
            
104
122
            print "Configuration File Converted"
105
123
            length = len(self.step_files)
106
124
            for num in range(0, length):
113
131
                outputfile = output + '/' + file_name[:-4] + 'dat'
114
132
                step_file = CADImport(xmlin1 = str(self.step_files[num]), \
115
133
                                    xsl = str(MM_XSL), output = str(outputfile))
116
 
                step_file.parse_xslt()
 
134
                direct_translation = 0
 
135
                for det_file in DET_GDML:
 
136
                    if file_name == det_file:
 
137
                        direct_translation = 1
 
138
                if direct_translation:
 
139
                    step_file.translate_gdml()
 
140
                else:
 
141
                    step_file.parse_xslt()
117
142
                step_file = None
118
143
                os.remove(self.step_files[num])
119
144
                print "Converting " + str(num+1) + \
120
 
                                        " of " + str(length) + " Geometry Files"
 
145
                      " of " + str(length)
 
146
                      
121
147
            os.remove(self.config_file)
122
148
            print "Files saved to " + str(output)
123
149