CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
def query
 

Static Public Member Functions

def CheckTempDirectory
 

Public Attributes

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

Static Public Attributes

dictionary databases = {}
 
list dbparams = databases['v2']
 
dictionary ips_for_proxy
 

Detailed Description

Definition at line 13 of file confdbOfflineConverter.py.

Constructor & Destructor Documentation

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

Definition at line 73 of file confdbOfflineConverter.py.

Referenced by confdbOfflineConverter.OfflineConverter.CheckTempDirectory().

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

Member Function Documentation

def confdbOfflineConverter.OfflineConverter.CheckTempDirectory (   dir)
static

Definition at line 62 of file confdbOfflineConverter.py.

References confdbOfflineConverter.OfflineConverter.__init__().

62 
63  def CheckTempDirectory(dir):
64  dir = os.path.realpath(dir)
65  if not os.path.isdir(dir):
66  try:
67  os.makedirs(dir)
68  except:
69  return None
70  return dir
71 
def confdbOfflineConverter.OfflineConverter.query (   self,
  args 
)

Definition at line 167 of file confdbOfflineConverter.py.

References DDTOBRodAlgo.connect, confdbOfflineConverter.OfflineConverter.connect, confdbOfflineConverter.OfflineConverter.javaCmd, join(), confdbOfflineConverter.OfflineConverter.proxy_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, confdbOfflineConverter.OfflineConverter.verbose, L1TStage2MuonComp.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().

168  def query(self, *args):
169  args = self.javaCmd + self.connect + self.proxy_connect_args + args
170  if self.verbose:
171  sys.stderr.write("\n" + ' '.join(args) + "\n\n" )
172  sub = subprocess.Popen(
173  args,
174  stdin = None,
175  stdout = subprocess.PIPE,
176  stderr = subprocess.PIPE,
177  shell = False,
178  universal_newlines = True )
179  return sub.communicate()
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Data Documentation

confdbOfflineConverter.OfflineConverter.baseDir

Definition at line 76 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.baseUrl

Definition at line 77 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.connect

Definition at line 95 of file confdbOfflineConverter.py.

Referenced by confdbOfflineConverter.OfflineConverter.query(), and o2o_db_cfgmap.DbManagerDAQ.update_hashmap().

dictionary confdbOfflineConverter.OfflineConverter.databases = {}
static

Definition at line 31 of file confdbOfflineConverter.py.

list confdbOfflineConverter.OfflineConverter.dbparams = databases['v2']
static

Definition at line 57 of file confdbOfflineConverter.py.

dictionary confdbOfflineConverter.OfflineConverter.ips_for_proxy
static
Initial value:
1 = {
2  'cmsr1-s.cern.ch' : '10.116.96.89',
3  'cmsr2-s.cern.ch' : '10.116.96.139',
4  'cmsr3-s.cern.ch' : '10.116.96.105'
5  }

Definition at line 46 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.jars

Definition at line 78 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.javaCmd

Definition at line 164 of file confdbOfflineConverter.py.

Referenced by confdbOfflineConverter.OfflineConverter.query().

confdbOfflineConverter.OfflineConverter.proxy

Definition at line 83 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.proxy_connect_args

Definition at line 102 of file confdbOfflineConverter.py.

Referenced by confdbOfflineConverter.OfflineConverter.query().

confdbOfflineConverter.OfflineConverter.proxyHost

Definition at line 84 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.proxyPort

Definition at line 85 of file confdbOfflineConverter.py.

confdbOfflineConverter.OfflineConverter.verbose

Definition at line 74 of file confdbOfflineConverter.py.

Referenced by python.diff_provenance.difference.list_diff(), python.diffProv.difference.list_diff(), python.diff_provenance.difference.module_diff(), python.diffProv.difference.module_diff(), python.diff_provenance.difference.onefilemodules(), python.diffProv.difference.onefilemodules(), core.TriggerMatchAnalyzer.TriggerMatchAnalyzer.process(), core.SkimAnalyzerCount.SkimAnalyzerCount.process(), objects.VertexAnalyzer.VertexAnalyzer.process(), and confdbOfflineConverter.OfflineConverter.query().

confdbOfflineConverter.OfflineConverter.version

Definition at line 75 of file confdbOfflineConverter.py.

Referenced by validation.Sample.datasetpattern(), and validation.Sample.filename().

confdbOfflineConverter.OfflineConverter.workDir

Definition at line 82 of file confdbOfflineConverter.py.