Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:46

0001 import urllib2, re, json, socket
0002 import sys
0003 
0004 URL = "http://vocms00170: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   req = urllib2.Request("%s/query/%s/data?%s" % (URL, query(q), qstring(qs)), headers={"Accept" : "application/json"})
0035   resp = urllib2.urlopen(req)
0036   if "getcode" in dir(resp) and resp.getcode() == 200:
0037     ret = json.loads(resp.read())
0038     if len(ret["data"]) > 0:
0039       return ret["data"][0][0]
0040   return None
0041 
0042 def get_all(q, qs):
0043   qid = query(q)
0044   ps = qstring(qs)
0045   u = "%s/query/%s/count?%s" % (URL, qid, ps)
0046   resp = urllib2.urlopen(u)
0047   if "getcode" in dir(resp) and resp.getcode() == 200:
0048     data = []
0049     c = int(resp.read())
0050     p = 1
0051     while c > 0:
0052       u = "%s/query/%s/page/1000/%d/data?%s" % (URL, qid, p, ps)
0053       req = urllib2.Request(u, headers={"Accept" : "application/json"})
0054       resp = urllib2.urlopen(req)
0055       if "getcode" in dir(resp) and resp.getcode() == 200:
0056         j = json.loads(resp.read())
0057         data.extend(j["data"])
0058       p += 1
0059       c -= 1000
0060     return data
0061   return None
0062 
0063 def main(rf, rt):
0064   ps = {}
0065   if rf != None: ps["rf"] = rf
0066   if rt != None: ps["rt"] = rt
0067   data = get_all(SQL, ps)
0068   for r in data:
0069     if r[3] != None:
0070       for t in ["pedestal","LED","laser"]:
0071         if re.search(t, r[3], flags=re.IGNORECASE) != None:
0072           d = get_single(TIME, { "p.run": int(r[0])}) 
0073           if d is not None:
0074             d = "\"" + d + "\""
0075           print r[0], t, d, r[2]
0076           break
0077   
0078 
0079 if __name__ == '__main__':
0080   
0081   rf = sys.argv[1] if len(sys.argv) > 1 else "-"
0082   rt = sys.argv[2] if len(sys.argv) > 2 else "-"
0083   rf = int(rf) if rf.isdigit() else 0
0084   rt = int(rt) if rt.isdigit() else 0
0085 
0086   main(rf, rt)