File indexing completed on 2024-04-06 11:56:35
0001 from __future__ import print_function
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 from builtins import range
0042 import datetime
0043 import time
0044 import os
0045 import sys
0046
0047
0048 class jobdatabase:
0049
0050 JOBNUMBER, JOBDIR, JOBID, JOBSTATUS, JOBNTRY, JOBRUNTIME, JOBNEVT, JOBHOST, JOBINCR, \
0051 JOBREMARK, JOBSP1, JOBSP2, JOBSP3 = ([] for i in range(13))
0052
0053 header, batchScript, cfgTemplate, infiList, classInf, addFiles, driver, mergeScript, \
0054 mssDir, updateTimeHuman, mssDirPool, spare1, spare2, spare3 = ('' for i in range(14))
0055
0056 updateTime, elapsedTime, pedeMem , nJobs = -1, -1, -1, -1
0057
0058
0059
0060 __default_db_file_name = "mps.db"
0061 def read_db(self, db_file_name = __default_db_file_name):
0062 try:
0063 DBFILE = open(db_file_name,'r')
0064 except IOError as e:
0065 if e.args != (2, 'No such file or directory'):
0066 raise
0067 else:
0068 if db_file_name == jobdatabase.__default_db_file_name:
0069 msg = ("No 'mps.db' found. Make sure you are in a campaign "
0070 "directory and that the campaign is set up.")
0071 else:
0072 msg = "Database file '"+db_file_name+"' not found. Exiting."
0073 print(msg)
0074 sys.exit(1)
0075
0076
0077 self.header = DBFILE.readline().strip()
0078 self.batchScript = DBFILE.readline().rstrip('\n')
0079 self.cfgTemplate = DBFILE.readline().rstrip('\n')
0080 self.infiList = DBFILE.readline().rstrip('\n')
0081 self.classInf = DBFILE.readline().rstrip('\n')
0082 self.addFiles = DBFILE.readline().rstrip('\n')
0083 self.driver = DBFILE.readline().rstrip('\n')
0084 self.mergeScript = DBFILE.readline().rstrip('\n')
0085 self.mssDir = DBFILE.readline().rstrip('\n')
0086 self.updateTime = int(DBFILE.readline())
0087 self.updateTimeHuman = DBFILE.readline().rstrip('\n')
0088 self.elapsedTime = int(DBFILE.readline())
0089 self.mssDirPool = DBFILE.readline().rstrip('\n')
0090 self.pedeMem = int(DBFILE.readline())
0091 self.spare1 = DBFILE.readline().rstrip('\n')
0092 self.spare2 = DBFILE.readline().rstrip('\n')
0093 self.spare3 = DBFILE.readline().rstrip('\n')
0094
0095
0096 self.nJobs = 0
0097 milleJobs = 0
0098
0099
0100 for line in DBFILE:
0101 if line.strip() == "": continue
0102 line = line.rstrip('\n')
0103 parts = line.split(":")
0104 self.JOBNUMBER.append(int(parts[0]))
0105 self.JOBDIR.append(parts[1].strip())
0106 self.JOBID.append(parts[2])
0107 self.JOBSTATUS.append(parts[3].strip())
0108 self.JOBNTRY.append(int(parts[4]))
0109 self.JOBRUNTIME.append(int(parts[5]))
0110 self.JOBNEVT.append(int(parts[6]))
0111 self.JOBHOST.append(parts[7].strip())
0112 self.JOBINCR.append(int(parts[8]))
0113 self.JOBREMARK.append(parts[9].strip())
0114 self.JOBSP1.append(parts[10].strip())
0115 self.JOBSP2.append(parts[11].strip())
0116 self.JOBSP3.append(parts[12].strip())
0117
0118
0119 if not self.JOBDIR[self.nJobs].startswith("jobm"):
0120 milleJobs += 1
0121 self.nJobs += 1
0122 self.nJobs = milleJobs
0123
0124 DBFILE.close()
0125
0126
0127
0128
0129
0130 def print_memdb(self):
0131
0132 print("\n=== mps database printout ===\n")
0133 print(self.header)
0134 print('Script:\t\t', self.batchScript)
0135 print('cfg:\t\t', self.cfgTemplate)
0136 print('files:\t\t', self.infiList)
0137 print('class:\t\t', self.classInf)
0138 print('name:\t\t', self.addFiles)
0139 print('driver:\t\t', self.driver)
0140 print('mergeScript:\t', self.mergeScript)
0141 print('mssDir:\t\t', self.mssDir)
0142 print('updateTime:\t', self.updateTimeHuman)
0143 print('elapsed:\t', self.elapsedTime)
0144 print('mssDirPool:\t', self.mssDirPool)
0145 print('pedeMem:\t', self.pedeMem, '\n')
0146
0147
0148 print('### dir jobid stat try rtime nevt remark weight name')
0149 print("------------------------------------------------------------------------------")
0150 for i in range(self.nJobs):
0151 print('%03d %6s %9s %6s %3d %5d %8d %8s %5s %s' % (
0152 self.JOBNUMBER[i],
0153 self.JOBDIR[i],
0154 self.JOBID[i],
0155 self.JOBSTATUS[i],
0156 self.JOBNTRY[i],
0157 self.JOBRUNTIME[i],
0158 self.JOBNEVT[i],
0159 self.JOBHOST[i],
0160 self.JOBSP2[i],
0161 self.JOBSP3[i]))
0162
0163
0164 if self.driver == 'merge':
0165 for i in range(self.nJobs,len(self.JOBDIR)):
0166 print('%s %6s %9s %6s %3d %5d %8d %8s %5s %s' % (
0167 'MMM',
0168 self.JOBDIR[i],
0169 self.JOBID[i],
0170 self.JOBSTATUS[i],
0171 self.JOBNTRY[i],
0172 self.JOBRUNTIME[i],
0173 self.JOBNEVT[i],
0174 self.JOBHOST[i],
0175 self.JOBSP2[i],
0176 self.JOBSP3[i]))
0177
0178
0179 totalEvents = sum(self.JOBNEVT[:self.nJobs])
0180 totalCpu = sum(self.JOBRUNTIME[:self.nJobs])
0181 meanCpuPerEvent = 0.
0182 if totalEvents > 0:
0183 meanCpuPerEvent = float(totalCpu)/totalEvents
0184 print("------------------------------------------------------------------------------")
0185 print("\t\t\t\t\tEvent total:\t", totalEvents)
0186 print("\t\t\t\t\tCPU total:\t", totalCpu, 's')
0187 print("\t\t\t\t\tMean CPU/event:\t",meanCpuPerEvent,'s')
0188
0189
0190
0191
0192
0193
0194
0195 def write_db(self):
0196 self.header = "mps database schema 3.2"
0197 self.currentTime = int(time.time())
0198 self.elapsedTime = 0;
0199 if self.updateTime != 0:
0200 self.elapsedTime = self.currentTime - self.updateTime
0201 self.updateTime = self.currentTime
0202 self.updateTimeHuman = str(datetime.datetime.today())
0203 self.spare1 = "-- unused --"
0204 self.spare2 = "-- unused --"
0205 self.spare3 = "-- unused --"
0206
0207
0208 os.system('[[ -a mps.db ]] && cp -p mps.db mps.db~')
0209
0210
0211 DBFILE = open ("mps.db", "w")
0212 headData = [ self.header, self.batchScript, self.cfgTemplate, self.infiList,
0213 self.classInf, self.addFiles, self.driver, self.mergeScript,
0214 self.mssDir, self.updateTime, self.updateTimeHuman,
0215 self.elapsedTime, self.mssDirPool, self.pedeMem,
0216 self.spare1, self.spare2, self.spare3 ]
0217 for item in headData:
0218 DBFILE.write("%s\n" % item)
0219
0220
0221 for i in range(len(self.JOBID)):
0222 DBFILE.write('%03d:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n' %
0223 (i+1,
0224 self.JOBDIR[i],
0225 self.JOBID[i],
0226 self.JOBSTATUS[i],
0227 self.JOBNTRY[i],
0228 self.JOBRUNTIME[i],
0229 self.JOBNEVT[i],
0230 self.JOBHOST[i],
0231 self.JOBINCR[i],
0232 self.JOBREMARK[i],
0233 self.JOBSP1[i],
0234 self.JOBSP2[i],
0235 self.JOBSP3[i]))
0236 DBFILE.close()
0237
0238
0239
0240
0241 def get_class(self, argument=''):
0242 CLASSES = self.classInf.split(':')
0243 if len(CLASSES)<1 or len(CLASSES)>2:
0244 print('\nget_class():\n class must be of the form \'class\' or \'classMille:classPede\', but is \'%s\'!\n\n', classInf)
0245 sys.exit(1)
0246 elif argument == 'mille':
0247 return CLASSES[0]
0248 elif argument == 'pede':
0249 if len(CLASSES) == 1:
0250 return CLASSES[0]
0251 elif len(CLASSES) == 2:
0252 return CLASSES[1]
0253 else:
0254 print('\nget_class():\n Know class only for \'mille\' or \'pede\', not %s!\n\n' %argument)
0255 sys.exit(1)