CMS 3D CMS Logo

presentation.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import abc
3 import math
4 import os
5 import re
6 
7 from genericValidation import ValidationForPresentation, ValidationWithPlotsSummary
8 from helperFunctions import recursivesubclasses
9 from presentationTemplates import *
10 from TkAlExceptions import AllInOneError
11 
12 # Plots related to a single validation:
14  def __init__(self, path):
15  if not os.path.isdir(path):
16  print("Error: Directory "+path+" not found!")
17  exit(1)
18  if not path.endswith('/'):
19  path += '/'
20  path = path.replace('\\', '/') # Beacause LaTeX has issues with '\'.
21  self.path = path
22  # List of plot files in given directory:
23  self.plots = [file for file in os.listdir(path)
24  if file.endswith('.eps')]
25 
26  @property
27  def validationclass(self):
28  possiblenames = []
29  for cls in recursivesubclasses(ValidationForPresentation):
30  if cls.__abstractmethods__: continue
31  if cls.plotsdirname() == os.path.basename(os.path.realpath(self.path.rstrip("/"))):
32  return cls
33  possiblenames.append(cls.plotsdirname())
34  raise AllInOneError("{} does not match any of the possible folder names:\n{}".format(self.path, ", ".join(possiblenames)))
35 
36 def validationclasses(validations):
37  from collections import OrderedDict
38  classes = [validation.validationclass for validation in validations]
39  #remove duplicates - http://stackoverflow.com/a/39835527/5228524
40  classes = list(OrderedDict.fromkeys(classes))
41  return classes
42 
43 # Layout of plots on a page:
45  def __init__(self, pattern=[], width=1, height=1):
46  self.pattern = [] # List of rows; row contains the order numbers
47  # of its plots; e.g. [[1,2,3], [4,5,6]]
48  self.width = width # Maximum width of one plot,
49  # with respect to textwidth.
50  self.height = height # Maximum height of one plot,
51  # with respect to textheight.
52 
53  # Sets variables for the given plots and returns the plots
54  # in an appropriate order:
55  def fit(self, plots):
56  rowlengths = []
57  # First, try to place plots in a square.
58  nplots = sum(len(p) for p in plots)
59  length = int(math.ceil(math.sqrt(nplots)))
60  # Then, fill the square from the bottom and remove extra rows.
61  fullRows = int(nplots/length)
62  residual = nplots - length*fullRows
63  nrows = fullRows
64  if residual != 0:
65  rowlengths.append(residual)
66  nrows += 1
67  for _ in xrange(fullRows):
68  rowlengths.append(length)
69 
70  # Now, fill the pattern.
71  self.pattern = []
72  if residual == 0 and len(plots[0])%length != 0 and\
73  len(plots[0])%nrows == 0:
74  # It's better to arrange plots in columns, not rows.
75  self.pattern.extend(range(i, i+nrows*(length-1)+1, nrows)
76  for i in range(1, nrows+1))
77  else:
78  if residual != 0:
79  self.pattern.append(range(1, 1+residual))
80  self.pattern.extend(range(i, i+length) for i in
81  range(residual+1, nplots-length+2, length))
82 
83  self.width = 1.0/length
84  self.height = 0.8/nrows
85 
86 
87 # Write a set of pages, one for each subdetector.
88 # Arguments: identifier: regular expression to get the wanted plots,
89 # used together with subdetector name
90 # title: title of the plot type
91 # validations: list of relevant ValidationPlots objects.
92 # Returns the parsed script.
94  __metaclass__ = abc.ABCMeta
95  def __init__(self, title):
96  self.title = title
97  def write(self, validations):
98  script = '\n'.join(_ for _ in self.pages(validations) if _)
99  if script != '':
100  script = subsectionTemplate.replace('[title]', self.title)+script
101  return script
102  @abc.abstractmethod
103  def pages(self, validations):
104  pass
105 
106 class SubsectionOnePage(SubsectionBase):
107  def __init__(self, identifier, title):
108  self.identifier = identifier
109  super(SubsectionOnePage, self).__init__(title)
110  def pages(self, validations):
111  return [writePageReg(self.identifier, self.title, validations)]
112 
114  def __init__(self, identifier, title):
115  self.identifier = identifier
116  super(SubsectionFromList, self).__init__(title)
117  def pages(self, validations):
118  return [writePageReg('(?=.*%s)%s'%(pageidentifier, self.identifier),
119  self.title+': ' +pagetitle, validations)
120  for pageidentifier, pagetitle in self.pageidentifiers]
121  @abc.abstractproperty
122  def pageidentifiers(self):
123  pass
124 
125 class SummarySection(SubsectionBase):
126  def __init__(self):
127  super(SummarySection, self).__init__("Summary")
128  def pages(self, validations):
129  return [summaryTemplate.replace('[title]', self.title)
130  .replace('[summary]', validation.validationclass.summaryitemsstring(folder=validation.path, latex=True))
131  .replace("tabular", "longtable") for validation in validations
132  if issubclass(validation.validationclass, ValidationWithPlotsSummary)]
133 
134 # Write a page containing plots of given type.
135 # Arguments: identifier: regular expression to get the wanted plots
136 # title: title of the plot type
137 # validations: list of relevant ValidationPlots objects
138 # layout: given page layout.
139 # Returns the parsed script.
140 def writePageReg(identifier, title, validations, layout=0):
141  plots = []
142  for validation in validations:
143  valiplots = [validation.path+plot for plot in validation.plots
144  if re.search(identifier, plot)]
145  valiplots.sort(key=plotSortKey)
146  plots.append(valiplots)
147  if sum(len(p) for p in plots) == 0:
148  print('Warning: no plots matching ' + identifier)
149  return ''
150 
151  # Create layout, if not given.
152  if layout == 0:
153  layout = PageLayout()
154  layout.fit(plots)
155 
156  return writePage([p for vali in plots for p in vali], title, layout)
157 
158 
159 # Write the given plots on a page.
160 # Arguments: plots: paths of plots to be drawn on the page
161 # title: title of the plot type
162 # layout: a PageLayout object definig the layout.
163 # Returns the parsed script.
164 def writePage(plots, title, layout):
165  plotrows = []
166  for row in layout.pattern:
167  plotrow = []
168  for i in xrange(len(row)):
169  plotrow.append(plotTemplate.replace('[width]', str(layout.width)).\
170  replace('[height]', str(layout.height)).\
171  replace('[path]', plots[row[i]-1]))
172  plotrows.append('\n'.join(plotrow))
173  script = ' \\\\\n'.join(plotrows)
174 
175  return frameTemplate.replace('[plots]', script).replace('[title]', title)
176 
177 
178 # Sort key to rearrange a plot list.
179 # Arguments: plot: to be sorted.
180 def plotSortKey(plot):
181  # Move normchi2 before chi2Prob
182  if plot.find('normchi2') != -1:
183  return 'chi2a'
184  if plot.find('chi2Prob') != -1:
185  return 'chi2b'
186  return plot
187 
188 import geometryComparison
189 import offlineValidation
190 import trackSplittingValidation
191 import primaryVertexValidation
192 import zMuMuValidation
def writePageReg(identifier, title, validations, layout=0)
def pages(self, validations)
def replace(string, replacements)
def pages(self, validations)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def validationclasses(validations)
Definition: presentation.py:36
def fit(self, plots)
Definition: presentation.py:55
def __init__(self, identifier, title)
def pages(self, validations)
def __init__(self, identifier, title)
def __init__(self, title)
Definition: presentation.py:95
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def __init__(self, pattern=[], width=1, height=1)
Definition: presentation.py:45
def write(self, validations)
Definition: presentation.py:97
def writePage(plots, title, layout)
def recursivesubclasses(cls)
#define str(s)
def pages(self, validations)
def plotSortKey(plot)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run