CMS 3D CMS Logo

Public Member Functions | Public Attributes

WorkFlowRunner::WorkFlowRunner Class Reference

Inherits threading::Thread.

List of all members.

Public Member Functions

def __init__
def doCmd
def run

Public Attributes

 cafVeto
 dryRun
 nfail
 noRun
 npass
 needs to set self.report
 report
 wrap up ####
 retStep
 stat
 status
 wf
 wfDir

Detailed Description

Definition at line 8 of file WorkFlowRunner.py.


Constructor & Destructor Documentation

def WorkFlowRunner::WorkFlowRunner::__init__ (   self,
  wf,
  noRun = False,
  dryRun = False,
  cafVeto = True 
)

Definition at line 9 of file WorkFlowRunner.py.

00010                                                                  :
00011         Thread.__init__(self)
00012         self.wf = wf
00013 
00014         self.status=-1
00015         self.report=''
00016         self.nfail=0
00017         self.npass=0
00018         self.noRun=noRun
00019         self.dryRun=dryRun
00020         self.cafVeto=cafVeto
00021         
00022         self.wfDir=str(self.wf.numId)+'_'+self.wf.nameId
00023         return


Member Function Documentation

def WorkFlowRunner::WorkFlowRunner::doCmd (   self,
  cmd 
)

Definition at line 24 of file WorkFlowRunner.py.

00025                         :
00026 
00027         msg = "\n# in: " +os.getcwd()
00028         if self.dryRun: msg += " dryRun for '"
00029         else:      msg += " going to execute "
00030         msg += cmd.replace(';','\n')
00031         print msg
00032 
00033         cmdLog = open(self.wfDir+'/cmdLog','a')
00034         cmdLog.write(msg+'\n')
00035         cmdLog.close()
00036         
00037         ret = 0
00038         if not self.dryRun:
00039             p = Popen(cmd, shell=True)
00040             ret = os.waitpid(p.pid, 0)[1]
00041             if ret != 0:
00042                 print "ERROR executing ",cmd,'ret=', ret
00043 
00044         return ret
    
def WorkFlowRunner::WorkFlowRunner::run (   self)

Definition at line 45 of file WorkFlowRunner.py.

00046                  :
00047 
00048         startDir = os.getcwd()
00049 
00050         if not os.path.exists(self.wfDir):
00051             os.makedirs(self.wfDir)
00052 
00053         preamble = 'cd '+self.wfDir+'; '
00054        
00055         startime='date %s' %time.asctime()
00056 
00057         # check where we are running:
00058         onCAF = False
00059         if 'cms/caf/cms' in os.environ['CMS_PATH']:
00060             onCAF = True
00061 
00062         ##needs to set
00063         #self.report
00064         self.npass  = []
00065         self.nfail = []
00066         self.stat = []
00067         self.retStep = []
00068 
00069         def closeCmd(i,ID):
00070             return ' > %s 2>&1; ' % ('step%d_'%(i,)+ID+'.log ',)
00071 
00072         inFile=None
00073         aborted=False
00074         for (istepmone,com) in enumerate(self.wf.cmds):
00075             istep=istepmone+1
00076             cmd = preamble
00077             if aborted:
00078                 self.npass.append(0)
00079                 self.nfail.append(0)
00080                 self.retStep.append(0)
00081                 self.stat.append('NOTRUN')
00082                 continue
00083             if not isinstance(com,str):
00084                 if self.cafVeto and (com.location == 'CAF' and not onCAF):
00085                     print "You need to be no CAF to run",self.wf.numId
00086                     self.npass.append(0)
00087                     self.nfail.append(0)
00088                     self.retStep.append(0)
00089                     self.stat.append('NOTRUN')
00090                     aborted=True
00091                     continue
00092                 cmd+=com.dbs()
00093                 cmd+=closeCmd(istep,'dbsquery')
00094                 retStep = self.doCmd(cmd)
00095                 #don't use the file list executed, but use the dbs command of cmsDriver for next step
00096                 inFile='filelist:step%d_dbsquery.log'%(istep,)
00097                 print "---"
00098             else:
00099                 #chaining IO , which should be done in WF object already and not using stepX.root but <stepName>.root
00100                 cmd += com
00101                 if self.noRun:
00102                     cmd +=' --no_exec'
00103                 if inFile: #in case previous step used DBS query (either filelist of dbs:)
00104                     cmd += ' --filein '+inFile
00105                     inFile=None
00106                 if 'HARVESTING' in cmd and not '134' in str(self.wf.numId) and not '--filein' in cmd:
00107                     cmd+=' --filein file:step%d_inDQM.root --fileout file:step%d.root '%(istep-1,istep)
00108                 else:
00109                     if istep!=1 and not '--filein' in cmd:
00110                         cmd+=' --filein file:step%s.root '%(istep-1,)
00111                     if not '--fileout' in com:
00112                         cmd+=' --fileout file:step%s.root '%(istep,)
00113                     
00114                                 
00115 
00116                 cmd+=closeCmd(istep,self.wf.nameId)            
00117                 retStep = self.doCmd(cmd)
00118             
00119             self.retStep.append(retStep)
00120             if (retStep!=0):
00121                 #error occured
00122                 self.npass.append(0)
00123                 self.nfail.append(1)
00124                 self.stat.append('FAILED')
00125                 #to skip processing
00126                 aborted=True
00127             else:
00128                 #things went fine
00129                 self.npass.append(1)
00130                 self.nfail.append(0)
00131                 self.stat.append('PASSED')
00132 
00133 
00134         os.chdir(startDir)
00135 
00136         endtime='date %s' %time.asctime()
00137         tottime='%s-%s'%(endtime,startime)
00138         
00139 
00140         #### wrap up ####
00141 
00142         logStat=''
00143         for i,s in enumerate(self.stat):
00144             logStat+='Step%d-%s '%(i,s)
00145         self.report='%s_%s %s - time %s; exit: '%(self.wf.numId,self.wf.nameId,logStat,tottime)+' '.join(map(str,self.retStep))+'\n'
00146 
00147         return 
00148 
00149 
00150 

Member Data Documentation

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.

needs to set self.report

Definition at line 9 of file WorkFlowRunner.py.

wrap up ####

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 47 of file WorkFlowRunner.py.

Definition at line 47 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.

Definition at line 9 of file WorkFlowRunner.py.