CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
confdbOfflineConverter.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import sys, os
3 import os.path
4 import tempfile
5 import urllib
6 import shutil
7 import subprocess
8 import atexit
9 
11 
12  databases = {}
13  databases['orcoff'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hlt_gui_r', '-s', 'convertme!' )
14  databases['hltdev'] = ( '-t', 'oracle', '-h', 'cmsr1-s.cern.ch', '-d', 'cms_cond.cern.ch', '-u', 'cms_hltdev_reader', '-s', 'convertme!' )
15 
16 
17  @staticmethod
19  dir = os.path.realpath(dir)
20  if not os.path.isdir(dir):
21  try:
22  os.makedirs(dir)
23  except:
24  return None
25  return dir
26 
27 
28  def __init__(self, database = 'hltdev', url = None, verbose = False):
29  self.verbose = verbose
30  self.baseDir = '/afs/cern.ch/user/c/confdb/www/lib'
31  self.baseUrl = 'http://confdb.web.cern.ch/confdb/lib'
32  self.jars = ( 'ojdbc6.jar', 'cmssw-evf-confdb-converter.jar' )
33  self.workDir = ''
34 
35  # check the database
36  if database in self.databases:
37  # load the connection parameters for the given database
38  self.connect = self.databases[database]
39  else:
40  # unsupported database
41  sys.stderr.write( "ERROR: unknown database \"%s\"\n" % database)
42  sys.exit(1)
43 
44  # check for a custom base URL
45  if url is not None:
46  self.baseUrl = url
47 
48  # try to read the .jar files from AFS, or download them
49  if os.path.isdir(self.baseDir) and all(os.path.isfile(self.baseDir + '/' + jar) for jar in self.jars):
50  # read the .jar fles from AFS
51  self.workDir = self.baseDir
52  else:
53  # try to use $CMSSW_BASE/tmp
54  self.workDir = OfflineConverter.CheckTempDirectory(os.environ['CMSSW_BASE'] + '/tmp/confdb')
55  if not self.workDir:
56  # try to use $TMP
57  self.workDir = OfflineConverter.CheckTempDirectory(os.environ['TMP'] + '/confdb')
58  if not self.workDir:
59  # create a new temporary directory, and install a cleanup callback
60  self.workDir = tempfile.mkdtemp()
61  atexit.register(shutil.rmtree, self.workDir)
62  # download the .jar files
63  for jar in self.jars:
64  # check if the file is already present
65  if os.path.exists(self.workDir + '/' + jar):
66  continue
67  # download to a temporay name and use an atomic rename (in case an other istance is downloading the same file
68  handle, temp = tempfile.mkstemp(dir = self.workDir, prefix = jar + '.')
69  os.close(handle)
70  urllib.urlretrieve(self.baseUrl + '/' + jar, temp)
71  if not os.path.exists(self.workDir + '/' + jar):
72  os.rename(temp, self.workDir + '/' + jar)
73  else:
74  os.unlink(temp)
75 
76  # setup the java command line and CLASSPATH
77  if self.verbose:
78  sys.stderr.write("workDir = %s\n" % self.workDir)
79 # Use non-blocking random # source /dev/urandom (instead of /dev/random), see:
80 # http://blockdump.blogspot.fr/2012/07/connection-problems-inbound-connection.html
81 # Also deal with timezone region not found
82 # http://stackoverflow.com/questions/9156379/ora-01882-timezone-region-not-found
83  self.javaCmd = ( 'java', '-cp', ':'.join(self.workDir + '/' + jar for jar in self.jars),'-Djava.security.egd=file:///dev/urandom','-Doracle.jdbc.timezoneAsRegion=false','confdb.converter.BrowserConverter' )
84 
85 
86  def query(self, *args):
87  args = self.javaCmd + self.connect + args
88  if self.verbose:
89  sys.stderr.write("\n" + ' '.join(args) + "\n\n" )
90  sub = subprocess.Popen(
91  args,
92  stdin = None,
93  stdout = subprocess.PIPE,
94  stderr = subprocess.PIPE,
95  shell = False,
96  universal_newlines = True )
97  return sub.communicate()
98 
99 def help():
100  sys.stdout.write("""Usage: %s OPTIONS
101 
102  --hltdev|--orcoff (target db [default: hltdev])
103 
104  --configId <id> (specify configuration by id)
105  --configName <name> (specify configuration by name)
106  --runNumber <run> (specify configuration by run)
107  [exactly one of --configId OR --configName OR --runNumber is required]
108 
109  --cff (retrieve configuration *fragment*)
110  --input <f1.root[,f2.root]> (insert PoolSource with specified fileNames)
111  --input <files.list> (read a text file which lists input ROOT files)
112  --output <out.root> (insert PoolOutputModule w/ specified fileName)
113  --nopsets (exclude all globale psets)
114  --noedsources (exclude all edsources)
115  --noes (exclude all essources *and* esmodules)
116  --noessources (exclude all essources)
117  --noesmodules (exclude all esmodules)
118  --noservices (exclude all services)
119  --nooutput (exclude all output modules)
120  --nopaths (exclude all paths [+=referenced seqs&mods])
121  --nosequences (don't define sequences [+=referenced s&m])
122  --nomodules (don't define modules)
123  --psets <pset1[,pset2]> (include only specified global psets)
124  --psets <-pset1[,-pset2]> (include all global psets but the specified)
125  --essources <ess1[,ess2]> (include only specified essources)
126  --essources <-ess1[,-ess2]> (include all essources but the specified)
127  --esmodules <esm1[,esm2]> (include only specified esmodules)
128  --esmodules <-esm1[,-esm2]> (include all esmodules but the specified)
129  --services <svc1[,svc2]> (include only specified services)
130  --services <-svc1[,-svc2]> (include all services but the specified)
131  --paths <p1[,p2]> (include only specified paths)
132  --paths <-p1[,-p2]> (include all paths but the specified)
133  --streams <s1[,s2]> (include only specified streams)
134  --datasets <d1[,d2]> (include only specified datasets)
135  --sequences <s1[,s2]> (include sequences, referenced or not!)
136  --modules <p1[,p2]> (include modules, referenced or not!)
137  --blocks <m1::p1[,p2][,m2]> (generate parameter blocks)
138 """)
139 
140 
141 def main():
142  args = sys.argv[1:]
143  db = 'hltdev'
144 
145  if not args:
146  help()
147  sys.exit(1)
148 
149  if '--help' in args or '-h' in args:
150  help()
151  sys.exit(0)
152 
153  if '--orcoff' in args and '--hltdev' in args:
154  sys.stderr.write( "ERROR: conflicting database specifications \"--hltdev\" and \"--orcoff\"\n" )
155  sys.exit(1)
156 
157  if '--runNumber' in args and '--hltdev' in args:
158  sys.stderr.write( "ERROR: conflicting database specifications \"--hltdev\" and \"--runNumber\"\n" )
159  sys.exit(1)
160 
161  if '--hltdev' in args:
162  db = 'hltdev'
163  args.remove('--hltdev')
164 
165  if '--orcoff' in args:
166  db = 'orcoff'
167  args.remove('--orcoff')
168 
169  if '--runNumber' in args:
170  db = 'orcoff'
171 
172  converter = OfflineConverter(database = db)
173  out, err = converter.query( * args )
174  if 'ERROR' in err:
175  sys.stderr.write( "%s: error while retriving the HLT menu\n\n%s\n\n" % (sys.argv[0], err) )
176  sys.exit(1)
177  else:
178  sys.stdout.write( out )
179 
180 
181 if __name__ == "__main__":
182  main()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
Definition: main.py:1