def check_bad_data(raw_data, prepend_data_headers=None, trig_count=None):
consecutive_triggers = <NUM_LIT:16> if trig_count == <NUM_LIT:0> else trig_count<EOL>is_fe_data_header = logical_and(is_fe_word, is_data_header)<EOL>trigger_idx = np.where(is_trigger_word(raw_data) >= <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>fe_dh_idx = np.where(is_fe_data_header(raw_data) >= <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>n_triggers = trigger_idx.shape[<NUM_LIT:0>]<EOL>n_dh = fe_dh_idx.shape[<NUM_LIT:0>]<EOL>if n_triggers:<EOL><INDENT>last_event_data_headers_cnt = np.where(fe_dh_idx > trigger_idx[-<NUM_LIT:1>])[<NUM_LIT:0>].shape[<NUM_LIT:0>]<EOL>if consecutive_triggers and last_event_data_headers_cnt == consecutive_triggers:<EOL><INDENT>if not np.all(trigger_idx[-<NUM_LIT:1>] > fe_dh_idx):<EOL><INDENT>trigger_idx = np.r_[trigger_idx, raw_data.shape]<EOL><DEDENT>last_event_data_headers_cnt = None<EOL><DEDENT>elif last_event_data_headers_cnt != <NUM_LIT:0>:<EOL><INDENT>fe_dh_idx = fe_dh_idx[:-last_event_data_headers_cnt]<EOL><DEDENT>elif not np.all(trigger_idx[-<NUM_LIT:1>] > fe_dh_idx):<EOL><INDENT>trigger_idx = np.r_[trigger_idx, raw_data.shape]<EOL><DEDENT><DEDENT>elif n_dh:<EOL><INDENT>trigger_idx = np.r_[trigger_idx, raw_data.shape]<EOL>last_event_data_headers_cnt = None<EOL><DEDENT>else:<EOL><INDENT>return False, prepend_data_headers, n_triggers, n_dh<EOL>
Checking FEI4 raw data array for corrupted data.