CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions
LumiList.LumiList Class Reference
Inheritance diagram for LumiList.LumiList:

Public Member Functions

def __add__ (self, other)
 
def __and__ (self, other)
 
def __contains__ (self, runTuple)
 
def __init__ (self, filename=None, lumis=None, runsAndLumis=None, runs=None, compactList=None, url=None)
 
def __len__ (self)
 
def __or__ (self, other)
 
def __str__ (self)
 
def __sub__ (self, other)
 
def contains (self, run, lumiSection=None)
 
def filterLumis (self, lumiList)
 
def getCMSSWString (self)
 
def getCompactList (self)
 
def getDuplicates (self)
 
def getLumis (self)
 
def getRuns (self)
 
def getVLuminosityBlockRange (self, tracked=False)
 
def removeRuns (self, runList)
 
def selectRuns (self, runList)
 
def writeJSON (self, fileName)
 

Public Attributes

 compactList
 
 duplicates
 
 filename
 
 url
 

Private Member Functions

def _getLumiParts (self)
 

Detailed Description

Deal with lists of lumis in several different forms:
Compact list:
    {
    '1': [[1, 33], [35, 35], [37, 47], [49, 75], [77, 130], [133, 136]],
    '2':[[1,45],[50,80]]
    }
    where the first key is the run number, subsequent pairs are
    ranges of lumis within that run that are desired
Runs and lumis:
    {
    '1': [1,2,3,4,6,7,8,9,10],
    '2': [1,4,5,20]
    }
    where the first key is the run number and the list is a list of
    individual lumi sections. This form also takes a list of these objects
    which can be much faster than LumiList += LumiList
Run  lumi pairs:
    [[1,1], [1,2],[1,4], [2,1], [2,5], [1,10]]
    where each pair in the list is an individual run&lumi
CMSSW representation:
    '1:1-1:33,1:35,1:37-1:47,2:1-2:45,2:50-2:80'
    The string used by CMSSW in lumisToProcess or lumisToSkip
    is a subset of the compactList example above

Definition at line 22 of file LumiList.py.

Constructor & Destructor Documentation

◆ __init__()

def LumiList.LumiList.__init__ (   self,
  filename = None,
  lumis = None,
  runsAndLumis = None,
  runs = None,
  compactList = None,
  url = None 
)
Constructor takes filename (JSON), a list of run/lumi pairs,
or a dict with run #'s as the keys and a list of lumis as the values, or just a list of runs

Definition at line 50 of file LumiList.py.

50  def __init__(self, filename = None, lumis = None, runsAndLumis = None, runs = None, compactList = None, url = None):
51  """
52  Constructor takes filename (JSON), a list of run/lumi pairs,
53  or a dict with run #'s as the keys and a list of lumis as the values, or just a list of runs
54  """
55  self.compactList = {}
56  self.duplicates = {}
57  if filename:
58  self.filename = filename
59  jsonFile = open(self.filename,'r')
60  self.compactList = json.load(jsonFile)
61  elif url:
62  self.url = url
63  jsonFile = urlopen(url)
64  self.compactList = json.load(jsonFile)
65  elif lumis:
66  runsAndLumis = {}
67  for (run, lumi) in lumis:
68  run = str(run)
69  if run not in runsAndLumis:
70  runsAndLumis[run] = []
71  runsAndLumis[run].append(lumi)
72 
73  if isinstance(runsAndLumis, list):
74  queued = {}
75  for runLumiList in runsAndLumis:
76  for run, lumis in runLumiList.items():
77  queued.setdefault(run, []).extend(lumis)
78  runsAndLumis = queued
79 
80  if runsAndLumis:
81  for run in runsAndLumis.keys():
82  runString = str(run)
83  lastLumi = -1000
84  lumiList = runsAndLumis[run]
85  if lumiList:
86  self.compactList[runString] = []
87  self.duplicates[runString] = []
88  for lumi in sorted(lumiList):
89  if lumi == lastLumi:
90  self.duplicates[runString].append(lumi)
91  elif lumi != lastLumi + 1: # Break in lumi sequence
92  self.compactList[runString].append([lumi, lumi])
93  else:
94  nRange = len(self.compactList[runString])
95  self.compactList[runString][nRange-1][1] = lumi
96  lastLumi = lumi
97  if runs:
98  for run in runs:
99  runString = str(run)
100  self.compactList[runString] = [[1, 0xFFFFFFF]]
101 
102  if compactList:
103  for run in compactList.keys():
104  runString = str(run)
105  if compactList[run]:
106  self.compactList[runString] = compactList[run]
107 
108  # Compact each run and make it unique
109 
110  for run in self.compactList.keys():
111  newLumis = []
112  for lumi in sorted(self.compactList[run]):
113  # If the next lumi starts inside or just after the last just change the endpoint of the first
114  if newLumis and newLumis[-1][0] <= lumi[0] <= newLumis[-1][1] + 1:
115  newLumis[-1][1] = max(newLumis[-1][1], lumi[1])
116  else:
117  newLumis.append(lumi)
118  self.compactList[run] = newLumis
119 

Member Function Documentation

◆ __add__()

def LumiList.LumiList.__add__ (   self,
  other 
)

Definition at line 196 of file LumiList.py.

196  def __add__(self, other):
197  # + is the same as |
198  return self.__or__(other)
199 

References GlobalTag.GlobalTag.__or__(), SequenceTypes._BooleanLogicSequenceable.__or__(), LumiList.LumiList.__or__(), Config._BoolModifierBase.__or__(), and Config.Modifier.__or__().

Referenced by counter.Counter.__iadd__(), and average.Average.__iadd__().

◆ __and__()

def LumiList.LumiList.__and__ (   self,
  other 
)

Definition at line 148 of file LumiList.py.

148  def __and__(self, other): # Things in both
149  result = {}
150  aruns = set(self.compactList.keys())
151  bruns = set(other.compactList.keys())
152  for run in aruns & bruns:
153  lumiList = [] # List for this run
154  unique = [] # List for this run
155  for alumi in self.compactList[run]:
156  for blumi in other.compactList[run]:
157  if blumi[0] <= alumi[0] and blumi[1] >= alumi[1]: # blumi has all of alumi
158  lumiList.append(alumi)
159  if blumi[0] > alumi[0] and blumi[1] < alumi[1]: # blumi is part of alumi
160  lumiList.append(blumi)
161  elif blumi[0] <= alumi[0] and blumi[1] < alumi[1] and blumi[1] >= alumi[0]: # overlaps start
162  lumiList.append([alumi[0], blumi[1]])
163  elif blumi[0] > alumi[0] and blumi[1] >= alumi[1] and blumi[0] <= alumi[1]: # overlaps end
164  lumiList.append([blumi[0], alumi[1]])
165 
166 
167  if lumiList:
168  unique = [copy.deepcopy(lumiList[0])]
169  for pair in lumiList[1:]:
170  if pair[0] == unique[-1][1]+1:
171  unique[-1][1] = copy.deepcopy(pair[1])
172  else:
173  unique.append(copy.deepcopy(pair))
174 
175  result[run] = unique
176  return LumiList(compactList = result)
177 
178 

References LumiList.LumiList.compactList, and relativeConstraints.keys.

◆ __contains__()

def LumiList.LumiList.__contains__ (   self,
  runTuple 
)

Definition at line 377 of file LumiList.py.

377  def __contains__ (self, runTuple):
378  return self.contains (runTuple)
379 
380 
381 
382 '''
383 # Unit test code
384 import unittest
385 import FWCore.ParameterSet.Config as cms
386 
387 class LumiListTest(unittest.TestCase):
388  """
389  _LumiListTest_
390 
391  """
392 
393  def testRead(self):
394  """
395  Test reading from JSON
396  """
397  exString = "1:1-1:33,1:35,1:37-1:47,2:49-2:75,2:77-2:130,2:133-2:136"
398  exDict = {'1': [[1, 33], [35, 35], [37, 47]],
399  '2': [[49, 75], [77, 130], [133, 136]]}
400  exVLBR = cms.VLuminosityBlockRange('1:1-1:33', '1:35', '1:37-1:47', '2:49-2:75', '2:77-2:130', '2:133-2:136')
401 
402  jsonList = LumiList(filename = 'lumiTest.json')
403  lumiString = jsonList.getCMSSWString()
404  lumiList = jsonList.getCompactList()
405  lumiVLBR = jsonList.getVLuminosityBlockRange(True)
406 
407  self.assertTrue(lumiString == exString)
408  self.assertTrue(lumiList == exDict)
409  self.assertTrue(lumiVLBR == exVLBR)
410 
411  def testList(self):
412  """
413  Test constucting from list of pairs
414  """
415 
416  listLs1 = range(1, 34) + [35] + range(37, 48)
417  listLs2 = range(49, 76) + range(77, 131) + range(133, 137)
418  lumis = zip([1]*100, listLs1) + zip([2]*100, listLs2)
419 
420  jsonLister = LumiList(filename = 'lumiTest.json')
421  jsonString = jsonLister.getCMSSWString()
422  jsonList = jsonLister.getCompactList()
423 
424  pairLister = LumiList(lumis = lumis)
425  pairString = pairLister.getCMSSWString()
426  pairList = pairLister.getCompactList()
427 
428  self.assertTrue(jsonString == pairString)
429  self.assertTrue(jsonList == pairList)
430 
431 
432  def testRuns(self):
433  """
434  Test constucting from run and list of lumis
435  """
436  runsAndLumis = {
437  1: range(1, 34) + [35] + range(37, 48),
438  2: range(49, 76) + range(77, 131) + range(133, 137)
439  }
440  runsAndLumis2 = {
441  '1': range(1, 34) + [35] + range(37, 48),
442  '2': range(49, 76) + range(77, 131) + range(133, 137)
443  }
444  blank = {
445  '1': [],
446  '2': []
447  }
448 
449  jsonLister = LumiList(filename = 'lumiTest.json')
450  jsonString = jsonLister.getCMSSWString()
451  jsonList = jsonLister.getCompactList()
452 
453  runLister = LumiList(runsAndLumis = runsAndLumis)
454  runString = runLister.getCMSSWString()
455  runList = runLister.getCompactList()
456 
457  runLister2 = LumiList(runsAndLumis = runsAndLumis2)
458  runList2 = runLister2.getCompactList()
459 
460  runLister3 = LumiList(runsAndLumis = blank)
461 
462 
463  self.assertTrue(jsonString == runString)
464  self.assertTrue(jsonList == runList)
465  self.assertTrue(runList2 == runList)
466  self.assertTrue(len(runLister3) == 0)
467 
468  def testFilter(self):
469  """
470  Test filtering of a list of lumis
471  """
472  runsAndLumis = {
473  1: range(1, 34) + [35] + range(37, 48),
474  2: range(49, 76) + range(77, 131) + range(133, 137)
475  }
476 
477  completeList = zip([1]*150, range(1, 150)) + \
478  zip([2]*150, range(1, 150)) + \
479  zip([3]*150, range(1, 150))
480 
481  smallList = zip([1]*50, range(1, 10)) + zip([2]*50, range(50, 70))
482  overlapList = zip([1]*150, range(30, 40)) + \
483  zip([2]*150, range(60, 80))
484  overlapRes = zip([1]*9, range(30, 34)) + [(1, 35)] + \
485  zip([1]*9, range(37, 40)) + \
486  zip([2]*30, range(60, 76)) + \
487  zip([2]*9, range(77, 80))
488 
489  runLister = LumiList(runsAndLumis = runsAndLumis)
490 
491  # Test a list to be filtered which is a superset of constructed list
492  filterComplete = runLister.filterLumis(completeList)
493  # Test a list to be filtered which is a subset of constructed list
494  filterSmall = runLister.filterLumis(smallList)
495  # Test a list to be filtered which is neither
496  filterOverlap = runLister.filterLumis(overlapList)
497 
498  self.assertTrue(filterComplete == runLister.getLumis())
499  self.assertTrue(filterSmall == smallList)
500  self.assertTrue(filterOverlap == overlapRes)
501 
502  def testDuplicates(self):
503  """
504  Test a list with lots of duplicates
505  """
506  result = zip([1]*100, range(1, 34) + range(37, 48))
507  lumis = zip([1]*100, range(1, 34) + range(37, 48) + range(5, 25))
508 
509  lister = LumiList(lumis = lumis)
510  self.assertTrue(lister.getLumis() == result)
511 
512  def testNull(self):
513  """
514  Test a null list
515  """
516 
517  runLister = LumiList(lumis = None)
518 
519  self.assertTrue(runLister.getCMSSWString() == '')
520  self.assertTrue(runLister.getLumis() == [])
521  self.assertTrue(runLister.getCompactList() == {})
522 
523  def testSubtract(self):
524  """
525  a-b for lots of cases
526  """
527 
528  alumis = {'1' : range(2,20) + range(31,39) + range(45,49),
529  '2' : range(6,20) + range (30,40),
530  '3' : range(10,20) + range (30,40) + range(50,60),
531  }
532  blumis = {'1' : range(1,6) + range(12,13) + range(16,30) + range(40,50) + range(33,36),
533  '2' : range(10,35),
534  '3' : range(10,15) + range(35,40) + range(45,51) + range(59,70),
535  }
536  clumis = {'1' : range(1,6) + range(12,13) + range(16,30) + range(40,50) + range(33,36),
537  '2' : range(10,35),
538  }
539  result = {'1' : range(6,12) + range(13,16) + range(31,33) + range(36,39),
540  '2' : range(6,10) + range(35,40),
541  '3' : range(15,20) + range(30,35) + range(51,59),
542  }
543  result2 = {'1' : range(6,12) + range(13,16) + range(31,33) + range(36,39),
544  '2' : range(6,10) + range(35,40),
545  '3' : range(10,20) + range (30,40) + range(50,60),
546  }
547  a = LumiList(runsAndLumis = alumis)
548  b = LumiList(runsAndLumis = blumis)
549  c = LumiList(runsAndLumis = clumis)
550  r = LumiList(runsAndLumis = result)
551  r2 = LumiList(runsAndLumis = result2)
552 
553  self.assertTrue((a-b).getCMSSWString() == r.getCMSSWString())
554  self.assertTrue((a-b).getCMSSWString() != (b-a).getCMSSWString())
555  # Test where c is missing runs from a
556  self.assertTrue((a-c).getCMSSWString() == r2.getCMSSWString())
557  self.assertTrue((a-c).getCMSSWString() != (c-a).getCMSSWString())
558  # Test empty lists
559  self.assertTrue(str(a-a) == '{}')
560  self.assertTrue(len(a-a) == 0)
561 
562  def testOr(self):
563  """
564  a|b for lots of cases
565  """
566 
567  alumis = {'1' : range(2,20) + range(31,39) + range(45,49),
568  '2' : range(6,20) + range (30,40),
569  '3' : range(10,20) + range (30,40) + range(50,60),
570  }
571  blumis = {'1' : range(1,6) + range(12,13) + range(16,30) + range(40,50) + range(39,80),
572  '2' : range(10,35),
573  '3' : range(10,15) + range(35,40) + range(45,51) + range(59,70),
574  }
575  clumis = {'1' : range(1,6) + range(12,13) + range(16,30) + range(40,50) + range(39,80),
576  '2' : range(10,35),
577  }
578  result = {'1' : range(2,20) + range(31,39) + range(45,49) + range(1,6) + range(12,13) + range(16,30) + range(40,50) + range(39,80),
579  '2' : range(6,20) + range (30,40) + range(10,35),
580  '3' : range(10,20) + range (30,40) + range(50,60) + range(10,15) + range(35,40) + range(45,51) + range(59,70),
581  }
582  a = LumiList(runsAndLumis = alumis)
583  b = LumiList(runsAndLumis = blumis)
584  c = LumiList(runsAndLumis = blumis)
585  r = LumiList(runsAndLumis = result)
586  self.assertTrue((a|b).getCMSSWString() == r.getCMSSWString())
587  self.assertTrue((a|b).getCMSSWString() == (b|a).getCMSSWString())
588  self.assertTrue((a|b).getCMSSWString() == (a+b).getCMSSWString())
589 
590  # Test list constuction (faster)
591 
592  multiple = [alumis, blumis, clumis]
593  easy = LumiList(runsAndLumis = multiple)
594  hard = a + b
595  hard += c
596  self.assertTrue(hard.getCMSSWString() == easy.getCMSSWString())
597 
598  def testAnd(self):
599  """
600  a&b for lots of cases
601  """
602 
603  alumis = {'1' : range(2,20) + range(31,39) + range(45,49),
604  '2' : range(6,20) + range (30,40),
605  '3' : range(10,20) + range (30,40) + range(50,60),
606  '4' : range(1,100),
607  }
608  blumis = {'1' : range(1,6) + range(12,13) + range(16,25) + range(25,40) + range(40,50) + range(33,36),
609  '2' : range(10,35),
610  '3' : range(10,15) + range(35,40) + range(45,51) + range(59,70),
611  '5' : range(1,100),
612  }
613  result = {'1' : range(2,6) + range(12,13) + range(16,20) + range(31,39) + range(45,49),
614  '2' : range(10,20) + range(30,35),
615  '3' : range(10,15) + range(35,40) + range(50,51)+ range(59,60),
616  }
617  a = LumiList(runsAndLumis = alumis)
618  b = LumiList(runsAndLumis = blumis)
619  r = LumiList(runsAndLumis = result)
620  self.assertTrue((a&b).getCMSSWString() == r.getCMSSWString())
621  self.assertTrue((a&b).getCMSSWString() == (b&a).getCMSSWString())
622  self.assertTrue((a|b).getCMSSWString() != r.getCMSSWString())
623 
624  def testRemoveSelect(self):
625  """
626  a-b for lots of cases
627  """
628 
629  alumis = {'1' : range(2,20) + range(31,39) + range(45,49),
630  '2' : range(6,20) + range (30,40),
631  '3' : range(10,20) + range (30,40) + range(50,60),
632  '4' : range(10,20) + range (30,80),
633  }
634 
635  result = {'2' : range(6,20) + range (30,40),
636  '4' : range(10,20) + range (30,80),
637  }
638 
639  rem = LumiList(runsAndLumis = alumis)
640  sel = LumiList(runsAndLumis = alumis)
641  res = LumiList(runsAndLumis = result)
642 
643  rem.removeRuns([1,3])
644  sel.selectRuns([2,4])
645 
646  self.assertTrue(rem.getCMSSWString() == res.getCMSSWString())
647  self.assertTrue(sel.getCMSSWString() == res.getCMSSWString())
648  self.assertTrue(sel.getCMSSWString() == rem.getCMSSWString())
649 
650  def testURL(self):
651  URL = 'https://cms-service-dqm.web.cern.ch/cms-service-dqm/CAF/certification/Collisions12/8TeV/Reprocessing/Cert_190456-195530_8TeV_08Jun2012ReReco_Collisions12_JSON.txt'
652  ll = LumiList(url=URL)
653  self.assertTrue(len(ll) > 0)
654 
655 
656  def testWrite(self):
657  alumis = {'1' : range(2,20) + range(31,39) + range(45,49),
658  '2' : range(6,20) + range (30,40),
659  '3' : range(10,20) + range (30,40) + range(50,60),
660  '4' : range(1,100),
661  }
662  a = LumiList(runsAndLumis = alumis)
663  a.writeJSON('newFile.json')
664 
665 
666 if __name__ == '__main__':
667  jsonFile = open('lumiTest.json','w')
668  jsonFile.write('{"1": [[1, 33], [35, 35], [37, 47]], "2": [[49, 75], [77, 130], [133, 136]]}')
669  jsonFile.close()
670  unittest.main()
671 '''
672 # Test JSON file
673 
674 #{"1": [[1, 33], [35, 35], [37, 47]], "2": [[49, 75], [77, 130], [133, 136]]}
675 

References edm::Association< C >.contains(), edm::eventsetup::DataProxyProvider::KeyedProxies.contains(), edm::helper::IndexRangeAssociation.contains(), edm::ThinnedRefSet< C >.contains(), FWGeometry.contains(), edm::ValueMap< T >.contains(), edm::MultiAssociation< C >.contains(), PhysicsTools::Calibration::MVAComputerContainer.contains(), LumiList.LumiList.contains(), SequenceTypes._ModuleSequenceType.contains(), SequenceTypes.Schedule.contains(), and SequenceTypes.Task.contains().

◆ __len__()

def LumiList.LumiList.__len__ (   self)
Returns number of runs in list

Definition at line 200 of file LumiList.py.

200  def __len__(self):
201  '''Returns number of runs in list'''
202  return len(self.compactList)
203 

References LumiList.LumiList.compactList.

◆ __or__()

def LumiList.LumiList.__or__ (   self,
  other 
)

Definition at line 179 of file LumiList.py.

179  def __or__(self, other):
180  result = {}
181  aruns = self.compactList.keys()
182  bruns = other.compactList.keys()
183  runs = set(aruns + bruns)
184  for run in runs:
185  overlap = sorted(self.compactList.get(run, []) + other.compactList.get(run, []))
186  unique = [copy.deepcopy(overlap[0])]
187  for pair in overlap[1:]:
188  if pair[0] >= unique[-1][0] and pair[0] <= unique[-1][1]+1 and pair[1] > unique[-1][1]:
189  unique[-1][1] = copy.deepcopy(pair[1])
190  elif pair[0] > unique[-1][1]:
191  unique.append(copy.deepcopy(pair))
192  result[run] = unique
193  return LumiList(compactList = result)
194 
195 

References LumiList.LumiList.compactList, and relativeConstraints.keys.

Referenced by LumiList.LumiList.__add__().

◆ __str__()

def LumiList.LumiList.__str__ (   self)

Definition at line 220 of file LumiList.py.

220  def __str__ (self):
221  doubleBracketRE = re.compile (r']],')
222  return doubleBracketRE.sub (']],\n',
223  json.dumps (self.compactList,
224  sort_keys=True))
225 

References LumiList.LumiList.compactList.

◆ __sub__()

def LumiList.LumiList.__sub__ (   self,
  other 
)

Definition at line 120 of file LumiList.py.

120  def __sub__(self, other): # Things from self not in other
121  result = {}
122  for run in sorted(self.compactList.keys()):
123  alumis = sorted(self.compactList[run])
124  blumis = sorted(other.compactList.get(run, []))
125  alist = [] # verified part
126  for alumi in alumis:
127  tmplist = [alumi[0], alumi[1]] # may be part
128  for blumi in blumis:
129  if blumi[0] <= tmplist[0] and blumi[1] >= tmplist[1]: # blumi has all of alumi
130  tmplist = []
131  break # blumi is has all of alumi
132  if blumi[0] > tmplist[0] and blumi[1] < tmplist[1]: # blumi is part of alumi
133  alist.append([tmplist[0], blumi[0]-1])
134  tmplist = [blumi[1]+1, tmplist[1]]
135  elif blumi[0] <= tmplist[0] and blumi[1] < tmplist[1] and blumi[1]>=tmplist[0]: # overlaps start
136  tmplist = [blumi[1]+1, tmplist[1]]
137  elif blumi[0] > tmplist[0] and blumi[1] >= tmplist[1] and blumi[0]<=tmplist[1]: # overlaps end
138  alist.append([tmplist[0], blumi[0]-1])
139  tmplist = []
140  break
141  if tmplist:
142  alist.append(tmplist)
143  result[run] = alist
144 
145  return LumiList(compactList = result)
146 
147 

References LumiList.LumiList.compactList, and relativeConstraints.keys.

◆ _getLumiParts()

def LumiList.LumiList._getLumiParts (   self)
private
Turn compactList into a list of the format
[ 'R1:L1', 'R2:L2-R2:L3' ] which is used by getCMSSWString and getVLuminosityBlockRange

Definition at line 263 of file LumiList.py.

263  def _getLumiParts(self):
264  """
265  Turn compactList into a list of the format
266  [ 'R1:L1', 'R2:L2-R2:L3' ] which is used by getCMSSWString and getVLuminosityBlockRange
267  """
268 
269  parts = []
270  runs = self.compactList.keys()
271  runs = sorted(runs, key=int)
272  for run in runs:
273  lumis = self.compactList[run]
274  for lumiPair in sorted(lumis):
275  if lumiPair[0] == lumiPair[1]:
276  parts.append(str("%s:%s" % (run, lumiPair[0])))
277  else:
278  parts.append(str("%s:%s-%s:%s" %
279  (run, lumiPair[0], run, lumiPair[1])))
280  return parts
281 
282 

References LumiList.LumiList.compactList, relativeConstraints.keys, and str.

Referenced by LumiList.LumiList.getCMSSWString(), and LumiList.LumiList.getVLuminosityBlockRange().

◆ contains()

def LumiList.LumiList.contains (   self,
  run,
  lumiSection = None 
)
returns true if the run, lumi section passed in is contained
in this lumiList.  Input can be either:
- a single tuple of (run, lumi),
- separate run and lumi numbers
- a single run number (returns true if any lumi sections exist)

Definition at line 342 of file LumiList.py.

342  def contains (self, run, lumiSection = None):
343  '''
344  returns true if the run, lumi section passed in is contained
345  in this lumiList. Input can be either:
346  - a single tuple of (run, lumi),
347  - separate run and lumi numbers
348  - a single run number (returns true if any lumi sections exist)
349  '''
350  if lumiSection is None:
351  # if this is an integer or a string, see if the run exists
352  if isinstance (run, int) or isinstance (run, str):
353  return str(run) in self.compactList
354  # if we're here, then run better be a tuple or list
355  try:
356  lumiSection = run[1]
357  run = run[0]
358  except:
359  raise RuntimeError("Improper format for run '%s'" % run)
360  lumiRangeList = self.compactList.get( str(run) )
361  if not lumiRangeList:
362  # the run isn't there, so no need to look any further
363  return False
364  for lumiRange in lumiRangeList:
365  # we want to make this as found if either the lumiSection
366  # is inside the range OR if the lumi section is greater
367  # than or equal to the lower bound of the lumi range and
368  # the upper bound is 0 (which means extends to the end of
369  # the run)
370  if lumiRange[0] <= lumiSection and \
371  (0 == lumiRange[1] or lumiSection <= lumiRange[1]):
372  # got it
373  return True
374  return False
375 
376 

References LumiList.LumiList.compactList, and str.

Referenced by LumiList.LumiList.__contains__().

◆ filterLumis()

def LumiList.LumiList.filterLumis (   self,
  lumiList 
)
Return a list of lumis that are in compactList.
lumilist is of the simple form
[(run1,lumi1),(run1,lumi2),(run2,lumi1)]

Definition at line 204 of file LumiList.py.

204  def filterLumis(self, lumiList):
205  """
206  Return a list of lumis that are in compactList.
207  lumilist is of the simple form
208  [(run1,lumi1),(run1,lumi2),(run2,lumi1)]
209  """
210  filteredList = []
211  for (run, lumi) in lumiList:
212  runsInLumi = self.compactList.get(str(run), [[0, -1]])
213  for (first, last) in runsInLumi:
214  if lumi >= first and lumi <= last:
215  filteredList.append((run, lumi))
216  break
217  return filteredList
218 
219 

References LumiList.LumiList.compactList, and str.

◆ getCMSSWString()

def LumiList.LumiList.getCMSSWString (   self)
Turn compactList into a list of the format
R1:L1,R2:L2-R2:L3 which is acceptable to CMSSW LumiBlockRange variable

Definition at line 283 of file LumiList.py.

283  def getCMSSWString(self):
284  """
285  Turn compactList into a list of the format
286  R1:L1,R2:L2-R2:L3 which is acceptable to CMSSW LumiBlockRange variable
287  """
288 
289  parts = self._getLumiParts()
290  output = ','.join(parts)
291  return str(output)
292 
293 

References LumiList.LumiList._getLumiParts(), join(), and str.

◆ getCompactList()

def LumiList.LumiList.getCompactList (   self)
Return the compact list representation

Definition at line 226 of file LumiList.py.

226  def getCompactList(self):
227  """
228  Return the compact list representation
229  """
230  return self.compactList
231 
232 

References LumiList.LumiList.compactList.

◆ getDuplicates()

def LumiList.LumiList.getDuplicates (   self)
Return the list of duplicates found during construction as a LumiList

Definition at line 233 of file LumiList.py.

233  def getDuplicates(self):
234  """
235  Return the list of duplicates found during construction as a LumiList
236  """
237  return LumiList(runsAndLumis = self.duplicates)
238 
239 

References LumiList.LumiList.duplicates.

◆ getLumis()

def LumiList.LumiList.getLumis (   self)
Return the list of pairs representation

Definition at line 240 of file LumiList.py.

240  def getLumis(self):
241  """
242  Return the list of pairs representation
243  """
244  theList = []
245  runs = self.compactList.keys()
246  runs = sorted(run, key=int)
247  for run in runs:
248  lumis = self.compactList[run]
249  for lumiPair in sorted(lumis):
250  for lumi in range(lumiPair[0], lumiPair[1]+1):
251  theList.append((int(run), lumi))
252 
253  return theList
254 
255 

References LumiList.LumiList.compactList, createfilelist.int, relativeConstraints.keys, and FastTimerService_cff.range.

◆ getRuns()

def LumiList.LumiList.getRuns (   self)
return the sorted list of runs contained

Definition at line 256 of file LumiList.py.

256  def getRuns(self):
257  '''
258  return the sorted list of runs contained
259  '''
260  return sorted (self.compactList.keys())
261 
262 

References LumiList.LumiList.compactList, and relativeConstraints.keys.

◆ getVLuminosityBlockRange()

def LumiList.LumiList.getVLuminosityBlockRange (   self,
  tracked = False 
)
Turn compactList into an (optionally tracked) VLuminosityBlockRange

Definition at line 294 of file LumiList.py.

294  def getVLuminosityBlockRange(self, tracked = False):
295  """
296  Turn compactList into an (optionally tracked) VLuminosityBlockRange
297  """
298 
299  import FWCore.ParameterSet.Config as cms
300  parts = self._getLumiParts()
301  if tracked:
302  return cms.VLuminosityBlockRange(parts)
303  else:
304  return cms.untracked.VLuminosityBlockRange(parts)
305 
306 

References LumiList.LumiList._getLumiParts().

◆ removeRuns()

def LumiList.LumiList.removeRuns (   self,
  runList 
)
removes runs from runList from collection

Definition at line 316 of file LumiList.py.

316  def removeRuns (self, runList):
317  '''
318  removes runs from runList from collection
319  '''
320  for run in runList:
321  run = str(run)
322  if run in self.compactList:
323  del self.compactList[run]
324 
325  return
326 
327 

References LumiList.LumiList.compactList, and str.

◆ selectRuns()

def LumiList.LumiList.selectRuns (   self,
  runList 
)
Selects only runs from runList in collection

Definition at line 328 of file LumiList.py.

328  def selectRuns (self, runList):
329  '''
330  Selects only runs from runList in collection
331  '''
332  runsToDelete = []
333  for run in self.compactList.keys():
334  if int(run) not in runList and run not in runList:
335  runsToDelete.append(run)
336 
337  for run in runsToDelete:
338  del self.compactList[run]
339 
340  return
341 

References LumiList.LumiList.compactList, createfilelist.int, and relativeConstraints.keys.

◆ writeJSON()

def LumiList.LumiList.writeJSON (   self,
  fileName 
)
Write out a JSON file representation of the object

Definition at line 307 of file LumiList.py.

307  def writeJSON(self, fileName):
308  """
309  Write out a JSON file representation of the object
310  """
311  jsonFile = open(fileName,'w')
312  jsonFile.write("%s\n" % self)
313  jsonFile.close()
314 
315 

Member Data Documentation

◆ compactList

LumiList.LumiList.compactList

◆ duplicates

LumiList.LumiList.duplicates

◆ filename

LumiList.LumiList.filename

Definition at line 58 of file LumiList.py.

Referenced by python.rootplot.rootmath.Target.__repr__(), and utils.unpickler.run().

◆ url

LumiList.LumiList.url

Definition at line 62 of file LumiList.py.

Referenced by rrapi.RRApi.get().

FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
LumiList
Definition: LumiList.py:1
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
str
#define str(s)
Definition: TestProcessor.cc:52
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
mps_setup.append
append
Definition: mps_setup.py:85
createfilelist.int
int
Definition: createfilelist.py:10
TriggerAnalyzer.__str__
def __str__(self)
Definition: TriggerAnalyzer.py:103
edm::contains
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37