CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
heppy_batch Namespace Reference

Classes

class  MyBatchManager
 

Functions

def batchScriptCERN
 
def batchScriptIC
 
def batchScriptLocal
 
def batchScriptPADOVA
 
def batchScriptPISA
 
def batchScriptPSI
 

Variables

tuple batchManager = MyBatchManager()
 
list cfgFileName = args[0]
 
tuple cfo = imp.load_source("pycfg", cfgFileName, handle)
 
tuple components = split( [comp for comp in config.components if len(comp.files)>0] )
 
 config = cfo.config
 
tuple handle = open(cfgFileName, 'r')
 
list listOfNames = [comp.name for comp in components]
 
tuple listOfValues = list(range(0, len(components)))
 
float waitingTime = 0.1
 

Function Documentation

def heppy_batch.batchScriptCERN (   jobDir,
  remoteDir = '' 
)
prepare the LSF version of the batch script, to run on LSF

Definition at line 78 of file heppy_batch.py.

References print(), python.rootplot.root2matplotlib.replace(), and digitizers_cfi.strip.

Referenced by heppy_batch.MyBatchManager.PrepareJobUser().

78 
79 def batchScriptCERN( jobDir, remoteDir=''):
80  '''prepare the LSF version of the batch script, to run on LSF'''
81 
82  dirCopy = """echo 'sending the logs back' # will send also root files if copy failed
83 rm Loop/cmsswPreProcessing.root
84 cp -r Loop/* $LS_SUBCWD
85 if [ $? -ne 0 ]; then
86  echo 'ERROR: problem copying job directory back'
87 else
88  echo 'job directory copy succeeded'
89 fi"""
90 
91  if remoteDir=='':
92  cpCmd=dirCopy
93  elif remoteDir.startswith("root://eoscms.cern.ch//eos/cms/store/"):
94  cpCmd="""echo 'sending root files to remote dir'
95 export LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATH #
96 for f in Loop/*/tree*.root
97 do
98  rm Loop/cmsswPreProcessing.root
99  ff=`echo $f | cut -d/ -f2`
100  ff="${{ff}}_`basename $f | cut -d . -f 1`"
101  echo $f
102  echo $ff
103  export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
104  source $VO_CMS_SW_DIR/cmsset_default.sh
105  for try in `seq 1 3`; do
106  echo "Stageout try $try"
107  echo "/afs/cern.ch/project/eos/installation/pro/bin/eos.select mkdir {srm}"
108  /afs/cern.ch/project/eos/installation/pro/bin/eos.select mkdir {srm}
109  echo "/afs/cern.ch/project/eos/installation/pro/bin/eos.select cp `pwd`/$f {srm}/${{ff}}_{idx}.root"
110  /afs/cern.ch/project/eos/installation/pro/bin/eos.select cp `pwd`/$f {srm}/${{ff}}_{idx}.root
111  if [ $? -ne 0 ]; then
112  echo "ERROR: remote copy failed for file $ff"
113  continue
114  fi
115  echo "remote copy succeeded"
116  remsize=$(/afs/cern.ch/project/eos/installation/pro/bin/eos.select find --size {srm}/${{ff}}_{idx}.root | cut -d= -f3)
117  locsize=$(cat `pwd`/$f | wc -c)
118  ok=$(($remsize==$locsize))
119  if [ $ok -ne 1 ]; then
120  echo "Problem with copy (file sizes don't match), will retry in 30s"
121  sleep 30
122  continue
123  fi
124  echo "everything ok"
125  rm $f
126  echo root://eoscms.cern.ch/{srm}/${{ff}}_{idx}.root > $f.url
127  break
128  done
129 done
130 cp -r Loop/* $LS_SUBCWD
131 if [ $? -ne 0 ]; then
132  echo 'ERROR: problem copying job directory back'
133 else
134  echo 'job directory copy succeeded'
135 fi
136 """.format(
137  idx = jobDir[jobDir.find("_Chunk")+6:].strip("/") if '_Chunk' in jobDir else 'all',
138  srm = (""+remoteDir+jobDir[ jobDir.rfind("/") : (jobDir.find("_Chunk") if '_Chunk' in jobDir else len(jobDir)) ]).replace("root://eoscms.cern.ch/","")
139  )
140  else:
141  print("chosen location not supported yet: ", remoteDir)
142  print('path must start with /store/')
143  sys.exit(1)
144 
145  script = """#!/bin/bash
146 #BSUB -q 8nm
147 echo 'environment:'
148 echo
149 env | sort
150 # ulimit -v 3000000 # NO
151 echo 'copying job dir to worker'
152 cd $CMSSW_BASE/src
153 eval `scramv1 ru -sh`
154 # cd $LS_SUBCWD
155 # eval `scramv1 ru -sh`
156 cd -
157 cp -rf $LS_SUBCWD .
158 ls
159 cd `find . -type d | grep /`
160 echo 'running'
161 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
162 echo
163 {copy}
164 """.format(copy=cpCmd)
165 
166  return script
167 
def batchScriptCERN
Definition: heppy_batch.py:78
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def heppy_batch.batchScriptIC (   jobDir)
prepare a IC version of the batch script

Definition at line 264 of file heppy_batch.py.

Referenced by heppy_batch.MyBatchManager.PrepareJobUser().

265 def batchScriptIC(jobDir):
266  '''prepare a IC version of the batch script'''
267 
268 
269  cmssw_release = os.environ['CMSSW_BASE']
270  script = """#!/bin/bash
271 export X509_USER_PROXY=/home/hep/$USER/myproxy
272 source /vols/cms/grid/setup.sh
273 cd {jobdir}
274 cd {cmssw}/src
275 eval `scramv1 ru -sh`
276 cd -
277 echo 'running'
278 python {cmssw}/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
279 echo
280 echo 'sending the job directory back'
281 mv Loop/* ./ && rm -r Loop
282 """.format(jobdir = jobDir,cmssw = cmssw_release)
283  return script
def batchScriptIC
Definition: heppy_batch.py:264
def heppy_batch.batchScriptLocal (   remoteDir,
  index 
)
prepare a local version of the batch script, to run using nohup

Definition at line 284 of file heppy_batch.py.

Referenced by heppy_batch.MyBatchManager.PrepareJobUser().

285 def batchScriptLocal( remoteDir, index ):
286  '''prepare a local version of the batch script, to run using nohup'''
287 
288  script = """#!/bin/bash
289 echo 'running'
290 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
291 echo
292 echo 'sending the job directory back'
293 mv Loop/* ./
294 """
295  return script
296 
def batchScriptLocal
Definition: heppy_batch.py:284
def heppy_batch.batchScriptPADOVA (   index,
  jobDir = './' 
)
prepare the LSF version of the batch script, to run on LSF

Definition at line 17 of file heppy_batch.py.

Referenced by heppy_batch.MyBatchManager.PrepareJobUser().

17 
18 def batchScriptPADOVA( index, jobDir='./'):
19  '''prepare the LSF version of the batch script, to run on LSF'''
20  script = """#!/bin/bash
21 #BSUB -q local
22 #BSUB -J test
23 #BSUB -o test.log
24 cd {jdir}
25 echo 'PWD:'
26 pwd
27 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
28 source $VO_CMS_SW_DIR/cmsset_default.sh
29 echo 'environment:'
30 echo
31 env > local.env
32 env
33 # ulimit -v 3000000 # NO
34 echo 'copying job dir to worker'
35 eval `scram runtime -sh`
36 ls
37 echo 'running'
38 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json >& local.output
39 exit $?
40 #echo
41 #echo 'sending the job directory back'
42 #echo cp -r Loop/* $LS_SUBCWD
43 """.format(jdir=jobDir)
44 
45  return script
def batchScriptPADOVA
Definition: heppy_batch.py:17
def heppy_batch.batchScriptPISA (   index,
  remoteDir = '' 
)
prepare the LSF version of the batch script, to run on LSF

Definition at line 46 of file heppy_batch.py.

Referenced by heppy_batch.MyBatchManager.PrepareJobUser().

46 
47 def batchScriptPISA( index, remoteDir=''):
48  '''prepare the LSF version of the batch script, to run on LSF'''
49  script = """#!/bin/bash
50 #BSUB -q cms
51 echo 'PWD:'
52 pwd
53 export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
54 source $VO_CMS_SW_DIR/cmsset_default.sh
55 echo 'environment:'
56 echo
57 env > local.env
58 env
59 # ulimit -v 3000000 # NO
60 echo 'copying job dir to worker'
61 ###cd $CMSSW_BASE/src
62 eval `scramv1 runtime -sh`
63 #eval `scramv1 ru -sh`
64 # cd $LS_SUBCWD
65 # eval `scramv1 ru -sh`
66 ##cd -
67 ##cp -rf $LS_SUBCWD .
68 ls
69 echo `find . -type d | grep /`
70 echo 'running'
71 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json >& local.output
72 exit $?
73 #echo
74 #echo 'sending the job directory back'
75 #echo cp -r Loop/* $LS_SUBCWD
76 """
77  return script
def batchScriptPISA
Definition: heppy_batch.py:46
def heppy_batch.batchScriptPSI (   index,
  jobDir,
  remoteDir = '' 
)
prepare the SGE version of the batch script, to run on the PSI tier3 batch system

Definition at line 168 of file heppy_batch.py.

References print().

169 def batchScriptPSI( index, jobDir, remoteDir=''):
170  '''prepare the SGE version of the batch script, to run on the PSI tier3 batch system'''
171 
172  cmssw_release = os.environ['CMSSW_BASE']
173  VO_CMS_SW_DIR = "/swshare/cms" # $VO_CMS_SW_DIR doesn't seem to work in the new SL6 t3wn
174 
175  if remoteDir=='':
176  cpCmd="""echo 'sending the job directory back'
177 rm Loop/cmsswPreProcessing.root
178 cp -r Loop/* $SUBMISIONDIR"""
179  elif remoteDir.startswith("/pnfs/psi.ch"):
180  cpCmd="""echo 'sending root files to remote dir'
181 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/dcap/ # Fabio's workaround to fix gfal-tools
182 for f in Loop/mt2*.root
183 do
184  ff=`basename $f | cut -d . -f 1`
185  #d=`echo $f | cut -d / -f 2`
186  gfal-mkdir {srm}
187  echo "gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root"
188  gfal-copy file://`pwd`/Loop/$ff.root {srm}/${{ff}}_{idx}.root
189  if [ $? -ne 0 ]; then
190  echo "ERROR: remote copy failed for file $ff"
191  else
192  echo "remote copy succeeded"
193  rm Loop/$ff.root
194  fi
195 done
196 rm Loop/cmsswPreProcessing.root
197 cp -r Loop/* $SUBMISIONDIR""".format(idx=index, srm='srm://t3se01.psi.ch'+remoteDir+jobDir[jobDir.rfind("/"):jobDir.find("_Chunk")])
198  else:
199  print("remote directory not supported yet: ", remoteDir)
200  print('path must start with "/pnfs/psi.ch"')
201  sys.exit(1)
202 
203 
204  script = """#!/bin/bash
205 shopt expand_aliases
206 ##### MONITORING/DEBUG INFORMATION ###############################
207 DATE_START=`date +%s`
208 echo "Job started at " `date`
209 cat <<EOF
210 ################################################################
211 ## QUEUEING SYSTEM SETTINGS:
212 HOME=$HOME
213 USER=$USER
214 JOB_ID=$JOB_ID
215 JOB_NAME=$JOB_NAME
216 HOSTNAME=$HOSTNAME
217 TASK_ID=$TASK_ID
218 QUEUE=$QUEUE
219 
220 EOF
221 echo "######## Environment Variables ##########"
222 env
223 echo "################################################################"
224 TOPWORKDIR=/scratch/`whoami`
225 JOBDIR=sgejob-$JOB_ID
226 WORKDIR=$TOPWORKDIR/$JOBDIR
227 SUBMISIONDIR={jdir}
228 if test -e "$WORKDIR"; then
229  echo "ERROR: WORKDIR ($WORKDIR) already exists! Aborting..." >&2
230  exit 1
231 fi
232 mkdir -p $WORKDIR
233 if test ! -d "$WORKDIR"; then
234  echo "ERROR: Failed to create workdir ($WORKDIR)! Aborting..." >&2
235  exit 1
236 fi
237 
238 #source $VO_CMS_SW_DIR/cmsset_default.sh
239 source {vo}/cmsset_default.sh
240 export SCRAM_ARCH=slc6_amd64_gcc481
241 #cd $CMSSW_BASE/src
242 cd {cmssw}/src
243 shopt -s expand_aliases
244 cmsenv
245 cd $WORKDIR
246 cp -rf $SUBMISIONDIR .
247 ls
248 cd `find . -type d | grep /`
249 echo 'running'
250 python $CMSSW_BASE/src/PhysicsTools/HeppyCore/python/framework/looper.py pycfg.py config.pck --options=options.json
251 #python $CMSSW_BASE/src/CMGTools/RootTools/python/fwlite/looper.py config.pck
252 echo
253 {copy}
254 ###########################################################################
255 DATE_END=`date +%s`
256 RUNTIME=$((DATE_END-DATE_START))
257 echo "################################################################"
258 echo "Job finished at " `date`
259 echo "Wallclock running time: $RUNTIME s"
260 exit 0
261 """.format(jdir=jobDir, vo=VO_CMS_SW_DIR,cmssw=cmssw_release, copy=cpCmd)
262 
263  return script
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def batchScriptPSI
Definition: heppy_batch.py:168

Variable Documentation

tuple heppy_batch.batchManager = MyBatchManager()

Definition at line 338 of file heppy_batch.py.

list heppy_batch.cfgFileName = args[0]

Definition at line 357 of file heppy_batch.py.

tuple heppy_batch.cfo = imp.load_source("pycfg", cfgFileName, handle)

Definition at line 361 of file heppy_batch.py.

tuple heppy_batch.components = split( [comp for comp in config.components if len(comp.files)>0] )

Definition at line 365 of file heppy_batch.py.

heppy_batch.config = cfo.config

Definition at line 362 of file heppy_batch.py.

tuple heppy_batch.handle = open(cfgFileName, 'r')

Definition at line 359 of file heppy_batch.py.

list heppy_batch.listOfNames = [comp.name for comp in components]

Definition at line 367 of file heppy_batch.py.

tuple heppy_batch.listOfValues = list(range(0, len(components)))

Definition at line 366 of file heppy_batch.py.

float heppy_batch.waitingTime = 0.1

Definition at line 370 of file heppy_batch.py.