00001
00002
00003 import re,os,sys
00004 import optparse
00005
00006
00007 try:
00008 import json
00009 except ImportError:
00010 import simplejson as json
00011
00012 from mutypes import *
00013
00014 import pprint
00015 pp = pprint.PrettyPrinter(indent=2)
00016
00017
00018 NAME_TO_TITLE = {
00019 "map_DTvsphi_dxdz.png" : "map of dxdz residual vs phi",
00020 "map_DTvsphi_dydz.png" : "map of dydz residual vs phi",
00021 "map_DTvsphi_x.png" : "map of x residual vs phi",
00022 "map_DTvsphi_y.png" : "map of y residual vs phi",
00023 "map_DTvsz_dxdz.png" : "map of dxdz residual vs z",
00024 "map_DTvsz_dydz.png" : "map of dydz residual vs z",
00025 "map_DTvsz_x.png" : "map of x residual vs z",
00026 "map_DTvsz_y.png" : "map of y residual vs z",
00027 "map_CSCvsphi_dxdz.png" : "map of d(rphi)/dz residual vs phi",
00028 "map_CSCvsphi_x.png" : "map of rphi residual vs phi",
00029 "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r",
00030 "map_CSCvsr_x.png" : "map of rphi residual vs r",
00031 "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi",
00032 "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi",
00033 "segdifphi_dt2_resid.png" : "segdiff in y residuals vs phi",
00034 "segdifphi_dt2_slope.png" : "segdiff in dydz residuals vs phi",
00035 "segdif_dt13_resid.png" : "segdiff in x residuals",
00036 "segdif_dt13_slope.png" : "segdiff in dxdz residuals",
00037 "segdif_dt2_resid.png" : "segdiff in y residuals",
00038 "segdif_dt2_slope.png" : "segdiff in dydz residuals",
00039 "segdifphi_csc_resid.png" : "segdiff in rphi residuals vs phi",
00040 "segdifphi_csc_slope.png" : "segdiff in d(rphi)/dz residuals vs phi",
00041 "segdif_csc_resid.png" : "segdiff in rphi residuals",
00042 "segdif_csc_slope.png" : "segdiff in d(rphi)/dz residuals",
00043 "dt_bellcurves.png" : "residuals distributions",
00044 "dt_polynomials.png" : "residuals relations to misalignments",
00045 "csc_bellcurves.png" : "residuals distributions",
00046 "csc_polynomials.png" : "residuals relations to misalignments",
00047 'dt_curvature_deltax.png' : 'Delta x residuals vs. curvature',
00048 'dt_curvature_deltadxdz.png' : 'Delta dxdz residuals vs. curvature',
00049 "medians.png" : "medians distribution"
00050 }
00051
00052
00053
00054
00055
00056
00057 usage='%prog [options]\n'+\
00058 'Creates a tree_items.js data file for a browsable JavaScript tree using results produced '+\
00059 'by running alignment_validation_plots.py.'
00060
00061 parser=optparse.OptionParser(usage)
00062
00063 parser.add_option("-i", "--inputDir",
00064 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",
00065 type="string",
00066 default='',
00067 dest="inputDir")
00068
00069 parser.add_option("-v", "--verbose",
00070 help="Degree of debug info verbosity",
00071 type="int",
00072 default=0,
00073 dest="verbose")
00074
00075 options,args=parser.parse_args()
00076
00077 if options.inputDir=='':
00078 print "\nOne or more of REQUIRED options is missing!\n"
00079 parser.print_help()
00080
00081 sys.exit()
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 os.chdir(options.inputDir)
00096
00097
00098
00099
00100
00101 iteration1 = "iter1"
00102 iterationN = "iterN"
00103 comdir = "common/"
00104
00105
00106
00107
00108 iteration_directory = iterationN
00109
00110
00111 def parseDir(dir,label,it1="",itN=""):
00112 """it1 and itN are the first and the last iterations' directory names
00113 dir is some directory with the results from for the LAST
00114 iteration, so it must contain a itN substring
00115 label is a label for tree's folder for this directory"""
00116 if len(itN)>0 and dir.find(itN)==-1:
00117 print "directory ", dir, "has no ", itN, " in it!!"
00118 return ["problem!!!",""]
00119 res = [label,dir]
00120 files = os.listdir(dir)
00121 files.sort()
00122 for f in files:
00123 if re.match(".+\.png", f):
00124 if len(it1)>0 and len(itN)>0:
00125 lnN = [itN,dir+'/'+f]
00126 dir1 = dir.replace(itN,it1)
00127 if not os.access(dir1+'/'+f,os.F_OK):
00128 print "WARNING: no ",dir1+'/'+f," file found!!!"
00129 ln1 = [it1,dir1+'/'+f]
00130 ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN]
00131 res.append(ln)
00132 else:
00133 ln = [NAME_TO_TITLE[f],dir+'/'+f]
00134
00135 res.append(ln)
00136
00137 return res
00138
00139
00140 mytree = []
00141 tree_level1 = ['test','']
00142
00143
00144 dt_basedir = iteration_directory+'/MB/'
00145 tree_level2 = parseDir(dt_basedir,"MB",iteration1,iterationN)
00146 for wheel in DT_TYPES:
00147 dd = dt_basedir + wheel[0]
00148 print dd
00149 tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN)
00150 for station in wheel[2]:
00151 dd = dt_basedir + wheel[0]+'/'+station[1]
00152 print dd
00153 tree_level4 = parseDir(dd,station[0],iteration1,iterationN)
00154 for sector in range(1,station[2]+1):
00155 ssector = "%02d" % sector
00156 dd = dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
00157
00158 tree_level5 = parseDir(dd,"%s/%d" % (station[0],sector),iteration1,iterationN)
00159 if len(tree_level5) == 2: tree_level5.append(['none',''])
00160 tree_level4.append(tree_level5)
00161 if len(tree_level4) == 2: tree_level4.append(['none',''])
00162 tree_level3.append(tree_level4)
00163 if len(tree_level3) == 2: tree_level3.append(['none',''])
00164 tree_level2.append(tree_level3)
00165 if len(tree_level2) == 2: tree_level2.append(['none',''])
00166 tree_level1.append(tree_level2)
00167
00168
00169 csc_basedir = iteration_directory+'/'
00170 for endcap in CSC_TYPES:
00171 dd = csc_basedir+endcap[0]
00172 print dd
00173 tree_level2 = parseDir(dd,endcap[0],iteration1,iterationN)
00174 for station in endcap[2]:
00175 dd = csc_basedir+endcap[0]+'/'+station[1]
00176 print dd
00177 tree_level3 = parseDir(dd,station[0],iteration1,iterationN)
00178 for ring in station[2]:
00179 dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
00180 print dd
00181 tree_level4 = parseDir(dd,"%s/%s" % (station[0],ring[1]),iteration1,iterationN)
00182 for chamber in range(1,ring[2]+1):
00183 schamber = "%02d" % chamber
00184 dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
00185
00186 tree_level5 = parseDir(dd,"%s/%s/%d" % (station[0],ring[1],chamber),iteration1,iterationN)
00187 tree_level4.append(tree_level5)
00188 if len(tree_level4) == 2: tree_level4.append(['none',''])
00189 tree_level3.append(tree_level4)
00190 if len(tree_level3) == 2: tree_level3.append(['none',''])
00191 tree_level2.append(tree_level3)
00192 if len(tree_level2) == 2: tree_level2.append(['none',''])
00193 tree_level1.append(tree_level2)
00194
00195
00196 common_basedir = comdir
00197 tree_level2 = parseDir(common_basedir,"All")
00198 tree_level1.append(tree_level2)
00199
00200
00201 mytree.append(tree_level1)
00202 print " "
00203
00204 print
00205
00206 ff = open("tree_items.js",mode="w")
00207 print >>ff, "var TREE_ITEMS = "
00208 json.dump(mytree,ff)
00209 ff.close()