ATLAS Offline Software
Loading...
Searching...
No Matches
MyPlots.MyPlots Class Reference
Inheritance diagram for MyPlots.MyPlots:
Collaboration diagram for MyPlots.MyPlots:

Public Member Functions

 __init__ (self)
 content (self, **args)
 configure (self)
 pageName (self)
 addPage (self, name, page, **attrs)
 addLink (self, name, alias, **attrs)
 addToPageHeader (self, snippet)
 index (self, **args)
 configureLinks (self)
 override (self)
 header (self, **args)
 navigation (self, **args)
 footer (self, **args)

Public Attributes

dict pageConfig
 globalConfig = GlobalConfiguration()
bool isConfigured = False

Static Public Attributes

 exposed

Detailed Description

Definition at line 54 of file MyPlots.py.

Constructor & Destructor Documentation

◆ __init__()

MyPlots.MyPlots.__init__ ( self)

Definition at line 56 of file MyPlots.py.

56 def __init__(self):
57 BeamSpotWebPage.__init__(self)
58 self.pageConfig['pageTitle'] = 'ATLAS Beam Spot Plots'
59

Member Function Documentation

◆ addLink()

WebPage.WebPage.addLink ( self,
name,
alias,
** attrs )
inherited
Add a new link to the page tree. Links share page objects with
   other pages through aliasing. This allows using different links
   with different queries to the same page as if they were separate
   pages. For links, highlighting of the current page is disabled
   (if enabled, all links leading to the same page would be
   highlighted).

Definition at line 309 of file WebPage.py.

309 def addLink(self, name, alias, **attrs):
310 """Add a new link to the page tree. Links share page objects with
311 other pages through aliasing. This allows using different links
312 with different queries to the same page as if they were separate
313 pages. For links, highlighting of the current page is disabled
314 (if enabled, all links leading to the same page would be
315 highlighted)."""
316 self.globalConfig.pageList.append(name)
317 self.globalConfig.pageAttributes[name] = dict(attrs)
318 self.globalConfig.pageAttributes[name]['alias'] = alias
319

◆ addPage()

WebPage.WebPage.addPage ( self,
name,
page,
** attrs )
inherited
Add a new web page to the page tree. All pages added via addPage
   share the same GlobalConfiguration object.

Definition at line 300 of file WebPage.py.

300 def addPage(self, name, page, **attrs):
301 """Add a new web page to the page tree. All pages added via addPage
302 share the same GlobalConfiguration object."""
303 page.globalConfig = self.globalConfig
304 page.pageConfig['pageName'] = name
305 self.globalConfig.pageList.append(name)
306 self.globalConfig.pageAttributes[name] = dict(attrs)
307 setattr(self,name,page) # Link page into page tree (for CherryPy)
308

◆ addToPageHeader()

WebPage.WebPage.addToPageHeader ( self,
snippet )
inherited
Add a snippet of code to the page header. Use this e.g. to include JavaScript libraries.

Definition at line 320 of file WebPage.py.

320 def addToPageHeader(self, snippet):
321 """Add a snippet of code to the page header. Use this e.g. to include JavaScript libraries."""
322 self.pageConfig['pageHeaderSnippets'] += snippet
323

◆ configure()

BeamSpotWebPage.BeamSpotWebPage.configure ( self)
inherited
Final configuration of web application after all data is initialized.

Reimplemented from WebPage.WebPage.

Definition at line 49 of file BeamSpotWebPage.py.

49 def configure(self):
50 self.pageConfig['cssName'] = self.globalConfig.baseUrl+'/css/beamspot.css'
51 if not self.pageConfig.get('pageTitle',''):
52 self.pageConfig['pageTitle'] = 'ATLAS Beam Spot Web Page'
53 self.pageConfig['header'] = header
54 self.pageConfig['footer'] = footer
55 WebPage.configure(self)
56
57
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ configureLinks()

WebPage.WebPage.configureLinks ( self)
inherited
Based on configuration data, for each web page create two link entries in pageConfig:
   The first entry has the form url_PAGENAME and contains the complete URL to link to
   a page. The second entry is named href_PAGENAME and contains style information and a
   href= prefix with proper quotation marks in addition to the URL. These link entries
   should be used to generate links in HTML pages with snippets like <a %(href_PAGENAME)s>
   or <a href="%(url_PAGENAME)>. The link entries can only be generated once all
   configuration data is available, ie configureLinks must be called from configure
   and not from __init__.

Definition at line 353 of file WebPage.py.

353 def configureLinks(self):
354 """Based on configuration data, for each web page create two link entries in pageConfig:
355 The first entry has the form url_PAGENAME and contains the complete URL to link to
356 a page. The second entry is named href_PAGENAME and contains style information and a
357 href= prefix with proper quotation marks in addition to the URL. These link entries
358 should be used to generate links in HTML pages with snippets like <a %(href_PAGENAME)s>
359 or <a href="%(url_PAGENAME)>. The link entries can only be generated once all
360 configuration data is available, ie configureLinks must be called from configure
361 and not from __init__."""
362 for p in self.globalConfig.pageList:
363 page = self.globalConfig.pageAttributes[p].get('alias',p)
364 query = self.globalConfig.pageAttributes[p].get('query','')
365 style = self.globalConfig.pageAttributes[p].get('style',None)
366 self.pageConfig['url_'+p] = '%s/%s/%s' % (self.globalConfig.baseUrl,page,query)
367 if p==self.pageName():
368 self.pageConfig['href_'+p] = 'href="%s/%s/%s" class="%s"' % (self.globalConfig.baseUrl,page,query,self.pageConfig['css_currentLink'])
369 else:
370 if style:
371 self.pageConfig['href_'+p] = 'href="%s/%s/%s" class="%s"' % (self.globalConfig.baseUrl,page,query,style)
372 else:
373 self.pageConfig['href_'+p] = 'href="%s/%s/%s"' % (self.globalConfig.baseUrl,page,query)
374

◆ content()

MyPlots.MyPlots.content ( self,
** args )
Generate the page content. Default value comes from self.pageConfig['content'].

Reimplemented from WebPage.WebPage.

Definition at line 60 of file MyPlots.py.

60 def content(self,**args):
61
62 # Configuration and defaults
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 # Start form
72 form = htmlPara('Select data and what to plot:', attr = 'class ="example"')
73
74 # Project tag selection
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 # Period selection (only if project selected)
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 # Fill and run number selection (only if no project selected)
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 # Ntuple selection
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 # Plot type selection
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 # Plot variable selection (except for summary plot)
108 if args['plotType']!='summary':
109 form += htmlSelect('for','varName', args,
110 ['posX','posY','posZ','sigmaX','sigmaY','sigmaZ','tiltX','tiltY','rhoXY','k'])
111
112 # Plot options
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 # Command line output option and submit button
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 # Render selection form
135 page = htmlForm(form, attr='class="params"')
136
137 # Output parameters for debugging
138 if 'debug' in args:
139 page += escape(str(args))
140
141 # Plotting
142 if 'doplot' in args:
143
144 # Unique file name
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 # Assemble command and execute
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 # NOTE: due to the defaults above, period will always be in args
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 # Plot
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 # Command line output
223 if status or ('verbose' in args):
224 page += cmdoutput % (escape(cmd),status,escape(output))
225
226 return page
227
228
229# Code to test or run locally

◆ footer()

WebPage.WebPage.footer ( self,
** args )
inherited
Generate the footer. Default value comes from self.pageConfig['footer'].

Definition at line 395 of file WebPage.py.

395 def footer(self, **args):
396 """Generate the footer. Default value comes from self.pageConfig['footer']."""
397 return self.pageConfig['footer'] % self.pageConfig
398
399
400# Example configuration file on how to run CherryPy with Apache mod_python:
401#
402# <Location "/">
403# PythonPath "sys.path+['/whatever']"
404# SetHandler python-program
405# PythonHandler cherrypy._cpmodpy::handler
406# PythonOption cherrypy.setup WebPage::setup_server
407# PythonDebug On
408# </Location>
409#
410#import cherrypy
411#def setup_server():
412# cherrypy.config.update({'environment': 'production',
413# 'log.screen': False,
414# 'server.socket_host': '127.0.0.1',
415# 'log.error_file': '/tmp/site.log',
416# 'show_tracebacks': False})
417# cherrypy.tree.mount(WebPage())
418
419
420# Test code

◆ header()

WebPage.WebPage.header ( self,
** args )
inherited
Generate the page header. Default value comes from self.pageConfig['header'].

Definition at line 383 of file WebPage.py.

383 def header(self, **args):
384 """Generate the page header. Default value comes from self.pageConfig['header']."""
385 return self.pageConfig['header'] % self.pageConfig
386

◆ index()

WebPage.WebPage.index ( self,
** args )
inherited
Return the complete page.

Definition at line 324 of file WebPage.py.

324 def index(self, **args):
325 """Return the complete page."""
326 if not self.isConfigured:
327 self.configure()
328 s = self.override()
329 if not s:
330 self.pageConfig['timeStamp'] = time.strftime('%a %b %d %X %Z %Y')
331 contents = self.content(**args) # Make sure contents is run first (so it
332 # can change any pageConfig entries if desired
333 s = startPage % self.pageConfig
334 s = s + htmlDiv('header', self.header(**args),
335 keepEmptyDiv=self.pageConfig['keepEmptyHeader'])
336 s = s + htmlDiv('navigation', self.navigation(**args),
337 keepEmptyDiv=self.pageConfig['keepEmptyNavigation'])
338 s = s + htmlDiv('content', contents,
339 keepEmptyDiv=self.pageConfig['keepEmptyContent'])
340 s = s + htmlDiv('footer', self.footer(**args),
341 keepEmptyDiv=self.pageConfig['keepEmptyFooter'])
342 s = s + endPage
343 return s
Definition index.py:1

◆ navigation()

WebPage.WebPage.navigation ( self,
** args )
inherited
Generate the navigation bar. Default value comes from self.pageConfig['navigation'].

Definition at line 387 of file WebPage.py.

387 def navigation(self, **args):
388 """Generate the navigation bar. Default value comes from self.pageConfig['navigation']."""
389 return self.pageConfig['navigation'] % self.pageConfig
390

◆ override()

WebPage.WebPage.override ( self)
inherited
Override provides a hook where code to generate or redirect to an alternative
   page can be placed by derived classes. If not override of the normal page is
   desired, override should return None. Otherwise it should either raise an
   appropriate exception or return a string containing the complete alternate page
   to display.

Definition at line 375 of file WebPage.py.

375 def override(self):
376 """Override provides a hook where code to generate or redirect to an alternative
377 page can be placed by derived classes. If not override of the normal page is
378 desired, override should return None. Otherwise it should either raise an
379 appropriate exception or return a string containing the complete alternate page
380 to display."""
381 return None
382

◆ pageName()

WebPage.WebPage.pageName ( self)
inherited
Short cut to retrieve the name (the last element in the URL)
   of the current page. This works only if the page has been
   added into the page tree using addPage.

Definition at line 294 of file WebPage.py.

294 def pageName(self):
295 """Short cut to retrieve the name (the last element in the URL)
296 of the current page. This works only if the page has been
297 added into the page tree using addPage."""
298 return self.pageConfig['pageName']
299

Member Data Documentation

◆ exposed

WebPage.WebPage.exposed
staticinherited

Definition at line 345 of file WebPage.py.

◆ globalConfig

WebPage.WebPage.globalConfig = GlobalConfiguration()
inherited

Definition at line 290 of file WebPage.py.

◆ isConfigured

bool WebPage.WebPage.isConfigured = False
inherited

Definition at line 291 of file WebPage.py.

◆ pageConfig

dict WebPage.WebPage.pageConfig
inherited
Initial value:
= { 'contentType': '', # For plain CGI need: 'Content-type: text/html\n\n'
'pageName': '',
'pageTitle': '',
'pageHeaderSnippets': '',
'cssName': 'default.css',
'css_currentLink': 'acurrentlink',
'header': '',
'navigation': '',
'content': '',
'footer': '',
'keepEmptyHeader': False, # Set to true to anyway generate div if empty
'keepEmptyNavigation': False,
'keepEmptyContent': False,
'keepEmptyFooter': False
}

Definition at line 273 of file WebPage.py.


The documentation for this class was generated from the following file: