CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
def __and__
 
def __contains__
 
def __init__
 
def __len__
 
def __or__
 
def __str__
 
def __sub__
 
def contains
 
def filterLumis
 
def getCMSSWString
 
def getCompactList
 
def getDuplicates
 
def getLumis
 
def getRuns
 
def getVLuminosityBlockRange
 
def removeRuns
 
def selectRuns
 
def writeJSON
 

Public Attributes

 compactList
 
 duplicates
 
 filename
 
 url
 

Private Member Functions

def _getLumiParts
 

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

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

Member Function Documentation

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

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

Definition at line 151 of file LumiList.py.

References LumiList.LumiList.compactList.

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

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

Definition at line 203 of file LumiList.py.

References LumiList.LumiList.compactList.

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

Definition at line 182 of file LumiList.py.

Referenced by LumiList.LumiList.__add__().

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

Definition at line 223 of file LumiList.py.

References LumiList.LumiList.compactList.

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

Definition at line 123 of file LumiList.py.

References LumiList.LumiList.compactList.

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

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

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

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

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

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

Definition at line 229 of file LumiList.py.

References LumiList.LumiList.compactList.

230  def getCompactList(self):
231  """
232  Return the compact list representation
233  """
234  return self.compactList
235 
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.

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

Definition at line 243 of file LumiList.py.

References LumiList.LumiList.compactList, and sistrip::SpyUtilities.range().

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

Definition at line 259 of file LumiList.py.

260  def getRuns(self):
261  '''
262  return the sorted list of runs contained
263  '''
264  return sorted (self.compactList.keys())
265 
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().

301  def getVLuminosityBlockRange(self, tracked = False):
302  """
303  Turn compactList into an (optionally tracked) VLuminosityBlockRange
304  """
305 
306  import FWCore.ParameterSet.Config as cms
307  parts = self._getLumiParts()
308  if tracked:
309  return cms.VLuminosityBlockRange(parts)
310  else:
311  return cms.untracked.VLuminosityBlockRange(parts)
312 
def getVLuminosityBlockRange
Definition: LumiList.py:300
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.

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

335  def selectRuns (self, runList):
336  '''
337  Selects only runs from runList in collection
338  '''
339  runsToDelete = []
340  for run in self.compactList.keys():
341  if int(run) not in runList and run not in runList:
342  runsToDelete.append(run)
343 
344  for run in runsToDelete:
345  del self.compactList[run]
346 
347  return
def LumiList.LumiList.writeJSON (   self,
  fileName 
)
Write out a JSON file representation of the object

Definition at line 313 of file LumiList.py.

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

Member Data Documentation

LumiList.LumiList.compactList

Definition at line 55 of file LumiList.py.

Referenced by LumiList.LumiList.__and__(), LumiList.LumiList.__len__(), LumiList.LumiList.__str__(), LumiList.LumiList.__sub__(), LumiList.LumiList._getLumiParts(), LumiList.LumiList.contains(), LumiList.LumiList.getCompactList(), LumiList.LumiList.getLumis(), LumiList.LumiList.removeRuns(), and LumiList.LumiList.selectRuns().

LumiList.LumiList.duplicates

Definition at line 56 of file LumiList.py.

Referenced by LumiList.LumiList.getDuplicates(), edmIntegrityCheck.IntegrityCheck.report(), edmIntegrityCheck.IntegrityCheck.structured(), and edmIntegrityCheck.IntegrityCheck.test().

LumiList.LumiList.filename

Definition at line 58 of file LumiList.py.

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

LumiList.LumiList.url

Definition at line 62 of file LumiList.py.

Referenced by rrapi.RRApi.get().