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')
 
def query (self, *args)
 

Static Public Member Functions

def CheckTempDirectory (dir)
 

Public Attributes

 baseDir
 
 baseUrl
 
 connect
 
 jars
 
 javaCmd
 
 proxy
 
 proxy_connect_args
 
 proxyHost
 
 proxyPort
 
 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' 
)

Definition at line 72 of file confdbOfflineConverter.py.

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

Member Function Documentation

◆ CheckTempDirectory()

def confdbOfflineConverter.OfflineConverter.CheckTempDirectory (   dir)
static

Definition at line 62 of file confdbOfflineConverter.py.

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

◆ query()

def confdbOfflineConverter.OfflineConverter.query (   self,
args 
)

Definition at line 167 of file confdbOfflineConverter.py.

167  def query(self, *args):
168  args = self.javaCmd + self.connect + self.proxy_connect_args + args
169  if self.verbose:
170  sys.stderr.write("\n" + ' '.join(args) + "\n\n" )
171  sub = subprocess.Popen(
172  args,
173  stdin = None,
174  stdout = subprocess.PIPE,
175  stderr = subprocess.PIPE,
176  shell = False,
177  universal_newlines = True )
178  out,err = sub.communicate()
179  # 12_0 uses "HLTSchedule", confdb was changed to make this "schedule", this resets it back for this release
180  out = out.replace("fragment.schedule","fragment.HLTSchedule").replace("process.schedule","process.HLTSchedule")
181  return out,err
182 

References DDTOBRodAlgo.connect, confdbOfflineConverter.OfflineConverter.connect, confdbOfflineConverter.OfflineConverter.javaCmd, join(), confdbOfflineConverter.OfflineConverter.proxy_connect_args, python.rootplot.root2matplotlib.replace(), VisualizationOptions.verbose, L1TdeStage2EMTF.verbose, L1TStage2uGMTMuon.verbose, L1TStage2EMTF.verbose, L1TStage2uGMT.verbose, DQMGenericTnPClient.verbose, dqmTnP::AbstractFitter.verbose, TritonService::FallbackOpts.verbose, L1TStage2OMTF.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().

Member Data Documentation

◆ baseDir

confdbOfflineConverter.OfflineConverter.baseDir

Definition at line 75 of file confdbOfflineConverter.py.

◆ baseUrl

confdbOfflineConverter.OfflineConverter.baseUrl

Definition at line 76 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 57 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 77 of file confdbOfflineConverter.py.

◆ javaCmd

confdbOfflineConverter.OfflineConverter.javaCmd

◆ proxy

confdbOfflineConverter.OfflineConverter.proxy

Definition at line 82 of file confdbOfflineConverter.py.

◆ proxy_connect_args

confdbOfflineConverter.OfflineConverter.proxy_connect_args

◆ proxyHost

confdbOfflineConverter.OfflineConverter.proxyHost

Definition at line 83 of file confdbOfflineConverter.py.

◆ proxyPort

confdbOfflineConverter.OfflineConverter.proxyPort

Definition at line 84 of file confdbOfflineConverter.py.

◆ verbose

confdbOfflineConverter.OfflineConverter.verbose

◆ version

confdbOfflineConverter.OfflineConverter.version

◆ workDir

confdbOfflineConverter.OfflineConverter.workDir

Definition at line 81 of file confdbOfflineConverter.py.

join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
contentValuesFiles.query
query
Definition: contentValuesFiles.py:38
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444