ATLAS Offline Software
Loading...
Searching...
No Matches
COOLRates Namespace Reference

Classes

class  COOLQueryHandler
class  COOLQueryWorker
class  QueryBundle
class  RateQueryBundle
class  RateQueryHandler
class  RateQueryWorker

Functions

 waitForReturn (fd)
 commonKeys (dictionaries)
 createTimeConverter (runLbRanges)
 rateNameInfo (runLbRanges, mySignal, numProc=1)
 generateRateQueryBundles (name, level, runLbRanges, nameToChannel, nameToFolder, alias=None)
 parseRatesString (ratesString)
 runNumberToRunLbRange (runNumbers)
 timeRangeToRunLbRange (timeRange)
 nanoTimeRangesToRunLbRanges (nanoTimeRanges)
 fillNumberToRunLbRange (fillNumbers)
 setAtlasStyle ()
 fillProfile (profileName, numBins, xMin, xMax, xValues, yValues)
 fillRateProfiles (data)
 configurePlotting (data)
 configureTime (data)
 configureLuminosity (data)
 configureNoBX (data)
 getNiceCanvas (name, aliases, textSize=25)
 configureCanvasLegend (canvas, aliases, textSize=25)
 plotRateProfiles (data, label=False, runNumber=None, fillNumber=None, log=True, minY=None, maxY=None, luminousBunches=None, drawOption='H')
 configureProfile (profile, i, minY, maxY, drawOption, data, log, textSize=25)
 getLumiEndPoints (data)
 generateAtlasLabel (canvas, timeLabel, luminousBunches, runNumber=None, fillNumber=None)
 fetchTimeLabel (timeStart, timeEnd)

Variables

str __author__ = "Peter Radloff"
str __version__ = "$Revision: 1.0$"
str __doc__ = "Fast Rate plotter from COOL database"
 logger = logging.getLogger(__name__)
 ch = logging.StreamHandler()
 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 parser = argparse.ArgumentParser(prog='COOLRates.py',description='Plots rate information from COOL')
 dest
 help
 default
 None
 metavar
 type
 int
 nargs
 action
 args = parser.parse_args()
dict folderLocations = {}
list MarkerColors = [TColor.GetColor(hexColor) for hexColor in ['#000000','#2956B2','#7DBD00','#FF542E','#AA0078','#FFCC00','#D01A55','#A6AF7A','#DCF600','#FF5B00','#659CEF','#F2BC00','#FFF0BA']]
list MarkerStyles = [20,21,22, 29,31, 33, 34, 23,24,25,26,27,28, 30]
list MarkerSizes = [1.,1.,1.4,1.8,1.,1.8,1.4,1.4,1.,1.,1.,1.,1.,1.8]
 mySignal = Process(target = waitForReturn, args=(sys.stdin.fileno(),))
 runLbRanges = runNumberToRunLbRange(args.RUNNUMBER)
 FILLNUMBER
 TIMERANGE
 RUNNUMBER
 timeConverter = createTimeConverter(runLbRanges)
 coolQueryHandler = COOLQueryHandler(mySignal,numProc=args.PROCESSES,verbose=args.VERBOSE)
 rateQueryHandler = RateQueryHandler(mySignal,numProc=args.PROCESSES,verbose=args.VERBOSE)
 nameToChannel
 nameToFolder
 numProc
 rateName
 level
 alias
dict Data = {}
dict rateOutput = Data['rates']['deadTime1'].get(runLb)
dict rateAfterPrescale = Data['rates']['deadTime2'].get(runLb)
float deadTime = 1.0-rateOutput/rateAfterPrescale
str drawOption = 'H'
 local

Function Documentation

◆ commonKeys()

COOLRates.commonKeys ( dictionaries)

Definition at line 61 of file COOLRates.py.

61def commonKeys(dictionaries):
62 if not len(dictionaries): return []
63 elif not len(dictionaries) >= 1: return dictionaries[0].keys()
64 keys = set(dictionaries[0].keys())
65 for dictionary in dictionaries[1:]:
66 keys = set(dictionary.keys())&keys
67 return list(keys)
68
69#====================================================================================================================
70
STL class.

◆ configureCanvasLegend()

COOLRates.configureCanvasLegend ( canvas,
aliases,
textSize = 25 )

Definition at line 888 of file COOLRates.py.

888def configureCanvasLegend(canvas,aliases,textSize=25):
889 height = 1.2*len(aliases)*textSize/canvas.GetWh()
890 width = int(max([len(name) for name in aliases])*textSize*.50)+70
891 canvas.SetLeftMargin(canvas.GetLeftMargin()*textSize/14.)
892 canvas.SetBottomMargin(canvas.GetBottomMargin()*textSize/14.)
893 legend = TLegend(0.00,1-canvas.GetTopMargin(),150./width,1-canvas.GetTopMargin()-height)
894 legend.SetTextSize(textSize)
895 legend.SetFillColor(0)
896 legend.SetShadowColor(0)
897 legend.SetBorderSize(0)
898 SetOwnership(legend, 0)
899
900 return canvas,legend
901
902#====================================================================================================================
903
#define max(a, b)
Definition cfImp.cxx:41

◆ configureLuminosity()

COOLRates.configureLuminosity ( data)

Definition at line 804 of file COOLRates.py.

804def configureLuminosity(data):
805 if 'filter' in data:
806 validPoints = len(commonKeys([data['luminosity'],data['filter']]))
807 if not validPoints:
808 xMin = 0
809 xMax = 0
810 else:
811 xMin = min([data['luminosity'][runLb] for runLb in commonKeys([data['luminosity'],data['filter']])])
812 xMax = max([data['luminosity'][runLb] for runLb in commonKeys([data['luminosity'],data['filter']])])
813 else:
814 validPoints = len(data['luminosity'])
815 if not validPoints:
816 xMin = 0
817 xMax = 0
818 else:
819 xMin = min(data['luminosity'].values())
820 xMax = max(data['luminosity'].values())
821 if xMin and xMax:
822 xScale=round(log10(xMax)-.5)
823 xLabel = 'Inst. Luminosity [10^{'+str(int(30+xScale))+'} cm^{-2} s^{-1}]'
824 xScale = float(10**xScale)
825 else:
826 xScale = 1.0
827 xLabel = 'Inst. Luminosity [10^{'+str(int(xScale+30))+'} cm^{-2} s^{-1}]'
828 xMin/=xScale
829 xMax/=xScale
830 xOffset = 0.0
831 numBins = int(min(validPoints/3.,100))
832 xFormat = None
833 data['plotConfig'] = {'xMin':xMin,'xMax':xMax,'xLabel':xLabel,'xScale':xScale,'xOffset':xOffset,'xFormat':xFormat,'numBins':numBins,'validPoints':validPoints,'yLabel':'Rate [Hz]'}
834 return data
835
836#====================================================================================================================
837
#define min(a, b)
Definition cfImp.cxx:40

◆ configureNoBX()

COOLRates.configureNoBX ( data)

Definition at line 838 of file COOLRates.py.

838def configureNoBX(data):
839 if 'filter' in data:
840 validPoints = len(commonKeys([data['noBX'],data['filter']]))
841 if not validPoints:
842 xMin = 0
843 xMax = 0
844 else:
845 xMin = min([data['noBX'][runLb] for runLb in commonKeys([data['noBX'],data['filter']])])
846 xMax = max([data['noBX'][runLb] for runLb in commonKeys([data['noBX'],data['filter']])])
847 else:
848 validPoints = len(data['noBX'])
849 if not validPoints:
850 xMin = 0
851 xMax = 0
852 else:
853 xMin = min(data['noBX'].values())
854 xMax = max(data['noBX'].values())
855 xScale = 1.0
856 xLabel = 'Average Interactions per Bunch Crossing'
857 xOffset = 0.0
858 numBins = int(min(validPoints/3.,100))
859 xFormat = None
860 data['plotConfig'] = {'xMin':xMin,'xMax':xMax,'xLabel':xLabel,'xScale':xScale,'xOffset':xOffset,'xFormat':xFormat,'numBins':numBins,'validPoints':validPoints,'yLabel':'Cross-section [outhouse]'}
861 return data
862
863#====================================================================================================================
864

◆ configurePlotting()

COOLRates.configurePlotting ( data)
                      #

Fills plotting data: # 1) xMin # 2) xMax # 3) xLabel # 4) xScale # 5) xOffset # 6) xFormat # 7) numBins # 8) validPoints # 8) yLabel # #

Definition at line 758 of file COOLRates.py.

758def configurePlotting(data):
759 xUnit = data['xUnit']
760 if xUnit == 'time':
761 data.update(configureTime(data))
762 elif xUnit == 'luminosity':
763 data.update(configureLuminosity(data))
764 elif xUnit == 'noBX':
765 data.update(configureNoBX(data))
766 return data
767
768#====================================================================================================================
769

◆ configureProfile()

COOLRates.configureProfile ( profile,
i,
minY,
maxY,
drawOption,
data,
log,
textSize = 25 )

Definition at line 984 of file COOLRates.py.

984def configureProfile(profile,i,minY,maxY,drawOption,data,log,textSize=25):
985 profile.SetMarkerColor(MarkerColors[i])
986 profile.SetMarkerStyle(MarkerStyles[i])
987 profile.SetMarkerSize(MarkerSizes[i])
988 profile.SetLineColor(MarkerColors[i])
989 if drawOption!='P': profile.SetMarkerSize(0.0)
990 if drawOption=='E3':
991 #profile.SetFillStyle(3001)
992 profile.SetFillColor(MarkerColors[i])
993 if not i:
994 profile.GetXaxis().SetLabelSize(textSize)
995 profile.GetXaxis().SetTitleSize(textSize)
996 profile.GetYaxis().SetLabelSize(textSize)
997 profile.GetYaxis().SetTitleSize(textSize)
998 profile.SetMinimum(minY)
999 profile.SetMaximum(maxY)
1000 profile.GetXaxis().SetTitle(data['plotConfig']['xLabel'])
1001 profile.GetYaxis().SetTitle(data['plotConfig']['yLabel'])
1002 if data['xUnit'] == 'time':
1003 profile.GetXaxis().SetTimeDisplay(1)
1004 profile.GetXaxis().SetTimeFormat(data['plotConfig']['xFormat'])
1005 dh = TDatime()
1006 dh.Set(int(data['plotConfig']['xOffset']), False)
1007 profile.GetXaxis().SetTimeOffset(dh.Convert(False))
1008 profile.GetXaxis().SetNdivisions(507)
1009 else:
1010 profile.GetXaxis().SetTimeDisplay(0)
1011 return profile
1012
1013#====================================================================================================================
1014

◆ configureTime()

COOLRates.configureTime ( data)

Definition at line 770 of file COOLRates.py.

770def configureTime(data):
771 xScale = 1.0*10**9
772 validPoints = len(data['time'])
773 if validPoints:
774 xOffset = min(data['time'].values())/xScale
775 xMin = 0.
776 xMax = max(data['time'].values())/xScale-xOffset
777 maxBins = xMax/300
778 minBins = xMax/1200
779 if maxBins <= 160:
780 numBins = maxBins
781 elif maxBins/2 <= 160:
782 numBins = maxBins/2
783 elif maxBins/3 <= 160:
784 numBins = maxBins/3
785 else:
786 numBins = minBins
787 if xMax > 48*60*60: xFormat = "%d/%m"
788 elif xMax > 12*60*60: xFormat = "%d-%Hh"
789 else: xFormat = "%H:%M"
790 else:
791 xOffset = 0.
792 xMin = 0.
793 xMax = 1.
794 numBins = 1.
795 xFormat = "%d/%m"
796 xLabel = time.strftime("%Z Time")
797 if 'filter' in data:
798 validPoints = len(commonKeys([data['time'],data['filter']]))
799 data['plotConfig'] = {'xMin':xMin,'xMax':xMax,'xLabel':xLabel,'xScale':xScale,'xOffset':xOffset,'xFormat':xFormat,'numBins':numBins,'validPoints':validPoints,'yLabel':'Rate [Hz]'}
800 return data
801
802#====================================================================================================================
803

◆ createTimeConverter()

COOLRates.createTimeConverter ( runLbRanges)

Definition at line 241 of file COOLRates.py.

241def createTimeConverter(runLbRanges):
242 timeConverter = {}
243 worker = COOLQueryWorker()
244
245 if runLbRanges is not None:
246 folder = worker.getFolder('/TRIGGER/LUMI/LBLB')
247 folder.setPrefetchAll(False)
248 for runLbStart,runLbEnd in runLbRanges:
249 timeConverter[(runLbStart,runLbEnd)]={}
250 folderIterator = folder.browseObjects(runLbStart,runLbEnd,cool.ChannelSelection())
251 while folderIterator.goToNext():
252 currentSlice = folderIterator.currentRef()
253 timeConverter[(runLbStart,runLbEnd)][int(currentSlice.since())] = int(currentSlice.payloadValue('StartTime'))
254 folderIterator.close()
255
256 return timeConverter
257
258#====================================================================================================================
259

◆ fetchTimeLabel()

COOLRates.fetchTimeLabel ( timeStart,
timeEnd )

Definition at line 1081 of file COOLRates.py.

1081def fetchTimeLabel(timeStart,timeEnd):
1082 timeTupleStart = time.localtime(timeStart)
1083 timeTupleEnd = time.localtime(timeEnd)
1084
1085 if timeTupleStart.tm_year != timeTupleEnd.tm_year:
1086 timeLabel = '{0} - {1}'.format(time.strftime('%b. %e %Y',timeTupleStart),time.strftime('%b. %e %Y',timeTupleEnd))
1087 else:
1088 if timeTupleStart.tm_mon != timeTupleEnd.tm_mon:
1089 timeLabel = '{0} - {1} {2}'.format(time.strftime('%b. %e',timeTupleStart),time.strftime('%b. %e',timeTupleEnd),timeTupleEnd.tm_year)
1090 else:
1091 if timeTupleStart.tm_mday != timeTupleEnd.tm_mday:
1092 timeLabel = '{0}-{1} {2}'.format(time.strftime('%b. %e',timeTupleStart),time.strftime('%e',timeTupleEnd),timeTupleEnd.tm_year)
1093 else:
1094 timeLabel = time.strftime('%b. %e %Y',timeTupleStart)
1095 return timeLabel
1096
1097#====================================================================================================================
1098"""
1099This marks the beginning of the script
1100"""
1101#====================================================================================================================
1102
1103

◆ fillNumberToRunLbRange()

COOLRates.fillNumberToRunLbRange ( fillNumbers)

Definition at line 600 of file COOLRates.py.

600def fillNumberToRunLbRange(fillNumbers):
601 minFill = min(fillNumbers)-1
602 worker = COOLQueryWorker()
603 result = {}
604 folder = worker.getFolder('/LHC/DCS/FILLSTATE')
605 folder.setPrefetchAll(False)
606 timeEnd = int(time.mktime(time.localtime()))*10**9
607 channelSelection = cool.ChannelSelection()
608 for i in range(25):
609 timeStart = timeEnd-259200000000000
610 #load information in 3 day chunks until lowest fill is less than or equal to minFill (break after loading full year)
611 folderIterator = folder.browseObjects(timeStart,timeEnd,channelSelection)
612 while folderIterator.goToNext():
613 currentSlice = folderIterator.currentRef()
614 fillNumber = currentSlice.payloadValue('FillNumber')
615 if not fillNumber.isdigit(): continue
616 fillNumber = int(fillNumber)
617 if fillNumber not in result: result[fillNumber]=[]
618 result[fillNumber].append(currentSlice.since())
619 result[fillNumber].append(currentSlice.until())
620 folderIterator.close()
621 timeEnd = timeStart
622 if not len(result): continue
623 if min(result.keys())<=minFill: break
624 nanoTimeRanges = []
625 for fillNumber in list(set(fillNumbers)&set(result.keys())):
626 nanoTimes = result[fillNumber]
627 nanoTimeRanges.append((min(nanoTimes),max(nanoTimes)))
628 worker.close()
629 return nanoTimeRangesToRunLbRanges(nanoTimeRanges)
630
631#====================================================================================================================
632"""
633This marks the beginning of plotting related tools
634"""
635#====================================================================================================================
636

◆ fillProfile()

COOLRates.fillProfile ( profileName,
numBins,
xMin,
xMax,
xValues,
yValues )

Definition at line 698 of file COOLRates.py.

698def fillProfile(profileName,numBins,xMin,xMax,xValues,yValues):
699 profile = TProfile(profileName,profileName,int(numBins),xMin,xMax)
700 for x,y in zip(xValues,yValues):
701 profile.Fill(x,y)
702 return profile
703
704#====================================================================================================================
705

◆ fillRateProfiles()

COOLRates.fillRateProfiles ( data)

Definition at line 706 of file COOLRates.py.

706def fillRateProfiles(data):
707 rates = []
708 if 'profiles' not in data: data['profiles'] = {}
709 for group in data['groups']:
710 for rate in group:
711 rates.append(rate)
712 xOffset = data['plotConfig']['xOffset']
713 xScale = data['plotConfig']['xScale']
714 for rateName,alias,level in rates:
715 if data['xUnit'] == 'noBX':
716 if 'filter' in data:
717 runLbs = commonKeys([data[data['xUnit']],data['filter'],data['rates'][alias],data['luminosity']])
718 else:
719 runLbs = commonKeys([data[data['xUnit']],data['rates'][alias],data['luminosity']])
720 else:
721 if 'filter' in data:
722 runLbs = commonKeys([data[data['xUnit']],data['filter'],data['rates'][alias]])
723 else:
724 runLbs = commonKeys([data[data['xUnit']],data['rates'][alias]])
725 xValues = []
726 yValues = []
727 if data['xUnit'] == 'noBX':
728 for runLb in runLbs:
729 luminosity = data['luminosity'].get(runLb)
730 if luminosity==0.: continue
731 yValue = data['rates'][alias].get(runLb)/luminosity
732 xValues.append(data[data['xUnit']].get(runLb)/xScale - xOffset)
733 yValues.append(yValue)
734 else:
735 for runLb in runLbs:
736 xValues.append(data[data['xUnit']].get(runLb)/xScale - xOffset)
737 yValues.append(data['rates'][alias].get(runLb))
738 data['profiles'][alias] = fillProfile(alias,data['plotConfig']['numBins'],data['plotConfig']['xMin'],data['plotConfig']['xMax'],xValues,yValues)
739 return data
740
741#====================================================================================================================
742
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ generateAtlasLabel()

COOLRates.generateAtlasLabel ( canvas,
timeLabel,
luminousBunches,
runNumber = None,
fillNumber = None )

Definition at line 1035 of file COOLRates.py.

1035def generateAtlasLabel(canvas,timeLabel,luminousBunches,runNumber = None,fillNumber = None):
1036 canvas.cd(1)
1037
1038 xOffset = .30
1039 yOffset = .27
1040
1041 AtlasLabel = []
1042
1043 AtlasLabel.append(TLatex())
1044 AtlasLabel[-1].SetNDC()
1045 AtlasLabel[-1].SetTextFont(42)
1046
1047 if runNumber is None: runNumber = []
1048 if fillNumber is None: fillNumber = []
1049
1050 if len(runNumber)==1:
1051 AtlasLabel[-1].DrawLatex(xOffset+0.115,yOffset,'Run {0} {1}'.format(runNumber[0],timeLabel))
1052 AtlasLabel.append(TLatex())
1053 AtlasLabel[-1].SetNDC()
1054 AtlasLabel[-1].SetTextFont(72)
1055 AtlasLabel[-1].DrawLatex(xOffset,yOffset,"ATLAS")
1056 elif len(fillNumber)==1:
1057 AtlasLabel[-1].DrawLatex(xOffset,yOffset,'LHC Fill {0} {1}'.format(fillNumber[0],timeLabel))
1058 else:
1059 AtlasLabel[-1].DrawLatex(xOffset,yOffset,'Running {0}'.format(timeLabel))
1060
1061 AtlasLabel.append(TLatex())
1062 AtlasLabel[-1].SetNDC()
1063 AtlasLabel[-1].SetTextFont(72)
1064 AtlasLabel[-1].DrawLatex(xOffset,yOffset+.07,"ATLAS")
1065
1066 AtlasLabel.append(TLatex())
1067 AtlasLabel[-1].SetNDC()
1068 AtlasLabel[-1].SetTextFont(42)
1069 AtlasLabel[-1].DrawLatex(xOffset+0.115,yOffset+.07,'Trigger Operations')
1070
1071 if luminousBunches is not None:
1072 AtlasLabel.append(TLatex())
1073 AtlasLabel[-1].SetNDC()
1074 AtlasLabel[-1].SetTextFont(42)
1075 AtlasLabel[-1].DrawLatex(xOffset,yOffset-.07,'{0} Luminous Bunches'.format(luminousBunches))
1076
1077 return canvas
1078
1079#====================================================================================================================
1080

◆ generateRateQueryBundles()

COOLRates.generateRateQueryBundles ( name,
level,
runLbRanges,
nameToChannel,
nameToFolder,
alias = None )

Definition at line 471 of file COOLRates.py.

471def generateRateQueryBundles(name,level,runLbRanges,nameToChannel,nameToFolder,alias=None):
472 queryBundles = []
473 if alias is None: alias = name
474 for runLbStart,runLbEnd in runLbRanges:
475 run = runLbStart>>32
476 if run not in nameToChannel:continue
477 if name not in nameToChannel[run]:continue
478 channel = nameToChannel[run][name]
479 if run not in nameToFolder:continue
480 if name not in nameToFolder[run]:continue
481 rateType = nameToFolder[run][name]
482 if rateType not in folderLocations:continue
483 if level not in folderLocations[rateType]:continue
484 folderName,payloadName,turnCounterFolder,turnCountPayloadName = folderLocations[rateType][level]
485 queryBundle = RateQueryBundle(runLbStart,runLbEnd,alias,folderName,payloadName,turnCounterFolder,turnCountPayloadName,channel)
486 queryBundles.append(queryBundle)
487 return queryBundles
488
489#====================================================================================================================
490

◆ getLumiEndPoints()

COOLRates.getLumiEndPoints ( data)

Definition at line 1015 of file COOLRates.py.

1015def getLumiEndPoints(data):
1016 if 'filter' in data:
1017 validPoints = len(commonKeys([data['luminosity'],data['filter']]))
1018 if not validPoints:
1019 lumiStart = 0.
1020 lumiEnd = 0.
1021 else:
1022 lumiStart = data['luminosity'][min(commonKeys([data['luminosity'],data['filter']]))]
1023 lumiEnd = data['luminosity'][max(commonKeys([data['luminosity'],data['filter']]))]
1024 else:
1025 if not validPoints:
1026 lumiStart = 0.
1027 lumiEnd = 0.
1028 else:
1029 lumiStart = data['luminosity'][min(data['luminosity'].keys())]
1030 lumiEnd = data['luminosity'][max(data['luminosity'].keys())]
1031 return (lumiStart,lumiEnd)
1032
1033#====================================================================================================================
1034

◆ getNiceCanvas()

COOLRates.getNiceCanvas ( name,
aliases,
textSize = 25 )

Definition at line 865 of file COOLRates.py.

865def getNiceCanvas(name,aliases,textSize=25):
866 canvas = TCanvas(name, name, 4, 45, 700, 500)
867 canvas.SetGridx(1)
868 canvas.SetGridy(1)
869 canvas.SetFillColor(0)
870 canvas.SetBorderMode(0)
871 canvas.SetBorderSize(0)
872 canvas.SetFrameFillColor(0)
873 #Stretch width and add subpad for legend
874 width = int(max([len(nm) for nm in aliases])*textSize*.50)+70
875 oldWidth = canvas.GetWindowWidth()
876 newWidth = oldWidth+width
877 canvas.SetCanvasSize(newWidth,canvas.GetWindowHeight())
878 canvas.Divide(2,1)
879 subPad1 = canvas.GetPad(1)
880 subPad1.SetPad(.005,.005,float(oldWidth)/newWidth,.995)
881 subPad2 = canvas.GetPad(2)
882 subPad2.SetPad(float(oldWidth)/newWidth,.005,.995,.995)
883 SetOwnership(canvas, 0)
884 return canvas
885
886#====================================================================================================================
887

◆ nanoTimeRangesToRunLbRanges()

COOLRates.nanoTimeRangesToRunLbRanges ( nanoTimeRanges)

Definition at line 573 of file COOLRates.py.

573def nanoTimeRangesToRunLbRanges(nanoTimeRanges):
574 runLbRanges = []
575 worker = COOLQueryWorker()
576 folder = worker.getFolder('/TRIGGER/LUMI/LBTIME')
577 folder.setPrefetchAll(False)
578 channelSelection = cool.ChannelSelection()
579 for timeStart,timeEnd in nanoTimeRanges:
580 folderIterator = folder.browseObjects(timeStart,timeEnd,channelSelection)
581 if folderIterator.isEmpty():
582 folderIterator.close()
583 continue
584 temp = {}
585 while folderIterator.goToNext():
586 currentSlice = folderIterator.currentRef()
587 run = int(currentSlice.payloadValue('Run'))
588 lb = int(currentSlice.payloadValue('LumiBlock'))
589 runLb = (run<<32)+lb
590 if run not in temp: temp[run]=[]
591 temp[run].append(runLb)
592 for run,runLbs in temp.items():
593 runLbRanges.append((min(runLbs),max(runLbs)))
594 folderIterator.close()
595 worker.close()
596 return runLbRanges
597
598#====================================================================================================================
599

◆ parseRatesString()

COOLRates.parseRatesString ( ratesString)

Definition at line 506 of file COOLRates.py.

506def parseRatesString(ratesString):
507 groups_ = []
508 groups = ratesString.split('|')
509 for group in groups:
510 if group == '': continue
511 groups_.append([])
512 for rate in group.split(','):
513 if rate == '': continue
514 if ':' in rate:
515 rateName,alias = tuple(rate.split(':'))
516 else:
517 rateName,alias = (rate,rate)
518 if rateName.endswith('-0'):
519 level = 'Input'
520 rateName = rateName[:-2]
521 elif rateName.endswith('-1'):
522 level = 'AfterPrescale'
523 rateName = rateName[:-2]
524 else:
525 level = 'Output'
526 groups_[-1].append((rateName,alias,level))
527 return groups_
528
529#====================================================================================================================
530

◆ plotRateProfiles()

COOLRates.plotRateProfiles ( data,
label = False,
runNumber = None,
fillNumber = None,
log = True,
minY = None,
maxY = None,
luminousBunches = None,
drawOption = 'H' )

Definition at line 904 of file COOLRates.py.

904def plotRateProfiles(data,label=False,runNumber=None,fillNumber=None,log=True,minY=None,maxY=None,luminousBunches=None,drawOption='H'):
905
906 TGaxis.SetMaxDigits(3)
907
908 data['canvases']={}
909
910 for groupNum,group in enumerate(data['groups']):
911
912 if minY is None: minY = 0.
913 if log: minY = max([10**-9,minY])
914 if maxY is None: maxY = 10.**10
915
916 currentMin = maxY
917 currentMax = minY
918
919 aliases = []
920 for rateName,alias,level in group:
921 aliases.append(alias)
922 temp = [data['profiles'][alias].GetBinContent(i) for i in range(data['profiles'][alias].GetNbinsX()+1) if minY<data['profiles'][alias].GetBinContent(i)<maxY]
923 if not len(temp): continue
924 thisMin = min(temp)
925 thisMax = max(temp)
926 currentMin = min(currentMin,thisMin)
927 currentMax = max(currentMax,thisMax)
928
929 canvas = getNiceCanvas('canvas{0}'.format(('000'+str(groupNum))[-3:]),aliases)
930
931 if currentMin>=currentMax:
932 logger.warning('No data in group, {0} is empty'.format(canvas.GetName()))
933 data['canvases'].update({canvas.GetName():canvas})
934 continue
935
936 scale = 1.1
937 if log: scale = 1.5
938 thisMinY = currentMin/scale
939 thisMaxY = currentMax*scale
940
941 subPad1 = canvas.GetPad(1)
942 if log: subPad1.SetLogy()
943
944 canvas,legend = configureCanvasLegend(canvas,aliases)
945
946 legendOption = 'L'
947 if 'P' in drawOption: legendOption = 'p'
948
949 canvas.cd(1)
950 for i,(rateName,alias,level) in enumerate(group):
951
952 profile = data['profiles'][alias]
953 profile = configureProfile(profile,i,thisMinY,thisMaxY,drawOption,data,log)
954 if drawOption:
955 if not i: profile.Draw(drawOption)
956 else: profile.Draw('{0} SAME'.format(drawOption))
957 else:
958 if not i: profile.Draw()
959 else: profile.Draw('SAME')
960 if log:
961 yAxis = profile.GetYaxis()
962 if int(log10(minY)) == int(log10(maxY)): yAxis.SetMoreLogLabels(True)
963 else: yAxis.SetMoreLogLabels(False)
964 yAxis.Draw()
965 legend.AddEntry(profile,alias,legendOption)
966
967 canvas.cd(2)
968 legend.Draw()
969
970 canvas.cd(1)
971 if label:
972 scale = 1.0*10**9
973 timeStart = min(data['time'].values())/scale
974 timeEnd = max(data['time'].values())/scale
975 timeLabel = fetchTimeLabel(timeStart,timeEnd)
976 #startLumi,endLumi = getLumiEndPoints(data)
977 canvas = generateAtlasLabel(canvas,timeLabel,luminousBunches,runNumber=runNumber,fillNumber=fillNumber)
978 data['canvases'].update({canvas.GetName():canvas})
979
980 return data
981
982#====================================================================================================================
983

◆ rateNameInfo()

COOLRates.rateNameInfo ( runLbRanges,
mySignal,
numProc = 1 )

Definition at line 308 of file COOLRates.py.

308def rateNameInfo(runLbRanges,mySignal,numProc=1):
309 def rateNameWorker(queueIn,queueOut):
310 worker = COOLQueryWorker()
311 while(1):
312 try: run = queueIn.get(False,0.001)
313 except Empty:
314 sleep(.001)
315 continue
316 if run is True:
317 break
318 runLbStart=run<<32
319 runLbEnd=runLbStart+1
320 nameToChannel={}
321 nameToFolder={}
322 #L1 Triggers
323 folder = worker.getFolder("/TRIGGER/LVL1/Menu")
324 folder.setPrefetchAll(False)
325 folderIterator = folder.browseObjects(runLbStart,runLbEnd,cool.ChannelSelection())
326 while folderIterator.goToNext():
327 currentSlice = folderIterator.currentRef()
328 nameToChannel[currentSlice.payloadValue('ItemName')] = currentSlice.channelId()
329 nameToFolder[currentSlice.payloadValue('ItemName')] = 0
330 folderIterator.close()
331 #HLT Triggers
332 folder = worker.getFolder("/TRIGGER/HLT/Menu")
333 folder.setPrefetchAll(False)
334 folderIterator = folder.browseObjects(runLbStart,runLbEnd,cool.ChannelSelection())
335 while folderIterator.goToNext():
336 currentSlice = folderIterator.currentRef()
337 if currentSlice.payloadValue('ChainName').startswith('L2'):
338 nameToChannel[currentSlice.payloadValue('ChainName')] = int(currentSlice.payloadValue('ChainCounter'))
339 nameToFolder[currentSlice.payloadValue('ChainName')] = 1
340 elif currentSlice.payloadValue('ChainName').startswith('EF'):
341 nameToChannel[currentSlice.payloadValue('ChainName')] = int(currentSlice.payloadValue('ChainCounter'))
342 nameToFolder[currentSlice.payloadValue('ChainName')] = 2
343 folderIterator.close()
344 #Totals/Streams
345 folder = worker.getFolder("/TRIGGER/HLT/TotalRates")
346 folder.setPrefetchAll(False)
347 for channel in folder.listChannels():
348 nameToChannel[folder.channelName(channel)] = channel
349 nameToFolder[folder.channelName(channel)] = 3
350 queueOut.put(({run:nameToChannel},{run:nameToFolder}))
351 queueOut.put(True)
352 return
353
354 def terminateProcesses(QueryProcesses,troughQueue):
355 while 1:
356 try:troughQueue.get(False)
357 except Empty: break
358 logger.critical('Queue is empty')
359 for i in range(numProc): troughQueue.put(True)
360 time.sleep(1)
361 for process in QueryProcesses:
362 process.terminate()
363 process.join()
364 logger.critical('Processes are joined')
365 raise KeyboardInterrupt
366
367 nameToChannel = {}
368 nameToFolder = {}
369
370 troughQueue = Queue()
371 resultQueue = Queue()
372
373 processes = [Process(target=rateNameWorker,args=(troughQueue,resultQueue,)) for i in range(numProc)]
374 for process in processes: process.start()
375
376 counter = 0
377 target = 0.
378 finished = 0
379
380 runs = list(set([runLbStart>>32 for runLbStart,runLbEnd in runLbRanges]))
381
382 for run in runs:
383 counter+=1
384 troughQueue.put(run)
385
386 startingQueries = counter
387
388 logger.info('{0} queries distributed over {1} workers'.format(startingQueries,numProc))
389
390 for i in range(numProc): troughQueue.put(True)
391
392 try:
393 while(1):
394 if not mySignal.is_alive():
395 raise KeyboardInterrupt
396 break
397 try: result = resultQueue.get(False,0.001)
398 except Empty:
399 time.sleep(.001)
400 continue
401 if result is True:
402 finished+=1
403 if finished==numProc: break
404 continue
405 tempNTC,tempNTF = result
406 nameToChannel.update(tempNTC)
407 nameToFolder.update(tempNTF)
408 counter-=1
409 percentComplete = min(100,int(round(float(startingQueries-counter)/startingQueries*100+.5)))
410 if percentComplete>=target:
411 target+=5.
412 logger.info('{0}% complete'.format(percentComplete))
413 except KeyboardInterrupt:
414 logger.critical('Caught signal, terminating processes')
415 terminateProcesses(processes,troughQueue)
416
417 for process in processes: process.join()
418
419 return nameToChannel,nameToFolder
420
421#====================================================================================================================
422
while((inf=(TStreamerInfo *) nextinfo()) !=0)

◆ runNumberToRunLbRange()

COOLRates.runNumberToRunLbRange ( runNumbers)

Definition at line 531 of file COOLRates.py.

531def runNumberToRunLbRange(runNumbers):
532 runLbRanges = []
533 worker = COOLQueryWorker()
534 folder = worker.getFolder('/TRIGGER/LUMI/LBLB')
535 folder.setPrefetchAll(False)
536 channelSelection = cool.ChannelSelection()
537 for runNumber in runNumbers:
538 folderIterator = folder.browseObjects(runNumber<<32,((runNumber+1)<<32)-1,channelSelection)
539 if folderIterator.isEmpty():
540 folderIterator.close()
541 continue
542 runLbs = []
543 while folderIterator.goToNext():
544 currentSlice = folderIterator.currentRef()
545 runLbs.append(currentSlice.since())
546 folderIterator.close()
547 runLbRanges.append((min(runLbs),max(runLbs)))
548 worker.close()
549 return runLbRanges
550
551#====================================================================================================================
552

◆ setAtlasStyle()

COOLRates.setAtlasStyle ( )

Definition at line 637 of file COOLRates.py.

637def setAtlasStyle():
638 from ROOT import TStyle
639
640 atlasStyle = TStyle("ATLAS","Atlas style")
641
642 atlasStyle.SetFrameBorderMode(0)
643 atlasStyle.SetFrameFillColor(0)
644 atlasStyle.SetCanvasBorderMode(0)
645 atlasStyle.SetCanvasColor(0)
646 atlasStyle.SetPadBorderMode(0)
647 atlasStyle.SetPadColor(0)
648 atlasStyle.SetStatColor(0)
649 atlasStyle.SetPaperSize(20,26)
650 atlasStyle.SetPadTopMargin(0.07)
651 atlasStyle.SetPadRightMargin(0.05)
652 atlasStyle.SetPadBottomMargin(0.16)
653 atlasStyle.SetPadLeftMargin(0.16)
654 atlasStyle.SetTitleXOffset(1.4)
655 atlasStyle.SetTitleYOffset(1.2)
656 font=43
657 tsize=0.05
658 atlasStyle.SetTextFont(font)
659 atlasStyle.SetTextSize(tsize)
660 atlasStyle.SetLabelFont(font,"x")
661 atlasStyle.SetTitleFont(font,"x")
662 atlasStyle.SetLabelFont(font,"y")
663 atlasStyle.SetTitleFont(font,"y")
664 atlasStyle.SetLabelFont(font,"z")
665 atlasStyle.SetTitleFont(font,"z")
666 atlasStyle.SetLabelSize(tsize,"x")
667 atlasStyle.SetTitleSize(tsize,"x")
668 atlasStyle.SetLabelSize(tsize,"y")
669 atlasStyle.SetTitleSize(tsize,"y")
670 atlasStyle.SetLabelSize(tsize,"z")
671 atlasStyle.SetTitleSize(tsize,"z")
672 atlasStyle.SetMarkerStyle(20)
673 atlasStyle.SetMarkerSize(1.2)
674 atlasStyle.SetHistLineWidth(2)
675 atlasStyle.SetLineStyleString(2,"[12 12]")
676 atlasStyle.SetEndErrorSize(0.)
677 atlasStyle.SetOptTitle(0)
678 atlasStyle.SetOptStat(0)
679 atlasStyle.SetOptFit(0)
680 atlasStyle.SetPadTickX(1)
681 atlasStyle.SetPadTickY(1)
682
683 gROOT.SetStyle("ATLAS")
684 gROOT.ForceStyle()
685
686#====================================================================================================================
687

◆ timeRangeToRunLbRange()

COOLRates.timeRangeToRunLbRange ( timeRange)

Definition at line 553 of file COOLRates.py.

553def timeRangeToRunLbRange(timeRange):
554
555 if len(timeRange.split(';'))!=2:
556 logger.critical('Time range "{0}" does not match YYYY-MM-DD:HH:mm:ss;YYYY-MM-DD:HH:mm:ss'.format(timeRange))
557 sys.exit(0)
558 timeStart,timeEnd = tuple(timeRange.split(';'))
559 try:
560 timeStart = time.strptime(timeStart,'%Y-%m-%d:%H:%M:%S')
561 timeEnd = time.strptime(timeEnd,'%Y-%m-%d:%H:%M:%S')
562 except Exception:
563 logger.critical('Time range "{0}" does not match YYYY-MM-DD:HH:mm:ss;YYYY-MM-DD:HH:mm:ss'.format(timeRange))
564 sys.exit(0)
565
566 timeStart = int(time.mktime(timeStart))*10**9
567 timeEnd = int(time.mktime(timeEnd))*10**9
568
569 return nanoTimeRangesToRunLbRanges([(timeStart,timeEnd)])
570
571#====================================================================================================================
572

◆ waitForReturn()

COOLRates.waitForReturn ( fd)

Definition at line 50 of file COOLRates.py.

50def waitForReturn(fd):
51 logger.critical('Press Return to safely exit')
52 signal.signal(signal.SIGINT, signal.SIG_IGN)
53 while(1):
54 ch = os.read(fd,1)
55 if ch == '\n': break
56 logger.critical('Received signal, exiting at first chance')
57 return
58
59#====================================================================================================================
60

Variable Documentation

◆ __author__

str COOLRates.__author__ = "Peter Radloff"
private

Definition at line 7 of file COOLRates.py.

◆ __doc__

str COOLRates.__doc__ = "Fast Rate plotter from COOL database"
private

Definition at line 9 of file COOLRates.py.

◆ __version__

str COOLRates.__version__ = "$Revision: 1.0$"
private

Definition at line 8 of file COOLRates.py.

◆ action

COOLRates.action

Definition at line 34 of file COOLRates.py.

◆ alias

COOLRates.alias

Definition at line 1172 of file COOLRates.py.

◆ args

COOLRates.args = parser.parse_args()

Definition at line 44 of file COOLRates.py.

◆ ch

COOLRates.ch = logging.StreamHandler()

Definition at line 22 of file COOLRates.py.

◆ coolQueryHandler

COOLRates.coolQueryHandler = COOLQueryHandler(mySignal,numProc=args.PROCESSES,verbose=args.VERBOSE)

Definition at line 1138 of file COOLRates.py.

◆ Data

dict COOLRates.Data = {}

Definition at line 1202 of file COOLRates.py.

◆ deadTime

float COOLRates.deadTime = 1.0-rateOutput/rateAfterPrescale

Definition at line 1220 of file COOLRates.py.

◆ default

COOLRates.default

Definition at line 31 of file COOLRates.py.

◆ dest

COOLRates.dest

Definition at line 30 of file COOLRates.py.

◆ drawOption

COOLRates.drawOption = 'H'

Definition at line 1241 of file COOLRates.py.

◆ FILLNUMBER

COOLRates.FILLNUMBER

Definition at line 1115 of file COOLRates.py.

◆ folderLocations

dict COOLRates.folderLocations = {}

Definition at line 286 of file COOLRates.py.

◆ formatter

COOLRates.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

Definition at line 23 of file COOLRates.py.

◆ help

COOLRates.help

Definition at line 30 of file COOLRates.py.

◆ int

COOLRates.int

Definition at line 31 of file COOLRates.py.

◆ level

COOLRates.level

Definition at line 1172 of file COOLRates.py.

◆ local

COOLRates.local

Definition at line 1253 of file COOLRates.py.

◆ logger

COOLRates.logger = logging.getLogger(__name__)

Definition at line 21 of file COOLRates.py.

◆ MarkerColors

list COOLRates.MarkerColors = [TColor.GetColor(hexColor) for hexColor in ['#000000','#2956B2','#7DBD00','#FF542E','#AA0078','#FFCC00','#D01A55','#A6AF7A','#DCF600','#FF5B00','#659CEF','#F2BC00','#FFF0BA']]
                                               #

Set default color, styles and sizes (14 available) # #

Definition at line 694 of file COOLRates.py.

◆ MarkerSizes

list COOLRates.MarkerSizes = [1.,1.,1.4,1.8,1.,1.8,1.4,1.4,1.,1.,1.,1.,1.,1.8]

Definition at line 696 of file COOLRates.py.

◆ MarkerStyles

list COOLRates.MarkerStyles = [20,21,22, 29,31, 33, 34, 23,24,25,26,27,28, 30]

Definition at line 695 of file COOLRates.py.

◆ metavar

COOLRates.metavar

Definition at line 31 of file COOLRates.py.

◆ mySignal

COOLRates.mySignal = Process(target = waitForReturn, args=(sys.stdin.fileno(),))

Definition at line 1106 of file COOLRates.py.

◆ nameToChannel

COOLRates.nameToChannel

Definition at line 1142 of file COOLRates.py.

◆ nameToFolder

COOLRates.nameToFolder

Definition at line 1142 of file COOLRates.py.

◆ nargs

COOLRates.nargs

Definition at line 31 of file COOLRates.py.

◆ None

COOLRates.None

Definition at line 31 of file COOLRates.py.

◆ numProc

COOLRates.numProc

Definition at line 1142 of file COOLRates.py.

◆ parser

COOLRates.parser = argparse.ArgumentParser(prog='COOLRates.py',description='Plots rate information from COOL')

Definition at line 29 of file COOLRates.py.

◆ rateAfterPrescale

dict COOLRates.rateAfterPrescale = Data['rates']['deadTime2'].get(runLb)

Definition at line 1217 of file COOLRates.py.

◆ rateName

COOLRates.rateName

Definition at line 1172 of file COOLRates.py.

◆ rateOutput

dict COOLRates.rateOutput = Data['rates']['deadTime1'].get(runLb)

Definition at line 1216 of file COOLRates.py.

◆ rateQueryHandler

COOLRates.rateQueryHandler = RateQueryHandler(mySignal,numProc=args.PROCESSES,verbose=args.VERBOSE)

Definition at line 1139 of file COOLRates.py.

◆ runLbRanges

COOLRates.runLbRanges = runNumberToRunLbRange(args.RUNNUMBER)

Definition at line 1114 of file COOLRates.py.

◆ RUNNUMBER

COOLRates.RUNNUMBER

Definition at line 1120 of file COOLRates.py.

◆ timeConverter

COOLRates.timeConverter = createTimeConverter(runLbRanges)

Definition at line 1136 of file COOLRates.py.

◆ TIMERANGE

COOLRates.TIMERANGE

Definition at line 1116 of file COOLRates.py.

◆ type

COOLRates.type

Definition at line 31 of file COOLRates.py.