/*-----------------*/ void checkstartthread(int clocktag) { char errmsg[300]; 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*4)) { sprintf(errmsg, "newclock thread stucked (%d secs). Trigger expert should restart ttcmidim and check miclock client!", diff_s); prtLog(errmsg); infolog_trgboth(LOG_FATAL, errmsg); } else { sprintf(errmsg, "checkstartthread tag:%d: newclock thread already started %d secs, cmd %s from procid %s@%s ignored...", clocktag, diff_s, lastmsg, procid, hname); //prtLog(errmsg); infolog_trgboth(LOG_WARNING, errmsg); }; return; }; }; clocktran=3; strcpy(clocktransition,"3"); GetMicSec(&clocktran_s, &clocktran_u); newclocktag= clocktag; rcnewclock= 0; sprintf(errmsg, "newclock thread starting. tag:%d starts:%d\n", newclocktag, newclockstarts); prtLog(errmsg); dim_start_thread(newclock, (void *)&newclocktag); dtq_sleep(1); printf("rcnewclock:%d starts:%d\n",rcnewclock, newclockstarts); }
void executectp(char *sendcmd) { int rc, errorway=0; char cmd[100]; #ifdef PQWAY if(strcmp(sendcmd,"wait")==0) { pq_receive(mq_rec, cmd); printf("executectp received:%s.\n", cmd); } else { printf("executectp send:%s.\n", sendcmd); pq_send(mq_sendmsg, sendcmd); fflush(stdout); return; }; #endif errorReason[0]= '\0'; smi_set_parER(); if(strcmp(cmd,"LOAD")==0) { printf("%s partition: %s mask: %s run:%d\n", cmd,pname, mask,run_number); rc= ctp_LoadPartition(pname,mask,run_number,ACT_CONFIG, errorReason); } else if(strcmp(cmd,"INIT")==0) { printf("%s partition: %s mask: %s run:%d\n", cmd,pname, mask,run_number); rc= ctp_InitPartition(pname,mask,run_number,ACT_CONFIG, errorReason); } else if(strcmp(cmd,"START_PARTITION")==0) { printf("Starting partition: %s\n", pname); rc= ctp_StartPartition(pname, errorReason); } else if(strcmp(cmd,"STOP_PARTITION")==0) { printf("Stopping partition: %s\n", pname); rc= ctp_StopPartition(pname); errorway=1; } else if(strcmp(cmd,"PAUSE_PARTITION")==0) { rc= ctp_PausePartition(pname, detectors); errorway= 1; } else if(strcmp(cmd,"RESUME_PARTITION")==0) { rc= ctp_ResumePartition(pname, detectors); errorway= 1; } else if(strcmp(cmd,"SYNC")==0) { w32 orbitn; rc= ctp_SyncPartition(pname, errorReason, &orbitn); if(rc!=0) { printf("ctp_SyncPartition() rc:%d %s\n", rc,errorReason); smi_set_parER(); errorway= 1; } else { sprintf(ORBIT_NUMBER,"%u", orbitn); smi_set_par("ORBIT_NUMBER", ORBIT_NUMBER, STRING); } } else if(strcmp(cmd,"quitignored")==0) { infolog_trgboth(LOG_ERROR, "Unsuccessful attempt to stop ctpproxy, partitions active"); } else { printf("executectp cmd ignored: %s\n", cmd); fflush(stdout); return; }; if(rc){ if(errorway) { // i.e. errorReason set already in smi sleep(1); smi_setState("ERROR"); } else { printf("%s rc:%d %s\n", cmd, rc, errorReason); smi_set_parER(); sleep(1); smi_setState("LOAD_FAILURE"); }; }else{ sleep (1); smi_setState("RUNNING"); }; fflush(stdout); }
/*-----------------*/ 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); }
/*-----------------------------------------------*/ void newclock(void *tag) { /* this thread started with 2 events( only 1 available in one time): - clock change - DLL_RESYNC */ rcnewclock= 888; newclockstarts++; printf("newclock thread started. clocktran:%d tag:%d quit:%d\n", clocktran, *(int *)tag, quit); fflush(stdout); while(clocktran>=0) { int nclients; nclients= dis_update_service(MICLOCK_TRANSITIONid); printf("updated MICLOCK_TRANSITION clients:%d clocktran:%d\n", nclients, clocktran); if(clocktran==0) break; dtq_sleep(SLOT_S); clocktran--; sprintf(clocktransition,"%d", clocktran); if(clocktran==0) { if(*(int *)tag==0) { /*int rc; char cmd[]="$VMECFDIR/ttcmidaemons/sctel.py MININF"; DLL_RESYNC(DLL_info); // commented 19092014 //printf("DLL_RESYNC + clearing the scope persistance\n"); rc= system(cmd); commented 19092014 printf("DLL_RESYNC + MININF not done!\n"); */ DLL_RESYNC(DLL_info); } else { #define reslen 3200 int rc; char server[24]; char cmd[80]; char result[reslen]; if(envcmp("VMESITE", "ALICE")==0) { strcpy(server, getenv("SERVER_NODE")); } else { strcpy(server, "adls"); }; infolog_trgboth(LOG_WARNING, "ALICE clock changed, restaring ctpproxy (25s)..."); sprintf(cmd, "ssh trigger@%s ctpproxy.py restart nomasks", server); setbcorbit(*(int *)tag); nclients= dis_update_service(MICLOCKid); printf("updated MICLOCK clients:%d\n", nclients); //printf("updated MICLOCK clients:%d, now ctpproxy.py restart nomasks...\n", nclients); rc= popenread(cmd, result, reslen); if(rc==EXIT_FAILURE) { printf("ERROR cmd:%s rc:%d\n", cmd, rc); } else { printf("result(len:%d):%s\n", strlen(result), result); }; }; }; if(quit==1) clocktran=0; }; clocktran_s=0; rcnewclock= 0; }
/*--------------------*/ void DOcmd(void *tag, void *msg, int *size) { /* msg: string finished by "\n\0" */ //printf("DOcmd: tag:%d size:%d msg:%s<-endofmsg\n", *tag, *size,msg); char mymsg[400]; int stdoutyes=1; strncpy(mymsg, (char *)msg, 400); mymsg[398]='\n'; mymsg[399]='\0'; // force \n (if not given) if((strncmp(mymsg,"pcfg ",5)==0) || (strncmp(mymsg,"Ncfg ",5)==0) || (strncmp(mymsg,"Acfg ",5)==0) ) { /* pcfg RUNNUMBER partname -try ACT download (ECS INIT) Ncfg RUNNUMBER partname -NO ACT, change: Ncfg -> pcfg Acfg RUNNUMBER partname - abort \n -stop this server rcfgdel useDAQLOGBOOK rcfgdel ignoreDAQLOGBOOK rcfgdel ALL 0xc606 -ctpproxy restart rcfgdel PARTNAME RUNN -process in .py, (ECS STOP) rcfgdel reload -just reload parted csupdate aliasesupdate intupdate clockshift rcfg -OBSOLETE! resetclock -just write out */ char c; unsigned int rundec=0; int rc, infoerr, ix=0, runnactive=0; char instname[100]=""; char version[100]=""; char pname[60]=""; char runc[16]=""; char emsg[500]; //rc= getname_rn(mymsg, pname, rundec); moved to DOrcfg() while(1) { int cix; c=(mymsg)[5+ix]; if((c==' ') || (c=='\n') || (c=='\0')) { if(runnactive==0) { if(c==' ') { ix++; runnactive=1; cix=0; continue; } else { break; }; } else { if(runc[0]!='\0') { rundec=atoi(runc); break; }; }; }; if(runnactive==1) { runc[cix]=c; runc[cix+1]='\0'; cix++; } else { pname[ix]= c; pname[ix+1]='\0'; }; ix++; if(ix>=60) break; }; infolog_SetStream(pname, rundec); if(mymsg[0]=='p') { char filter[20000]=""; //actdb_open(); rc=actdb_getPartition(pname,filter, instname, version); //actdb_close(); if(rc==0) { sprintf(emsg,"INFO %s (run:%d inst:%s ver:%s) downloaded from ACT.", pname, rundec, instname, version); infoerr=LOG_INFO; } else if(rc==1) { sprintf(emsg,"ERROR %s (run:%d) not found in ACT, might be OK if shift leader disabled it in ACT (i.e. is in 'Local File' mode)", pname, rundec); infoerr=LOG_ERROR; } else { sprintf(emsg,"actdb_getPartition(%s) run:%d rc:%d (-2: partition not available in ACT)", pname,rundec,rc); infoerr=LOG_ERROR; }; } else if(mymsg[0]=='A') { //printf("INFO Acfg %s %d\n", pname, rundec); del_insver(rundec); } else { // Ncfg runnumber partname sprintf(emsg,"INFO %s (run:%d) not searched in ACT (ECS:ACT_CONFIG=NO)", pname, rundec); infoerr=LOG_INFO; mymsg[0]= 'p'; }; if(mymsg[0]=='p') { //prtLog(emsg); //myprtLog(emsg); infolog_trgboth(infoerr, emsg); rc= add_insver(rundec, pname, instname, version); if(rc==-1) { sprintf(emsg,"run:%d, instance/ver will not be stored in ACT", rundec); infolog_trg(LOG_FATAL, emsg); printf("ERROR %s", emsg); }; }; infolog_SetStream("",0); /*---- moved to .rcfg time if(ignoreDAQLOGBOOK==1) { rcdaq=0; } else { rcdaq= daqlogbook_open(); //rcdaq=0; if(rcdaq!=0) { printf("ERROR update_cs: DAQlogbook_open failed rc:%d",rcdaq); rc=4; //prtError("DAQlogbook_open failed"); }else{ char itemname[200]; rc= daqlogbook_update_cs(rundec, CSString); do_partitionCtpConfigItem(pname, itemname); rc_insert= daqlogbook_update_ACTConfig(rundec, itemname,instname,version); rcdaq= daqlogbook_close(); }; if((rc==0) && (rc_insert==0)) { infoerr=LOG_INFO; } else { infoerr=LOG_FATAL; }; sprintf(emsg,"daglogbook_update_cs rc:%d _update_ACTConfig rc:%d", rc, rc_insert); infolog_trg(infoerr, emsg); }; -------- moved to .rcfg */ // 1...,...10....,....20..3 } else if((strncmp(mymsg,"rcfgdel ignoreDAQLOGBOOK",23)==0)) { int rcdaq; ignoreDAQLOGBOOK=1; rcdaq= daqlogbook_close(); if(rcdaq==-1) { printf("ERROR DAQlogbook_close failed\n"); } else { printf("INFO DAQlogbook closed:rc:%d (ignoreDAQLOGBOOK from ctpproxy received)\n",rcdaq); }; stdoutyes=0; //cshmSetGlobFlag(FLGignoreDAQLOGBOOK); } else if((strncmp(mymsg,"rcfgdel useDAQLOGBOOK",20)==0)) { int rcdaq; rcdaq= daqlogbook_open(); //rcdaq=0; if(rcdaq!=0) { printf("ERROR DAQlogbook_open failed rc:%d",rcdaq); ignoreDAQLOGBOOK=1; cshmSetGlobFlag(FLGignoreDAQLOGBOOK); } else { ignoreDAQLOGBOOK=0; cshmClearGlobFlag(FLGignoreDAQLOGBOOK); }; stdoutyes=0; } else if((strncmp(mymsg,"rcfgdel ALL 0x...",11)==0)) { //ctpproxy [re]start //int irc; printf("INFO rcfgdel ALL 0x... (redis, readTables...)\n"); red_clear_detsinrun(0); reset_insver(); readTables(); ctpc_clear(); updateCNAMES(); /*irc=*/ check_xcounters(); } else if((strncmp(mymsg,"rcfgdel reload",14)==0)) { //reload parted // perhaps it is reasonable to clean (even if ctpproxy did not restart but is // without active partitions) //reset_insver(); //readTables(); //ctpc_clear(); updateCNAMES(); //printf("INFO rcfgdel reload\n"); ; } else if((strncmp(mymsg,"rcfgdel ",8)==0)) { // rcfgdel partname runn enum Ttokentype t1; int ixl, runn; char pname[16]; char intval[16];; char emsg[200]; emsg[0]='\0'; ixl=8; t1= nxtoken(mymsg, pname, &ixl); // runNumber if(t1==tSYMNAME) { t1= nxtoken(mymsg, intval, &ixl); // runNumber if(t1==tINTNUM) { runn= str2int(intval); // from 26.2. maybe not needed here, but seems ok when INIT brings ctpproxy to LOAD_FAILURE del_insver(runn); } else { sprintf(emsg,"pydimserver: bad run number in rcfgdel %s cmd", pname); }; } else { sprintf(emsg,"pydimserver: bad part. name in %s cmd", mymsg); }; if(emsg[0]=='\0') { red_clear_detsinrun(runn); ctpc_delrun(runn); updateCNAMES(); } else { infolog_trg(LOG_ERROR, emsg); printf("ERROR %s\n",emsg); }; } else if((strncmp(mymsg,"csupdate",8)==0)) { int csclients; // char *cs; /*cs=*/ readCS(); csclients= dis_update_service(CSid); printf("INFO CS update for %d clients\n", csclients); stdoutyes=0; } else if((strncmp(mymsg,"aliasesupdate",13)==0)) { int rc; rc= readAliases(); if(rc==-1) { char emsg[200]; strcpy(emsg,"aliasesupdate: info from aliases.txt not updated correctly"); infolog_trg(LOG_INFO, emsg); printf("ERROR %s\n",emsg); }; stdoutyes=0; } else if((strncmp(mymsg,"intupdate",9)==0)) { int rc1, rc2; rc1= getINT12fromcfg(INT1String, INT2String, MAXINT12LINE); printf("INFO rc:%d INT1:%s INT2:%s\n", rc1, INT1String, INT2String); rc1= dis_update_service(INT1id); rc2= dis_update_service(INT2id); printf("INFO INT1/INT2 update for %d/%d clients\n", rc1, rc2); stdoutyes=0; } else if((strncmp(mymsg,"clockshift ",11)==0)) { char halfns[20]; int ix,rc; unsigned int hns,cordeval,last_applied; /* char c; halfns[0]='\0'; for(ix=0; ix<40; ix++) { c= mymsg[11+ix]; if((c=='\0') || (c=='\n')) { halfns[ix]= '\0'; break; }; halfns[ix]= c; }; halfns[20]= '\0';*/ ix= sscanf(&mymsg[11], "%d %d %d\n", &hns, &cordeval, &last_applied); if( (ix<2) || (hns>63) || (cordeval>1023) ) { printf("ERROR set clockshift %d %d incorrect, not updated.\n",hns, cordeval); } else { //int csclients; sprintf(halfns, "%d %d %d", hns, cordeval, last_applied); rc= writedbfile("clockshift", halfns); // 2ints: halfns cordereg //csclients= dis_update_service(CSid); is not here printf("INFO set clockshift %s. rc(=chars):%d \n", halfns, rc); }; stdoutyes=0; } else if((strncmp(mymsg,"rcfg ",5)==0)) { // moved to DOrcfg() printf("ERROR rcfg cmd ignored (processed by CTPRCFG cmd\n"); stdoutyes=0; } else if((strncmp(mymsg,"resetclock",9)==0)) { ; }; if(strcmp(mymsg,"\n")==0) { //stopserving(); myprtLog("Quitting server..."); printf("stop\n"); fflush(stdout); //sleep(1); //exit(0); }; if(stdoutyes==1) { /* pcfg -prepare .pcfg (parted.py) - scp .pcfg rcfg partName NNN clu1 clu2 ... clu6 cl1 ... clNCLASS NewLine -prepare .rcfg (parted.py) - smaqmv */ printf("%s",mymsg); fflush(stdout); }; }
/*--------------------*/ void DOrcfg(void *tag, void *bmsg, int *size) { // bmsg: binary message TDAQInfo TDAQInfo *dain; int rc; unsigned int rundec; char pname[40]; //printf("INFO DOrcfg len:%d %lu\n", *size,sizeof(TDAQInfo)); if(*size != sizeof(TDAQInfo)){ char emsg[ERRMSGL]; sprintf(emsg, "DOrcfg: Structure dim size different from command size."); infolog_trg(LOG_FATAL, emsg); printf("ERROR %s\n", emsg); return ; } dain= (TDAQInfo *)bmsg; //printTDAQInfo(dain); printf("INFO DOrcfg msg:%s", dain->run1msg); rc= getname_rn(dain->run1msg, pname, &rundec); if(check_xcounters()) return; if(rc==0) { //printf("INFO effiout:0x%x\n", effiout); /*new from aug2015: effiout: bit pattern of inp. detectors effectively filtered out not used: prepared if DAQ wants in future 'per cluster' -in that case 'per cluster' info -should by passed in TDAQInfo structure from ctp proxy (now it is not) or -somehow, pydimserver.py should deliver 'per cluster' (now delivering 'per partition') red_update_detsinrun() invoked also in following call */ rc= daqlogbook_update_clusters(rundec, pname, dain, ignoreDAQLOGBOOK); //, effiout); printf("INFO Dorcfg rc=%i \n",rc); //printf("%s",dain->run1msg); fflush(stdout); moved down if(rc==0) { // inputs -> DAQ int level,maxinp,ix,ind,rcu; for(level=0; level<3; level++) { if(level==2) {maxinp=12; } else {maxinp=24; } for(ix=0; ix<maxinp; ix++) { ind= findInput(level, ix+1); if(ind==-1) continue; if(ignoreDAQLOGBOOK) { rcu=0; //printf("INFO L%d.%d %s\n", level, ix+1, validCTPINPUTs[ind].name); } else { rcu= daqlogbook_insert_triggerInput(rundec, ix+1, validCTPINPUTs[ind].name, level); printf("INFO L%d.%d %s\n", level, ix+1, validCTPINPUTs[ind].name); }; if(rcu != 0) { char emsg[ERRMSGL]; sprintf(emsg, "daqlogbook_insert_triggerInput(%d,%d,%s,%d) rc:%d", rundec,ix+1, validCTPINPUTs[ind].name, level, rcu); infolog_trg(LOG_FATAL, emsg); printf("ERROR %s\n", emsg); break; }; }; }; printf("%s",dain->run1msg); fflush(stdout); } else { char emsg[ERRMSGL]; sprintf(emsg,"DAQlogbook_update_cluster failed. rc:%d", rc); infolog_trgboth(LOG_FATAL, emsg); }; }; }
/*----------------------------------------*/ 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); }
/*--------------------------------------------------- SMI_handle_command() */ void SMI_handle_command() { char action[64], param[128], parname[64], msg[256]; char run_number_str[64]; int n_params, ptype, psize, i; prtProfTime(NULL); smi_get_action(action,&n_params); UPPER(action); strcpy(msg,""); if(n_params != 2){ printf("# of pars received: %i. \n",n_params); //exit(8); }; for (i=1;i<=n_params;i++) { smi_get_next_par(parname,&ptype,&psize); smi_get_par_value(parname,param); printf("SMI: parname=%s param=%s \n", parname,param); if(strcmp(parname,"PARTITION") == 0) { strcpy(pname,param); } else if(strcmp(parname,"MASK") == 0){ strcpy(mask,param); } else if(strcmp(parname,"MODE") == 0){ if((strcmp(param,"NOTHING")!=0) && (strcmp(param,"PHYSICS")!=0) && (strcmp(param,"UNDEFINED")!=0)) { strcpy(partmode,param); } else { strcpy(partmode,""); }; } else if(strcmp(parname,"RUN_NUMBER") == 0) { strcpy(run_number_str,param); //run_number=atoi(run_number_str) run_number= (int) strtol(run_number_str, (char **)NULL, 10); if(run_number<=0) { printf("RUN_NUMBER <=0\n"); smi_setState("ERROR"); goto RETSMI; }; } else if(strcmp(parname,"ACT_CONFIG") == 0) { strcpy(ACT_CONFIG,param); } else if(strcmp(parname,"DETECTORS") == 0) { // comma separated list of dets (e.g. "PMD,MUON_TRK") detectors= detList2bitpat(param); // "CTP" will be ignored (bit not set) if(detectors==-1) { sprintf(errorReason, "Bad list of detectors:%s...",param); smi_set_parER(); smi_setState("ERROR"); goto RETSMI; }; printf("detectors:%s= 0x%x\n",param, detectors); } else { char wmsg[200]; sprintf(wmsg,"unknown parameter from ECS:%s", param); prtWarning(wmsg); }; strcat(msg," "); strcat(msg,param); }; printf("%s Got action %s with parameters %s\n",obj,action,msg); if (strcmp(state,"RUNNING") == 0 ) { if((strcmp(action,"LOAD_PARTITION") == 0) || (strcmp(action,"INIT_PARTITION") == 0)) { char INITLOAD[8]; if(strcmp(action,"LOAD_PARTITION") == 0) { strcpy(INITLOAD,"LOAD"); } else { strcpy(INITLOAD,"INIT"); }; if(quit>0) { sprintf(msg,"%s_PARTITION ignored. ctp_proxy stopping, waiting for the stop of all partitions",INITLOAD); infolog_trgboth(LOG_FATAL, msg); } else { smi_set_parEF(pname); executectp(INITLOAD); }; } else if (strcmp(action,"START_PARTITION") == 0) { smi_set_parEF(pname); executectp(action); } else if (strcmp(action,"STOP_PARTITION") == 0) { smi_set_parEF(pname); executectp(action); } else if (strcmp(action,"PAUSE_PARTITION") == 0) { smi_set_parEF(pname); executectp(action); } else if (strcmp(action,"SYNC") == 0) { // correct: strcmp("SYNC") smi_set_parEF(pname); executectp(action); } else if (strcmp(action,"RESUME_PARTITION") == 0) { smi_set_parEF(pname); executectp(action); } else { char msg[200]; sprintf(msg, "Illegal action %s in state RUNNING ignored.\n",action); infolog_trgboth(LOG_ERROR, msg); smi_setState("RUNNING"); } } else if (strcmp(state,"EXECUTING") == 0 ) { char msg[200]; sprintf(msg, "Illegal action %s in state EXECUTING ignored.\n",action); smi_setState("EXECUTING"); } else if (strcmp(state,"LOAD_FAILURE") == 0 ) { if(strcmp(action,"ACKNOWLEDGE") == 0 ) { strcpy(errorReason,"not set"); smi_set_parER(); smi_setState("RUNNING"); } else { printf("Illegal action %s in state LOAD_FAILURE\n",action); smi_setState("LOAD_FAILURE"); } } else if (strcmp(state,"ERROR") == 0 ) { if (strcmp(action,"RESET") == 0 ) { smi_setState("RUNNING"); } else { printf("Illegal action %s in state ERROR\n",action); smi_setState("ERROR"); } }; RETSMI: prtProfTime("SMI_handle end"); return; }