Go to the documentation of this file.00001
00002
00003 import sys
00004 import os
00005
00006
00007
00008 if len(sys.argv) != 2 :
00009 print """
00010 Usage: create_harvesting_py.py <dataset>
00011 example:
00012 create_harvesting_py.py \
00013 /RelValTTbar/CMSSW_3_1_0_pre4_STARTUP_30X_v1/GEN-SIM-RECO
00014 """
00015 sys.exit(10)
00016
00017
00018 if os.getenv('DBSCMD_HOME','NOTSET') == 'NOTSET' :
00019 print "dbs not set!"
00020 sys.exit(11)
00021
00022 if os.getenv('CMSSW_VERSION','NOTSET') == 'NOTSET' :
00023 print """
00024 cmssw not set!
00025 example:
00026 cmsrel CMSSW_3_1_0_pre4
00027 cd CMSSW_3_1_0_pre4/src
00028 eval `scramv1 runtime -sh`
00029 cd -
00030 """
00031 sys.exit(12)
00032
00033 dsetpath = sys.argv[1]
00034
00035 from DBSAPI.dbsApi import DbsApi
00036 from DBSAPI.dbsException import *
00037 from DBSAPI.dbsApiException import *
00038 from DBSAPI.dbsOptions import DbsOptionParser
00039
00040 optManager = DbsOptionParser()
00041 (opts,args) = optManager.getOpt()
00042 api = DbsApi(opts.__dict__)
00043
00044 print "dataset: ", dsetpath
00045 print "data files: "
00046 for afile in api.listFiles(path=dsetpath):
00047 print " %s" % afile['LogicalFileName']
00048
00049
00050 totnevts=0
00051 for afile in api.listFiles(path=dsetpath):
00052 totnevts += afile['NumberOfEvents']
00053 njobs = 1
00054 nevtref = 9000
00055 if totnevts > nevtref : njobs = (int) (totnevts / 9000)
00056 print "Total # events: ", totnevts, \
00057 " to be executed in ", njobs, "processes"
00058
00059
00060
00061 raw_cmsdriver = "cmsDriver.py harvest -s HARVESTING:validationHarvesting --mc --conditions FrontierConditions_GlobalTag,STARTUP_30X::All --harvesting AtJobEnd --no_exec -n -1"
00062
00063 print "executing cmsdriver command:\n\t", raw_cmsdriver
00064
00065 os.system( '`' + raw_cmsdriver + '`' )
00066
00067
00068
00069 fin_name="harvest_HARVESTING_STARTUP.py"
00070 pyout_name = "harvest.py"
00071 os.system("touch " + fin_name)
00072 os.system('mv ' + fin_name + " " + pyout_name )
00073 pyout = open(pyout_name, 'a')
00074
00075
00076 pyout.write("\n\n##additions to cmsDriver output \n")
00077 pyout.write("#DQMStore.referenceFileName = ''\n")
00078 pyout.write("process.dqmSaver.workflow = '" + dsetpath + "'\n")
00079 pyout.write("process.source.fileNames = cms.untracked.vstring(\n")
00080
00081 for afile in api.listFiles(path=dsetpath):
00082 pyout.write(" '%s',\n" % afile['LogicalFileName'])
00083
00084 pyout.write(")")
00085 pyout.close()
00086
00087
00088
00089
00090 crab_block = """
00091 [CRAB]
00092 jobtype = cmssw
00093 scheduler = glite
00094 #server_name =
00095
00096 [EDG]
00097 remove_default_blacklist=1
00098 rb = CERN
00099
00100 [USER]
00101 return_data = 0
00102 copy_data = 1
00103 storage_element=srm-cms.cern.ch
00104 storage_path=/srm/managerv2?SFN=/castor/cern.ch/
00105 user_remote_dir=/user/n/nuno/relval/harvest/
00106 publish_data=0
00107 thresholdLevel=70
00108 eMail=nuno@cern.ch
00109
00110 [CMSSW]
00111 total_number_of_events=-1
00112 show_prod = 1
00113 """
00114
00115 crab_name="crab.cfg"
00116 os.system("touch " + crab_name)
00117 os.system("mv " + crab_name + " " + crab_name + "_old")
00118
00119 crab_cfg = open(crab_name, 'w')
00120 crab_cfg.write(crab_block)
00121
00122 rootfile = "DQM_V0001_R000000001" \
00123 + dsetpath.replace('/','__') \
00124 + ".root"
00125
00126 crab_cfg.write("number_of_jobs=" + str(njobs) + "\n")
00127 crab_cfg.write("pset=" + pyout_name + "\n")
00128 crab_cfg.write("output_file=" + rootfile + "\n")
00129 crab_cfg.write("datasetpath=" + dsetpath + "\n")
00130
00131
00132 crab_cfg.close()
00133
00134
00135
00136
00137 print '\n\nCreated:\n\t %(pwd)s/%(pf)s \n\t %(pwd)s/%(cf)s' \
00138 % {'pwd' : os.environ["PWD"], 'pf' : pyout_name, 'cf' : crab_name}
00139
00140 print "Done."