CMS 3D CMS Logo

pyDBSRunClass.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import string
00005 
00006 class FileInfo:
00007     '''Stores info about a given file within a run.
00008     '''
00009     def __init__(self,infotext=None):
00010         self.fileName=None
00011         self.numEvents=0
00012         self.lumiBlock=0
00013         self.dataset=None
00014         self.goodFile=False
00015         self.infotext=string.split(infotext,",")
00016         if len(self.infotext)>0:
00017             self.fileName=self.infotext[0]
00018         if len(self.infotext)>1:
00019             self.numEvents=string.atoi(self.infotext[1])
00020         if len(self.infotext)>2:
00021             self.lumiBlock=string.atoi(self.infotext[2])
00022         if len(self.infotext)>3:
00023             self.dataset=self.infotext[3]
00024             self.goodFile=True
00025         return
00026         
00027 
00028 class DBSRun:
00029     '''
00030     Stores information about a given run
00031     (Run number, files in run, whether DQM has been performed on run.)
00032     '''
00033     
00034     def __init__(self,filelist=None,lumiblocks=None,debug=False):
00035         
00036         #'''
00037         #Class stores all files associated with a given run number, as
00038         #given by DBS.  Also stores local DQM status, checking whether
00039         #DQM has run on the set of files, and whether it has successfully
00040         #completed.
00041         #'''
00042         self.debug=debug
00043         
00044         self.runnum=-1
00045         self.dataset=None
00046         self.files=[] # Stores files associated with run
00047         if (filelist<>None):
00048             self.files=filelist
00049 
00050         self.fileInfo=[]
00051 
00052         self.totalEvents=0
00053         self.ignoreRun=0 # if true, DQM won't be performed on run
00054         self.startedDQM=0 # set to true once DQM started 
00055         self.finishedDQM=0 # set to true once DQM finished (DQM directory for run exists)
00056         self.previouslyFinishedDQM=0 # This is no longer being used -- we can probably remove it completely
00057         self.maxEvents=1000 # number of events to run over with DQM
00058 
00059         # The following variables are used for searching only over certain lumi blocks
00060         self.numLumiBlocks=0
00061         self.lumiBlockIncrement=0
00062         self.currentLumiBlock=1
00063         
00064         return
00065 
00066     def AddFileInfo(self,FileInfo):
00067         ''' Adds run info from File to lists.'''
00068         if (FileInfo.goodFile==True):
00069             self.fileInfo.append(FileInfo)
00070         self.files.append(FileInfo.fileName)
00071         #self.UpdateRunInfo()
00072         return
00073 
00074     def UpdateRunInfo(self):
00075         ''' Finds largest luminosity block and updates total number of events.'''
00076         tempevents=0
00077         
00078         for i in self.fileInfo:
00079             if (i.fileName not in self.files):
00080                 self.files.append(i.fileName)
00081             if (self.dataset==None):
00082                 self.dataset=i.dataset
00083             elif (self.dataset<>i.dataset):
00084                 print "<pyDBSRunClass:  UpdateRunInfo WARNING>:  datasets do not agree!"
00085                 print "\tRun dataset = ",self.dataset
00086                 print "\tFile dataset = ",i.dataset
00087             if i.lumiBlock>self.numLumiBlocks:
00088                 self.numLumiBlocks=i.lumiBlock
00089             tempevents=tempevents+i.numEvents
00090         self.totalEvents=tempevents
00091         return
00092     
00093 
00094     def Print(self,screenoutput=False):
00095         '''
00096         Returns DBSRun class variable values as a string.
00097         '''
00098         mylen=0
00099         if (self.files<>None):
00100             mylen=len(self.files)
00101         x= "%10s     %35s     %10s     %14s%12s%15s%15s     %20s\n"%(self.runnum,
00102                                                                 self.dataset,
00103                                                                 mylen,
00104                                                                 self.totalEvents,
00105                                                                 self.ignoreRun,
00106                                                                 self.startedDQM,
00107                                                                 self.finishedDQM,
00108                                                                 #self.previouslyFinishedDQM
00109                                                             self.currentLumiBlock
00110                                                        )
00111         if screenoutput:
00112             print "%10s     %55s     %10s%12s%15s%15s\n"%("Run","Dataset",
00113                                                           "# files","Ignore",
00114                                                           "Start","End")
00115             print x
00116         return x
00117 
00118     def Print2(self,screenoutput=False):
00119         '''
00120         Print command to be used within listbox.
00121         '''
00122 
00123         # Try to make everything as uniformly-aligned as possible:
00124         if (self.ignoreRun==0):
00125             self.ignoreRun=False
00126         elif (self.ignoreRun==1):
00127             self.ignoreRun=True
00128         if (self.startedDQM==0):
00129             self.startedDQM=False
00130         if (self.startedDQM==1):
00131             self.startedDQM=True
00132         if (self.finishedDQM==0):
00133             self.finishedDQM=False
00134         if (self.finishedDQM==1):
00135             self.finishedDQM=True
00136 
00137         # Set value strings so that they all have the same length
00138         # (This doesn't mean that they will look completely aligned,
00139         #  since different characters take up different amounts of space.
00140         #  What's a good way around this?
00141         
00142         run=`self.runnum`
00143         ignore=`self.ignoreRun`
00144         mylen=`0`
00145         if self.files<>None:
00146             mylen=`len(self.files)`
00147         start=`self.startedDQM`
00148         end=`self.finishedDQM`
00149         dataset=self.dataset
00150         while len(run)<10:
00151             run=" "+run
00152         while (len(mylen)<20):
00153             mylen=" "+mylen
00154         while len(ignore)<20:
00155             ignore=" "+ignore
00156         while len(start)<20:
00157             start=" "+start
00158         while len(end)<20:
00159             end=" "+end
00160 
00161         # Create string to be printed in listbox
00162         temp = "%10s%20s%30s%25s%20s%20s%s"%(run,start,end,ignore,mylen," ",dataset)
00163         if screenoutput:
00164             print "%10s%20s%30s%25s%20s%20s%s"%("Run","Start","End","Ignore","# files"," ","Dataset")
00165             print temp
00166             print "\tLumi block variables: "
00167             print "\t\t# lumi blocks in file: %s"%self.numLumiBlocks
00168             print "\t\tlumi block increment: %s"%self.lumiBlockIncrement 
00169             print "\t\tcurrent lumi block: %s"%self.currentLumiBlock
00170 
00171 
00172         return temp
00173     
00174 def dbsSort(x,y):
00175     '''
00176     Sorts DBSRun objects by run number.
00177     '''
00178     return x.runnum>y.runnum
00179 
00180 
00181 
00182 
00183 
00184 ##########################################
00185 # testing program
00186 
00187 if __name__=="__main__":
00188 
00189     print "Testing creation of a DBSRun class:"
00190     temp=[]
00191     if len(sys.argv)>1:
00192         temp=[DBSRun(sys.argv[1:])]
00193     else:
00194         temp=[DBSRun()]
00195     for i in temp:
00196         print "\n Displaying 'Print' output of DBSRun instance:\n"
00197         i.Print(screenoutput=1)
00198         print "\n\n Displaying 'Print2' output of DBSRun instance:\n"
00199         i.Print2(screenoutput=1)
00200 
00201     print "\n\nThat's all, folks!"

Generated on Tue Jun 9 17:32:56 2009 for CMSSW by  doxygen 1.5.4