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 self.__db.startReadOnlyTransaction()
00063 try :
00064 self.__modName = str(db.payloadModules(tag)[0])
00065 Plug = __import__(self.__modName)
00066 except RuntimeError :
00067 self.__modName = 0
00068 iov = db.iov(tag)
00069
00070
00071 self.__me = iov.range(iov.firstSince(), iov.lastTill())
00072 if (till) : self.__me = iov.range(since,till)
00073 if (head) : self.__me = iov.head(head)
00074 if (tail) : self.__me = iov.tail(tail)
00075 self.__timetype = iov.timetype()
00076 self.__comment = iov.comment()
00077 self.__revision = iov.revision()
00078 self.__timestamp = CondDB.unpackTime(iov.timestamp())
00079 self.__payloadClasses = list(iov.payloadClasses())
00080 self.__db.commitTransaction()
00081
00082 def list(self) :
00083 ret = []
00084 for elem in self.__me.elements :
00085 ret.append( (elem.payloadToken(), elem.since(), elem.till(),0))
00086 return ret
00087
00088 def payloadSummaries(self):
00089 ret = []
00090 self.__db.startReadOnlyTransaction()
00091 Plug = __import__(self.__modName)
00092 payload = Plug.Object(self.__db)
00093 for elem in self.__me.elements:
00094 payloadtoken=elem.payloadToken()
00095 payload.load(elem)
00096 ret.append(payload.summary())
00097 self.__db.commitTransaction()
00098 return ret
00099
00100 def summaries(self) :
00101 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no summaries"]
00102 self.__db.startReadOnlyTransaction()
00103 Plug = __import__(self.__modName)
00104 ret = []
00105 p = Plug.Object(self.__db)
00106 for elem in self.__me.elements :
00107 p.load(elem)
00108 ret.append( (elem.payloadToken(), elem.since(), elem.till(), p.summary()))
00109 self.__db.commitTransaction()
00110 return ret
00111
00112 def trend(self, what) :
00113 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
00114 self.__db.startReadOnlyTransaction()
00115 Plug = __import__(self.__modName)
00116 ret = []
00117 w = setWhat(Plug.What(),what)
00118 ex = Plug.Extractor(w)
00119 p = Plug.Object(self.__db)
00120 for elem in self.__me.elements :
00121 p.load(elem)
00122 p.extract(ex)
00123 v = [i for i in ex.values()]
00124 ret.append((elem.since(),elem.till(),v))
00125 self.__db.commitTransaction()
00126 return ret
00127
00128 def trendinrange(self, what, head, tail) :
00129 '''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
00130 '''
00131 if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
00132 self.__db.startReadOnlyTransaction()
00133 Plug = __import__(self.__modName)
00134 ret = []
00135 w = setWhat(Plug.What(),what)
00136 ex = Plug.Extractor(w)
00137
00138 p = Plug.Object(self.__db)
00139 for elem in self.__me.elements :
00140 since = elem.since()
00141 till = elem.till()
00142 if (head < since < tail) or (since < head < till) or (since < tail < till):
00143 p.load(elem)
00144 p.extract(ex)
00145 v = [i for i in ex.values()]
00146 ret.append((elem.since(),elem.till(),v))
00147 self.__db.commitTransaction()
00148 return ret
00149
00150 def timetype(self):
00151 return self.__timetype
00152 def comment(self):
00153 return self.__comment
00154 def revision(self):
00155 return self.__revision
00156 def timestamp(self):
00157 return self.__timestamp
00158 def payloadClasses(self):
00159 return self.__payloadClasses
00160 def payLoad(self, since):
00161 listOfIovElem= [iovElem for iovElem in self.__me.elements if iovElem.since() == since]
00162 IOVElem = listOfIovElem[0]
00163 self.__db.startReadOnlyTransaction()
00164 Plug = __import__(self.__modName)
00165 payload = Plug.Object(self.__db)
00166 payload.load(IOVElem)
00167 self.__db.commitTransaction()
00168
00169 return payload
00170
00171
00172
00173 class PayLoad :
00174 def __init__(self, db, tag, elem) :
00175 self.__db = db
00176 self.__tag = tag
00177 self.__elem = elem
00178 self.__db.startReadOnlyTransaction()
00179 self.__modName = str(db.payloadModules(tag)[0])
00180 Plug = __import__(self.__modName)
00181 self.__me = Plug.Object(db)
00182 self.__me.load(elem)
00183 self.__db.commitTransaction()
00184
00185 def __str__(self) :
00186 return self.__me.dump()
00187
00188 def object(self) :
00189 return self.__me
00190
00191 def summary(self) :
00192 return self.__me.summary()
00193
00194 def dump(self) :
00195 return self.__me.dump()
00196
00197 def plot(self, fname, s, il, fl) :
00198 vi = CondDB.VInt()
00199 vf = CondDB.VFloat()
00200 for i in il:
00201 vi.append(int(i))
00202 for i in fl:
00203 vf.append(float(i))
00204 return self.__me.plot(fname,s,vi,vf)
00205
00206 def trend_plot(self, fname, s, il, fl, sl) :
00207 vi = CondDB.VInt()
00208 vf = CondDB.VFloat()
00209 vs = CondDB.VString()
00210 for i in il:
00211 vi.append(int(i))
00212 for i in fl:
00213 vf.append(float(i))
00214 for i in sl:
00215 vs.append(str(i))
00216 return self.__me.trend_plot(fname,s,vi,vf,vs)
00217
00218 def summary_adv(self, s, il, fl, sl):
00219
00220 vi = CondDB.VInt()
00221 vf = CondDB.VFloat()
00222 vs = CondDB.VString()
00223 for i in il:
00224 vi.append(int(i))
00225 for i in fl:
00226 vf.append(float(i))
00227 for i in sl:
00228 vs.append(str(i))
00229 return self.__me.summary_adv(s,vi,vf,vs)
00230
00231 def dumpFile(self, fname, s, il, fl, sl):
00232 vi = CondDB.VInt()
00233 vf = CondDB.VFloat()
00234 vs = CondDB.VString()
00235 for i in il:
00236 vi.append(int(i))
00237 for i in fl:
00238 vf.append(float(i))
00239 for i in sl:
00240 vs.append(str(i))
00241 return self.__me.dumpFile(fname,s,vi,vf,vs)