"""
##############################################################################
#                                                                            #
#  Ganga submission script to analyze clusters for TT                        #
#                                                                            #
#  @package ST/STAging                                                       #
#  @author Ch. Elsasser                                                      #
#  @date   27/06/2013                                                        #
#                                                                            #
##############################################################################
"""



# List runs belonging to fills

runDict = {
  0    : [104414]
}

#fills=[1020,1616,1944,2083,2252,2472,2797,3108,3478]
fills=[0]
#fills=[1020]

for k in fills:
  runs=runDict[k]
  print "====================================="
  print "Fill: "+str(k)
  for i in runs:
    print "====================================="
    j=Job(application='Vetra',name="TT-"+str(i))
    print "Run: "+str(i)
    j.application.optsfile="/afs/cern.ch/user/e/elsasser/cmtuser/Vetra_v13r2/ST/STAging/options/base/TTClusters.py"
    j.application.version='v13r2'
    bkq = BKQuery(type='Run', dqflag='All')
    bkq.path = "/"+str(i)+"/Real Data/90000000/RAW"
    print "BK Query path: "+bkq.path
    j.inputdata = bkq.getDataset()
    print "Input data contain "+str(len(j.inputdata.getFileNames()))+" file(s)"
    j.backend=Dirac()
    j.backend.settings['CPUTime']=2*172800
    j.splitter=SplitByFiles(filesPerJob=5,
                            ignoremissing=True,
                            bulksubmit=True)
    j.outputfiles=[DiracFile('*.root')]
    j.postprocessors=[Notifier(address='elsasser@cern.ch')]
    j.submit()
    print "Job submitted!"
    print "====================================="
    print ""
  print ""
