13 m_verb(0), m_online(true), m_go_end(false), m_handle(-1), m_run(0)
20 if (! file_exists(fname)) {
21 cerr <<
"!!ERROR!! Coda file does not exist: " << fname <<
"." << endl;
29 for (
int i_wait = 0; i_wait < n_wait + 1; i_wait++) {
30 FILE* fp = fopen (fname.c_str(),
"r");
32 cout <<
"Failed at fopen() with errno=" << errno <<
"." << endl;
34 if (fseek(fp, 0L, SEEK_END) != 0) {
35 cout <<
"Failed at fseek() with errno=" << errno <<
"." << endl;
37 m_file_size = ftell(fp);
39 if (m_file_size >= file_size_min) {
44 cout <<
"File size: " << m_file_size <<
" < " << file_size_min
45 <<
". Wait for " << sec_wait <<
" s (" << i_wait <<
")." << endl;
51 cout <<
"File size not enough (" << m_file_size <<
" < " << file_size_min <<
"). Wait timeout. Exiting..." << endl;
56 cout <<
"Loading " << fname <<
"..." << endl;
59 int ret =
evOpen((
char*)fname.c_str(), (
char*)
"r", &m_handle);
61 cout <<
"Failed at opening the Coda file. ret = " << ret <<
". Exiting..." << endl;
70 if (m_handle < 0)
return 0;
78 for (
int i_evt = 0; i_evt < n_evt; i_evt++) {
80 cout <<
"CodaInputManager::SkipCodaEvent(): Failed at i=" << i_evt <<
" (n=" << n_evt <<
")." << endl;
89 if (m_go_end)
return false;
90 int ret =
evRead(m_handle, m_event_words, buflen);
92 coda_id = m_event_count++;
93 words = m_event_words;
97 if (m_online && m_run > 0) {
98 cout <<
"No new event seems available for now. Try to recover." << endl;
100 cout <<
"Exiting since the END file exists." << endl;
106 cout <<
"Exiting since the next run file exists." << endl;
111 int event_count = m_event_count;
112 ret =
OpenFile(m_fname, m_file_size + 32768, 10, 20);
116 cout <<
"OpenFile() returned " << ret <<
"." << endl;
119 cout <<
"CodaInputManager::NextCodaEvent(): Bad end." << endl;
124 bool CodaInputManager::file_exists(
const std::string fname)
126 FILE *fp = fopen(fname.c_str(),
"r");
145 shift = numBitFromRight;
147 hexBit = hexBit >> (4 * shift);
149 hexBit = hexBit & 0xF;
160 int get_hex_bits (
unsigned int hexNum,
int numBitFromRight,
int numBits)
162 unsigned int hexBits = 0x0;
164 unsigned int bitwiseand = 0xF;
165 unsigned int eff = 0xF;
169 shift = numBitFromRight - numBits + 1;
171 hexBits = hexBits >> (4 * shift);
176 for (i = 1; i < numBits; i++)
178 bitwiseand += (eff << (4 * i) );
182 hexBits = hexBits & bitwiseand;
195 while (numBitFromRight--)
211 int get_bin_bits (
unsigned int binNum,
int numBitFromRight,
int numBits)
218 for (n = 0; n < (numBits - 1); n++)
223 for (n = 0; n < (numBits) && n <= numBitFromRight; n++)
225 binBit =
get_bin_bit (binNum, numBitFromRight - n);
226 binBits += binBit * d;
235 cerr <<
"!!ERROR!! " << message << endl;
239 void PrintWords(
int* words,
int idx_begin,
int idx_end,
int idx_atte)
241 cout <<
" PrintWords[" << idx_begin <<
"-" << idx_end <<
"]:\n";
242 for (
int idx = idx_begin; idx < idx_end; idx++) {
243 if (idx % 5 == 0) cout <<
"\n " << setw(6) << idx <<
": ";
244 cout <<
" " << hex << setw(8) << words[idx] << dec;
245 if (idx == idx_atte) cout <<
"!";
262 cout <<
" Event code = " << hex << code
265 << dec <<
" (" << n_wd <<
")" << endl;
268 int n_wd_roc = words[idx ];
270 cout <<
" ROC " << setw(2) << roc_id <<
" (" << n_wd_roc <<
") |";
271 int idx_roc_end = idx + n_wd_roc + 1;
273 while (idx < idx_roc_end) {
274 int e906flag = words[idx];
275 if (e906flag == (
int)0xe906c0da) {
282 bool is_flag = (flag_hi == (int)0xe906);
286 bool has_dummy = (words[idx+2] == (int)0xe906e906);
287 idx += n_wd_bd + (has_dummy ? 3 : 2);
288 bool overflow_n_wd = (idx > idx_roc_end);
289 cout << hex <<
" " << (is_flag ?
"" :
"?") << flag_lo <<
":" << board_id
290 << dec <<
"(" << n_wd_bd <<
")";
291 if (overflow_n_wd) cout <<
"OF";
293 if (idx < idx_roc_end) cout <<
" | UF";
294 else if (idx > idx_roc_end) cout <<
" | OF";
static std::string GetCodaFilePath(const int run)
int evOpen(char *fname, char *flags, int *handle)
int evRead(int handle, int *buffer, int buflen)
static std::string GetEndFilePath(const int run)