ATLAS Offline Software
Loading...
Searching...
No Matches
AtlCoolTriggerTool.py
Go to the documentation of this file.
1# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2
3from TrigConfStorage.TriggerCoolUtil import TriggerCoolUtil
4from PyCool import cool
5import copy
6import sys
7
8
10
11 def __init__(self, options={}):
12 self.opt = options
13 if not self.check_options():
14 sys.exit(0)
15 self.init()
16
17
18
19 def check_options(self):
20 opt = self.opt
21 if opt.l1 and not opt.menu:
22 print ("Option l1 requires option 'menu' to be set")
23 return False
24
25 if opt.l2 and not opt.menu:
26 print ("Option l2 requires option 'menu' to be set")
27 return False
28
29 if opt.ef and not opt.menu:
30 print ("Option ef requires option 'menu' to be set")
31 return False
32
33 if opt.processing and opt.processing!='hlt':
34 print ("Option p|processing must be set to 'hlt'")
35 return False
36
37 if opt.menu and not (opt.l1 or opt.l2 or opt.ef):
38 opt.l1 = opt.l2 = opt.ef = True
39
40 return True
41
42
43 def MergeRanges(self, listOfRanges):
44 newRR=[]
45 for rr in listOfRanges:
46 if len(newRR)==0:
47 newRR.append(copy.deepcopy(rr))
48 else:
49 if rr[0]-1<=newRR[-1][1]:
50 newRR[-1][1] = max(rr[1],newRR[-1][1])
51 else:
52 newRR.append(copy.deepcopy(rr))
53 return newRR
54
55
56 def GetRunRanges(self, runRange):
57 listOfRanges = []
58 runRanges = runRange.split(',')
59 for rr in runRanges:
60 startend = rr.split('-')
61 if len(startend)==1: startend += [startend[0]]
62 firstlast = [0, (cool.ValidityKeyMax>>32)-1]
63 if startend[0]: firstlast[0] = int(startend[0])
64 if startend[1]: firstlast[1] = int(startend[1])
65 firstlast.sort()
66 listOfRanges += [firstlast]
67 listOfRanges.sort()
68 return self.MergeRanges(listOfRanges)
69
70
71 def init(self):
72 self.runlist = self.GetRunRanges(self.opt.runlist)
73 self.dbconn = TriggerCoolUtil.GetConnection(self.opt.db,self.opt.verbosity)
74
75
76 def getConfigKeys(self):
77 hltkeys = TriggerCoolUtil.getHLTConfigKeys(self.dbconn, self.runlist)
78 hltpskeys = TriggerCoolUtil.getHLTPrescaleKeys(self.dbconn, self.runlist)
79 l1keys = TriggerCoolUtil.getL1ConfigKeys(self.dbconn, self.runlist)
80
81 runs = list(set(list(hltkeys)+list(hltpskeys)+list(l1keys)))
82 runs.sort()
83 runStartTimes = None
84 if self.opt.time:
85 runStartTimes = TriggerCoolUtil.getRunStartTime(self.dbconn, self.runlist, runs)
86
87 allkeys = dict([(r,{}) for r in runs])
88 for r in runs:
89 if r in hltkeys: allkeys[r].update(hltkeys[r])
90 if r in hltpskeys: allkeys[r].update(hltpskeys[r])
91 if r in l1keys: allkeys[r].update(l1keys[r])
92 if runStartTimes and r in runStartTimes: allkeys[r].update(runStartTimes[r])
93
94 return (runs, allkeys)
95
96 def printHLTProcessingString(self,runKeys):
97 runs = runKeys.keys()
98 runs.sort()
99
100
101 for r in runs:
102 keys = runKeys[r]
103 print ('c'.join(["%su%s" % (x[1],x[0]) for x in keys["HLTPSK2"]]))
104
105 def printConfigKeys(self, runKeys):
106 #t = string.Template('run $RUN ($STARTTIME) release %10')
107 runs = list(runKeys)
108 runs.sort()
109
110 for r in runs:
111 keys = runKeys[r]
112 timestr=""
113 if self.opt.time:
114 try: timestr = "(%s) " % keys["STARTTIME"]
115 except KeyError: timestr = "(--------unknown---------) "
116 try:
117 rel = keys["REL"]
118 smk = keys["SMK"]
119 hltpsk = "%4i (1-)" % keys["HLTPSK"]
120 except KeyError:
121 rel = "unknown"
122 smk = "0"
123 hltpsk = "unknown"
124
125 hltpsknew = hltpsk
126 if r > 127453:
127 hltpsknew = ""
128 if "HLTPSK2" in keys:
129 for x in keys["HLTPSK2"]:
130 if x[2]<0: hltpsknew += "%4i (%i-)" % (x[0],x[1])
131 elif x[2]==x[1]: hltpsknew += "%4i (%i) " % (x[0],x[1])
132 else: hltpsknew += "%4i (%i-%i) " % (x[0],x[1],x[2])
133 if not hltpsknew: hltpsknew = "unknown"
134
135 lvl1psk = ""
136 if "LVL1PSK" in keys:
137 for x in keys["LVL1PSK"]:
138 if x[2]<0: lvl1psk += "%4i (%i-)" % (x[0],x[1])
139 elif x[2]==x[1]: lvl1psk += "%4i (%i) " % (x[0],x[1])
140 else: lvl1psk += "%4i (%i-%i) " % (x[0],x[1],x[2])
141 if not lvl1psk: lvl1psk = "unknown"
142
143 print ("run %6i %srelease %9s smk %4s hltps %s lvl1ps %s" % (r, timestr, rel, smk, hltpsknew, lvl1psk),)
144
145 if r > 127453 and "HLTPSK2" in keys and "HLTPSK" in keys and keys["HLTPSK"] != keys["HLTPSK2"][0][0]:
146 msg = "WARNING: Menu folder shows different HLT prescale for SOR: %i" % keys["HLTPSK"]
147 print (msg)
148 else: print()
149
150 def printMenu(self, run):
151 if not self.opt.menu: return
152 if self.opt.l1:
153 TriggerCoolUtil.printL1Menu(self.dbconn, run, self.opt.verbosity)
154 if self.opt.l2 or self.opt.ef:
155 TriggerCoolUtil.printHLTMenu(self.dbconn, run, self.opt.verbosity, printL2=self.opt.l2, printEF=self.opt.ef)
156
157 def printStreams(self,run):
158 if not self.opt.streams: return
159 TriggerCoolUtil.printStreams(self.dbconn,run,self.opt.verbosity)
160
161 def execute(self):
162 (runs, configKeys) = self.getConfigKeys()
163
164 if self.opt.processing=='hlt':
165 self.printHLTProcessingString(configKeys)
166 return
167 else:
168 self.printConfigKeys(configKeys)
169
170 self.opt.isSingleRun = len(runs)==1
171
172 if self.opt.menu and not self.opt.isSingleRun:
173 print ("Error: option 'menu' works only for single run")
174 sys.exit(0)
175
176 if self.opt.streams and not self.opt.isSingleRun:
177 print ("Error: option 'streams' works only for single run")
178 sys.exit(0)
179
180 if self.opt.isSingleRun:
181 self.printMenu(runs[0])
182 self.printStreams(runs[0])
void print(char *figname, TCanvas *c1)
#define max(a, b)
Definition cfImp.cxx:41
STL class.