3 from __future__
import print_function
12 CopyRights =
'####################################\n'
13 CopyRights +=
'# LaunchOnFarm Script #\n'
14 CopyRights +=
'# Loic.quertenmont@cern.ch #\n'
15 CopyRights +=
'# April 2010 #\n'
16 CopyRights +=
'####################################\n'
36 runInteractively =
False
49 Path_Cfg = Farm_Directories[1]+Jobs_Index+Jobs_Name+
'_cfg.py'
51 config_file=open(argv[1],
'r')
52 config_txt =
'\n\n' + CopyRights +
'\n\n'
53 config_txt += config_file.read()
56 while i < len(argv)-1:
57 config_txt = config_txt.replace(argv[i],argv[i+1])
61 config_txt = config_txt.replace(
"XXX_I_XXX" ,
"%04i"%Jobs_Count)
62 config_txt = config_txt.replace(
"XXX_PATH_XXX" ,os.getcwd())
63 config_txt = config_txt.replace(
"XXX_OUTPUT_XXX" ,Jobs_Name)
64 config_txt = config_txt.replace(
"XXX_NAME_XXX" ,Jobs_Index+Jobs_Name)
65 config_txt = config_txt.replace(
"XXX_SEED_XXX" ,
str(Jobs_Seed+Jobs_Count))
66 config_txt = config_txt.replace(
"XXX_NEVENTS_XXX" ,
str(Jobs_NEvent))
67 config_txt = config_txt.replace(
"XXX_SKIP_XXX" ,
str(Jobs_Skip))
68 if Jobs_Count < len(Jobs_Inputs):
69 config_txt = config_txt.replace(
"XXX_INPUT_XXX" ,Jobs_Inputs[Jobs_Count])
71 config_file=open(Path_Cfg,
'w')
72 config_file.write(config_txt)
81 Path_Shell = Farm_Directories[1]+Jobs_Index+Jobs_Name+
'.sh'
84 for i
in range(2,len(argv)):
85 function_argument+=
"%s" % argv[i]
87 function_argument+=
', '
88 function_argument+=
')'
90 shell_file=open(Path_Shell,
'w')
91 shell_file.write(
'#! /bin/sh\n')
92 shell_file.write(CopyRights +
'\n')
93 shell_file.write(
'export SCRAM_ARCH='+os.getenv(
"SCRAM_ARCH",
"slc5_amd64_gcc462")+
'\n')
94 shell_file.write(
'export BUILD_ARCH='+os.getenv(
"BUILD_ARCH",
"slc5_amd64_gcc462")+
'\n')
95 shell_file.write(
'export VO_CMS_SW_DIR='+os.getenv(
"VO_CMS_SW_DIR",
"/nfs/soft/cms")+
'\n')
97 shell_file.write(
'cd ' + os.getcwd() +
'\n')
98 shell_file.write(
'eval `scramv1 runtime -sh`\n')
102 shell_file.write(
'cd -\n')
103 shell_file.write(argv[1] +
" %s\n" % function_argument)
104 elif argv[0]==
'ROOT':
106 shell_file.write(
'cd -\n')
107 shell_file.write(
'root -l -b << EOF\n')
108 shell_file.write(
' TString makeshared(gSystem->GetMakeSharedLib());\n')
109 shell_file.write(
' TString dummy = makeshared.ReplaceAll("-W ", "-Wno-deprecated-declarations -Wno-deprecated -Wno-unused-local-typedefs ");\n')
110 shell_file.write(
' TString dummy = makeshared.ReplaceAll("-Wshadow ", " -std=c++0x -D__USE_XOPEN2K8 ");\n')
111 shell_file.write(
' cout << "Compilling with the following arguments: " << makeshared << endl;\n')
112 shell_file.write(
' gSystem->SetMakeSharedLib(makeshared);\n')
113 shell_file.write(
' gSystem->SetIncludePath( "-I$ROOFITSYS/include" );\n')
114 shell_file.write(
' .x %s+' % argv[1] + function_argument +
'\n')
115 shell_file.write(
' .q\n')
116 shell_file.write(
'EOF\n\n')
117 elif argv[0]==
'FWLITE':
119 shell_file.write(
'cd -\n')
120 shell_file.write(
'root -l -b << EOF\n')
121 shell_file.write(
' TString makeshared(gSystem->GetMakeSharedLib());\n')
122 shell_file.write(
' TString dummy = makeshared.ReplaceAll("-W ", "-Wno-deprecated-declarations -Wno-deprecated ");\n')
123 shell_file.write(
' TString dummy = makeshared.ReplaceAll("-Wshadow ", " -std=c++0x -D__USE_XOPEN2K8 ");\n')
124 shell_file.write(
' cout << "Compilling with the following arguments: " << makeshared << endl;\n')
125 shell_file.write(
' gSystem->SetMakeSharedLib(makeshared);\n')
126 shell_file.write(
' gSystem->SetIncludePath("-I$ROOFITSYS/include");\n')
127 shell_file.write(
' gSystem->Load("libFWCoreFWLite");\n')
128 shell_file.write(
' FWLiteEnabler::enable();\n')
129 shell_file.write(
' gSystem->Load("libDataFormatsFWLite.so");\n')
130 shell_file.write(
' gSystem->Load("libAnalysisDataFormatsSUSYBSMObjects.so");\n')
131 shell_file.write(
' gSystem->Load("libDataFormatsVertexReco.so");\n')
132 shell_file.write(
' gSystem->Load("libDataFormatsHepMCCandidate.so");\n')
133 shell_file.write(
' gSystem->Load("libPhysicsToolsUtilities.so");\n')
134 shell_file.write(
' gSystem->Load("libdcap.so");\n')
135 shell_file.write(
' .x %s+' % argv[1] + function_argument +
'\n')
136 shell_file.write(
' .q\n')
137 shell_file.write(
'EOF\n\n')
138 elif argv[0]==
'CMSSW':
141 shell_file.write(
'cd -\n')
142 shell_file.write(
'cmsRun ' + os.getcwd() +
'/'+Path_Cfg +
'\n')
145 shell_file.write(
'#Program to use is not specified... Guess it is bash command\n')
146 shell_file.write(argv[1] +
" %s\n" % function_argument)
148 for i
in range(len(Jobs_FinalCmds)):
149 shell_file.write(Jobs_FinalCmds[i]+
'\n')
150 shell_file.write(
'mv '+ Jobs_Name+
'* '+os.getcwd()+
'/'+Farm_Directories[3]+
'\n')
152 os.system(
"chmod 777 "+Path_Shell)
159 Path_Cmd = Farm_Directories[1]+Jobs_Name+
'.cmd'
160 cmd_file=open(Path_Cmd,
'w')
163 cmd_file.write(CopyRights +
'\n')
165 cmd_file.write(
'Universe = vanilla\n')
166 cmd_file.write(
'Environment = CONDORJOBID=$(Process)\n')
167 cmd_file.write(
'notification = Error\n')
169 if(commands.getstatusoutput(
"uname -n")[1].
find(
"ucl.ac.be")!=-1):
170 cmd_file.write(
'requirements = (CMSFARM=?=True)&&(Memory > 200)\n')
172 cmd_file.write(
'requirements = (Memory > 200)\n')
173 cmd_file.write(
'should_transfer_files = YES\n')
174 cmd_file.write(
'when_to_transfer_output = ON_EXIT\n')
178 global runInteractively
183 Path_Log = Farm_Directories[2]+Jobs_Index+Jobs_Name
184 cmd_file=open(Path_Cmd,
'a')
187 cmd_file.write(
"sh "+ os.getcwd() +
"/"+Path_Shell +
"\n")
190 cmd_file.write(
"bsub -q " + Jobs_Queue +
" -J " + Jobs_Name+Jobs_Index +
" '" + os.getcwd() +
"/"+Path_Shell +
" 0 ele'\n")
192 cmd_file.write(
"bsub -o /dev/null -q " + Jobs_Queue +
" -J " + Jobs_Name+Jobs_Index +
" '" + os.getcwd() +
"/"+Path_Shell +
" 0 ele'\n")
195 cmd_file.write(
'Executable = %s\n' % Path_Shell)
196 cmd_file.write(
'output = %s.out\n' % Path_Log)
197 cmd_file.write(
'error = %s.err\n' % Path_Log)
198 cmd_file.write(
'log = %s.log\n' % Path_Log)
199 cmd_file.write(
'Queue 1\n')
204 global Farm_Directories
205 Farm_Directories = [FarmDirectory+
'/', FarmDirectory+
'/inputs/', FarmDirectory+
'/logs/', FarmDirectory+
'/outputs/']
206 for i
in range(0,len(Farm_Directories)):
207 if os.path.isdir(Farm_Directories[i]) ==
False:
208 os.system(
'mkdir ' + Farm_Directories[i])
212 input_file = open(path,
'r')
213 input_lines = input_file.readlines()
217 BlockSize = (len(input_lines)/NJobs)
222 while LineIndex < len(input_lines):
223 Jobs_Inputs[JobIndex] += input_lines[LineIndex]
226 if BlockIndex>BlockSize:
229 Jobs_Inputs.append(
"")
236 global Farm_Directories
237 global runInteractively
239 if(runInteractively): useLSF=
True
242 command_out = commands.getstatusoutput(
"bjobs")[1]
243 if(command_out.find(
"command not found")<0): useLSF =
True
244 else: useLSF =
False;
252 global Farm_Directories
258 Jobs_Index =
"%04i_" % Jobs_Count
259 if Jobs_Count==0
and (Argv[0]==
"ROOT" or Argv[0]==
"FWLITE"):
261 print(
"Compiling the Macro...")
263 os.system(
'sh '+Path_Shell)
264 os.system(
'rm '+Path_Shell)
265 print(
"Getting the jobs...")
269 Jobs_Count = Jobs_Count+1
278 os.system(
"sh " + Path_Cmd)
280 os.system(
"condor_submit " + Path_Cmd)
282 print(
'\n'+CopyRights)
283 print(
'%i Job(s) has/have been submitted on the Computing Cluster' % Jobs_Count)
290 def SendCMSJobs(FarmDirectory, JobName, ConfigFile, InputFiles, NJobs, Argv):
293 for i
in range(NJobs):
294 LaunchOnCondor.SendCluster_Push ([
"CMSSW", ConfigFile])
302 if(InputPattern.find(
'/store/cmst3')==0) :
303 index = InputPattern.rfind(
'/')
304 Listtmp = commands.getstatusoutput(
'cmsLs ' + InputPattern[0:index] +
' | awk \'{print $5}\'')[1].
split(
'\n')
305 pattern = InputPattern[index+1:len(InputPattern)]
307 if fnmatch.fnmatch(file, pattern): List.append(InputPattern[0:index]+
'/'+file)
308 elif(InputPattern.find(
'/castor/')==0):
309 index = InputPattern.rfind(
'/')
310 Listtmp = commands.getstatusoutput(
'rfdir ' + InputPattern[0:index] +
' | awk \'{print $9}\'')[1].
split(
'\n')
311 pattern = InputPattern[index+1:len(InputPattern)]
313 if fnmatch.fnmatch(file, pattern): List.append(InputPattern[0:index]+
'/'+file)
315 List = glob.glob(InputPattern)
318 for i
in range(len(List)):
319 List[i] = Prefix + List[i] + Suffix
325 for i
in range(len(InputList)):
326 outString += InputList[i]
330 out_file=open(outputFile,
'w')
331 for i
in range(len(InputList)):
332 out_file.write(
' ' + InputList[i] +
'\n')
336 input_file = open(path,
'r')
337 input_lines = input_file.readlines()
345 Temp_Cfg = Farm_Directories[1]+Jobs_Index+Jobs_Name+
'_TEMP_cfg.py'
347 if len(InputFiles)==0:
348 print(
'Empty InputFile List for Job named "%s", Job will not be submitted' % JobName)
351 InputFilesString =
""
352 for i
in range(len(InputFiles)):
353 InputFilesString +=
" " + InputFiles[i] +
'\n'
355 cfg_file=open(Temp_Cfg,
'w')
356 cfg_file.write(
'import FWCore.ParameterSet.Config as cms\n')
357 cfg_file.write(
'process = cms.Process("Merge")\n')
359 cfg_file.write(
'process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )\n')
360 cfg_file.write(
'process.load("FWCore.MessageService.MessageLogger_cfi")\n')
362 cfg_file.write(
'process.MessageLogger.cerr.FwkReport.reportEvery = 50000\n')
363 cfg_file.write(
'process.source = cms.Source("PoolSource",\n')
364 cfg_file.write(
' fileNames = cms.untracked.vstring(\n')
365 cfg_file.write(
'%s' % InputFilesString)
366 cfg_file.write(
' )\n')
367 cfg_file.write(
')\n')
369 cfg_file.write(
'process.OUT = cms.OutputModule("PoolOutputModule",\n')
370 cfg_file.write(
' outputCommands = cms.untracked.vstring(%s),\n' % KeepStatement)
371 cfg_file.write(
' fileName = cms.untracked.string(%s)\n' % OutputFile)
372 cfg_file.write(
')\n')
374 cfg_file.write(
'process.endPath = cms.EndPath(process.OUT)\n')
376 SendCluster_Push ([
"CMSSW", Temp_Cfg])
378 os.system(
'rm '+ Temp_Cfg)