CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
iovInspector.py
Go to the documentation of this file.
1 #
2 # iov info server backend
3 #
4 # it assumes that all magic and incantations are done...
5 #
6 import time
7 import pluginCondDBPyInterface as CondDB
8 
10  def __init__(self,w) :
11  self.__me = w
12  self.__ret ={}
13  def describe(self) :
14  _w = self.__me
15  _atts = (att for att in dir(self.__me) if not (att[0]=='_' or att[0:4]=='set_' or att[0:6]=='descr_'))
16  for _att in _atts:
17  exec('_a=_w.'+_att+'()')
18  if (_a.__class__==CondDB.VInt):
19  if(hasattr(self.__me,'descr_'+_att)) :
20  self.multiple(_att)
21  else :
22  self.commaSeparated(_att)
23  else :
24  self.single(_att,_a)
25  return self.__ret
26 
27  def single(self,att,a) :
28  self.__ret[att]=('single',[val for val in dir(a) if not (val[0]=='_' or val=='name'or val=='values')])
29 
30  def multiple(self,att) :
31  _w = self.__me
32  exec('_d=_w.descr_'+att+'()')
33  self.__ret[att]=('multiple',[val for val in _d])
34 
35  def commaSeparated(self,att) :
36  self.__ret[att]=('commaSeparated',[])
37 
38 
39 def extractorWhat(db, tag) :
40  exec('import '+db.moduleName(tag)+' as Plug')
41  ret ={}
42  w = WhatDescription(Plug.What())
43  return w.describe()
44 
45 def setWhat(w,ret) :
46  for key in ret.keys():
47  _val = ret[key]
48  if (type(_val)==type([])) :
49  _vi = CondDB.VInt()
50  for i in _val :
51  _vi.append(i)
52  exec ('w.set_'+key+'(_vi)')
53  else :
54  exec ('w.set_'+key+'(w.'+key+'().'+ret[key]+')')
55  return w
56 
57 
58 class Iov :
59  def __init__(self, db, tag, since=0, till=0, head=0, tail=0) :
60  self.__db = db
61  self.__tag = tag
62  self.__db.startReadOnlyTransaction()
63  try :
64  self.__modName = str(db.payloadModules(tag)[0])
65  Plug = __import__(self.__modName)
66  except RuntimeError :
67  self.__modName = 0
68  iov = db.iov(tag)
69  #the __me data member is always an IOVRange
70  #the IOVSequence is used in the ctor only
71  self.__me = iov.range(iov.firstSince(), iov.lastTill())
72  if (till) : self.__me = iov.range(since,till)
73  if (head) : self.__me = iov.head(head)
74  if (tail) : self.__me = iov.tail(tail)
75  self.__timetype = iov.timetype()
76  self.__comment = iov.comment()
77  self.__revision = iov.revision()
78  self.__timestamp = CondDB.unpackTime(iov.timestamp())
79  self.__payloadClasses = list(iov.payloadClasses())
80  self.__db.commitTransaction()
81 
82  def list(self) :
83  ret = []
84  for elem in self.__me.elements :
85  ret.append( (elem.payloadToken(), elem.since(), elem.till(),0))
86  return ret
87 
88  def payloadSummaries(self):
89  ret = []
90  self.__db.startReadOnlyTransaction()
91  Plug = __import__(self.__modName)
92  payload = Plug.Object(self.__db)
93  for elem in self.__me.elements:
94  payloadtoken=elem.payloadToken()
95  payload.load(elem)
96  ret.append(payload.summary())
97  self.__db.commitTransaction()
98  return ret
99 
100  def summaries(self) :
101  if (self.__modName==0) : return ["no plugin for " + self.__tag+" no summaries"]
102  self.__db.startReadOnlyTransaction()
103  Plug = __import__(self.__modName)
104  ret = []
105  p = Plug.Object(self.__db)
106  for elem in self.__me.elements :
107  p.load(elem)
108  ret.append( (elem.payloadToken(), elem.since(), elem.till(), p.summary()))
109  self.__db.commitTransaction()
110  return ret
111 
112  def trend(self, what) :
113  if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
114  self.__db.startReadOnlyTransaction()
115  Plug = __import__(self.__modName)
116  ret = []
117  w = setWhat(Plug.What(),what)
118  ex = Plug.Extractor(w)
119  p = Plug.Object(self.__db)
120  for elem in self.__me.elements :
121  p.load(elem)
122  p.extract(ex)
123  v = [i for i in ex.values()]
124  ret.append((elem.since(),elem.till(),v))
125  self.__db.commitTransaction()
126  return ret
127 
128  def trendinrange(self, what, head, tail) :
129  '''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
130  '''
131  if (self.__modName==0) : return ["no plugin for " + self.__tag+" no trend"]
132  self.__db.startReadOnlyTransaction()
133  Plug = __import__(self.__modName)
134  ret = []
135  w = setWhat(Plug.What(),what)
136  ex = Plug.Extractor(w)
137 
138  p = Plug.Object(self.__db)
139  for elem in self.__me.elements :
140  since = elem.since()
141  till = elem.till()
142  if (head < since < tail) or (since < head < till) or (since < tail < till):
143  p.load(elem)
144  p.extract(ex)
145  v = [i for i in ex.values()]
146  ret.append((elem.since(),elem.till(),v))
147  self.__db.commitTransaction()
148  return ret
149 
150  def timetype(self):
151  return self.__timetype
152  def comment(self):
153  return self.__comment
154  def revision(self):
155  return self.__revision
156  def timestamp(self):
157  return self.__timestamp
158  def payloadClasses(self):
159  return self.__payloadClasses
160  def payLoad(self, since):
161  listOfIovElem= [iovElem for iovElem in self.__me.elements if iovElem.since() == since]
162  IOVElem = listOfIovElem[0]
163  self.__db.startReadOnlyTransaction()
164  Plug = __import__(self.__modName)
165  payload = Plug.Object(self.__db)
166  payload.load(IOVElem)
167  self.__db.commitTransaction()
168  #print payload
169  return payload
170 
171 
172 
173 class PayLoad :
174  def __init__(self, db, tag, elem) :
175  self.__db = db
176  self.__tag = tag
177  self.__elem = elem
178  self.__db.startReadOnlyTransaction()
179  self.__modName = str(db.payloadModules(tag)[0])
180  Plug = __import__(self.__modName)
181  self.__me = Plug.Object(db)
182  self.__me.load(elem)
183  self.__db.commitTransaction()
184 
185  def __str__(self) :
186  return self.__me.dump()
187 
188  def object(self) :
189  return self.__me
190 
191  def summary(self) :
192  return self.__me.summary()
193 
194  def dump(self) :
195  return self.__me.dump()
196 
197  def plot(self, fname, s, il, fl) :
198  vi = CondDB.VInt()
199  vf = CondDB.VFloat()
200  for i in il:
201  vi.append(int(i))
202  for i in fl:
203  vf.append(float(i))
204  return self.__me.plot(fname,s,vi,vf)
205 
206  def trend_plot(self, fname, s, il, fl, sl) :
207  vi = CondDB.VInt()
208  vf = CondDB.VFloat()
209  vs = CondDB.VString()
210  for i in il:
211  vi.append(int(i))
212  for i in fl:
213  vf.append(float(i))
214  for i in sl:
215  vs.append(str(i))
216  return self.__me.trend_plot(fname,s,vi,vf,vs)
217 
218  def summary_adv(self, s, il, fl, sl):
219  #i = int(i)
220  vi = CondDB.VInt()
221  vf = CondDB.VFloat()
222  vs = CondDB.VString()
223  for i in il:
224  vi.append(int(i))
225  for i in fl:
226  vf.append(float(i))
227  for i in sl:
228  vs.append(str(i))
229  return self.__me.summary_adv(s,vi,vf,vs)
230 
231  def dumpFile(self, fname, s, il, fl, sl):
232  vi = CondDB.VInt()
233  vf = CondDB.VFloat()
234  vs = CondDB.VString()
235  for i in il:
236  vi.append(int(i))
237  for i in fl:
238  vf.append(float(i))
239  for i in sl:
240  vs.append(str(i))
241  return self.__me.dumpFile(fname,s,vi,vf,vs)
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
dbl *** dir
Definition: mlp_gen.cc:35