CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLuminosity/LumiDB/python/queryDataSource.py

Go to the documentation of this file.
00001 import array,coral
00002 from RecoLuminosity.LumiDB import CommonUtil,nameDealer
00003 
00004 def uncalibrateLumi(runnumber,instlumi,instlumierror):
00005     '''
00006     input: runnumber,calibrated instlumi,calibrated instlumierror
00007     output: (uncalibrated instlumi, uncalbrated instlumierror)
00008     '''
00009     normpp7tev=float(6370.0)
00010     normpp900gev=float(16500.0)
00011     normhi7tev=float(2.383)
00012     oldnormpp7tev=float(6330)
00013     if runnumber in [136290,136294,136297,134721,134725]:#900Gev pp runs
00014         return (float(instlumi)/normpp900gev,float(instlumierror)/normpp900gev)
00015     if runnumber >=150431 and runnumber<=153368 :#7TeV HI runs
00016         return (float(instlumi)/normhi7tev,float(instlumierror)/normhi7tev)
00017     return (float(instlumi)/normpp7tev,float(instlumierror)/normpp7tev)
00018     
00019 def uncalibratedlumiFromOldLumi(session,runnumber):
00020     '''
00021     retrieve old lumi value, divide by norm and restore to raw value
00022     select lumilsnum,cmslsnum,instlumi,instlumierror,instlumiquality,startorbit,numorbit,beamenergy,beamstatus,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2 from lumisummary where runnum=:runnumber order by lumilsnum
00023     
00024     select s.lumilsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality from lumidetail d,lumisummary s where d.lumisummary_id=s.lumisummary_id and s.runnum=:runnumber and d.algoname=:algoname order by s.lumilsnum
00025     
00026     output: {lumilsnum:[cmslsnum,uncalibratedinstlumi,uncalibratedinstlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2,bxlumivalue_occ1,bxlumierror_occ1,,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]}]}
00027     dict size ~ 200mb for 1000LS
00028     '''
00029     nTotAlgo=3
00030     try:
00031         datadict={}
00032         session.transaction().start(True)
00033         lumischema=session.nominalSchema()
00034         summaryQuery=lumischema.newQuery()
00035         summaryQuery.addToTableList( nameDealer.lumisummaryTableName() )
00036         summaryQuery.addToOutputList( 'LUMILSNUM','lumilsnum')
00037         summaryQuery.addToOutputList( 'CMSLSNUM','cmslsnum')
00038         summaryQuery.addToOutputList( 'INSTLUMI','instlumi')
00039         summaryQuery.addToOutputList( 'INSTLUMIERROR','instlumierror')
00040         summaryQuery.addToOutputList( 'INSTLUMIQUALITY','instlumiquality')
00041         summaryQuery.addToOutputList( 'BEAMSTATUS','beamstatus')
00042         summaryQuery.addToOutputList( 'BEAMENERGY','beamenergy')        
00043         summaryQuery.addToOutputList( 'NUMORBIT','numorbit')
00044         summaryQuery.addToOutputList( 'STARTORBIT','startorbit')
00045         summaryQuery.addToOutputList( 'CMSBXINDEXBLOB','cmsbxindexblob')
00046         summaryQuery.addToOutputList( 'BEAMINTENSITYBLOB_1','beamintensityblob_1')
00047         summaryQuery.addToOutputList( 'BEAMINTENSITYBLOB_2','beamintensityblob_2')
00048         summaryCondition=coral.AttributeList()
00049         summaryCondition.extend('runnumber','unsigned int')
00050         summaryCondition['runnumber'].setData(int(runnumber))
00051         summaryResult=coral.AttributeList()
00052         summaryResult.extend('lumilsnum','unsigned int')
00053         summaryResult.extend('cmslsnum','unsigned int')
00054         summaryResult.extend('instlumi','float')
00055         summaryResult.extend('instlumierror','float')
00056         summaryResult.extend('instlumiquality','short')
00057         summaryResult.extend('beamstatus','string')
00058         summaryResult.extend('beamenergy','float')
00059         summaryResult.extend('numorbit','unsigned int')
00060         summaryResult.extend('startorbit','unsigned int')
00061         summaryResult.extend('cmsbxindexblob','blob')
00062         summaryResult.extend('beamintensityblob_1','blob')
00063         summaryResult.extend('beamintensityblob_2','blob')
00064         summaryQuery.defineOutput(summaryResult)
00065         summaryQuery.addToOrderList('lumilsnum')
00066         summaryQuery.setCondition('RUNNUM=:runnumber',summaryCondition)
00067         summarycursor=summaryQuery.execute()
00068         while summarycursor.next():
00069             lumilsnum=summarycursor.currentRow()['lumilsnum'].data()
00070             cmslsnum=summarycursor.currentRow()['cmslsnum'].data()
00071             instlumi=summarycursor.currentRow()['instlumi'].data()
00072             instlumierror=summarycursor.currentRow()['instlumierror'].data()
00073             instlumiquality=summarycursor.currentRow()['instlumiquality'].data()
00074             (uncalibratedinstlumi,uncalibratedinstlumierror)=uncalibrateLumi(runnumber,instlumi,instlumierror)
00075             startorbit=summarycursor.currentRow()['startorbit'].data()
00076             numorbit=summarycursor.currentRow()['numorbit'].data()
00077             beamenergy=summarycursor.currentRow()['beamenergy'].data()
00078             beamstatus=summarycursor.currentRow()['beamstatus'].data()
00079             cmsbxindexblob=None
00080             if not summarycursor.currentRow()['cmsbxindexblob'].isNull():
00081                 cmsbxindexblob=summarycursor.currentRow()['cmsbxindexblob'].data()
00082             beamintensityblob_1=None
00083             if not summarycursor.currentRow()['beamintensityblob_1'].isNull():
00084                 beamintensityblob_1=summarycursor.currentRow()['beamintensityblob_1'].data()
00085             beamintensityblob_2=None
00086             if not summarycursor.currentRow()['beamintensityblob_2'].isNull():
00087                 beamintensityblob_2=summarycursor.currentRow()['beamintensityblob_2'].data()
00088             datadict[lumilsnum]=[cmslsnum,uncalibratedinstlumi,uncalibratedinstlumierror,instlumiquality,beamstatus,beamenergy,startorbit,numorbit,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2]
00089         del summaryQuery
00090         #print datadict
00091         for algoname in ['OCC1','OCC2','ET']:
00092             detailQuery=lumischema.newQuery()
00093             detailQuery.addToTableList( nameDealer.lumisummaryTableName(),'s' )
00094             detailQuery.addToTableList( nameDealer.lumidetailTableName(),'d' )
00095             detailQuery.addToOutputList('s.LUMILSNUM','lumilsnum' )
00096             detailQuery.addToOutputList('d.BXLUMIVALUE','bxlumivalue' )
00097             detailQuery.addToOutputList('d.BXLUMIERROR','bxlumierror' )
00098             detailQuery.addToOutputList('d.BXLUMIQUALITY','bxlumiquality' )
00099             detailCondition=coral.AttributeList()
00100             detailCondition.extend('runnumber','unsigned int')
00101             detailCondition.extend('algoname','string')
00102             detailCondition['runnumber'].setData(int(runnumber))
00103             detailCondition['algoname'].setData(algoname)
00104             detailResult=coral.AttributeList()
00105             detailResult.extend('lumilsnum','unsigned int')
00106             detailResult.extend('bxlumivalue','blob')
00107             detailResult.extend('bxlumierror','blob')
00108             detailResult.extend('bxlumiquality','blob')
00109             detailQuery.defineOutput(detailResult)
00110             detailQuery.addToOrderList('lumilsnum')
00111             detailQuery.setCondition('s.RUNNUM=:runnumber AND s.LUMISUMMARY_ID=d.LUMISUMMARY_ID AND d.ALGONAME=:algoname',detailCondition)
00112             detailcursor=detailQuery.execute()
00113             while detailcursor.next():
00114                 lumilsnum=detailcursor.currentRow()['lumilsnum'].data()
00115                 bxlumivalue=detailcursor.currentRow()['bxlumivalue'].data()
00116                 bxlumierror=detailcursor.currentRow()['bxlumierror'].data()
00117                 bxlumiquality=detailcursor.currentRow()['bxlumiquality'].data()
00118                 datadict[lumilsnum].extend([bxlumivalue,bxlumierror,bxlumiquality])
00119             del detailQuery
00120         session.transaction().commit()
00121         return datadict
00122     except :
00123         raise     
00124 def hltFromOldLumi(session,runnumber):
00125     '''
00126     select count(distinct pathname) from hlt where runnum=:runnum
00127     select cmslsnum,pathname,inputcount,acceptcount,prescale from hlt where runnum=:runnum order by cmslsnum,pathname
00128     [pathnames,databuffer]
00129     databuffer: {cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}
00130     '''
00131     try:
00132         databuffer={}
00133         session.transaction().start(True)
00134         lumischema=session.nominalSchema()
00135         npath=0
00136         qHandle=lumischema.newQuery()
00137         qHandle.addToTableList( nameDealer.hltTableName() )
00138         qHandle.addToOutputList('COUNT(DISTINCT PATHNAME)','npath')
00139         qCondition=coral.AttributeList()
00140         qCondition.extend('runnum','unsigned int')
00141         qCondition['runnum'].setData(int(runnumber))
00142         qResult=coral.AttributeList()
00143         qResult.extend('npath','unsigned int')
00144         qHandle.defineOutput(qResult)
00145         qHandle.setCondition('RUNNUM=:runnum',qCondition)
00146         cursor=qHandle.execute()
00147         while cursor.next():
00148             npath=cursor.currentRow()['npath'].data()
00149         del qHandle
00150         #print 'npath ',npath
00151 
00152         qHandle=lumischema.newQuery()
00153         qHandle.addToTableList( nameDealer.hltTableName() )
00154         qHandle.addToOutputList('CMSLSNUM','cmslsnum')
00155         qHandle.addToOutputList('PATHNAME','pathname')
00156         qHandle.addToOutputList('INPUTCOUNT','inputcount')
00157         qHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
00158         qHandle.addToOutputList('PRESCALE','prescale')
00159         qCondition=coral.AttributeList()
00160         qCondition.extend('runnum','unsigned int')
00161         qCondition['runnum'].setData(int(runnumber))
00162         qResult=coral.AttributeList()
00163         qResult.extend('cmslsnum','unsigned int')
00164         qResult.extend('pathname','string')
00165         qResult.extend('inputcount','unsigned int')
00166         qResult.extend('acceptcount','unsigned int')
00167         qResult.extend('prescale','unsigned int')
00168         qHandle.defineOutput(qResult)
00169         qHandle.setCondition('RUNNUM=:runnum',qCondition)
00170         qHandle.addToOrderList('cmslsnum')
00171         qHandle.addToOrderList('pathname')
00172         cursor=qHandle.execute()
00173         pathnameList=[]
00174         inputcountArray=array.array('l')
00175         acceptcountArray=array.array('l')
00176         prescaleArray=array.array('l')
00177         ipath=0
00178         pathnHLT_PixelTracksVdMames=''
00179         while cursor.next():
00180             cmslsnum=cursor.currentRow()['cmslsnum'].data()
00181             pathname=cursor.currentRow()['pathname'].data()
00182             ipath+=1
00183             inputcount=cursor.currentRow()['inputcount'].data()
00184             acceptcount=cursor.currentRow()['acceptcount'].data()
00185             prescale=cursor.currentRow()['prescale'].data()
00186             pathnameList.append(pathname)
00187             inputcountArray.append(inputcount)
00188             acceptcountArray.append(acceptcount)
00189             prescaleArray.append(prescale)
00190             if ipath==npath:
00191                 if cmslsnum==1:
00192                     pathnames=','.join(pathnameList)
00193                 inputcountBlob=CommonUtil.packArraytoBlob(inputcountArray)
00194                 acceptcountBlob=CommonUtil.packArraytoBlob(acceptcountArray)
00195                 prescaleBlob=CommonUtil.packArraytoBlob(prescaleArray)
00196                 databuffer[cmslsnum]=[inputcountBlob,acceptcountBlob,prescaleBlob]
00197                 pathnameList=[]
00198                 inputcountArray=array.array('l')
00199                 acceptcountArray=array.array('l')
00200                 prescaleArray=array.array('l')
00201                 ipath=0
00202         del qHandle
00203         session.transaction().commit()
00204         #print 'pathnames ',pathnames
00205         return [pathnames,databuffer]
00206     except :
00207         raise 
00208 
00209 def trgFromOldLumi(session,runnumber):
00210     '''
00211     select bitnum,bitname from trg where runnum=:runnumber and cmslsnum=1 order by bitnum
00212     select cmslsnum,deadtime,trgcount,prescale from trg where bitnum=:bitnum and runnum=:runnumber 
00213     input: runnumber
00214     output: [bitnames,{cmslsnum,[deadtime,bitzerocount,bitzerpoprescale,trgcountBlob,trgprescaleBlob]}]
00215     '''
00216     session.transaction().start(True)
00217     lumischema=session.nominalSchema()
00218     qHandle=lumischema.newQuery()
00219     try:
00220         qHandle=lumischema.newQuery()
00221         qHandle.addToTableList(nameDealer.trgTableName())
00222         qHandle.addToOutputList('BITNUM','bitnum')
00223         qHandle.addToOutputList('BITNAME','bitname')
00224         qCondition=coral.AttributeList()
00225         qCondition.extend('runnum','unsigned int')
00226         qCondition['runnum'].setData(int(runnumber))
00227         qCondition.extend('cmslsnum','unsigned int')
00228         qCondition['cmslsnum'].setData(int(1))
00229         qResult=coral.AttributeList()
00230         qResult.extend('bitnum','unsigned int')
00231         qResult.extend('bitname','string')
00232         qHandle.defineOutput(qResult)
00233         qHandle.setCondition('RUNNUM=:runnum AND CMSLSNUM=:cmslsnum',qCondition)
00234         qHandle.addToOrderList('BITNUM')
00235         cursor=qHandle.execute()
00236         bitnums=[]
00237         bitnameList=[]
00238         while cursor.next():
00239             bitnum=cursor.currentRow()['bitnum'].data()
00240             bitname=cursor.currentRow()['bitname'].data()
00241             bitnums.append(bitnum)
00242             bitnameList.append(bitname)
00243         del qHandle
00244         bitnames=','.join(bitnameList)
00245         databuffer={}
00246         nbits=len(bitnums)
00247         qHandle=lumischema.newQuery()
00248         qHandle.addToTableList(nameDealer.trgTableName())
00249         qHandle.addToOutputList('CMSLSNUM','cmslsnum')
00250         qHandle.addToOutputList('BITNUM','bitnum')
00251         qHandle.addToOutputList('DEADTIME','deadtime')
00252         qHandle.addToOutputList('TRGCOUNT','trgcount')
00253         qHandle.addToOutputList('PRESCALE','prescale')
00254         qCondition=coral.AttributeList()
00255         qCondition.extend('runnum','unsigned int')
00256         qCondition['runnum'].setData(int(runnumber))
00257         qResult=coral.AttributeList()
00258         qResult.extend('cmslsnum','unsigned int')
00259         qResult.extend('bitnum','unsigned int')
00260         qResult.extend('deadtime','unsigned long long')
00261         qResult.extend('trgcount','unsigned int')
00262         qResult.extend('prescale','unsigned int')
00263         qHandle.defineOutput(qResult)
00264         qHandle.setCondition('RUNNUM=:runnum',qCondition)
00265         qHandle.addToOrderList('CMSLSNUM')
00266         qHandle.addToOrderList('BITNUM')
00267         cursor=qHandle.execute()
00268         trgcountArray=array.array('l')
00269         prescaleArray=array.array('l')
00270         while cursor.next():
00271             cmslsnum=cursor.currentRow()['cmslsnum'].data()
00272             bitnum=cursor.currentRow()['bitnum'].data()
00273             deadtime=cursor.currentRow()['deadtime'].data()
00274             trgcount=cursor.currentRow()['trgcount'].data()
00275             prescale=cursor.currentRow()['prescale'].data()
00276             if not databuffer.has_key(cmslsnum):
00277                 databuffer[cmslsnum]=[]
00278                 databuffer[cmslsnum].append(deadtime)
00279             if bitnum==0:
00280                 databuffer[cmslsnum].append(trgcount)
00281                 databuffer[cmslsnum].append(prescale)
00282             trgcountArray.append(trgcount)
00283             prescaleArray.append(prescale)
00284             if bitnum==nbits-1:
00285                 trgcountBlob=CommonUtil.packArraytoBlob(trgcountArray)
00286                 prescaleBlob=CommonUtil.packArraytoBlob(prescaleArray)
00287                 databuffer[cmslsnum].append(trgcountBlob)
00288                 databuffer[cmslsnum].append(prescaleBlob)
00289                 trgcountArray=array.array('l')
00290                 prescaleArray=array.array('l')
00291         del qHandle            
00292         session.transaction().commit()
00293         return [bitnames,databuffer]
00294     except:
00295         del qHandle
00296         raise
00297 
00298 def trgFromWBM(session,runnumber):
00299     '''
00300     '''
00301     pass
00302 
00303 def trgFromNewGT(session,runnumber):
00304     '''
00305     select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
00306     select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
00307     select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
00308     select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber order by algo_index
00309     select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber order by techtrig_index
00310     select prescale_factor_algo_000,prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where runnr=:runnumber and prescale_index=0;
00311     select prescale_factor_tt_000,prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where runnr=:runnumber and prescale_index=0;
00312     '''
00313     pass
00314 
00315 def trgFromOldGT(session,runnumber):
00316     '''
00317     input: runnumber
00318     output: [bitnameclob,{cmslsnum:[deadtime,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]}]
00319     1. select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
00320     2. select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
00321     3. select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
00322     4. select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber order by algo_index
00323     ## not needed5. select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber order by techtrig_index
00324     5  select distinct(prescale_index)  from cms_gt_mon.lumi_sections where run_number=:runnumber;
00325     6. select prescale_factor_algo_000,algo.prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where prescale_index=:prescale_index and runnr=:runnumber;
00326     7. select prescale_factor_tt_000,tech.prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where prescale_index=:prescale_index and runnr=:runnumber;
00327     8. select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber order by lumi_section
00328     
00329     '''
00330     result=[]
00331     deadtimeresult={}#{cmslsnum:deadtime}
00332     NAlgoBit=128 #0-127
00333     NTechBit=64  #0-63
00334     algocount={}#{cmslsnum:[algocounts]}
00335     techcount={}#{cmslsnum:[techcounts]}
00336     bitnames=[]
00337     bitzerocountDict={}
00338     bitzeroprescaleDict={}
00339     perlsdict={}#{cmslsnum:[deadtime,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]}
00340     prescaleDict={} #{prescale_index:[[algo_prescale_factors][tech_prescale_factors]]}
00341     prescaleResult={}#{lsnumber:[algo_prescale_factors,tech_prescale_factors]}
00342     try:
00343         session.transaction().start(True)
00344         gtmonschema=session.schema('CMS_GT_MON')
00345         #
00346         # select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
00347         #
00348         deadviewQuery=gtmonschema.newQuery()
00349         deadviewQuery.addToTableList('GT_MON_TRIG_DEAD_VIEW')
00350         deadOutput=coral.AttributeList()
00351         deadOutput.extend('counts','unsigned int')
00352         deadOutput.extend('lsnr','unsigned int')
00353         deadviewQuery.addToOutputList('counts')
00354         deadviewQuery.addToOutputList('lsnr')
00355         bindVariablesDead=coral.AttributeList()
00356         bindVariablesDead.extend('runnumber','int')
00357         bindVariablesDead.extend('countername','string')
00358         bindVariablesDead['runnumber'].setData(int(runnumber))
00359         bindVariablesDead['countername'].setData('DeadtimeBeamActive')
00360         deadviewQuery.setCondition('RUNNR=:runnumber AND DEADCOUNTER=:countername',bindVariablesDead)
00361         deadviewQuery.addToOrderList('lsnr')
00362         deadviewQuery.defineOutput(deadOutput)
00363         deadcursor=deadviewQuery.execute()
00364         s=0
00365         while deadcursor.next():
00366             row=deadcursor.currentRow()
00367             s+=1
00368             lsnr=row['lsnr'].data()
00369             while s!=lsnr:
00370                 print 'DEADTIME alert: found hole in LS range'
00371                 print '         fill deadtimebeamactive 0 for LS '+str(s)
00372                 deadtimeresult[s]=0
00373                 s+=1
00374             count=row['counts'].data()
00375             deadtimeresult[s]=count
00376         if s==0:
00377             deadcursor.close()
00378             del deadviewQuery
00379             session.transaction().commit()
00380             raise 'requested run '+str(runnumber )+' does not exist for deadcounts'
00381         del deadviewQuery
00382         #print 'deadtimeresult ',deadtimeresult
00383         mybitcount_algo=[]
00384         algoviewQuery=gtmonschema.newQuery()
00385         #
00386         # select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
00387         #
00388         algoviewQuery.addToTableList('GT_MON_TRIG_ALGO_VIEW')
00389         algoOutput=coral.AttributeList()
00390         algoOutput.extend('counts','unsigned int')
00391         algoOutput.extend('lsnr','unsigned int')
00392         algoOutput.extend('algobit','unsigned int')
00393         algoviewQuery.addToOutputList('counts')
00394         algoviewQuery.addToOutputList('lsnr')
00395         algoviewQuery.addToOutputList('algobit')
00396         algoCondition=coral.AttributeList()
00397         algoCondition.extend('runnumber','unsigned int')
00398         algoCondition['runnumber'].setData(int(runnumber))
00399         algoviewQuery.setCondition('RUNNR=:runnumber',algoCondition)
00400         algoviewQuery.addToOrderList('lsnr')
00401         algoviewQuery.addToOrderList('algobit')
00402         algoviewQuery.defineOutput(algoOutput)
00403       
00404         algocursor=algoviewQuery.execute()
00405         s=0
00406         while algocursor.next():
00407             row=algocursor.currentRow()
00408             lsnr=row['lsnr'].data()
00409             counts=row['counts'].data()
00410             algobit=row['algobit'].data()
00411             mybitcount_algo.append(counts)
00412             if algobit==0:
00413                 bitzerocountDict[lsnr]=counts
00414             if algobit==NAlgoBit-1:
00415                 s+=1
00416                 while s!=lsnr:
00417                     print 'ALGO COUNT alert: found hole in LS range'
00418                     print '     fill all algocount 0 for LS '+str(s)
00419                     tmpzero=[0]*NAlgoBit
00420                     algocount[s]=tmpzero
00421                     s+=1
00422                 algocount[s]=mybitcount_algo
00423                 mybitcount_algo=[]
00424         if s==0:
00425             algocursor.close()
00426             del algoviewQuery
00427             session.transaction().commit()
00428             raise 'requested run '+str(runnumber+' does not exist for algocounts ')
00429         del algoviewQuery
00430                 
00431         mybitcount_tech=[]
00432         techviewQuery=gtmonschema.newQuery()
00433         techviewQuery.addToTableList('GT_MON_TRIG_TECH_VIEW')
00434         #
00435         # select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
00436         #
00437         techOutput=coral.AttributeList()
00438         techOutput.extend('counts','unsigned int')
00439         techOutput.extend('lsnr','unsigned int')
00440         techOutput.extend('techbit','unsigned int')
00441         techviewQuery.addToOutputList('COUNTS','counts')
00442         techviewQuery.addToOutputList('LSNR','lsnr')
00443         techviewQuery.addToOutputList('TECHBIT','techbit')
00444         techCondition=coral.AttributeList()
00445         techCondition.extend('runnumber','unsigned int')
00446         techCondition['runnumber'].setData(int(runnumber))
00447         techviewQuery.setCondition('RUNNR=:runnumber',techCondition)
00448         techviewQuery.addToOrderList('lsnr')
00449         techviewQuery.addToOrderList('techbit')
00450         techviewQuery.defineOutput(techOutput)
00451       
00452         techcursor=techviewQuery.execute()
00453         s=0
00454         while techcursor.next():
00455             row=techcursor.currentRow()
00456             lsnr=row['lsnr'].data()
00457             counts=row['counts'].data()
00458             techbit=row['techbit'].data()
00459             mybitcount_tech.append(counts)
00460             if techbit==NTechBit-1:
00461                 s+=1
00462                 while s!=lsnr:
00463                     print 'TECH COUNT alert: found hole in LS range'
00464                     print '     fill all techcount 0 for LS '+str(s)
00465                     tmpzero=[0]*NTechBit
00466                     techcount[s]=tmpzero
00467                     s+=1
00468                 techcount[s]=mybitcount_tech
00469                 mybitcount_tech=[]
00470         if s==0:
00471             techcursor.close()
00472             del techviewQuery
00473             session.transaction().commit()
00474             raise 'requested run '+str(runnumber+' does not exist for techcounts ')
00475         del techviewQuery
00476 
00477         gtschema=session.schema('CMS_GT')
00478         triggernamemap={}
00479         namealiasQuery=gtschema.newQuery()
00480         #
00481         # select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber 
00482         #
00483         triggernamemap={}
00484         namealiasQuery.addToTableList('GT_RUN_ALGO_VIEW')
00485         algonameOutput=coral.AttributeList()
00486         algonameOutput.extend('algo_index','unsigned int')
00487         algonameOutput.extend('alias','string')
00488         namealiasQuery.addToOutputList('algo_index')
00489         namealiasQuery.addToOutputList('alias')
00490         algonameCondition=coral.AttributeList()
00491         algonameCondition.extend('runnumber','unsigned int')
00492         algonameCondition['runnumber'].setData(int(runnumber))
00493         namealiasQuery.setCondition('RUNNUMBER=:runnumber',algonameCondition)
00494         namealiasQuery.defineOutput(algonameOutput)
00495         algonamecursor=namealiasQuery.execute()
00496         while algonamecursor.next():
00497             row=algonamecursor.currentRow()
00498             algo_index=row['algo_index'].data()
00499             algo_name=row['alias'].data()
00500             triggernamemap[algo_index]=algo_name
00501         del namealiasQuery
00502 
00503         #techtriggernamemap={}
00504         #technamealiasQuery=gtschema.newQuery()
00505         #
00506         # select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber
00507         #
00508         # this queryis unnecessary
00509         #technamealiasQuery.addToTableList('GT_RUN_TECH_VIEW')
00510         #technameOutput=coral.AttributeList()
00511         #technameOutput.extend('techtrig_index','unsigned int')
00512         #technameOutput.extend('name','string')
00513         #technamealiasQuery.addToOutputList('techtrig_index')
00514         #technamealiasQuery.addToOutputList('name')
00515         #technameCondition=coral.AttributeList()
00516         #technameCondition.extend('runnumber','unsigned int')
00517         #technameCondition['runnumber'].setData(int(runnumber))
00518         #technamealiasQuery.setCondition('RUNNUMBER=:runnumber',technameCondition)
00519         #technamealiasQuery.defineOutput(technameOutput)
00520         #technamecursor=technamealiasQuery.execute()
00521         #while technamecursor.next():
00522             #row=technamecursor.currentRow()
00523             #techtrig_index=row['techtrig_index'].data()
00524             #tech_name=row['name'].data()
00525             #techtriggernamemap[techtrig_index]=tech_name
00526         #del technamealiasQuery
00527         #
00528         # reprocess Algo name result filling unallocated trigger bit with string "False"
00529         #
00530         for algoidx in range(NAlgoBit):
00531             if algoidx in triggernamemap.keys():
00532                 bitnames.append(triggernamemap[algoidx])
00533             else:
00534                 bitnames.append('False')
00535         #
00536         # reprocess Tech name 
00537         #
00538         for techidx in range(NTechBit):
00539              bitnames.append(str(techidx))
00540         bitnameclob=','.join(bitnames)     
00541         #
00542         # select distinct(prescale_index) from cms_gt_mon.lumi_sections where run_number=:runnumber;
00543         #
00544         prescaleidx=[]
00545         presidxQuery=gtmonschema.newQuery()
00546         presidxQuery.addToTableList('LUMI_SECTIONS')
00547         
00548         presidxBindVariable=coral.AttributeList()
00549         presidxBindVariable.extend('runnumber','int')
00550         presidxBindVariable['runnumber'].setData(int(runnumber))
00551 
00552         presidxOutput=coral.AttributeList()
00553         presidxOutput.extend('prescale_index','int')
00554         presidxQuery.addToOutputList('distinct(PRESCALE_INDEX)','prescale_index')
00555         presidxQuery.defineOutput(presidxOutput)
00556         presidxQuery.setCondition('RUN_NUMBER=:runnumber',presidxBindVariable)
00557         presidxCursor=presidxQuery.execute()
00558         while presidxCursor.next():
00559             presc=presidxCursor.currentRow()['prescale_index'].data()
00560             prescaleidx.append(presc)
00561         #print prescaleidx
00562         del presidxQuery
00563         #
00564         # select algo.prescale_factor_algo_000,,algo.prescale_factor_algo_001..._127 from gt_run_presc_algo_view where run_number=:runnumber and prescale_index=:prescale_index;
00565         #
00566         for prescaleindex in prescaleidx:
00567             algoprescQuery=gtschema.newQuery()
00568             algoprescQuery.addToTableList('GT_RUN_PRESC_ALGO_VIEW')
00569             algoPrescOutput=coral.AttributeList()
00570             algoprescBase='PRESCALE_FACTOR_ALGO_'
00571             for bitidx in range(NAlgoBit):
00572                 algopresc=algoprescBase+str(bitidx).zfill(3)
00573                 algoPrescOutput.extend(algopresc,'unsigned int')
00574                 algoprescQuery.addToOutputList(algopresc)
00575             PrescbindVariable=coral.AttributeList()
00576             PrescbindVariable.extend('runnumber','int')
00577             PrescbindVariable.extend('prescaleindex','int')
00578             PrescbindVariable['runnumber'].setData(int(runnumber))
00579             PrescbindVariable['prescaleindex'].setData(prescaleindex)
00580             algoprescQuery.setCondition('RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex',PrescbindVariable)
00581             algoprescQuery.defineOutput(algoPrescOutput)
00582             algopresccursor=algoprescQuery.execute()
00583             while algopresccursor.next():
00584                 row=algopresccursor.currentRow()
00585                 algoprescale=[]
00586                 for bitidx in range(NAlgoBit):
00587                     algopresc=algoprescBase+str(bitidx).zfill(3)
00588                     algoprescale.append(row[algopresc].data())
00589                 prescaleDict[prescaleindex]=algoprescale
00590             del algoprescQuery
00591 
00592         #
00593         # select prescale_factor_tt_000,prescale_factor_tt_001..._127 from gt_run_presc_tech_view where run_number=:runnumber and prescale_index=:prescale_index;
00594         #
00595         for prescaleindex in prescaleidx:
00596             techprescQuery=gtschema.newQuery()
00597             techprescQuery.addToTableList('GT_RUN_PRESC_TECH_VIEW')
00598             techPrescOutput=coral.AttributeList()
00599             techprescBase='PRESCALE_FACTOR_TT_'
00600             for bitidx in range(NTechBit):
00601                 techpresc=techprescBase+str(bitidx).zfill(3)
00602                 techPrescOutput.extend(techpresc,'unsigned int')
00603                 techprescQuery.addToOutputList(techpresc)
00604             PrescbindVariable=coral.AttributeList()
00605             PrescbindVariable.extend('runnumber','int')
00606             PrescbindVariable.extend('prescaleindex','int')
00607             PrescbindVariable['runnumber'].setData(int(runnumber))
00608             PrescbindVariable['prescaleindex'].setData(prescaleindex)
00609             techprescQuery.setCondition('RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex',PrescbindVariable)
00610             techprescQuery.defineOutput(techPrescOutput)
00611             techpresccursor=techprescQuery.execute()
00612             while techpresccursor.next():
00613                 row=techpresccursor.currentRow()
00614                 techprescale=[]
00615                 for bitidx in range(NTechBit):
00616                     techpresc=techprescBase+str(bitidx).zfill(3)
00617                     techprescale.append(row[techpresc].data())
00618                 prescaleDict[prescaleindex]+=techprescale
00619             del techprescQuery
00620         #print prescaleDict
00621         #
00622         #select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber
00623         #
00624         lumiprescQuery=gtmonschema.newQuery()
00625         lumiprescQuery.addToTableList('LUMI_SECTIONS')
00626         
00627         lumiprescBindVariable=coral.AttributeList()
00628         lumiprescBindVariable.extend('runnumber','int')
00629         lumiprescBindVariable['runnumber'].setData(int(runnumber))
00630 
00631         lumiprescOutput=coral.AttributeList()
00632         lumiprescOutput.extend('lumisection','int')
00633         lumiprescOutput.extend('prescale_index','int')
00634         lumiprescQuery.addToOutputList('LUMI_SECTION')
00635         lumiprescQuery.addToOutputList('PRESCALE_INDEX')
00636         lumiprescQuery.defineOutput(lumiprescOutput)
00637         lumiprescQuery.setCondition('RUN_NUMBER=:runnumber',lumiprescBindVariable)
00638         lumiprescCursor=lumiprescQuery.execute()
00639         while lumiprescCursor.next():
00640             row=lumiprescCursor.currentRow()
00641             lumisection=row['lumisection'].data()
00642             psindex=row['prescale_index'].data()
00643             bitzeroprescale=prescaleDict[psindex][0]
00644             bitzeroprescaleDict[lumisection]=prescaleDict[psindex][0]
00645             prescaleResult[lumisection]=prescaleDict[psindex]
00646         #print prescaleResult
00647         del lumiprescQuery
00648         #return result
00649         session.transaction().commit()
00650         #
00651         #assemble result
00652         #
00653         for cmslsnum,deadcount in deadtimeresult.items():
00654             bitzerocount=bitzerocountDict[cmslsnum]
00655             bitzeroprescale=bitzeroprescaleDict[cmslsnum]
00656             trgcounts=array.array('l')
00657             for acounts in algocount[cmslsnum]:
00658                 trgcounts.append(acounts)
00659             for tcounts in techcount[cmslsnum]:
00660                 trgcounts.append(tcounts)
00661             trgcountBlob=CommonUtil.packArraytoBlob(trgcounts)
00662             trgprescale=array.array('l')
00663             for aprescale in prescaleResult[cmslsnum]:
00664                 trgprescale.append(aprescale)
00665             trgprescaleBlob=CommonUtil.packArraytoBlob(trgprescale)
00666             perlsdict[cmslsnum]=[deadcount,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]
00667         result=[bitnameclob,perlsdict]
00668         return result
00669     except:
00670         session.transaction().rollback()
00671         del session
00672         raise
00673     
00674 def hltFromRuninfoV2(session,runnumber):
00675     '''
00676     input:
00677     output: [pathnameclob,{cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}]
00678     select count(distinct PATHNAME) as npath from HLT_SUPERVISOR_LUMISECTIONS_V2 where runnr=:runnumber and lsnumber=1;
00679     select l.pathname,l.lsnumber,l.l1pass,l.paccept,m.psvalue from hlt_supervisor_lumisections_v2 l,hlt_supervisor_scalar_map m where l.runnr=m.runnr and l.psindex=m.psindex and l.pathname=m.pathname and l.runnr=:runnumber order by l.lsnumber
00680     '''
00681     npaths=0
00682     pathnames=[]
00683     hltdict={}
00684     try:
00685         session.transaction().start(True)
00686         hltschema=session.schema('CMS_RUNINFO')
00687         bvar=coral.AttributeList()
00688         bvar.extend('runnumber','unsigned int')
00689         bvar.extend('lsnumber','unsigned int')
00690         bvar['runnumber'].setData(int(runnumber))
00691         bvar['lsnumber'].setData(1)
00692         q1=hltschema.newQuery()
00693         q1.addToTableList('HLT_SUPERVISOR_LUMISECTIONS_V2')
00694         nls=coral.AttributeList()
00695         nls.extend('npath','unsigned int')
00696         q1.addToOutputList('count(distinct PATHNAME)','npath')
00697         q1.setCondition('RUNNR=:runnumber AND LSNUMBER=:lsnumber',bvar)
00698         q1.defineOutput(nls)
00699         c=q1.execute()
00700         while c.next():
00701             npath=c.currentRow()['npath'].data()
00702         del q1
00703         if npath==0:
00704             print 'request run is empty, do nothing'
00705             
00706         q=hltschema.newQuery()
00707         bindVar=coral.AttributeList()
00708         bindVar.extend('runnumber','unsigned int')
00709         bindVar['runnumber'].setData(int(runnumber))
00710         q.addToTableList('HLT_SUPERVISOR_LUMISECTIONS_V2','l')
00711         q.addToTableList('HLT_SUPERVISOR_SCALAR_MAP','m')
00712         q.addToOutputList('l.LSNUMBER','lsnumber')
00713         q.addToOutputList('l.PATHNAME','pathname')
00714         q.addToOutputList('l.L1PASS','hltinput')
00715         q.addToOutputList('l.PACCEPT','hltaccept')
00716         q.addToOutputList('m.PSVALUE','prescale')
00717         q.setCondition('l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR=:runnumber',bindVar)
00718         q.addToOrderList('l.LSNUMBER')
00719         q.addToOrderList('l.PATHNAME')
00720         q.setRowCacheSize(10692)
00721         cursor=q.execute()
00722         lastLumiSection=1
00723         currentLumiSection=0
00724         allpaths=[]
00725         ipath=0
00726         hltinputs=array.array('l')
00727         hltaccepts=array.array('l')
00728         prescales=array.array('l')
00729         while cursor.next():
00730             row=cursor.currentRow()
00731             cmsluminr=row['lsnumber'].data()
00732             hltinput=row['hltinput'].data()
00733             hltaccept=row['hltaccept'].data()
00734             prescale=row['prescale'].data()
00735             pathname=row['pathname'].data()
00736             ipath+=1
00737             if cmsluminr==1:
00738                 pathnames.append(pathname)
00739             if not hltdict.has_key(cmsluminr):
00740                 hltdict[cmsluminr]=[]
00741             hltinputs.append(hltinput)
00742             hltaccepts.append(hltaccept)
00743             prescales.append(prescale)
00744             if ipath==npath:
00745                 #pack
00746                 #print 'packing hltinputs ',hltinputs
00747                 hltinputsBlob=CommonUtil.packArraytoBlob(hltinputs)
00748                 #print 'packing hltaccepts ',hltaccepts
00749                 hltacceptsBlob=CommonUtil.packArraytoBlob(hltaccepts)
00750                 #print 'packing prescales ',prescales
00751                 prescalesBlob=CommonUtil.packArraytoBlob(prescales)
00752                 hltdict[cmsluminr].extend([hltinputsBlob,hltacceptsBlob,hltacceptsBlob])
00753                 ipath=0
00754                 hltinputs=array.array('l')
00755                 hltaccepts=array.array('l')
00756                 prescales=array.array('l')
00757         pathnameclob=','.join(pathnames)  
00758         del q
00759         session.transaction().commit()
00760         return [pathnameclob,hltdict]
00761     except:
00762         raise
00763 
00764 def hltFromRuninfoV3(session,runnumber):
00765     '''
00766     input:
00767     output: [datasource,pathnameclob,{cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}]
00768     select distinct(pathid) from HLT_SUPERVISOR_TRIGGERPATHS where runnnumber=:runnumber;
00769     select count(*) from HLT_SUPERVISOR_LUMISECTIONS_V3 where runnumber=:runnumber;//total ls
00770     select tr.runnumber,tr.lsnumber,tr.pathid,tr.l1pass,tr.paccept,ls.psindex,sm.psvalue from hlt_supervisor_triggerpaths tr,hlt_supervisor_lumisections_v3 ls,hlt_supervisor_scalar_map_v2 sm where tr.runnumber=ls.runnumber and tr.lsnumber=ls.lsnumber and sm.runnumber=tr.runnumber and sm.pathid=tr.pathid and sm.psindex=ls.psindex and tr.runnumber=:runnumber order by tr.lsnumber;
00771     loop :
00772           select pathname from cms_hlt.paths where pathid=:pathid
00773     '''
00774     pass
00775 
00776 def hltconf(session,hltkey):
00777     '''
00778     select paths.pathid,paths.name,stringparamvalues.value from stringparamvalues,paths,parameters,superidparameterassoc,modules,moduletemplates,pathmoduleassoc,configurationpathassoc,configurations where parameters.paramid=stringparamvalues.paramid and  superidparameterassoc.paramid=parameters.paramid and modules.superid=superidparameterassoc.superid and moduletemplates.superid=modules.templateid and pathmoduleassoc.moduleid=modules.superid and paths.pathid=pathmoduleassoc.pathid and configurationpathassoc.pathid=paths.pathid and configurations.configid=configurationpathassoc.configid and moduletemplates.name='HLTLevel1GTSeed' and parameters.name='L1SeedsLogicalExpression' and configurations.configdescriptor=:hlt_description;
00779     select paths.pathid,paths.name,stringparamvalues.value from stringparamvalues,paths,parameters,superidparameterassoc,modules,moduletemplates,pathmoduleassoc,configurationpathassoc,configurations where parameters.paramid=stringparamvalues.paramid and  superidparameterassoc.paramid=parameters.paramid and modules.superid=superidparameterassoc.superid and moduletemplates.superid=modules.templateid and pathmoduleassoc.moduleid=modules.superid and paths.pathid=pathmoduleassoc.pathid and configurationpathassoc.pathid=paths.pathid and configurations.configid=configurationpathassoc.configid and moduletemplates.name='HLTLevel1GTSeed' and parameters.name='L1SeedsLogicalExpression' and configurations.configid=:hlt_numkey;
00780     ##select paths.pathid from cms_hlt.paths paths,cms_hlt.configurations config where config.configdescriptor=' ' and name=:pathname
00781     '''
00782     try:
00783         session.transaction().start(True)
00784         hltconfschema=session.nominalSchema()
00785         hltconfQuery=hltconfschema.newQuery()
00786 
00787         hltconfQuery.addToOutputList('PATHS.NAME','hltpath')
00788         hltconfQuery.addToOutputList('STRINGPARAMVALUES.VALUE','l1expression')
00789                 
00790         hltconfQuery.addToTableList('PATHS')
00791         hltconfQuery.addToTableList('STRINGPARAMVALUES')
00792         hltconfQuery.addToTableList('PARAMETERS')
00793         hltconfQuery.addToTableList('SUPERIDPARAMETERASSOC')
00794         hltconfQuery.addToTableList('MODULES')
00795         hltconfQuery.addToTableList('MODULETEMPLATES')
00796         hltconfQuery.addToTableList('PATHMODULEASSOC')
00797         hltconfQuery.addToTableList('CONFIGURATIONPATHASSOC')
00798         hltconfQuery.addToTableList('CONFIGURATIONS')
00799 
00800         hltconfBindVar=coral.AttributeList()
00801         hltconfBindVar.extend('hltseed','string')
00802         hltconfBindVar.extend('l1seedexpr','string')
00803         hltconfBindVar.extend('hltkey','string')
00804         hltconfBindVar['hltseed'].setData('HLTLevel1GTSeed')
00805         hltconfBindVar['l1seedexpr'].setData('L1SeedsLogicalExpression')
00806         hltconfBindVar['hltkey'].setData(hltkey)
00807         hltconfQuery.setCondition('PARAMETERS.PARAMID=STRINGPARAMVALUES.PARAMID AND SUPERIDPARAMETERASSOC.PARAMID=PARAMETERS.PARAMID AND MODULES.SUPERID=SUPERIDPARAMETERASSOC.SUPERID AND MODULETEMPLATES.SUPERID=MODULES.TEMPLATEID AND PATHMODULEASSOC.MODULEID=MODULES.SUPERID AND PATHS.PATHID=PATHMODULEASSOC.PATHID AND CONFIGURATIONPATHASSOC.PATHID=PATHS.PATHID AND CONFIGURATIONS.CONFIGID=CONFIGURATIONPATHASSOC.CONFIGID AND MODULETEMPLATES.NAME=:hltseed AND PARAMETERS.NAME=:l1seedexpr AND CONFIGURATIONS.CONFIGDESCRIPTOR=:hltkey',hltconfBindVar)
00808         hlt2l1map={}
00809         cursor=hltconfQuery.execute()
00810         while cursor.next():
00811             hltpath=cursor.currentRow()['hltpath'].data()
00812             print hltpath
00813             l1expression=cursor.currentRow()['l1expression'].data()
00814             hlt2l1map[hltpath]=l1expression
00815         del hltconfQuery
00816         session.transaction().commit()
00817         return hlt2l1map
00818     except:
00819         raise
00820 
00821 def runsummary(session,schemaname,runnumber,complementalOnly=False):
00822     '''
00823     x select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.TRG:TSC_KEY';
00824     x select distinct(string_value) from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:AMODEtag'
00825     x select distinct(string_value),session_id from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:EGEV' order by SESSION_ID
00826     
00827     select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:SEQ_NAME'
00828     select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:HLT_KEY_DESCRIPTION';
00829     select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:FILLN' and rownum<=1;
00830     select time from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:START_TIME_T';
00831     select time from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:STOP_TIME_T';
00832     input:
00833     output:[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]
00834     if complementalOnly:
00835        [l1key,amodetag,egev]
00836     '''
00837     runsessionparameterTable=''
00838     result=[]
00839     l1key=''
00840     amodetag=''
00841     egev=''
00842     hltkey=''
00843     fillnum=''
00844     sequence=''
00845     starttime=''
00846     stoptime=''
00847     try:
00848         session.transaction().start(True)
00849         runinfoschema=session.schema(schemaname)
00850         l1keyQuery=runinfoschema.newQuery()
00851         l1keyQuery.addToTableList('RUNSESSION_PARAMETER')
00852         l1keyOutput=coral.AttributeList()
00853         l1keyOutput.extend('l1key','string')
00854         l1keyCondition=coral.AttributeList()
00855         l1keyCondition.extend('name','string')
00856         l1keyCondition.extend('runnumber','unsigned int')
00857         l1keyCondition['name'].setData('CMS.TRG:TSC_KEY')
00858         l1keyCondition['runnumber'].setData(int(runnumber))
00859         l1keyQuery.addToOutputList('STRING_VALUE')
00860         l1keyQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',l1keyCondition)
00861         l1keyQuery.defineOutput(l1keyOutput)
00862         cursor=l1keyQuery.execute()
00863         while cursor.next():
00864             l1key=cursor.currentRow()['l1key'].data()
00865         del l1keyQuery
00866         result.append(l1key)
00867         
00868         amodetagQuery=runinfoschema.newQuery()
00869         amodetagQuery.addToTableList('RUNSESSION_PARAMETER')
00870         amodetagOutput=coral.AttributeList()
00871         amodetagOutput.extend('amodetag','string')
00872         amodetagCondition=coral.AttributeList()
00873         amodetagCondition.extend('name','string')
00874         amodetagCondition.extend('runnumber','unsigned int')
00875         amodetagCondition['name'].setData('CMS.SCAL:AMODEtag')
00876         amodetagCondition['runnumber'].setData(int(runnumber))
00877         amodetagQuery.addToOutputList('distinct(STRING_VALUE)')
00878         amodetagQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',amodetagCondition)
00879         amodetagQuery.limitReturnedRows(1)
00880         amodetagQuery.defineOutput(amodetagOutput)
00881         cursor=amodetagQuery.execute()
00882         while cursor.next():
00883             amodetag=cursor.currentRow()['amodetag'].data()
00884         del amodetagQuery
00885         result.append(amodetag)
00886         
00887         egevQuery=runinfoschema.newQuery()
00888         egevQuery.addToTableList('RUNSESSION_PARAMETER')
00889         egevOutput=coral.AttributeList()
00890         egevOutput.extend('egev','string')
00891         egevCondition=coral.AttributeList()
00892         egevCondition.extend('name','string')
00893         egevCondition.extend('runnumber','unsigned int')
00894         egevCondition['name'].setData('CMS.SCAL:EGEV')
00895         egevCondition['runnumber'].setData(int(runnumber))
00896         egevQuery.addToOutputList('distinct(STRING_VALUE)')
00897         egevQuery.addToOutputList('SESSION_ID')
00898         egevQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',egevCondition)
00899         egevQuery.defineOutput(egevOutput)
00900         egevQuery.addToOrderList('SESSION_ID')
00901         cursor=egevQuery.execute()
00902         while cursor.next():
00903             egev=cursor.currentRow()['egev'].data()
00904         del egevQuery
00905         result.append(egev)
00906         
00907         if not complementalOnly:
00908             seqQuery=runinfoschema.newQuery()
00909             seqQuery.addToTableList('RUNSESSION_PARAMETER')
00910             seqOutput=coral.AttributeList()
00911             seqOutput.extend('seq','string')
00912             seqCondition=coral.AttributeList()
00913             seqCondition.extend('name','string')
00914             seqCondition.extend('runnumber','unsigned int')
00915             seqCondition['name'].setData('CMS.LVL0:SEQ_NAME')
00916             seqCondition['runnumber'].setData(int(runnumber))
00917             seqQuery.addToOutputList('STRING_VALUE')
00918             seqQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',seqCondition)
00919             seqQuery.defineOutput(seqOutput)
00920             cursor=seqQuery.execute()
00921             while cursor.next():
00922                 sequence=cursor.currentRow()['seq'].data()
00923             del seqQuery
00924             result.append(sequence)
00925 
00926             hltkeyQuery=runinfoschema.newQuery()
00927             hltkeyQuery.addToTableList('RUNSESSION_PARAMETER')
00928             hltkeyOutput=coral.AttributeList()
00929             hltkeyOutput.extend('hltkey','string')
00930             hltkeyCondition=coral.AttributeList()
00931             hltkeyCondition.extend('name','string')
00932             hltkeyCondition.extend('runnumber','unsigned int')
00933             hltkeyCondition['name'].setData('CMS.LVL0:HLT_KEY_DESCRIPTION')
00934             hltkeyCondition['runnumber'].setData(int(runnumber))
00935             hltkeyQuery.addToOutputList('STRING_VALUE')
00936             hltkeyQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',hltkeyCondition)
00937             #hltkeyQuery.limitReturnedRows(1)
00938             hltkeyQuery.defineOutput(hltkeyOutput)
00939             cursor=hltkeyQuery.execute()
00940             while cursor.next():
00941                 hltkey=cursor.currentRow()['hltkey'].data()
00942                 del hltkeyQuery
00943             result.append(hltkey)
00944 
00945             fillnumQuery=runinfoschema.newQuery()
00946             fillnumQuery.addToTableList('RUNSESSION_PARAMETER')
00947             fillnumOutput=coral.AttributeList()
00948             fillnumOutput.extend('fillnum','string')
00949             fillnumCondition=coral.AttributeList()
00950             fillnumCondition.extend('name','string')
00951             fillnumCondition.extend('runnumber','unsigned int')
00952             fillnumCondition['name'].setData('CMS.SCAL:FILLN')
00953             fillnumCondition['runnumber'].setData(int(runnumber))
00954             fillnumQuery.addToOutputList('STRING_VALUE')
00955             fillnumQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',fillnumCondition)
00956             fillnumQuery.limitReturnedRows(1)
00957             fillnumQuery.defineOutput(fillnumOutput)
00958             cursor=fillnumQuery.execute()
00959             while cursor.next():
00960                 fillnum=cursor.currentRow()['fillnum'].data()
00961             del fillnumQuery
00962             result.append(fillnum)
00963 
00964             starttimeQuery=runinfoschema.newQuery()
00965             starttimeQuery.addToTableList('RUNSESSION_PARAMETER')
00966             starttimeOutput=coral.AttributeList()
00967             starttimeOutput.extend('starttime','time stamp')
00968             starttimeCondition=coral.AttributeList()
00969             starttimeCondition.extend('name','string')
00970             starttimeCondition.extend('runnumber','unsigned int')
00971             starttimeCondition['name'].setData('CMS.LVL0:START_TIME_T')
00972             starttimeCondition['runnumber'].setData(int(runnumber))
00973             starttimeQuery.addToOutputList('TIME')
00974             starttimeQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',starttimeCondition)
00975             starttimeQuery.defineOutput(starttimeOutput)
00976             cursor=starttimeQuery.execute()
00977             while cursor.next():
00978                 starttime=cursor.currentRow()['starttime'].data()
00979             del starttimeQuery
00980             result.append(starttime)
00981 
00982             stoptimeQuery=runinfoschema.newQuery()
00983             stoptimeQuery.addToTableList('RUNSESSION_PARAMETER')
00984             stoptimeOutput=coral.AttributeList()
00985             stoptimeOutput.extend('stoptime','time stamp')
00986             stoptimeCondition=coral.AttributeList()
00987             stoptimeCondition.extend('name','string')
00988             stoptimeCondition.extend('runnumber','unsigned int')
00989             stoptimeCondition['name'].setData('CMS.LVL0:STOP_TIME_T')
00990             stoptimeCondition['runnumber'].setData(int(runnumber))
00991             stoptimeQuery.addToOutputList('TIME')
00992             stoptimeQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',stoptimeCondition)
00993             stoptimeQuery.defineOutput(stoptimeOutput)
00994             cursor=stoptimeQuery.execute()
00995             while cursor.next():
00996                 stoptime=cursor.currentRow()['stoptime'].data()
00997             del stoptimeQuery
00998             result.append(stoptime)
00999             session.transaction().commit()
01000         else:
01001             session.transaction().commit()
01002         return result
01003     except:
01004         raise
01005     
01006 if __name__ == "__main__":
01007     from RecoLuminosity.LumiDB import sessionManager
01008     #svc=sessionManager.sessionManager('oracle://cms_orcoff_prep/cms_lumi_dev_offline',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
01009     #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
01010     #lsresult=trgFromOldLumi(session,135735)
01011     #print lsresult
01012     #lshltresult=hltFromOldLumi(session,135735)
01013     #print lshltresult
01014     #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_runinfo',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
01015     #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
01016     #runsummary(session,'CMS_RUNINFO',135735,complementalOnly=True)
01017     #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_gt',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
01018     #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
01019     #print trgFromOldGT(session,135735)
01020     #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_runinfo',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
01021     #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
01022     #print hltFromRuninfoV2(session,135735)
01023     svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_lumi_prod',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
01024     session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
01025     print uncalibratedlumiFromOldLumi(session,135735)
01026     del session