- fixes to simulation macros
[u/mrichter/AliRoot.git] / HLT / CALO / macros / run_tests.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import os
5
6 class Simulator():
7    
8    def __init__(self):
9       self.pwd = os.getenv("PWD")
10       print "SIMULATOR"
11       
12    def mkDirStructure(self):
13          os.system("mkdir -p simulations/single")
14          os.system("mkdir -p simulations/pi0")
15    
16    def copyFiles(self):
17          os.system("cp ConfigSingle.C simulations/single/Config.C")
18          os.system("cp ConfigPi0.C simulations/pi0/Config.C")
19          os.system("cp sim.C simulations/single/sim.C")
20          os.system("cp sim.C simulations/pi0/sim.C")
21    
22    def cleanFiles(self):
23          os.system("rm simulations/single/ -rf")
24          os.system("rm simulations/pi0/ -rf")
25
26    def editConfigFiles(self, dophos, doemcal, dotm):
27
28       if dophos == True:
29          command = "sed -i \'s/Int_t   iPHOS  =  0/Int_t   iPHOS  =  1/g\' simulations/single/Config.C"
30          os.system(command)
31       if doemcal == True:
32          command = "sed -i \'s/Int_t   iEMCAL =  0/Int_t   iEMCAL =  1/g\' simulations/single/Config.C"
33          os.system(command)
34
35       if dotm == True:
36          command = "sed -i \'s/Int_t   iTPC   =  0/Int_t   iTPC   =  1/g\' simulations/single/Config.C"
37          os.system(command)
38
39    def initSimulation(self):
40       self.cleanFiles()
41       self.mkDirStructure()
42       self.copyFiles()
43
44    def runSimulation(self, nevents, dophos, doemcal, dotm):
45       self.editConfigFiles(dophos, doemcal, dotm)
46       simargs = str(nevents) + ", " + str(int(dophos)) + ", " + str(int(doemcal)) + ", " + str(int(dotm))
47       command = "cd simulations/single/ && aliroot -b -q sim.C\'(" + simargs + ")\'"
48       os.system(command)
49       os.system("cd " + self.pwd)
50
51 class Tester():
52    def __init__(self):
53       print "TESTER"
54
55    def initTest(self):
56       self.pwd = os.getenv("PWD")
57       os.system("rm -rf tests/all/")
58       os.system("mkdir -p tests/all/single")
59       os.system("cp rec_hlt_calo.C tests/all/single/.")
60       os.system("cp runAll.C tests/all/single/.")
61       os.system("cp read_HLT_ESDs.C tests/all/single/.")
62
63    def run(self, dophos, doemcal, dotm):
64       
65       runargs = "\"./\", \"./\", " + str(int(dophos)) + ", " + str(int(doemcal)) + ", " + str(int(dotm))
66       path = self.pwd + "/simulations/single/."
67       command = "cd tests/all/single/;  ln -s " + path + "/raw* .; ln -s " + path + "/GRP . ; aliroot runAll.C\'(" + runargs + ")\'"
68       os.system(command)
69       os.system("cd " + self.pwd)
70
71 from optparse import OptionParser
72
73 parser = OptionParser()
74
75 parser.add_option("-s", "--simulatedata", action="store_true", dest="simulatedata",
76                                  default=False, help="Simulate data for the tests")
77 parser.add_option("-n", "--nevents", dest="nevents",
78                                  default=100, help="Specify the number of events to simulate. If you change this the reference histograms will be useless")
79 parser.add_option("", "--no-phos", action="store_false", dest="runphos", 
80                                  default=True, help="Testing: Don't run PHOS tests. Simulation: Don't simulate for PHOS")
81 parser.add_option("", "--no-emcal", action="store_false", dest="runemcal",
82                                  default=True, help="Testing: Don't run EMCAL tests. Simulation: Don't simulate for EMCAL")
83 parser.add_option("", "--no-trackmatching", action="store_false", dest="runtm",
84                                  default=True, help="Testing: Don't run the track matcher, Simulation: Don't simulate TPC")
85
86 (options, args) = parser.parse_args()
87
88 if options.simulatedata:
89    simulator = Simulator()
90    simulator.initSimulation()
91    simulator.runSimulation(options.nevents, options.runphos, options.runemcal, options.runtm)
92    exit(0)
93
94 else:
95    tester = Tester()
96    tester.initTest()
97    tester.run(options.runphos, options.runemcal, options.runtm)
98    exit(0)
99     
100