/* * read_daq_cfg.c for K4 * Creation Date : Nov 14 2000 * Author : Y.Nakaune */ #include #include #include #include "convert.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 ---------------------------------------------------*/ void adc_sci( 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 ch=%3d counter_number=%3d\n", mod, adch, ctnb ); #endif if ( mod > ADC_MOD || adch > ADC_CH || ctnb > SCI_NUMBER ) { perror( "CFG_ADC_SCI: wrong configuration" ); return; } adc_sci_cfg[mod][adch].ctnb = (int)ctnb; } /*----------------------------------------------------- tmc_sci ---------------------------------------------------*/ void tmc_sci( 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 ch=%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; } tmc_sci_cfg[mod][tmch].ctnb = (int)ctnb; } /*----------------------------------------------------- tmc_dc Assign each TMC channel to DC channel ---------------------------------------------------*/ void tmc_dc( 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; } tmc_dc_cfg[mod][tmch].chmbnb = (int)chmbnb; tmc_dc_cfg[mod][tmch].xy = (int)xy; } /*----------------------------------------------------- adc_tgc Assign each ADC channel to TGC channel ------------------------------------------------------*/ void adc_tgc( 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 || adch > ADC_CH || lay > TGC_LAYER || ws > W_S || tgch > TGC_CH ) { perror( "CFG_ADC_TGC : wrong configuration" ); return; } adc_tgc_cfg[mod][adch].lay = (int)lay; adc_tgc_cfg[mod][adch].ws = (int)ws; adc_tgc_cfg[mod][adch].tgch = (int)tgch; } /*----------------------------------------------------- tmc_tgc Assign each TMC channel to TGC channel ---------------------------------------------------*/ void tmc_tgc( 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; } tmc_tgc_cfg[mod][tmch].lay = (int)lay; tmc_tgc_cfg[mod][tmch].ws = (int)ws; tmc_tgc_cfg[mod][tmch].tgch = (int)tgch; } /*----------------------------------------------------- raed_daq_cfg Read CFG file to write to STDOUT ---------------------------------------------------*/ void read_daq_cfg( FILE *fp ) { int id = 0, mod, ch; char buff[ BUF_SIZE ]; /*----------clear cfg_adc and cfg_tmc----------*/ for ( mod=0; mod < TMC_MOD; mod++ ) { for ( ch=0; ch < TMC_CH; ch++ ) { tmc_sci_cfg[mod][ch].ctnb = -1; tmc_dc_cfg[mod][ch].chmbnb = -1; tmc_tgc_cfg[mod][ch].lay = -1; } } for ( mod=0; mod < ADC_MOD; mod++ ) { for ( ch=0; ch < ADC_CH; ch++ ) { adc_sci_cfg[mod][ch].ctnb = -1; adc_tgc_cfg[mod][ch].lay = -1; } } while ( fgets( buff, BUF_SIZE, fp ) != 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( buff ); break; case ADC_SCI_CFG : adc_sci( buff ); break; case TMC_DC_CFG : tmc_dc( buff ); break; case TMC_TGC_CFG : tmc_tgc( buff ); break; case ADC_TGC_CFG : adc_tgc( buff ); break; default : break; } } } } /*----------EOF-------------------------------------*/