/* * daq_rd.c * Creation date : Aug 4 1998 * Author : K. Hayashi */ #include #include #include #include "daq.h" /*----------------------------------------------------------------------------- read_adc Read ADC data ----------------------------------------------------------------------------*/ #if ( defined ADC_TGC || defined ADC_DT ) int read_adc( Recnst *rc, Cfg_adc *cfg, FILE *fp ) { int i, j; int data_size; int w_s, lay, ch, x_y, u_d; long offset; Daq_adc adc; /* Read ADC data from DAQ */ if( fread( &data_size, 1, sizeof(int), fp ) != sizeof(int) ){ perror( "read_adc: data_size" ); return -1; } else if( data_size != sizeof(Daq_adc) ){ perror( "read_adc: wrong data_size" ); return -1; } if( fread( &adc, 1, data_size, fp ) != (size_t)data_size ){ perror( "read_adc: adc data" ); return -1; } /* Reconstruction ADC data */ for( i = 0; i < ADC_MOD; i++ ){ for( j = 0; j < ADC_CH; j++ ){ #ifdef ADC_TGC w_s = cfg->w_s[i][j]; lay = cfg->tlay[i][j]; ch = cfg->tgch[i][j]; if( w_s > -1 && lay > -1 && ch > -1 ){ rc->a[ ch ][ lay ][ w_s ] = (float)adc.am[i][j]; } #endif #ifdef ADC_DT x_y = cfg->x_y[i][j]; u_d = cfg->u_d[i][j]; lay = cfg->dlay[i][j]; ch = cfg->dtch[i][j]; if( x_y > -1 && u_d > -1 && lay > -1 && ch > -1 ){ if( x_y == 0 ){ rc->ax[ch][lay][u_d] = (float)adc.am[i][j]; } else{ rc->ay[ch][lay][u_d] = (float)adc.am[i][j]; } } #endif } } return 0; } #endif /*----------------------------------------------------------------------------- read_tmc Read TMC data ----------------------------------------------------------------------------*/ int read_tmc( Recnst *rc, Cfg_tmc *cfg, FILE *fp ) { int i, j; int w_s, lay, ch, x_y, u_d; int data_size; char *ptr; Daq_tmc tmc; memset( rc, 0, sizeof(Recnst) ); /* Read TMC data from DAQ */ if( fread( &data_size, 1, sizeof(int), fp ) != sizeof(int) ){ perror( "read_tmc: data_size" ); return -1; } else if( (size_t)data_size < sizeof(Daq_tmc) ){ perror( "read_tmc: wrong data_size" ); return -1; } if( ( ptr = (char *)malloc( data_size ) ) == NULL ){ perror( "read_tmc: malloc" ); return -1; } if( fread( ptr, 1, data_size, fp ) != (size_t)data_size ){ perror( "read_tmc: tmc data" ); return -1; } memcpy( &tmc, ptr, sizeof(Daq_tmc) ); free(ptr); /* Reconstruction TMC data */ for( i = 0; i < TMC_MOD; i++ ){ for( j = 0; j < TMC_CH; j++ ){ #ifdef TMC_TGC w_s = cfg->w_s[i][j]; lay = cfg->tlay[i][j]; ch = cfg->tgch[i][j]; if( w_s > -1 && lay > -1 && ch > -1 ){ rc->t[ ch ][ lay ][ w_s ] = (float)tmc.tm[i][j]; } #endif #ifdef TMC_SCI if( cfg->sci[i][j] > -1 ){ rc->sci[ cfg->sci[i][j] ] = (float)tmc.tm[i][j]; } #endif x_y = cfg->x_y[i][j]; u_d = cfg->u_d[i][j]; lay = cfg->dlay[i][j]; ch = cfg->dtch[i][j]; if( x_y > -1 && u_d > -1 && lay > -1 && ch > -1 ){ if( x_y == 0 ){ rc->tx[ch][lay][u_d] = (float)tmc.tm[i][j]; } else { rc->ty[ch][lay][u_d] = (float)tmc.tm[i][j]; } } } } return 0; } /* End of File */