CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Static Private Attributes
Mpslibclass.jobdatabase Class Reference

Public Member Functions

def get_class
 
def print_memdb
 
def read_db
 
def write_db
 

Public Attributes

 addFiles
 
 batchScript
 
 cfgTemplate
 
 classInf
 
 currentTime
 
 driver
 
 elapsedTime
 
 header
 
 infiList
 
 mergeScript
 
 mssDir
 
 mssDirPool
 
 nJobs
 
 pedeMem
 
 spare1
 
 spare2
 
 spare3
 
 updateTime
 
 updateTimeHuman
 

Static Private Attributes

string __default_db_file_name = "mps.db"
 

Detailed Description

Definition at line 46 of file Mpslibclass.py.

Member Function Documentation

def Mpslibclass.jobdatabase.get_class (   self,
  argument = '' 
)

Definition at line 238 of file Mpslibclass.py.

239  def get_class(self, argument=''):
240  CLASSES = self.classInf.split(':')
241  if len(CLASSES)<1 or len(CLASSES)>2:
242  print '\nget_class():\n class must be of the form \'class\' or \'classMille:classPede\', but is \'%s\'!\n\n', classInf
243  sys.exit(1)
244  elif argument == 'mille':
245  return CLASSES[0]
246  elif argument == 'pede':
247  if len(CLASSES) == 1:
248  return CLASSES[0]
249  elif len(CLASSES) == 2:
250  return CLASSES[1]
251  else:
252  print '\nget_class():\n Know class only for \'mille\' or \'pede\', not %s!\n\n' %argument
253  sys.exit(1)
def Mpslibclass.jobdatabase.print_memdb (   self)

Definition at line 127 of file Mpslibclass.py.

References Mpslibclass.jobdatabase.addFiles, Mpslibclass.jobdatabase.batchScript, Mpslibclass.jobdatabase.cfgTemplate, Mpslibclass.jobdatabase.classInf, Mpslibclass.jobdatabase.driver, Mpslibclass.jobdatabase.elapsedTime, Mpslibclass.jobdatabase.header, Mpslibclass.jobdatabase.infiList, Mpslibclass.jobdatabase.mergeScript, Mpslibclass.jobdatabase.mssDir, Mpslibclass.jobdatabase.mssDirPool, Mpslibclass.jobdatabase.nJobs, Mpslibclass.jobdatabase.pedeMem, and Mpslibclass.jobdatabase.updateTimeHuman.

128  def print_memdb(self):
129  #print metainfo
130  print "\n=== mps database printout ===\n"
131  print self.header
132  print 'Script:\t\t', self.batchScript
133  print 'cfg:\t\t', self.cfgTemplate
134  print 'files:\t\t', self.infiList
135  print 'class:\t\t', self.classInf
136  print 'name:\t\t', self.addFiles
137  print 'driver:\t\t', self.driver
138  print 'mergeScript:\t', self.mergeScript
139  print 'mssDir:\t\t', self.mssDir
140  print 'updateTime:\t', self.updateTimeHuman
141  print 'elapsed:\t', self.elapsedTime
142  print 'mssDirPool:\t', self.mssDirPool
143  print 'pedeMem:\t', self.pedeMem, '\n'
144 
145  #print interesting Job-level lists ---- to add: t/evt, fix remarks
146  print '### dir jobid stat try rtime nevt remark weight name'
147  print "------------------------------------------------------------------------------"
148  for i in xrange(self.nJobs):
149  print '%03d %6s %9d %6s %3d %5d %8d %8s %5s %s' % (
150  self.JOBNUMBER[i],
151  self.JOBDIR[i],
152  self.JOBID[i],
153  self.JOBSTATUS[i],
154  self.JOBNTRY[i],
155  self.JOBRUNTIME[i],
156  self.JOBNEVT[i],
157  self.JOBHOST[i],
158  self.JOBSP2[i],
159  self.JOBSP3[i])
160 
161  #print merge Jobs if merge mode
162  if self.driver == 'merge':
163  for i in xrange(self.nJobs,len(self.JOBDIR)):
164  print '%s %6s %9d %6s %3d %5d %8d %8s %5s %s' % (
165  'MMM',
166  self.JOBDIR[i],
167  self.JOBID[i],
168  self.JOBSTATUS[i],
169  self.JOBNTRY[i],
170  self.JOBRUNTIME[i],
171  self.JOBNEVT[i],
172  self.JOBHOST[i],
173  self.JOBSP2[i],
174  self.JOBSP3[i])
175 
176  #print summed info
177  totalEvents = sum(self.JOBNEVT[:self.nJobs])
178  totalCpu = sum(self.JOBRUNTIME[:self.nJobs])
179  meanCpuPerEvent = 0.
180  if totalEvents > 0:
181  meanCpuPerEvent = float(totalCpu)/totalEvents
182  print "------------------------------------------------------------------------------"
183  print "\t\t\t\t\tEvent total:\t", totalEvents
184  print "\t\t\t\t\tCPU total:\t", totalCpu, 's'
185  print "\t\t\t\t\tMean CPU/event:\t",meanCpuPerEvent,'s'
186 
187 
188 
189 
def Mpslibclass.jobdatabase.read_db (   self,
  db_file_name = __default_db_file_name 
)

Definition at line 59 of file Mpslibclass.py.

59 
60  def read_db(self, db_file_name = __default_db_file_name):
61  try:
62  DBFILE = open(db_file_name,'r')
63  except IOError as e:
64  if e.args != (2, 'No such file or directory'):
65  raise
66  else:
67  if db_file_name == jobdatabase.__default_db_file_name:
68  msg = ("No 'mps.db' found. Make sure you are in a campaign "
69  "directory and that the campaign is set up.")
70  else:
71  msg = "Database file '"+db_file_name+"' not found. Exiting."
72  print msg
73  sys.exit(1)
74 
75  #read infolines at the top, used rstrip to delete the '\n'
76  self.header = DBFILE.readline().strip()
77  self.batchScript = DBFILE.readline().rstrip('\n')
78  self.cfgTemplate = DBFILE.readline().rstrip('\n')
79  self.infiList = DBFILE.readline().rstrip('\n')
80  self.classInf = DBFILE.readline().rstrip('\n') #formerly named 'class' ->conflict
81  self.addFiles = DBFILE.readline().rstrip('\n')
82  self.driver = DBFILE.readline().rstrip('\n')
83  self.mergeScript = DBFILE.readline().rstrip('\n')
84  self.mssDir = DBFILE.readline().rstrip('\n')
85  self.updateTime = int(DBFILE.readline())
86  self.updateTimeHuman = DBFILE.readline().rstrip('\n')
87  self.elapsedTime = int(DBFILE.readline())
88  self.mssDirPool = DBFILE.readline().rstrip('\n')
89  self.pedeMem = int(DBFILE.readline())
90  self.spare1 = DBFILE.readline().rstrip('\n')
91  self.spare2 = DBFILE.readline().rstrip('\n')
92  self.spare3 = DBFILE.readline().rstrip('\n')
93 
94  #read actual jobinfo into arrays
95  self.nJobs = 0
96  milleJobs = 0
97 
98 
99  for line in DBFILE:
100  line = line.rstrip('\n') #removes the pesky \n from line
101  parts = line.split(":") #read each line and split into parts list
102  self.JOBNUMBER.append(int(parts[0]))
103  self.JOBDIR.append(parts[1])
104  self.JOBID.append(int(parts[2]))
105  self.JOBSTATUS.append(parts[3])
106  self.JOBNTRY.append(int(parts[4]))
107  self.JOBRUNTIME.append(int(parts[5])) #int float?
108  self.JOBNEVT.append(int(parts[6]))
109  self.JOBHOST.append(parts[7])
110  self.JOBINCR.append(int(parts[8]))
111  self.JOBREMARK.append(parts[9])
112  self.JOBSP1.append(parts[10])
113  self.JOBSP2.append(parts[11])
114  self.JOBSP3.append(parts[12])
115 
116  #count number of jobs
117  if not self.JOBDIR[self.nJobs].startswith("jobm"):
118  milleJobs += 1
119  self.nJobs += 1
120  self.nJobs = milleJobs
121 
122  DBFILE.close()
123 
124 
def Mpslibclass.jobdatabase.write_db (   self)

Definition at line 192 of file Mpslibclass.py.

References Mpslibclass.jobdatabase.header.

193  def write_db(self):
194  self.header = "mps database schema 3.2"
195  self.currentTime = int(time.time())
196  self.elapsedTime = 0;
197  if self.updateTime != 0:
198  self.elapsedTime = self.currentTime - self.updateTime
199  self.updateTime = self.currentTime
200  self.updateTimeHuman = str(datetime.datetime.today()) #no timezone :(
201  self.spare1 = "-- unused --"
202  self.spare2 = "-- unused --"
203  self.spare3 = "-- unused --"
204 
205  #if mps.db already exists, backup as mps.db~ (in case of interupt during write)
206  os.system('[[ -a mps.db ]] && cp -p mps.db mps.db~')
207 
208  #write mps.db header
209  DBFILE = open ("mps.db", "w")
210  headData = [ self.header, self.batchScript, self.cfgTemplate, self.infiList,
211  self.classInf, self.addFiles, self.driver, self.mergeScript,
212  self.mssDir, self.updateTime, self.updateTimeHuman,
213  self.elapsedTime, self.mssDirPool, self.pedeMem,
214  self.spare1, self.spare2, self.spare3 ]
215  for item in headData:
216  DBFILE.write("%s\n" % item)
217 
218  #write mps.db jobinfo
219  for i in xrange(len(self.JOBID)):
220  DBFILE.write('%03d:%s:%05d:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n' %
221  (i+1,
222  self.JOBDIR[i],
223  self.JOBID[i],
224  self.JOBSTATUS[i],
225  self.JOBNTRY[i],
226  self.JOBRUNTIME[i],
227  self.JOBNEVT[i],
228  self.JOBHOST[i],
229  self.JOBINCR[i],
230  self.JOBREMARK[i],
231  self.JOBSP1[i],
232  self.JOBSP2[i],
233  self.JOBSP3[i]))
234  DBFILE.close()

Member Data Documentation

string Mpslibclass.jobdatabase.__default_db_file_name = "mps.db"
staticprivate

Definition at line 58 of file Mpslibclass.py.

Mpslibclass.jobdatabase.addFiles

Definition at line 80 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.batchScript

Definition at line 76 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.cfgTemplate

Definition at line 77 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.classInf

Definition at line 79 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.currentTime

Definition at line 194 of file Mpslibclass.py.

Mpslibclass.jobdatabase.driver

Definition at line 81 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.elapsedTime

Definition at line 86 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.header

Definition at line 75 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb(), and Mpslibclass.jobdatabase.write_db().

Mpslibclass.jobdatabase.infiList

Definition at line 78 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.mergeScript

Definition at line 82 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.mssDir

Definition at line 83 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.mssDirPool

Definition at line 87 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.nJobs

Definition at line 94 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.pedeMem

Definition at line 88 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().

Mpslibclass.jobdatabase.spare1

Definition at line 89 of file Mpslibclass.py.

Mpslibclass.jobdatabase.spare2

Definition at line 90 of file Mpslibclass.py.

Mpslibclass.jobdatabase.spare3

Definition at line 91 of file Mpslibclass.py.

Mpslibclass.jobdatabase.updateTime

Definition at line 84 of file Mpslibclass.py.

Mpslibclass.jobdatabase.updateTimeHuman

Definition at line 85 of file Mpslibclass.py.

Referenced by Mpslibclass.jobdatabase.print_memdb().