10 : m_file_size_min(32768), m_sec_wait(15), m_n_wait(40)
21 if (coda )
delete coda;
22 if (list_sd )
delete list_sd;
23 if (list_ed )
delete list_ed;
24 if (list_ed_now)
delete list_ed_now;
29 m_file_size_min = file_size_min;
30 m_sec_wait = sec_wait;
34 return coda->
OpenFile(fname, file_size_min, sec_wait, n_wait);
39 static EventDataMap::iterator it = list_ed_now->begin();
40 if (it == list_ed_now->end()) {
42 while (list_ed_now->size() == 0 && ! coda->
IsEnded()) {
45 it = list_ed_now->begin();
47 if (it != list_ed_now->end()) {
61 int MainDaqParser::ParseOneSpill()
63 static bool call_1st =
true;
64 if (call_1st) call_1st =
false;
66 cout <<
"...sleep(" <<
dec_par.
time_wait <<
") to pretend waiting for next spill..." << endl;
68 cout <<
"...done." << endl;
76 int evt_type_id = event_words[1];
80 switch (evt_type_id & 0xFFFF) {
82 ret = ProcessCodaPhysics(event_words);
85 switch (evt_type_id) {
87 ret = ProcessCodaPrestart(event_words);
95 cerr <<
"!!ERROR!! Uncovered Coda event type: " << evt_type_id <<
". Exit." << endl;
100 ret = ProcessCodaFee(event_words);
110 cerr <<
"!!ERROR!! Uncovered Coda event type: " << evt_type_id <<
". Exit." << endl;
114 cout <<
"WARNING: ParseOneSpill(): ret = " << ret << endl;
130 cout <<
"\nStatistics in MainDaqParser:\n"
131 <<
" Phys events: all = " << run_data.
n_phys_evt <<
"\n"
132 <<
" Flush events: all = " << run_data.
n_flush_evt <<
"\n"
134 <<
" Real events: all = " << run_data.
n_evt_all <<
", decoded = " << run_data.
n_evt_dec <<
"\n"
135 <<
" TDC hits: total = " << run_data.
n_hit <<
", bad = " << run_data.
n_hit_bad <<
"\n"
136 <<
" v1495 hits: total = " << run_data.
n_t_hit <<
", bad = " << run_data.
n_t_hit_bad <<
"\n"
151 int MainDaqParser::ProcessCodaPrestart(
int* words)
167 int MainDaqParser::ProcessCodaFee(
int* words)
170 cerr <<
"!!ERROR!! Not FEE_EVENT in case of FEE_PREFIX: " << words[1] <<
". Exit." << endl;
174 if (words[3] == (
int)0xe906f011) {
175 return ProcessCodaFeeBoard(words);
176 }
else if (words[3] == (
int)0xe906f012) {
178 return ProcessCodaFeePrescale(words);
184 int MainDaqParser::ProcessCodaFeeBoard(
int* words)
224 run_data.
fee.push_back(data);
226 cout <<
" feeE " << data.
roc <<
" " << data.
board <<
" " << data.
hard
238 int MainDaqParser::ProcessCodaFeePrescale(
int* words)
241 int feeTriggerBits = words[4];
243 for (
int ii = 0; ii < 10; ii++) {
247 for (
int ii = 0; ii < 5; ii++) run_data. nim_enabled[ii] =
get_bin_bit (feeTriggerBits, ii+5);
250 for (
int ii = 0; ii < 8; ii++) {
251 run_data.
prescale[ii] = words[ii + 5];
253 for (
int ii = 0; ii < 5; ii++) run_data.
fpga_prescale[ii] = words[ii + 5];
254 for (
int ii = 0; ii < 3; ii++) run_data. nim_prescale[ii] = words[ii + 10];
259 for (
int ii = 0; ii < 10; ii++) cout <<
" " << run_data.
trig_bit[ii];
261 for (
int ii = 0; ii < 8; ii++) cout <<
" " << run_data.
prescale[ii];
277 int MainDaqParser::ProcessCodaPhysics(
int* words)
280 int eventCode = words[1];
289 ret = ProcessPhysFlush(words);
293 ret = ProcessPhysSlow(words);
296 ret = ProcessPhysPrestart(words);
306 ret = ProcessPhysSpillCounter(words);
309 ret = ProcessPhysRunDesc(words);
312 ret = ProcessPhysBOSEOS(words,
TYPE_BOS);
315 ret = ProcessPhysBOSEOS(words,
TYPE_EOS);
319 cout <<
"Unknown event code: " << eventCode <<
". Ignore." << endl;
326 int MainDaqParser::ProcessPhysRunDesc(
int* words)
329 int evLength = words[0];
331 for (
int i_wd = 4; i_wd < (evLength + 1); i_wd++) {
332 unsigned int number = words[i_wd];
333 for (
int ii = 0; ii < 4; ii++) {
334 char word = (char)(number & 0xFF);
335 if (word == 0x22) word = 0x27;
337 number = number >> 8;
342 cout <<
" run desc: " << desc.length() <<
" chars." << endl;
349 int MainDaqParser::ProcessPhysPrestart(
int* words)
351 int evLength = words[0];
352 vector<string> list_line;
354 for (
int i_wd = 4; i_wd < (evLength + 1); i_wd++) {
355 unsigned int number = words[i_wd];
356 for (
int ii = 0; ii < 4; ii++) {
357 if ((number & 0xFF) ==
'\n') {
358 list_line.push_back(line);
361 line += (char)(number & 0xFF);
363 number = number >> 8;
366 if (line.length() > 0) list_line.push_back(line);
367 else cerr <<
"Unexpectedly line.length() == 0." << endl;
368 for (
unsigned int ii = 0; ii < list_line.size(); ii++) {
369 cout <<
" pre " << list_line[ii] << endl;
389 int MainDaqParser::ProcessPhysSlow(
int* words)
392 int evLength = words[0];
395 vector<string> list_line;
397 for (
int i_wd = 4; i_wd < (evLength + 1); i_wd++) {
398 unsigned int number = words[i_wd];
399 for (
int ii = 0; ii < 4; ii++) {
400 if ((number & 0xFF) ==
'\n') {
401 list_line.push_back(line);
404 line += (char)(number & 0xFF);
406 number = number >> 8;
409 if (line.length() > 0) list_line.push_back(line);
410 else cout <<
"WARNING: Unexpectedly line.length() == 0." << endl;
412 std::vector<SlowControlData> list_data;
413 for (
unsigned int ii = 0; ii < list_line.size(); ii++) {
414 istringstream iss(list_line[ii]);
415 string ts, name, value, type;
416 iss >> ts >> name >> value >> type;
425 list_data.push_back(data);
429 for (
unsigned int ii = 0; ii < list_data.size(); ii++) {
432 if ( data->
type ==
"target" &&
433 (data->
name ==
"TARGPOS_CONTROL" ||
434 data->
name.substr(0, 4) ==
"FREQ" ||
435 data->
name.substr(0, 4) ==
"PROX" ||
436 data->
name.substr(0, 5) ==
"TARG_" ) ) {
439 SpillData* spill_data = &(*list_sd)[spill_id];
456 int MainDaqParser::ProcessPhysSpillCounter(
int* words)
461 for (
int i_wd = 4; i_wd < n_wd + 1; i_wd++) {
462 int number = words[i_wd];
463 for (
int i_byte = 0; i_byte < 4; i_byte++) {
464 spillNum[i_wd_sc++] = (char)(number & 0xFF);
465 number = number >> 8;
468 spillNum[i_wd_sc] =
'\0';
481 int MainDaqParser::ProcessPhysBOSEOS(
int* words,
const int type)
483 string type_str = (type ==
TYPE_BOS ?
"BOS" :
"EOS");
487 if (PackOneSpillData() != 0) {
488 cout <<
"Error submitting data. Exiting..." << endl;
495 static int spillID_local = 0;
518 int evLength = words[0];
519 while (idx < evLength && (words[idx] & 0xfffff000) != 0xe906f000) {
520 int rocEvLength = words[idx];
521 int idx_roc_end = idx + rocEvLength;
522 if ( (rocEvLength + idx) > evLength) {
523 cout <<
"Word limit error: " << rocEvLength <<
" + " << idx <<
" > " << evLength << endl;
530 int codaEvVmeTime = words[idx];
546 if (type !=
TYPE_BOS && rocID == 25) idx = idx_roc_end + 1;
550 if (rocEvLength <= 6) idx = idx_roc_end + 1;
552 while (idx <= idx_roc_end) {
553 int e906flag = words[idx];
556 idx = ProcessBoardData (words, idx, idx_roc_end, e906flag);
557 if (idx == -1)
return 0;
569 int MainDaqParser::ProcessPhysFlush(
int* words)
571 const bool print_event =
false;
572 int evLength = words[0];
578 if (print_event) cout <<
"\nEvent code = 0x" << hex << words[1] << dec <<
" (" << evLength <<
")";
582 while (idx < evLength) {
583 int rocEvLength = words[idx];
587 if (rocEvLength <= 6) {
588 idx += rocEvLength + 1;
592 cerr <<
"ERROR: rocEvLength != 0x0000****." << endl;
599 int idx_roc_end = idx + rocEvLength + 1;
600 if (idx_roc_end > evLength + 1) {
602 cerr <<
"ERROR: ROC Event Length exceeds event length\n"
603 <<
" Event: " <<
dec_par.
codaID <<
", EventLength = " << evLength
604 <<
", position = " << idx <<
", rocEvLength = " << words[idx] << endl;
613 cerr <<
"ERROR: rocID > 32." << endl;
618 if (print_event) cout <<
"\n ROC " << setw(2) << rocID <<
" (" << setw(3) << rocEvLength <<
") |";
625 while (idx < idx_roc_end) {
626 int e906flag = words[idx];
629 cerr <<
"Seems not e906flag (0x" << hex << e906flag << dec <<
")" << endl;
631 cout <<
" At idx = " << idx <<
" / " << evLength <<
".\n";
637 if (e906flag == (
int)0xe906c0da) {
644 if (print_event) cout << hex <<
" " << (e906flag&0xFFFF) <<
"@" << board_id << dec <<
"(" << n_wd_bd <<
")";
645 idx = ProcessBoardData(words, idx, idx_roc_end, e906flag);
647 if (
dec_par.
verbose > 1) cout <<
" ProcessBoardData() returned -1: 0x" << hex << e906flag << dec <<
" " << board_id <<
" " << rocID <<
" " <<
dec_par.
codaID << endl;
651 if (idx != idx_roc_end)
Abort(
"idx != idx_roc_end");
653 if (print_event) cout << endl;
673 int MainDaqParser::ProcessBoardData (
int* words,
int idx,
int idx_roc_end,
int e906flag)
675 if ( e906flag == (
int)0xE906F003 ) idx = ProcessBoardScaler (words, idx);
676 else if ( e906flag == (
int)0xE906F005 ) idx = ProcessBoardV1495TDC(words, idx);
677 else if ( e906flag == (
int)0xE906F018 ) idx = ProcessBoardJyTDC2 (words, idx, idx_roc_end);
678 else if ( e906flag == (
int)0xE906F019 )
return -1;
679 else if ( e906flag == (
int)0xe906f01b ) idx = ProcessBoardFeeQIE (words, idx);
680 else if ( e906flag == (
int)0xE906F014 ) idx = ProcessBoardTriggerCount(words, idx);
681 else if ( e906flag == (
int)0xE906F00F ) idx = ProcessBoardTriggerBit (words, idx);
684 else if ( e906flag == (
int)0xE906F999 ) idx = ProcessBoardStdV1495TDC(words, idx);
685 else if ( e906flag == (
int)0xE906F010 ) idx = ProcessBoardStdJyTDC2 (words, idx, idx_roc_end);
686 else if ( e906flag == (
int)0xe906f013 ) idx = ProcessBoardStdFeeQIE (words, idx);
687 else if ( e906flag == (
int)0xE906F999 ) idx = ProcessBoardStdTriggerCount(words, idx);
688 else if ( e906flag == (
int)0xE906F999 ) idx = ProcessBoardStdTriggerBit (words, idx);
692 <<
": e906flag = " << e906flag <<
" @ " << idx-1 <<
"\n";
695 Abort(
"Unexpected board type.");
700 int MainDaqParser::ProcessBoardScaler (
int* words,
int idx)
702 int boardID = (0xFFFF & words[idx]);
707 for (
int ii = 0; ii < 32; ii++) {
708 unsigned int value = words[idx];
715 data.
board = boardID;
730 int MainDaqParser::ProcessBoardTriggerBit (
int* words,
int j)
732 int n_words = words[j];
733 if (n_words == 0)
return j+1;
737 if (n_words % 2 != 0) {
739 Abort(
"N of trigger words % 2 != 0.");
741 int n_evt = n_words / 2;
742 for (
int i_evt = 0; i_evt < n_evt; i_evt++) {
743 int triggerBits = words[j + 2*i_evt ];
744 int evt_id = words[j + 2*i_evt + 1];
748 SetEventInfo(evt, evt_id);
752 for (
int i = 0; i < 10; i++) trigger[i] =
get_bin_bit (triggerBits, i);
753 for (
int i = 0; i < 5; i++) {
755 evt->
MATRIX[i] = trigger[i ];
756 evt->
NIM [i] = trigger[i+5];
763 int MainDaqParser::ProcessBoardTriggerCount (
int* words,
int j)
768 int n_words = words[j];
769 if (n_words == 0)
return j+1;
773 if (n_words % 11 != 0) {
775 Abort(
"N of trigger-count words % 11 != 0.");
777 int n_evt = n_words / 11;
778 for (
int i_evt = 0; i_evt < n_evt; i_evt++) {
779 int idx_evt = j + 11*i_evt;
780 int evt_id = words[idx_evt + 10];
784 SetEventInfo(evt, evt_id);
785 for (
int i_type = 0; i_type < 5; i_type++) {
786 evt->
RawMATRIX [i_type] = words[idx_evt + i_type ];
806 int MainDaqParser::ProcessBoardFeeQIE (
int* words,
int idx)
810 while (words[idx] == (
int)0xe906e906) idx++;
814 int idx_end = idx + n_wd + 1;
816 if (n_wd == 0)
return idx;
818 while (words[idx] == (
int)0xe906e906) { idx++; idx_end++; }
834 for (
int i_evt = 0; i_evt < 7 && idx < idx_end; i_evt++) {
836 int eventID = words[idx_evt + 48];
839 if (n_wd_evt == 44) idx_evt += 5;
840 else if (n_wd_evt != 39) {
848 unsigned int sums_vals[4];
849 for (
int i_sum = 0; i_sum < 4 ; i_sum++) {
855 unsigned int triggerCount = words[idx_evt] | (
get_hex_bits (words[idx_evt+1], 7, 4) );
859 unsigned int turnOnset = words[idx_evt] | (
get_hex_bits (words[idx_evt+1], 7, 4) );
864 unsigned int rfOnset =
get_hex_bits(words[idx_evt],7,4);
867 unsigned int rf_vals[25];
868 for (
int i_rf = 0; i_rf < 25; i_rf++) {
869 if (words[idx_evt] == (
int)0xe906e906)
Abort(
"Unexpected 0xe906e906 in QIE.");
881 SetEventInfo(evt, eventID);
883 for (
int ii = 0; ii < 4; ii++) evt->
sums[ii] = sums_vals[ii];
887 for (
int ii = 0; ii < 25 ; ii++) evt->
rf[ii+4] = rf_vals[ii];
892 if (idx != idx_end) {
893 cout << idx <<
" != " << idx_end;
894 Abort(
"idx != idx_end in feeQIE().");
905 int MainDaqParser::ProcessBoardV1495TDC (
int* words,
int idx)
907 int boardID = words[idx++];
908 int n_wd_fpga = words[idx++];
909 if (n_wd_fpga == 0)
return idx;
910 int idx_end = idx + n_wd_fpga;
914 vector<int> list_chan;
915 vector<int> list_time;
916 while (idx < idx_end) {
919 int word_stop = words[idx+1];
920 int evt_id = words[idx+2];
932 SetEventInfo(evt, evt_id);
934 if (word_stop == (
int)0xd2ad) {
937 }
else if (word_stop == (
int)0xd3ad) {
942 cerr <<
" !! v1495: bad stop word: " << word_stop << endl;
945 for (
unsigned int ii = 0; ii < list_chan.size(); ii++) {
951 hit.
chan = list_chan[ii];
952 hit.
time = time_stop - list_time[ii];
968 if (idx != idx_end)
Abort(
"idx != idx_end in ProcessBoardV1495TDC.");
993 int MainDaqParser::ProcessBoardJyTDC2 (
int* words,
int idx_begin,
int idx_roc_end)
998 int nWordsBoard =
get_hex_bits (words[idx_begin], 3, 4);
999 if (nWordsBoard == 0)
return idx_begin + 1;
1003 if (hex7 != 0 || hex54 != 0) {
1008 return idx_begin + 1;
1012 int idx_events_begin = idx_begin + 2;
1013 int idx_events_end = idx_events_begin + nWordsBoard - 1;
1014 if (words[idx_begin + 1] == (
int)0xe906e906) {
1018 if (idx_events_end > idx_roc_end) {
1024 bool header_found =
false;
1025 double time_header = 0;
1026 vector<int > list_chan;
1027 vector<double> list_time;
1028 for (
int idx = idx_events_begin; idx < idx_events_end; idx++) {
1033 int word = words[idx];
1034 if (
get_bin_bit(word, 16) == 0)
Abort(
"Stop signal is not rising. Not supported.");
1035 double fine = 4.0 -
get_hex_bit (word, 0) * 4.0 / 9.0;
1037 time_header = fine + rough;
1038 header_found =
true;
1041 if (! header_found) {
1046 int evt_id = words[idx];
1050 SetEventInfo(evt, evt_id);
1053 for (
unsigned int ii = 0; ii < list_chan.size(); ii++) {
1058 hit.
board = boardID;
1059 hit.
chan = list_chan[ii];
1060 hit.
time = list_time[ii];
1065 header_found =
false;
1069 if (! header_found) {
1074 int word = words[idx];
1079 double fine = 4.0 -
get_hex_bit (word, 0) * 4.0 / 9.0;
1081 double time = time_header - (fine + rough);
1082 if (time < 0) time += 4096;
1083 list_time.push_back(time);
1087 int chan = cable_chan + 16*cable_id;
1088 list_chan.push_back(chan);
1095 return idx_events_end;
1098 int MainDaqParser::ProcessBoardStdTriggerBit (
int* words,
int idx)
1104 int triggerBits = words[idx];
1106 for (
int i = 0; i < 5; i++) {
1115 int MainDaqParser::ProcessBoardStdTriggerCount (
int* words,
int idx)
1124 for (
int ii = 0; ii < 5; ii++) {
1137 int MainDaqParser::ProcessBoardStdFeeQIE (
int* words,
int idx)
1141 while (words[idx] == (
int)0xe906e906) idx++;
1145 int idx_end = idx + n_wd + 1;
1147 if (n_wd == 0)
return idx;
1149 while (words[idx] == (
int)0xe906e906) { idx++; idx_end++; }
1152 if (n_wd2 == 0x2C) idx += 5;
1160 for (
int i_sum = 0; i_sum < 4 ; i_sum++) {
1178 for (
int i_rf = 0; i_rf < 25; i_rf++) {
1179 if (words[idx] == (
int)0xe906e906)
Abort(
"Unexpected 0xe906e906 in QIE.");
1184 if (idx != idx_end) {
1185 cout << idx <<
" != " << idx_end;
1186 Abort(
"idx != idx_end in StdFeeQIE().");
1194 int MainDaqParser::ProcessBoardStdV1495TDC (
int* words,
int idx)
1200 int boardID = words[idx++];
1204 bool ignore = (
get_bin_bit(words[idx + 1], 12) != 1);
1206 if ((words[idx] & 0xFFFF) == (int)0xd1ad) {
1210 if ((words[idx + 1] & 0xFFFF) == (int)0xd2ad) {
1213 }
else if ((words[idx + 1] & 0xFFFF) == (int)0xd3ad) {
1220 int numChannels = (words[idx] & 0x0000FFFF);
1221 if (numChannels > 255) {
1228 unsigned int stopTime = (words[idx] & 0x00000FFF);
1235 hit.
board = boardID;
1237 for (
int kk = 0; kk < numChannels; kk++) {
1238 unsigned int channel =
get_hex_bits(words[idx+kk], 3, 2);
1239 unsigned int channelTime =
get_hex_bits(words[idx+kk], 1, 2);
1240 double tdcTime = stopTime - channelTime;
1248 return idx + numChannels;
1257 int MainDaqParser::ProcessBoardStdJyTDC2 (
int* words,
int idx_begin,
int idx_roc_end)
1260 int nWordsBoard =
get_hex_bits (words[idx_begin], 3, 4);
1261 if (nWordsBoard == 0)
return idx_begin + 1;
1262 int idx_end = idx_begin + nWordsBoard;
1263 if (idx_end > idx_roc_end) {
1264 cerr <<
"WARNING: Word overflow. Skip ROC (" <<
dec_par.
rocID <<
")" << endl;
1268 int idx = idx_begin + 1;
1269 if (words[idx] == (
int)0xe906e906) idx++;
1271 int trigger_clock_cycle =
get_hex_bit(words[idx], 0);
1272 double trigger_rough = 4.0 *
get_hex_bits(words[idx], 3, 3);
1273 double trigger_fine;
1275 trigger_fine = 4.0 - trigger_clock_cycle * 4.0 / 9.0;
1277 trigger_fine = 0.5 * trigger_clock_cycle;
1279 double trigger_time = trigger_rough + trigger_fine;
1287 hit.
board = boardID;
1289 while (idx < idx_end) {
1291 if (rising && (words[idx] & 0x80000000) == 0) {
1292 double fine = 4.0 -
get_hex_bit (words[idx], 0) * 4.0 / 9.0;
1294 double time = trigger_time - (fine + rough);
1295 if (time < 0) time += 4096;
1299 int chan = cable_chan + 16*cable_id;
1312 int MainDaqParser::PackOneSpillData()
1314 if (
dec_par.
verbose > 2) cout <<
"PackOneSpillData(): n=" << list_ed->size() << endl;
1326 for (EventDataMap::iterator it = list_ed->begin(); it != list_ed->end(); ) {
1327 unsigned int evt_id = it->first;
1333 it = list_ed->erase(it);
1339 unsigned int n_taiwan = ed->
list_hit .size();
1341 run_data.
n_hit += n_taiwan;
1346 for (
unsigned int ih = 0; ih < n_taiwan; ih++) {
1352 for (
unsigned int ih = 0; ih < n_v1495; ih++) {
1361 list_ed_now = list_ed;
1367 void MainDaqParser::SetEventInfo(
EventInfo* evt,
const int eventID)
unsigned int selectWindow
SlowControlDataList list_slow_cont
std::map< unsigned int, SpillData > SpillDataMap
ChanMapV1495 chan_map_v1495
bool NextPhysicsEvent(EventData *&ed, SpillData *&sd, RunData *&rd)
int OpenCodaFile(const std::string fname, const long file_size_min=32768, const int sec_wait=15, const int n_wait=40)
ChanMapTaiwan chan_map_taiwan
unsigned int multihit_elim_enabled
std::map< unsigned int, EventData > EventDataMap
unsigned int segmentation
unsigned int spill_id_slow
void PrintData(std::ostream &os=std::cout)
unsigned int falling_enabled
unsigned int eos_vme_time
ChanMapScaler chan_map_scaler
ScalerDataList list_scaler
unsigned int turn_id_max
Max turnOnset in a spill. Used to drop NIM3 events that came after the beam stops. See elog 15010.
unsigned int updating_enabled
void SetID(const int run_id, const int spill_id)
HitDataList list_hit_trig
bool Find(const short roc, const short board, const short chan, std::string &name)
bool Find(const short roc, const short board, const short chan, short &det, short &ele, short &lvl)
void AddTdcError(const int event, const int roc, const TdcError_t type)
bool Find(const short roc, const short board, const short chan, short &det, short &ele)
unsigned int triggerCount
unsigned int bos_vme_time
void SetFlushError(const bool val)