ATLAS Offline Software
Loading...
Searching...
No Matches
athena_checkUpload.py
Go to the documentation of this file.
2
8
9import os,sys,time,glob,fnmatch, string, datetime
10from time import gmtime, strftime
11import urllib,urllib2
12from Ft.Xml.Domlette import NonvalidatingReader
13
14
17def StartDate(period):
18
19 start_date = (datetime.date.today() - datetime.timedelta(period)).isoformat()
20 return start_date
21
22
23def ConvertedRunNumber(rNumber):
24 RNumber = long(rNumber)
25 return RNumber << 32
26
27
28def RunListInDBTotal(start_date, end_date, file_name, string_pattern):
29 prefix="http://atlas-service-runinformation.web.cern.ch/atlas-service-runinformation/cgi-bin/runnumbers.py?"
30 url=prefix+"start.date="+start_date+"%2012:06:00&end.date="+end_date+"%2012:06:00&format=html"
31 # print(url)
32 request=urllib2.Request(url)
33 u=urllib2.urlopen(request)
34 DocString = u.read()
35
36 DocString_1 = DocString.replace ( '<td>', ' ' )
37 DocString_2 = DocString_1.replace ( '</td>', ' ' )
38 DocString_3 = DocString_2.replace ( '<tr>', ' ' )
39 DocString_4 = DocString_3.replace ( '</tr>', ' ' )
40 DocString_5 = DocString_4.replace ( '<th>Name</th><th>Number</th><th>Start At (UTC)</th><th>Duration</th><th>Partition</th>', ' ' )
41
42
43 f=open(file_name, 'w')
44 f.write(DocString_5)
45 f.close()
46
47 Runs = []
48 if os.path.exists(file_name):
49 f = open(file_name,'r')
50 for line in f.readlines():
51 if line.find(string_pattern)>= 0:
52 ar=string.split(line)
53 Runs.append(int(ar[1]))
54 f.close()
55 else:
56 print("-->ERROR: athena_checkUpload: Can't find input file !")
57
58
59 os.remove(file_name)
60
61 return Runs
62
63
64def channelValueQuery(server, schema, dbname, folder, iov0, iov1, tag, channels):
65 timespan= str(iov0) + '-' + str(iov1)
66 prefix='http://coolcherrypy.cern.ch:8080/cooldb/'
67 d = '/'
68 url = prefix+server+d+schema+d+dbname+folder+'/timespan/'+timespan+'/tag/'+tag+'/channels/'+channels
69 httpHeaders={'Accept':'text/xml'}
70 textData=None
71 #print(url)
72 request=urllib2.Request(url,textData, httpHeaders)
73 u=urllib2.urlopen(request)
74 xmlDocString = u.read()
75 return xmlDocString
76
77
78def RunListInDB(array, server, schema, dbname, folder, tag, channels):
79 Array_runsInDB=[]
80 if (len(array) != 0):
81 for i in range(len(array)):
82 runNumber=array[i]
83 iovSince=ConvertedRunNumber(runNumber)
84 iovUntil=ConvertedRunNumber(runNumber+1)-1
85
86 derived_string=channelValueQuery(server, schema, dbname, folder, iovSince, iovUntil, tag, channels)
87
88 derived=NonvalidatingReader.parseString(derived_string,uri="dummy")
89 numNoisyModules=derived.xpath(u'count(//channel)')
90
91 if numNoisyModules !=0.0:
92 Array_runsInDB.append(runNumber)
93 else:
94 Array_runsInDB.append(-999)
95
96 return Array_runsInDB
97
98
99
100def GetNumberOfNoisyModulesInDB(array, server, schema, dbname, folder, tag, channels):
101 Array_numNoisyModules=[]
102 if (array[0] != -999):
103 for i in range(len(array)):
104 runNumber=array[i]
105 iovSince=ConvertedRunNumber(runNumber)
106 iovUntil=ConvertedRunNumber(runNumber+1)-1
107
108 derived_string=channelValueQuery(server, schema, dbname, folder, iovSince, iovUntil, tag, channels)
109
110 derived=NonvalidatingReader.parseString(derived_string,uri="dummy")
111 numNoisyModules=derived.xpath(u'count(//channel)')
112 if numNoisyModules !=0.0:
113 Array_numNoisyModules.append(numNoisyModules)
114 else:
115 Array_numNoisyModules.append(-999)
116
117 return Array_numNoisyModules
118
119
120def GetNumberOfNoisyStripsInDB(array, server, schema, dbname, folder, tag, channels):
121 Array_numNoisyStrips = []
122 if (array[0] != -999):
123 for i in range(len(array)):
124 runNumber=array[i]
125 iovSince=ConvertedRunNumber(runNumber)
126 iovUntil=ConvertedRunNumber(runNumber+1)-1
127
128 derived_string=channelValueQuery(server, schema, dbname, folder, iovSince, iovUntil, tag, channels)
129
130 derived=NonvalidatingReader.parseString(derived_string,uri="dummy")
131 numNoisyModules=derived.xpath(u'count(//channel)')
132 if numNoisyModules !=0.0:
133
134 allDefectStripsList=(derived.xpath(u"//channel/value[@name='DefectList']"))
135 numNoisyStrips=0
136 numNoisyStripsAdds=0
137
138 for strips in allDefectStripsList:
139 words=strips.firstChild.data.split()
140 for j in range(len(words)):
141 jk=words[j]
142 if jk.find("-")>=0:
143 sep=jk.replace ( '-', ' ' )
144 sep1=sep.split()
145 numNoisyStripsAdds=numNoisyStripsAdds+int(sep1[1])-int(sep1[0])
146
147 numNoisyStrips=numNoisyStrips+len(strips.firstChild.data.split())
148
149 Array_numNoisyStrips.append(numNoisyStrips + numNoisyStripsAdds)
150
151 else:
152 Array_numNoisyStrips.append(-999)
153
154 return Array_numNoisyStrips
155
156
158 sum=0
159 if (len(array) != 0):
160 for j in range(len(array)):
161 sum=sum+array[j]
162 NoisyModulesAverage = sum/len(array)
163 else:
164 NoisyModulesAverage = -999
165 return NoisyModulesAverage
166
167
168def DisplayInfoForRunsInDB(runs, noisy_mods, noisy_strips):
169 if (len(runs) != 0):
170 for i in range(len(runs)):
171 print("Run: ",runs[i], " --> Num. noisy modules: ", noisy_mods[i], " --> Num. noisy channels: ", noisy_strips[i])
172 else:
173 print("--> No information found.")
174
175
179Period=7
180startDate=StartDate(Period)
181endDate=str(datetime.date.today())
182
183fileName="./runs_"+startDate+"_"+endDate+".txt"
184
185Server='ATLAS_COOLPROD'
186Schema='ATLAS_COOLOFL_SCT'
187Dbname='COMP200'
188Folder='/SCT/Derived/Monitoring'
189Tag='SctDerivedMonitoring-003-00'
190String_Pattern='ATLAS'
191# String_Pattern='point-1'
192
193RunsInDBTotal=RunListInDBTotal(startDate, endDate, fileName, String_Pattern)
194RunsInDB=RunListInDB(RunsInDBTotal, Server,Schema,Dbname,Folder,Tag,'*')
195print(RunsInDB)
196numNoisyModulesInDB=GetNumberOfNoisyModulesInDB(RunsInDB, Server,Schema,Dbname,Folder,Tag,'*')
197noisyModulesAverageInDB=GetNoisyModulesAverageInDB(numNoisyModulesInDB)
198
199noisyStripsInDB=GetNumberOfNoisyStripsInDB(RunsInDB, Server,Schema,Dbname,Folder,Tag,'*')
200noisyStripsInDB_lastRun=noisyStripsInDB[0]
201
202
203print("------------> Runs in COOL DB since ", startDate, " until ", endDate, "<------------")
204DisplayInfoForRunsInDB(RunsInDB, numNoisyModulesInDB, noisyStripsInDB)
205print(" Average of number noisy modules for the above runs: ", noisyModulesAverageInDB)
206print(" Number of nosiy strips in the last uploaded run ", RunsInDB[0],": ", noisyStripsInDB_lastRun)
207print("--------------------------------------------------------------------------------")
208
209
void print(char *figname, TCanvas *c1)
RunListInDBTotal(start_date, end_date, file_name, string_pattern)
channelValueQuery(server, schema, dbname, folder, iov0, iov1, tag, channels)
GetNumberOfNoisyModulesInDB(array, server, schema, dbname, folder, tag, channels)
StartDate(period)
--> Definitions:
RunListInDB(array, server, schema, dbname, folder, tag, channels)
GetNumberOfNoisyStripsInDB(array, server, schema, dbname, folder, tag, channels)
DisplayInfoForRunsInDB(runs, noisy_mods, noisy_strips)