~mbogomilov/maus/devel3

« back to all changes in this revision

Viewing changes to src/map/MapCppEMRPlaneHits/test_map_cpp_emr_plane_hits.py

  • Committer: Durga Rajaram
  • Date: 2014-01-14 07:07:02 UTC
  • mfrom: (659.1.80 relcand)
  • Revision ID: durga@fnal.gov-20140114070702-2l1fuj1w6rraw7xe
Tags: MAUS-v0.7.6
MAUS-v0.7.6

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 MapCppEMRPlaneHits"""
 
17
 
 
18
import os
 
19
import json
 
20
import unittest
 
21
from Configuration import Configuration
 
22
import MAUS
 
23
 
 
24
class TestMapCppEMRPlaneHits(unittest.TestCase): #pylint: disable=R0904
 
25
    """Tests for MapCppEMRPlaneHits"""
 
26
    @classmethod
 
27
    def setUpClass(cls): # pylint: disable = C0103
 
28
        """Sets a mapper and configuration"""
 
29
        cls.mapper = MAUS.MapCppEMRPlaneHits()
 
30
        cls.c = Configuration()
 
31
 
 
32
    def test_empty(self):
 
33
        """Check can handle empty configuration"""
 
34
        result = self.mapper.birth("")
 
35
        self.assertFalse(result)
 
36
        result = self.mapper.process("")
 
37
        doc = json.loads(result)
 
38
        self.assertTrue("errors" in doc)
 
39
        self.assertTrue("bad_json_document" in doc["errors"] or 
 
40
                        "no_channel_map" in doc["errors"])
 
41
 
 
42
    def test_init(self):
 
43
        """Check birth with default configuration"""
 
44
        success = self.mapper.birth(self. c.getConfigJSON())
 
45
        self.assertTrue(success)
 
46
 
 
47
    def test_no_data(self):
 
48
        """Check that nothing happens in absence of data"""
 
49
        test1 = ('%s/src/map/MapCppEMRPlaneHits/noDataTest.json' % 
 
50
                 os.environ.get("MAUS_ROOT_DIR"))
 
51
        fin = open(test1,'r')
 
52
        data = fin.read()
 
53
        # test with no data.
 
54
        result = self.mapper.process(data)
 
55
        spill_out = json.loads(result)
 
56
        n_ev = len(spill_out['recon_events'])
 
57
        #print spill_out["errors"]
 
58
        self.assertEqual(0, n_ev)
 
59
        self.assertFalse("bad_json_document" in spill_out["errors"])
 
60
        self.assertFalse("bad_cpp_data" in spill_out["errors"])
 
61
 
 
62
    def test_process(self):
 
63
        """Test MapCppEMRPlaneHits process method"""
 
64
        test2 = ('%s/src/map/MapCppEMRPlaneHits/processTest.json' % 
 
65
                 os.environ.get("MAUS_ROOT_DIR"))
 
66
        fin = open(test2,'r')
 
67
        data = fin.read()
 
68
        # test with some crazy events.
 
69
        result = self.mapper.process(data)
 
70
        #spill_in = json.loads(data)
 
71
        spill_out = json.loads(result)
 
72
        #print spill_out["errors"]
 
73
        self.assertFalse("bad_json_document" in spill_out["errors"])
 
74
        self.assertFalse("bad_cpp_data" in spill_out["errors"])
 
75
        n_ev = len(spill_out['recon_events'])
 
76
        self.assertEqual(3, n_ev)
 
77
        n_hits_0 = len(spill_out['recon_events'][0]['emr_event']\
 
78
                                ['emr_plane_hits'])
 
79
        self.assertEqual(1, n_hits_0)
 
80
        n_hits_1 = len(spill_out['recon_events'][1]['emr_event']\
 
81
                                ['emr_plane_hits'])
 
82
        self.assertEqual(2, n_hits_1)
 
83
        n_hits_2 = len(spill_out['recon_events'][2]['emr_event']\
 
84
                                ['emr_plane_hits'])
 
85
        self.assertEqual(1, n_hits_2)
 
86
 
 
87
if __name__ == "__main__":
 
88
    unittest.main()
 
89