CMS 3D CMS Logo

Functions
mps_parse_pedechi2hist Namespace Reference

Functions

def get_all_ids_names (mps_db)
 
def get_his_data (his_file)
 
def get_used_binaries (cfg, no_binary_check)
 
def main (argv=None)
 

Function Documentation

def mps_parse_pedechi2hist.get_all_ids_names (   mps_db)
Returns two lists containing the mille job IDs and the associated names.

Arguments:
- `mps_db`: path to the MPS database file

Definition at line 76 of file mps_parse_pedechi2hist.py.

Referenced by main().

76 def get_all_ids_names(mps_db):
77  """Returns two lists containing the mille job IDs and the associated names.
78 
79  Arguments:
80  - `mps_db`: path to the MPS database file
81  """
82 
83  lib = mpslib.jobdatabase()
84  lib.read_db(mps_db)
85 
86  ids = lib.JOBNUMBER[:lib.nJobs]
87  names = lib.JOBSP3[:lib.nJobs]
88 
89  return ids, names
90 
91 
def mps_parse_pedechi2hist.get_his_data (   his_file)
Parse the pede histogram file.

Arguments:
- `his_file`: pede histogram file

Definition at line 116 of file mps_parse_pedechi2hist.py.

Referenced by main().

116 def get_his_data(his_file):
117  """Parse the pede histogram file.
118 
119  Arguments:
120  - `his_file`: pede histogram file
121  """
122 
123  his_data = []
124  with open(his_file, "r") as his:
125  found_chi2_start = False;
126 
127  for line in his:
128  if r"final <Chi^2/Ndf> from accepted local fits vs file number" in line:
129  found_chi2_start = True
130  if not found_chi2_start:
131  continue
132  else:
133  if r"end of xy-data" in line: break
134  if not re.search("\d", line): continue
135  if re.search(r"[a-z]", line): continue
136  splitted = line.split()
137  his_data.append(splitted[-1])
138 
139  return his_data
140 
141 
def mps_parse_pedechi2hist.get_used_binaries (   cfg,
  no_binary_check 
)
Returns list of used binary IDs.

Arguments:
- `cfg`: python config used to run the pede job
- `no_binary_check`: if 'True' a check for file existence is skipped

Definition at line 92 of file mps_parse_pedechi2hist.py.

References createfilelist.int.

Referenced by main().

92 def get_used_binaries(cfg, no_binary_check):
93  """Returns list of used binary IDs.
94 
95  Arguments:
96  - `cfg`: python config used to run the pede job
97  - `no_binary_check`: if 'True' a check for file existence is skipped
98  """
99 
100  cms_process = mps_tools.get_process_object(cfg)
101 
102  binaries = cms_process.AlignmentProducer.algoConfig.mergeBinaryFiles
103  if no_binary_check:
104  used_binaries = binaries
105  else:
106  # following check works only if 'args.cfg' was run from the same directory:
107  used_binaries = [b for b in binaries
108  if os.path.exists(os.path.join(os.path.dirname(cfg), b))]
109 
110  used_binaries = [int(re.sub(r"milleBinary(\d+)\.dat", r"\1", b))
111  for b in used_binaries]
112 
113  return used_binaries
114 
115 
def get_used_binaries(cfg, no_binary_check)
def mps_parse_pedechi2hist.main (   argv = None)
Main routine of the script.

Arguments:
- `argv`: arguments passed to the main routine

Definition at line 28 of file mps_parse_pedechi2hist.py.

References get_all_ids_names(), get_his_data(), get_used_binaries(), and join().

28 def main(argv = None):
29  """Main routine of the script.
30 
31  Arguments:
32  - `argv`: arguments passed to the main routine
33  """
34 
35  if argv == None:
36  argv = sys.argv[1:]
37 
38  parser = argparse.ArgumentParser(description="Analysis pede histogram file")
39  parser.add_argument("-d", "--mps-db", dest="mps_db", required=True,
40  metavar="PATH", help="MPS database file ('mps.db')")
41  parser.add_argument("--his", dest="his_file", required=True,
42  metavar="PATH", help="pede histogram file")
43  parser.add_argument("-c", "--cfg", dest="cfg", metavar="PATH", required=True,
44  help="python configuration file of pede job")
45  parser.add_argument("-b", "--no-binary-check", dest="no_binary_check",
46  default=False, action="store_true",
47  help=("skip check for existing binaries "
48  "(possibly needed if used interactively)"))
49  args = parser.parse_args(argv)
50 
51 
52  for input_file in (args.mps_db, args.his_file, args.cfg):
53  if not os.path.exists(input_file):
54  print "Could not find input file:", input_file
55  sys.exit(1)
56 
57  ids, names = get_all_ids_names(args.mps_db)
58  used_binaries = get_used_binaries(args.cfg, args.no_binary_check)
59  his_data = get_his_data(args.his_file)
60 
61  if len(his_data) != len(used_binaries):
62  print "The number of used binaries is", len(used_binaries),
63  print "whereas in contrast, however, the <chi2/ndf> histogram in Pede has",
64  print len(his_data), "bins (Pede version >= rev92 might help if #bins < #binaries).",
65  print "Exiting."
66  sys.exit(1)
67 
68  with open("chi2pedehis.txt", "w") as f:
69  for i, b in enumerate(used_binaries):
70  index = ids.index(b)
71  name = names[index]
72  f.write(" ".join([name, "{:03d}".format(b), his_data[i]])+"\n")
73 
74 
def get_used_binaries(cfg, no_binary_check)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18