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  urllib.urlretrieve(self.baseUrl + '/' + jar, self.workDir + '/' + jar)
65 
66  # setup the java command line and CLASSPATH
67  if self.verbose:
68  sys.stderr.write("workDir = %s\n" % self.workDir)
69  self.javaCmd = ( 'java', '-cp', ':'.join(self.workDir + '/' + jar for jar in self.jars), 'confdb.converter.BrowserConverter' )
70 
71 
72  def query(self, *args):
73  args = self.javaCmd + self.connect + args
74  if self.verbose:
75  sys.stderr.write("\n" + ' '.join(args) + "\n\n" )
76  sub = subprocess.Popen(
77  args,
78  stdin = None,
79  stdout = subprocess.PIPE,
80  stderr = subprocess.PIPE,
81  shell = False,
82  universal_newlines = True )
83  return sub.communicate()
84 
85 def help():
86  sys.stdout.write("""Usage: %s OPTIONS
87 
88  --hltdev|--orcoff (target db [default: hltdev])
89 
90  --configId <id> (specify configuration by id)
91  --configName <name> (specify configuration by name)
92  --runNumber <run> (specify configuration by run)
93  [exactly one of --configId OR --configName OR --runNumber is required]
94 
95  --cff (retrieve configuration *fragment*)
96  --input <f1.root[,f2.root]> (insert PoolSource with specified fileNames)
97  --input <files.list> (read a text file which lists input ROOT files)
98  --output <out.root> (insert PoolOutputModule w/ specified fileName)
99  --nopsets (exclude all globale psets)
100  --noedsources (exclude all edsources)
101  --noes (exclude all essources *and* esmodules)
102  --noessources (exclude all essources)
103  --noesmodules (exclude all esmodules)
104  --noservices (exclude all services)
105  --nooutput (exclude all output modules)
106  --nopaths (exclude all paths [+=referenced seqs&mods])
107  --nosequences (don't define sequences [+=referenced s&m])
108  --nomodules (don't define modules)
109  --psets <pset1[,pset2]> (include only specified global psets)
110  --psets <-pset1[,-pset2]> (include all global psets but the specified)
111  --essources <ess1[,ess2]> (include only specified essources)
112  --essources <-ess1[,-ess2]> (include all essources but the specified)
113  --esmodules <esm1[,esm2]> (include only specified esmodules)
114  --esmodules <-esm1[,-esm2]> (include all esmodules but the specified)
115  --services <svc1[,svc2]> (include only specified services)
116  --services <-svc1[,-svc2]> (include all services but the specified)
117  --paths <p1[,p2]> (include only specified paths)
118  --paths <-p1[,-p2]> (include all paths but the specified)
119  --streams <s1[,s2]> (include only specified streams)
120  --datasets <d1[,d2]> (include only specified datasets)
121  --sequences <s1[,s2]> (include sequences, referenced or not!)
122  --modules <p1[,p2]> (include modules, referenced or not!)
123  --blocks <m1::p1[,p2][,m2]> (generate parameter blocks)
124 """)
125 
126 
127 def main():
128  args = sys.argv[1:]
129  db = 'hltdev'
130 
131  if not args:
132  help()
133  sys.exit(1)
134 
135  if '--help' in args or '-h' in args:
136  help()
137  sys.exit(0)
138 
139  if '--orcoff' in args and '--hltdev' in args:
140  sys.stderr.write( "ERROR: conflicting database specifications \"--hltdev\" and \"--orcoff\"\n" )
141  sys.exit(1)
142 
143  if '--runNumber' in args and '--hltdev' in args:
144  sys.stderr.write( "ERROR: conflicting database specifications \"--hltdev\" and \"--runNumber\"\n" )
145  sys.exit(1)
146 
147  if '--hltdev' in args:
148  db = 'hltdev'
149  args.remove('--hltdev')
150 
151  if '--orcoff' in args:
152  db = 'orcoff'
153  args.remove('--orcoff')
154 
155  if '--runNumber' in args:
156  db = 'orcoff'
157 
158  converter = OfflineConverter(database = db)
159  out, err = converter.query( * args )
160  if 'ERROR' in err:
161  sys.stderr.write( "%s: error while retriving the HLT menu\n\n%s\n\n" % (sys.argv[0], err) )
162  sys.exit(1)
163  else:
164  sys.stdout.write( out )
165 
166 
167 if __name__ == "__main__":
168  main()
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
Definition: main.py:1