00001 import os
00002 import re
00003
00004 from GBSTask import GBSTask
00005
00006 class MinosDCMTask(GBSTask) :
00007 """Top level object to manage a single task.
00008
00009 This class inherits from GBSTask and adds the following user callable methods
00010
00011 Getters:-
00012
00013 GetDCMQuery()
00014 Return the DCM Query used to create ProtoJobs
00015
00016
00017 Setters:-
00018
00019 SetDCMQuery(query)
00020
00021 Define the DCM query used to create ProtoJobs
00022
00023 e.g. task.SetDCMQuery("[ file_name like N00008695_002%.cosmic.sntp.R1_18.0.root ]")
00024
00025 AddProtoJob()
00026
00027 Apply DCM query and for each file returned use the run and
00028 subrun numbers to form a name. If a Job of that name does not
00029 already exist add a ProtJob using the DCM URL as the Script Local
00030 Arg.
00031
00032 Warn if there are Jobs that don't correspond to a file returned
00033 from the query.
00034 """
00035
00036
00037
00038
00039 def __init__(self,name,parent,model,model_args):
00040 self.__DCMQuery = ""
00041
00042 GBSTask.__init__(self,name,parent,model,model_args)
00043
00044 def _DoMemberIO(self,ioh):
00045 self.__DCMQuery = ioh("DCM Query", "s",self.__DCMQuery)
00046 GBSTask._DoMemberIO(self,ioh)
00047
00048 def GetType(self): return "MinosDCMTask"
00049
00050 def __repr__(self) : return self.AsString()
00051
00052
00053
00054
00055 def AsString(self,level = "Full"):
00056
00057 """Return string description.
00058
00059 Return string description at the following levels:-
00060 "Brief" one line summary suitable for rows in tables
00061 "Heading" one line summary suitable as heading for "Brief"
00062 "Full" full desciption including value of every data member"""
00063
00064 if ( level == "Heading" \
00065 or level == "Brief" ): return GBSTask.AsString(self,level)
00066
00067 s = GBSTask.AsString(self,level)
00068 s += "\nDCM Query: '" + self.__DCMQuery + "'"
00069 return s
00070
00071
00072 def AddProtoJob(self):
00073
00074 """Apply DCM query and add new ProtJobs as necessary."""
00075
00076 file_list_file = self.GetStoreLocation("child_dir") + "/DCM_query_result"
00077 if os.path.isfile(file_list_file): os.remove(file_list_file)
00078 cmd = "$DCM_HOME/dcm.sh get --accept_dcm_url --file_list %s %s >/dev/null" % (file_list_file,self.__DCMQuery)
00079 if os.system(cmd):
00080 print "Failed to run " + cmd
00081 return
00082 f = open(file_list_file)
00083
00084
00085 unmatched_jobs = GBSTask.GetJobs(self)
00086
00087 num_pjobs = 0
00088 for line in f:
00089 line = line.rstrip()
00090 mo = re.search(r"(\d{6,}_\d{3,})",line)
00091 if not mo:
00092 print "Cannot extract run and subrun number from: " + line,
00093 else:
00094 job_name = mo.group(1)
00095
00096 if unmatched_jobs.has_key(job_name): del unmatched_jobs[job_name]
00097 if GBSTask.AddProtoJob(self,job_name,line):
00098 print "Accepting job_%s: %s" % (job_name,line)
00099 num_pjobs += 1
00100
00101 f.close()
00102 os.remove(file_list_file)
00103
00104 if num_pjobs: print str(num_pjobs) + " Protojobs created"
00105 else: print "No Protojobs created"
00106
00107
00108 unmatched_job_names = unmatched_jobs.keys()
00109 if len(unmatched_job_names):
00110 print "\nCaution: The following jobs are not part of the current DCM query:-\n"
00111 unmatched_job_names.sort()
00112 for job_name in unmatched_job_names:
00113 print job_name + ": " + unmatched_jobs[job_name].GetScriptLocalArgs()
00114
00115 def GetDCMQuery(self):
00116
00117 """Return the DCM Query used to create ProtoJobs"""
00118
00119 return self.__DCMQuery
00120
00121 def SetDCMQuery(self,query):
00122
00123 """Define the DCM query used to create ProtoJobs"""
00124
00125 if self.IsDisabled("SetDCMQuery"): return
00126 self.__DCMQuery = query
00127 self.Write()
00128
00129 def GetTestOnlyMethods(self):
00130
00131 """Return a list of methods that are only available in 'Test' mode."""
00132
00133 l = GBSTask.GetTestOnlyMethods(self)
00134 l.append("SetDCMQuery")
00135 return l
00136
00137
00138
00139