Пример #1
2
int main()
{
    int handle, status, nevents, nwords, i;
    uint32_t  evBuf[16], *ip;

    status = evOpen("/tmp/fileTestSmallBigEndian.ev", "a", &handle);
    nevents = 0;

    /* bank  header */
    evBuf[0]  = 0x0000000f;        evBuf[1]  = 0x00020b02;

    /* data */
    evBuf[2]  = 0x0000000c;        evBuf[3]  = 0x0000000d;
    evBuf[4]  = 0x0000000e;        evBuf[5]  = 0x0000000f;
    evBuf[6]  = 0x00000010;        evBuf[7]  = 0x00000011;
    evBuf[8]  = 0x00000012;        evBuf[9]  = 0x00000013;
    evBuf[10] = 0x00000014;        evBuf[11] = 0x00000015;
    evBuf[12] = 0x00000016;        evBuf[13] = 0x00000017;
    evBuf[14] = 0x00000018;        evBuf[15] = 0x00000019;


    status = evWrite(handle, evBuf);
    printf ("    Write file, status = %d\n", status);
    status = evClose(handle);
    printf ("    Closed file, status = %d\n\n", status);
}
Пример #2
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);
}
Пример #3
0
static void *closeThread(void *arg) {

    int status;
    sched_yield();
//    printf ("    *** Sleep in close thread\n");
//    sleep(1);
    printf ("    *** Call evClose() in close thread\n");
    status = evClose(handle);
    printf ("    \"Closed\" buffer, status = %#x\n\n", status);

}
Пример #4
0
static void
__end()
{
  int ii, total_count, rem_count;

  CDODISABLE(TEST,1,0);

#ifdef USE_GEM
  printf("\n  Read %d events\n\n",*(rol->nevents));
  evClose(input_handle);
#endif

  printf("INFO: User End 1 Executed\n");

  return;
}
Пример #5
0
int main(int argc, char **argv)
{
    int handle, status, nevents, nwords, debug=0;
    uint32_t *buffer;
    int i, maxEvBlk = 2;
    char *filename;


    /* The beginning "|" tells evio to open a pipe and write to that
     * so it goes to the stdin of evReadPipe. */
    filename = "|evReadPipe";
    filename = "-";
    

    if (debug) printf("Write to program = %s\n", filename+1);

    status = evOpen(filename, "w", &handle);
    if (debug) printf ("    Opened file, status = %d\n", status);

    status = evWriteDictionary(handle, dictionary);

    buffer = makeEvent();

    if (debug) printEvent(1, buffer);


    for (i=0; i < 3; i++) {
        status = evWrite(handle, buffer);
        if (debug) printf ("    Wrote event to file status = %d\n",status);
    }

    status = evClose(handle);
    if (debug) printf ("    evWritePipe: closed file, status = %d\n\n", status);
 
    free(buffer);
}
Пример #6
0
int
main(int argc, char **argv)
{
  int i, nw, status, trig, layer, strip;
  int l, tag, num, nchan[22], *nchanptr, nn, mm, npulses;
  int pulse_integral, pulse_time, pulse_min, pulse_max;
  int ind, fragtag, fragnum, nbytes, ind_data, timestamp_flag, type, *nhits;
  int slot, slot_old, event, chan, tdc;
  int banktag = 0xe102, banknum = 0, banktyp = 0xf;
  char *fmt = "c,i,l,N(c,N(s,i,s,s))";
  unsigned int ret, word;
  unsigned long long timestamp, timestamp_old;
  unsigned char *end, *start;
  FILE *fd;
  GET_PUT_INIT;

  if(argc!=3) printf("Usage: evioUtilTest <input evio file> <output evio file>\n");
  input_filename = strdup(argv[1]);
  output_filename = strdup(argv[2]);
  printf("Use >%s< as input file\n",input_filename);
  printf("Use >%s< as output file\n",output_filename);
  if(!strcmp(input_filename,output_filename))
  {
    printf("input and output files must be different - exit\n");
    exit(0);
  }

  fd = fopen(output_filename,"r");
  if(fd>0)
  {
    printf("Output file %s exist - exit\n",output_filename);
    fclose(fd);
    exit(0);
  }

  /* open evio input file */
  if((status = evOpen(input_filename,"r",&input_handle))!=0)
  {
    printf("\n ?Unable to open input file %s, status=%d\n\n",input_filename,status);
    exit(1);
  }

  /* open evio output file */
  if((status = evOpen(output_filename,"w",&output_handle))!=0)
  {
    printf("\n ?Unable to open output file %s, status=%d\n\n",output_filename,status);
    exit(1);
  }


  nevent=0;
  nwrite=0;
  trig = 0;
  pulse_min = 0;
  pulse_max = 0;
  npulses = 1;
  timestamp = 0x0102030405LL;
  while( (status=evRead(input_handle,buf,MAXEVIOBUF))==0 && nevent < max_event)
  {
    nevent++;
    if(!(nevent%10000)) printf("processed %d events\n",nevent);
    if(skip_event>=nevent) continue;
    /*if(user_event_select(buf)==0) continue;*/









    /**********************/
	/* evioBankUtil stuff */


#if 0

    /********/
    /* ECAL */
    /********/

	fragtag = 1602;
    fragnum = 0;
    tag = 1602;

    printf("\n");
    for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */
	{
      ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data);
      if(ind > 0)
	  {
		/*
		PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4));
		*/

        if(num==1)      printf("SECTOR: ");
        else if(num==2) printf("    IO: ");
        else if(num==3) printf("  VIEW: ");
        else if(num==4) printf(" STRIP: ");
        else if(num==5) printf("   ADC: ");
        else if(num==6) printf("   TDC: ");

        for(i=0; i<nbytes/4; i++)
		{
          inBuf[num][i] = buf[ind_data+i];
          printf("%6d",inBuf[num][i]);
		}
        printf("\n");
	  }
	}
    printf("\n");



    /* clean up */
    nw = 0;
	printf("Process %d hit candidates\n",nbytes/4);
    for(i=0; i<nbytes/4; i++)
	{
      if(inBuf[1][i] != 5) continue; /* skip wrong sectors */
      if(inBuf[5][i] <= 0) continue; /* skip zero energy */

      aBuf[nw].sector = inBuf[1][i];
      aBuf[nw].io     = inBuf[2][i];
      aBuf[nw].view   = inBuf[3][i];
      aBuf[nw].strip  = inBuf[4][i];
      aBuf[nw].adc    = inBuf[5][i];
      aBuf[nw].tdc    = inBuf[6][i];
	  nw++;
	}

	printf("Found %d good hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}
	printf("\n");

    /* sort */
    qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare);

	printf("Sorted %d hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}

    if(ind > 0)
	{
      trig ++;
      slot_old = 0;
	  
      i = evOpenFrag(buf, 7, 1);
      printf("evOpenFrag returned %d\n",i);
	  
      ret = evOpenBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data);
      printf("evOpenBank returns = %d\n",ret);

      b08out = (unsigned char *)&buf[ind_data];
      printf("first b08out = 0x%08x\n",b08out);

	  for(i=0; i<22; i++) nchan[i] = 0;

      for(i=0; i<nw; i++)
      {
        printf("begin while: b08=0x%08x\n",b08);

		layer = (aBuf[i].io-1)*3+aBuf[i].view-1;
		printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer);
        strip = aBuf[i].strip-1;
        slot = adcslotecal [layer] [strip];
		chan = adcchanecal [layer] [strip];
        printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]);

        if(slot != slot_old)
		{
          slot_old = slot;

          PUT8(slot);
          PUT32(trig);
          PUT64(timestamp);

          nchan[slot]=0;
          nchanptr = (unsigned int *)b08out;
          PUT32(nchan[slot]); /* reserve space for channel counter */

          printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]);
		}

        /*for(nn=0; nn<nchan[slot]; nn++)*/
	    {
	      nchan[slot] ++;
          *nchanptr = nchan[slot];

          PUT8(chan);
          PUT32(npulses);
          printf("  chan=%d, npulses=%d\n",chan,npulses);

          for(mm=0; mm<npulses; mm++)
	      {
            pulse_integral = aBuf[i].adc;
            pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */
            PUT16(pulse_time);
            PUT32(pulse_integral);
            PUT16(pulse_min);
            PUT16(pulse_max);
            printf("  pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral);
        /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/
	      }

          printf("last b08out=0x%08x\n",b08out);
        }
      }
	  /*printf("last b08out = 0x%08x\n",b08out);*/
      evCloseBank(buf, 7/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out);
	}

#endif




#if 1

    /********/
    /* PCAL */
    /********/

	fragtag = 1502;
    fragnum = 0;
    tag = 1502;

    printf("\n");
    for(num=1; num<=6; num++) /* 1-sector, 2-io, 3-view, 4-strip, 5-adc, 6-tdc */
	{
      ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data);
      if(ind > 0)
	  {
		/*
		PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4));
		*/

        if(num==1)      printf("SECTOR: ");
        else if(num==2) printf("    IO: ");
        else if(num==3) printf("  VIEW: ");
        else if(num==4) printf(" STRIP: ");
        else if(num==5) printf("   ADC: ");
        else if(num==6) printf("   TDC: ");

        for(i=0; i<nbytes/4; i++)
		{
          inBuf[num][i] = buf[ind_data+i];
          printf("%6d",inBuf[num][i]);
		}
        printf("\n");
	  }
	}
    printf("\n");



    /* clean up */
    nw = 0;
	printf("Process %d hit candidates\n",nbytes/4);
    for(i=0; i<nbytes/4; i++)
	{
      if(inBuf[1][i] != 5) continue; /* skip wrong sectors */
      if(inBuf[5][i] <= 0) continue; /* skip zero energy */

      aBuf[nw].sector = inBuf[1][i];
      aBuf[nw].io     = inBuf[2][i];
      aBuf[nw].view   = inBuf[3][i];
      aBuf[nw].strip  = inBuf[4][i];
      aBuf[nw].adc    = inBuf[5][i];
      aBuf[nw].tdc    = inBuf[6][i];
	  nw++;
	}

	printf("Found %d good hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}
	printf("\n");

    /* sort */
    qsort((void *)aBuf, nw, sizeof(ECData), (int (*) (const void *, const void *))ecdata_compare);

	printf("Sorted %d hits\n",nw);
    for(num=1; num<=6; num++)
	{
      if(num==1)      printf("SECTOR: ");
      else if(num==2) printf("    IO: ");
      else if(num==3) printf("  VIEW: ");
      else if(num==4) printf(" STRIP: ");
      else if(num==5) printf("   ADC: ");
      else if(num==6) printf("   TDC: ");
      for(i=0; i<nw; i++)
	  {
        if(num==1)      printf("%6d",aBuf[i].sector);
        else if(num==2) printf("%6d",aBuf[i].io);
        else if(num==3) printf("%6d",aBuf[i].view);
        else if(num==4) printf("%6d",aBuf[i].strip);
        else if(num==5) printf("%6d",aBuf[i].adc);
        else if(num==6) printf("%6d",aBuf[i].tdc);
	  }
	  printf("\n");
	}

    if(ind > 0)
	{
      trig ++;
      slot_old = 0;
	  
      i = evOpenFrag(buf, 8, 1);
      printf("evOpenFrag returned %d\n",i);
	  
      ret = evOpenBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, banktyp, fmt, &ind_data);
      printf("evOpenBank returns = %d\n",ret);

      b08out = (unsigned char *)&buf[ind_data];
      printf("first b08out = 0x%08x\n",b08out);

	  for(i=0; i<22; i++) nchan[i] = 0;

      for(i=0; i<nw; i++)
      {
        printf("begin while: b08=0x%08x\n",b08);

		layer = (aBuf[i].io-1)*3+aBuf[i].view-1;
		printf("+++++++++++++ %d %d -> %d\n",aBuf[i].io,aBuf[i].view,layer);
        strip = aBuf[i].strip-1;
        slot = adcslotpcal [layer] [strip];
		chan = adcchanpcal [layer] [strip];
        printf("### layer=%d strip=%d -> slot=%d chan=%d (nchan(so far)=%d)\n",layer,strip,slot,chan,nchan[slot]);

        if(slot != slot_old)
		{
          slot_old = slot;

          PUT8(slot);
          PUT32(trig);
          PUT64(timestamp);

          nchan[slot]=0;
          nchanptr = (unsigned int *)b08out;
          PUT32(nchan[slot]); /* reserve space for channel counter */

          printf("slot=%d, trig=%d, timestamp=%lld nchan[%d]=%d\n",slot,trig,timestamp,slot,nchan[slot]);
		}

        /*for(nn=0; nn<nchan[slot]; nn++)*/
	    {
	      nchan[slot] ++;
          *nchanptr = nchan[slot];

          PUT8(chan);
          PUT32(npulses);
          printf("  chan=%d, npulses=%d\n",chan,npulses);

          for(mm=0; mm<npulses; mm++)
	      {
            pulse_integral = aBuf[i].adc;
            pulse_time = aBuf[i].tdc-25000; /* sergey: arbitrary !!! */
            PUT16(pulse_time);
            PUT32(pulse_integral);
            PUT16(pulse_min);
            PUT16(pulse_max);
            printf("  pulse_time=%d pulse_integral=%d\n",pulse_time,pulse_integral);
        /*printf(">>> layer %d, strip %d -> adc %d\n",adclayerecal[slot][chan],adcstripecal[slot][chan],pulse_integral);*/
	      }

          printf("last b08out=0x%08x\n",b08out);
        }
      }
	  /*printf("last b08out = 0x%08x\n",b08out);*/
      evCloseBank(buf, 8/*fragtag*/, 1/*fragnum*/, banktag, banknum, b08out);
	}
#endif



	/* evioBankUtil stuff */
    /**********************/





    nwrite++;
	printf("nwrite=%d\n",nwrite);
    status = evWrite(output_handle,buf);
    if(status!=0)
    {
      printf("\n ?evWrite error output file %s, status=%d (0x%08x)\n\n",output_filename,status,status);
      exit(1);
    }

    if( (max_event>0) && (nevent>=max_event+skip_event) ) break;

  }


  /* done */
  printf("\n  Read %d events, copied %d events\n\n",nevent,nwrite);
  evClose(output_handle);
  evClose(input_handle);

  exit(0);
}
Пример #7
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);

}
Пример #8
0
static void *receiverThread(void *arg) {
    int listenfd=0, handle, status, nevents, nwords, *ip;
    int i;
    uint32_t dictLen, buffer[2048];
    char *dict;
    struct sockaddr_in cliaddr;
    socklen_t len = sizeof(cliaddr);
    
printf("Receiver thread: listen on server socket\n");

    /* open a listening socket */
    listenfd = tcp_listen(serverPort, bufferSize);
    if (listenfd < 0) {
        printf("Error starting listening socket\n");
        exit(1);
    }

    /* wait for connection to client */
printf("Receiver thread: accepting\n");
    recvFd = Accept(listenfd, (SA *) &cliaddr, &len);
    if (recvFd < 0) {
        printf("Error receiving client TCP connection\n");
        exit(1);
    }
    
printf("Receiver thread: got client ... \n");
    status = evOpenSocket(recvFd, "r", &handle);
printf ("Receiver thread: Opened socket, status = %#x\n", status);

     status = evGetDictionary(handle, &dict, &dictLen);
printf ("Receiver thread: get dictionary, status = %#x\n\n", status);

     if (dictionary != NULL) {
         printf("DICTIONARY =\n%s\n", dict);
         free(dict);
     }

     nevents = 0;
    
     while (1) {

//printf("Receiver thread: Waiting on evRead\n");
         if ((status = evRead(handle, buffer, 2048)) != S_SUCCESS) {
             printf("Receiver thread: Done reading\n");
             break;
         }
         
         nevents++;
        
         printf("Receiver thread: Read event #%d,  len = %d data words\n", nevents, buffer[0] - 1);

         ip = buffer;
         nwords = buffer[0] + 1;
        
         printf("      Header words\n");
         printf("        %#10.8x\n", *ip++);
         printf("        %#10.8x\n\n", *ip++);
         printf("      Data words\n");
   
         nwords -= 2;
        
         for (; nwords > 0; nwords-=4) {
             for (i = MIN(nwords,4); i > 0; i--) {
                 printf("        %#10.8x", *ip++);
             }
             printf("\n");
         }
         printf("\n");
     }
    
printf("\nReceiver thread: Last read, status = %x\n", status);
    if (status == EOF) {
        printf("Receiver thread: Last read, reached EOF!\n");
    }
    
    status = evClose(handle);
    printf ("Receiver thread: Closed socket, status = %#x\n\n", status);
}
Пример #9
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);
}
Пример #10
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);
}
Пример #11
0
void
usrtrig(unsigned long EVTYPE, unsigned long EVSOURCE)
{
  int len, ii, status;
  int ind, tag, num, fragtag, fragnum, nbytes, ind_data, timestamp_flag, type, *nhits;
  GET_PUT_INIT;

  rol->dabufp = (long *) 0;

  CEOPEN(EVTYPE, BT_BANKS);

  /*usleep(500);*/
  sleep(1);
  
#ifdef USE_GEM

reopened:

  if( (status = evRead(input_handle,buf,MAXEVIOBUF)) == 0 )
  {
	//fragtag = 7;
	fragtag = 3;
    fragnum = -1;
    //tag = 57631;
    num = 0;
    
    for(tag=9; tag<=13; tag++) /* 5,6,7,8,9,10,11,12 */
	{
      ind = evLinkBank(buf, fragtag, fragnum, tag, num, &nbytes, &ind_data);
      
      if(ind > 0)
	  {
		
		/*PRINT_BUFFER(&buf[ind_data], &buf[ind_data]+(nbytes/4));*/

        BANKOPEN(tag,1,num);
        len = nbytes/4;
        for(ii=0; ii<len; ii++)
        {
          *rol->dabufp++ = buf[ind_data+ii];
          
        }
        BANKCLOSE;

	  }
	}

  }
  else if(status==-1)
  {
    printf("Reached end-of-file (status=%d), reopen\n",status);fflush(stdout);

    evClose(input_handle);

    /* open evio input file */
    if((status = evOpen(input_filename,"r",&input_handle))!=0)
    {
      printf("\n ?Unable to open input file >%s<, status=%d\n\n",input_filename,status);
      exit(1);
    }
    else
    {
      printf("\n Open data file >%s<\n",input_filename);
    }
    goto reopened;
  }
  else
  {
    printf("Error reading data file (status=%d)\n",status);fflush(stdout);
    exit(1);
  }



#endif

  /*
  BANKOPEN(0xe1FF,1,rol->pid);
  len = 20;
  for(ii=0; ii<len; ii++)
  {
    *rol->dabufp++ = ii;
  }
  BANKCLOSE;
  */

  CECLOSE;

  return;
}