5 result = open(template).
read()
9 print "Replacing",old,
"to",new
10 result = result.replace(old,new)
15 if not castor_dir:
raise ValueError,
'Please specify valid castor dir'
17 from subprocess
import Popen,PIPE
18 p1 = Popen([
'nsls',castor_dir],stdout=PIPE)
19 p2 = Popen([
'grep',type],stdin=p1.stdout,stdout=PIPE)
20 files = [prefix + castor_dir +
"/" + item[:-1]
for item
in p2.stdout]
25 if not dir:
raise ValueError,
'Please specify valid dir'
27 from subprocess
import Popen,PIPE
28 p1 = Popen([
'ls',dir],stdout=PIPE)
29 p2 = Popen([
'grep',type],stdin=p1.stdout,stdout=PIPE)
30 files = [dir +
"/" + item[:-1]
for item
in p2.stdout]
34 def haddInCastor(castor_dir,result_file,type = 'root',prefix = 'rfio:
',suffix = None):
35 if not castor_dir:
raise ValueError,
'Please specify valid castor dir'
36 if not result_file:
raise ValueError,
'Please specify valid output file name'
41 from subprocess
import call
43 if suffix: files = [item + suffix
for item
in files]
45 cmd = [
'hadd',result_file]
52 if not dir:
raise ValueError,
'Please specify valid dir'
53 if not result_file:
raise ValueError,
'Please specify valid output file name'
55 from subprocess
import call
57 cmd = [
'hadd',result_file]
67 os.system(
'source /afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh')
69 os.system(
'source /afs/cern.ch/cms/ccs/wm/scripts/Crab/crab.sh')
79 option = item.split(
'=')[0]
80 if option
in inputFields:
81 value = item.split(
'=')[1]
82 if value
in (
'true',
'True',
'yes',
'Yes'): value =
True
83 elif value
in (
'false',
'False',
'no',
'No'): value =
False
85 setattr(options,option,value)
87 for item
in requiredFields:
88 if not hasattr(options,item):
89 raise RuntimeError,
'Need to set "%s"' % item
94 pset = imp.load_source(
"psetmodule",pset_name)
98 for path
in process.paths:
99 getattr(process,path)._seq = getattr(process,seqname)*getattr(process,path)._seq
102 if not os.path.exists(dir): os.makedirs(dir)
103 open(dir +
'/' + pset_name,
'w').write(process.dumpPython())
106 config = ConfigParser.ConfigParser()
107 config.read(cfg_name)
112 if not crab_cfg.has_section(
'CRAB'): crab_cfg.add_section(
'CRAB')
113 crab_cfg.set(
'CRAB',
'jobtype',
'cmssw')
114 crab_cfg.set(
'CRAB',
'scheduler',config.scheduler)
115 if config.useserver: crab_cfg.set(
'CRAB',
'use_server',1)
118 if not crab_cfg.has_section(
'CMSSW'): crab_cfg.add_section(
'CMSSW')
119 crab_cfg.set(
'CMSSW',
'datasetpath',config.datasetpath)
120 crab_cfg.set(
'CMSSW',
'pset',
'pset.py')
123 crab_cfg.remove_option(
'CMSSW',
'total_number_of_events')
124 crab_cfg.remove_option(
'CMSSW',
'events_per_job')
125 crab_cfg.remove_option(
'CMSSW',
'number_of_jobs')
126 crab_cfg.remove_option(
'CMSSW',
'total_number_of_lumis')
127 crab_cfg.remove_option(
'CMSSW',
'lumis_per_job')
128 crab_cfg.remove_option(
'CMSSW',
'lumi_mask')
129 crab_cfg.remove_option(
'CMSSW',
'split_by_run')
131 crab_cfg.set(
'CMSSW',
'runselection',config.runselection)
134 if hasattr(config,
'splitByLumi')
and config.splitByLumi:
135 crab_cfg.set(
'CMSSW',
'total_number_of_lumis',config.totalnumberlumis)
136 crab_cfg.set(
'CMSSW',
'lumis_per_job',config.lumisperjob)
137 if hasattr(config,
'lumimask')
and config.lumimask: crab_cfg.set(
'CMSSW',
'lumi_mask',config.lumimask)
139 crab_cfg.set(
'CMSSW',
'split_by_run',1)
142 if not crab_cfg.has_section(
'USER'): crab_cfg.add_section(
'USER')
145 if hasattr(config,
'stageOutCAF')
and config.stageOutCAF:
146 crab_cfg.set(
'USER',
'return_data',0)
147 crab_cfg.set(
'USER',
'copy_data',1)
148 crab_cfg.set(
'USER',
'storage_element',
'T2_CH_CAF')
149 crab_cfg.set(
'USER',
'user_remote_dir',config.userdircaf)
150 crab_cfg.set(
'USER',
'check_user_remote_dir',0)
151 elif hasattr(config,
'stageOutLocal')
and config.stageOutLocal:
152 crab_cfg.set(
'USER',
'return_data',1)
153 crab_cfg.set(
'USER',
'copy_data',0)
154 crab_cfg.remove_option(
'USER',
'storage_element')
155 crab_cfg.remove_option(
'USER',
'user_remote_dir')
156 crab_cfg.remove_option(
'USER',
'check_user_remote_dir')
158 if hasattr(config,
'email')
and config.email: crab_cfg.set(
'USER',
'eMail',config.email)
159 crab_cfg.set(
'USER',
'xml_report',
'crabReport.xml')
161 if hasattr(config,
'runOnGrid')
and config.runOnGrid:
162 crab_cfg.remove_section(
'CAF')