Commit b7aca2b49942baa0393d4dfeefaf8de7634f4933

Authored by knodlseder
1 parent 5b47c172

write DS keywords

src/ctselect/ctselect.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctselect - CTA data selection tool * 2 * ctselect - CTA data selection tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2010 by Jurgen Knodlseder * 4 + * copyright (C) 2010-2011 by Jurgen Knodlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
@@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
29 #define STRING_COLUMN_TEST 1 29 #define STRING_COLUMN_TEST 1
30 30
31 /* __ Coding definitions _________________________________________________ */ 31 /* __ Coding definitions _________________________________________________ */
32 -#define SELECT_TIME 0 32 +#define SELECT_TIME 1
33 #define SELECT_ENERGY 1 33 #define SELECT_ENERGY 1
34 #define SELECT_ROI 1 34 #define SELECT_ROI 1
35 35
@@ -124,6 +124,9 @@ void ctselect::run(void) @@ -124,6 +124,9 @@ void ctselect::run(void)
124 // Append GTI to FITS file 124 // Append GTI to FITS file
125 append_gti(); 125 append_gti();
126 126
  127 + // Set data selection keywords
  128 + write_ds_keys();
  129 +
127 // Save output FITS file 130 // Save output FITS file
128 m_file.saveto(m_outfile, clobber()); 131 m_file.saveto(m_outfile, clobber());
129 132
@@ -263,61 +266,47 @@ void ctselect::append_gti(void) @@ -263,61 +266,47 @@ void ctselect::append_gti(void)
263 266
264 267
265 /***********************************************************************//** 268 /***********************************************************************//**
266 - * @brief Copy events 269 + * @brief Write data selection keywords
267 * 270 *
268 - * This is some old code that is not used but that is kept for the moment  
269 - * for debugging purposes. 271 + * @todo This is a very dumb data selection keyword writing routine that does
  272 + * not take into account any existing keywords. We definitely want a
  273 + * more secure logic that checks for existing keywords and possible
  274 + * conflicts. But for this prototype software, this code does the job.
270 ***************************************************************************/ 275 ***************************************************************************/
271 -void ctselect::copy(void) 276 +void ctselect::write_ds_keys(void)
272 { 277 {
273 - // Open FITS file  
274 - GFits file(m_infile);  
275 - //std::cout << file << std::endl;  
276 -  
277 - // Optional perform Bit column testing  
278 - #if BIT_COLUMN_TEST  
279 - GFitsTableBitCol* ptr = (GFitsTableBitCol*)file.table("EVENTS")->column("TELMASK");  
280 - for (int i = 0; i < ptr->length(); ++i) {  
281 - std::cout << i << ": ";  
282 - for (int k = 0; k < ptr->number(); ++k)  
283 - std::cout << (int)(*(ptr))(i, k) << " ";  
284 - std::cout << std::endl;  
285 - }  
286 - (*(ptr))(8507, 1) = true;  
287 - (*(ptr))(8508, 0) = false;  
288 - (*(ptr))(8509, 1) = false;  
289 - (*(ptr))(8509, 2) = false;  
290 - std::cout << "change now:" << std::endl;  
291 - for (int i = 8507; i < 8510; ++i) {  
292 - std::cout << i << ": ";  
293 - for (int k = 0; k < ptr->number(); ++k)  
294 - std::cout << (int)(*(ptr))(i, k) << " ";  
295 - std::cout << std::endl;  
296 - }  
297 - #endif  
298 -  
299 - // Optional perform String column testing  
300 - #if STRING_COLUMN_TEST  
301 - GFitsTableStringCol* ptr = (GFitsTableStringCol*)file.table("ANALYSIS")->column("UNIT");  
302 - std::cout << "Anynul: " << ptr->anynul() << std::endl;  
303 - for (int i = 0; i < ptr->length(); ++i) {  
304 - std::cout << "\"" << ptr->string(i) << "\"" << std::endl;  
305 - }  
306 - #endif  
307 -  
308 - // Save file  
309 - file.saveto(m_outfile, true);  
310 - //std::cout << file << std::endl;  
311 -  
312 - // Optional perform String column testing  
313 - #if STRING_COLUMN_TEST  
314 - GFits file2(m_outfile);  
315 - GFitsTableStringCol* ptr2 = (GFitsTableStringCol*)file2.table("ANALYSIS")->column("UNIT");  
316 - std::cout << "Anynul: " << ptr2->anynul() << std::endl;  
317 - for (int i = 0; i < ptr2->length(); ++i) {  
318 - std::cout << "\"" << ptr2->string(i) << "\"" << std::endl;  
319 - }  
320 - #endif 278 + // Get event list header
  279 + GFitsHDU* hdu = m_file.hdu("EVENTS");
  280 +
  281 + // Continue only if HDU is valid
  282 + if (hdu != NULL) {
  283 +
  284 + // Set cone selection string
  285 + std::string dsval2 = "CIRCLE("+str(m_ra)+","+str(m_dec)+","+str(m_rad)+")";
  286 +
  287 + // Set energy selection string
  288 + std::string dsval3 = str(m_emin)+":"+str(m_emax);
  289 +
  290 + // Add time selection keywords
  291 + hdu->card("DSTYP1", "TIME", "Data selection type");
  292 + hdu->card("DSUNI1", "s", "Data selection unit");
  293 + hdu->card("DSVAL1", "TABLE", "Data selection value");
  294 + hdu->card("DSREF1", ":GTI", "Data selection reference");
  295 +
  296 + // Add acceptance cone selection
  297 + hdu->card("DSTYP2", "POS(RA,DEC)", "Data selection type");
  298 + hdu->card("DSUNI2", "deg", "Data selection unit");
  299 + hdu->card("DSVAL2", dsval2, "Data selection value");
  300 +
  301 + // Add energy range selection
  302 + hdu->card("DSTYP3", "ENERGY", "Data selection type");
  303 + hdu->card("DSUNI3", "TeV", "Data selection unit");
  304 + hdu->card("DSVAL3", dsval3, "Data selection value");
  305 +
  306 + // Set number of data selection keys
  307 + hdu->card("NDSKEYS", 3, "Number of data selections");
  308 +
  309 + } // endif: HDU was valid
321 310
322 // Return 311 // Return
323 return; 312 return;
src/ctselect/ctselect.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctselect - CTA data selection tool * 2 * ctselect - CTA data selection tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2010 by Jurgen Knodlseder * 4 + * copyright (C) 2010-2011 by Jurgen Knodlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
@@ -44,7 +44,7 @@ public: @@ -44,7 +44,7 @@ public:
44 void get_parameters(void); 44 void get_parameters(void);
45 void select(void); 45 void select(void);
46 void append_gti(void); 46 void append_gti(void);
47 - void copy(void); 47 + void write_ds_keys(void);
48 48
49 protected: 49 protected:
50 // Protected methods 50 // Protected methods