samDefinitionConsistencyCheck.py
Go to the documentation of this file.
1 print "run : --- Sam definition file consistency checker"
2 ########################### Imports
3 import samweb_client
4 sam = samweb_client.SAMWebClient(experiment="nova")
5 ########################### Functions
6 def findRun(file_name):
7  tokens = file_name.split("_")
8  for token in tokens:
9  if token[0] != "r": continue
10  return int(token[1:])
11  assert False, "Run can't be found in file: %s"%file_name
12 def findSubRun(file_name):
13  tokens = file_name.split("_")
14  for token in tokens:
15  if token[0] != "s": continue
16  return int(token[1:])
17  assert False, "Sub-run can't be found in file: %s"%file_name
18 ########################### Options
19 from optparse import OptionParser
20 parser = OptionParser()
21 parser.add_option("-i", "--input_definitions", help="comma separated list of input definitions", action="store", type=str, dest="inputs", default=False)
22 (options, args) = parser.parse_args()
23 assert options.inputs, "No inputs"
24 print "run : inputs: %s"%options.inputs
25 input_list = options.inputs.split(",")
26 print "run : %i definitions provided"%len(input_list)
27 ########################### Get information
28 files = {}
29 all_runs = {}
30 for definition in input_list:
31  print "run : Finding files for definition: %s"%definition
32  def_files = samweb_client.files.listFiles(sam,defname=definition)
33  for def_file in def_files:
34  run = findRun(def_file)
35  subrun = findSubRun(def_file)
36 
37  if run not in all_runs.keys():
38  all_runs[run] = {}
39  if subrun not in all_runs[run].keys():
40  all_runs[run][subrun] = {}
41 
42  if definition not in all_runs[run][subrun].keys():
43  all_runs[run][subrun][definition] = []
44  all_runs[run][subrun][definition].append(def_file)
45  print "run : - found %i files"%len(def_files)
46  print "run : - runs found so far: %i"%len(all_runs.keys())
47 ########################### Analysis
48 print "run : --- Checking for inconsistencies"
49 missing = {}
50 duplicate = {}
51 for definition in input_list:
52  missing[definition] = {}
53  duplicate[definition] = {}
54 runs = all_runs.keys()
55 runs.sort()
56 for run in runs:
57  subruns = all_runs[run].keys()
58  subruns.sort()
59  for subrun in subruns:
60  definitions = all_runs[run][subrun]
61 
62  # Look for missing files
63  if len(definitions) != len(input_list):
64  # print "run : missing file found for run %i, subrun %i"%(run,subrun)
65  for definition in input_list:
66  if definition in definitions:
67  # print "run : - def:%s has file(s): %s"%(definition,repr(definitions[definition]))
68  pass
69  else:
70  # print "run : - def:%s doesn't have this run/subrun"%(definition)
71  if run not in missing[definition].keys():
72  missing[definition][run] = []
73  missing[definition][run].append(subrun)
74 ########################### Summarise
75 print "run : --- Missing files"
76 header = "run : %10s"%"run"
77 for definition in input_list:
78  header += " | %20s"%definition[:20]
79 print header
80 seperator = (len(header)-7)*"-"
81 print "run : %s"%seperator
82 for run in runs:
83  line = "run : %10i"%run
84  missing_files = False
85  for definition in definitions:
86  this_missing = 0
87  if run in missing[definition].keys():
88  this_missing = len(missing[definition][run])
89  missing_files = True
90  line += " | %20i"%this_missing
91  if missing_files: print line
92 print "run : %s"%seperator
93 ########################### Done
94 print "run : --- done"
keys
Reco plots.
Definition: caf_analysis.py:46
def listFiles(samweb, dimensions=None, defname=None, fileinfo=False, stream=False)
Definition: files.py:47