CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
lumiInstPlot Namespace Reference

Classes

class  constants
 

Functions

def getInstLumiPerLS
 
def getLumiPerRun
 
def main
 

Variables

string VERSION = '1.00'
 

Function Documentation

def lumiInstPlot.getInstLumiPerLS (   dbsession,
  c,
  runList,
  selectionDict,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09 
)
input: runList[runnum], selectionDict{runnum:[ls]}
output:[[runnumber,lsnumber,deliveredInst,recordedInst,norbit,startorbit,runstarttime,runstoptime]]

Definition at line 17 of file lumiInstPlot.py.

References CommonUtil.count_dups(), lumiQueryAPI.lumisummaryByrun(), and lumiQueryAPI.runsummaryByrun().

Referenced by main().

17 
18 def getInstLumiPerLS(dbsession,c,runList,selectionDict,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09):
19  '''
20  input: runList[runnum], selectionDict{runnum:[ls]}
21  output:[[runnumber,lsnumber,deliveredInst,recordedInst,norbit,startorbit,runstarttime,runstoptime]]
22  '''
23  result=[]
24  selectedRunlist=runList
25  if len(selectionDict)!=0:
26  selectedRunlist=[]
27  allruns=runlist+selectionDict.keys()
28  dups=CommonUtil.count_dups(allruns)
29  for runnum,dupcount in dups:
30  if dupcount==2:
31  selectedRunlist.append(runnum)
32 
33  dbsession.transaction().start(True)
34  for run in selectedRunlist:
35  q=dbsession.nominalSchema().newQuery()
36  runsummary=lumiQueryAPI.runsummaryByrun(q,run)
37  del q
38  runstarttime=runsummary[3]
39  runstoptime=runsummary[4]
40  q=dbsession.nominalSchema().newQuery()
41  lumiperrun=lumiQueryAPI.lumisummaryByrun(q,run,c.LUMIVERSION,beamstatus,beamenergy,beamenergyfluctuation)
42  del q
43  if len(lumiperrun)==0: #no result for this run
44  result.append([run,1,0.0,0.0,0,0,runstarttime,runstoptime])
45  else:
46  for lumiperls in lumiperrun:
47  cmslsnum=lumiperls[0]
48  instlumi=lumiperls[1]
49  recordedlumi=0.0
50  numorbit=lumiperls[2]
51  startorbit=lumiperls[3]
52  deadcount=0
53  bitzero=0
54  result.append([run,cmslsnum,instlumi,recordedlumi,numorbit,startorbit,runstarttime,runstoptime])
55  dbsession.transaction().commit()
56  if c.VERBOSE:
57  print result
58  return result
Definition: start.py:1
def count_dups
Definition: CommonUtil.py:43
def getInstLumiPerLS
Definition: lumiInstPlot.py:17
def lumiInstPlot.getLumiPerRun (   dbsession,
  c,
  run,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09 
)
input: run
output:{runnumber:[[lsnumber,deliveredInst,recordedInst,norbit,startorbit,runstarttime,runstoptime]]}

Definition at line 59 of file lumiInstPlot.py.

References lumiQueryAPI.lumisummaryByrun(), lumiQueryAPI.runsummaryByrun(), and lumiQueryAPI.trgbitzeroByrun().

Referenced by main().

59 
60 def getLumiPerRun(dbsession,c,run,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09):
61  '''
62  input: run
63  output:{runnumber:[[lsnumber,deliveredInst,recordedInst,norbit,startorbit,runstarttime,runstoptime]]}
64  '''
65  result=[]
66  dbsession.transaction().start(True)
67  q=dbsession.nominalSchema().newQuery()
68  runsummary=lumiQueryAPI.runsummaryByrun(q,run)
69  del q
70  runstarttime=runsummary[3]
71  runstoptime=runsummary[4]
72  fillnum=runsummary[0]
73  q=dbsession.nominalSchema().newQuery()
74  lumiperrun=lumiQueryAPI.lumisummaryByrun(q,run,c.LUMIVERSION,beamstatus,beamenergy,beamenergyfluctuation)
75  del q
76  q=dbsession.nominalSchema().newQuery()
77  trgperrun=lumiQueryAPI.trgbitzeroByrun(q,run) # {cmslsnum:[trgcount,deadtime,bitname,prescale]}
78  del q
79 
80  for lumiperls in lumiperrun:
81  cmslsnum=lumiperls[0]
82  instlumi=lumiperls[1]
83  recordedlumi=0.0
84  numorbit=lumiperls[2]
85  startorbit=lumiperls[3]
86  deadcount=0
87  bitzero=0
88  if trgperrun.has_key(cmslsnum):
89  bitzero=trgperrun[cmslsnum][0]
90  deadcount=trgperrun[cmslsnum][1]
91  bitzeroprescale=trgperrun[cmslsnum][-1]
92  try:
93  recordedlumi=instlumi*(1.0-float(deadcount)/(float(bitzero)*float(bitzeroprescale)))
94  except ZeroDivisionError:
95  recordedlumi=-0.1 #
96  result.append([cmslsnum,instlumi,recordedlumi,numorbit,startorbit,fillnum,runstarttime,runstoptime])
97  dbsession.transaction().commit()
98  if c.VERBOSE:
99  print result
100  return result
Definition: start.py:1
def lumiInstPlot.main ( )

Definition at line 101 of file lumiInstPlot.py.

References python.multivaluedict.append(), getInstLumiPerLS(), getLumiPerRun(), getHLTprescales.index, max(), lumiQueryAPI.runsByTimerange(), and CommonUtil.transposed().

102 def main():
103  allowedscales=['linear','log','both']
104  c=constants()
105  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Plot integrated luminosity as function of the time variable of choice")
106  # add required arguments
107  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
108  # add optional arguments
109  parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
110  parser.add_argument('-n',dest='normfactor',action='store',help='normalization factor (optional, default to 1.0)')
111  parser.add_argument('-i',dest='inputfile',action='store',help='lumi range selection file (optional)')
112  parser.add_argument('-o',dest='outputfile',action='store',help='csv outputfile name (optional)')
113  parser.add_argument('-b',dest='beammode',action='store',help='beam mode, optional, no default')
114  parser.add_argument('-lumiversion',dest='lumiversion',action='store',help='lumi data version, optional for all, default 0001')
115  parser.add_argument('-begin',dest='begin',action='store',help='begin xvalue (required)')
116  parser.add_argument('-end',dest='end',action='store',help='end xvalue(optional). Default to the maximum exists DB')
117  parser.add_argument('-batch',dest='batch',action='store',help='graphical mode to produce PNG file. Specify graphical file here. Default to lumiSum.png')
118  parser.add_argument('-yscale',dest='yscale',action='store',required=False,default='linear',help='y_scale')
119  parser.add_argument('--interactive',dest='interactive',action='store_true',help='graphical mode to draw plot in a TK pannel.')
120  parser.add_argument('-timeformat',dest='timeformat',action='store',help='specific python timeformat string (optional). Default mm/dd/yy hh:min:ss.00')
121  parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, default to $CMS_PATH/SITECONF/local/JobConfig, if path undefined, fallback to cern proxy&server')
122  parser.add_argument('action',choices=['peakperday','run'],help='plot type of choice')
123  #graphical mode options
124  parser.add_argument('--annotateboundary',dest='annotateboundary',action='store_true',help='annotate boundary run numbers')
125  parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose mode, print result also to screen')
126  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
127  # parse arguments
128  args=parser.parse_args()
129  connectstring=args.connect
130  connectparser=connectstrParser.connectstrParser(connectstring)
131  connectparser.parse()
132  usedefaultfrontierconfig=False
133  cacheconfigpath=''
134  if connectparser.needsitelocalinfo():
135  if not args.siteconfpath:
136  cacheconfigpath=os.environ['CMS_PATH']
137  if cacheconfigpath:
138  cacheconfigpath=os.path.join(cacheconfigpath,'SITECONF','local','JobConfig','site-local-config.xml')
139  else:
140  usedefaultfrontierconfig=True
141  else:
142  cacheconfigpath=args.siteconfpath
143  cacheconfigpath=os.path.join(cacheconfigpath,'site-local-config.xml')
145  if usedefaultfrontierconfig:
146  p.parseString(c.defaultfrontierConfigString)
147  else:
148  p.parse(cacheconfigpath)
149  connectstring=connectparser.fullfrontierStr(connectparser.schemaname(),p.parameterdict())
150  runnumber=0
151  svc = coral.ConnectionService()
152  if args.debug :
153  msg=coral.MessageStream('')
154  msg.setMsgVerbosity(coral.message_Level_Debug)
155  ifilename=''
156  ofilename='instlumi.csv'
157  beammode='stable'
158  timeformat=''
159  selectionDict={}
160  if args.authpath and len(args.authpath)!=0:
161  os.environ['CORAL_AUTH_PATH']=args.authpath
162  if args.normfactor:
163  c.NORM=float(args.normfactor)
164  if args.lumiversion:
165  c.LUMIVERSION=args.lumiversion
166  if args.beammode:
167  c.BEAMMODE=args.beammode
168  if args.verbose:
169  c.VERBOSE=True
170  if args.inputfile:
171  ifilename=args.inputfile
172  if args.batch:
173  opicname=args.batch
174  if args.outputfile:
175  ofilename=args.outputfile
176  if args.timeformat:
177  timeformat=args.timeformat
178  session=svc.connect(connectstring,accessMode=coral.access_Update)
179  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
180  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
181  if ifilename:
182  ifparser=inputFilesetParser(ifilename)
183  runsandls=ifparser.runsandls()
184  keylist=runsandls.keys()
185  keylist.sort()
186  for run in keylist:
187  if selectionDict.has_key(run):
188  lslist=runsandls[run]
189  lslist.sort()
190  selectionDict[run]=lslist
191  if args.action == 'run':
192  minRun=int(args.begin)
193  if not args.end:
194  maxRun=minRun
195  else:
196  maxRun=int(args.end)
197  runList=range(minRun,maxRun+1)
198  elif args.action == 'peakperday':
199  session.transaction().start(True)
201  minTime=t.StrToDatetime(args.begin,timeformat)
202  if not args.end:
203  maxTime=datetime.datetime.utcnow() #to now
204  else:
205  maxTime=t.StrToDatetime(args.end,timeformat)
206  #print minTime,maxTime
207  qHandle=session.nominalSchema().newQuery()
208  runDict=lumiQueryAPI.runsByTimerange(qHandle,minTime,maxTime)#xrawdata
209  session.transaction().commit()
210  runList=runDict.keys()
211  del qHandle
212  runList.sort()
213  else:
214  print 'unsupported action ',args.action
215  exit
216  #print 'runList ',runList
217  #print 'runDict ', runDict
218  fig=Figure(figsize=(6,4.5),dpi=100)
220 
221  logfig=Figure(figsize=(6,4.5),dpi=100)
222  mlog=matplotRender.matplotRender(logfig)
223 
224  if args.action == 'peakperday':
226  lumiperls=getInstLumiPerLS(session,c,runList,selectionDict)
227  if args.outputfile:
228  reporter=csvReporter.csvReporter(ofilename)
229  fieldnames=['day','run','lsnum','maxinstlumi']
230  reporter.writeRow(fieldnames)
231  #minDay=minTime.toordinal()
232  #maxDay=maxTime.toordinal()
233  daydict={}#{day:[[run,lsnum,instlumi]]}
234  result={}#{day:[maxrun,maxlsnum,maxinstlumi]}
235  for lsdata in lumiperls:
236  runnumber=lsdata[0]
237  lsnum=lsdata[1]
238  runstarttimeStr=lsdata[-2]#note: it is a string!!
239  startorbit=lsdata[5]
240  deliveredInst=lsdata[2]
241  lsstarttime=l.OrbitToTime(runstarttimeStr,startorbit)
242  day=lsstarttime.toordinal()
243  if not daydict.has_key(day):
244  daydict[day]=[]
245  daydict[day].append([runnumber,lsnum,deliveredInst])
246  days=daydict.keys()
247  days.sort()
248  for day in days:
249  daydata=daydict[day]
250  transposeddata=CommonUtil.transposed(daydata,defaultval=0.0)
251  todaysmaxinst=max(transposeddata[2])
252  todaysmaxidx=transposeddata[2].index(todaysmaxinst)
253  todaysmaxrun=transposeddata[0][todaysmaxidx]
254  todaysmaxls=transposeddata[1][todaysmaxidx]
255  result[day]=[todaysmaxrun,todaysmaxls,todaysmaxinst]
256  if args.outputfile :
257  reporter.writeRow([day,todaysmaxrun,todaysmaxls,todaysmaxinst])
258  m.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale='linear')
259  mlog.plotPeakPerday_Time(result,minTime,maxTime,annotateBoundaryRunnum=args.annotateboundary,yscale='log')
260 
261  if args.action == 'run':
262  runnumber=runList[0]
263  lumiperrun=getLumiPerRun(session,c,runnumber)#[[lsnumber,deliveredInst,recordedInst,norbit,startorbit,fillnum,runstarttime,runstoptime]]
264  #print 'lumiperrun ',lumiperrun
265  xdata=[]#[runnumber,fillnum,norbit,stattime,stoptime,totalls,ncmsls]
266  ydata={}#{label:[instlumi]}
267  ydata['Delivered']=[]
268  ydata['Recorded']=[]
269  norbit=lumiperrun[0][3]
270  fillnum=lumiperrun[0][-3]
271  starttime=lumiperrun[0][-2]
272  stoptime=lumiperrun[0][-1]
273  ncmsls=0
274  totalls=len(lumiperrun)
275  for lsdata in lumiperrun:
276  lsnumber=lsdata[0]
277  if lsnumber!=0:
278  ncmsls+=1
279  deliveredInst=lsdata[1]
280  recordedInst=lsdata[2]
281  ydata['Delivered'].append(deliveredInst)
282  ydata['Recorded'].append(recordedInst)
283  xdata=[runnumber,fillnum,norbit,starttime,stoptime,totalls,ncmsls]
284  m.plotInst_RunLS(xdata,ydata)
285  del session
286  del svc
287  if args.batch and args.yscale=='linear':
288  m.drawPNG(args.batch)
289  elif args.batch and args.yscale=='log':
290  mlog.drawPNG(args.batch)
291  elif args.batch and args.yscale=='both':
292  m.drawPNG(args.batch)
293  basename,extension=os.path.splitext(args.batch)
294  logfilename=basename+'_log'+extension
295  mlog.drawPNG(logfilename)
296  else:
297  raise Exception('unsupported yscale for batch mode : '+args.yscale)
298 
299  if not args.interactive:
300  return
301  if args.interactive is True and args.yscale=='linear':
302  m.drawInteractive()
303  elif args.interactive is True and args.yscale=='log':
304  mlog.drawInteractive()
305  else:
306  raise Exception('unsupported yscale for interactive mode : '+args.yscale)
Definition: start.py:1
def transposed
Definition: CommonUtil.py:52
const T & max(const T &a, const T &b)
def getInstLumiPerLS
Definition: lumiInstPlot.py:17

Variable Documentation

string lumiInstPlot.VERSION = '1.00'

Definition at line 2 of file lumiInstPlot.py.