Ejemplo n.º 1
0
int evread
#else
int evread_
#endif
(int *handle,int *buffer,int *buflen)
{
  return(evRead(*handle,buffer,*buflen));
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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;
}