CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Alignment/MuonAlignmentAlgorithms/scripts/createCSCRingsJobs.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import os, sys, optparse, math
00004 
00005 copyargs = sys.argv[:]
00006 for i in range(len(copyargs)):
00007     if copyargs[i] == "":
00008         copyargs[i] = "\"\""
00009     if copyargs[i].find(" ") != -1:
00010         copyargs[i] = "\"%s\"" % copyargs[i]
00011 commandline = " ".join(copyargs)
00012 
00013 prog = sys.argv[0]
00014 
00015 usage = """./%(prog)s DIRNAME ITERATIONS INITIALGEOM INPUTFILES [options]
00016 
00017 Creates (overwrites) a directory for each of the iterations and creates (overwrites)
00018 submitJobs.sh with the submission sequence and dependencies.
00019 
00020 DIRNAME        directories will be named DIRNAME01, DIRNAME02...
00021 ITERATIONS     number of iterations
00022 INITIALGEOM    SQLite file containing muon geometry with tag names
00023                DTAlignmentRcd, DTAlignmentErrorRcd, CSCAlignmentRcd, CSCAlignmentErrorRcd
00024 INPUTFILES     Python file defining 'fileNames', a list of input files as
00025                strings (create with findQualityFiles.py)""" % vars()
00026 
00027 parser = optparse.OptionParser(usage)
00028 parser.add_option("--validationLabel",
00029                   help="[REQUIRED] the label to be used to mark a run; the results will be put into a LABEL_DATESTAMP.tgz tarball",
00030                   type="string",
00031                   default="",
00032                   dest="validationLabel")
00033 parser.add_option("-j", "--jobs",
00034                    help="approximate number of \"gather\" subjobs",
00035                    type="int",
00036                    default=50,
00037                    dest="subjobs")
00038 parser.add_option("-s", "--submitJobs",
00039                    help="alternate name of submitJobs.sh script (please include .sh extension); a file with this name will be OVERWRITTEN",
00040                    type="string",
00041                    default="submitJobs.sh",
00042                    dest="submitJobs")
00043 parser.add_option("-b", "--big",
00044                   help="if invoked, subjobs will also be run on cmscaf1nd",
00045                   action="store_true",
00046                   dest="big")
00047 parser.add_option("--globalTag",
00048                   help="GlobalTag for alignment/calibration conditions (typically all conditions except muon and tracker alignment)",
00049                   type="string",
00050                   default="CRAFT0831X_V1::All",
00051                   dest="globaltag")
00052 parser.add_option("--trackerconnect",
00053                   help="connect string for tracker alignment (frontier://... or sqlite_file:...)",
00054                   type="string",
00055                   default="",
00056                   dest="trackerconnect")
00057 parser.add_option("--trackeralignment",
00058                   help="name of TrackerAlignmentRcd tag",
00059                   type="string",
00060                   default="Alignments",
00061                   dest="trackeralignment")
00062 parser.add_option("--trackerAPEconnect",
00063                   help="connect string for tracker APEs (frontier://... or sqlite_file:...)",
00064                   type="string",
00065                   default="",
00066                   dest="trackerAPEconnect")
00067 parser.add_option("--trackerAPE",
00068                   help="name of TrackerAlignmentErrorRcd tag (tracker APEs)",
00069                   type="string",
00070                   default="AlignmentErrors",
00071                   dest="trackerAPE")
00072 parser.add_option("--gprcdconnect",
00073                   help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...)",
00074                   type="string",
00075                   default="",
00076                   dest="gprcdconnect")
00077 parser.add_option("--gprcd",
00078                   help="name of GlobalPositionRcd tag",
00079                   type="string",
00080                   default="GlobalPosition",
00081                   dest="gprcd")
00082 parser.add_option("--iscosmics",
00083                   help="if invoked, use cosmic track refitter instead of the standard one",
00084                   action="store_true",
00085                   dest="iscosmics")
00086 parser.add_option("--station123params",
00087                   help="alignable parameters for DT stations 1, 2, 3 (see SWGuideAlignmentAlgorithms#Selection_of_what_to_align)",
00088                   type="string",
00089                   default="111111",
00090                   dest="station123params")
00091 parser.add_option("--station4params",
00092                   help="alignable parameters for DT station 4",
00093                   type="string",
00094                   default="100011",
00095                   dest="station4params")
00096 parser.add_option("--cscparams",
00097                   help="alignable parameters for CSC chambers",
00098                   type="string",
00099                   default="100011",
00100                   dest="cscparams")
00101 parser.add_option("--minTrackPt",
00102                   help="minimum allowed track transverse momentum (in GeV)",
00103                   type="string",
00104                   default="0",
00105                   dest="minTrackPt")
00106 parser.add_option("--maxTrackPt",
00107                   help="maximum allowed track transverse momentum (in GeV)",
00108                   type="string",
00109                   default="1000",
00110                   dest="maxTrackPt")
00111 parser.add_option("--minTrackP",
00112                   help="minimum allowed track momentum (in GeV)",
00113                   type="string",
00114                   default="0",
00115                   dest="minTrackP")
00116 parser.add_option("--maxTrackP",
00117                   help="maximum allowed track momentum (in GeV)",
00118                   type="string",
00119                   default="10000",
00120                   dest="maxTrackP")
00121 parser.add_option("--minTrackerHits",
00122                   help="minimum number of tracker hits",
00123                   type="int",
00124                   default=15,
00125                   dest="minTrackerHits")
00126 parser.add_option("--maxTrackerRedChi2",
00127                   help="maximum tracker chi^2 per degrees of freedom",
00128                   type="string",
00129                   default="10",
00130                   dest="maxTrackerRedChi2")
00131 parser.add_option("--notAllowTIDTEC",
00132                   help="if invoked, do not allow tracks that pass through the tracker's TID||TEC region (not recommended)",
00133                   action="store_true",
00134                   dest="notAllowTIDTEC")
00135 parser.add_option("--twoBin",
00136                   help="if invoked, apply the \"two-bin method\" to control charge-antisymmetric errors",
00137                   action="store_true",
00138                   dest="twoBin")
00139 parser.add_option("--weightAlignment",
00140                   help="if invoked, segments will be weighted by ndf/chi^2 in the alignment",
00141                   action="store_true",
00142                   dest="weightAlignment")
00143 parser.add_option("--minAlignmentSegments",
00144                   help="minimum number of segments required to align a chamber",
00145                   type="int",
00146                   default=5,
00147                   dest="minAlignmentHits")
00148 parser.add_option("--notCombineME11",
00149                   help="if invoked, treat ME1/1a and ME1/1b as separate objects",
00150                   action="store_true",
00151                   dest="notCombineME11")
00152 parser.add_option("--maxEvents",
00153                   help="maximum number of events",
00154                   type="string",
00155                   default="-1",
00156                   dest="maxEvents")
00157 parser.add_option("--skipEvents",
00158                   help="number of events to be skipped",
00159                   type="string",
00160                   default="0",
00161                   dest="skipEvents")
00162 parser.add_option("--maxResSlopeY",
00163                   help="maximum residual slope y component",
00164                   type="string",
00165                   default="10",
00166                   dest="maxResSlopeY")
00167 parser.add_option("--ring2only",
00168                   help="if invoked, use only ring 2 results to align all rings in corresponding disks",
00169                   action="store_true",
00170                   dest="ring2only")
00171 parser.add_option("--createMapNtuple",
00172                   help="if invoked while mapplots are switched on, a special ntuple would be created",
00173                   action="store_true",
00174                   dest="createMapNtuple")
00175 parser.add_option("--inputInBlocks",
00176                   help="if invoked, assume that INPUTFILES provides a list of files already groupped into job blocks, -j has no effect in that case",
00177                   action="store_true",
00178                   dest="inputInBlocks")
00179 parser.add_option("--json",
00180                   help="If present with JSON file as argument, use JSON file for good lumi mask. "+\
00181                   "The latest JSON file is available at /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions11/7TeV/Prompt/",
00182                   type="string",
00183                   default="",
00184                   dest="json")
00185 parser.add_option("--preFilter",
00186                   help="if invoked, MuonAlignmentPreFilter module would be invoked in the Path's beginning. Can significantly speed up gather jobs.",
00187                   action="store_true",
00188                   dest="preFilter")
00189 parser.add_option("--useTrackerMuons",
00190                   help="use tracker muons approach instead of the default global muons tracks based one",
00191                   action="store_true",
00192                   dest="useTrackerMuons")
00193 parser.add_option("--muonCollectionTag",
00194                   help="InputTag of muons collection to use in tracker muons based approach",
00195                   type="string",
00196                   default="newmuons",
00197                   dest="muonCollectionTag")
00198 parser.add_option("--maxDxy",
00199                   help="maximum track impact parameter with relation to beamline",
00200                   type="string",
00201                   default="1000.",
00202                   dest="maxDxy")
00203 parser.add_option("--minNCrossedChambers",
00204                   help="minimum number of muon chambers that a track is required to cross",
00205                   type="string",
00206                   default="2",
00207                   dest="minNCrossedChambers")
00208 
00209 if len(sys.argv) < 5:
00210     raise SystemError, "Too few arguments.\n\n"+parser.format_help()
00211 
00212 DIRNAME = sys.argv[1]
00213 ITERATIONS = int(sys.argv[2])
00214 INITIALGEOM = sys.argv[3]
00215 INPUTFILES = sys.argv[4]
00216 
00217 options, args = parser.parse_args(sys.argv[5:])
00218 globaltag = options.globaltag
00219 trackerconnect = options.trackerconnect
00220 trackeralignment = options.trackeralignment
00221 trackerAPEconnect = options.trackerAPEconnect
00222 trackerAPE = options.trackerAPE
00223 gprcdconnect = options.gprcdconnect
00224 gprcd = options.gprcd
00225 iscosmics = str(options.iscosmics)
00226 station123params = options.station123params
00227 station4params = options.station4params
00228 cscparams = options.cscparams
00229 muonCollectionTag = options.muonCollectionTag
00230 minTrackPt = options.minTrackPt
00231 maxTrackPt = options.maxTrackPt
00232 minTrackP = options.minTrackP
00233 maxTrackP = options.maxTrackP
00234 maxDxy = options.maxDxy
00235 minTrackerHits = str(options.minTrackerHits)
00236 maxTrackerRedChi2 = options.maxTrackerRedChi2
00237 minNCrossedChambers = options.minNCrossedChambers
00238 allowTIDTEC = str(not options.notAllowTIDTEC)
00239 twoBin = str(options.twoBin)
00240 weightAlignment = str(options.weightAlignment)
00241 minAlignmentHits = str(options.minAlignmentHits)
00242 combineME11 = str(not options.notCombineME11)
00243 maxEvents = options.maxEvents
00244 skipEvents = options.skipEvents
00245 validationLabel = options.validationLabel
00246 maxResSlopeY = options.maxResSlopeY
00247 preFilter = not not options.preFilter
00248 useTrackerMuons = options.useTrackerMuons
00249 
00250 createMapNtuple=False
00251 if options.createMapNtuple: createMapNtuple=True
00252 
00253 ring2only = ""
00254 if options.ring2only: ring2only = "--ring2only"
00255 inputInBlocks = ""
00256 if options.inputInBlocks: inputInBlocks = "--inputInBlocks"
00257 
00258 json_file = options.json
00259 
00260 if validationLabel == '':
00261   print "\nOne or more of REQUIRED options is missing!\n"
00262   parser.print_help()
00263   sys.exit()
00264 
00265 fileNames=[]
00266 fileNamesBlocks=[]
00267 execfile(INPUTFILES)
00268 njobs = options.subjobs
00269 if (options.inputInBlocks):
00270   njobs = len(fileNamesBlocks)
00271   if njobs==0:
00272     print "while --inputInBlocks is specified, the INPUTFILES has no blocks!"
00273     sys.exit()
00274 
00275 stepsize = int(math.ceil(1.*len(fileNames)/njobs))
00276 
00277 pwd = str(os.getcwdu())
00278 
00279 bsubfile = ["#!/bin/sh", ""]
00280 bsubnames = []
00281 last_align = None
00282 
00283 #####################################################################
00284 # step 0: convert initial geometry to xml
00285 INITIALXML = INITIALGEOM + '.xml'
00286 if INITIALGEOM[-3:]=='.db':
00287   INITIALXML = INITIALGEOM[:-3] + '.xml'
00288 print "Converting",INITIALGEOM,"to",INITIALXML," ...will be done in several seconds..."
00289 exit_code = os.system("./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py  %s %s" % (INITIALGEOM,INITIALXML))
00290 if exit_code>0:
00291   print "problem: conversion exited with code:", exit_code
00292   sys.exit()
00293 
00294 
00295 #####################################################################
00296 # do two iterations of gather + align jobs
00297 directory = ""
00298 for iteration in range(1, ITERATIONS+1):
00299     if iteration == 1:
00300         inputdb = INITIALGEOM
00301         inputdbdir = directory[:]
00302         inputxml = INITIALXML
00303     else:
00304         inputdb = director + ".db"
00305         inputdbdir = directory[:]
00306         inputxml = director + ".xml"
00307 
00308     directory = "%s%02d/" % (DIRNAME, iteration)
00309     director = directory[:-1]
00310     directory1 = "%s01/" % DIRNAME
00311     director1 = directory1[:-1]
00312     os.system("rm -rf %s; mkdir %s" % (directory, directory))
00313     os.system("cp gather_cfg.py %s" % directory)
00314     #os.system("cp align_cfg.py %s" % directory)
00315 
00316     bsubfile.append("cd %s" % directory)
00317 
00318     for jobnumber in range(njobs):
00319         gather_fileName = "%sgather%03d.sh" % (directory, jobnumber)
00320         if not options.inputInBlocks:
00321           inputfiles = " ".join(fileNames[jobnumber*stepsize:(jobnumber+1)*stepsize])
00322         else:
00323           inputfiles = " ".join(fileNamesBlocks[jobnumber])
00324 
00325         copyplots = "plotting*.root"
00326 
00327         copytrackerdb = ""
00328         if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
00329         if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
00330         if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
00331 
00332         if len(inputfiles) > 0:
00333             file(gather_fileName, "w").write("""#/bin/sh
00334 # %(commandline)s
00335 
00336 export ALIGNMENT_CAFDIR=`pwd`
00337 
00338 cd %(pwd)s
00339 eval `scramv1 run -sh`
00340 export ALIGNMENT_AFSDIR=`pwd`
00341 
00342 export ALIGNMENT_INPUTFILES='%(inputfiles)s'
00343 export ALIGNMENT_ITERATION=%(iteration)d
00344 export ALIGNMENT_JOBNUMBER=%(jobnumber)d
00345 export ALIGNMENT_MAPPLOTS=True
00346 export ALIGNMENT_SEGDIFFPLOTS=True
00347 export ALIGNMENT_CURVATUREPLOTS=False
00348 export ALIGNMENT_GLOBALTAG=%(globaltag)s
00349 export ALIGNMENT_INPUTDB=%(inputdb)s
00350 export ALIGNMENT_TRACKERCONNECT=%(trackerconnect)s
00351 export ALIGNMENT_TRACKERALIGNMENT=%(trackeralignment)s
00352 export ALIGNMENT_TRACKERAPECONNECT=%(trackerAPEconnect)s
00353 export ALIGNMENT_TRACKERAPE=%(trackerAPE)s
00354 export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s
00355 export ALIGNMENT_GPRCD=%(gprcd)s
00356 export ALIGNMENT_ISCOSMICS=%(iscosmics)s
00357 export ALIGNMENT_STATION123PARAMS=%(station123params)s
00358 export ALIGNMENT_STATION4PARAMS=%(station4params)s
00359 export ALIGNMENT_CSCPARAMS=%(cscparams)s
00360 export ALIGNMENT_MUONCOLLECTIONTAG=%(muonCollectionTag)s
00361 export ALIGNMENT_MINTRACKPT=%(minTrackPt)s
00362 export ALIGNMENT_MAXTRACKPT=%(maxTrackPt)s
00363 export ALIGNMENT_MINTRACKP=%(minTrackP)s
00364 export ALIGNMENT_MAXTRACKP=%(maxTrackP)s
00365 export ALIGNMENT_MAXDXY=%(maxDxy)s
00366 export ALIGNMENT_MINTRACKERHITS=%(minTrackerHits)s
00367 export ALIGNMENT_MAXTRACKERREDCHI2=%(maxTrackerRedChi2)s
00368 export ALIGNMENT_MINNCROSSEDCHAMBERS=%(minNCrossedChambers)s
00369 export ALIGNMENT_ALLOWTIDTEC=%(allowTIDTEC)s
00370 export ALIGNMENT_TWOBIN=%(twoBin)s
00371 export ALIGNMENT_WEIGHTALIGNMENT=%(weightAlignment)s
00372 export ALIGNMENT_MINALIGNMENTHITS=%(minAlignmentHits)s
00373 export ALIGNMENT_COMBINEME11=%(combineME11)s
00374 export ALIGNMENT_MAXEVENTS=%(maxEvents)s
00375 export ALIGNMENT_SKIPEVENTS=%(skipEvents)s
00376 export ALIGNMENT_MAXRESSLOPEY=%(maxResSlopeY)s
00377 export ALIGNMENT_DO_DT='False'
00378 export ALIGNMENT_DO_CSC='True'
00379 export ALIGNMENT_JSON=%(json_file)s
00380 export ALIGNMENT_CREATEMAPNTUPLE=%(createMapNtuple)s
00381 export ALIGNMENT_PREFILTER=%(preFilter)s
00382 export ALIGNMENT_USETRACKERMUONS=%(useTrackerMuons)s
00383 
00384 if [ \"zzz$ALIGNMENT_JSON\" != \"zzz\" ]; then
00385   cp -f $ALIGNMENT_JSON $ALIGNMENT_CAFDIR/
00386 fi
00387 
00388 cp -f %(directory)sgather_cfg.py %(inputdbdir)s%(inputdb)s %(copytrackerdb)s $ALIGNMENT_CAFDIR/
00389 cd $ALIGNMENT_CAFDIR/
00390 ls -l
00391 cmsRun gather_cfg.py
00392 ls -l
00393 cp -f %(copyplots)s $ALIGNMENT_AFSDIR/%(directory)s
00394 """ % vars())
00395             os.system("chmod +x %s" % gather_fileName)
00396             bsubfile.append("echo %sgather%03d.sh" % (directory, jobnumber))
00397 
00398             if last_align is None: waiter = ""
00399             else: waiter = "-w \"ended(%s)\"" % last_align
00400             if options.big: queue = "cmscaf1nd"
00401             else: queue = "cmscaf1nh"
00402 
00403             bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_gather%03d\" %s gather%03d.sh" % (queue, director, jobnumber, waiter, jobnumber))
00404 
00405             bsubnames.append("ended(%s_gather%03d)" % (director, jobnumber))
00406 
00407     copytrackerdb = ""
00408     if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
00409     if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
00410     if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
00411 
00412     file("%salign.sh" % directory, "w").write("""#!/bin/sh
00413 # %(commandline)s
00414 
00415 export ALIGNMENT_CAFDIR=`pwd`
00416 mkdir files
00417 mkdir out
00418 
00419 cd %(pwd)s
00420 eval `scramv1 run -sh`
00421 export ALIGNMENT_AFSDIR=`pwd`
00422 
00423 # combine _plotting.root files into one:
00424 nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
00425 if [ \"$nfiles\" != \"0\" ]; then
00426   flist=""
00427   for fn in %(directory)splotting0*.root
00428   do
00429     FILESIZE=$(stat -c%%s "$fn")
00430     if [ $FILESIZE -gt 1000 ]; then
00431       echo $fn, $FILESIZE
00432       flist="$flist $fn"
00433     fi
00434   done
00435   echo $flist
00436   #hadd -f1 %(directory)s%(director)s_plotting.root %(directory)splotting0*.root
00437   hadd -f1 %(directory)s%(director)s_plotting.root $flist
00438   #if [ $? == 0 ]; then rm %(directory)splotting0*.root; fi
00439 fi
00440 
00441 # copy plotting and db files to CAFDIR
00442 cp -f %(directory)s%(director)s_plotting.root  $ALIGNMENT_CAFDIR/files
00443 cp -f inertGlobalPositionRcd.db %(inputdbdir)s%(inputdb)s  %(inputdbdir)s%(inputxml)s  %(copytrackerdb)s  $ALIGNMENT_CAFDIR/
00444 
00445 # copy the scripts to CAFDIR
00446 cd Alignment/MuonAlignmentAlgorithms/scripts/
00447 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
00448 cp -f mutypes.py $ALIGNMENT_CAFDIR/
00449 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
00450 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
00451 cp -f convertSQLiteXML.py $ALIGNMENT_CAFDIR/
00452 cp -f alignCSCRings.py $ALIGNMENT_CAFDIR/
00453 cp -f signConventions.py $ALIGNMENT_CAFDIR/
00454 cd -
00455 
00456 cd $ALIGNMENT_CAFDIR/
00457 ls -l
00458 
00459 # run alignment validation to produce map plots and sin fit results
00460 ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out  --csc --map --segdiff --createDirSructure
00461 
00462 # align CSC rings using the fit results from the previous step
00463 ./alignCSCRings.py -d $ALIGNMENT_CAFDIR/out -l %(validationLabel)s -x %(inputxml)s %(ring2only)s
00464 
00465 # convert ring-aligned xml geometry into sqlite
00466 ./convertSQLiteXML.py %(inputxml)s.ring.xml %(director)s.db
00467 
00468 # convert the new sqlite into proper chambers and layers xml
00469 ./convertSQLiteXML.py %(director)s.db %(director)s.xml
00470 
00471 #copy all good stuff to $ALIGNMENT_AFSDIR/%(directory)s
00472 tar czf %(director)s_%(validationLabel)s.tgz out
00473 cp -f %(director)s_%(validationLabel)s.tgz $ALIGNMENT_AFSDIR/%(directory)s
00474 cp -f out/tmp_test_results_map__%(validationLabel)s.pkl  $ALIGNMENT_AFSDIR/%(directory)s%(director)s.pkl
00475 cp -f %(inputxml)s.ring.xml  $ALIGNMENT_AFSDIR/%(directory)s
00476 cp -f %(director)s.xml  $ALIGNMENT_AFSDIR/%(directory)s
00477 cp -f %(director)s.db  $ALIGNMENT_AFSDIR/%(directory)s
00478 
00479 # if it's last iteration, apply chamber motion policy
00480 #if [ \"$ALIGNMENT_ITERATION\" == 2 ]; then
00481 #  #nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
00482 #fi
00483 
00484 """ % vars())
00485     os.system("chmod +x %salign.sh" % directory)
00486 
00487     bsubfile.append("echo %salign.sh" % directory)
00488     if options.big: queue = "cmscaf1nd"
00489     else: queue = "cmscaf1nh"
00490     bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_align\" -w \"%s\" align.sh" % (queue, director, " && ".join(bsubnames)))
00491     bsubnames = []
00492     last_align = "%s_align" % director
00493     
00494     # after the last iteration do diagnostics run for putting into a browser
00495     if iteration == ITERATIONS:
00496         # do we have plotting files created?
00497         directory1 = "%s01/" % DIRNAME
00498         director1 = directory1[:-1]
00499 
00500         file("%svalidation.sh" % directory, "w").write("""#!/bin/sh
00501 # %(commandline)s
00502 
00503 export ALIGNMENT_CAFDIR=`pwd`
00504 #mkdir files
00505 mkdir out
00506 mkdir tmp
00507 
00508 cd %(pwd)s
00509 eval `scramv1 run -sh`
00510 ALIGNMENT_AFSDIR=`pwd`
00511 
00512 # copy the scripts to CAFDIR
00513 cd Alignment/MuonAlignmentAlgorithms/scripts/
00514 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
00515 cp -f mutypes.py $ALIGNMENT_CAFDIR/
00516 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
00517 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
00518 cp -f createTree.py $ALIGNMENT_CAFDIR/
00519 cp -f signConventions.py $ALIGNMENT_CAFDIR/
00520 cd -
00521 cp Alignment/MuonAlignmentAlgorithms/test/browser/tree* $ALIGNMENT_CAFDIR/out/
00522 
00523 # copy the results to CAFDIR
00524 cp -f %(directory1)s%(director1)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
00525 cp -f %(directory)s%(director)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
00526 
00527 cd $ALIGNMENT_CAFDIR/
00528 tar xzvf tmp/%(director1)s_%(validationLabel)s.tgz
00529 mv tmp/out/* out/
00530 mv out/iterN out/iter1
00531 mv out/tmp_test_results_map__%(validationLabel)s.pkl out/tmp_test_results_map__%(validationLabel)s_1.pkl
00532 tar xzvf tmp/%(director)s_%(validationLabel)s.tgz
00533 mv tmp/out/* out/
00534 
00535 echo \" ### Start running ###\"
00536 date
00537 
00538 # run simple diagnostic
00539 ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out --csc --diagnostic
00540 
00541 # fill the tree browser structure: 
00542 ./createTree.py -i $ALIGNMENT_CAFDIR/out
00543 
00544 timestamp=`date \"+%%y-%%m-%%d %%H:%%M:%%S\"`
00545 echo \"%(validationLabel)s.plots (${timestamp})\" > out/label.txt
00546 
00547 ls -l out/
00548 timestamp=`date +%%Y%%m%%d%%H%%M%%S`
00549 tar czf %(validationLabel)s_${timestamp}.tgz out
00550 cp -f %(validationLabel)s_${timestamp}.tgz $ALIGNMENT_AFSDIR/
00551 
00552 """ % vars())
00553         os.system("chmod +x %svalidation.sh" % directory)
00554         
00555         bsubfile.append("echo %svalidation.sh" % directory)
00556         bsubfile.append("bsub -R \"type==SLC5_64\" -q cmscaf1nd -J \"%s_validation\" -w \"ended(%s)\" validation.sh" % (director, last_align))
00557 
00558     bsubfile.append("cd ..")
00559     bsubfile.append("")
00560 
00561 
00562 file(options.submitJobs, "w").write("\n".join(bsubfile))
00563 os.system("chmod +x %s" % options.submitJobs)
00564