diff --git a/cscripts/cscaldb.py b/cscripts/cscaldb.py index dfcc705..4ccdad1 100755 --- a/cscripts/cscaldb.py +++ b/cscripts/cscaldb.py @@ -71,9 +71,7 @@ class cscaldb(ctools.cscript): def _get_parameters(self): # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index d11d4a5..9f9b808 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -154,10 +154,8 @@ class csfindobs(ctools.cscript): (self._obs_index, self._prodname)) raise RuntimeError(msg) - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csiactcopy.py b/cscripts/csiactcopy.py index 48d891d..bb4f8ae 100755 --- a/cscripts/csiactcopy.py +++ b/cscripts/csiactcopy.py @@ -80,11 +80,9 @@ class csiactcopy(ctools.cscript): self._outpath = gammalib.expand_env(self['outpath'].string()) self._runlist = self['runlist'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') - + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) + # Return return diff --git a/cscripts/csiactdata.py b/cscripts/csiactdata.py index 1c54d56..b5a3c77 100755 --- a/cscripts/csiactdata.py +++ b/cscripts/csiactdata.py @@ -83,10 +83,8 @@ class csiactdata(ctools.cscript): '"master_indx" to specifiy a different '+ 'filename.') - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index bb62d73..26e76d6 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -214,10 +214,8 @@ class csiactobs(ctools.cscript): self._subdir = os.path.dirname(self._hdu_index) self._debug = False # Debugging in client tools - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index f2e56d1..a345f69 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -140,9 +140,7 @@ class cslightcrv(ctools.cscript): self['outfile'].filename() # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csmodelinfo.py b/cscripts/csmodelinfo.py index 6becbf6..ceaf4e0 100755 --- a/cscripts/csmodelinfo.py +++ b/cscripts/csmodelinfo.py @@ -80,10 +80,8 @@ class csmodelinfo(ctools.cscript): if self._read_ahead(): self["ds9file"].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csmodelmerge.py b/cscripts/csmodelmerge.py index e345ee1..69e8732 100755 --- a/cscripts/csmodelmerge.py +++ b/cscripts/csmodelmerge.py @@ -107,10 +107,8 @@ class csmodelmerge(ctools.cscript): # Get clobber parameter self._clobber = self['clobber'].boolean() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index 3405b4b..dcdeefe 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -128,10 +128,8 @@ class csobs2caldb(ctools.cscript): self['irf'].string() self['rootdir'].string() - # Write input parameters and header into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csobsdef.py b/cscripts/csobsdef.py index e715957..f375073 100755 --- a/cscripts/csobsdef.py +++ b/cscripts/csobsdef.py @@ -112,10 +112,8 @@ class csobsdef(ctools.cscript): if self._read_ahead(): self['outobs'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 0ab4a78..4533a8d 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -86,10 +86,8 @@ class csobsinfo(ctools.cscript): if self._read_ahead(): self['ds9file'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cspull.py b/cscripts/cspull.py index e178d0f..823cea4 100755 --- a/cscripts/cspull.py +++ b/cscripts/cspull.py @@ -123,9 +123,7 @@ class cspull(ctools.cscript): self['profile'].boolean() # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csresmap.py b/cscripts/csresmap.py index 9946b24..0be341d 100755 --- a/cscripts/csresmap.py +++ b/cscripts/csresmap.py @@ -129,10 +129,8 @@ class csresmap(ctools.cscript): if (self._read_ahead()): self['outmap'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csroot2caldb.py b/cscripts/csroot2caldb.py index 085554a..12524b6 100755 --- a/cscripts/csroot2caldb.py +++ b/cscripts/csroot2caldb.py @@ -79,10 +79,8 @@ class csroot2caldb(ctools.cscript): self['bgdoversample'].integer() self['bgdinfill'].boolean() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cssens.py b/cscripts/cssens.py index f653c63..1d3830f 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -124,10 +124,8 @@ class cssens(ctools.cscript): gammalib.GEnergy(self._emin, 'TeV'), gammalib.GEnergy(self._emax, 'TeV')) - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csspec.py b/cscripts/csspec.py index 02c60bb..2f035cb 100755 --- a/cscripts/csspec.py +++ b/cscripts/csspec.py @@ -122,10 +122,8 @@ class csspec(ctools.cscript): if self._read_ahead(): self["outfile"].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log("\n") + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cstsdist.py b/cscripts/cstsdist.py index b52bd9d..77a7124 100755 --- a/cscripts/cstsdist.py +++ b/cscripts/cstsdist.py @@ -102,10 +102,8 @@ class cstsdist(ctools.cscript): self['outfile'].filename() self['debug'].boolean() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cstsmapmerge.py b/cscripts/cstsmapmerge.py index 1d50b58..987958e 100755 --- a/cscripts/cstsmapmerge.py +++ b/cscripts/cstsmapmerge.py @@ -118,10 +118,8 @@ class cstsmapmerge(ctools.cscript): if self._read_ahead(): self['outmap'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/cstsmapsplit.py b/cscripts/cstsmapsplit.py index 9eaa33e..52127ca 100755 --- a/cscripts/cstsmapsplit.py +++ b/cscripts/cstsmapsplit.py @@ -92,10 +92,8 @@ class cstsmapsplit(ctools.cscript): self._compute_null = self['compute_null'].boolean() self._outfile = self['outfile'].filename() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + # Write input parameters into logger + self._log_parameters(gammalib.TERSE) # Return return diff --git a/cscripts/csworkflow.py b/cscripts/csworkflow.py index b1e3fd7..1e83460 100755 --- a/cscripts/csworkflow.py +++ b/cscripts/csworkflow.py @@ -76,9 +76,7 @@ class csworkflow(ctools.cscript): self._workflow = gammalib.GXml(xmlfile.url()) # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log('\n') + self._log_parameters(gammalib.TERSE) # Return return diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index 7f0f632..a55c3bd 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -226,47 +226,34 @@ void ctbin::run(void) // Get task parameters get_parameters(); - // Write observation(s) into logger - if (logTerse()) { - log << std::endl; - log.header1(gammalib::number("Observation", m_obs.size())); - log << m_obs.print(m_chatter) << std::endl; - } + // Write input observation container into logger + log_observations(NORMAL, m_obs); // Write header - if (logTerse()) { - log << std::endl; - log.header1(gammalib::number("Bin observation", m_obs.size())); - } + log_header1(TERSE, gammalib::number("Bin observation", m_obs.size())); // Loop over all observations in the container for (int i = 0; i < m_obs.size(); ++i) { // Write header for observation - if (logTerse()) { - log.header3(get_obs_header(m_obs[i])); - } + log_header3(NORMAL, get_obs_header(m_obs[i])); // Get CTA observation GCTAObservation* obs = dynamic_cast(m_obs[i]); // Skip observation if it's not CTA if (obs == NULL) { - if (logTerse()) { - log << " Skipping "; - log << m_obs[i]->instrument(); - log << " observation" << std::endl; - } + std::string msg = " Skipping "+m_obs[i]->instrument()+ + " observation\n"; + log_string(NORMAL, msg); continue; } // Skip observation if we have a binned observation if (obs->eventtype() == "CountsCube") { - if (logTerse()) { - log << " Skipping binned "; - log << obs->instrument(); - log << " observation" << std::endl; - } + std::string msg = " Skipping binned "+m_obs[i]->instrument()+ + " observation\n"; + log_string(NORMAL, msg); continue; } @@ -288,12 +275,8 @@ void ctbin::run(void) // Set a single cube in the observation container obs_cube(); - // Write observation(s) into logger - if (logTerse()) { - log << std::endl; - log.header1(gammalib::number("Binned observation", m_obs.size())); - log << m_obs.print(m_chatter) << std::endl; - } + // Write resulting observation container into logger + log_observations(NORMAL, m_obs, "Binned observation"); // Optionally publish counts cube if (m_publish) { @@ -313,10 +296,7 @@ void ctbin::run(void) void ctbin::save(void) { // Write header - if (logTerse()) { - log << std::endl; - log.header1("Save counts cube"); - } + log_header1(TERSE, "Save counts cube"); // Get counts cube filename m_outcube = (*this)["outcube"].filename(); @@ -330,11 +310,8 @@ void ctbin::save(void) // Save only if observation is valid if (obs != NULL) { - // Log filename - if (logTerse()) { - log << gammalib::parformat("Counts cube file"); - log << m_outcube.url() << std::endl; - } + // Log counts cube file name + log_value(NORMAL, "Counts cube file", m_outcube.url()); // Save cube obs->save(m_outcube, clobber()); @@ -356,10 +333,7 @@ void ctbin::save(void) void ctbin::publish(const std::string& name) { // Write header - if (logTerse()) { - log << std::endl; - log.header1("Publish counts cube"); - } + log_header1(TERSE, "Publish counts cube"); // Set default name is user name is empty std::string user_name(name); @@ -367,11 +341,8 @@ void ctbin::publish(const std::string& name) user_name = CTBIN_NAME; } - // Log filename - if (logTerse()) { - log << gammalib::parformat("Counts cube name"); - log << user_name << std::endl; - } + // Log counts cube name + log_value(NORMAL, "Counts cube name", user_name); // Publish counts cube m_counts.publish(user_name); @@ -500,10 +471,7 @@ void ctbin::get_parameters(void) } // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } + log_parameters(TERSE); // Return return; @@ -610,23 +578,14 @@ void ctbin::fill_cube(GCTAObservation* obs) m_livetime += obs->livetime(); // Log filling results - if (logTerse()) { - log << gammalib::parformat("Events in list"); - log << obs->events()->size() << std::endl; - log << gammalib::parformat("Events in cube"); - log << num_in_map << std::endl; - log << gammalib::parformat("Event bins outside RoI"); - log << num_outside_roi << std::endl; - log << gammalib::parformat("Events outside cube area"); - log << num_outside_map << std::endl; - log << gammalib::parformat("Events outside energy bins"); - log << num_outside_ebds << std::endl; - } + log_value(TERSE, "Events in list", obs->events()->size()); + log_value(TERSE, "Events in cube", num_in_map); + log_value(TERSE, "Event bins outside RoI", num_outside_roi); + log_value(TERSE, "Events outside cube area", num_outside_map); + log_value(TERSE, "Events outside energy bins", num_outside_ebds); // Log cube - if (logExplicit()) { - log << m_counts << std::endl; - } + log_string(EXPLICIT, m_counts.print()); } // endif: observation was valid diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 4c08b70..1859c1b 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -211,12 +211,6 @@ void ctbkgcube::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Warn if there are not enough energy bins int n = m_background.energies().size(); double logEmin = std::log10(m_background.energies()[0].TeV()); @@ -605,6 +599,9 @@ void ctbkgcube::get_parameters(void) m_outmodel = (*this)["outmodel"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctbutterfly/ctbutterfly.cpp b/src/ctbutterfly/ctbutterfly.cpp index deb2a21..9671fe3 100644 --- a/src/ctbutterfly/ctbutterfly.cpp +++ b/src/ctbutterfly/ctbutterfly.cpp @@ -211,12 +211,6 @@ void ctbutterfly::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -687,6 +681,9 @@ void ctbutterfly::get_parameters(void) m_outfile = (*this)["outfile"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctcubemask/ctcubemask.cpp b/src/ctcubemask/ctcubemask.cpp index 89090ca..8ba0950 100644 --- a/src/ctcubemask/ctcubemask.cpp +++ b/src/ctcubemask/ctcubemask.cpp @@ -212,12 +212,6 @@ void ctcubemask::run(void) // Get parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Write observation(s) into logger if (logTerse()) { log << std::endl; @@ -471,6 +465,9 @@ void ctcubemask::get_parameters(void) m_prefix = (*this)["prefix"].string(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctedispcube/ctedispcube.cpp b/src/ctedispcube/ctedispcube.cpp index c728729..2f5403a 100644 --- a/src/ctedispcube/ctedispcube.cpp +++ b/src/ctedispcube/ctedispcube.cpp @@ -223,12 +223,6 @@ void ctedispcube::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Write header if (logTerse()) { log << std::endl; @@ -417,6 +411,9 @@ void ctedispcube::get_parameters(void) m_outcube = (*this)["outcube"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/cterror/cterror.cpp b/src/cterror/cterror.cpp index 510a2a1..2901e5c 100644 --- a/src/cterror/cterror.cpp +++ b/src/cterror/cterror.cpp @@ -224,12 +224,6 @@ void cterror::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -568,6 +562,9 @@ void cterror::get_parameters(void) m_outmodel = (*this)["outmodel"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index 4b22314..cdaeb12 100644 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -211,12 +211,6 @@ void ctexpcube::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Warn if there are not enough energy bins int n = m_expcube.energies().size(); double logEmin = std::log10(m_expcube.energies()[0].TeV()); @@ -460,6 +454,9 @@ void ctexpcube::get_parameters(void) m_outcube = (*this)["outcube"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp index 078483b..a6f130a 100644 --- a/src/ctlike/ctlike.cpp +++ b/src/ctlike/ctlike.cpp @@ -209,12 +209,6 @@ void ctlike::run(void) // Get parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -441,6 +435,9 @@ void ctlike::get_parameters(void) static_cast(m_opt)->logger(NULL); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctmapcube/ctmapcube.cpp b/src/ctmapcube/ctmapcube.cpp index 1af5829..e9bfc5e 100644 --- a/src/ctmapcube/ctmapcube.cpp +++ b/src/ctmapcube/ctmapcube.cpp @@ -380,10 +380,7 @@ void ctmapcube::get_parameters(void) m_cube = GModelSpatialDiffuseCube(cube, energies); // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } + log_parameters(TERSE); // Return return; diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index 695b77d..e87ac41 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -211,12 +211,6 @@ void ctmodel::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -618,6 +612,9 @@ void ctmodel::get_parameters(void) } // endif: cube was scheduled for appending + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index ce1ae07..049a5c6 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -231,12 +231,6 @@ void ctobssim::run(void) // Get parameters get_parameters(); - // Write input parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Special mode: if read ahead is specified we know that we called // the execute() method, hence files are saved immediately and event // lists are disposed afterwards. @@ -665,6 +659,9 @@ void ctobssim::get_parameters(void) } // endfor: looped over observations + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctpsfcube/ctpsfcube.cpp b/src/ctpsfcube/ctpsfcube.cpp index 89e3297..932a9db 100644 --- a/src/ctpsfcube/ctpsfcube.cpp +++ b/src/ctpsfcube/ctpsfcube.cpp @@ -210,12 +210,6 @@ void ctpsfcube::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Write header if (logTerse()) { log << std::endl; @@ -401,6 +395,9 @@ void ctpsfcube::get_parameters(void) m_outcube = (*this)["outcube"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index 6590a08..a687d8e 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -218,12 +218,6 @@ void ctselect::run(void) // Get parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Write observation(s) into logger if (logTerse()) { log << std::endl; @@ -623,6 +617,9 @@ void ctselect::get_parameters(void) m_timemin.set(m_tmin, m_cta_ref); m_timemax.set(m_tmax, m_cta_ref); + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index ee54e88..1597f0b 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -215,12 +215,6 @@ void ctskymap::run(void) // Get parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Write observation(s) into logger if (logTerse()) { log << std::endl; @@ -414,6 +408,9 @@ void ctskymap::get_parameters(void) m_outmap = (*this)["outmap"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/cttsmap/cttsmap.cpp b/src/cttsmap/cttsmap.cpp index 27c3ff2..8ac037e 100644 --- a/src/cttsmap/cttsmap.cpp +++ b/src/cttsmap/cttsmap.cpp @@ -209,12 +209,6 @@ void cttsmap::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -630,6 +624,9 @@ void cttsmap::get_parameters(void) m_outmap = (*this)["outmap"].filename(); } + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/ctulimit/ctulimit.cpp b/src/ctulimit/ctulimit.cpp index 41dc9a5..d038b66 100644 --- a/src/ctulimit/ctulimit.cpp +++ b/src/ctulimit/ctulimit.cpp @@ -225,12 +225,6 @@ void ctulimit::run(void) // Get task parameters get_parameters(); - // Write parameters into logger - if (logTerse()) { - log_parameters(); - log << std::endl; - } - // Set energy dispersion flag for all CTA observations and save old // values in save_edisp vector std::vector save_edisp; @@ -582,6 +576,9 @@ void ctulimit::get_parameters(void) m_tol = (*this)["tol"].real(); m_max_iter = (*this)["max_iter"].integer(); + // Write parameters into logger + log_parameters(TERSE); + // Return return; } diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index d5362dd..33d2123 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -894,6 +894,40 @@ void ctool::require_inobs_nocube(const std::string& method) /***********************************************************************//** + * @brief Log observation container + * + * @param[in] chatter Minimum required chattiness + * @param[in] obs Observation container + * @param[in] what String specifying the container content + * + * Log observations if chattiness is at least @p chatter. + ***************************************************************************/ +void ctool::log_observations(const GChatter& chatter, + const GObservations& obs, + const std::string& what) +{ + // Get chattiness of ctool + GChatter chattiness = static_cast((*this)["chatter"].integer()); + + // Only write message if chattiness is at least equal to the minimum + // required chattiness + if (chattiness >= chatter) { + + // Log observation header + log << std::endl; + log.header1(gammalib::number(what, obs.size())); + + // Log observation content dependent on chattiness + log << obs.print(chattiness) << std::endl; + + } // endif: Chattiness satisfied minimum required level + + // Return + return; +} + + +/***********************************************************************//** * @brief Set response for all CTA observations in container * * @param[in,out] obs Observation container diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 0bb2e86..66c4651 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -85,6 +85,11 @@ protected: void require_inobs_nolist(const std::string& method); void require_inobs_nocube(const std::string& method); + // Protected methods for logging + void log_observations(const GChatter& chatter, + const GObservations& obs, + const std::string& what = "Observation"); + // Protected support methods void set_response(GObservations& obs); void set_obs_response(GCTAObservation* obs); diff --git a/test/test_ctbin.py b/test/test_ctbin.py index 892d39a..a4e2442 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -71,8 +71,8 @@ class Test(test): # Setup ctbin command cmd = ctbin+' inobs="'+self._events+'"'+ \ ' outcube="cntmap_cmd1.fits"'+\ - ' emin=0.1 emax=100.0 enumbins=20 ebinalg="LOG"'+ \ - ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ + ' emin=0.1 emax=100.0 enumbins=10 ebinalg="LOG"'+ \ + ' nxpix=40 nypix=40 binsz=0.1 coordsys="CEL"'+ \ ' xref=83.63 yref=22.01 proj="CAR"'+ \ ' logfile="ctbin_cmd1.log" chatter=1' @@ -91,8 +91,8 @@ class Test(test): # Setup ctbin command cmd = ctbin+' inobs="events_that_do_not_exist.fits"'+ \ ' outcube="cntmap_cmd2.fits"'+\ - ' emin=0.1 emax=100.0 enumbins=20 ebinalg="LOG"'+ \ - ' nxpix=200 nypix=200 binsz=0.02 coordsys="CEL"'+ \ + ' emin=0.1 emax=100.0 enumbins=10 ebinalg="LOG"'+ \ + ' nxpix=40 nypix=40 binsz=0.1 coordsys="CEL"'+ \ ' xref=83.63 yref=22.01 proj="CAR"'+ \ ' logfile="ctbin_cmd1.log" chatter=1' @@ -108,17 +108,33 @@ class Test(test): """ Test ctbin from Python """ - # Set-up ctbin + # Allocate ctbin + bin = ctools.ctbin() + + # Check that empty ctbin has an empty observation container and counts + # cube + self.test_value(bin.obs().size(), 0, + 'Check that empty ctbin has an empty observation container') + self.test_value(bin.cube().size(), 0, + 'Check that empty ctbin has an empty counts cube') + + # Check that saving and publishing does nothing + bin['debug'] = True + bin['outcube'] = 'ctbin_py0.fits' + #bin.save() # Segfaults, see issue #1835 + #bin.publish() # Segfaults, see issue #1835 + + # Set ctbin parameters bin = ctools.ctbin() bin['inobs'] = self._events - bin['outcube'] = 'cntmap.fits' + bin['outcube'] = 'ctbin_py1.fits' bin['ebinalg'] = 'LOG' bin['emin'] = 0.1 bin['emax'] = 100.0 - bin['enumbins'] = 20 - bin['nxpix'] = 200 - bin['nypix'] = 200 - bin['binsz'] = 0.02 + bin['enumbins'] = 10 + bin['nxpix'] = 40 + bin['nypix'] = 40 + bin['binsz'] = 0.1 bin['coordsys'] = 'CEL' bin['proj'] = 'CAR' bin['xref'] = 83.63 @@ -132,14 +148,14 @@ class Test(test): # see issue #1823 (need to fix that) bin.run() - # Check content of observation and cube + # Check content of observation container and counts cube self._check_observation(bin, 5542) self._check_cube(bin.cube(), 5542) # Test copy constructor cpy_bin = bin.copy() - # Check content of observation and cube + # Check content of observation container and counts cube self._check_observation(cpy_bin, 5542) self._check_cube(cpy_bin.cube(), 5542) @@ -148,20 +164,29 @@ class Test(test): cpy_bin['chatter'] = 3 cpy_bin.run() - # Check content of observation and cube. We expect now an empty - # event cube as on input the observation is binned, and any binned - # observation will be skipped, hence the counts cube should be - # empty. + # Check content of observation container and counts cube. Now an empty + # event cube is expected since on input the observation is binned, and + # any binned observation will be skipped. self._check_observation(cpy_bin, 0) self._check_cube(cpy_bin.cube(), 0) # Save counts cube bin.save() - # Load counts cube and check content. - evt = gammalib.GCTAEventCube('cntmap.fits') + # Load counts cube and check content + evt = gammalib.GCTAEventCube('ctbin_py1.fits') self._check_cube(evt, 5542) + # Now clear ctbin tool + #bin.clear() # Segfaults, see issue #1835 + + # Check that cleared ctbin has an empty observation container and + # counts cube + #self.test_value(bin.obs().size(), 0, + # 'Check that empty ctbin has an empty observation container') + #self.test_value(bin.cube().size(), 0, + # 'Check that empty ctbin has an empty counts cube') + # Prepare observation container for stacked analysis cta = gammalib.GCTAObservation(self._events) obs = gammalib.GObservations() @@ -174,52 +199,33 @@ class Test(test): # Set-up ctbin using an observation container bin = ctools.ctbin(obs) - bin['outcube'] = 'cntmap.fits' + bin['outcube'] = 'ctbin_py3.fits' bin['ebinalg'] = 'LOG' bin['emin'] = 0.1 bin['emax'] = 100.0 - bin['enumbins'] = 20 - bin['nxpix'] = 200 - bin['nypix'] = 200 - bin['binsz'] = 0.02 + bin['enumbins'] = 10 + bin['nxpix'] = 40 + bin['nypix'] = 40 + bin['binsz'] = 0.1 bin['coordsys'] = 'CEL' bin['proj'] = 'CAR' bin['xref'] = 83.63 bin['yref'] = 22.01 + bin['publish'] = True + bin['debug'] = True bin['logfile'] = 'ctbin_py3.log' bin['chatter'] = 4 - # Run ctbin tool - bin.logFileOpen() # Make sure we get a log file - bin.run() + # Execute ctbin tool + bin.execute() # Check content of observation and cube (need multiplier=3 since # three identical observations have been appended) self._check_observation(bin, 5542, multiplier=3) self._check_cube(bin.cube(), 5542, multiplier=3) - # Set-up ctbin using an observation container - bin = ctools.ctbin(obs) - bin['outcube'] = 'cntmap2.fits' - bin['ebinalg'] = 'LOG' - bin['emin'] = 0.1 - bin['emax'] = 100.0 - bin['enumbins'] = 20 - bin['nxpix'] = 200 - bin['nypix'] = 200 - bin['binsz'] = 0.02 - bin['coordsys'] = 'CEL' - bin['proj'] = 'CAR' - bin['xref'] = 83.63 - bin['yref'] = 22.01 - bin['logfile'] = 'ctbin_py4.log' - bin['chatter'] = 4 - - # Execute ctbin tool - bin.execute() - # Load counts cube and check content. - evt = gammalib.GCTAEventCube('cntmap2.fits') + evt = gammalib.GCTAEventCube('ctbin_py3.fits') self._check_cube(evt, 5542, multiplier=3) # Return @@ -237,23 +243,23 @@ class Test(test): nevents : int Expected number of events multiplier : float, optional - Observation multiplier + Ontime and livetime multiplier """ # Test observation container obs = gammalib.GCTAObservation(ctbin.obs()[0]) pnt = obs.pointing() self.test_value(ctbin.obs().size(), 1, - 'There is one observation') - self.test_assert(obs.instrument() == 'CTA', - 'Observation is CTA observation') + 'Check that there is one observation on the observation container') + self.test_value(obs.instrument(), 'CTA', + 'Check that the one observation is a CTA observation') self.test_value(obs.ontime(), 1800.0*multiplier, 1.0e-6, - 'Ontime is 1800 sec') + 'Check ontime of observation') self.test_value(obs.livetime(), 1710.0*multiplier, 1.0e-6, - 'Livetime is 1710 sec') + 'Check livetime of observation') self.test_value(pnt.dir().ra_deg(), 83.63, 1.0e-6, - 'Pointing Right Ascension is 83.63 deg') + 'Check pointing Right Ascension of observation') self.test_value(pnt.dir().dec_deg(), 22.01, 1.0e-6, - 'Pointing Declination is 22.01 deg') + 'Check pointing Declination of observation') # Test event cube self._check_cube(obs.events(), nevents, multiplier=multiplier) @@ -276,9 +282,10 @@ class Test(test): Event number multiplier """ # Test event cube - self.test_value(cube.size(), 800000, '800000 event bins') + self.test_value(cube.size(), 16000, + 'Check bin size of counts cube') self.test_value(cube.number(), nevents*multiplier, - str(nevents*multiplier)+' events') + 'Check number of events in counts cube') # Return return