10 parser = optparse.OptionParser(usage =
"%prog [options]")
11 parser.add_option(
"-i",
"--inputSamples", help=
"list of samples. One per line. Default=Sherpa_samples.txt", dest=
"inputSamples", default=
"Sherpa_samples.txt")
12 parser.add_option(
"--testSampleDir", help=
"where to store the test samples. Default=testSamples", dest=
"testSampleDir",default=
"testSamples" )
13 parser.add_option(
"--weightDir", help=
"where to store the weight files. Default=Weight_files", dest=
"weightDir", default=
"Weight_files")
14 (opts, args) = parser.parse_args()
17 from datetime
import date
19 if 'SYSTTOOLSPATH' in os.environ.keys():
20 SystToolsPath=os.environ[
'SYSTTOOLSPATH']
22 print(
"[ERROR] Environment variable SYSTTOOLSPATH is not set. It should be set to the systematics-tools directory. Use setupSystematicsToolR21.sh")
24 os.system(
"mkdir -p %s" % opts.testSampleDir)
25 os.system(
"mkdir -p %s" % opts.weightDir)
28 for line
in f.readlines():
30 if line[0]==
"#" or line==
'' :
continue
31 thisSampleName=line.split()[0]
32 gen=thisSampleName.split(
".")[2].
split(
"_")[0]
33 if 'Ph' in gen
or 'Powheg' in gen:
35 elif 'MG' in gen
or 'MadGraph' in gen:
37 elif 'Sherpa' in gen
or 'Sh' in gen:
39 elif 'aMcAtNlo' in gen:
42 print(
"unrecognized generator")
44 dsid=thisSampleName.split(
".")[1]
45 print(
"[INFO] processing DSID", dsid)
49 print(
"[INFO] DSID",dsid,
"already exists. Skipping")
54 for dirName
in os.listdir(opts.testSampleDir):
56 testSamplePath=opts.testSampleDir+
"/"+dirName
57 for fileName
in os.listdir(testSamplePath):
58 testSamplePath=testSamplePath+
"/"+fileName
59 print(
"[INFO] Sample found")
62 if 'root' not in testSamplePath
or testSamplePath.endswith(
".part"):
64 print(
"[WARNING] Sample not downloaded properly.")
66 for filename
in os.listdir(SystToolsPath+
"/data/Weight_files/"):
69 if (testSamplePath
is None and weightflag
is False):
70 print(
"[INFO] do not currently have a test sample for ", thisSampleName)
71 rucioCommand=
"rucio download --nrandom 1 %s --dir %s " % (thisSampleName, opts.testSampleDir)
72 print(
"[INFO] --> downloading one using this command \n ",rucioCommand)
73 os.system(rucioCommand)
74 if ":" in thisSampleName: testSamplePath=opts.testSampleDir+
"/"+thisSampleName.split(
":")[1]
75 else : testSamplePath=opts.testSampleDir+
"/"+thisSampleName
76 if not os.path.exists(testSamplePath):
77 print(
"[ERROR INFO] No such directory: %s", testSamplePath)
79 for fileName
in os.listdir(testSamplePath):
80 if fileName.endswith(
".part"):
81 print(
"[ERROR INFO] Downloading failed")
83 tSample=testSamplePath
84 testSamplePath=testSamplePath+
"/"+fileName
88 print(
"[SUCCESS] found test file ", testSamplePath)
89 athenaCommand=
"athena --filesInput=%s --evtMax=1 DSIDDatabaseTool/DSIDDatabaseToolAlgJobOptions.py" % (testSamplePath)
90 print(
"[INFO] running athena weight retrieving tool using \n", athenaCommand)
91 os.system(athenaCommand)
92 rmCommand =
"rm -r %s" % (tSample)
94 print(
"[INFO] copying weight file")
95 mvCommand=
"mv weight.txt %s" % (
'weight_'+gen+
'_'+dsid+
'.txt')
97 cpCommand=
"cp %s %s/data/Weight_files/." % (
'weight_'+gen+
'_'+dsid+
'.txt',SystToolsPath)
99 commandLine=
"rm %s" % (
'weight_'+gen+
'_'+dsid+
'.txt')
100 os.system(commandLine)
101 if flag
or weightflag:
102 buildCommand=
"buildDatabase.py %s/data/Weight_files/%s" % (SystToolsPath,
'weight_'+gen+
'_'+dsid+
'.txt')
103 print(
"[INFO] updating Database for dsid", dsid)
104 os.system(buildCommand)
106 d1=today.strftime(
"%Y-%m-%d")
107 copyData=
"cp %s/data/DSID_Database.yaml %s/data/DSID_Database_%s.yaml" % (SystToolsPath, SystToolsPath, d1)
108 copyDict=
"cp %s/data/Weight_Database.yaml %s/data/Weight_Database_%s.yaml" % (SystToolsPath, SystToolsPath, d1)