CMS 3D CMS Logo

dumpparser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Parse the pede.dump.gz file and returns a pedeDump object with the
5 # parsed information of the file.
6 
7 
8 import gzip
9 import logging
10 import re
11 
12 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes import PedeDumpData
13 
14 
15 def parse(path, config):
16  logger = logging.getLogger("mpsvalidate")
17 
18  # parse pede.dump.gz
19 
20  pedeDump = PedeDumpData()
21 
22  # only recognize warning the first time
23  warningBool = False
24 
25  # save lines in list
26  try:
27  with gzip.open(path) as gzipFile:
28  dumpFile = gzipFile.readlines()
29  except IOError:
30  logger.error("PedeDump: {0} does not exist".format(path))
31  return
32 
33  for i, line in enumerate(dumpFile):
34  # Sum(Chi^2)/Sum(Ndf)
35  if ("Sum(Chi^2)/Sum(Ndf) =" in line):
36  number = []
37  number.append(map(float, re.findall(
38  r"[-+]?\d*\.\d+", dumpFile[i])))
39  number.append(map(int, re.findall(r"[-+]?\d+", dumpFile[i + 1])))
40  number.append(map(float, re.findall(
41  r"[-+]?\d*\.\d+", dumpFile[i + 2])))
42  pedeDump.sumSteps = "{0} / ( {1} - {2} )".format(
43  number[0][0], number[1][0], number[1][1])
44  pedeDump.sumValue = number[2][0]
45 
46  # Sum(W*Chi^2)/Sum(Ndf)/<W>
47  if ("Sum(W*Chi^2)/Sum(Ndf)/<W> =" in line):
48  number = []
49  number.append(map(float, re.findall(
50  r"[-+]?\d*\.\d+", dumpFile[i])))
51  number.append(map(int, re.findall(r"[-+]?\d+", dumpFile[i + 1])))
52  number.append(map(float, re.findall(
53  r"[-+]?\d*\.\d+", dumpFile[i + 2])))
54  number.append(map(float, re.findall(
55  r"[-+]?\d*\.\d+", dumpFile[i + 3])))
56  pedeDump.sumSteps = "{0} / ( {1} - {2} ) / {3}".format(
57  number[0][0], number[1][0], number[1][1], number[2][0])
58  pedeDump.sumWValue = number[3][0]
59 
60  if ("with correction for down-weighting" in line):
61  number = map(float, re.findall(r"[-+]?\d*\.\d+", dumpFile[i]))
62  pedeDump.correction = number[0]
63 
64  # Peak dynamic memory allocation
65  if ("Peak dynamic memory allocation:" in line):
66  number = map(float, re.findall(r"[-+]?\d*\.\d+", dumpFile[i]))
67  pedeDump.memory = number[0]
68 
69  # total time
70  if ("Iteration-end" in line):
71  number = map(int, re.findall(r"\d+", dumpFile[i + 1]))
72  pedeDump.time = number[:3]
73 
74  # warings
75  if ("WarningWarningWarningWarning" in line and warningBool == False):
76  warningBool = True
77  j = i + 8
78  while ("Warning" not in dumpFile[j]):
79  pedeDump.warning.append(dumpFile[j])
80  j += 1
81 
82  # nrec number of records
83  if (" = number of records" in line):
84  number = map(int, re.findall("\d+", dumpFile[i]))
85  pedeDump.nrec = number[0]
86 
87  # ntgb total number of parameters
88  if (" = total number of parameters" in line):
89  number = map(int, re.findall("\d+", dumpFile[i]))
90  pedeDump.ntgb = number[0]
91 
92  # nvgb number of variable parameters
93  if (" = number of variable parameters" in line):
94  number = map(int, re.findall("\d+", dumpFile[i]))
95  pedeDump.nvgb = number[0]
96 
97  return pedeDump
def parse(path, config)
Definition: dumpparser.py:15