CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
mps_parse_pedechi2hist Namespace Reference

Functions

def get_all_ids_names
 
def get_his_data
 
def get_used_binaries
 
def main
 

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 75 of file mps_parse_pedechi2hist.py.

Referenced by main().

75 
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 
def mps_parse_pedechi2hist.get_his_data (   his_file)
Parse the pede histogram file.

Arguments:
- `his_file`: pede histogram file

Definition at line 121 of file mps_parse_pedechi2hist.py.

Referenced by main().

122 def get_his_data(his_file):
123  """Parse the pede histogram file.
124 
125  Arguments:
126  - `his_file`: pede histogram file
127  """
128 
129  his_data = []
130  with open(his_file, "r") as his:
131  found_chi2_start = False;
132 
133  for line in his:
134  if r"final <Chi^2/Ndf> from accepted local fits vs file number" in line:
135  found_chi2_start = True
136  if not found_chi2_start:
137  continue
138  else:
139  if r"end of xy-data" in line: break
140  if not re.search("\d", line): continue
141  if re.search(r"[a-z]", line): continue
142  splitted = line.split()
143  his_data.append(splitted[-1])
144 
145  return his_data
146 
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 91 of file mps_parse_pedechi2hist.py.

Referenced by main().

91 
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  sys.path.append(os.path.dirname(cfg))
101 
102  cache_stdout = sys.stdout
103  sys.stdout = open(os.devnull, "w") # suppress unwanted output
104  from alignment_merge import process.AlignmentProducer.algoConfig
105  sys.stdout = cache_stdout
106 
107  binaries = algoConfig.mergeBinaryFiles
108  if no_binary_check:
109  used_binaries = binaries
110  else:
111  # following check works only if 'args.cfg' was run from the same directory:
112  used_binaries = [b for b in binaries
113  if os.path.exists(os.path.join(os.path.dirname(cfg), b))]
114 
115  used_binaries = [int(re.sub(r"milleBinary(\d+)\.dat", r"\1", b))
116  for b in used_binaries]
117  del sys.path[-1] # remove the temporary search path extension
118 
119  return used_binaries
120 
def mps_parse_pedechi2hist.main (   argv = None)
Main routine of the script.

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

Definition at line 27 of file mps_parse_pedechi2hist.py.

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

27 
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 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18