/* */ /* File Name : cfg.c for beamtest */ /* Creation Date : Nov 13 2000 */ /* Author : Y.Nakaune */ /* Update History */ /* Nov 15 H.Kuashige : modify for cosmetics */ #include #include #include #include "buf.h" #define ADC_TGC_CFG 1 #define TMC_TGC_CFG 2 #define TMC_DC_CFG 3 #define ADC_SCI_CFG 4 #define TMC_SCI_CFG 5 /*----------------------------------------------------- Adc_Sci ---------------------------------------------------*/ static void Adc_Sci( Cfg_adc *cfg, char *ptr ) { unsigned int mod, adch, ctnb; if ( sscanf( ptr, "%u %u %u \n", &mod, &adch, &ctnb ) != 3 ) { perror( "CFG_ADC_SCI: find wrong format" ); return; } #ifdef F_DEBUG if ( Debug == 1 ) fprintf(stderr,"CFG_ADC_SCI: mod=%2d adch=%3d counter_number=%3d\n", mod, adch, ctnb ); #endif if ( mod > ADC_MOD || mod < 1 || adch > ADC_CH || ctnb > SCI_NUMBER ) { perror( "CFG_ADC_SCI: wrong configuration" ); return; } cfg->sci_nb[mod][adch] = (int)ctnb; /* array_NAF */ array_naf[number_naf_entry] = ( ( mod << 9 ) | ( adch << 5 ) ); number_naf_entry++; } /*----------------------------------------------------- Tmc_Sci ---------------------------------------------------*/ static void Tmc_Sci( Cfg_tmc *cfg, char *ptr ) { unsigned int mod, tmch, ctnb; if ( sscanf( ptr, "%u %u %u \n", &mod, &tmch, &ctnb ) != 3 ) { perror( "CFG_TMC_SCI: find wrong format" ); return; } #ifdef F_DEBUG if ( Debug == 1 ) fprintf(stderr,"CFG_TMC_SCI: mod=%2d tmch=%3d counter_number=%3d\n", mod, tmch, ctnb ); #endif if ( mod >= TMC_MOD || tmch > TMC_CH || ctnb > SCI_NUMBER ) { perror( "CFG_TMC_SCI: wrong configuration" ); return; } cfg->sci_nb[mod][tmch] = (int)ctnb; } /*----------------------------------------------------- Tmc_Dc Assign each TMC channel to DC channel ---------------------------------------------------*/ static void Tmc_Dc( Cfg_tmc *cfg, char *ptr ) { unsigned int mod, tmch, chmbnb, xy; if ( sscanf( ptr, "%u %u %u %u \n", &mod, &tmch, &chmbnb, &xy ) != 4 ) { perror( "CFG_TMC_DC: find wrong format "); return; } #ifdef F_DEBUG if ( Debug == 1 ) { fprintf(stderr, "CFG_TMC_DC:mod=%2d tmch=%3d chamber_number=%3d xy=%3d \n", mod, tmch, chmbnb, xy ); } #endif if ( mod >= TMC_MOD || tmch > TMC_CH || chmbnb > DC_NUMBER || xy > DC_XY ){ perror( "CFG_TMC_DC: wrong configuration" ); return; } cfg->dc_nb[mod][tmch] = (int)chmbnb; cfg->dc_xy[mod][tmch] = (int)xy; } /*----------------------------------------------------- Adc_Tgc Assign each ADC channel to TGC channel ------------------------------------------------------*/ static void Adc_Tgc( Cfg_adc *cfg, char *ptr ) { unsigned int mod, adch, lay, ws, tgch; if ( sscanf( ptr, "%u %u %u %u %u \n", &mod, &adch, &lay, &ws, &tgch ) != 5 ) { perror( "CFG_ADC_TGC : find wrong format" ); return; } #ifdef F_DEBUG if( Debug == 1 ) { fprintf( stderr, "CFG_ADC_TGC : mod=%2d adch=%3d lay=%3d ws=%3d tgch=%3d\n", mod, adch, lay, ws, tgch ); } #endif if( mod > ADC_MOD || mod < 1 || adch > ADC_CH || lay > TGC_LAYER || ws > W_S || tgch > TGC_CH ) { perror( "CFG_ADC_TGC : wrong configuration" ); return; } cfg->tgc_lay[mod][adch] = (int)lay; cfg->tgc_ws[mod][adch] = (int)ws; cfg->tgc_ch[mod][adch] = (int)tgch; /* arrey_NAF */ array_naf[number_naf_entry] = ( ( mod << 9 ) | ( adch << 5 ) ); number_naf_entry++; } /*----------------------------------------------------- Tmc_Tgc Assign each TMC channel to TGC channel ---------------------------------------------------*/ static void Tmc_Tgc( Cfg_tmc *cfg, char *ptr ) { unsigned int mod, tmch, lay, ws, tgch; if ( sscanf( ptr, "%u %u %u %u %u \n", &mod, &tmch, &lay, &ws, &tgch ) != 5 ) { perror( "CFG_TMC_TGC : find wrong format" ); return; } #ifdef F_DEBUG if( Debug == 1 ) { fprintf( stderr, "CFG_TMC_TGC : mod=%2d tmch=%3d lay=%3d ws=%3d tgch=%3d\n", mod, tmch, lay, ws, tgch ); } #endif if( mod >= TMC_MOD || tmch > TMC_CH || lay > TGC_LAYER || ws > W_S || tgch > TGC_CH ) { perror( "CFG_TMC_TGC : wrong configuration" ); return; } cfg->tgc_lay[mod][tmch] = (int)lay; cfg->tgc_ws[mod][tmch] = (int)ws; cfg->tgc_ch[mod][tmch] = (int)tgch; } /*----------------------------------------------------- write_cfg ---------------------------------------------------*/ void write_cfg( Cfg_adc *adc, Cfg_tmc *tmc, FILE *fp ) { int cfgdatasize; cfgdatasize = sizeof(Cfg_adc) + sizeof(Cfg_tmc); WriteFLG( CFG_FLG, fp ); fwrite( &cfgdatasize, sizeof(int), 1, fp ); fwrite( adc, sizeof(Cfg_adc), 1, fp ); fwrite( tmc, sizeof(Cfg_tmc), 1, fp ); WriteFLG( CFG_END_FLG, fp ); } /*----------------------------------------------------- ReadCFG Read CFG file to write to STDOUT ---------------------------------------------------*/ void ReadCFG( Cfg_adc *cfg_adc, Cfg_tmc *cfg_tmc, char *file, FILE *fp ) { int id = 0; char buff[ BUFF_LENGTH ]; FILE *fp_cfg; memset( cfg_adc, -1, sizeof(Cfg_adc) ); memset( cfg_tmc, -1, sizeof(Cfg_tmc) ); if ( ( fp_cfg = fopen( file, "r" ) ) == NULL ) { fprintf( stderr, "File ( %s ) Not Found !\n", file ); exit(1); } while ( fgets( buff, BUFF_LENGTH, fp_cfg ) != NULL ) { if ( buff[0] == '#' || buff[0] == '\n' ) continue; else if ( strncmp( buff, "TMC_SCI", 7 ) == 0 ) id = TMC_SCI_CFG; else if ( strncmp( buff, "ADC_SCI", 7 ) == 0 ) id = ADC_SCI_CFG; else if ( strncmp( buff, "TMC_DC", 6 ) == 0 ) id = TMC_DC_CFG; else if ( strncmp( buff, "TMC_TGC", 7 ) == 0 ) id = TMC_TGC_CFG; else if ( strncmp( buff, "ADC_TGC", 7 ) == 0 ) id = ADC_TGC_CFG; else switch ( id ) { case TMC_SCI_CFG: Tmc_Sci( cfg_tmc, buff ); break; case ADC_SCI_CFG: Adc_Sci( cfg_adc, buff ); break; case TMC_DC_CFG: Tmc_Dc( cfg_tmc, buff ); break; case TMC_TGC_CFG: Tmc_Tgc( cfg_tmc, buff ); break; case ADC_TGC_CFG: Adc_Tgc( cfg_adc, buff ); break; } } fclose( fp_cfg ); write_cfg( cfg_adc, cfg_tmc, fp ); fflush( fp ); } /*----------EOF-------------------------------------*/