mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 23:10:02 +02:00
now the loadimage, read/reset counterblock for gotthard works
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@159 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
410725784c
commit
c0a69ebc2d
@ -4645,7 +4645,7 @@ int slsDetector::loadImageToDetector(imageType index,string const fname){
|
||||
|
||||
|
||||
|
||||
int slsDetector::sendImageToDetector(imageType index,short int arg[]){
|
||||
int slsDetector::sendImageToDetector(imageType index,short int imageVals[]){
|
||||
|
||||
int ret=FAIL;
|
||||
int retval;
|
||||
@ -4653,7 +4653,7 @@ int slsDetector::sendImageToDetector(imageType index,short int arg[]){
|
||||
char mess[100];
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl<< "Sending image to detector " << std::endl;
|
||||
std::cout<<"Sending image to detector " <<std::endl;
|
||||
#endif
|
||||
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
@ -4661,7 +4661,7 @@ int slsDetector::sendImageToDetector(imageType index,short int arg[]){
|
||||
if (controlSocket->Connect()>=0) {
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&index,sizeof(index));
|
||||
controlSocket->SendDataOnly(arg,sizeof(arg));
|
||||
controlSocket->SendDataOnly(imageVals,thisDetector->dataBytes);
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
@ -4676,9 +4676,6 @@ int slsDetector::sendImageToDetector(imageType index,short int arg[]){
|
||||
|
||||
}
|
||||
}
|
||||
if (ret==FAIL) {
|
||||
std::cout<< "failed " << std::endl;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -5552,3 +5549,86 @@ synchronizationMode slsDetector::setSynchronization(synchronizationMode flag) {
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::getCounterBlock(short int arg[],int startACQ){
|
||||
|
||||
int ret=FAIL;
|
||||
int fnum=F_READ_COUNTER_BLOCK;
|
||||
char mess[100];
|
||||
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
if (controlSocket->Connect()>=0) {
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&startACQ,sizeof(startACQ));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret!=FAIL)
|
||||
controlSocket->ReceiveDataOnly(arg,thisDetector->dataBytes);
|
||||
else {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
controlSocket->Disconnect();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int slsDetector::writeCounterBlockFile(string const fname,int startACQ){
|
||||
|
||||
int ret=FAIL;
|
||||
short int counterVals[thisDetector->nChans*thisDetector->nChips];
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl<< "Reading Counter to \""<<fname;
|
||||
if(startACQ==1)
|
||||
std::cout<<"\" and Restarting Acquisition";
|
||||
std::cout<<std::endl;
|
||||
#endif
|
||||
|
||||
ret=getCounterBlock(counterVals,startACQ);
|
||||
if(ret==OK)
|
||||
ret=writeDataFile(fname,counterVals);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetector::resetCounterBlock(int startACQ){
|
||||
|
||||
int ret=FAIL;
|
||||
int fnum=F_RESET_COUNTER_BLOCK;
|
||||
char mess[100];
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< std::endl<< "Resetting Counter";
|
||||
if(startACQ==1)
|
||||
std::cout<<" and Restarting Acquisition";
|
||||
std::cout<<std::endl;
|
||||
#endif
|
||||
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
if (controlSocket->Connect()>=0) {
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(&startACQ,sizeof(startACQ));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL){
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
}
|
||||
controlSocket->Disconnect();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
//#include "slsDetectorCommand.h"
|
||||
|
||||
|
||||
|
||||
//enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS};
|
||||
|
||||
|
||||
@ -1339,7 +1338,7 @@ typedef struct sharedSlsDetector {
|
||||
\param arg image
|
||||
|
||||
*/
|
||||
int sendImageToDetector(imageType index,short int arg[]);
|
||||
int sendImageToDetector(imageType index,short int imageVals[]);
|
||||
|
||||
/**
|
||||
Sets/gets the synchronization mode of the various detectors
|
||||
@ -1348,6 +1347,33 @@ typedef struct sharedSlsDetector {
|
||||
*/
|
||||
synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE);
|
||||
|
||||
/**
|
||||
writes the counter memory block from the detector
|
||||
\param startACQ is 1 to start acquisition after reading counter
|
||||
\param fname file name to load data from
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int writeCounterBlockFile(string const fname,int startACQ=0);
|
||||
|
||||
|
||||
/**
|
||||
gets counter memory block in detector
|
||||
\param startACQ is 1 to start acquisition after reading counter
|
||||
\param arg counter memory block from detector
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int getCounterBlock(short int arg[],int startACQ=0);
|
||||
|
||||
|
||||
/**
|
||||
Resets counter in detector
|
||||
\param startACQ is 1 to start acquisition after resetting counter
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int resetCounterBlock(int startACQ=0);
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -794,14 +794,30 @@ class slsDetectorBase {
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int loadImageToDetector(imageType index,string const fname)=0;
|
||||
|
||||
|
||||
/**
|
||||
Test function
|
||||
\param times number of repetitions
|
||||
\returns repetition when it fails
|
||||
*/
|
||||
virtual int testFunction(int times=0)=0;
|
||||
|
||||
/**
|
||||
writes the counter memory block from the detector
|
||||
\param startACQ is 1 to start acquisition after reading counter
|
||||
\fname file fname to load data from
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int writeCounterBlockFile(string const fname,int startACQ=0)=0;
|
||||
|
||||
|
||||
/**
|
||||
Resets counter memory block in detector
|
||||
\param startACQ is 1 to start acquisition after resetting counter
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
virtual int resetCounterBlock(int startACQ=0)=0;
|
||||
|
||||
|
||||
/**
|
||||
function to test acquisition
|
||||
*/
|
||||
virtual int testFunction(int itimes=0)=0;
|
||||
|
||||
|
||||
/************************************************************************
|
||||
|
||||
|
@ -126,6 +126,14 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorBase *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdImage;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="readctr"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
|
||||
i++;
|
||||
|
||||
descrToFuncMap[i].m_pFuncName="resetctr"; //
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdCounter;
|
||||
i++;
|
||||
|
||||
/* trim/cal directories */
|
||||
descrToFuncMap[i].m_pFuncName="trimdir"; //OK
|
||||
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettingsDir;
|
||||
@ -1635,36 +1643,90 @@ string slsDetectorCommand::cmdImage(int narg, char *args[], int action){
|
||||
if (action==HELP_ACTION)
|
||||
return helpImage(narg,args,HELP_ACTION);
|
||||
else if (action==GET_ACTION)
|
||||
return string("Cannot get");
|
||||
|
||||
return string("Cannot get");
|
||||
|
||||
sval=string(args[1]);
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
|
||||
|
||||
if (string(args[0])==string("darkimage"))
|
||||
retval=myDet->loadImageToDetector(DARK_IMAGE,sval);
|
||||
retval=myDet->loadImageToDetector(DARK_IMAGE,sval);
|
||||
else if (string(args[0])==string("gainimage"))
|
||||
retval=myDet->loadImageToDetector(GAIN_IMAGE,sval);
|
||||
retval=myDet->loadImageToDetector(GAIN_IMAGE,sval);
|
||||
|
||||
|
||||
if(!retval)
|
||||
if(retval==OK)
|
||||
return string("Image loaded succesfully");
|
||||
else
|
||||
return string("Image NOT loaded");
|
||||
return string("Image load failed");
|
||||
}
|
||||
|
||||
|
||||
string slsDetectorCommand::helpImage(int narg, char *args[], int action){
|
||||
if (action==PUT_ACTION || action==HELP_ACTION){
|
||||
if (string(args[0])==string("darkimage"))
|
||||
return string("darkimage f \t loads the image to detector from file f\n");
|
||||
else
|
||||
return string("gainimage f \t loads the image to detector from file f\n");
|
||||
}
|
||||
else
|
||||
return string("Cannot get");
|
||||
ostringstream os;
|
||||
if (action==PUT_ACTION || action==HELP_ACTION){
|
||||
os << "darkimage f \t loads the image to detector from file f"<< std::endl;
|
||||
os << "gainimage f \t loads the image to detector from file f"<< std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION){
|
||||
os << "darkimage \t Cannot get"<< std::endl;
|
||||
os << "gainimage \t Cannot get"<< std::endl;
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdCounter(int narg, char *args[], int action){
|
||||
int ival;
|
||||
string sval;
|
||||
int retval;
|
||||
if (action==HELP_ACTION)
|
||||
return helpCounter(narg,args,HELP_ACTION);
|
||||
else if (action==PUT_ACTION)
|
||||
ival=atoi(args[1]);
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
|
||||
if (string(args[0])==string("readctr")){
|
||||
if (action==PUT_ACTION)
|
||||
return string("Cannot put");
|
||||
else{
|
||||
if (narg<3)
|
||||
return string("should specify I/O file");
|
||||
sval=string(args[2]);
|
||||
retval=myDet->writeCounterBlockFile(sval,ival);
|
||||
}
|
||||
}
|
||||
else if (string(args[0])==string("resetctr")){
|
||||
if (action==GET_ACTION)
|
||||
return string("Cannot get");
|
||||
else
|
||||
retval=myDet->resetCounterBlock(ival);
|
||||
}
|
||||
|
||||
|
||||
if(retval==OK)
|
||||
return string("Counter read/reset succesfully");
|
||||
else
|
||||
return string("Counter read/reset failed");
|
||||
}
|
||||
|
||||
|
||||
string slsDetectorCommand::helpCounter(int narg, char *args[], int action){
|
||||
ostringstream os;
|
||||
os << std::endl;
|
||||
if (action==PUT_ACTION || action==HELP_ACTION){
|
||||
os << "readctr \t Cannot put"<< std::endl;
|
||||
os << "resetctr i \t resets counter in detector, restarts acquisition if i=1"<< std::endl;
|
||||
}
|
||||
if (action==GET_ACTION || action==HELP_ACTION)
|
||||
os << "readctr i fname\t reads counter in detector to file fname, restarts acquisition if i=1"<< std::endl;
|
||||
os << "resetctr \t Cannot get"<< std::endl;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
string slsDetectorCommand::cmdPositions(int narg, char *args[], int action){
|
||||
int ival;
|
||||
|
@ -80,6 +80,7 @@ class slsDetectorCommand {
|
||||
static string helpAdvanced(int narg, char *args[], int action);
|
||||
static string helpConfiguration(int narg, char *args[], int action);
|
||||
static string helpImage(int narg, char *args[], int action);
|
||||
static string helpCounter(int narg, char *args[], int action);
|
||||
static string helpADC(int narg, char *args[], int action);
|
||||
|
||||
|
||||
@ -149,6 +150,7 @@ class slsDetectorCommand {
|
||||
string cmdAdvanced(int narg, char *args[], int action);
|
||||
string cmdConfiguration(int narg, char *args[], int action);
|
||||
string cmdImage(int narg, char *args[], int action);
|
||||
string cmdCounter(int narg, char *args[], int action);
|
||||
string cmdADC(int narg, char *args[], int action);
|
||||
|
||||
|
||||
|
@ -880,6 +880,39 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data, int o
|
||||
|
||||
|
||||
|
||||
/*writes raw data file */
|
||||
int slsDetectorUtils::writeDataFile(string fname, int nch, short int *data){
|
||||
ofstream outfile;
|
||||
if (data==NULL)
|
||||
return FAIL;
|
||||
|
||||
outfile.open (fname.c_str(),ios_base::out);
|
||||
if (outfile.is_open())
|
||||
{
|
||||
writeDataFile(outfile, nch, data, 0);
|
||||
outfile.close();
|
||||
return OK;
|
||||
} else {
|
||||
std::cout<< "Could not open file " << fname << "for writing"<< std::endl;
|
||||
return FAIL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*writes raw data file */
|
||||
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, short int *data, int offset){
|
||||
if (data==NULL)
|
||||
return FAIL;
|
||||
|
||||
for (int ichan=0; ichan<nch; ichan++)
|
||||
outfile << ichan+offset << " " << *(data+ichan) << std::endl;
|
||||
|
||||
return OK;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1071,7 +1104,7 @@ int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch, i
|
||||
while (infile.good() and interrupt==0) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< str << std::endl;
|
||||
;//std::cout<< str << std::endl;
|
||||
#endif
|
||||
istringstream ssstr(str);
|
||||
ssstr >> ichan >> idata;
|
||||
@ -1095,7 +1128,7 @@ int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch, i
|
||||
}
|
||||
// }
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "read " << iline <<" channels " << std::endl;
|
||||
;//std::cout<< "read " << iline <<" channels " << std::endl;
|
||||
#endif
|
||||
}
|
||||
return iline;
|
||||
@ -1135,6 +1168,21 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int *data, int offset){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetectorUtils::writeDataFile(string fname, short int *data){
|
||||
|
||||
return writeDataFile(fname, getTotalNumberOfChannels(), data);
|
||||
}
|
||||
|
||||
int slsDetectorUtils::writeDataFile(ofstream &outfile, short int *data, int offset){
|
||||
|
||||
return writeDataFile(outfile, getTotalNumberOfChannels(), data, offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(string fname, float *data, float *err, float *ang, char dataformat) {
|
||||
return readDataFile(getTotalNumberOfChannels(), fname, data, err, ang, dataformat);
|
||||
|
||||
|
@ -176,6 +176,19 @@ class slsDetectorUtils : public slsDetectorBase {
|
||||
virtual int writeDataFile(string fname, int *data);
|
||||
int writeDataFile(ofstream &outfile, int *data, int offset=0);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
writes a data file
|
||||
\param name of the file to be written
|
||||
\param data array of data values
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
\sa mythenDetector::writeDataFile
|
||||
*/
|
||||
virtual int writeDataFile(string fname, short int *data);
|
||||
int writeDataFile(ofstream &outfile, short int *data, int offset=0);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
reads a data file
|
||||
@ -229,7 +242,8 @@ class slsDetectorUtils : public slsDetectorBase {
|
||||
|
||||
static int writeDataFile(string fname, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
static int writeDataFile(ofstream &outfile, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0);
|
||||
/**
|
||||
|
||||
/**
|
||||
|
||||
writes a data file
|
||||
\param name of the file to be written
|
||||
@ -239,7 +253,17 @@ class slsDetectorUtils : public slsDetectorBase {
|
||||
*/
|
||||
static int writeDataFile(string fname,int nch, int *data);
|
||||
static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0);
|
||||
|
||||
/**
|
||||
|
||||
writes a data file
|
||||
\param name of the file to be written
|
||||
\param data array of data values
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
\sa mythenDetector::writeDataFile
|
||||
*/
|
||||
static int writeDataFile(string fname,int nch, short int *data);
|
||||
static int writeDataFile(ofstream &outfile,int nch, short int *data, int offset=0);
|
||||
/**
|
||||
|
||||
reads a data file
|
||||
|
Loading…
x
Reference in New Issue
Block a user