CMS 3D CMS Logo

Functions
compareDQMOutput Namespace Reference

Functions

def collect_and_compare_files (base_dir, pr_dir, output_dir, num_procs, pr_number, test_number, release_format)
 
def compare (base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format)
 
def generate_summary_html (output_dir, pr_number, summary_dir)
 
def get_file_pairs (base_dir, pr_dir)
 
def upload (files)
 
def upload_to_gui (output_dir, num_procs)
 

Function Documentation

def compareDQMOutput.collect_and_compare_files (   base_dir,
  pr_dir,
  output_dir,
  num_procs,
  pr_number,
  test_number,
  release_format 
)

Definition at line 12 of file compareDQMOutput.py.

References objects.autophobj.float, and get_file_pairs().

Referenced by generate_summary_html().

12 def collect_and_compare_files(base_dir, pr_dir, output_dir, num_procs, pr_number, test_number, release_format):
13  files = get_file_pairs(base_dir, pr_dir)
14 
15  threads = []
16  for _ in range(num_procs):
17  thread = Thread(target=compare, args=(base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format))
18  thread.start()
19  threads.append(thread)
20 
21  [thread.join() for thread in threads]
22 
23  COMPARISON_RESULTS.sort(key=lambda k: float(k['workflow']))
24 
def collect_and_compare_files(base_dir, pr_dir, output_dir, num_procs, pr_number, test_number, release_format)
def get_file_pairs(base_dir, pr_dir)
def compareDQMOutput.compare (   base_dir,
  pr_dir,
  output_dir,
  files,
  pr_number,
  test_number,
  release_format 
)

Definition at line 25 of file compareDQMOutput.py.

References createfilelist.int, join(), edm.print(), and split.

25 def compare(base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format):
26  while files:
27  try:
28  file_name = files.pop()
29  command = ['python', os.path.join(os.path.dirname(__file__), 'compareHistograms.py'), '-b', os.path.join(base_dir, file_name), \
30  '-p', os.path.join(pr_dir, file_name), '-o', output_dir, '-n', pr_number, '-t', test_number, '-r', release_format]
31  print('Running comparison:')
32  print(' '.join(command))
33 
34  output = subprocess.check_output(command)
35 
36  output_elements = output.split('\n')[1:]
37  base_output_filename = output_elements[0]
38  pr_output_filename = output_elements[1]
39  run_nr = base_output_filename.split('_')[2].lstrip('R').lstrip('0')
40  output_numbers = output_elements[2].split(' ')
41 
42  workflow = os.path.basename(os.path.dirname(os.path.join(base_dir, file_name))).split('_')[0]
43  base_dataset = '/' + '/'.join(base_output_filename.rstrip('.root').split('__')[1:])
44  pr_dataset = '/' + '/'.join(pr_output_filename.rstrip('.root').split('__')[1:])
45 
46  COMPARISON_RESULTS.append({'workflow': workflow, 'base_dataset': base_dataset, 'pr_dataset': pr_dataset, 'run_nr': run_nr,\
47  'changed_elements': int(output_numbers[0]), 'removed_elements': int(output_numbers[1]), 'added_elements': int(output_numbers[2])})
48  except:
49  pass
50 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def compare(base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139
def compareDQMOutput.generate_summary_html (   output_dir,
  pr_number,
  summary_dir 
)

Definition at line 86 of file compareDQMOutput.py.

References collect_and_compare_files(), str, and upload_to_gui().

86 def generate_summary_html(output_dir, pr_number, summary_dir):
87  template_file = open(os.path.join(os.path.dirname(__file__), 'dqm-histo-comparison-summary-template.html'), 'r')
88  result = template_file.read()
89 
90  result = result.replace('$PR_NUMBER$', pr_number)
91 
92  table_items = ''
93  total_changes = 0
94 
95  for comp in COMPARISON_RESULTS:
96  total_changes += comp['removed_elements'] + comp['added_elements'] + comp['changed_elements']
97  baseline_count = comp['changed_elements'] + comp['removed_elements']
98  pr_count = comp['changed_elements'] + comp['added_elements']
99  overlay_count = baseline_count
100 
101  # Make urls
102  base_url = 'https://cmsweb.cern.ch/dqm/dev/start?runnr=%s;dataset%%3D%s;sampletype%%3Doffline_relval;workspace%%3DEverything;' % (comp['run_nr'], comp['base_dataset'])
103  pr_url = 'https://cmsweb.cern.ch/dqm/dev/start?runnr=%s;dataset%%3D%s;sampletype%%3Doffline_relval;workspace%%3DEverything;' % (comp['run_nr'], comp['pr_dataset'])
104  overlay_url = 'https://cmsweb.cern.ch/dqm/dev/start?runnr=%s;dataset%%3D%s;referenceshow%%3Dall;referenceobj1%%3Dother::%s::;sampletype%%3Doffline_relval;workspace%%3DEverything;' \
105  % (comp['run_nr'], comp['pr_dataset'], comp['base_dataset'])
106 
107  table_items += ' <tr>\n'
108  table_items += ' <td><a href="%s" target="_blank">%s baseline GUI</a><span> (%s)</span></td>\n' % (base_url, comp['workflow'], baseline_count)
109  table_items += ' <td><a href="%s" target="_blank">%s pr GUI</a><span> (%s)</span></td>\n' % (pr_url, comp['workflow'], pr_count)
110  table_items += ' <td><a href="%s" target="_blank">%s overlay GUI</a><span> (%s)</span></td>\n' % (overlay_url, comp['workflow'], overlay_count)
111  table_items += ' <td><span class="removed">-%s</span><span class="added">+%s</span><span class="changed">%s</span></td>\n' \
112  % (comp['removed_elements'], comp['added_elements'], comp['changed_elements'])
113  table_items += ' </tr>\n'
114 
115  result = result.replace('$TOTAL_CHANGES$', str(total_changes))
116  result = result.replace('$NUMBER_OF_WORKFLOWS$', str(len(COMPARISON_RESULTS)))
117  result = result.replace('$PER_WORKFLOW_LIST$', table_items)
118  template_file.close()
119 
120  # Write output
121  result_file_path = os.path.join(summary_dir, 'dqm-histo-comparison-summary.html')
122  if os.path.dirname(result_file_path):
123  if not os.path.exists(os.path.dirname(result_file_path)):
124  os.makedirs(os.path.dirname(result_file_path))
125  summary_file = open(result_file_path, 'w')
126  summary_file.write(result)
127  summary_file.close()
128 
def generate_summary_html(output_dir, pr_number, summary_dir)
#define str(s)
def compareDQMOutput.get_file_pairs (   base_dir,
  pr_dir 
)

Definition at line 51 of file compareDQMOutput.py.

References genParticles_cff.map.

Referenced by collect_and_compare_files().

51 def get_file_pairs(base_dir, pr_dir):
52  base_files = glob.glob(os.path.join(base_dir, '*.*_*/DQM_*.root'))
53  pr_files = glob.glob(os.path.join(pr_dir, '*.*_*/DQM_*.root'))
54 
55  # Remove base directories and leave
56  # only parts of paths that are same
57  base_files = map(lambda x: os.path.relpath(x, base_dir), base_files)
58  pr_files = map(lambda x: os.path.relpath(x, pr_dir), pr_files)
59 
60  # Find intersection
61  return [value for value in base_files if value in pr_files]
62 
def get_file_pairs(base_dir, pr_dir)
def compareDQMOutput.upload (   files)

Definition at line 73 of file compareDQMOutput.py.

References join(), and edm.print().

73 def upload(files):
74  while files:
75  try:
76  file = files.pop()
77  command = ['python', os.path.join(os.path.dirname(__file__), 'visDQMUpload.py'), 'https://cmsweb.cern.ch/dqm/dev', file]
78  print('Uploading output:')
79  print(' '.join(command))
80 
81  subprocess.call(command)
82  print('')
83  except:
84  pass
85 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def compareDQMOutput.upload_to_gui (   output_dir,
  num_procs 
)

Definition at line 63 of file compareDQMOutput.py.

Referenced by generate_summary_html().

63 def upload_to_gui(output_dir, num_procs):
64  base_files = glob.glob(os.path.join(output_dir, 'base/*.root'))
65  pr_files = glob.glob(os.path.join(output_dir, 'pr/*.root'))
66 
67  files = base_files + pr_files
68 
69  for _ in range(num_procs):
70  thread = Thread(target=upload, args=(files,))
71  thread.start()
72 
def upload_to_gui(output_dir, num_procs)