Пример #1
0
void
usrtrig(unsigned int EVTYPE, unsigned int EVSOURCE)
{
  int *jw, ind, ind2, i, ii, jj, jjj, blen, len, rlen, itdcbuf, nbytes;
  unsigned int *tdcbuf_save, *tdc, trailer;
  unsigned int *dabufp1, *dabufp2;
  int njjloops, slot;
  int nwords;
#ifndef VXWORKS
  TIMERL_VAR;
#endif
  char *chptr, *chptr0;

  /*printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);*/


  if(syncFlag) printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);

  rol->dabufp = NULL;

  /*
usleep(100);
  */
  /*
  sleep(1);
  */



  CEOPEN(EVTYPE, BT_BANKS); /* reformatted on CODA_format.c !!! */

  if((syncFlag<0)||(syncFlag>1))         /* illegal */
  {
    printf("Illegal1: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE);
  }
  else if((syncFlag==0)&&(EVTYPE==0))    /* illegal */
  {
    printf("Illegal2: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE);
  }
  else if((syncFlag==1)&&(EVTYPE==0))    /* force_sync (scaler) events */
  {
    ;
/*
!!! we are geting here on End transition: syncFlag=1 EVTYPE=0 !!!
*/
  }
  else if((syncFlag==0)&&(EVTYPE==15)) /* helicity strob events */
  {
    ;
  }
  else           /* physics and physics_sync events */
  {

    /* for EVIO format, will dump raw data */
    tdcbuf_save = tdcbuf;

    /*************/
	/* TS stuff */

    /* Set high, the first output port 
    tsSetOutputPort(1,0,0,0,0,0);
    */

    /* Grab the data from the TS */
vmeBusLock();
    len = tsReadBlock(tdcbuf,1000,1);
vmeBusUnlock();
    if(len<=0)
    {
      printf("ERROR in tsReadBlock : No data or error, len = %d\n",len);
      sleep(1);
    }
    else
    {
	  ;
	  /*
      printf("ts: len=%d\n",len);
      for(jj=0; jj<len; jj++) printf("ts[%2d] 0x%08x\n",jj,LSWAP(tdcbuf[jj]));
	  */
	  /*	  
ts: len=8
ts[ 0] 0x8555d101
ts[ 1] 0xff102001
ts[ 2] 0x3a010004
ts[ 3] 0x000001d1
ts[ 4] 0x3f0bb0db
ts[ 5] 0x00000005
ts[ 6] 0x02000000
ts[ 7] 0x8d400008
	  */


      BANKOPEN(0xe10A,1,rol->pid);
      for(jj=0; jj<len; jj++) *rol->dabufp++ = tdcbuf[jj];
      BANKCLOSE;
	  
    }

    /* Turn off all output ports 
    tsSetOutputPort(0,0,0,0,0,0);
    */
	/* TS stuff */
    /*************/





#ifdef DEBUG
    printf("trig1: start trigger processing\n");fflush(stdout);
#endif



#ifndef VXWORKS
TIMERL_START;
#endif

























  /* create HEAD bank if master and standalone crates, NOT slave */

	event_number = (EVENT_NUMBER) * block_level - block_level;

    BANKOPEN(0xe112,1,0);

	dabufp1 = rol->dabufp;

    *rol->dabufp ++ = LSWAP((0x10<<27)+block_level); /*block header*/

    for(ii=0; ii<block_level; ii++)
	{
      event_number ++;
	  /*
	  printf(">>>>>>>>>>>>> %d %d\n",(EVENT_NUMBER),event_number);
      sleep(1);
	  */
      *rol->dabufp ++ = LSWAP((0x12<<27)+(event_number&0x7FFFFFF)); /*event header*/

      nwords = 6; /* UPDATE THAT IF THE NUMBER OF DATA WORDS CHANGED BELOW !!! */
      *rol->dabufp ++ = LSWAP((0x14<<27)+nwords); /*head data*/

      /* COUNT DATA WORDS FROM HERE */
      *rol->dabufp ++ = 0; /*version  number */
      *rol->dabufp ++ = LSWAP(RUN_NUMBER); /*run  number */
      *rol->dabufp ++ = LSWAP(event_number); /*event number */
      if(ii==(block_level-1))
	  {
        *rol->dabufp ++ = LSWAP(time(0)); /*event unix time */
		*rol->dabufp ++ = LSWAP(EVTYPE);  /*event type */
        *rol->dabufp ++ = 0;              /*reserved for L3 info*/
	  }
      else
	  {
        *rol->dabufp ++ = 0;
        *rol->dabufp ++ = 0;
        *rol->dabufp ++ = 0;
	  }
      /* END OF DATA WORDS */
	}

    nwords = ((int)rol->dabufp-(int)dabufp1)/4 + 1;
    trailer = (0x11<<27)+nwords;
    /*printf("ROL1: nwords=%d, block trailer = %d (0x%08x)\n",nwords,trailer,trailer);*/
    *rol->dabufp ++ = LSWAP(trailer); /*block trailer*/

    BANKCLOSE;





#ifndef VXWORKS
TIMERL_STOP(100000/block_level,1000+rol->pid);
#endif




    /* read boards configurations */
    if(syncFlag==1 || EVENT_NUMBER==1)
    {
      printf("SYNC: read boards configurations\n");

      BANKOPEN(0xe10E,3,rol->pid);
      chptr = chptr0 =(char *)rol->dabufp;
      nbytes = 0;

      /* add one 'return' to make evio2xml output nicer */
      *chptr++ = '\n';
      nbytes ++;

vmeBusLock();
      len = tsUploadAll(chptr, 10000);
vmeBusUnlock();
      /*printf("\nTS len=%d\n",len);
      printf(">%s<\n",chptr);*/
      chptr += len;
      nbytes += len;




#if 0
	  /* temporary for crates with GTP */
      if(rol->pid==37||rol->pid==39)
	  {
#define TEXT_STR  1000
        char *roc;
        int  ii, kk, stt = 0;
        char result[TEXT_STR];      /* string for messages from tcpClientCmd */
        char exename[200];          /* command to be executed by tcpServer */

        if(rol->pid==37) roc = "hps1gtp";
        else             roc = "hps2gtp";

        sprintf(exename,"gtpUploadAllPrint()");

        /*printf("gtptest1: roc >%s< exename >%s<\n",roc,exename);*/

        memset(result,0,TEXT_STR);
        tcpClientSetMysqlHost(mysql_host);
        tcpClientCmd(roc, exename, result);

        len = strlen(result) - 2; /* 'result' has 2 extra chars in the end we do not want ????? */
        /*printf("gtptest1: len=%d, >%s<",len,result);*/

        strncpy(chptr,result,len);
        chptr += len;
        nbytes += len;
      }
#endif






      /* 'nbytes' does not includes end_of_string ! */
      chptr[0] = '\n';
      chptr[1] = '\n';
      chptr[2] = '\n';
      chptr[3] = '\n';
      nbytes = (((nbytes+1)+3)/4)*4;
      chptr0[nbytes-1] = '\0';

      nwords = nbytes/4;
      rol->dabufp += nwords;

      BANKCLOSE;

      printf("SYNC: read boards configurations - done\n");
    }












	


    /* read scaler(s) */
    if(syncFlag==1 || EVENT_NUMBER==1)
    {
      printf("SYNC: read scalers\n");

#ifdef USE_DSC2
	  /*printf("ndsc2_daq=%d\n",ndsc2_daq);*/
	  if(ndsc2_daq>0)
	  {
        BANKOPEN(0xe115,1,rol->pid);
        for(jj=0; jj<ndsc2_daq; jj++)
        {
          slot = dsc2Slot_daq(jj);
vmeBusLock();
          /* in following argument 4 set to 0xFF means latch and read everything, 0x3F - do not latch and read everything */
          nwords = dsc2ReadScalers(slot, tdcbuf, 0x10000, 0xFF, 1);
          /*printf("nwords=%d, nwords = 0x%08x 0x%08x 0x%08x 0x%08x\n",nwords,tdcbuf[0],tdcbuf[1],tdcbuf[2],tdcbuf[3]);*/
vmeBusUnlock();

#ifdef SSIPC
/*
	      {
            int status, mm;
            unsigned int dd[72];
            for(mm=0; mm<72; mm++) dd[mm] = tdcbuf[mm];
            status = epics_msg_send("hallb_dsc2_hps2_slot2","uint",72,dd);
	      }
*/
#endif
          /* unlike other boards, dcs2 scaler readout already swapped in 'dsc2ReadScalers', so swap it back, because
          rol2.c expects big-endian format*/
          for(ii=0; ii<nwords; ii++) *rol->dabufp ++ = LSWAP(tdcbuf[ii]);
        }
        BANKCLOSE;
	  }

#endif

      printf("SYNC: read scalers - done\n");
	}


    /* print and send livetime, event rate, event count 
    if(syncFlag==1)
	{
      printf("SYNC: livetime\n");

      int livetime, live_percent;
vmeBusLock();
      tsLatchTimers();
      livetime = tsLive(0);
vmeBusUnlock();
      live_percent = livetime/10;
	  printf("============= Livetime=%3d percent\n",live_percent);
#ifdef SSIPC
	  {
        int status;
        status = epics_msg_send("hallb_livetime","int",1,&live_percent);
	  }
#endif
      printf("SYNC: livetime - done\n");
	}
	*/


    /* for physics sync event, make sure all board buffers are empty */
    if(syncFlag==1)
    {
      printf("SYNC: make sure all board buffers are empty\n");

      int nblocks;
      nblocks = 0;/*tsGetNumberOfBlocksInBuffer();TS*/
      /*printf(" Blocks ready for readout: %d\n\n",nblocks);*/

      if(nblocks)
	  {
        printf("SYNC ERROR: TS nblocks = %d\n",nblocks);fflush(stdout);
        sleep(10);
	  }
      printf("SYNC: make sure all board buffers are empty - done\n");
	}




  }

  /* close event */
  CECLOSE;

  /*
  nusertrig ++;
  printf("usrtrig called %d times\n",nusertrig);fflush(stdout);
  */
  return;
}
Пример #2
0
void
usrtrig(unsigned int EVTYPE, unsigned int EVSOURCE)
{
  int *jw, ind, ind2, i, ii, jj, jjj, blen, len, rlen, itdcbuf, nbytes;
  unsigned int *tdcbuf_save, *tdc;
  unsigned int *dabufp1, *dabufp2;
  int njjloops, slot;
  int nwords;
#ifndef VXWORKS
  TIMERL_VAR;
#endif

#ifdef USE_PRAD
  int islot;
  int stat, dCnt, idata;
  unsigned int sync_or_unbuff;
  unsigned int *dma_dabufp;
#endif

  char *chptr, *chptr0;

  /*printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);*/


  if(syncFlag) printf("EVTYPE=%d syncFlag=%d\n",EVTYPE,syncFlag);

  rol->dabufp = (int *) 0;

  /*
usleep(100);
  */
  /*
  sleep(1);
  */

  CEOPEN(EVTYPE, BT_BANKS); /* reformatted on CODA_format.c !!! */

  if((syncFlag<0)||(syncFlag>1))         /* illegal */
  {
    printf("Illegal1: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE);
  }
  else if((syncFlag==0)&&(EVTYPE==0))    /* illegal */
  {
    printf("Illegal2: syncFlag=%d EVTYPE=%d\n",syncFlag,EVTYPE);
  }
  else if((syncFlag==1)&&(EVTYPE==0))    /* force_sync (scaler) events */
  {
    ;
/*
!!! we are geting here on End transition: syncFlag=1 EVTYPE=0 !!!
*/
  }
  else if((syncFlag==0)&&(EVTYPE==15)) /* helicity strob events */
  {
    ;
  }
  else           /* physics and physics_sync events */
  {

    /* for EVIO format, will dump raw data */
    tdcbuf_save = tdcbuf;

    /*************/
	/* TI stuff */

    /* Set high, the first output port 
    tiSetOutputPort(1,0,0,0);
    */

    /* Grab the data from the TI */
vmeBusLock();
    len = tiReadBlock(tdcbuf,900>>2,1);
vmeBusUnlock();
    BANKOPEN(0xe10A,1,rol->pid);
    if(len<=0)
    {
      printf("ERROR in tiReadBlock : No data or error, len = %d\n",len);
      sleep(1);
    }
    else
    {
	  ;
	  /*
      printf("ti: len=%d\n",len);
      for(jj=0; jj<len; jj++) printf("ti[%2d] 0x%08x\n",jj,LSWAP(tdcbuf[jj]));
	  */

	  
      for(jj=0; jj<len; jj++) *rol->dabufp++ = tdcbuf[jj];
	  
    }
    *rol->dabufp++ = LSWAP((lms_phase<<16) | trigger_type);
/*
    *rol->dabufp++ = LSWAP(tiGetScalar(1,0));
    *rol->dabufp++ = LSWAP(tiGetScalar(2,0));
    *rol->dabufp++ = LSWAP(tiGetScalar(3,0));
    *rol->dabufp++ = LSWAP(tiGetScalar(4,0));
    *rol->dabufp++ = LSWAP(tiGetScalar(5,0));
    *rol->dabufp++ = LSWAP(tiGetScalar(6,0));
*/
    BANKCLOSE;

    /* Turn off all output ports 
    tiSetOutputPort(0,0,0,0);
    */
	/* TI stuff */
    /*************/


#ifdef DEBUG
    printf("fadc1: start fadc processing\n");fflush(stdout);
#endif



#ifndef VXWORKS
TIMERL_START;
#endif







#ifdef USE_PRAD

#ifdef USE_V767

    BANKOPEN(0xe121,1,rol->pid);
    dma_dabufp = rol->dabufp;


vmeBusLock();
    stat = v767Dready(0);
vmeBusUnlock();

    jj = 0;
    while( (jj<100) && (stat==0) )
    {
vmeBusLock();
      stat = v767Dready(0);
vmeBusUnlock();
      jj++;
    }

    if(stat)
    {
vmeBusLock();
      dCnt = v767ReadEvent(0, dma_dabufp, 256);
vmeBusUnlock();
      if(dCnt <= 0) /*Error*/
	  {
        *dma_dabufp++ = LSWAP(0xed767bad);
        printf("v767(%d): No data or error.  dCnt = %d\n", ii, dCnt);
      }
      else
      {
        dma_dabufp += dCnt;
        /*printf("Read: %d\n", dCnt);*/
      }
    }
    else
    {
      printf("v767(%d): Timeout. Data not ready.\n", ii);
    }


    rol->dabufp = dma_dabufp;
    BANKCLOSE;

#endif

#ifdef USE_V1190
    int icheck = 0, maxcheck = 200, nev = 0;

    for(icheck = 0; icheck < maxcheck; icheck++)
    {
      nev = tdc1190Dready(0);
      if(nev > 0) break;
    }

    if(nev > 0) 
    {
      
      vmeBusLock();
      rlen = tdc1190ReadBoard(0, tdcbuf);
      vmeBusUnlock();
      
      if(rlen > 0) 
	  {
	  BANKOPEN(0xe121,1,rol->pid);

	    for(jj=0; jj<rlen; jj++)
	    {
	      *rol->dabufp++ = LSWAP(tdcbuf[jj]);
#ifdef V1190_TEST
	      if(!((*rol->nevents)%1000)) 
		  {
		    printf("Read %d words. \n", rlen);
		    if((tdcbuf[jj]&0xf8000000) == 0)
		      printf("channel %d, value %d\n", (tdcbuf[jj] >> 18)&0x7f, (tdcbuf[jj]&0x3ffff));
		  }
#endif
	    }
	    BANKCLOSE;
	  }
Пример #3
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;
}