- Timestamp:
- 04/08/13 14:26:32 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15127 r15280 46 46 47 47 extern void factOut (int severity, int err, char *message); 48 extern void factReportIncomplete (uint64_t rep); 48 49 49 50 extern void gotNewRun (int runnr, PEVNT_HEADER * headers); … … 98 99 int gw_runStat; 99 100 100 int gi_memStat = +1;101 //int gi_memStat = +1; 101 102 102 103 uint32_t gi_myRun = 0; … … 128 129 char str[MXSTR]; 129 130 131 #define THOMAS_MALLOC 132 133 #ifdef THOMAS_MALLOC 134 #define MAX_HEAD_MEM (NBOARDS * sizeof(PEVNT_HEADER)) 135 #define MAX_TOT_MEM (sizeof(EVENT) + (NPIX+NTMARK)*1024*2 + MAX_HEAD_MEM) 136 typedef struct TGB_struct 137 { 138 struct TGB_struct *prev; 139 void *mem; 140 } TGB_entry; 141 142 TGB_entry *tgb_last = NULL; 143 uint64_t tgb_memory = 0; 144 uint64_t tgb_inuse = 0; 145 146 void *TGB_Malloc() 147 { 148 // No free slot available, next alloc would exceed max memory 149 if (!tgb_last && tgb_memory+MAX_TOT_MEM>g_maxMem) 150 return NULL; 151 152 // We will return this amount of memory 153 tgb_inuse += MAX_TOT_MEM; 154 155 // No free slot available, allocate a new one 156 if (!tgb_last) 157 { 158 tgb_memory += MAX_TOT_MEM; 159 return malloc(MAX_TOT_MEM); 160 } 161 162 // Get the next free slot from the stack and return it 163 TGB_entry *last = tgb_last; 164 165 TGB_entry *mem = last->mem; 166 tgb_last = last->prev; 167 168 free(last); 169 170 return mem; 171 }; 172 173 void TGB_free(void *mem) 174 { 175 // Add the last free slot to the stack 176 TGB_entry *entry = malloc(sizeof(TGB_entry)); 177 178 entry->prev = tgb_last; 179 entry->mem = mem; 180 181 tgb_last = entry; 182 183 // Decrease the amont of memory in use accordingly 184 tgb_inuse -= MAX_TOT_MEM; 185 } 186 #endif 187 188 #ifdef ETIENNE_MALLOC 130 189 //ETIENNE 131 190 #define MAX_SLOTS_PER_CHUNK 100 … … 207 266 for (int i=1;i<numNewSlots;i++) 208 267 { 209 EtiMemoryChunks[numAllocatedChunks].pointers[i] = EtiMemoryChunks[numAllocatedChunks].pointers[0] + i*MAX_SLOT_SIZE;// &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]);268 EtiMemoryChunks[numAllocatedChunks].pointers[i] = (char*)EtiMemoryChunks[numAllocatedChunks].pointers[0] + i*MAX_SLOT_SIZE;// &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]); 210 269 EtiMemoryChunks[numAllocatedChunks].events[i] = -1; 211 270 } … … 226 285 currentChunk->events[mBufferMapping[evtIndex].slot] = -1; 227 286 currentChunk->nFreeSlots++; 228 287 288 return; /* TEST */ 289 229 290 int chunkIndex = mBufferMapping[evtIndex].chunk; 230 291 if (chunkIndex != numAllocatedChunks-1) … … 249 310 } 250 311 //END ETIENNE 251 312 #endif 252 313 253 314 … … 465 526 evtCtrl.pcTime[i] = actime; //initiate to far future 466 527 528 #ifdef ETIENNE_MALLOC 467 529 //ETIENNE 468 530 mBufferMapping[i].chunk = -1; … … 470 532 mBufferMapping[i].slot = -1; 471 533 //END ETIENNE 472 } 534 #endif 535 } 536 #ifdef ETIENNE_MALLOC 473 537 for (int j=0;j<MAX_CHUNKS;j++) 474 538 EtiMemoryChunks[j].pointers[0] = NULL; 539 #endif 475 540 476 541 actRun.FADhead = malloc (NBOARDS * sizeof (PEVNT_HEADER)); … … 498 563 // < 0 if no space left 499 564 500 struct timeval *tv, atv; 501 tv = &atv; 565 struct timeval tv; 502 566 uint32_t tsec, tusec; 503 567 uint oldest; … … 506 570 int i, b, evFree; 507 571 // int headmem = 0; 508 size_t needmem = 0;572 // size_t needmem = 0; 509 573 510 574 … … 578 642 i = evFree; //found free entry; use it ... 579 643 580 gettimeofday ( tv, NULL);581 tsec = atv.tv_sec;582 tusec = atv.tv_usec;644 gettimeofday (&tv, NULL); 645 tsec = tv.tv_sec; 646 tusec = tv.tv_usec; 583 647 584 648 //check if runId already registered in runCtrl … … 665 729 return -11; 666 730 } 667 */ 731 */ 732 733 #ifdef THOMAS_MALLOC 734 mBuffer[i].FADhead = TGB_Malloc(); 735 mBuffer[i].fEvent = NULL; 736 mBuffer[i].buffer = NULL; 737 if (mBuffer[i].FADhead == NULL) { 738 snprintf (str, MXSTR, "malloc header failed for event %d", evID); 739 factOut (kError, 882, str); 740 return -12; 741 } 742 mBuffer[i].fEvent = (void*)((char*)mBuffer[i].FADhead+MAX_HEAD_MEM); 743 #endif 744 745 #ifdef ETIENNE_MALLOC 668 746 mBuffer[i].FADhead = ETI_Malloc(evID, i); 669 747 mBuffer[i].buffer = NULL; … … 678 756 if (gj.usdMem > gj.maxMem) 679 757 gj.maxMem = gj.usdMem; 680 if (gi_memStat > 0) {758 /*if (gi_memStat > 0) { 681 759 gi_memStat = -99; 682 760 snprintf (str, MXSTR, "No memory left to keep event %6d sock %3d", 683 761 evID, sk); 684 762 factOut (kError, 882, str); 685 } 763 }*/ 686 764 #ifdef EVTDEBUG 687 765 else … … 694 772 return -11; 695 773 } 774 #endif 775 776 #ifdef STANDARD_MALLOC 777 778 mBuffer[i].FADhead = malloc (MAX_HEAD_MEM+MAX_EVT_MEM); 779 mBuffer[i].fEvent = NULL; 780 mBuffer[i].buffer = NULL; 781 if (mBuffer[i].FADhead == NULL) { 782 snprintf (str, MXSTR, "malloc header failed for event %d", evID); 783 factOut (kError, 882, str); 784 return -12; 785 } 786 mBuffer[i].fEvent = (void*)((char*)mBuffer[i].FADhead+MAX_HEAD_MEM); 787 #endif 788 696 789 /* 697 790 mBuffer[i].FADhead = malloc (headmem); … … 746 839 mBuffer[i].trgNum = trgNum; 747 840 mBuffer[i].trgTyp = trgTyp; 748 mBuffer[i].evtLen = needmem;841 // mBuffer[i].evtLen = needmem; 749 842 mBuffer[i].Errors[0] = 750 mBuffer[i].Errors[1] = mBuffer[i].Errors[2] = mBuffer[i].Errors[3] = 0; 843 mBuffer[i].Errors[1] = mBuffer[i].Errors[2] = mBuffer[i].Errors[3] = 0; 844 845 #ifdef ETIENNE_MALLOC 751 846 //ETIENNE 752 847 //gj.usdMem += needmem + headmem + gi_maxSize; … … 757 852 } 758 853 //END ETIENNE 854 #endif 855 856 #ifdef THOMAS_MALLOC 857 gj.usdMem = tgb_inuse; 858 #endif 859 759 860 if (gj.usdMem > gj.maxMem) 760 861 gj.maxMem = gj.usdMem; … … 800 901 801 902 // int headmem = 0; 903 // size_t freemem = 0; 904 905 #ifdef ETIENNE_MALLOC 802 906 int evid; 803 // size_t freemem = 0;804 805 907 evid = mBuffer[i].evNum; 908 ETI_Free(evid, i); 909 #endif 910 806 911 // freemem = mBuffer[i].evtLen; 807 912 //ETIENNE 808 ETI_Free(evid, i); 913 #ifdef THOMAS_MALLOC 914 TGB_free(mBuffer[i].FADhead); 915 #endif 916 917 #ifdef STANDARD_MALLOC 918 free (mBuffer[i].FADhead); 919 #endif 920 809 921 // free (mBuffer[i].fEvent); 810 922 mBuffer[i].fEvent = NULL; … … 819 931 mBuffer[i].evNum = mBuffer[i].nRoi = -1; 820 932 mBuffer[i].runNum = 0; 933 934 #ifdef ETIENNE_MALLOC 821 935 //ETIENNE 822 936 // gj.usdMem = gj.usdMem - freemem - headmem - gi_maxSize; … … 827 941 } 828 942 //END ETIENNE 943 #endif 944 945 #ifdef THOMAS_MALLOC 946 gj.usdMem = tgb_inuse; 947 #endif 948 829 949 gj.bufTot--; 830 950 831 if (gi_memStat < 0) {951 /*if (gi_memStat < 0) { 832 952 if (gj.usdMem <= 0.75 * gj.maxMem) 833 953 gi_memStat = +1; 834 } 835 954 }*/ 836 955 837 956 return 0; … … 883 1002 } /*-----------------------------------------------------------------*/ 884 1003 1004 //struct rnd 1005 //{ 1006 // int val; 1007 // int idx; 1008 //}; 1009 // 1010 //struct rnd random_arr[MAX_SOCK]; 1011 // 1012 //int compare(const void *f1, const void *f2) 1013 //{ 1014 // struct rnd *r1 = (struct rnd*)f1; 1015 // struct rnd *r2 = (struct rnd*)f2; 1016 // return r1->val - r2->val; 1017 //} 885 1018 886 1019 … … 904 1037 905 1038 906 struct timeval *tv, atv; 907 tv = &atv; 1039 struct timeval tv; 908 1040 uint32_t tsec, tusec; 909 1041 … … 946 1078 947 1079 START: 948 gettimeofday ( tv, NULL);949 g_actTime = tsec = atv.tv_sec;950 g_actUsec = tusec = atv.tv_usec;1080 gettimeofday (&tv, NULL); 1081 g_actTime = tsec = tv.tv_sec; 1082 g_actUsec = tusec = tv.tv_usec; 951 1083 gi_myRun = g_actTime; 952 1084 evtCtrl.frstPtr = 0; … … 983 1115 gj.bufTot = gj.maxEvt = gj.xxxEvt = 0; 984 1116 gj.usdMem = gj.maxMem = gj.xxxMem = 0; 1117 #ifdef THOMAS_MALLOC 1118 gj.totMem = tgb_memory; 1119 #else 985 1120 gj.totMem = g_maxMem; 1121 #endif 986 1122 gj.bufNew = gj.bufEvt = 0; 987 1123 gj.badRoiE = gj.badRoiR = gj.badRoiB = … … 1005 1141 gi_runStat = g_runStat; 1006 1142 gj.readStat = g_runStat; 1007 gettimeofday ( tv, NULL);1008 g_actTime = tsec = atv.tv_sec;1009 g_actUsec = tusec = atv.tv_usec;1143 gettimeofday (&tv, NULL); 1144 g_actTime = tsec = tv.tv_sec; 1145 g_actUsec = tusec = tv.tv_usec; 1010 1146 1011 1147 … … 1052 1188 numok = 0; //count number of succesfull actions 1053 1189 1054 for (i = 0; i < MAX_SOCK; i++) { //check all sockets if something to read 1190 /* 1191 for (i=0; i<MAX_SOCK/7; i++) 1192 { 1193 random_arr[i].val = rand(); 1194 random_arr[i].idx = i; 1195 } 1196 1197 qsort(random_arr, MAX_SOCK/7, sizeof(struct rnd), compare); 1198 1199 for (int iii = 0; iii < MAX_SOCK/7; iii++) { //check all sockets if something to read 1200 1201 b = random_arr[iii].idx; 1202 i = b*7; 1203 p = 0; 1204 */ 1205 1206 for (i = 0; i < MAX_SOCK; i+=7) { //check all sockets if something to read 1207 1055 1208 b = i / 7 ; 1056 1209 p = i % 7 ; 1057 1210 1058 if ( p >= NUMSOCK) { ; }1059 else {1211 /*if ( p >= NUMSOCK) { ; } 1212 else*/ { 1060 1213 if (sockDef[b] > 0) 1061 1214 s0 = +1; … … 1070 1223 if (rd[i].sockStat == -1) { 1071 1224 rd[i].errCnt++ ; 1225 usleep(25000); 1072 1226 // if (rd[i].errCnt < 100) rd[i].sockStat = rd[i].errCnt ; 1073 1227 // else if (rd[i].errCnt < 1000) rd[i].sockStat = 1000 ; … … 1101 1255 1102 1256 if (rd[i].sockStat == 0) { //we have a connection ==> try to read 1103 if (rd[i].bufLen > 0) { //might be nothing to read [buffer full] 1257 1258 if (rd[i].bufLen<=0) 1259 { 1260 #ifdef EVTDEBUG 1261 snprintf (str, MXSTR, "do not read from socket %d %d", i, 1262 rd[i].bufLen); 1263 factOut (kDebug, 301, str); 1264 #endif 1265 continue; 1266 } 1267 1268 // if (rd[i].bufLen > 0) { //might be nothing to read [buffer full] 1104 1269 numok++; 1105 size_t maxread = rd[i].bufLen ;1106 if (maxread > MAXREAD ) maxread=MAXREAD ;1107 1270 1108 1271 jrd = 1109 1272 recv (rd[i].socket, &rd[i].rBuf->B[rd[i].bufPos], 1110 maxread, MSG_DONTWAIT); 1111 // rd[i].bufLen, MSG_DONTWAIT); 1273 rd[i].bufLen, MSG_DONTWAIT); 1274 1275 #ifdef EVTDEBUG 1112 1276 if (jrd > 0) { 1113 1277 debugStream (i, &rd[i].rBuf->B[rd[i].bufPos], jrd); 1114 #ifdef EVTDEBUG1115 1278 memcpy (&rd[i].xBuf->B[rd[i].bufPos], 1116 1279 &rd[i].rBuf->B[rd[i].bufPos], jrd); … … 1120 1283 rd[i].rBuf->B[rd[i].bufPos + 1]); 1121 1284 factOut (kDebug, 301, str); 1122 #endif1123 1285 } 1286 #endif 1124 1287 1125 1288 if (jrd == 0) { //connection has closed ... … … 1140 1303 } else 1141 1304 numok--; //else nothing waiting to be read 1142 jrd = 0;1305 //jrd = 0; 1143 1306 } 1144 } else {1145 jrd = 0; //did read nothing as requested1307 /* } else { 1308 // jrd = 0; //did read nothing as requested 1146 1309 #ifdef EVTDEBUG 1147 1310 snprintf (str, MXSTR, "do not read from socket %d %d", i, … … 1150 1313 #endif 1151 1314 } 1315 */ 1316 if (jrd<=0) 1317 continue; 1152 1318 1153 1319 gi.gotByte[b] += jrd; 1154 1320 gj.rateBytes[b] += jrd; 1155 1321 1156 if (jrd > 0) {1322 //if (jrd > 0) { 1157 1323 numokx++; 1158 1324 jrdx += jrd; 1159 }1325 //} 1160 1326 1161 1327 … … 1167 1333 factOut (kInfo, 301, str); 1168 1334 #endif 1169 1170 } else if (rd[i].bufTyp > 0) { // we are reading data ... 1171 if (jrd < rd[i].bufLen) { //not yet all read 1172 rd[i].bufPos += jrd; //==> prepare for continuation 1173 rd[i].bufLen -= jrd; 1335 continue; 1336 } 1337 1338 rd[i].bufPos += jrd; //==> prepare for continuation 1339 rd[i].bufLen -= jrd; 1340 1341 if (rd[i].bufTyp > 0) { // we are reading data ... 1342 1343 if (rd[i].bufLen>0/*jrd < rd[i].bufLen*/) { //not yet all read 1344 #ifdef EVTDEBUG 1174 1345 debugRead (i, jrd, rd[i].evtID, rd[i].ftmID, rd[i].runID, 0, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; 0=reading data 1175 } else { //full dataset read 1176 rd[i].bufLen = 0; 1177 rd[i].bufPos = rd[i].fadLen; 1178 if (rd[i].rBuf->B[rd[i].bufPos - 1] != stop.B[0] 1179 || rd[i].rBuf->B[rd[i].bufPos - 2] != stop.B[1]) { 1346 #endif 1347 continue; 1348 } 1349 1350 //int pos = rdi_bufPos = rd[i].bufPos; 1351 //int pos = rdi_bufLen = rd[i].bufLen; 1352 //int pos = rdi_bufTyp = rd[i].bufTyp; 1353 1354 rd[i].bufTyp = 0; //ready to read next header 1355 rd[i].bufLen = frst_len; 1356 rd[i].bufPos = 0; 1357 1358 //{ 1359 //full dataset read 1360 //rd[i].bufLen = 0; 1361 //rd[i].bufPos = rd[i].fadLen; 1362 if (rd[i].rBuf->B[rd[i].fadLen - 1] != stop.B[0] || 1363 rd[i].rBuf->B[rd[i].fadLen - 2] != stop.B[1]) { 1180 1364 gi.evtErr++; 1181 1365 snprintf (str, MXSTR, 1182 1366 "End-of-event flag wrong on socket %3d for event %4d (len=%5d), expected %3d %3d, got %3d %3d", 1183 1367 i, rd[i].evtID, rd[i].fadLen, stop.B[0], stop.B[1], 1184 rd[i].rBuf->B[rd[i]. bufPos - 1], rd[i].rBuf->B[rd[i].bufPos- 2]);1368 rd[i].rBuf->B[rd[i].fadLen - 1], rd[i].rBuf->B[rd[i].fadLen - 2]); 1185 1369 factOut (kError, 301, str); 1186 goto EndBuf; 1370 //goto EndBuf; 1371 continue; 1187 1372 1188 1373 #ifdef EVTDEBUG … … 1192 1377 i, rd[i].fadLen, rd[i].rBuf->B[0], 1193 1378 rd[i].rBuf->B[1], start.B[1], start.B[0], 1194 rd[i].rBuf->B[rd[i]. bufPos- 2],1195 rd[i].rBuf->B[rd[i]. bufPos- 1], stop.B[1],1379 rd[i].rBuf->B[rd[i].fadLen - 2], 1380 rd[i].rBuf->B[rd[i].fadLen - 1], stop.B[1], 1196 1381 stop.B[0]); 1197 1382 factOut (kDebug, 301, str); … … 1199 1384 } 1200 1385 1201 if (jrd > 0) 1386 #ifdef EVTDEBUG 1387 //if (jrd > 0) 1202 1388 debugRead (i, jrd, rd[i].evtID, rd[i].ftmID, rd[i].runID, 1, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; 1=finished event 1389 #endif 1203 1390 1204 1391 /* //we have a complete buffer, copy to WORK area … … 1261 1448 snprintf (str, MXSTR, "Inconsistent Roi accross boards B=%d, expected %d, got %d", kr, checkRoi, roi[0]); 1262 1449 factOut (kError, 1, str); 1263 goto EndBuf; 1450 // goto EndBuf; 1451 continue; 1264 1452 } 1265 1453 roiHopper += checkRoi+4; … … 1277 1465 snprintf (str, MXSTR, "Inconsistent Roi accross patches B=%d P=%d, expected %d, got %d", kr, jr, roi[jr], checkRoi); 1278 1466 factOut (kFatal, 1, str); 1279 goto EndBuf; 1467 // goto EndBuf; 1468 continue; 1280 1469 } 1281 1470 } … … 1294 1483 1295 1484 if (evID < -1000) { 1296 goto EndBuf; //not usable board/event/run --> skip it 1485 // goto EndBuf; //not usable board/event/run --> skip it 1486 //rd[i].bufTyp = 0; //ready to read next header 1487 //rd[i].bufLen = frst_len; 1488 //rd[i].bufPos = 0; 1489 continue; 1297 1490 } 1298 1491 if (evID < 0) { //no space left, retry later … … 1303 1496 } 1304 1497 #endif 1305 xwait.tv_sec = 0; 1306 xwait.tv_nsec = 10000000; // sleep for ~10 msec 1307 nanosleep (&xwait, NULL); 1308 goto EndBuf1; //hope there is free space next round 1498 rd[i].bufTyp = -1; 1499 rd[i].bufLen = 0; 1500 rd[i].bufPos = rd[i].fadLen; 1501 1502 //xwait.tv_sec = 0; 1503 //xwait.tv_nsec = 10000000; // sleep for ~10 msec 1504 //nanosleep (&xwait, NULL); 1505 continue; 1506 //goto EndBuf1; //hope there is free space next round 1309 1507 } 1310 1508 //we have a valid entry in mBuffer[]; fill it … … 1342 1540 evID, boardId, i, rd[i].fadLen, 1343 1541 rd[i].rBuf->B[0], rd[i].rBuf->B[1], 1344 rd[i].rBuf->B[rd[i]. bufPos- 2],1345 rd[i].rBuf->B[rd[i]. bufPos- 1]);1542 rd[i].rBuf->B[rd[i].fadLen - 2], 1543 rd[i].rBuf->B[rd[i].fadLen - 1]); 1346 1544 factOut (kWarn, 501, str); 1347 goto EndBuf; //--> skip Board 1545 // goto EndBuf; //--> skip Board 1546 //rd[i].bufTyp = 0; //ready to read next header 1547 //rd[i].bufLen = frst_len; 1548 //rd[i].bufPos = 0; 1549 continue; 1348 1550 } 1349 1551 … … 1433 1635 } 1434 1636 1435 EndBuf:1436 rd[i].bufTyp = 0; //ready to read next header1437 rd[i].bufLen = frst_len;1438 rd[i].bufPos = 0;1439 EndBuf1:1637 // EndBuf: 1638 //rd[i].bufTyp = 0; //ready to read next header 1639 //rd[i].bufLen = frst_len; 1640 //rd[i].bufPos = 0; 1641 //EndBuf1: 1440 1642 ; 1441 }1643 //} 1442 1644 1443 1645 } else { //we are reading event header 1444 rd[i].bufPos += jrd; 1445 rd[i].bufLen -= jrd; 1446 if (rd[i].bufPos >= minLen) { //sufficient data to take action 1646 //rd[i].bufPos += jrd; 1647 //rd[i].bufLen -= jrd; 1648 if (rd[i].bufPos < minLen) //{ //sufficient data to take action 1649 { 1650 #ifdef EVTDEBUG 1651 debugRead (i, jrd, 0, 0, 0, -2, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet 1652 #endif 1653 continue; 1654 } 1655 1447 1656 //check if startflag correct; else shift block .... 1448 1657 for (k = 0; k < rd[i].bufPos - 1; k++) { … … 1456 1665 rd[i].bufPos = 0; 1457 1666 rd[i].bufLen = head_len; 1458 } else if (k > 0) { 1667 continue; 1668 } 1669 1670 if (k > 0) { 1459 1671 rd[i].bufPos -= k; 1460 1672 rd[i].bufLen += k; 1461 mem cpy(&rd[i].rBuf->B[0], &rd[i].rBuf->B[k],1462 rd[i].bufPos);1673 memmove (&rd[i].rBuf->B[0], &rd[i].rBuf->B[k], 1674 rd[i].bufPos); 1463 1675 #ifdef EVTDEBUG 1464 1676 memcpy (&rd[i].xBuf->B[0], &rd[i].xBuf->B[k], … … 1466 1678 #endif 1467 1679 } 1468 if (rd[i].bufPos >= minLen) { 1680 1681 if (rd[i].bufPos < minLen) 1682 { 1683 #ifdef EVTDEBUG 1684 debugRead (i, jrd, 0, 0, 0, -2, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet 1685 #endif 1686 continue; 1687 } 1688 1689 //{ 1469 1690 if (rd[i].skip > 0) { 1470 1691 snprintf (str, MXSTR, "Skipped %d bytes on port %d", … … 1473 1694 rd[i].skip = 0; 1474 1695 } 1696 1697 // TGB: This needs much more checks than just the first two bytes! 1475 1698 goodhed++; 1476 1699 … … 1523 1746 rd[i].runID = gi_myRun; 1524 1747 1525 if (rd[i].bufLen <= head_len || rd[i].bufLen > MAX_LEN) {1748 /*if (rd[i].bufLen <= head_len || rd[i].bufLen > MAX_LEN) { 1526 1749 snprintf (str, MXSTR, 1527 1750 "Illegal event-length %d on port %d, %d expected.", rd[i].bufLen, i, head_len); 1528 1751 factOut (kFatal, 881, str); 1529 1752 rd[i].bufLen = 100000; //? 1530 } 1753 }*/ 1531 1754 1532 1755 int fadBoard = rd[i].rBuf->S[12]; 1533 1756 debugHead (i, fadBoard, rd[i].rBuf); 1534 1757 debugRead (i, jrd, rd[i].evtID, rd[i].ftmID, rd[i].runID, -1, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid;-1=start event 1535 } else {1536 debugRead (i, jrd, 0, 0, 0, -2, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet1537 }1538 } else {1539 debugRead (i, jrd, 0, 0, 0, -2, tsec, tusec); // i=socket; jrd=#bytes; ievt=eventid; -2=start event, unknown id yet1540 }1541 1542 1758 } //end interpreting last read 1543 1759 } … … 1553 1769 1554 1770 g_actTime = time (NULL); 1555 if (g_actTime > gi_SecTime) { 1771 if (g_actTime <= gi_SecTime) { 1772 usleep(1); 1773 continue; 1774 } 1775 1556 1776 gi_SecTime = g_actTime; 1557 1777 … … 1579 1799 factOut (kWarn, 601, str); 1580 1800 1801 uint64_t report = 0; 1802 1581 1803 int ik,ib,jb; 1582 1804 ik=0; 1583 1805 for (ib=0; ib<NBOARDS; ib++) { 1584 if (ib%10==0) { 1585 snprintf (&str[ik], MXSTR, "|"); 1586 ik++; 1806 if (ib%10==0) { 1807 str[ik++] = '|'; 1587 1808 } 1588 1809 jb = mBuffer[id].board[ib]; 1589 1810 if ( jb<0 ) { 1590 if (gi_NumConnect[b] >0 ) { 1591 snprintf (&str[ik], MXSTR, "."); 1592 } else { 1593 snprintf (&str[ik], MXSTR, "x"); 1811 if (gi_NumConnect[b] >0 ) { 1812 str[ik++] = '.'; 1813 report |= 1<<ib; 1814 } else { 1815 str[ik++] = 'x'; 1594 1816 } 1595 1817 } else { 1596 snprintf (&str[ik], MXSTR, "%d",jb%10);1818 str[ik++] = '0'+(jb%10); 1597 1819 } 1598 ik++;1599 1820 } 1600 s nprintf (&str[ik], MXSTR, "|");1821 str[ik] = '|'; 1601 1822 factOut (kWarn, 601, str); 1823 1824 factReportIncomplete(report); 1602 1825 1603 1826 evtCtrl.evtStat[k0] = 91; //timeout for incomplete events … … 1631 1854 gj.deltaT = 1000; //temporary, must be improved 1632 1855 1633 int b; 1634 for (b = 0; b < NBOARDS; b++) 1635 gj.totBytes[b] += gj.rateBytes[b]; 1636 gj.totMem = g_maxMem; 1856 for (int ib = 0; ib < NBOARDS; ib++) 1857 gj.totBytes[ib] += gj.rateBytes[ib]; 1858 #ifdef THOMAS_MALLOC 1859 gj.totMem = tgb_memory; 1860 #else 1861 gj.totMem = g_maxMem; 1862 #endif 1637 1863 if (gj.maxMem > gj.xxxMem) 1638 1864 gj.xxxMem = gj.maxMem; … … 1647 1873 for (b = 0; b < NBOARDS; b++) 1648 1874 gj.rateBytes[b] = 0; 1649 } 1650 1875 /* 1876 } 1651 1877 if (numok > 0) 1652 1878 numok2 = 0; … … 1661 1887 nanosleep (&xwait, NULL); 1662 1888 } 1663 1889 */ 1664 1890 } //and do next loop over all sockets ... 1665 1666 1891 1667 1892 snprintf (str, MXSTR, "Stop reading ... RESET=%d", g_reset); … … 1753 1978 if (evtCtrl.evtStat[k0] > minclear) { 1754 1979 int id = evtCtrl.evtBuf[k0]; 1980 #ifdef EVTDEBUG 1755 1981 snprintf (str, MXSTR, "ev %5d free event buffer, nb=%3d", 1756 1982 mBuffer[id].evNum, mBuffer[id].nBoard); 1757 1983 factOut (kDebug, -1, str); 1984 #endif 1758 1985 mBufFree (id); //event written--> free memory 1759 1986 evtCtrl.evtStat[k0] = -1; … … 1789 2016 1790 2017 1791 snprintf (str, MXSTR, "Exit read Process 2018 snprintf (str, MXSTR, "Exit read Process..."); 1792 2019 factOut (kInfo, -1, str); 2020 2021 #ifdef THOMAS_MALLOC 2022 snprintf (str, MXSTR, "%ld Bytes flaged as in-use.", tgb_inuse); 2023 factOut (kInfo, -1, str); 2024 #endif 2025 1793 2026 gi_runStat = -99; 1794 2027 gj.readStat = -99; … … 2022 2255 } 2023 2256 if (runCtrl[j].procId != 0) { 2257 #ifdef EVTDEBUG 2024 2258 snprintf (str, MXSTR, 2025 2259 "procEvt: Skip event %d because no active run %d", ievt, 2026 2260 irun); 2027 2261 factOut (kDebug, 502, str); 2262 #endif 2028 2263 evtCtrl.evtStat[k0] = 9091; 2029 2264 } else { … … 2295 2530 runCtrl[j].fileId += 100; 2296 2531 } else { 2532 #ifdef EVTDEBUG 2297 2533 snprintf (str, MXSTR, "writeEvt: File for run %d is closed", 2298 2534 irun); 2299 2535 factOut (kDebug, 123, str); 2536 #endif 2300 2537 } 2301 2538 evtCtrl.evtStat[k0] = 9903; … … 2310 2547 runCtrl[j].actEvt++; 2311 2548 evtCtrl.evtStat[k0] = 9901; 2549 #ifdef EVTDEBUG 2312 2550 snprintf (str, MXSTR, 2313 2551 "%5d successfully wrote for run %d id %5d", 2314 2552 ievt, irun, k0); 2315 2553 factOut (kDebug, 504, str); 2554 #endif 2316 2555 // gj.writEvt++ ; 2317 2556 } else {
Note:
See TracChangeset
for help on using the changeset viewer.