File_IO added

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@207 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
ramani_n
2012-08-02 14:37:37 +00:00
parent 5aebcd4888
commit 1982b25d89
21 changed files with 2223 additions and 108 deletions

View File

@ -510,6 +510,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
/** calculates the expected data size */
thisDetector->timerValue[PROBES_NUMBER]=0;
thisDetector->timerValue[FRAME_NUMBER]=1;
thisDetector->timerValue[MEASUREMENTS_NUMBER]=1;
thisDetector->timerValue[CYCLES_NUMBER]=1;
@ -3275,6 +3276,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
int ret=OK;
int n=0;
if (index!=MEASUREMENTS_NUMBER) {
#ifdef VERBOSE
@ -3304,8 +3306,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//std::cout<< "offline " << std::endl;
if (t>=0)
thisDetector->timerValue[index]=t;
}
}
} else {
if (t>=0)
thisDetector->timerValue[index]=t;
}
#ifdef VERBOSE
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
#endif
@ -3541,20 +3546,11 @@ int slsDetector::setPort(portType index, int num){
//Naveen change
int slsDetector::setTotalProgress() {
int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1;
int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1;
if (thisDetector->timerValue[FRAME_NUMBER])
nf=thisDetector->timerValue[FRAME_NUMBER];
@ -3565,6 +3561,10 @@ int slsDetector::setTotalProgress() {
if (thisDetector->numberOfPositions>0)
npos=thisDetector->numberOfPositions;
if (timerValue[MEASUREMENTS_NUMBER]>0)
nc=timerValue[MEASUREMENTS_NUMBER];
if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & (1 << MAX_ACTIONS)))
nscan[0]=thisDetector->nScanSteps[0];
@ -3575,6 +3575,7 @@ int slsDetector::setTotalProgress() {
#ifdef VERBOSE
cout << "nc " << nc << endl;
cout << "nm " << nm << endl;
cout << "nf " << nf << endl;
cout << "npos " << npos << endl;
cout << "nscan[0] " << nscan[0] << endl;
@ -4571,7 +4572,6 @@ int slsDetector::getAngularConversion(int &direction, angleConversionConstant *
} else {
return 0;
}
}

View File

@ -405,7 +405,8 @@ int slsDetectorActions::getScanPrecision(int iscan){
int slsDetectorActions::executeScan(int level, int istep) {
int trimbit;
int trimbit,aMask,prec0,prec1,pindex,npos;
float sv0,sv1;
char cmd[MAX_STR_LENGTH];
if (level<0 || level>MAX_SCAN_LEVELS)
@ -430,7 +431,7 @@ int slsDetectorActions::executeScan(int level, int istep) {
break;
default:
//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(aMask,sv0,prec0,sv1,prec1,pindex,npos).c_str(),currentScanVariable[level],getScanParameter(level).c_str());
#ifdef VERBOSE
cout << "Executing scan script "<< level << " " << cmd << endl;
#endif

View File

@ -229,7 +229,7 @@ class slsDetectorBase : public virtual slsDetectorUsers , public virtual slsDet
/** generates file name without extension */
virtual string createFileName()=0;
string createFileName(int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos);
@ -292,9 +292,9 @@ class slsDetectorBase : public virtual slsDetectorUsers , public virtual slsDet
*/
virtual int setNumberOfModules(int i=-1, dimension d=X)=0;
int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1){int nm=-1; if (nx>=0) nm=nx/getChansPerMod(0); return setNumberOfModules(nm,X);};
int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1){return setNumberOfModules(nx/getChansPerMod(0),X);};
int getDetectorSize(int &x0, int &y0, int &nx, int &ny){x0=0; nx=setNumberOfModules(-1,X)*getChansPerMod(0); y0=0; ny=1; return nx;};
int getDetectorSize(int &x0, int &y0, int &nx, int &ny){x0=0; nx=setNumberOfModules(-1,X)*getChansPerMod(0); return nx;};
virtual int getMaxNumberOfModules(dimension d=X)=0; //
int getMaximumDetectorSize(int &nx, int &ny){nx=getMaxNumberOfModules(X)*getChansPerMod(0); ny=1; return nx;};

View File

@ -1312,9 +1312,9 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){
if (action==PUT_ACTION) {
if (sscanf(args[1],"%d",&i))
myDet->enableWriteToFile(i);
;
return string("Write to File Enabled");
}
return string(myDet->getFileName());
else return string("Write to File 'Not' Enabled");
}

View File

@ -1,13 +1,17 @@
#include "slsDetectorUtils.h"
#include "usersFunctions.h"
#include "slsDetectorCommand.h"
#include "postProcessing.h"
#include <cstdlib>
#include <sys/ipc.h>
#include <sys/shm.h>
using namespace std;
slsDetectorUtils::slsDetectorUtils() {
#ifdef VERBOSE
cout << "setting callbacks" << endl;
#endif
@ -21,6 +25,8 @@ slsDetectorUtils::slsDetectorUtils() {
cout << "done " << endl;
#endif
};
@ -38,8 +44,6 @@ void slsDetectorUtils::acquire(int delflag){
#endif
void *status;
setStartIndex(*fileIndex);
// int lastindex=startindex, nowindex=startindex;
@ -74,8 +78,7 @@ void slsDetectorUtils::acquire(int delflag){
if (*threadedProcessing) {
startThread(delflag);
}
//cout << "data thread started " << endl;
//cout << "data thread started " << endl;
int np=1;
if (*numberOfPositions>0)
np=*numberOfPositions;
@ -97,6 +100,11 @@ void slsDetectorUtils::acquire(int delflag){
ns1=1;
//loop measurements
setStartIndex(*fileIndex);
//cout << "action at start" << endl;
if (*stoppedFlag==0) {
executeAction(startScript);
@ -259,6 +267,9 @@ void slsDetectorUtils::acquire(int delflag){
executeAction(stopScript);
}
// loop measurements
// waiting for the data processing thread to finish!
if (*threadedProcessing) {
pthread_mutex_lock(&mp);
@ -278,11 +289,11 @@ void slsDetectorUtils::acquire(int delflag){
//Naveen change
int slsDetectorUtils::setTotalProgress() {
int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1;
int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1;
if (timerValue[FRAME_NUMBER])
nf=timerValue[FRAME_NUMBER];
@ -290,19 +301,23 @@ int slsDetectorUtils::setTotalProgress() {
if (timerValue[CYCLES_NUMBER]>0)
nc=timerValue[CYCLES_NUMBER];
if (*numberOfPositions>0)
if (timerValue[MEASUREMENTS_NUMBER]>0)
nc=timerValue[MEASUREMENTS_NUMBER];
if (*numberOfPositions>0)
npos=*numberOfPositions;
if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS)))
nscan[0]=nScanSteps[0];
if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS)))
nscan[0]=nScanSteps[0];
if ((nScanSteps[1]>0) && (*actionMask & (1 << (MAX_ACTIONS+1))))
nscan[1]=nScanSteps[1];
totalProgress=nf*nc*npos*nscan[0]*nscan[1];
totalProgress=nm*nf*nc*npos*nscan[0]*nscan[1];
#ifdef VERBOSE
cout << "nc " << nc << endl;
cout << "nm " << nm << endl;
cout << "nf " << nf << endl;
cout << "npos " << npos << endl;
cout << "nscan[0] " << nscan[0] << endl;
@ -658,12 +673,9 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
ofstream outfile;
char *args[2];
char myargs[2][1000];
args[0]=myargs[0];
args[1]=myargs[1];
// for (int ia=0; ia<2; ia++) {
// args[ia]=new char[1000];
//}
for (int ia=0; ia<2; ia++) {
args[ia]=new char[1000];
}
@ -694,18 +706,18 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
}
strcpy(myargs[0],names[iv].c_str());
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".ff");
strcpy(myargs[1],fname1.c_str());
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(myargs[0],names[iv].c_str());
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".bad");
strcpy(myargs[1],fname1.c_str());
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
@ -713,14 +725,14 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){
if (level==2) {
strcpy(myargs[0],names[iv].c_str());
strcpy(args[0],names[iv].c_str());
size_t c=fname.rfind('/');
if (c<string::npos) {
fname1=fname.substr(0,c+1)+string("trim_")+fname.substr(c+1);
} else {
fname1=string("trim_")+fname;
}
strcpy(myargs[1],fname1.c_str());
strcpy(args[1],fname1.c_str());
#ifdef VERBOSE
std::cout<< "writing to file " << fname1 << std::endl;
#endif

View File

@ -9,6 +9,7 @@ class pthread_mutex_t;
class pthread_t;
#endif
extern "C" {
#include <pthread.h>
}
@ -35,7 +36,7 @@ using namespace std;
#include "slsDetectorActions.h"
#include "postProcessing.h"
#define MAX_TIMERS 10
#define MAX_TIMERS 11
#define MAX_ROIS 100
#define MAXPOS 50
@ -47,19 +48,20 @@ using namespace std;
(used in the PSi command line interface)
*/
//class postProcessing;
class slsDetectorUtils : public slsDetectorActions, public postProcessing {
//public postProcessing
public:
slsDetectorUtils();
slsDetectorUtils();
virtual ~slsDetectorUtils(){};
virtual int getNumberOfDetectors(){return 1;};
@ -71,10 +73,10 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
using slsDetectorBase::setFlatFieldCorrection;
using postProcessing::setBadChannelCorrection;
int enableFlatFieldCorrection(int i=-1) {if (i>0) setFlatFieldCorrectionFile("default"); else if (i==0) setFlatFieldCorrectionFile(""); return getFlatFieldCorrection();}
int enablePixelMaskCorrection(int i=-1) {if (i>0) setBadChannelCorrection("default"); else if (i==0) setBadChannelCorrection(""); return getBadChannelCorrection();}
int enableCountRateCorrection(int i=-1){if (i>0) setRateCorrection(-1); else if (i==0) setRateCorrection(0); return getRateCorrection();}
// string getFilePath(){return fileIO::getFilePath();};
int enableFlatFieldCorrection(int i=-1) {if (i>0) setFlatFieldCorrectionFile("default"); else if (i==0) setFlatFieldCorrectionFile(""); return getFlatFieldCorrection();};
int enablePixelMaskCorrection(int i=-1) {if (i>0) setBadChannelCorrection("default"); else if (i==0) setBadChannelCorrection(""); return getBadChannelCorrection();};
int enableCountRateCorrection(int i=-1){if (i>0) setRateCorrection(-1); else if (i==0) setRateCorrection(0); return getRateCorrection();};
// string getFilePath(){return fileIO::getFilePath();};;
// string setFilePath(string s){return fileIO::setFilePath(s);};
// string getFileName(){return fileIO::getFileName();};
@ -83,8 +85,14 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
// int getFileIndex(){return fileIO::getFileIndex();};
// int setFileIndex(int s){return fileIO::setFileIndex(s);};
/*
int getScanPrecision(int i){return slsDetectorActions::getScanPrecision(i);};
// int getScanPrecision(int i){return slsDetectorActions::getScanPrecision(i);};
int getActionMask() {return slsDetectorActions::getActionMask();};
float getCurrentScanVariable(int i) {return slsDetectorActions::getCurrentScanVariable(i);};
int getCurrentPositionIndex(){return angularConversion::getCurrentPositionIndex();};
int getNumberOfPositions(){return angularConversion::getNumberOfPositions();};
*/
// int getActionMask() {return slsDetectorActions::getActionMask();};
// double getCurrentScanVariable(int i) {return slsDetectorActions::getCurrentScanVariable(i);};
@ -140,7 +148,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
\param i position in the multiSlsDetector structure
\return id or -1 if FAIL
*/
virtual int getDetectorId(int i=-1) =0;
virtual int getDetectorId(int i=-1)=0;
/** Sets the detector id (shared memory id) of an slsDetector in a multiSlsDetector structure
\param ival id to be set
@ -177,7 +185,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual int setPort(portType t, int i=-1)=0;
/**
get detector ids/versions for module
get detector ids/versions for module=0
\param mode which id/version has to be read
\param imod module number for module serial number
\returns id
@ -299,7 +307,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
virtual char* getSettingsDir()=0;
/** sets the detector trimbit/settings directory */
virtual char* setSettingsDir(string s)=0;
virtual char* setSettingsDir(string s);
/**
returns the location of the calibration files
@ -517,7 +525,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
virtual int writeConfigurationFile(string const fname)=0;
virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0;
void registerGetPositionCallback( double (*func)(void*),void *arg){get_position=func; POarg=arg;};
@ -548,11 +556,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
int retrieveDetectorSetup(string const fname, int level=0);
protected:
static const int64_t thisSoftwareVersion=0x20120124;
//protected:
int *stoppedFlag;