/******************************************* * Look the parameters in the CAEN Mail box * * and make histograms * * * *******************************************/ #include #include #include #include #include #include #include #include "../lib/mylib1.h" #include "../dbase/hv_dbase.h" #include "a200.h" SY227_MBOX *sy227_mod; int sem_227mod_id; SY127_MBOX *sy127_mod; hv_mod_struct *mid; int sem_127mod_id; char *caller; char line[80], cline[80], tmpfile[64], tmpfile_h[64]; int n_order; int cpu_nr, tcp_ip_nr; FILE *fp, *fp1, *fp2, *fopen(); int pout; char *scatola_nera = "scatola_nera_h"; int hosp; main(argc, argv) int argc; char *argv[]; { char *chamber_code; char *mod_name0 = "hv_config0"; char *mod_name1 = "hv_config1"; char *mod_name2 = "hv_config2"; char *mod_name, *hv_config[3]; int dis, sl; int ch1, ch2, first_print; int nwrite, nerror, par_val; short ndata, data[45], prot_word; short i, ir, j, k, chan, value, code; int n_good, n_bad; float imean, vmean; short ch_imax, imax, d_vmon[32], d_imon[32], d_status[32]; short hv_ch, on_off, hv_in; int sy127_mod_vim_tim[6]; int sy127_mod_sta_tim[6]; int sy227_mod_vim_tim[6]; int sy227_mod_sta_tim[6]; int sy127_mod_nvim; int sy127_mod_nvim_err; int sy127_mod_nsta; int sy127_mod_nsta_err; int sy227_mod_nvim; int sy227_mod_nvim_err; int sy227_mod_nsta; int sy227_mod_nsta_err; short status_hv_ch; short v0_hv_ch; short vmon_hv_ch; short i0_hv_ch; short imon_hv_ch; int yy, mm, dd, hh, min, sec; int jtime1, jdate1; int jtime2, jdate2; int tick; short day; int time_lost, time_to_sleep; int ncycle, n_anomalous[40]; static char h_module[] = "HV_HISTOGRAMS"; float array[500]; char h_name[80]; int nread; if ((pout = create(scatola_nera, 0x03, 0x03)) == -1) if ((pout = open(scatola_nera, 0x03)) == -1) exit(_errmsg(errno," tubi_sitter: error opening %s\n",scatola_nera)); close(pout); if((sy127_mod = (SY127_MBOX *)modlink("sy127mod", 0)) == (SY127_MBOX *) -1) exit(_errmsg(errno,"tubi_sitter: err. link data module\n")); sem_127mod_id = sem_link_cr("SY127mod", argv[0]); if((sy227_mod = (SY227_MBOX *)modlink("sy227mod", 0)) == (SY227_MBOX *) -1) exit(_errmsg(errno,"tubi_sitter: err. link data module\n")); sem_227mod_id = sem_link_cr("SY227mod", argv[0]); get_config(&tcp_ip_nr, &cpu_nr, hv_config); mod_name = hv_config[cpu_nr]; if ((mid = (hv_mod_struct *)modlink(mod_name, 0)) == (hv_mod_struct *)-1) if ((mid = (hv_mod_struct *)modload(mod_name, 0)) == (hv_mod_struct *)-1) exit(_errmsg(errno, "%s: error linking module %s\n", argv[0], mod_name)); printf(" moduli e semafori pronti\n"); chamber_code = "0"; printf(" prima di hlimap ( per aprire %s )\n", h_module); hlimap(100000, h_module); printf(" dopo hlimap1\n"); printf(" dopo hlimap2\n"); printf(" dopo hlimap3\n"); printf(" dopo hlimap4\n"); n_order = 0; for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++){ k = 0; /* successivamente si potrebbe chiedere soltanto una camera */ if((strcmp(chamber_code, mid->distr[dis].slot[sl].cable[k].chamber) == 0 || strcmp(chamber_code, mid->distr[dis].slot[sl].cable[k].cable_name) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch >= 0 && mid->distr[dis].slot[sl].cable[k].first_ch >= 0) ) && !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) ){ /* not cond */ n_order++; printf(" n_order = %d\n"); strcpy(h_name, mid->distr[dis].slot[sl].cable[k].cable_name); strcat(h_name, ": inst. currents"); hbook1(n_order, h_name, 32, 0., 32.); strcpy(h_name, mid->distr[dis].slot[sl].cable[k].cable_name); strcat(h_name, ": integ. currents"); hbook1(40 + n_order, h_name, 32, 0., 32.); } } printf(" hbook1 chiamate\n"); ncycle = 0; while(1){ ncycle++; if ((pout = open(scatola_nera, 0x03)) == -1) exit(_errmsg(errno," tubi_sitter: error opening %s\n",scatola_nera)); if (lseek(pout, 0, 0) == -1) exit(_errmsg(errno," error rewinding %s\n",scatola_nera)); data_ora(&yy, &mm, &dd, &hh, &min, &sec); sprintf(cline, "%2d/%2d/%2d %2d:%2d histogramming starts\n", dd, mm, yy, hh, min); write(pout, cline, strlen(cline)); n_order = 0; for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++){ k = 0; n_order++; if((strcmp(chamber_code, mid->distr[dis].slot[sl].cable[k].chamber) == 0 || strcmp(chamber_code, mid->distr[dis].slot[sl].cable[k].cable_name) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch >= 0 && mid->distr[dis].slot[sl].cable[k].first_ch >= 0) ) && !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) ){ /* not cond */ if (mid->distr[dis].slot[sl].d_used_ch){ hv_ch = mid->distr[dis].slot[sl].hv_ch; sem_wait(sem_127mod_id, argv[0]); status_hv_ch = sy127_mod->hv_par[1].status[hv_ch]; v0_hv_ch = sy127_mod->hv_par[1].v0[hv_ch]; vmon_hv_ch = sy127_mod->hv_par[1].vmon[hv_ch]; i0_hv_ch = sy127_mod->hv_par[1].i0[hv_ch]; imon_hv_ch = sy127_mod->hv_par[1].imon[hv_ch]; sem_free(sem_127mod_id, argv[0]); if (strcmp(mid->distr[dis].slot[sl].cable[k].chamber,"01")){ /* distributors */ sem_wait(sem_227mod_id, argv[0]); on_off = sy227_mod->sl_par[dis][sl].onoff; hv_in = sy227_mod->sl_par[dis][sl].hvin; for ( i = 0; i < 32; i++){ d_vmon[i] = sy227_mod->sl_par[dis][sl].vmon[i]; d_imon[i] = sy227_mod->sl_par[dis][sl].imon[i]; d_status[i] = sy227_mod->sl_par[dis][sl].status[i]; } sem_free(sem_227mod_id, argv[0]); hunpak(40 + n_order, array, 32); for (i = 0; i < 32; i++){ hf1(n_order, (float)i, (float)d_imon[i]); array[i] = array[i] + d_imon[i]; } hpak(40 + n_order, array); } } } } data_ora(&yy, &mm, &dd, &hh, &min, &sec); sprintf(cline, "%2d/%2d/%2d %2d:%2d *** CYCLE FINISHED *******\n\n\n", dd, mm, yy, hh, min); write(pout, cline, strlen(cline)); sprintf(cline, " Ignore following lines \n\n\n"); write(pout, cline, strlen(cline)); close(pout); nread = sy227_mod->nvim; do { sleep(10); } while (sy227_mod->nvim == nread); /* wait for a new update */ } /* end of while(1) loop */ }