CMS 3D CMS Logo

Classes | Functions | Variables
validation Namespace Reference

Classes

class  Sample
 
class  SeparateValidation
 
class  SimpleSample
 
class  SimpleValidation
 
class  Validation
 

Functions

def _copyDir (src, dst)
 
def _copySubDir (oldfile, newfile, basenames, dirname)
 
def _doPlotsForPlotter (self, plotter, sample, limitSubFoldersOnlyTo=None)
 
def _findDuplicates (lst)
 
def _getGlobalTag (sample, release)
 
def _getRelValUrl (release)
 
def _processPlotsForSample (plotterFolder, sample)
 
def _stripRelease (release)
 

Variables

 _doBHadronSamples
 
 _doConversionSamples
 
 _doElectronSamples
 
 _globalTags
 
 _releasePostfixes
 
 _relvalUrls
 
 IgnoreCommandLineOptions
 

Function Documentation

◆ _copyDir()

def validation._copyDir (   src,
  dst 
)
private
Copy non-TTree objects from src TDirectory to dst TDirectory.

Definition at line 1165 of file validation.py.

Referenced by _copySubDir().

1165 def _copyDir(src, dst):
1166  """Copy non-TTree objects from src TDirectory to dst TDirectory."""
1167  keys = src.GetListOfKeys()
1168  for key in keys:
1169  classname = key.GetClassName()
1170  cl = ROOT.TClass.GetClass(classname)
1171  if not cl:
1172  continue
1173  if not (cl.InheritsFrom("TTree") and cl.InheritsFrom("TDirectory")):
1174  dst.cd()
1175  obj = key.ReadObj()
1176  obj.Write()
1177  obj.Delete()
1178 
def _copyDir(src, dst)
Definition: validation.py:1165

◆ _copySubDir()

def validation._copySubDir (   oldfile,
  newfile,
  basenames,
  dirname 
)
private
Copy a subdirectory from oldfile to newfile.

Arguments:
oldfile   -- String for source TFile
newfile   -- String for destination TFile
basenames -- List of strings for base directories, first existing one is picked
dirname   -- String for directory name under the base directory

Definition at line 1130 of file validation.py.

References _copyDir(), join(), and submitPVValidationJobs.split().

Referenced by validation.Validation._doPlots().

1130 def _copySubDir(oldfile, newfile, basenames, dirname):
1131  """Copy a subdirectory from oldfile to newfile.
1132 
1133  Arguments:
1134  oldfile -- String for source TFile
1135  newfile -- String for destination TFile
1136  basenames -- List of strings for base directories, first existing one is picked
1137  dirname -- String for directory name under the base directory
1138  """
1139  oldf = ROOT.TFile.Open(oldfile)
1140 
1141  dirold = None
1142  for basename in basenames:
1143  dirold = oldf.GetDirectory(basename)
1144  if dirold:
1145  break
1146  if not dirold:
1147  raise Exception("Did not find any of %s directories from file %s" % (",".join(basenames), oldfile))
1148  if dirname:
1149  d = dirold.Get(dirname)
1150  if not d:
1151  raise Exception("Did not find directory %s under %s" % (dirname, dirold.GetPath()))
1152  dirold = d
1153 
1154  newf = ROOT.TFile.Open(newfile, "RECREATE")
1155  dirnew = newf
1156  for d in basenames[0].split("/"):
1157  dirnew = dirnew.mkdir(d)
1158  if dirname:
1159  dirnew = dirnew.mkdir(dirname)
1160  _copyDir(dirold, dirnew)
1161 
1162  oldf.Close()
1163  return newf
1164 
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _copyDir(src, dst)
Definition: validation.py:1165
def _copySubDir(oldfile, newfile, basenames, dirname)
Definition: validation.py:1130

◆ _doPlotsForPlotter()

def validation._doPlotsForPlotter (   self,
  plotter,
  sample,
  limitSubFoldersOnlyTo = None 
)
private

Definition at line 1189 of file validation.py.

References _processPlotsForSample(), join(), and FastTimerService_cff.range.

1189 def _doPlotsForPlotter(self, plotter, sample, limitSubFoldersOnlyTo=None):
1190  plotterInstance = plotter.readDirs(*self._openFiles)
1191  manager = multiprocessing.Manager()
1192  return_dict = manager.dict()
1193  proc = []
1194  iProc = 0
1195 
1196  for plotterFolder, dqmSubFolder in plotterInstance.iterFolders(limitSubFoldersOnlyTo=limitSubFoldersOnlyTo):
1197  if sample is not None and not _processPlotsForSample(plotterFolder, sample):
1198  continue
1199  newsubdir = self._subdirprefix+plotterFolder.getSelectionName(dqmSubFolder)
1200  newdir = os.path.join(self._newdir, newsubdir)
1201  if not os.path.exists(newdir):
1202  os.makedirs(newdir, exist_ok=True)
1203 
1204  plotterFolder.create(self._openFiles, self._labels, dqmSubFolder)
1205  p = multiprocessing.Process(target=self._doPlots, args=(plotterFolder, dqmSubFolder, newsubdir, newdir, iProc, return_dict))
1206  proc.append((plotterFolder, dqmSubFolder, p))
1207  p.start()
1208  iProc += 1
1209 
1210  for i in range(iProc):
1211  proc[i][2].join()
1212  if len(return_dict[i]) > 0:
1213  self._htmlReport.addPlots(proc[i][0], proc[i][1], return_dict[i])
1214 
def _doPlotsForPlotter(self, plotter, sample, limitSubFoldersOnlyTo=None)
Definition: validation.py:1189
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:464
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ _findDuplicates()

def validation._findDuplicates (   lst)
private

Definition at line 1179 of file validation.py.

Referenced by validation.Validation._doPlots(), validation.SimpleValidation._doPlots(), validation.SeparateValidation._doPlots(), validation.Validation._doPlotsFastFull(), and validation.Validation._doPlotsPileup().

1179 def _findDuplicates(lst):
1180  found = set()
1181  found2 = set()
1182  for x in lst:
1183  if x in found:
1184  found2.add(x)
1185  else:
1186  found.add(x)
1187  return list(found2)
1188 
def _findDuplicates(lst)
Definition: validation.py:1179

◆ _getGlobalTag()

def validation._getGlobalTag (   sample,
  release 
)
private
Get a GlobalTag.

Arguments:
sample  -- Sample object
release -- CMSSW release string

Definition at line 360 of file validation.py.

References print().

Referenced by validation.Validation._doPlots(), validation.Validation._doPlotsFastFull(), validation.Validation._doPlotsPileup(), validation.Validation._getRefFileAndSelection(), validation.Sample.datasetpattern(), and validation.Sample.filename().

360 def _getGlobalTag(sample, release):
361  """Get a GlobalTag.
362 
363  Arguments:
364  sample -- Sample object
365  release -- CMSSW release string
366  """
367  if not release in _globalTags:
368  print("Release %s not found from globaltag map in validation.py" % release)
369  sys.exit(1)
370  gtmap = _globalTags[release]
371  selectedGT = None
372  if sample.hasOverrideGlobalTag():
373  ogt = sample.overrideGlobalTag()
374  if release in ogt:
375  gtmap = _globalTags[ogt[release]]
376  scenario = ""
377  if sample.hasScenario():
378  scenario = sample.scenario()
379  sims = []
380  if sample.fullsim():
381  if sample.pileupEnabled():
382  sim = "fullsim_"+sample.pileupType()
383  sims.extend([
384  sim+"_PU%d"%sample.pileupNumber(),
385  sim
386  ])
387  elif sample.fastsim():
388  sim = "fastsim"
389  if sample.pileupEnabled():
390  sim += "_"+sample.pileupType()
391  sims.append(sim+"_PU%d"%sample.pileupNumber())
392  sims.append(sim)
393 
394  selectedGT = None
395  # First try with scenario+simulation
396  if scenario != "":
397  for sim in sims:
398  selectedGT = gtmap.get(scenario+"_"+sim, None)
399  if selectedGT is not None:
400  break
401  # Then with scenario (but only if sample specifies a scenario)
402  if selectedGT is None:
403  selectedGT = gtmap.get(scenario, None)
404  # Then with simulation
405  if selectedGT is None:
406  for sim in sims:
407  selectedGT = gtmap.get(sim, None)
408  if selectedGT is not None:
409  break
410  # Finally default
411  if selectedGT is None:
412  selectedGT = gtmap["default"]
413 
414  if isinstance(selectedGT, dict):
415  return selectedGT.get(sample.name(), selectedGT["default"])
416  else:
417  return selectedGT
418 
419 # Mapping from release series to RelVal download URLs
def _getGlobalTag(sample, release)
Definition: validation.py:360
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ _getRelValUrl()

def validation._getRelValUrl (   release)
private
Get RelVal download URL for a given release.

Definition at line 452 of file validation.py.

References print().

Referenced by validation.Validation.download().

452 def _getRelValUrl(release):
453  """Get RelVal download URL for a given release."""
454  version_re = re.compile("CMSSW_(?P<X>\d+)_(?P<Y>\d+)")
455  m = version_re.search(release)
456  if not m:
457  raise Exception("Regex %s does not match to release version %s" % (version_re.pattern, release))
458  version = "%s_%s_X" % (m.group("X"), m.group("Y"))
459  if not version in _relvalUrls:
460  print("No RelVal URL for version %s, please update _relvalUrls" % version)
461  sys.exit(1)
462  return _relvalUrls[version]
463 
def _getRelValUrl(release)
Definition: validation.py:452
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ _processPlotsForSample()

def validation._processPlotsForSample (   plotterFolder,
  sample 
)
private

Definition at line 464 of file validation.py.

Referenced by validation.Validation._doFastsimFastVsFullPlots(), validation.Validation._doPhase2PileupPlots(), and _doPlotsForPlotter().

464 def _processPlotsForSample(plotterFolder, sample):
465  if plotterFolder.onlyForPileup() and not sample.pileupEnabled():
466  return False
467  if plotterFolder.onlyForElectron() and not sample.doElectron():
468  return False
469  if plotterFolder.onlyForConversion() and not sample.doConversion():
470  return False
471  if plotterFolder.onlyForBHadron() and not sample.doBHadron():
472  return False
473  return True
474 
def _processPlotsForSample(plotterFolder, sample)
Definition: validation.py:464

◆ _stripRelease()

def validation._stripRelease (   release)
private

Definition at line 353 of file validation.py.

Referenced by validation.Validation._doPlots(), validation.Validation._doPlotsFastFull(), validation.Validation._doPlotsPileup(), and validation.Sample.filename().

353 def _stripRelease(release):
354  for pf in _releasePostfixes:
355  if pf in release:
356  return _stripRelease(release.replace(pf, ""))
357  return release
358 
359 
def _stripRelease(release)
Definition: validation.py:353

Variable Documentation

◆ _doBHadronSamples

validation._doBHadronSamples
private

Definition at line 448 of file validation.py.

◆ _doConversionSamples

validation._doConversionSamples
private

Definition at line 444 of file validation.py.

◆ _doElectronSamples

validation._doElectronSamples
private

Definition at line 439 of file validation.py.

◆ _globalTags

validation._globalTags
private

Definition at line 19 of file validation.py.

◆ _releasePostfixes

validation._releasePostfixes
private

Definition at line 351 of file validation.py.

◆ _relvalUrls

validation._relvalUrls
private

Definition at line 420 of file validation.py.

◆ IgnoreCommandLineOptions

validation.IgnoreCommandLineOptions

Definition at line 13 of file validation.py.