/* * BufferSubscriber.cpp * * Created on: Dec 14, 2017 * Author: hovanes */ #include "stdio.h" #include "BufferSubscriber.hh" namespace VETROC { void decodeData( unsigned int data ) { struct vetroc_data_struct { // We're told the VETROC is similar to FADC, so I copied that struct; // but surely some of this is not used unsigned int new_type; unsigned int type; unsigned int slot_id_hd; unsigned int slot_id_tr; unsigned int slot_id_evh; unsigned int n_evts; unsigned int blk_num; unsigned int modID; unsigned int PL; unsigned int NSB; unsigned int NSA; unsigned int n_words; unsigned int evt_num_1; unsigned int evt_num_2; unsigned int time_now; unsigned int time_1; unsigned int time_2; unsigned int time_3; unsigned int time_4; unsigned int chan; unsigned int width; unsigned int valid_1; unsigned int adc_1; unsigned int valid_2; unsigned int adc_2; unsigned int over; unsigned int adc_sum; unsigned int pulse_num; unsigned int thres_bin; unsigned int quality; unsigned int integral; unsigned int time; unsigned int chan_a; unsigned int source_a; unsigned int chan_b; unsigned int source_b; unsigned int group; unsigned int time_coarse; unsigned int time_fine; unsigned int vmin; unsigned int vpeak; unsigned int trig_type_int; unsigned int trig_state_int; unsigned int evt_num_int; unsigned int err_status_int; unsigned int scaler_data_words; }; static struct vetroc_data_struct vetroc_data; bool i_print = true ; // Routine from B. Moffit for FADC. Here we attempt to adapt for VETROC. // int i_print = 1; static unsigned int type_last = 15; /* initialize to type FILLER WORD */ static unsigned int time_last = 0; static unsigned int iword = 0; // Note, vetroc_data_struct vetroc_data is global, see top of code // if ( i_print ) printf( "%3d: ", iword++ ); if ( data & 0x80000000 ) /* data type defining word */ { vetroc_data.new_type = 1; vetroc_data.type = (data & 0x78000000) >> 27; } else { vetroc_data.new_type = 0; vetroc_data.type = type_last; } switch ( vetroc_data.type ) { case 0: /* BLOCK HEADER */ vetroc_data.slot_id_hd = ((data) & 0x7C00000) >> 22; vetroc_data.n_evts = (data & 0x3FF800) >> 11; vetroc_data.blk_num = (data & 0x7FF); if ( i_print ) printf( "%8X - BLOCK HEADER - slot = %d n_evts = %d n_blk = %d\n", data, vetroc_data.slot_id_hd, vetroc_data.n_evts, vetroc_data.blk_num ); break; case 1: /* BLOCK TRAILER */ vetroc_data.slot_id_tr = (data & 0x7C00000) >> 22; vetroc_data.n_words = (data & 0x3FFFFF); if ( i_print ) printf( "%8X - BLOCK TRAILER - slot = %d n_words = %d\n", data, vetroc_data.slot_id_tr, vetroc_data.n_words ); break; case 2: /* EVENT HEADER */ if ( vetroc_data.new_type ) { vetroc_data.evt_num_1 = (data & 0x7FFFFFF); // if ( 1 ) if ( i_print ) printf( "%08X - EVENT HEADER 1 - evt_num = %d\n", data, vetroc_data.evt_num_1 & 0xFFFFF ); } // else { // vetroc_data.evt_num_2 = (data & 0x7FFFFFF); // if ( 1 ) //// if ( i_print ) // printf( "%8X - EVENT HEADER 2 - evt_num = %d\n", data, vetroc_data.evt_num_2 ); // } break; case 3: /* TRIGGER TIME */ if ( vetroc_data.new_type ) { vetroc_data.time_1 = (data & 0xFFFFFF); if ( i_print ) // if ( 1 ) printf( "%8X - TRIGGER TIME 1 - time = %08x\n", data, vetroc_data.time_1 ); vetroc_data.time_now = 1; time_last = 1; } else { if ( time_last == 1 ) { vetroc_data.time_2 = (data & 0xFFFFFF); if ( i_print ) printf( "%8X - TRIGGER TIME 2 - time = %08x\n", data, vetroc_data.time_2 ); vetroc_data.time_now = 2; } else if ( time_last == 2 ) { vetroc_data.time_3 = (data & 0xFFFFFF); if ( i_print ) printf( "%8X - TRIGGER TIME 3 - time = %08x\n", data, vetroc_data.time_3 ); vetroc_data.time_now = 3; } else if ( time_last == 3 ) { vetroc_data.time_4 = (data & 0xFFFFFF); if ( i_print ) printf( "%8X - TRIGGER TIME 4 - time = %08x\n", data, vetroc_data.time_4 ); vetroc_data.time_now = 4; } else if ( i_print ) printf( "%8X - TRIGGER TIME - (ERROR)\n", data ); time_last = vetroc_data.time_now; } break; case 4: /* nothing yet */ case 5: case 6: case 7: break; case 8: /* PULSE TIME */ vetroc_data.chan = (data & 0x7800000) >> 23; vetroc_data.pulse_num = (data & 0x600000) >> 21; vetroc_data.quality = (data & 0x180000) >> 19; vetroc_data.time = (data & 0xFFFF); if ( i_print ) printf( "%8X - PULSE TIME - chan = %d pulse # = %d quality = %d time = %d\n", data, vetroc_data.chan, vetroc_data.pulse_num, vetroc_data.quality, vetroc_data.time ); break; case 9: /* nothing yet */ case 10: case 11: case 12: break; case 13: /* END OF EVENT */ if ( i_print ) printf( "%8X - END OF EVENT = %d\n", data, vetroc_data.type ); break; case 14: /* DATA NOT VALID (no data available) */ if ( i_print ) printf( "%8X - DATA NOT VALID = %d\n", data, vetroc_data.type ); break; case 15: /* FILLER WORD */ if ( i_print ) printf( "%8X - FILLER WORD = %d\n", data, vetroc_data.type ); break; } type_last = vetroc_data.type; /* save type of current data word */ } } /* namespace VETROC */