CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
web.app_utils Namespace Reference

Functions

def db_list_with_releases
 
def get_dataset_name
 
def get_directory_summary_stats
 
def get_folders
 
def get_img_path
 
def get_img_url
 
def get_percentage
 
def get_release
 
def get_release_list
 
def get_release_summary_stats
 
def get_stats
 
def join_ranges
 

Variables

dictionary renaming
 

Function Documentation

def web.app_utils.db_list_with_releases (   path = '.')
Returns available database list and their releases.

Definition at line 149 of file app_utils.py.

References web.app_utils.get_release_list(), and join().

Referenced by web.dbfile2html.dbfile2html(), and web.browse_db.BrowseDB.default().

150 def db_list_with_releases(path='.'):
151  '''Returns available database list and their releases.'''
152  db_list = [db for db in listdir(path) if db.endswith('.db')]
153  db_list_with_releases = []
154  for db in db_list:
155  conn = sqlite3.connect(join(path, db))
156  releases = get_release_list(conn.cursor())
157  db_list_with_releases.append((db[:-3], releases))
158  conn.close()
159  return db_list_with_releases
160 
161 # ------------------- Template Context generators --------------------
def db_list_with_releases
Definition: app_utils.py:149
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def get_release_list
Definition: app_utils.py:143
def web.app_utils.get_dataset_name (   name)
Returns extracted dataset name from the given ROOT filename.

Definition at line 66 of file app_utils.py.

References join().

Referenced by web.app_utils.get_directory_summary_stats(), and web.app_utils.get_folders().

66 
67 def get_dataset_name(name):
68  '''Returns extracted dataset name from the given ROOT filename.'''
69  if re.search('RelVal', name):
70  run = str(int(re.findall('_R(\d{9})_', name)[0]))
71  ds = re.findall('GR_R_\d*_V\d*C?_(?:RelVal)?_([\w\d]*-v\d+)_', name)[0]
72  else:
73  run, ds = re.findall('R(\d{9})__([\w\d]*)__CMSSW_', name)[0:1]
74  return '_'.join([ds, str(int(run))])
75 
def get_dataset_name
Definition: app_utils.py:66
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def web.app_utils.get_directory_summary_stats (   c,
  url_args,
  file_id,
  threshold 
)
Returns context for ``directory_summary.html`` template.

Definition at line 282 of file app_utils.py.

References python.multivaluedict.dict, web.app_utils.get_dataset_name(), web.app_utils.get_img_url(), web.app_utils.get_percentage(), web.app_utils.get_release(), web.app_utils.get_stats(), and join().

Referenced by web.dbfile2html.dbfile2html(), and web.browse_db.BrowseDB.default().

283 def get_directory_summary_stats(c, url_args, file_id, threshold):
284  '''Returns context for ``directory_summary.html`` template.'''
285  context = dict()
286  c.execute('''SELECT directory_id, filename1, filename2 FROM RootFileComparison
287  WHERE id = ?''', (file_id,))
288  dir_id, f1, f2 = c.fetchone()
289  context['release1'] = get_release(f1)
290  context['release2'] = get_release(f2)
291  if not url_args:
292  dir_name = get_dataset_name(f1)
293  else:
294  #### Select DQMData/Run directory.
295  directory_names = []
296 
297  for dir_name in url_args:
298  c.execute('''SELECT id, name FROM Directory WHERE name = ? AND
299  parent_id = ?''', (dir_name, dir_id))
300  dir_id, name = c.fetchone()
301  directory_names.append(name)
302  context['parent_name'] = '/'.join(directory_names)
303 
304  ## Select stats
305  c.execute('''SELECT from_histogram_id, till_histogram_id FROM
306  Directory WHERE id = ?''', (dir_id,))
307  ranges = c.fetchone()
308  successes, nulls, fails = get_stats(c, threshold, (ranges,))
309  success, null, fail = get_percentage(successes, nulls, fails)
310  context.update({
311  'successes': successes, 'nulls': nulls, 'fails': fails,
312  'success': success, 'null': null, 'fail': fail,
313  'total': successes + nulls + fails, 'dir_name': dir_name
314  })
315  # subdirs: name, total, success, fail, null
316  c.execute('''SELECT name, from_histogram_id, till_histogram_id FROM Directory
317  WHERE parent_id = ?''', (dir_id,))
318  subdirs = c.fetchall()
319  subdir_stats = []
320  for name, from_id, till_id in subdirs:
321  successes, nulls, fails = get_stats(c, threshold, [(from_id, till_id,)])
322  success, null, fail = get_percentage(successes, nulls, fails)
323  subdir_stats.append((name, successes + nulls + fails, successes,
324  nulls, fails, success, null, fail))
325  context['subdirs'] = sorted(subdir_stats, key=lambda x: x[4], reverse=True)
326 
327  # histograms: name, p_value
328  c.execute('''SELECT name, p_value FROM HistogramComparison
329  WHERE directory_id = ?''', (dir_id,))
330  failed_histos = []
331  successful_histos = []
332  null_histos = []
333  for name, p_value in c.fetchall():
334  path = quote('%s/%s' % ('/'.join(url_args), name))
335  url1 = get_img_url(path, f1)
336  url2 = get_img_url(path, f2)
337  overlay = get_img_url(path, f1, f2)
338  if p_value < 0:
339  null_histos.append((name, p_value, url1, url2, overlay))
340  elif p_value <= threshold:
341  failed_histos.append((name, p_value, url1, url2, overlay))
342  else:
343  successful_histos.append((name, p_value, url1, url2, overlay))
344 
345  context['failed_histos'] = sorted(failed_histos, key=lambda x: x[1], reverse=True)
346  context['null_histos'] = null_histos
347  context['successful_histos'] = sorted(successful_histos, key=lambda x: x[1], reverse=True)
348  return context
def get_img_url
Definition: app_utils.py:56
def get_release
Definition: app_utils.py:76
def get_dataset_name
Definition: app_utils.py:66
def get_percentage
Definition: app_utils.py:99
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def get_directory_summary_stats
Definition: app_utils.py:282
def web.app_utils.get_folders (   c,
  file_id,
  filename,
  dir_id,
  threshold 
)
Returns file folder stats for one "summary table" column.

Definition at line 112 of file app_utils.py.

References python.multivaluedict.append(), python.multivaluedict.dict, web.app_utils.get_dataset_name(), and web.app_utils.get_stats().

Referenced by web.app_utils.get_release_summary_stats().

113 def get_folders(c, file_id, filename, dir_id, threshold): # TODO: If folder [Egamma|JetMet] analyse their subdirs
114  '''Returns file folder stats for one "summary table" column.'''
115  ds_name = get_dataset_name(filename)
116  c.execute('''SELECT name, from_histogram_id, till_histogram_id FROM
117  Directory WHERE parent_id=?''', (dir_id,))
118  dirs = c.fetchall()
119  file_folders = dict()
120  total_successes, total_nulls, total_fails = 0, 0, 0
121  for name, from_id, till_id in dirs:
122  successes, nulls, fails = get_stats(c, threshold, ((from_id, till_id),))
123  total_successes += successes
124  total_nulls += nulls
125  total_fails += fails
126  if file_folders.has_key(name):
127  file_folders[name].append([file_id, ds_name, successes, nulls, fails])
128  else:
129  file_folders[name] = [file_id, ds_name, successes, nulls, fails]
130  return [('Summary', [file_id, ds_name, total_successes, total_nulls, total_fails])] + file_folders.items()
131 
def get_dataset_name
Definition: app_utils.py:66
def web.app_utils.get_img_path (   filename,
  path 
)
Returns image path for https://cmsweb.cern.ch/dqm histogram
visualisation service

Definition at line 47 of file app_utils.py.

Referenced by web.app_utils.get_img_url().

47 
48 def get_img_path(filename, path):
49  '''Returns image path for https://cmsweb.cern.ch/dqm histogram
50  visualisation service'''
51  run = int(re.findall('_R(\d*)__', filename)[0])
52  parts = [e.rstrip('.root') for e in filename.split('__')]
53  path = path.replace('Run summary/', '')
54  return 'archive/%s/%s/%s/%s/%s' % (run, parts[1], parts[2], parts[3], path)
55 
def get_img_path
Definition: app_utils.py:47
def web.app_utils.get_img_url (   path,
  f1,
  f2 = None,
  w = 250,
  h = 250 
)
Returns full URL of histogram (or histogram overlay) image for
https://cmsweb.cern.ch/dqm visualisation service.

Definition at line 56 of file app_utils.py.

References web.app_utils.get_img_path().

Referenced by web.app_utils.get_directory_summary_stats().

56 
57 def get_img_url(path, f1, f2=None, w=250, h=250):
58  '''Returns full URL of histogram (or histogram overlay) image for
59  https://cmsweb.cern.ch/dqm visualisation service.'''
60  base = 'https://cmsweb.cern.ch/dqm/relval/plotfairy'
61  if not f2:
62  return '%s/%s?w=%s;h=%s' % (base, get_img_path(f1, path), w, h)
63  return '%s/overlay?obj=%s;obj=%s;w=%s;h=%s' % (base,
64  get_img_path(f1, path), get_img_path(f2, path), w, h)
65 
def get_img_url
Definition: app_utils.py:56
def get_img_path
Definition: app_utils.py:47
def web.app_utils.get_percentage (   successes,
  nulls,
  fails 
)
Converts integers ``successes``, ``nulls`` and ``fails`` to percents.

Definition at line 99 of file app_utils.py.

Referenced by web.app_utils.get_directory_summary_stats(), and web.app_utils.get_release_summary_stats().

99 
100 def get_percentage(successes, nulls, fails):
101  '''Converts integers ``successes``, ``nulls`` and ``fails`` to percents.'''
102  if successes is None:
103  return None, None, None
104  total = successes + fails + nulls
105  if not total:
106  return None, None, None
107  success = round(100. * successes / total, 2)
108  null = round(100. * nulls / total, 2)
109  fail = round(100. * fails / total, 2)
110  return success, null, fail
111 
def get_percentage
Definition: app_utils.py:99
def web.app_utils.get_release (   name)
Returns extracted release from the given ROOT filename.

Definition at line 76 of file app_utils.py.

Referenced by web.app_utils.get_directory_summary_stats().

76 
77 def get_release(name):
78  '''Returns extracted release from the given ROOT filename.'''
79  return re.findall('R\d{9}__([\w\d_-]*)__DQM.root', name)[0]
80 
def get_release
Definition: app_utils.py:76
def web.app_utils.get_release_list (   c)
Returns all ``ReleaseComparisons`` found on database.

Definition at line 143 of file app_utils.py.

Referenced by web.app_utils.db_list_with_releases(), and web.browse_db.BrowseDB.default().

144 def get_release_list(c):
145  '''Returns all ``ReleaseComparisons`` found on database.'''
146  c.execute('SELECT title, statistical_test FROM ReleaseComparison')
147  return c.fetchall()
148 
def get_release_list
Definition: app_utils.py:143
def web.app_utils.get_release_summary_stats (   c,
  release_title,
  st_test,
  threshold = 1e-5 
)
Returns context for ``release_summary.html`` template.

Definition at line 162 of file app_utils.py.

References python.multivaluedict.append(), python.multivaluedict.dict, web.app_utils.get_folders(), web.app_utils.get_percentage(), and web.app_utils.get_stats().

Referenced by web.dbfile2html.dbfile2html(), and web.browse_db.BrowseDB.default().

163 def get_release_summary_stats(c, release_title, st_test, threshold=1e-5):
164  '''Returns context for ``release_summary.html`` template.'''
165  ## Summary
166  context = dict()
167  c.execute('''SELECT release1, release2, id FROM ReleaseComparison
168  WHERE title = ? AND statistical_test = ?''', (release_title, st_test))
169  context['release1'], context['release2'], release_comp_id = c.fetchone()
170 
171  # All directory ranges
172  c.execute('''SELECT from_histogram_id, till_histogram_id FROM Directory
173  WHERE id IN (SELECT directory_id FROM RootFileComparison
174  WHERE release_comparison_id = ?)''', (release_comp_id,))
175  dir_ranges = c.fetchall()
176 
177  if len(dir_ranges) > 1:
178  dir_ranges = reduce(join_ranges, dir_ranges)
179 
180  context['successes'], context['nulls'], context['fails'], = get_stats(c, threshold, dir_ranges)
181 
182  context['total'] = context['successes'] + context['fails'] + context['nulls']
183  if context['total']:
184  context['success'], context['null'], context['fail'] = \
185  get_percentage(context['successes'], context['nulls'], context['fails'])
186 
187  ## Data needed for the all the statistics:
188  c.execute('''SELECT id, filename1, directory_id FROM RootFileComparison
189  WHERE release_comparison_id = ?''', (release_comp_id,))
190  files = c.fetchall()
191 
192  ## folders: [(folder_name, [folder: (file_id, filename, success, null, fail)]), ...]
193  folders = dict()
194  for file_id, filename, dir_id in files:
195  # file_folders: [(folder_name, [(file_id, file_name, success, null, fail)]), ...]
196  file_folders = get_folders(c, file_id, filename, dir_id, threshold)
197  for folder_name, file_folder_stats in file_folders:
198  if folders.has_key(folder_name):
199  # Add folder stats
200  folders[folder_name].append(file_folder_stats)
201  # Update folder summary
202  folders[folder_name][0][2] += file_folder_stats[2]
203  folders[folder_name][0][3] += file_folder_stats[3]
204  folders[folder_name][0][4] += file_folder_stats[4]
205  else:
206  folder_summary = [None, 'Summary', file_folder_stats[2],
207  file_folder_stats[3], file_folder_stats[4]]
208  folders[folder_name] = [folder_summary, file_folder_stats]
209 
210  ## Calculate ratios
211  folders = [('Summary', folders.pop('Summary'))] + sorted(folders.items(), key=lambda x: x[0])
212  for folder, file_stats in folders:
213  # Insert N/A if histo is missing
214  if len(file_stats) != len(files)+1:
215  for i, file_ in enumerate(files):
216  if file_[0] != file_stats[i][0]:
217  file_stats = file_stats[:i] + [[None, "N/A", None, None, None]] + file_stats[i:]
218  # Count the ratios
219  for i, stats in enumerate(file_stats):
220  stats[2], stats[3], stats[4] = get_percentage(*stats[2:5])
221  context['folders'] = folders
222 
223 
224  ## Select Summary Barchart, Detailed Barchart
225  for folder in folders:
226  print folder
227  # detailed_ratios: (name, success_ratio)
228  # summary_ratios: (name, success_ratio)
229 
230 
231  ## Summary Barchart
232  # TODO: optimise not to fetch from DB again.
233  c.execute('''SELECT name, from_histogram_id, till_histogram_id FROM Directory
234  WHERE parent_id IN (SELECT directory_id FROM RootFileComparison
235  WHERE release_comparison_id = ?)''', (release_comp_id,))
236  lvl3_dir_ranges = c.fetchall()
237 
238  cum_lvl3_dir_ranges = dict()
239  for name, from_id, till_id in lvl3_dir_ranges:
240  if cum_lvl3_dir_ranges.has_key(name):
241  cum_lvl3_dir_ranges[name].append((from_id, till_id))
242  else:
243  cum_lvl3_dir_ranges[name] = [(from_id, till_id)]
244 
245  # Fetch stats
246  summary_stats = dict()
247  detailed_stats = dict()
248  for name, ranges in cum_lvl3_dir_ranges.iteritems():
249  successes, nulls, fails = get_stats(c, threshold, ranges)
250  if detailed_stats.has_key(name):
251  detailed_stats[name][0] += successes
252  detailed_stats[name][1] += nulls
253  detailed_stats[name][2] += fails
254  else:
255  detailed_stats[name] = [successes, nulls, fails]
256  if renaming.has_key(name):
257  if summary_stats.has_key(renaming[name]):
258  summary_stats[renaming[name]][0] += successes
259  summary_stats[renaming[name]][1] += nulls
260  summary_stats[renaming[name]][2] += fails
261  else:
262  summary_stats[renaming[name]] = [successes, nulls, fails]
263 
264  # Calculate ratio
265  summary_ratios = []
266  for name, stats in summary_stats.iteritems():
267  total = sum(stats)
268  if total:
269  ratio = float(stats[0]) / sum(stats)
270  summary_ratios.append((name, ratio))
271  detailed_ratios = []
272  for name, stats in detailed_stats.iteritems():
273  total = sum(stats)
274  if total:
275  ratio = float(stats[0]) / sum(stats)
276  detailed_ratios.append((name, ratio))
277 
278  context['summary_ratios'] = sorted(summary_ratios, key=lambda x: x[0])
279  context['detailed_ratios'] = sorted(detailed_ratios, key=lambda x: x[0])
280  return context
281 
def get_release_summary_stats
Definition: app_utils.py:162
def get_percentage
Definition: app_utils.py:99
def web.app_utils.get_stats (   c,
  threshold,
  dir_ranges 
)
Returns ``successes``, ``fails``, ``nulls`` for the given dir_ranges.

Definition at line 81 of file app_utils.py.

Referenced by web.app_utils.get_directory_summary_stats(), web.app_utils.get_folders(), and web.app_utils.get_release_summary_stats().

81 
82 def get_stats(c, threshold, dir_ranges):
83  '''Returns ``successes``, ``fails``, ``nulls`` for the given dir_ranges.'''
84  successes, nulls, fails = 0, 0, 0
85  for from_id, till_id in dir_ranges:
86  c.execute('''SELECT count(*) FROM HistogramComparison
87  WHERE p_value >= 0 AND p_value > ? AND
88  id >= ? and id <= ?''', (threshold, from_id, till_id))
89  successes += c.fetchone()[0]
90  c.execute('''SELECT count(*) FROM HistogramComparison WHERE
91  p_value < 0 AND id >= ? AND id <= ?''', (from_id, till_id))
92  nulls += c.fetchone()[0]
93  c.execute('''SELECT count(*) FROM HistogramComparison
94  WHERE p_value >= 0 AND p_value <= ? AND
95  id >= ? AND id <= ?''', (threshold, from_id, till_id))
96  fails += c.fetchone()[0]
97  return successes, nulls, fails
98 
def web.app_utils.join_ranges (   ranges,
  elem 
)
To do less DB calls, joins [(from_id, till_id), ...] ranges.

Definition at line 132 of file app_utils.py.

133 def join_ranges(ranges, elem):
134  '''To do less DB calls, joins [(from_id, till_id), ...] ranges.'''
135  if type(ranges) == tuple:
136  ranges = [ranges]
137  if ranges[-1][-1] + 1 == elem[0]:
138  ranges[-1] = (ranges[-1][0], elem[1])
139  else:
140  ranges.append(elem)
141  return ranges
142 

Variable Documentation

dictionary web.app_utils.renaming
Initial value:
1 = {
2  'MessageLogger': 'Miscellanea', 'FourVector': 'Generic',
3  'Castor': 'Castor Calorimeter', 'RPCDigisV': 'Resistive Plate Chambers',
4  'GlobalRecHitsV': 'Miscellanea: Sim.', 'Top': 'Top', 'HLTJETMET': 'JetMet',
5  'GlobalDigisV': 'Miscellanea: Sim.', 'L1TEMU': 'Level 1 Trigger',
6  'TrackerRecHitsV': 'Tracking System', 'MuonDTHitsV': 'Muon Objects',
7  'EcalDigisV': 'Ecal Calorimeter', 'EcalHitsV': 'Ecal Calorimeter',
8  'Muons': 'Muon Objects', 'DT': 'Drift Tubes', 'TrackerDigisV': 'Tracking System',
9  'Pixel': 'Tracking System', 'EcalPreshower': 'Ecal Calorimeter',
10  'EgammaV': 'Photons', 'AlCaEcalPi0': 'Alca', 'SusyExo': 'SusyExo',
11  'MuonDTDigisV': 'Muon Objects', 'TauRelVal': 'Tau',
12  'HcalHitsV': 'Hcal Calorimeter', 'RPC': 'Resistive Plate Chambers',
13  'EcalRecHitsV': 'Ecal Calorimeter', 'EgOffline': 'EGamma',
14  'MuonCSCDigisV': 'Muon Objects', 'ParticleFlow': 'Miscellanea',
15  'Info': 'Miscellanea', 'Tracking': 'Tracking',
16  'NoiseRatesV': 'Miscellanea: Sim.', 'Generator': 'Miscellanea: Sim.',
17  'Btag': 'B Tagging', 'Higgs': 'Higgs', 'GlobalHitsV': 'Miscellanea: Sim.',
18  'HcalRecHitsV': 'Hcal Calorimeter', 'TrackerHitsV': 'Tracking System',
19  'CSC': 'Cathode Strip Chambers', 'Muon,HLTMonMuon': 'Muon',
20  'Hcal': 'Hcal Calorimeter', 'TauOffline': 'Tau',
21  'HeavyFlavor': 'HeavyFlavor', 'JetMET': 'Jet', 'Physics': 'Miscellanea',
22  'CaloTowersV': 'Hcal Calorimeter', 'SiStrip': 'Tracking System',
23  'EcalClusterV': 'Ecal Calorimeter', 'HLTEgammaValidation': 'EGamma',
24  'EcalPhiSym': 'Alca', 'L1T': 'Level 1 Trigger', 'MixingV': 'Miscellanea: Sim.',
25  'FourVector_Val': 'Generic', 'EcalEndcap': 'Ecal Calorimeter',
26  'TauOnline': 'Tau', 'Egamma': 'Photons', 'HcalIsoTrack': 'Alca',
27  'EcalBarrel': 'Ecal Calorimeter'
28 }

Definition at line 17 of file app_utils.py.