Skip to content

Instantly share code, notes, and snippets.

@mattleblanc
Created September 6, 2016 12:00
Show Gist options
  • Save mattleblanc/26d53187b490e46c1ad864897c11ff61 to your computer and use it in GitHub Desktop.
Save mattleblanc/26d53187b490e46c1ad864897c11ff61 to your computer and use it in GitHub Desktop.
import ROOT
import logging
import shutil
import os
logging.basicConfig(level=logging.INFO)
from optparse import OptionParser
parser = OptionParser()
# job configuration
parser.add_option("--submitDir", help="dir to store the output", default="submit_dir")
parser.add_option("--inputRun", help="input run number from EOS", default="none")
parser.add_option("--nevents", type=int, help="number of events to process for all the datasets")
parser.add_option("--skip-events", type=int, help="skip the first n events")
parser.add_option("-w", "--overwrite", action='store_true', default=True, help="overwrite previous submitDir")
parser.add_option("--driver", help="select where to run", choices=("direct", "condor", "prooflite", "proof", "grid"), default="direct")
(options, args) = parser.parse_args()
import atexit
@atexit.register
def quite_exit():
ROOT.gSystem.Exit(0)
logging.info("loading packages")
ROOT.gROOT.SetBatch(True)
ROOT.gROOT.Macro("$ROOTCOREDIR/scripts/load_packages.C")
if options.overwrite:
import shutil
shutil.rmtree(options.submitDir, True)
#Set up the job for xAOD access:
ROOT.xAOD.Init().ignore();
# create a new sample handler to describe the data files we use
logging.info("creating new sample handler")
sh_all = ROOT.SH.SampleHandler()
sh_list = ROOT.SH.DiskListXRD("eosatlas.cern.ch", "/eos/atlas/atlascerngroupdisk/det-larg/Tier0/perm/data16_13TeV/physics_CosmicCalo/"+options.inputRun+"/")
ROOT.SH.ScanDir().filePattern ("*.1").sampleDepth(-2).scan(sh_all, sh_list)
#ROOT.SH.scanDir(sh_all, directory)
# print out the samples we found
logging.info("%d different datasets found scanning all directories", len(sh_all))
print sh_all
# set the name of the tree in our files
sh_all.setMetaString("nc_tree", "CollectionTree")
# this is the basic description of our job
logging.info("creating new job")
job = ROOT.EL.Job()
job.sampleHandler(sh_all)
#Set the xAOD access mode of the job:
job.options().setString( ROOT.EL.Job.optXaodAccessMode,ROOT.EL.Job.optXaodAccessMode_branch );
if options.nevents:
logging.info("processing only %d events", options.nevents)
job.options().setDouble(ROOT.EL.Job.optMaxEvents, options.nevents)
if options.skip_events:
logging.info("skipping first %d events", options.skip_events)
job.options().setDouble(ROOT.EL.Job.optSkipEvents, options.skip_events)
# add our algorithm to the job
logging.info("creating algorithms")
alg_TimeWindowVeto = ROOT.TimeWindowVeto()
#alg.m_dataSource = options.dataSource;
#alg.m_topology = options.topology
logging.info("adding algorithms")
job.algsAdd(alg_TimeWindowVeto)
# make the driver we want to use:
# this one works by running the algorithm directly
logging.info("creating driver")
driver = None
if (options.driver == "direct"):
logging.info("running on direct")
driver = ROOT.EL.DirectDriver()
logging.info("submit job")
driver.submit(job, options.submitDir)
elif (options.driver == "condor" ):
driver = ROOT.EL.CondorDriver()
driver.options().setBool(ROOT.EL.Job.optBatchSharedFileSystem, False) # US Connect
#driver.options().setBool(ROOT.EL.Job.optBatchSharedFileSystem, True) # TRIUMF
driver.options().setString(ROOT.EL.Job.optCondorConf, "stream_output = true")
driver.submitOnly(job, options.submitDir)
elif (options.driver == "prooflite"):
logging.info("running on prooflite")
driver = ROOT.EL.ProofDriver()
logging.info("submit job")
driver.submit(job, options.submitDir)
elif (options.driver == "proof"):
logging.info("running on proof")
driver = ROOT.EL.ProofDriver()
driver.proofMaster = "[email protected]:21001";
driver.makeParOptions = "--nobuild";
driver.proofParm.setString ("PROOF_LookupOpt", "none");
driver.proofParm.setString ("PROOF_INTWAIT", "30000")
driver.proofParm.setString ("PROOF_INITCMD", ROOT.gSystem.GetFromPipe("source $ROOTCOREBIN/../rcSetup.sh -P").Data())
driver.submit (job, options.submitDir);
elif (options.driver == "grid"):
logging.info("running on Grid")
driver = ROOT.EL.PrunDriver()
driver.options().setString("nc_outputSampleName", "user.%nickname%.%in:name[2]%."+options.process+".%in:name[5]%.%in:name[6]%_PlotHF_v1")
driver.options().setDouble("nc_nGBPerJob", 2)
#driver.options().setDouble("nc_disableAutoRetry", 1)
#driver.options().setString("nc_cmtConfig", "x86_64-slc6-gcc48-opt")
#driver.options().setString("EL::Job::optGridMergeOutput", "0")
#driver.options().setString("nc_excludedSite", "TRIUMF-LCG2_DATADISK")
#driver.options().setString("nc_EventLoop_SubmitFlags", "--allowTaskDuplication");
# driver.options().setString("EL::Job::optGridDestSE","CERN-PROD_LOCALGROUPDISK")
#driver.options().setString("nc_optGridDestSE","CERN-PROD_LOCALGROUPDISK")
logging.info("submit job")
driver.submitOnly(job, options.submitDir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment