ATLAS Offline Software
athena_checkUpload.py
Go to the documentation of this file.
1 
2 
8 
9 import os,sys,time,glob,fnmatch, string, datetime
10 from time import gmtime, strftime
11 import urllib,urllib2
12 from Ft.Xml.Domlette import NonvalidatingReader
13 
14 
17 def StartDate(period):
18 
19  start_date = (datetime.date.today() - datetime.timedelta(period)).isoformat()
20  return start_date
21 
22 
23 def ConvertedRunNumber(rNumber):
24  RNumber = long(rNumber)
25  return RNumber << 32
26 
27 
28 def 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 
64 def 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 
78 def 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 
100 def 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 
120 def 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 
168 def 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 
179 Period=7
180 startDate=StartDate(Period)
181 endDate=str(datetime.date.today())
182 
183 fileName="./runs_"+startDate+"_"+endDate+".txt"
184 
185 Server='ATLAS_COOLPROD'
186 Schema='ATLAS_COOLOFL_SCT'
187 Dbname='COMP200'
188 Folder='/SCT/Derived/Monitoring'
189 Tag='SctDerivedMonitoring-003-00'
190 String_Pattern='ATLAS'
191 # String_Pattern='point-1'
192 
193 RunsInDBTotal=RunListInDBTotal(startDate, endDate, fileName, String_Pattern)
194 RunsInDB=RunListInDB(RunsInDBTotal, Server,Schema,Dbname,Folder,Tag,'*')
195 print(RunsInDB)
196 numNoisyModulesInDB=GetNumberOfNoisyModulesInDB(RunsInDB, Server,Schema,Dbname,Folder,Tag,'*')
197 noisyModulesAverageInDB=GetNoisyModulesAverageInDB(numNoisyModulesInDB)
198 
199 noisyStripsInDB=GetNumberOfNoisyStripsInDB(RunsInDB, Server,Schema,Dbname,Folder,Tag,'*')
200 noisyStripsInDB_lastRun=noisyStripsInDB[0]
201 
202 
203 print("------------> Runs in COOL DB since ", startDate, " until ", endDate, "<------------")
204 DisplayInfoForRunsInDB(RunsInDB, numNoisyModulesInDB, noisyStripsInDB)
205 print(" Average of number noisy modules for the above runs: ", noisyModulesAverageInDB)
206 print(" Number of nosiy strips in the last uploaded run ", RunsInDB[0],": ", noisyStripsInDB_lastRun)
207 print("--------------------------------------------------------------------------------")
208 
209 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
athena_checkUpload.RunListInDB
def RunListInDB(array, server, schema, dbname, folder, tag, channels)
Definition: athena_checkUpload.py:78
athena_checkUpload.GetNumberOfNoisyStripsInDB
def GetNumberOfNoisyStripsInDB(array, server, schema, dbname, folder, tag, channels)
Definition: athena_checkUpload.py:120
athena_checkUpload.DisplayInfoForRunsInDB
def DisplayInfoForRunsInDB(runs, noisy_mods, noisy_strips)
Definition: athena_checkUpload.py:168
athena_checkUpload.GetNumberOfNoisyModulesInDB
def GetNumberOfNoisyModulesInDB(array, server, schema, dbname, folder, tag, channels)
Definition: athena_checkUpload.py:100
athena_checkUpload.RunListInDBTotal
def RunListInDBTotal(start_date, end_date, file_name, string_pattern)
Definition: athena_checkUpload.py:28
athena_checkUpload.ConvertedRunNumber
def ConvertedRunNumber(rNumber)
Definition: athena_checkUpload.py:23
athena_checkUpload.GetNoisyModulesAverageInDB
def GetNoisyModulesAverageInDB(array)
Definition: athena_checkUpload.py:157
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
athena_checkUpload.channelValueQuery
def channelValueQuery(server, schema, dbname, folder, iov0, iov1, tag, channels)
Definition: athena_checkUpload.py:64
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Trk::open
@ open
Definition: BinningType.h:40
athena_checkUpload.StartDate
def StartDate(period)
--> Definitions:
Definition: athena_checkUpload.py:17
str
Definition: BTagTrackIpAccessor.cxx:11