~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

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

merging in changes in merge branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import json
12
12
import os
13
13
from Configuration import Configuration
 
14
from cdb._exceptions import CdbPermanentError
14
15
 
15
16
 
16
17
class GetTrackerCalib:
21
22
 
22
23
    def __init__(self):
23
24
        print "Init running"
24
 
        self.config = json.loads(Configuration().getConfigJSON())
 
25
        self.config = json.loads(\
 
26
                      Configuration().getConfigJSON(command_line_args = True))
25
27
        calib_cdb_url = self.config['cdb_download_url'] + 'calibration?wsdl'
26
28
        self._calib = cdb.Calibration()
27
29
        self._calib.set_url(calib_cdb_url)
41
43
        if method == "Date":
42
44
            self.Date(_input)
43
45
        if method == "Run":
44
 
            self.Date(self.Convert_Run(_input))
 
46
            try:
 
47
                self.Run(_input)
 
48
            except CdbPermanentError:
 
49
                self.Date(self.Convert_Run(_input))
45
50
        if method == "Current":
46
51
            self.Current()
47
52
 
55
60
 
56
61
        self.Output(calib, badchan, cable)
57
62
 
 
63
    def Run(self, run_num):
 
64
        """
 
65
        Collects calibration info by run
 
66
        """
 
67
        try:
 
68
            print "Getting SciFi calibrations and maps for Run ", run_num
 
69
            calib = self._calib.get_calibration_for_run\
 
70
                ("Trackers", run_num, "trackers")
 
71
            badchan = self._calib.get_calibration_for_run\
 
72
                  ("Trackers", run_num, "bad_chan")
 
73
            cable = self._cable.get_cabling_for_run\
 
74
                ("Trackers", run_num)
 
75
            self.Output(calib, badchan, cable)
 
76
        except CdbPermanentError:
 
77
            raise CdbPermanentError\
 
78
                   ("CDB error getting scifi calibration by run")
 
79
 
58
80
    def Date(self, date):
59
81
        """
60
82
        Collects calibration info by date
91
113
        path_calib = path + "/files/calibration/"
92
114
        path_cable = path + "/files/cabling/"
93
115
        print path
94
 
        calib_out = open(path_calib+"scifi_calibraion.txt","w")
 
116
        calib_out = open(path_calib+"scifi_calibration.txt","w")
95
117
        badchan_out = open(path_calib+"scifi_bad_channels.txt","w")
96
118
        cable_out = open(path_cable+"scifi_mapping.txt","w")
97
119