6 result = open(template).
read()
10 print "Replacing",old,
"to",new
11 result = result.replace(old,new)
16 datasetstr = datasetpath
18 if datasetstr[0] ==
'/': datasetstr = datasetstr[1:]
19 datasetstr = datasetstr.replace(
'/',
'_')
24 workflowName = datasetpath
25 sections = workflowName.split(
'/')[1:]
26 workflowName =
'/%s/%s-%s-rev%d/%s' % (sections[0],sections[1],type,rev,sections[2])
31 if not castor_dir:
raise ValueError(
'Please specify valid castor dir')
33 from subprocess
import Popen,PIPE
34 p1 = Popen([
'nsls',castor_dir],stdout=PIPE)
38 files = [
"%s%s/%s" % (prefix,castor_dir,item.rstrip())
for item
in p1.stdout
if item.find(type) != -1 ]
43 if not dir:
raise ValueError(
'Please specify valid dir')
50 files = os.listdir(dir)
51 files = [
"%s/%s" % (dir,item)
for item
in files
if item.find(type) != -1 ]
56 from subprocess
import call
59 print "Copying files from %s to %s" % (castor_dir,output_dir)
61 cmd = [
'rfcp',item,output_dir]
64 if retcode != 0:
raise RuntimeError(
'Error in copying file %s to directory %s' % (item,output_dir))
69 if not dir:
raise ValueError(
'Please specify valid dir')
70 if not output_dir:
raise ValueError(
'Please specify valid output dir')
72 from subprocess
import call
76 cmd.append(output_dir)
81 def haddInCastor(castor_dir,result_file,type = 'root',prefix = 'rfio:
',suffix = None):
82 if not castor_dir:
raise ValueError(
'Please specify valid castor dir')
83 if not result_file:
raise ValueError(
'Please specify valid output file name')
88 from subprocess
import call
90 if suffix: files = [item + suffix
for item
in files]
92 cmd = [
'hadd',result_file]
99 if not dir:
raise ValueError(
'Please specify valid dir')
100 if not result_file:
raise ValueError(
'Please specify valid output file name')
102 from subprocess
import call
104 cmd = [
'hadd',result_file]
114 os.system(
'source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh')
116 os.system(
'source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh')
125 for item
in sys.argv:
126 option = item.split(
'=')[0]
127 if option
in inputFields:
128 value = item.split(
'=')[1]
129 if value
in (
'true',
'True',
'yes',
'Yes'): value =
True
130 elif value
in (
'false',
'False',
'no',
'No'): value =
False
132 setattr(options,option,value)
134 for item
in requiredFields:
135 if not hasattr(options,item):
136 raise RuntimeError(
'Need to set "%s"' % item)
141 pset = imp.load_source(
"psetmodule",psetName)
145 module = __import__(psetPath)
146 process = sys.modules[psetPath].process
151 processNew = copy.copy(process)
155 for path
in process.paths:
156 getattr(process,path)._seq = getattr(process,seqname)*getattr(process,path)._seq
159 if not os.path.exists(dir): os.makedirs(dir)
160 open(dir +
'/' + psetName,
'w').
write(process.dumpPython())
163 if not os.path.exists(dir): os.makedirs(dir)
165 pklFileName = psetName.split(
'.')[0] +
'.pkl'
166 pklFile = open(dir +
'/' + pklFileName,
"wb")
167 myPickle = pickle.Pickler(pklFile)
168 myPickle.dump(process)
171 outFile = open(dir +
'/' + psetName,
"w")
172 outFile.write(
"import FWCore.ParameterSet.Config as cms\n")
173 outFile.write(
"import pickle\n")
174 outFile.write(
"process = pickle.load(open('%s', 'rb'))\n" % pklFileName)
179 config = ConfigParser.ConfigParser()
180 if cfgName: config.read(cfgName)
184 additionalInputFiles =
''
185 if crabCfg.has_option(
'USER',
'additional_input_files'):
186 additionalInputFiles = crabCfg.get(
'USER',
'additional_input_files')
188 if additionalInputFiles: additionalInputFiles +=
',%s' % inputFile
189 else: additionalInputFiles = inputFile
191 crabCfg.set(
'USER',
'additional_input_files',additionalInputFiles)
197 if not crabCfg.has_section(
'CRAB'): crabCfg.add_section(
'CRAB')
198 crabCfg.set(
'CRAB',
'jobtype',
'cmssw')
200 if hasattr(config,
'scheduler')
and config.scheduler: crabCfg.set(
'CRAB',
'scheduler',config.scheduler)
201 else: crabCfg.set(
'CRAB',
'scheduler',
'CAF')
203 if hasattr(config,
'useserver')
and config.useserver: crabCfg.set(
'CRAB',
'use_server',1)
206 if not crabCfg.has_section(
'CMSSW'): crabCfg.add_section(
'CMSSW')
207 if hasattr(config,
'datasetpath')
and config.datasetpath: crabCfg.set(
'CMSSW',
'datasetpath',config.datasetpath)
208 else: crabCfg.set(
'CMSSW',
'datasetpath',
'/XXX/YYY/ZZZ')
209 crabCfg.set(
'CMSSW',
'pset',
'pset.py')
212 crabCfg.remove_option(
'CMSSW',
'total_number_of_events')
213 crabCfg.remove_option(
'CMSSW',
'events_per_job')
214 crabCfg.remove_option(
'CMSSW',
'number_of_jobs')
215 crabCfg.remove_option(
'CMSSW',
'total_number_of_lumis')
216 crabCfg.remove_option(
'CMSSW',
'lumis_per_job')
217 crabCfg.remove_option(
'CMSSW',
'lumi_mask')
218 crabCfg.remove_option(
'CMSSW',
'split_by_run')
221 if hasattr(config,'totalnumberevents'): crabCfg.set('CMSSW','total_number_of_events',config.totalnumberevents)
222 if hasattr(config,'eventsperjob'): crabCfg.set('CMSSW','events_per_job',config.eventsperjob)
224 if hasattr(config,
'splitByLumi')
and config.splitByLumi:
225 crabCfg.set(
'CMSSW',
'total_number_of_lumis',config.totalnumberlumis)
226 crabCfg.set(
'CMSSW',
'lumis_per_job',config.lumisperjob)
227 if hasattr(config,
'lumimask')
and config.lumimask: crabCfg.set(
'CMSSW',
'lumi_mask',config.lumimask)
228 elif hasattr(config,
'splitByEvent')
and config.splitByEvent:
229 crabCfg.set(
'CMSSW',
'total_number_of_events',config.totalnumberevents)
230 crabCfg.set(
'CMSSW',
'events_per_job',config.eventsperjob)
232 crabCfg.set(
'CMSSW',
'split_by_run',1)
234 if hasattr(config,
'splitByEvent')
and config.splitByEvent:
235 crabCfg.remove_option(
'CMSSW',
'runselection')
237 if hasattr(config,
'runselection')
and config.runselection:
238 crabCfg.set(
'CMSSW',
'runselection',config.runselection)
241 if not crabCfg.has_section(
'USER'): crabCfg.add_section(
'USER')
244 if hasattr(config,
'stageOutCAF')
and config.stageOutCAF:
245 crabCfg.set(
'USER',
'return_data',0)
246 crabCfg.set(
'USER',
'copy_data',1)
247 crabCfg.set(
'USER',
'storage_element',
'T2_CH_CAF')
248 crabCfg.set(
'USER',
'user_remote_dir',config.userdircaf)
249 crabCfg.set(
'USER',
'check_user_remote_dir',0)
250 elif hasattr(config,
'stageOutLocal')
and config.stageOutLocal:
251 crabCfg.set(
'USER',
'return_data',1)
252 crabCfg.set(
'USER',
'copy_data',0)
253 crabCfg.remove_option(
'USER',
'storage_element')
254 crabCfg.remove_option(
'USER',
'user_remote_dir')
255 crabCfg.remove_option(
'USER',
'check_user_remote_dir')
257 if hasattr(config,
'email')
and config.email: crabCfg.set(
'USER',
'eMail',config.email)
258 crabCfg.set(
'USER',
'xml_report',
'crabReport.xml')
260 if hasattr(config,
'runOnGrid')
and config.runOnGrid:
261 crabCfg.remove_section(
'CAF')
262 if hasattr(config,
'ce_black_list'):
263 if not crabCfg.has_section(
'GRID'): crabCfg.add_section(
'GRID')
264 crabCfg.set(
'GRID',
'ce_black_list', config.ce_black_list)
265 if hasattr(config,
'ce_white_list'):
266 if not crabCfg.has_section(
'GRID'): crabCfg.add_section(
'GRID')
267 crabCfg.set(
'GRID',
'ce_white_list', config.ce_white_list)
269 if not crabCfg.has_section(
'CAF'): crabCfg.add_section(
'CAF')
270 crabCfg.set(
'CAF',
'queue',config.queueAtCAF)