CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
confdbOfflineConverter.OfflineConverter Class Reference

Public Member Functions

def __init__ (self, version='v3', database='run3', url=None, verbose=False, proxy=False, proxyHost='localhost', proxyPort='8080', tunnel=False, tunnelPort='10121')
 
def query (self, args)
 

Static Public Member Functions

def CheckTempDirectory (dir)
 

Public Attributes

 baseDir
 
 baseUrl
 
 connect
 
 jars
 
 javaCmd
 
 proxy
 
 proxy_connect_args
 
 proxyHost
 
 proxyPort
 
 tunnel
 
 tunnel_connect_args
 
 tunnelPort
 
 verbose
 
 version
 
 workDir
 

Static Public Attributes

 databases
 
 dbparams
 
 ips_for_proxy
 

Detailed Description

Definition at line 13 of file confdbOfflineConverter.py.

Constructor & Destructor Documentation

◆ __init__()

def confdbOfflineConverter.OfflineConverter.__init__ (   self,
  version = 'v3',
  database = 'run3',
  url = None,
  verbose = False,
  proxy = False,
  proxyHost = 'localhost',
  proxyPort = '8080',
  tunnel = False,
  tunnelPort = '10121' 
)

Definition at line 76 of file confdbOfflineConverter.py.

Referenced by confdbOfflineConverter.OfflineConverter.CheckTempDirectory().

76  tunnel = False, tunnelPort = '10121'):
77  self.verbose = verbose
78  self.version = version
79  self.baseDir = '/afs/cern.ch/user/c/confdb/www/%s/lib' % version
80  self.baseUrl = 'https://confdb.web.cern.ch/confdb/%s/lib' % version
81  self.jars = ( 'ojdbc8.jar', 'cmssw-evf-confdb-converter.jar' )
82  if version=='v2':
83  #legacy driver for run2 gui
84  self.jars = ( 'ojdbc6.jar', 'cmssw-evf-confdb-converter.jar' )
85  self.workDir = ''
86  self.proxy = proxy
87  self.proxyHost = proxyHost
88  self.proxyPort = proxyPort
89  self.tunnel = tunnel
90  self.tunnelPort = tunnelPort
91 
92  if self.proxy and self.tunnel:
93  sys.stderr.write( "ERROR: proxy and tunnel options can not both be true" )
94  sys.exit(1)
95 
96  # check the schema version
97  if version not in self.databases:
98  # unsupported database version
99  sys.stderr.write( "ERROR: unsupported database version \"%s\"\n" % version)
100 
101  # check the database
102  if database in self.databases[version]:
103  # load the connection parameters for the given database
104  self.connect = self.databases[version][database]
105  else:
106  # unsupported database
107  sys.stderr.write( "ERROR: unknown database \"%s\" for version \"%s\"\n" % (database, version))
108  sys.exit(1)
109 
110  if self.proxy:
111  self.proxy_connect_args = ('--dbproxy', '--dbproxyport', self.proxyPort, '--dbproxyhost', self.proxyHost)
112  temp_connect = []
113  for entry in self.connect:
114  for key,item in self.ips_for_proxy.items():
115  entry = entry.replace(key,item)
116  temp_connect.append(entry.replace(key,item))
117  self.connect = tuple(temp_connect)
118  else:
119  self.proxy_connect_args = ()
120 
121  # this sets the host to localhost
122  if self.tunnel:
123  temp_connect = list(self.connect)
124  host_index = temp_connect.index('-h')
125  temp_connect[host_index+1] = "localhost"
126  self.connect = tuple(temp_connect)
127  self.tunnel_connect_args = ('--dbport', self.tunnelPort)
128  else:
129  self.tunnel_connect_args = ()
130 
131  # check for a custom base URL
132  if url is not None:
133  self.baseUrl = url
134 
135  # try to read the .jar files from AFS, or download them
136  if os.path.isdir(self.baseDir) and all(os.path.isfile(self.baseDir + '/' + jar) for jar in self.jars):
137  # read the .jar fles from AFS
138  self.workDir = self.baseDir
139  else:
140  # try to use $CMSSW_BASE/tmp
141  self.workDir = OfflineConverter.CheckTempDirectory(os.path.join(os.environ['CMSSW_BASE'],'tmp','confdb',self.version))
142  if not self.workDir:
143  # try to use $TMP
144  self.workDir = OfflineConverter.CheckTempDirectory(os.path.join(os.environ['TMP'],'confdb',self.version))
145  if not self.workDir:
146  # create a new temporary directory, and install a cleanup callback
147  self.workDir = tempfile.mkdtemp()
148  atexit.register(shutil.rmtree, self.workDir)
149  # download the .jar files
150  version_website = requests.get(self.baseUrl+"/../confdb.version").text
151  jars_require_update = True
152  if os.path.exists(os.path.join(self.workDir,"confdb.version")):
153  with open(os.path.join(self.workDir,"confdb.version")) as f:
154  version_existing = f.read()
155  if version_existing==version_website:
156  jars_require_update = False
157 
158  if jars_require_update:
159  for jar in self.jars:
160  # download to a temporay name and use an atomic rename (in case an other istance is downloading the same file
161  handle, temp = tempfile.mkstemp(dir = self.workDir, prefix = jar + '.')
162  os.close(handle)
163  request = requests.get(self.baseUrl + '/' + jar)
164  with open(temp,'wb') as f:
165  f.write(request.content)
166  os.rename(temp, self.workDir + '/' + jar)
167  #jars updated, write their version
168  handle, temp = tempfile.mkstemp(dir = self.workDir, prefix = "confdb.version" + '.')
169  os.close(handle)
170  with open(temp,'w') as f:
171  f.write(version_website)
172  os.rename(temp,os.path.join(self.workDir,"confdb.version"))
173 
174  # setup the java command line and CLASSPATH
175  if self.verbose:
176  sys.stderr.write("workDir = %s\n" % self.workDir)
177  # use non-blocking random number source /dev/urandom (instead of /dev/random), see:
178  # http://blockdump.blogspot.fr/2012/07/connection-problems-inbound-connection.html
179  # deal with timezone region not found
180  # http://stackoverflow.com/questions/9156379/ora-01882-timezone-region-not-found
181  # increase the thread stack size from the default of 1 MB to work around java.lang.StackOverflowError errors, see
182  # man java
183  self.javaCmd = ( 'java', '-cp', ':'.join(self.workDir + '/' + jar for jar in self.jars), '-Djava.security.egd=file:///dev/urandom', '-Doracle.jdbc.timezoneAsRegion=false', '-Xss32M', 'confdb.converter.BrowserConverter' )
184 
185 
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Function Documentation

◆ CheckTempDirectory()

def confdbOfflineConverter.OfflineConverter.CheckTempDirectory (   dir)
static

Definition at line 64 of file confdbOfflineConverter.py.

References confdbOfflineConverter.OfflineConverter.__init__().

64  def CheckTempDirectory(dir):
65  dir = os.path.realpath(dir)
66  if not os.path.isdir(dir):
67  try:
68  os.makedirs(dir)
69  except:
70  return None
71  return dir
72 
73 

◆ query()

def confdbOfflineConverter.OfflineConverter.query (   self,
  args 
)

Definition at line 186 of file confdbOfflineConverter.py.

References DDTOBRodAlgo.connect, confdbOfflineConverter.OfflineConverter.connect, confdbOfflineConverter.OfflineConverter.javaCmd, join(), confdbOfflineConverter.OfflineConverter.proxy_connect_args, confdbOfflineConverter.OfflineConverter.tunnel_connect_args, VisualizationOptions.verbose, L1TdeStage2EMTF.verbose, L1TStage2uGMTMuon.verbose, L1TStage2RegionalShower.verbose, L1TStage2EMTF.verbose, DQMGenericTnPClient.verbose, dqmTnP::AbstractFitter.verbose, L1TStage2OMTF.verbose, TritonService::FallbackOpts.verbose, DeviationsFromFileSensor2D.verbose, L1TStage2BMTF.verbose, L1TStage2MuonComp.verbose, confdbOfflineConverter.OfflineConverter.verbose, L1TStage2RegionalMuonCandComp.verbose, L1TCaloLayer1RawToDigi.verbose, HIPAlignmentAlgorithm.verbose, BeamSpotDipServer.verbose, o2olib.O2OJobMgr.verbose, L1TStage2uGTCaloLayer2Comp.verbose, OpticalObject.verbose, and L1TdeStage2CaloLayer2.verbose.

Referenced by production_tasks.BaseDataset.run(), and edmIntegrityCheck.IntegrityCheck.test().

186  def query(self, *args):
187  args = self.javaCmd + self.connect + self.proxy_connect_args + self.tunnel_connect_args + args
188  if self.verbose:
189  sys.stderr.write("\n" + ' '.join(args) + "\n\n" )
190  sub = subprocess.Popen(
191  args,
192  stdin = None,
193  stdout = subprocess.PIPE,
194  stderr = subprocess.PIPE,
195  shell = False,
196  universal_newlines = True )
197  return sub.communicate()
198 
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Data Documentation

◆ baseDir

confdbOfflineConverter.OfflineConverter.baseDir

Definition at line 79 of file confdbOfflineConverter.py.

◆ baseUrl

confdbOfflineConverter.OfflineConverter.baseUrl

Definition at line 80 of file confdbOfflineConverter.py.

◆ connect

confdbOfflineConverter.OfflineConverter.connect

◆ databases

confdbOfflineConverter.OfflineConverter.databases
static

Definition at line 31 of file confdbOfflineConverter.py.

◆ dbparams

confdbOfflineConverter.OfflineConverter.dbparams
static

Definition at line 59 of file confdbOfflineConverter.py.

◆ ips_for_proxy

confdbOfflineConverter.OfflineConverter.ips_for_proxy
static

Definition at line 46 of file confdbOfflineConverter.py.

◆ jars

confdbOfflineConverter.OfflineConverter.jars

Definition at line 81 of file confdbOfflineConverter.py.

◆ javaCmd

confdbOfflineConverter.OfflineConverter.javaCmd

◆ proxy

confdbOfflineConverter.OfflineConverter.proxy

Definition at line 86 of file confdbOfflineConverter.py.

◆ proxy_connect_args

confdbOfflineConverter.OfflineConverter.proxy_connect_args

◆ proxyHost

confdbOfflineConverter.OfflineConverter.proxyHost

Definition at line 87 of file confdbOfflineConverter.py.

◆ proxyPort

confdbOfflineConverter.OfflineConverter.proxyPort

Definition at line 88 of file confdbOfflineConverter.py.

◆ tunnel

confdbOfflineConverter.OfflineConverter.tunnel

Definition at line 89 of file confdbOfflineConverter.py.

◆ tunnel_connect_args

confdbOfflineConverter.OfflineConverter.tunnel_connect_args

◆ tunnelPort

confdbOfflineConverter.OfflineConverter.tunnelPort

Definition at line 90 of file confdbOfflineConverter.py.

◆ verbose

confdbOfflineConverter.OfflineConverter.verbose

◆ version

confdbOfflineConverter.OfflineConverter.version

◆ workDir

confdbOfflineConverter.OfflineConverter.workDir

Definition at line 85 of file confdbOfflineConverter.py.