Example #1
2
int main1()
{
    int handle, status;
    uint32_t *ip, *pBuf;
    uint32_t maxEvBlk = 4;
    // uint64_t split = 230;
    uint64_t split = 100;


    printf("\nEvent I/O tests...\n");
    status = evOpen("/tmp/firstEventTestC.ev", "s", &handle);
    printf ("    Opened /tmp/firstEventTest.ev, status = %d\n", status);

    status = evIoctl(handle, "N", (void *) (&maxEvBlk));
    printf ("    Changed max events/block to %d, status = %#x\n", maxEvBlk, status);

    status = evIoctl(handle, "S", (void *) (&split));
    printf ("    Changed split to %d, status = %#x\n", split, status);

    printf ("    Write dictionary, status = %d\n",status);
    status = evWriteDictionary(handle, dictionary);

    pBuf = makeFirstEvent(1);

    printf ("    Write first event, status = %d\n",status);
    status = evWriteFirstEvent(handle, pBuf);

    ip = makeEvent();

    printf ("    Write event 1, status = %d\n",status);
    status = evWrite(handle, ip);

    printf ("    Write event 2, status = %d\n",status);
    status = evWrite(handle, ip);

    printf ("    Write event 3, status = %d\n",status);
    status = evWrite(handle, ip);

    status = evClose(handle);
    printf ("    Closed file, status = %d\n\n", status);

    free(pBuf);
    free(ip);
}
Example #2
0
int main1() {
    int status, nevents, nwords;
    int i, maxEvBlk = 2;
    int *ip, *pBuf, *dict, dictLen, bufLen;
    size_t bufSize = 10000;
    char eventBuffer[4*bufSize];
    pthread_t  tid;
    struct timespec wait = {0, 10000L}; /* .00001 sec */

    memset(eventBuffer, 0, 4*bufSize);


    printf("\nEvent I/O tests to BUFFER (%p) ...\n", eventBuffer);
    status = evOpenBuffer(eventBuffer, bufSize, "w", &handle);

    status = evIoctl(handle, "N", (void *) (&maxEvBlk));
    printf ("    Changed max events/block to %d, status = %#x\n", maxEvBlk, status);

    status = evWriteDictionary(handle, dictionary);
    printf ("    Write dictionary to buffer, status = %#x\n\n", status);

    /* Launch thread to close */
    pthread_create(&tid, NULL, closeThread, (void *)NULL);

    while (1) {
        /* write 1 event to buffer */
        status = evWrite(handle, data1);
        if (status != S_SUCCESS) {
            printf ("    error in write, status = %#x\n\n", status);
            break;
        }
        nanosleep(&wait, NULL);
    }
}
Example #3
0
int main()
{
    int handle, status, nevents, nwords;
    int buffer[2048], i, maxEvBlk = 2;
    int *ip, *pBuf, *dict, dictLen, bufLen, bufLenBytes;
    uint32_t bank1[3], bank2[3], bank3[3];
    char eventBuffer[4 * ((4*8) + (5*3))];
    bufLen = (4*8) + (5*3);
    bufLenBytes = 4 * bufLen;
    memset(eventBuffer, 0, bufLenBytes);

    // create 3 little banks
    // length of 2 ints
    bank1[0] = bank2[0] = bank3[0] = 2;
    // tag = 1,2,3, banks contains ints, num = 1,2,3 
    bank1[1] = 1 << 16 | 0x1 << 8 | 1;
    bank2[1] = 2 << 16 | 0x1 << 8 | 2;
    bank3[1] = 3 << 16 | 0x1 << 8 | 3;
    // data = 1,2,3
    bank1[2] = 1;
    bank2[2] = 2;
    bank3[2] = 3;
    


    printf("\nEvent I/O tests to BUFFER  ...\n");
    status = evOpenBuffer(eventBuffer, bufLen, "w", &handle);
    printf ("    Opened buffer, status = %#x\n", status);

//    status = evWriteDictionary(handle, dictionary);
//    printf ("    Write dictionary to buffer, status = %#x\n\n", status);

    status = evIoctl(handle, "N", (void *) (&maxEvBlk));
    printf ("    Changed max events/block to %d, status = %#x\n", maxEvBlk, status);

    status = evWrite(handle, bank1);
    printf ("    Wrote event #1 to buffer, status = %#x\n",status);
    if (status != S_SUCCESS) {
        printf("Error writing, %s, quit\n", evPerror(status));
        exit(1);
    }

    status = evGetBufferLength(handle, &bufLenBytes);
    printf ("    Wrote %d bytes to buffer\n", bufLenBytes);
    
printBuffer((uint32_t *) eventBuffer, bufLenBytes/4);

    status = evWrite(handle, bank2);
    printf ("    Wrote event #2 to buffer, status = %#x\n",status);
    if (status != S_SUCCESS) {
        printf("Error writing, %s, quit\n", evPerror(status));
        exit(1);
    }

    status = evGetBufferLength(handle, &bufLenBytes);
    printf ("    Wrote %d bytes to buffer\n", bufLenBytes);

printBuffer((uint32_t *) eventBuffer, bufLenBytes/4);

    status = evWrite(handle, bank3);
    printf ("    Wrote event #3 to buffer, status = %#x\n",status);
    if (status != S_SUCCESS) {
        printf("Error writing, %s, quit\n", evPerror(status));
        exit(1);
    }

    status = evGetBufferLength(handle, &bufLenBytes);
    printf ("    Wrote %d bytes to buffer\n", bufLenBytes);

printBuffer((uint32_t *) eventBuffer, bufLenBytes/4);

    status = evWrite(handle, bank1);
    printf ("    Wrote event #1 to buffer, status = %#x\n",status);
    if (status != S_SUCCESS) {
        printf("Error writing, %s, quit\n", evPerror(status));
        exit(1);
    }

    status = evGetBufferLength(handle, &bufLenBytes);
    printf ("    Wrote %d bytes to buffer\n", bufLenBytes);
    
printBuffer((uint32_t *) eventBuffer, bufLenBytes/4);

    status = evWrite(handle, bank2);
    printf ("    Wrote event #2 to buffer, status = %#x\n",status);
    if (status != S_SUCCESS) {
        printf("Error writing, %s, quit\n", evPerror(status));
        exit(1);
    }

    status = evGetBufferLength(handle, &bufLenBytes);
    printf ("    Wrote %d bytes to buffer\n", bufLenBytes);

    status = evClose(handle);
    printf ("    \"Closed\" buffer, status = %#x\n\n", status);

printBuffer((uint32_t *) eventBuffer, bufLen);

}
Example #4
0
int main()
{
    int i, handle, status, sendFd, maxEvBlk=2;
    pthread_t tid;
    // char stuff[128];


    printf("Try running Receiver thread\n");
      
    /* run receiver thread */
    pthread_create(&tid, NULL, receiverThread, (void *) NULL);

    printf("Sending thd: sleep for 2 seconds\n");
    
    /* give it a chance to start */
    sleep(2);

    /* Create sending socket */
    sendFd = createSendFd();

    printf("Sending thd: socket fd = %d\n\n", sendFd);

    printf("\nSending thd: event I/O tests to socket (%d)\n", sendFd);
    status = evOpenSocket(sendFd, "w", &handle);
    
    printf("Sending thd: sleep for 1 more seconds\n");
    
    /* give it a chance to start */
    sleep(1);
    
    printf ("Sending thd: opened socket, status = %#x\n", status);

    
    status = evIoctl(handle, "N", (void *) (&maxEvBlk));
    printf ("Sending thd: changed max events/block to %d, status = %d\n", maxEvBlk, status);
    

    /* target block size = 8 header + 16 event words */
    i = 40;
    status = evIoctl(handle, "B", &i);
    if (status == S_EVFILE_BADSIZEREQ) {
        printf("Sending thd: bad value for target block size given\n");
        exit(0);
    }
    else if (status != S_SUCCESS) {
        printf("Sending thd: error setting target block size\n");
        exit(0);
    }
    printf ("Sending thd: changed target block size to %d, status = %d\n", i, status);


    /* buffer size = 2-8 headers + 16 event words or */
    
    i = 48;
    status = evIoctl(handle, "W", &i);
    if (status == S_EVFILE_BADSIZEREQ) {
        printf("Sending thd: bad value for buffer size given\n");
        exit(0);
    }
    else if (status != S_SUCCESS) {
        printf("Sending thd: error setting buffer size\n");
        exit(0);
    }
    printf ("Sending thd: changed buffer size to %d, status = %d\n", i, status);
    

    status = evWriteDictionary(handle, dictionary);
    printf ("Sending thd: write dictionary to socket, status = %d\n\n", status);

//    printf ("Sending thd: will write ** MED (16 word) ** ev to socket, status = %d\n",status);
//    status = evWrite(handle, evBuf_16);
    for (i=0; i < 4; i++) {
        printf("\nevtestSock: write little event %d ...\n", (i+1));
        status = evWrite(handle, evBuf_8);
        if (status != S_SUCCESS) {
            printf("Error in evWrite(), status = %x\n", status);
            exit(0);
        }
//        printf("\nEnter to continue\n");
//        gets(stuff);
    }

//    printf ("Sending thd: will write ** LITTLE (8 word) ** ev to socket, status = %d\n",status);
//    status = evWrite(handle, evBuf_8);

    printf ("Sending thd: will write ** BIG (18 word) ** ev to socket, status = %d\n",status);
    status = evWrite(handle, evBuf_18);

    printf ("Sending thd: will write ** HUGE (20 word) ** ev to socket, status = %d\n",status);
    status = evWrite(handle, evBuf_20);

    printf ("Sending thd: Call close()\n");
    status = evClose(handle);
    printf ("Sending thd: closed send socket, status %#x, wait 2 seconds\n\n", status);

    /* Don't exit the program before the receiver thread can do its stuff. */
    sleep(2);

    /* Close socket */
    close(sendFd);

    return(0);
}
Example #5
0
int main (int argc, char **argv)
{
    int i, handle, nevents, status, bufLen, nWords, dLen, version;
    uint32_t *buf, *ip;
    char *dictionary = NULL;


    if (argc != 2) {
        printf("Incorrect number of arguments:\n");
        printf("  usage: %s filename\n", argv[0]);
        exit(-1);
    }

    if ( (status = evOpen(argv[1], "r", &handle)) < 0) {
        printf("Unable to open file %s status = %d\n",argv[1],status);
        exit(-1);
    } else {
        printf("Opened %s for reading, hit <enter> to see each individual event\n\n",argv[1]);
    }

    /* Get evio version # of file */
    status = evIoctl(handle, "v", &version);
    if (status == S_SUCCESS) {
        printf("Evio file version = %d\n", version);
    }

    /* Get a dictionary if there is one */
    status = evGetDictionary(handle, &dictionary, &dLen);
    if (status == S_SUCCESS && dictionary != NULL) {
        printf("Dictionary =\n%s\n\n", dictionary);
        free(dictionary);
    }

    nevents=0;
    while ((status = evReadAlloc(handle, &buf, &bufLen))==0) {
        nevents++;
        printf("    Event #%d,  len = %d words\n", nevents, buf[0]);
        nWords = buf[0] + 1;

        for (ip=buf; nWords > 0; nWords-=4) {
            for (i = MIN(nWords,4); i > 0; i--) {
                printf("      %#10.8x", *ip++);
            }
            printf("\n");
        }
       
        printf("\n");

        free(buf);
        printf("Hit enter for next event\n");
        getc(stdin);
    }

    if ( status == EOF ) {
        printf("Hit end-of-file\n");
    }
    else {
        printf("Error reading file, quit\n");
    }
    evClose(handle);
  
    exit(0);
}