DESY Hbb Analysis Framework
hlt/submitCrab3Data.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os.path
4 import urllib2
5 import sys
6 from WMCore.Configuration import Configuration
7 from CRABClient.UserUtilities import getUsernameFromSiteDB
8 
9 # colors
10 W = '\033[0m' # white (normal)
11 R = '\033[31m' # red
12 G = '\033[32m' # green
13 O = '\033[33m' # orange
14 B = '\033[34m' # blue
15 P = '\033[35m' # purple
16 
17 
18 ARGSN = len(sys.argv)
19 if ARGSN < 3:
20  print (R+"You need to provide the CMSSW python config, the samples list file and optionally the json in this order"+W)
21  sys.exit()
22 
23 # ---
24 # Some parameter steering
25 RUN_RANGE = ''
26 UNITS_PER_JOB = 10
27 TYPE = 'DATA'
28 CAMPAIGN = 'Run2016/80x_triggerstudies17_run2016hv1_raw_userv35'
29 
30 ARGS = sys.argv
31 PSET = ARGS[1]
32 SAMPLE = ARGS[2]
33 JSON = ''
34 if ARGSN == 4:
35  JSON = ARGS[3]
36 
37 psetname, pset_ext = os.path.splitext(PSET)
38 samplename, sample_ext = os.path.splitext(SAMPLE)
39 
40 if not ( os.path.isfile(PSET) and pset_ext == '.py' ):
41  print (R+"The given python config does not exist or it is not a python file"+W)
42  sys.exit()
43 
44 if not ( os.path.isfile(SAMPLE) and sample_ext == '.txt' ):
45  print (R+"The given sample list file does not exist or it is not a txt file"+W)
46  sys.exit()
47 
48 # Some parameter steering
49 PROCESS = samplename.split('/')[-1]
50 MYPATH = '/store/user/%s/' % (getUsernameFromSiteDB())
51 BASEOUTDIR = MYPATH+'Analysis/Ntuples/' + TYPE + '/' + CAMPAIGN
52 
53 dataset_list = 'samples/data/' + PROCESS + '.txt'
54 f_datasets = open(dataset_list,'r')
55 datasets = f_datasets.readlines()
56 
57 # colors
58 W = '\033[0m' # white (normal)
59 R = '\033[31m' # red
60 G = '\033[32m' # green
61 O = '\033[33m' # orange
62 B = '\033[34m' # blue
63 P = '\033[35m' # purple
64 
65 # _________________________________________________________________________
66 
67 if __name__ == '__main__':
68 
69  from CRABAPI.RawCommand import crabCommand
70  from CRABClient.ClientExceptions import ClientException
71  from httplib import HTTPException
72 
73  from Analysis.Ntuplizer.crabConfig import crabConfig
74  config = crabConfig()
75 
76 # ====== GENERAL
77  config.General.workArea += '_' + PROCESS
78  config.General.transferLogs = False
79 
80 # ====== DATA
81  config.Data.splitting = 'LumiBased'
82  config.Data.unitsPerJob = UNITS_PER_JOB
83  config.Data.totalUnits = -1
84  config.Data.outLFNDirBase = BASEOUTDIR + '/'
85  if JSON != '':
86  config.Data.lumiMask = JSON
87 # config.Data.inputDBS = 'https://cmsweb.cern.ch/dbs/prod/phys03/DBSReader/'
88 # config.Data.allowNonValidInputDataset = True # If dataset not valid yet, will run over valid files only
89  if RUN_RANGE != '':
90  config.Data.runRange = RUN_RANGE
91 
92 
93 # ====== JOBTYPE
94  config.JobType.psetName = PSET
95 # config.JobType.inputFiles = ['Fall15_25nsV2_DATA_PtResolution_AK4PFPuppi.txt','Fall15_25nsV2_DATA_PtResolution_AK4PFchs.txt','Fall15_25nsV2_DATA_SF_AK4PFPuppi.txt','Fall15_25nsV2_DATA_SF_AK4PFchs.txt']
96  config.JobType.numCores = 4
97 
98  for dataset in datasets:
99  dataset = dataset.split('\n')[0]
100  dataset_name = dataset.split('/')[1]
101  dataset_cond = dataset.split('/')[2]
102  dataset_tier = dataset.split('/')[3]
103 #
104  config.Data.inputDataset = dataset
105  config.Data.outputDatasetTag = dataset_cond
106 #
107  config.General.requestName = dataset_name
108  config.General.requestName += '_'+dataset_cond
109  if RUN_RANGE != '':
110  config.General.requestName += '_'+RUN_RANGE
111 
112  outtext = "Submitting dataset " + dataset + "..."
113  print (O+str(outtext)+W)
114 #
115  crabCommand('submit', config = config)
116  print (O+"--------------------------------"+W)
117  print
118 
119 # _________________________________________________________________________