Detectors types can (should) be configured in the multiSlsDetector structure

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@181 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2012-05-22 12:24:15 +00:00
parent 83ee449e3c
commit 0bab16cde7
13 changed files with 650 additions and 248 deletions

View File

@ -125,6 +125,8 @@ slsDetector::slsDetector(int id) :slsDetectorUtils(),
{
detectorType type=(detectorType)getDetectorType(id);
while (shmId<0) {
@ -220,7 +222,6 @@ slsDetector::slsDetector(char *name, int id, int cport) : slsDetectorUtils(),
chipregs(NULL),
chanregs(NULL)
{
detectorType type=(detectorType)getDetectorType(name, cport);
@ -252,7 +253,7 @@ slsDetector::slsDetector(char *name, int id, int cport) : slsDetectorUtils(),
}
slsDetectorDefs::detectorType slsDetector::getDetectorType(char *name, int cport) {
slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cport) {
int retval=FAIL;
detectorType t=GENERIC;
@ -433,9 +434,14 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(int id) {
int slsDetector::initializeDetectorSize(detectorType type) {
char *goff;
goff=(char*)thisDetector;
// cout << "init detector size" << endl;
/** if the shared memory has newly be created, initialize the detector variables */
if (thisDetector->alreadyExisting==0) {
// cout << "detector not existing " << endl;
/** set hostname to default */
strcpy(thisDetector->hostname,DEFAULT_HOSTNAME);
@ -464,6 +470,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=24;
thisDetector->moveFlag=1;
cout << "move flag" << thisDetector->moveFlag<< endl;
break;
case PICASSO:
thisDetector->nChans=128;
@ -620,35 +627,6 @@ int slsDetector::initializeDetectorSize(detectorType type) {
#endif
// getPointers(&thisDetector->stoppedFlag, \
// &thisDetector->threadedProcessing, \
// &thisDetector->actionMask, \
// thisDetector->actionScript, \
// thisDetector->actionParameter, \
// thisDetector->nScanSteps, \
// thisDetector->scanMode, \
// thisDetector->scanScript, \
// thisDetector->scanParameter, \
// thisDetector->scanSteps, \
// thisDetector->scanPrecision, \
// &thisDetector->numberOfPositions, \
// thisDetector->detPositions, \
// thisDetector->angConvFile, \
// &thisDetector->correctionMask, \
// &thisDetector->binSize, \
// &thisDetector->fineOffset, \
// &thisDetector->globalOffset, \
// &thisDetector->angDirection, \
// thisDetector->flatFieldDir, \
// thisDetector->flatFieldFile, \
// thisDetector->badChanFile, \
// thisDetector->timerValue, \
// &thisDetector->currentSettings, \
// &thisDetector->currentThresholdEV, \
// thisDetector->filePath, \
// thisDetector->fileName, \
// &thisDetector->fileIndex);
stoppedFlag=&thisDetector->stoppedFlag;
threadedProcessing=&thisDetector->threadedProcessing;
actionMask=&thisDetector->actionMask;
@ -686,21 +664,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
#ifdef VERBOSE
cout << "done" << endl;
#endif
// #ifdef VERBOSE
// cout << "filling bad channel mask" << endl;
// #endif
// /** fill the BadChannelMask \sa fillBadChannelMask */
// fillBadChannelMask();
// #ifdef VERBOSE
// cout << "done" << endl;
// #endif
/** modifies the last PID accessing the detector */
thisDetector->lastPID=getpid();
#ifdef VERBOSE
cout << "Det size initialized " << endl;
#endif
return OK;
}
@ -4915,7 +4887,7 @@ int slsDetector::writeConfigurationFile(string const fname){
}
int slsDetector::writeConfigurationFile(ofstream &outfile){
int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
slsDetectorCommand *cmd=new slsDetectorCommand(this);
int nvar;
@ -4938,6 +4910,8 @@ int slsDetector::writeConfigurationFile(ofstream &outfile){
"nmod", \
"badchannels", \
"angconv", \
"angdir", \
"moveflag", \
"globaloff", \
"binsize", \
"threaded", \
@ -4957,7 +4931,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile){
case MYTHEN:
nsig=4;
default:
nvar=23;
nvar=25;
}
@ -4969,14 +4943,19 @@ int slsDetector::writeConfigurationFile(ofstream &outfile){
for (iv=0; iv<nvar; iv++) {
cout << iv << " " << names[iv] << endl;
// cout << iv << " " << names[iv] << endl;
if (names[iv]=="extsig") {
for (int is=0; is<nsig; is++) {
sprintf(args[0],"%s:%d",names[iv].c_str(),is);
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
}
} else {
strcpy(args[0],names[iv].c_str());
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
}
}
@ -5001,7 +4980,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile){
It should be possible to dump all the settings of the detector (including trimbits, threshold energy, gating/triggering, acquisition time etc.
in a file and retrieve it for repeating the measurement with identicals settings, if necessary
*/
int slsDetector::dumpDetectorSetup(string const fname, int level){
int slsDetector::dumpDetectorSetup(string const fname, ofstream &outfile, int level, int id){
slsDetectorCommand *cmd=new slsDetectorCommand(this);
string names[]={
"fname",\
@ -5049,7 +5028,6 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
int nvar=41;
int iv=0;
string fname1;
ofstream outfile;
char *args[2];
for (int ia=0; ia<2; ia++) {
args[ia]=new char[1000];
@ -5061,71 +5039,127 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
nargs=1;
if (level==2) {
fname1=fname+string(".config");
writeConfigurationFile(fname1);
strcpy(args[0],"config");
strcpy(args[1],fname1.c_str());
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(2,args,GET_ACTION) << std::endl;
iv++;
}
for (iv=0; iv<nvar-5; iv++) {
strcpy(args[0],names[iv].c_str());
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
iv++;
}
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".ff");
strcpy(args[1],fname1.c_str());
}
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".bad");
strcpy(args[1],fname1.c_str());
}
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".angoff");
strcpy(args[1],fname1.c_str());
}
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
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(args[1],fname1.c_str());
#ifdef VERBOSE
std::cout<< "writing to file " << fname1 << std::endl;
#endif
}
if (id>=0)
outfile << id << ":";
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
// for (int is=0; is<4; is++) {
// sprintf(args[0],"%s:%d",names[iv].c_str(),is);
if (id>=0)
outfile << id << ":";
outfile << args[0] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
// }
iv++;
delete cmd;
return 0;
}
/*
It should be possible to dump all the settings of the detector (including trimbits, threshold energy, gating/triggering, acquisition time etc.
in a file and retrieve it for repeating the measurement with identicals settings, if necessary
*/
int slsDetector::dumpDetectorSetup(string const fname, int level){
string fname1;
ofstream outfile;
if (level==2) {
fname1=fname+string(".det");
} else
fname1=fname;
outfile.open(fname1.c_str(),ios_base::out);
if (outfile.is_open()) {
for (iv=0; iv<nvar-5; iv++) {
strcpy(args[0],names[iv].c_str());
outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
}
dumpDetectorSetup(fname, outfile, level);
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".ff");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".bad");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
fname1=fname+string(".angoff");
strcpy(args[1],fname1.c_str());
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
if (level==2) {
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(args[1],fname1.c_str());
#ifdef VERBOSE
std::cout<< "writing to file " << fname1 << std::endl;
#endif
}
outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl;
iv++;
strcpy(args[0],names[iv].c_str());
// for (int is=0; is<4; is++) {
// sprintf(args[0],"%s:%d",names[iv].c_str(),is);
outfile << args[0] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl;
// }
iv++;
outfile.close();
}
else {
} else {
std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl;
return FAIL;
}
@ -5133,12 +5167,55 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
#ifdef VERBOSE
std::cout<< "wrote " <<iv << " lines to "<< fname1 << std::endl;
#endif
delete cmd;
return 0;
}
int slsDetector::retrieveDetectorSetup(string fname1, int level){

View File

@ -270,11 +270,8 @@ typedef struct sharedSlsDetector {
*/
slsDetector(detectorType type=GENERIC, int id=0);
/** constructor
/** constructor
\param id is the detector index which is needed to define the shared memory id. Different physical detectors should have different IDs in order to work independently
*/
slsDetector(int id);
@ -321,8 +318,7 @@ typedef struct sharedSlsDetector {
*/
int writeConfigurationFile(string const fname);
int writeConfigurationFile(ofstream &outfile);
int writeConfigurationFile(ofstream &outfile, int id=-1);
@ -336,6 +332,9 @@ typedef struct sharedSlsDetector {
*/
int dumpDetectorSetup(string const fname, int level=0);
int dumpDetectorSetup(string const fname, ofstream &outfile, int level=0, int id=-1);
/**
Loads the detector setup from file
\param fname file to read from
@ -389,7 +388,7 @@ typedef struct sharedSlsDetector {
/** returns the detector hostname \sa sharedSlsDetector */
string getHostname(int ipos=-1) {return string(thisDetector->hostname);};
/** returns the detector hostname \sa sharedSlsDetector */
string setHostname(char *name, int ipos=-1) {setTCPSocket(string(name)); return string(thisDetector->hostname);};
string setHostname(const char *name, int ipos=-1) {setTCPSocket(string(name)); return string(thisDetector->hostname);};
/** connect to the control port */
int connectControl();
/** disconnect from the control port */
@ -607,6 +606,12 @@ typedef struct sharedSlsDetector {
*/
detectorType getDetectorsType(int pos=-1);
detectorType setDetectorsType(detectorType type=GET_DETECTOR_TYPE, int pos=-1){return getDetectorsType(pos);};
string sgetDetectorsType(int pos=-1){return getDetectorType(getDetectorsType(pos));};
string ssetDetectorsType(detectorType type=GET_DETECTOR_TYPE, int pos=-1){return getDetectorType(getDetectorsType(pos));};
string ssetDetectorsType(string t, int pos=-1){return getDetectorType(getDetectorsType(pos));}
// Detector configuration functions
/**
@ -1255,7 +1260,7 @@ typedef struct sharedSlsDetector {
\param
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
*/
static detectorType getDetectorType(char *name, int cport=DEFAULT_PORTNO);
static detectorType getDetectorType(const char *name, int cport=DEFAULT_PORTNO);
/**
returns the detector type from hostname and controlport
@ -1338,6 +1343,8 @@ typedef struct sharedSlsDetector {
int getMoveFlag(int imod){if (moveFlag) return *moveFlag; else return 1;};
/** Frees the shared memory - should not be used*/
int freeSharedMemory();
protected:
@ -1401,8 +1408,6 @@ typedef struct sharedSlsDetector {
*/
int initSharedMemory(detectorType type=GENERIC, int id=0);
/** Frees the shared memory - should not be used*/
int freeSharedMemory();
/**
Initializes the thisDetector structure
\param type is needed to define the number of channels, chips, modules etc.

View File

@ -53,6 +53,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
i++;
descrToFuncMap[i].m_pFuncName="type"; //OK
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdHostname;
i++;
descrToFuncMap[i].m_pFuncName="hostname"; //OK
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdHostname;
i++;
@ -929,23 +933,44 @@ string slsDetectorCommand::cmdHostname(int narg, char *args[], int action){
if (vvstr.fail())
ivar=-1;
}
p=string(args[0]).find("hostname");
if (action==PUT_ACTION) {
//add by hostname
if (ivar==-1) {
strcpy(hostname,"");
for (int id=1; id<narg; id++) {
strcat(hostname,args[id]);
if(narg>2)
strcat(hostname,"+");
}
} else
strcpy(hostname,args[1]);
myDet->setHostname(hostname, ivar);
}
return string(myDet->getHostname(ivar));
if (p==string::npos) {
//type
// cout << "should add by type!" << endl;
if (action==PUT_ACTION) {
//add by type
if (ivar==-1) {
strcpy(hostname,"");
for (int id=1; id<narg; id++) {
strcat(hostname,args[id]);
if(narg>2)
strcat(hostname,"+");
}
} else
strcpy(hostname,args[1]);
myDet->ssetDetectorsType(hostname, ivar);
}
return myDet->sgetDetectorsType(ivar);
} else {
if (action==PUT_ACTION) {
//add by hostname
if (ivar==-1) {
strcpy(hostname,"");
for (int id=1; id<narg; id++) {
strcat(hostname,args[id]);
if(narg>2)
strcat(hostname,"+");
}
} else
strcpy(hostname,args[1]);
myDet->setHostname(hostname, ivar);
}
return string(myDet->getHostname(ivar));
}
}

View File

@ -11,7 +11,7 @@ using namespace std;
/** @short This class handles the command line I/Os, help etc. of the text clients */
class slsDetectorCommand : public slsDetectorDefs {
class slsDetectorCommand : public virtual slsDetectorDefs {
public:
@ -26,7 +26,7 @@ class slsDetectorCommand : public slsDetectorDefs {
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
/* \returns answer string */
/* *\/ */
string executeLine(int narg, char *args[], int action=HELP_ACTION);
virtual string executeLine(int narg, char *args[], int action);
/* /\** */
/* returns the help for the executeLine command */

View File

@ -107,7 +107,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
\param pos position in the multi detector structure (is -1 expects concatenated hostnames divided by a +)
\returns hostname
*/
virtual string setHostname(char* name, int pos=-1)=0;
virtual string setHostname(const char* name, int pos=-1)=0;
/** returns the detector type
@ -116,6 +116,20 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
virtual detectorType getDetectorsType(int pos=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual string sgetDetectorsType(int pos=-1)=0;
/** returns the detector type
\param pos position in the multi detector structure (is -1 returns type of detector with id -1)
\returns type
*/
virtual detectorType setDetectorsType(detectorType t=GET_DETECTOR_TYPE, int pos=-1)=0;
virtual string ssetDetectorsType(detectorType t=GET_DETECTOR_TYPE, int pos=-1)=0;
virtual string ssetDetectorsType(string s, int pos=-1)=0;
/** Gets the detector id (shared memory id) of an slsDetector