CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaHLTBitMon_ParallelJobs.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #-----------------------------------------------------
4 # original author: Andrea Lucaroni
5 # Revision: $Revision: 1.53 $
6 # Last update: $Date: 2011/06/28 19:01:36 $
7 # by: $Author: mussgill $
8 #-----------------------------------------------------
9 
10 import re
11 import json
12 import os
13 import stat
14 import sys
15 
16 import array
17 import pickle as pk
18 
19 from optparse import OptionParser
20 #####DEBUG
21 DEBUG = 0
22 
24  template = os.path.expandvars('$CMSSW_BASE/src/Alignment/CommonAlignmentProducer/data/AlCaHLTBitMon_cfg_template_py')
25  if os.path.exists(template):
26  return template
27  template = os.path.expandvars('$CMSSW_RELEASE_BASE/src/Alignment/CommonAlignmentProducer/data/AlCaHLTBitMon_cfg_template_py')
28  if os.path.exists(template):
29  return template
30  return 'None'
31 
32 def mkHLTKeyListList(hltkeylistfile):
33  keylistlist = []
34  f = open(hltkeylistfile, 'r')
35  for line in f:
36  keylistlist.append(line.replace('\n',''))
37  f.close()
38  return keylistlist
39 
40 def parallelJobs(hltkeylistfile,jsonDir,globalTag,templateName,queue,cafsetup):
41  PWD = os.path.abspath('.')
42 
43  if templateName == 'default':
44  templateFile = getConfigTemplateFilename()
45  else:
46  templateFile = os.path.abspath(os.path.expandvars(templateName))
47 
48  tfile = open(templateFile, 'r')
49  template = tfile.read()
50  tfile.close()
51  template = template.replace('%%%GLOBALTAG%%%', globalTag)
52 
53  keylistlist = mkHLTKeyListList(hltkeylistfile)
54  index = 0
55  for keylist in keylistlist:
56 
57  configName = 'AlCaHLTBitMon_%d_cfg.py'%index
58  jobName = 'AlCaHLTBitMon_%d_job.csh'%index
59  jsonFile = os.path.abspath('%(dir)s/%(index)d.json' % {'dir' : jsonDir, 'index' : index})
60  dataFile = os.path.abspath('%(dir)s/%(index)d.data' % {'dir' : jsonDir, 'index' : index})
61  logFile = 'AlCaHLTBitMon_%d'%index
62 
63  dfile = open(dataFile, 'r')
64  data = dfile.read()
65  dfile.close()
66 
67  config = template.replace('%%%JSON%%%', jsonFile);
68  config = config.replace('%%%DATA%%%', data);
69  config = config.replace('%%%KEYNAME%%%', keylist);
70  config = config.replace('%%%LOGFILE%%%', logFile);
71 
72  cfile = open(configName, 'w')
73  for line in config:
74  cfile.write(line)
75  cfile.close()
76 
77  jfile = open(jobName, 'w')
78  jfile.write('#!/bin/tcsh\n\n')
79  if cafsetup == True:
80  jfile.write('source /afs/cern.ch/cms/caf/setup.csh\n\n')
81 
82  jfile.write('cd $1\n\n')
83  jfile.write('eval `scramv1 run -csh`\n\n')
84  jfile.write('cmsRun %s\n\n'%configName)
85  jfile.write('cp %s.log $2'%logFile)
86  jfile.close()
87 
88  if os.path.exists('./%s'%keylist) == False:
89  os.system('mkdir ./%s'%keylist)
90 
91  os.system('chmod u+x %s'%jobName)
92  #print('bsub -q %(queue)s %(jobname)s %(pwd)s %(pwd)s/%(outdir)s' % {'queue' : queue, 'jobname' : jobName, 'pwd' : PWD, 'outdir' : keylist})
93  os.system('bsub -q %(queue)s %(jobname)s %(pwd)s %(pwd)s/%(outdir)s' % {'queue' : queue, 'jobname' : jobName, 'pwd' : PWD, 'outdir' : keylist})
94 
95  index = index + 1
96 
98  parser = OptionParser()
99 
100  parser.add_option("-k", "--keylist",
101  dest="hltKeyListFile",
102  default="lista_key.txt",
103  help="text file with HLT keys")
104 
105  parser.add_option("-j", "--json",
106  dest="jsonDir",
107  help="directory with the corresponding json files")
108 
109  parser.add_option("-g", "--globalTag",
110  dest="globalTag",
111  help="the global tag to use in the config files")
112 
113  parser.add_option("-t", "--template",
114  dest="template",
115  default="default",
116  help="the template to use for the config files")
117 
118  parser.add_option("-q", "--queue",
119  dest="queue",
120  default="cmscaf1nd",
121  help="the queue to use (default=cmscaf1nd)")
122 
123  parser.add_option("-c", "--cafsetup", action="store_true",
124  dest="cafsetup",
125  default=False,
126  help="wether the caf setup is sourced in the scripts")
127 
128  (options, args) = parser.parse_args()
129 
130  if len(sys.argv) == 1:
131  print("\nUsage: %s --help"%sys.argv[0])
132  sys.exit(0)
133 
134  if str(options.hltKeyListFile) == 'None':
135  print("Please provide a file with HLT keys")
136  sys.exit(0)
137 
138  if str(options.jsonDir) == 'None':
139  print("Please provide a directory containing the json files")
140  sys.exit(0)
141 
142  if str(options.globalTag) == 'None':
143  print("Please provide a global tag")
144  sys.exit(0)
145 
146  return options
147 
148 
149 #---------------------------------------------MAIN
150 
151 options = defineOptions()
152 p = parallelJobs(options.hltKeyListFile,
153  options.jsonDir,
154  options.globalTag,
155  options.template,
156  options.queue,
157  options.cafsetup)
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10