Exemplo n.º 1
0
/*--------------------------------------------------- updateConfig
update following info in DAQlogbook::
- .rcfg + alignment
- col. schedule
- partition instance name/version (was sent in time of .pcfg)
*/
void updateConfig(int runn, char *pname, char *instname, char *instver) {
int rc, rl; int bm; w32 globflags;
char *mem; char *environ, *envWORK;
char cfgname[200], aliname[200], itemname[200];
char emsg[1000];

#define MAXALIGNMENTLEN 4000
#define MAXRCFGLEN 30000
char alignment[MAXALIGNMENTLEN];
environ= getenv("VMESITE");
envWORK= getenv("VMEWORKDIR"); strcpy(cfgname, envWORK);
if(strcmp(environ,"ALICE")==0) {
  strcpy(aliname, "/home/dl6/snapshot/alidcsvme001/home/alice/trigger/v/vme/WORK/");
} else if(strcmp(environ,"SERVER")==0) {
  strcpy(aliname, "/home/dl6/snapshot/altri1/home/alice/trigger/v/vme/WORK/");
} else {
  printf("INFO strange VMESITE env. var:%s using WORKDIR/WORK\n",environ);
  sprintf(aliname, "%s/WORK/", envWORK);
};
strcat(aliname, "alignment2daq");
rl= readdbfile(aliname, alignment, MAXALIGNMENTLEN); alignment[rl]='\0';
if(alignment=='\0') {
  infolog_trg(LOG_FATAL, "Alignment info in DAQlogbook is empty");
  printf("ERROR Alignment info in DAQlogbook is empty");
};
printf("INFO alignment file len:%d (MAX:%d)\n",rl, MAXALIGNMENTLEN );
sprintf(cfgname,"%s/WORK/RCFG/r%d.rcfg", envWORK, runn);
mem= (char *)malloc(MAXRCFGLEN+1); mem[0]='\0';
rl= readdbfile(cfgname, mem, MAXRCFGLEN); mem[rl]='\0';
printf("INFO %s rcfg file len:%d (MAXlen:%d)\n",cfgname, rl, MAXRCFGLEN );
printf("INFO ctpshmbase2:%p\n", ctpshmbase);
if(rl < 10) {
  sprintf(emsg, "updateConfig: File: %s read error\n",cfgname); 
  infolog_trg(LOG_FATAL, emsg);
  printf("ERROR %s", emsg);
} else {  
  if(ignoreDAQLOGBOOK) { rc=0;}
  else {
    rc= daqlogbook_update_triggerConfig(runn, mem, alignment, effiout);
    printf("INFO daqlogbook_update_triggerConfig rc:%d\n", rc);
  };
  if(rc!=0) {
    sprintf(emsg, "DAQlogbook_update_triggerConfig: rc:%d\n",rc); 
    infolog_trg(LOG_FATAL, emsg);
    printf("ERROR %s", emsg);
  };
};
free(mem);
printf("INFO ctpshmbase3:%p\n", ctpshmbase);
cshmDetach(); printf("INFO shm detached.\n");
cshmInit();   /* without this line and with daqlogbook_update_triggerConfig above, server crashes
in P2, but not in lab. In lab, repeated cshmInit leads to:
[trigger@avmes logs]$ grep -e ctpshmbase -e attached pydimserver.log 
02.10.2015 14:13:28 received:INFO shared memory attached at address 0x7f1028920000
02.10.2015 14:13:28 received:INFO ctpshmbase1:0x7f1028920000
02.10.2015 14:13:44 received:INFO ctpshmbase2:0x7f1028920000
02.10.2015 14:13:44 received:INFO ctpshmbase3:0x7f1028920000
02.10.2015 14:13:44 received:INFO shared memory attached at address 0x7f102891c000
02.10.2015 14:13:44 received:INFO ctpshmbase4:0x7f102891c000
- seems ok (reattached at diffrent address +0x4000)
 */
printf("INFO ctpshmbase4: detached+attached%p\n", ctpshmbase);
bm= cshmBM(); 
globflags= cshmGlobFlags(); 
printf("INFO beammode:%d GlobalFlags:0x%x\n", bm, globflags);   // todo:cs update only for 7(RAMP)..12(UNSTABLE BEAMS)
if(ignoreDAQLOGBOOK) { 
  rc=0;
} else {
  if((bm>=7) && (bm<=12)) {
    rc= daqlogbook_update_cs(runn, CSString);
  } else {
    printf("INFO cs not updated ( bm<7 or bm>12)\n");
  };
  do_partitionCtpConfigItem(pname, itemname);
  rc= daqlogbook_update_ACTConfig(runn, itemname,instname,instver);
};
}
Exemplo n.º 2
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);
}   
Exemplo n.º 3
0
/*--------------------------------------------------- main */
int main(int argc, char **argv) {
int rc,grc=0;
//char *cs; 
char command[40];
char servername[40];
char cmd[80];

setlinebuf(stdout);
if(argc!=3) {
  printf("ERROR: Usage: linux/server servername command\n"); return(8);
};
infolog_SetFacility("CTP");
infolog_SetStream("",0);
strcpy(servername, argv[1]);
strcpy(command, argv[2]);
sprintf(cmd, "%s/%s", servername, command);   // CTPRCFG/RCFG
// following line has to be 1st line printed!
printf("DIM server:%s cmd:%s\n", servername, command); // should be 1st line

reset_insver();
/*cs=*/ readCS();
rc= readAliases(); 
if(rc==-1) {
  char emsg[200];
  strcpy(emsg,"aliases info from aliases.txt not updated correctly");
  infolog_trg(LOG_ERROR, emsg); printf("ERROR %s\n",emsg);
};
cshmInit();
readTables();   // + when ctpprxy restarted, i.e. in time of rcfgdel 0 ALL
printf("INFO ctpshmbase1:%p\n", ctpshmbase);
ctpc_clear(); ctpc_print(CNAMESString);
//updateCNAMES();
rc= getINT12fromcfg(INT1String, INT2String, MAXINT12LINE);
printf("INFO rc:%d INT1:%s INT2:%s\n", rc, INT1String, INT2String);

rc= mydbConnect();

dis_add_error_handler(error_handler);
dis_add_exit_handler(exit_handler);
dis_add_client_exit_handler (client_exit_handler);
// commands:
CTPRCFGRCFGid= dis_add_cmnd(cmd,"C", DOcmd, 88);
printf("INFO DIM cmd:%s id:%d\n", cmd, CTPRCFGRCFGid);
sprintf(cmd, "%s", servername);   // CTPRCFG binary (after LS1) RCFG request
CTPRCFGid= dis_add_cmnd(cmd,NULL, DOrcfg, 89);
printf("INFO DIM cmd:%s id:%d\n", cmd, CTPRCFGid);

sprintf(cmd, "%s/LTUCFG", servername);   // LTUCFG binary (after LS1)
LTUCFGid= dis_add_cmnd(cmd,NULL, DOltucfg, 90);
printf("INFO DIM cmd:%s id:%d\n", cmd, LTUCFGid);

sprintf(cmd, "%s/COM2DAQ", servername);   // CTPRCFG/COM2DAQ
C2Did= dis_add_cmnd(cmd,"C", DOcom2daq, 91);
printf("INFO DIM cmd:%s id:%d\n", cmd, C2Did);
sprintf(cmd, "%s/SETBM", servername);   // CTPRCFG/SETBM
SETBMid= dis_add_cmnd(cmd,"C", DOsetbm, 92);
printf("INFO DIM cmd:%s id:%d\n", cmd, SETBMid);
/*
sprintf(cmd, "%s/FSUPDATE", servername);   // CTPRCFG/FSUPDATE
FSUid= dis_add_cmnd(cmd,NULL, DOfsupdate, 92);
printf("INFO DIM cmd:%s id:%d\n", cmd, FSUid);
*/
// services:
sprintf(cmd, "%s/INT1", servername);   // CTPRCFG/INT1
INT1id=dis_add_service(cmd,"C:99", INT1String, MAXINT12LINE, NULL, 4567);
printf("INFO DIM service:%s id:%d\n", cmd, INT1id);
sprintf(cmd, "%s/INT2", servername);   // CTPRCFG/INT2
INT2id=dis_add_service(cmd,"C:99", INT2String, MAXINT12LINE, NULL, 4568);
printf("INFO DIM service:%s id:%d\n", cmd, INT2id);
sprintf(cmd, "%s/CS", servername);   // CTPRCFG/CS
CSid=dis_add_service(cmd,"C", CSString, MAXCSString, CScaba, 4569);
printf("INFO DIM service:%s id:%d\n", cmd, CSid);
sprintf(cmd, "%s/CNAMES", servername);   // CTPRCFG/CNAMES
CNAMESid=dis_add_service(cmd,"C", CNAMESString, MAXCNAMESString, CNAMEScaba, 4570);
printf("INFO DIM service:%s id:%d\n", cmd, CNAMESid);

dis_start_serving(servername);  
while(1) {
  char *frc;
#define MAXLINECS 8000
  char line[MAXLINECS];   //80 chars per class for NCLASS classes
  //sleep(10);
  frc= fgets(line, MAXLINECS, stdin);
  if(frc==NULL) break;
  if(strncmp(line,"quit",4)==0) {
    break;
  } else if(strncmp(line,"class ",6)==0) {
    int rcdaq;
    printf("INFO igDAQLOGBOOK:%d line:%s",ignoreDAQLOGBOOK, line);
    /* from 28.5.2013: DAQlogbook opened/closed when ctp_proxy restarted
    rcdaq= daqlogbook_open();
    if(rcdaq==-1) {
      printf("ERROR DAQlogbook_open failed\n");
    } else {
      if(ignoreDAQLOGBOOK==0) {
        rcdaq= updateDAQDB(line);
        if(rcdaq!=0) {
          printf("ERROR updateDAQLOGBOOK failed. rc=%d\n", rcdaq);
        };
        rcdaq= daqlogbook_close();
        if(rcdaq==-1) {
          printf("ERROR DAQlogbook_close failed\n");
        };
      };
    };*/
    rcdaq= updateDAQDB(line);
    if(rcdaq!=0) {
      printf("ERROR updateDAQLOGBOOK failed. rc=%d\n", rcdaq);
    };
  } else if(strncmp(line,"inpupd ",7)==0) {
    update_ctpins(line);
  } else if(strncmp(line,"indets ",7)==0) {
    int ix, ix1, runnumb; char *efstart;
    ix1= sscanf(&line[7], "%d ", &runnumb);
    efstart= strstr(&line[7], "0x");   // indets runN 0xeffiout 0xindets
    ix= sscanf(efstart, "0x%x 0x%x\n", &effiout, &indets);
    printf("INFO ix1:%d runnumb:%d ix:%d effiout:0x%x indets:0x%x\n",
      ix1, runnumb, ix, effiout, indets); fflush(stdout);
    //rcupd= updeff_insver(runnumb, effiout);
  } else if(strncmp(line,"cmd ",4)==0) {
    int unsigned ix,rcsystem;
    for(ix=0; ix<strlen(line); ix++) {
      if(line[ix]=='\n'){ line[ix]='\0'; break; };
    };
    rcsystem= system(&line[4]);
    printf("INFO rc:%d cmd:%s\n", rcsystem, &line[4]);   
    continue;
  } else {
    printf("ERROR %s", line); fflush(stdout);
  };
};
rc= daqlogbook_close();
if(rc==-1) {
  printf("ERROR DAQlogbook_close failed\n");
};
mydbDisconnect();
stopserving();
cshmDetach(); printf("INFO shm detached.\n");
return(grc);
}
Exemplo n.º 4
0
/*----------------------------------------*/ int main(int argc, char **argv) {
int rc;
int ssmcr_tries=0;
infolog_SetFacility("CTP"); infolog_SetStream("",0);
#ifdef PQWAY
printf("main_ctp: opening rec/send queues...\n");
mq_rec= pq_open();
if(mq_rec==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_rec not created");
  exit(8);
}
mq_sendmsg= pq_connect();
if(mq_sendmsg==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_sendmsg not connected");
  exit(8);
}
#endif
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
signal(SIGKILL, gotsignal); siginterrupt(SIGKILL, 0); // -9
signal(SIGTERM, gotsignal); siginterrupt(SIGTERM, 0); // kill pid
signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);   // CTRL C   2
partmode[0]='\0';
printf("cshmInit i.e. initBakery(swtriggers/ccread/ssmcr ONLY once, when shm allocated)...\n");
/*printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
printf("initBakery(ccread,5): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs\n");
*/
cshmInit();
setglobalflags(argc, argv);

/* changed in aug2016 (initBakery only once from now, when shm allocated)
printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
initBakery(&ctpshmbase->swtriggers, "swtriggers", swtriggers_N);
printf("initBakery(ccread,6): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs 5:orbitddl2\n");
initBakery(&ctpshmbase->ccread, "ccread", ccread_N);
printf("initBakery(ssmcr,4): 0:smaq 1:orbitddl2 2:ctp 3:inputs\n");
initBakery(&ctpshmbase->ssmcr, "ssmcr", ssmcr_N);
*/
printBakery(&ctpshmbase->swtriggers);
printBakery(&ctpshmbase->ccread);
printBakery(&ctpshmbase->ssmcr);
unlockBakery(&ctpshmbase->swtriggers,swtriggers_ctpproxy);
unlockBakery(&ctpshmbase->ccread,ccread_ctpproxy);
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);

/* Let' synchronise with smcr only, i.e. 
- ccread_dims,... can go in parallel with ctp_Initproxy, 
  orbitddl2: should use ccread_orbitddl2 customer when reading counters
  
- swtriggers_gcalib/_dims cannot appear (no global runs becasue ctpproxy being restarted)
*/
while(1) { // do not allow SSM usage (smaq) because ctp_Initproxy is initialising it
  char msg[100];
  rc= lockBakeryTimeout(&ctpshmbase->ssmcr,ssmcr_ctpproxy, 10);
  if(rc==1) {
    if(ssmcr_tries>0) {
      sprintf(msg, "Got ssmcr resource after %d attempts", ssmcr_tries);
      infolog_trgboth(LOG_INFO, msg);
    };
    break;  // ssmcr reserved for me now
  };
  ssmcr_tries++;
  sprintf(msg,"%d secs Waiting for ssmcr resource. Is smaq stopped?", ssmcr_tries*10);
  infolog_trgboth(LOG_WARNING, msg);
};
if(isArg(argc, argv, "configrunset")) {
  /* do we need before orbitddl2.py INT/L2 orbit in SYNC (automatic with L2a)?
  */
  int rc, reslen;
  char cmd[200];
  char result[1000]="";   // ~ 10 lines
  char orbchanged[]="Warning: orbitoffset changed:";
  if(envcmp("VMESITE", "PRIVATE")==0) {
    strcpy(cmd, "who");
  } else {
    strcpy(cmd, "orbitddl2.py configrunset");
  };
  infolog_trgboth(LOG_INFO, "Starting L0 orbit calibration (30s...)");
  rc= popenread(cmd, result, 1000);   // opens vme...
  reslen= strlen(result);
  if((rc==EXIT_FAILURE) || (reslen<=1)) { 
    infolog_trgboth(LOG_ERROR, "L0 orbit calibration problem");
  } else {
    int ixr= reslen;
    if(result[ixr-1]=='\n') {   //remove last NL character if present
      result[ixr-1]='\0';
      ixr= reslen-2;
    } else {
      ixr= reslen-1;   // pointer to the last non-NEWLINE character
    };
    while(ixr>=0) {    // find last line
      if(result[ixr]=='\n') {
        ixr++; break;
      };
      ixr--;
    };
    sprintf(cmd, "L0 orbit calibration: %s", &result[ixr]);
    if((strcmp(&result[ixr], "Everything ok")==0) ||
       (strncmp(&result[ixr], orbchanged, strlen(orbchanged))==0)
      ) {
      infolog_trgboth(LOG_INFO, cmd);
    } else {
      infolog_trgboth(LOG_ERROR, cmd);
      infolog_trgboth(LOG_ERROR, "ctpproxy not started"); 
      unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
      rc=8; goto STP;
    };
  };
};
// init CTP after calibration (e.g. to repair modifications done by orbitddl2.py)
rc=ctp_Initproxy();
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
if(rc!=0) goto STP;

// DIM services not registered here (see ctpdims.c), they run in separae task:
// ds_register();
strcpy(obj,argv[1]);
smi_attach(obj, SMI_handle_command);
printf("CTP attached to: %s\n",obj);
/* if smi_volatile: stops the ctp_proxy in case TRIGGER domain is down
smi_volatile();   
*/
strcpy(errorReason,"not set"); smi_set_parER();
strcpy(ORBIT_NUMBER,""); smi_set_par("ORBIT_NUMBER",ORBIT_NUMBER,STRING);
smi_setState("RUNNING");
while(1) {
#ifdef PQWAY
  executectp("wait");
#else
  usleep(1000000);
#endif
  if(quit>9) break;
};
rc= ctp_Endproxy();
STP:
#ifdef PQWAY
pq_close(mq_sendmsg, 0);
pq_close(mq_rec, 1);
#endif
printf("Calling cshmDetach()...\n"); cshmDetach();
return (rc);
}