CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
crabFunctions.CrabTask Class Reference

Class for a single CrabRequest e This class represents one crab3 task/request. More...

Public Member Functions

def __init__ (self, taskname="", crab_config="", crabController=None, initUpdate=True, debuglevel="ERROR", datasetpath="", localDir="", outlfn="")
 The object constructor. More...
 
def crab_folder (self)
 
def crabConfig (self)
 Function to access crab config object or read it if unititalized. More...
 
def crabFolder (self)
 
def datasetpath (self)
 
def handleNoState (self)
 Function to handle Task which received NOSTATE status. More...
 
def isData (self)
 Property function to find out if task runs on data. More...
 
def readLogArch (self, logArchName)
 Function to read log info from log.tar.gz. More...
 
def resubmit_failed (self)
 Function to resubmit failed jobs in tasks. More...
 
def test_print (self)
 
def update (self)
 Function to update Task in associated Jobs. More...
 
def updateJobStats (self, dCacheFileList=None)
 Function to update JobStatistics. More...
 

Public Attributes

 debug
 
 failureReason
 
 finalFiles
 
 isUpdating
 
 jobs
 
 lastUpdate
 
 localDir
 
 log
 
 maxjobnumber
 
 name
 
 nComplete
 
 nCooloff
 
 nFailed
 
 nFinished
 
 nIdle
 
 nJobs
 
 nRunning
 
 nTransferring
 
 nUnsubmitted
 
 outlfn
 
 resubmitCount
 
 state
 
 taskId
 
 totalEvents
 
 uuid
 

Private Attributes

 _crabConfig
 
 _crabFolder
 
 _datasetpath_default
 
 _isData
 

Detailed Description

Class for a single CrabRequest e This class represents one crab3 task/request.

Definition at line 372 of file crabFunctions.py.

Constructor & Destructor Documentation

def crabFunctions.CrabTask.__init__ (   self,
  taskname = "",
  crab_config = "",
  crabController = None,
  initUpdate = True,
  debuglevel = "ERROR",
  datasetpath = "",
  localDir = "",
  outlfn = "" 
)

The object constructor.

Parameters
selfThe object pointer.
tasknameThe object pointer.
initUpdateFlag if crab status should be called when an instance is created

Definition at line 387 of file crabFunctions.py.

387  outlfn = "" ,):
388 
389  # crab config as a python object should only be used via .config
390  self._crabConfig = None
391 
392  self._crabFolder = None
393 
394  if taskname:
395  self.name = taskname
396  else:
397  if not crab_config:
398  raise ValueError("Either taskname or crab_config needs to be set")
399  if not os.path.exists( crab_config):
400  raise IOError("File %s not found" % crab_config )
401  self.name = crab_config
402  self.name = self.crabConfig.General.requestName
403  self.uuid = uuid.uuid4()
404  #~ self.lock = multiprocessing.Lock()
405  #setup logging
406  self.log = logging.getLogger( 'crabTask' )
407  self.log.setLevel(logging._levelNames[ debuglevel ])
408  self.jobs = {}
409  self.localDir = localDir
410  self.outlfn = outlfn
411  self.isUpdating = False
412  self.taskId = -1
413  #variables for statistics
414  self.nJobs = 0
415  self.state = "NOSTATE"
416  self.maxjobnumber = 0
417  self.nUnsubmitted = 0
418  self.nIdle = 0
419  self.nRunning = 0
420  self.nTransferring = 0
421  self.nCooloff = 0
422  self.nFailed = 0
423  self.nFinished = 0
424  self.nComplete = 0
425  self.failureReason = None
426  self.lastUpdate = datetime.datetime.now().strftime( "%Y-%m-%d_%H.%M.%S" )
427 
428  self._isData = None
429  self.resubmitCount = 0
430 
431  self.debug = False
432 
433  self.finalFiles = []
434  self.totalEvents = 0
435 
436 
437  self._datasetpath_default = datasetpath
438 
439  #start with first updates
440  if initUpdate:
441  self.update()
442  self.updateJobStats()
443 
def updateJobStats(self, dCacheFileList=None)
Function to update JobStatistics.
def update(self)
Function to update Task in associated Jobs.

Member Function Documentation

def crabFunctions.CrabTask.crab_folder (   self)

Definition at line 507 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.update().

507  def crab_folder(self):
508  return os.path.join( self.crabConfig.General.workArea,
509  "crab_" + self.crabConfig.General.requestName)
def crabFunctions.CrabTask.crabConfig (   self)
def crabFunctions.CrabTask.crabFolder (   self)

Definition at line 480 of file crabFunctions.py.

References crabFunctions.CrabTask._crabFolder, AlignableObjectId::entry.name, preexistingValidation.PreexistingValidation.name, alignment.Alignment.name, XMLProcessor::_loaderBaseConfig.name, genericValidation.GenericValidation.name, h4DSegm.name, TrackerSectorStruct.name, classes.MonitorData.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, and hTMaxCell.name.

480  def crabFolder( self ):
481  if not self._crabFolder is None: return self._crabFolder
482  crab = CrabController()
483  if os.path.exists( os.path.join( self.crabConfig.General.workArea, crab._prepareFoldername( self.name ) ) ):
484  self._crabFolder = os.path.join( self.crabConfig.General.workArea, crab._prepareFoldername( self.name ) )
485  return self._crabFolder
486  alternative_path = os.path.join(os.path.cwd(), crab._prepareFoldername( self.name ) )
487  if os.path.exists( alternative_path ):
488  self._crabFolder = alternative_path
489  return self._crabFolder
490  self.log.error( "Unable to find folder for Task")
491  return ""
492 
The CrabController class.
def crabFunctions.CrabTask.datasetpath (   self)

Definition at line 472 of file crabFunctions.py.

References crabFunctions.CrabTask._datasetpath_default.

472  def datasetpath( self ):
473  try:
474  return self.crabConfig.Data.inputDataset
475  except:
476  pass
477  return self._datasetpath_default
478 
def crabFunctions.CrabTask.handleNoState (   self)

Function to handle Task which received NOSTATE status.

Parameters
selfCrabTask The object pointer.

Definition at line 542 of file crabFunctions.py.

References AlignableObjectId::entry.name, preexistingValidation.PreexistingValidation.name, alignment.Alignment.name, XMLProcessor::_loaderBaseConfig.name, genericValidation.GenericValidation.name, h4DSegm.name, TrackerSectorStruct.name, classes.MonitorData.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, hTMaxCell.name, crabFunctions.CrabTask.resubmitCount, CastorLedAnalysis.state, HcalLedAnalysis.state, HcalPedestalAnalysis.state, CastorPedestalAnalysis.state, and crabFunctions.CrabTask.state.

542  def handleNoState( self ):
543  crab = CrabController()
544  if "The CRAB3 server backend could not resubmit your task because the Grid scheduler answered with an error." in task.failureReason:
545  # move folder and try it again
546  cmd = 'mv %s bak_%s' %(crab._prepareFoldername( self.name ),crab._prepareFoldername( self.name ))
547  p = subprocess.Popen(cmd,stdout=subprocess.PIPE, shell=True)#,shell=True,universal_newlines=True)
548  (out,err) = p.communicate()
549  self.state = "SHEDERR"
550  configName = '%s_cfg.py' %(crab._prepareFoldername( self.name ))
551  crab.submit( configName )
552 
553  elif task.failureReason is not None:
554  self.state = "ERRHANDLE"
555  crab.resubmit( self.name )
556  self.resubmitCount += 1
557 
The CrabController class.
def handleNoState(self)
Function to handle Task which received NOSTATE status.
def crabFunctions.CrabTask.isData (   self)

Property function to find out if task runs on data.

Parameters
selfCrabTask The object pointer.

Definition at line 448 of file crabFunctions.py.

References crabFunctions.CrabTask._isData.

448  def isData( self ):
449  if self._isData is None:
450  try:
451  test = self.crabConfig.Data.lumiMask
452  self._isData = True
453  except:
454  if self.name.startswith( "Data_" ):
455  self._isData = True
456  else:
457  self._isData = False
458  return self._isData
459 
460 
def isData(self)
Property function to find out if task runs on data.
def crabFunctions.CrabTask.readLogArch (   self,
  logArchName 
)

Function to read log info from log.tar.gz.

Parameters
selfThe object pointer.
logArchNamepath to the compressed log file
Returns
a dictionary with parsed info

Definition at line 599 of file crabFunctions.py.

References createfilelist.int, edm.print(), and split.

599  def readLogArch(self, logArchName):
600  JobNumber = logArchName.split("/")[-1].split("_")[1].split(".")[0]
601  log = {'readEvents' : 0}
602  with tarfile.open( logArchName, "r") as tar:
603  try:
604  JobXmlFile = tar.extractfile('FrameworkJobReport-%s.xml' % JobNumber)
605  root = ET.fromstring( JobXmlFile.read() )
606  for child in root:
607  if child.tag == 'InputFile':
608  for subchild in child:
609  if subchild.tag == 'EventsRead':
610  nEvents = int(subchild.text)
611  log.update({'readEvents' : nEvents})
612  break
613  break
614  except:
615  print("Can not parse / read %s" % logArchName)
616  return log
617 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def readLogArch(self, logArchName)
Function to read log info from log.tar.gz.
double split
Definition: MVATrainer.cc:139
def crabFunctions.CrabTask.resubmit_failed (   self)

Function to resubmit failed jobs in tasks.

Parameters
selfCrabTask The object pointer.

Definition at line 496 of file crabFunctions.py.

References crabFunctions.CrabTask.jobs, crabFunctions.CrabTask.lastUpdate, AlignableObjectId::entry.name, preexistingValidation.PreexistingValidation.name, alignment.Alignment.name, XMLProcessor::_loaderBaseConfig.name, genericValidation.GenericValidation.name, h4DSegm.name, TrackerSectorStruct.name, classes.MonitorData.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, and hTMaxCell.name.

496  def resubmit_failed( self ):
497  failedJobIds = []
498  controller = CrabController()
499  for jobkey in self.jobs.keys():
500  job = self.jobs[jobkey]
501  if job['State'] == 'failed':
502  failedJobIds.append( job['JobIds'][-1] )
503  controller.resubmit( self.name, joblist = failedJobIds )
504  self.lastUpdate = datetime.datetime.now().strftime( "%Y-%m-%d_%H.%M.%S" )
505 
The CrabController class.
def resubmit_failed(self)
Function to resubmit failed jobs in tasks.
def crabFunctions.CrabTask.test_print (   self)

Definition at line 558 of file crabFunctions.py.

References crabFunctions.CrabTask.uuid.

558  def test_print(self):
559  return self.uuid
def crabFunctions.CrabTask.update (   self)

Function to update Task in associated Jobs.

Parameters
selfCrabTask The object pointer.

Definition at line 513 of file crabFunctions.py.

References crabFunctions.CrabTask.crab_folder(), crabFunctions.CrabTask.failureReason, crabFunctions.CrabTask.isUpdating, crabFunctions.CrabTask.jobs, crabFunctions.CrabTask.lastUpdate, AlignableObjectId::entry.name, preexistingValidation.PreexistingValidation.name, alignment.Alignment.name, XMLProcessor::_loaderBaseConfig.name, genericValidation.GenericValidation.name, h4DSegm.name, TrackerSectorStruct.name, classes.MonitorData.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, hTMaxCell.name, Mpslibclass.jobdatabase.nJobs, crabFunctions.CrabTask.nJobs, crabFunctions.CrabTask.resubmitCount, CastorLedAnalysis.state, HcalLedAnalysis.state, HcalPedestalAnalysis.state, CastorPedestalAnalysis.state, crabFunctions.CrabTask.state, and crabFunctions.CrabTask.updateJobStats().

Referenced by progressbar.ProgressBar.__next__(), MatrixUtil.Matrix.__setitem__(), MatrixUtil.Steps.__setitem__(), Vispa.Gui.VispaWidget.VispaWidget.autosize(), Vispa.Views.LineDecayView.LineDecayContainer.createObject(), Vispa.Views.LineDecayView.LineDecayContainer.deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget.enableAutosizing(), dqm-mbProfile.Profile.finish(), progressbar.ProgressBar.finish(), Vispa.Gui.MenuWidget.MenuWidget.leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget.mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer.mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer.objectMoved(), MatrixUtil.Steps.overwrite(), Vispa.Views.LineDecayView.LineDecayContainer.removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget.removePorts(), Vispa.Gui.FindDialog.FindDialog.reset(), Vispa.Gui.PortConnection.PointToPointConnection.select(), Vispa.Gui.VispaWidget.VispaWidget.select(), Vispa.Views.LineDecayView.LineDecayContainer.select(), Vispa.Gui.VispaWidget.VispaWidget.setText(), Vispa.Gui.VispaWidget.VispaWidget.setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget.setZoom(), Vispa.Views.LineDecayView.LineDecayContainer.setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection.updateConnection().

513  def update(self):
514  #~ self.lock.acquire()
515  self.log.debug( "Start update for task %s" % self.name )
516  self.isUpdating = True
517  controller = CrabController()
518  self.state = "UPDATING"
519  # check if we should drop this sample due to missing info
520 
521  self.log.debug( "Try to get status for task" )
522  self.state , self.jobs,self.failureReason = controller.status(self.crab_folder)
523  self.log.debug( "Found state: %s" % self.state )
524  if self.state=="FAILED":
525  #try it once more
526  time.sleep(2)
527  self.state , self.jobs,self.failureReason = controller.status(self.crab_folder)
528  self.nJobs = len(self.jobs)
529  self.updateJobStats()
530  if self.state == "NOSTATE":
531  self.log.debug( "Trying to resubmit because of NOSTATE" )
532  if self.resubmitCount < 3: self.self.handleNoState()
533  # add to db if not
534  # Final solution inf state not yet found
535  self.isUpdating = False
536  self.lastUpdate = datetime.datetime.now().strftime( "%Y-%m-%d_%H.%M.%S" )
537  #~ self.lock.release()
538 
def updateJobStats(self, dCacheFileList=None)
Function to update JobStatistics.
The CrabController class.
def update(self)
Function to update Task in associated Jobs.
def crabFunctions.CrabTask.updateJobStats (   self,
  dCacheFileList = None 
)

Function to update JobStatistics.

Parameters
selfThe object pointer.
dCacheFilelistA list of files on the dCache

Definition at line 564 of file crabFunctions.py.

References any(), createfilelist.int, crabFunctions.CrabTask.jobs, AlignableObjectId::entry.name, preexistingValidation.PreexistingValidation.name, alignment.Alignment.name, XMLProcessor::_loaderBaseConfig.name, genericValidation.GenericValidation.name, h4DSegm.name, TrackerSectorStruct.name, classes.MonitorData.name, MuonGeometrySanityCheckPoint.name, classes.OutputData.name, h2DSegm.name, geometry.Structure.name, plotscripts.SawTeethFunction.name, crabFunctions.CrabTask.name, hTMaxCell.name, crabFunctions.CrabTask.nComplete, and edm.print().

Referenced by crabFunctions.CrabTask.update().

564  def updateJobStats(self,dCacheFileList = None):
565  jobKeys = sorted(self.jobs.keys())
566  try:
567  intJobkeys = [int(x) for x in jobKeys]
568  except:
569  print("error parsing job numers to int")
570 
571  #maxjobnumber = max(intJobkeys)
572 
573  stateDict = {'unsubmitted':0,'idle':0,'running':0,'transferring':0,'cooloff':0,'failed':0,'finished':0}
574  nComplete = 0
575 
576  # loop through jobs
577  for key in jobKeys:
578  job = self.jobs[key]
579  #check if all completed files are on decache
580  for statekey in stateDict.keys():
581  if statekey in job['State']:
582  stateDict[statekey]+=1
583  # check if finished fails are found on dCache if dCacheFilelist is given
584  if dCacheFileList is not None:
585  outputFilename = "%s_%s"%( self.name, key)
586  if 'finished' in statekey and any(outputFilename in s for s in dCacheFileList):
587  nComplete +=1
588 
589  for state in stateDict:
590  attrname = "n" + state.capitalize()
591  setattr(self, attrname, stateDict[state])
592  self.nComplete = nComplete
593 
def updateJobStats(self, dCacheFileList=None)
Function to update JobStatistics.
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66

Member Data Documentation

crabFunctions.CrabTask._crabConfig
private

Definition at line 390 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.crabConfig().

crabFunctions.CrabTask._crabFolder
private

Definition at line 392 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.crabFolder().

crabFunctions.CrabTask._datasetpath_default
private

Definition at line 437 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.datasetpath().

crabFunctions.CrabTask._isData
private

Definition at line 428 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.isData().

crabFunctions.CrabTask.debug
crabFunctions.CrabTask.failureReason

Definition at line 425 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.update().

crabFunctions.CrabTask.finalFiles

Definition at line 433 of file crabFunctions.py.

crabFunctions.CrabTask.isUpdating

Definition at line 411 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.update().

crabFunctions.CrabTask.jobs
crabFunctions.CrabTask.lastUpdate
crabFunctions.CrabTask.localDir

Definition at line 409 of file crabFunctions.py.

crabFunctions.CrabTask.log
crabFunctions.CrabTask.maxjobnumber

Definition at line 416 of file crabFunctions.py.

crabFunctions.CrabTask.name

Definition at line 395 of file crabFunctions.py.

Referenced by ElectronMVAID.ElectronMVAID.__call__(), FWLite.ElectronMVAID.__call__(), dirstructure.Directory.__create_pie_image(), DisplayManager.DisplayManager.__del__(), dqm_interfaces.DirID.__eq__(), BeautifulSoup.Tag.__eq__(), dirstructure.Directory.__get_full_path(), dirstructure.Comparison.__get_img_name(), dataset.Dataset.__getDataType(), dataset.Dataset.__getFileInfoList(), dirstructure.Comparison.__make_image(), core.autovars.NTupleVariable.__repr__(), core.autovars.NTupleObjectType.__repr__(), core.autovars.NTupleObject.__repr__(), core.autovars.NTupleCollection.__repr__(), dirstructure.Directory.__repr__(), dqm_interfaces.DirID.__repr__(), dirstructure.Comparison.__repr__(), config.Service.__setattr__(), config.CFG.__str__(), counter.Counter.__str__(), average.Average.__str__(), BeautifulSoup.Tag.__str__(), BeautifulSoup.SoupStrainer.__str__(), FWLite.WorkingPoints._reformat_cut_definitions(), core.autovars.NTupleObjectType.addSubObjects(), core.autovars.NTupleObjectType.addVariables(), core.autovars.NTupleObjectType.allVars(), dirstructure.Directory.calcStats(), crabFunctions.CrabTask.crabConfig(), crabFunctions.CrabTask.crabFolder(), validation.Sample.digest(), python.rootplot.utilities.Hist.divide(), python.rootplot.utilities.Hist.divide_wilson(), DisplayManager.DisplayManager.Draw(), TreeCrawler.Package.dump(), core.autovars.NTupleVariable.fillBranch(), core.autovars.NTupleObject.fillBranches(), core.autovars.NTupleCollection.fillBranchesScalar(), core.autovars.NTupleCollection.fillBranchesVector(), core.autovars.NTupleCollection.get_cpp_declaration(), core.autovars.NTupleCollection.get_cpp_wrapper_class(), core.autovars.NTupleCollection.get_py_wrapper_class(), utils.StatisticalTest.get_status(), production_tasks.Task.getname(), dataset.CMSDataset.getPrimaryDatasetEntries(), dataset.PrivateDataset.getPrimaryDatasetEntries(), crabFunctions.CrabTask.handleNoState(), VIDSelectorBase.VIDSelectorBase.initialize(), personalPlayback.Applet.log(), core.autovars.NTupleVariable.makeBranch(), core.autovars.NTupleObject.makeBranches(), core.autovars.NTupleCollection.makeBranchesScalar(), core.autovars.NTupleCollection.makeBranchesVector(), dirstructure.Directory.print_report(), dataset.BaseDataset.printInfo(), dataset.Dataset.printInfo(), crabFunctions.CrabTask.resubmit_failed(), production_tasks.MonitorJobs.run(), BeautifulSoup.SoupStrainer.searchTag(), python.rootplot.utilities.Hist.TGraph(), python.rootplot.utilities.Hist.TH1F(), crabFunctions.CrabTask.update(), crabFunctions.CrabTask.updateJobStats(), Vispa.Views.PropertyView.Property.valueChanged(), counter.Counter.write(), and average.Average.write().

crabFunctions.CrabTask.nComplete

Definition at line 424 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.updateJobStats().

crabFunctions.CrabTask.nCooloff

Definition at line 421 of file crabFunctions.py.

crabFunctions.CrabTask.nFailed

Definition at line 422 of file crabFunctions.py.

crabFunctions.CrabTask.nFinished

Definition at line 423 of file crabFunctions.py.

crabFunctions.CrabTask.nIdle

Definition at line 418 of file crabFunctions.py.

crabFunctions.CrabTask.nJobs

Definition at line 414 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.update().

crabFunctions.CrabTask.nRunning

Definition at line 419 of file crabFunctions.py.

crabFunctions.CrabTask.nTransferring

Definition at line 420 of file crabFunctions.py.

crabFunctions.CrabTask.nUnsubmitted

Definition at line 417 of file crabFunctions.py.

crabFunctions.CrabTask.outlfn

Definition at line 410 of file crabFunctions.py.

crabFunctions.CrabTask.resubmitCount
crabFunctions.CrabTask.state
crabFunctions.CrabTask.taskId

Definition at line 412 of file crabFunctions.py.

crabFunctions.CrabTask.totalEvents

Definition at line 434 of file crabFunctions.py.

crabFunctions.CrabTask.uuid

Definition at line 403 of file crabFunctions.py.

Referenced by crabFunctions.CrabTask.test_print().