#ifndef ACIS_PROCESS_EVENTS_H #define ACIS_PROCESS_EVENTS_H #include #ifndef EVENT_DEFS_H #include "event_defs.h" #define EVENT_DEFS_H #endif #ifndef DITHER_DEFS_H #include "dither_defs.h" #endif /* Here you must convert the name of your main function into an SPP/fortran * converted name. Here is the rule. Take the first 5 characters of * your function name (that are literal characters, underscores do not count!) * and the last character, and follow it by an underscore. */ #define acis_process_events acisps_ /* the following define is used for determining whether or not a parity * error condition exists in acis_process_events. A flag is initialized to * PARITY_ERR_EXISTS and is incremented to the sum of the 9 pulse height * columns from the input event. If the sum totals zero for any event then * a parity condition exists for that event. * * PARITY ERROR */ #define PARITY_ERR_EXISTS 0 /* if the sum of the 9 event ph's equals this value (0) then a parity error cond. exists */ /* the following is a temporary list of error codes to use until a * standard error handling system is put in place. * * ERROR CODES */ #define ACIS_PROCESS_EVENTS_NO_ERROR LEV_1_NO_ERROR /* default - no error encountered*/ #define ACIS_PROCESS_EVENTS_ERROR_1 LEV_1_WRITE_ERR /* write error */ #define ACIS_PROCESS_EVENTS_ERROR_2 2 /* grading scheme not recognized */ #define ACIS_PROCESS_EVENTS_ERROR_3 3 /* unable to allocate requested memory */ #define ACIS_PROCESS_EVENTS_ERROR_4 4 /* local maxima of ph's out of sequence */ #define ACIS_PROCESS_EVENTS_ERROR_5 5 /* invalid acis sys (valid are 2.0, 2.1, 2.2) */ #define ACIS_PROCESS_EVENTS_ERROR_6 6 /* data dependency of selected option not met */ #define ACIS_PROCESS_EVENTS_ERROR_7 7 /* detector column error */ #define ACIS_PROCESS_EVENTS_ERROR_8 8 /* bad start or stop coordinates */ #define ACIS_PROCESS_EVENTS_ERROR_9 9 /* start time error */ #define ACIS_PROCESS_EVENTS_ERROR_10 10 /* end time error */ #define ADET_NO_ERROR ACIS_PROCESS_EVENTS_NO_ERROR /* the following defines represent the grade levels for the asca grading * scheme. Currently these values are here because find_asca_grade() is the * only function that needs to access them; however, in the future it may * make more sense to move them to a global header package. * * ASCA GRADINGS */ #define ASCA_GRADE_S 0 /* asca grade for S */ #define ASCA_GRADE_S_PLUS 1 /* asca grade for S+ */ #define ASCA_GRADE_PV 2 /* asca grade for Pv */ #define ASCA_GRADE_PL 3 /* asca grade for Pl */ #define ASCA_GRADE_PR 4 /* asca grade for Pr */ #define ASCA_GRADE_P_PLUS 5 /* asca grade for P+ */ #define ASCA_GRADE_L_AND_Q 6 /* asca grade for L+Q */ #define ASCA_GRADE_DEFAULT 7 /* default asca grade */ /* the following defines represent the grade levels for the acis grading * scheme. Currently these values are here because find_acis_grade() is the * only function that needs to access them; however, in the future it may * make more sense to move them to a global header package. * * ACIS GRADINGS */ #define ACIS_GRADE_SINGLE 0 /* acis grade for Single */ #define ACIS_GRADE_VERT 1 /* acis grade for Vertical */ #define ACIS_GRADE_HORIZ 2 /* acis grade for Horizontal */ #define ACIS_GRADE_TRIPLE 3 /* acis grade for Triple */ #define ACIS_GRADE_QUAD 4 /* acis grade for Quad */ #define ACIS_GRADE_GEO 5 /* acis grade for Geo */ #define ACIS_GRADE_DIAG 6 /* acis grade for Diagonal */ #define ACIS_GRADE_DEFAULT 7 /* default acis grade */ #define ACIS_GRADE_ALL 8 /* acis grade for All */ /* the following defines are used by the coordinate transformation functions * in acis_process_events to represent the various coordinate systems. * * COORDINATE SYSTEMS */ #define ADET_NO_COORD "none" #define ADET_CHIP_COORD "chip" #define ADET_TDET_COORD "tdet" #define ADET_DET_COORD "det" #define ADET_TAN_COORD "tan" #define ADET_SKY_COORD "sky" #define ADET_INV_VAL -1 #define ADET_NONE_VAL 0 #define ADET_CHIP_VAL 1 #define ADET_TDET_VAL 2 #define ADET_DET_VAL 4 #define ADET_TAN_VAL 8 #define ADET_SKY_VAL 16 /* the following macros define the ranges of various arrays used in the * acis_process_events code. They are meant to assist in the readability of the code * If these values are changed to adjust structure sizes, the corresponding * code must be compensated as well. * * MISC. DEFINES */ #define TIME_INT_EPSILON 1 /* epsilon for tstart/tstop range */ #define ADET_NO_SCHEME 0 /* no grading scheme */ #define ADET_ACIS_SCHEME 1 /* acis grading scheme */ #define ADET_ASCA_SCHEME 2 /* asca grading scheme */ #define ADET_CENT_APPLY 0 /* apply centroid flag */ #define ADET_CENT_UNDO 1 /* undo already applied centroid */ #define BLANK_PARM " " /* 'empty' string to pass into pixlib */ #define X_AXIS_KEY "XS-INDXX" #define Y_AXIS_KEY "XS-INDXY" #define AC_SYSTEM "ACSYS" #define GRATINGS "GRATINGS" #define HETG_KEY "HETG" #define LETG_KEY "LETG" #define TOGA_KEY "TOGA" #define SYSTEM_STRING "system" #define WINSIZE_KEY "WINSIZE" #define WINSIZE_DEFAULT_VAL 0 #define CCD_KEY "CCD_ID" #define USE_CCD_COLUMN FALSE #define USE_CCD_KEYWORD TRUE #define NO_CHIP_ID_KEYWORD -1 #define CENTROID "CENTROID" #define USE_CENT "USED" #define DONT_CENT "NOT USED" #define ADET_NO_GRATING 0 /* no grating used */ #define ADET_LE_GRATING 1 /* LETG grating */ #define ADET_HE_GRATING 2 /* HETG grating */ #define ADET_TG_GRATING 3 /* TOGA grating */ /* the following defines are used by evthrcdet to perform staging corrections * on hsi data. * * STAGING MACROS */ #define STG_X_KEY "STF_X" /* keyword to identify x axis stage value */ #define STG_Y_KEY "STF_Y" /* keyword to identify y axis stage value */ #define STG_Z_KEY "STF_Z" /* keyword to identify z axis stage value */ #define STG_AIMPOINT_X 0 /* index of staging data x axis */ #define STG_AIMPOINT_Y 1 /* index of staging data y axis */ #define STG_AIMPOINT_Z 2 /* index of staging data z axis */ #define HPY_YAW_KEY "HRMA_YAW" /* keyword for HRMA pitch yaw */ #define HPY_PIT_KEY "HRMA_PIT" /* keyword for HRMA pitch yaw */ #define HPY_PIT 0 /* index of hpy pit data */ #define HPY_YAW 1 /* index of hpy yaw data */ #define STG_ANG1_KEY "STF_ANG1" /* keyword to identify fam az */ #define STG_ANG2_KEY "STF_ANG2" /* keyword to identify fam el */ #define STG_ANG3_KEY "STF_ANG3" /* keyword to identify fam roll */ #define STG_ANG1_NDX 0 /* index of fam az */ #define STG_ANG2_NDX 1 /* index of fam el */ #define STG_ANG3_NDX 2 /* index of fam roll */ #define FOA_X_KEY "FOAFP_X" /* keyword to identify foafp x */ #define FOA_Y_KEY "FOAFP_Y" /* keyword to identify foafp y */ #define FOA_Z_KEY "FOAFP_Z" /* keyword to identify foafp z */ #define LASSZ_KEY "SIM_Z" /* keyword to identify lass z position */ #define LASSZ_NDX 2 /* index of lassz position in coord set */ /* the following defines are used by acis_process_events to determine if any * errors have been encountered during processing of input 'stacks'/ * files. Errors have a specific bit assigned to them with the two * high end bits being used to classify errors as Major or minor. * Major errors will cause acis_process_events to terminate execution. Minor * errors are noted in the debug run log. * * |3|3|2|2|2|2|2|2|2|2|2|2|1|1|1|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0| * |1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0|9|8|7|6|5|4|3|2|1|0| * * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * 31 (M)ajor Error * 30 (m)inor Error * 15 input file - unable to successfully process any input files * 14 dither file - missing required columns or unable to open * 13 input file - different winsize values in same stack * 12 output file - error parsing output file event columns * 11 output file - dynamic memory allocation failed * 10 output file - file open failed * 09 input file - not all stack files consistent in centroiding * 08 input file - different grating values in same stack * 07 input file - data dependency not met for input file * 06 input file - error parsing input file event columns * 05 input file - dynamic memory allocation failed * 04 input file - file open failed * 03 input file - instrument file specified as a parameter DNE * 02 axes specified in parameter file do not exist in output file * 01 input stack contains no files or stacks * 00 input parameters are inconsistent or incorrect * * STACK IMPLEMENTATION ERROR MASKS */ typedef unsigned long ERR_MASK_T; #define ERR_MASK_NO_ERRS ((ERR_MASK_T) 0x00000000) #define ERR_MASK_INPARM ((ERR_MASK_T) 0x80000001) #define ERR_MASK_EMPTY_STACK ((ERR_MASK_T) 0x80000002) #define ERR_MASK_AXES_DNE ((ERR_MASK_T) 0x80000004) #define ERR_MASK_FILE_DNE ((ERR_MASK_T) 0x80000008) #define ERR_MASK_IN_OPEN ((ERR_MASK_T) 0x40000010) #define ERR_MASK_IN_ALLOC ((ERR_MASK_T) 0x40000020) #define ERR_MASK_IN_PARSE ((ERR_MASK_T) 0x40000040) #define ERR_MASK_DEP_NOT_MET ((ERR_MASK_T) 0x40000080) #define ERR_MASK_GRATING ((ERR_MASK_T) 0x80000100) #define ERR_MASK_CENTROID ((ERR_MASK_T) 0x80000200) #define ERR_MASK_OUT_OPEN ((ERR_MASK_T) 0x80000400) #define ERR_MASK_OUT_ALLOC ((ERR_MASK_T) 0x80000800) #define ERR_MASK_OUT_PARSE ((ERR_MASK_T) 0x80001000) #define ERR_MASK_WINSIZE ((ERR_MASK_T) 0x80002000) #define ERR_MASK_DITHER ((ERR_MASK_T) 0x80004000) #define ERR_MASK_ALL_BAD ((ERR_MASK_T) 0x80008000) #define ERR_MASK_MINOR ((ERR_MASK_T) 0x40000000) #define ERR_MASK_MAJOR ((ERR_MASK_T) 0x80000000) /* the following defines represent error status/ warning strings that will * be written out to pipeline control in the event that an error condition * or warning condition is detected. Currently these messages key off of the * error masks listed above (STACK IMPLEMENTATION ERROR MASKS). The routine * log_error_status calls the routine err_msg to log the error or warning to * stderr. * * PIPELINE ERROR/WARNING MESSAGES */ #define ADET_PARM_ERR "Invalid input parameters. Acis_process_events not executed" #define ADET_EMPTY_STACK_ERR "No files in the stack. Acis_process_events not executed" #define ADET_AXES_ERR "Invalid axes specified. Acis_process_events not executed" #define ADET_OPEN_ERR "Unable to open output file. Acis_process_events not executed" #define ADET_ALLOC_ERR "Unable to allocate dynamic memory. Acis_process_events not executed" #define ADET_PARSE_ERR "Unable to parse output event columns. Acis_process_events not executed" #define ADET_GRATING_ERR "All files must be of the same grating type. Acis_process_events not executed" #define ADET_WINSIZE_ERR "All files must be of the same winsize type. Acis_process_events not executed" #define ADET_CENTROID_ERR "All files must be consistent in centroiding. Acis_process_events not executed" #define ADET_FILE_DNE_ERR "Can't find parameter file '%s'. Acis_process_events not executed" #define ADET_TSTART_ERR "Event file start times must be in chronological order. Evthrcdet not executed" #define ADET_TSTOP_ERR "Event file end times must be later than the start times. Evthrcdet not executed" #define ADET_ALL_BAD_ERR "Unable to successfully process any input files. Output file is empty or incomplete." #define ADET_DITHER_ERR "Could not open specified dither file or the file did not contain all necessary columns. Acis_process_events not executed." #define ADET_DEPEND_WARN "Data dependencies for %s not met. Discarding events." #define ADET_OPEN_WARN "Unable to open file %s. Discarding events." #define ADET_ALLOC_WARN "Unable to allocate dynamic memory for %s. Discarding events." #define ADET_PARSE_WARN "Unable to parse column data from %s. Discarding events." #define ADET_STAGE_WARN "Staging data does not exist for data file %s. Using {0,0,0} as default values." #define ADET_HPY_WARN "Default hpy data does not exist for data file %s. Using {0,0} as default values." #define ADET_STG_ANG_WARN "Default staging angle data does not exist for data file %s. Using {0, 0, 0} as default values." #define ADET_FAOFP_WARN "foafp_x, foafp_y, or foafp_z data does not exist for the input file %s. Not performing 'winsize' corrections." #define ADET_LASSZ_WARN "Default lassz value not found in %s header. Not setting the default aimpoint." /* the following defines are used as bit masks to determine if all data * dependencies have been met for the various options selected to be performed * on the input events. The mask variable itself is an unsigned short. * * |15 14 13 12 11 10 9 8| 7 6 5 4 3 2 1 0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * | | | | | | | | | | | | | | | | | * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * \_ all dep \ \ \ \_ evtgrade \ \ \ \ \_ 9 phas * \ \ \___ grade \ \ \ \___ flt grade * \ \_____ transform \ \ \_____ ccd col * \_______ centroid \ \_______ x col * \_________ y col * DATA DEPENDENCY MASK */ #define ADET_MASK_INIT ((unsigned short) 0x00) /* no dependencies met */ #define ADET_MASK_PHAS ((unsigned short) 0x0001) /* 9 phas exist */ #define ADET_MASK_FLTGRD ((unsigned short) 0x0002) /* flt grade exists */ #define ADET_MASK_CCD ((unsigned short) 0x0004) /* ccd col exists */ #define ADET_MASK_XPOS ((unsigned short) 0x0008) /* x column exists */ #define ADET_MASK_YPOS ((unsigned short) 0x0010) /* y column exists */ #define ADET_MASK_UNUSED1 ((unsigned short) 0x0020) /* unused */ #define ADET_MASK_UNUSED2 ((unsigned short) 0x0040) /* unused */ #define ADET_MASK_UNUSED3 ((unsigned short) 0x0080) /* unused */ #define ADET_MASK_EVTGRD ((unsigned short) 0x0100) /* evtgrade deps met */ #define ADET_MASK_GRADE ((unsigned short) 0x0200) /* grading deps met */ #define ADET_MASK_TRANS ((unsigned short) 0x0400) /* coord transform deps */ #define ADET_MASK_CENT ((unsigned short) 0x0800) /* centroid deps met */ #define ADET_MASK_UNUSED4 ((unsigned short) 0x1000) /* unused */ #define ADET_MASK_UNUSED5 ((unsigned short) 0x2000) /* unused */ #define ADET_MASK_UNUSED6 ((unsigned short) 0x4000) /* unused */ #define ADET_MASK_ALLDEP ((unsigned short) 0x8000) /* all dependencies met */ #define ADET_MASK_GOOD ((unsigned short) 0x8000) #define ADET_MASK_BAD ((unsigned short) 0x7fff) #define ADET_MASK_DOTRANS ((unsigned short) 0x001c) /* x col, y col, ccd */ #define ADET_MASK_DOCENT ((unsigned short) 0x001d) /* x&y cols, ccd, phas*/ #define ADET_MASK_DOEVTGRD ((unsigned short) 0x0001) /* phas */ #define ADET_MASK_DOGRD ((unsigned short) 0x0001) /* */ #define ADET_MASK_DOGRD_ALT ((unsigned short) 0x0002) /* */ /* the following structure is used to hold the input parameters which are * used by acis_process_events for various processing information. The values contained * in the structure are loaded in from the acis_process_events parameter file. * * INPUT PARAMETERS STRUCTURE */ typedef struct input_parms_t { double start_time; /* default time field */ double end_time; /* end time for header */ double cy0; /* chip pos of predicted beam location (acis2c) */ double time_offset; /* time offset to synch to fam data times */ VEC1_DBLE fp_scale; /* fp scale in arc seconds */ VEC1_DBLE tdet_scale; /* tdet scale in arc seconds */ double antialias_scale; /* scale used in determinining anti-aliasing */ /* range of randomization */ int debug; /* level of debug information to log */ int bkt_size; /* bucket size */ int page_size; /* size of a page */ short scheme; /* grading scheme- ASCA, ACIS, NONE */ short threshold; /* split threshold level */ boolean found_foa; /* foafp_x, foafpy, and foafp_z keywords read */ boolean doevtgrade; /* event grading enabled */ short x_col; /* column being used as x for det calcs */ short y_col; /* column being used as y for det calcs */ short header_ccd; /* column used as ccd id for det calcs */ short grating; /* grating type */ short start; /* start of coordinate transformations */ short stop; /* end of coordinate transformations */ short fpsys; /* focal plane coordinate system */ short tdetsys; /* tiled detector coordinate system */ short event_size; /* number of pha cols expected per input event */ short winsize; /* winsize for fast window chip -> real chip */ short supported_mode; /* repesentation of input file read and datamode*/ short datatype; /* specifies flight,sac, or acis-2c */ boolean input_centroid; /* input data has been centroided (T=yes) */ boolean output_centroid; /* output data is to be centroided (T=yes) */ boolean ccd_choice; /* flag to tell which ccd val to use */ boolean random; /* T = allow randomization in float conversion */ char* acis_sys; /* pointer to string of acis system used */ char* instrume; /* pointer to instrument string */ } INPUT_PARMS_T, *INPUT_PARMS_P_T; /* the following structure is used by acis_process_events to keep track of processing * statistics. This values are output so that the user can determine the * extent of accuracy in processing. * * STATISTICS STRUCTURE */ typedef struct statistics_t { long total_events_in; long total_events_out; long num_files_in; long num_bad_files; long parity_error_cnt; unsigned short dependencies; /* dependency mask */ short error_flag; char* err_info_p; /* ptr to string of error info used by log_err_stats */ } STATISTICS_T, *STATISTICS_P_T; /* This is just the Function prototype of the acis_process_events tool */ extern int acis_process_events(void); extern void sum_grade_event(EVENT_REC_P_T, INPUT_PARMS_P_T); extern short find_acis_grade(short, short); extern short find_asca_grade(short, short); extern void calculate_centroid(EVENT_REC_P_T, INPUT_PARMS_P_T, short, double, double, double*, double*); extern void process_grades_acis(EVENT*, EVENT_REC_P_T, INPUT_PARMS_P_T, STATISTICS_P_T); extern boolean verify_scheme_request(INPUT_PARMS_P_T, char*, STATISTICS_P_T); extern void calculate_coords_acis(EVENT*, EVENT_REC_P_T, INPUT_PARMS_P_T, STATISTICS_P_T); extern void calc_chip_coords(EVENT_REC_P_T, INPUT_PARMS_P_T, STATISTICS_P_T); extern void calc_det_coords(EVENT_REC_P_T, INPUT_PARMS_P_T); extern void calc_tan_coords(EVENT_REC_P_T, INPUT_PARMS_P_T); extern void calc_sky_coords(EVENT_REC_P_T, INPUT_PARMS_P_T); extern short parse_coord_range(char*); extern boolean map_start_column(short, short*, short*); extern unsigned short dependency_check_acis(short*, INPUT_PARMS_P_T, int); extern void log_error_stats(FILE*, INPUT_PARMS_P_T, STATISTICS_P_T, ERR_MASK_T); extern int log_warning_stats(FILE*, EVENT*, INPUT_PARMS_P_T, ERR_MASK_T, char*); extern boolean make_wcs_updates(EVENT*, EVENT_REC_P_T, INPUT_PARMS_P_T); extern short set_grating_type(EVENT*); extern ERR_MASK_T setup_output_axes (EVENT*, char**, EVENT*, char**, INPUT_PARMS_P_T, short, short*); extern void set_up_mirror(EVENT*, char*, DITHER_REC_P_T); /* routine to get position value for fast window chip -> chip cord call */ extern void get_predicted_beam_position(EVENT*, INPUT_PARMS_P_T); #endif /* last line of header file- closes #ifndef ACIS_PROCESS_EVENTS_H */