ATLAS Offline Software
Loading...
Searching...
No Matches
master.py
Go to the documentation of this file.
1# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2
3#Author: Abhishek Nag (TU Dresden) #Co-Author: Louie Corpe (UCL)
4#email: abhishek.nag@cern.ch l.corpe@cern.ch
5
6import os
7import optparse
8import readDatabase
9
10parser = optparse.OptionParser(usage = "%prog [options]")
11parser.add_option("-i","--inputSamples", help="list of samples. One per line. Default=Sherpa_samples.txt", dest="inputSamples", default="Sherpa_samples.txt")
12parser.add_option("--testSampleDir", help="where to store the test samples. Default=testSamples", dest="testSampleDir",default="testSamples" )
13parser.add_option("--weightDir", help="where to store the weight files. Default=Weight_files", dest="weightDir", default="Weight_files")
14(opts, args) = parser.parse_args()
15
16
17from datetime import date
18SystToolsPath=""
19if 'SYSTTOOLSPATH' in os.environ.keys():
20 SystToolsPath=os.environ['SYSTTOOLSPATH']
21else:
22 print("[ERROR] Environment variable SYSTTOOLSPATH is not set. It should be set to the systematics-tools directory. Use setupSystematicsToolR21.sh")
23 exit(1)
24os.system("mkdir -p %s" % opts.testSampleDir)
25os.system("mkdir -p %s" % opts.weightDir)
26
27f=open(opts.inputSamples)
28for line in f.readlines():
29 flag=False
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:
34 gen='Powheg'
35 elif 'MG' in gen or 'MadGraph' in gen:
36 gen='MadGraph'
37 elif 'Sherpa' in gen or 'Sh' in gen:
38 gen='Sherpa'
39 elif 'aMcAtNlo' in gen:
40 gen='aMcAtNlo'
41 else:
42 print("unrecognized generator")
43 continue
44 dsid=thisSampleName.split(".")[1]
45 print("[INFO] processing DSID", dsid)
46
47 dictionary, keys=readDatabase.getWeights(int(dsid))
48 if keys != []:
49 print("[INFO] DSID",dsid,"already exists. Skipping")
50 continue
51 tSample=None
52 testSamplePath=None
53 weightflag=False
54 for dirName in os.listdir(opts.testSampleDir):
55 if dsid in dirName:
56 testSamplePath=opts.testSampleDir+"/"+dirName
57 for fileName in os.listdir(testSamplePath):
58 testSamplePath=testSamplePath+"/"+fileName
59 print("[INFO] Sample found")
60 flag=True
61 break
62 if 'root' not in testSamplePath or testSamplePath.endswith(".part"):
63 testSamplePath=None
64 print("[WARNING] Sample not downloaded properly.")
65 flag=False
66 for filename in os.listdir(SystToolsPath+"/data/Weight_files/"):
67 if dsid in filename:
68 weightflag=True
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)
78 continue
79 for fileName in os.listdir(testSamplePath):
80 if fileName.endswith(".part"):
81 print("[ERROR INFO] Downloading failed")
82 continue
83 tSample=testSamplePath
84 testSamplePath=testSamplePath+"/"+fileName
85 flag=True
86 break
87 if flag is True:
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)
93 os.system(rmCommand)
94 print("[INFO] copying weight file")
95 mvCommand="mv weight.txt %s" % ('weight_'+gen+'_'+dsid+'.txt')
96 os.system(mvCommand)
97 cpCommand="cp %s %s/data/Weight_files/." % ('weight_'+gen+'_'+dsid+'.txt',SystToolsPath)
98 os.system(cpCommand)
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)
105 today = date.today()
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)
109 os.system(copyData)
110 os.system(copyDict)
111f.close()
void print(char *figname, TCanvas *c1)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177