Changeset 15341
- Timestamp:
- 04/15/13 12:40:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r15340 r15341 7 7 #include <stdlib.h> 8 8 #include <stdint.h> 9 #include <stdarg.h> 9 10 #include <unistd.h> 10 11 #include <stdio.h> … … 126 127 WRK_DATA mBuffer[MAX_EVT * MAX_RUN]; //local working space 127 128 128 #define MXSTR 1000 129 char str[MXSTR]; 129 //#define MXSTR 1000 130 //char str[MXSTR]; 131 132 void factPrintf(int severity, int id, const char *fmt, ...) 133 { 134 char str[1000]; 135 136 va_list ap; 137 va_start(ap, fmt); 138 vsnprintf(str, 1000, fmt, ap); 139 va_end(ap); 140 141 factOut(severity, id, str); 142 } 143 130 144 131 145 #define THOMAS_MALLOC … … 227 241 if (EtiMemoryChunks[i].nFreeSlots < 0) 228 242 { 229 snprintf(str, MXSTR, "Number of free slot in chunk %d went below zero (%d) slot: %d", i, EtiMemoryChunks[i].nFreeSlots, j); 230 factOut(kError, 000, str); 243 factPrintf(kError, 0, "Number of free slot in chunk %d went below zero (%d) slot: %d", i, EtiMemoryChunks[i].nFreeSlots, j); 231 244 return NULL; 232 245 } … … 239 252 //If I reach this point then we have a problem because it should have found 240 253 //a free spot just above. 241 snprintf(str, MXSTR, "Could not find a free slot in a chunk that's supposed to have some. chunk=%d", i); 242 factOut(kError, 000, str); 254 factPrintf(kError, 0, "Could not find a free slot in a chunk that's supposed to have some. chunk=%d", i); 243 255 return NULL; 244 256 } … … 252 264 if (EtiMemoryChunks[numAllocatedChunks].pointers[0] == NULL) 253 265 { 254 snprintf (str, MXSTR, "Allocation of %lu bytes failed. %d chunks are currently allocated (max allowed %lu bytes)", MAX_CHUNK_SIZE, numAllocatedChunks, g_maxMem); 255 factOut (kError, 000, str); 266 factPrintf(kError, 0, "Allocation of %lu bytes failed. %d chunks are currently allocated (max allowed %lu bytes)", MAX_CHUNK_SIZE, numAllocatedChunks, g_maxMem); 256 267 return NULL; 257 268 } … … 279 290 if (currentChunk->events[mBufferMapping[evtIndex].slot] != evtId) 280 291 { 281 snprintf (str, MXSTR, "Mismatch in chunk mapping table. Expected evtId %d. Got %d. No memory was freed.", evtId, currentChunk->events[mBufferMapping[evtIndex].slot]); 282 factOut (kError, 000, str); 292 factPrintf(kError, 0, "Mismatch in chunk mapping table. Expected evtId %d. Got %d. No memory was freed.", evtId, currentChunk->events[mBufferMapping[evtIndex].slot]); 283 293 return; 284 294 } … … 296 306 if (EtiMemoryChunks[chunkIndex].pointers[0] == NULL) 297 307 { 298 snprintf(str, MXSTR, "Chunk %d not allocated as it ought to be. Skipping memory release.", chunkIndex); 299 factOut(kError, 000, str); 308 factPrintf(kError, 0, "Chunk %d not allocated as it ought to be. Skipping memory release.", chunkIndex); 300 309 return; 301 310 } … … 385 394 /*-----------------------------------------------------------------*/ 386 395 396 397 387 398 int 388 399 runFinish1 (uint32_t runnr) 389 400 { 390 snprintf (str, MXSTR, "Should finish run %d (but not yet possible)", 391 runnr); 392 factOut (kInfo, 173, str); //but continue anyhow 401 factPrintf(kInfo, 173, "Should finish(1) run %d (but not yet possible)", runnr); 393 402 return 0; 394 403 } … … 396 405 runFinish (uint32_t runnr) 397 406 { 398 snprintf (str, MXSTR, "Should finish run %d (but not yet possible)", 399 runnr); 400 factOut (kInfo, 173, str); //but continue anyhow 401 return 0; 407 factPrintf(kInfo, 173, "Should finish run %d (but not yet possible)", runnr); 408 return 0; 402 409 } 403 410 … … 431 438 j = close (rd->socket); 432 439 if (j > 0) { 433 snprintf (str, MXSTR, "Closing socket %d failed: %m (close,rc=%d)", sid, errno); 434 factOut (kFatal, 771, str); 440 factPrintf(kFatal, 771, "Closing socket %d failed: %m (close,rc=%d)", sid, errno); 435 441 } else { 436 snprintf (str, MXSTR, "Succesfully closed socket %d", sid); 437 factOut (kInfo, 771, str); 442 factPrintf(kInfo, 771, "Succesfully closed socket %d", sid); 438 443 } 439 444 } … … 462 467 rd->rBuf = malloc (sizeof (CNV_FACT)); 463 468 if (rd->rBuf == NULL) { 464 snprintf (str, MXSTR, "Could not create local buffer %d (malloc failed)", sid); 465 factOut (kFatal, 774, str); 469 factPrintf(kFatal, 774, "Could not create local buffer %d (malloc failed)", sid); 466 470 rd->sockStat = 77; 467 471 return -3; … … 471 475 472 476 if ((rd->socket = socket (PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0)) <= 0) { 473 snprintf (str, MXSTR, "Generating socket %d failed: %m (socket,rc=%d)", sid, errno); 474 factOut (kFatal, 773, str); 477 factPrintf(kFatal, 773, "Generating socket %d failed: %m (socket,rc=%d)", sid, errno); 475 478 rd->sockStat = 88; 476 479 return -2; … … 478 481 optval = 1; 479 482 if (setsockopt (rd->socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { 480 snprintf (str, MXSTR, "Setting SO_KEEPALIVE for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 481 factOut (kInfo, 173, str); //but continue anyhow 483 factPrintf(kInfo, 173, "Setting SO_KEEPALIVE for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 482 484 } 483 485 optval = 10; //start after 10 seconds 484 486 if (setsockopt (rd->socket, SOL_TCP, TCP_KEEPIDLE, &optval, optlen) < 0) { 485 snprintf (str, MXSTR, "Setting TCP_KEEPIDLE for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 486 factOut (kInfo, 173, str); //but continue anyhow 487 factPrintf(kInfo, 173, "Setting TCP_KEEPIDLE for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 487 488 } 488 489 optval = 10; //do every 10 seconds 489 490 if (setsockopt (rd->socket, SOL_TCP, TCP_KEEPINTVL, &optval, optlen) < 0) { 490 snprintf (str, MXSTR, "Setting TCP_KEEPINTVL for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 491 factOut (kInfo, 173, str); //but continue anyhow 491 factPrintf(kInfo, 173, "Setting TCP_KEEPINTVL for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 492 492 } 493 493 optval = 2; //close after 2 unsuccessful tries 494 494 if (setsockopt (rd->socket, SOL_TCP, TCP_KEEPCNT, &optval, optlen) < 0) { 495 snprintf (str, MXSTR, "Setting TCP_KEEPCNT for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 496 factOut (kInfo, 173, str); //but continue anyhow 497 } 498 499 500 snprintf (str, MXSTR, "Successfully generated socket %d", sid); 501 factOut (kInfo, 773, str); 495 factPrintf(kInfo, 173, "Setting TCP_KEEPCNT for socket %d failed: %m (setsockopt,rc=%d)", sid, errno); 496 } 497 498 factPrintf(kInfo, 773, "Successfully generated socket %d", sid); 499 502 500 rd->sockStat = -1; //try to (re)open socket 503 501 rd->errCnt = 0; … … 576 574 577 575 if (nRoi[0] < 0 || nRoi[0] > 1024) { 578 snprintf (str, MXSTR, "Illegal roi in channel 0: %d (allowed: 0<=roi<=1024)", nRoi[0]); 579 factOut (kError, 999, str); 576 factPrintf(kError, 999, "Illegal roi in channel 0: %d (allowed: 0<=roi<=1024)", nRoi[0]); 580 577 gj.badRoiR++; 581 578 gj.badRoi[b]++; … … 585 582 for (int jr = 1; jr < 8; jr++) { 586 583 if (nRoi[jr] != nRoi[0]) { 587 snprintf (str, MXSTR, "Mismatch of roi (%d) in channel %d with roi (%d) in channel 0.", nRoi[jr], jr, nRoi[0]); 588 factOut (kError, 711, str); 584 factPrintf(kError, 711, "Mismatch of roi (%d) in channel %d with roi (%d) in channel 0.", nRoi[jr], jr, nRoi[0]); 589 585 gj.badRoiB++; 590 586 gj.badRoi[b]++; … … 593 589 } 594 590 if (nRoi[8] < nRoi[0]) { 595 snprintf (str, MXSTR, "Mismatch of roi (%d) in channel 8. Should be larger or equal than the roi (%d) in channel 0.", nRoi[8], nRoi[0]); 596 factOut (kError, 712, str); 591 factPrintf(kError, 712, "Mismatch of roi (%d) in channel 8. Should be larger or equal than the roi (%d) in channel 0.", nRoi[8], nRoi[0]); 597 592 gj.badRoiB++; 598 593 gj.badRoi[b]++; … … 609 604 if (mBuffer[i].nRoi != nRoi[0] 610 605 || mBuffer[i].nRoiTM != nRoi[8]) { 611 snprintf (str, MXSTR, "Mismatch of roi within event. Expected roi=%d and roi_tm=%d, got %d and %d.", 612 mBuffer[i].nRoi, mBuffer[i].nRoiTM, nRoi[0], nRoi[8]); 613 factOut (kError, 821, str); 606 factPrintf(kError, 821, "Mismatch of roi within event. Expected roi=%d and roi_tm=%d, got %d and %d.", 607 mBuffer[i].nRoi, mBuffer[i].nRoiTM, nRoi[0], nRoi[8]); 614 608 gj.badRoiE++; 615 609 gj.badRoi[b]++; … … 636 630 //event does not yet exist; create it 637 631 if (evFree < 0) { //no space available in ctrl 638 snprintf (str, MXSTR, "No control slot to keep event %d", evID); 639 factOut (kError, 881, str); 632 factPrintf(kError, 881, "No control slot to keep event %d", evID); 640 633 return -1; 641 634 } … … 660 653 if (runCtrl[k].roi0 != nRoi[0] 661 654 || runCtrl[k].roi8 != nRoi[8]) { 662 snprintf (str, MXSTR, "Mismatch of roi within run. Expected roi=%d and roi_tm=%d, got %d and %d.", 663 runCtrl[k].roi0, runCtrl[k].roi8, nRoi[0], nRoi[8]); 664 factOut (kError, 931, str); 655 factPrintf(kError, 931, "Mismatch of roi within run. Expected roi=%d and roi_tm=%d, got %d and %d.", 656 runCtrl[k].roi0, runCtrl[k].roi8, nRoi[0], nRoi[8]); 665 657 gj.badRoiR++; 666 658 gj.badRoi[b]++; … … 679 671 680 672 if (evFree < 0 && jold < 0) { 681 snprintf (str, MXSTR, "Not able to register the new run %d", runID); 682 factOut (kFatal, 883, str); 673 factPrintf(kFatal, 883, "Not able to register the new run %d", runID); 683 674 return -1001; 684 } else { 675 } 676 685 677 if (evFree < 0) 686 678 evFree = jold; 687 snprintf (str, MXSTR, "New run %d (evFree=%d) registered with roi=%d and roi_tm=%d", runID, 688 evFree, nRoi[0], nRoi[8]); 689 factOut (kInfo, 503, str); 679 factPrintf(kInfo, 503, "New run %d (evFree=%d) registered with roi=%d and roi_tm=%d", runID, 680 evFree, nRoi[0], nRoi[8]); 690 681 runCtrl[evFree].runId = runID; 691 682 runCtrl[evFree].roi0 = nRoi[0]; … … 707 698 runTail[evFree].nEventsBad = 708 699 runTail[evFree].PCtime0 = runTail[evFree].PCtimeX = 0; 709 }710 700 711 701 RUNFOUND: … … 736 726 mBuffer[i].buffer = NULL; 737 727 if (mBuffer[i].FADhead == NULL) { 738 snprintf (str, MXSTR, "malloc header failed for event %d", evID); 739 factOut (kError, 882, str); 728 factPrintf(kError, 882, "malloc header failed for event %d", evID); 740 729 return -12; 741 730 } … … 765 754 else 766 755 { 767 snprintf (str, MXSTR, "No memory left to keep event %6d sock %3d", 768 evID, sk); 769 factOut (kDebug, 882, str); 756 factPrintf(kDebug, 882, "No memory left to keep event %6d sock %3d", evID, sk); 770 757 } 771 758 #endif … … 780 767 mBuffer[i].buffer = NULL; 781 768 if (mBuffer[i].FADhead == NULL) { 782 snprintf (str, MXSTR, "malloc header failed for event %d", evID); 783 factOut (kError, 882, str); 769 factPrintf(kError, 882, "malloc header failed for event %d", evID); 784 770 return -12; 785 771 } … … 876 862 877 863 #ifdef EVTDEBUG 878 snprintf (str, MXSTR, 879 "%5d %8d start new evt %8d %8d sock %3d len %5d t %10d", evID, 880 runID, i, evtCtrl.lastPtr, sk, fadlen, mBuffer[i].pcTime); 881 factOut (kDebug, -11, str); 864 factPrintf(kDebug, -11, "%5d %8d start new evt %8d %8d sock %3d len %5d t %10d", 865 evID, runID, i, evtCtrl.lastPtr, sk, fadlen, mBuffer[i].pcTime); 882 866 #endif 883 867 evtCtrl.lastPtr++; … … 1041 1025 1042 1026 1043 snprintf (str, MXSTR, "Start initializing (readFAD)"); 1044 factOut (kInfo, -1, str); 1027 factPrintf(kInfo, -1, "Start initializing (readFAD)"); 1045 1028 1046 1029 // int cpu = 7; //read thread … … 1130 1113 mBufInit (); //initialize buffers 1131 1114 1132 snprintf (str, MXSTR, "End initializing (readFAD)"); 1133 factOut (kInfo, -1, str); 1115 factPrintf(kInfo, -1, "End initializing (readFAD)"); 1134 1116 } 1135 1117 … … 1249 1231 gi.numConn[b]++; 1250 1232 gj.numConn[b]++; 1251 snprintf (str, MXSTR, "New connection %d (number of connections: %d)", b, gi.numConn[b]); 1252 factOut (kInfo, -1, str); 1233 factPrintf(kInfo, -1, "New connection %d (number of connections: %d)", b, gi.numConn[b]); 1253 1234 } 1254 1235 } … … 1259 1240 { 1260 1241 #ifdef EVTDEBUG 1261 snprintf (str, MXSTR, "do not read from socket %d %d", i, 1262 rd[i].bufLen); 1263 factOut (kDebug, 301, str); 1242 factPrintf(kDebug, 301, "do not read from socket %d %d", i, rd[i].bufLen); 1264 1243 #endif 1265 1244 continue; … … 1278 1257 memcpy (&rd[i].xBuf->B[rd[i].bufPos], 1279 1258 &rd[i].rBuf->B[rd[i].bufPos], jrd); 1280 snprintf (str, MXSTR, 1281 "read sock %3d bytes %5d len %5d first %d %d", i, 1282 jrd, rd[i].bufLen, rd[i].rBuf->B[rd[i].bufPos], 1283 rd[i].rBuf->B[rd[i].bufPos + 1]); 1284 factOut (kDebug, 301, str); 1259 factPrintf(kDebug, 301, "read sock %3d bytes %5d len %5d first %d %d", 1260 i, jrd, rd[i].bufLen, rd[i].rBuf->B[rd[i].bufPos], rd[i].rBuf->B[rd[i].bufPos + 1]); 1285 1261 } 1286 1262 #endif 1287 1263 1288 1264 if (jrd == 0) { //connection has closed ... 1289 snprintf (str, MXSTR, "Socket %d closed by FAD", i); 1290 factOut (kInfo, 441, str); 1265 factPrintf(kInfo, 441, "Socket %d closed by FAD", i); 1291 1266 GenSock (s0, i, 0, NULL, &rd[i]); 1292 1267 gi.gotErr[b]++; … … 1298 1273 } else if (jrd < 0) { //did not read anything 1299 1274 if (errno != EAGAIN && errno != EWOULDBLOCK) { 1300 snprintf (str, MXSTR, "Reading from socket %d failed: %m (recv,rc=%d)", i, errno); 1301 factOut (kError, 442, str); 1275 factPrintf(kError, 442, "Reading from socket %d failed: %m (recv,rc=%d)", i, errno); 1302 1276 gi.gotErr[b]++; 1303 1277 } else … … 1329 1303 // just do nothing 1330 1304 #ifdef EVTDEBUG 1331 snprintf (str, MXSTR, "skipping %d bytes on socket %d", jrd, 1332 i); 1333 factOut (kInfo, 301, str); 1305 factPrintf(kInfo, 301, "skipping %d bytes on socket %d", jrd, i); 1334 1306 #endif 1335 1307 continue; … … 1363 1335 rd[i].rBuf->B[rd[i].fadLen - 2] != stop.B[1]) { 1364 1336 gi.evtErr++; 1365 snprintf (str, MXSTR, 1366 "End-of-event flag wrong on socket %3d for event %4d (len=%5d), expected %3d %3d, got %3d %3d", 1367 i, rd[i].evtID, rd[i].fadLen, stop.B[0], stop.B[1], 1368 rd[i].rBuf->B[rd[i].fadLen - 1], rd[i].rBuf->B[rd[i].fadLen - 2]); 1369 factOut (kError, 301, str); 1337 factPrintf(kError, 301, "End-of-event flag wrong on socket %3d for event %4d (len=%5d), expected %3d %3d, got %3d %3d", 1338 i, rd[i].evtID, rd[i].fadLen, stop.B[0], stop.B[1], 1339 rd[i].rBuf->B[rd[i].fadLen - 1], rd[i].rBuf->B[rd[i].fadLen - 2]); 1370 1340 //goto EndBuf; 1371 1341 continue; … … 1373 1343 #ifdef EVTDEBUG 1374 1344 } else { 1375 snprintf (str, MXSTR, 1376 "good end of buffer found sock %3d len %5d %d %d : %d %d - %d %d : %d %d", 1345 factPrintf(kDebug, 301, "good end of buffer found sock %3d len %5d %d %d : %d %d - %d %d : %d %d", 1377 1346 i, rd[i].fadLen, rd[i].rBuf->B[0], 1378 1347 rd[i].rBuf->B[1], start.B[1], start.B[0], … … 1380 1349 rd[i].rBuf->B[rd[i].fadLen - 1], stop.B[1], 1381 1350 stop.B[0]); 1382 factOut (kDebug, 301, str);1383 1351 #endif 1384 1352 } … … 1446 1414 if (checkRoi != roi[0]) 1447 1415 { 1448 snprintf (str, MXSTR, "Inconsistent Roi accross boards B=%d, expected %d, got %d", kr, checkRoi, roi[0]); 1449 factOut (kError, 1, str); 1416 factPrintf(kError, 1, "Inconsistent Roi accross boards B=%d, expected %d, got %d", kr, checkRoi, roi[0]); 1450 1417 // goto EndBuf; 1451 1418 continue; … … 1463 1430 if (checkRoi != roi[jr]) 1464 1431 { 1465 snprintf (str, MXSTR, "Inconsistent Roi accross patches B=%d P=%d, expected %d, got %d", kr, jr, roi[jr], checkRoi); 1466 factOut (kFatal, 1, str); 1432 factPrintf(kFatal, 1, "Inconsistent Roi accross patches B=%d P=%d, expected %d, got %d", kr, jr, roi[jr], checkRoi); 1467 1433 // goto EndBuf; 1468 1434 continue; … … 1492 1458 #ifdef EVTDEBUG 1493 1459 if (rd[i].bufLen != 0) { 1494 snprintf (str, MXSTR, "something screwed up"); 1495 factOut (kFatal, 1, str); 1460 factPrintf(kFatal, 1, "something screwed up"); 1496 1461 } 1497 1462 #endif … … 1512 1477 rd[i].fadLen); 1513 1478 if (xchk != 0) { 1514 snprintf (str, MXSTR, "ERROR OVERWRITE %d %d on port %d", 1515 xchk, rd[i].fadLen, i); 1516 factOut (kFatal, 1, str); 1479 factPrintf(kFatal, 1, "ERROR OVERWRITE %d %d on port %d", xchk, rd[i].fadLen, i); 1517 1480 1518 1481 uint iq; 1519 1482 for (iq = 0; iq < rd[i].fadLen; iq++) { 1520 1483 if (rd[i].rBuf->B[iq] != rd[i].xBuf->B[iq]) { 1521 snprintf (str, MXSTR, "ERROR %4d %4d %x %x", i, iq, 1522 rd[i].rBuf->B[iq], rd[i].xBuf->B[iq]); 1523 factOut (kFatal, 1, str); 1484 factPrintf(kFatal, 1, "ERROR %4d %4d %x %x", i, iq, rd[i].rBuf->B[iq], rd[i].xBuf->B[iq]); 1524 1485 } 1525 1486 } … … 1531 1492 int fadCrate = fadBoard / 256; 1532 1493 if (boardId != (fadCrate * 10 + fadBoard % 256)) { 1533 snprintf (str, MXSTR, "Board ID mismatch. Expected %d, got %d (C=%d, B=%d)", 1534 boardId, fadBoard, fadCrate, fadBoard % 256); 1535 factOut (kWarn, 301, str); 1494 factPrintf(kWarn, 301, "Board ID mismatch. Expected %d, got %d (C=%d, B=%d)", 1495 boardId, fadBoard, fadCrate, fadBoard % 256); 1536 1496 } 1537 1497 if (mBuffer[evID].board[boardId] != -1) { 1538 snprintf (str, MXSTR, 1539 "Got event %5d from board %3d (i=%3d, len=%5d) twice: Starts with %3d %3d - ends with %3d %3d", 1498 factPrintf(kWarn, 501, "Got event %5d from board %3d (i=%3d, len=%5d) twice: Starts with %3d %3d - ends with %3d %3d", 1540 1499 evID, boardId, i, rd[i].fadLen, 1541 1500 rd[i].rBuf->B[0], rd[i].rBuf->B[1], 1542 1501 rd[i].rBuf->B[rd[i].fadLen - 2], 1543 1502 rd[i].rBuf->B[rd[i].fadLen - 1]); 1544 factOut (kWarn, 501, str);1545 1503 // goto EndBuf; //--> skip Board 1546 1504 //rd[i].bufTyp = 0; //ready to read next header … … 1614 1572 if (++runCtrl[ir].lastEvt == 0) { 1615 1573 gotNewRun (actrun, mBuffer[evID].FADhead); 1616 snprintf (str, MXSTR, "gotNewRun called for run %d, event %d", 1617 mBuffer[evID].runNum, 1618 mBuffer[evID].evNum); 1619 factOut (kInfo, 1, str); 1574 factPrintf(kInfo, 1, "gotNewRun called for run %d, event %d", 1575 mBuffer[evID].runNum, mBuffer[evID].evNum); 1620 1576 break; 1621 1577 } … … 1624 1580 } 1625 1581 #ifdef EVTDEBUG 1626 snprintf (str, MXSTR, 1627 "%5d complete event roi %4d roiTM %d cpy %8d %5d", 1628 mBuffer[evID].evNum, roi[0], roi[8] - roi[0], 1629 qncpy, qnrun); 1630 factOut (kDebug, -1, str); 1582 factPrintf(kDebug, -1, "%5d complete event roi %4d roiTM %d cpy %8d %5d", 1583 mBuffer[evID].evNum, roi[0], roi[8] - roi[0], qncpy, qnrun); 1631 1584 #endif 1632 1585 //complete event read ---> flag for next processing … … 1689 1642 //{ 1690 1643 if (rd[i].skip > 0) { 1691 snprintf (str, MXSTR, "Skipped %d bytes on port %d", 1692 rd[i].skip, i); 1693 factOut (kInfo, 666, str); 1644 factPrintf(kInfo, 666, "Skipped %d bytes on port %d", rd[i].skip, i); 1694 1645 rd[i].skip = 0; 1695 1646 } … … 1736 1687 int fadcrate = fadboard / 256; 1737 1688 fadboard = (fadcrate * 10 + fadboard % 256); 1738 snprintf (str, MXSTR, 1739 "sk %3d head: %5d %5d %5d %10d %4d %6d", i, 1740 rd[i].fadLen, rd[i].evtID, rd[i].ftmID, 1741 rd[i].runID, fadboard, jrd); 1742 factOut (kDebug, 1, str); 1689 factPrintf(kDebug, 1, "sk %3d head: %5d %5d %5d %10d %4d %6d", 1690 i, rd[i].fadLen, rd[i].evtID, rd[i].ftmID, rd[i].runID, fadboard, jrd); 1743 1691 #endif 1744 1692 … … 1762 1710 1763 1711 #ifdef EVTDEBUG 1764 snprintf (str, MXSTR, "Loop ---- %3d --- %8d", numokx, jrdx); 1765 factOut (kDebug, -1, str); 1712 factDebug(kDebug, -1, "Loop ---- %3d --- %8d", numokx, jrdx); 1766 1713 #endif 1767 1714 … … 1795 1742 && evtCtrl.pcTime[k0] < g_actTime - 30) { 1796 1743 int id = evtCtrl.evtBuf[k0]; 1797 snprintf (str, MXSTR, "%5d skip incomplete evt %8d %8d %2d", mBuffer[id].evNum, evtCtrl.evtBuf[k0], k0, 1798 evtCtrl.evtStat[k0]); 1799 factOut (kWarn, 601, str); 1744 factPrintf(kWarn, 601, "%5d skip incomplete evt %8d %8d %2d", 1745 mBuffer[id].evNum, evtCtrl.evtBuf[k0], k0, evtCtrl.evtStat[k0]); 1800 1746 1801 1747 uint64_t report = 0; 1748 1749 char str[1000]; 1802 1750 1803 1751 int ik,ib,jb; … … 1821 1769 str[ik++] = '|'; 1822 1770 str[ik] = 0; 1823 factOut 1771 factOut(kWarn, 601, str); 1824 1772 1825 1773 factReportIncomplete(report); … … 1835 1783 int id = evtCtrl.evtBuf[k0]; 1836 1784 #ifdef EVTDEBUG 1837 snprintf (str, MXSTR, "%5d free event buffer, nb=%3d", 1838 mBuffer[id].evNum, mBuffer[id].nBoard); 1839 factOut (kDebug, -1, str); 1785 factPrintf(kDebug, -1, "%5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard); 1840 1786 #endif 1841 1787 mBufFree (id); //event written--> free memory … … 1891 1837 } //and do next loop over all sockets ... 1892 1838 1893 snprintf (str, MXSTR, "Stop reading ... RESET=%d", g_reset); 1894 factOut (kInfo, -1, str); 1839 factPrintf(kInfo, -1, "Stop reading ... RESET=%d", g_reset); 1895 1840 1896 1841 if (g_reset > 0) { … … 1918 1863 if (gi_resetS > 0) { 1919 1864 //must close all open sockets ... 1920 snprintf (str, MXSTR, "Close all sockets..."); 1921 factOut (kInfo, -1, str); 1865 factPrintf(kInfo, -1, "Close all sockets..."); 1922 1866 for (i = 0; i < MAX_SOCK; i++) { 1923 1867 if (rd[i].sockStat == 0) { … … 1960 1904 if (gi_resetR == 1) { 1961 1905 minclear = 900; 1962 snprintf (str, MXSTR, "Drain all buffers ...");1906 factPrintf(kInfo, -1, "Drain all buffers ..."); 1963 1907 } else { 1964 1908 minclear = 0; 1965 snprintf (str, MXSTR, "Flush all buffers ..."); 1966 } 1967 factOut (kInfo, -1, str); 1909 factPrintf(kInfo, -1, "Flush all buffers ..."); 1910 } 1968 1911 1969 1912 int numclear = 1; … … 1980 1923 int id = evtCtrl.evtBuf[k0]; 1981 1924 #ifdef EVTDEBUG 1982 snprintf (str, MXSTR, "ev %5d free event buffer, nb=%3d", 1983 mBuffer[id].evNum, mBuffer[id].nBoard); 1984 factOut (kDebug, -1, str); 1925 factPrintf(kDebug, -1, "ev %5d free event buffer, nb=%3d", mBuffer[id].evNum, mBuffer[id].nBoard); 1985 1926 #endif 1986 1927 mBufFree (id); //event written--> free memory … … 2009 1950 } 2010 1951 2011 snprintf (str, MXSTR, "Continue read Process ..."); 2012 factOut (kInfo, -1, str); 1952 factPrintf(kInfo, -1, "Continue read Process ..."); 2013 1953 gi_reset = 0; 2014 1954 goto START; … … 2017 1957 2018 1958 2019 snprintf (str, MXSTR, "Exit read Process..."); 2020 factOut (kInfo, -1, str); 1959 factPrintf(kInfo, -1, "Exit read Process..."); 2021 1960 2022 1961 #ifdef THOMAS_MALLOC 2023 snprintf (str, MXSTR, "%ld Bytes flaged as in-use.", tgb_inuse); 2024 factOut (kInfo, -1, str); 1962 factPrintf(kInfo, -1, "%ld Bytes flaged as in-use.", tgb_inuse); 2025 1963 #endif 2026 1964 … … 2045 1983 threadID = (int64_t)thrid; 2046 1984 2047 snprintf (str, MXSTR, "Starting sub-process-thread %ld", threadID); 2048 factOut (kInfo, -1, str); 1985 factPrintf(kInfo, -1, "Starting sub-process-thread %ld", threadID); 2049 1986 2050 1987 while (g_runStat > -2) { //in case of 'exit' we still must process pending events … … 2071 2008 2072 2009 if (jret <= threadID) { 2073 snprintf (str, MXSTR, 2074 "Process %ld wants to send event to process %d... not allowed.", 2075 threadID, jret); 2076 factOut (kError, -1, str); 2010 factPrintf(kError, -1, "Process %ld wants to send event to process %d... not allowed.", threadID, jret); 2077 2011 jret = 5300; 2078 2012 } else if (jret <= 0) … … 2090 2024 2091 2025 if (gj.readStat < -10 && numWait == 0) { //nothing left to do 2092 snprintf (str, MXSTR, "Exit subProcessing in process %ld", threadID); 2093 factOut (kInfo, -1, str); 2026 factPrintf(kInfo, -1, "Exit subProcessing in process %ld", threadID); 2094 2027 return 0; 2095 2028 } … … 2102 2035 } 2103 2036 2104 snprintf (str, MXSTR, "Ending sub-process-thread %ld", threadID); 2105 factOut (kInfo, -1, str); 2037 factPrintf(kInfo, -1, "Ending sub-process-thread %ld", threadID); 2106 2038 return 0; 2107 2039 } /*-----------------------------------------------------------------*/ … … 2115 2047 int status, j; 2116 2048 struct timespec xwait; 2117 char str[MXSTR];2118 2119 2120 2049 2121 2050 int lastRun = 0; //usually run from last event still valid … … 2124 2053 // int cpu = 1; //process thread (will be several in final version) 2125 2054 2126 snprintf (str, MXSTR, "Starting process-thread with %d subprocesses", 2127 gi_maxProc); 2128 factOut (kInfo, -1, str); 2055 factPrintf(kInfo, -1, "Starting process-thread with %d subprocesses", gi_maxProc); 2129 2056 2130 2057 /* CPU_ZERO initializes all the bits in the mask to zero. */ … … 2184 2111 } 2185 2112 if (j >= MAX_RUN) { 2186 snprintf (str, MXSTR, 2187 "procEvt: Can not find run %d for event %d in %d", 2188 irun, ievt, id); 2189 factOut (kFatal, 901, str); 2113 factPrintf(kFatal, 901, "procEvt: Can not find run %d for event %d in %d", irun, ievt, id); 2190 2114 } 2191 2115 lastRun = j; … … 2200 2124 runCtrl[j1].procId = 2; //--> do no longer accept events for processing 2201 2125 //---- problem: processing still going on ==> must wait for closing .... 2202 snprintf (str, MXSTR, 2203 "procEvt: Finished run since new one opened %d", 2204 runCtrl[j1].runId); 2205 factOut (kInfo, -1, str); 2126 factPrintf(kInfo, -1, "procEvt: Finished run since new one opened %d", runCtrl[j1].runId); 2206 2127 runFinish1 (runCtrl[j1].runId); 2207 2128 } … … 2229 2150 runOpen (irun, &actRun, sizeof (actRun)); 2230 2151 if (runCtrl[j].fileHd == NULL) { 2231 snprintf (str, MXSTR, 2232 "procEvt: Could not open a file for run %d (runOpen failed)", irun); 2233 factOut (kError, 502, str); 2152 factPrintf(kError, 502, "procEvt: Could not open a file for run %d (runOpen failed)", irun); 2234 2153 runCtrl[j].fileId = 91; 2235 2154 runCtrl[j].procId = 91; 2236 2155 } else { 2237 snprintf (str, MXSTR, "procEvt: Opened new file for run %d (evt=%d)", 2238 irun, ievt); 2239 factOut (kInfo, -1, str); 2156 factPrintf(kInfo, -1, "procEvt: Opened new file for run %d (evt=%d)", irun, ievt); 2240 2157 runCtrl[j].fileId = 0; 2241 2158 runCtrl[j].procId = 0; … … 2248 2165 || runCtrl[j].lastTime < g_actTime - 300 2249 2166 || runCtrl[j].maxEvt <= runCtrl[j].procEvt) { 2250 snprintf (str, MXSTR, 2251 "procEvt: Reached end of run condition for run %d", 2252 irun); 2253 factOut (kInfo, 502, str); 2167 factPrintf(kInfo, 502, "procEvt: Reached end of run condition for run %d", irun); 2254 2168 runFinish1 (runCtrl[j].runId); 2255 2169 runCtrl[j].procId = 1; … … 2258 2172 if (runCtrl[j].procId != 0) { 2259 2173 #ifdef EVTDEBUG 2260 snprintf (str, MXSTR, 2261 "procEvt: Skip event %d because no active run %d", ievt, 2262 irun); 2263 factOut (kDebug, 502, str); 2174 fcatPrintf(kDebug, 502, "procEvt: Skip event %d because no active run %d", ievt, irun); 2264 2175 #endif 2265 2176 evtCtrl.evtStat[k0] = 9091; … … 2335 2246 2336 2247 if (gj.readStat < -10 && numWait == 0) { //nothing left to do 2337 snprintf (str, MXSTR, "Exit Processing Process ..."); 2338 factOut (kInfo, -1, str); 2248 factPrintf(kInfo, -1, "Exit Processing Process ..."); 2339 2249 gp_runStat = -22; //==> we should exit 2340 2250 gj.procStat = -22; //==> we should exit … … 2356 2266 // when gi_runStat claims that all events are in the buffer... 2357 2267 2358 snprintf (str, MXSTR, "Abort Processing Process ..."); 2359 factOut (kInfo, -1, str); 2268 factPrintf(kInfo, -1, "Abort Processing Process ..."); 2360 2269 int kd = evtCtrl.lastPtr - evtCtrl.frstPtr; 2361 2270 if (kd < 0) … … 2427 2336 int k, j ; 2428 2337 struct timespec xwait; 2429 char str[MXSTR];2430 2338 2431 2339 // cpu_set_t mask; 2432 2340 // int cpu = 1; //write thread 2433 2341 2434 snprintf (str, MXSTR, "Starting write-thread"); 2435 factOut (kInfo, -1, str); 2342 factPrintf(kInfo, -1, "Starting write-thread"); 2436 2343 2437 2344 /* CPU_ZERO initializes all the bits in the mask to zero. */ … … 2478 2385 } 2479 2386 if (j >= MAX_RUN) { 2480 snprintf (str, MXSTR, 2481 "writeEvt: Can not find run %d for event %d in %d", 2482 irun, ievt, id); 2483 factOut (kFatal, 901, str); 2387 factPrintf(kFatal, 901, "writeEvt: Can not find run %d for event %d in %d", irun, ievt, id); 2484 2388 gi.wrtErr++; 2485 2389 } … … 2508 2412 runOpen (irun, &actRun, sizeof (actRun)); 2509 2413 if (runCtrl[j].fileHd == NULL) { 2510 snprintf (str, MXSTR, 2511 "writeEvt: Could not open a file for run %d (runOpen failed)", irun); 2512 factOut (kError, 502, str); 2414 factPrintf(kError, 502, "writeEvt: Could not open a file for run %d (runOpen failed)", irun); 2513 2415 runCtrl[j].fileId = 91; 2514 2416 } else { 2515 snprintf (str, MXSTR, "writeEvt: Opened new file for run %d (evt %d)", 2516 irun, ievt); 2517 factOut (kInfo, -1, str); 2417 factPrintf(kInfo, -1, "writeEvt: Opened new file for run %d (evt %d)", irun, ievt); 2518 2418 runCtrl[j].fileId = 0; 2519 2419 } … … 2523 2423 if (runCtrl[j].fileId != 0) { 2524 2424 if (runCtrl[j].fileId < 0) { 2525 snprintf (str, MXSTR, 2526 "writeEvt: Never opened file for run %d", irun); 2527 factOut (kError, 123, str); 2425 factPrintf(kError, 123, "writeEvt: Never opened file for run %d", irun); 2528 2426 } else if (runCtrl[j].fileId < 100) { 2529 snprintf (str, MXSTR, "writeEvt: File for run %d is closed", 2530 irun); 2531 factOut (kWarn, 123, str); 2427 factPrintf(kWarn, 123, "writeEvt: File for run %d is closed", irun); 2532 2428 runCtrl[j].fileId += 100; 2533 2429 } else { 2534 2430 #ifdef EVTDEBUG 2535 snprintf (str, MXSTR, "writeEvt: File for run %d is closed", 2536 irun); 2537 factOut (kDebug, 123, str); 2431 factPrintf(kDebug, 123, "writeEvt: File for run %d is closed", irun); 2538 2432 #endif 2539 2433 } … … 2550 2444 evtCtrl.evtStat[k0] = 9901; 2551 2445 #ifdef EVTDEBUG 2552 snprintf (str, MXSTR, 2553 "%5d successfully wrote for run %d id %5d", 2554 ievt, irun, k0); 2555 factOut (kDebug, 504, str); 2446 factPrintf(kDebug, 504, "%5d successfully wrote for run %d id %5d", ievt, irun, k0); 2556 2447 #endif 2557 2448 // gj.writEvt++ ; 2558 2449 } else { 2559 snprintf (str, MXSTR, "writeEvt: Writing event for run %d failed (runWrite)", 2560 irun); 2561 factOut (kError, 503, str); 2450 factPrintf(kError, 503, "writeEvt: Writing event for run %d failed (runWrite)", irun); 2562 2451 evtCtrl.evtStat[k0] = 9902; 2563 2452 gi.wrtErr++; … … 2593 2482 sizeof (runTail[j])); 2594 2483 if (i < 0) { 2595 snprintf (str, MXSTR, "writeEvt: Error closing run %d (runClose[1],i=%d)", 2596 runCtrl[j].runId, i); 2597 factOut (kError, 503, str); 2484 factPrintf(kError, 503, "writeEvt: Error closing run %d (runClose[1],i=%d)", runCtrl[j].runId, i); 2598 2485 runCtrl[j].fileId = 92; 2599 2486 } else { 2600 snprintf (str, MXSTR, "writeEvt: Closed run %d (ii[1]=%d)", irun, 2601 ii); 2602 factOut (kInfo, 503, str); 2487 factPrintf(kInfo, 503, "writeEvt: Closed run %d (ii[1]=%d)", irun, ii); 2603 2488 runCtrl[j].fileId = 93; 2604 2489 } … … 2633 2518 if (runIdFound == 0) 2634 2519 { 2635 snprintf(str, MXSTR, "An Active run (number %u) has been registered, but it could not be found in the runs list", actrun); 2636 factOut(kInfo, 000, str); 2520 factPrintf(kInfo, 0, "An Active run (number %u) has been registered, but it could not be found in the runs list", actrun); 2637 2521 } 2638 2522 // snprintf(str, MXSTR, "Maximum runId: %d", maxStartedRun); … … 2647 2531 (runCtrl[j].runId != 0)) 2648 2532 { 2649 snprintf (str, MXSTR, "writeEvt: No file will be opened for run %ud. Last run: %ud (started)", runCtrl[j].runId, actrun); 2650 factOut (kInfo, 000, str); 2533 factPrintf(kInfo, 0, "writeEvt: No file will be opened for run %ud. Last run: %ud (started)", runCtrl[j].runId, actrun); 2651 2534 ;//TODO notify that this run will never be opened 2652 2535 } … … 2679 2562 sizeof (runTail[j])); 2680 2563 if (i < 0) { 2681 snprintf (str, MXSTR, "writeEvt: Error closing run %d (runClose[2],i=%d)", 2682 runCtrl[j].runId, i); 2683 factOut (kError, 506, str); 2564 factPrintf(kError, 506, "writeEvt: Error closing run %d (runClose[2],i=%d)", runCtrl[j].runId, i); 2684 2565 runCtrl[j].fileId = 94; 2685 2566 } else { 2686 snprintf (str, MXSTR, "writeEvt: Closed run %d (ii[2]=%d)", 2687 runCtrl[j].runId, ii); 2688 factOut (kInfo, 507, str); 2567 factPrintf(kInfo, 507, "writeEvt: Closed run %d (ii[2]=%d)", runCtrl[j].runId, ii); 2689 2568 runCtrl[j].fileId = 95; 2690 2569 } … … 2700 2579 2701 2580 if (gj.readStat < -10 && numWait == 0) { //nothing left to do 2702 snprintf (str, MXSTR, "Finish Write Process ..."); 2703 factOut (kInfo, -1, str); 2581 factPrintf(kInfo, -1, "Finish Write Process ..."); 2704 2582 gw_runStat = -22; //==> we should exit 2705 2583 gj.writStat = -22; //==> we should exit … … 2712 2590 2713 2591 //must close all open files .... 2714 snprintf (str, MXSTR, "Abort Writing Process ..."); 2715 factOut (kInfo, -1, str); 2592 factPrintf(kInfo, -1, "Abort Writing Process ..."); 2716 2593 2717 2594 closerun: 2718 snprintf (str, MXSTR, "Close all open files ..."); 2719 factOut (kInfo, -1, str); 2595 factPrintf(kInfo, -1, "Close all open files ..."); 2720 2596 for (j = 0; j < MAX_RUN; j++) 2721 2597 if (runCtrl[j].fileId == 0) { … … 2732 2608 int ii = 0; 2733 2609 if (runCtrl[j].closeTime < g_actTime) 2734 ii = 2;2735 elseif (runCtrl[j].lastTime < g_actTime - 300)2736 ii = 3;2737 elseif (runCtrl[j].maxEvt <= runCtrl[j].actEvt)2738 ii = 4;2610 ii |= 1; // = 2 2611 /*else*/ if (runCtrl[j].lastTime < g_actTime - 300) 2612 ii |= 2; // = 3 2613 /*else*/ if (runCtrl[j].maxEvt <= runCtrl[j].actEvt) 2614 ii |= 4; // = 4 2739 2615 if (i < 0) { 2740 snprintf (str, MXSTR, "writeEvt: Error closing run %d (runClose[3],i=%d)", 2741 runCtrl[j].runId, i); 2742 factOut (kError, 506, str); 2616 factPrintf(kError, 506, "writeEvt: Error closing run %d (runClose[3],i=%d)", runCtrl[j].runId, i); 2743 2617 runCtrl[j].fileId = 96; 2744 2618 } else { 2745 snprintf (str, MXSTR, "writeEvt: Closed run %d (ii[3]=%d)", runCtrl[j].runId, 2746 ii); 2747 factOut (kInfo, 507, str); 2619 factPrintf(kInfo, 507, "writeEvt: Closed run %d (ii[3]=%d)", runCtrl[j].runId, ii); 2748 2620 runCtrl[j].fileId = 97; 2749 2621 } … … 2752 2624 gw_runStat = -99; 2753 2625 gj.writStat = -99; 2754 snprintf (str, MXSTR, "Exit Writing Process ..."); 2755 factOut (kInfo, -1, str); 2626 factPrintf(kInfo, -1, "Exit Writing Process ..."); 2756 2627 return 0; 2757 2628 … … 2775 2646 gj.readStat = gj.procStat = gj.writStat = 0; 2776 2647 2777 snprintf (str, MXSTR, "Starting EventBuilder V15.07 A"); 2778 factOut (kInfo, -1, str); 2648 factPrintf(kInfo, -1, "Starting EventBuilder V15.07 A"); 2779 2649 2780 2650 //initialize run control logics … … 2791 2661 gi_maxProc = g_maxProc; 2792 2662 if (gi_maxProc <= 0 || gi_maxProc > 90) { 2793 snprintf (str, MXSTR, "Illegal number of processes %d", gi_maxProc); 2794 factOut (kFatal, 301, str); 2663 factPrintf(kFatal, 301, "Illegal number of processes %d", gi_maxProc); 2795 2664 gi_maxProc = 1; 2796 2665 }
Note:
See TracChangeset
for help on using the changeset viewer.