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 1166 of file validation.py.

Referenced by _copySubDir().

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

◆ _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 1131 of file validation.py.

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

Referenced by validation.Validation._doPlots().

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

◆ _doPlotsForPlotter()

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

Definition at line 1190 of file validation.py.

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

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

◆ _findDuplicates()

def validation._findDuplicates (   lst)
private

Definition at line 1180 of file validation.py.

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

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

◆ _getGlobalTag()

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

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

Definition at line 361 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().

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

References print().

Referenced by validation.Validation.download().

453 def _getRelValUrl(release):
454  """Get RelVal download URL for a given release."""
455  version_re = re.compile("CMSSW_(?P<X>\d+)_(?P<Y>\d+)")
456  m = version_re.search(release)
457  if not m:
458  raise Exception("Regex %s does not match to release version %s" % (version_re.pattern, release))
459  version = "%s_%s_X" % (m.group("X"), m.group("Y"))
460  if not version in _relvalUrls:
461  print("No RelVal URL for version %s, please update _relvalUrls" % version)
462  sys.exit(1)
463  return _relvalUrls[version]
464 
def _getRelValUrl(release)
Definition: validation.py:453
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 465 of file validation.py.

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

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

◆ _stripRelease()

def validation._stripRelease (   release)
private

Definition at line 354 of file validation.py.

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

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

Variable Documentation

◆ _doBHadronSamples

validation._doBHadronSamples
private

Definition at line 449 of file validation.py.

◆ _doConversionSamples

validation._doConversionSamples
private

Definition at line 445 of file validation.py.

◆ _doElectronSamples

validation._doElectronSamples
private

Definition at line 440 of file validation.py.

◆ _globalTags

validation._globalTags
private

Definition at line 20 of file validation.py.

◆ _releasePostfixes

validation._releasePostfixes
private

Definition at line 352 of file validation.py.

◆ _relvalUrls

validation._relvalUrls
private

Definition at line 421 of file validation.py.

◆ IgnoreCommandLineOptions

validation.IgnoreCommandLineOptions

Definition at line 14 of file validation.py.