/* Get number of events made by attachment */ int et_attach_geteventsmake(et_sys_id id, et_att_id att_id, uint64_t *events) { et_id *etid = (et_id *) id; if (etid->locality == ET_REMOTE) { return etr_attach_geteventsmake(id, att_id, events); } if (!et_alive(id)) { return ET_ERROR_DEAD; } /* Protection from (local) et_close() unmapping shared memory */ et_memRead_lock(etid); /* Has caller already called et_close()? */ if (etid->closed) { et_mem_unlock(etid); if (etid->debug >= ET_DEBUG_ERROR) { et_logmsg("ERROR", "et_attach_geteventsmake, et id is closed\n"); } return ET_ERROR_CLOSED; } if ((att_id < 0) || (att_id >= etid->sys->config.nattachments)) { et_mem_unlock(etid); if (etid->debug >= ET_DEBUG_ERROR) { et_logmsg("ERROR", "et_attach_geteventsmake, bad attachment id\n"); } return ET_ERROR; } if (events != NULL) { *events = etid->sys->attach[att_id].events_make; } et_mem_unlock(etid); return ET_OK; }
main(int argc,char **argv) { int *ev, len, i, j, status, numread, totalread=0, nevents_max, event_size, chunk; int con[ET_STATION_SELECT_INTS]; et_event **pe; et_openconfig openconfig; et_statconfig sconfig; et_att_id attach; et_stat_id my_stat; et_sys_id id; sigset_t sigblock; struct timespec timeout; pthread_t tid; BOSIOptr BIOstream; char *ch; char *str1 = "OPEN UNIT=11 FILE='/scratch/boiarino/test.A00' WRITE RECL=32768 SPLITMB=2047 RAW SEQ NEW BINARY"; /*"OPEN UNIT=11 FILE='/work/clas/disk1/boiarino/test.A00' WRITE RECL=32768 SPLITMB=2047 RAW SEQ NEW BINARY";*/ if(argc != 3) { printf("Usage: et2bos_test <et_filename> <station_name>\n"); exit(1); } timeout.tv_sec = 0; timeout.tv_nsec = 1; /* setup signal handling */ sigfillset(&sigblock); /* block all signals */ status = pthread_sigmask(SIG_BLOCK, &sigblock, NULL); if (status != 0) { printf("et2bos: pthread_sigmask failure\n"); exit(1); } #ifdef sun thr_setconcurrency(thr_getconcurrency() + 1); #endif /* spawn signal handling thread */ pthread_create(&tid, NULL, signal_thread, (void *)NULL); restartLinux: /* open ET system */ et_open_config_init(&openconfig); et_open_config_setwait(openconfig, ET_OPEN_WAIT); if (et_open(&id, argv[1], openconfig) != ET_OK) { printf("et2bos: et_open problems\n"); exit(1); } et_open_config_destroy(openconfig); /* * Now that we have access to an ET system, find out how many * events it has and what size they are. Then allocate an array * of pointers to use for reading, writing, and modifying these events. */ if (et_system_getnumevents(id, &nevents_max) != ET_OK) { printf("et2bos: ET has died\n"); exit(1); } if (et_system_geteventsize(id, &event_size) != ET_OK) { printf("et2bos: ET has died\n"); exit(1); } if ( (pe = (et_event **) calloc(nevents_max, sizeof(et_event *))) == NULL) { printf("et2bos: cannot allocate memory\n"); exit(1); } et_station_config_init(&sconfig); et_station_config_setuser(sconfig, ET_STATION_USER_MULTI); et_station_config_setrestore(sconfig, ET_STATION_RESTORE_OUT); et_station_config_setprescale(sconfig, 1); /* old "all" mode */ et_station_config_setselect(sconfig, ET_STATION_SELECT_ALL); et_station_config_setblock(sconfig, ET_STATION_BLOCKING); et_station_config_setcue(sconfig, 150); /* if ET_STATION_NONBLOCKING */ /* set debug level */ et_system_setdebug(id, ET_DEBUG_INFO); /* create station */ if ((status = et_station_create(id, &my_stat, argv[2], sconfig)) < 0) { if (status == ET_ERROR_EXISTS) { /* my_stat contains pointer to existing station */; printf("et2bos: set ptr to the existing station\n"); } else if (status == ET_ERROR_TOOMANY) { printf("et2bos: too many stations created\n"); goto error; } else { printf("et2bos: error in station creation\n"); goto error; } } printf("et2bos: station ready\n"); if (et_station_attach(id, my_stat, &attach) < 0) { printf("et2bos: error in station attach\n"); goto error; } /* open FPACK file for writing */ /*if( (status = FParm(str1,&fd)) !=0) { printf("FParm status %d \n",status); printf("command was >%s<\n",str1); exit(1); }*/ /* set file descriptor pointer */ BIOstream = (BOSIOptr)fd; /* initialize BOS array */ bosInit(jw,NBCS); while (et_alive(id)) { /**************/ /* read data */ /**************/ /* example of single, timeout read */ /* status = et_event_get(&id, attach, &pe[0], ET_TIMED, &timeout); */ /* example of single, asynchronous read */ /* status = et_event_get(&id, attach, &pe[0], ET_ASYNC, NULL);*/ /* example of reading array of up to "chunk" events */ /* chunk = 500; */ /* numread = status = et_events_get(&id, attach, pe, ET_SLEEP, NULL, chunk, &numread);*/ chunk = 500; status = et_events_get(id, attach, pe, ET_SLEEP, NULL, chunk, &numread); if (status == ET_OK) { ; } else if (status == ET_ERROR_DEAD) { printf("et2bos: ET system is dead\n"); goto end; } else if (status == ET_ERROR_TIMEOUT) { printf("et2bos: got timeout\n"); goto end; } else if (status == ET_ERROR_EMPTY) { printf("et2bos: no events\n"); goto end; } else if (status == ET_ERROR_BUSY) { printf("et2bos: station is busy\n"); goto end; } else if (status == ET_ERROR_WAKEUP) { printf("et2bos: someone told me to wake up\n"); goto end; } else if ((status == ET_ERROR_WRITE) || (status == ET_ERROR_READ)) { printf("et2bos: socket communication error\n"); goto end; } else if (status != ET_OK) { printf("et2bos: get error\n"); goto error; } /****************************************/ /* print data, write data to FPACK file */ /****************************************/ for (j=0; j<numread; j++) { et_event_getdata(pe[j], (void **) &ev); /* et_event_getlength(pe[j], &len); printf("et2bos: recname=>%4.4s%4.4s<, run#=%d, event#=%d, reclen=%d\n", (char *)&ev[3],(char *)&ev[4],ev[5],ev[6],ev[10]); printf(" temp = %d, pri = %d, len = %d\n", pe[j]->temp,et_event_getpriority(pe[j]),len); et_event_getcontrol(pe[j], con); for (i=0; i < ET_STATION_SELECT_INTS; i++) { printf("control[%d] = %d\n",i,con[i]); } */ /* drop banks from previous event */ bosLdrop(jw, "E"); bosNgarbage(jw); bosWgarbage(jw); /* create banks in BOS array */ status = et2bos(ev, jw, "E"); if (status != 0) { printf ("et2bos_test: error %d in et2bos()\n",status); exit(1); } /* call next if want to use ET record header; otherwise record name will be "RUNEVENT" and other info from HEAD bank */ /*bosWriteRecord(fd,&ev[3],ev[5],ev[6],ev[8]);*/ /* write down BOS banks to file */ /* status = bosWrite(fd, jw, "E"); if (status != 0) { printf ("et2bos_test: error %d in bosWrite()\n",status); exit(1); } */ } /*********************/ /* return data to ET */ /*********************/ /* example of writing single event */ /* status = et_event_put(id, attach, pe[0]);*/ /* example of writing array of events */ status = et_events_put(id, attach, pe, numread); if (status == ET_ERROR_DEAD) { printf("et2bos: ET is dead\n"); goto end; } else if ((status == ET_ERROR_WRITE) || (status == ET_ERROR_READ)) { printf("et2bos: socket communication error\n"); goto end; } else if (status != ET_OK) { printf("et2bos: put error\n"); goto error; } totalread += numread; end: /* print something out after having read NUMEVENTS events */ if (totalread >= NUMEVENTS) { totalread = 0; printf(" et2bos: %d events\n", NUMEVENTS); } /* if ET system is dead, wait here until it comes back */ while (!et_alive(id)) { status = et_wait_for_alive(id); if (status == ET_OK) { int locality; et_system_getlocality(id, &locality); /* if Linux, re-establish connection to ET system since socket broken */ if (locality == ET_LOCAL_NOSHARE) { printf("et2bos: try to reconnect Linux client\n"); et_forcedclose(id); goto restartLinux; } } } } /* while(alive) */ error: free(pe); printf("et2bos: ERROR\n"); exit(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); }
main(int argc,char **argv) { int *jw; BOSIO *fd; int status, i, j, size, nevents_max, event_size, freq, freq_tot=0, freq_avg, iterations=1, count; int con[ET_STATION_SELECT_INTS]; et_statconfig sconfig; et_openconfig openconfig; et_event **pe; et_att_id attach; et_sys_id id; struct timespec timeout, t1, t2; double time, avgsize, totsize; sigset_t sigblock; pthread_t tid; if (argc != 2) { printf("Usage: fpack2et <et_filename>\n"); exit(1); } timeout.tv_sec = 0; timeout.tv_nsec = 1; printf("fpack2et: will try to attach\n"); et_open_config_init(&openconfig); if (et_open(&id, argv[1], openconfig) != ET_OK) { printf("fpack2et: et_attach problems\n"); exit(1); } et_open_config_destroy(openconfig); et_system_setdebug(id, ET_DEBUG_INFO); /* * Now that we have access to an ET system, find out have many * events it has and what size they are. Then allocate an array * of pointers to use for reading, writing, and modifying these events. */ if (et_system_getnumevents(id, &nevents_max) != ET_OK) { printf("et_client: ET has died"); exit(1); } if (et_system_geteventsize(id, &event_size) != ET_OK) { printf("et_client: ET has died"); exit(1); } printf("event_size=%d\n",event_size); if ( (pe = (et_event **) calloc(nevents_max, sizeof(et_event *))) == NULL) { printf("et_client: cannot allocate memory"); exit(1); } if (et_station_attach(id, ET_GRANDCENTRAL, &attach) < 0) { printf("et_client: error in station attach\n"); exit(1); } printf("fpack2et: attached to gc, att = %d, pid = %d\n", attach, getpid()); /* open FPACK file */ if ( (status = bosOpen("./bigfile","r",&fd)) !=0) { printf("bosOpen status %d \n",status); fflush(stdout); goto error; } while (et_alive(id)) { #if defined(linux) || defined(Darwin) gettimeofday(&t1, NULL); #else clock_gettime(CLOCK_REALTIME, &t1); #endif avgsize = 0.; totsize = 0.; for (j=0; j < NUMLOOPS ; j++) { count = 0; for (i=0; i < CHUNK ; i++) { /*status = et_event_new(id, attach, &pe[i], ET_SLEEP, NULL, size);*/ status = et_event_new(id, attach, &pe[i], ET_SLEEP, NULL, (event_size-100)); if (status == ET_OK) { count++; } else if (status == ET_ERROR) { printf("fpack2et: et_event_new() returns ET_ERROR\n"); break; } else if (status == ET_ERROR_TIMEOUT) { printf("fpack2et: got timeout\n"); break; } else if (status == ET_ERROR_EMPTY) { printf("fpack2et: no events\n"); break; } else if (status == ET_ERROR_BUSY) { printf("fpack2et: grandcentral is busy\n"); break; } else if (status != ET_OK) { printf("fpack2et: request error\n"); goto error; } /************************************************/ /* write data, set priority, set control values */ /************************************************/ /* read one event from FPACK file */ et_event_getdata(pe[i], (void **)&jw); if((status = etRead(fd,jw,event_size,&size,control) ) == EBIO_EOF) { /*goto endoffile;*/ bosRewind(fd); status = etRead(fd,jw,event_size,&size,control); } avgsize += (double)size; totsize += (double)size; if ( status != 0) { printf("etRead error = %d\n",status); fflush(stdout); goto error; } control[0] = 1; /* to make MON happy */ et_event_setcontrol(pe[i], control, 4); et_event_setlength(pe[i], size); /*if(i==5) et_event_setpriority(pe[i], ET_HIGH);*/ /* status = et_event_put(id, attach, pe[i]); */ } /* for CHUNK */ /* write data */ /* goto a456; */ status = et_events_put(id, attach, pe, count); /*exit(0);*/ if (status == ET_OK) { ; } else if (status == ET_ERROR_DEAD) { printf("fpack2et: et_events_put() returns ET_ERROR_DEAD\n"); break; } else if (status != ET_OK) { printf("fpack2et: put error\n"); goto error; } a456: ; } /* for NUMLOOPS */ /* statistics */ avgsize = avgsize / ((double)(CHUNK*NUMLOOPS)); #if defined(linux) || defined(Darwin) gettimeofday(&t2, NULL); #else clock_gettime(CLOCK_REALTIME, &t2); #endif time = (double)(t2.tv_sec - t1.tv_sec) + 1.e-9*(t2.tv_nsec - t1.tv_nsec); freq = (CHUNK*NUMLOOPS)/time; if ((INT_MAX - freq_tot) < freq) { freq_tot = 0; iterations = 1; } freq_tot += freq; freq_avg = freq_tot/iterations; totsize = totsize/time/1024./1024.; iterations++; printf("%4d fpack2et: %7d Hz, %7d Hz Avg; %7.1f bytes size, %6.1f MBytes/sec\n", (int)totsize,freq,freq_avg,avgsize,totsize); if (!et_alive(id)) { et_wait_for_alive(id); } } /* while(alive) */ error: printf("fpack2et: ERROR\n"); exit(0); endoffile: /* close FPACK file */ bosClose(fd); exit(0); }
main(int argc,char **argv) { int i, j, size, status, nevents_max, event_size; et_att_id attach; et_sys_id id; et_event *pe; et_openconfig openconfig; if (argc != 2) { printf("Usage: et_producer <et_filename>\n"); exit(1); } /* set the desired size of our events in bytes */ size = 10; /* opening the ET system is the first thing we must do */ et_open_config_init(&openconfig); et_open_config_sethost(openconfig, ET_HOST_ANYWHERE); et_open_config_setcast(openconfig, ET_BROADCAST); if (et_open(&id, argv[1], openconfig) != ET_OK) { printf("et_producer: et_open problems\n"); exit(1); } et_open_config_destroy(openconfig); /* set the level of debug output that we want (everything) */ et_system_setdebug(id, ET_DEBUG_INFO); /* attach to GRANDCENTRAL station since we are producing events */ if (et_station_attach(id, ET_GRANDCENTRAL, &attach) < 0) { printf("et_producer: error in station attach\n"); exit(1); } while (et_alive(id)) { /* get new/unused event */ status = et_event_new(id, attach, &pe, ET_SLEEP, NULL, size); if (status != ET_OK) { printf("et_producer: error in et_event_new\n"); goto error; } /* put data into the event here */ /* put event back into the ET system */ status = et_event_put(id, attach, pe); if (status != ET_OK) { printf("et_producer: put error\n"); goto error; } if (!et_alive(id)) { et_wait_for_alive(id); } } /* while(alive) */ error: printf("et_producer: ERROR\n"); exit(0); }