/*---------------------- rc: 0:ok 1: at least on of the boards was not busy 10: >80mics between 1. and last stop */ int stop_ssm(int *boards) { w32 ssmstatus, seconds1,micseconds1, seconds2,micseconds2,diff; int nbs,ix,rc=0; ix=1; nbs= boards[2]; GetMicSec(&seconds1, &micseconds1); while(1) { int board; w32 boardoffset, busybit; if(ix>=nbs) ix=0; board= boards[ix]; boardoffset=BSP*ctpboards[board].dial; busybit=0x100; ssmstatus= vmer32(SSMstatus+boardoffset); if( (ssmstatus&busybit)==0 ) { printf("stopSSM: %d board not busy(SSMstatus:%x), no action\n", board, ssmstatus); rc=1; }; vmew32(SSMstop+boardoffset, DUMMYVAL); if(ix==0) break; ix++; }; GetMicSec(&seconds2, &micseconds2); if((diff=DiffSecUsec(seconds2, micseconds2, seconds1, micseconds1))>80) { rc=10; printf("startSSM: diff[usecs]=%d last SSMstatus before stop:%x\n", diff, ssmstatus); }; //printf("stop_ssm: diff:%dus\n", diff); return(rc); }
/*FGROUP SimpleTests send L1h word ower B channel. data: 12bits data words: numbe of words to be send as quickly as possible MAXW: number of words to be send in one batch (after batch is sent, the loop testing TTC_STATUS for empty fifo is started) FIFO capacity is 128 words. */ void sendB(w32 data, int words, int MAXW) { //#define MAXW 120 int ix, wordssent=0; // L1h:1 L1data:2 L2ah:3 L2adata:4 L2r:5 RoIh:6 RoIdata:7 FEEreset:8 w32 Command=1; w32 fn=0, mics1,mics2,secs1,secs2,udif; float rate; GetMicSec(&secs1, &mics1); for(ix=0; ix<words; ix++) { w32 dawo; if((ix%MAXW)==0) { int ix2; // wait for empty fifo: for(ix2=0; ix2<1000; ix2++) { dawo= vmer32(TTC_STATUS); //if(dawo&2) { // TTC FIFO full if(dawo&1) { // TTC FIFO empty fn++; goto FEMPTY; }; }; printf("Timeout when waiting for empty fifo\n"); goto STOP; }; FEMPTY: dawo= 0x80010000 | data | ((Command&0xf)<<12); vmew32(TTC_DATA, dawo); wordssent++; }; STOP: GetMicSec(&secs2, &mics2); udif= DiffSecUsec(secs2,mics2,secs1,mics1); rate= 1.*wordssent/udif; //printf("TTCfifo full: %d times\n", fn); printf("loops when waiting for empty FIFO: %d times\n", fn); printf("wordssent:%d udif:%d rate[/usec]:%f\n", wordssent, udif, rate); }
//-------------------------------------------------------------------------- // startssm normal order, only CTP boards //------------------------------------------------------------------------- int startSSMnor(int n,int *boards){ int i,board,rc=0; w32 boardoffset, seconds1,micseconds1, seconds2,micseconds2,diff; w32 status; GetMicSec(&seconds1, &micseconds1); for(i=0;i<n;i++){ board= boards[i]; boardoffset=BSP*ctpboards[board].dial; vmew32(SSMaddress+boardoffset,0); /* micwait(30); */ status= vmer32(SSMstatus+boardoffset); vmew32(SSMstart+boardoffset, DUMMYVAL); }; GetMicSec(&seconds2, &micseconds2); if((diff=DiffSecUsec(seconds2, micseconds2, seconds1, micseconds1))>80) { rc=10; printf("startSSM: diff[usecs]=%d SSMstatus before start:%x\n",diff, status); }; return(rc); }
/*FGROUP SMAQ - Snapshot Memory Aquisition intboard - if 0 : do not take int board 1 : take int board and trigger on l0 input board 2 : take int board and trigger on l0int1 counters 3 : take int board and trigger on l0int2 counters inpnum - inpnumber on l0 level to trigger on: 1..48 on l1 level to trigger on:51..74 101..148 -take 2 ssms triggering on 1..48 input of L0 151..174 -take 2 ssms triggering on 1..24 input of L1 0: trigger on LHCpp (BOBR card in the CTP crate) rc: 0: ok 1: cannot open BOBR vme 2. input not onnected (LM0) 3: cannot stop SSM Output: - log file - contains also BC of interaction records - l0 ssm dump */ int inputsSMAQ(int intboard ,int inpnum012){ //w32 L0counts[MAXCOUNTERS]; w32 last[MAXCOUNTERS]; w32 l0first[MAXCOUNTERS]; int counteroffset,countermax; int trigboard; // with this board we trigger 1:L0 2:L1 3:L2 int boards[3]; w32 timeadr; int i,timeold,time; int inpnum, inpnum_ix; // triggering on this input, rel. position in board counts double timediff; int trigold,trigcur; int vspbobr; int trigcond,beepcond; Tlhcpp lhcpp; FILE *flog=NULL; char *environ; char fnpath[1024],logname[1024]; char dt[32]; int nottriggered=0; w32 timebefore; // Open the log file getdatetime(dt); dt[10]='_'; environ= getenv("VMEWORKDIR"); strcpy(fnpath, environ); strcat(fnpath,"/WORK/"); sprintf(logname,"%ssmaq_%s.log",fnpath,dt); /* flog=fopen(logname,"w"); if(flog==NULL){ printf("Cannot open file %s \n",logname); return 1; }*/ printf("Log file %s not opened, using stdout.\n",logname); // Check the site (ALICE or else) environ= getenv("SMAQ_C"); if(environ!=0) {strcpy(SMAQ_C, environ);}; // initCorrel(); // boards[2]= 1; // 1 board only if(inpnum012>100) { // we want l0+l1(l2) snapshot boards[2]= 2; // 2 boards boards[0]= 2; boards[1]= 1; // start order: l0, l1 inpnum012= inpnum012-100; }; // boards[2]: # of boards inpnum012:1..48 or 51..74 if(inpnum012>50) { // trigger: L1 inpnum= inpnum012-50; trigboard=2; boards[0]= trigboard; timeadr=L1OFFSET; counteroffset= L1OFFSET; // inps start just after time inpnum_ix= counteroffset + inpnum; } else { // trigger: L0 int swin; inpnum= inpnum012; trigboard=1; timeadr=L0TIMEOFFSET; counteroffset=L0OFFSET; swin= getSwnDB(inpnum); if(swin== -1) return(2); inpnum_ix= counteroffset + swin; printf("input %d is connected to CTP switch counter l0inp%d\n", inpnum,swin); }; countermax=counteroffset+NINP+6; // 6 for int counters if(boards[2]== 1 ) { boards[0]= trigboard; printf("triggering with L%d inp%d/%d max:%d. Readout board: L%d\n", trigboard-1, inpnum, counteroffset, countermax, boards[0]-1); } else { printf("triggering with L%d inp%d/%d max:%d. Readout boards: L%d L%d\n", trigboard-1, inpnum, counteroffset, countermax, boards[0]-1, boards[1]-1); }; /* now boards[2]: number of boards to be readout 2: boards[0..1] is l1+l0 1: boards[0] is l1 or l0 */ initNames(trigboard); if(intboard == 2){ // trigger on int1 // set also lut table inpnum=27; } else if(intboard == 3){ // trigger on int 2 inpnum=28; } /* inpnum: CTP input number (1..24), or special: 27,28: trigger on int1,2 (to be checked) inpnum_ix -rel. address in counter's array */ getCountersBoard(trigboard,counteroffset + NINP,l0first,3); for(i=0;i<NINP;i++){ int ic; ic= counteroffset+i+1; firstRead[i]=l0first[ic]; prevRead[i]=l0first[ic]; prevtime= l0first[L0TIMEOFFSET]; } // open bobr vmespace if(inpnum==0) { if((vspbobr=bobrOpen()) == -1){ printf("Cannot open bobr vme space\n"); return 1; } else { int rc; rc= getlhcpp(vspbobr,1,0, &lhcpp); // get next BST message if(rc!=0) { printf("rc:%d from getlhcpp()\n",rc); exit(8); }; }; }; // 1st readings getCountersBoard(trigboard,countermax,last,3); timeold=last[timeadr]; timebefore= timeold; if(inpnum)trigold=last[inpnum_ix]; //counting from 1 else beepcond= (((lhcpp.Byte54)&0x1) != 0); setstart_ssm(boards); /* if(intboard){ setomSSM(4,0x3);startSSM1(4); // OUT, continuous initprintBCs(); } usleep(100000); */ while(1){ int rc; w32 ts1,ts2,us1,us2, cntr_us; if(inpnum==0) { // we trigger on lhcpp rc= getlhcpp(vspbobr,1, PP_PERIOD, &lhcpp); if(rc!=0) { printf("No LHCpp after %d secs. getlhcpp() rc:%d\n", PP_PERIOD, rc); trigcond=0; } else { trigcond=1; }; } else { // we trigger on CTP inputs counter change GetMicSec(&ts1, &us1); getCountersBoard(trigboard,countermax,last,3); //GetMicSec(&ts2, &us2); when here, we do not see signal we // are triggering on! Got better when moved down (trigcond fulfilled) time=last[timeadr]; trigcur=last[inpnum_ix]; trigcond= (trigcur != trigold); //printf("trigcond:%d %d %d trigcur:%u time:%u\n", trigcond, trigboard, countermax,trigcur, time); }; if(trigcond){ int rc; w32 trigdif; double td; char msg[200]; rc= stop_ssm(boards); if(rc== 10) { sprintf(msg, "cannot stop ssm(s)"); prtLog(msg); return(3); }; if(intboard)stopSSM(4); //beepni(); cicolino not used recently GetMicSec(&ts2, &us2); rc= getSSMs(boards, trigboard, inpnum,intboard,flog); trigdif= dodif32(trigold,trigcur); td= getTime(timebefore, time); timebefore= time; cntr_us= DiffSecUsec(ts2,us2,ts1,us1); /*sprintf(msg, "inpnum:%d empty loops:%d old: %u new: %u td:%9.2f ms", inpnum,nottriggered,trigold,trigcur, td); prtLog(msg);*/ printf("trigdif:0x%x 0x%x %d inpnum_ix:%d\n", trigold, trigcur, trigdif, inpnum_ix); sprintf(msg, "empty loops:%d td:%9.2f ms getSSMs rc:%d cnts reading %d us", nottriggered, td, rc, cntr_us); prtLog(msg); nottriggered= 0; setstart_ssm(boards); // following should be after start -better to throw out rare signal and wait for other than // to take empty ssm getCountersBoard(trigboard,countermax,last,3); time=last[timeadr]; trigcur=last[inpnum_ix]; trigold=trigcur; if(rc!=0) { break; }; } else { nottriggered++; }; if(quit!=0) { int rc; // the request 'stop smaqing' registered (signal -s SIGUSR1 pid), let's stop: rc= stop_ssm(boards); printf("quitting on signal:%d stop_ssm rc:%d\n", quit, rc); break; }; //usleep(200000); // was 200 at the start of Aug (can be much more for 1bobr/48 secs) timediff=getTime(timeold,time); //printf("time: old %u new %u diff %f\n",timeold,time,timediff); if(timediff>100000){ // 10**5 == 100secs //char dt[32]; //smaqprintCounters(trigboard,L0counts, inpnum, f); getdatetime(dt); dt[10]='_'; printf("time: diff %f %s\n",timediff,dt); timeold=time; }; } if(inpnum==0) bobrClose(vspbobr); //fclose(flog); return 0; }
/*------------------------*/ w32 diffnowbefore(Ttime *now, Ttime *before) { w32 dif; dif= DiffSecUsec(now->secs, now->usecs, before->secs, before->usecs); return(dif); }