Ejemplo n.º 1
0
int
codaInit(char *conf)
{
  if(codaUpdateStatus("configuring") != CODA_OK)
  {
    return(CODA_ERROR);
  }

  UDP_start();

  if(codaUpdateStatus("configured") != CODA_OK)
  {
    return(CODA_ERROR);
  }

  return(CODA_OK);
}
Ejemplo n.º 2
0
int
codaDownload(char *conf)
{
  objClass object = localobject;
  ET_priv *etp = (ET_priv *) object->privated;

  static char tmp[1000];
  static char tmp2[1000];
  int  ix, status, ntransferred;  
  char *ch;
  int  listArgc;
  char listArgv[LISTARGV1][LISTARGV2];

  MYSQL *dbsock;
  char tmpp[1000];

  int res;
  pthread_attr_t attr;

  
  etp->object = object;

  printf("111\n");fflush(stdout);

  /*****************************/
  /*****************************/
  /* FROM CLASS (former conf1) */

  strcpy(configname,conf); /* Sergey: save CODA configuration name */
  printf("coda_ett: configname = >%s<\n",configname);fflush(stdout);


  UDP_start();

  tcpState = DA_DOWNLOADING;
  if(codaUpdateStatus("downloading") != ET_OK) return(ET_ERROR);



  /*****************************/
  /*****************************/
  /*****************************/

  printf("INFO: Downloading configuration '%s'\n", configname);


  printf("etp->id = 0x%08x\n",etp->id);
  printf("etp->id = 0x%08x\n",etp->id);
  printf("etp->id = 0x%08x\n",etp->id);

  printf("etp->exit = %d\n",etp->exit);
  printf("etp->exit = %d\n",etp->exit);
  printf("etp->exit = %d\n",etp->exit);

  /* if not the first entry, exit ettStart thread 
  if(etp->id != 0)
  {
    etp->exit = 1;
    while(etp->exit == 1)
    {
      printf("Waiting for ettStart thread to exit ...\n");
      sleep(1);
    }
    printf("ettStart thread to exited !\n");
    sleep(10);
  }
  */

  /*
  if(etp->id != 0)
  {
    printf("Sending kill request to ettStart thread ...\n");
    pthread_kill(etp->id, 0);
  }
  sleep(10);
  */

  /* if the first entry, start ettStart thread */
  if(etp->id == 0)
  {
    pthread_attr_init(&attr); /* initialize attr with default attributes */
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    res = pthread_create(&etp->id, &attr, (void *(*)(void *)) ettStart, NULL);
    if(res!=0)
    {
      printf("ERROR: pthread_create(ettStart) returned %d - exit\n",res);
      exit(-1);
    }
    else
    {
      printf("ettStart thread started, etp->id = 0x%08x\n",etp->id);
    }
  }

  printf("coda_ett: downloaded !!!\n");

  tcpState = DA_DOWNLOADED;
  if(codaUpdateStatus("downloaded") != ET_OK) return(ET_ERROR);

  return(ET_OK);
}
Ejemplo n.º 3
0
int
codaDownload(char *conf)
{
  objClass object = localobject;

  MONp monp = (MONp) object->privated;
  int deflt = 0;
  static char tmp[1000];
  static char tmp2[1000];
  int  ix;  
  int  listArgc;
  char listArgv[LISTARGV1][LISTARGV2];

  MYSQL *dbsock;
  char tmpp[1000];

  
  monp->object = object;


  /***************************************************/
  /* extract all necessary information from database */


  /*****************************/
  /*****************************/
  /* FROM CLASS (former conf1) */

  strcpy(configname,conf); /* Sergey: save CODA configuration name */

  UDP_start();

  /* connect to database */
  dbsock = dbConnect(getenv("MYSQL_HOST"), expid);

  sprintf(tmp,"SELECT value FROM %s_option WHERE name='SPLITMB'",
    configname);
  if(dbGetInt(dbsock, tmp, &monp->split)==MON_ERROR)
  {
    monp->split = 2047 << 20;
    printf("cannot get SPLITMB, set monp->split=%d\n",monp->split);
  }
  else
  {
    printf("get monp->split = %d\n",monp->split);
    monp->split = monp->split<<20;
    printf("set monp->split = %d\n",monp->split);
  }

  sprintf(tmp,"SELECT value FROM %s_option WHERE name='RECL'",
    configname);
  if(dbGetInt(dbsock, tmp, &monp->record_length)==MON_ERROR)
  {
    monp->record_length = 32768;
    printf("cannot get RECL, set monp->record_length=%d\n",monp->record_length);
  }
  else
  {
    printf("get monp->record_length = %d\n",monp->record_length);
  }


  sprintf(tmp,"SELECT value FROM %s_option WHERE name='EvDumpLevel'",
    configname);
  if(dbGetInt(dbsock, tmp, &monp->log_EvDumpLevel)==MON_ERROR)
  {
    monp->log_EvDumpLevel = 0;
    printf("cannot get EvDumpLevel, set monp->log_EvDumpLevel=%d\n",monp->log_EvDumpLevel);
  }
  else
  {
    printf("get monp->log_EvDumpLevel = %d\n",monp->log_EvDumpLevel);
  }


  /* do not nned that !!!???
  sprintf(tmp,"SELECT inputs FROM %s WHERE name='%s'",configname,object->name);
  if(dbGetStr(dbsock, tmp, tmpp)==MON_ERROR)
  {
    printf("cannot get 'inputs' from table>%s< for the name>%s<\n",configname,object->name);
  }
  else
  {
    printf("inputs >%s<\n",tmpp);
  }
  */

  sprintf(tmp,"SELECT outputs FROM %s WHERE name='%s'",configname,object->name);
  if(dbGetStr(dbsock, tmp, tmpp)==MON_ERROR)
  {
    printf("cannot get 'outputs' from table>%s< for the name>%s<\n",configname,object->name);
    return(MON_ERROR);
  }
  else
  {
    strcpy(monp->output_type,tmpp);
    printf("get monp->output_type >%s<\n",monp->output_type);
  }

  /* default output to none */
  monp->output_switch = 3;

  if( !strncmp(monp->output_type,"file",4) ) /* output to binary file */
  {
    sprintf(tmp,"SELECT value FROM %s_option WHERE name='dataFile'",configname);
    if(dbGetStr(dbsock, tmp, tmpp)==MON_ERROR)
    {
      printf("cannot get 'dataFile' from table >%s_option<\n",configname);
      return(MON_ERROR);
    }
    else
    {
      monp->filename = strdup(tmpp); /* Sergey: change it to strcpy(monp->filename,tmpp);*/
      printf("get monp->filename >%s<\n",monp->filename);
    }
    monp->output_switch = 1;
  }
  else if( !strncmp(monp->output_type,"debug",5) ) /* debug dump */
  {
    monp->output_switch = 2;
  }
  else if( !strncmp(monp->output_type,"none",4) ) /* output to /dev/null */
  {
    monp->output_switch = 3;
  }
  else if( !strncmp(monp->output_type,"coda",4) ) /* output in CODA format */
  {
    sprintf(tmp,"SELECT value FROM %s_option WHERE name='dataFile'",configname);
    if(dbGetStr(dbsock, tmp, tmpp)==MON_ERROR)
    {
      printf("cannot get 'dataFile' from table >%s_option<\n",configname);
      return(MON_ERROR);
    }
    else
    {
      monp->filename = strdup(tmpp); /* Sergey: change it to strcpy(monp->filename,tmpp);*/
      printf("get monp->filename >%s<\n",monp->filename);
    }
  	printf("coda format will be used\n");
    monp->output_switch = 4;
  }
  else
  {
    printf("invalid monp->output_type >%s<\n",monp->output_type);
    return(MON_ERROR);
  }

  /*****************************/
  /*****************************/
  /*****************************/

  monp->fd = -1;

  if (monp->mod_id) {
    printf("INFO: Unloading module %x\n", monp->mod_id);

#if defined __sun||LINUX
    if (dlclose ((void *) monp->mod_id) != 0)
    {
      printf("ERROR: failed to unload module to decode >%s<\n",monp->mod_name);
      return MON_ERROR;
    }
#else
    printf("WARN: dynamic loading not yet supported on this platform\n");
#endif
  }
  
  printf("INFO: Downloading configuration '%s'\n", configname);

  strcpy(monp->mod_name,"CODA");


  /* Get the list of readout-lists from the database */
  sprintf(tmpp,"SELECT code FROM %s WHERE name='%s'",configname,object->name);
  if(dbGetStr(dbsock, tmpp, tmp)==MON_ERROR) return(MON_ERROR);
printf("++++++======>%s<\n",tmp);


  /* disconnect from database */
  dbDisconnect(dbsock);


  /* Decode configuration string */
  listArgc = 0;
  if(!((strcmp (tmp, "{}") == 0)||(strcmp (tmp, "") == 0)))
  {
    if(listSplit1(tmp, 1, &listArgc, listArgv)) return(MON_ERROR);
    for(ix=0; ix<listArgc; ix++) printf("nrols [%1d] >%s<\n",ix,listArgv[ix]);
  }
  else
  {
    printf("download: do not split list >%s<\n",tmp);
  }


  /* Get object filename in order to find the ROLs __init routine */
  if(listArgc)
  {
    strcpy(monp->mod_name,listArgv[0]);

    /* Load the decode module */
    sprintf(tmp,"%s/%s_file.so",getenv("CODA_LIB"),listArgv[0]);
#if defined __sun||LINUX
    if (monp->mod_id) dlclose(monp->mod_id);
    monp->mod_id = dlopen ((const char *) tmp, RTLD_NOW | RTLD_GLOBAL);
    if (monp->mod_id == 0) {
      printf("WARN: dlopen failed to open >%s<\n",tmp);
      printf("WARN: >%s<\n",dlerror());
      deflt = 1;
    }
#else
    printf("WARN: dynamic loading not supported\n");
    deflt = 1;
#endif
    
  }
  else
  {
    deflt = 1;
    printf("WARN: row %s table %s no code entry, use CODA file fmt.\n",
      object->name,configname);
  }


  /******************************************************************/
  /* Now look up the routines in the library and fill in the tables */
  if(deflt)
  {
    /* default to CODA format */
    printf("INFO: Using inbuilt (CODA) format\n");
	/*
    monp->open_proc = CODA_open_file;
    monp->close_proc = CODA_close_file;
    monp->write_proc = CODA_write_event;
    */
  }
  else
  {
    IFUNCPTR proc;
    /* find input formatting procs */
    sprintf(tmp,"%s_open_file",monp->mod_name);
    proc = (IFUNCPTR) dlsym (monp->mod_id, tmp);
    monp->open_proc = proc;
    sprintf(tmp,"%s_close_file",monp->mod_name);
    proc = (IFUNCPTR) dlsym (monp->mod_id, tmp);
    monp->close_proc = proc;
    sprintf(tmp,"%s_write_event",monp->mod_name);
    proc = (IFUNCPTR) dlsym (monp->mod_id, tmp);
    monp->write_proc = proc;

    printf("INFO: Loaded module for format %s\n",monp->mod_name);
  }

  /* If we need to initialize, reinitialize, or
   * if et_alive fails on Linux, then initialize.
   */
  if( (et_init == 0)   ||
      (et_reinit == 1) ||
      ((!et_alive(et_sys)) && (et_locality == ET_LOCAL_NOSHARE))
     )
  {
    if(mon_et_initialize() != MON_OK)
    {
      printf("ERROR: mon download: cannot initalize ET system\n");
      return(MON_ERROR);
    }
  }

  codaUpdateStatus("downloaded");

  return(MON_OK);
}