CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumiPlotFiller.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import os,os.path,sys,commands,time,datetime,shutil
3 import coral
4 from RecoLuminosity.LumiDB import argparse,lumiQueryAPI,lumiTime,csvReporter
5 ###
6 #Script to fill the lumi monitoring site. This is not a generic tool
7 ###
8 def findFileTrueName(filename):
9  '''given a filename, find its true name
10  '''
11  truename=filename
12  if os.path.islink(filename):
13  truename=os.path.realpath(filename)
14  else:
15  print '[WARNING] ',filename,' is not a link'
16  return truename
17 def create2011RunList(c,p='.',o='.',dryrun=False):
18  '''
19  input:
20  c connect string
21  p authenticaion path
22  '''
23  msg=coral.MessageStream('')
24  msg.setMsgVerbosity(coral.message_Level_Error)
25  os.environ['CORAL_AUTH_PATH']='/build1/zx'
26  svc = coral.ConnectionService()
27  connectstr=c
28  session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
29  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
30  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
31  session.transaction().start(True)
32  schema=session.nominalSchema()
33  allruns=lumiQueryAPI.allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
34  session.transaction().commit()
35  del session
36  del svc
37  allruns.sort()
38  if not dryrun:
39  report=csvReporter.csvReporter(os.path.join(o,'runlist.txt'))
40  for run in allruns:
41  if run>=160442:
42  report.writeRow([run])
43  else:
44  for run in allruns:
45  if run>=160442:
46  print run
47 
48 def createRunList(c,p='.',o='.',dryrun=False):
49  '''
50  input:
51  c connect string
52  p authenticaion path
53  '''
54  msg=coral.MessageStream('')
55  msg.setMsgVerbosity(coral.message_Level_Error)
56  os.environ['CORAL_AUTH_PATH']='/build1/zx'
57  svc = coral.ConnectionService()
58  connectstr=c
59  session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
60  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
61  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
62  session.transaction().start(True)
63  schema=session.nominalSchema()
64  allruns=lumiQueryAPI.allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
65  session.transaction().commit()
66  del session
67  del svc
68  allruns.sort()
69  if not dryrun:
70  report=csvReporter.csvReporter(os.path.join(o,'runlist.txt'))
71  for run in allruns:
72  report.writeRow([run])
73  else:
74  print allruns
75 
76 def totalLumi2011vstime(c,p='.',i='',o='.',begTime="03/14/11 09:00:00.00",endTime="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
77  plotoutname='totallumivstime-2011.png'
78  textoutname='totallumivstime-2011.csv'
79  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
80  if selectionfile:
81  elements.append('-i')
82  elements.append(selectionfile)
83  if endTime:
84  elements.append('-end')
85  elements.append('"'+endTime+'"')
86  if beamstatus:
87  elements.append('-beamstatus')
88  if beamstatus=='stable':
89  elements.append('"STABLE BEAMS"')
90  if beamenergy:
91  elements.append('-beamenergy')
92  elements.append(str(beamenergy))
93  if beamfluctuation:
94  elements.append('-beamfluctuation')
95  elements.append(str(beamfluctuation))
96  if withTextOutput:
97  elements.append('-o')
98  elements.append(os.path.join(o,textoutname))
99  if annotateBoundaryRunnum:
100  elements.append('--annotateboundary')
101  command=' '.join(elements)
102  print command
103  if not dryrun:
104  statusAndOutput=commands.getstatusoutput(command)
105  print statusAndOutput[1]
106 
107 def totalLumi2010vstime(c,p='.',i='',o='.',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
108  plotoutname='totallumivstime-2010.png'
109  textoutname='totallumivstime-2010.csv'
110  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
111  if selectionfile:
112  elements.append('-i')
113  elements.append(selectionfile)
114  if endTime:
115  elements.append('-end')
116  elements.append('"'+endTime+'"')
117  if beamstatus:
118  elements.append('-beamstatus')
119  if beamstatus=='stable':
120  elements.append('"STABLE BEAMS"')
121  if beamenergy:
122  elements.append('-beamenergy')
123  elements.append(str(beamenergy))
124  if beamfluctuation:
125  elements.append('-beamfluctuation')
126  elements.append(str(beamfluctuation))
127  if withTextOutput:
128  elements.append('-o')
129  elements.append(os.path.join(o,textoutname))
130  if annotateBoundaryRunnum:
131  elements.append('--annotateboundary')
132  command=' '.join(elements)
133  print command
134  if not dryrun:
135  statusAndOutput=commands.getstatusoutput(command)
136  print statusAndOutput[1]
137 
138 def totalLumivstime(c,p='.',i='',o='.',begTime="03/30/10 10:00:00.00",endTime=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
139  '''
140  input:
141  c connect string
142  p authenticaion path
143  i input selection file name
144  o output path
145  '''
146  plotoutname='totallumivstime.png'
147  textoutname='totallumivstime.csv'
148  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','time']
149  if selectionfile:
150  elements.append('-i')
151  elements.append(selectionfile)
152  if endTime:
153  elements.append('-end')
154  elements.append('"'+endTime+'"')
155  if beamstatus:
156  elements.append('-beamstatus')
157  if beamstatus=='stable':
158  elements.append('"STABLE BEAMS"')
159  if beamenergy:
160  elements.append('-beamenergy')
161  elements.append(str(beamenergy))
162  if beamfluctuation:
163  elements.append('-beamfluctuation')
164  elements.append(str(beamfluctuation))
165  if withTextOutput:
166  elements.append('-o')
167  elements.append(os.path.join(o,textoutname))
168  if annotateBoundaryRunnum:
169  elements.append('--annotateboundary')
170  command=' '.join(elements)
171  print command
172  if not dryrun:
173  statusAndOutput=commands.getstatusoutput(command)
174  print statusAndOutput[1]
175 
176 def totalLumivstimeLastweek(c,p='.',i='',o='.',selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
177  '''
178  input:
179  c connect string
180  p authenticaion path
181  i input selection file name
182  o output path
183  ##fix me: year boundary is not considered!
184  '''
186  plotoutname='totallumivstime-weekly.png'
187  textoutname='totallumivstime-weekly.csv'
188  nowTime=datetime.datetime.now()
189  lastMondayStr=' '.join([str(nowTime.isocalendar()[0]),str(nowTime.isocalendar()[1]-1),str(nowTime.isocalendar()[2])])
190 
191  lastweekMonday=datetime.datetime(*time.strptime(lastMondayStr,'%Y %W %w')[0:5])
192  lastweekEndSunday=lastweekMonday+datetime.timedelta(days=7,hours=24)
193 
194  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+t.DatetimeToStr(lastweekMonday)+'"','-end','"'+t.DatetimeToStr(lastweekEndSunday)+'"','-batch',os.path.join(o,plotoutname),'time']
195  if withTextOutput:
196  elements.append('-o')
197  elements.append(os.path.join(o,textoutname))
198  if beamstatus:
199  elements.append('-beamstatus')
200  if beamstatus=='stable':
201  elements.append('"STABLE BEAMS"')
202  if beamenergy:
203  elements.append('-beamenergy')
204  elements.append(str(beamenergy))
205  if beamfluctuation:
206  elements.append('-beamfluctuation')
207  elements.append(str(beamfluctuation))
208  command=' '.join(elements)
209  print command
210  if not dryrun:
211  statusAndOutput=commands.getstatusoutput(command)
212  print statusAndOutput[1]
213 
214 def lumi2010PerDay(c,p='.',i='',o='',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
215  plotoutname='lumiperday-2010.png'
216  textoutname='lumiperday-2010.csv'
217  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
218  if selectionfile:
219  elements.append('-i')
220  elements.append(selectionfile)
221  if endTime:
222  elements.append('-end')
223  elements.append('"'+endTime+'"')
224  if beamstatus:
225  elements.append('-beamstatus')
226  if beamstatus=='stable':
227  elements.append('"STABLE BEAMS"')
228  if beamenergy:
229  elements.append('-beamenergy')
230  elements.append(str(beamenergy))
231  if beamfluctuation:
232  elements.append('-beamfluctuation')
233  elements.append(str(beamfluctuation))
234  if withTextOutput:
235  elements.append('-o')
236  elements.append(os.path.join(o,textoutname))
237  if annotateBoundaryRunnum:
238  elements.append('--annotateboundary')
239  command=' '.join(elements)
240  print command
241  if not dryrun:
242  statusAndOutput=commands.getstatusoutput(command)
243  print statusAndOutput[1]
244 
245 def lumi2011PerDay(c,p='.',i='',o='',begTime="03/14/11 09:00:00.00",endTime=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
246  plotoutname='lumiperday-2011.png'
247  textoutname='lumiperday-2011.csv'
248  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
249  if selectionfile:
250  elements.append('-i')
251  elements.append(selectionfile)
252  if endTime:
253  elements.append('-end')
254  elements.append('"'+endTime+'"')
255  if beamstatus:
256  elements.append('-beamstatus')
257  if beamstatus=='stable':
258  elements.append('"STABLE BEAMS"')
259  if beamenergy:
260  elements.append('-beamenergy')
261  elements.append(str(beamenergy))
262  if beamfluctuation:
263  elements.append('-beamfluctuation')
264  elements.append(str(beamfluctuation))
265  if withTextOutput:
266  elements.append('-o')
267  elements.append(os.path.join(o,textoutname))
268  if annotateBoundaryRunnum:
269  elements.append('--annotateboundary')
270  command=' '.join(elements)
271  print command
272  if not dryrun:
273  statusAndOutput=commands.getstatusoutput(command)
274  print statusAndOutput[1]
275 
276 def lumiPerDay(c,p='.',i='',o='',begTime="03/30/10 10:00:00.00",endTime="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
277  '''
278  input:
279  c connect string
280  p authenticaion path
281  i input selection file
282  o outputpath
283  '''
284  plotoutname='lumiperday.png'
285  textoutname='lumiperday.csv'
286  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','perday']
287  if selectionfile:
288  elements.append('-i')
289  elements.append(selectionfile)
290  if endTime:
291  elements.append('-end')
292  elements.append('"'+endTime+'"')
293  if beamstatus:
294  elements.append('-beamstatus')
295  if beamstatus=='stable':
296  elements.append('"STABLE BEAMS"')
297  if beamenergy:
298  elements.append('-beamenergy')
299  elements.append(str(beamenergy))
300  if beamfluctuation:
301  elements.append('-beamfluctuation')
302  elements.append(str(beamfluctuation))
303  if withTextOutput:
304  elements.append('-o')
305  elements.append(os.path.join(o,textoutname))
306  if annotateBoundaryRunnum:
307  elements.append('--annotateboundary')
308  command=' '.join(elements)
309  print command
310  if not dryrun:
311  statusAndOutput=commands.getstatusoutput(command)
312  print statusAndOutput[1]
313 
314 def totalLumi2010vsRun(c,p='.',i='',o='',begRun="132440",endRun="149509",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
315  plotoutname='totallumivsrun-2010.png'
316  textoutname='totallumivsrun-2010.csv'
317  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
318  if endRun:
319  elements.append('-end')
320  elements.append(endRun)
321  if beamstatus:
322  elements.append('-beamstatus')
323  if beamstatus=='stable':
324  elements.append('"STABLE BEAMS"')
325  if beamenergy:
326  elements.append('-beamenergy')
327  elements.append(str(beamenergy))
328  if beamfluctuation:
329  elements.append('-beamfluctuation')
330  elements.append(str(beamfluctuation))
331  if withTextOutput:
332  elements.append('-o')
333  elements.append(os.path.join(o,textoutname))
334  command=' '.join(elements)
335  print command
336  if not dryrun:
337  statusAndOutput=commands.getstatusoutput(command)
338  print statusAndOutput[1]
339 
340 def totalLumi2011vsRun(c,p='.',i='',o='',begRun="160442",endRun=None,selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
341  plotoutname='totallumivsrun-2011.png'
342  textoutname='totallumivsrun-2011.csv'
343  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
344  if endRun:
345  elements.append('-end')
346  elements.append(endRun)
347  if beamstatus:
348  elements.append('-beamstatus')
349  if beamstatus=='stable':
350  elements.append('"STABLE BEAMS"')
351  if beamenergy:
352  elements.append('-beamenergy')
353  elements.append(str(beamenergy))
354  if beamfluctuation:
355  elements.append('-beamfluctuation')
356  elements.append(str(beamfluctuation))
357  if withTextOutput:
358  elements.append('-o')
359  elements.append(os.path.join(o,textoutname))
360  command=' '.join(elements)
361  print command
362  if not dryrun:
363  statusAndOutput=commands.getstatusoutput(command)
364  print statusAndOutput[1]
365 
366 def totalLumivsRun(c,p='.',i='',o='',begRun="132440",endRun="",selectionfile=None,beamstatus=None,beamenergy=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
367  '''
368  input:
369  c connect string
370  p authenticaion path
371  i input selection file
372  o outputpath
373  '''
374  plotoutname='totallumivsrun.png'
375  textoutname='totallumivsrun.csv'
376  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begRun,'-batch',os.path.join(o,plotoutname),'-yscale both','run']
377  if endRun:
378  elements.append('-end')
379  elements.append(endRun)
380  if beamstatus:
381  elements.append('-beamstatus')
382  if beamstatus=='stable':
383  elements.append('"STABLE BEAMS"')
384  if beamenergy:
385  elements.append('-beamenergy')
386  elements.append(str(beamenergy))
387  if beamfluctuation:
388  elements.append('-beamfluctuation')
389  elements.append(str(beamfluctuation))
390  if withTextOutput:
391  elements.append('-o')
392  elements.append(os.path.join(o,textoutname))
393  command=' '.join(elements)
394  print command
395  if not dryrun:
396  statusAndOutput=commands.getstatusoutput(command)
397  print statusAndOutput[1]
398 
399 def totalLumi2010vsFill(c,p='.',i='',o='',begFill="1005",endFill="1461",selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
400  plotoutname='totallumivsfill-2010.png'
401  textoutname='totallumivsfill-2010.csv'
402  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
403  if endFill:
404  elements.append('-end')
405  elements.append(endFill)
406  if beamstatus:
407  elements.append('-beamstatus')
408  if beamstatus=='stable':
409  elements.append('"STABLE BEAMS"')
410  if beamenergy:
411  elements.append('-beamenergy')
412  elements.append(str(beamenergy))
413  if beamfluctuation:
414  elements.append('-beamfluctuation')
415  elements.append(str(beamfluctuation))
416  if withTextOutput:
417  elements.append('-o')
418  elements.append(os.path.join(o,textoutname))
419  command=' '.join(elements)
420  print command
421  if not dryrun:
422  statusAndOutput=commands.getstatusoutput(command)
423  print statusAndOutput[1]
424 
425 def totalLumi2011vsFill(c,p='.',i='',o='',begFill="1616",endFill=None,selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
426  plotoutname='totallumivsfill-2011.png'
427  textoutname='totallumivsfill-2011.csv'
428  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
429  if endFill:
430  elements.append('-end')
431  elements.append(endFill)
432  if beamstatus:
433  elements.append('-beamstatus')
434  if beamstatus=='stable':
435  elements.append('"STABLE BEAMS"')
436  if beamenergy:
437  elements.append('-beamenergy')
438  elements.append(str(beamenergy))
439  if beamfluctuation:
440  elements.append('-beamfluctuation')
441  elements.append(str(beamfluctuation))
442  if withTextOutput:
443  elements.append('-o')
444  elements.append(os.path.join(o,textoutname))
445  command=' '.join(elements)
446  print command
447  if not dryrun:
448  statusAndOutput=commands.getstatusoutput(command)
449  print statusAndOutput[1]
450 
451 def totalLumivsFill(c,p='.',i='',o='',begFill="1005",endFill="",selectionfile=None,beamenergy=None,beamstatus=None,beamfluctuation=None,dryrun=False,withTextOutput=False):
452  '''
453  input:
454  c connect string
455  p authenticaion path
456  i input selection file
457  o output path
458  '''
459  plotoutname='totallumivsfill.png'
460  textoutname='totallumivsfill.csv'
461  elements=['lumiSumPlot.py','-c',c,'-P',p,'-begin',begFill,'-batch',os.path.join(o,plotoutname),'-yscale both','fill']
462  if endFill:
463  elements.append('-end')
464  elements.append(endFill)
465  if beamstatus:
466  elements.append('-beamstatus')
467  if beamstatus=='stable':
468  elements.append('"STABLE BEAMS"')
469  if beamenergy:
470  elements.append('-beamenergy')
471  elements.append(str(beamenergy))
472  if beamfluctuation:
473  elements.append('-beamfluctuation')
474  elements.append(str(beamfluctuation))
475  if withTextOutput:
476  elements.append('-o')
477  elements.append(os.path.join(o,textoutname))
478  command=' '.join(elements)
479  print command
480  if not dryrun:
481  statusAndOutput=commands.getstatusoutput(command)
482  print statusAndOutput[1]
483 def instLumiForRuns(c,runnumbers,p='.',o='',dryrun=False):
484  '''
485  draw instlumperrun plot for the given runs
486  input:
487  c connect string
488  runnumbers []
489  p authenticaion path
490  o output path
491  '''
492  plotoutname='rollinginstlumi_'
493  textoutname='rollinginstlumi_'
494  for idx,run in enumerate(runnumbers):
495  batch=os.path.join(o,plotoutname+str(idx+1)+'.png')
496  elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin',str(run),'-batch',batch,'run']
497  command=' '.join(elements)
498  print command
499  if not dryrun:
500  statusAndOutput=commands.getstatusoutput(command)
501  print statusAndOutput[1]
502 
503 def instPeak2010Perday(c,p='.',o='.',begTime="03/30/10 10:00:00.00",endTime="11/03/10 00:00:00.00",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
504  plotoutname='lumipeak-2010.png'
505  textoutname='lumipeak-2010.csv'
506  elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
507  if endTime:
508  elements.append('-end')
509  elements.append('"'+endTime+'"')
510  if withTextOutput:
511  elements.append('-o')
512  elements.append(os.path.join(o,textoutname))
513  if annotateBoundaryRunnum:
514  elements.append('--annotateboundary')
515  command=' '.join(elements)
516  print command
517  if not dryrun:
518  statusAndOutput=commands.getstatusoutput(command)
519  print statusAndOutput[1]
520 
521 def instPeak2011Perday(c,p='.',o='.',begTime="03/14/11 09:00:00.00",endTime="",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
522  plotoutname='lumipeak-2011.png'
523  textoutname='lumipeak-2011.csv'
524  elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
525  if endTime:
526  elements.append('-end')
527  elements.append('"'+endTime+'"')
528  if withTextOutput:
529  elements.append('-o')
530  elements.append(os.path.join(o,textoutname))
531  if annotateBoundaryRunnum:
532  elements.append('--annotateboundary')
533  command=' '.join(elements)
534  print command
535  if not dryrun:
536  statusAndOutput=commands.getstatusoutput(command)
537  print statusAndOutput[1]
538 
539 def instPeakPerday(c,p='.',o='.',begTime="03/30/10 10:00:00.00",endTime="",dryrun=False,withTextOutput=False,annotateBoundaryRunnum=False):
540  '''
541  input:
542  c connect string
543  p authenticaion path
544  o outout text/csv file
545  '''
546  plotoutname='lumipeak.png'
547  textoutname='lumipeak.csv'
548  elements=['lumiInstPlot.py','-c',c,'-P',p,'-begin','"'+begTime+'"','-batch',os.path.join(o,plotoutname),'-yscale both','peakperday']
549  if endTime:
550  elements.append('-end')
551  elements.append('"'+endTime+'"')
552  if withTextOutput:
553  elements.append('-o')
554  elements.append(os.path.join(o,textoutname))
555  if annotateBoundaryRunnum:
556  elements.append('--annotateboundary')
557  command=' '.join(elements)
558  print command
559  if not dryrun:
560  statusAndOutput=commands.getstatusoutput(command)
561  print statusAndOutput[1]
562 
563 def main():
564  actionlist=['instperrun','instpeakvstime','instpeak2011vstime','totalvstime','total2011vstime','totallumilastweek','totalvsfill','total2011vsfill','totalvsrun','total2011vsrun','perday','perday2011','createrunlist','create2011runlist','physicsperday','physicsvstime']
565  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Produce lumi plots")
566  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
567  parser.add_argument('-P',dest='authpath',action='store',required=False,help='auth path. Optional. Default to .')
568  parser.add_argument('-L',dest='logpath',action='store',required=False,help='log path. Optional. Default to .')
569  parser.add_argument('-i',dest='ifile',action='store',required=False,help='input selection file. Optional.')
570  parser.add_argument('-o',dest='opath',action='store',required=False,help='output file path. Optional')
571  parser.add_argument('-beamenergy',dest='beamenergy',action='store',required=False,help='beamenergy (in GeV) selection criteria,e.g. 3.5e3')
572  parser.add_argument('-beamfluctuation',dest='beamfluctuation',action='store',required=False,help='allowed beamenergy fluctuation (in GeV),e.g. 0.2e3')
573  parser.add_argument('--annotateboundary',dest='annotateboundary',action='store_true',help='annotate boundary run numbers')
574  parser.add_argument('-beamstatus',dest='beamstatus',action='store',required=False,help='selection criteria beam status,e.g. stable')
575  parser.add_argument('--withTextOutput',dest='withtextoutput',action='store_true',help='write to text output file')
576  parser.add_argument('--dryrun',dest='dryrun',action='store_true',help='dryrun mode')
577  parser.add_argument('action',choices=actionlist,help='command actions')
578  args=parser.parse_args()
579 
580  authpath='.'
581  logpath='.'
582  opath='.'
583  connectstr=args.connect
584  isDryrun=False
585  withTextOutput=False
586  beamstatus=None
587  beamenergy=None
588  beamfluctuation=None
589  if args.beamenergy:
590  beamenergy=args.beamenergy
591  if args.beamstatus:
592  beamstatus=args.beamstatus
593  if args.beamfluctuation:
594  beamfluctuation=args.beamfluctuation
595  if args.dryrun:
596  isDryrun=True
597  if args.withtextoutput:
598  withTextOutput=True
599  if args.authpath:
600  authpath=args.authpath
601  if args.logpath:
602  lumilogpath=args.logpath
603  if args.ifile:
604  ifile=args.ifile
605  if args.opath:
606  opath=args.opath
607  if args.action == 'create2011runlist':
608  create2011RunList(connectstr,authpath,o=opath,dryrun=isDryrun)
609  if args.action == 'createrunlist':
610  createRunList(connectstr,authpath,o=opath,dryrun=isDryrun)
611  if args.action == 'instperrun':
612  if not args.ifile:
613  print 'option -i is required for action instperrun'
614  return 2
615  f=open(args.ifile,'r')
616  runs=[]
617  for run in f:
618  runs.append(int(run))
619  last2runs=[runs[-2],runs[-1]]
620  instLumiForRuns(connectstr,last2runs,p=authpath,o=opath,dryrun=isDryrun)
621  if args.action == 'total2011vsrun':
622  if args.ifile:
623  f=open(args.ifile,'r')
624  runs=[]
625  for run in f:
626  runs.append(int(run))
627  else:
628  runs=['160442','']
629  totalLumi2011vsRun(connectstr,p=authpath,begRun=str(runs[0]),o=opath,endRun=str(runs[-1]),beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
630 
631  if args.action == 'totalvsrun':
632  if args.ifile:
633  f=open(args.ifile,'r')
634  runs=[]
635  for run in f:
636  runs.append(int(run))
637  else:
638  runs=['132440','']
639  totalLumivsRun(connectstr,p=authpath,begRun=str(runs[0]),o=opath,endRun=str(runs[-1]),beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
640 
641  if args.action == 'instpeakvstime':
642  instPeakPerday(connectstr,p=authpath,o=opath,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
643 
644  if args.action == 'instpeak2011vstime':
645  instPeak2011Perday(connectstr,p=authpath,o=opath,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
646  if args.action == 'total2011vstime':
647  totalLumi2011vstime(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
648 
649  if args.action == 'totalvstime':
650  totalLumivstime(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
651 
652  if args.action == 'totallumilastweek':
653  totalLumivstimeLastweek(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
654 
655  if args.action == 'total2011vsfill':
656  totalLumi2011vsFill(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
657 
658  if args.action == 'totalvsfill':
659  totalLumivsFill(connectstr,p=authpath,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
660 
661  if args.action == 'perday2011':
662  lumi2011PerDay(connectstr,p=authpath,o=opath,dryrun=isDryrun,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
663 
664  if args.action == 'perday':
665  lumiPerDay(connectstr,p=authpath,o=opath,dryrun=isDryrun,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,withTextOutput=withTextOutput,annotateBoundaryRunnum=args.annotateboundary)
666 
667  if args.action == 'physicsperday' or args.action == 'physicsvstime':
668  if not args.ifile:
669  print 'input selection file is required'
670  return 3
671  if not os.path.isfile(args.ifile):
672  print 'file: '+args.ifile+' does not exist'
673  return 4
674  truefilename=findFileTrueName(args.ifile)
675  #print 'truefilename ',truefilename
676  #
677  #if truefilename modification time is more recent than the output plot, replot it
678  #
679  inputmodtime=os.path.getmtime(truefilename)
680  #print 'inputmodtime ',inputmodtime
681  if not os.path.isfile(os.path.join(opath,'lumiperday.png')) or not os.path.isfile(os.path.join(opath,'totallumivstime.png')):
682  if not isDryrun:
683  shutil.copy2(truefilename,os.path.join(opath,os.path.basename(truefilename)))
684  print 'cp '+truefilename+' '+os.path.join(opath,os.path.basename(truefilename))
685  if args.action == 'physicsperday':
686  lumiPerDay(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
687  if args.action == 'physicsvstime':
688  totalLumivstime(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
689  else:
690  outputmodtime=os.path.getmtime(os.path.join(opath,'lumiperday.png'))
691  #print 'outputmodtime ',outputmodtime
692  if inputmodtime > outputmodtime :
693  print 'physics selection file '+truefilename+' modified, updating physics plots: '
694  if not isDryrun:
695  shutil.copy2(truefilename,os.path.join(opath,os.path.basename(truefilename)))
696  print 'cp '+truefilename+' '+os.path.join(opath,os.path.basename(truefilename))
697  if args.action == 'physicsperday':
698  lumiPerDay(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
699  if args.action == 'physicsvstime':
700  totalLumivstime(connectstr,p=authpath,selectionfile=truefilename,o=opath,beamstatus=beamstatus,beamenergy=beamenergy,beamfluctuation=beamfluctuation,dryrun=isDryrun,withTextOutput=withTextOutput)
701  else:
702  print 'physics selection file older than plot, do nothing'
703  return 0
704 
705 if __name__=='__main__':
706  main()
Definition: start.py:1
def allruns
==============real api=====###
def findFileTrueName
Script to fill the lumi monitoring site.
static std::string join(char **cmd)
Definition: RemoteFile.cc:18