#include <Decoder-TypeDef.hh>#include <Algorithm-TypeDef.hh>#include <vector>#include <TString.h>#include <cstdlib>Go to the source code of this file.
Functions | |
| void | print_word (std::vector< PMT::word_t > *in_array) |
| int | main (int argc, char **argv) |
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 8 of file xmit_search_event.cc.
References FORMAT::ASCII, FORMAT::BINARY, bin_io_handler::close(), bin_io_handler::eof(), MSG::ERROR, PMT::INVALID_WORD, bin_io_handler::is_open(), MSG::NORMAL, bin_io_handler::open(), print_word(), bin_io_handler::READ, bin_io_handler::read_word(), Message::send(), bin_io_handler::set_filename(), bin_io_handler::set_format(), and bin_io_handler::set_mode().
00008 { 00009 00010 00011 if ( argc < 3) 00012 { 00013 std::cerr << std::endl 00014 << Form("Usage: %s [FLAG] [ARG]",argv[0]) << std::endl << std::endl 00015 << "Mandatory flags:" << std::endl 00016 << "-i [input file] ... specify input filename (full or relative path) here." << std::endl 00017 << "-n [event id] ... specify the target event id." << std::endl 00018 << std::endl 00019 << "Optional flags:" << std::endl 00020 << "-f [format] ... specify input file format. 0=binary (default), 1=ASCII." << std::endl 00021 00022 << "-c ... when specified, continues to EOF even after target event is found."<<std::endl 00023 << std::endl; 00024 exit(1); 00025 } 00026 00027 // Make this false if you wanna break after finding the target event. 00028 // Why make it true? => it helps to find possibly duplicated event id. 00029 bool read_through=false; 00030 bool bin_format=true; 00031 00032 bin_io_handler fin; 00033 fin.set_mode(bin_io_handler::READ); 00034 fin.set_format(FORMAT::BINARY); 00035 00036 PMT::word_t target_id = PMT::INVALID_WORD; 00037 00038 char c; 00039 while ( (c=getopt(argc,argv,"i:f:n:c")) != -1 ) { 00040 00041 switch (c) { 00042 case 'i': // input file location 00043 fin.set_filename(optarg); 00044 Message::send(MSG::NORMAL,__FUNCTION__,Form("Input file: %s",optarg)); 00045 break; 00046 case 'f': // input format 00047 if(std::atoi(optarg)==0) { 00048 fin.set_format(FORMAT::BINARY); 00049 Message::send(MSG::NORMAL,__FUNCTION__,"Set format: BINARY"); 00050 }else if(std::atoi(optarg)==1){ 00051 fin.set_format(FORMAT::ASCII); 00052 Message::send(MSG::NORMAL,__FUNCTION__,"Set format: ASCII"); 00053 }else{ 00054 Message::send(MSG::ERROR,__FUNCTION__, 00055 Form("Invalid argument for -f: %s",optarg)); 00056 exit(1); 00057 } 00058 break; 00059 case 'n': // target event_id 00060 target_id=(PMT::word_t)(std::atoi(optarg)); 00061 Message::send(MSG::NORMAL,__FUNCTION__, 00062 Form("Set target event ID: %d",target_id)); 00063 break; 00064 case 'c': 00065 read_through=true; 00066 Message::send(MSG::NORMAL,__FUNCTION__, 00067 "Throughout mode set ... continue scanning till the EOF."); 00068 break; 00069 } 00070 } 00071 00072 if(target_id==PMT::INVALID_WORD){ 00073 Message::send(MSG::ERROR,__FUNCTION__,"Event ID not specified!"); 00074 exit(1); 00075 } 00076 00077 target_id = (0xf0000000 + ((target_id & 0xfff) << 16) + 0x0000f000 + ((target_id >> 12) & 0xfff)); 00078 00079 const PMT::word_t key_header=0xffffffff; 00080 00081 std::vector<PMT::word_t> word_array(4,0); 00082 PMT::word_t word=0x0; 00083 bool fire=false; 00084 fin.open(); 00085 00086 if(!fin.is_open()) exit(1); 00087 00088 while(1){ 00089 00090 word = fin.read_word(); 00091 00092 if(fin.eof()) break; 00093 if(fire && word==key_header) { 00094 00095 word_array.push_back(word); 00096 00097 if(!read_through) break; 00098 00099 print_word(&word_array); 00100 00101 fire=false; 00102 word_array.clear(); 00103 word_array.reserve(4); 00104 word_array.push_back(0); 00105 word_array.push_back(0); 00106 word_array.push_back(0); 00107 word_array.push_back(0); 00108 } 00109 00110 if(!fire){ 00111 word_array[0]=word_array[1]; 00112 word_array[1]=word_array[2]; 00113 word_array[2]=word_array[3]; 00114 word_array[3]=word; 00115 00116 if(word_array[0]==key_header && word_array[3]==target_id){ 00117 fire=true; 00118 } 00119 }else 00120 word_array.push_back(word); 00121 } 00122 00123 if(!read_through){ 00124 print_word(&word_array); 00125 } 00126 00127 fin.close(); 00128 }
| void print_word | ( | std::vector< PMT::word_t > * | in_array | ) |
Definition at line 130 of file xmit_search_event.cc.
References PMT::CHANNEL_HEADER, PMT::CHANNEL_LAST_WORD, PMT::CHANNEL_WORD, PMT::EVENT_HEADER, PMT::EVENT_LAST_WORD, PMT::FEM_LAST_WORD, algo_xmit_decoder::get_word_class(), and PMT::UNDEFINED_WORD.
Referenced by main().
00130 { 00131 00132 algo_xmit_decoder algo; 00133 size_t ctr=0; 00134 std::string msg(""); 00135 00136 std::vector<PMT::word_t> word_array; 00137 word_array.reserve(in_array->size() * 2); 00138 for(std::vector<PMT::word_t>::const_iterator iter(in_array->begin()); 00139 iter!=in_array->end(); 00140 ++iter){ 00141 word_array.push_back( (*iter) & 0xffff); 00142 word_array.push_back( (*iter) >> 16 ); 00143 } 00144 00145 for(std::vector<PMT::word_t>::const_iterator iter(word_array.begin()); 00146 iter!=word_array.end(); 00147 ++iter){ 00148 00149 PMT::PMT_WORD word_type=algo.get_word_class((*iter)); 00150 00151 switch(word_type){ 00152 case PMT::UNDEFINED_WORD: 00153 case PMT::CHANNEL_WORD: 00154 msg+=Form(" %04x ",(*iter)); 00155 break; 00156 case PMT::EVENT_FIRST_HEADER: 00157 case PMT::EVENT_HEADER: 00158 case PMT::EVENT_LAST_WORD: 00159 msg+=" \033[93m"; 00160 msg+=Form("%04x ",(*iter)); 00161 msg+="\033[0m"; 00162 break; 00163 case PMT::FIRST_WORD: 00164 case PMT::FEM_LAST_WORD: 00165 msg+=" \033[91m"; 00166 msg+=Form("%04x ",(*iter)); 00167 msg+="\033[0m"; 00168 break; 00169 case PMT::CHANNEL_HEADER: 00170 case PMT::CHANNEL_LAST_WORD: 00171 msg+=" \033[95m"; 00172 msg+=Form("%04x ",(*iter)); 00173 msg+="\033[0m"; 00174 break; 00175 } 00176 ctr+=1; 00177 if(ctr && ctr%8==0){ 00178 std::cout<<msg.c_str()<<std::endl; 00179 msg=""; 00180 } 00181 } 00182 if(msg.size()>0) std::cout<<msg.c_str()<<std::endl; 00183 std::cout<<" ... continue to next event ... " <<std::endl; 00184 }
1.4.7