~maus-detector-integration/maus/ckov_merge

« back to all changes in this revision

Viewing changes to src/input/InputCppDAQOfflineData/test_InputCppDAQOfflineData.py

  • Committer: Chris Rogers
  • Date: 2012-03-05 16:24:30 UTC
  • mfrom: (340.32.8 release)
  • Revision ID: chris.rogers@stfc.ac.uk-20120305162430-5v76jvrfqmrw4z4u
MergeĀ releaseĀ 0.1.4

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
"""Tests for MapCppTOFOfflineDigits"""
 
17
 
 
18
# pylint: disable = C0103
 
19
 
 
20
import os
 
21
import md5
 
22
import unittest
 
23
from Configuration import Configuration
 
24
from InputCppDAQOfflineData import InputCppDAQOfflineData
 
25
 
 
26
class InputCppDAQOfflineDataTestCase(unittest.TestCase): #pylint:disable=R0904
 
27
    """Tests for InputCppDAQOfflineData"""
 
28
    @classmethod
 
29
    def setUpClass(self): # pylint: disable = C0103, C0202
 
30
        """Sets a mapper and configuration"""
 
31
        if not os.environ.get("MAUS_ROOT_DIR"):
 
32
            raise Exception('InitializeFail', 'MAUS_ROOT_DIR unset!')
 
33
        # Set our data path & filename
 
34
        # It would be nicer to test with a smaller data file!
 
35
        self._datapath = '%s/src/input/InputCppDAQData' % \
 
36
                            os.environ.get("MAUS_ROOT_DIR")
 
37
        self._datafile = '02873'
 
38
        self._c = Configuration()
 
39
        self.mapper = None
 
40
 
 
41
    def test_init(self):
 
42
        """Check birth with default configuration"""
 
43
        self.mapper = InputCppDAQOfflineData(self._datapath, \
 
44
                                       self._datafile)
 
45
        self.assertTrue(self.mapper.birth( self._c.getConfigJSON() ))
 
46
        # Check re-init without closing fails
 
47
        self.assertFalse(self.mapper.birth( self._c.getConfigJSON() ))
 
48
        self.assertTrue(self.mapper.death())
 
49
        return
 
50
 
 
51
    def test_single(self):
 
52
        """Test a single event"""
 
53
        self.mapper = InputCppDAQOfflineData(self._datapath, \
 
54
                                       self._datafile)
 
55
        self.assertTrue(self.mapper.birth(self. _c.getConfigJSON() ))
 
56
        # Get a single event and check it's the right size
 
57
        self.assertTrue(self.mapper.readNextEvent())
 
58
        data = self.mapper.getCurEvent()
 
59
        # Data shold be 80 (first event is start of burst)
 
60
        self.assertEqual(len(data), 80)
 
61
        self.assertTrue(self.mapper.death())
 
62
        return
 
63
 
 
64
    def test_multi(self):
 
65
        """Test reading the whole file"""
 
66
        self.mapper = InputCppDAQOfflineData(self._datapath, \
 
67
                                       self._datafile)
 
68
        self.assertTrue(self.mapper.birth( self._c.getConfigJSON() ))
 
69
        event_count = 0
 
70
 
 
71
        # We can try md5'ing the whole dataset
 
72
        digester = md5.new()
 
73
 
 
74
        for i in self.mapper.emitter():
 
75
            digester.update(i)
 
76
            event_count = event_count + 1
 
77
 
 
78
        # We should now have processed 26 events
 
79
        self.assertEqual(event_count, 26)
 
80
 
 
81
        # Check the md5 sum matches the expected value
 
82
        # changed checksum to reflect the run_num addition
 
83
        self.assertEqual(digester.hexdigest(), \
 
84
                         '426cc54172fc1091185f4eaacdd8b85a')
 
85
 
 
86
        self.assertTrue(self.mapper.death())
 
87
 
 
88
    @classmethod
 
89
    def tearDownClass(self): # pylint: disable = C0103, C0202
 
90
        """Check that we can death() MapCppTOFDigits"""
 
91
        pass
 
92
 
 
93
if __name__ == '__main__':
 
94
    unittest.main()