File indexing completed on 2024-11-25 02:29:03
0001
0002
0003
0004
0005
0006
0007
0008
0009 from builtins import range
0010 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib
0011 import re
0012 import os
0013 import argparse
0014
0015 lib = mpslib.jobdatabase()
0016
0017
0018
0019 parser = argparse.ArgumentParser(
0020 description='Produce Config for Pede-job from Mille-config.')
0021
0022
0023 parser.add_argument('-c', '--checkok', action='store_true',
0024 help='check which jobs are OK and write just them to the config')
0025 parser.add_argument('-w', '--checkweight', action='store_true',
0026 help='check for weight assignments in mps.db and add them to binarylist')
0027 parser.add_argument("-a", "--append", dest="append", metavar="SNIPPET",
0028 help="config snippet to be appended to the output config")
0029
0030
0031 parser.add_argument('inCfg', action='store',
0032 help='path to cfg-file, that is used as base')
0033 parser.add_argument('mergeCfg', action='store',
0034 help='path and name of the config that is produced')
0035 parser.add_argument('mergeDir', action='store',
0036 help='path to the merge directory')
0037 parser.add_argument('nJobs', action='store', type=int,
0038 help='number of jobs')
0039
0040
0041 args = parser.parse_args()
0042 inCfg = args.inCfg
0043 mergeCfg = args.mergeCfg
0044 mergeDir = args.mergeDir
0045 nJobs = args.nJobs
0046 checkok = args.checkok
0047 checkweight = args.checkweight
0048
0049 if checkok or checkweight:
0050 lib.read_db()
0051
0052
0053
0054
0055
0056 if not os.path.isdir(mergeDir):
0057 os.system('mkdir '+mergeDir)
0058
0059
0060 with open(inCfg, 'r') as INFILE:
0061 body = INFILE.read()
0062
0063
0064
0065 match = re.search('setupAlgoMode\s*?\=\s*?[\"\'].*?[\"\']', body)
0066 if match:
0067 body = re.sub('setupAlgoMode\s*?\=\s*?[\"\'].*?[\"\']',
0068 'setupAlgoMode = \"pede\"',
0069 body)
0070 else:
0071 print('Error in mps_merge: No setupAlgoMode found in baseconfig.')
0072
0073
0074
0075 binaryList = ''
0076 firstentry = True
0077 for i in range(nJobs):
0078 separator = ',\n '
0079 if firstentry:
0080 separator = '\n '
0081 if checkok and lib.JOBSTATUS[i]!='OK':
0082 continue
0083 firstentry = False
0084
0085 newName = 'milleBinary%03d.dat' % (i+1)
0086 if checkweight and (lib.JOBSP2[i]!='' and lib.JOBSP2[i]!='1.0'):
0087 weight = lib.JOBSP2[i]
0088 print('Adding %s to list of binary files using weight %s' % (newName,weight))
0089 binaryList = '%s%s\'%s -- %s\'' % (binaryList, separator, newName, weight)
0090 else:
0091 print('Adding %s to list of binary files' % newName)
0092 binaryList = '%s%s\'%s\'' % (binaryList, separator, newName)
0093
0094
0095
0096 match = re.search('[\"\']placeholder_binaryList[\"\']', body)
0097 if match:
0098 body = re.sub('[\"\']placeholder_binaryList[\"\']',
0099 binaryList,
0100 body)
0101 else:
0102 print('Error in mps_merge: No \'placeholder_binaryList\' found in baseconfig.')
0103
0104
0105
0106 treeList =''
0107 firstentry = True
0108 for i in range(nJobs):
0109 separator = ',\n '
0110 if firstentry:
0111 separator = '\n '
0112 if checkok and lib.JOBSTATUS[i]!='OK':
0113 continue
0114 firstentry = False
0115
0116 newName = 'treeFile%03d.root' % (i+1)
0117 print('Adding %s to list of tree files.' % newName)
0118 treeList = '%s%s\'%s\'' % (treeList, separator, newName)
0119
0120
0121
0122 match = re.search('[\"\']placeholder_treeList[\"\']', body)
0123 if match:
0124 body = re.sub('[\"\']placeholder_treeList[\"\']',
0125 treeList,
0126 body)
0127 else:
0128 print('Error in mps_merge: No \'placeholder_treeList\' found in baseconfig.')
0129
0130 if args.append is not None:
0131 with open(args.append) as snippet:
0132 body += snippet.read()
0133
0134 with open(mergeCfg, 'w') as OUTFILE:
0135 OUTFILE.write(body)