CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CommonUtils.py
Go to the documentation of this file.
1 
3  return 'TAGINVENTORY_TABLE'
5  return 'TAGINVENTORY_IDS'
6 def treeTableName(treename):
7  return 'TAGTREE_TABLE_'+str.upper(treename)
8 def treeIDTableName(treename):
9  return 'TAGTREE_'+str.upper(treename)+'_IDS'
11  return 'ENTRYCOMMENT_TABLE'
12 
13 import coral
14 def dropAllTreeTables(dbsession):
15  """drop all tagtree related tables
16  """
17  try:
18  dbsession.transaction().start(False)
19  tablelist = dbsession.nominalSchema().listTables()
20  for tname in tablelist:
21  if tname.find('TAGTREE_') != -1:
22  dbsession.nominalSchema().dropTable(tname)
23  dbsession.transaction().commit()
24  except Exception, e:
25  raise Exception, str(e)
26 
27 def tagInTrees(dbsession,tagname,pfn=''):
28  """returns the tree names which contain the given tag
29  select tagid from taginventory_table where tagname=tagname
30  select count(*) from tablename where tablename.tagid=tagid
31  """
32  try:
33  dbsession.transaction().start(True)
34  invquery = dbsession.nominalSchema().tableHandle(inventoryTableName()).newQuery()
35  conditionbindDict=coral.AttributeList()
36  conditionbindDict.extend('tagname','string')
37  conditionbindDict['tagname'].setData(tagname)
38  condition='tagname = :tagname'
39  if len(pfn) !=0 :
40  condition+=' AND pfn = :pfn'
41  conditionbindDict.extend('pfn','string')
42  conditionbindDict['pfn'].setData(pfn)
43  invquery.setCondition(condition,conditionbindDict)
44  invquery.addToOutputList('tagid')
45  invquery.addToOutputList('pfn')
46  cursor = invquery.execute()
47  tagidmap={}
48  while ( cursor.next() ):
49  tagid=cursor.currentRow()['tagid'].data()
50  pfn=cursor.currentRow()['pfn'].data()
51  tagidmap[pfn]=tagid
52  cursor.close()
53  dbsession.transaction().commit()
54  del invquery
55  if len(tagidmap)==0:
56  return tagidmap
57 
58  result={}
59  treetablelist=[]
60  dbsession.transaction().start(True)
61  tablelist = dbsession.nominalSchema().listTables()
62  for t in tablelist:
63  if t.find('TAGTREE_TABLE_')!= -1:
64  treetablelist.append(t)
65  for (pfn,tagid) in tagidmap.items():
66  result[pfn]=[]
67  condition='tagid = :tagid'
68  for t in treetablelist:
69  conditionBind=coral.AttributeList()
70  conditionBind.extend('tagid','unsigned long')
71  conditionBind['tagid'].setData(tagid)
72  q=dbsession.nominalSchema().tableHandle(t).newQuery()
73  q.addToOutputList('count(*)','count')
74  myresult=coral.AttributeList()
75  myresult.extend('count','unsigned long')
76  q.defineOutput(myresult)
77  q.setCondition(condition,conditionBind)
78  cr=q.execute()
79  while (cr.next()):
80  if cr.currentRow()['count'].data()!=0:
81  result[pfn].append(t[len('TAGTREE_TABLE_'):])
82  cr.close()
83  del q
84  dbsession.transaction().commit()
85  return result
86  except Exception, e:
87  raise Exception, str(e)
88 
89 if __name__ == "__main__":
90  #context = coral.Context()
91  #context.setVerbosityLevel( 'ERROR' )
92  svc = coral.ConnectionService()
93  session = svc.connect( 'sqlite_file:testInventory.db',
94  accessMode = coral.access_Update )
95  try:
96  print 'TEST 1'
97  intrees=tagInTrees(session,'Tracker_Geometry_CRUZET3')
98  print intrees
99  print 'TEST 2'
100  hello=tagInTrees(session,'Tracker_Geometry_CRUZ3')
101  print hello
102  print 'TEST 3'
103  kitty=tagInTrees(session,'Tracker_Geometry_CRUZET3','pfnme')
104  print kitty
105  print 'TEST 4'
106  mikey=tagInTrees(session,'Tracker_Geometry_CRUZET3','frontier://(proxyurl=http://localhost:3128)(serverurl=http://frontier1.cms:8000/FrontierOnProd)(serverurl=http://frontier2.cms:8000/FrontierOnProd)(retrieve-ziplevel=0)/CMS_COND_20X_ALIGNMENT')
107  print mikey
108  del session
109  except Exception, e:
110  print "Failed in unit test"
111  print str(e)
112  del session
Definition: start.py:1