60 def content(self,**args):
61
62
63 ntDir = self.globalConfig['ntDir']
64 periodDir = ntDir+'/DataPeriods'
65 cmd = self.globalConfig['wwwDir']+'/run-beamspotnt.sh'
66 if not os.path.exists(cmd):
67 return error(
'Configuration error: %s does not exist or unreadable' % cmd)
68 if not 'plotType' in args:
69 args['plotType'] = 'plot'
70
71
72 form = htmlPara('Select data and what to plot:', attr = 'class ="example"')
73
74
75 projectList = sorted([ os.path.basename(p) for p in glob.glob(periodDir+'/data*')])
76 form += htmlSelect('Project tag','project', args, projectList, 'all data',
77 attr = 'onchange = "this.form.submit()"')
78
79
80 if 'project' in args and args['project']:
81 periodList = glob.glob(periodDir+'/'+args['project']+'/*')
82 periodList = sorted([ os.path.basename(p)[:-10] for p in periodList ])
83 if 'AllYear' in periodList:
84 periodList.remove('AllYear')
85 periodList.insert(0,'AllYear')
86 if not 'period' in args and periodList:
87 args['period'] = periodList[0]
88 form += htmlSelect('Period','period', args, periodList, attr='multiple size=5')
89
90
91 if not args.get('project'):
92 form += htmlTextInput('or select fill', 'fillnr', args,6,6)
93 form += htmlTextInput('or run', 'runnr', args,6,6)
94
95
96 form += htmlPara()
97 form += htmlSelect('Ntuple', 'nt', args,
98 ['initial T0 processing::t0/beamspotnt-IndetBeampos-ES1-UPD2.root',
99 'latest data from COOL::cool/beamspotnt-COOL-Current.root'])
100
101
102 form += htmlPara()
103 form += htmlSelect('Type of plot','plotType', args,
104 ['time evolution::plot', 'summary (slow)::summary', 'histogram::hist'],
105 attr = 'onchange = "this.form.submit()"')
106
107
108 if args['plotType']!='summary':
109 form += htmlSelect('for','varName', args,
110 ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k'])
111
112
113 form += htmlPara('Options:', attr='class ="example"')
114 if args['plotType']!='hist':
115 form += htmlCheckbox('Use LB instead of time on x axis','lbaxis',args)
116 form += htmlCheckbox('Predefined axis range','ydef', args)
117 form += htmlPara()
118 form += htmlTextInput('y axis scale expansion factor','yscale',args,6,6)
119 if args['plotType']=='plot':
120 form += htmlPara()
121 form += htmlTextInput('y axis minimum','ymin',args,6,6)
122 form += htmlTextInput('y axis maximum','ymax',args,6,6)
123 else:
124 form += htmlTextInput('x axis minimum','xmin',args,6,6)
125 form += htmlTextInput('x axis maximum','xmax',args,6,6)
126 form += htmlPara()
127 form += htmlCheckbox('Log y axis', 'logy', args)
128
129
130 form += htmlPara('Generate plot (depending on what parameters you choose, this may take a while.. please be patient):', attr='class ="example"')
131 form += htmlCheckbox('Show command line output','verbose',args)
132 form += htmlSubmit('Plot', 'doplot', attr = 'class="submit"')
133
134
135 page = htmlForm(form, attr='class="params"')
136
137
138 if 'debug' in args:
139 page += escape(str(args))
140
141
142 if 'doplot' in args:
143
144
145 t = time.time()
146 ms = 1000.*(t-floor(t))
147 varName = args.get('varName', 'all')
148 baseName = 'beamspot-%s-%s' % (args['plotType'], varName)
149 baseName = time.strftime(baseName+'-%Y%m%d-%H%M%S',time.localtime())
150 baseName += '%03i' % ms
151
152
153 cmd += ' -b'
154 cmd += ' -f %s/%s' % (ntDir,args['nt'])
155 cmd += ' -o %s/tmp/%s.gif,%s/tmp/%s.eps,%s/tmp/%s.pdf' % (self.globalConfig['wwwDir'],baseName,
156 self.globalConfig['wwwDir'],baseName,
157 self.globalConfig['wwwDir'],baseName)
158 if args.get('project'):
159
160 selPeriodList = args['period'] if isinstance(args['period'],list) else [args['period']]
161 selPeriodString = ','.join([args['project']+'.'+p for p in selPeriodList])
162 cmd += ' --perioddef %s --period %s' % (periodDir,selPeriodString)
163 if args.get('fillnr'):
164 try:
165 cmd += ' --fill %i' % int(args['fillnr'])
166 except:
167 return page+
error(
'Fill number must be an integer')
168 if args.get('runnr'):
169 try:
170 cmd += ' --run %i' % int(args['runnr'])
171 except:
172 return page+
error(
'Run number must be an integer')
173 if not 'lbaxis' in args:
174 cmd += ' --timeaxis'
175 if 'logy' in args:
176 cmd += ' --logy'
177 if 'ydef' in args:
178 cmd += ' --ydef'
179 if args.get('yscale','')!='':
180 try:
181 dummy = float(args['yscale'])
182 cmd += ' --yscale %s' % args['yscale']
183 except:
184 return page+
error(
'y axis scale expansion factor must be a number')
185 if args.get('ymin','')!='':
186 try:
187 dummy = float(args['ymin'])
188 cmd += ' --ymin %s' % args['ymin']
189 except:
190 return page+
error(
'y axis minimum must be a number')
191 if args.get('ymax','')!='':
192 try:
193 dummy = float(args['ymax'])
194 cmd += ' --ymax %s' % args['ymax']
195 except:
196 return page+
error(
'y axis maximum must be a number')
197 if args.get('xmin','')!='':
198 try:
199 dummy = float(args['xmin'])
200 cmd += ' --xmin %s' % args['xmin']
201 except:
202 return page+
error(
'x axis minimum must be a number')
203 if args.get('xmax','')!='':
204 try:
205 dummy = float(args['xmax'])
206 cmd += ' --xmax %s' % args['xmax']
207 except:
208 return page+
error(
'x axis maximum must be a number')
209 if args['plotType']=='summary':
210 cmd += ' summary'
211 else:
212 cmd += ' %s %s' % (args['plotType'], args['varName'])
213 (status,output) = subprocess.getstatusoutput(cmd)
214
215
216 if not status:
217 imageUrl = '%s/tmp/%s.gif' % (self.globalConfig.baseUrl,baseName)
218 epsUrl = '%s/tmp/%s.eps' % (self.globalConfig.baseUrl,baseName)
219 pdfUrl = '%s/tmp/%s.pdf' % (self.globalConfig.baseUrl,baseName)
220 page += image % (imageUrl,epsUrl,pdfUrl,imageUrl)
221
222
223 if status or ('verbose' in args):
224 page += cmdoutput % (escape(cmd),status,escape(output))
225
226 return page
227
228
229