MakeMiniprodValidationCuts.py
Go to the documentation of this file.
1 
2 import os.path
3 
4 DIR = "/nova/app/users/essmith/devsrepo/essmith/miniprod5_validation/events/lists/lists"
5 OUTFILE = "Miniprod5ValidationCuts.cxx"
6 
7 CUT_TEMPLATE = """
8  const Cut kIs_Prod4%(prod4_sel)s_Prod5%(prod5_sel)s_%(horn)s([](const caf::SRProxy * sr)
9  {
10  const std::unordered_set<std::size_t> hashes
11  {
12 %(hash_list)s
13  };
14 
15  return hashes.find(Hash(&sr->spill)) != hashes.end();
16  });
17 
18 
19 """
20 
21 cut_text = ""
22 for horn_current in ("fhc", "rhc"):
23  sels = ("unselected", "presel", "CVNeLow", "CVNeHigh")
24  for prod4_sel in sels:
25  for prod5_sel in sels:
26  f = os.path.join(DIR, "ND_%(horn)s_p4%(prod4_sel)s_p5%(prod5_sel)s.txt" % { "horn": horn_current, "prod4_sel": prod4_sel, "prod5_sel" : prod5_sel})
27  if not os.path.isfile(f):
28  continue
29  print f
30 
31  hash_text = ""
32  with open(f) as infile:
33  for line in infile:
34  numbers = (l.lstrip("0") if l != len(l) * "0" else "0" for l in line.split())
35  hash_text += " Hash(std::vector<std::size_t>{%s}),\n" % (", ".join(numbers))
36 
37  subst = { "prod4_sel": prod4_sel, "prod5_sel": prod5_sel, "horn": horn_current.upper(), "hash_list": hash_text}
38  for sel in ("prod4_sel", "prod5_sel"):
39  subst[sel] = subst[sel].replace("elected", "el")
40  subst[sel] = subst[sel][:1].upper() + subst[sel][1:]
41  cut_text += CUT_TEMPLATE % subst
42 
43 text = []
44 with open(OUTFILE, 'r') as infile:
45  text = [line for line in infile]
46 with open(OUTFILE, 'w') as outfile:
47  replacing = False
48  for line in text:
49  if not replacing and "AUTOFILL BELOW" in line:
50  replacing = True
51  elif replacing and "END AUTOFILL" in line:
52  replacing = False
53  outfile.write(cut_text)
54  elif replacing:
55  continue
56 
57  outfile.write(line)
procfile open("FD_BRL_v0.txt")