~9marusia6/maus/beamlinesimulation

« back to all changes in this revision

Viewing changes to tests/integration/test_utilities/test_execute_against_data/test_execute_against_data.py

  • Committer: justinchristensen at berkeley
  • Date: 2012-06-08 08:47:52 UTC
  • mfrom: (669.1.1 release)
  • Revision ID: justinchristensen@berkeley.edu-20120608084752-5x3f3rzflhhcewwi
new version

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import urllib
26
26
import subprocess
27
27
import tarfile
28
 
import json
29
28
import time
 
29
import ROOT
 
30
import libMausCpp # pylint: disable=W0611
30
31
 
31
32
RUN_NUMBER = "03541"
32
33
TEST_URL = "http://www.hep.ph.ic.ac.uk/micedata/MICE/Step1/03500/"
95
96
    """
96
97
    Test the main method of the batch script
97
98
    """
 
99
    def __check_sim_file(self):
 
100
        """
 
101
        Make some simple data integrity checks on the simulation file
 
102
        """
 
103
        root_file = ROOT.TFile(RUN_NUMBER+'_sim.root', # pylint: disable = E1101
 
104
                                               "READ")
 
105
        data = ROOT.MAUS.Data() # pylint: disable = E1101
 
106
        tree = root_file.Get("Spill")
 
107
        tree.SetBranchAddress("data", data)
 
108
        self.assertGreater(tree.GetEntries(), 0)
 
109
        tree.GetEntry(0)
 
110
        self.assertGreater(data.GetSpill().GetMCEventSize(), 1)
 
111
        root_file.Close()
 
112
 
 
113
    def __check_recon_file(self):
 
114
        """
 
115
        Make some simple data integrity checks on the simulation file
 
116
        """
 
117
        root_file = ROOT.TFile(RUN_NUMBER+'_recon.root', # pylint: disable=E1101
 
118
                                               "READ")
 
119
        data = ROOT.MAUS.Data() # pylint: disable = E1101
 
120
        tree = root_file.Get("Spill")
 
121
        tree.SetBranchAddress("data", data)
 
122
        self.assertGreater(tree.GetEntries(), 0)
 
123
        tree.GetEntry(3)
 
124
        self.assertEqual(data.GetSpill().GetDaqEventType(), "physics_event")
 
125
        self.assertGreater(data.GetSpill().GetReconEventSize(), 0)
 
126
        self.assertGreater(data.GetSpill().GetAReconEvent(0).GetTOFEvent().\
 
127
                                  GetTOFEventDigit().GetTOF1DigitArraySize(), 0)
 
128
        root_file.Close()
 
129
 
 
130
 
98
131
    # want to test also each of the return codes is okay
99
132
    def test_main_success(self):
100
133
        """
121
154
        tar_out = tarfile.open(TEST_OUT, 'r:*')
122
155
        tar_out.extractall()
123
156
        for file_name in [TEST_OUT, TEST_FILE, 'batch.log', 'download.log', \
124
 
                   'reco.log', 'sim.log', RUN_NUMBER+'_recon.json', \
125
 
                   RUN_NUMBER+'_sim.json']:
 
157
                   'reco.log', 'sim.log', RUN_NUMBER+'_recon.root', \
 
158
                   RUN_NUMBER+'_sim.root']:
126
159
            self.assertTrue(os.path.isfile(file_name), file_name)
127
 
        sim_first_line = open(RUN_NUMBER+'_sim.json').readline()
128
 
        sim_first_spill = json.loads(sim_first_line)
129
 
        self.assertGreater(len(sim_first_spill['mc']), 1)
130
 
        rec_in = open(RUN_NUMBER+'_recon.json')
131
 
        # start of run twice (?), start of burst 
132
 
        for i in range(3): # pylint: disable = W0612
133
 
            rec_in.readline()
134
 
        rec_first_spill = json.loads(rec_in.readline())
135
 
        self.assertTrue('mc' not in rec_first_spill.keys())
136
 
        self.assertGreater(len(rec_first_spill['digits']['tof1']), 0)
 
160
        self.__check_sim_file()
 
161
        self.__check_recon_file()
137
162
        os.chdir(here)
138
163
 
139
164
if __name__ == "__main__":