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
|
Tests for input cpp data
|
18
|
"""
|
19
|
|
20
|
#pylint: disable = C0103
|
21
|
|
22
|
import os
|
23
|
import md5
|
24
|
import unittest
|
25
|
import json
|
26
|
|
27
|
from Configuration import Configuration
|
28
|
from InputCppDAQData import InputCppDAQData
|
29
|
|
30
|
class InputCppDAQDataTestCase(unittest.TestCase): #pylint: disable = R0904
|
31
|
"""
|
32
|
We test input cpp data by checking unpacked files using an md5sum. Note that
|
33
|
this is rather quick and dirty...
|
34
|
"""
|
35
|
@classmethod
|
36
|
def setUpClass(cls):
|
37
|
"""
|
38
|
Setup the data file and configuration
|
39
|
"""
|
40
|
if not os.environ.get("MAUS_ROOT_DIR"):
|
41
|
raise Exception('InitializeFail', 'MAUS_ROOT_DIR unset!')
|
42
|
# Set our data path & filename
|
43
|
# It would be nicer to test with a smaller data file!
|
44
|
cls._datapath = '%s/src/input/InputCppDAQData' % \
|
45
|
os.environ.get("MAUS_ROOT_DIR")
|
46
|
cls._datafile = '02873'
|
47
|
cls._c = Configuration()
|
48
|
|
49
|
def setUp(self):
|
50
|
"""
|
51
|
Setup the InputCppDAQData mapper
|
52
|
"""
|
53
|
self.mapper = InputCppDAQData(self._datapath, self._datafile)
|
54
|
|
55
|
def test_init(self):
|
56
|
"""
|
57
|
Check that we can call birth on the data file
|
58
|
"""
|
59
|
self.assertTrue(self.mapper.birth( self._c.getConfigJSON() ))
|
60
|
# Check re-init without closing fails
|
61
|
self.assertFalse(self.mapper.birth( self._c.getConfigJSON() ))
|
62
|
self.assertTrue(self.mapper.death())
|
63
|
return
|
64
|
|
65
|
def test_single(self):
|
66
|
"""
|
67
|
Test a single spill
|
68
|
"""
|
69
|
self.assertTrue(self.mapper.birth(self. _c.getConfigJSON() ))
|
70
|
# Get a single event and check it's the right size
|
71
|
data = self.mapper.getNextEvent()
|
72
|
# Data shold be 66 (an empty spill, first event is start of burst)
|
73
|
self.assertEqual(len(data), 67)
|
74
|
self.assertTrue(self.mapper.death())
|
75
|
return
|
76
|
|
77
|
def test_multi(self):
|
78
|
"""
|
79
|
Test reading the whole file
|
80
|
"""
|
81
|
self.assertTrue(self.mapper.birth( self._c.getConfigJSON() ))
|
82
|
spill_count = 0
|
83
|
event_count = 0
|
84
|
|
85
|
# We can try md5'ing the whole dataset
|
86
|
digester = md5.new()
|
87
|
|
88
|
for inp in self.mapper.emitter():
|
89
|
digester.update(inp)
|
90
|
json_in = json.loads(inp)
|
91
|
spill_count = spill_count + 1
|
92
|
event_count += len(json_in["daq_data"])
|
93
|
|
94
|
# We should now have processed 8 spills
|
95
|
self.assertEqual(spill_count, 8)
|
96
|
self.assertEqual(event_count, 26)
|
97
|
|
98
|
# Check the md5 sum matches the expected value
|
99
|
self.assertEqual(digester.hexdigest(),
|
100
|
'f4f50073b67d488f8b678a969b8564f6')
|
101
|
|
102
|
self.assertTrue(self.mapper.death())
|
103
|
|
104
|
@classmethod
|
105
|
def tearDownClass(cls):
|
106
|
pass
|
107
|
|
108
|
if __name__ == '__main__':
|
109
|
unittest.main()
|