/******************************************* * 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" #define SVEGLIA 1010 #define N_MIN 900 float array[1000], array1[60]; SY227_MBOX *sy227_mod; int sem_227mod_id; SY127_MBOX *sy127_mod; hv_mod_struct *mid; int sem_127mod_id; char *caller; sighand(signal) register int signal; { if ( signal == SVEGLIA ) ; else{ munlink(sy127_mod); munlink(sy227_mod); munlink(mid); sem_unl(sem_127mod_id, caller); sem_unl(sem_227mod_id, caller); exit(0); } } main(argc, argv) int argc; char *argv[]; { SY227_MBOX *sy227_mod; int sem_227mod_id; SY127_MBOX *sy127_mod; hv_mod_struct *mid; int sem_127mod_id; char *caller; char in_chamber[10]; int n_order; int cpu_nr, tcp_ip_nr; FILE *fp, *fp1, *fp2, *fopen(); 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, ch, ir, j, k, chan, value; int n_good, n_bad; int n_active; float imean, vmean; float media_camera[20], lst_camera[20]; short ch_imax, imax, d_vmon[32], d_imon[32], d_status[32]; short hv_ch_A, hv_ch_Ref, 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_A; short v0_hv_ch_A; short vmon_hv_ch_A; short i0_hv_ch_A; short imon_hv_ch_A; short status_hv_ch_Ref; short v0_hv_ch_Ref; short vmon_hv_ch_Ref; short i0_hv_ch_Ref; short imon_hv_ch_Ref; int yy, mm, dd, hh, min, sec; int jtime1, jdate1; int jtime2, jdate2; int tick; short day; int ncycle, n_anomalous[40]; static char h_module[] = "LAYER_HIST"; char h_name[80]; int nread, nvolte; int code, piano[2], ott1[2], ott2[2], sta1[2], sta2[2], n_lst; /* stdout->_flag |=_UNBUF; /* serve a non bufferizzare l'output ) */ intercept(sighand); 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)); chamber_code = "0"; hlimap(100000, h_module); strcpy(in_chamber, ""); n_order = 0; for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++){ /* successivamente si potrebbe chiedere soltanto una camera */ if((strcmp(chamber_code, mid->distr[dis].slot[sl].chamber) == 0 || strcmp(chamber_code, mid->distr[dis].slot[sl].cable_name) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch_Ref >= 0 ) ) && !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) ){ /* not cond */ if (strcmp(in_chamber, mid->distr[dis].slot[sl].chamber)){ strcpy(in_chamber, mid->distr[dis].slot[sl].chamber); n_order++; } printf(" n_order = %d\n", n_order); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 1 : inst. currents"); hbook1( (n_order-1)* 4 + 1 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 2 : inst. currents"); hbook1( (n_order-1)* 4 + 2 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 3 : inst. currents"); hbook1( (n_order-1)* 4 + 3 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 4 : inst. currents"); hbook1( (n_order-1)* 4 + 4 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 1 : integ. currents"); hbook1( (n_order-1)* 4 + 1 + 80 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 2 : integ. currents"); hbook1( (n_order-1)* 4 + 2 + 80 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " layer 3 : integ. currents"); hbook1( (n_order-1)* 4 + 3 + 80 , h_name, 60, 0., 60.); strcpy(h_name, mid->distr[dis].slot[sl].chamber); strcat(h_name, " /1min last 15 hours"); hbook1( n_order + 160, h_name, N_MIN, -(float) N_MIN , 0.); } } hbook1( 196," Appoggio 1", 60, 0., 60.); hbook1( 197," Appoggio 2", 60, 0., 60.); hbook1( 198," Appoggio 2", 60, 0., 60.); hbook1( 199," Appoggio 3", 60, 0., 60.); ncycle = 0; nread = 0; alm_cycle((int) SVEGLIA, (int) BIT32 | 256*60 ); while(1){ nvolte = 0; do { nvolte++; sleep(10); } while (sy227_mod->nvim == nread && nvolte <= 3); /* wait for a new update */ nread = sy227_mod->nvim; ncycle++; data_ora(&yy, &mm, &dd, &hh, &min, &sec); strcpy(in_chamber, ""); n_order = 0; for(dis = 0; dis < mid->n_crates; dis++) for(sl = 0; sl < 4; sl++){ if (strcmp(in_chamber, mid->distr[dis].slot[sl].chamber)){ strcpy(in_chamber, mid->distr[dis].slot[sl].chamber); n_order++; media_camera[n_order-1] = 0.; lst_camera[n_order-1] = 0.; } hreset((n_order -1)*4 + 1); hreset((n_order -1)*4 + 2); hreset((n_order -1)*4 + 3); hreset((n_order -1)*4 + 4); hreset(196); hreset(197); hreset(198); hreset(199); if((strcmp(chamber_code, mid->distr[dis].slot[sl].chamber) == 0 || strcmp(chamber_code, mid->distr[dis].slot[sl].cable_name) == 0 || ( strcmp("0", chamber_code) == 0 && mid->distr[dis].slot[sl].hv_ch_Ref >= 0 ) ) && !(mid->distr[dis].slot[sl].cond IS_CONDITIONING) ){ /* not cond */ if (mid->distr[dis].slot[sl].d_used_ch){ hv_ch_A = mid->distr[dis].slot[sl].hv_ch_A; hv_ch_Ref = mid->distr[dis].slot[sl].hv_ch_Ref; sem_wait(sem_127mod_id, argv[0]); status_hv_ch_A = sy127_mod->hv_par[1].status[hv_ch_A]; v0_hv_ch_A = sy127_mod->hv_par[1].v0[hv_ch_A]; vmon_hv_ch_A = sy127_mod->hv_par[1].vmon[hv_ch_A]; i0_hv_ch_A = sy127_mod->hv_par[1].i0[hv_ch_A]; imon_hv_ch_A = sy127_mod->hv_par[1].imon[hv_ch_A]; status_hv_ch_Ref = sy127_mod->hv_par[1].status[hv_ch_Ref]; v0_hv_ch_Ref = sy127_mod->hv_par[1].v0[hv_ch_Ref]; vmon_hv_ch_Ref = sy127_mod->hv_par[1].vmon[hv_ch_Ref]; i0_hv_ch_Ref = sy127_mod->hv_par[1].i0[hv_ch_Ref]; imon_hv_ch_Ref = sy127_mod->hv_par[1].imon[hv_ch_Ref]; sem_free(sem_127mod_id, argv[0]); if (strcmp(mid->distr[dis].slot[sl].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]; if ( !(status_hv_ch_Ref IS_RAMPU) && !(status_hv_ch_Ref IS_RAMPD) ) d_imon[i] = sy227_mod->sl_par[dis][sl].imon[i]; else d_imon[i] = -1.; d_status[i] = sy227_mod->sl_par[dis][sl].status[i]; } sem_free(sem_227mod_id, argv[0]); imean = 0; n_active = 0; for (i = 0; i < 32; i++){ /* decodifica connessioni */ code = mid->distr[dis].slot[sl].lst[i][0]; n_lst = 0; piano[0] = code / 1000000; if (piano[0]){ sta1[0] = (code - piano[0] * 1000000)/100000 ; ott1[0] = (code - piano[0] * 1000000 - sta1[0]*100000) /1000 ; sta2[0] = (code - piano[0] * 1000000 - sta1[0]*100000 - ott1[0] * 1000)/100 ; ott2[0] = code - piano[0] * 1000000 - sta1[0]*100000 - ott1[0] * 1000 - sta2[0] * 100 ; if (ott1[0]) n_lst++; if (ott2[0]) n_lst++; } code = mid->distr[dis].slot[sl].lst[i][1]; piano[1] = code / 1000000; if (piano[1]){ sta1[1] = (code - piano[1] * 1000000)/100000 ; ott1[1] = (code - piano[1] * 1000000 - sta1[1]*100000) /1000 ; sta2[1] = (code - piano[1] * 1000000 - sta1[1]*100000 - ott1[1] * 1000)/100 ; ott2[1] = code - piano[1] * 1000000 - sta1[1]*100000 - ott1[1] * 1000 - sta2[1] * 100 ; if (ott1[1]) n_lst++; if (ott2[1]) n_lst++; } /* riempie istogrammi */ if(piano[0] && n_lst){ if(ott1[0]){ media_camera[n_order-1] += (float)d_imon[i]/(float)n_lst; lst_camera[n_order-1] += 1.; hf1( (n_order-1) * 4 + piano[0], (float)ott1[0], (float)d_imon[i]/(float)n_lst); hf1( piano[0] + 195, (float)ott1[0], (float)d_imon[i]/(float)n_lst); } if(ott2[0]){ media_camera[n_order-1] += (float)d_imon[i]/(float)n_lst; lst_camera[n_order-1] += 1.; hf1( (n_order-1) * 4 + piano[0], (float)ott2[0], (float)d_imon[i]/(float)n_lst); hf1( piano[0] + 195, (float)ott2[0], (float)d_imon[i]/(float)n_lst); } } if(piano[1] && n_lst){ if(ott1[1]){ media_camera[n_order-1] += (float)d_imon[i]/(float)n_lst; lst_camera[n_order-1] += 1.; hf1( (n_order-1) * 4 + piano[1], (float)ott1[1], (float)d_imon[i]/(float)n_lst); hf1( piano[1] + 195, (float)ott1[1], (float)d_imon[i]/(float)n_lst); } if(ott2[1]){ media_camera[n_order-1] += (float)d_imon[i]/(float)n_lst; lst_camera[n_order-1] += 1.; hf1( (n_order-1) * 4 + piano[1], (float)ott2[1], (float)d_imon[i]/(float)n_lst); hf1( piano[1] + 195, (float)ott2[1], (float)d_imon[i]/(float)n_lst); } } } } } } /* fine IF sulle slot buone */ for ( i = 0; i < 4; i++){ hunpak(195 + i, array1, 60); hunpak((n_order - 1)*4 + i +1 , array, 60); for ( j = 1; j < 60; j++) array[j] = ( (ncycle-1)*array[j] + array1[j] )/(float)ncycle; hpak((n_order - 1)*4 + i +1 , array); } } /* fine LOOP sulle slots */ for ( ch = 0; ch < n_order; ch++ ){ if (lst_camera[ch]) media_camera[ch] /= lst_camera[ch]; hunpak(ch + 1 + 160, array, N_MIN); for ( i = 0; i < N_MIN; i++){ array[i] = array[i+1]; } array[N_MIN - 1] = media_camera[ch]; hpak(ch + 1 + 160, array); } data_ora(&yy, &mm, &dd, &hh, &min, &sec); sleep(0); /* aspetta l'allarme */ } /* end of while(1) loop */ }