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 | 30 | # ============= # |
| 31 | 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 | 41 | def __init__(self, *argv): |
| 38 | 42 | """ |
| 39 | 43 | Constructor. |
| 40 | 44 | """ |
| 41 | 45 | # Set name |
| 42 | 46 | self._name = "cscaldb" |
| 43 | - self._version = "1.0.0" | |
| 47 | + self._version = "1.1.0" | |
| 44 | 48 | |
| 45 | 49 | # Initialise application |
| 46 | 50 | if len(argv) == 0: |
| ... | ... | @@ -51,8 +55,8 @@ class cscaldb(ctools.cscript): |
| 51 | 55 | raise TypeError("Invalid number of arguments given.") |
| 52 | 56 | |
| 53 | 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 | 61 | # Return |
| 58 | 62 | return |
| ... | ... | @@ -64,6 +68,8 @@ class cscaldb(ctools.cscript): |
| 64 | 68 | # Return |
| 65 | 69 | return |
| 66 | 70 | |
| 71 | + | |
| 72 | + # Private methods | |
| 67 | 73 | def _get_parameters(self): |
| 68 | 74 | """ |
| 69 | 75 | Get parameters from parfile. |
| ... | ... | @@ -156,6 +162,8 @@ class cscaldb(ctools.cscript): |
| 156 | 162 | # Return response names |
| 157 | 163 | return names |
| 158 | 164 | |
| 165 | + | |
| 166 | + # Public methods | |
| 159 | 167 | def execute(self): |
| 160 | 168 | """ |
| 161 | 169 | Execute the script. |
| ... | ... | @@ -171,16 +179,16 @@ class cscaldb(ctools.cscript): |
| 171 | 179 | Run the script. |
| 172 | 180 | """ |
| 173 | 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 | 185 | # Get parameters |
| 178 | 186 | self._get_parameters() |
| 179 | 187 | |
| 180 | 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 | 193 | # Get the calibration database |
| 186 | 194 | caldb = gammalib.GCaldb() |
| ... | ... | @@ -196,9 +204,9 @@ class cscaldb(ctools.cscript): |
| 196 | 204 | continue |
| 197 | 205 | |
| 198 | 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 | 211 | # Extract instruments |
| 204 | 212 | instruments = self._get_instruments(caldb, mission) |
| ... | ... | @@ -207,25 +215,25 @@ class cscaldb(ctools.cscript): |
| 207 | 215 | for instrument in instruments: |
| 208 | 216 | |
| 209 | 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 | 222 | # Open calibration index file and retrieve calibrations |
| 215 | 223 | filename = "/data/"+mission+"/"+instrument+"/caldb.indx" |
| 216 | 224 | cifname = caldb.rootdir() + filename |
| 217 | 225 | fits = gammalib.GFits(cifname) |
| 218 | 226 | cif = fits["CIF"] |
| 219 | - cals = cif["CAL_CBD"] | |
| 227 | + caltable = cif["CAL_CBD"] | |
| 220 | 228 | |
| 221 | 229 | # Extract response names |
| 222 | - names = self._get_response_names(cals) | |
| 230 | + names = self._get_response_names(caltable) | |
| 223 | 231 | |
| 224 | 232 | # Print response name |
| 225 | - if self.logTerse(): | |
| 233 | + if self._logTerse(): | |
| 226 | 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 | 238 | # Return |
| 231 | 239 | return |
| ... | ... | @@ -235,14 +243,12 @@ class cscaldb(ctools.cscript): |
| 235 | 243 | # Main routine entry point # |
| 236 | 244 | # ======================== # |
| 237 | 245 | if __name__ == '__main__': |
| 238 | - """ | |
| 239 | - Logs calibration database into the log file. | |
| 240 | - """ | |
| 246 | + | |
| 241 | 247 | # Create instance of application |
| 242 | 248 | app = cscaldb(sys.argv) |
| 243 | 249 | |
| 244 | 250 | # Open logfile |
| 245 | - app.logFileOpen() | |
| 251 | + app._logFileOpen() | |
| 246 | 252 | |
| 247 | 253 | # Execute application |
| 248 | 254 | app.execute() | ... | ... |