mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
all detectors merged into slsDetector
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@83 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -15,7 +15,9 @@ ID: $Id$
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
@ -50,7 +52,7 @@ int multiSlsDetector::initSharedMemory(int id=0) {
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"multiSlsDetector: Size of shared memory is "<< sz << std::endl;
|
||||
std::cout<<"multiSlsDetector: Size of shared memory is "<< sz << " - id " << mem_key << std::endl;
|
||||
#endif
|
||||
shm_id = shmget(mem_key,sz,IPC_CREAT | 0666); // allocate shared memory
|
||||
|
||||
@ -106,6 +108,7 @@ multiSlsDetector::multiSlsDetector(int id) : shmId(-1)
|
||||
|
||||
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
cout << thisMultiDetector->detectorIds[i] << endl;
|
||||
detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i]);
|
||||
}
|
||||
for (int i=thisMultiDetector->numberOfDetectors; i<MAXDET; i++)
|
||||
@ -126,25 +129,50 @@ multiSlsDetector::~multiSlsDetector() {
|
||||
int multiSlsDetector::addSlsDetector(int id, int pos, int ox, int oy) {
|
||||
int j=thisMultiDetector->numberOfDetectors;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Adding detector " << id << " in position " << pos << endl;
|
||||
#endif
|
||||
|
||||
if (pos<0)
|
||||
pos=j;
|
||||
|
||||
if (pos>j)
|
||||
return thisMultiDetector->numberOfDetectors;
|
||||
pos=thisMultiDetector->numberOfDetectors;
|
||||
|
||||
|
||||
for (int ip=thisMultiDetector->numberOfDetectors-1; ip>pos; ip--) {
|
||||
thisMultiDetector->detectorIds[ip+1]=thisMultiDetector->detectorIds[ip];
|
||||
detectors[ip+1]=detectors[ip];
|
||||
if (pos!=thisMultiDetector->numberOfDetectors) {
|
||||
for (int ip=thisMultiDetector->numberOfDetectors-1; ip>=pos; ip--) {
|
||||
#ifdef VERBOSE
|
||||
cout << "Moving detector " << thisMultiDetector->detectorIds[ip] << " from position " << ip << " to " << ip+1 << endl;
|
||||
#endif
|
||||
thisMultiDetector->detectorIds[ip+1]=thisMultiDetector->detectorIds[ip];
|
||||
detectors[ip+1]=detectors[ip];
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "Creating new detector " << pos << endl;
|
||||
#endif
|
||||
|
||||
detectorType t=slsDetector::getDetectorType(id);
|
||||
detectors[pos]=new slsDetector(t,id);
|
||||
|
||||
// detectorType t=slsDetector::getDetectorType(id);
|
||||
detectors[pos]=new slsDetector(id);
|
||||
thisMultiDetector->detectorIds[pos]=detectors[pos]->getDetectorId();
|
||||
thisMultiDetector->numberOfDetectors++;
|
||||
thisMultiDetector->dataBytes+=detectors[pos]->getDataBytes();
|
||||
thisMultiDetector->numberOfChannels+=detectors[pos]->getNChans()*detectors[pos]->getNChips()*detectors[pos]->getNMods();
|
||||
|
||||
|
||||
|
||||
thisMultiDetector->dataBytes+=detectors[pos]->getDataBytes();
|
||||
|
||||
thisMultiDetector->numberOfChannels+=detectors[pos]->getNChans()*detectors[pos]->getNChips()*detectors[pos]->getNMods();
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Detector added " << thisMultiDetector->numberOfDetectors<< endl;
|
||||
|
||||
for (int ip=0; ip<thisMultiDetector->numberOfDetectors; ip++) {
|
||||
cout << "Detector " << thisMultiDetector->detectorIds[ip] << " position " << ip << " " << detectors[ip]->getHostname() << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return thisMultiDetector->numberOfDetectors;
|
||||
|
||||
}
|
||||
@ -188,6 +216,10 @@ int multiSlsDetector::setDetectorOffset(int pos, int ox, int oy) {
|
||||
int multiSlsDetector::removeSlsDetector(int pos) {
|
||||
int j;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Removing detector in position " << pos << endl;
|
||||
#endif
|
||||
|
||||
if (pos<0 )
|
||||
pos=thisMultiDetector->numberOfDetectors-1;
|
||||
|
||||
@ -1128,7 +1160,11 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
||||
#endif
|
||||
sprintf(ffffname,"%s/%s",thisMultiDetector->flatFieldDir,fname.c_str());
|
||||
nch=readDataFile(string(ffffname),data);
|
||||
if (nch>0) {
|
||||
|
||||
if (nch>thisMultiDetector->numberOfChannels)
|
||||
nch=thisMultiDetector->numberOfChannels;
|
||||
|
||||
if (nch>0) {
|
||||
strcpy(thisMultiDetector->flatFieldFile,fname.c_str());
|
||||
|
||||
|
||||
@ -1292,7 +1328,7 @@ int multiSlsDetector::setRateCorrection(float t){
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl;
|
||||
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
}
|
||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||
@ -1303,7 +1339,7 @@ int multiSlsDetector::getRateCorrection(float &t){
|
||||
|
||||
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisDetector->tDead << std::endl;
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
//which t should we return if they are all different?
|
||||
return 1;
|
||||
@ -1319,7 +1355,7 @@ float multiSlsDetector::getRateCorrectionTau(){
|
||||
|
||||
if (thisMultiDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisDetector->tDead << std::endl;
|
||||
std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||
#endif
|
||||
//which t should we return if they are all different?
|
||||
return 1;
|
||||
@ -1915,6 +1951,197 @@ float multiSlsDetector::getCurrentProgress() {
|
||||
|
||||
|
||||
|
||||
string multiSlsDetector::executeLine(int narg, char *args[], int action) {
|
||||
|
||||
ostringstream os;
|
||||
|
||||
string var=string(args[0]), sval;
|
||||
int ival, ivar;
|
||||
int id;
|
||||
int myId=-1;
|
||||
|
||||
os << "Executing " ;
|
||||
for (int ia=0; ia<narg; ia++)
|
||||
os << args[ia] << " " ;
|
||||
os << " action " << action << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (action==slsDetector::READOUT_ACTION) {
|
||||
os << "Executing readout" << endl;
|
||||
return string("ok");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (var.find("add")==0) {
|
||||
if (var.size()<=4)
|
||||
ivar=-1;
|
||||
else {
|
||||
//return string("syntax is add:i where i is the detector position");
|
||||
istringstream vvstr(var.substr(9));
|
||||
vvstr >> ivar;
|
||||
if (vvstr.fail())
|
||||
ivar=-1; //append at the end
|
||||
//return string("syntax is add:i where i is the detector position");
|
||||
}
|
||||
if (action==slsDetector::PUT_ACTION) {
|
||||
// if (ivar>thisMultiDetector->numberOfDetectors || ivar<0) {
|
||||
// ivar=thisMultiDetector->numberOfDetectors;
|
||||
// cout << "Appending detector " << endl;
|
||||
//}
|
||||
|
||||
if (sscanf(args[1],"%d",&ival)) {
|
||||
// add by detector id
|
||||
#ifdef VERBOSE
|
||||
cout << "Add detector by id " << thisMultiDetector->numberOfDetectors << endl;
|
||||
#endif
|
||||
|
||||
for (id=0; id<thisMultiDetector->numberOfDetectors; id++) {
|
||||
//check that it is not already in the list, in that case move to new position
|
||||
if (detectors[id]) {
|
||||
if (detectors[id]->getDetectorId()==ival) {
|
||||
cout << "Detector " << id << "exists!" << endl;
|
||||
if (id==ivar)
|
||||
break;
|
||||
if (id==(thisMultiDetector->numberOfDetectors-1) && ivar==-1)
|
||||
break;
|
||||
removeSlsDetector(id);
|
||||
addSlsDetector(ival, ivar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id==thisMultiDetector->numberOfDetectors) {
|
||||
if (slsDetector::exists(ivar)==0) {
|
||||
return string("Detector does not exist - You should first create it to determine type etc.");
|
||||
}
|
||||
addSlsDetector(ival, ivar);
|
||||
}
|
||||
// if it does not already exist create it
|
||||
} else {
|
||||
//add by hostname
|
||||
#ifdef VERBOSE
|
||||
cout << "Adding " << args[1] << " in position " << ivar << endl;
|
||||
#endif
|
||||
|
||||
for (id=0; id<thisMultiDetector->numberOfDetectors; id++) {
|
||||
//check that it is not already in the list, in that case move to new position
|
||||
if (detectors[id]) {
|
||||
#ifdef VERBOSE
|
||||
cout << "Detector " << id << " is " << detectors[id]->getHostname() << endl;
|
||||
#endif
|
||||
if (detectors[id]->getHostname()==string(args[1])) {
|
||||
#ifdef VERBOSE
|
||||
cout << "Detector " << id << " exists!" << endl;
|
||||
#endif
|
||||
if (id==ivar)
|
||||
break;
|
||||
if (id==(thisMultiDetector->numberOfDetectors-1) && ivar==-1)
|
||||
break;
|
||||
myId=detectors[id]->getDetectorId();
|
||||
removeSlsDetector(id);
|
||||
addSlsDetector(myId, ivar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id==thisMultiDetector->numberOfDetectors) {
|
||||
detectorType t=slsDetector::getDetectorType(args[1], DEFAULT_PORTNO);
|
||||
if (t==GENERIC)
|
||||
return string("could not connect to detector to determine type");
|
||||
#ifdef VERBOSE
|
||||
else
|
||||
cout << "Detector type is " << t << endl;
|
||||
#endif
|
||||
myId=10;
|
||||
slsDetector *s=NULL;
|
||||
while (slsDetector::exists(myId)>0) {
|
||||
cout << myId << endl;
|
||||
s=new slsDetector(myId);
|
||||
if (s->getHostname()==string(args[1]))
|
||||
break;
|
||||
delete s;
|
||||
s=NULL;
|
||||
myId++;
|
||||
}
|
||||
// if it does not already exist create it
|
||||
if (s==NULL) {
|
||||
#ifdef VERBOSE
|
||||
cout << "Creating new detector with id " << myId << endl;
|
||||
#endif
|
||||
s=new slsDetector(t, myId);
|
||||
s->setTCPSocket(args[1]);
|
||||
delete s;
|
||||
}
|
||||
addSlsDetector(myId, ivar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} else if (var.find("hostname")==0) {
|
||||
|
||||
if (var.size()<=9)
|
||||
return string("syntax is hostname:i where i is the detector id");
|
||||
istringstream vvstr(var.substr(9));
|
||||
vvstr >> ival;
|
||||
if (vvstr.fail())
|
||||
return string("syntax is hostname:i where i is the detector id");
|
||||
if (action==slsDetector::PUT_ACTION) {
|
||||
sval=string(args[1]);
|
||||
os << "setting hostname of detector " << ival << " to " << sval << endl;
|
||||
//cout << slsDetector::getDetectorType(args[1], DEFAULT_PORTNO) << endl;
|
||||
|
||||
//controlla che non esista gia'
|
||||
// se esiste modifica l'hostname, altrimenti aggiungilo in coda
|
||||
|
||||
|
||||
|
||||
}
|
||||
os << "getting hostname of detector " << ival << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
string multiSlsDetector::helpLine(int action) {
|
||||
ostringstream os;
|
||||
|
||||
os << "This is the help line of action " << action << endl;
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -431,7 +431,6 @@ class multiSlsDetector {
|
||||
int writeDataFile(string fname, int *data);
|
||||
|
||||
/**
|
||||
|
||||
reads a data file
|
||||
\param name of the file to be read
|
||||
\param data array of data values to be filled
|
||||
@ -444,7 +443,7 @@ class multiSlsDetector {
|
||||
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0);
|
||||
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0) {return slsDetector::readDataFile(nch, fname, data, err, ang, dataformat);}
|
||||
|
||||
/**
|
||||
|
||||
@ -454,7 +453,7 @@ class multiSlsDetector {
|
||||
\returns OK or FAIL if it could not read the file or data=NULL
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
int readDataFile(string fname, int *data);
|
||||
int readDataFile(string fname, int *data){slsDetector::readDataFile(fname,data,thisMultiDetector->numberOfChannels);};
|
||||
|
||||
|
||||
/**
|
||||
@ -463,7 +462,7 @@ class multiSlsDetector {
|
||||
\param fname file to be read
|
||||
\sa angleConversionConstant mythenDetector::readAngularConversion
|
||||
*/
|
||||
virtual int readAngularConversion(string fname="", int id=-1);
|
||||
/////////////////////////////// virtual int readAngularConversion(string fname="", int id=-1);
|
||||
|
||||
|
||||
|
||||
@ -473,7 +472,7 @@ class multiSlsDetector {
|
||||
\param fname file to be written
|
||||
\sa angleConversionConstant mythenDetector::writeAngularConversion
|
||||
*/
|
||||
virtual int writeAngularConversion(string fname="", int id=-1);
|
||||
/////////////////////////////////////////virtual int writeAngularConversion(string fname="", int id=-1);
|
||||
|
||||
|
||||
|
||||
@ -807,7 +806,7 @@ s
|
||||
\returns 0 if angular conversion disabled, >0 otherwise
|
||||
\sa mythenDetector::setAngularConversion
|
||||
*/
|
||||
virtual int setAngularConversion(string fname="")=0;
|
||||
/////////////////////////////////////////////////// virtual int setAngularConversion(string fname="");
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
@ -817,41 +816,41 @@ s
|
||||
\returns 0 if angular conversion disabled, >0 otherwise
|
||||
\sa mythenDetector::getAngularConversion
|
||||
*/
|
||||
virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0;
|
||||
/////////////////////////////////////////////////// virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL);
|
||||
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
returns the angular conversion file
|
||||
\sa mythenDetector::getAngularConversion */
|
||||
virtual string getAngularConversion()=0;
|
||||
/////////////////////////////////////////////////// virtual string getAngularConversion();
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
set detector global offset
|
||||
\sa mythenDetector::setGlobalOffset
|
||||
*/
|
||||
virtual float setGlobalOffset(float f)=0;
|
||||
/////////////////////////////////////////////////// virtual float setGlobalOffset(float f);
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
set detector fine offset
|
||||
\sa mythenDetector::setFineOffset
|
||||
*/
|
||||
virtual float setFineOffset(float f)=0;
|
||||
/////////////////////////////////////////////////// virtual float setFineOffset(float f);
|
||||
/**
|
||||
pure virtual function
|
||||
get detector fine offset
|
||||
\sa mythenDetector::getFineOffset
|
||||
*/
|
||||
virtual float getFineOffset()=0;
|
||||
/////////////////////////////////////////////////// virtual float getFineOffset();
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
get detector global offset
|
||||
\sa mythenDetector::getGlobalOffset
|
||||
*/
|
||||
virtual float getGlobalOffset()=0;
|
||||
/////////////////////////////////////////////////// virtual float getGlobalOffset();
|
||||
|
||||
/**
|
||||
pure virtual function
|
||||
@ -861,7 +860,7 @@ s
|
||||
\returns number of positions
|
||||
\sa mythenDetector::setPositions
|
||||
*/
|
||||
virtual int setPositions(int nPos, float *pos)=0;
|
||||
/////////////////////////////////////////////////// virtual int setPositions(int nPos, float *pos);
|
||||
/**
|
||||
pure virtual function
|
||||
get positions for the acquisition
|
||||
@ -869,7 +868,7 @@ s
|
||||
\returns number of positions
|
||||
\sa mythenDetector::getPositions
|
||||
*/
|
||||
virtual int getPositions(float *pos=NULL)=0;
|
||||
/////////////////////////////////////////////////// virtual int getPositions(float *pos=NULL);
|
||||
|
||||
|
||||
/** pure virtual function
|
||||
@ -878,13 +877,13 @@ s
|
||||
\returns current bin size
|
||||
\sa mythenDetector::setBinSize
|
||||
*/
|
||||
virtual float setBinSize(float bs)=0;
|
||||
/////////////////////////////////////////////////// virtual float setBinSize(float bs);
|
||||
|
||||
/** pure virtual function
|
||||
return detector bin size used for merging (approx angular resolution)
|
||||
\sa mythenDetector::getBinSize
|
||||
*/
|
||||
virtual float getBinSize()=0;
|
||||
/////////////////////////////////////////////////// virtual float getBinSize();
|
||||
|
||||
|
||||
|
||||
@ -1058,7 +1057,7 @@ s
|
||||
\returns OK or FAIL
|
||||
\sa mythenDetector::resetMerging
|
||||
*/
|
||||
virtual int resetMerging(float *mp, float *mv,float *me, int *mm)=0;
|
||||
/////////////////////////////////////////////////// virtual int resetMerging(float *mp, float *mv,float *me, int *mm);
|
||||
/**
|
||||
pure virtual function
|
||||
merge dataset
|
||||
@ -1071,7 +1070,7 @@ s
|
||||
\param mm multiplicity of merged arrays
|
||||
\sa mythenDetector::addToMerging
|
||||
*/
|
||||
virtual int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm)=0;
|
||||
/////////////////////////////////////////////////// virtual int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm);
|
||||
|
||||
/** pure virtual function
|
||||
calculates the "final" positions, data value and errors for the emrged data
|
||||
@ -1089,15 +1088,15 @@ s
|
||||
*/
|
||||
int exitServer();
|
||||
|
||||
/** pure virtual function
|
||||
/** pure /////////////////////////////////////////////////// virtual function
|
||||
function for processing data
|
||||
/param delflag if 1 the data are processed, written to file and then deleted. If 0 they are added to the finalDataQueue
|
||||
\sa mythenDetector::processData
|
||||
*/
|
||||
virtual void* processData(int delflag=1)=0; // thread function
|
||||
/////////////////////////////////////////////////// virtual void* processData(int delflag=1); // thread function
|
||||
|
||||
|
||||
virtual void acquire(int delflag=1)=0;
|
||||
/////////////////////////////////////////////////// virtual void acquire(int delflag=1);
|
||||
|
||||
/** calcualtes the total number of steps of the acquisition.
|
||||
called when number of frames, number of cycles, number of positions and scan steps change
|
||||
@ -1108,6 +1107,28 @@ s
|
||||
float getCurrentProgress();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string executeLine(int narg, char *args[], int action=slsDetector::GET_ACTION);
|
||||
|
||||
|
||||
|
||||
static string helpLine(int action=slsDetector::GET_ACTION);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user