~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/common_py/calibration/get_tof_calib.py

tof calibrations and cabling from cdb

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/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
"""
 
18
Get TOF calibrations from DB
 
19
"""
 
20
 
 
21
import cdb
 
22
import json
 
23
from Configuration import Configuration
 
24
 
 
25
class GetCalib:
 
26
    """
 
27
    Evaluator class to evaluate mathematical expressions 
 
28
 
 
29
    Able to see many simple math expressions and some common units; the
 
30
    standard geant4 system of units is enabled.
 
31
    """
 
32
 
 
33
    def __init__(self):
 
34
        """
 
35
        Initialise the evaluator with math functions and units
 
36
        """
 
37
        self._current_cali = {}
 
38
        self.reset()
 
39
        cfg = Configuration()
 
40
        cfgdoc = cfg.getConfigJSON()
 
41
        cfgdoc_json = json.loads(cfgdoc)
 
42
        cdb_url = cfgdoc_json['cdb_download_url'] + 'calibration?wsdl'
 
43
        self.cdb_server = cdb.Calibration()
 
44
        self.cdb_server.set_url(cdb_url)
 
45
        #print 'Server: ', self.cdb_server.get_name(), \
 
46
        #                  self.cdb_server.get_version()
 
47
 
 
48
    def get_calib(self, devname, ctype, fromdate):
 
49
        """
 
50
        Evaluate a string expression given by formula
 
51
        """
 
52
        tof_devs = {'TOF0', 'TOF1', 'TOF2'}
 
53
        tof_ctypes = {'t0', 'tw', 'trigger'}
 
54
        #print 'Calib: ', devname, ctype, fromdate
 
55
        if devname != "" and ctype != "":
 
56
            if devname not in tof_devs or ctype not in tof_ctypes:
 
57
                raise Exception('get_tof_calib failed. \
 
58
                                 Invalid detector/calib type.')
 
59
            # check whether we are asked for the current calibration 
 
60
            # or calibration for an older date
 
61
            if fromdate == "" or fromdate == "current":
 
62
                #print 'getting current calib', devname, ctype
 
63
                self._current_cali = \
 
64
                     self.cdb_server.get_current_calibration(devname, ctype)
 
65
            else:
 
66
                #print 'getting calib for date', fromdate
 
67
                self._current_cali = \
 
68
                     self.cdb_server.get_calibration_for_date(devname,fromdate,
 
69
                                                                         ctype)
 
70
            #print self._current_cali
 
71
        else:
 
72
            raise Exception('get_tof_calib failed.No device/calibration type.')
 
73
        return self._current_cali  
 
74
 
 
75
    def reset(self):
 
76
        """
 
77
        Reinitialize calibration 
 
78
        """
 
79
        self._current_cali = {}