enCalLog and angCalLog added

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@233 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-08-27 15:29:18 +00:00
parent d50ac0fe30
commit 7093e92c08
13 changed files with 287 additions and 47 deletions

View File

@ -1,5 +1,6 @@
CFLAGS= -DC_ONLY
#FLAGS+= #-DVERBOSE -DVERYVERBOSE
DFLAGS= -DDACS_INT
INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis
@ -12,7 +13,7 @@ SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFuncti
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

View File

@ -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};

View File

@ -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; \

View File

@ -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) { \

View File

@ -146,19 +146,21 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
if (script=="") {
scanMode[iscan]=0;
scanMode[iscan]=noScan;
} else {
strcpy(scanScript[iscan],script.c_str());
if (script=="none") {
scanMode[iscan]=0;
scanMode[iscan]=noScan;
} else if (script=="energy") {
scanMode[iscan]=1;
scanMode[iscan]=energyScan;
} else if (script=="threshold") {
scanMode[iscan]=2;
scanMode[iscan]=thresholdScan;
} else if (script=="trimbits") {
scanMode[iscan]=3;
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else {
scanMode[iscan]=4;
scanMode[iscan]=scriptScan;
}
}
@ -172,7 +174,7 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
if (nvalues>=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<MAX_SCAN_LEVELS) {
if (script=="") {
scanMode[iscan]=0;
scanMode[iscan]=noScan;
} else {
strcpy(scanScript[iscan],script.c_str());
if (script=="none") {
scanMode[iscan]=0;
scanMode[iscan]=noScan;
} else if (script=="energy") {
scanMode[iscan]=1;
scanMode[iscan]=energyScan;
} else if (script=="threshold") {
scanMode[iscan]=2;
scanMode[iscan]=thresholdScan;
} else if (script=="trimbits") {
scanMode[iscan]=3;
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else {
scanMode[iscan]=4;
scanMode[iscan]=scriptScan;
}
}
@ -280,7 +284,7 @@ int slsDetectorActions::setScanSteps(int iscan, int nvalues, double *values) {
if (nvalues>=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 << " " <<scanMode[level] << endl;
}
return 0;
@ -482,6 +493,12 @@ int slsDetectorActions::executeAction(int level) {
fName.c_str(), \
getActionParameter(level).c_str());
break;
case enCalLog:
return 0;
break;
case angCalLog:
return 0;
break;
default:
strcpy(cmd,"");
}
@ -495,3 +512,6 @@ int slsDetectorActions::executeAction(int level) {
}

View File

@ -24,6 +24,10 @@ class slsDetectorActions : public virtual slsDetectorBase
// : public virtual postProcessing
{
public :
enum {noScan, energyScan, thresholdScan, trimbitsScan, scriptScan, positionScan};
/** default constructor */
slsDetectorActions(){};
@ -202,6 +206,11 @@ class slsDetectorActions : public virtual slsDetectorBase
int setLastIndex(int i=-1){if (i>=0 && i>lastIndex) lastIndex=i; return lastIndex;};
virtual double moveDetector(double)=0;
virtual double getDetectorPosition()=0;
protected:

View File

@ -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]);
}

View File

@ -2,6 +2,8 @@
#include "usersFunctions.h"
#include "slsDetectorCommand.h"
#include "postProcessing.h"
#include "enCalLogClass.h"
#include "angCalLogClass.h"
#include <cstdlib>
#include <sys/ipc.h>
@ -37,6 +39,8 @@ slsDetectorUtils::slsDetectorUtils() {
void slsDetectorUtils::acquire(int delflag){
angCalLogClass *aclog=NULL;
enCalLogClass *eclog=NULL;
#ifdef VERBOSE
cout << "Acquire function "<< 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 (*correctionMask&(1<< I0_NORMALIZATION)) {
if (aclog) {
if ((*correctionMask&(1<< ANGULAR_CONVERSION))==0) {
pthread_mutex_lock(&mp);
currentPosition=getDetectorPosition();
posfinished=0;
pthread_mutex_unlock(&mp);
}
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;
}

View File

@ -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.)

View File

@ -0,0 +1,62 @@
#ifndef ANGCALLOGCLASS_H
#define ANGCALLOGCLASS_H
#include <iostream>
#include <fstream>
#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

View File

@ -0,0 +1,54 @@
#ifndef ENCALLOGCLASS_H
#define ENCALLOGCLASS_H
#include <iostream>
#include <fstream>
#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; im<det->setNumberOfModules(); 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

View File

@ -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<<WRITE_FILE)); if(i==0) ((*correctionMask)&=~(1<< WRITE_FILE)); return ((*correctionMask)&(1<< WRITE_FILE));};
int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<<WRITE_FILE)); else if (i==0) ((*correctionMask)&=~(1<< WRITE_FILE)); return (((*correctionMask)&(1<< WRITE_FILE ))>>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);};

View File

@ -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;
}