diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 38dea181c..2217d53d4 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -1,5 +1,6 @@ CFLAGS= -DC_ONLY #FLAGS+= #-DVERBOSE -DVERYVERBOSE + DFLAGS= -DDACS_INT INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis @@ -8,11 +9,11 @@ INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsD CC=g++ -SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp +SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/angularConversion.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp OBJS = $(SRC_CLNT:.cpp=.o) -HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorUsers.h multiSlsDetector/multiSlsDetectorCommand.h +HEADERS = $(SRC_CLNT:.cpp=.h) commonFiles/sls_detector_defs.h slsDetectorAnalysis/detectorData.h slsDetector/slsDetectorBase.h slsDetector/slsDetectorUsers.h multiSlsDetector/multiSlsDetectorCommand.h slsDetectorAnalysis/enCalLogClass.h slsDetectorAnalysis/angCalLogClass.h diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 94078e65b..dffc96ab3 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -51,7 +51,7 @@ class slsDetectorDefs { #endif - enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; + enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS}; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h index c20bbdd56..0662fcc52 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h @@ -55,7 +55,6 @@ class multiSlsDetectorClient { }; del=1; } \ - cout << "multislsdetector id "<< id << endl; \ iv=sscanf(argv[0],"%d:%s",&pos, cmd); \ if (iv==2 && pos>=0) { \ argv[0]=cmd; \ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h index a14c672a3..90d3c9e10 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorCommand.h @@ -30,7 +30,6 @@ class multiSlsDetectorCommand : public slsDetectorCommand { string executeLine(int narg, char *args[], int action, int id=-1) { \ string s; \ - printf("mess %d of %d\n",id, myDet->getNumberOfDetectors()); \ if (id>=0) { slsDetector *d=myDet->getSlsDetector(id); \ if (d) { \ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp index ce942cd58..fe0b7ad05 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp @@ -146,19 +146,21 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v if (iscan>=0 && iscan=0) { if (nvalues==0) - scanMode[iscan]=0; + scanMode[iscan]=noScan; else { nScanSteps[iscan]=nvalues; if (nvalues>MAX_SCAN_STEPS) @@ -217,19 +219,21 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v int slsDetectorActions::setScanScript(int iscan, string script) { if (iscan>=0 && iscan=0) { if (nvalues==0) - scanMode[iscan]=0; + scanMode[iscan]=noScan; else { nScanSteps[iscan]=nvalues; if (nvalues>MAX_SCAN_STEPS) @@ -414,26 +418,33 @@ int slsDetectorActions::executeScan(int level, int istep) { currentScanIndex[level]=istep; switch(scanMode[level]) { - case 1: + case energyScan: setThresholdEnergy((int)currentScanVariable[level]); //energy scan break; - case 2: - setDAC(currentScanVariable[level],THRESHOLD); // threshold scan + case thresholdScan: + setDAC((dacs_t)currentScanVariable[level],THRESHOLD); // threshold scan break; - case 3: + case trimbitsScan: trimbit=(int)currentScanVariable[level]; setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan break; - case 0: + case positionScan: + //check if channels are connected! + moveDetector(currentScanVariable[level]); + break; + case noScan: currentScanVariable[level]=0; break; - default: + case scriptScan: //Custom scan script level 1. The arguments are passed as nrun=n fn=filename var=v par=p" - sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",getScanScript(level).c_str(),getFileIndex(),createFileName().c_str(),currentScanVariable[level],getScanParameter(level).c_str()); + sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",getScanScript(level).c_str(),getFileIndex(),createFileName().c_str(),currentScanVariable[level],getScanParameter(level).c_str()); #ifdef VERBOSE cout << "Executing scan script "<< level << " " << cmd << endl; #endif system(cmd); + break; + default: + cout << "Scan mode unknown "<< level << " " <=0 && i>lastIndex) lastIndex=i; return lastIndex;}; + virtual double moveDetector(double)=0; + virtual double getDetectorPosition()=0; + + + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 2435faa7f..69f36c78e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -234,6 +234,21 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; i++; + descrToFuncMap[i].m_pFuncName="encallog"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + descrToFuncMap[i].m_pFuncName="angcallog"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; + i++; + + + + + + + + descrToFuncMap[i].m_pFuncName="headerbefore"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdScripts; i++; @@ -1306,15 +1321,20 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){ int i; char ans[100]; + if (action==HELP_ACTION) { return helpFileName(narg, args, action); } if (action==PUT_ACTION) { if (sscanf(args[1],"%d",&i)) myDet->enableWriteToFile(i); - return string("Write to File Enabled"); + else + return string("could not decode enable file write"); + + } - else return string("Write to File 'Not' Enabled"); + sprintf(ans,"%d",myDet->enableWriteToFile()); + return string(ans); } @@ -1805,7 +1825,7 @@ string slsDetectorCommand::helpPositions(int narg, char *args[], int action) { string slsDetectorCommand::cmdScripts(int narg, char *args[], int action) { int ia=-1; - + char answer[100]; if (action==HELP_ACTION) return helpScripts(narg,args,action); @@ -1816,6 +1836,11 @@ string slsDetectorCommand::cmdScripts(int narg, char *args[], int action) { if (cmd.find("headerafter")!=string::npos) ia=headerAfter; if (cmd.find("headerbefore")!=string::npos) ia=headerBefore; + if (cmd.find("encallog")!=string::npos) ia=enCalLog; + if (cmd.find("angcallog")!=string::npos) ia=angCalLog; + + + if (ia==-1) return string("cannot define action ")+cmd; if (cmd.find("par")!=string::npos) { @@ -1827,6 +1852,29 @@ string slsDetectorCommand::cmdScripts(int narg, char *args[], int action) { } else { + if (ia==enCalLog || ia==angCalLog) { + + + if (action==PUT_ACTION) { + + int arg=-1; + + + sscanf(args[1],"%d",&arg); + + if (arg==0) + myDet->setActionScript(ia,"none"); + else + myDet->setActionScript(ia,args[1]); + + } + + sprintf(answer,"%d",myDet->getActionMode(ia)); + return string(answer); + + } + + if (action==PUT_ACTION) { myDet->setActionScript(ia, args[1]); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 1866f2076..11fc1e407 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -2,6 +2,8 @@ #include "usersFunctions.h" #include "slsDetectorCommand.h" #include "postProcessing.h" +#include "enCalLogClass.h" +#include "angCalLogClass.h" #include #include @@ -37,7 +39,9 @@ slsDetectorUtils::slsDetectorUtils() { void slsDetectorUtils::acquire(int delflag){ - + angCalLogClass *aclog=NULL; + enCalLogClass *eclog=NULL; + #ifdef VERBOSE cout << "Acquire function "<< delflag << endl; cout << "Stopped flag is "<< stoppedFlag << delflag << endl; @@ -47,14 +51,26 @@ void slsDetectorUtils::acquire(int delflag){ // int lastindex=startindex, nowindex=startindex; + int connectChannels=0; - - if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) { - connect_channels(NULL); + if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(0)==positionScan)) { + if (connectChannels==0) + if (connect_channels) { + connect_channels(CCarg); + connectChannels=1; + } } - + + if (getActionMode(angCalLog)) + aclog=new angCalLogClass(this); + + if (getActionMode(enCalLog)) + eclog=new enCalLogClass(this); + + + // setTotalProgress(); progressIndex=0; *stoppedFlag=0; @@ -137,8 +153,7 @@ void slsDetectorUtils::acquire(int delflag){ // cout << "positions " << endl; if (*stoppedFlag==0) { if (*numberOfPositions>0) { - if (go_to_position) - go_to_position (detPositions[ip],NULL); + moveDetector(detPositions[ip]); currentPositionIndex=ip+1; #ifdef VERBOSE std::cout<< "moving to position" << std::endl; @@ -160,26 +175,45 @@ void slsDetectorUtils::acquire(int delflag){ if (*stoppedFlag==0) { + + + + executeAction(headerBefore); if (*correctionMask&(1<< ANGULAR_CONVERSION)) { pthread_mutex_lock(&mp); - if (get_position) - currentPosition=get_position(NULL); + currentPosition=getDetectorPosition(); + posfinished=0; + pthread_mutex_unlock(&mp); + } + + if (aclog) { + if ((*correctionMask&(1<< ANGULAR_CONVERSION))==0) { + pthread_mutex_lock(&mp); + currentPosition=getDetectorPosition(); posfinished=0; pthread_mutex_unlock(&mp); } - /* if (*correctionMask&(1<< I0_NORMALIZATION)) { + aclog->addStep(currentPosition, getCurrentFileName()); + } + + if (eclog) + eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName()); + + + + if (*correctionMask&(1<< I0_NORMALIZATION)) { if (get_i0) - get_i0(0); - }*/ + get_i0(0, IOarg); + } startAndReadAll(); if (*correctionMask&(1<< I0_NORMALIZATION)) { if (get_i0) - currentI0=get_i0(1,NULL); // this is the correct i0!!!!! + currentI0=get_i0(1,IOarg); // this is the correct i0!!!!! } pthread_mutex_lock(&mp); @@ -278,10 +312,17 @@ void slsDetectorUtils::acquire(int delflag){ } - if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) { + if (connectChannels) { if (disconnect_channels) - disconnect_channels(NULL); + disconnect_channels(DCarg); } + + if (aclog) + delete aclog; + + if (eclog) + delete eclog; + } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 141ec56e5..cab393f93 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -518,6 +518,8 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual int getMaxNumberOfModules(dimension d=X)=0; + double moveDetector(double pos){if (go_to_position) go_to_position (pos,GTarg); else cout << "no move detector callback registered" << endl; return getDetectorPosition();}; + double getDetectorPosition(){double pos=-1; if (get_position) pos=get_position(POarg); else cout << "no get position callback registered" << endl; return pos;}; /** Writes the configuration file -- will contain all the informations needed for the configuration (e.g. for a PSI detector caldir, settingsdir, angconv, badchannels etc.) diff --git a/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h b/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h new file mode 100644 index 000000000..b5b5f9efc --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/angCalLogClass.h @@ -0,0 +1,62 @@ +#ifndef ANGCALLOGCLASS_H +#define ANGCALLOGCLASS_H + +#include +#include +#include "slsDetectorCommand.h" +#include "slsDetectorUtils.h" +#include "sls_detector_defs.h" + +using namespace std; + +class angCalLogClass { + + + public: + + + angCalLogClass(slsDetectorUtils *det){ \ + char cmd[1000]; + char *argv[2]; \ + argv[0]=cmd; \ + sprintf(cmd,"_%d.angcal",det->getFileIndex()); \ + outfile.open(string(det->getFilePath()+string("/")+det->getFileName()+string(cmd)).c_str()); \ + myDet=new slsDetectorCommand(det); \ + strcpy(cmd,"nmod"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"angconv"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"globaloff"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"fineoff"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"angdir"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"ffdir"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"flatfield"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"badchannels"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + }; + + ~angCalLogClass(){delete myDet; outfile.close();}; + + int addStep(double pos, string fname) {outfile << pos << " " << fname << endl; return 0;}; + + + + private: + + slsDetectorCommand *myDet; + ofstream outfile; + + + +}; + + + + + +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h b/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h new file mode 100644 index 000000000..ee050913d --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/enCalLogClass.h @@ -0,0 +1,54 @@ +#ifndef ENCALLOGCLASS_H +#define ENCALLOGCLASS_H + +#include +#include +#include "slsDetectorCommand.h" +#include "slsDetectorUtils.h" +#include "sls_detector_defs.h" + +using namespace std; + +class enCalLogClass { + + + public: + + + enCalLogClass(slsDetectorUtils *det){ \ + char cmd[1000]; + char *argv[2]; \ + argv[0]=cmd; \ + sprintf(cmd,"_%d.encal",det->getFileIndex()); \ + outfile.open(string(det->getFilePath()+string("/")+det->getFileName()+string(cmd)).c_str()); \ + myDet=new slsDetectorCommand(det); \ + strcpy(cmd,"settings"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + strcpy(cmd,"nmod"); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + for (int im=0; imsetNumberOfModules(); im++) { \ + sprintf(cmd,"modulenumber:%d",im); \ + outfile << myDet->executeLine(1,argv,slsDetectorDefs::GET_ACTION) << endl; \ + }; \ + }; + + ~enCalLogClass(){delete myDet; outfile.close();}; + + int addStep(double threshold, string fname) {outfile << threshold << " " << fname << endl; return 0;}; + + + + private: + + slsDetectorCommand *myDet; + ofstream outfile; + + + +}; + + + + + +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index 89c2d99b0..8180c0e46 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -119,17 +119,17 @@ class postProcessing : public angularConversion, public fileIO { static int rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t); - int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<0) ((*correctionMask)|=(1<>WRITE_FILE) ;}; - int setAngularCorrectionMask(int i=-1){if (i==0) (*correctionMask)&=~(1<< ANGULAR_CONVERSION); if (i>0) (*correctionMask)|=(1<< ANGULAR_CONVERSION); return ((*correctionMask)&(1<< ANGULAR_CONVERSION));}; + int setAngularCorrectionMask(int i=-1){if (i==0) (*correctionMask)&=~(1<< ANGULAR_CONVERSION); if (i>0) (*correctionMask)|=(1<< ANGULAR_CONVERSION); return (((*correctionMask)&(1<< ANGULAR_CONVERSION))>>ANGULAR_CONVERSION);}; int enableAngularConversion(int i=-1) {if (i>0) return setAngularConversionFile("default"); if (i==0) return setAngularConversionFile(""); return setAngularCorrectionMask();}; - int enableBadChannelCorrection(int i=-1) {if (i>0) return setBadChannelCorrection("default"); if (i==0) return setBadChannelCorrection(""); return ((*correctionMask)&(1<< DISCARD_BAD_CHANNELS));}; + int enableBadChannelCorrection(int i=-1) {if (i>0) return setBadChannelCorrection("default"); if (i==0) return setBadChannelCorrection(""); return (((*correctionMask)&(1<< DISCARD_BAD_CHANNELS))>>DISCARD_BAD_CHANNELS);}; diff --git a/slsDetectorSoftware/usersFunctions/usersFunctions.cpp b/slsDetectorSoftware/usersFunctions/usersFunctions.cpp index 78ade083b..0315d4038 100644 --- a/slsDetectorSoftware/usersFunctions/usersFunctions.cpp +++ b/slsDetectorSoftware/usersFunctions/usersFunctions.cpp @@ -154,6 +154,8 @@ double defaultGetPosition(void *d) { pos=value; } else printf(ca_message(status)); +#else + printf("\nmotor position is %f\n",pos); #endif @@ -184,10 +186,13 @@ int defaultGoToPosition(double p,void *d) { printf(ca_message(status)); #else pos=p; + printf("\nmoving motor to position %f\n",p); #endif //"caputq X04SA-ES2-TH2:RO p" //cawait -nounit -timeout 3600 X04SA-ES2-TH2:RO.DMOV '==1' + + return (int)p; }