MinosRSMJob.py

Go to the documentation of this file.
00001 import os
00002 import re
00003 
00004 from GBSJob       import GBSJob
00005 from MinosRSMTask import IsValidJobName
00006 
00007 class MinosRSMJob(GBSJob) :
00008     """Object to submit, and if necessary resubmit a job until it
00009     succeeds or needs user intervention.
00010 
00011     This class inherits from GBSJob and exploits the constraint,
00012     imposed by MinosRSMTask, that its name must be of the form:-
00013 
00014       job_rrrrrrrr_ssss
00015 
00016       where
00017 
00018         rrrrrrrr  is an 8 digit zero padded run number
00019         ssss      is a 4 digit zero padded subrun number
00020 
00021     to add to its local environment:-
00022 
00023       run=<run-number>
00024       subrun=<subrun-number>
00025 
00026     It introduces the new methods:-
00027 
00028       GetRun()
00029       GetSubrun()
00030       Rename(new_name)
00031 
00032     """
00033 
00034     ######  GBSObject inherited responsibilities   ###### 
00035       
00036 
00037     def __init__(self,name,parent,model,model_args):
00038         GBSJob.__init__(self,name,parent,model,model_args)
00039         self.SetLocalEnvironment(self.GetLocalEnvironment())
00040 
00041     def _DoMemberIO(self,ioh):
00042         GBSJob._DoMemberIO(self,ioh)
00043 
00044     def GetType(self): return "MinosRSMJob"
00045 
00046     def __repr__(self) : return self.AsString()
00047     
00048     ######  User Callable Methods (Getters then Setters)  ###### 
00049 
00050     def GetRun(self):
00051         """Return run number"""
00052         return int(re.search(r"job_(\d+)",self.GetName()).group(1))
00053 
00054     def GetSubrun(self):
00055         """Return subrun number"""
00056         return int(re.search(r"job_\d+_(\d+)",self.GetName()).group(1))
00057 
00058     def SetLocalEnvironment(self,env_str):
00059 
00060         """Set, as a comma separated list string, the environment that local to this job.
00061 
00062         Extends the GBSJob method by adding run=<run-number>,subrun=<subrun-number>."""
00063 
00064         GBSJob.SetLocalEnvironment(self,env_str)
00065         GBSJob.SetLocalEnvironment(self,"+run=" + str(self.GetRun()) + ",subrun=" + str(self.GetSubrun()))
00066 
00067         
00068     ######  Private Methods (not user callable)  ######
00069 
00070     def _Rename(self,new_name):
00071         """Rename job to new_name.  Should only be called by parent Task."""
00072 
00073         #  Check that rename is legal.
00074         if not IsValidJobName(new_name): return
00075         if self.GetParent().GetJob(new_name,False):
00076             print "Sorry, there already is a job named " + new_name
00077             return
00078         
00079         # Perform rename including environmental variables, state file and child directory (if present).
00080         old_state_file = self.GetStoreLocation("self")
00081         old_child_dir  = self.GetStoreLocation("child_dir")
00082         GBSJob.Rename(self,new_name)
00083         new_state_file = self.GetStoreLocation("self")
00084         new_child_dir  = self.GetStoreLocation("child_dir")
00085         os.rename(old_state_file,new_state_file)
00086         if os.path.isdir(old_child_dir): os.rename(old_child_dir,new_child_dir)
00087         self.SetLocalEnvironment(self.GetLocalEnvironment())
00088         self.Write()        

Generated on Fri Mar 5 09:25:41 2010 for gbs by  doxygen 1.4.7