Changeset 12491 for trunk/FACT++/src/EventBuilder.c
- Timestamp:
- 11/11/11 02:47:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.c
r12485 r12491 158 158 void* ETI_Malloc(int evtId, int evtIndex) 159 159 { 160 int i,j; 161 for (i=0;i<numAllocatedChunks;i++) { 160 for (int i=0;i<numAllocatedChunks;i++) { 162 161 if (EtiMemoryChunks[i].nFreeSlots > 0) { 163 for ( j=0;j<EtiMemoryChunks[i].nSlots;j++)162 for (int j=0;j<EtiMemoryChunks[i].nSlots;j++) 164 163 { 165 164 if (EtiMemoryChunks[i].events[j] == -1) … … 204 203 mBufferMapping[evtIndex].slot = 0; 205 204 206 for (i =1;i<numNewSlots;i++)205 for (int i=1;i<numNewSlots;i++) 207 206 { 208 207 EtiMemoryChunks[numAllocatedChunks].pointers[i] = &(((char*)(EtiMemoryChunks[numAllocatedChunks].pointers[i-1]))[MAX_SLOT_SIZE]); … … 453 452 // initialize mBuffer (mark all entries as unused\empty) 454 453 455 int i,j; 456 uint32_t actime; 457 458 actime = g_actTime + 50000000; 459 460 for (i = 0; i < MAX_EVT * MAX_RUN; i++) { 454 uint32_t actime = g_actTime + 50000000; 455 456 for (int i = 0; i < MAX_EVT * MAX_RUN; i++) { 461 457 mBuffer[i].evNum = mBuffer[i].nRoi = -1; 462 458 mBuffer[i].runNum = 0; … … 472 468 //END ETIENNE 473 469 } 474 for ( j=0;j<MAX_CHUNKS;j++)470 for (int j=0;j<MAX_CHUNKS;j++) 475 471 EtiMemoryChunks[j].pointers[0] = NULL; 476 472 … … 505 501 int jold; 506 502 507 int i, k, jr,b, evFree;503 int i, b, evFree; 508 504 int headmem = 0; 509 505 size_t needmem = 0; … … 520 516 } 521 517 522 for ( jr = 1; jr < 8; jr++) {518 for (int jr = 1; jr < 8; jr++) { 523 519 if (nRoi[jr] != nRoi[0]) { 524 520 snprintf (str, MXSTR, "wrong nRoi[%d]: %d %d", jr, nRoi[jr], … … 542 538 evFree = -1; 543 539 544 for ( k = 0; k < MAX_RUN; k++) {540 for (int k = 0; k < MAX_RUN; k++) { 545 541 if (mBuffer[i].evNum == evID && mBuffer[i].runNum == runID) { //event is already registered; 546 542 // is it ok ???? … … 588 584 oldest = g_actTime + 1000; 589 585 jold = -1; 590 for ( k = 0; k < MAX_RUN; k++) {586 for (int k = 0; k < MAX_RUN; k++) { 591 587 if (runCtrl[k].runId == runID) { 592 588 // if (runCtrl[k].procId > 0) { //run is closed -> reject … … 676 672 mBuffer[i].fEvent = NULL; 677 673 gj.usdMem = 0; 678 for ( k=0;k<numAllocatedChunks;k++)674 for (int k=0;k<numAllocatedChunks;k++) 679 675 gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE; 680 676 if (gj.usdMem > gj.maxMem) … … 722 718 //flag all boards as unused 723 719 mBuffer[i].nBoard = 0; 724 for ( k = 0; k < NBOARDS; k++) {720 for (int k = 0; k < NBOARDS; k++) { 725 721 mBuffer[i].board[k] = -1; 726 722 } 727 723 //flag all pixels as unused 728 for ( k = 0; k < NPIX; k++) {724 for (int k = 0; k < NPIX; k++) { 729 725 mBuffer[i].fEvent->StartPix[k] = -1; 730 726 } 731 727 //flag all TMark as unused 732 for ( k = 0; k < NTMARK; k++) {728 for (int k = 0; k < NTMARK; k++) { 733 729 mBuffer[i].fEvent->StartTM[k] = -1; 734 730 } … … 750 746 //gj.usdMem += needmem + headmem + gi_maxSize; 751 747 gj.usdMem = 0; 752 for ( k=0;k<numAllocatedChunks;k++)748 for (int k=0;k<numAllocatedChunks;k++) 753 749 { 754 750 gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE; … … 818 814 // gj.usdMem = gj.usdMem - freemem - headmem - gi_maxSize; 819 815 gj.usdMem = 0; 820 int k; 821 for (k=0;k<numAllocatedChunks;k++) 816 for (int k=0;k<numAllocatedChunks;k++) 822 817 { 823 818 gj.usdMem += EtiMemoryChunks[k].nSlots * MAX_SLOT_SIZE; … … 840 835 resetEvtStat () 841 836 { 842 int i; 843 844 for (i = 0; i < MAX_SOCK; i++) 837 for (int i = 0; i < MAX_SOCK; i++) 845 838 gi.numRead[i] = 0; 846 839 847 for (i = 0; i < NBOARDS; i++) {840 for (int i = 0; i < NBOARDS; i++) { 848 841 gi.gotByte[i] = 0; 849 842 gi.gotErr[i] = 0; … … 1228 1221 1229 1222 //End of the header. to channels now 1230 int eCount = 0;1231 1223 int eStart = 36; 1232 int ePatchesCount = 0; 1233 int currentRoi; 1234 for (;ePatchesCount<4*9;ePatchesCount++) 1224 for (int ePatchesCount = 0; ePatchesCount<4*9;ePatchesCount++) 1235 1225 { 1236 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//id 1237 eCount++; 1238 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//start_cell 1239 eCount++; 1240 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//roi 1241 currentRoi = rd[i].rBuf->S[eStart+eCount]; 1242 eCount++; 1243 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//filling 1244 eCount++; 1245 eCount+=currentRoi;//skip the pixel data 1246 } 1247 // snprintf(str, MXSTR, "Swapped %d bytes", eCount*2); 1248 // factOut(kError, 000, str); 1226 rd[i].rBuf->S[eStart+0] = ntohs(rd[i].rBuf->S[eStart+0]);//id 1227 rd[i].rBuf->S[eStart+1] = ntohs(rd[i].rBuf->S[eStart+1]);//start_cell 1228 rd[i].rBuf->S[eStart+2] = ntohs(rd[i].rBuf->S[eStart+2]);//roi 1229 rd[i].rBuf->S[eStart+3] = ntohs(rd[i].rBuf->S[eStart+3]);//filling 1230 1231 eStart += 4+rd[i].rBuf->S[eStart+2];//skip the pixel data 1232 } 1249 1233 1250 1234 //channels done. footer now … … 1480 1464 } 1481 1465 goodhed++; 1482 //ETIENNE swap the header bytes already 1483 int eStart = 0; 1484 rd[i].rBuf->S[eStart+0] = ntohs(rd[i].rBuf->S[eStart+0]);//start_package_flag 1485 rd[i].rBuf->S[eStart+1] = ntohs(rd[i].rBuf->S[eStart+1]);//package_length 1486 rd[i].rBuf->S[eStart+2] = ntohs(rd[i].rBuf->S[eStart+2]);//version_no 1487 rd[i].rBuf->S[eStart+3] = ntohs(rd[i].rBuf->S[eStart+3]);//PLLLCK 1488 rd[i].rBuf->S[eStart+4] = ntohs(rd[i].rBuf->S[eStart+4]);//trigger_crc 1489 rd[i].rBuf->S[eStart+5] = ntohs(rd[i].rBuf->S[eStart+5]);//trigger_type 1490 rd[i].rBuf->I[eStart+3] = ntohl(rd[i].rBuf->I[eStart+3]);//trigger_id 1491 rd[i].rBuf->I[eStart+4] = ntohl(rd[i].rBuf->I[eStart+4]);//fad_evt_counter 1492 rd[i].rBuf->I[eStart+5] = ntohl(rd[i].rBuf->I[eStart+5]);//REFCLK_frequency 1493 rd[i].rBuf->S[eStart+12] = ntohs(rd[i].rBuf->S[eStart+12]);//board_id 1494 rd[i].rBuf->S[eStart+14] = ntohs(rd[i].rBuf->S[eStart+14]);//number_of_triggers_to_generate 1495 rd[i].rBuf->S[eStart+15] = ntohs(rd[i].rBuf->S[eStart+15]);//trigger_generator_prescaler 1496 // int eInter = ntohl(rd[i].rBuf->I[eStart+8]);//DNA 1497 // rd[i].rBuf->I[eStart+8] = ntohl(rd[i].rBuf->I[eStart+9]); 1498 //rd[i].rBuf->I[eStart+9] = eInter; 1499 rd[i].rBuf->I[eStart+10] = ntohl(rd[i].rBuf->I[eStart+10]);//time 1500 rd[i].rBuf->I[eStart+11] = ntohl(rd[i].rBuf->I[eStart+11]);//runnumber; 1501 int eCount = 24; 1502 for (;eCount<24+NTemp;eCount++) 1503 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//drs_temperature 1504 for (; eCount < 24+NTemp+NDAC; eCount++) 1505 rd[i].rBuf->S[eStart+eCount] = ntohs(rd[i].rBuf->S[eStart+eCount]);//dac 1506 1507 1508 // rd[i].fadLen = rd[i].rBuf->S[1] * 2; 1509 // snprintf(str, MXSTR, "Size of the fad buffer: %d", rd[i].fadLen); 1510 // factOut(kError, 000, str); 1511 1466 1467 // Swap everything except start_package_flag. 1468 // It is to difficult to find out where it is used how, 1469 // but it doesn't really matter because it is not really 1470 // used anywehere else 1471 rd[i].rBuf->S[1] = ntohs(rd[i].rBuf->S[1]); // package_length 1472 rd[i].rBuf->S[2] = ntohs(rd[i].rBuf->S[2]); // version_no 1473 rd[i].rBuf->S[3] = ntohs(rd[i].rBuf->S[3]); // PLLLCK 1474 rd[i].rBuf->S[4] = ntohs(rd[i].rBuf->S[4]); // trigger_crc 1475 rd[i].rBuf->S[5] = ntohs(rd[i].rBuf->S[5]); // trigger_type 1476 1477 rd[i].rBuf->S[12] = ntohs(rd[i].rBuf->S[12]); // board id 1478 rd[i].rBuf->S[13] = ntohs(rd[i].rBuf->S[13]); // adc_clock_phase_shift 1479 rd[i].rBuf->S[14] = ntohs(rd[i].rBuf->S[14]); // number_of_triggers_to_generate 1480 rd[i].rBuf->S[15] = ntohs(rd[i].rBuf->S[15]); // trigger_generator_prescaler 1481 1482 rd[i].rBuf->I[3] = ntohl(rd[i].rBuf->I[3]); // trigger_id 1483 rd[i].rBuf->I[4] = ntohl(rd[i].rBuf->I[4]); // fad_evt_counter 1484 rd[i].rBuf->I[5] = ntohl(rd[i].rBuf->I[5]); // REFCLK_frequency 1485 1486 rd[i].rBuf->I[10] = ntohl(rd[i].rBuf->I[10]); // runnumber; 1487 rd[i].rBuf->I[11] = ntohl(rd[i].rBuf->I[11]); // time; 1488 1489 for (int s=24;s<24+NTemp+NDAC;s++) 1490 rd[i].rBuf->S[s] = ntohs(rd[i].rBuf->S[s]); // drs_temperature / dac 1491 1492 rd[i].fadLen = rd[i].rBuf->S[1] * 2; 1512 1493 rd[i].fadVers = rd[i].rBuf->S[2]; 1513 rd[i].ftmTyp = rd[i].rBuf->S[5]; 1514 rd[i].ftmID = rd[i].rBuf->I[3]; //(FTMevt) 1515 rd[i].evtID = rd[i].rBuf->I[4]; //(FADevt) 1516 rd[i].runID = rd[i].rBuf->I[11]; 1517 rd[i].bufTyp = 1; //ready to read full record 1518 rd[i].bufLen = rd[i].fadLen - rd[i].bufPos; 1519 1494 rd[i].ftmTyp = rd[i].rBuf->S[5]; 1495 rd[i].ftmID = rd[i].rBuf->I[3]; //(FTMevt) 1496 rd[i].evtID = rd[i].rBuf->I[4]; //(FADevt) 1497 rd[i].runID = rd[i].rBuf->I[11]; 1498 rd[i].bufTyp = 1; //ready to read full record 1499 rd[i].bufLen = rd[i].fadLen - rd[i].bufPos; 1500 1501 #ifdef EVTDEBUG 1520 1502 int fadboard = rd[i].rBuf->S[12]; 1521 1503 int fadcrate = fadboard / 256; 1522 1504 fadboard = (fadcrate * 10 + fadboard % 256); 1523 #ifdef EVTDEBUG1524 1505 snprintf (str, MXSTR, 1525 1506 "sk %3d head: %5d %5d %5d %10d %4d %6d", i, … … 1534 1515 if (rd[i].bufLen <= head_len || rd[i].bufLen > MAX_LEN) { 1535 1516 snprintf (str, MXSTR, 1536 " illegal event-length on port %d", i);1517 "Illegal event-length %d on port %d, %d expected.", rd[i].bufLen, i, head_len); 1537 1518 factOut (kFatal, 881, str); 1538 1519 rd[i].bufLen = 100000; //? 1539 1520 } 1521 1540 1522 int fadBoard = rd[i].rBuf->S[12]; 1541 1523 debugHead (i, fadBoard, rd[i].rBuf);
Note:
See TracChangeset
for help on using the changeset viewer.