CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Functions | Variables
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_list, summary_dir)
 
def get_file_pairs (base_dir, pr_dir)
 
def upload (files)
 
def upload_to_gui (output_dir, num_procs)
 

Variables

 args
 
 COMPARISON_RESULTS
 
 default
 
 description
 
 help
 
 parser
 
 pr_number
 
 release_format
 
 required
 
 type
 

Function Documentation

◆ collect_and_compare_files()

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 nano_mu_digi_cff.float, get_file_pairs(), and FastTimerService_cff.range.

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)

◆ compare()

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 edm.decode(), createfilelist.int, join(), print(), and submitPVValidationJobs.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 = ['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).decode()
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') output_numbers = output_elements[2].split(' ')
40 
41  workflow = os.path.basename(os.path.dirname(os.path.join(base_dir, file_name))).split('_')[0]
42  base_dataset = '/' + '/'.join(base_output_filename.rstrip('.root').split('__')[1:])
43  pr_dataset = '/' + '/'.join(pr_output_filename.rstrip('.root').split('__')[1:])
44 
45  cmssw_version = '_'.join(release_format.split('_')[:4])
46  cmssw_version = cmssw_version[:-1] + 'x'
47  root_file_dir_in_gui = 'ROOT/RelValData/%s/' % cmssw_version
48  if 'R000000001__RelVal' in base_output_filename:
49  root_file_dir_in_gui = 'ROOT/RelVal/%s/' % cmssw_version
50 
51  base_file_path_in_gui = root_file_dir_in_gui + base_output_filename
52  pr_file_path_in_gui = root_file_dir_in_gui + pr_output_filename
53 
54  COMPARISON_RESULTS.append({'workflow': workflow, 'base_dataset': base_dataset, 'pr_dataset': pr_dataset, 'run_nr': run_nr,\
55  'changed_elements': int(output_numbers[0]), 'removed_elements': int(output_numbers[1]), 'added_elements': int(output_numbers[2]),
56  'base_file_path_in_gui': base_file_path_in_gui, 'pr_file_path_in_gui': pr_file_path_in_gui})
57  except Exception as ex:
58  print('Exception comparing two root files: %s' % ex)
59 
60 
bool compare(const P &i, const P &j)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
bool decode(bool &, std::string_view)
Definition: types.cc:72

◆ generate_summary_html()

def compareDQMOutput.generate_summary_html (   output_dir,
  pr_list,
  summary_dir 
)

Definition at line 101 of file compareDQMOutput.py.

References str.

101 def generate_summary_html(output_dir, pr_list, summary_dir):
102  template_file_path = os.path.join(os.getenv('CMSSW_BASE'), 'src', 'DQMServices', 'FileIO', 'scripts', 'dqm-histo-comparison-summary-template.html')
103  if not os.path.isfile(template_file_path):
104  template_file_path = os.path.join(os.getenv('CMSSW_RELEASE_BASE'), 'src', 'DQMServices', 'FileIO', 'scripts', 'dqm-histo-comparison-summary-template.html')
105  template_file = open(template_file_path, 'r')
106  result = template_file.read()
107 
108  result = result.replace('$PR_LIST$', pr_list)
109 
110  table_items = ''
111  total_changes = 0
112 
113  for comp in COMPARISON_RESULTS:
114  total_changes += comp['removed_elements'] + comp['added_elements'] + comp['changed_elements']
115  baseline_count = comp['changed_elements'] + comp['removed_elements']
116  pr_count = comp['changed_elements'] + comp['added_elements']
117  overlay_count = baseline_count
118 
119  # Make urls
120  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'])
121  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'])
122  overlay_url = 'https://cmsweb.cern.ch/dqm/dev/start?runnr=%s;dataset%%3D%s;referenceshow%%3Dall;referencenorm=False;referenceobj1%%3Dother::%s::;sampletype%%3Doffline_relval;workspace%%3DEverything;' \
123  % (comp['run_nr'], comp['pr_dataset'], comp['base_dataset'])
124  base_raw_url = 'https://cmsweb.cern.ch/dqm/dev/jsroot/index.htm?file=https://cmsweb.cern.ch/dqm/dev/data/browse/%s' % comp['base_file_path_in_gui']
125  pr_raw_url = 'https://cmsweb.cern.ch/dqm/dev/jsroot/index.htm?file=https://cmsweb.cern.ch/dqm/dev/data/browse/%s' % comp['pr_file_path_in_gui']
126 
127  table_items += ' <tr>\n'
128  table_items += ' <td><a href="%s" target="_blank">%s baseline GUI</a><span> (%s)</span></td>\n' % (base_url, comp['workflow'], baseline_count)
129  table_items += ' <td><a href="%s" target="_blank">%s pr GUI</a><span> (%s)</span></td>\n' % (pr_url, comp['workflow'], pr_count)
130  table_items += ' <td><a href="%s" target="_blank">%s overlay GUI</a><span> (%s)</span></td>\n' % (overlay_url, comp['workflow'], overlay_count)
131  table_items += ' <td><a href="%s" target="_blank">%s baseline rootjs</a><span> (%s)</span></td>\n' % (base_raw_url, comp['workflow'], baseline_count)
132  table_items += ' <td><a href="%s" target="_blank">%s pr rootjs</a><span> (%s)</span></td>\n' % (pr_raw_url, comp['workflow'], pr_count)
133  table_items += ' <td><span class="removed">-%s</span><span class="added">+%s</span><span class="changed">%s</span></td>\n' \
134  % (comp['removed_elements'], comp['added_elements'], comp['changed_elements'])
135  table_items += ' </tr>\n'
136 
137  result = result.replace('$TOTAL_CHANGES$', str(total_changes))
138  result = result.replace('$NUMBER_OF_WORKFLOWS$', str(len(COMPARISON_RESULTS)))
139  result = result.replace('$PER_WORKFLOW_LIST$', table_items)
140  template_file.close()
141 
142  # Write output
143  result_file_path = os.path.join(summary_dir, 'dqm-histo-comparison-summary.html')
144  if os.path.dirname(result_file_path):
145  if not os.path.exists(os.path.dirname(result_file_path)):
146  os.makedirs(os.path.dirname(result_file_path))
147  summary_file = open(result_file_path, 'w')
148  summary_file.write(result)
149  summary_file.close()
150 
def generate_summary_html(output_dir, pr_list, summary_dir)
#define str(s)

◆ get_file_pairs()

def compareDQMOutput.get_file_pairs (   base_dir,
  pr_dir 
)

Definition at line 61 of file compareDQMOutput.py.

Referenced by collect_and_compare_files().

61 def get_file_pairs(base_dir, pr_dir):
62  base_files = glob.glob(os.path.join(base_dir, '*.*_*/DQM_*.root'))
63  pr_files = glob.glob(os.path.join(pr_dir, '*.*_*/DQM_*.root'))
64 
65  # Remove base directories and leave
66  # only parts of paths that are same
67  base_files = [ os.path.relpath(x, base_dir) for x in base_files ]
68  pr_files = [ os.path.relpath(x, pr_dir) for x in pr_files ]
69 
70  # Find intersection
71  return [value for value in base_files if value in pr_files]
72 
def get_file_pairs(base_dir, pr_dir)

◆ upload()

def compareDQMOutput.upload (   files)

Definition at line 86 of file compareDQMOutput.py.

References join(), and print().

86 def upload(files):
87  while files:
88  try:
89  file = files.pop()
90  command = ['visDQMUpload.py', 'https://cmsweb.cern.ch/dqm/dev', file]
91  print('Uploading output:')
92  print(' '.join(command))
93 
94  subprocess.call(command)
95  print('')
96  except Exception as ex:
97  # This might throw when another thread pops the last filename immediately after this one
98  # started the loop. In this case this exception can be safely ignored.
99  print('Exception uploading a file: %s' % ex)
100 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ upload_to_gui()

def compareDQMOutput.upload_to_gui (   output_dir,
  num_procs 
)

Definition at line 73 of file compareDQMOutput.py.

References SiStripPI.min, print(), and FastTimerService_cff.range.

73 def upload_to_gui(output_dir, num_procs):
74  base_files = glob.glob(os.path.join(output_dir, 'base/*.root'))
75  pr_files = glob.glob(os.path.join(output_dir, 'pr/*.root'))
76 
77  files = base_files + pr_files
78 
79  print('Files to be uploaded:')
80  print(files)
81 
82  for _ in range(min(num_procs, len(files))):
83  thread = Thread(target=upload, args=(files,))
84  thread.start()
85 
def upload_to_gui(output_dir, num_procs)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Variable Documentation

◆ args

compareDQMOutput.args

Definition at line 164 of file compareDQMOutput.py.

◆ COMPARISON_RESULTS

compareDQMOutput.COMPARISON_RESULTS

Definition at line 10 of file compareDQMOutput.py.

◆ default

compareDQMOutput.default

Definition at line 155 of file compareDQMOutput.py.

◆ description

compareDQMOutput.description

Definition at line 152 of file compareDQMOutput.py.

◆ help

compareDQMOutput.help

Definition at line 155 of file compareDQMOutput.py.

◆ parser

compareDQMOutput.parser

Definition at line 152 of file compareDQMOutput.py.

◆ pr_number

compareDQMOutput.pr_number

Definition at line 167 of file compareDQMOutput.py.

◆ release_format

compareDQMOutput.release_format

Definition at line 173 of file compareDQMOutput.py.

◆ required

compareDQMOutput.required

Definition at line 159 of file compareDQMOutput.py.

◆ type

compareDQMOutput.type

Definition at line 158 of file compareDQMOutput.py.