File indexing completed on 2024-11-25 02:29:04
0001
0002
0003 from builtins import range
0004 import re,os,sys
0005 import optparse
0006
0007
0008 try:
0009 import json
0010 except ImportError:
0011 import simplejson as json
0012
0013 from mutypes import *
0014
0015 import pprint
0016 pp = pprint.PrettyPrinter(indent=2)
0017
0018
0019 NAME_TO_TITLE = {
0020 "map_DTvsphi_dxdz.png" : "map of dxdz residual vs phi",
0021 "map_DTvsphi_dydz.png" : "map of dydz residual vs phi",
0022 "map_DTvsphi_x.png" : "map of x residual vs phi",
0023 "map_DTvsphi_y.png" : "map of y residual vs phi",
0024 "map_DTvsz_dxdz.png" : "map of dxdz residual vs z",
0025 "map_DTvsz_dydz.png" : "map of dydz residual vs z",
0026 "map_DTvsz_x.png" : "map of x residual vs z",
0027 "map_DTvsz_y.png" : "map of y residual vs z",
0028 "map_DTvsz_all_dxdz.png" : "map of dxdz residual vs z",
0029 "map_DTvsz_all_dydz.png" : "map of dydz residual vs z",
0030 "map_DTvsz_all_x.png" : "map of x residual vs z",
0031 "map_DTvsz_all_y.png" : "map of y residual vs z",
0032 "map_CSCvsphi_dxdz.png" : "map of d(rphi)/dz residual vs phi",
0033 "map_CSCvsphi_x.png" : "map of rphi residual vs phi",
0034 "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r",
0035 "map_CSCvsr_x.png" : "map of rphi residual vs r",
0036 "segdifphi_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals vs phi",
0037 "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi",
0038 "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi",
0039 "segdifphi_dt2_resid.png" : "segdiff in y residuals vs phi",
0040 "segdifphi_dt2_slope.png" : "segdiff in dydz residuals vs phi",
0041 "segdif_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals",
0042 "segdif_dt13_resid.png" : "segdiff in x residuals",
0043 "segdif_dt13_slope.png" : "segdiff in dxdz residuals",
0044 "segdif_dt2_resid.png" : "segdiff in y residuals",
0045 "segdif_dt2_slope.png" : "segdiff in dydz residuals",
0046 "segdifphi_csc_resid.png" : "segdiff in rphi residuals vs phi",
0047 "segdifphi_csc_slope.png" : "segdiff in d(rphi)/dz residuals vs phi",
0048 "segdif_csc_resid.png" : "segdiff in rphi residuals",
0049 "segdif_csc_slope.png" : "segdiff in d(rphi)/dz residuals",
0050 "dt_bellcurves.png" : "residuals distributions",
0051 "dt_polynomials.png" : "residuals relations to misalignments",
0052 "csc_bellcurves.png" : "residuals distributions",
0053 "csc_polynomials.png" : "residuals relations to misalignments",
0054 'dt_curvature_deltax.png' : 'Delta x residuals vs. curvature',
0055 'dt_curvature_deltadxdz.png' : 'Delta dxdz residuals vs. curvature',
0056 "medians.png" : "medians distribution"
0057 }
0058
0059
0060
0061
0062
0063
0064 usage='%prog [options]\n'+\
0065 'Creates a tree_items.js data file for a browsable JavaScript tree using results produced '+\
0066 'by running alignment_validation_plots.py.'
0067
0068 parser=optparse.OptionParser(usage)
0069
0070 parser.add_option("-i", "--inputDir",
0071 help="[REQUIRED] input directory: should contain 'iter1', 'iterN' and 'common' directories filled with alignment_validation_plots.py. The resulting tree_items.js is also dumped into this directory",
0072 type="string",
0073 default='',
0074 dest="inputDir")
0075
0076 parser.add_option("-v", "--verbose",
0077 help="Degree of debug info verbosity",
0078 type="int",
0079 default=0,
0080 dest="verbose")
0081
0082 options,args=parser.parse_args()
0083
0084 if options.inputDir=='':
0085 print("\nOne or more of REQUIRED options is missing!\n")
0086 parser.print_help()
0087
0088 sys.exit()
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102 os.chdir(options.inputDir)
0103
0104
0105
0106
0107
0108 iteration1 = "iter1"
0109 iterationN = "iterN"
0110 comdir = "common/"
0111
0112
0113
0114
0115 iteration_directory = iterationN
0116
0117
0118 def parseDir(dir,label,it1="",itN=""):
0119 """it1 and itN are the first and the last iterations' directory names
0120 dir is some directory with the results from for the LAST
0121 iteration, so it must contain a itN substring
0122 label is a label for tree's folder for this directory"""
0123 if len(itN)>0 and dir.find(itN)==-1:
0124 print("directory ", dir, "has no ", itN, " in it!!")
0125 return ["problem!!!",""]
0126 res = [label,dir]
0127 files = sorted(os.listdir(dir))
0128 for f in files:
0129 if re.match(".+\.png", f):
0130 if len(it1)>0 and len(itN)>0:
0131 lnN = [itN,dir+'/'+f]
0132 dir1 = dir.replace(itN,it1)
0133 if not os.access(dir1+'/'+f,os.F_OK):
0134 print("WARNING: no ",dir1+'/'+f," file found!!!")
0135 ln1 = [it1,dir1+'/'+f]
0136 ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN]
0137 res.append(ln)
0138 else:
0139 ln = [NAME_TO_TITLE[f],dir+'/'+f]
0140
0141 res.append(ln)
0142
0143 return res
0144
0145
0146 mytree = []
0147 tree_level1 = ['test','']
0148
0149
0150 dt_basedir = iteration_directory+'/MB/'
0151 tree_level2 = parseDir(dt_basedir,"MB",iteration1,iterationN)
0152 for wheel in DT_TYPES:
0153 dd = dt_basedir + wheel[0]
0154 print(dd)
0155 tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN)
0156 for station in wheel[2]:
0157 dd = dt_basedir + wheel[0]+'/'+station[1]
0158 print(dd)
0159 tree_level4 = parseDir(dd,station[0],iteration1,iterationN)
0160 for sector in range(1,station[2]+1):
0161 ssector = "%02d" % sector
0162 dd = dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
0163
0164 tree_level5 = parseDir(dd,"%s/%d" % (station[0],sector),iteration1,iterationN)
0165 if len(tree_level5) == 2: tree_level5.append(['none',''])
0166 tree_level4.append(tree_level5)
0167 if len(tree_level4) == 2: tree_level4.append(['none',''])
0168 tree_level3.append(tree_level4)
0169 if len(tree_level3) == 2: tree_level3.append(['none',''])
0170 tree_level2.append(tree_level3)
0171 if len(tree_level2) == 2: tree_level2.append(['none',''])
0172 tree_level1.append(tree_level2)
0173
0174
0175 csc_basedir = iteration_directory+'/'
0176 for endcap in CSC_TYPES:
0177 dd = csc_basedir+endcap[0]
0178 print(dd)
0179 tree_level2 = parseDir(dd,endcap[0],iteration1,iterationN)
0180 for station in endcap[2]:
0181 dd = csc_basedir+endcap[0]+'/'+station[1]
0182 print(dd)
0183 tree_level3 = parseDir(dd,station[0],iteration1,iterationN)
0184 for ring in station[2]:
0185 dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
0186 print(dd)
0187 tree_level4 = parseDir(dd,"%s/%s" % (station[0],ring[1]),iteration1,iterationN)
0188 for chamber in range(1,ring[2]+1):
0189 schamber = "%02d" % chamber
0190 dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
0191
0192 tree_level5 = parseDir(dd,"%s/%s/%d" % (station[0],ring[1],chamber),iteration1,iterationN)
0193 tree_level4.append(tree_level5)
0194 if len(tree_level4) == 2: tree_level4.append(['none',''])
0195 tree_level3.append(tree_level4)
0196 if len(tree_level3) == 2: tree_level3.append(['none',''])
0197 tree_level2.append(tree_level3)
0198 if len(tree_level2) == 2: tree_level2.append(['none',''])
0199 tree_level1.append(tree_level2)
0200
0201
0202 common_basedir = comdir
0203 tree_level2 = parseDir(common_basedir,"All")
0204 tree_level1.append(tree_level2)
0205
0206
0207 mytree.append(tree_level1)
0208 print(" ")
0209
0210 print()
0211
0212 ff = open("tree_items.js",mode="w")
0213 print("var TREE_ITEMS = ", file=ff)
0214 json.dump(mytree,ff)
0215 ff.close()