CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
compareDQMOutput Namespace Reference

Functions

def collect_and_compare_files
 
def compare
 
def generate_summary_html
 
def get_file_pairs
 
def upload
 
def upload_to_gui
 

Variables

tuple args = parser.parse_args()
 
list COMPARISON_RESULTS = []
 
tuple parser
 
string pr_number = 'Unknown'
 
 release_format = args.release_format
 

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 get_file_pairs(), and sistrip::SpyUtilities.range().

12 
13 def collect_and_compare_files(base_dir, pr_dir, output_dir, num_procs, pr_number, test_number, release_format):
14  files = get_file_pairs(base_dir, pr_dir)
15 
16  threads = []
17  for _ in range(num_procs):
18  thread = Thread(target=compare, args=(base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format))
19  thread.start()
20  threads.append(thread)
21 
22  [thread.join() for thread in threads]
23 
24  COMPARISON_RESULTS.sort(key=lambda k: float(k['workflow']))
const uint16_t range(const Frame &aFrame)
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(), join(), print(), and submitPVValidationJobs.split().

25 
26 def compare(base_dir, pr_dir, output_dir, files, pr_number, test_number, release_format):
27  while files:
28  try:
29  file_name = files.pop()
30  command = ['compareHistograms.py', '-b', os.path.join(base_dir, file_name), \
31  '-p', os.path.join(pr_dir, file_name), '-o', output_dir, '-n', pr_number, '-t', test_number, '-r', release_format]
32  print('Running comparison:')
33  print(' '.join(command))
34 
35  output = subprocess.check_output(command).decode()
36 
37  output_elements = output.split('\n')[1:]
38  base_output_filename = output_elements[0]
39  pr_output_filename = output_elements[1]
40  run_nr = base_output_filename.split('_')[2].lstrip('R').lstrip('0')
41  output_numbers = output_elements[2].split(' ')
42 
43  workflow = os.path.basename(os.path.dirname(os.path.join(base_dir, file_name))).split('_')[0]
44  base_dataset = '/' + '/'.join(base_output_filename.rstrip('.root').split('__')[1:])
45  pr_dataset = '/' + '/'.join(pr_output_filename.rstrip('.root').split('__')[1:])
46 
47  cmssw_version = '_'.join(release_format.split('_')[:4])
48  cmssw_version = cmssw_version[:-1] + 'x'
49  root_file_dir_in_gui = 'ROOT/RelValData/%s/' % cmssw_version
50  if 'R000000001__RelVal' in base_output_filename:
51  root_file_dir_in_gui = 'ROOT/RelVal/%s/' % cmssw_version
52 
53  base_file_path_in_gui = root_file_dir_in_gui + base_output_filename
54  pr_file_path_in_gui = root_file_dir_in_gui + pr_output_filename
55 
56  COMPARISON_RESULTS.append({'workflow': workflow, 'base_dataset': base_dataset, 'pr_dataset': pr_dataset, 'run_nr': run_nr,\
57  'changed_elements': int(output_numbers[0]), 'removed_elements': int(output_numbers[1]), 'added_elements': int(output_numbers[2]),
58  'base_file_path_in_gui': base_file_path_in_gui, 'pr_file_path_in_gui': pr_file_path_in_gui})
59  except Exception as ex:
60  print('Exception comparing two root files: %s' % ex)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
bool decode(bool &, std::string const &)
Definition: types.cc:71
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def compareDQMOutput.generate_summary_html (   output_dir,
  pr_list,
  summary_dir 
)

Definition at line 101 of file compareDQMOutput.py.

References str.

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

Definition at line 61 of file compareDQMOutput.py.

Referenced by collect_and_compare_files().

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

Definition at line 86 of file compareDQMOutput.py.

References join(), and print().

86 
87 def upload(files):
88  while files:
89  try:
90  file = files.pop()
91  command = ['visDQMUpload.py', 'https://cmsweb.cern.ch/dqm/dev', file]
92  print('Uploading output:')
93  print(' '.join(command))
94 
95  subprocess.call(command)
96  print('')
97  except Exception as ex:
98  # This might throw when another thread pops the last filename immediately after this one
99  # started the loop. In this case this exception can be safely ignored.
100  print('Exception uploading a file: %s' % ex)
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
def compareDQMOutput.upload_to_gui (   output_dir,
  num_procs 
)

Definition at line 73 of file compareDQMOutput.py.

References min(), print(), and sistrip::SpyUtilities.range().

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

Variable Documentation

tuple compareDQMOutput.args = parser.parse_args()

Definition at line 164 of file compareDQMOutput.py.

list compareDQMOutput.COMPARISON_RESULTS = []

Definition at line 10 of file compareDQMOutput.py.

tuple compareDQMOutput.parser
Initial value:
1 = argparse.ArgumentParser(description="This tool compares DQM monitor elements within DQM files found in base-dir with the ones found in in pr-dir. "
2  "All workflow directories are searched for correctly named DQM root files. "
3  "Comparison is done bin by bin and output is written to a root files containing only the changes.")

Definition at line 152 of file compareDQMOutput.py.

tuple compareDQMOutput.pr_number = 'Unknown'

Definition at line 167 of file compareDQMOutput.py.

list compareDQMOutput.release_format = args.release_format

Definition at line 173 of file compareDQMOutput.py.