CMS 3D CMS Logo

sessionManager.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import coral,os,os.path
3 from RecoLuminosity.LumiDB import cacheconfigParser,connectstrParser
4 
7  return '''<frontier-connect><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier1.cern.ch:3128"/><proxy url = "http://cmst0frontier2.cern.ch:3128"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>'''
8 
9  def __init__(self,connectString,authpath=None,siteconfpath=None,debugON = False):
10  self.__connectString=connectString
11  self.__svc=None
13  usedefaultfrontierconfig = False
14  cacheconfigpath = ''
15  try:
16  self.__connectparser.parse()
17  if self.__connectparser.needsitelocalinfo():
18  if not siteconfpath:
19  cacheconfigpath = os.environ['CMS_PATH']
20  if cacheconfigpath:
21  cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
22  else:
23  usedefaultfrontierconfig = True
24  else:
25  cacheconfigpath = siteconfpath
26  cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
28  if usedefaultfrontierconfig:
29  ccp.parseString ( self.defaultfrontierConfigString() )
30  else:
31  ccp.parse (cacheconfigpath)
32  self.__connectString = self.__connectparser.fullfrontierStr(self.__connectparser.schemaname(), ccp.parameterdict())
33  if self.__connectparser.protocol()=='oracle':
34  if authpath:
35  os.environ['CORAL_AUTH_PATH']=authpath
36  else:
37  os.environ['CORAL_AUTH_PATH']='.'
38  if debugON :
39  msg = coral.MessageStream ('')
40  msg.setMsgVerbosity (coral.message_Level_Debug)
41  self.__svc = coral.ConnectionService()
42  except:
43  if self.__svc: del self.__svc
44  raise
45  def openSession(self,isReadOnly=True,cpp2sqltype=[],sql2cpptype=[] ):
46  try:
47  session=None
48  if self.__connectparser.protocol()=='frontier' or isReadOnly:
49  session = self.__svc.connect(self.__connectString, accessMode = coral.access_ReadOnly)
50  else:
51  session = self.__svc.connect(self.__connectString, accessMode = coral.access_Update)
52  for (cpptype,sqltype) in cpp2sqltype:
53  session.typeConverter().setCppTypeForSqlType(cpptype,sqltype)
54  for (sqltype,cpptype) in sql2cpptype:
55  session.typeConverter().setSqlTypeForCppType(sqltype,cpptype)
56  return session
57  except:
58  if session: del session
59  raise
60  def realConnectString(self):
61  return self.__connectString
62  def __del__(self):
63  del self.__svc
64  def svcHandle(self):
65  return self.__svc
66 
67 if __name__ == "__main__":
68  svc=sessionManager('oracle://cms_orcoff_prep/cms_lumi_dev_offline',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
69  print(svc.realConnectString())
70  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
71  session.transaction().start(True)
72  session.transaction().commit()
73  del session
74  svc=sessionManager('frontier://LumiPrep/CMS_LUMI_DEV_OFFLINE',debugON=False)
75  print(svc.realConnectString())
76  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
77  del session
Definition: start.py:1
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def __init__(self, connectString, authpath=None, siteconfpath=None, debugON=False)
def openSession(self, isReadOnly=True, cpp2sqltype=[], sql2cpptype=[])