/* * Example file for the CAMAC driver. * It waits for a LAM of a certain address and then reads out a channel there. * All values are filled into a histogram which is displayed on the screen. * It needs the HPLOT/HBOOK library (with their C interfaces) from CERN as * well as the cfortran package * Look at the end of the file how to compile it. */ #define f2cFortran #define extname #include #include #include #include "higz.h" #include "hplot.h" #include "XWindows.h" #include #include #include #include #include #include #include #define PAWSIZE 1000000L int pawc_[PAWSIZE]; void init_hbook(void); void update_hplot(int hv); int main (int argc, char **argv){ int i; /* running loop variable in the measurement loop */ int fd_crate; /* measurement crate file descriptor */ int data; /* data from CAMAC operations */ int n_events; /* number of events */ time_t last_update; time_t start_time, stop_time; /* * Here follow the configuration parameters * quick and dirty */ const char *crate = "/dev/camac0"; /* crate device */ const int adc_pos = 20; /* ADC 2249 position */ const int hbook_nr = 1000; /* nr of booked HBOOK histogram */ const int t_update = 10; /* update frequency of HPLOT picture [sec] */ printf("\n**************************\n" "* Measuring ADC spectrum *\n" "**************************\n\n"); /* * Get run parameters from cmd line or interactive */ if (argc != 3) { fprintf(stderr, "usage:\nadc [filename] [events]\n"); exit(-1); } n_events = atoi(argv[2]); printf("Files : %s\n", argv[1]); printf("Events : %d\n", n_events); /* * Open camac crates */ if ((fd_crate = open (crate, O_RDWR)) < 0) { perror(crate); exit (-1); } /* * Init the CERN stuff */ init_hbook(); HBOOK1(hbook_nr,"ADC data",1200,0.,1200.,0.); /* * Init ADC 2249A */ CNAF(fd_crate, adc_pos, 0, CAMAC_DISABLE, &data); CNAF(fd_crate, adc_pos, 0, CAMAC_CLEAR_1, &data); /* * Main measurement loop */ start_time = time(NULL); last_update = start_time - t_update/2; for (i = 1; i <= n_events; ++i) { int valid = 0; CNALAM(fd_crate, adc_pos, 0, 1000); data=0; /* waiting for LAM and read data */ CNAF(fd_crate, adc_pos, 0, CAMAC_READ_1, &data); ioctl(fd_crate, CAMAC_TEST_LAM, &valid); CNAF(fd_crate, adc_pos, 0, CAMAC_CLEAR_1, NULL); if (valid) { HFILL(hbook_nr, (float) data, 0., 1.); printf("%8i %4i\r", i,data);fflush(stdout); } else { printf("%8i \r", i);fflush(stdout); i--; /* dont count this event */ } if (((time(NULL) > last_update + t_update) || (i == n_events)) && (i > 0)) { update_hplot(hbook_nr); last_update = time(NULL); } } /* k loop (update)*/ stop_time = time(NULL); printf("Total run time = %i\n. Frequency = %g Hz\n", (int)(stop_time-start_time), (double)n_events/(double)(stop_time-start_time)); /* * Close the CAMAC crate */ close(fd_crate); /* * stop HIGZ and write data file */ printf("press to stop HIGZ"); getchar(); HRPUT(0,argv[1], "N"); HPLEND(); exit(0); } /* main() */ /****************************************************************************/ void init_hbook(void) { int kwtype = 10; float xwindow = 12.0; float ywindow = 12.0; HLIMIT(PAWSIZE); HPLINT(kwtype); IDAWK(1); HPLSIZ (xwindow,ywindow," "); HPLZON(1,1,1," "); HPLOPT("NBOX",1); /* histogram options */ HPLOPT("NDAT",1); HPLOPT("NTIC",1); /* HPLOPT("TIC ",1); */ HPLOPT("UTIT",1); HPLOPT("STAT",1); /* statistics */ HPLOPT("LOGY",1); HPLSET("STAT",111); HPLOPT("HARD",1); /* hardware characters! */ IGSET("TXFP", -130); /* times roman! */ HPLSET("TFON", -130); /* general comments */ HPLSET("VFON", -130); /* axis values */ HPLSET("CFON", -130); /* comments */ HPLSET("GFON", -130); /* global title */ HPLSET("LFON", -130); /* axis labels */ HPLSET("HCOL",2); HPLSET("HTYP",1); HPLSET("GSIZ",0.33); HPLSET("TSIZ",0.50); HPLSET("ASIZ",0.33); HPLSET("CSIZ",0.33); HPLSET("VSIZ",0.33); HPLSET("SMGR",0.00); HPLSET("SMGU",0.00); HPLSET("YTIC",0.15); HPLSET("XTIC",0.15); HPLSET("XMGR",0.5); HPLSET("XMGL",1.6); HPLSET("YMGU",0.5); HPLSET("YMGL",1.6); HPLSET("XLAB",1.2); HPLSET("XVAL",0.3); HPLSET("YVAL",0.4); } /* init_hbook() */ /****************************************************************************/ void update_hplot(int hist) { static int f_hplot = 1; IACWK(1); if (f_hplot) { HPLOT(hist," "," ",0); HPLAX("adc channels","entries"); f_hplot = 0; } else HPLOT(hist,"U"," ",0); IXUPDWI(0); IDAWK(1); } /* update_hplot() */ /****************************************************************************/ /* Local Variables: compile-command: "gcc -I/cern/pro/include adc.c -L/cern/pro/lib -lgraflib -lgrafX11 -lpacklib -L/usr/X11/lib -lX11 -lm -lf2c -o adc" End: */