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

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

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