Beispiel #1
0
INT cd_fgd_read(char *pevent, int offset)
{
   float *pdata;
   FGD_INFO *fgd_info;
   EQUIPMENT *pequipment;

   pequipment = *((EQUIPMENT **) pevent);
   fgd_info = (FGD_INFO *) pequipment->cd_info;

   if (fgd_info->format == FORMAT_FIXED) {
      memcpy(pevent, fgd_info->demand, sizeof(float) * fgd_info->num_channels);
      pevent += sizeof(float) * fgd_info->num_channels;

      memcpy(pevent, fgd_info->measured, sizeof(float) * fgd_info->num_channels);
      pevent += sizeof(float) * fgd_info->num_channels;

      return 2 * sizeof(float) * fgd_info->num_channels;
   } else if (fgd_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create VDMD bank */
      bk_create(pevent, "VDMD", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->demand, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create IMES bank */
      bk_create(pevent, "IMES", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->measured, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP1 bank */
      bk_create(pevent, "TEM1", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp1, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP2 bank */
      bk_create(pevent, "TEM2", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp2, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP1 bank */
      bk_create(pevent, "TEM3", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp3, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      return bk_size(pevent);
   } else if (fgd_info->format == FORMAT_YBOS) {
     printf("Not implemented\n");
     return 0;
   } else
     return 0;
}
Beispiel #2
0
INT adc_summing(EVENT_HEADER * pheader, void *pevent)
{
   INT i, j, n_adc;
   float *cadc;
   ASUM_BANK *asum;

   /* look for CADC bank, return if not present */
   n_adc = bk_locate(pevent, "CADC", &cadc);
   if (n_adc == 0)
      return 1;

   /* create ADC sum bank */
   bk_create(pevent, "ASUM", TID_STRUCT, &asum);

   /* sum all channels above threashold */
   asum->sum = 0.f;
   for (i = j = 0; i < n_adc; i++)
      if (cadc[i] > adc_summing_param.adc_threshold) {
         asum->sum += cadc[i];
         j++;
      }

   /* calculate ADC average */
   asum->average = j > 0 ? asum->sum / j : 0;

   /* fill sum histo */
   HF1(ADCSUM_ID_BASE, asum->sum, 1.f);

   /* close calculated bank */
   bk_close(pevent, asum + 1);

   return SUCCESS;
}
Beispiel #3
0
//fill mbank from /equip/environ/variables
INT read_periodic_event(char *pevent, INT off){
  printf("Reading Periodic Event\n");
  HNDLE hDB;
  cm_get_experiment_database(&hDB, NULL);

  HNDLE hkey;
  float temp1[3];
  INT size;
  // get key handle for temp
  db_find_key(hDB, 0, "/Equipment/Temperature/Variables/Input", &hkey);
  // return temp
  size = sizeof(temp1);
  db_get_data(hDB, hkey, &temp1, &size, TID_FLOAT);

  //char *pevent;
  bk_init(pevent);
  float *pdata;
  //  *pdata = temp1[0];
   // create SCLR bank
     bk_create(pevent, "NEW1", TID_FLOAT, &pdata);


// *pdata = 29.3;
printf("%f\n",temp1[0]);

   // close SCLR bank
bk_close(pevent, pdata);
printf("eo fB\n");
   return bk_size(pevent);


}
Beispiel #4
0
INT temp_copy(EVENT_HEADER * pheader, void *pevent)
{
   INT end, start, n;
   float *pin;
   float *pout;

   /* look for temp bank */
   n = bk_locate(pevent, "INPT", &pin);
   if (n == 0)
      return 1;

   /* create  bank */
   bk_create(pevent, "TEMP", TID_FLOAT, &pout);

   //set copy bounds indicies
   start =0; end =4; 

   /* copy partial bank*/
   for (INT i = start; i < end; i++) {
	if ( i >= n ) continue;
     	pout[i] = (float) pin[i] ;
	//printf("%d %f\n",i,pout[i]);
   }
	probe1->Fill(pheader->time_stamp,pout[0]);
	probe2->Fill(pheader->time_stamp,pout[1]);
        probe3->Fill(pheader->time_stamp,pout[2]);

   /* close bank */
   bk_close(pevent, pout + (end-start));

   return SUCCESS;
}
Beispiel #5
0
INT adc_summing(EVENT_HEADER *pheader, void *pevent)
{
  INT          i, n_adc;
  float        *cadc;
  ASUM_BANK    *asum;

  /* look for CADC bank, return if not present */
  n_adc = bk_locate(pevent, "CADC", &cadc);
  if (n_adc == 0)
    return 1;

  /* create ADC sum bank */
  bk_create(pevent, "ASUM", TID_STRUCT, &asum);

  /* sum all channels above threshold */
  asum->sum = 0.f;
  for (i=0 ; i<n_adc ; i++)
    asum->sum += cadc[i];

#ifdef MANA_LITE
 printf("manalite: adc_summing: HBOOK disable\n");
#else
  /* fill sum histo */
  HF1(ADCSUM_ID_BASE, asum->sum, 1.f);
#endif

  /* close calculated bank */
  bk_close(pevent, asum+1);
  
  return SUCCESS;
}
Beispiel #6
0
INT read_tiny_event(char *pevent, INT offset)
{
   static WORD *pdata = NULL;
   static WORD sub_counter = 0;
   // Super event structure 
   if (offset == 0) {           // FIRST event of the Super event 
      bk_init(pevent);
      bk_create(pevent, "SUPR", TID_WORD, &pdata);
      sub_counter = 1;
   } else if (offset == -1) {   // CLOSE Super event
      bk_close(pevent, pdata);
      return bk_size(pevent);
   }
   // READ event
   *pdata++ = 0xB0E;
   *pdata++ = sub_counter++;
   *pdata++ = 0xE0E;

   if (offset == 0) {
      // Compute the proper event length on the FIRST event in the Super Event
      // NWORDS correspond to the !! NWORDS WORD above !!
      // sizeof(BANK_HEADER) + sizeof(BANK) will make the 16 bytes header
      // sizeof(WORD) is defined by the TID_WORD in bk_create()
      return NWORDS * sizeof(WORD) + sizeof(BANK_HEADER) + sizeof(BANK);
   } else {
      // Return the data section size only
      // sizeof(WORD) is defined by the TID_WORD in bk_create()
      return NWORDS * sizeof(WORD);
   }
}
Beispiel #7
0
INT read_scaler_event(char *pevent, INT off)
{
   DWORD *pdata, a;

   /* init bank structure */
   bk_init(pevent);

   /* create SCLR bank */
   bk_create(pevent, "SCLR", TID_DWORD, &pdata);

   /* read scaler bank */
   for (a = 0; a < N_SCLR; a++)
      cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);

   bk_close(pevent, pdata);

   return bk_size(pevent);
}
Beispiel #8
0
INT readout(char* pevent, INT off)
{

DWORD *pdata;

bk_init32(pevent);

bk_create(pevent,"INPT",TID_DWORD,&pdata);

int val = 98;

HNDLE hDB;
HNDLE hKey;

INT size;

cm_get_experiment_database(&hDB,NULL);

db_find_key(hDB,0,"/Equipment/Environment 2/Variables/Secret",&hKey);

size = sizeof(val);

db_get_data(hDB,hKey,&val,&size,TID_INT);

*pdata++ = val;

struct timeval t;
int status;
status = gettimeofday(&t,NULL);

printf(" t_tv.sec: %d",t.tv_sec);

printf(" ro: val is %d",val);

val++;

db_set_value(hDB,0,"/Equipment/Environment 2/Variables/Secret",&val,sizeof(val),1,TID_INT);

bk_close(pevent,pdata);

return bk_size(pevent);

}
Beispiel #9
0
INT adc_summing(EVENT_HEADER * pheader, void *pevent)
{
   INT i, j, n_adc;
   float *cadc;
   ASUM_BANK *asum;

   /* look for CADC bank, return if not present */
   n_adc = bk_locate(pevent, "CADC", &cadc);
   if (n_adc == 0)
      return 1;

   /* create ADC sum bank */
   bk_create(pevent, "ASUM", TID_STRUCT, &asum);

   /* sum all channels above threashold */
   asum->sum = 0.f;
   for (i = j = 0; i < n_adc; i++)
      if (cadc[i] > adc_summing_param.adc_threshold) {
         asum->sum += cadc[i];
         j++;
      }

   /* calculate ADC average */
   asum->average = j > 0 ? asum->sum / j : 0;

   /* evaluate tests */
   SET_TEST(low_sum, asum->sum < 1000);
   SET_TEST(high_sum, asum->sum > 1000);

   /* fill sum histo */
   hAdcSum->Fill(asum->sum, 1);

   /* fill average histo */
   hAdcAvg->Fill(asum->average);

   /* close calculated bank */
   bk_close(pevent, asum + 1);

   return SUCCESS;
}
Beispiel #10
0
INT cd_gen_read(char *pevent, int offset)
{
   float *pdata;
   GEN_INFO *gen_info;
   EQUIPMENT *pequipment;
#ifdef HAVE_YBOS
   DWORD *pdw;
#endif

   pequipment = *((EQUIPMENT **) pevent);
   gen_info = (GEN_INFO *) pequipment->cd_info;

   if (gen_info->format == FORMAT_FIXED) {
      memcpy(pevent, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pevent += sizeof(float) * gen_info->num_channels;

      memcpy(pevent, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pevent += sizeof(float) * gen_info->num_channels;

      return 2 * sizeof(float) * gen_info->num_channels;
   } else if (gen_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create DMND bank */
      bk_create(pevent, "DMND", TID_FLOAT, (void **)&pdata);
      memcpy(pdata, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      bk_close(pevent, pdata);

      /* create MSRD bank */
      bk_create(pevent, "MSRD", TID_FLOAT, (void **)&pdata);
      memcpy(pdata, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      bk_close(pevent, pdata);

      return bk_size(pevent);
   } else if (gen_info->format == FORMAT_YBOS) {
#ifdef HAVE_YBOS
      ybk_init((DWORD *) pevent);

      /* create EVID bank */
      ybk_create((DWORD *) pevent, "EVID", I4_BKTYPE, (DWORD *) (&pdw));
      *(pdw)++ = EVENT_ID(pevent);      /* Event_ID + Mask */
      *(pdw)++ = SERIAL_NUMBER(pevent); /* Serial number */
      *(pdw)++ = TIME_STAMP(pevent);    /* Time Stamp */
      ybk_close((DWORD *) pevent, pdw);

      /* create DMND bank */
      ybk_create((DWORD *) pevent, "DMND", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      ybk_close((DWORD *) pevent, pdata);

      /* create MSRD bank */
      ybk_create((DWORD *) pevent, "MSRD", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      ybk_close((DWORD *) pevent, pdata);

      return ybk_size((DWORD *) pevent);
#else
      assert(!"YBOS support not compiled in");
#endif
   }

   return 0;
}
Beispiel #11
0
/** 
 * Event readout routine.
 * 
 * @param pevent 
 * @param off offset (for subevents)
 * 
 * @return 
 */
INT read_trigger_event(char *pevent, INT off)
{

  // DWORD *pdata;
  char bk_name[8];
  int status;

  data_avail = FALSE;

  /* init bank structure */
  bk_init32(pevent);
  
  /* create structured bank */
  // 
  //sprintf(bk_name,"SI%02i",frontend_index);
  // Just one VME crate, we don't use frontend_index

#if 0  
  sprintf(bk_name,"FD%02i",frontend_index); 
  bk_create(pevent, bk_name, TID_DWORD, &pdata);


  // all udp data received. copy data to midas bank
  /** \todo check data size */
  //pthread_mutex_lock( &buf_packet_gl_mutex );
  /*TG
  memcpy(pdata,gpu_data,gpu_data_size);
  pdata += gpu_data_size/sizeof(pdata[0]);
  */

  int fake_data_size = 12*10*1000; //originally 10*1000 
  *pdata++ = (DWORD) 0x1CEB00DA;
  pdata += fake_data_size/sizeof(pdata[0]);
  bk_close(pevent, pdata);
#endif 

#if 0  
  // unlock udp threads
  for (int i=0; i<udp_thread_num; i++)
    {
      pthread_mutex_unlock( &udp_thread_info[i].mutex  );
    }
#endif 

#if 0
  // read out tempratures sensord of SIS3350 boards
  sprintf(bk_name,"ST%02i",frontend_index);
  WORD *tdata;
  bk_create(pevent, bk_name, TID_WORD, &tdata);

  for (int i=0; i<SIS3350_NUM; i++) 
    {
      if ( ! sis3350_info[i].board.enabled ) continue; 
      unsigned int t;
      sis3350_ReadTemperature(i, &t);
      *tdata++ = (WORD)sis3350_info[i].SN;
      *tdata++ = (WORD)t;
      short int *ts = (short int*)&t;
      float tf = *ts;
      tf /= 4;
      printf("Board %i temperature: %f\n",sis3350_info[i].SN,tf);
    }
  bk_close(pevent, tdata);
#endif

  
#if 0
  // timing
  struct timeval t;
  DWORD *tr_data;
  sprintf(bk_name,"CS%02i",frontend_index);
  bk_create(pevent, bk_name, TID_DWORD, &tr_data);


  status = gettimeofday( &t, NULL);
  if ( status != 0)
    {
      printf("ERROR! gettimeofday() failed\n");
      t.tv_sec = 0;
      t.tv_usec = 0;
    }
 
  trigger_info.time_slave_got_data_s  = t.tv_sec;
  trigger_info.time_slave_got_data_us = t.tv_usec;
 
  *tr_data++ = trigger_info.trigger_nr;
  *tr_data++ = trigger_info.trigger_mask;
  *tr_data++ = trigger_info.time_master_got_eof_s;
  *tr_data++ = trigger_info.time_master_got_eof_us;
  *tr_data++ = trigger_info.time_slave_got_eof_s;
  *tr_data++ = trigger_info.time_slave_got_eof_us;
  *tr_data++ = trigger_info.time_tcp_finish_data_read_s;
  *tr_data++ = trigger_info.time_tcp_finish_data_read_us;

  bk_close(pevent, tr_data);

  long int dt_s = trigger_info.time_slave_got_data_s;
  dt_s -= trigger_info.time_slave_got_eof_s;
  long int dt_us =  trigger_info.time_slave_got_data_us;
  dt_us -= trigger_info.time_slave_got_eof_us;
  if ( dt_us < 0 )
    {
      dt_s -= 1;
      dt_us += 1000000;
    }
  
  printf("Readout: trigger dt = %li s %li us\n", dt_s, dt_us);
  
  printf("Bank size: %i\n", bk_size(pevent));
#endif

#if 1
 struct timeval start_READY_time, end_READY_time;                 
 
  gettimeofday(&start_READY_time, NULL);
  rpc_g2_ready( frontend_index + frontend_index_offset );
  gettimeofday(&end_READY_time, NULL);

  dt_READY = dt_READY 
    + toddiff(&end_READY_time, &start_READY_time);                            
  n_dt_READYs++;

  printf("n READYs, dt READY average, dt %d %f %f\n", n_dt_READYs, dt_READY/n_dt_READYs,  toddiff(&end_READY_time, &start_READY_time));
#endif

   
  return bk_size(pevent);
}
Beispiel #12
0
INT read_trigger_event(char *pevent, INT off)
{
   WORD *pdata, a;
   INT q, timeout;

   /* init bank structure */
   bk_init(pevent);

   /* create structured ADC0 bank */
   bk_create(pevent, "ADC0", TID_WORD, &pdata);

   /* wait for ADC conversion */
   for (timeout = 100; timeout > 0; timeout--) {
      camc_q(CRATE, SLOT_ADC, 0, 8, &q);
      if (q)
         break;
   }
   if (timeout == 0)
      ss_printf(0, 10, "No ADC gate!");

   /* use following code to read out real CAMAC ADC */
   /*
      for (a=0 ; a<N_ADC ; a++)
      cami(CRATE, SLOT_ADC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_ADC; a++)
      *pdata++ = rand() % 1024;

   /* clear ADC */
   camc(CRATE, SLOT_ADC, 0, 9);

   bk_close(pevent, pdata);

   /* create variable length TDC bank */
   bk_create(pevent, "TDC0", TID_WORD, &pdata);

   /* use following code to read out real CAMAC TDC */
   /*
      for (a=0 ; a<N_TDC ; a++)
      cami(CRATE, SLOT_TDC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_TDC; a++)
      *pdata++ = rand() % 1024;

   /* clear TDC */
   camc(CRATE, SLOT_TDC, 0, 9);

   bk_close(pevent, pdata);

   /* clear IO unit LAM */
   camc(CRATE, SLOT_IO, 0, 10);

   /* clear LAM in crate controller */
   cam_lam_clear(CRATE, SLOT_IO);

   /* reset external LAM Flip-Flop */
   camo(CRATE, SLOT_IO, 1, 16, 0xFF);
   camo(CRATE, SLOT_IO, 1, 16, 0);

   ss_sleep(10);

   return bk_size(pevent);
}
Beispiel #13
0
INT cd_multi_read(char *pevent, int offset)
{
   float *pdata;
   MULTI_INFO *m_info;
   EQUIPMENT *pequipment;
#ifdef HAVE_YBOS
   DWORD *pdw;
#endif

   pequipment = *((EQUIPMENT **) pevent);
   m_info = (MULTI_INFO *) pequipment->cd_info;

   if (m_info->format == FORMAT_FIXED) {
      memcpy(pevent, m_info->var_input, sizeof(float) * m_info->num_channels_input);
      pevent += sizeof(float) * m_info->num_channels_input;

      memcpy(pevent, m_info->var_output, sizeof(float) * m_info->num_channels_output);
      pevent += sizeof(float) * m_info->num_channels_output;

      return sizeof(float) * (m_info->num_channels_input + m_info->num_channels_output);
   } else if (m_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create INPT bank */
      if (m_info->num_channels_input) {
         bk_create(pevent, "INPT", TID_FLOAT, (void **)&pdata);
         memcpy(pdata, m_info->var_input, sizeof(float) * m_info->num_channels_input);
         pdata += m_info->num_channels_input;
         bk_close(pevent, pdata);
      }

      /* create OUTP bank */
      if (m_info->num_channels_output) {
         bk_create(pevent, "OUTP", TID_FLOAT, (void **)&pdata);
         memcpy(pdata, m_info->var_output, sizeof(float) * m_info->num_channels_output);
         pdata += m_info->num_channels_output;
         bk_close(pevent, pdata);
      }

      return bk_size(pevent);
   } else if (m_info->format == FORMAT_YBOS) {
#ifdef HAVE_YBOS
      ybk_init((DWORD *) pevent);

      /* create EVID bank */
      ybk_create((DWORD *) pevent, "EVID", I4_BKTYPE, (DWORD *) (&pdw));
      *(pdw)++ = EVENT_ID(pevent);      /* Event_ID + Mask */
      *(pdw)++ = SERIAL_NUMBER(pevent); /* Serial number */
      *(pdw)++ = TIME_STAMP(pevent);    /* Time Stamp */
      ybk_close((DWORD *) pevent, pdw);

      /* create INPT bank */
      ybk_create((DWORD *) pevent, "INPT", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, m_info->var_input, sizeof(float) * m_info->num_channels_input);
      pdata += m_info->num_channels_input;
      ybk_close((DWORD *) pevent, pdata);

      /* create OUTP bank */
      ybk_create((DWORD *) pevent, "OUTP", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, m_info->var_output, sizeof(float) * m_info->num_channels_output);
      pdata += m_info->num_channels_output;
      ybk_close((DWORD *) pevent, pdata);

      return ybk_size((DWORD *) pevent);
#lese
      assert(!"YBOS support not compiled in");
#endif
   }

   return 0;
}
Beispiel #14
0
/** 
 * Event readout routine.
 * 
 * @param pevent 
 * @param off offset (for subevents)
 * 
 * @return 
 */
INT read_trigger_event(char *pevent, INT off)
{

  int status;
  short *pdata;
  DWORD *hdata;
  char bk_name[8];

  dbprintf("Begin read_trigger_event!\n");

  // get data ready time
  struct timeval t_lock_data;
  status = gettimeofday( &t_lock_data, NULL);
  trigger_info.time_slave_lock_dataready_s  = t_lock_data.tv_sec;
  trigger_info.time_slave_lock_dataready_us = t_lock_data.tv_usec;

  // store timing information and current TCPfillnumber, GPUfillnumber in header databank
  gpu_data_header[13] = t_lock_data.tv_sec;
  gpu_data_header[14] = t_lock_data.tv_usec;

  //AMC13 fill number
  unsigned int AMC13fillcounter = ( be32toh ( gpu_data_header[0] ) & 0x00FFFFFF ); 

  /* init bank structure */
  bk_init32(pevent);
  dbprintf("event serial_number %d\n", SERIAL_NUMBER(pevent));

  // header bank wrote last in order to complete the timing data  

  // make trailer databank 
  sprintf(bk_name,"EC%02i",frontend_index);
  bk_create(pevent, bk_name, TID_DWORD, (void**)&hdata); // TID_DWORD unsigned int of four bytes                        
  memcpy( hdata, gpu_data_tail, gpu_data_tail_size); 
  hdata += gpu_data_tail_size / sizeof(hdata[0]); 
  bk_close(pevent, hdata);
  dbprintf("%s(%d): made trailer databank %s size 0x%08x, tail[0] 0x%08x, readout electronics fill number %d\n", 
	   __func__, __LINE__, bk_name, gpu_data_tail_size, *gpu_data_tail, gpu_data_header[1]);

  // make raw databank 
  if ( amc13_settings_odb.store_raw && !( ( AMC13fillcounter + amc13_settings_odb.prescale_offset_raw ) % amc13_settings_odb.prescale_raw ) ) {
    sprintf(bk_name,"RC%02i",frontend_index);
    bk_create(pevent, bk_name, TID_SHORT, (void**)&pdata); // TID_SHORT signed int of two bytes                         
    printf("created raw bank %s, now do memcpy\n",bk_name);
    memcpy( pdata, gpu_data_raw, gpu_data_raw_size); 
    printf("raw data memcpy complete\n");
    pdata += gpu_data_raw_size / sizeof(pdata[0]);
    bk_close(pevent, pdata);                                               
    dbprintf("%s(%d): made raw databank %s size 0x%08x, *data %p, data[0] 0x%04x, readout electronics fill number %d\n", 
	     __func__, __LINE__, bk_name, gpu_data_raw_size,  gpu_data_raw, *gpu_data_raw, gpu_data_header[1]);
  }
  
#ifdef USE_GPU
  // make processed databank 
  if ( amc13_settings_odb.TQ_on  ) {
    dbprintf("%s(%d): fill FC data bank\n",__func__, __LINE__);
   sprintf(bk_name,"FC%02i",frontend_index);
   bk_create(pevent, bk_name, TID_SHORT, (void**)&pdata);  
   dbprintf("%s(%d): gpu_data_proc: 0x%08x  gpu_data_proc_size: %d\n",__func__,__LINE__,*gpu_data_proc,gpu_data_proc_size);
   memcpy(pdata, gpu_data_proc, gpu_data_proc_size);   
   dbprintf("%s(%d): sizeof(pdata): %d\n",__func__,__LINE__,sizeof(pdata));
   if(sizeof(pdata) != 0)
      pdata += gpu_data_proc_size / sizeof(pdata[0]);
   bk_close(pevent, pdata);
   dbprintf("%s(%d): made processed databank %s size %d\n", 
	   __func__, __LINE__, bk_name, gpu_data_proc_size);

   // make histogram databank
   printf("gpu_data_his_size = %d\n",gpu_data_his_size);
   if ( amc13_settings_odb.store_hist && !( (AMC13fillcounter + amc13_settings_odb.flush_offset_hist) % amc13_settings_odb.flush_hist ) ) {
     dbprintf("%s(%d): fill HC data bank\n",__func__, __LINE__);
     sprintf(bk_name,"HC%02i",frontend_index);
     dbprintf("1\n");
     bk_create(pevent, bk_name, TID_DWORD, (void**)&hdata);
     dbprintf("2 gpu_data_hiz_size = %d\n",gpu_data_his_size);
     memcpy( hdata, gpu_data_his, gpu_data_his_size); 
     dbprintf("3\n");
     hdata += gpu_data_his_size / sizeof(hdata[0]);
     dbprintf("4\n");
     bk_close(pevent, hdata);                                               
     dbprintf("%s(%d): made histogram databank %s size 0x%08x, data[0] 0x%08x, readout electronics fill number %d\n", 
	      __func__, __LINE__, bk_name, gpu_data_his_size, *gpu_data_his, gpu_data_header[1]);
   }
  }
#endif // USE_GPU

  struct timeval t_got_data;
  status = gettimeofday( &t_got_data, NULL);
  trigger_info.time_slave_got_data_s  = t_got_data.tv_sec;
  trigger_info.time_slave_got_data_us = t_got_data.tv_usec;

  // make header databank
  gpu_data_header[15] = t_got_data.tv_sec;
  gpu_data_header[16] = t_got_data.tv_usec;
  gpu_data_header[17] = TCPfillnumber;
  gpu_data_header[18] = GPUfillnumber;

  sprintf(bk_name,"BC%02i",frontend_index);
  bk_create(pevent, bk_name, TID_DWORD, (void**)&hdata); // TID_DWORD unsigned int of FOUR bytes
  memcpy( hdata, gpu_data_header, gpu_data_header_size); 
  hdata += gpu_data_header_size / sizeof(hdata[0]);
  bk_close(pevent, hdata);
  dbprintf("%s(%d): made header databank %s size 0x%08x, header[0] 0x%08x, readout electronics fill number %d\n", 
	   __func__, __LINE__, bk_name, gpu_data_header_size, *gpu_data_header, gpu_data_header[1]);

                                         
  // unlocking gpu thread access to GPU output buffer
  pthread_mutex_unlock( &(gpu_thread_1_info.mutex)  );


  // fill timing info into SR databank
  DWORD *tr_data;
  sprintf(bk_name,"SR%02i",frontend_index);
  bk_create(pevent, bk_name, TID_DWORD, (void**)&tr_data);
  *tr_data++ = trigger_info.trigger_nr;    // trigger number (via RPC message from master)
  *tr_data++ = trigger_info.trigger_mask;  // trigger mask (via RPC message from master)

  *tr_data++ = trigger_info.time_master_got_eof_s;      // master EOF trigger time (via RPC message from master), secs
  *tr_data++ = trigger_info.time_master_got_eof_us;     // master EOF trigger time (via RPC message from master), usecs
  *tr_data++ = trigger_info.time_slave_got_eof_s;       // slave EOF trigger time called from master via RPC message, secs
  *tr_data++ = trigger_info.time_slave_got_eof_us;      // slave EOF trigger time called from master via RPC message, usecs

  // tcp_thread
  *tr_data++ = trigger_info.time_tcp_start_read_s;      // start time of tcp read in tcp_thread, secs
  *tr_data++ = trigger_info.time_tcp_start_read_us;     // start time of tcp read in tcp_thread, usecs
  *tr_data++ = trigger_info.time_tcp_finish_header_read_s;     // finish time of tcp read in tcp_thread, secss
  *tr_data++ = trigger_info.time_tcp_finish_header_read_us;    // finish time of tcp read in tcp_thread, usecs
  *tr_data++ = trigger_info.time_tcp_finish_data_read_s;     // finish time of tcp read in tcp_thread, secs
  *tr_data++ = trigger_info.time_tcp_finish_data_read_us;    // finish time of tcp read in tcp_thread, usecs

  // gpu_thread
  *tr_data++ = trigger_info.time_gputhread_started_s;  ///< woke-up gpu_thread for processing, secs
  *tr_data++ = trigger_info.time_gputhread_started_us;  ///< woke-up gpu_thread for processing, usecs
  *tr_data++ = trigger_info.time_gputhread_copytogpu_done_s;  ///<woke-up gpu_thread for processing, secs
  *tr_data++ = trigger_info.time_gputhread_copytogpu_done_us;  ///< woke-up gpu_thread for processing, usecs
  *tr_data++ = trigger_info.time_gputhread_finished_s; ///< gpu_thread finished processing, secs 
  *tr_data++ = trigger_info.time_gputhread_finished_us; ///< gpu_thread finished processing, usecs

  // MFE_thread
  *tr_data++ = trigger_info.time_slave_lock_dataready_s;  // slave locked waiting on data, secs
  *tr_data++ = trigger_info.time_slave_lock_dataready_us; // slave locked waiting on data, usecs
  *tr_data++ = trigger_info.time_slave_got_data_s;      // slave got data fron tcp_thread and unloacked tcp_thread, secs
  *tr_data++ = trigger_info.time_slave_got_data_us;     // slave got data fron tcp_thread and unloacked tcp_thread, usecs

  bk_close(pevent, tr_data);


  // dt1 time between start, finish of tcp_thread read() of data
  long int dt1_s = trigger_info.time_slave_got_data_s;
  dt1_s -= trigger_info.time_gputhread_finished_s;
  long int dt1_us =  trigger_info.time_slave_got_data_us;
  dt1_us -= trigger_info.time_gputhread_finished_us;
  if ( dt1_us < 0 )
    {
      dt1_s -= 1;
      dt1_us += 1000000;
    }
  
  // dt2 time between tcp_thread read completion and read_trigger_event unlocked
  long int dt2_s = trigger_info.time_slave_got_data_s;
  dt2_s -= trigger_info.time_tcp_finish_data_read_s;
  long int dt2_us =  trigger_info.time_slave_got_data_us;
  dt2_us -= trigger_info.time_tcp_finish_data_read_us;
  if ( dt2_us < 0 )
    {
      dt2_s -= 1;
      dt2_us += 1000000;
    }

  // dt3 total duration of readout through TCP, GPU, midas FE threads
  long int dt3_s = trigger_info.time_slave_got_data_s;
  dt3_s -= trigger_info.time_tcp_finish_header_read_s;
  long int dt3_us =  trigger_info.time_slave_got_data_us;
  dt3_us -= trigger_info.time_tcp_finish_header_read_us;
  if ( dt3_us < 0 )
    {
      dt3_s -= 1;
      dt3_us += 1000000;
    }
  
  //dbprintf("%s(%d): EOF master-slave propogation time: dt = %li s %li us\n", __func__, __LINE__, dt0_s, dt0_us);
  dbprintf("%s(%d): gpu done to MFE done  duration: dt = %li s %li us\n", __func__, __LINE__, dt1_s, dt1_us);
  dbprintf("%s(%d): tcp got data to MFE done duration: dt = %li s %li us\n", __func__, __LINE__, dt2_s, dt2_us);
  dbprintf("%s(%d): tcp got header to MFE done duration: dt = %li s %li us\n", __func__, __LINE__, dt3_s, dt3_us);
  dbprintf("%s(%d): midas bank size: %i\n", __func__, __LINE__, bk_size(pevent));

  // used for hardware debugging  
#ifdef USE_PARALLEL_PORT
  printf("read_trigger_event: write pulse to parallel port address 0x%08x\n", pp_addr);
  outb( 0xff, pp_addr);
  usleep(20);
  outb( 0x00, pp_addr);
#endif

  return bk_size(pevent);
}
Beispiel #15
0
INT envi_copy(EVENT_HEADER * pheader, void *pevent)
{

    INT end, start, n;
    float *pin;
    float *pout;

    /* look for envi bank */
    n = bk_locate(pevent, "INPT", &pin);
    if (n == 0)
        return 1;

    /* create  bank */
    bk_create(pevent, "TEMP", TID_FLOAT, &pout);

    //set copy bounds indicies
    start =0;
    end =11;

    /* copy partial bank*/
    for (INT i = start; i < end; i++) {
        if ( i >= n ) continue;
        pout[i] = (float) pin[i] ;
        //printf("%d %f\n",i,pout[i]);

    }

    probe1->Fill(pout[0]);
    probe2->Fill(pout[1]);
    probe3->Fill(pout[2]);
    probe4->Fill(pout[3]);
    probe5->Fill(pout[4]);
    probe6->Fill(pout[5]);
    probe7->Fill(pout[6]);
    probe8->Fill(pout[7]);

    capac1->Fill(pout[8]);
    capac2->Fill(pout[9]);
    capac3->Fill(pout[10]);
    capac4->Fill(pout[11]);

    /* close bank */
    bk_close(pevent, pout + (end-start));

    gData->tStamp = pheader->time_stamp;
    gData->p1val = pout[0];
    gData->p2val = pout[1];
    gData->p3val = pout[2];
    gData->p4val = pout[3];
    gData->p5val = pout[4];
    gData->p6val = pout[5];
    gData->p7val = pout[6];
    gData->p8val = pout[7];
    gData->c1val = pout[8];
    gData->c2val = pout[9];
    gData->c3val = pout[10];
    gData->c4val = pout[11];

    fEventTree->Fill();

    return SUCCESS;
}
Beispiel #16
0
INT ge_ln2_read(char *pevent, INT off) {

  static INT    status, size;
  static DWORD  lastfilled, now, timelimit;
  static BOOL   justfilled;
  static DWORD  *timesincefill;

  bk_init(pevent);
  timesincefill = NULL;

  // Get recent values
  size = sizeof(lastfilled);
  status = db_get_value(hDB, 0, sLastFilled, &lastfilled, &size, TID_DWORD, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting last filled time");
    return 0;
  }

  size = sizeof(justfilled);
  status = db_get_value(hDB, 0, sJustFilled, &justfilled, &size, TID_BOOL, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting just filled status");
    return 0;
  }

  size = sizeof(timelimit);
  status = db_get_value(hDB, 0, sTimeLimit, &timelimit, &size, TID_DWORD, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting time limit between fills");
    return 0;
  }

  // If just filled, write time to ODB
  if (justfilled == TRUE) {
    lastfilled = (DWORD)time(NULL);
    status = db_set_value(hDB, 0, sLastFilled, &lastfilled, sizeof(lastfilled), 1, TID_DWORD);
    if (status != DB_SUCCESS) {
      cm_msg(MERROR, "gn_ln2_read", "Error setting last filled time");
      return 0;
    }
    justfilled = FALSE;
    status = db_set_value(hDB, 0, sJustFilled, &justfilled, sizeof(justfilled), 1, TID_BOOL);
    if (status != DB_SUCCESS) {
      cm_msg(MERROR, "gn_ln2_read", "Error setting just filled status");
      return 0;
    }

    al_reset_alarm(sAlarmName);

    bk_create(pevent, "LN2F", TID_DWORD, &timesincefill);
    *timesincefill = 0;
    bk_close(pevent, ++timesincefill);

    return bk_size(pevent);
  }

  // Check the status
  bk_create(pevent, "LN2F", TID_DWORD, &timesincefill);
  now = (DWORD) time(NULL);
  *timesincefill = now - lastfilled;
  if (*timesincefill > timelimit) {
    al_trigger_alarm(sAlarmName, "Germanium must be filled!", "Alarm", "", AT_INTERNAL);
    printf("Alarm!\n");
  }
  bk_close(pevent, ++timesincefill);

  return bk_size(pevent);
}