Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:04

0001 #! /usr/bin/env python3
0002 
0003 from builtins import range
0004 import os, sys, optparse, math
0005 
0006 copyargs = sys.argv[:]
0007 for i in range(len(copyargs)):
0008     if copyargs[i] == "":
0009         copyargs[i] = "\"\""
0010     if copyargs[i].find(" ") != -1:
0011         copyargs[i] = "\"%s\"" % copyargs[i]
0012 commandline = " ".join(copyargs)
0013 
0014 prog = sys.argv[0]
0015 
0016 usage = """./%(prog)s DIRNAME ITERATIONS INITIALGEOM INPUTFILES [options]
0017 
0018 Creates (overwrites) a directory for each of the iterations and creates (overwrites)
0019 submitJobs.sh with the submission sequence and dependencies.
0020 
0021 DIRNAME        directories will be named DIRNAME01, DIRNAME02...
0022 ITERATIONS     number of iterations
0023 INITIALGEOM    SQLite file containing muon geometry with tag names
0024                DTAlignmentRcd, DTAlignmentErrorExtendedRcd, CSCAlignmentRcd, CSCAlignmentErrorExtendedRcd
0025 INPUTFILES     Python file defining 'fileNames', a list of input files as
0026                strings (create with findQualityFiles.py)""" % vars()
0027 
0028 parser = optparse.OptionParser(usage)
0029 parser.add_option("--validationLabel",
0030                   help="[REQUIRED] the label to be used to mark a run; the results will be put into a LABEL_DATESTAMP.tgz tarball",
0031                   type="string",
0032                   default="",
0033                   dest="validationLabel")
0034 parser.add_option("-j", "--jobs",
0035                    help="approximate number of \"gather\" subjobs",
0036                    type="int",
0037                    default=50,
0038                    dest="subjobs")
0039 parser.add_option("-s", "--submitJobs",
0040                    help="alternate name of submitJobs.sh script (please include .sh extension); a file with this name will be OVERWRITTEN",
0041                    type="string",
0042                    default="submitJobs.sh",
0043                    dest="submitJobs")
0044 parser.add_option("-b", "--big",
0045                   help="if invoked, subjobs will also be run on cmscaf1nd",
0046                   action="store_true",
0047                   dest="big")
0048 parser.add_option("--globalTag",
0049                   help="GlobalTag for alignment/calibration conditions (typically all conditions except muon and tracker alignment)",
0050                   type="string",
0051                   default="CRAFT0831X_V1::All",
0052                   dest="globaltag")
0053 parser.add_option("--trackerconnect",
0054                   help="connect string for tracker alignment (frontier://... or sqlite_file:...)",
0055                   type="string",
0056                   default="",
0057                   dest="trackerconnect")
0058 parser.add_option("--trackeralignment",
0059                   help="name of TrackerAlignmentRcd tag",
0060                   type="string",
0061                   default="Alignments",
0062                   dest="trackeralignment")
0063 parser.add_option("--trackerAPEconnect",
0064                   help="connect string for tracker APEs (frontier://... or sqlite_file:...)",
0065                   type="string",
0066                   default="",
0067                   dest="trackerAPEconnect")
0068 parser.add_option("--trackerAPE",
0069                   help="name of TrackerAlignmentErrorExtendedRcd tag (tracker APEs)",
0070                   type="string",
0071                   default="AlignmentErrorsExtended",
0072                   dest="trackerAPE")
0073 parser.add_option("--gprcdconnect",
0074                   help="connect string for GlobalPositionRcd (frontier://... or sqlite_file:...)",
0075                   type="string",
0076                   default="",
0077                   dest="gprcdconnect")
0078 parser.add_option("--gprcd",
0079                   help="name of GlobalPositionRcd tag",
0080                   type="string",
0081                   default="GlobalPosition",
0082                   dest="gprcd")
0083 parser.add_option("--iscosmics",
0084                   help="if invoked, use cosmic track refitter instead of the standard one",
0085                   action="store_true",
0086                   dest="iscosmics")
0087 parser.add_option("--station123params",
0088                   help="alignable parameters for DT stations 1, 2, 3 (see SWGuideAlignmentAlgorithms#Selection_of_what_to_align)",
0089                   type="string",
0090                   default="111111",
0091                   dest="station123params")
0092 parser.add_option("--station4params",
0093                   help="alignable parameters for DT station 4",
0094                   type="string",
0095                   default="100011",
0096                   dest="station4params")
0097 parser.add_option("--cscparams",
0098                   help="alignable parameters for CSC chambers",
0099                   type="string",
0100                   default="100011",
0101                   dest="cscparams")
0102 parser.add_option("--minTrackPt",
0103                   help="minimum allowed track transverse momentum (in GeV)",
0104                   type="string",
0105                   default="0",
0106                   dest="minTrackPt")
0107 parser.add_option("--maxTrackPt",
0108                   help="maximum allowed track transverse momentum (in GeV)",
0109                   type="string",
0110                   default="1000",
0111                   dest="maxTrackPt")
0112 parser.add_option("--minTrackP",
0113                   help="minimum allowed track momentum (in GeV)",
0114                   type="string",
0115                   default="0",
0116                   dest="minTrackP")
0117 parser.add_option("--maxTrackP",
0118                   help="maximum allowed track momentum (in GeV)",
0119                   type="string",
0120                   default="10000",
0121                   dest="maxTrackP")
0122 parser.add_option("--minTrackerHits",
0123                   help="minimum number of tracker hits",
0124                   type="int",
0125                   default=15,
0126                   dest="minTrackerHits")
0127 parser.add_option("--maxTrackerRedChi2",
0128                   help="maximum tracker chi^2 per degrees of freedom",
0129                   type="string",
0130                   default="10",
0131                   dest="maxTrackerRedChi2")
0132 parser.add_option("--notAllowTIDTEC",
0133                   help="if invoked, do not allow tracks that pass through the tracker's TID||TEC region (not recommended)",
0134                   action="store_true",
0135                   dest="notAllowTIDTEC")
0136 parser.add_option("--twoBin",
0137                   help="if invoked, apply the \"two-bin method\" to control charge-antisymmetric errors",
0138                   action="store_true",
0139                   dest="twoBin")
0140 parser.add_option("--weightAlignment",
0141                   help="if invoked, segments will be weighted by ndf/chi^2 in the alignment",
0142                   action="store_true",
0143                   dest="weightAlignment")
0144 parser.add_option("--minAlignmentSegments",
0145                   help="minimum number of segments required to align a chamber",
0146                   type="int",
0147                   default=5,
0148                   dest="minAlignmentHits")
0149 parser.add_option("--notCombineME11",
0150                   help="if invoked, treat ME1/1a and ME1/1b as separate objects",
0151                   action="store_true",
0152                   dest="notCombineME11")
0153 parser.add_option("--maxEvents",
0154                   help="maximum number of events",
0155                   type="string",
0156                   default="-1",
0157                   dest="maxEvents")
0158 parser.add_option("--skipEvents",
0159                   help="number of events to be skipped",
0160                   type="string",
0161                   default="0",
0162                   dest="skipEvents")
0163 parser.add_option("--maxResSlopeY",
0164                   help="maximum residual slope y component",
0165                   type="string",
0166                   default="10",
0167                   dest="maxResSlopeY")
0168 parser.add_option("--ring2only",
0169                   help="if invoked, use only ring 2 results to align all rings in corresponding disks",
0170                   action="store_true",
0171                   dest="ring2only")
0172 parser.add_option("--createMapNtuple",
0173                   help="if invoked while mapplots are switched on, a special ntuple would be created",
0174                   action="store_true",
0175                   dest="createMapNtuple")
0176 parser.add_option("--inputInBlocks",
0177                   help="if invoked, assume that INPUTFILES provides a list of files already groupped into job blocks, -j has no effect in that case",
0178                   action="store_true",
0179                   dest="inputInBlocks")
0180 parser.add_option("--json",
0181                   help="If present with JSON file as argument, use JSON file for good lumi mask. "+\
0182                   "The latest JSON file is available at /afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions11/7TeV/Prompt/",
0183                   type="string",
0184                   default="",
0185                   dest="json")
0186 parser.add_option("--preFilter",
0187                   help="if invoked, MuonAlignmentPreFilter module would be invoked in the Path's beginning. Can significantly speed up gather jobs.",
0188                   action="store_true",
0189                   dest="preFilter")
0190 parser.add_option("--useTrackerMuons",
0191                   help="use tracker muons approach instead of the default global muons tracks based one",
0192                   action="store_true",
0193                   dest="useTrackerMuons")
0194 parser.add_option("--muonCollectionTag",
0195                   help="InputTag of muons collection to use in tracker muons based approach",
0196                   type="string",
0197                   default="newmuons",
0198                   dest="muonCollectionTag")
0199 parser.add_option("--maxDxy",
0200                   help="maximum track impact parameter with relation to beamline",
0201                   type="string",
0202                   default="1000.",
0203                   dest="maxDxy")
0204 parser.add_option("--minNCrossedChambers",
0205                   help="minimum number of muon chambers that a track is required to cross",
0206                   type="string",
0207                   default="2",
0208                   dest="minNCrossedChambers")
0209 
0210 if len(sys.argv) < 5:
0211     raise SystemError("Too few arguments.\n\n"+parser.format_help())
0212 
0213 DIRNAME = sys.argv[1]
0214 ITERATIONS = int(sys.argv[2])
0215 INITIALGEOM = sys.argv[3]
0216 INPUTFILES = sys.argv[4]
0217 
0218 options, args = parser.parse_args(sys.argv[5:])
0219 globaltag = options.globaltag
0220 trackerconnect = options.trackerconnect
0221 trackeralignment = options.trackeralignment
0222 trackerAPEconnect = options.trackerAPEconnect
0223 trackerAPE = options.trackerAPE
0224 gprcdconnect = options.gprcdconnect
0225 gprcd = options.gprcd
0226 iscosmics = str(options.iscosmics)
0227 station123params = options.station123params
0228 station4params = options.station4params
0229 cscparams = options.cscparams
0230 muonCollectionTag = options.muonCollectionTag
0231 minTrackPt = options.minTrackPt
0232 maxTrackPt = options.maxTrackPt
0233 minTrackP = options.minTrackP
0234 maxTrackP = options.maxTrackP
0235 maxDxy = options.maxDxy
0236 minTrackerHits = str(options.minTrackerHits)
0237 maxTrackerRedChi2 = options.maxTrackerRedChi2
0238 minNCrossedChambers = options.minNCrossedChambers
0239 allowTIDTEC = str(not options.notAllowTIDTEC)
0240 twoBin = str(options.twoBin)
0241 weightAlignment = str(options.weightAlignment)
0242 minAlignmentHits = str(options.minAlignmentHits)
0243 combineME11 = str(not options.notCombineME11)
0244 maxEvents = options.maxEvents
0245 skipEvents = options.skipEvents
0246 validationLabel = options.validationLabel
0247 maxResSlopeY = options.maxResSlopeY
0248 preFilter = not not options.preFilter
0249 useTrackerMuons = options.useTrackerMuons
0250 
0251 createMapNtuple=False
0252 if options.createMapNtuple: createMapNtuple=True
0253 
0254 ring2only = ""
0255 if options.ring2only: ring2only = "--ring2only"
0256 inputInBlocks = ""
0257 if options.inputInBlocks: inputInBlocks = "--inputInBlocks"
0258 
0259 json_file = options.json
0260 
0261 if validationLabel == '':
0262   print("\nOne or more of REQUIRED options is missing!\n")
0263   parser.print_help()
0264   sys.exit()
0265 
0266 fileNames=[]
0267 fileNamesBlocks=[]
0268 execfile(INPUTFILES)
0269 njobs = options.subjobs
0270 if (options.inputInBlocks):
0271   njobs = len(fileNamesBlocks)
0272   if njobs==0:
0273     print("while --inputInBlocks is specified, the INPUTFILES has no blocks!")
0274     sys.exit()
0275 
0276 stepsize = int(math.ceil(1.*len(fileNames)/njobs))
0277 
0278 pwd = str(os.getcwd())
0279 
0280 bsubfile = ["#!/bin/sh", ""]
0281 bsubnames = []
0282 last_align = None
0283 
0284 #####################################################################
0285 # step 0: convert initial geometry to xml
0286 INITIALXML = INITIALGEOM + '.xml'
0287 if INITIALGEOM[-3:]=='.db':
0288   INITIALXML = INITIALGEOM[:-3] + '.xml'
0289 print("Converting",INITIALGEOM,"to",INITIALXML," ...will be done in several seconds...")
0290 exit_code = os.system("./Alignment/MuonAlignmentAlgorithms/scripts/convertSQLiteXML.py  %s %s" % (INITIALGEOM,INITIALXML))
0291 if exit_code>0:
0292   print("problem: conversion exited with code:", exit_code)
0293   sys.exit()
0294 
0295 
0296 #####################################################################
0297 # do two iterations of gather + align jobs
0298 directory = ""
0299 for iteration in range(1, ITERATIONS+1):
0300     if iteration == 1:
0301         inputdb = INITIALGEOM
0302         inputdbdir = directory[:]
0303         inputxml = INITIALXML
0304     else:
0305         inputdb = director + ".db"
0306         inputdbdir = directory[:]
0307         inputxml = director + ".xml"
0308 
0309     directory = "%s%02d/" % (DIRNAME, iteration)
0310     director = directory[:-1]
0311     directory1 = "%s01/" % DIRNAME
0312     director1 = directory1[:-1]
0313     os.system("rm -rf %s; mkdir %s" % (directory, directory))
0314     os.system("cp gather_cfg.py %s" % directory)
0315     #os.system("cp align_cfg.py %s" % directory)
0316 
0317     bsubfile.append("cd %s" % directory)
0318 
0319     for jobnumber in range(njobs):
0320         gather_fileName = "%sgather%03d.sh" % (directory, jobnumber)
0321         if not options.inputInBlocks:
0322           inputfiles = " ".join(fileNames[jobnumber*stepsize:(jobnumber+1)*stepsize])
0323         else:
0324           inputfiles = " ".join(fileNamesBlocks[jobnumber])
0325 
0326         copyplots = "plotting*.root"
0327 
0328         copytrackerdb = ""
0329         if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
0330         if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
0331         if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
0332 
0333         if len(inputfiles) > 0:
0334             file(gather_fileName, "w").write("""#/bin/sh
0335 # %(commandline)s
0336 
0337 export ALIGNMENT_CAFDIR=`pwd`
0338 
0339 cd %(pwd)s
0340 eval `scramv1 run -sh`
0341 export ALIGNMENT_AFSDIR=`pwd`
0342 
0343 export ALIGNMENT_INPUTFILES='%(inputfiles)s'
0344 export ALIGNMENT_ITERATION=%(iteration)d
0345 export ALIGNMENT_JOBNUMBER=%(jobnumber)d
0346 export ALIGNMENT_MAPPLOTS=True
0347 export ALIGNMENT_SEGDIFFPLOTS=True
0348 export ALIGNMENT_CURVATUREPLOTS=False
0349 export ALIGNMENT_GLOBALTAG=%(globaltag)s
0350 export ALIGNMENT_INPUTDB=%(inputdb)s
0351 export ALIGNMENT_TRACKERCONNECT=%(trackerconnect)s
0352 export ALIGNMENT_TRACKERALIGNMENT=%(trackeralignment)s
0353 export ALIGNMENT_TRACKERAPECONNECT=%(trackerAPEconnect)s
0354 export ALIGNMENT_TRACKERAPE=%(trackerAPE)s
0355 export ALIGNMENT_GPRCDCONNECT=%(gprcdconnect)s
0356 export ALIGNMENT_GPRCD=%(gprcd)s
0357 export ALIGNMENT_ISCOSMICS=%(iscosmics)s
0358 export ALIGNMENT_STATION123PARAMS=%(station123params)s
0359 export ALIGNMENT_STATION4PARAMS=%(station4params)s
0360 export ALIGNMENT_CSCPARAMS=%(cscparams)s
0361 export ALIGNMENT_MUONCOLLECTIONTAG=%(muonCollectionTag)s
0362 export ALIGNMENT_MINTRACKPT=%(minTrackPt)s
0363 export ALIGNMENT_MAXTRACKPT=%(maxTrackPt)s
0364 export ALIGNMENT_MINTRACKP=%(minTrackP)s
0365 export ALIGNMENT_MAXTRACKP=%(maxTrackP)s
0366 export ALIGNMENT_MAXDXY=%(maxDxy)s
0367 export ALIGNMENT_MINTRACKERHITS=%(minTrackerHits)s
0368 export ALIGNMENT_MAXTRACKERREDCHI2=%(maxTrackerRedChi2)s
0369 export ALIGNMENT_MINNCROSSEDCHAMBERS=%(minNCrossedChambers)s
0370 export ALIGNMENT_ALLOWTIDTEC=%(allowTIDTEC)s
0371 export ALIGNMENT_TWOBIN=%(twoBin)s
0372 export ALIGNMENT_WEIGHTALIGNMENT=%(weightAlignment)s
0373 export ALIGNMENT_MINALIGNMENTHITS=%(minAlignmentHits)s
0374 export ALIGNMENT_COMBINEME11=%(combineME11)s
0375 export ALIGNMENT_MAXEVENTS=%(maxEvents)s
0376 export ALIGNMENT_SKIPEVENTS=%(skipEvents)s
0377 export ALIGNMENT_MAXRESSLOPEY=%(maxResSlopeY)s
0378 export ALIGNMENT_DO_DT='False'
0379 export ALIGNMENT_DO_CSC='True'
0380 export ALIGNMENT_JSON=%(json_file)s
0381 export ALIGNMENT_CREATEMAPNTUPLE=%(createMapNtuple)s
0382 export ALIGNMENT_PREFILTER=%(preFilter)s
0383 export ALIGNMENT_USETRACKERMUONS=%(useTrackerMuons)s
0384 
0385 if [ \"zzz$ALIGNMENT_JSON\" != \"zzz\" ]; then
0386   cp -f $ALIGNMENT_JSON $ALIGNMENT_CAFDIR/
0387 fi
0388 
0389 cp -f %(directory)sgather_cfg.py %(inputdbdir)s%(inputdb)s %(copytrackerdb)s $ALIGNMENT_CAFDIR/
0390 cd $ALIGNMENT_CAFDIR/
0391 ls -l
0392 cmsRun gather_cfg.py
0393 ls -l
0394 cp -f %(copyplots)s $ALIGNMENT_AFSDIR/%(directory)s
0395 """ % vars())
0396             os.system("chmod +x %s" % gather_fileName)
0397             bsubfile.append("echo %sgather%03d.sh" % (directory, jobnumber))
0398 
0399             if last_align is None: waiter = ""
0400             else: waiter = "-w \"ended(%s)\"" % last_align
0401             if options.big: queue = "cmscaf1nd"
0402             else: queue = "cmscaf1nh"
0403 
0404             bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_gather%03d\" %s gather%03d.sh" % (queue, director, jobnumber, waiter, jobnumber))
0405 
0406             bsubnames.append("ended(%s_gather%03d)" % (director, jobnumber))
0407 
0408     copytrackerdb = ""
0409     if trackerconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerconnect[12:]
0410     if trackerAPEconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % trackerAPEconnect[12:]
0411     if gprcdconnect[0:12] == "sqlite_file:": copytrackerdb += "%s " % gprcdconnect[12:]
0412 
0413     file("%salign.sh" % directory, "w").write("""#!/bin/sh
0414 # %(commandline)s
0415 
0416 export ALIGNMENT_CAFDIR=`pwd`
0417 mkdir files
0418 mkdir out
0419 
0420 cd %(pwd)s
0421 eval `scramv1 run -sh`
0422 export ALIGNMENT_AFSDIR=`pwd`
0423 
0424 # combine _plotting.root files into one:
0425 nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
0426 if [ \"$nfiles\" != \"0\" ]; then
0427   flist=""
0428   for fn in %(directory)splotting0*.root
0429   do
0430     FILESIZE=$(stat -c%%s "$fn")
0431     if [ $FILESIZE -gt 1000 ]; then
0432       echo $fn, $FILESIZE
0433       flist="$flist $fn"
0434     fi
0435   done
0436   echo $flist
0437   #hadd -f1 %(directory)s%(director)s_plotting.root %(directory)splotting0*.root
0438   hadd -f1 %(directory)s%(director)s_plotting.root $flist
0439   #if [ $? == 0 ]; then rm %(directory)splotting0*.root; fi
0440 fi
0441 
0442 # copy plotting and db files to CAFDIR
0443 cp -f %(directory)s%(director)s_plotting.root  $ALIGNMENT_CAFDIR/files
0444 cp -f inertGlobalPositionRcd.db %(inputdbdir)s%(inputdb)s  %(inputdbdir)s%(inputxml)s  %(copytrackerdb)s  $ALIGNMENT_CAFDIR/
0445 
0446 # copy the scripts to CAFDIR
0447 cd Alignment/MuonAlignmentAlgorithms/scripts/
0448 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
0449 cp -f mutypes.py $ALIGNMENT_CAFDIR/
0450 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
0451 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
0452 cp -f convertSQLiteXML.py $ALIGNMENT_CAFDIR/
0453 cp -f alignCSCRings.py $ALIGNMENT_CAFDIR/
0454 cp -f signConventions.py $ALIGNMENT_CAFDIR/
0455 cd -
0456 
0457 cd $ALIGNMENT_CAFDIR/
0458 ls -l
0459 
0460 # run alignment validation to produce map plots and sin fit results
0461 ./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
0462 
0463 # align CSC rings using the fit results from the previous step
0464 ./alignCSCRings.py -d $ALIGNMENT_CAFDIR/out -l %(validationLabel)s -x %(inputxml)s %(ring2only)s
0465 
0466 # convert ring-aligned xml geometry into sqlite
0467 ./convertSQLiteXML.py %(inputxml)s.ring.xml %(director)s.db
0468 
0469 # convert the new sqlite into proper chambers and layers xml
0470 ./convertSQLiteXML.py %(director)s.db %(director)s.xml
0471 
0472 #copy all good stuff to $ALIGNMENT_AFSDIR/%(directory)s
0473 tar czf %(director)s_%(validationLabel)s.tgz out
0474 cp -f %(director)s_%(validationLabel)s.tgz $ALIGNMENT_AFSDIR/%(directory)s
0475 cp -f out/tmp_test_results_map__%(validationLabel)s.pkl  $ALIGNMENT_AFSDIR/%(directory)s%(director)s.pkl
0476 cp -f %(inputxml)s.ring.xml  $ALIGNMENT_AFSDIR/%(directory)s
0477 cp -f %(director)s.xml  $ALIGNMENT_AFSDIR/%(directory)s
0478 cp -f %(director)s.db  $ALIGNMENT_AFSDIR/%(directory)s
0479 
0480 # if it's last iteration, apply chamber motion policy
0481 #if [ \"$ALIGNMENT_ITERATION\" == 2 ]; then
0482 #  #nfiles=$(ls %(directory)splotting0*.root 2> /dev/null | wc -l)
0483 #fi
0484 
0485 """ % vars())
0486     os.system("chmod +x %salign.sh" % directory)
0487 
0488     bsubfile.append("echo %salign.sh" % directory)
0489     if options.big: queue = "cmscaf1nd"
0490     else: queue = "cmscaf1nh"
0491     bsubfile.append("bsub -R \"type==SLC5_64\" -q %s -J \"%s_align\" -w \"%s\" align.sh" % (queue, director, " && ".join(bsubnames)))
0492     bsubnames = []
0493     last_align = "%s_align" % director
0494     
0495     # after the last iteration do diagnostics run for putting into a browser
0496     if iteration == ITERATIONS:
0497         # do we have plotting files created?
0498         directory1 = "%s01/" % DIRNAME
0499         director1 = directory1[:-1]
0500 
0501         file("%svalidation.sh" % directory, "w").write("""#!/bin/sh
0502 # %(commandline)s
0503 
0504 export ALIGNMENT_CAFDIR=`pwd`
0505 #mkdir files
0506 mkdir out
0507 mkdir tmp
0508 
0509 cd %(pwd)s
0510 eval `scramv1 run -sh`
0511 ALIGNMENT_AFSDIR=`pwd`
0512 
0513 # copy the scripts to CAFDIR
0514 cd Alignment/MuonAlignmentAlgorithms/scripts/
0515 cp -f plotscripts.py $ALIGNMENT_CAFDIR/
0516 cp -f mutypes.py $ALIGNMENT_CAFDIR/
0517 cp -f alignmentValidation.py $ALIGNMENT_CAFDIR/
0518 cp -f phiedges_fitfunctions.C $ALIGNMENT_CAFDIR/
0519 cp -f createTree.py $ALIGNMENT_CAFDIR/
0520 cp -f signConventions.py $ALIGNMENT_CAFDIR/
0521 cd -
0522 cp Alignment/MuonAlignmentAlgorithms/test/browser/tree* $ALIGNMENT_CAFDIR/out/
0523 
0524 # copy the results to CAFDIR
0525 cp -f %(directory1)s%(director1)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
0526 cp -f %(directory)s%(director)s_%(validationLabel)s.tgz $ALIGNMENT_CAFDIR/tmp/
0527 
0528 cd $ALIGNMENT_CAFDIR/
0529 tar xzvf tmp/%(director1)s_%(validationLabel)s.tgz
0530 mv tmp/out/* out/
0531 mv out/iterN out/iter1
0532 mv out/tmp_test_results_map__%(validationLabel)s.pkl out/tmp_test_results_map__%(validationLabel)s_1.pkl
0533 tar xzvf tmp/%(director)s_%(validationLabel)s.tgz
0534 mv tmp/out/* out/
0535 
0536 echo \" ### Start running ###\"
0537 date
0538 
0539 # run simple diagnostic
0540 ./alignmentValidation.py -l %(validationLabel)s -i $ALIGNMENT_CAFDIR --i1 files --iN files --i1prefix %(director1)s --iNprefix %(director)s -o $ALIGNMENT_CAFDIR/out --csc --diagnostic
0541 
0542 # fill the tree browser structure: 
0543 ./createTree.py -i $ALIGNMENT_CAFDIR/out
0544 
0545 timestamp=`date \"+%%y-%%m-%%d %%H:%%M:%%S\"`
0546 echo \"%(validationLabel)s.plots (${timestamp})\" > out/label.txt
0547 
0548 ls -l out/
0549 timestamp=`date +%%Y%%m%%d%%H%%M%%S`
0550 tar czf %(validationLabel)s_${timestamp}.tgz out
0551 cp -f %(validationLabel)s_${timestamp}.tgz $ALIGNMENT_AFSDIR/
0552 
0553 """ % vars())
0554         os.system("chmod +x %svalidation.sh" % directory)
0555         
0556         bsubfile.append("echo %svalidation.sh" % directory)
0557         bsubfile.append("bsub -R \"type==SLC5_64\" -q cmscaf1nd -J \"%s_validation\" -w \"ended(%s)\" validation.sh" % (director, last_align))
0558 
0559     bsubfile.append("cd ..")
0560     bsubfile.append("")
0561 
0562 
0563 file(options.submitJobs, "w").write("\n".join(bsubfile))
0564 os.system("chmod +x %s" % options.submitJobs)
0565