00001
00002
00003
00004
00005
00006 import time
00007 import pluginCondDBPyInterface as CondDB
00008
00009 class WhatDescription :
00010 def __init__(self,w) :
00011 self.__me = w
00012 self.__ret ={}
00013 def describe(self) :
00014 _w = self.__me
00015 _atts = (att for att in dir(self.__me) if not (att[0]=='_' or att[0:4]=='set_' or att[0:6]=='descr_'))
00016 for _att in _atts:
00017 exec('_a=_w.'+_att+'()')
00018 if (_a.__class__==CondDB.VInt):
00019 if(hasattr(self.__me,'descr_'+_att)) :
00020 self.multiple(_att)
00021 else :
00022 self.commaSeparated(_att)
00023 else :
00024 self.single(_att,_a)
00025 return self.__ret
00026
00027 def single(self,att,a) :
00028 self.__ret[att]=('single',[val for val in dir(a) if not (val[0]=='_' or val=='name'or val=='values')])
00029
00030 def multiple(self,att) :
00031 _w = self.__me
00032 exec('_d=_w.descr_'+att+'()')
00033 self.__ret[att]=('multiple',[val for val in _d])
00034
00035 def commaSeparated(self,att) :
00036 self.__ret[att]=('commaSeparated',[])
00037
00038
00039 def extractorWhat(db, tag) :
00040 exec('import '+db.moduleName(tag)+' as Plug')
00041 ret ={}
00042 w = WhatDescription(Plug.What())
00043 return w.describe()
00044
00045 def setWhat(w,ret) :
00046 for key in ret.keys():
00047 _val = ret[key]
00048 if (type(_val)==type([])) :
00049 _vi = CondDB.VInt()
00050 for i in _val :
00051 _vi.append(i)
00052 exec ('w.set_'+key+'(_vi)')
00053 else :
00054 exec ('w.set_'+key+'(w.'+key+'().'+ret[key]+')')
00055 return w
00056
00057
00058 class Iov :
00059 def __init__(self, db, tag, since=0, till=0, head=0, tail=0) :
00060 self.__db = db
00061 self.__tag = tag
00062 try :
00063 self.__modName = db.moduleName(tag)
00064 exec('import '+self.__modName+' as Plug')
00065 except RuntimeError :
00066 self.__modName = 0
00067 self.__me = db.iov(tag)
00068 if (till) : self.__me.setRange(since,till)
00069 if (head) : self.__me.head(head)
00070 if (tail) : self.__me.tail(tail)
00071
00072 def list(self) :
00073 ret = []
00074 for elem in self.__me.elements :
00075 ret.append( (elem.payloadToken(), elem.since(), elem.till(),0))
00076 return ret
00077
00078 def payloadSummaries(self):
00079 ret = []
00080 for elem in self.__me.elements:
00081 payloadtoken=elem.payloadToken()
00082 exec('import '+self.__db.moduleName(payloadtoken)+' as Plug')
00083 payload = Plug.Object(self.__db.payLoad(payloadtoken))
00084 ret.append(payload.summary())
00085 return ret
00086
00087 def summaries(self) :
00088 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no summaries"]
00089 exec('import '+self.__modName+' as Plug')
00090 ret = []
00091 for elem in self.__me.elements :
00092 p = Plug.Object(elem)
00093 ret.append( (elem.payloadToken(), elem.since(), elem.till(), p.summary()))
00094 return ret
00095
00096 def trend(self, what) :
00097 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
00098 exec('import '+self.__modName+' as Plug')
00099 ret = []
00100 w = setWhat(Plug.What(),what)
00101 ex = Plug.Extractor(w)
00102 for elem in self.__me.elements :
00103 p = Plug.Object(elem)
00104 p.extract(ex)
00105 v = [i for i in ex.values()]
00106 ret.append((elem.since(),elem.till(),v))
00107 return ret
00108
00109 def trendinrange(self, what, head, tail) :
00110 '''extract trend in the given range. the input parameters are in 64bit integer format. Users should pack the timestamp or lumiid before calling this method
00111 '''
00112 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
00113 exec('import '+self.__modName+' as Plug')
00114 ret = []
00115 w = setWhat(Plug.What(),what)
00116 ex = Plug.Extractor(w)
00117
00118 for elem in self.__me.elements :
00119 since = elem.since()
00120 till = elem.till()
00121 if (head < since < tail) or (since < head < till) or (since < tail < till):
00122 p = Plug.Object(elem)
00123 p.extract(ex)
00124 v = [i for i in ex.values()]
00125 ret.append((elem.since(),elem.till(),v))
00126 return ret
00127
00128 def timetype(self):
00129 return self.__me.timetype()
00130 def comment(self):
00131 return self.__me.comment()
00132 def revision(self):
00133 return self.__me.revision()
00134 def timestamp(self):
00135 return CondDB.unpackTime(self.__me.timestamp())
00136 def payloadContainerName(self):
00137 return self.__me.payloadContainerName()
00138 def payLoad(self, since):
00139 listOfIovElem= [iovElem for iovElem in self.__me.elements if iovElem.since() == since]
00140 IOVElem = listOfIovElem[0]
00141 exec('import '+self.__db.moduleName(IOVElem.payloadToken())+' as Plug')
00142 payload = Plug.Object(IOVElem)
00143
00144 return payload
00145
00146
00147
00148 class PayLoad :
00149 def __init__(self, db, token) :
00150 self.__db = db
00151 self.__token = token
00152 exec('import '+db.moduleName(token)+' as Plug')
00153
00154 self.__me = Plug.Object(db.payLoad(token))
00155
00156 def __str__(self) :
00157 return self.__me.dump()
00158
00159 def object(self) :
00160 return self.__me
00161
00162 def summary(self) :
00163 return self.__me.summary()
00164
00165 def dump(self) :
00166 return self.__me.dump()
00167
00168 def plot(self, fname, s, il, fl) :
00169 vi = CondDB.VInt()
00170 vf = CondDB.VFloat()
00171 for i in il:
00172 vi.append(int(i))
00173 for i in fl:
00174 vf.append(float(i))
00175 return self.__me.plot(fname,s,vi,vf)
00176
00177 def trend_plot(self, fname, s, il, fl, sl) :
00178 vi = CondDB.VInt()
00179 vf = CondDB.VFloat()
00180 vs = CondDB.VString()
00181 for i in il:
00182 vi.append(int(i))
00183 for i in fl:
00184 vf.append(float(i))
00185 for i in sl:
00186 vs.append(str(i))
00187 return self.__me.trend_plot(fname,s,vi,vf,vs)
00188
00189 def summary_adv(self, s, il, fl, sl):
00190
00191 vi = CondDB.VInt()
00192 vf = CondDB.VFloat()
00193 vs = CondDB.VString()
00194 for i in il:
00195 vi.append(int(i))
00196 for i in fl:
00197 vf.append(float(i))
00198 for i in sl:
00199 vs.append(str(i))
00200 return self.__me.summary_adv(s,vi,vf,vs)
00201
00202 def dumpFile(self, fname, s, il, fl, sl):
00203 vi = CondDB.VInt()
00204 vf = CondDB.VFloat()
00205 vs = CondDB.VString()
00206 for i in il:
00207 vi.append(int(i))
00208 for i in fl:
00209 vf.append(float(i))
00210 for i in sl:
00211 vs.append(str(i))
00212 return self.__me.dumpFile(fname,s,vi,vf,vs)