#include #include #include #include "root_inc.hh" #include "rootspy_hist.hh" #include "hist_lib.hh" #include /* int init_hist(); int fill_hist(); int fill_ped(int ped); int fill_bank(unsigned int *bank, int size); int reset_hist(int flag) ; */ //-------------- RCM MONOTORING ------------------- //#include "shmem_roc.h" static void shmem_get(); static int semid,shmid; static roc_shmem *shmem_ptr; int *HIST_buffer; int *skip_event_counter; int64_t *tiBusyTime; int *HIST_FLAG; int *RUN_NUM; int *RUN_FLAG; int *buffer_size; Hist * histptr; int *FADC_TYPE; int RUN_NUM_OLD=0; //TList *ALL_1D_HIST; //TApplication* appl; //===================================================== int sig_int=0, sig_hup=0, sig_alarm=0,sig_pipe=0; void ctrl_c(int m) { sig_int=1; printf("\n CTRL-C pressed...\n"); exit(1); // printf("\n CTRL-C pressed, cancel timer=%d\n",alarm(1)); } void fpipe(int m) { sig_pipe=1; printf("\n Signal SIGPIPE ...\n"); } void ignore_sigpipe(void) { struct sigaction act; int r; memset(&act, 0, sizeof(act)); //act.sa_handler = SIG_IGN; act.sa_handler = fpipe; act.sa_flags = SA_RESTART; r = sigaction(SIGPIPE, &act, NULL); if (r) printf("sigaction SIGPIPE \n"); } //-------------------------------------------- struct hist_param { int ic; TSocket * sock; char host_name[128]; }; int Debug=0; int Debug_Slot=0; int Debug_Chan=0; //===================================================== int load_dac(int *new_dac,int *new_thr,int FLAG) { if (0>*FADC_TYPE || *FADC_TYPE>=MAX_FADC_CONFIG) return -1; printf("===> load_dac(), FLAG=%d \n",FLAG); for (int ii=0; ii0 || shmem_ptr->fadc_config[*FADC_TYPE].DAC[ii]>0 ) printf("load bin=%d marker=%d ",ii,shmem_ptr->fadc_config[*FADC_TYPE].DAC[ii]); if (FLAG>0 && new_dac[ii]>10) { shmem_ptr->fadc_config[*FADC_TYPE].DAC[ii]=new_dac[ii]; printf("dac=%d ",new_dac[ii]); } if ( shmem_ptr->fadc_config[*FADC_TYPE].DAC[ii]==1 && new_dac[ii]<=10 ) { printf("Error , empty chnnel=%d newdac=%d marker=%d ",ii,new_dac[ii],shmem_ptr->fadc_config[*FADC_TYPE].DAC[ii]); histptr->FillPed(ii,1.,*FADC_TYPE); histptr->FillSigma(ii,3.,*FADC_TYPE); } shmem_ptr->fadc_config[*FADC_TYPE].THR[ii]=new_thr[ii]; //-- error : +baseline !! if (new_dac[ii]>0) printf(" thr=%d \n",new_thr[ii]); //shmem_ptr->DAC_ped[ii]=new_dac[ii]; } shmem_ptr->fadc_config[*FADC_TYPE].Flag=1; } //===================================================== int mark_chan(int *new_dac,int *new_thr) { if (0>*FADC_TYPE || *FADC_TYPE>=MAX_FADC_CONFIG) return -1; for (int ii=0; iifadc_config[*FADC_TYPE].DAC[ii]; new_thr[ii]=0; // shmem_ptr->fadc_config[*FADC_TYPE].THR[ii]; } } //===================================================== void *hist_serv_thread(void* arg); //===================================================== // //===================================================== static void *fill_bank_thread (void *arg ) { unsigned int *buffer = (unsigned int*) arg; int new_dac[MAX_CONF]; int new_thr[MAX_CONF]; int rc=-1; *HIST_FLAG=0; //*FADC_TYPE=1; prctl(PR_SET_NAME,"hist_thread"); ignore_sigpipe(); while(1) { if (*RUN_NUM!=RUN_NUM_OLD) { //--- New Run -- //histptr->RunInfo->SetBinContent(1,*RUN_NUM); RUN_NUM_OLD=(*RUN_NUM); } if (*HIST_FLAG==1) { /* buffer filled */ if (Debug>1) printf(" BUFFER FILLED!!! :: HIST_FLAG=%d RUN_FLAG=%d \n",*HIST_FLAG,*RUN_FLAG); //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ if (*RUN_FLAG==0 || *RUN_FLAG==1 || *RUN_FLAG==5 || *RUN_FLAG==7 ) { //-- RUN_FLAG==0,1,5 etc... fill_bank (buffer,*buffer_size); } else if (*RUN_FLAG>100) { //-- fit ADC hist, RUN_FLAG=3000 , .... printf(" Call FIT_HIST DAC=%d \n",*RUN_FLAG); //mark_chan(new_dac,new_thr); rc=fit_hist(*RUN_NUM,*RUN_FLAG,*FADC_TYPE,new_dac,new_thr,MAX_CONF); save_hists(*RUN_NUM,*RUN_FLAG); if (rc==1) { // load new pedestals and thr; this is Nfits. load_dac(new_dac,new_thr,1); *RUN_FLAG=4; //--- set DAC and start run to check pedestals. printf("set RUN_FLAG=4 \n",*RUN_FLAG); } else if (rc==2) { //--- reload new THR only //load_dac(new_dac,new_thr,0); load_dac(new_dac,new_thr,1); //-- load both. *RUN_FLAG=6; //--- all done load and stop. //--- for RUN_FLAG=102 printf("set RUN_FLAG=2 \n",*RUN_FLAG); } else if (rc==3) { //--- last fit //load_dac(new_dac,new_thr,0); load_dac(new_dac,new_thr,1); //-- load both. *RUN_FLAG=2; //--- all done load and stop. //--- for RUN_FLAG=102 printf("set RUN_FLAG=2 \n",*RUN_FLAG); } else { //-- rc=0 = Nfits reset_hist(*RUN_NUM,1); //-- reset only adc hists; *RUN_FLAG=1; //--- continue fill ADC hist printf("set RUN_FLAG=1 \n",*RUN_FLAG); } //------------------------------------------------------------------------------ } else if (*RUN_FLAG==3) { //--- DACs loaded with interpolated values, THR is not good yet printf("got RUN_FLAG=%d reset_hist(%d,1) set RUN_FLAG=0 \n",*RUN_FLAG,*RUN_NUM); reset_hist(*RUN_NUM,1); *RUN_FLAG=0; //--- reset done, stop } else if (*RUN_FLAG==15) { //--- printf("got RUN_FLAG=%d reset_hist(%d,1) set RUN_FLAG=5 \n",*RUN_FLAG,*RUN_NUM); reset_hist(*RUN_NUM,1); *RUN_FLAG=5; //--- reset done, continue } else if (*RUN_FLAG==17) { //--- printf("got RUN_FLAG=%d reset_hist(%d,1) set RUN_FLAG=5 \n",*RUN_FLAG,*RUN_NUM); reset_hist(*RUN_NUM,1); *RUN_FLAG=7; //--- reset done, continue } //------------------------------------------------------------------------------ *HIST_FLAG=0; if (Debug>1) printf(" BUFFER FILLED!!! :: EXIT::: HIST_FLAG=%d RUN_FLAG=%d rc=%d \n",*HIST_FLAG,*RUN_FLAG,rc); //------------------------------------------------------------------------------ } else if (*HIST_FLAG==2) { /* prestart */ printf(" PRESTART:: HIST_FLAG=%d RUN_NUM=%d \n",*HIST_FLAG,*RUN_NUM); reset_hist(*RUN_NUM,0); mark_chan(new_dac,new_thr); *HIST_FLAG=0; } else if (*HIST_FLAG==3) { /* end of run */ printf(" END_of_RUN=%d :: HIST_FLAG=%d \n",*RUN_NUM,*HIST_FLAG); save_hists(*RUN_NUM,0); *HIST_FLAG=0; } else if (*HIST_FLAG==4) { /* reset */ printf(" RESET:: RUN=%d HIST_FLAG=%d \n",*RUN_NUM,*HIST_FLAG); save_hists(*RUN_NUM,0); *HIST_FLAG=0; } usleep(100); } } //===================================================== static void *fill_rates_thread (void *arg ) { unsigned int *buffer = (unsigned int*) arg; unsigned int update_f_old=0, update_d_old=0, update_r_old=0; double dtime; int count=0; int fill_slots = 1; //----------------------- prctl(PR_SET_NAME,"rate_thread"); ignore_sigpipe(); sleep(5); while(1) { histptr->RunInfo->SetBinContent(1,*RUN_NUM); histptr->RunInfo->SetBinContent(2,*skip_event_counter); int tiBusyTime32 = *tiBusyTime; histptr->RunInfo->SetBinContent(3,tiBusyTime32); //if (Debug>1) printf("--------------------> tiBusyTime=%ld \n",tiBusyTime32); //--------------------------------------------------------------------------------------------------- // F A D C 2 5 0 //--------------------------------------------------------------------------------------------------- unsigned int update_f=shmem_ptr->f250_scalers.update; if ( update_f != update_f_old) { //---- for(int slot=0; slot<21; slot++) { if (shmem_ptr->f250_scalers.counters[slot][16]==0) continue; if (Debug>3) printf("--------------------> Fill slot=%d , rates:",slot); for(int ichan=0; ichan<16; ichan++) { if (Debug>3) if( (ichan%4) == 0 ) printf("\n"); if (Debug>3) printf("| %2d: %10.3f Hz ",ichan,shmem_ptr->f250_scalers.rates[slot][ichan]); fill_f250_scalers(slot, ichan, shmem_ptr->f250_scalers.rates[slot][ichan] ); } if (Debug>3) printf("\n timer: %.3f sec., %d cnt.\n",shmem_ptr->f250_scalers.rates[slot][16]); if (Debug>4) { printf("---------- counters: "); for(int ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %08d ",ichan,shmem_ptr->f250_scalers.counters[slot][ichan]); } printf("\n timer: %d cnt. \n",shmem_ptr->f250_scalers.counters[slot][16]); } } update_f_old=update_f; //printf("\n Update: %lu us. , UI=%d TT=%d \n",update_f,sizeof(unsigned int), sizeof(time_t)); } //--------------------------------------------------------------------------------------------------- // D S C R I M I N A T O R S //--------------------------------------------------------------------------------------------------- unsigned int update_d=shmem_ptr->discr_scalers.update; if ( update_d != update_d_old) { //---- fill_discr_time(-1.); count++; for(int slot=0; slot<=21; slot++) { //--- !!! hard-coded 21 if (shmem_ptr->discr_scalers.counters[slot][16]==0) continue; if (Debug>3) printf(" Fill slot=%d \n",slot); for(int ichan=0; ichan<16; ichan++) { if (Debug>3) if( (ichan%4) == 0 ) printf("\n"); if (Debug>3) printf("| %2d: %10.3f Hz ",ichan,shmem_ptr->discr_scalers.rates[slot][ichan]); fill_discr_scalers(slot, ichan, shmem_ptr->discr_scalers.rates[slot][ichan] ); } if (Debug>3) printf("\n timer: %.3f sec. \n",shmem_ptr->discr_scalers.rates[slot][16]); if (Debug>2) for(int ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %08d ",ichan,shmem_ptr->discr_scalers.counters[slot][ichan]); } unsigned long long ct=time(NULL)*(unsigned long long)1000000; if (Debug>4) printf("\n time: %lu us. time=%f us, systime=%lu sec. (%llu us)\n" ,shmem_ptr->discr_scalers.counters[slot][16] ,shmem_ptr->discr_scalers.rates[slot][16],time(NULL),ct); } // if (fill_slots) { fill_discr_slots(shmem_ptr->discr_scalers.Nslots, shmem_ptr->discr_scalers.slots); fill_slots=0; } dtime=shmem_ptr->discr_scalers.tv_sec+shmem_ptr->discr_scalers.tv_usec*1e-6; fill_discr_time(dtime); //if (count==100) save_hists(1001,0); //--------------------------------------------------------------------------------------------------- update_f_old=update_f; update_d_old=update_d; //printf("\n Update: %lu us. , UI=%d TT=%d \n",update_f,sizeof(unsigned int), sizeof(time_t)); } //--------------------------------------------------------------------------------------------------- // D I R C //--------------------------------------------------------------------------------------------------- unsigned int update_r=shmem_ptr->dirc_scalers.update; if ( update_r != update_r_old) { //---- //fill_dirc_time(-1.); count++; for(int slot=DIRC_FIRST_SLOT; slot<(DIRC_FIRST_SLOT+DIRC_USED_SLOT); slot++) { //--- !!! hard-coded 21 DIRC_MAX_CHAN if (shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN]==shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN-1]) continue; shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN-1]=shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN]; //-- update if (Debug>3) printf(" Fill slot=%d \n",slot); reset_dirc_scalers(slot); reset_dirc_data(slot); printf("=============================================================== DIRC scalers slot=%d \n",slot); int ndata = shmem_ptr->dirc_scalers.counters[slot][0]; if (Debug>2) for(int ichan=0; ichan4) if( (ichan%6) == 0 ) printf("\n"); if (Debug>4) printf("| %2d: %10u ",ichan,shmem_ptr->dirc_scalers.counters[slot][ichan]); } if (Debug>4) printf("\n timer: %u cnt. \n",shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN]); printf("slot=%d ndata=%d\n",slot,ndata); //reset_dirc_scalers(slot); unsigned int ii=0; unsigned int length=shmem_ptr->dirc_scalers.counters[slot][ii++]; while(iidirc_scalers.counters[slot][ii++]; unsigned int ref=shmem_ptr->dirc_scalers.counters[slot][ii++]; double scale=1.; if(ref>0) { scale = 125000000.0 / ref; //printf("sspRich_ReadScalers:: reference scaler = %f \n",scale); } else { printf("sspRich_ReadScalers:: ERROR - reference scaler invalid\n"); scale = 1.0; } for (int ic=0; ic4) if( (ic%6) == 0 ) printf("\n"); if (Debug>4) printf("| %2d: %11.3f counter=%llu scale=%f ",ic,shmem_ptr->dirc_scalers.counters[slot][ii]*scale,shmem_ptr->dirc_scalers.counters[slot][ii],scale); fill_dirc_scalers(slot, fiber, ic, shmem_ptr->dirc_scalers.counters[slot][ii]*scale ); shmem_ptr->dirc_scalers.rates[slot][ii]=shmem_ptr->dirc_scalers.counters[slot][ii]*scale; ii++; } } unsigned long long ct=time(NULL)*(unsigned long long)1000000; if (Debug>4) printf("\n time: %lu us. time=%f us, systime=%lu sec. (%llu us)\n" ,shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN] ,shmem_ptr->dirc_scalers.rates[slot][DIRC_MAX_CHAN],time(NULL),ct); ndata = shmem_ptr->dirc_scalers.data[slot][0]; printf("--------------------------------------------------------------->> DIRC temperature slot=%d ndata =%d \n",slot,ndata); if (Debug>2) for(int ichan=0; ichan3) if( (ichan%6) == 0 ) printf("\n"); if (Debug>3) printf("| %2d: %10u ",ichan,shmem_ptr->dirc_scalers.data[slot][ichan]); } if (Debug>3) printf("\n timer: %u cnt. \n",shmem_ptr->dirc_scalers.rates[slot][DIRC_MAX_CHAN]); printf("slot=%d temp/volt ndata=%d\n",slot, ndata); //reset_dirc_data(slot); ii=0; length=shmem_ptr->dirc_scalers.data[slot][ii++]; while(iidirc_scalers.data[slot][ii++]; for (int ic=0; ic3) if( (ic%6) == 0 ) printf("\n ------------- mSlot = %d Fiber = %d -------------\n",slot,fiber); if (Debug>3) printf("| %2d: %11.3f ",ic,shmem_ptr->dirc_scalers.data[slot][ii]/1000.); fill_dirc_data(slot, fiber, ic, shmem_ptr->dirc_scalers.data[slot][ii] ); ii++; } } //printf("check:: slot=%d ii=%d ndata=%d \n",slot,ii,ndata); ct=time(NULL)*(unsigned long long)1000000; if (Debug>4) printf("\n time: %lu us. time=%f us, systime=%lu sec. (%llu us)\n" ,shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_DATA] ,shmem_ptr->dirc_scalers.rates[slot][DIRC_MAX_DATA],time(NULL),ct); } //-- slot loop -- update_r_old=update_r; // //if (fill_slots) { fill_dirc_slots(shmem_ptr->dirc_scalers.Nslots, shmem_ptr->dirc_scalers.slots); fill_slots=0; } dtime=shmem_ptr->dirc_scalers.tv_sec+shmem_ptr->dirc_scalers.tv_usec*1e-6; fill_dirc_time(dtime); //if (count==100) save_hists(1001,0); //--------------------------------------------------------------------------------------------------- } usleep(100); } } //===================================================== void usage(char* name) { printf("\nusage: %s -h[elp] -d[debug]=LEVEL \n",name); } int STREQ(char*s1,const char*s2) { if (strncasecmp(s1,s2,strlen(s2))) return 0; else return 1; } //===================================================== // //===================================================== int main(int argc, char *argv[]) { char *substr1, *substr2; static int HIST_INIT; //appl=new TApplication("App", NULL, 0); pthread_t hist_thread, rate_thread; TThread *th_hist_srv=NULL; //----------------------- for (int ii=1;ii ",ii,argv[ii]); //------------------------------------------------------------------- if(STREQ(argv[ii],"-d")) { //-- port Debug=1; if ((substr1=strstr(argv[ii],"="))) { printf("found /=/ |%s|\n",substr1); Debug=atoi(&substr1[1]); Debug_Slot=Debug/1000; Debug_Chan=(Debug/10)%100; Debug=Debug%10; printf("Debug=%d Slot=%d Chan=%d\n",Debug,Debug_Slot,Debug_Chan); } } //------------------------------------------------------------------- //------------------------------------------------------------------- if(STREQ(argv[ii],"-h")) { usage(argv[0]); exit(0); } } //----------------------- //signal(SIGINT,ctrl_c); //signal(SIGPIPE,fpipe); //signal(SIGPIPE, SIG_IGN); ignore_sigpipe(); //----------------------- shmem_get(); HIST_buffer=shmem_ptr->EventBuffer; HIST_FLAG=&shmem_ptr->EventBufferFLAG; RUN_FLAG=&shmem_ptr->RUN_Flag; RUN_NUM=&shmem_ptr->RUN_Number; FADC_TYPE=&shmem_ptr->FADC_TYPE; buffer_size=&shmem_ptr->EventLength; skip_event_counter=&shmem_ptr->EventSkipCounter; tiBusyTime=&shmem_ptr->Time_mark; *HIST_FLAG=0; //*skip_event_counter=0; histptr = init_hist(shmem_ptr); HIST_INIT=1; // ALL_1D_HIST=histptr->ALL_1D_HIST; reset_hist(0,0); int ret = pthread_create (&hist_thread, 0, fill_bank_thread, HIST_buffer); if (ret) { perror ("pthread_create"); } ret = pthread_create (&rate_thread, 0, fill_rates_thread, HIST_buffer); if (ret) { perror ("pthread_create"); } //reset_hist(0,0); th_hist_srv = new TThread("hist_serv_thread", hist_serv_thread, NULL); th_hist_srv->Run(); /* int i=0; while(1) { i++; //for(i=0;i<100;i++) { fill_hist(); fill_fadc(1,1,200); fill_ped(100); if (!(i%10)) printf("Event=%d\n",i); usleep(100000); } */ while(1) { sleep(1); } close_hist(); return 0; } /*=====================================================================*/ void *hist_serv(void* arg) { /*=====================================================================*/ TMessage mess1(kMESS_OBJECT); TMessage *mess; // int DEBUG=0; int DBG_h=7; int DBG_a=7; struct hist_param *param = (struct hist_param *) arg; TSocket * sd=param->sock; int ic=param->ic; int id; TThread::Printf(" New Client TThread --> hist_serv sock=%d ic=%d <--",sd,ic); prctl(PR_SET_NAME,"hist_serv_thread"); //TDirectory *dir = (TDirectory*)gDirectory->FindObjectAny("ROCS"); //if(dir) dir->cd(); /*--------------------------------------*/ ignore_sigpipe(); while (sig_int==0) { int ret = sd->Recv(mess); if (Debug>DBG_a) printf("hist_serv():: Received message, ret(len)=%d mess=%p \n",ret,mess); if (ret<=0) { printf("hist_serv():: Error recv, Close socket %lu ret=%d\n",(long int)sd,ret); sd->Close(); return NULL; } if (mess && mess->What() == kMESS_STRING) { char *hname=NULL; char cmd[256]; mess->ReadString(cmd, 256); if (Debug>DBG_a) printf("hist_serv():: Client %d: %s\n",ic, cmd); if (!strncmp(cmd,"Update",6)) printf("hist_serv():: Client %d: %s\n",ic, cmd); if (!strncmp(cmd,"Update",6) || !strncmp(cmd,"Hist:",5) ) { if (!strncmp(cmd,"Hist:",5) ) hname=&cmd[5]; mess1.Reset(); // re-use TMessage object int icc=0; TObject *obj; if (Debug>DBG_a) printf("hist_serv():: RUN loop\n"); //--- send RUN hist TIter next0(histptr->ALL_RUN_HIST); while ((obj = next0())) { mess1.Reset(); icc++; const char *hh = obj->GetName(); if (Debug>DBG_h) { printf("hist_serv():: ICC=%d request=%s hname=%s hh=%s ",icc,cmd,hname,hh); obj->Print(); } if ( strncmp(cmd,"Update",6) && strcmp(hname,hh) ) continue; if (Debug>DBG_h) { printf("hist_serv():: SEND hist: request=%s hname=%s hh=%s ",cmd,hname,hh); } mess1.WriteObject(obj); // write object in message buffer int ret = sd->Send(mess1); if (ret<=0) { printf("hist_serv():: Error send, Close socket %lu \n",(long int)sd); sd->Close(); return NULL; } } if (Debug>DBG_a) printf("hist_serv():: 1D loop\n"); //--- send 1D hist TIter next1(histptr->ALL_1D_HIST); while ((obj = next1())) { mess1.Reset(); icc++; const char *hh = obj->GetName(); if (Debug>DBG_h) { printf("hist_serv():: ICC=%d request=%s hname=%s hh=%s ",icc,cmd,hname,hh); obj->Print(); } if ( strncmp(cmd,"Update",6) && strcmp(hname,hh) ) continue; if (Debug>DBG_h) { printf("hist_serv():: SEND hist: request=%s hname=%s hh=%s ",cmd,hname,hh); } mess1.WriteObject(obj); // write object in message buffer int ret = sd->Send(mess1); if (ret<=0) { printf("hist_serv():: Error send, Close socket %lu \n",(long int)sd); sd->Close(); return NULL; } } if (Debug>DBG_a) printf("hist_serv():: FIT loop\n"); //--- send FIT hist TIter next1f(histptr->ALL_FIT_HIST); while ((obj = next1f())) { mess1.Reset(); icc++; const char *hh = obj->GetName(); if (Debug>DBG_h) { printf("hist_serv():: ICC=%d request=%s hname=%s hh=%s ",icc,cmd,hname,hh); obj->Print(); } if ( strncmp(cmd,"Update",6) && strcmp(hname,hh) ) continue; if (Debug>DBG_h) { printf("hist_serv():: SEND hist: request=%s hname=%s hh=%s ",cmd,hname,hh); } mess1.WriteObject(obj); // write object in message buffer int ret = sd->Send(mess1); if (ret<=0) { printf("hist_serv():: Error send, Close socket %lu \n",(long int)sd); sd->Close(); return NULL; } } if (Debug>DBG_a) printf("hist_serv():: 2D loop\n"); //--- send 2D hist TIter next2(histptr->ALL_2D_HIST); while ((obj = next2())) { mess1.Reset(); icc++; const char *hh = obj->GetName(); if (Debug>DBG_h) { printf("hist_serv():: ICC=%d request=%s hname=%s hh=%s ",icc,cmd,hname,hh); obj->Print(); } if ( strncmp(cmd,"Update",6) && strcmp(hname,hh) ) continue; if (Debug>DBG_h) { printf("hist_serv():: SEND hist: request=%s hname=%s hh=%s ",cmd,hname,hh); } mess1.WriteObject(obj); // write object in message buffer int ret = sd->Send(mess1); if (ret<=0) { printf("hist_serv():: Error send, Close socket %lu \n",(long int)sd); sd->Close(); return NULL; } } //-- obj loop 2D hist } else if (!strncmp(cmd,"Finished",8)) { printf("hist_serv():: Client Finished \n"); printf("hist_serv():: Close socket %lu ic=%d \n",(long int)sd,ic); sd->Close(); return NULL; } } else if (mess->What() == kMESS_OBJECT) { printf("hist_serv():: !!!!!!!!!!!!!! got object of class: %s\n", mess->GetClass()->GetName()); TThread::Lock(); TH1 *h = (TH1 *)mess->ReadObject(mess->GetClass()); TThread::UnLock(); h->Print(); delete h; // delete histogram } else { printf("hist_serv():: *** Unexpected message ***\n"); } delete mess; int ret1 = sd->Send("END"); // tell clients we are finished if (ret1<=0) { printf("hist_serv():: Error send, Close socket %lu ret1=%d \n",(long int)sd,ret1); sd->Close(); return NULL; } } //--- while sig_int==0 printf("hist_serv()::===> EXIT hist_serv() client \n"); return NULL; } /*=====================================================================*/ void *hist_serv_thread(void* arg) { /*=====================================================================*/ const int MAX_CLNT=20; TSocket *sd, *soc[MAX_CLNT]={NULL}; TThread *th_hist=NULL; //--- better joint ??? =>array TServerSocket *ss; struct hist_param param; TThread::Printf(" New TThread --> hist_serv <-- Enter"); //appl->Run(); ignore_sigpipe(); while(!sig_int) { ss = new TServerSocket(32765, kTRUE); if (ss->IsValid()) break; printf("hist_serv_thread:: Error Open TServerSocket, err=%d\n", ss->GetErrorCode()); delete ss; sleep(5); } while (sig_int==0) { printf("hist_serv_thread:: ................ NEW wait ......\n"); sd = ss->Accept(); if (sd<=0) { printf("Error Accept sd=%lu, Close connection \n",(long int)sd); sd->Close(); continue; } printf("hist_serv_thread:: ................ NEW client ......\n"); int ifound=0; for (int ic=0;icIsValid()) { if (sd->Send("go 0")<=0) sd->Close(); else { ifound=1; param.ic=ic; param.sock=sd; soc[ic]=sd; //-- not used -- for count only printf("hist_serv_thread():: accept ic=%d \n",ic); //--- start new thread ---- th_hist = new TThread("hist_serv", hist_serv,¶m); th_hist->Run(); printf("New Thread hist_serv() started \n"); break; } } } if (!ifound) { printf("hist_serv_thread():: only accept %d clients connections !!\n",MAX_CLNT); sd->Send("Exceed the Number of Clients"); sd->Close(); } continue; } printf("===> EXIT hist_serv_thread() \n"); return NULL; } /*=====================================================================*/ /* */ /*=====================================================================*/ static void shmem_get() { /*---------------------------------------------------------------------*/ /* Shared memory */ /*---------------------------------------------------------------------*/ if ( (semid=semget( SEM_ID1, 1, 0) ) < 0 ) { printf("shmem_ROL_2: can not get semaphore \n"); fflush(stdout); } if ( (shmid=shmget(SHM_ID1,sizeof(roc_shmem), 0))<0) { printf("==> shmem_ROL_2: shared memory 0x%x, size=%d get error=%d\n",SHM_ID1,sizeof(roc_shmem),shmid); fflush(stdout); exit(1); } if ( (shmem_ptr=(roc_shmem *) shmat (shmid, 0, 0))<0 ) { printf("==> shmem_ROL_2: shared memory attach error\n"); fflush(stdout); } printf("==> shmem_ROL_2: shared memory attached OK ptr=%p\n",shmem_ptr); fflush(stdout); printf("===== ROL_2 wait semaphore ====== \n"); fflush(stdout); //--- add new shmem client here ----------- //-- access to shmem -- //sem_wait(semid); if (shmem_ptr) shmem_ptr->rol2_hist=1; //sem_post(semid); } //===================================================== // //=====================================================