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') self.compactList = json.load(jsonFile)
60  elif url:
61  self.url = url
62  jsonFile = urlopen(url)
63  self.compactList = json.load(jsonFile)
64  elif lumis:
65  runsAndLumis = {}
66  for (run, lumi) in lumis:
67  run = str(run)
68  if run not in runsAndLumis:
69  runsAndLumis[run] = []
70  runsAndLumis[run].append(lumi)
71 
72  if isinstance(runsAndLumis, list):
73  queued = {}
74  for runLumiList in runsAndLumis:
75  for run, lumis in runLumiList.items():
76  queued.setdefault(run, []).extend(lumis)
77  runsAndLumis = queued
78 
79  if runsAndLumis:
80  for run in runsAndLumis.keys():
81  runString = str(run)
82  lastLumi = -1000
83  lumiList = runsAndLumis[run]
84  if lumiList:
85  self.compactList[runString] = []
86  self.duplicates[runString] = []
87  for lumi in sorted(lumiList):
88  if lumi == lastLumi:
89  self.duplicates[runString].append(lumi)
90  elif lumi != lastLumi + 1: # Break in lumi sequence
91  self.compactList[runString].append([lumi, lumi])
92  else:
93  nRange = len(self.compactList[runString])
94  self.compactList[runString][nRange-1][1] = lumi
95  lastLumi = lumi
96  if runs:
97  for run in runs:
98  runString = str(run)
99  self.compactList[runString] = [[1, 0xFFFFFFF]]
100 
101  if compactList:
102  for run in compactList.keys():
103  runString = str(run)
104  if compactList[run]:
105  self.compactList[runString] = compactList[run]
106 
107  # Compact each run and make it unique
108 
109  for run in self.compactList.keys():
110  newLumis = []
111  for lumi in sorted(self.compactList[run]):
112  # If the next lumi starts inside or just after the last just change the endpoint of the first
113  if isinstance(lumi, int):
114  newLumis.append(lumi)
115  else:
116  if newLumis and newLumis[-1][0] <= lumi[0] <= newLumis[-1][1] + 1:
117  newLumis[-1][1] = max(newLumis[-1][1], lumi[1])
118  else:
119  newLumis.append(lumi)
120  self.compactList[run] = newLumis
121 
122 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
#define str(s)

Member Function Documentation

◆ __add__()

def LumiList.LumiList.__add__ (   self,
  other 
)

Definition at line 199 of file LumiList.py.

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__().

199  def __add__(self, other):
200  # + is the same as |
201  return self.__or__(other)
202 

◆ __and__()

def LumiList.LumiList.__and__ (   self,
  other 
)

Definition at line 151 of file LumiList.py.

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

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

◆ __contains__()

def LumiList.LumiList.__contains__ (   self,
  runTuple 
)

Definition at line 383 of file LumiList.py.

References edm::Association< C >.contains(), edm::eventsetup::DataProxyProvider::KeyedProxies.contains(), edm::helper::IndexRangeAssociation.contains(), edm::ThinnedRefSet< C >.contains(), l1ct::PFRegionEmu.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._TaskBase.contains().

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

◆ __len__()

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

Definition at line 203 of file LumiList.py.

References LumiList.LumiList.compactList.

203  def __len__(self):
204  '''Returns number of runs in list'''
205  return len(self.compactList)
206 

◆ __or__()

def LumiList.LumiList.__or__ (   self,
  other 
)

Definition at line 182 of file LumiList.py.

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

Referenced by LumiList.LumiList.__add__().

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

◆ __str__()

def LumiList.LumiList.__str__ (   self)

Definition at line 223 of file LumiList.py.

References LumiList.LumiList.compactList.

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

◆ __sub__()

def LumiList.LumiList.__sub__ (   self,
  other 
)

Definition at line 123 of file LumiList.py.

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

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

◆ _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 266 of file LumiList.py.

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

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

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

◆ 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 348 of file LumiList.py.

References LumiList.LumiList.compactList, and str.

Referenced by LumiList.LumiList.__contains__().

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

◆ 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 207 of file LumiList.py.

References LumiList.LumiList.compactList, and str.

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

◆ 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 289 of file LumiList.py.

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

289  def getCMSSWString(self):
290  """
291  Turn compactList into a list of the format
292  R1:L1,R2:L2-R2:L3 which is acceptable to CMSSW LumiBlockRange variable
293  """
294 
295  parts = self._getLumiParts()
296  output = ','.join(parts)
297  return str(output)
298 
299 
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define str(s)

◆ getCompactList()

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

Definition at line 229 of file LumiList.py.

References LumiList.LumiList.compactList.

229  def getCompactList(self):
230  """
231  Return the compact list representation
232  """
233  return self.compactList
234 
235 

◆ getDuplicates()

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

Definition at line 236 of file LumiList.py.

References LumiList.LumiList.duplicates.

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

◆ getLumis()

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

Definition at line 243 of file LumiList.py.

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

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

◆ getRuns()

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

Definition at line 259 of file LumiList.py.

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

259  def getRuns(self):
260  '''
261  return the sorted list of runs contained
262  '''
263  return sorted (self.compactList.keys())
264 
265 

◆ getVLuminosityBlockRange()

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

Definition at line 300 of file LumiList.py.

References LumiList.LumiList._getLumiParts().

300  def getVLuminosityBlockRange(self, tracked = False):
301  """
302  Turn compactList into an (optionally tracked) VLuminosityBlockRange
303  """
304 
305  import FWCore.ParameterSet.Config as cms
306  parts = self._getLumiParts()
307  if tracked:
308  return cms.VLuminosityBlockRange(parts)
309  else:
310  return cms.untracked.VLuminosityBlockRange(parts)
311 
312 

◆ removeRuns()

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

Definition at line 322 of file LumiList.py.

References LumiList.LumiList.compactList, and str.

322  def removeRuns (self, runList):
323  '''
324  removes runs from runList from collection
325  '''
326  for run in runList:
327  run = str(run)
328  if run in self.compactList:
329  del self.compactList[run]
330 
331  return
332 
333 
#define str(s)

◆ selectRuns()

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

Definition at line 334 of file LumiList.py.

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

334  def selectRuns (self, runList):
335  '''
336  Selects only runs from runList in collection
337  '''
338  runsToDelete = []
339  for run in self.compactList.keys():
340  if int(run) not in runList and run not in runList:
341  runsToDelete.append(run)
342 
343  for run in runsToDelete:
344  del self.compactList[run]
345 
346  return
347 

◆ writeJSON()

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

Definition at line 313 of file LumiList.py.

313  def writeJSON(self, fileName):
314  """
315  Write out a JSON file representation of the object
316  """
317  jsonFile = open(fileName,'w')
318  jsonFile.write("%s\n" % self)
319  jsonFile.close()
320 
321 

Member Data Documentation

◆ compactList

◆ duplicates

◆ filename

LumiList.LumiList.filename

Definition at line 58 of file LumiList.py.

Referenced by python.rootplot.rootmath.Target.__repr__().

◆ url

LumiList.LumiList.url

Definition at line 62 of file LumiList.py.

Referenced by rrapi.RRApi.get().