/* */ /* File Name : buf.c */ /* Creation Date : Nov 14 2000 */ /* Author : Y.Nakaune */ /* */ /* Update History */ /* Nov 15 H.Kuashige : */ /* modify for cosmetics */ /* fix calling sequence of ReadyADC */ /* Nov 29 H.Kuashige : */ /* add OffSpillSleep */ #include #include #include #include #include #include "buf.h" #define SLEEP_OFF_SPILL 1 /*------------------------------------------------------- #ifdef USE_CAMAC_PROFILER #include "camlib.h" #define PROF_N_SAMPLE 10 #define PROF_NAF (2<<9) static int profiler[ PROF_N_SAMPLE ]; static void clear_prof() { int i; for (i=0; i< PROF_N_SAMPLE; ++i) profiler[i]=0; } static void report_prof() { int i; printf(" PROFILER \n"); for (i=0; i< PROF_N_SAMPLE; ++i) { printf(" %2d: %d \n",i,profiler[i]); } } static void meas_prof(int idx) { int status, q, x; u_short s_data; status = CAMACW( PROF_NAF, &s_data, &q, &x ); profiler[idx] = s_data; } #endif ----------------------------------------------------------*/ /*-------------------------------------------------------- usage ---------------------------------------------------------*/ static void usage( char *cmd ) { fprintf( stderr, "\nUsage: %s [-n nmax] [-c file] [-r run_number] header\n", cmd ); fprintf( stderr, "\t n: set event Number, or infinite mode\n" ); fprintf( stderr, "\t c: set configure file of the channel assign\n" ); fprintf( stderr, "\t r: Run number\n" ); fprintf( stderr, "\t
: output file
%s\n\n", DOT_RAW ); exit( 1 ); } /*---------------------------------------------------------- WriteFlg ---------------------------------------------------------*/ void WriteFLG( const unsigned int flag, FILE *fp ) { fwrite( &flag, sizeof(int), 1, fp ); } /*---------------------------------------------------------- PrintOutOption ---------------------------------------------------------*/ static void PrintOutOption( int run_number, int nmax, const char* cfg_file, const char* comment ) { printf( "\n" ); printf( "Run Number : %3d\n", run_number ); printf( "Config. file : %s\n", cfg_file ); printf( "Number of Event : %d\n", nmax ); printf( "D1 : %d %d %d \n", tgc_cfg.pre_doublet_x, tgc_cfg.pre_doublet_y, tgc_cfg.pre_doublet_z ); printf( "T3 : %d %d %d \n", tgc_cfg.pre_triplet_x, tgc_cfg.pre_triplet_y, tgc_cfg.pre_triplet_z ); printf( "conversion D1 : %d %d %d \n", tgc_cfg.doublet_x, tgc_cfg.doublet_y, tgc_cfg.doublet_z ); printf( "conversion T3 : %d %d %d \n", tgc_cfg.triplet_x, tgc_cfg.triplet_y, tgc_cfg.triplet_z ); printf( "HV (kV) : %2.1f %2.1f %2.1f %2.1f %2.1f\n", tgc_cfg.HV[0], tgc_cfg.HV[1], tgc_cfg.HV[2], tgc_cfg.HV[3], tgc_cfg.HV[4] ); printf( "Pressure (mmAq) : %d %d %d %d %d\n", tgc_cfg.Pressure[0], tgc_cfg.Pressure[1], tgc_cfg.Pressure[2], tgc_cfg.Pressure[3], tgc_cfg.Pressure[4] ); printf( "Comment : %s", comment ); printf( "\n" ); } /*---------------------------------------------------------- main ---------------------------------------------------------*/ int main( int argc, char **argv ) { int run_number; int nmax = 1; /* number of events to be read out*/ int event = 0; /* number of read out events */ int event_number; /* event number */ static char comment[4096]; /* RUN comment */ char tgc_file[128] = TGC_CFG_FILE; /* TGC configuration file name */ static char cfg_file[64] = ""; /* file name for DAQ configuration */ Cfg_adc cfg_adc; Cfg_tmc cfg_tmc; char rawfile[128]; /* raw data file name */ FILE *fp = NULL; /* pointer to raw data file */ static char start_date[128], end_date[128]; /* RUN start/end time */ time_t st_now; time_t ed_now; int char_size = 0, file_size = 0; int tgc_cfg_size = 0; int tmstart_size = 0, tmend_size = 0; int opt; int l, idx; char buf_con[16]; int trg_check; /*------------------------------------------------------------------*/ /* Initiaraze number_naf_entry for array_naf[]*/ number_naf_entry = 0; /*---Options---*/ while ( ( opt = getopt( argc, argv, "n:c:r:h" ) ) != -1 ) { switch ( opt ) { case 'n': nmax = atoi( optarg ); break; case 'c': strcpy( cfg_file, optarg ); break; case 'r': run_number = atoi( optarg ); break; default: usage( argv[0] ); } } if ( optind < argc ) { sprintf( rawfile, "%s%s", argv[optind], DOT_RAW ); } else usage( argv[0] ); /*---Input Comment---*/ printf( "Enter RUN Begin Comment \n > " ); fgets( comment, sizeof( comment ), stdin ); /*---Read TGC.cfg---*/ ReadTGC_CFG( tgc_file ); /*---Print out options---*/ PrintOutOption( run_number, nmax, cfg_file, comment); /*---Confirm options---*/ printf( "O.K ? (y/n) : " ); fgets( buf_con, sizeof( buf_con ), stdin ); if ( buf_con[0] != 'y' ) { printf( "\n" ); usage( argv[0] ); exit(0); } printf( "\n" ); /* open raw data file */ if ( ( fp = fopen( rawfile, "r" ) ) != NULL ) { printf( "Raw data file %s exists. \n", rawfile ); printf( "Do you want to overwrite ? (y/n) : " ); fgets( buf_con, sizeof( buf_con ), stdin ); if ( buf_con[0] != 'y' ) { printf( "\n" ); exit(0); } printf( "\n" ); } if ( ( fp = fopen( rawfile, "wb" ) ) == NULL ) exit_err( rawfile ); /* comment size search */ char_size = strlen( comment ); if (char_size & 0x03) { l = char_size & 0x03; for (idx =0; idx