118 def calcFromList(self,triggername,lblist):
119 """ Calculate the integrated luminosity for a list of LBs, returning
120 a lumiResult object"""
121
122 triggerlevel=self.triggerLevel(triggername)
123 if triggerlevel is None: return None
124 totalL=0
125 totaltime=0.
126 totalacc=3*[0]
127 totalgoodblock=0
128 totalbadblock=0
129
130 folderLBCOUNTL1=self.cooldb.getFolder('/TRIGGER/LUMI/LVL1COUNTERS')
131 folderLBCOUNTHLT=self.cooldb.getFolder('/TRIGGER/LUMI/HLTCOUNTERS')
132 folderL1PRESCALE=self.cooldb.getFolder('/TRIGGER/LVL1/Prescales')
133
134 for lbinfo in lblist:
135 if (self.loglevel>0):
print(
"Beginning calculation for",lbinfo)
136
137 runstat,chainnums,hltprescale=self._getChains(lbinfo.run,triggername,triggerlevel)
138 if (self.loglevel>1):
print(
"L1/2/3 chain numbers",chainnums[0],chainnums[1],chainnums[2])
139 if (runstat):
140 since,until=lbinfo.IOVRange()
141
142 if (self.detstatus!=""):
143 if (self.loglevel>0):
144 print(
"Applying detector status cuts: %s" % self.detstatus)
145 gooddetstatus=statusCutsToRange(self.detstatusdb,'/GLOBAL/DETSTATUS/LBSUMM',since,until,self.detstatustag,self.detstatus)
146 else:
147 gooddetstatus=RangeList(since,until)
148
149 if (self.loglevel>0):
print(
"LumiB L1-Acc L2-Acc L3-Acc L1-pre L2-pre L3-pre LiveTime IntL/nb-1")
150
151 l1precache=IOVCache()
152 itr=folderL1PRESCALE.browseObjects(since,until-1,cool.ChannelSelection(chainnums[0]))
153 while (itr.goToNext()):
154 obj=itr.currentRef()
155 l1precache.add(obj.since(),obj.until(),obj.payload()['Lvl1Prescale'])
156 itr.close()
157
158
159 lumicache=self.getLumiCache(since,until)
160
161
162
163
164 l1countitr=folderLBCOUNTL1.browseObjects(since,until-1,cool.ChannelSelection(chainnums[0]))
165 if (triggerlevel>1):
166 l2countitr=folderLBCOUNTHLT.browseObjects(since,until-1,cool.ChannelSelection(chainnums[1]))
167 if (triggerlevel>2):
168 l3countitr=folderLBCOUNTHLT.browseObjects(since,until-1,cool.ChannelSelection(chainnums[2]))
169 while l1countitr.goToNext():
170
171 l1countobj=l1countitr.currentRef()
172 lb=l1countobj.since() & 0xFFFFFFFF
173 l1payload=l1countobj.payload()
174 l1acc=l1payload['L1Accept']
175
176
177 if (l1payload['AfterPrescale']>0):
178 livefrac=float(l1payload['L1Accept'])/float(l1payload['AfterPrescale'])
179 else:
180 livefrac=1.
181
182 if (triggerlevel>1):
183 l2countitr.goToNext()
184 l2countobj=l2countitr.currentRef()
185 if (l2countobj.since()!=l1countobj.since()):
186 raise RuntimeError("L2/L1 counter synchronisation error")
187 l2payload=l2countobj.payload()
188 l2acc=l2payload['HLTAccept']
189 else:
190 l2acc=0
191
192 if (triggerlevel>2):
193 l3countitr.goToNext()
194 l3countobj=l3countitr.currentRef()
195 if (l3countobj.since()!=l1countobj.since()):
196 raise RuntimeError("L3/L1 counter synchronisation error")
197 l3payload=l3countobj.payload()
198 l3acc=l3payload['HLTAccept']
199 else:
200 l3acc=0
201 if (len(gooddetstatus.getAllowedRanges(l1countobj.since(),l1countobj.until()))>0):
202
203
204
205
206 (lumi,deltat)=lumicache.find(l1countobj.since())
207 l1prescale=l1precache.find(l1countobj.since())
208 if (lumi is not None and l1prescale is not None):
209
210
211 livetime=livefrac*deltat
212 intlumi=(lumi*livetime)/float(l1prescale*hltprescale[0]*hltprescale[1])
213 if (self.loglevel>1):
print(
"%5i %7i %7i %7i %8i %8i %8i %8.2f %10.1f" % (lb,l1acc,l2acc,l3acc,l1prescale,hltprescale[0],hltprescale[1],livetime,intlumi))
214 else:
215 intlumi=0
216 print(
"%5i %7i %7i %7i <missing prescale or lumi>" %(lb,l1acc,l2acc,l3acc))
217
218 totalacc[0]+=l1acc
219 totalacc[1]+=l2acc
220 totalacc[2]+=l3acc
221 totaltime+=livetime
222 totalL+=intlumi
223 totalgoodblock+=1
224 else:
225 totalbadblock+=1
226 l1countitr.close()
227 else:
228 print(
"Trigger not defined for run",lbinfo.run)
229 if (self.loglevel>0):
print(
"Rng-T %7i %7i %7i %8.2f %10.1f" % (totalacc[0],totalacc[1],totalacc[2],totaltime,totalL))
230 return lumiResult(totalL,totalacc[0],totalacc[1],totalacc[2],totaltime,totalgoodblock,totalbadblock)
231