131 #include <linux/version.h>
138 #include <sys/time.h>
139 #include <sys/types.h>
140 #include <sys/stat.h>
153 #include "sis3100_vme_calls.h"
217 #define SIS3820_ADDRESS_0 0x38000000
218 #define SIS3820_ADDRESS_1 0x39000000
219 #define V1190_ADDRESS 0xEE000000
220 #define MAX_NUMBER_LWORDS 1024
221 #define ALMOST_FULL_LEVEL 1024
222 #define DATABUFFER_SIZE 131072
223 #define DIFF_TOLERANCE -12200
224 #define TD_EVENT (1<<0)
227 #define LE_POSITRON_EVENT (1<<1)
228 #define M2_EVENT (1<<2)
229 #define BC_EVENT (1<<3)
230 #define M1_EVENT (1<<4)
231 #define M1_POSITRON_EVENT (1<<5)
235 #define MASTERFIRST 2
302 INT
pause_run(INT run_number,
char *error);
306 INT
poll_event(INT source, INT count, BOOL test);
315 INT *channel, INT *ind);
317 INT *channel, INT *ind);
349 LAM_SOURCE(0,0xFFFFFF),
456 cm_get_experiment_database(&hDB, NULL);
458 db_create_record(hDB, 0,
"/Experiment/Run Parameters", strcomb(exp_param_str));
459 db_create_record(hDB, 0,
"/Equipment/Trigger/Settings", strcomb(trigger_settings_str));
460 db_create_record(hDB, 0,
"/Equipment/Scaler/Settings", strcomb(scaler_settings_str));
461 db_create_record(hDB, 0,
"/Equipment/Trigger/Vme_Statistics", strcomb(vme_stats_str));
462 db_create_record(hDB, 0,
"/Equipment/Beamline/Settings", strcomb(beamline_settings_str));
463 db_create_record(hDB, 0,
"/Equipment/Beamline/Variables", strcomb(beamline_event_str));
464 db_create_record(hDB, 0,
"/Equipment/LEMVAC/Settings", strcomb(lemvac_settings_str));
465 db_create_record(hDB, 0,
"/Equipment/LEMVAC/Variables", strcomb(lemvac_event_str));
466 db_create_record(hDB, 0,
"/Equipment/ModCryo/Settings", strcomb(modcryo_settings_str));
467 db_create_record(hDB, 0,
"/Equipment/ModCryo/Variables", strcomb(modcryo_event_str));
468 db_create_record(hDB, 0,
"/Equipment/SampleCryo/Settings", strcomb(samplecryo_settings_str));
469 db_create_record(hDB, 0,
"/Equipment/SampleCryo/Variables", strcomb(samplecryo_event_str));
470 db_create_record(hDB, 0,
"/Equipment/SCS2001M/Settings", strcomb(scs2001m_settings_str));
471 db_create_record(hDB, 0,
"/Equipment/SCS2001M/Variables", strcomb(scs2001m_event_str));
472 db_create_record(hDB, 0,
"/Equipment/HV/Settings", strcomb(hv_settings_str));
473 db_create_record(hDB, 0,
"/Equipment/HV/Variables", strcomb(hv_event_str));
474 db_create_record(hDB, 0,
"/Equipment/HV Detectors/Settings", strcomb(hv_detectors_settings_str));
475 db_create_record(hDB, 0,
"/Equipment/HV Detectors/Variables", strcomb(hv_detectors_event_str));
479 if (db_find_key(hDB, 0,
"/Equipment/Trigger/Settings", &hkey))
480 db_open_record(hDB, hkey, &trigger_settings,
sizeof(trigger_settings), MODE_READ, NULL, NULL);
482 if (db_find_key(hDB, 0,
"/Equipment/Trigger/Vme_Statistics", &hkey))
483 db_open_record(hDB, hkey, &vme_stats,
sizeof(vme_stats), MODE_WRITE, NULL, NULL);
485 if (db_find_key(hDB, 0,
"/Runinfo", &hkey))
486 db_open_record(hDB, hkey, &
runinfo,
sizeof(
runinfo), MODE_READ, NULL, NULL);
491 if (db_find_key(hDB, 0,
"/Info", &hkey))
492 db_open_record(hDB, hkey, &info,
sizeof(info), MODE_READ, NULL, NULL);
495 if (db_find_key(hDB, 0,
"/Equipment/Beamline/Variables", &hkey))
496 db_open_record(hDB, hkey, &beamline_event,
sizeof(beamline_event), MODE_READ, NULL, NULL);
497 if (db_find_key(hDB, 0,
"/Equipment/LEMVAC/Variables", &hkey))
498 db_open_record(hDB, hkey, &lemvac_event,
sizeof(lemvac_event), MODE_READ, NULL, NULL);
499 if (db_find_key(hDB, 0,
"/Equipment/ModCryo/Variables", &hkey))
500 db_open_record(hDB, hkey, &moddy_event,
sizeof(moddy_event), MODE_READ, NULL, NULL);
501 if (db_find_key(hDB, 0,
"/Equipment/SampleCryo/Variables", &hkey))
502 db_open_record(hDB, hkey, &sample_event,
sizeof(sample_event), MODE_READ, NULL, NULL);
503 if (db_find_key(hDB, 0,
"/Equipment/Omega/Variables", &hkey))
504 db_open_record(hDB, hkey, &omega_event,
sizeof(omega_event), MODE_READ, NULL, NULL);
505 if (db_find_key(hDB, 0,
"/Equipment/SCS2001M/Variables", &hkey))
506 db_open_record(hDB, hkey, &scs2001m_event,
sizeof(scs2001m_event), MODE_READ, NULL, NULL);
507 if (db_find_key(hDB, 0,
"/Equipment/HV/Variables", &hkey))
508 db_open_record(hDB, hkey, &hv_event,
sizeof(hv_event), MODE_READ, NULL, NULL);
509 if (db_find_key(hDB, 0,
"/Equipment/HV Detectors/Variables", &hkey))
510 db_open_record(hDB, hkey, &hvdet_event,
sizeof(hvdet_event), MODE_READ, NULL, NULL);
511 memset(&vme_stats, 0x00,
sizeof(vme_stats));
512 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
513 memset(&tdc_pileup, 0x00,
sizeof(tdc_pileup));
528 cm_msg(MINFO,
"frontend_init",
"LINUX_VERSION = 0x%x",LINUX_VERSION_CODE);
530 if (LINUX_VERSION_CODE < 0x20600)
531 sprintf(vme_device,
"/dev/sis1100");
533 sprintf(vme_device,
"/dev/sis1100_00remote");
535 if ((
hdev = open(vme_device, O_RDWR, 0)) < 0) {
536 cm_msg(MERROR,
"frontend_init",
"Error on opening VME device %s", vme_device);
549 cm_msg(MINFO,
"frontend_init",
"scaler flags, address 0x%8.8x = %d, 0x%8.8x = %d",
573 cm_msg(MERROR,
"frontend_exit",
574 "Error on access to SIS3820_0, key reset failed, return code %x\n", status);
581 cm_msg(MERROR,
"frontend_exit",
582 "Error on access to SIS3820_1, key reset failed, return code %x\n", status);
601 DWORD pattern_1stChip, pattern_2ndChip;
606 memset(&ch_pattern, 0x00,
sizeof(ch_pattern));
607 pattern_1stChip = pattern_2ndChip = 0;
613 pattern_1stChip = pattern_1stChip | (1<<i);
615 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
621 pattern_1stChip = pattern_1stChip | (1<<i);
623 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
629 pattern_1stChip = pattern_1stChip | (1<<i);
631 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
641 pattern_1stChip = pattern_1stChip | (1<<i);
643 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
655 pattern_1stChip = pattern_1stChip | (1<<i);
657 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
665 pattern_1stChip = pattern_1stChip | (1<<i);
667 pattern_2ndChip = pattern_2ndChip | (1<<(i%32));
676 cm_msg(MINFO,
"begin_of_run",
"pattern_1stChip = 0x%08x", pattern_1stChip);
677 cm_msg(MINFO,
"begin_of_run",
"pattern_2ndChip = 0x%08x", pattern_2ndChip);
679 ch_pattern[0] = pattern_1stChip & 0xFFFF;
680 ch_pattern[1] = (pattern_1stChip & 0xFFFF0000)>>16;
681 ch_pattern[2] = pattern_2ndChip & 0xFFFF;
682 ch_pattern[3] = (pattern_2ndChip & 0xFFFF0000)>>16;
684 #ifndef HAVE_TEST_RUN
686 for (i=0; i<2; i++) {
689 cm_msg(MINFO,
"begin_of_run",
"V1190 1st Chip channel pattern: pattern = 0x%04x", ch_pattern[i]);
693 cm_msg(MERROR,
"begin_of_run",
"Error writing channel pattern to TDC V1190, return code %x\n", status);
700 for (i=2; i<4; i++) {
703 cm_msg(MINFO,
"begin_of_run",
"V1190 2nd Chip channel pattern: pattern = 0x%04x", ch_pattern[i]);
707 cm_msg(MERROR,
"begin_of_run",
"Error writing channel pattern to TDC V1190, return code %x\n", status);
719 cm_msg(MERROR,
"begin_of_run",
720 "Error on resetting TDC V1190, return code %x\n", status);
732 cm_msg(MERROR,
"begin_of_run",
733 "Error on access to SIS3820_0, key disable failed, return code %x\n", status);
740 cm_msg(MERROR,
"begin_of_run",
741 "Error on access to SIS3820_0, key reset failed, return code %x\n", status);
750 cm_msg(MERROR,
"begin_of_run",
751 "Error on access to SIS3820_0, key enable failed, return code %x\n", status);
763 cm_msg(MERROR,
"begin_of_run",
764 "Error on access to SIS3820_1, key disable failed, return code %x\n", status);
771 cm_msg(MERROR,
"begin_of_run",
772 "Error on access to SIS3820_1, key reset failed, return code %x\n", status);
781 cm_msg(MERROR,
"begin_of_run",
782 "Error on access to SIS3820_1, key enable failed, return code %x\n", status);
839 cm_msg(MINFO,
"begin_of_run",
"Fast Muon event_defined = 0x%04x, master channel fast muon= %d",
842 cm_msg(MINFO,
"begin_of_run",
"Slow Muon event_defined = 0x%04x, master channel slow muon= %d",
847 memset(&vme_stats, 0x00,
sizeof(vme_stats));
848 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
849 memset(&tdc_pileup, 0x00,
sizeof(tdc_pileup));
857 fp = fopen(
"/data/nemu/fe.log",
"w");
858 if ( fp == NULL )
return FE_ERR_HW;
872 cm_msg(MINFO,
"end_of_run",
"V1190 Disabled all channels: return_code = 0x%08x", return_code);
876 cm_msg(MINFO,
"end_of_run",
"total number of written slow muon events = %15.0f", vme_stats.
slowMuonEvents);
877 cm_msg(MINFO,
"end_of_run",
"total number of written fast muon events = %15.0f", vme_stats.
fastMuonEvents);
878 cm_msg(MINFO,
"end_of_run",
"total number of read events = %15.0f", vme_stats.
readcounts);
879 cm_msg(MINFO,
"end_of_run",
"TDC error counts = %15.0f", vme_stats.
tdc_error_counts);
880 cm_msg(MINFO,
"end_of_run",
"p_read = 0x%x, p_write = 0x%x",
p_read,
p_write);
881 cm_msg(MINFO,
"end_of_run",
"total Run time in TDC bins (double) = %18.0f", vme_stats.
run_time);
882 cm_msg(MINFO,
"end_of_run",
"total Run time 10kHz clock = %18.5f", vme_stats.
channelCounts[1]/10000.);
907 cm_msg(MERROR,
"resume_run",
908 "Error on resetting TDC V1190, return code %x\n", status);
963 u_int32_t *output_buffer;
964 u_int32_t get_lwords, sum_lwords;
967 INT tdc_time, channel, diffTimeSlowMuon, diffTimeFastMuon;
991 if (
runinfo.state != STATE_RUNNING )
995 diffTimeSlowMuon = diffTimeFastMuon = 0;
1017 #define BINNING 0.1953125 // TDC bin in ns
1018 double rate[4], ran;
1020 DWORD mincounter, tdctime;
1027 memset(&time, 0x00,
sizeof(time));
1029 for (i=0; i<sum_lwords; i++) {
1031 ran = (double) rand()/ (double) RAND_MAX;
1033 for (j=1; j<4; j++) {
1034 ran = (double) rand()/ (double) RAND_MAX;
1035 time[j] = (-1./rate[j]*log(1.- ran))/
BINNING;
1039 for (j=0; j<4; j++) {
1041 for (k=0; k<4; k++) {
1042 if (j!=k && time[j] <= time[k]) mincounter++;
1044 if (mincounter == 3)
break;
1051 tdctime = tdctime | (channel<<19);
1058 tdctime = tdctime | (channel<<19);
1059 ran = (double) rand()/(double) RAND_MAX;
1060 time[1] = time[1] + (
U_LONG) (-1./rate[j]*log(1. - ran))/
BINNING;;
1066 tdctime = tdctime | (channel<<19);
1067 ran = (double) rand()/(double) RAND_MAX;
1068 time[2] = time[2] + (
U_LONG) (-1./rate[j]*log(1. - ran))/
BINNING;;
1074 tdctime = tdctime | (channel<<19);
1075 ran = (double) rand()/(double) RAND_MAX;
1076 time[3] = time[3] + (
U_LONG) (-1./rate[j]*log(1. - ran))/
BINNING;;
1083 output_buffer[i] = tdctime;
1089 for (i=0; i<32; i++) {
1091 memcpy(output_buffer + sum_lwords, &blt_data, get_lwords *
sizeof(u_int32_t));
1092 sum_lwords += get_lwords;
1093 if (return_code == 0x211)
1101 for (i=0; i<sum_lwords; i++) {
1102 v1190_data = (
V1190_DATA *) &output_buffer[i];
1103 tdc_time = v1190_data->
data;
1104 channel = v1190_data->
channel;
1108 if (v1190_data->
buffer == 4) {
1112 fprintf(fp,
"found TDC error\n");
1115 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1121 fprintf(fp,
"Event reset due to channel %d overflow\n", channel);
1123 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1277 if (diffTimeFastMuon < 0 && abs(diffTimeFastMuon) >=
t0_offset)
1279 else if ( diffTimeFastMuon < 0 && abs(diffTimeFastMuon) <
t0_offset )
1282 if (diffTimeSlowMuon < 0 && abs(diffTimeSlowMuon) >=
t0_offset)
1284 else if ( diffTimeSlowMuon < 0 && abs(diffTimeSlowMuon) <
t0_offset )
1289 "raw data = %6d %3d %7d 0x%08x, vmeTime = %10.5e, difftime = %8d, ev.time = %8d, pu-flag = %2d, 0x%04x\n",
1290 i, channel, tdc_time, output_buffer[i],
1307 }
else if (channel ==
CLOCK ) {
1309 if (i - tdc_eval_event.
clockIndex == 1 && i !=1) {
1310 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1313 if (i == sum_lwords - 1)
1322 free(output_buffer);
1335 INT diff_toLastEvent;
1344 if ( tdc_eval_event.
set_t0 == 0) {
1355 tdc_eval_event.
event_time += diff_toLastEvent;
1370 switch (event_type){
1406 fprintf(fp,
"runTime = %12d, PUend = %12d, pu = %04d, clean = %6d, good = %6d\n",
1488 INT i, j, k, masterIndex;
1489 INT decChannel[8], decInd[8], bcChannel, bcInd, tdChannel, tdInd, m2Channel, m2Ind;
1491 BOOL good_event, pos_event, bc_event, posL_event, posT_event, posR_event, posB_event;
1497 fprintf(fp,
"evaluate_slow_muon_event, M2clean = %10.0f, TDclean = %10.0f\n", vme_stats.
mcp2_clean, vme_stats.
td_clean);
1500 good_event = pos_event = bc_event = mcp2_event = FALSE;
1501 posL_event = posT_event = posR_event = posB_event = FALSE;
1512 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1517 bcChannel = bcInd = m2Channel = m2Ind = tdChannel = tdInd = -1;
1520 decChannel[i] = decInd[i] = -1;
1530 TD,
TD,
MCP2F, masterIndex, &tdChannel, &tdInd);
1537 &decChannel[0], &decInd[0]) ||
1539 &decChannel[1], &decInd[1]);
1541 &decChannel[2], &decInd[2]) ||
1543 &decChannel[3], &decInd[3]);
1545 &decChannel[4], &decInd[4]) ||
1547 &decChannel[5], &decInd[5]);
1549 &decChannel[6], &decInd[6]) ||
1551 &decChannel[7], &decInd[7]);
1552 pos_event = posL_event || posT_event || posR_event || posB_event;
1567 good_event = mcp2_event;
1572 good_event = bc_event;
1577 good_event = pos_event;
1582 good_event = pos_event && bc_event;
1586 good_event = mcp2_event && bc_event;
1590 good_event = mcp2_event && pos_event;
1594 good_event = mcp2_event && pos_event && bc_event;
1604 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1629 if ( decChannel[0] == -1 )
continue;
1632 if ( decChannel[1] == -1 )
continue;
1635 if ( decChannel[2] == -1 )
continue;
1638 if ( decChannel[3] == -1 )
continue;
1641 if ( decChannel[4] == -1 )
continue;
1644 if ( decChannel[5] == -1 )
continue;
1647 if ( decChannel[6] == -1 )
continue;
1650 if ( decChannel[7] == -1 )
continue;
1662 if ( j < tdInd || tdInd == -1)
continue;
1669 if ( j < m2Ind || m2Ind == -1 )
continue;
1678 if ( m2Ind == -1)
continue;
1692 if ( i == decChannel[0] && j < decInd[0] )
1699 if ( i == decChannel[1] && j < decInd[1] )
1706 if ( i == decChannel[2] && j < decInd[2] )
1713 if ( i == decChannel[3] && j < decInd[3] )
1720 if ( i == decChannel[4] && j < decInd[4] )
1727 if ( i == decChannel[5] && j < decInd[5] )
1734 if ( i == decChannel[6] && j < decInd[6] )
1741 if ( i == decChannel[7] && j < decInd[7] )
1780 for (j=0; j < tdc_eval_event.
eventSize+1; j++) {
1789 fprintf(fp,
"tdc data = %02d, %8d, channel %4d, hex = 0x%08x\n", j,
1797 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1811 INT i, j, k, bcChannel, bcInd, decChannel, decInd, masterIndex;
1812 BOOL good_event, bc_event, pos_event;
1816 fprintf(fp,
"evaluate_fast_muon_event, mcp1 = %10.0f, mcp1 clean = %10.0f\n",
1820 good_event = bc_event = pos_event = FALSE;
1822 bcChannel = bcInd = decChannel = decInd = -1;
1832 good_event = bc_event;
1836 good_event = pos_event;
1840 good_event = bc_event && pos_event;
1850 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1865 if ( bcChannel == -1 )
continue;
1869 if ( decChannel == -1 )
continue;
1885 if ( abs(tdc_eval_event.
tdc_event[i][j] - tdc_eval_event.
tdc_event[bcChannel][bcInd]) >
1892 if ( i == decChannel && j < decInd )
1918 for (j = 0; j < tdc_eval_event.
eventSize+1; j++) {
1927 fprintf(fp,
"tdc data = %02d, %8d, channel %4d, hex = 0x%08x, ch = %4d, index = %4d\n",
1937 memset(&tdc_eval_event, 0x00,
sizeof(tdc_eval_event));
1959 INT *channel, INT *ind)
1962 INT difftime_now, difftime_last;
1965 difftime_now = difftime_last = 0;
1967 difftime_now = difftime_last = 2 * tofWindow;
1968 *channel = *ind = -1;
1969 for (i=firstCh; i <= lastCh; i++) {
1975 if (difftime_now < tofWindow && difftime_now > 0) {
1976 if (difftime_now > difftime_last) {
1977 difftime_last = difftime_now;
1988 if (difftime_now < tofWindow && difftime_now > 0) {
1989 if (difftime_now < difftime_last) {
1990 difftime_last = difftime_now;
1998 if ( *channel == -1 )
return FALSE;
2003 if ( tdc_eval_event.
pileup[*channel][*ind] == 1 ) {
2005 fprintf(fp,
" TOF pileup at channel %d, hit %d\n", *channel, *ind);
2027 INT *channel, INT *ind)
2030 INT difftime_now, difftime_last, difftime;
2032 difftime_now = difftime_last = 2*decWindow;
2033 *channel = *ind = -1;
2035 if (coincWindow < 0) {
2037 for (i=firstCh; i <= lastCh; i++) {
2041 if (difftime_now < decWindow && difftime_now > 0) {
2042 if ( difftime_now < difftime_last ) {
2043 difftime_last = difftime_now;
2058 for (i=0; i < tdc_eval_event.
foundChannel[firstCh]; i++) {
2059 for (j=0; j < tdc_eval_event.
foundChannel[lastCh]; j++) {
2060 difftime = abs(tdc_eval_event.
tdc_event[firstCh][i] - tdc_eval_event.
tdc_event[lastCh][j]);
2062 if (difftime < coincWindow) {
2064 if (difftime_now < decWindow && difftime_now > 0) {
2065 if (difftime_now < difftime_last) {
2066 difftime_last = difftime_now;
2076 if ( *channel == -1 )
return FALSE;
2108 case CMD_INTERRUPT_ENABLE:
2110 case CMD_INTERRUPT_DISABLE:
2112 case CMD_INTERRUPT_ATTACH:
2114 case CMD_INTERRUPT_DETACH:
2149 bk_create(pevent,
"TDC0", TID_DWORD, (
void**)&pdata);
2158 ndata = (*
p_read & 0x0000FFFF) + 1;
2160 for (i=0; i < ndata; i++) {
2189 bk_close(pevent, pdata);
2190 return bk_size(pevent);
2210 u_int32_t data[100];
2217 bk_create(pevent,
"SCL0", TID_DWORD, (
void**)&pdata);
2220 #ifdef HAVE_TEST_RUN
2231 *pdata++ = (100 + rand()%40-20) | channel;
2240 cm_msg(MERROR,
"read_scaler_event",
"Error reading data from VME Scaler SIS3820!");
2254 if ( status != 0 ) {
2257 cm_msg(MERROR,
"read_scaler_event",
"Error reading data from VME Scaler SIS3820!");
2269 bk_close(pevent, pdata);
2270 return bk_size(pevent);
2282 double *pDoubleData;
2288 bk_create(pevent,
"DBEA", TID_FLOAT, (
void**)&pdata);
2289 n_max =
sizeof(beamline_event.
demand)/
sizeof(
float);
2290 for (i = 0; i < n_max; i++)
2291 *pdata++ = beamline_event.
demand[i];
2292 bk_close(pevent, pdata);
2295 bk_create(pevent,
"MBEA", TID_FLOAT, (
void**)&pdata);
2296 n_max =
sizeof(beamline_event.
measured)/
sizeof(
float);
2297 for (i = 0; i < n_max; i++)
2298 *pdata++ = beamline_event.
measured[i];
2299 bk_close(pevent, pdata);
2302 bk_create(pevent,
"MVAC", TID_FLOAT, (
void**)&pdata);
2303 n_max =
sizeof(lemvac_event.
input)/
sizeof(
float);
2304 for (i = 0; i < n_max; i++)
2305 *pdata++ = lemvac_event.
input[i];
2306 bk_close(pevent, pdata);
2309 bk_create(pevent,
"MMOD", TID_FLOAT, (
void**)&pdata);
2310 n_max =
sizeof(moddy_event.
input)/
sizeof(
float);
2311 for (i = 0; i < n_max; i++)
2312 *pdata++ = moddy_event.
input[i];
2313 bk_close(pevent, pdata);
2316 bk_create(pevent,
"MSAM", TID_FLOAT, (
void**)&pdata);
2317 n_max =
sizeof(sample_event.
input)/
sizeof(
float);
2319 sample_event.
input[0] = omega_event.
input[0]+273.16;
2320 for (i = 0; i < n_max; i++)
2321 *pdata++ = sample_event.
input[i];
2322 bk_close(pevent, pdata);
2325 bk_create(pevent,
"M900", TID_FLOAT, (
void**)&pdata);
2326 n_max =
sizeof(scs2001m_event.
input)/
sizeof(
float);
2327 for (i = 0; i < n_max; i++)
2328 *pdata++ = scs2001m_event.
input[i];
2329 bk_close(pevent, pdata);
2332 bk_create(pevent,
"MHVT", TID_FLOAT, (
void**)&pdata);
2333 n_max =
sizeof(hv_event.
measured)/
sizeof(
float);
2334 for (i = 0; i < n_max; i++)
2336 bk_close(pevent, pdata);
2339 bk_create(pevent,
"MHVD", TID_FLOAT, (
void**)&pdata);
2340 n_max =
sizeof(hvdet_event.
measured)/
sizeof(
float);
2341 for (i = 0; i < n_max; i++)
2342 *pdata++ = hvdet_event.
measured[i];
2343 bk_close(pevent, pdata);
2346 bk_create(pevent,
"MWAV", TID_DOUBLE, (
void**)&pDoubleData);
2360 bk_close(pevent, pDoubleData);
2362 return bk_size(pevent);
2389 cm_get_experiment_database(&hDB, NULL);
2395 db_find_key(hDB, 0,
"/Equipment/Scaler/Settings", &hkey);
2396 db_get_record(hDB, hkey, &scaler_settings, &size, 0);
2405 cm_msg(MERROR,
"scaler_mode",
"Error on setting mode of SIS3820, return code %x\n", status);
2415 cm_msg(MERROR,
"scaler_mode",
"Error on setting control status of SIS3820, return code %x\n", status);
2422 cm_msg(MERROR,
"scaler_mode",
"Error on reading control status of SIS3820, return code %x\n", status);
2424 cm_msg(MINFO,
"scaler_mode",
"SIS3820 control status reads: 0x%8.8x \n",control);
2429 cm_msg(MERROR,
"scaler_mode",
"Error on reading operation mode of SIS3820, return code %x\n", status);
2431 cm_msg(MINFO,
"scaler_mode",
"SIS3820 operation mode reads: 0x%8.8x \n",control);
2455 u_int32_t modid, control,
mode;
2460 cm_msg(MERROR,
"frontend_init",
2461 "Error on access to SIS3820 0x%8.8x, key reset failed, return code %x\n", module_address, status);
2471 cm_msg(MERROR,
"frontend_init",
2472 "Error on access to SIS3820, couldn't get module info, return code %x\n", status);
2476 cm_msg(MINFO,
"frontend_init",
"SIS3820 modid and firmware = 0x%8.8x", modid);
2477 cm_msg(MINFO,
"frontend_init",
"SIS3820 control status = 0x%8.8x", control);
2478 cm_msg(MINFO,
"frontend_init",
"SIS3820 operation mode = 0x%8.8x", mode);
2484 cm_msg(MERROR,
"frontend_init",
2485 "Error on access to SIS3820, key enable failed, return code %x\n", status);
2489 cm_msg(MINFO,
"frontent_init",
"SIS3820 enabled for counting");
2508 #ifdef HAVE_TEST_RUN
2514 cm_msg(MINFO,
"init_v1190",
"V1190 Module Reset: return_code = 0x%08x", return_code );
2516 if ( return_code != 0x0 )
return FE_ERR_HW;
2521 cm_msg(MINFO,
"init_v1190",
"V1190 Set_Detection: return_code = 0x%08x", return_code );
2523 if ( return_code != 0x0 )
return FE_ERR_HW;
2525 cm_msg(MINFO,
"init_v1190",
"V1190 Set_to_Leading_Edge: return_code = 0x%08x", return_code );
2527 if ( return_code != 0x0 )
return FE_ERR_HW;
2532 cm_msg(MINFO,
"init_v1190",
"V1190 Set_LSB: return_code = 0x%08x", return_code );
2534 if ( return_code != 0x0 )
return FE_ERR_HW;
2536 cm_msg(MINFO,
"init_v1190",
"V1190 Set_LSB_200ps: return_code = 0x%08x", return_code );
2538 if ( return_code != 0x0 )
return FE_ERR_HW;
2544 cm_msg(MINFO,
"init_v1190",
"V1190 Disable all channels: return_code = 0x%08x", return_code);
2551 cm_msg(MINFO,
"init_v1190",
"V1190 Set_Continuous storage: return_code = 0x%08x", return_code );
2554 if ( return_code != 0x0 )
return FE_ERR_HW;
2559 cm_msg(MINFO,
"init_v1190",
"V1190 Set_Almost_Full_Level: return_code = 0x%08x", return_code );
2565 cm_msg(MINFO,
"init_v1190",
"V1190 Control_Register: return_code = 0x%08x", return_code );
2570 cm_msg(MINFO,
"init_v1190",
"V1190 Almost Full Level: return_code = 0x%08x", return_code);
2571 cm_msg(MINFO,
"init_v1190",
"V1190 Almost Full Level: data = 0x%04x", data );
2575 cm_msg(MINFO,
"init_v1190",
"V1190 Modul status: return_code = 0x%08x", return_code);
2576 cm_msg(MINFO,
"init_v1190",
"V1190 Modul status: data = 0x%04x", data );
2580 cm_msg(MINFO,
"init_v1190",
"V1190 Control Register: return_code = 0x%08x", return_code);
2581 cm_msg(MINFO,
"init_v1190",
"V1190 Control Register: data = 0x%04x", data );
2584 if ( return_code != 0x0 )
return FE_ERR_HW;
2595 struct timeval tvNowTime, tvDiffTime;
2597 gettimeofday(&tvNowTime, 0);
2599 timersub(&tvNowTime, &
tvLastTime, &tvDiffTime);
2602 s3100_control_write(
hdev, 0x80, 1<<28);
2609 timersub(&tvNowTime, &
tvLastTime, &tvDiffTime);
2612 s3100_control_write(
hdev, 0x80, 1<<29);
double frontend_loop_counts
#define TD_EVENT
Event flags.
#define HV_DETECTORS_EVENT_STR(_name)
#define V1190_SET_TR_LEAD_LSB
#define BEAMLINE_EVENT_STR(_name)
static struct timeval tvLastTime
double keysight_u8481a_timestamp
#define HV_EVENT_STR(_name)
const char * frontend_name
< created by ODBedit, command "make"
INT max_event_size
maximum event size produced by this frontend
#define ALMOST_FULL_LEVEL
VME_STATS vme_stats
Required ODB structures.
LEMVAC_EVENT lemvac_event
SCALER_SETTINGS scaler_settings
double channelCounts[N_TDC_CHANNELS]
#define SCS2001M_EVENT_STR(_name)
static TDC_PILEUP tdc_pileup
#define HV_DETECTORS_SETTINGS_STR(_name)
#define SIS3820_ADDRESS_0
Local definitions to connect to VME module.
static DWORD dataWindowFastMuon
double tektronix_set_power
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
#define LEMVAC_SETTINGS_STR(_name)
UINT32 tof_bc_pileup_window
struct TRIGGER_SETTINGS::@20 event_2_settings
#define V1190_ALMFULL_BIT
INT display_period
a frontend status page is displayed with this frequency in ms
static DWORD dataWindowSlowMuon
INT read_scaler_event(char *pevent, INT off)
DWORD doEvaluateFastMuonEvent
M1 = 0x10, M1-e+ = 0x20.
int sis3820_key_disable(int device, u_int32_t sis3820_base)
double tektronix_timestamp
BOOL check_positron(INT decWindow, INT coincWindow, INT firstCh, INT lastCh, INT masterChannel, INT masterIndex, INT *channel, INT *ind)
INT event_buffer_size
buffer size to hold events
U_LONG endBeamCounterEvent
#define HV_SETTINGS_STR(_name)
#define SAMPLECRYO_SETTINGS_STR(_name)
#define SIS3820_CONTROL_INPUT_MODE3
#define N_HITS
a single detector may have up to N_HITS hits for event evaluation
BOOL check_tof_and_pileup(INT timing, INT tofWindow, INT firstCh, INT lastCh, INT masterChannel, INT masterIndex, INT *channel, INT *ind)
INT evaluate_slow_muon_event()
static DWORD * databuffer
ring buffer for TDC data
#define V1190_MODULE_RESET
static INT hdev
handle for VME-PCI device
static BOOL flag_scaler_address_0
#define SIS3820_SCALER_DATA_FORMAT_32BIT
#define EXTON1_FLAG
flag for "red/green", "on/off" mode: ON
#define SIS3820_CONTROL_INPUT_MODE0
int sis3820_key_enable(int device, u_int32_t sis3820_base)
DWORD doEvaluateSlowMuonEvent
bit pattern for trigger condition:
INT pileup[N_TDC_CHANNELS][N_HITS]
save information for each hit if it had a pre pileup or not
double keysight_u2002a_timestamp
double ana_pico_timestamp
#define V1190_CONTROL_REGISTER
INT mode
scaler mode, see scaler_mode()
#define SIS3820_SCALER_DATA_FORMAT_24BIT
static U_LONG runTime
absolute run time in TDC LSB units
INT foundChannel[N_TDC_CHANNELS]
count appearance of channel i
INT read_trigger_event(char *pevent, INT off)
INT evaluate_fast_muon_event()
double keysight_u2002a_measured_power
unsigned long long U_LONG
GNU C-Compiler 64bit integer.
int init_v1190(u_int32_t module_address)
INT lastBeamCounterEventPileup
#define TDC_BIT_RANGE
2^19 is the bit range of the TDC in 100ps and 200ps mode
static BOOL flag_scaler_address_1
flags to indicate status of VME scalers
#define V1190_DISABLE_ALL_CHANNEL
static TDC_EVAL_EVENT tdc_eval_event
static U_LONG nextGoodTime
absolute run time when new events are accepted (for on/off mode)
static DWORD masterChannelSlowMuon
"master" TDC channel for slow muons (TD or M2)
#define CTRL_REFERENCE_CH1_DISABLE
#define VME_STATS_STR(_name)
#define MODCRYO_EVENT_STR(_name)
INT lastMasterEvent1or2Pileup
static DWORD eventDefinedFastMuon
bit pattern containing trigger mode for fast muons (BC-M1)
INT begin_of_run(INT run_number, char *error)
int sis3820_operation_mode_read(int device, u_int32_t sis3820_base, u_int32_t *mode)
static DWORD eventDefinedSlowMuon
bit pattern containing trigger mode for slow muons (BC-TD-M2)
INT set_t0
flag indicating if t0 has been set
TRIGGER_SETTINGS trigger_settings
int sis3820_operation_mode_write(int device, u_int32_t sis3820_base, u_int32_t mode)
struct TRIGGER_SETTINGS::@17 events
#define TRIGGER_SETTINGS_STR(_name)
U_LONG endMasterEvent0
U_LONG==unsigned long long, GNU C-compiler 64bit integer.
U_LONG pileup_end(INT pileupWindow)
int sis3820_control_read(int device, u_int32_t sis3820_base, u_int32_t *control_status)
struct TRIGGER_SETTINGS::@19 event_1_settings
#define DATABUFFER_SIZE
set size of FiFo (ring) buffer, 2^17
#define MAX_NUMBER_LWORDS
max number of block data transfer */
static DWORD * p_write
read and write pointers for data ring buffer
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
INT tdc_data[N_TDC_CHANNELS *DATA_N_HITS]
this array is actually the Midas event
#define V1190_STATUS_REGISTER
INT resume_run(INT run_number, char *error)
INT read_slowcontrol_event(char *pevent, INT off)
#define V1190_EDGE_LEADING_MODE
#define M1_POSITRON_EVENT
double tektronix_set_frequency
HV_DETECTORS_EVENT hvdet_event
UINT32 delay_offpuls_usec_
INT do_master_channel(INT ch, INT event_type)
static BOOL flag_on_puls
flag to indicate that "puls" was turned on, "on/off" or "red/green" mode
double frontend_loop_readtdc
MODCRYO_EVENT moddy_event
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
#define DATA_N_HITS
max. of DATA_N_HITS in data file
#define EVENT_1_TYPE
Event type 1 = (BC)-TD-MC2-(e+)
char sample_cryo[NAME_LENGTH]
#define LEMVAC_EVENT_STR(_name)
#define MODCRYO_SETTINGS_STR(_name)
MICROWAVE_LOG microwave_log
#define CTRL_REFERENCE_CH1_ENABLE
static BOOL flag_external_on
flag to indicate "on/off", "red/green" mode
#define EXTOFF1_FLAG
flag for "red/green", "on/off" mode: OFF
INT event_time
absolute time in event after reset of structure
BEAMLINE_EVENT beamline_event
for slow control parameters
#define V1190_SOFTWARE_CLEAR
INT lastMasterEvent0Pileup
INT do_channel(INT ch, INT time)
UINT32 period_onpuls_usec_
#define V1190_ALMOST_FULL_LEVEL
#define V1190_OUTPUT_BUFFER_SIZE
void scaler_mode(u_int32_t module_address)
BOOL equipment_common_overwrite
int sis3820_key_reset(int device, u_int32_t sis3820_base)
#define N_TDC_CHANNELS
number of TDC channels
static INT rate[N_SCALER]
#define LE_POSITRON_EVENT
INT end_of_run(INT run_number, char *error)
INT poll_event(INT source, INT count, BOOL test)
SCS2001M_EVENT scs2001m_event
#define SCALER_SETTINGS_STR(_name)
#define SAMPLECRYO_EVENT_STR(_name)
#define N_SCALER
total number of scaler channels
#define N_SCALER_MODULE
number of channels of one scaler module
static DWORD masterChannelFastMuon
"master" TDC channel for BC-M1 (usually M1)
#define V1190_OPCODE_ADDRESS
#define SCS2001M_SETTINGS_STR(_name)
#define EXP_PARAM_STR(_name)
#define V1190_SET_DETECTION
#define EVENT_2_TYPE
Event type 2 = TD-e+-(BC), LE-muSR.
#define CLOCK
TDC channel assignments.
#define MASTERLAST
timing flags
#define BEAMLINE_SETTINGS_STR(_name)
int sis3820_scaler_read(int device, u_int32_t sis3820_base, int mode, int nwords, u_int32_t *data)
int sis3820_modid_read(int device, u_int32_t sis3820_base, u_int32_t *modid)
int init_sis3820(u_int32_t module_address)
SAMPLECRYO_EVENT sample_event
BOOL tdc_disable_atstartup
INT pause_run(INT run_number, char *error)
static DWORD masterFlagSlowMuon
use either TD_EVENT or M2_EVENT as slow muon master
double ana_pico_set_frequency
INT tdc_event[N_TDC_CHANNELS][N_HITS]
each channel may have up to N_HITS hits
int sis3820_control_write(int device, u_int32_t sis3820_base, u_int32_t control_status)
struct TRIGGER_SETTINGS::@18 event_0_settings
#define SIS3820_ADDRESS_1
VME address of 2nd scaler module.
double ana_pico_set_power
const char * frontend_file_name
The frontend file name, don't change it.
U_LONG endMasterEvent1or2
#define EVENT_0_TYPE
EVENT type 0 = BC-MCP1-(e+)
double keysight_u8481a_measured_power
#define V1190_ADDRESS
the VME address of the CAEN V1190 TDC