本文整理匯總了Python中Ganga.GPI類的典型用法代碼示例。如果您正苦於以下問題:Python GPI類的具體用法?Python GPI怎麽用?Python GPI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了GPI類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getJobs
def getJobs(self):
""" Get the job slice of all jobs that process this task """
jobslice = JobRegistrySlice("tasks(%i).getJobs()" % (self.id))
for trf in self.transforms:
for jid in trf.getJobs():
jobslice.objects[GPI.jobs(jid).fqid] = stripProxy(GPI.jobs(jid))
return JobRegistrySliceProxy(jobslice)
示例2: getTransform
def getTransform(self):
tid = self.tasks_id.split(":")
if len(tid) == 2 and tid[0].isdigit() and tid[1].isdigit():
try:
task = GPI.tasks(int(tid[0]))
except KeyError:
return None
if task:
return task.transforms[int(tid[1])]
if len(tid) == 3 and tid[1].isdigit() and tid[2].isdigit():
task = GPI.tasks(int(tid[1]))
if task:
return task.transforms[int(tid[2])]
return None
示例3: copyOutput
def copyOutput(self):
"""Copy the output data to local storage"""
job = GPI.jobs(self.active_job_ids[0])
if self.copy_output._name != "TaskLocalCopy" or job.outputdata._impl._name != "DQ2OutputDataset":
logger.error(
"Cannot transfer from DS type '%s' to '%s'. Please contact plugin developer."
% (job.outputdata._name, self.copy_output._name)
)
return False
# check which fies still need downloading
to_download = []
for f in job.outputfiles:
# check for REs
if self.copy_output.isValid(os.path.join(f.localDir, f.namePattern)) and not self.copy_output.isDownloaded(
os.path.join(f.localDir, f.namePattern)
):
to_download.append(f)
# is everything downloaded?
if len(to_download) == 0:
return True
# nope, so pick the requested number and off we go
for f in to_download:
f.get()
return False
示例4: checkOutputContainers
def checkOutputContainers(self):
"""Go through all completed units and make sure datasets are registered as required"""
logger.info("Cleaning out transform %d container..." % self.getID())
try:
dslist = []
dq2_lock.acquire()
try:
dslist = dq2.listDatasetsInContainer(self.getContainerName())
except:
dslist = []
try:
dq2.deleteDatasetsFromContainer(self.getContainerName(), dslist )
except DQContainerDoesNotHaveDataset:
pass
except Exception as x:
logger.error("Problem cleaning out Transform container: %s %s", x.__class__, x)
except DQException as x:
logger.error('DQ2 Problem cleaning out Transform container: %s %s' %( x.__class__, x))
finally:
dq2_lock.release()
logger.info("Checking output data has been registered for Transform %d..." % self.getID())
for unit in self.units:
if len(unit.active_job_ids) == 0:
continue
if unit.status == "completed" and GPI.jobs(unit.active_job_ids[0]).outputdata and GPI.jobs(unit.active_job_ids[0]).outputdata._impl._name == "DQ2OutputDataset":
logger.info("Checking containers in Unit %d..." % unit.getID() )
unit.registerDataset()
示例5: n_all
def n_all(self):
total = 0
for jid in self.active_job_ids:
try:
job = GPI.jobs(jid)
except Exception as err:
logger.debug("n_all Err: %s" % str(err))
task = self._getParent()._getParent()
trf = self._getParent()
logger.warning("Cannot find job with id %d. Maybe reset this unit with: tasks(%d).transforms[%d].resetUnit(%d)" %
(jid, task.id, trf.getID(), self.getID()))
continue
j = stripProxy(job)
# try to preserve lazy loading
if hasattr(j, 'getNodeIndexCache') and j.getNodeIndexCache() and 'subjobs:status' in j.getNodeIndexCache():
if len(j.getNodeIndexCache()['subjobs:status']) != 0:
total += len(j.getNodeIndexCache()['subjobs:status'])
else:
total += 1
else:
#logger.warning("WARNING: (status check) No index cache for job object %d" % jid)
if j.subjobs:
total = len(j.subjobs)
else:
total = 1
return total
示例6: test_update
def test_update(self):
from Ganga import GPI
t = GPI.LHCbTask()
tr = GPI.LHCbTransform(application=DaVinci(), backend=Dirac())
t.appendTransform(tr)
try:
bkQueryList = [GPI.BKTestQuery(stripping20up)]
tr.updateQuery()
assert false, 'Should have thrown exception if updated with no query'
except:
tr.addQuery(GPI.BKTestQuery(stripping20down))
# Check some new data added
assert len(tr.inputdata), 'No data added after call to update'
try:
# Shouldn't allow a second update before processed the data in
# toProcess_dataset
tr.updateQuery()
assert false, 'Should have thrown an error if updated with files already to process'
except:
# run so can update again with a removed dataset recall that jobs with the
# old dataset only created when run called.
t.run()
assert len(tr.getJobs()), "No Jobs created upon run()"
job = GPI.jobs(int(tr.getJobs()[0].fqid.split('.')[0]))
sleep_until_state(job, 300, 'submitted')
del tr._impl.query.dataset.files[0]
tr.update(True)
# Check the dead dataset is picked up
assert len(
tr._impl.removed_data.files), "Didn\'t Pick up loss of a dataset"
job.remove()
示例7: removeUnusedJobs
def removeUnusedJobs(self):
"""Remove all jobs that aren't being used, e.g. failed jobs"""
for unit in self.units:
for jid in unit.prev_job_ids:
try:
logger.warning("Removing job '%d'..." % jid)
job = GPI.jobs(jid)
job.remove()
except:
logger.error("Problem removing job '%d'" % jid)
示例8: updateStatus
def updateStatus(self, status):
"""Update status hook"""
# register the dataset if applicable
if status == "completed":
job = GPI.jobs(self.active_job_ids[0])
if job.outputdata and job.outputdata._impl._name == "DQ2OutputDataset" and not self.registerDataset():
return
super(AtlasUnit,self).updateStatus(status)
示例9: _getPartitionMasterJob
def _getPartitionMasterJob(self, partition):
"""Get the master job from any number of partition jobs."""
partition_jobs = self.getPartitionJobs(partition) # only call method once
if not len(partition_jobs):
raise GangaException(None, "Cant get partition master job when NO jobs assigned to partition")
elif len(partition_jobs) is 1:
return partition_jobs[0]
# Need registry access here might be better to get registry directly
# as in prepared stuff, see Executable for example or even
# tasksregistry.py!
return GPI.jobs(partition_jobs[0].fqid.split(".")[0])
示例10: getParentUnitJobs
def getParentUnitJobs(self, parent_units, include_subjobs=True):
"""Return the list of parent jobs"""
job_list = []
for parent in parent_units:
job = GPI.jobs(parent.active_job_ids[0])
if job.subjobs:
job_list += job.subjobs
else:
job_list += [job]
return job_list
示例11: updateStatus
def updateStatus(self, status):
"""Update status hook"""
# check for input data deletion of chain data
if status == "completed" and self._getParent().delete_chain_input and len(self.req_units) > 0:
# the inputdata field *must* be filled from the parent task
# NOTE: When changing to inputfiles, will probably need to check
# for any specified in trf.inputfiles
# check that the parent replicas have been copied by checking
# backend status == Done
job_list = []
for req_unit in self.req_units:
trf = self._getParent()._getParent().transforms[
int(req_unit.split(":")[0])]
req_unit_id = req_unit.split(":")[1]
if req_unit_id != "ALL":
unit = trf.units[int(req_unit_id)]
job_list.append(GPI.jobs(unit.active_job_ids[0]))
else:
for unit in trf.units:
job_list.append(GPI.jobs(unit.active_job_ids[0]))
for j in job_list:
if j.subjobs:
for sj in j.subjobs:
if sj.backend.status != "Done":
return
else:
if j.backend.status != "Done":
return
job = GPI.jobs(self.active_job_ids[0])
for f in job.inputdata.files:
logger.warning(
"Removing chain inputdata file '%s'..." % f.name)
f.remove()
super(LHCbUnit, self).updateStatus(status)
示例12: remove
def remove(self, remove_jobs="do_nothing"):
"""Delete the task"""
# make sure the task isn't running
if self.status.find("running") != -1:
logger.error(
"Task is still running. Please pause before removing!")
return
if not remove_jobs in [True, False]:
logger.info("You want to remove the task %i named '%s'." %
(self.id, self.name))
logger.info(
"Since this operation cannot be easily undone, please call this command again:")
logger.info(
" * as tasks(%i).remove(remove_jobs=True) if you want to remove all associated jobs," % (self.id))
logger.info(
" * as tasks(%i).remove(remove_jobs=False) if you want to keep the jobs." % (self.id))
return
if remove_jobs:
for trf in self.transforms:
for unit in trf.units:
for jid in unit.active_job_ids:
try:
j = GPI.jobs(jid)
j.remove()
except Exception as err:
logger.debug("Remove Err: %s" % str(err))
pass
for jid in unit.prev_job_ids:
try:
j = GPI.jobs(jid)
j.remove()
except Exception as err2:
logger.debug("Remove Err2: %s" % str(err2))
pass
self._getRegistry()._remove(self)
logger.info("Task #%s deleted" % self.id)
示例13: checkForResubmission
def checkForResubmission(self):
"""check if this unit should be resubmitted"""
# check if we already have a job
if len(self.active_job_ids) == 0:
return False
else:
job = GPI.jobs(self.active_job_ids[0])
if job.status in ["failed", "killed"]:
return True
return False
示例14: createChainUnit
def createChainUnit(self, parent_units, use_copy_output=True):
"""Create an output unit given this output data"""
# we need a parent job that has completed to get the output files
incl_pat_list = []
excl_pat_list = []
for parent in parent_units:
if len(parent.active_job_ids) == 0 or parent.status != "completed":
return None
for inds in self.inputdata:
from Ganga.GPI import TaskChainInput
if isType(inds, TaskChainInput) and inds.input_trf_id == parent._getParent().getID():
incl_pat_list += inds.include_file_mask
excl_pat_list += inds.exclude_file_mask
# go over the output files and copy the appropriates over as input
# files
flist = []
import re
for parent in parent_units:
job = GPI.jobs(parent.active_job_ids[0])
if job.subjobs:
job_list = job.subjobs
else:
job_list = [job]
for sj in job_list:
for f in sj.outputfiles:
# match any dirac files that are allowed in the file mask
if isType(f, DiracFile):
if len(incl_pat_list) > 0:
for pat in incl_pat_list:
if re.search(pat, f.lfn):
flist.append("LFN:" + f.lfn)
else:
flist.append("LFN:" + f.lfn)
if len(excl_pat_list) > 0:
for pat in excl_pat_list:
if re.search(pat, f.lfn) and "LFN:" + f.lfn in flist:
flist.remove("LFN:" + f.lfn)
# just do one unit that uses all data
unit = LHCbUnit()
unit.name = "Unit %d" % len(self.units)
unit.inputdata = LHCbDataset(files=[DiracFile(lfn=f) for f in flist])
return unit
示例15: n_active
def n_active(self):
if self.status == 'completed':
return 0
tot_active = 0
active_states = ['submitted', 'running']
for jid in self.active_job_ids:
try:
job = GPI.jobs(jid)
except Exception as err:
logger.debug("n_active Err: %s" % str(err))
task = self._getParent()._getParent()
trf = self._getParent()
logger.warning("Cannot find job with id %d. Maybe reset this unit with: tasks(%d).transforms[%d].resetUnit(%d)" %
(jid, task.id, trf.getID(), self.getID()))
continue
j = stripProxy(job)
# try to preserve lazy loading
if hasattr(j, 'getNodeIndexCache') and j.getNodeIndexCache() and 'subjobs:status' in j.getNodeIndexCache():
if len(j.getNodeIndexCache()['subjobs:status']) > 0:
for sj_stat in j.getNodeIndexCache()['subjobs:status']:
if sj_stat in active_states:
tot_active += 1
else:
if j.getNodeIndexCache()['status'] in active_states:
tot_active += 1
else:
#logger.warning("WARNING: (active check) No index cache for job object %d" % jid)
if j.status in active_states:
if j.subjobs:
for sj in j.subjobs:
if sj.status in active_states:
tot_active += 1
else:
tot_active += 1
return tot_active