Commit 949057f8c3dbeaa207634be907e01cc362858ee6

Authored by Pierrick Martin
1 parent 0d9c23cf

Modified how events file name is prepared to deal with case of multiple observat…

…ions without corresponding input file names. Also changed code so that an XML is always written even if just one observation.
src/ctbin/ctbin.cpp
@@ -358,15 +358,19 @@ void ctbin::save(void) @@ -358,15 +358,19 @@ void ctbin::save(void)
358 } 358 }
359 } 359 }
360 360
  361 + /*
361 // Case A: Save counts map(s) and XML metadata information 362 // Case A: Save counts map(s) and XML metadata information
362 if (m_use_xml) { 363 if (m_use_xml) {
363 save_xml(); 364 save_xml();
364 } 365 }
365 -  
366 // Case B: Save counts map as FITS file 366 // Case B: Save counts map as FITS file
367 else { 367 else {
368 save_fits(); 368 save_fits();
369 } 369 }
  370 + */
  371 +
  372 + // Always save FITS and an XML summary
  373 + save_xml();
370 374
371 // Return 375 // Return
372 return; 376 return;
@@ -762,16 +766,27 @@ void ctbin::free_members(void) @@ -762,16 +766,27 @@ void ctbin::free_members(void)
762 * Converts an input filename into an output filename by prepending the 766 * Converts an input filename into an output filename by prepending the
763 * prefix stored in the member m_prefix to the input filename. Any path will 767 * prefix stored in the member m_prefix to the input filename. Any path will
764 * be stripped from the input filename. Also a trailing ".gz" will be 768 * be stripped from the input filename. Also a trailing ".gz" will be
765 - * stripped. 769 + * stripped. If no input file name exist, prefix and observation
  770 + * number are used.
766 ***************************************************************************/ 771 ***************************************************************************/
767 -std::string ctbin::set_outfile_name(const std::string& filename) const 772 +std::string ctbin::set_outfile_name(const int index) const
768 { 773 {
  774 +
  775 + // Initialize output file name
  776 + std::string outname="";
  777 +
769 // Split input filename into path elements 778 // Split input filename into path elements
770 - std::vector<std::string> elements = gammalib::split(filename, "/");  
771 -  
772 - // The last path element is the filename  
773 - std::string outname = m_prefix + elements[elements.size()-1];  
774 - 779 + std::vector<std::string> elements = gammalib::split(m_infiles[index], "/");
  780 +
  781 + // If there is an observation input file name
  782 + if (elements.size() > 0) {
  783 + outname = m_prefix + elements[elements.size()-1];
  784 + }
  785 + // ...else, use observation number
  786 + else {
  787 + outname = m_prefix + m_obs[index]->id() + ".fits";
  788 + }
  789 +
775 // Strip any ".gz" 790 // Strip any ".gz"
776 outname = gammalib::strip_chars(outname, ".gz"); 791 outname = gammalib::strip_chars(outname, ".gz");
777 792
@@ -841,7 +856,7 @@ void ctbin::save_xml(void) @@ -841,7 +856,7 @@ void ctbin::save_xml(void)
841 if (obs != NULL) { 856 if (obs != NULL) {
842 857
843 // Set event output file name 858 // Set event output file name
844 - std::string outfile = set_outfile_name(m_infiles[i]); 859 + std::string outfile = set_outfile_name(i);
845 860
846 // Store output file name in observation 861 // Store output file name in observation
847 obs->eventfile(outfile); 862 obs->eventfile(outfile);
src/ctbin/ctbin.hpp
@@ -73,7 +73,7 @@ protected: @@ -73,7 +73,7 @@ protected:
73 void init_members(void); 73 void init_members(void);
74 void copy_members(const ctbin& app); 74 void copy_members(const ctbin& app);
75 void free_members(void); 75 void free_members(void);
76 - std::string set_outfile_name(const std::string& filename) const; 76 + std::string set_outfile_name(const int index) const;
77 void save_fits(void); 77 void save_fits(void);
78 void save_xml(void); 78 void save_xml(void);
79 void save_counts_map(const GCTAObservation* obs, 79 void save_counts_map(const GCTAObservation* obs,