Commit 85273f2e6a2313f32a093464ac6d86c19158f362
1 parent
ef8439a7
Adapt to change in GApplication interface (methods are now private).
Showing
1 changed file
with
32 additions
and
26 deletions
cscripts/cscaldb.py
| @@ -30,17 +30,21 @@ import os | @@ -30,17 +30,21 @@ import os | ||
| 30 | # ============= # | 30 | # ============= # |
| 31 | class cscaldb(ctools.cscript): | 31 | class cscaldb(ctools.cscript): |
| 32 | """ | 32 | """ |
| 33 | - The cscaldb class logs the content of the ctools calibration database | ||
| 34 | - into the log file. Optionally, if the "debug" parameter is set to "yes" | ||
| 35 | - the calibration database is also logged into the console. | 33 | + Shows the content of the ctools calibration database. |
| 34 | + | ||
| 35 | + If the "debug" parameter is set to "yes" the calibration database | ||
| 36 | + is shown in the console, otherwise the content is only written | ||
| 37 | + into the "cscaldb.log" log file. | ||
| 36 | """ | 38 | """ |
| 39 | + | ||
| 40 | + # Constructors and destructors | ||
| 37 | def __init__(self, *argv): | 41 | def __init__(self, *argv): |
| 38 | """ | 42 | """ |
| 39 | Constructor. | 43 | Constructor. |
| 40 | """ | 44 | """ |
| 41 | # Set name | 45 | # Set name |
| 42 | self._name = "cscaldb" | 46 | self._name = "cscaldb" |
| 43 | - self._version = "1.0.0" | 47 | + self._version = "1.1.0" |
| 44 | 48 | ||
| 45 | # Initialise application | 49 | # Initialise application |
| 46 | if len(argv) == 0: | 50 | if len(argv) == 0: |
| @@ -51,8 +55,8 @@ class cscaldb(ctools.cscript): | @@ -51,8 +55,8 @@ class cscaldb(ctools.cscript): | ||
| 51 | raise TypeError("Invalid number of arguments given.") | 55 | raise TypeError("Invalid number of arguments given.") |
| 52 | 56 | ||
| 53 | # Set logger properties | 57 | # Set logger properties |
| 54 | - self.log_header() | ||
| 55 | - self.log.date(True) | 58 | + self._log_header() |
| 59 | + self._log.date(True) | ||
| 56 | 60 | ||
| 57 | # Return | 61 | # Return |
| 58 | return | 62 | return |
| @@ -64,6 +68,8 @@ class cscaldb(ctools.cscript): | @@ -64,6 +68,8 @@ class cscaldb(ctools.cscript): | ||
| 64 | # Return | 68 | # Return |
| 65 | return | 69 | return |
| 66 | 70 | ||
| 71 | + | ||
| 72 | + # Private methods | ||
| 67 | def _get_parameters(self): | 73 | def _get_parameters(self): |
| 68 | """ | 74 | """ |
| 69 | Get parameters from parfile. | 75 | Get parameters from parfile. |
| @@ -156,6 +162,8 @@ class cscaldb(ctools.cscript): | @@ -156,6 +162,8 @@ class cscaldb(ctools.cscript): | ||
| 156 | # Return response names | 162 | # Return response names |
| 157 | return names | 163 | return names |
| 158 | 164 | ||
| 165 | + | ||
| 166 | + # Public methods | ||
| 159 | def execute(self): | 167 | def execute(self): |
| 160 | """ | 168 | """ |
| 161 | Execute the script. | 169 | Execute the script. |
| @@ -171,16 +179,16 @@ class cscaldb(ctools.cscript): | @@ -171,16 +179,16 @@ class cscaldb(ctools.cscript): | ||
| 171 | Run the script. | 179 | Run the script. |
| 172 | """ | 180 | """ |
| 173 | # Switch screen logging on in debug mode | 181 | # Switch screen logging on in debug mode |
| 174 | - if self.logDebug(): | ||
| 175 | - self.log.cout(True) | 182 | + if self._logDebug(): |
| 183 | + self._log.cout(True) | ||
| 176 | 184 | ||
| 177 | # Get parameters | 185 | # Get parameters |
| 178 | self._get_parameters() | 186 | self._get_parameters() |
| 179 | 187 | ||
| 180 | # Write input parameters into logger | 188 | # Write input parameters into logger |
| 181 | - if self.logTerse(): | ||
| 182 | - self.log_parameters() | ||
| 183 | - self.log("\n") | 189 | + if self._logTerse(): |
| 190 | + self._log_parameters() | ||
| 191 | + self._log("\n") | ||
| 184 | 192 | ||
| 185 | # Get the calibration database | 193 | # Get the calibration database |
| 186 | caldb = gammalib.GCaldb() | 194 | caldb = gammalib.GCaldb() |
| @@ -196,9 +204,9 @@ class cscaldb(ctools.cscript): | @@ -196,9 +204,9 @@ class cscaldb(ctools.cscript): | ||
| 196 | continue | 204 | continue |
| 197 | 205 | ||
| 198 | # Write mission into logger | 206 | # Write mission into logger |
| 199 | - if self.logTerse(): | ||
| 200 | - self.log("\n") | ||
| 201 | - self.log.header1("Mission: "+mission) | 207 | + if self._logTerse(): |
| 208 | + self._log("\n") | ||
| 209 | + self._log.header1("Mission: "+mission) | ||
| 202 | 210 | ||
| 203 | # Extract instruments | 211 | # Extract instruments |
| 204 | instruments = self._get_instruments(caldb, mission) | 212 | instruments = self._get_instruments(caldb, mission) |
| @@ -207,25 +215,25 @@ class cscaldb(ctools.cscript): | @@ -207,25 +215,25 @@ class cscaldb(ctools.cscript): | ||
| 207 | for instrument in instruments: | 215 | for instrument in instruments: |
| 208 | 216 | ||
| 209 | # Write mission into logger | 217 | # Write mission into logger |
| 210 | - if self.logTerse(): | ||
| 211 | - self.log.header3("Response functions in database \""+ | ||
| 212 | - instrument+"\"") | 218 | + if self._logTerse(): |
| 219 | + self._log.header3("Response functions in database \""+ | ||
| 220 | + instrument+"\"") | ||
| 213 | 221 | ||
| 214 | # Open calibration index file and retrieve calibrations | 222 | # Open calibration index file and retrieve calibrations |
| 215 | filename = "/data/"+mission+"/"+instrument+"/caldb.indx" | 223 | filename = "/data/"+mission+"/"+instrument+"/caldb.indx" |
| 216 | cifname = caldb.rootdir() + filename | 224 | cifname = caldb.rootdir() + filename |
| 217 | fits = gammalib.GFits(cifname) | 225 | fits = gammalib.GFits(cifname) |
| 218 | cif = fits["CIF"] | 226 | cif = fits["CIF"] |
| 219 | - cals = cif["CAL_CBD"] | 227 | + caltable = cif["CAL_CBD"] |
| 220 | 228 | ||
| 221 | # Extract response names | 229 | # Extract response names |
| 222 | - names = self._get_response_names(cals) | 230 | + names = self._get_response_names(caltable) |
| 223 | 231 | ||
| 224 | # Print response name | 232 | # Print response name |
| 225 | - if self.logTerse(): | 233 | + if self._logTerse(): |
| 226 | for name in names: | 234 | for name in names: |
| 227 | - self.log(name+"\n") | ||
| 228 | - self.log("\n") | 235 | + self._log(name+"\n") |
| 236 | + self._log("\n") | ||
| 229 | 237 | ||
| 230 | # Return | 238 | # Return |
| 231 | return | 239 | return |
| @@ -235,14 +243,12 @@ class cscaldb(ctools.cscript): | @@ -235,14 +243,12 @@ class cscaldb(ctools.cscript): | ||
| 235 | # Main routine entry point # | 243 | # Main routine entry point # |
| 236 | # ======================== # | 244 | # ======================== # |
| 237 | if __name__ == '__main__': | 245 | if __name__ == '__main__': |
| 238 | - """ | ||
| 239 | - Logs calibration database into the log file. | ||
| 240 | - """ | 246 | + |
| 241 | # Create instance of application | 247 | # Create instance of application |
| 242 | app = cscaldb(sys.argv) | 248 | app = cscaldb(sys.argv) |
| 243 | 249 | ||
| 244 | # Open logfile | 250 | # Open logfile |
| 245 | - app.logFileOpen() | 251 | + app._logFileOpen() |
| 246 | 252 | ||
| 247 | # Execute application | 253 | # Execute application |
| 248 | app.execute() | 254 | app.execute() |