00001 #ifndef ALGO_TRIG_DECODER_CC
00002 #define ALGO_TRIG_DECODER_CC
00003
00004 #include "algo_trig_decoder.hh"
00005
00006 algo_trig_decoder::algo_trig_decoder() : algo_base() {
00007 _name="algo_trig_decoder";
00008 _data=0;
00009 reset();
00010 }
00011
00012
00013 bool algo_trig_decoder::process_word(PMT::word_t word) {
00014
00015 bool status=true;
00016
00017
00018 if(_bt_mode){
00019
00020
00021 if(!_bt_nwords_filled)
00022 _bt_nwords_filled = (_bt_nwords == _bt_words.size());
00023
00024
00025 if(_bt_nwords_filled)
00026 _bt_words.pop_front();
00027
00028
00029 _bt_words.push_back(word);
00030
00031 }
00032
00033 if(!_data){
00034 _data=(trig_info*)(_storage->get_data(DATA_STRUCT::TRIG_INFO));
00035 if(!_data){
00036 Message::send(MSG::ERROR,__FUNCTION__,
00037 "Could not retrieve writeable trig_info pointer!");
00038 return false;
00039 }
00040 }
00041
00042 _trigger_words[_trigger_word_count]=word;
00043
00044 _trigger_word_count++;
00045
00046 if(_trigger_word_count==TRIGGER_WORD_COUNT) {
00047
00048
00049
00050 if(_trigger_words[(TRIGGER_WORD_COUNT - 1)] != TRIGGER_LAST_WORD) {
00051
00052 Message::send(MSG::ERROR,__FUNCTION__,
00053 Form(" Invalid end-of-trigger-data word: %x (event %d)",
00054 _trigger_words[_trigger_word_count-1],_last_event_id));
00055
00056 status = false;
00057
00058 if(_debug_mode) {
00059
00060 std::string msg("Currently in memory: ");
00061
00062 for(size_t i=0; i<TRIGGER_WORD_COUNT; ++i) {
00063
00064 msg += Form("%08x ",_trigger_words[i]);
00065
00066 if( (i+1) < TRIGGER_WORD_COUNT)
00067
00068 _trigger_words[i]=_trigger_words[i+1];
00069
00070 }
00071
00072 Message::send(MSG::WARNING,__FUNCTION__,
00073 Form("%s ... Continue by shifting a data word...",msg.c_str()));
00074
00075 _trigger_word_count-=1;
00076
00077 }
00078
00079 }else{
00080
00081 decode_trigger_words(_trigger_words);
00082
00083 _storage->next_event();
00084
00085 clear_event_info();
00086 }
00087 }
00088
00089 _nwords+=1;
00090 _checksum+=word;
00091
00092 return status;
00093 }
00094
00095 bool algo_trig_decoder::decode_trigger_words(PMT::word_t *trigger_words){
00096
00097 _data->set_trig_timeslice( (trigger_words[0]>>4) & 0xfff );
00098 _data->set_trig_frame_id( ((trigger_words[1] & 0xff)<<16) + (trigger_words[0]>>16) );
00099 _data->set_trig_id( (trigger_words[1]>>8) );
00100 _data->set_pmt_data( trigger_words[2] & 0xff );
00101
00102 _data->set_trigger_bits( (trigger_words[2]>>8 & 0x1),
00103 (trigger_words[2]>>9 & 0x1),
00104 (trigger_words[2]>>10 & 0x1),
00105 (trigger_words[2]>>12 & 0x1),
00106 (trigger_words[2]>>11 & 0x1),
00107 (trigger_words[2]>>13 & 0x1),
00108 (trigger_words[2]>>14 & 0x1) );
00109
00110 _data->set_reminder_64MHz((trigger_words[2]>>15 & 0x3));
00111 _data->set_reminder_16MHz((trigger_words[0]>>1 & 0x7));
00112
00113 if(_verbosity[MSG::INFO]){
00114 std::ostringstream msg;
00115 msg << std::endl << "Decoded words: ";
00116 for(size_t i=0; i<TRIGGER_WORD_COUNT; ++i)
00117 msg << Form("0x%08x ",trigger_words[i]) ;
00118 msg
00119 << std::endl
00120 << Form("Trigger id : %d",_data->trig_id()) << std::endl
00121 << Form("Frame id : %d",_data->trig_frame_id()) << std::endl
00122 << Form("Sample id : %d",_data->trig_timeslice()) << std::endl
00123 << Form("PC : %d",_data->trig_pc()) << std::endl
00124 << Form("EXT : %d",_data->trig_ext()) << std::endl
00125 << Form("Active : %d",_data->active()) << std::endl
00126 << Form("Gate 1 : %d",_data->gate1()) << std::endl
00127 << Form("Gate 2 : %d",_data->gate2()) << std::endl
00128 << Form("Veto : %d",_data->veto_in()) << std::endl
00129 << Form("Calib : %d",_data->calib()) << std::endl
00130 << std::endl;
00131 Message::send(MSG::INFO,__FUNCTION__,msg.str());
00132 }
00133
00134 if(_data->trig_id() && _data->trig_id() != (_last_event_id+1))
00135
00136 Message::send(MSG::WARNING,__FUNCTION__,
00137 Form("Processed event %d while the last event ID was %d ... missing %d!",
00138 _data->trig_id(),
00139 _last_event_id,
00140 (_last_event_id+1)));
00141
00142 _last_event_id = _data->trig_id();
00143
00144 return true;
00145 }
00146
00147 void algo_trig_decoder::reset(){
00148
00149 init_checker_info();
00150 clear_event_info();
00151 algo_base::reset();
00152
00153 }
00154
00155 void algo_trig_decoder::clear_event_info(){
00156
00157 _trigger_word_count=0;
00158
00159 for(size_t i=0; i<TRIGGER_WORD_COUNT; ++i)
00160 _trigger_words[i]=0x0;
00161
00162 }
00163
00164
00165 bool algo_trig_decoder::check_event_quality() {
00166
00167 return (_trigger_word_count == TRIGGER_WORD_COUNT);
00168 }
00169
00170 #endif