Esempio n. 1
0
/*-----------------*/ void DLL_RESYNCcmd(void *tag, void *msgv, int *size)  {
char errmsg[200];
char *msg= (char *)msgv; int rc; 
sprintf(errmsg, "DLL_RESYNCcmd: tag:%d size:%d msg:%5.5s\n", 
  *(int *)tag, *size, msg); prtLog(errmsg); 
rc= authenticate("");
//rc=0;
if(rc!=0) {
  //sprintf(errmsg, "DLL_RESYNC not authenticated, but executed");prtLog(errmsg); 
  char clientid[100];
  getclientid(clientid);
  sprintf(errmsg, "DLL_RESYNC not allowed from client %s", clientid);prtLog(errmsg); 
};

checkstartthread(0);
/*
if(clocktran!=0)  {
  sprintf(errmsg, "newclock thread already started. Trigger expert should restart ttcmidim and miclock client!"); prtLog(errmsg); 
  infolog_trgboth(LOG_FATAL, errmsg);
  return;  
};
clocktran=3; strcpy(clocktransition,"3"); newclocktag=0; GetMicSec(&clocktran_s, &clocktran_u);
sprintf(errmsg, "newclock thread DLL_RESYNC starting. tag:%d \n", newclocktag); prtLog(errmsg); 
dim_start_thread(newclock, (void *)&newclocktag);
*/
}
Esempio n. 2
0
/*---------------------------------------------*/ void gotsignal(int signum) {
char msg[100];
// SIGUSR1:  // kill -s USR1 pid
signal(signum, gotsignal); siginterrupt(signum, 0);
sprintf(msg, "got signal:%d", signum); prtLog(msg);
if((signum==SIGUSR1) || (signum==SIGQUIT) ) {
  int np;
  np= getNAllPartitions();
  if(np!=0) {
    //quit=1; // wait till all partitions stopped
    //sprintf(msg, "Waiting for the stop of all partitions before exit");
    sprintf(msg, "Unsuccessful attempt to stop ctpproxy, %d partitions active", np);
    prtLog(msg);
    pq_send(mq_sendmsg,"quitignored");
  } else {
    quit=10;  // stop immediately (no partitions loaded)
  };
} else if((signum==SIGKILL) || (signum==SIGINT) ) {
    sprintf(msg, "SIGINT, immediate stop"); prtLog(msg);
  quit=11; // =9. stop immediately
};
#ifdef PQWAY
if(quit>9) {
  pq_send(mq_sendmsg,"quit");
};
#endif
}
Esempio n. 3
0
void gotsignal(int signum) {
char msg[100];
switch(signum) {
case SIGUSR1:  // kill -s USR1 pid
  signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
  sprintf(msg, "got SIGUSR1 signal:%d, fflush(stdout)\n", signum);
  prtLog(msg);
  //fflush(stdout);
  break;
case SIGINT:
  signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);
  printf("got SIGINT signal, quitting...:%d\n", signum);
  quit=signum;
  break;
case SIGQUIT:
  signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
  printf("got SIGQUIT signal, quitting...:%d\n", signum);
  quit=signum;
  break;
case SIGBUS: 
  //vmeish(); not to be called (if called, it kills dims process)
  sprintf(msg, "got SIGBUS signal:%d\n", signum); prtLog(msg);
  break; 
default:
  printf("got unknown signal:%d\n", signum);
};
}
Esempio n. 4
0
/*-----------------*/ void checkstartthread(int clocktag) {
char errmsg[200];
if(clocktran!=0)  {
  /* run1 way:
  sprintf(errmsg, "MICLOCK_SET: newclock thread already started! exiting..."); prtLog(errmsg); 
  quit=1;   // better quit, and restart (monitor.py should be active !)
   * run2: 
  - ignore a command setting new clock, if pevious one no finished yet 
  - restart myself if stucked too long in thread */
  if(clocktran_s!=0) {          
    w32 diff_s, diff_u;
    DiffSecUsecFrom(clocktran_s, clocktran_u, &diff_s, &diff_u);
    if(diff_s > (w32) (SLOT_S*5)) {
      sprintf(errmsg, "newclock thread stucked (%d secs). Trigger expert should restart ttcmidim and miclock client!", diff_s); prtLog(errmsg); 
      infolog_trgboth(LOG_FATAL, errmsg);
    } else {
      sprintf(errmsg, "checkstartthread tag:%d: newclock thread already started %d secs, cmd ignored...",
        clocktag, diff_s); prtLog(errmsg); 
    };
    return;  
  };
};
clocktran=3; strcpy(clocktransition,"3"); GetMicSec(&clocktran_s, &clocktran_u);
newclocktag= clocktag;
sprintf(errmsg, "newclock thread starting. tag:%d \n", newclocktag); prtLog(errmsg); 
dim_start_thread(newclock, (void *)&newclocktag);
}
Esempio n. 5
0
int update_qpll() {
int rc,rcret=0; w32 stat; 
//int mainerr,mainlck,bc1err,bc1lck; char buffer[50];
if(envcmp("VMESITE", "ALICE")==0) {
  if(micratepresent()& 0x2) {
    stat= readstatus();
  } else { stat=0xfff; };
  // update freqs:
  if(micratepresent()& 0x1) {
    getRFRX(vspRFRX[0], rfrx1); getRFRX(vspRFRX[1], rfrx2);
    freqs[0]= rfrx1[2].freq; freqs[1]= rfrx2[2].freq;
    freqs[2]= rfrx1[1].freq; freqs[3]= rfrx2[1].freq;
  };
  //printf("ref bc1 orbit1\n"); printf("--- bc2 orbit2\n");
} else {
  /* simulate change:
  stat= qpllstat+1;
  rfrx1[2].freq= rfrx1[2].freq + 1;
  rfrx2[2].freq= rfrx2[2].freq + 1;
  rfrx1[1].freq= rfrx1[1].freq + 10;
  rfrx2[1].freq= rfrx2[1].freq + 10; */
  ;  // do not change
};
if((freqs[0] != rfrx1[2].freq) ||
   (freqs[1] != rfrx2[2].freq) ||
   (freqs[3] != rfrx1[1].freq) ||
   (freqs[4] != rfrx2[1].freq)
) {
  rc= dis_update_service(FREQSid);
};
//stat=qpllstat+1; //simulate change
if(stat != qpllstat) {
  char msg[100];
  qpllstat= stat;
  sprintf(qpllnow,"%3.3x", qpllstat);
  rc= dis_update_service(QPLLid);
  if((stat | REF_MASK) != (qpllstat | REF_MASK)) {
    sprintf(msg, "QPLL update (ref ignored here) rc:%d qpllstat:0x%x",
      rc,qpllstat);
    prtLog(msg);
  };
  /*
  mainerr= (qpllstat & 0x2)>>1; mainlck= (qpllstat & 0x1);
  bc1err= (qpllstat & 0x80)>>7; bc1lck= (qpllstat & 0x40)>>6;
  sprintf(buffer, "mon ds006:ds007:ds008:ds009 N:%d:%d:%d:%d", 
    mainerr, mainlck, bc1err, bc1lck);
  rc= udpsend(udpsock, (unsigned char *)buffer, strlen(buffer)+1);
  prtLog(buffer); */
};
nlogqpll++;
if((nlogqpll % 36000)==0) {    // 3600:log 1 per 2 hours
  char msg[100];
  sprintf(msg, "qpllstat%d:0x%x", nlogqpll, qpllstat);
  prtLog(msg);
};
if(quit!=0) rcret=10;
return(rcret);
}
Esempio n. 6
0
/*--------------------------------------------------------------- error_handler
A severity code: 0 - info, 1 - warning, 2 - error, 3 - fatal.
*/
void error_handler(int severity, int error_code, char *message) {
char msg1[100];
const char *sev[5]={"info", "warning", "error", "fatal", "???"};
if((severity<0) || (severity>3)) {
  severity=4;
};
sprintf(msg1,"*** DIM %s: %d", sev[severity], error_code);
prtLog(msg1); prtLog(message);
}
Esempio n. 7
0
----------------------------------------*/ void read_gcalibcfg() {
FILE* gcalcfg;
enum Ttokentype token;
char line[MAXLINELENGTH], value[MAXCTPINPUTLENGTH];
char em1[200]="";
gcalcfg= openFile("gcalib.cfg","r");
if(gcalcfg==NULL) {
  prtLog("gcalib cannot be read. Using defaults");
  return;
};
while(fgets(line, MAXLINELENGTH, gcalcfg)){
  int ix,det,milsec, roc,log;
  roc=0; log=0;
  //printf("Decoding line:%s ",line);
  if(line[0]=='#') continue;
  if(line[0]=='\n') continue;
  ix=0; token= nxtoken(line, value, &ix);
  if(token==tSYMNAME) {
    char ltuname[20];
    strcpy(ltuname, value);
    det= findLTUdetnum(ltuname);
    if(det<0) {
      strcpy(em1,"bad LTU name in gcalib.cfg"); goto ERR; 
    };
    token=nxtoken(line, value, &ix);
    if(token==tINTNUM) {         // period in ms
      milsec= str2int(value);
    } else {strcpy(em1,"bad period (integer expected ms) in gcalib.cfg"); goto ERR; };
    ACTIVEDETS[det].periodms= milsec;
    token=nxtoken(line, value, &ix);
    if(token==tINTNUM) {         // roc (decimal)
      roc= str2int(value);
    } else if(token != tEOCMD) {
      strcpy(em1,"bad ROC (0-7 expected) in gcalib.cfg"); goto ERR;
    };
    token=nxtoken(line, value, &ix);
    if(token==tSYMNAME) {
      if(value[0]=='y') {
        log= 1;
      } else if(value[0]=='n') {
        log= 0;
      } else {
        sprintf(em1,"bad LOG option %s (y or n expected) in gcalib.cfg", value); goto ERR;
      }
    } else if((token != tEOCMD) && (token!=tCROSS)) {
      sprintf(em1,"bad LOG option  %s(y or n expected) in gcalib.cfg", value); goto ERR;
    };
    ACTIVEDETS[det].logroc= (log<<4) | roc;
    sprintf(em1,"gcalib.cfg:%s %dms 0x%x", ACTIVEDETS[det].name, ACTIVEDETS[det].periodms,
      ACTIVEDETS[det].logroc);
    prtLog(em1); em1[0]='\0';
  } else {strcpy(em1,"LTU name expected"); goto ERR; };
};
ERR: 
fclose(gcalcfg); if(em1[0]!='\0') prtLog(em1); return;
};
Esempio n. 8
0
void startThread() {
dim_start_thread(calthread, (void *)&TAGcalthread);
usleep(100000);
if(threadactive==0) {
  char msg[200];
  sprintf(msg,"thread not started! exiting..."); prtLog(msg);
  //exit(8);
  quit=8;
};
/*
if(detectfile("gcalrestart", 0) >=0) {   //debug: simulate error by file presence
  // i.e.: echo blabla >$VMEWORKDIR/gcalrestart
  char msg[200];
  //system("gcalibrestart_at.sh >/tmp/gcalibresatrt_at.log");
  system("rm gcalrestart");
  sprintf(msg,"gcalrestart removed, registered, exiting..."); prtLog(msg);
  //exit(8);
  quit=8; 
}else {
  char msg[200];
  //system("gcalibrestart_at.sh");
  sprintf(msg,"WORK/../gcalrestart not present (i.e. real crash, not simulated)"); prtLog(msg);
};
*/
}
Esempio n. 9
0
/*-----------------*/ void CORDE_SETcmd(void *tag, void *msgv, int *size)  {
char errmsg[200];
char *msg= (char *)msgv; int rc; w32 cosh;
char sshift[20]; int shift=0, origshift; 
if(*size>19) {rc=19;}
else {rc=*size; };
strncpy(sshift,msg,rc); sshift[rc]='\0';
errno= 0;
shift= strtol(sshift, (char **)NULL, 10);
if ((errno == ERANGE && (shift == LONG_MAX || shift == LONG_MIN))
     || (errno != 0 && shift == 0)) {
  sprintf(errmsg, "Error: incorrect shift:%s, not set", sshift); prtLog(errmsg); 
  return;  
};
sprintf(errmsg, "CORDE_SETcmd: size:%d msg:%5.5s :%s:%d\n", 
  *size, msg, sshift, shift); prtLog(errmsg); 
rc= authenticate("");
//rc=0; //prtLog("CORDE_SET not authenticated!\n");
if(rc!=0) {
  sprintf(errmsg, "CORDE shift forbidden\n"); prtLog(errmsg); 
  return;  
};
if(shift==0) {
  sprintf(errmsg, "Error: Bad shift:%s, not set", sshift); prtLog(errmsg); 
  return;  
};
cosh= corde_shift(CORDE_DELREG, shift, &origshift);
//sprintf(errmsg, "corde_shift(,%d, %d)", shift, origshift); prtLog(errmsg); 
if(cosh>1023) {
  sprintf(errmsg, "Error: Corde reg. not set, corde_shift rc:0x%x\n", cosh); prtLog(errmsg); 
} else {
  w32 pol,halfns; char line[80];
  // always, after shift resynchronize DLL on RF2TTC:
  // not here (called from miclock):
  //DLL_RESYNC(0);
  sprintf(errmsg, "corde_shift(%x, %d, ) orig:%d set to:%d.",
    CORDE_DELREG, shift, origshift, cosh); 
  prtLog(errmsg); 
  sprintf(errmsg,"CORDE shift: %d -> %d ps",origshift*10, cosh*10);
  infolog_trg(LOG_INFO, errmsg);
  // update $dbctp/clockshift,  daqlogbook and SHIFTid service:
  // not done here (can we use DIM client library here?), but in miclock.py
  // which is not correct (it can get unsync!)
  //rc= dic_cmnd_callback("CTPRCFG/RCFG", message, strlen(message)+1, callback, 33);
  rc= dis_update_service(SHIFTid);
  sprintf(errmsg,"TTCMI/SHIFT updated for %d clients\n", rc); prtLog(errmsg); 
  pol= i2cread_delay(BC_DELAY25_BCMAIN); halfns= pol-0x140;
  // update $dbctp/clockshift
  // run1 last values (12.2.201): 29 973 960
  sprintf(line, "%d %d %d", halfns, cosh, origshift);
  writedbfile((char *)"/home/alice/trigger/v/vme/CFG/clockshift", line);
  shiftCommentInDAQ((int)halfns, origshift, 
    (int)halfns, (int)cosh,"fine");
  sprintf(errmsg,"DAQlogbook updated (rc:void).Corde: %d -> %d\n",
    origshift, cosh);prtLog(errmsg); 
};
}
Esempio n. 10
0
/*----------------------------------------------------------- SHIFTcaba
*/
void SHIFTcaba(void *tag, void **msgpv, int *size, int *blabla) {
char **msgp= (char **)msgpv;
char msg[100];
// readVME:
getshiftnow();
*msgp= shiftnow;
*size= strlen(shiftnow)+1;
sprintf(msg, "SHIFTcaba shiftnow:%s size:%d", shiftnow, *size); prtLog(msg); 
}
Esempio n. 11
0
/*------------------------------------------------------------- infolog()
severity: LOG_INFO, LOG_ERROR, LOG_FATAL  from 22.3.2012: LOG_WARNING, LOG_DEBUG
msg: message (no \n at the end!)
Note:
SYSTEM: see infoLoggerStandalone.sh: DATE_INFOLOGGER_SYSTEM=TRG
FACILITY: set once in:
    ltu_proxy/main(), dummy_ctp.c/main() ttcmi/ttcmi.c:
        infolog_SetFacility("ltu_DETNAME")
STREAM: set in ltu_utils Setglobalmode/Setstdalonemode
        infoSetStream(PARTIITON_NAME/dimservername);

In CERNLAB the following should be started to setup environment:
. /opt/infoLogger/infoLoggerStandalone.sh
*/
void ctplog(char severity, char *msg) {
if((severity==LOG_ERROR) || (severity==LOG_FATAL)) {
  prtError(msg);
} else if(severity==LOG_INFO) {
  prtLog(msg);
} else {
  prtWarning(msg);
};
}
Esempio n. 12
0
/*---------------------------------------------*/ void gotsignal(int signum) {
char msg[100];
// SIGUSR1:  // kill -s USR1 pid
signal(signum, gotsignal); siginterrupt(signum, 0);
sprintf(msg, "got signal:%d", signum); prtLog(msg);
if((signum==SIGUSR1) || (signum==SIGKILL) ) {
  quit=1;
};quit=signum;  // for ANY signal
}
Esempio n. 13
0
/*----------------------------------------------------------- MICLOCKcaba
*/
void MICLOCKcaba(void *tag, void **msgpv, int *size, int *blabla) {
char **msgp= (char **)msgpv; int rc;
char msg[100], clientid[100];
// readVME:
getclocknow();
rc= getclientid(clientid);
*msgp= clocknow;
*size= strlen(clocknow)+1;
sprintf(msg, "MICLOCKcaba clocknow:%s size:%d clientid:%s rc:%d",
  clocknow, *size, clientid, rc); prtLog(msg); 
}
Esempio n. 14
0
/*-----------------*/ void MICLOCK_SETcmd(void *tag, void *msgv, int *size)  {
char errmsg[200];
char msg[80]; int rc,rc2=0; int nwclocktag, msglen;
sprintf(errmsg, "MICLOCK_SETcmd: tag:%d size:%d msg:%5.5s", 
  *(int *)tag, *size, (char *)msgv); prtLog(errmsg); 
/* pydim client: msg not finished by 0x0 ! -that's why strncmp() used below...

if(*size >=2) {
msg[*size]='\0';   // with python client ok
//if(msg[*size-2]=='\n') { msg[*size-2]='\0'; } else { msg[*size-1]='\0'; };
};
*/
msglen= *size;
strncpy(msg, (char *)msgv, msglen); msg[msglen]='\0';
rc= authenticate(""); rc2=1; //rc2= authenticate("oerjan/");
//rc=0;
if((rc!=0) and (rc2!=0) ) {
  //sprintf(errmsg, "Only trigger/oerjan user can change the clock"); prtLog(errmsg); 
  sprintf(errmsg, "Only alidcscom779 can request the change of the clock"); prtLog(errmsg); 
  return;  
};
if(strncmp(msg,"qq", 2)==0) ds_stop();
if(strncmp(msg,"BEAM1", 5)==0) { nwclocktag=1;
} else if(strncmp(msg,"BEAM2", 5)==0) { nwclocktag=2;
} else if(strncmp(msg,"REF", 3)==0) { nwclocktag=3;
} else if(strncmp(msg,"LOCAL", 5)==0) { nwclocktag=4;
} else { 
  sprintf(errmsg, "bad clock request:%s ignored.\n", msg); infolog_trgboth(LOG_ERROR, errmsg); 
  return; 
};
strcpy(lastmsg,msg);
getclocknow();
if(clocktag==nwclocktag) {
  sprintf(errmsg, "clock request:%s ignored (already set).\n", msg); infolog_trgboth(LOG_ERROR, errmsg); 
  return; 
};
sprintf(errmsg, "ALICE clock change to %s starting...\n", msg); infolog_trgboth(LOG_WARNING, errmsg); 
checkstartthread(nwclocktag);
}
Esempio n. 15
0
void printDET1(int ix) {
char active[20]; char msg[200];
if(ACTIVEDETS[ix].deta!=-1) {
  strcpy(active,"ACTIVE");
} else {
  strcpy(active,"NOT ACTIVE");
};
sprintf(msg, "%2d: %s %s. rate:%d ms. logroc:0x%x fileix:%d attempts/sent:%d/%d", 
  ix,ACTIVEDETS[ix].name, active, ACTIVEDETS[ix].periodms, 
  ACTIVEDETS[ix].logroc, ACTIVEDETS[ix].fileix,
  ACTIVEDETS[ix].attempts, ACTIVEDETS[ix].sent); 
prtLog(msg);
}
Esempio n. 16
0
/*int DataFiles::open_df(w32 runn) {
}*/
void DataFiles::close_df(int ixdet) {
FILE *fd; int ix,ixin; char msg[80];
ixin= ACTIVEDETS[ixdet].fileix;
if(ixin== -1) {
  printf("close_df: det:%d pointing to closed file (-1).\n", ixdet);
  return;
};
fd= DATAFILES[ixin].dataf;
if(DATAFILES[ixin].runn == 0) {
  printf("close_df: det:%d already closed.\n", ixdet);
  return;
};
sprintf(msg, "close_df: closing det:%d", ixdet); prtLog(msg);
fclose(fd);
DATAFILES[ixin].dataf= 0;
DATAFILES[ixin].runn= 0;
ix= ffala-1;
while(1) {
  if(DATAFILES[ix].runn==0) ffala= ix;
  if(ix==0) break;
  ix--;
};
}
Esempio n. 17
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;
}
Esempio n. 18
0
/*------------------------------------*/ int main(int argc, char **argv)  {
int rc,ads,ix; char msg[100];
/*
if(argc<3) {
  printf("Usage: ltuserver LTU_name base\n\
where LTU_name is detector name\n\
      base is the base address of LTU (e.g. 0x811000)\n\
"); exit(8);
}; 
if(argc>1) {
  if(strcmp(argv[1],"no1min")==0) {
    dimsflags=dimsflags | NO1MINFLAG;
  };
};*/
setlinebuf(stdout);
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);
signal(SIGBUS, gotsignal); siginterrupt(SIGBUS, 0);
sprintf(msg, "gcalib starting, ver 2 %s %s...", __DATE__, __TIME__);
prtLog(msg);
rc= vmeopen("0x820000", "0xd000");
if(rc!=0) {
  printf("vmeopen CTP vme:%d\n", rc); exit(8);
};
cshmInit();
unlockBakery(&ctpshmbase->swtriggers,swtriggers_gcalib);

initDET(); // has to be after cshmInit()
DFS= new DataFiles();
checkCTP(); 
printf("No initCTP. initCTP left to be done by main ctp-proxy when started\n"); 
//initCTP();
registerDIM();
beammode= get_DIMW32("CTPDIM/BEAMMODE");  //cannot be used inside callback
ads= shmupdateDETs();  // added from 18.11.2010
if(ads>0){
  if(threadactive==0) {
    startThread();
  } else {
    printf("ads:%d but threadactive is 1 at the start", ads);   //cannot happen
  };
};
#ifdef SIMVME
printf("srand(73), (SIMVME)...\n");
srand(73);
#endif
printDETS();
while(1)  {  
  /* the activity of calthread is checked here:
    if threadactive==1 & heartbeat did not change, the calthread
    is not active in spite of threadactive is claiming it is active!
  */
  if(threadactive==1) {
    if(heartbeat == last_heartbeat) {
      prtLog("ERROR: heartbeat is quiet, setting threadactive to 0.");
      threadactive=0;
    };
  };
  //printf("sleeping 40secs...\n");
  last_heartbeat= heartbeat;
  /*dtq_sleep(2); */
  sleep(40);  // should be more than max. cal.trig period (33s for muon_trg)
  /*if(detectfile("gcalrestart", 0) >=0) { 
    char msg[200];
    sprintf(msg,"gcalrestart exists"); prtLog(msg);
    system("rm gcalrestart");
    sprintf(msg,"main: gcalrestart removed, exiting..."); prtLog(msg);
    quit=8; 
  }; */
  if(quit>0) break;
  beammode= get_DIMW32("CTPDIM/BEAMMODE");  //cannot be used inside callback
  //ds_update();
};  
sprintf(msg, "Exiting gcalib. quit:%d...\n",quit); prtLog(msg);
stopDIM(); 
// stop all active dets:
for(ix=0; ix<NDETEC; ix++) {
  rc= delDET(ix);
  if(rc!=0) { printf("delDET(%d) rc:%d", ix, rc); };
};
delete DFS;
cshmDetach();
vmeclose();
exit(0);
}   
Esempio n. 19
0
/*--------------------*/ void calthread(void *tag) {
    Ttime ct,deltaTtime;
    w32 delta;
    int sddburst=0;
//printf("calthread:\n");
    threadactive=1;
    if(DBGCMDS) {
        prtLog("calthread start.");
    };
    while(1) {
        int ndit;
        heartbeat++;
        if(heartbeat>0xfffffff0) heartbeat=0;
        ndit= findnextcDET();   // find closest one in time
        //printf("det:%s %d %d\n", ACTIVEDETS[ndit].name, ACTIVEDETS[ndit].caltime.secs, ACTIVEDETS[ndit].caltime.usecs);
        if(ndit==-1) goto STP;
        if(globalcalDET(ndit)==0) {
            delDET(ndit);
            if(NACTIVE==0) goto STP;
            continue;
        };
        getcurtime(&ct);
        if( ACTIVEDETS[ndit].caltime.secs>0) {
            w32 milisecs;
            int rcgt;
            delta=diffnowbefore(&ACTIVEDETS[ndit].caltime, &ct);
            if(delta>100) {
                usleep(delta);
            };
            if(globalcalDET(ndit)==0) {
                delDET(ndit);
                if(NACTIVE==0) goto STP;
                continue;
            };
            // generate calib. trigger:
            if(cshmGlobFlag(FLGignoreGCALIB)==0) {
                w32 orbitn;
                rcgt= GenSwtrg(1, 'c', ACTIVEDETS[ndit].roc, ACTIVEDETS[ndit].calbc,1<<ndit,
                               swtriggers_gcalib, &orbitn);
                if(rcgt==12345678) {
                    delDET(ndit);
                    if(NACTIVE==0) goto STP;
                    continue;
                };
                ACTIVEDETS[ndit].attempts++;
            } else {
                rcgt=0; // cal. trigger not generated (disabled during start/stop part)
            };
            getcurtime(&ct); // time of cal. trigger just attempted to be generated
            // movd up ACTIVEDETS[ndit].attempts++;
            if(rcgt==1) {
                if(ACTIVEDETS[ndit].lasttime.secs==0) {
                    milisecs=0;
                } else {
                    milisecs= diffnowbefore(&ct, &ACTIVEDETS[ndit].lasttime)/1000;
                };
                ACTIVEDETS[ndit].sent++;
                //printf("CT:%s \t %d\t%d ms:%d\n", ACTIVEDETS[ndit].name, ct.secs, ct.usecs, milisecs);
                //printf("CT:%s ms:%d\n", ACTIVEDETS[ndit].name, milisecs);
                ACTIVEDETS[ndit].lasttime.secs= ct.secs;
                ACTIVEDETS[ndit].lasttime.usecs= ct.usecs;
            };
            // usleep(100);  // do we need this (waiting for the completion)?
            /* if(ACTIVEDETS[ndit].attempts > 200 ) {
              emptyDET(); goto STP;
            }; */
        };
        // the planning of next cal. trigger for ndit detector:
        // NextTime= CurrentTime + period[ndit] i.e.
        // IS THE SAME IN EITHER CASE (successful or unsuccsessful)
        if( ACTIVEDETS[ndit].caltime.secs==0) {   // wait 2 secs before 1st cal. event
            char msg[200];
            sprintf(msg, "1st planning:%s \t %d\t%d", ACTIVEDETS[ndit].name, ct.secs, ct.usecs);
            prtLog(msg);
            deltaTtime.secs=2;
            deltaTtime.usecs=0;
        } else {
            deltaTtime.secs=0;
            deltaTtime.usecs=1000*ACTIVEDETS[ndit].period;
        };
        if(ndit==SDD) {   // SDD 3x50ms every 15minutes
            sddburst++;
            if(sddburst==3) {
                sddburst=0;
                deltaTtime.usecs= 15*60*1000000;
            };
        };
        addtime(&ct, &deltaTtime);
        ACTIVEDETS[ndit].caltime.secs= ct.secs;
        ACTIVEDETS[ndit].caltime.usecs= ct.usecs;
        //printf("det:%s next:%d %d\n", ACTIVEDETS[ndit].name, ct.secs,ct.usecs);
    };
STP:
    threadactive=0;
    if(DBGCMDS) {
        prtLog("calthread stop.");
    };
}
Esempio n. 20
0
/*--------------------*/ void calthread(void *tag) {
Ttime ct,deltaTtime; w32 delta; int sddburst=0;
//printf("calthread:\n");
threadactive=1;
if(DBGCMDS) {
  char msg[100];
  sprintf(msg, "calthread start. DFS.ffala:%d", DFS->getffala());
  prtLog(msg);
};
while(1) {
  int ndit;
  heartbeat++; if(heartbeat>0xfffffff0) heartbeat=0;
  ndit= findnextcDET();   // find closest one in time. ndit: index into ACTIVEDETS
  //printf("det:%s %d %d\n", ACTIVEDETS[ndit].name, ACTIVEDETS[ndit].caltime.secs, ACTIVEDETS[ndit].caltime.usecs);
  if(ndit==-1) goto STP;  // cal. triggers not needed, stop thread
  if(globalcalDET(ndit)==0) {
    delDET(ndit); if(NACTIVE==0) goto STP;
    continue;
  };
  getcurtime(&ct); 
  if( ACTIVEDETS[ndit].caltime.secs>0) {
    w32 milisecs; int rcgt;
    delta=diffnowbefore(&ACTIVEDETS[ndit].caltime, &ct);
    if(delta>100) {
      usleep(delta);
    };
    if(globalcalDET(ndit)==0) {
      delDET(ndit); if(NACTIVE==0) goto STP;
      continue;
    };
    // generate calib. trigger:
    if(cshmGlobFlag(FLGignoreGCALIB)==0) {
      w32 orbitn[3];   // orbitn tsec tusec
      rcgt= GenSwtrg(1, 'c', ACTIVEDETS[ndit].logroc&0xf, ACTIVEDETS[ndit].calbc,1<<ndit, 
        swtriggers_gcalib, orbitn);
      ct.secs= orbitn[1]; ct.usecs= orbitn[2];
      if(rcgt==12345678) {
        delDET(ndit); if(NACTIVE==0) goto STP;
        continue;
      } else {
        w32 rcgtold;
        rcgtold= rcgt;
        if((rcgt & 0xffffff00)== 0xffffff00) {   // spec. case: one cal. trigger
          char line[80];
          rcgt= rcgt & 0xff;
          // update pp_N.data file: det tsec tusec orbitid rc
          sprintf(line,"%x %x %x %x %x\n", ndit, orbitn[1], orbitn[2],orbitn[0], rcgt);
          DFS->write_df(ndit, line);
        } else {
          char msg[100];
         sprintf(msg,"ERROR: got 0x%x instead of 0xffffff.., deactivating det. %d...",
            rcgtold, ndit);
          prtLog(msg);
          delDET(ndit); if(NACTIVE==0) goto STP;
          continue;
        };
      };
      ACTIVEDETS[ndit].attempts++;
    } else {
      rcgt=0; // cal. trigger not generated (disabled during start/stop part)
    };
    // getcurtime(&ct); // time of cal. trigger just attempted to be generated. Commented out 8.1.2017
    // movd up ACTIVEDETS[ndit].attempts++;
    if(rcgt==4) {    // 4:l2a OK, generated
      if(ACTIVEDETS[ndit].lasttime.secs==0) {
        milisecs=0;
      } else {
        milisecs= diffnowbefore(&ct, &ACTIVEDETS[ndit].lasttime)/1000;
      };
      ACTIVEDETS[ndit].sent++;
      //printf("CT:%s \t %d\t%d ms:%d\n", ACTIVEDETS[ndit].name, ct.secs, ct.usecs, milisecs);
      //printf("CT:%s ms:%d\n", ACTIVEDETS[ndit].name, milisecs);
      ACTIVEDETS[ndit].lasttime.secs= ct.secs;
      ACTIVEDETS[ndit].lasttime.usecs= ct.usecs;
    };
    // usleep(100);  // do we need this (waiting for the completion)?
    /* if(ACTIVEDETS[ndit].attempts > 200 ) {
      emptyDET(); goto STP;
    }; */
  };
  // the planning of next cal. trigger for ndit detector:
  // NextTime= CurrentTime + periodms[ndit] i.e.
  // IS THE SAME IN EITHER CASE (successful or unsuccsessful)
  if( ACTIVEDETS[ndit].caltime.secs==0) {   // wait 2 secs before 1st cal. event
    char msg[200];
    sprintf(msg, "1st planning:%s \t %d\t%d", ACTIVEDETS[ndit].name, ct.secs, ct.usecs);
    prtLog(msg);
    deltaTtime.secs=2; deltaTtime.usecs=0;
  } else {
    deltaTtime.secs=0; deltaTtime.usecs=1000*ACTIVEDETS[ndit].periodms;
  };
  if(ndit==SDD) {   // SDD 3x50ms every 15minutes
    sddburst++;
    if(sddburst==3) {
      sddburst=0;
      deltaTtime.usecs= 15*60*1000000;
    };
  };
  addtime(&ct, &deltaTtime);
  ACTIVEDETS[ndit].caltime.secs= ct.secs;
  ACTIVEDETS[ndit].caltime.usecs= ct.usecs;
  //printf("det:%s next:%d %d\n", ACTIVEDETS[ndit].name, ct.secs,ct.usecs); 
};
STP:
threadactive=0;
if(DBGCMDS) {
  prtLog("calthread stop.");
};
}
Esempio n. 21
0
/*--------------------------------------------------------------- exit_handler
*/
void exit_handler(int *exitcode) {
char msg1[100];
sprintf(msg1,"exit_handler exitcode:%d", *exitcode);
prtLog(msg1);
}
Esempio n. 22
0
/*--------------------------------------------------------------- ds_register
*/
void ds_register(char *action) {
int ix,rc=0; int rcexit=0;
char command[MAXCMDL];
if(micratepresent()& 0x2) {
  char msg[200]="";
  vspRF2TTC=0;
  rc= vmxopenam(&vspRF2TTC, "0xf00000", "0x100000", "A32");
  sprintf(msg, "vmxopen RF2TTC rc:%d vsp:%d\n", rc, vspRF2TTC); printf(msg);
  if(rc!=0) {
    rcexit=8;
  };
} else {
  printf("RF2TTC not connected\n");
};
if(micratepresent()& 0x1) {
  rc= openrfrxs();
  if(rc!=0) {
    rcexit=8;
  };
} else {
  printf("RFRXs not connected\n");
};
if(micratepresent()& 0x2) {
  char msg[100];
  //w32 bcm, om;
  //bcm= vmer32(BCmain_MAN_SELECT); om= vmer32(ORBmain_MAN_SELECT);
  //printf("ds_register1: 0x%x 0x%x\n", bcm, om);
  if(strcmp(action,"-writeall")==0) {
    sprintf(msg, "Initialising RF2TTC,CORDE,RFRX boards..."); prtLog(msg);
    writeall(); 
  } else {
    sprintf(msg, "RF2TTC,CORDE,RFRX boards not touched"); prtLog(msg);
  };
  //bcm= vmer32(BCmain_MAN_SELECT); om= vmer32(ORBmain_MAN_SELECT);
  //printf("ds_register2: 0x%x 0x%x\n", bcm, om);
};
if(micratepresent()& 0x1) {
  int ix;
  printf("getRFRX way:\n");
  getRFRX(vspRFRX[0], rfrx1); getRFRX(vspRFRX[1], rfrx2); 
  freqs[0]= rfrx1[2].freq; freqs[1]= rfrx2[2].freq;
  freqs[2]= rfrx1[1].freq; freqs[3]= rfrx2[1].freq;
  printf("ref bc1 orbit1:"); for(ix=0; ix<3; ix++) {
    printf("%d/%f ", rfrx1[ix].ref, rfrx1[ix].freq);
  }; printf("\n");
  printf("--- bc2 orbit2:"); for(ix=0; ix<3; ix++) {
    printf("%d/%f ", rfrx2[ix].ref, rfrx2[ix].freq);
  }; printf("\n"); 
} else {
  printf("RFRXs not connected\n");
  for(ix=0; ix<=4; ix++) {
    freqs[ix]=0.0;
  };
};
if(rcexit!=0) exit(rcexit);
printenvironment();
printf("DIM server:%s\n",MYNAME);
dis_add_error_handler(error_handler);
dis_add_exit_handler(exit_handler);
//dis_add_client_exit_handler (client_exit_handler);
printf("Commands:\n");
strcpy(command, MYNAME); strcat(command, "/MICLOCK_SET");
dis_add_cmnd(command,"C", MICLOCK_SETcmd, MICLOCK_SETtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/CORDE_SET");
dis_add_cmnd(command,"C", CORDE_SETcmd, CORDE_SETtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/DLL_RESYNC");
dis_add_cmnd(command,"C", DLL_RESYNCcmd, DLL_RESYNCtag);  printf("%s\n", command);

printf("\nServices:\n");
strcpy(command, MYNAME); strcat(command, "/MICLOCK");
MICLOCKid=dis_add_service(command,"C", clocknow, MAXLILE+1,
  MICLOCKcaba, MICLOCKtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/MICLOCK_TRANSITION");
MICLOCK_TRANSITIONid=dis_add_service(command,"C", clocktransition, 2,
  NULL, MICLOCK_TRANSITIONtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/SHIFT");
SHIFTid=dis_add_service(command,"C", shiftnow, MAXLILE+1,
  SHIFTcaba, SHIFTtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/QPLL");
//QPLLid=dis_add_service(command,"C", qpllnow, MAXLILE+1,
QPLLid=dis_add_service(command, "L", &qpllstat, sizeof(qpllstat),
//  QPLLcaba, QPLLtag);  printf("%s\n", command);
  NULL, QPLLtag);  printf("%s\n", command);
strcpy(command, MYNAME); strcat(command, "/RFRX");
FREQSid=dis_add_service(command,"F:4", freqs, 16,
  FREQScaba, FREQStag);  printf("%s\n", command);

rc=dis_start_serving(MYNAME);  
printf("serving rc:%d\n", rc);
printf("not Starting the thread reading BC*QPLL_STATUS regs...\n");
//dim_start_thread(qpll_thread, (void *)&TAGqpll_thread);
}