Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:27

0001 import urllib2, re, simplejson as json, socket
0002 import sys
0003 
0004 URL = "http://vocms00169:2113"
0005 SQL = "select \
0006         r.RUNNUMBER,\
0007         r.START_TIME,\
0008         r.RUN_TRIGGERS,\
0009         r.RUN_TYPE\
0010       from \
0011         hcal.runs r \
0012       where \
0013         r.RUN_GLOBAL = 0 and \
0014         (r.runnumber >= :rf or :rf = 0) and \
0015         (r.runnumber <= :rt or :rt = 0) \
0016       order by \
0017         r.runnumber"
0018 
0019 TIME = "select to_char(p.time,'YYYY-MM-DD HH24:MI:SS') time from hcal.run_parameters p where p.name like '%TRIGGERS'"
0020 
0021 def query(query):
0022   resp = urllib2.urlopen(URL + "/query", query)
0023   if "getcode" in dir(resp) and resp.getcode() == 200:
0024     return resp.read()
0025 
0026 def qstring(qstring):
0027   ps = ""
0028   for k in qstring.keys():
0029     ps += "&" if ps != "" else ""
0030     ps += "%s=%s" % (k, qstring[k])
0031   return ps
0032 
0033 def get_single(q, qs):
0034   resp = urllib2.urlopen("%s/query/%s/data?%s" % (URL, query(q), qstring(qs)))
0035   if "getcode" in dir(resp) and resp.getcode() == 200:
0036     return json.loads(resp.read())["data"][0][0]
0037   return None
0038 
0039 def get_all(q, qs):
0040   qid = query(q)
0041   ps = qstring(qs)
0042   u = "%s/query/%s/count?%s" % (URL, qid, ps)
0043   resp = urllib2.urlopen(u)
0044   if "getcode" in dir(resp) and resp.getcode() == 200:
0045     data = []
0046     c = int(resp.read())
0047     p = 1
0048     while c > 0:
0049       u = "%s/query/%s/page/1000/%d/data?%s" % (URL, qid, p, ps)
0050       resp = urllib2.urlopen(u)
0051       if "getcode" in dir(resp) and resp.getcode() == 200:
0052         j = json.loads(resp.read())
0053         data.extend(j["data"])
0054       p += 1
0055       c -= 1000
0056     return data
0057   return None
0058 
0059 def main(rf, rt):
0060   ps = {}
0061   if rf != None: ps["rf"] = rf
0062   if rt != None: ps["rt"] = rt
0063   data = get_all(SQL, ps)
0064   for r in data:
0065     if r[3] != None:
0066       for t in ["pedestal","LED","laser"]:
0067         if re.search(t, r[3], flags=re.IGNORECASE) != None:
0068           d = get_single(TIME, { "p.run": int(r[0])}) 
0069           print r[0], t, "\"" + d + "\"", r[2]
0070           break
0071   
0072 
0073 if __name__ == '__main__':
0074   
0075   rf = sys.argv[1] if len(sys.argv) > 1 else "-"
0076   rt = sys.argv[2] if len(sys.argv) > 2 else "-"
0077   rf = int(rf) if rf.isdigit() else 0
0078   rt = int(rt) if rt.isdigit() else 0
0079 
0080   main(rf, rt)