Exemple #1
0
/*FGROUP ALItools
---------------------------------------------------------------------------------------
Record and read and synchronise 2 SSMs
*/
int take2SSM(int board1,int board2,int ntimes){
 int boards[2];
 int i,dontcare;
 int rare,counter;
 int chan01,chanM1,level1;
 int chan02,chanM2,level2;
 w32 offset;

 rare = (board1 == RareFlag.board) || (board2 == RareFlag.board);
 if(board2 == RareFlag.board){  // board1 assumed to have flag
   int board = board2;
   board2=board1;
   board1=board;
 }
 printf("take2SSM: rare= %i\n",rare);
  if(rare){
   counter=findcounter(RareFlag.board,RareFlag.mode,RareFlag.input);
   if(counter == 0){
    printf("take2SSM: Unknown input: %i \n",RareFlag.input);
    return 1;
   }
   setomSSM(board1,0xb);
   setomSSM(board2,0xb);
 }else{
   setomSSM(board1,0xa);
   setomSSM(board2,0xa);
 }

 board2pars(board1,&chan01,&chanM1,&level1);
 board2pars(board2,&chan02,&chanM2,&level2);
 boards[0]=board1;
 boards[1]=board2;
 
 // board2 starts first
 for(i=0;i<ntimes;i++){
   if(startSSMnor(2,boards)){
    printf("startSSM error: SSMs have not started inside one ORBIT. Sync not possible \n");
   }
   usleep(40000);
  if(rare){
    condstopSSM(board1,counter,100,10000,4);
    stopSSM(board2);
  }else{
    stopSSM(board1);
    stopSSM(board2);
  }
   readSSM(board1);
   readSSM(board2);
   IDread++;
   dontcare= syncSSM(2,boards);
   printf("offsets: %i %i\n",sms[board1].offset,sms[board2].offset);
   offset=sms[1].offset-sms[2].offset;
   add2SSM0(sms[board1].sm,chan01,chanM1,level1,0);   
   add2SSM0(sms[board2].sm,chan02,chanM2,level2,offset);   
 }
 return 0;
}
Exemple #2
0
/*FGROUP ALItools
----------------------------------------------------------------------------
Record and read 1SSM
*/
void takerbSSM(int ntimes){
 int i,chan0=0,chanM=31,level=24;
 int rare,counter;
 int board=1;
 rare = (board == RareFlag.board) && (RareFlag.mode == 1);
 if(rare){
   counter=findcounter(RareFlag.board,RareFlag.mode,RareFlag.input);
   if(counter == 0){
    printf("take1SSM: Unknown input: %i \n",RareFlag.input);
    return;
   }
   setomSSM(board,0x3);
 }else setomSSM(board,0x2);
 for(i=0;i<ntimes;i++){   
  startSSM1(board);
  usleep(30000);
  if(rare){
    condstopSSM(board,counter,5000,13000,ccread_inputs);
  }else{
   stopSSM(board);
  }
  readSSM(board);
  IDread++;
  //filter(sms[board].sm,25);
  add2SSM0(sms[board].sm,chan0,chanM,level,0);
 }
}
Exemple #3
0
/*FGROUP ALItools
------------------------------------------------------------------------------
Record and read 1SSM
*/
void take1SSM(int board,int ntimes){
 int i,chan0,chanM,level,rare,counter;
 rare = (board == RareFlag.board) && (RareFlag.mode == 0);
 board2pars(board,&chan0,&chanM,&level);
 if(rare){
   counter=findcounter(RareFlag.board,RareFlag.mode,RareFlag.input);
   if(counter == 0){
    printf("take1SSM: Unknown input: %i \n",RareFlag.input);
    return;
   }
   setomSSM(board,0xb);
 }
 else setomSSM(board,0xa); //before after
 printf("take1SSM: rare,board,counter: %i %i %i\n",rare,board,counter);
 for(i=0;i<ntimes;i++){   
  startSSM1(board);
  usleep(30000);
  if(rare){
    printf("take1SSM:  2 rare,board,counter: %i %i %i ",rare,board,counter);
    condstopSSM(board,counter,100,10000,ccread_inputs);
    printf(" finished succesfuly \n");
  }else{
    stopSSM(board);
  }
  readSSM(board);
  IDread++;
  add2SSM0(sms[board].sm,chan0,chanM,level,0);
 }
}
Exemple #4
0
/*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;
}