CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaHLTBitMon_QueryRunRegistry.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #-----------------------------------------------------
4 # original author: Andrea Lucaroni
5 # Revision: $Revision: 1.4 $
6 # Last update: $Date: 2012/05/24 13:00:56 $
7 # by: $Author: taroni $
8 #-----------------------------------------------------
9 
10 from xml.dom import minidom
11 import re
12 import json
13 import os
14 import stat
15 import sys
16 
17 #include DBS
18 from DBSAPI.dbsApiException import DbsException
19 import DBSAPI.dbsApi
20 from DBSAPI.dbsApiException import *
21 
22 # include XML-RPC client library
23 # RR API uses XML-RPC webservices interface for data access
24 import xmlrpclib
25 
26 import array
27 import pickle as pk
28 
29 from optparse import OptionParser
30 #####DEBUG
31 DEBUG=0
32 import inspect
33 
34 def lineno():
35  """Returns the current line number in our program."""
36  return inspect.currentframe().f_back.f_lineno
37 
38 #size file
39 def filesize1(n):
40  info = os.stat(n)
41  sz = info[stat.ST_SIZE]
42  return sz
43 
44 ### lumiCalc
45 def printLumi(file,namefile):
46  if(filesize1(file) != 0):
47  string= "lumiCalc2.py -c frontier://LumiCalc/CMS_LUMI_PROD -i "
48  string1= " --nowarning overview >"
49  string2= string + file + string1 + namefile
50  data = os.system(string2)
51  else:
52  data = ""
53  print "0 lumi are not avaible"
54  return data
55 
56 ###file dbs
57 def DBSquery(dataset,site,run):
58 
59  url = "http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
60  if DEBUG:
61  print lineno()
62  args = {}
63  args['url'] = url
64  args['level'] = 'CRITICAL'
65  if DEBUG:
66  print lineno()
67  api = DBSAPI.dbsApi.DbsApi(args)
68  if DEBUG:
69  print lineno()
70  try:
71  files = api.listFiles(path=dataset,tier_list =site,runNumber=run)
72  except DbsApiException, ex:
73  print "Caught API Exception %s: %s " % (ex.getClassName(), ex.getErrorMessage() )
74  files = ""
75  if ex.getErrorCode() not in (None, ""):
76  print "DBS Exception Error Code: ", ex.getErrorCode()
77  if DEBUG:
78  print lineno()
79  return files
80 
81 ###file cff data
82 def makecff(file_list,namefile):
83  file1 = open(namefile ,'w')
84  stringS = "process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )\n"
85  stringS = stringS + "readFiles = cms.untracked.vstring()\n"
86  stringS = stringS + "secFiles = cms.untracked.vstring()\n"
87  stringS = stringS + "\n"
88  file1.write(stringS)
89 
90  filecount = 0
91  extendOpen = 0
92  for filename in file_list:
93 
94  if extendOpen == 0:
95  stringS = "readFiles.extend([\n"
96  file1.write(stringS)
97  extendOpen = 1
98 
99  stringS = " '"
100  stringS = stringS + str(filename)
101  stringS = stringS + "',\n"
102  file1.write(stringS)
103  filecount = filecount + 1
104  if filecount == 50:
105  stringS = "])\n\n"
106  file1.write(stringS)
107  filecount = 0
108  extendOpen = 0
109 
110  if extendOpen == 1:
111  stringS = "])\n\n"
112  file1.write(stringS)
113 
114  stringS = "process.source = cms.Source(\"PoolSource\",\n"
115  stringS = stringS + " fileNames = readFiles,\n"
116  stringS = stringS + " secondaryFileNames = secFiles\n"
117  stringS = stringS + ")\n"
118  file1.write(stringS)
119  file1.close()
120 
121 
123  parser = OptionParser()
124  parser.add_option("-w", "--workspace",
125  dest="workspaceName",
126  default="GLOBAL",
127  help="define workspace: GLOBAL TRACKER ")
128 
129  parser.add_option("-r", "--regexp",
130  dest="regexp",
131  type="string",
132  default='groupName : LIKE %Collisions12% , runNumber : = 190000 ',
133  help=" \"{runNumber} >= 148127 and {runNumber} < 148128 \" ")
134 
135  parser.add_option("-d", "--datasetPath",
136  dest="dataset", \
137  default="/MinimumBias/Run2010A-TkAlMinBias-Dec22ReReco_v1/ALCARECO",
138  help="For example : --datasetPath /MinimumBias/Run2010A-TkAlMinBias-Dec22ReReco_v1/ALCARECO")
139 
140  parser.add_option("-s", "--site",
141  dest="site",
142  default="T2_CH_CAF",
143  help="For example : site T2_CH_CAF")
144 
145  parser.add_option("-i", "--info",
146  action="store_true",
147  dest="info",
148  default=False,
149  help="printout the column names on which it's possible to cut")
150 
151  (options, args) = parser.parse_args()
152  if len(sys.argv) == 1:
153  print("\nUsage: %s --help"%sys.argv[0])
154  sys.exit(0)
155 
156  return options
157 
158 
159 def serverQuery(workspaceName,regexp):
160 
161  # get handler to RR XML-RPC server
162  server = xmlrpclib.ServerProxy('http://cms-service-runregistry-api.web.cern.ch/cms-service-runregistry-api/xmlrpc')
163  if DEBUG:
164  print lineno(), regexp
165  data = server.RunDatasetTable.export(workspaceName,'xml_all' ,regexp)
166  return data
167 
168 #----------------------------------------------------
169 
170 def getText(nodelist):
171  rc = ""
172  for node in nodelist:
173  if node.nodeType == node.TEXT_NODE:
174  rc = rc + node.data
175  return rc
176 
177 def getElement(obj,name):
178  return obj.getElementsByTagName(name)
179 
180 def printObj(obj,name):
181  return getText(getElement(obj,name)[0].childNodes)
182 
183 
184 def getData(doc,options,dataset,site):
185  if DEBUG:
186  print lineno(), 'getData'
187  server = xmlrpclib.ServerProxy('http://cms-service-runregistry-api.web.cern.ch/cms-service-runregistry-api/xmlrpc')
188  runs = getElement(doc,'RUN')
189  txtLongData=""
190  txtkey=""
191  lista=[]
192 
193  sep="\t"
194 
195  for run in runs:
196  txtrun=printObj(run,'NUMBER') + sep + printObj(run,'HLTKEY')
197  txtLongData+= txtrun + sep + "\n"
198  for run in runs:
199  test=printObj(run,'HLTKEY')
200  if not (test in lista):
201  lista.append(test)
202 
203  file2=open("lista_key.txt",'w')
204  for pkey in range(len(lista)):
205  pwkey = lista[pkey] +"\n"
206  file2.write(pwkey)
207  if DEBUG:
208  print lineno(), lista[pkey]
209 
210  file2.close()
211 
212  for i in range(len(lista)):
213  if DEBUG:
214  print lineno(), lista[i]
215  nameDBS=""
216  nameDBS=str(i)+".data"
217  name=""
218  name=str(i)+".json"
219  nameLumi=""
220  nameLumi=str(i)+".lumi"
221  file1 = open( name ,'w')
222  listaDBS = []
223  if DEBUG:
224  print lineno(), nameDBS
225  for run in runs:
226  key=printObj(run,'HLTKEY')
227  if (key == lista[i]):
228  print "running......", key
229  if DEBUG:
230  print lineno(), printObj(run,'NUMBER')
231  txtruns = "{runNumber} >= " + printObj(run,'NUMBER') + " and {runNumber} <= " + str(int(printObj(run,'NUMBER')))
232  txtriv = txtruns + " and {cmpDcsBPix} = 1 and {cmpDcsFPix} = 1 and {cmpDcsTibTid} = 1 and {cmpDcsTob} = 1 and {cmpDcsTecM} = 1 and {cmpDcsTecP} = 1"
233  lumirun = server.RunLumiSectionRangeTable.export('GLOBAL', 'json',txtriv)
234  if DEBUG:
235  print lineno(), lumirun
236  ###dbs file
237  if lumirun:
238  file = DBSquery(dataset,site,str(printObj(run,'NUMBER')))
239 ## if DEBUG:
240 ## print lineno(), file
241  if (file != "") :
242  for uno in file:
243  stringDBS = {}
244  stringDBS = uno['LogicalFileName']
245  listaDBS += [stringDBS]
246  if DEBUG:
247  print lineno(), lumirun
248  comp="{}"
249  if (lumirun == comp):
250  print "LUMI ZERO"
251  else:
252  file1.write(lumirun)
253 
254  file1.close()
255  string=""
256  string="sed -i 's/}{/, /g'"
257  string2=""
258  string2= string + " " + name
259  os.system(string2)
260  printLumi(name,nameLumi)
261  os.system("sed -i 's/\//_/g' lista_key.txt")
262  listaDBS2 =[]
263  for rootLSF in listaDBS:
264  if not (rootLSF in listaDBS2):
265  listaDBS2.append(rootLSF)
266  makecff(listaDBS2,nameDBS)
267 
268  return txtLongData
269 
270 #---------------------------------------------
271 
272 def extractData(mode,reg,dataset,site,options):
273  doc = minidom.parseString(serverQuery(mode,reg))
274  return getData(doc,options,dataset,site)
275 
276 def getRegExp(regexp):
277  items = regexp.split(',')
278  dd = {}
279  for item in items:
280  key,value = item.split(':')
281  dd[key.replace(' ','')] = value
282  return dd
283 
284 
285 #---------------------------------------------MAIN
286 
287 options = defineOptions()
288 data=extractData(options.workspaceName,options.regexp,options.dataset,options.site,options)
289 
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
if(dp >Float(M_PI)) dp-