ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/python/frogRun/getRunInfo.py
Revision: 1.3
Committed: Tue Dec 2 08:41:33 2008 UTC (16 years, 4 months ago) by querten
Content type: text/x-python
Branch: MAIN
CVS Tags: Version_1_107, Version_1_106, HEAD
Changes since 1.2: +0 -0 lines
Log Message:
Go to Version_1.20 of frogRun

File Contents

# Content
1 #!/usr/bin/env python
2
3 #
4 # $Id: getRunInfo.py,v 1.3.2.5 2008/10/29 20:46:59 vadler Exp $
5 #
6
7 ## CMSSW/DQM/SiStripMonitorClient/scripts/getRunInfo.py
8 #
9 # For a given run, this script collects information useful for SiStrip DQM
10 # from web sources.
11 # Questions and comments to: volker.adler@cern.ch
12
13
14 import sys
15 import os
16 import string
17 import urllib
18 import datetime
19
20 # Constants
21
22 # numbers
23 INT_offset = 8
24 # strings
25 STR_SiStrip = 'SIST'
26 #STR_wwwDBSData = 'https://cmsweb.cern.ch/dbs_discovery/getData'
27 STR_wwwDBSData = '/dbs_discovery/getData'
28 LSTR_dbsInstances = ['cms_dbs_caf_analysis_01',
29 'cms_dbs_prod_global' ]
30 STR_headDatasets = 'datasets'
31 STR_headFiles = 'available data files'
32 DICT_htmlTags = {}
33 DICT_htmlTags['GLOBAL_NAME'] = 'global name '
34 DICT_htmlTags['STATUS'] = 'status '
35 DICT_htmlTags['IN_DBS'] = 'in DBS '
36 DICT_htmlTags['SUBSYSTEMS'] = 'subsystems '
37 DICT_htmlTags['EVENTS'] = '# of triggers '
38 DICT_htmlTags['START_TIME'] = 'start time (local) '
39 DICT_htmlTags['END_TIME'] = 'end time (local) '
40 DICT_htmlTags['L1KEY'] = 'L1 key '
41 DICT_htmlTags['HLTKEY'] = 'HLT key '
42 DICT_htmlTags['L1SOURCES'] = 'L1 sources '
43 DICT_htmlTags['RUN_RATE'] = 'event rate (Hz) '
44 DICT_htmlTags['STOP_REASON'] = 'stop reason '
45 DICT_htmlTags['SHIFTER'] = 'DQM shifter '
46 DICT_htmlTags['CREATE_USER'] = 'entry created by '
47 DICT_htmlTags['CREATE_TIME'] = 'entry creation time '
48 DICT_htmlTags['ONLINE_COMMENT'] = 'DQM online shifter\'s comment '
49 DICT_htmlTags['OFFLINE_COMMENT'] = 'DQM offline shifter\'s comment'
50
51 # Globals
52
53 global Str_run
54 global Dict_cmsmonRunRegistry
55 global DictDict_dbsDatasets
56 global DictDict_dbsEvents
57 global Dict_dbsDatasets
58 global Dict_maxLenDbsDatasets
59 # initialise
60 Str_run = sys.argv[1]
61 Dict_cmsmonRunRegistry = {}
62 DictDict_dbsDatasets = {}
63 DictDict_dbsEvents = {}
64 Dict_dbsDatasets = {}
65 Dict_maxLenDbsDatasets = {}
66
67 ## FUNCTIONS
68
69 ## Func_GetHtmlTags(str_text)
70 #
71 # Gets HTML tags from a string
72 def Func_GetHtmlTags(str_text):
73 """ Func_GetHtmlTags(str_text):
74 Gets HTML tags from a string
75 """
76 dict_tags = {}
77 # first look for tags w/ values
78 lstr_split = str_text.split('</')
79 for str_split in lstr_split[1:]:
80 str_key = str_split.split('>')[0]
81 dict_tags[str_key] = str_key in dict_tags
82 # second look for tags w/o values
83 lstr_split = str_text.split('/>')
84 for str_split in lstr_split[:-1]:
85 str_key = str_split.split('<')[-1].split()[0]
86 dict_tags[str_key] = str_key in dict_tags
87 return dict_tags
88
89 ## Func_GetHtmlTagValue(str_tag, str_text)
90 #
91 # Gets the value of the n-th oocurence a given HTML tag from a string
92 def Func_GetHtmlTagValue(str_tag, str_text, int_index = 1):
93 """ Func_GetHtmlTagValue(str_tag, str_text):
94 Gets the value of the n-th oocurence a given HTML tag from a string
95 """
96 if int_index > str_text.count('<'+str_tag):
97 return ''
98 str_1 = str_text.split('<'+str_tag)[int_index]
99 if str_1[0] != '>':
100 if str_1.split('>')[0][-1] == '/':
101 return ''
102 return str_1.split('>',1)[1].split('</'+str_tag+'>')[0]
103
104 ## Func_GetHtmlTagValues(str_text)
105 #
106 # Gets HTML tag values from a string
107 def Func_GetHtmlTagValues(str_text):
108 """ Func_GetHtmlTagValues(str_text):
109 Gets HTML tag values from a string
110 """
111 lstr_split = str_text.split('</')
112 lstr_values = []
113 for str_split in lstr_split[:-1]:
114 lstr_values.append(str_split.split('>')[-1])
115 return lstr_values
116
117 ## Func_GetHtmlTagValueAttr(str_tag, str_text)
118 #
119 # Gets the (last) attribute of a given HTML tag value from a string
120 def Func_GetHtmlTagValueAttr(str_value, str_text):
121 """ Func_GetHtmlTagValueAttr(str_value, str_text):
122 Gets the (last) attributes of a given HTML tag value from a string
123 """
124 return str_text.split('\">'+str_value+'<')[0].split('=\"')[-1]
125
126 ## Func_FillInfoRunRegistry()
127 #
128 # Retrieves run info from RunRegistry and fills it into containers
129 def Func_FillInfoRunRegistry():
130 """ Func_FillInfoRunRegistry():
131 Retrieves run info from RunRegistry and fills it into containers
132 """
133 str_cmsmonRunRegistry = urllib.urlencode({'format':'xml', 'intpl':'xml', 'qtype':'RUN_NUMBER', 'sortname':'RUN_NUMBER'})
134 file_cmsmonRunRegistry = urllib.urlopen("http://pccmsdqm04.cern.ch/runregistry/runregisterdata", str_cmsmonRunRegistry)
135 str_cmsmonRunRegistryLong = ''
136 for str_cmsmonRunRegistry in file_cmsmonRunRegistry.readlines():
137 str_cmsmonRunRegistryLong += str_cmsmonRunRegistry.splitlines()[0]
138 bool_foundRun = False
139 str_cmsmonRun = ''
140 for int_runIndex in range(1,int(str_cmsmonRunRegistryLong.split('<RUNS')[1].split('>')[0].split('total=\"')[1].split('\"')[0])):
141 str_cmsmonRun = Func_GetHtmlTagValue('RUN', str_cmsmonRunRegistryLong, int_runIndex)
142 if Func_GetHtmlTagValue('NUMBER', str_cmsmonRun) == Str_run:
143 bool_foundRun = True
144 break
145 if not bool_foundRun:
146 print '> getRunInfo.py > run ' + Str_run + ' not found in run registry'
147 return False
148 dict_cmsmonHtmlTags = Func_GetHtmlTags(str_cmsmonRun)
149 for str_cmsmonHtmlTag in dict_cmsmonHtmlTags.keys():
150 if dict_cmsmonHtmlTags[str_cmsmonHtmlTag] == False:
151 Dict_cmsmonRunRegistry[str_cmsmonHtmlTag] = Func_GetHtmlTagValue(str_cmsmonHtmlTag, str_cmsmonRun)
152 if Dict_cmsmonRunRegistry['SUBSYSTEMS'].find(STR_SiStrip) < 0:
153 print '> getRunInfo.py > SiStrip was not in this run'
154 return False
155 return True
156
157 ## Func_FillInfoDBS(str_dbsInstance)
158 #
159 # Retrieves run info from DBS and fills it into containers
160 def Func_FillInfoDBS(str_dbsInstance):
161 """ Func_FillInfoDBS(str_dbsInstance)
162 Retrieves run info from DBS and fills it into containers
163 """
164 str_dbsRuns = urllib.urlencode({'ajax':'0', '_idx':'0', 'pagerStep':'0', 'userMode':'user', 'release':'Any', 'tier':'Any', 'dbsInst':str_dbsInstance, 'primType':'Any', 'primD':'Any', 'minRun':Str_run, 'maxRun':Str_run})
165 file_dbsRuns = urllib.urlopen("https://cmsweb.cern.ch/dbs_discovery/getRunsFromRange", str_dbsRuns)
166 lstr_dbsRuns = []
167 lstr_dbsDatasets = []
168 dict_dbsDatasets = {}
169 dict_dbsEvents = {}
170 for str_dbsRuns in file_dbsRuns.readlines():
171 lstr_dbsRuns.append(str_dbsRuns)
172 if str_dbsRuns.find(STR_wwwDBSData) >= 0:
173 if str_dbsRuns.split('&amp;proc=')[1].find('&amp;') >= 0:
174 lstr_dbsDatasets.append(str_dbsRuns.split('&amp;proc=')[1].split('&amp;')[0])
175 else:
176 lstr_dbsDatasets.append(str_dbsRuns.split('&amp;proc=')[1])
177 int_maxLenDbsDatasets = 0
178 for str_dbsDataset in lstr_dbsDatasets:
179 str_dbsLFN = urllib.urlencode({'dbsInst':str_dbsInstance, 'blockName':'*', 'dataset':str_dbsDataset, 'userMode':'user', 'run':Str_run})
180 file_dbsLFN = urllib.urlopen("https://cmsweb.cern.ch/dbs_discovery/getLFNlist", str_dbsLFN)
181 lstr_dbsLFN = []
182 int_events = 0
183 for str_dbsLFN in file_dbsLFN.readlines():
184 lstr_dbsLFN.append(str_dbsLFN)
185 if str_dbsLFN.find('contians') >= 0 and str_dbsLFN.find('file(s)'): # FIXME: be careful, this typo might be corrected sometimes on the web page...
186 dict_dbsDatasets[str_dbsDataset] = str_dbsLFN.split()[1]
187 if str_dbsLFN.startswith('/store/data/'):
188 int_events += int(Func_GetHtmlTagValue('td' ,lstr_dbsLFN[len(lstr_dbsLFN)-4]))
189 dict_dbsEvents[str_dbsDataset] = str(int_events)
190 if len(str_dbsDataset) > int_maxLenDbsDatasets:
191 int_maxLenDbsDatasets = len(str_dbsDataset)
192 DictDict_dbsDatasets[str_dbsInstance] = dict_dbsDatasets
193 DictDict_dbsEvents[str_dbsInstance] = dict_dbsEvents
194 Dict_dbsDatasets[str_dbsInstance] = lstr_dbsDatasets
195 Dict_maxLenDbsDatasets[str_dbsInstance] = int_maxLenDbsDatasets
196
197 ## MAIN PROGRAM
198
199 print
200 print '> getRunInfo.py > information on run \t*** %s ***' %(Str_run)
201 print
202
203 # Get run information from the web
204
205 # get run RunRegistry entries
206 bool_runRegistry = Func_FillInfoRunRegistry()
207
208 # get run DBS entries
209 for str_dbsInstance in LSTR_dbsInstances:
210 Func_FillInfoDBS(str_dbsInstance)
211
212 # Print information
213
214 # from run registry
215 if bool_runRegistry:
216 print
217 print '> getRunInfo.py > * information from run registry *'
218 print
219 for str_htmlTag in DICT_htmlTags.keys():
220 if str_htmlTag in Dict_cmsmonRunRegistry:
221 print '> getRunInfo.py > %s: %s' %(DICT_htmlTags[str_htmlTag],Dict_cmsmonRunRegistry[str_htmlTag])
222
223 # from DBS
224 print
225 print '> getRunInfo.py > * information from DBS *'
226 print
227 for str_dbsInstance in LSTR_dbsInstances:
228 print '> getRunInfo.py > DBS instance: %s' %(str_dbsInstance)
229 if str_dbsInstance == LSTR_dbsInstances[0]:
230 print ' (This is the instance used at CAF!)'
231 str_print = '> getRunInfo.py > ' + STR_headDatasets
232 for int_i in range(Dict_maxLenDbsDatasets[str_dbsInstance]-len(STR_headDatasets)):
233 str_print += ' '
234 str_print += ' '
235 int_length = len(str_print)
236 print '%s%s' %(str_print,STR_headFiles)
237 str_print = ' '
238 for int_i in range(int_length-16+len(STR_headFiles)/2+INT_offset+8):
239 str_print += '-'
240 print str_print
241 for str_dbsDataset in Dict_dbsDatasets[str_dbsInstance]:
242 str_print = ' ' + str_dbsDataset
243 for int_i in range(Dict_maxLenDbsDatasets[str_dbsInstance]-len(str_dbsDataset)):
244 str_print += ' '
245 str_print += ' '
246 for int_i in range(len(STR_headFiles)/2-len(DictDict_dbsDatasets[str_dbsInstance][str_dbsDataset])):
247 str_print += ' '
248 str_print += DictDict_dbsDatasets[str_dbsInstance][str_dbsDataset] + ' ('
249 for int_i in range(INT_offset-len(DictDict_dbsEvents[str_dbsInstance][str_dbsDataset])):
250 str_print += ' '
251 print '%s%s events)' %(str_print,DictDict_dbsEvents[str_dbsInstance][str_dbsDataset])
252 print