3 from __future__
import print_function
7 from PyCool
import cool
8 from CoolConvUtilities.AtlCoolLib
import indirectOpen
9 from DQDefects
import DefectsDB
12 serverfile=
open(
"/afs/cern.ch/user/l/larmon/public/atlasdqmpass.txt")
13 password=serverfile.readline().strip()
15 except Exception
as e:
16 print (
"Failed to read xmlrpc server connection details from AFS location")
21 def getLBsToIgnore(runnum,burstsFromCosmic=True,bulkProcessing=False, dropNonReady=True):
30 print (
"ERROR: Can't access COOLONL_TDAQ/CONDBR2")
33 fmode=tdaqdb.getFolder(
"/TDAQ/RunCtrl/DataTakingMode")
36 until=((1+runnum)<<32)-1
39 itr=fmode.browseObjects(since,until,cool.ChannelSelection.all())
43 isReady=pl[
"ReadyForPhysics"]
44 lb1=
max(since,obj.since()) & 0xFFFFFFFF
52 print (
"Ignoring LumiBlocks %i - %i not ATLAS READY" % (lb1,lb2))
53 badLBs.update(
range(lb1,lb2))
54 nNotReadyLBs+=(lb2-lb1)
62 tdaqdb.closeDatabase()
64 print (
"Run %i goes up to LB %i" % (runnum,maxLb))
69 stream =
'physics_CosmicCalo'
71 serverstring=
"https://%s@atlasdqm.cern.ch" % password
72 server = xmlrpc.client.ServerProxy(serverstring)
73 multicall = xmlrpc.client.MultiCall(server)
76 run_spec = {
'source': source,
'high_run': runnum,
'low_run': runnum}
77 multicall.get_procpass_amitag_mapping(run_spec)
79 if len(results[0])==0:
80 print (
"Nothing found about run",runnum,
"on DQM server")
83 list = results[0][
str(runnum)]
85 if (
"f" in item[2]
and bulkProcessing
and "CosmicCalo" in item[1]
and item[0]>proc):
87 if (
"x" in item[2]
and (
not bulkProcessing)
and "CosmicCalo" in item[1]
and item[0]>proc):
92 except Exception
as e:
93 print (
"ERROR: can't retrieve the AMI Tag")
97 print (
"I haven't found any processing version for CosmicCalo. Assume express processing")
102 multicall = xmlrpc.client.MultiCall(server)
103 run_spec = {
'source': source,
'high_run': runnum,
'stream': stream,
'proc_ver': proc,
'low_run': runnum}
104 multicall.get_timestamp(run_spec)
106 timestamp=results[0][
str(runnum)]
107 from time
import asctime,localtime
108 print (
"DQM server timestamp:", asctime(localtime(timestamp)))
109 print (
"Now: ",asctime())
110 except Exception
as e:
111 print (
"ERROR: can't get timestamp from DQM server")
115 multicall = xmlrpc.client.MultiCall(server)
116 run_spec = {
'source': source,
'high_run': runnum,
'stream': stream,
'proc_ver': proc,
'low_run': runnum}
117 multicall.get_dqmf_all_results(run_spec,
'LAr/LAR_GLOBAL/Collisions-Bkg/LArCollTimeLumiBlockTimeCut')
118 results = multicall()
119 RE = re.compile(
r'\((?P<lb>\S+)\.0*\)')
122 list = results[0][
str(runnum)]
126 m = RE.search(item).groupdict()
128 ncollisions=
int(results[0][
str(runnum)][item])
131 print (
"LumiBlock %i ignored because it is empty bunches are polluted with collisions" % lb)
134 except Exception
as e:
135 print (
"ERROR: can't get LArCollTimeLumiBlockTimeCut from DQM server")
138 if (burstsFromCosmic):
139 histoName = {
'EMBC':
'BarrelC',
'EMBA':
'BarrelA',
'EMECC':
'EMECC',
'EMECA':
'EMECA'}
140 for iPart
in histoName.keys():
141 multicall = xmlrpc.client.MultiCall(server)
143 multicall.get_dqmf_all_results(run_spec,
'/LAr/%s/Occupancy-Noise/Noise_Burst/NoisyEvent_TimeVeto_%s'%(iPart,iPart))
145 results = multicall()
147 resultlist = results[0][
str(runnum)]
149 for item
in resultlist:
153 m = RE.search(item).groupdict()
155 yieldbursts=
float(results[0][
str(runnum)][item])
158 print (
"LumiBlock %i ignored because it contains bursts in CosmicCalo stream in %s" % (lb,iPart))
161 except Exception
as e:
162 print (
"ERROR: can't get NoisyEvent from DQM server")
171 lar_defects = [d
for d
in (db.defect_names | db.virtual_defect_names)
if d.startswith(
"LAR")]
172 defects = db.retrieve((runnum, minLb), (runnum, maxLb), lar_defects)
173 for defect
in defects:
174 part=defect.channel.split(
"_")[1]
176 if "HVTRIP" in defect.channel
and defect.present:
177 for lb
in range(defect.since.lumi,defect.until.lumi):
179 print (
"LumiBlock %i ignored because of a HV trip in partition %s" % (lb,part))
183 if (
not burstsFromCosmic):
184 if not bulkProcessing:
185 if "NOISEBURST" in defect.channel
and defect.present:
186 for lb
in range(defect.since.lumi,defect.until.lumi):
188 print (
"LumiBlock %i ignored because of a noise burst in partition %s" % (lb,part))
192 if "SEVNOISEBURST" in defect.channel
and defect.present:
193 for lb
in range(defect.since.lumi,defect.until.lumi):
195 print (
"LumiBlock %i ignored because of a severe noise burst in partition %s" % (lb,part))
203 nBadLBs=nBadLBs-nNotReadyLBs
205 print (
"Found %i not-ready LBs, %i atlas-ready LBs and %i bad LBs" % (nNotReadyLBs,nReadyLBs,nBadLBs))
213 if __name__ ==
"__main__":
215 if len(sys.argv) == 1 :
217 print (
"usage: python %s <options> <runnumber> "%(sys.argv[0]))
221 burstsFromCosmic=
True
227 opts,args=getopt.getopt(sys.argv[1:],
"brco:",[])
230 burstsFromCosmics=
False
239 print (
"No run number found")
243 print (
"Too many arguments")
249 print (
"Searching for bad lumi blocks in run %d for bulk processing"%run)
251 print (
"Searching for bad lumi blocks in run %d for express processing"%run)
254 print (
"LB not marked as AtlasReady will be considered bad")
256 print (
"LB not marked as AtlasReady will be considered good")
263 print (
"LBs to ignore:",badLBsorted)
265 if outputFN
is not None:
267 out.write(
', '.
join([
str(i)
for i
in badLBsorted ]))