CMS 3D CMS Logo

doHarvest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import sys
5 import os
6 
7 #Check arg,settings
8 
9 if len(sys.argv) != 2 :
10  print("""
11  Usage: create_harvesting_py.py <dataset>
12  example:
13  create_harvesting_py.py \
14  /RelValTTbar/CMSSW_3_1_0_pre4_STARTUP_30X_v1/GEN-SIM-RECO
15  """)
16  sys.exit(10)
17 
18 #Get data files of dataset to be processed
19 if os.getenv('DBSCMD_HOME','NOTSET') == 'NOTSET' :
20  print("dbs not set!")
21  sys.exit(11)
22 
23 if os.getenv('CMSSW_VERSION','NOTSET') == 'NOTSET' :
24  print("""
25  cmssw not set!
26  example:
27  cmsrel CMSSW_3_1_0_pre4
28  cd CMSSW_3_1_0_pre4/src
29  eval `scramv1 runtime -sh`
30  cd -
31  """)
32  sys.exit(12)
33 
34 dsetpath = sys.argv[1]
35 
36 from DBSAPI.dbsApi import DbsApi
37 from DBSAPI.dbsException import *
38 from DBSAPI.dbsApiException import *
39 from DBSAPI.dbsOptions import DbsOptionParser
40 
41 optManager = DbsOptionParser()
42 (opts,args) = optManager.getOpt()
43 api = DbsApi(opts.__dict__)
44 
45 print("dataset: ", dsetpath)
46 print("data files: ")
47 for afile in api.listFiles(path=dsetpath):
48  print(" %s" % afile['LogicalFileName'])
49 
50 #Determine number of events/processes
51 totnevts=0
52 for afile in api.listFiles(path=dsetpath):
53  totnevts += afile['NumberOfEvents']
54 njobs = 1
55 nevtref = 9000
56 if totnevts > nevtref : njobs = (int) (totnevts / 9000)
57 print("Total # events: ", totnevts, \
58  " to be executed in ", njobs, "processes")
59 
60 
61 #Run cmsDriver command
62 raw_cmsdriver = "cmsDriver.py harvest -s HARVESTING:validationHarvesting --mc --conditions FrontierConditions_GlobalTag,STARTUP_30X::All --harvesting AtJobEnd --no_exec -n -1"
63 
64 print("executing cmsdriver command:\n\t", raw_cmsdriver)
65 
66 os.system( '`' + raw_cmsdriver + '`' )
67 
68 
69 #Open output py
70 fin_name="harvest_HARVESTING_STARTUP.py"
71 pyout_name = "harvest.py"
72 os.system("touch " + fin_name)
73 os.system('mv ' + fin_name + " " + pyout_name )
74 pyout = open(pyout_name, 'a')
75 
76 #Added to py config: input, output file name, dqm settings
77 pyout.write("\n\n##additions to cmsDriver output \n")
78 pyout.write("process.dqmSaver.workflow = '" + dsetpath + "'\n")
79 pyout.write("process.source.fileNames = cms.untracked.vstring(\n")
80 
81 for afile in api.listFiles(path=dsetpath):
82  pyout.write(" '%s',\n" % afile['LogicalFileName'])
83 
84 pyout.write(")")
85 pyout.close()
86 
87 
88 #Create crab conf
89 
90 crab_block = """
91 [CRAB]
92 jobtype = cmssw
93 scheduler = glite
94 #server_name =
95 
96 [EDG]
97 remove_default_blacklist=1
98 rb = CERN
99 
100 [USER]
101 return_data = 0
102 copy_data = 1
103 storage_element=srm-cms.cern.ch
104 storage_path=/srm/managerv2?SFN=/castor/cern.ch/
105 user_remote_dir=/user/n/nuno/relval/harvest/
106 publish_data=0
107 thresholdLevel=70
108 eMail=nuno@cern.ch
109 
110 [CMSSW]
111 total_number_of_events=-1
112 show_prod = 1
113 """
114 
115 crab_name="crab.cfg"
116 os.system("touch " + crab_name)
117 os.system("mv " + crab_name + " " + crab_name + "_old")
118 
119 crab_cfg = open(crab_name, 'w')
120 crab_cfg.write(crab_block)
121 
122 rootfile = "DQM_V0001_R000000001" \
123  + dsetpath.replace('/','__') \
124  + ".root"
125 
126 crab_cfg.write("number_of_jobs=" + str(njobs) + "\n")
127 crab_cfg.write("pset=" + pyout_name + "\n")
128 crab_cfg.write("output_file=" + rootfile + "\n")
129 crab_cfg.write("datasetpath=" + dsetpath + "\n")
130 
131 
132 crab_cfg.close()
133 
134 #os.system("cat " + pyout_name)
135 #print "Created crab conf:\t", crab_name,"\n"
136 
137 print('\n\nCreated:\n\t %(pwd)s/%(pf)s \n\t %(pwd)s/%(cf)s' \
138  % {'pwd' : os.environ["PWD"], 'pf' : pyout_name, 'cf' : crab_name})
139 
140 print("Done.")
str
#define str(s)
Definition: TestProcessor.cc:53
dbsApiException
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
dbsException