~sophie-middleton08/maus/devel

« back to all changes in this revision

Viewing changes to tests/integration/test_simulation/test_tracking_speed/test_tracking_speed.py

  • Committer: Chris Rogers
  • Date: 2013-04-30 15:29:46 UTC
  • mfrom: (659.1.64 release-candidate)
  • Revision ID: chris.rogers@stfc.ac.uk-20130430152946-7xe8q7zwcn3a4uhs
Tags: MAUS-v0.5.2
MAUS-v0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
#
 
3
#  MAUS is free software: you can redistribute it and/or modify
 
4
#  it under the terms of the GNU General Public License as published by
 
5
#  the Free Software Foundation, either version 3 of the License, or
 
6
#  (at your option) any later version.
 
7
#
 
8
#  MAUS is distributed in the hope that it will be useful,
 
9
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
#  GNU General Public License for more details.
 
12
#
 
13
#  You should have received a copy of the GNU General Public License
 
14
#  along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
"""
 
17
Get tracking speed as a function of n_spills
 
18
"""
 
19
 
 
20
import time
 
21
import unittest
 
22
import os
 
23
import subprocess
 
24
import json
 
25
 
 
26
MAUS_ROOT_DIR = os.getenv("MAUS_ROOT_DIR")
 
27
TMP_PATH = os.path.join(MAUS_ROOT_DIR, "tmp")
 
28
SIM_PATH = os.path.join(MAUS_ROOT_DIR, "bin", "simulate_mice.py")
 
29
TEST_PATH = os.path.join(MAUS_ROOT_DIR,
 
30
                        "tests/integration/test_simulation/test_tracking_speed")
 
31
 
 
32
class TestTrackingSpeed(unittest.TestCase): # pylint: disable=R0904
 
33
    """
 
34
    Test class to check tracking speed
 
35
    """
 
36
 
 
37
    def test_tracking_speed(self): # pylint: disable=R0201
 
38
        """
 
39
        Run simulation and time execution time.
 
40
        """
 
41
        log = open(TMP_PATH+'/test_tracking_speed.log', 'w')
 
42
        out = open(TMP_PATH+'/test_tracking_speed.json', 'w')
 
43
        
 
44
        # run simulation
 
45
        config = os.path.join(TEST_PATH, 'configuration.py')
 
46
        results = []
 
47
        for n_spills in [0, 1, 5, 10, 50]:
 
48
            time_start = time.time()
 
49
            subproc = subprocess.Popen([
 
50
                           SIM_PATH,
 
51
                           '--configuration_file', config,
 
52
                           '--spill_generator_number_of_spills', str(n_spills)],
 
53
                           stdout = log, stderr=subprocess.STDOUT)
 
54
            subproc.wait() # pylint: disable=E1101
 
55
            print "Took", time.time() - time_start, "seconds to track", \
 
56
                  n_spills, "spills each with 10 muons"
 
57
            results.append({"dt":time.time()-time_start, "n_spills":n_spills})
 
58
        out.write(json.dumps(results))
 
59
 
 
60
 
 
61
if __name__ == "__main__":
 
62
    unittest.main()
 
63