#define RESET "\033[0m" #define BLACK "\033[30m" /* Black */ #define RED "\033[31m" /* Red */ #define GREEN "\033[32m" /* Green */ #define YELLOW "\033[33m" /* Yellow */ #define BLUE "\033[34m" /* Blue */ #define MAGENTA "\033[35m" /* Magenta */ #define CYAN "\033[36m" /* Cyan */ #define WHITE "\033[37m" /* White */ #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ #define BOLDRED "\033[1m\033[31m" /* Bold Red */ #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ #ifndef UINT16 #define UINT16 unsigned short #endif #define ROCLEN 80 /* length of ROC_name */ #define STRLEN 250 /* length of str_tmp */ #define NBD_FADC250 22 #define MAX_FADC250_CH 16 #define NBD_FADC125 22 #define MAX_FADC125_CH 72 #define NBD_DSC2 22 #define MAX_DSC2_CH 16 #define NBD_TDC1290 22 char roc_name[ROCLEN]; char filename[STRLEN]; typedef enum { fcal = 10, bcal = 20, cdc = 30, fdc = 40, tof = 50, trigger = 100, det_unknown = -1 } det_type; typedef enum { fadc250 = 5, f1tdc = 6, dsc2 = 10, fadc125 = 15, tdc1290 = 20, tss = 30, bd_unknown = -1 } bd_type; typedef struct { int group; int f_rev; int b_rev; int b_ID; char SerNum[80]; char crate[80]; char conf_common_dir[STRLEN]; char conf_common_ver[STRLEN]; char conf_user_dir[STRLEN]; char conf_user_ver[STRLEN]; int mode; unsigned int winOffset; unsigned int winWidth; unsigned int nsb; unsigned int nsa; unsigned int npeak; unsigned int chDisMask; unsigned int trigMask; unsigned int dac[MAX_FADC250_CH]; unsigned int read_thr[MAX_FADC250_CH]; unsigned int trig_bl[MAX_FADC250_CH]; unsigned int trig_thr; unsigned int trig_nsb; unsigned int trig_nsa; } FADC250_CONF; typedef struct { int group; int f_rev; int b_rev; int p_rev; int b_ID; char SerNum[80]; char crate[80]; char conf_common_dir[STRLEN]; char conf_common_ver[STRLEN]; char conf_user_dir[STRLEN]; char conf_user_ver[STRLEN]; int mode; unsigned int winOffset; unsigned int winWidth; unsigned int nsb; unsigned int nsa; unsigned int npeak; unsigned int mask[4]; unsigned int dac[MAX_FADC125_CH]; unsigned int read_thr[MAX_FADC125_CH]; } FADC125_CONF; typedef struct { int group; int f_rev; int b_ID; char SerNum[12]; UINT16 TDCChMask; UINT16 TRGChMask; UINT16 TDCORMask; UINT16 TRGORMask; int TDCWidth; int TRGWidth; int TDCThreshold[MAX_DSC2_CH]; int TRGThreshold[MAX_DSC2_CH]; int TRGDigitalWidth[MAX_DSC2_CH]; int TRGDigitalDelay[MAX_DSC2_CH]; } DSC2_CONF; typedef struct { int group; int f_rev; char SerNum[80]; int window_width; int window_offset; int window_extra; int window_reject; int n_Hits; int almostFullLevel; int outProgControl; int blt_Events; int cblt_not; int a24_a32; int sngl_blt_mblt; int berr_fifo; int sst_rate; int edge; unsigned int mask; } TDC1290_CONF; /** TI configuration parameters **/ typedef struct { unsigned int slot; unsigned int ver; /* version */ unsigned int rev; /* revision */ unsigned int crate_id; /* crate_id: 1-15 */ unsigned int trig_src; /* trigger source: 0-5 */ unsigned int holdoff_rule; /* trigger holdoff rule: 1-5 */ unsigned int holdoff_interval; /* trigger holdoff time interval (in time_step): 1-63 */ unsigned int holdoff_step; /* trigger holdoff time step: 0 = 16ns, 1 = 500ns */ unsigned int sync_src; /* sync source: 0-4 */ unsigned int sync_delay; /* sync delay: 1-127 */ unsigned int sync_width; /* sync width: 1-127 */ unsigned int sync_units; /* sync units: 0 = 4ns, 1 = 32ns */ unsigned int fiber_delay; /* fiber delay */ unsigned int fiber_latency; /* fiber offset */ unsigned int busy_src; /* busy source mask: bitmask: bits: 16-0 */ unsigned int busy_flag; /* busy source flag: 0-1 */ unsigned int block_level; /* block level: 1-15 */ unsigned int event_format; /* event format: 0-3 */ unsigned int block_bflevel; /* block buffer level: 0-65535 */ unsigned int out_port_mask; /* output port mask: bits: 3-0 (p4,p3,p2,p1) */ unsigned int clk_src; /* clock source: 0 = internal, 1 = external */ unsigned int ti_master; /* Stand alone runs with master TI - 1, 0 - TS is used */ unsigned int ti_master_trig; /* TI master trigger type: 1 - pulser; 2 - internal */ unsigned int ti_fp_inputs; /* select trigger source input: bitmask: bit5 bit4 bit3 bit2 bit1 bit0 (inp6, inp5, inp4, inp3, inp2, inp1) */ unsigned int ti_fiber_en; /* optical fiber ports enabled on master TI: port1 - port8 */ unsigned int ti_soft_trig[4]; /* enable software trigger: [0] - trigger type 1 or 2 (playback) [1] - number of events to trigger [2] - period multiplier, depends on range (0-0x7FFF) [3] - small (0) or large (1) small: minimum of 120ns, increments of 30ns up to 983.13us large: minimum of 120ns, increments of 30.72us up to 1.007s */ } board_ti; typedef struct { unsigned int slot; unsigned int ver; /* version */ unsigned int rev; /* revision */ unsigned int crate_id; /* crate_id: 1-15 */ unsigned int ts_master_trig; /* TS master trigger type: 1 - pulser; 2 - internal */ unsigned int ts_fp_inputs; /* TS front pannel inputs: input B1 - bit 0 */ unsigned int ts_td_slots; /* slots for TD boards in the crate: slot3 - slot20 */ unsigned int ts_soft_trig[4]; /* enable software trigger: [0] - trigger type 1 or 2 (playback) [1] - number of events to trigger [2] - period multiplier, depends on range (0-0x7FFF) [3] - small (0) or large (1) small: minimum of 120ns, increments of 30ns up to 983.13us large: minimum of 120ns, increments of 30.72us up to 1.007s */ unsigned int blocklevel; /* block level */ unsigned int bufferlevel; /* buffer level */ } board_ts; FADC250_CONF fa250[NBD_FADC250]; FADC125_CONF fa125[NBD_FADC125]; DSC2_CONF dsc[NBD_DSC2]; TDC1290_CONF caen1290[NBD_TDC1290]; board_ti ti_bd; board_ts ts_bd; det_type get_det_type(char *crate ); bd_type get_board_type(char *crate ); char *get_board_type_name(char* crate); int read_conf_global(char *filename, char *crate); int read_conf_common(char *crate); int read_conf_user(char *crate); void print_fadc250_conf(int slot); int get_nbd_fadc250(); FADC250_CONF get_conf_fadc250(int slot); FADC125_CONF get_conf_fadc125(int slot); int get_nbd_fadc125(); void print_fadc125_conf(int slot); void print_le_conf(); void print_caen1290_conf(); void print_ti_conf(); void print_ts_conf(); #define SCAN_MSK \ args = sscanf (str_tmp, "%*s %d %d %d %d %d %d %d %d \ %d %d %d %d %d %d %d %d", \ &msk[ 0], &msk[ 1], &msk[ 2], &msk[ 3], \ &msk[ 4], &msk[ 5], &msk[ 6], &msk[ 7], \ &msk[ 8], &msk[ 9], &msk[10], &msk[11], \ &msk[12], &msk[13], &msk[14], &msk[15]) #define SCAN_MSK1 \ args = sscanf (str_tmp, "%*s %d %d %d %d %d %d %d %d \ %d %d %d %d %d %d %d %d %d %d", \ &msk1[ 0], &msk1[ 1], &msk1[ 2], &msk1[ 3], \ &msk1[ 4], &msk1[ 5], &msk1[ 6], &msk1[ 7], \ &msk1[ 8], &msk1[ 9], &msk1[10], &msk1[11], \ &msk1[12], &msk1[13], &msk1[14], &msk1[15], &msk1[16], &msk1[17] ) #define GET_READ_MSK \ SCAN_MSK; \ ui1 = 0; \ for(jj = 0; jj < MAX_FADC250_CH; jj++) \ { \ if((msk[jj] < 0) || (msk[jj] > 1)) \ { \ printf("\nReadConfigFile: Wrong mask bit value, %d\n\n",msk[jj]); return(-6); \ } \ if(strcmp(keyword,"FADC250_ADC_MASK") == 0) msk[jj] = ~(msk[jj])&0x1; \ ui1 |= (msk[jj]< 20){ \ printf(BOLDRED "\nRead_conf: Wrong slot number %d, %s\n" RESET, slot,str_tmp); \ return(-2); \ } \ (BSTRUCT) = 1; \ } \ } else { \ printf(BOLDRED "\n Read_conf: Wrong number of slots in FADC_SLOTS %d. Only one slot is allowed. Exit \n" RESET, args); \ return(-2); \ } \ } #define SCAN_B_SETS(BKEYWORD,BSTRUCT) \ if(strcmp(keyword,(BKEYWORD)) == 0) \ { \ sscanf (str_tmp, "%*s %d", &val); \ for(jj = 3; jj < NBD_FADC250; jj++) (BSTRUCT) = val; \ } #define SCAN_B_XSETS(BKEYWORD,BSTRUCT) \ if(strcmp(keyword,(BKEYWORD)) == 0) \ { \ sscanf (str_tmp, "%*s %x", &val); \ for (jj = 3; jj < NBD_FADC250; jj++) (BSTRUCT) = val; \ } #define SCAN_B_SSETS(BKEYWORD,BSTRUCT) \ if(strcmp(keyword,(BKEYWORD)) == 0) \ { \ args = sscanf (str_tmp, "%*s %s", &str_val[0]); \ if(args == 1) \ { \ for(jj = 3; jj < NBD_FADC250; jj++) sprintf( (char *) (BSTRUCT), "%s", str_val); \ } else printf(" Warning: no values set to either FADC250_COMMON or FADC250_USER \n"); \ } #define SCAN_TDP(TDP_K, TDP_S) \ if(strcmp(keyword,(TDP_K)) == 0) \ { \ sscanf (str_tmp, "%*s %d", &val); \ for(jj = 3; jj < NBD_FADC250; jj++) \ for(ii=0; ii < MAX_FADC250_CH; ii++) (TDP_S)[ii] = val; \ } #define SCAN_TDP_125(TDP_K,TDP_S) \ if(strcmp(keyword,(TDP_K)) == 0) \ { \ sscanf (str_tmp, "%*s %d", &val); \ for(jj = 3; jj < NBD_FADC125; jj++) \ for(ii=0; ii < MAX_FADC125_CH; ii++) (TDP_S)[ii] = val; \ } #define SCAN_TDP_ALLCH(TDP3_K,TDP3_S) \ if(strcmp(keyword,(TDP3_K)) == 0) \ { \ SCAN_MSK; \ if(args != 16) \ { \ printf("\nReadConfigFile: Wrong argument's number %d, should be 16\n\n",args); \ return(-8); \ } \ for(jj = 3; jj < NBD_FADC250; jj++) \ for(ii = 0; ii < MAX_FADC250_CH; ii++) (TDP3_S)[ii] = msk[ii]; \ } #define SCAN_B_MSKS(BKEYWORD,BSTRUCT) \ if(strcmp(keyword,(BKEYWORD)) == 0) \ { \ GET_READ_MSK; \ (BSTRUCT) = ui1; \ } #define SCAN_FA125_DAC_THR(BKEYWORD,BSTRUCT) \ if(strncmp(keyword,(BKEYWORD),15) == 0){ \ SCAN_MSK1; \ for(jj = 0; jj < 18; jj++){ \ if((msk1[jj] < 0) || (msk1[jj] > 8000)){ /* SP: threshold limits should be verified later */ \ printf(BOLDRED "\n FATAL: Read FADC125 DAC or THR: Wrong value, %d, jj = %d\n\n" RESET, msk1[jj],jj); \ return(-2); \ } \ } \ str2[0] = keyword[15]; \ str2[1] = keyword[16]; \ str2[2] = '\0'; \ first = atoi(str2); \ last = first + 18; \ if(first < 0 || last > 72){ \ printf(BOLDRED "\n FATAL: Read FADC125 DAC or THR: Wrong channel range: first = %d last = %d. Line = %d \n" RESET,first, last, line); return(-2); \ } \ for(jj = first; jj < last; jj++) \ (BSTRUCT)[jj] = msk1[jj - first ]; \ } #define SCAN_SOFT_TRIG(BKEYWORD,TI_SOFT) \ if(strcmp(keyword,(BKEYWORD)) == 0){ \ sscanf (str_tmp, "%*s %d %d %x %d", &soft_trig[0], &soft_trig[1], &soft_trig[2], &soft_trig[3]); \ for(jj=0; jj < 4; jj++)(TI_SOFT)[jj] = soft_trig[jj]; \ } #define SCAN_TI_FIBER(BKEYWORD,TI_FIBER) \ if(strcmp(keyword,(BKEYWORD)) == 0){ \ args = sscanf (str_tmp, "%*s %d %d %d %d %d %d %d %d", &ti_fiber[0], &ti_fiber[1], &ti_fiber[2], &ti_fiber[3], \ &ti_fiber[4], &ti_fiber[5], &ti_fiber[6], &ti_fiber[7]); \ if(args > 7){ \ printf(" TI_FIBER too many ports: EXIT %d \n",args); \ return(-7); \ } \ for(jj=0; jj < args; jj++){ \ if(ti_fiber[jj] > 0 && ti_fiber[jj] < 9){ \ (TI_FIBER) = (TI_FIBER) | (1 << (ti_fiber[jj]-1)); \ } else { \ printf(" TI_FIBER out of range %d \n",ti_fiber[jj]); \ return(-2); \ } \ } \ } #define SCAN_TD_SLOTS(BKEYWORD,TD_SLOTS) \ if(strcmp(keyword,(BKEYWORD)) == 0){ \ SCAN_MSK; \ if(args > 16){ \ printf(" TS_TD_SLOTS too many slots: EXIT %d \n",args); \ return(-2); \ } \ for(jj=0; jj < args; jj++){ \ if( (msk[jj] > 2 && msk[jj] < 21) && (msk[jj] != 11) && (msk[jj] != 12)) { \ (TD_SLOTS) = (TD_SLOTS) | (1 << msk[jj]); \ } else { \ printf(BOLDRED "TS_TD_SLOTS out of range %d \n" RESET, msk[jj]); \ return(-2); \ } \ } \ } #define SCAN_FP_INPUTS(BKEYWORD,FP_INPUTS) \ if(strcmp(keyword,(BKEYWORD)) == 0){ \ SCAN_MSK; \ if(args > 16){ \ printf(" TS_FP_INPUTS too many inputs: EXIT %d \n",args); \ return(-2); \ } \ for(jj=0; jj < args; jj++){ \ if( (msk[jj] > 0 && msk[jj] < 32) ) { \ (FP_INPUTS) = (FP_INPUTS) | (1 << (msk[jj]-1)); \ } else { \ printf(BOLDRED "TS_FP_INPUT out of range %d \n" RESET, msk[jj]); \ return(-2); \ } \ } \ }