stagestatus.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 ######################################################################
3 #
4 # Name: stagestatus.py
5 #
6 # Purpose: Python class StageStatus (used by project.py script).
7 # This class contains information about project stage status.
8 #
9 # Created: 12-Dec-2014 Herbert Greenlee
10 #
11 ######################################################################
12 
13 from __future__ import absolute_import
14 from __future__ import print_function
15 import os
16 import project_utilities
17 import larbatch_posix
18 
19 # Project status class.
20 
22 
23  # Constructor.
24 
25  def __init__(self, stage):
26 
27  # Default values.
28 
29  self.stage = stage # Stage name.
30  self.exists = False # Does bookdir exist?
31  self.nfile = 0 # Number of good art files.
32  self.nev = 0 # Number of good art events.
33  self.nana = 0 # Number of good non-art root files.
34  self.nerror = 0 # Number of workers with errors.
35  self.nmiss = 0 # Number of unprocessed input files.
36 
37  # Update data.
38 
39  self.update()
40 
41  # Update data for this stage.
42 
43  def update(self):
44 
45  bookdir = self.stage.bookdir
46 
47  # Test whether output directory exists.
48 
49  if larbatch_posix.exists(bookdir):
50 
51  # Output directory exists.
52 
53  self.exists = True
54  self.nfile = 0
55  self.nev = 0
56  self.nana = 0
57  self.nerror = 0
58  self.nmiss = 0
59 
60  # Count good files and events.
61 
62  eventsfile = os.path.join(bookdir, 'events.list')
63  if larbatch_posix.exists(eventsfile):
64  lines = larbatch_posix.readlines(eventsfile)
65  for line in lines:
66  words = line.split()
67  if len(words) >= 2:
68  self.nfile = self.nfile + 1
69  self.nev = self.nev + int(words[1])
70 
71  # Count good files analysis root files.
72 
73  filesana = os.path.join(bookdir, 'filesana.list')
74  if larbatch_posix.exists(filesana):
75  lines = larbatch_posix.readlines(filesana)
76  for line in lines:
77  self.nana = self.nana + 1
78 
79  # Count errors.
80 
81  badfile = os.path.join(bookdir, 'bad.list')
82  if larbatch_posix.exists(badfile):
83  lines = larbatch_posix.readlines(badfile)
84  for line in lines:
85  if line.strip():
86  self.nerror += 1
87 
88  # Count missing files.
89 
90  missingfile = os.path.join(bookdir, 'missing_files.list')
91  if larbatch_posix.exists(missingfile):
92  lines = larbatch_posix.readlines(missingfile)
93  for line in lines:
94  if line.strip():
95  self.nmiss += 1
96 
97  else:
98 
99  # Output directory does not exist.
100 
101  self.exists = False
102