// // gcc rates.c -I ../rcm/monitor/ -o rates.exe // ./rates.exe // // #include #include #include #include //-------------------------------------------- #include "shmem_roc.h" static void shmem_get(); static int semid,shmid; static roc_shmem *shmem_ptr; void get_rates (); //-------------------------------------------- int main(int argc,char ** argv) { int slot=0,fiber=-1; if (argc > 1) { slot=atoi(argv[1]); } if (argc > 2) { fiber=atoi(argv[2]); } shmem_get(); get_rates(slot,fiber); } //----------------------------------------------------------------------------------- // get rates //----------------------------------------------------------------------------------- void get_rates (int mslot, int mfiber) { int slot,ichan; unsigned int update_f_old=0, update_d_old=0, update_r_old=0; while(1) { //--------------------------------------------------------------------------------------------------- // DIRC rates //--------------------------------------------------------------------------------------------------- unsigned int update_r=shmem_ptr->dirc_scalers.update; if ( update_r != update_r_old) { printf("\n DIRC new loop.. update=%lu old=%lu\n",update_r,update_r_old); //---- for(slot=0; slot<21; slot++) { if (shmem_ptr->dirc_scalers.update==0) continue; if (mslot!=0 && mslot!=slot ) continue; printf("\n check slot=%d: time=%lu \n",slot,shmem_ptr->dirc_scalers.update); //printf(" Fill slot=%d \n",slot); printf("=============================================================== DIRC slot=%d \n",slot); int ndata = shmem_ptr->dirc_scalers.counters[slot][0]; int ic,ii=0; unsigned int length=shmem_ptr->dirc_scalers.counters[slot][ii++]; while(iidirc_scalers.counters[slot][ii++]; if (mfiber<0 || mfiber==fiber) printf("fiber=%d\n",fiber); 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 (ic=0; icdirc_scalers.counters[slot][ii]*scale,shmem_ptr->dirc_scalers.counters[slot][ii],scale); if (mfiber<0 || mfiber==fiber) printf("| %3d: %11.3f ",ic,shmem_ptr->dirc_scalers.counters[slot][ii]*scale); ii++; } if (mfiber<0 || mfiber==fiber) printf("\n--------------------------------- time %llu dt=%llu\n",shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN],shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN]-shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN-1]); } /* for(ichan=0; ichandirc_scalers.counters[slot][ichan]); } printf("\n timer: %u cnt. \n",shmem_ptr->dirc_scalers.counters[slot][DIRC_MAX_CHAN]); for(ichan=0; ichandirc_scalers.rates[slot][ichan]); } printf("\n timer: %.3f sec. \n",shmem_ptr->dirc_scalers.rates[slot][DIRC_MAX_CHAN]); */ //ndata = shmem_ptr->dirc_scalers.data[slot][0]; } update_r_old=update_r; //printf("\n Update: %lu us. , UI=%d TT=%d \n",update_r,sizeof(unsigned int), sizeof(time_t)); } //--------------------------------------------------------------------------------------------------- // FA250 rates //--------------------------------------------------------------------------------------------------- unsigned int update_f=shmem_ptr->f250_scalers.update; if ( update_f != update_f_old) { printf("\n FA250 new loop.. update=%lu old=%lu\n",update_f,update_f_old); //---- for(slot=0; slot<21; slot++) { if (shmem_ptr->f250_scalers.counters[slot][16]==0) continue; printf("\n check slot: update=%d time=%lu \n",slot,shmem_ptr->f250_scalers.counters[slot][16]); //printf(" Fill slot=%d \n",slot); printf("=============================================================== FADC slot=%d \n",slot); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %11.3f Hz ",ichan,shmem_ptr->f250_scalers.rates[slot][ichan]); } printf("\n timer: %.3f sec. \n",shmem_ptr->f250_scalers.rates[slot][16]); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %10u ",ichan,shmem_ptr->f250_scalers.counters[slot][ichan]); } printf("\n timer: %u 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)); } //--------------------------------------------------------------------------------------------------- // DISCR rates //--------------------------------------------------------------------------------------------------- unsigned int update_d=shmem_ptr->discr_scalers.update; if ( update_d != update_d_old) { //---- for(slot=0; slot<=21; slot++) { if (shmem_ptr->discr_scalers.counters[slot][16]==0) continue; if (mslot!=0 && mslot!=slot ) continue; printf("\n============== TDC ==================================== Fill DISCR slot=%d \n",slot); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %10.3f Hz ",ichan,shmem_ptr->discr_scalers.rates[slot][ichan]); } printf("\n timer: %.3f sec. \n",shmem_ptr->discr_scalers.rates[slot][16]); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %08d ",ichan,shmem_ptr->discr_scalers.counters[slot][ichan]); } printf("\n time: %lu us. \n",shmem_ptr->discr_scalers.counters[slot][16]); printf("\n--------------- TRG ------------------------------------ Fill DISCR slot=%d \n",slot); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %10.3f Hz ",ichan,shmem_ptr->discr_scalers.rates2[slot][ichan]); } printf("\n timer: %.3f sec. \n",shmem_ptr->discr_scalers.rates2[slot][16]); for(ichan=0; ichan<16; ichan++) { if( (ichan%4) == 0 ) printf("\n"); printf("| %2d: %08d ",ichan,shmem_ptr->discr_scalers.counters2[slot][ichan]); } printf("\n time: %lu us. \n",shmem_ptr->discr_scalers.counters2[slot][16]); } //--------------------------------------------------------------------------------------------------- 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)); } usleep(100); } } //----------------------------------------------------------------------------------- // Shared memory //----------------------------------------------------------------------------------- static void shmem_get() { if ( (semid=semget( SEM_ID1, 1, 0) ) < 0 ) { printf("shmem: can not get semaphore \n"); fflush(stdout); } if ( (shmid=shmget(SHM_ID1,sizeof(roc_shmem), 0))<0) { printf("==> shmem: 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: shared memory attach error\n"); fflush(stdout); } printf("==> shmem: shared memory attached OK ptr=%p\n",shmem_ptr); fflush(stdout); //printf("===== wait semaphore ====== \n"); //fflush(stdout); //-- access to shmem -- //sem_wait(semid); // if (shmem_ptr) shmem_ptr->rol2_hist=1; //sem_post(semid); } //-----------------------------------------------------------------------------------