All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
python.projectdef.ProjectDef Class Reference

Public Member Functions

def __init__
 
def __str__
 
def get_stage
 
def get_fcl
 

Public Attributes

 name
 
 num_events
 
 num_jobs
 
 max_files_per_job
 
 ups
 
 os
 
 resource
 
 role
 
 lines
 
 server
 
 site
 
 blacklist
 
 cpu
 
 disk
 
 memory
 
 merge
 
 anamerge
 
 release_tag
 
 release_qual
 
 version
 
 local_release_dir
 
 local_release_tar
 
 file_type
 
 run_type
 
 run_number
 
 script
 
 validate_on_worker
 
 copy_to_fts
 
 cvmfs
 
 stash
 
 singularity
 
 start_script
 
 stop_script
 
 force_dag
 
 fclpath
 
 stages
 
 parameters
 

Detailed Description

Definition at line 23 of file projectdef.py.

Constructor & Destructor Documentation

def python.projectdef.ProjectDef.__init__ (   self,
  project_element,
  default_first_input_list,
  default_input_lists,
  check = True 
)

Definition at line 28 of file projectdef.py.

28 
29  def __init__(self, project_element, default_first_input_list, default_input_lists, check=True):
30 
31  # Assign default values.
32 
33  self.name= '' # Project name.
34  self.num_events = 0 # Total events (all jobs).
35  self.num_jobs = 1 # Number of jobs.
36  self.max_files_per_job = 0 # Max number of files per job.
37  self.ups = [] # Top level ups products.
38  self.os = '' # Batch OS.
39  self.resource = 'DEDICATED,OPPORTUNISTIC' # Jobsub resources.
40  self.role = '' # Role (normally Analysis or Production).
41  self.lines = '' # Arbitrary condor commands.
42  self.server = '-' # Jobsub server.
43  self.site = '' # Site.
44  self.blacklist = '' # Blacklist.
45  self.cpu = 0 # Number of cpus.
46  self.disk = '' # Disk space (string value+unit).
47  self.memory = 0 # Amount of memory (integer MB).
48  self.merge = 'hadd -T' # histogram merging program.
49  self.anamerge = '' # Analysis merge flag.
50  self.release_tag = '' # Larsoft release tag.
51  self.release_qual = 'debug' # Larsoft release qualifier.
52  self.version = '' # Project version.
53  self.local_release_dir = '' # Larsoft local release directory.
54  self.local_release_tar = '' # Larsoft local release tarball.
55  self.file_type = '' # Sam file type.
56  self.run_type = '' # Sam run type.
57  self.run_number = 0 # Sam run number.
58  self.script = 'condor_lar.sh' # Batch script.
59  self.validate_on_worker = 0 # Run post-job validation on the worker node
60  self.copy_to_fts = 0 # Copy a copy of the file to a dropbox scanned by fts. Note that a copy is still sent to <outdir>
61  self.cvmfs = 1 # Cvmfs flag.
62  self.stash = 1 # Stash cache flag.
63  self.singularity = 1 # Singularity flag.
64  self.start_script = 'condor_start_project.sh' # Sam start project script.
65  self.stop_script = 'condor_stop_project.sh' # Sam stop project script.
66  self.force_dag = 0 # Force dag for sam input jobs.
67  self.fclpath = [] # Fcl search path.
68  self.stages = [] # List of stages (StageDef objects).
69  self.parameters = {} # Dictionary of metadata parameters.
70 
71  # Extract values from xml.
72 
73  # Project name (attribute)
74 
75  if 'name' in dict(project_element.attributes):
76  self.name = str(project_element.attributes['name'].firstChild.data)
77  if self.name == '':
78  raise XMLError('Project name not specified.')
79 
80  # Total events (subelement).
81 
82  num_events_elements = project_element.getElementsByTagName('numevents')
83  for num_events_element in num_events_elements:
84  if num_events_element.parentNode == project_element:
85  self.num_events = int(num_events_element.firstChild.data)
86  if self.num_events == 0:
87  raise XMLError('Number of events not specified.')
88 
89  # Number of jobs (subelement).
90 
91  num_jobs_elements = project_element.getElementsByTagName('numjobs')
92  for num_jobs_element in num_jobs_elements:
93  if num_jobs_element.parentNode == project_element:
94  self.num_jobs = int(num_jobs_element.firstChild.data)
95 
96  # Max Number of files per jobs.
97 
98  max_files_per_job_elements = project_element.getElementsByTagName('maxfilesperjob')
99  for max_files_per_job_element in max_files_per_job_elements:
100  if max_files_per_job_element.parentNode == project_element:
101  self.max_files_per_job = int(max_files_per_job_element.firstChild.data)
102 
103  # Top level ups product (repeatable subelement).
104 
105  ups_elements = project_element.getElementsByTagName('ups')
106  for ups_element in ups_elements:
107  self.ups.append(str(ups_element.firstChild.data))
108 
109  # If ups products list is empty, set default.
110 
111  if len(self.ups) == 0:
112  self.ups = get_ups_products().split(',')
113 
114  # OS (subelement).
115 
116  os_elements = project_element.getElementsByTagName('os')
117  for os_element in os_elements:
118  if os_element.parentNode == project_element:
119  self.os = str(os_element.firstChild.data)
120  self.os = ''.join(self.os.split())
121 
122  # Resource (subelement).
123 
124  resource_elements = project_element.getElementsByTagName('resource')
125  for resource_element in resource_elements:
126  if resource_element.parentNode == project_element:
127  self.resource = str(resource_element.firstChild.data)
128  self.resource = ''.join(self.resource.split())
129 
130  # Role (subelement).
131 
132  role_elements = project_element.getElementsByTagName('role')
133  for role_element in role_elements:
134  if role_element.parentNode == project_element:
135  self.role = str(role_element.firstChild.data)
136 
137  # Lines (subelement).
138 
139  lines_elements = project_element.getElementsByTagName('lines')
140  for lines_element in lines_elements:
141  if lines_element.parentNode == project_element:
142  self.lines = str(lines_element.firstChild.data)
143 
144  # Server (subelement).
145 
146  server_elements = project_element.getElementsByTagName('server')
147  for server_element in server_elements:
148  if server_element.parentNode == project_element:
149  self.server = str(server_element.firstChild.data)
150 
151  # Site (subelement).
152 
153  site_elements = project_element.getElementsByTagName('site')
154  for site_element in site_elements:
155  if site_element.parentNode == project_element:
156  self.site = str(site_element.firstChild.data)
157  self.site = ''.join(self.site.split())
158 
159  # Blacklist (subelement).
160 
161  blacklist_elements = project_element.getElementsByTagName('blacklist')
162  for blacklist_element in blacklist_elements:
163  if blacklist_element.parentNode == project_element:
164  self.blacklist = str(blacklist_element.firstChild.data)
165  self.blacklist = ''.join(self.blacklist.split())
166 
167  # Cpu (subelement).
168 
169  cpu_elements = project_element.getElementsByTagName('cpu')
170  for cpu_element in cpu_elements:
171  if cpu_element.parentNode == project_element:
172  self.cpu = int(cpu_element.firstChild.data)
173 
174  # Disk (subelement).
175 
176  disk_elements = project_element.getElementsByTagName('disk')
177  for disk_element in disk_elements:
178  if disk_element.parentNode == project_element:
179  self.disk = str(disk_element.firstChild.data)
180  self.disk = ''.join(self.disk.split())
181 
182  # Memory (subelement).
183 
184  memory_elements = project_element.getElementsByTagName('memory')
185  for memory_element in memory_elements:
186  if memory_element.parentNode == project_element:
187  self.memory = int(memory_element.firstChild.data)
188 
189  # merge (subelement).
190 
191  merge_elements = project_element.getElementsByTagName('merge')
192  for merge_element in merge_elements:
193  if merge_element.parentNode == project_element:
194  if merge_element.firstChild:
195  self.merge = str(merge_element.firstChild.data)
196  else:
197  self.merge = ''
198 
199  # anamerge (subelement).
200 
201  anamerge_elements = project_element.getElementsByTagName('anamerge')
202  for anamerge_element in anamerge_elements:
203  if anamerge_element.parentNode == project_element:
204  if anamerge_element.firstChild:
205  self.anamerge = str(anamerge_element.firstChild.data)
206  else:
207  self.anamerge = ''
208 
209  # Larsoft (subelement).
210 
211  larsoft_elements = project_element.getElementsByTagName('larsoft')
212  if larsoft_elements:
213 
214  # Release tag (subelement).
215 
216  tag_elements = larsoft_elements[0].getElementsByTagName('tag')
217  if tag_elements and tag_elements[0].firstChild != None:
218  self.release_tag = str(tag_elements[0].firstChild.data)
219 
220  # Release qualifier (subelement).
221 
222  qual_elements = larsoft_elements[0].getElementsByTagName('qual')
223  if qual_elements:
224  self.release_qual = str(qual_elements[0].firstChild.data)
225 
226  # Local release directory or tarball (subelement).
227  #
228 
229  local_elements = larsoft_elements[0].getElementsByTagName('local')
230  if local_elements:
231  local = str(local_elements[0].firstChild.data)
232  if larbatch_posix.isdir(local):
233  self.local_release_dir = local
234  else:
235  self.local_release_tar = local
236 
237  # Version (subelement).
238 
239  version_elements = project_element.getElementsByTagName('version')
240  if version_elements:
241  self.version = str(version_elements[0].firstChild.data)
242  else:
243  self.version = self.release_tag
244 
245  # Make sure local test release directory/tarball exists, if specified.
246  # Existence of non-null local_release_dir has already been tested.
247 
248  if check and self.local_release_tar != '' and not larbatch_posix.exists(self.local_release_tar):
249  raise IOError("Local release directory/tarball %s does not exist." % self.local_release_tar)
250 
251  # Sam file type (subelement).
252 
253  file_type_elements = project_element.getElementsByTagName('filetype')
254  if file_type_elements:
255  self.file_type = str(file_type_elements[0].firstChild.data)
256 
257  # Sam run type (subelement).
258 
259  run_type_elements = project_element.getElementsByTagName('runtype')
260  if run_type_elements:
261  self.run_type = str(run_type_elements[0].firstChild.data)
262 
263  # Sam run number (subelement).
264 
265  run_number_elements = project_element.getElementsByTagName('runnumber')
266  if run_number_elements:
267  self.run_number = int(run_number_elements[0].firstChild.data)
268 
269  # Batch script (subelement).
270 
271  script_elements = project_element.getElementsByTagName('script')
272  for script_element in script_elements:
273  if script_element.parentNode == project_element:
274  self.script = str(script_element.firstChild.data)
275 
276  # Make sure batch script exists, and convert into a full path.
277 
278  if check:
279  script_path = ''
280  try:
281  jobinfo = subprocess.Popen(['which', self.script],
282  stdout=subprocess.PIPE,
283  stderr=subprocess.PIPE)
284  jobout, joberr = jobinfo.communicate()
285  jobout = convert_str(jobout)
286  joberr = convert_str(joberr)
287  rc = jobinfo.poll()
288  script_path = jobout.splitlines()[0].strip()
289  except:
290  pass
291  if script_path == '' or not larbatch_posix.access(script_path, os.X_OK):
292  raise IOError('Script %s not found.' % self.script)
293  self.script = script_path
294 
295  # Validate-on-worker flag (subelement).
296 
297  worker_validations = project_element.getElementsByTagName('check')
298  for worker_validation in worker_validations:
299  if worker_validation.parentNode == project_element:
300  self.validate_on_worker = int(worker_validation.firstChild.data)
301 
302  # Copy to FTS flag (subelement).
303 
304  worker_copys = project_element.getElementsByTagName('copy')
305  for worker_copy in worker_copys:
306  if worker_copy.parentNode == project_element:
307  self.copy_to_fts = int(worker_copy.firstChild.data)
308 
309  # Cvmfs flag (subelement).
310 
311  cvmfs_elements = project_element.getElementsByTagName('cvmfs')
312  for cvmfs_element in cvmfs_elements:
313  if cvmfs_element.parentNode == project_element:
314  self.cvmfs = int(cvmfs_element.firstChild.data)
315 
316  # Stash flag (subelement).
317 
318  stash_elements = project_element.getElementsByTagName('stash')
319  for stash_element in stash_elements:
320  if stash_element.parentNode == project_element:
321  self.stash = int(stash_element.firstChild.data)
322 
323  # Singularity flag (subelement).
324 
325  singularity_elements = project_element.getElementsByTagName('singularity')
326  for singularity_element in singularity_elements:
327  if singularity_element.parentNode == project_element:
328  self.singularity = int(singularity_element.firstChild.data)
329 
330  # Start project batch script (subelement).
331 
332  start_script_elements = project_element.getElementsByTagName('startscript')
333  for start_script_element in start_script_elements:
334  if start_script_element.parentNode == project_element:
335  self.start_script = str(start_script_element.firstChild.data)
336  self.force_dag = 1
337 
338  # Make sure start project batch script exists, and convert into a full path.
339 
340  if check:
341  script_path = ''
342  try:
343  jobinfo = subprocess.Popen(['which', self.start_script],
344  stdout=subprocess.PIPE,
345  stderr=subprocess.PIPE)
346  jobout, joberr = jobinfo.communicate()
347  jobout = convert_str(jobout)
348  joberr = convert_str(joberr)
349  rc = jobinfo.poll()
350  script_path = jobout.splitlines()[0].strip()
351  except:
352  pass
353  self.start_script = script_path
354 
355  # Stop project batch script (subelement).
356 
357  stop_script_elements = project_element.getElementsByTagName('stopscript')
358  for stop_script_element in stop_script_elements:
359  if stop_script_element.parentNode == project_element:
360  self.stop_script = str(stop_script_element.firstChild.data)
361  self.force_dag = 1
362 
363  # Make sure stop project batch script exists, and convert into a full path.
364 
365  if check:
366  script_path = ''
367  try:
368  jobinfo = subprocess.Popen(['which', self.stop_script],
369  stdout=subprocess.PIPE,
370  stderr=subprocess.PIPE)
371  jobout, joberr = jobinfo.communicate()
372  jobout = convert_str(jobout)
373  joberr = convert_str(joberr)
374  rc = jobinfo.poll()
375  script_path = jobout.splitlines()[0].strip()
376  except:
377  pass
378  self.stop_script = script_path
379 
380  # Fcl search path (repeatable subelement).
381 
382  fclpath_elements = project_element.getElementsByTagName('fcldir')
383  for fclpath_element in fclpath_elements:
384  self.fclpath.append(str(fclpath_element.firstChild.data))
385 
386  # Add $FHICL_FILE_PATH.
387 
388  if check and 'FHICL_FILE_PATH' in os.environ:
389  for fcldir in os.environ['FHICL_FILE_PATH'].split(':'):
390  if larbatch_posix.exists(fcldir):
391  self.fclpath.append(fcldir)
392 
393  # Make sure all directories of fcl search path exist.
394 
395  if check:
396  for fcldir in self.fclpath:
397  if not larbatch_posix.exists(fcldir):
398  raise IOError("Fcl search directory %s does not exist." % fcldir)
399 
400  # Project stages (repeatable subelement).
401 
402  stage_elements = project_element.getElementsByTagName('stage')
403  default_previous_stage = ''
404  default_input_lists[default_previous_stage] = default_first_input_list
405  for stage_element in stage_elements:
406 
407  # Get base stage, if any.
408 
409  base_stage = None
410  if 'base' in dict(stage_element.attributes):
411  base_name = str(stage_element.attributes['base'].firstChild.data)
412  if base_name != '':
413  for stage in self.stages:
414  if stage.name == base_name:
415  base_stage = stage
416  break
417 
418  if base_stage == None:
419  raise LookupError('Base stage %s not found.' % base_name)
420 
421  self.stages.append(StageDef(stage_element,
422  base_stage,
423  default_input_lists,
424  default_previous_stage,
425  self.num_jobs,
426  self.num_events,
427  self.max_files_per_job,
428  self.merge,
429  self.anamerge,
430  self.cpu,
431  self.disk,
432  self.memory,
433  self.validate_on_worker,
434  self.copy_to_fts,
435  self.cvmfs,
436  self.stash,
437  self.singularity,
438  self.script,
439  self.start_script,
440  self.stop_script,
441  self.site,
442  self.blacklist,
443  check=check))
444  default_previous_stage = self.stages[-1].name
445  default_input_lists[default_previous_stage] = os.path.join(self.stages[-1].bookdir,
446  'files.list')
447 
448  # Dictionary of metadata parameters
449 
450  param_elements = project_element.getElementsByTagName('parameter')
451  for param_element in param_elements:
452  name = str(param_element.attributes['name'].firstChild.data)
453  value = str(param_element.firstChild.data)
454  self.parameters[name] = value
455 
456  # Done.
457 
458  return
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.

Member Function Documentation

def python.projectdef.ProjectDef.__str__ (   self)

Definition at line 461 of file projectdef.py.

462  def __str__(self):
463  result = 'Project name = %s\n' % self.name
464  result += 'Total events = %d\n' % self.num_events
465  result += 'Number of jobs = %d\n' % self.num_jobs
466  result += 'Max files per job = %d\n' % self.max_files_per_job
467  result += 'Top level ups products:\n'
468  for prod in self.ups:
469  result += ' %s\n' % prod
470  result += 'OS = %s\n' % self.os
471  result += 'Resource = %s\n' % self.resource
472  result += 'Role = %s\n' % self.role
473  result += 'Lines = %s\n' % self.lines
474  result += 'Jobsub server = %s\n' % self.server
475  result += 'Site = %s\n' % self.site
476  result += 'Blacklist = %s\n' % self.blacklist
477  result += 'Cpu = %d\n' % self.cpu
478  result += 'Disk = %s\n' % self.disk
479  result += 'Memory = %d MB\n' % self.memory
480  result += 'Histogram merging program = %s\n' % self.merge
481  result += 'Analysis merge flag = %s\n' % self.anamerge
482  result += 'Larsoft release tag = %s\n' % self.release_tag
483  result += 'Larsoft release qualifier = %s\n' % self.release_qual
484  result += 'Version = %s\n' % self.version
485  result += 'Local test release directory = %s\n' % self.local_release_dir
486  result += 'Local test release tarball = %s\n' % self.local_release_tar
487  result += 'File type = %s\n' % self.file_type
488  result += 'Run type = %s\n' % self.run_type
489  result += 'Run number = %d\n' % self.run_number
490  result += 'Batch script = %s\n' % self.script
491  result += 'Start sam project script = %s\n' % self.start_script
492  result += 'Stop sam project script = %s\n' % self.stop_script
493  result += 'Force dag = %d\n' % self.force_dag
494  result += 'Fcl search path:\n'
495  for fcldir in self.fclpath:
496  result += ' %s\n' % fcldir
497  result += 'Metadata parameters:\n'
498  for key in self.parameters:
499  result += '%s: %s\n' % (key,self.parameters[key])
500  result += '\nStages:'
501  for stage in self.stages:
502  result += '\n\n' + str(stage)
503  return result
def python.projectdef.ProjectDef.get_fcl (   self,
  fclname 
)

Definition at line 525 of file projectdef.py.

526  def get_fcl(self, fclname):
527 
528  fcl_list = []
529  for name in fclname:
530  fcl = ''
531  for fcldir in self.fclpath:
532  fcl = os.path.join(fcldir, name)
533  #print fcl
534  if larbatch_posix.exists(fcl):
535  break
536 
537  if fcl == '' or not larbatch_posix.exists(fcl):
538  raise IOError('Could not find fcl file %s.' % name)
539  fcl_list.append(fcl)
540  return fcl_list
def python.projectdef.ProjectDef.get_stage (   self,
  stagename 
)

Definition at line 506 of file projectdef.py.

507  def get_stage(self, stagename):
508 
509  if len(self.stages) == 0:
510  raise LookupError("Project does not have any stages.")
511 
512  elif stagename == '' and len(self.stages) == 1:
513  return self.stages[0]
514 
515  else:
516  for stage in self.stages:
517  if stagename == stage.name:
518  return stage
519 
520  # If we fell through to here, we didn't find an appropriate stage.
521 
522  raise RuntimeError('No stage %s.' % stagename)

Member Data Documentation

python.projectdef.ProjectDef.anamerge

Definition at line 48 of file projectdef.py.

python.projectdef.ProjectDef.blacklist

Definition at line 43 of file projectdef.py.

python.projectdef.ProjectDef.copy_to_fts

Definition at line 59 of file projectdef.py.

python.projectdef.ProjectDef.cpu

Definition at line 44 of file projectdef.py.

python.projectdef.ProjectDef.cvmfs

Definition at line 60 of file projectdef.py.

python.projectdef.ProjectDef.disk

Definition at line 45 of file projectdef.py.

python.projectdef.ProjectDef.fclpath

Definition at line 66 of file projectdef.py.

python.projectdef.ProjectDef.file_type

Definition at line 54 of file projectdef.py.

python.projectdef.ProjectDef.force_dag

Definition at line 65 of file projectdef.py.

python.projectdef.ProjectDef.lines

Definition at line 40 of file projectdef.py.

python.projectdef.ProjectDef.local_release_dir

Definition at line 52 of file projectdef.py.

python.projectdef.ProjectDef.local_release_tar

Definition at line 53 of file projectdef.py.

python.projectdef.ProjectDef.max_files_per_job

Definition at line 35 of file projectdef.py.

python.projectdef.ProjectDef.memory

Definition at line 46 of file projectdef.py.

python.projectdef.ProjectDef.merge

Definition at line 47 of file projectdef.py.

python.projectdef.ProjectDef.name

Definition at line 32 of file projectdef.py.

python.projectdef.ProjectDef.num_events

Definition at line 33 of file projectdef.py.

python.projectdef.ProjectDef.num_jobs

Definition at line 34 of file projectdef.py.

python.projectdef.ProjectDef.os

Definition at line 37 of file projectdef.py.

python.projectdef.ProjectDef.parameters

Definition at line 68 of file projectdef.py.

python.projectdef.ProjectDef.release_qual

Definition at line 50 of file projectdef.py.

python.projectdef.ProjectDef.release_tag

Definition at line 49 of file projectdef.py.

python.projectdef.ProjectDef.resource

Definition at line 38 of file projectdef.py.

python.projectdef.ProjectDef.role

Definition at line 39 of file projectdef.py.

python.projectdef.ProjectDef.run_number

Definition at line 56 of file projectdef.py.

python.projectdef.ProjectDef.run_type

Definition at line 55 of file projectdef.py.

python.projectdef.ProjectDef.script

Definition at line 57 of file projectdef.py.

python.projectdef.ProjectDef.server

Definition at line 41 of file projectdef.py.

python.projectdef.ProjectDef.singularity

Definition at line 62 of file projectdef.py.

python.projectdef.ProjectDef.site

Definition at line 42 of file projectdef.py.

python.projectdef.ProjectDef.stages

Definition at line 67 of file projectdef.py.

python.projectdef.ProjectDef.start_script

Definition at line 63 of file projectdef.py.

python.projectdef.ProjectDef.stash

Definition at line 61 of file projectdef.py.

python.projectdef.ProjectDef.stop_script

Definition at line 64 of file projectdef.py.

python.projectdef.ProjectDef.ups

Definition at line 36 of file projectdef.py.

python.projectdef.ProjectDef.validate_on_worker

Definition at line 58 of file projectdef.py.

python.projectdef.ProjectDef.version

Definition at line 51 of file projectdef.py.


The documentation for this class was generated from the following file: