CMS 3D CMS Logo

createTree.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 from __future__ import print_function
4 import re,os,sys
5 import optparse
6 
7 # python 2.6 has json modue; <2.6 could use simplejson
8 try:
9  import json
10 except ImportError:
11  import simplejson as json
12 
13 from mutypes import *
14 
15 import pprint
16 pp = pprint.PrettyPrinter(indent=2)
17 
18 
19 NAME_TO_TITLE = {
20 "map_DTvsphi_dxdz.png" : "map of dxdz residual vs phi",
21 "map_DTvsphi_dydz.png" : "map of dydz residual vs phi",
22 "map_DTvsphi_x.png" : "map of x residual vs phi",
23 "map_DTvsphi_y.png" : "map of y residual vs phi",
24 "map_DTvsz_dxdz.png" : "map of dxdz residual vs z",
25 "map_DTvsz_dydz.png" : "map of dydz residual vs z",
26 "map_DTvsz_x.png" : "map of x residual vs z",
27 "map_DTvsz_y.png" : "map of y residual vs z",
28 "map_DTvsz_all_dxdz.png" : "map of dxdz residual vs z",
29 "map_DTvsz_all_dydz.png" : "map of dydz residual vs z",
30 "map_DTvsz_all_x.png" : "map of x residual vs z",
31 "map_DTvsz_all_y.png" : "map of y residual vs z",
32 "map_CSCvsphi_dxdz.png" : "map of d(rphi)/dz residual vs phi",
33 "map_CSCvsphi_x.png" : "map of rphi residual vs phi",
34 "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r",
35 "map_CSCvsr_x.png" : "map of rphi residual vs r",
36 "segdifphi_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals vs phi",
37 "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi",
38 "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi",
39 "segdifphi_dt2_resid.png" : "segdiff in y residuals vs phi",
40 "segdifphi_dt2_slope.png" : "segdiff in dydz residuals vs phi",
41 "segdif_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals",
42 "segdif_dt13_resid.png" : "segdiff in x residuals",
43 "segdif_dt13_slope.png" : "segdiff in dxdz residuals",
44 "segdif_dt2_resid.png" : "segdiff in y residuals",
45 "segdif_dt2_slope.png" : "segdiff in dydz residuals",
46 "segdifphi_csc_resid.png" : "segdiff in rphi residuals vs phi",
47 "segdifphi_csc_slope.png" : "segdiff in d(rphi)/dz residuals vs phi",
48 "segdif_csc_resid.png" : "segdiff in rphi residuals",
49 "segdif_csc_slope.png" : "segdiff in d(rphi)/dz residuals",
50 "dt_bellcurves.png" : "residuals distributions",
51 "dt_polynomials.png" : "residuals relations to misalignments",
52 "csc_bellcurves.png" : "residuals distributions",
53 "csc_polynomials.png" : "residuals relations to misalignments",
54 'dt_curvature_deltax.png' : 'Delta x residuals vs. curvature',
55 'dt_curvature_deltadxdz.png' : 'Delta dxdz residuals vs. curvature',
56 "medians.png" : "medians distribution"
57 }
58 ######################################################
59 # functions definitions
60 
61 ######################################################
62 # To parse commandline args
63 
64 usage='%prog [options]\n'+\
65  'Creates a tree_items.js data file for a browsable JavaScript tree using results produced '+\
66  'by running alignment_validation_plots.py.'
67 
68 parser=optparse.OptionParser(usage)
69 
70 parser.add_option("-i", "--inputDir",
71  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",
72  type="string",
73  default='',
74  dest="inputDir")
75 
76 parser.add_option("-v", "--verbose",
77  help="Degree of debug info verbosity",
78  type="int",
79  default=0,
80  dest="verbose")
81 
82 options,args=parser.parse_args()
83 
84 if options.inputDir=='':
85  print("\nOne or more of REQUIRED options is missing!\n")
86  parser.print_help()
87  # See \n"+sys.argv[0]+" --help"
88  sys.exit()
89 
90 ######################################################
91 
92 
93 
94 ############################################################################################################
95 ############################################################################################################
96 # main script
97 
98 # create directory structure
99 
100 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
101 #os.chdir(basedir)
102 os.chdir(options.inputDir)
103 
104 #iteration1 = "iteration_01"
105 #iteration3 = "iteration_03"
106 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
107 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
108 iteration1 = "iter1"
109 iterationN = "iterN"
110 comdir = "common/"
111 
112 ######################################################
113 # open root and py result files
114 
115 iteration_directory = iterationN
116 
117 
118 def parseDir(dir,label,it1="",itN=""):
119  """it1 and itN are the first and the last iterations' directory names
120  dir is some directory with the results from for the LAST
121  iteration, so it must contain a itN substring
122  label is a label for tree's folder for this directory"""
123  if len(itN)>0 and dir.find(itN)==-1:
124  print("directory ", dir, "has no ", itN, " in it!!")
125  return ["problem!!!",""]
126  res = [label,dir]
127  files = sorted(os.listdir(dir))
128  for f in files:
129  if re.match(".+\.png", f):
130  if len(it1)>0 and len(itN)>0:
131  lnN = [itN,dir+'/'+f]
132  dir1 = dir.replace(itN,it1)
133  if not os.access(dir1+'/'+f,os.F_OK):
134  print("WARNING: no ",dir1+'/'+f," file found!!!")
135  ln1 = [it1,dir1+'/'+f]
136  ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN]
137  res.append(ln)
138  else:
139  ln = [NAME_TO_TITLE[f],dir+'/'+f]
140  #print ln
141  res.append(ln)
142  #pp.pprint(res)
143  return res
144 
145 
146 mytree = []
147 tree_level1 = ['test','']
148 
149 # DT
150 dt_basedir = iteration_directory+'/MB/'
151 tree_level2 = parseDir(dt_basedir,"MB",iteration1,iterationN)
152 for wheel in DT_TYPES:
153  dd = dt_basedir + wheel[0]
154  print(dd)
155  tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN)
156  for station in wheel[2]:
157  dd = dt_basedir + wheel[0]+'/'+station[1]
158  print(dd)
159  tree_level4 = parseDir(dd,station[0],iteration1,iterationN)
160  for sector in range(1,station[2]+1):
161  ssector = "%02d" % sector
162  dd = dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
163  #print dd
164  tree_level5 = parseDir(dd,"%s/%d" % (station[0],sector),iteration1,iterationN)
165  if len(tree_level5) == 2: tree_level5.append(['none',''])
166  tree_level4.append(tree_level5)
167  if len(tree_level4) == 2: tree_level4.append(['none',''])
168  tree_level3.append(tree_level4)
169  if len(tree_level3) == 2: tree_level3.append(['none',''])
170  tree_level2.append(tree_level3)
171 if len(tree_level2) == 2: tree_level2.append(['none',''])
172 tree_level1.append(tree_level2)
173 
174 # CSC
175 csc_basedir = iteration_directory+'/'
176 for endcap in CSC_TYPES:
177  dd = csc_basedir+endcap[0]
178  print(dd)
179  tree_level2 = parseDir(dd,endcap[0],iteration1,iterationN)
180  for station in endcap[2]:
181  dd = csc_basedir+endcap[0]+'/'+station[1]
182  print(dd)
183  tree_level3 = parseDir(dd,station[0],iteration1,iterationN)
184  for ring in station[2]:
185  dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
186  print(dd)
187  tree_level4 = parseDir(dd,"%s/%s" % (station[0],ring[1]),iteration1,iterationN)
188  for chamber in range(1,ring[2]+1):
189  schamber = "%02d" % chamber
190  dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
191  #print dd
192  tree_level5 = parseDir(dd,"%s/%s/%d" % (station[0],ring[1],chamber),iteration1,iterationN)
193  tree_level4.append(tree_level5)
194  if len(tree_level4) == 2: tree_level4.append(['none',''])
195  tree_level3.append(tree_level4)
196  if len(tree_level3) == 2: tree_level3.append(['none',''])
197  tree_level2.append(tree_level3)
198  if len(tree_level2) == 2: tree_level2.append(['none',''])
199  tree_level1.append(tree_level2)
200 
201 # Common plots
202 common_basedir = comdir
203 tree_level2 = parseDir(common_basedir,"All")
204 tree_level1.append(tree_level2)
205 
206 
207 mytree.append(tree_level1)
208 print(" ")
209 #pp.pprint(mytree)
210 print()
211 
212 ff = open("tree_items.js",mode="w")
213 print("var TREE_ITEMS = ", file=ff)
214 json.dump(mytree,ff)
215 ff.close()
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def parseDir(dir, label, it1="", itN="")
Definition: createTree.py:118