1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
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.
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.
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/>.
16
"""Tests for MapCppTOFOfflineDigits"""
18
# pylint: disable = C0103
23
from Configuration import Configuration
24
from InputCppDAQOfflineData import InputCppDAQOfflineData
26
class InputCppDAQOfflineDataTestCase(unittest.TestCase): #pylint:disable=R0904
27
"""Tests for InputCppDAQOfflineData"""
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()
42
"""Check birth with default configuration"""
43
self.mapper = InputCppDAQOfflineData(self._datapath, \
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())
51
def test_single(self):
52
"""Test a single event"""
53
self.mapper = InputCppDAQOfflineData(self._datapath, \
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())
65
"""Test reading the whole file"""
66
self.mapper = InputCppDAQOfflineData(self._datapath, \
68
self.assertTrue(self.mapper.birth( self._c.getConfigJSON() ))
71
# We can try md5'ing the whole dataset
74
for i in self.mapper.emitter():
76
event_count = event_count + 1
78
# We should now have processed 26 events
79
self.assertEqual(event_count, 26)
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')
86
self.assertTrue(self.mapper.death())
89
def tearDownClass(self): # pylint: disable = C0103, C0202
90
"""Check that we can death() MapCppTOFDigits"""
93
if __name__ == '__main__':