예제 #1
0
int
main(int argc, char *argv[])
{
  char *mod, *roc;
  int  ii, kk, stt = 0;
  char result[TEXT_STR];      /* string for messages from tcpClientCmd */
  char exename[200];          /* VME discr vxworks exec name */

  /* check input parameters */
  if(argc < 3 || argc > 4) PRINT_USAGE;

  roc = argv[1];
  mod = argv[2];

  if( strcmp(mod,"set") && strcmp(mod,"mon") ) PRINT_USAGE;

  printf("fadc250: mod >%s<, roc >%s<\n",mod,roc);

  if(!strcmp(mod,"mon")) /* mon */
  {
    if(argc==4) sprintf(exename,"fadc250Mon(%s)",argv[3]);
    else sprintf(exename,"fadc250Mon(0)");
  }
  else /* set */
  {
    if(argc==4) sprintf(exename, "fadc250Config(\"%s\")",argv[3]);
    else  sprintf(exename, "fadc250Config(\"\")");
 }

  printf("roc >%s< exename >%s<\n",roc,exename);

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

  printf("%s", result);

  exit(0);
}
예제 #2
0
int
main(int argc, char *argv[])
{
  char *roc;
  int  ii, kk, stt = 0;
  char result[TEXT_STR];      /* string for messages from tcpClientCmd */
  char exename[200];          /* VME discr vxworks exec name */

  /* check input parameters */
  if(argc < 2 || argc > 2) PRINT_USAGE;

  roc = argv[1];

  sprintf(exename,"gtpUploadAllPrint()");

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

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

  printf("%s", result);

  exit(0);
}
예제 #3
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;
}
예제 #4
0
int
main(int argc, char *argv[])
{
  char fma[F_NAME] = { "" };  /* config file name */
  /* char *det = "pretrig3";  */
  char *mod, *roc;
  char *ident; 
  int  i, j, ii, kk, stt = 0;
  char result[TEXT_STR];      /* string for messages from tcpClientCmd */
  char exename[200];          /* VME discr vxworks exec name */
  bool isHod = false;
  int processAll = 0;
  int threshVal = 0;
  char *str = "SetThreshold";


/* get the environment variables */
  clonparms = getenv("CLON_PARMS");

  // setup variables
  roc = "pretrig3";
  mod = "mon";

  // initialize variables
  int IC_disc[23][23];
  int IC_chan[23][23];
  int IC_HOD_quad[10][8];
  int IC_HOD_index[10][8];
  int IC_HOD_disc[10][8];   // 4 and 18 orig
  int IC_HOD_chan[10][8];

  for (i = 0; i < 23; i++) {
    for (j = 0; j < 23; j++) {
      IC_disc[i][j] = 0;
      IC_chan[i][j] = 0;
      if (i < 4 && j < 18) {
	IC_HOD_disc[i][j] = 0;
	IC_HOD_chan[i][j] = 0;
      }
      if (i < 10 && j < 8) {
	IC_HOD_quad[i][j] = -1;
	IC_HOD_index[i][j] = -1;
      }
    }
  }

  // read the input files
  char *filename1 = "/usr/local/clas/parms/ic/IC_out.txt";
  FILE *file1 = fopen(filename1, "r");
  if (file1 == NULL) {
    printf("\nCan't open \n%s\n\n", filename1);
    return 0;
  }
  
  int x = 0;
  int y = 0;
  int quad = 0;
  int index = 0;
  int disc = 0;
  int chan = 0;

  while (fscanf(file1, "%d %d %d %d", &x, &y, &disc, &chan) != EOF) {
    x--; y--;
    IC_disc[x][y] = disc;
    IC_chan[x][y] = chan;
  }

  fclose(file1);

  // read the IC hodoscope file
  char *filename2 = "/usr/local/clas/parms/ic/hod_xyqi.txt";
  FILE *file2 = fopen(filename2, "r");
  if (file2 == NULL) {
    printf("\nCan't open \n%s\n\n", filename2);
    return 0;
  }

  while (fscanf(file2, "%d %d %d %d %d %d", &x, &y, &quad, &index, &disc, &chan) != EOF) {
    quad--;index--;
    IC_HOD_quad[x][y] = quad;
    IC_HOD_index[x][y] = index;
    IC_HOD_disc[x][y] = disc;
    IC_HOD_chan[x][y] = chan;
  }

  fclose(file2);

  // check input parameters
  if (argc < 5) {
    stt = 1;
  } else {
    // check first string for ic or hod
    ident = argv[1];
    if ((strcmp(ident, "ic") != 0) && (strcmp(ident, "hod") != 0)) {
      stt = 2;
    } else if (strcmp(ident, "hod") == 0) {
      isHod = true;
    } 
    // check x and y
    x = atoi(argv[2]);
    y = atoi(argv[3]);
    // check if both x and y are 0
    if (stt == 0 && x == 0 && y == 0) {
      processAll = 1;
    } else {
      if (stt == 0 && isHod == 1) {
	// check if x and y coordinates are within range
	if ((x < 0 || x > 9 || y < 1 || y > 8) || (IC_HOD_quad[x][y] == -1)) {
  	  printf("Error: incorrect x y coordinates specified\n");
	  stt = 3;
	} else {
	  quad = IC_HOD_quad[x][y];
	  index = IC_HOD_index[x][y];
	  disc = IC_HOD_disc[x][y];
	  chan = IC_HOD_chan[x][y];
	}
      } else if (stt == 0) {
        x--;
        y--;
	if ((IC_disc[x][y] == 0) || (x < 0 || x > 22 || y < 0 || y > 22)) {
	  printf("Error: incorrect x y coordinates specified\n");
	  stt = 3;
	}
      }
    }

    // check if last argument is 0 or 1
    threshVal = atoi(argv[4]);
    if (stt == 0 && (threshVal < 1  || threshVal > 255)) {
      printf("Error: incorrect threshold for channel\n");
      stt = 4;
    } 
  }

  if (stt != 0) {
    printf("  usage: setdvcsthresh [ic | hod] x y [ thresh ]\n");
    printf("    ic|hod : specify whether want ic or hodoscope \n");
    printf("    x: x position (1-23) in IC or (0-9) in hodoscope\n");
    printf("    y: y position (1-23) in IC or (1-8) in hodoscope\n");
    printf("    thresh: threshold for the channel (1-255 mV)\n");
    printf("  NOTE: the x axis coordinates 0 and 9 are reserved for \n");
    printf("    channels connected to those between 1 and 8.\n");
    printf("  To set all discriminator channels to same threshold for IC or hodoscope, use:\n");
    printf("    setdvcsthresh [ic | hod] 0 0 [ thresh ]\n");
    exit(stt);
  }


  // if input is correct then enable or disable channel as requested
  unsigned int discAdd = GetDiscAddress(1);  
  int channel = 0;

  // if want to process all discriminators, then run a for loop
  if (processAll == 1) {
    char *detstr = (isHod == 1) ? "hodoscope" : "IC";
    int startDisc = (isHod == 1) ? 29 : 1;
    int endDisc = (isHod == 1) ? 33: 28;
    printf("Setting all discriminators and channels for %s to: %d\n", detstr, 
	   threshVal);
    for (i = startDisc; i <= endDisc; i++) {
      discAdd = GetDiscAddress(i);
      printf(" Setting for discriminator: %d\n", i);
      for (j = 0; j <= 15; j++) {
        sprintf(exename, "v895SetThreshold(%u, %d, %d)", discAdd, j,threshVal);
        memset(result,0,TEXT_STR);
        tcpClientCmd(roc, exename, result);
      }
    }
  } else {  // process a single channel in a discriminator
    if (isHod == 1) {
      discAdd = GetDiscAddress(IC_HOD_disc[x][y]);
      channel = IC_HOD_chan[x][y];
      printf("Setting discriminator %d channel %d threshold: %d\n", 
	     IC_HOD_disc[x][y], IC_HOD_chan[x][y], threshVal);
    } else {
      discAdd = GetDiscAddress(IC_disc[x][y]);
      channel = IC_chan[x][y];
      printf("Setting discriminator %d channel %d threshold: %d\n", 
	     IC_disc[x][y], IC_chan[x][y], threshVal);
    }

    sprintf(exename, "v895SetThreshold(%u, %d, %d)",discAdd,channel,threshVal);
    memset(result,0,TEXT_STR);
    tcpClientCmd(roc, exename, result);
  }

  exit(stt);   /* end of main() */
}