Raw data file write/read now uses absolute channel values in multidetector systems. Flat field and bad channel corrections and angular conversion debugged

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@135 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-03-02 11:01:53 +00:00
parent 5e086b9ee6
commit 461fd8824f
9 changed files with 709 additions and 207 deletions

View File

@ -1,14 +1,12 @@
CFLAGS= -DC_ONLY
FLAGS=-DVERBOSE
INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand
#-I eigerDetector -ImythenDetector -IgotthardDetector
#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.c multiSlsDetector/multiSlsDetector.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp
#mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp
SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c mythenDetectorServer/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c
#mythenDetectorServer/sharedmemory.c
all: package mythenServer doc picassoServer
@ -30,13 +28,12 @@ picassoServer: $(SRC_MYTHEN_SVC)
package: $(SRC_CLNT)
$(CXX) -fPIC -g -o objs/slsDetectorCommand.o -c -Wall slsDetector/slsDetectorCommand.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/slsDetectorUtils.o -c -Wall slsDetector/slsDetectorUtils.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/slsDetectorUtils.o -c -Wall slsDetector/slsDetectorUtils.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/multiSlsDetector.o -c -Wall multiSlsDetector/multiSlsDetector.cpp $(INCLUDES) $(FLAGS)
$(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
$(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
$(CXX) -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cpp $(INCLUDES) $(FLAGS)
$(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o objs/multiSlsDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
#objs/mythenDetector.o objs/gotthardDetector.o
ln -sf libSlsDetector.so libSlsDetector.so.1
ln -sf libSlsDetector.so libSlsDetector.so.1.0.1
ar rcs libSlsDetector.a objs/slsDetector.o objs/usersFunctions.o objs/MySocketTCP.o objs/multiSlsDetector.o objs/slsDetectorUtils.o objs/slsDetectorCommand.o

View File

@ -105,6 +105,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
thisMultiDetector->dataBytes=0;
thisMultiDetector->numberOfChannels=0;
thisMultiDetector->maxNumberOfChannels=0;
@ -225,15 +226,15 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
&thisMultiDetector->fileIndex);
#ifdef VERBOSE
cout << "filling bad channel mask" << endl;
#endif
/** fill the BadChannelMask \sa fillBadChannelMask */
fillBadChannelMask();
// #ifdef VERBOSE
// cout << "filling bad channel mask" << endl;
// #endif
// /** fill the BadChannelMask \sa fillBadChannelMask */
// fillBadChannelMask();
#ifdef VERBOSE
cout << "done" << endl;
#endif
// #ifdef VERBOSE
// cout << "done" << endl;
// #endif
}
@ -297,7 +298,8 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
thisMultiDetector->dataBytes+=detectors[pos]->getDataBytes();
thisMultiDetector->numberOfChannels+=detectors[pos]->getNChans()*detectors[pos]->getNChips()*detectors[pos]->getNMods();
thisMultiDetector->numberOfChannels+=detectors[pos]->getTotalNumberOfChannels();
thisMultiDetector->maxNumberOfChannels-=detectors[j]->getMaxNumberOfChannels();
#ifdef VERBOSE
cout << "Detector added " << thisMultiDetector->numberOfDetectors<< endl;
@ -528,7 +530,8 @@ int multiSlsDetector::removeSlsDetector(int pos) {
if (detectors[j]) {
thisMultiDetector->dataBytes-=detectors[j]->getDataBytes();
thisMultiDetector->numberOfChannels-=detectors[j]->getNChans()*detectors[pos]->getNChips()*detectors[pos]->getNMods();
thisMultiDetector->numberOfChannels-=detectors[j]->getTotalNumberOfChannels();
thisMultiDetector->maxNumberOfChannels-=detectors[j]->getMaxNumberOfChannels();
delete detectors[j];
thisMultiDetector->numberOfDetectors--;
@ -738,7 +741,7 @@ int multiSlsDetector::getThresholdEnergy(int pos) {
ret=detectors[i]->getThresholdEnergy();
if (ret1==-100)
ret1=ret;
else if (ret!=ret1)
else if (ret<(ret1-200) || ret>(ret1+200))
ret1=FAIL;
}
@ -767,11 +770,17 @@ int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings ise
for (i=posmin; i<posmax; i++) {
if (detectors[i]) {
ret=detectors[i]->setThresholdEnergy(e_eV,-1,isettings);
#ifdef VERBOSE
cout << "detetcor " << i << " threshold " << ret << endl;
#endif
if (ret1==-100)
ret1=ret;
else if (ret!=ret1)
else if (ret<(ret1-200) || ret>(ret1+200))
ret1=FAIL;
#ifdef VERBOSE
cout << "return value " << ret1 << endl;
#endif
}
}
@ -1350,14 +1359,14 @@ float* multiSlsDetector::decodeData(int *datain) {
float *dataout=new float[thisMultiDetector->numberOfChannels];
int ich=0;
float *detp;
int *datap=datain;
int *datap=datain;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
detp=detectors[i]->decodeData(datap);
datap+=detectors[i]->getDataBytes();
for (int j=0; j<detectors[i]->getNChans()*detectors[i]->getNChips()*detectors[i]->getNMods(); j++) {
datap+=detectors[i]->getDataBytes()/sizeof(int);
for (int j=0; j<detectors[i]->getTotalNumberOfChannels(); j++) {
dataout[ich]=detp[j];
ich++;
}
@ -1429,7 +1438,7 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
for (int ichan=0; ichan<nch; ichan++) {
if (detectors[idet]) {
if (ichdet>=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods()) {
if (ichdet>=detectors[idet]->getTotalNumberOfChannels()) {
ichdet=0;
detectors[idet]->setBadChannelCorrection(nbad,badlist,1);
idet++;
@ -1468,13 +1477,18 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
idet=0;
ichdet=0;
int detoff=0;
for (int ichan=0; ichan<nch; ichan++) {
if (detectors[idet]) {
if (ichdet>=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods()) {
detectors[idet]->setFlatFieldCorrection(ffcoefficients+ichdet, fferrors+ichdet);
ichdet=ichan;
if (ichdet>=detectors[idet]->getTotalNumberOfChannels()) {
#ifdef VERBOSE
cout << "Set flat field detector " << idet << "(offset "<< detoff << ")" << endl;
#endif
detectors[idet]->setFlatFieldCorrection(ffcoefficients+detoff, fferrors+detoff);
ichdet=0;//ichan;
detoff=ichan;
idet++;
}
}
@ -1487,9 +1501,13 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
ffcoefficients[ichan]=0.;
fferrors[ichan]=1.;
}
ichdet++;
}
if (detectors[idet]) {
detectors[idet]->setFlatFieldCorrection(ffcoefficients+ichdet, fferrors+ichdet);
#ifdef VERBOSE
cout << "**Set flat field detector " << idet << "(offset "<< detoff << ")" << endl;
#endif
detectors[idet]->setFlatFieldCorrection(ffcoefficients+detoff, fferrors+detoff);
}
} else {
std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl;
@ -1500,7 +1518,7 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
}
return -1;
}
} else {
} else {
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
thisMultiDetector->correctionMask&=~(1<<FLAT_FIELD_CORRECTION);
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
@ -1531,7 +1549,7 @@ int multiSlsDetector::setFlatFieldCorrection(float *corr, float *ecorr) {
else
ep=NULL;
detectors[idet]->setFlatFieldCorrection(p, ep);
ichdet+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
ichdet+=detectors[idet]->getTotalNumberOfChannels();
}
}
return 0;
@ -1559,7 +1577,7 @@ int multiSlsDetector::getFlatFieldCorrection(float *corr, float *ecorr) {
else
ep=NULL;
detectors[idet]->getFlatFieldCorrection(p, ep);
ichdet+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
ichdet+=detectors[idet]->getTotalNumberOfChannels();
}
}
return 0;
@ -1590,10 +1608,16 @@ int multiSlsDetector::getFlatFieldCorrection(float *corr, float *ecorr) {
int multiSlsDetector::flatFieldCorrect(float* datain, float *errin, float* dataout, float *errout){
int ichdet=0;
float *pdata, *perr=errin;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
detectors[idet]->flatFieldCorrect(datain+ichdet, errin+ichdet, dataout+ichdet, errout+ichdet);
ichdet+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
#ifdef VERBOSE
cout << " detector " << idet << " offset " << ichdet << endl;
#endif
if (errin)
perr+=ichdet;
detectors[idet]->flatFieldCorrect(datain+ichdet, perr, dataout+ichdet, errout+ichdet);
ichdet+=detectors[idet]->getTotalNumberOfChannels();//detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
}
}
return 0;
@ -1677,10 +1701,13 @@ int multiSlsDetector::getRateCorrection(){
int multiSlsDetector::rateCorrect(float* datain, float *errin, float* dataout, float *errout){
int ichdet=0;
float *perr=errin;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
detectors[idet]->rateCorrect(datain+ichdet, errin+ichdet, dataout+ichdet, errout+ichdet);
ichdet+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
if (errin)
perr+=ichdet;
detectors[idet]->rateCorrect(datain+ichdet, perr, dataout+ichdet, errout+ichdet);
ichdet+=detectors[idet]->getTotalNumberOfChannels();
}
}
return 0;
@ -1696,9 +1723,16 @@ int multiSlsDetector::setBadChannelCorrection(string fname){
fname=string(thisMultiDetector->badChanFile);
int ret=setBadChannelCorrection(fname, nbad, badlist);
if (ret==0)
#ifdef VERBOSE
cout << "file contained " << ret << " badcahns" << endl;
#endif
if (ret==0) {
thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
nbad=0;
} else {
thisMultiDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS);
strcpy(thisMultiDetector->badChanFile,fname.c_str());
}
return setBadChannelCorrection(nbad,badlist,0);
@ -1717,9 +1751,12 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
for (int ich=0; ich<nbad; ich++) {
if (detectors[idet]) {
while ((badlist[ich]-choff)>=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods()) {
if ((badlist[ich]-choff)>=detectors[idet]->getTotalNumberOfChannels()) {
#ifdef VERBOSE
cout << "setting " << nbaddet << " badchans to detector " << idet << endl;
#endif
detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0);
choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
choff+=detectors[idet]->getTotalNumberOfChannels();
nbaddet=0;
idet++;
if (detectors[idet]==NULL)
@ -1727,10 +1764,26 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
}
badlistdet[nbaddet]=(badlist[ich]-choff);
nbaddet++;
cout << nbaddet << " " << badlist[ich] << " " << badlistdet[nbaddet-1] << endl;
}
}
if (nbaddet>0) {
if (detectors[idet]) {
#ifdef VERBOSE
cout << "setting " << nbaddet << " badchans to detector " << idet << endl;
#endif
detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0);
choff+=detectors[idet]->getTotalNumberOfChannels();
nbaddet=0;
idet++;
}
}
nbaddet=0;
for (int i=idet; i<thisMultiDetector->numberOfDetectors; i++) {
#ifdef VERBOSE
cout << "setting " << 0 << " badchans to detector " << i << endl;
#endif
if (detectors[i]) {
detectors[i]->setBadChannelCorrection(nbaddet,badlist,0);
}
@ -1740,12 +1793,17 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
nbaddet=0;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[idet]) {
#ifdef VERBOSE
cout << "setting " << 0 << " badchans to detector " << idet << endl;
#endif
detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0);
}
}
thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
}
#ifdef VERBOSE
cout << (thisMultiDetector->correctionMask&(1<<DISCARD_BAD_CHANNELS)) << endl;
#endif
return thisMultiDetector->correctionMask&(1<<DISCARD_BAD_CHANNELS);
}
@ -1784,6 +1842,9 @@ int multiSlsDetector::readAngularConversion(string fname) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
#ifdef VERBOSE
cout << " detector " << idet << endl;
#endif
detectors[idet]->readAngularConversion(infile);
}
}
@ -1918,6 +1979,24 @@ int multiSlsDetector::setChannel(long long reg, int ichan, int ichip, int imod)
/**
sets the value of s angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\param v the value to be set
\returns the actual value
*/
float multiSlsDetector::setAngularConversionParameter(angleConversionParameter c, float v) {
float ret=slsDetectorUtils::setAngularConversionParameter(c,v);
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
detectors[idet]->setAngularConversionParameter(c,v);
}
}
return ret;
}
@ -1931,10 +2010,10 @@ float* multiSlsDetector::convertAngles(float pos) {
if (detectors[idet]) {
p=detectors[idet]->convertAngles(pos);
for (int ich=0; ich<detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods(); ich++) {
for (int ich=0; ich<detectors[idet]->getTotalNumberOfChannels(); ich++) {
ang[choff+ich]=p[ich];
}
choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
choff+=detectors[idet]->getTotalNumberOfChannels();
delete [] p;
}
}
@ -1953,12 +2032,12 @@ int multiSlsDetector::getBadChannelCorrection(int *bad) {
bd = new int[nd];
nd=detectors[idet]->getBadChannelCorrection(bd);
for (int id=0; id<nd; id++) {
if (bd[id]<detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods()) {
if (bd[id]<detectors[idet]->getTotalNumberOfChannels()) {
if (bad) bad[ntot]=choff+bd[id];
ntot++;
}
}
choff+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
choff+=detectors[idet]->getTotalNumberOfChannels();
delete [] bd;
}
}
@ -2408,7 +2487,7 @@ int multiSlsDetector::setDynamicRange(int p) {
if (detectors[idet]) {
ret1=detectors[idet]->setDynamicRange(p);
thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes();
thisMultiDetector->numberOfChannels+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
thisMultiDetector->numberOfChannels+=detectors[idet]->getTotalNumberOfChannels();
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
@ -2459,7 +2538,7 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) {
}
ret+=detectors[idet]->setNumberOfModules(nm);
thisMultiDetector->dataBytes+=detectors[idet]->getDataBytes();
thisMultiDetector->numberOfChannels+=detectors[idet]->getNChans()*detectors[idet]->getNChips()*detectors[idet]->getNMods();
thisMultiDetector->numberOfChannels+=detectors[idet]->getTotalNumberOfChannels();
}
}
return ret;
@ -2471,7 +2550,7 @@ int multiSlsDetector::decodeNMod(int i, int &id, int &im) {
cout << " Module " << i << " belongs to detector ";
#endif
if (i<0 || i>=setNumberOfModules()) {
if (i<0 || i>=getMaxNumberOfModules()) {
id=-1;
im=-1;
#ifdef VERBOSE
@ -3090,3 +3169,161 @@ int multiSlsDetector::loadImageToDetector(imageType t, string s) {
int multiSlsDetector::testFunction(int times) {
}
int multiSlsDetector::writeDataFile(string fname, float *data, float *err, float *ang, char dataformat, int nch) {
#ifdef VERBOSE
cout << "using overloaded multiSlsDetector function to write formatted data file " << endl;
#endif
ofstream outfile;
int idata, choff=0, off=0;
float *pe=err, *pa=ang;
int nch_left=nch, n;
if (nch_left<=0)
nch_left=getTotalNumberOfChannels();
if (data==NULL)
return FAIL;
// args|=0x10; // one line per channel!
outfile.open (fname.c_str(),ios_base::out);
if (outfile.is_open())
{
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
n=detectors[i]->getTotalNumberOfChannels();
if (nch_left<n)
n=nch_left;
detectors[i]->writeDataFile(outfile,n, data+off, pe, pa, dataformat, choff);
nch_left-=n;
choff+=detectors[i]->getMaxNumberOfChannels();
off+=n;
if (pe)
pe=pe+off;
if (pa)
pa=pa+off;
}
}
outfile.close();
return OK;
} else {
std::cout<< "Could not open file " << fname << "for writing"<< std::endl;
return FAIL;
}
}
int multiSlsDetector::writeDataFile(string fname, int *data) {
ofstream outfile;
int choff=0, off=0;
#ifdef VERBOSE
cout << "using overloaded multiSlsDetector function to write raw data file " << endl;
#endif
if (data==NULL)
return FAIL;
outfile.open (fname.c_str(),ios_base::out);
if (outfile.is_open())
{
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
detectors[i]->writeDataFile(outfile, detectors[i]->getTotalNumberOfChannels(), data+off, choff);
choff+=detectors[i]->getMaxNumberOfChannels();
off+=detectors[i]->getTotalNumberOfChannels();
}
}
outfile.close();
return OK;
} else {
std::cout<< "Could not open file " << fname << "for writing"<< std::endl;
return FAIL;
}
}
int multiSlsDetector::readDataFile(string fname, float *data, float *err, float *ang, char dataformat){
#ifdef VERBOSE
cout << "using overloaded multiSlsDetector function to read formatted data file " << endl;
#endif
ifstream infile;
int ichan, iline=0;
int interrupt=0;
string str;
int choff=0, off=0;
float *pe=err, *pa=ang;
#ifdef VERBOSE
std::cout<< "Opening file "<< fname << std::endl;
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
iline+=detectors[i]->readDataFile(detectors[i]->getTotalNumberOfChannels(), infile, data+off, pe, pa, dataformat, choff);
choff+=detectors[i]->getMaxNumberOfChannels();
off+=detectors[i]->getTotalNumberOfChannels();
if (pe)
pe=pe+off;
if (pa)
pa=pa+off;
}
}
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
return -1;
}
return iline;
}
int multiSlsDetector::readDataFile(string fname, int *data) {
#ifdef VERBOSE
cout << "using overloaded multiSlsDetector function to read raw data file " << endl;
#endif
ifstream infile;
int ichan, iline=0;
int interrupt=0;
string str;
int choff=0, off=0;
#ifdef VERBOSE
std::cout<< "Opening file "<< fname << std::endl;
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
iline+=detectors[i]->readDataFile(infile, data+off,detectors[i]->getTotalNumberOfChannels(), choff);
choff+=detectors[i]->getMaxNumberOfChannels();
off+=detectors[i]->getTotalNumberOfChannels();
}
}
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
return -1;
}
return iline;
}

View File

@ -86,6 +86,9 @@ class multiSlsDetector : public slsDetectorUtils {
/** total number of channels for all detectors */
int numberOfChannels;
/** total number of channels for all detectors */
int maxNumberOfChannels;
/** timer values */
@ -273,6 +276,8 @@ class multiSlsDetector : public slsDetectorUtils {
int getTotalNumberOfChannels(){return thisMultiDetector->numberOfChannels;};
int getMaxNumberOfChannels(){return thisMultiDetector->maxNumberOfChannels;};
float getScanStep(int index, int istep){return thisMultiDetector->scanSteps[index][istep];};
/** returns the detector offset (in number of channels)
\param pos position of the detector
@ -894,7 +899,69 @@ class multiSlsDetector : public slsDetectorUtils {
*/
int testFunction(int times=0);
/**
sets the value of s angular conversion parameter
\param c can be ANGULAR_DIRECTION, GLOBAL_OFFSET, FINE_OFFSET, BIN_SIZE
\param v the value to be set
\returns the actual value
*/
float setAngularConversionParameter(angleConversionParameter c, float v);
/**
writes a data file
\param name of the file to be written
\param data array of data values
\param err array of arrors on the data. If NULL no errors will be written
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
\param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector
\returns OK or FAIL if it could not write the file or data=NULL
\sa mythenDetector::writeDataFile
*/
int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
/**
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
*/
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
\param err array of arrors on the data. If NULL no errors are expected on the file
\param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
\param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
/**
reads a data file
\param name of the file to be read
\param data array of data values
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
int readDataFile(string fname, int *data);
protected:

View File

@ -670,15 +670,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 << "filling bad channel mask" << endl;
// #endif
// /** fill the BadChannelMask \sa fillBadChannelMask */
// fillBadChannelMask();
#ifdef VERBOSE
cout << "done" << endl;
#endif
// #ifdef VERBOSE
// cout << "done" << endl;
// #endif
/** modifies the last PID accessing the detector */
thisDetector->lastPID=getpid();
@ -1041,6 +1041,7 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con
int slsDetector::connectControl() {
if (controlSocket)
return controlSocket->Connect();
return FAIL;
}
/** disconnect from the control port */
int slsDetector::disconnectControl() {
@ -1055,6 +1056,7 @@ int slsDetector::disconnectControl() {
int slsDetector::connectData() {
if (dataSocket)
return dataSocket->Connect();
return FAIL;
};
/** disconnect from the data port */
int slsDetector::disconnectData(){
@ -1068,6 +1070,7 @@ int slsDetector::disconnectControl() {
int slsDetector::connectStop() {
if (stopSocket)
return stopSocket->Connect();
return FAIL;
};
/** disconnect from the stop port */
int slsDetector::disconnectStop(){
@ -4021,7 +4024,10 @@ int slsDetector::setFlatFieldCorrection(string fname){
int slsDetector::setFlatFieldCorrection(float *corr, float *ecorr) {
if (corr!=NULL) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
// #ifdef VERBOSE
// std::cout<< ichan << " "<< corr[ichan] << std::endl;
// #endif
ffcoefficients[ichan]=corr[ichan];
if (ecorr!=NULL)
fferrors[ichan]=ecorr[ichan];
@ -4079,16 +4085,19 @@ int slsDetector::flatFieldCorrect(float* datain, float *errin, float* dataout, f
std::cout<< "Flat field correcting data" << std::endl;
#endif
float e, eo;
if (thisDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION)) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) {
if (errin==NULL)
if (thisDetector->correctionMask & (1<<FLAT_FIELD_CORRECTION)) {
for (int ichan=0; ichan<thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ichan++) {
if (errin==NULL) {
e=0;
else
} else {
e=errin[ichan];
}
flatFieldCorrect(datain[ichan],e,dataout[ichan],eo,ffcoefficients[ichan],fferrors[ichan]);
if (errout)
errout[ichan]=eo;
// #ifdef VERBOSE
// cout << ichan << " " <<datain[ichan]<< " " << ffcoefficients[ichan]<< " " << dataout[ichan] << endl;
// #endif
}
}
return 0;
@ -4209,22 +4218,29 @@ int slsDetector::setBadChannelCorrection(string fname){
int slsDetector::setBadChannelCorrection(int nch, int *chs, int ff) {
#ifdef VERBOSE
cout << "setting " << nch << " bad chans " << endl;
#endif
if (ff==0) {
if (nch<MAX_BADCHANS) {
if (nch<MAX_BADCHANS && nch>0) {
thisDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS);
thisDetector->nBadChans=nch;
for (int ich=0 ;ich<nch; ich++) {
thisDetector->badChansList[ich]=chs[ich];
}
}
} else
thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
} else {
if (nch<MAX_BADCHANS) {
if (nch<MAX_BADCHANS && nch>0) {
thisDetector->nBadFF=nch;
for (int ich=0 ;ich<nch; ich++) {
thisDetector->badFFList[ich]=chs[ich];
}
}
}
#ifdef VERBOSE
cout << "badchans flag is "<< (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) << endl;
#endif
fillBadChannelMask();
if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) {
return thisDetector->nBadChans+thisDetector->nBadFF;

View File

@ -601,9 +601,14 @@ typedef struct sharedSlsDetector {
/** Returns the number of modules (without connecting to the detector) */
int getNMods(){return thisDetector->nMods;}; //
/** Returns the number of modules (without connecting to the detector) */
int getMaxMods(){return thisDetector->nModsMax;}; //
int getTotalNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;};
int getMaxNumberOfChannels(){return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;};
/* Communication to server */

View File

@ -87,6 +87,13 @@ int slsDetectorUtils::getPointers(int * const l_stoppedFlag, \
fileName=l_fileName;
fileIndex=l_fileIndex;
#ifdef VERBOSE
cout << "pointer to badChannelMask is "<< badChannelMask << endl;
#endif
fillBadChannelMask();
#ifdef VERBOSE
cout << "pointer to badChannelMask is "<< badChannelMask << endl;
#endif
return OK;
@ -337,7 +344,7 @@ int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbad, int *badl
std::cout << "Setting bad channel correction to " << fname << std::endl;
#endif
if (fname=="") {
if (fname=="" || fname=="none") {
nbad=0;
return 0;
} else {
@ -395,7 +402,7 @@ int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbad, int *badl
}
infile.close();
if (nbad>0 && nbad<MAX_BADCHANS) {
return 1;
return nbad;
} else
return 0;
}
@ -512,6 +519,7 @@ int slsDetectorUtils::readAngularConversion( ifstream& infile, int nmod, angleCo
while (infile.good() and interrupt==0) {
getline(infile,str);
#ifdef VERBOSE
cout << "** mod " << nm << " " ;
std::cout<< str << std::endl;
#endif
istringstream ssstr(str);
@ -522,15 +530,18 @@ int slsDetectorUtils::readAngularConversion( ifstream& infile, int nmod, angleCo
ssstr >> ss >> er_conv;
ssstr >> ss >> off;
ssstr >> ss >> eoff;
if (mod<nmod && mod>=0) {
angOff[mod].center=center;
angOff[mod].r_conversion=r_conv;
angOff[mod].offset=off;
angOff[mod].ecenter=ecenter;
angOff[mod].er_conversion=er_conv;
angOff[mod].eoffset=eoff;
nm++;
}
if (nm<nmod && nm>=0 ) {
angOff[nm].center=center;
angOff[nm].r_conversion=r_conv;
angOff[nm].offset=off;
angOff[nm].ecenter=ecenter;
angOff[nm].er_conversion=er_conv;
angOff[nm].eoffset=eoff;
} else
break;
nm++;
if (nm>=nmod)
break;
}
return nm;
}
@ -616,12 +627,17 @@ int slsDetectorUtils::addToMerging(float *p1, float *v1, float *e1, float *mp,
binmi=-180.;
binma=binmi+binsize;
#ifdef VERBOSE
cout << "pointer to badchan mask is " << badChanMask << endl;
#endif
if (angDir>0) {
for (int ip=0; ip<nchans; ip++) {
if ((cm)&(1<< DISCARD_BAD_CHANNELS)) {
if (badChanMask[ip]) {
#ifdef VERBOSE
cout << "channel " << ip << " is bad " << endl;
#endif
continue;
}
}
@ -752,7 +768,8 @@ int slsDetectorUtils::writeDataFile(string fname, int nch, float *data, float *e
outfile.open (fname.c_str(),ios_base::out);
if (outfile.is_open())
{
writeDataFile(outfile, nch, data, err, ang, dataformat);
writeDataFile(outfile, nch, data, err, ang, dataformat, 0);
outfile.close();
return OK;
} else {
std::cout<< "Could not open file " << fname << "for writing"<< std::endl;
@ -761,7 +778,7 @@ int slsDetectorUtils::writeDataFile(string fname, int nch, float *data, float *e
};
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, float *data, float *err, float *ang, char dataformat){
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, float *data, float *err, float *ang, char dataformat, int offset){
int idata;
@ -773,7 +790,7 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, float *data, flo
for (int ichan=0; ichan<nch; ichan++) {
if (ang==NULL) {
outfile << ichan << " ";
outfile << ichan+offset << " ";
} else {
outfile << ang[ichan] << " ";
}
@ -795,7 +812,7 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, float *data, flo
// }
}
outfile.close();
return OK;
}
@ -819,7 +836,7 @@ int slsDetectorUtils::writeDataFile(string fname, int nch, int *data){
outfile.open (fname.c_str(),ios_base::out);
if (outfile.is_open())
{
writeDataFile(outfile, nch, data);
writeDataFile(outfile, nch, data, 0);
outfile.close();
return OK;
} else {
@ -831,13 +848,14 @@ int slsDetectorUtils::writeDataFile(string fname, int nch, int *data){
/*writes raw data file */
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data){
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data, int offset){
if (data==NULL)
return FAIL;
for (int ichan=0; ichan<nch; ichan++)
outfile << ichan << " " << *(data+ichan) << std::endl;
outfile << ichan+offset << " " << *(data+ichan) << std::endl;
return OK;
};
@ -870,7 +888,7 @@ int slsDetectorUtils::readDataFile(int nch, string fname, float *data, float *er
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
readDataFile(nch, infile, data, err, ang, dataformat);
iline=readDataFile(nch, infile, data, err, ang, dataformat, 0);
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
@ -880,7 +898,7 @@ int slsDetectorUtils::readDataFile(int nch, string fname, float *data, float *er
};
int slsDetectorUtils::readDataFile(int nch, ifstream &infile, float *data, float *err, float *ang, char dataformat){
int slsDetectorUtils::readDataFile(int nch, ifstream &infile, float *data, float *err, float *ang, char dataformat, int offset){
int ichan, iline=0;
@ -902,13 +920,16 @@ int slsDetectorUtils::readDataFile(int nch, ifstream &infile, float *data, float
istringstream ssstr(str);
if (ang==NULL) {
ssstr >> ichan >> fdata;
ich=ichan;
//ich=ichan;
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}
if (ich!=iline)
std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl;
// if (ich!=iline)
// std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl;
ich=iline;
if (ichan<offset)
continue;
} else {
ssstr >> fang >> fdata;
ich=iline;
@ -924,18 +945,22 @@ int slsDetectorUtils::readDataFile(int nch, ifstream &infile, float *data, float
break;
}
if (ich<maxchans) {
if (ang) {
if (ang) {
ang[ich]=fang;
}
data[ich]=fdata;
if (err)
err[ich]=ferr;
iline++;
} else {
std::cout<< " too many lines in file: "<< iline << " instead of " << maxchans << std::endl;
interrupt=1;
break;
}
} // else {
// std::cout<< " too many lines in file: "<< iline << " instead of " << maxchans << std::endl;
// interrupt=1;
// break;
// }
if (iline>=nch) {
interrupt=1;
break;
}
}
return iline;
};
@ -954,7 +979,7 @@ int slsDetectorUtils::readDataFile(string fname, int *data, int nch){
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
readDataFile(infile, data, nch);
iline=readDataFile(infile, data, nch, 0);
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
@ -963,7 +988,7 @@ int slsDetectorUtils::readDataFile(string fname, int *data, int nch){
return iline;
};
int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int nch){
int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int nch, int offset){
int ichan, idata, iline=0;
int interrupt=0;
@ -981,19 +1006,21 @@ int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int nch){
interrupt=1;
break;
}
if (ichan!=iline) {
std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl;
interrupt=1;
break;
} else {
if (iline<nch) {
// if (ichan!=iline) {
// std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl;
// interrupt=1;
// break;
// } else {
if (iline<nch) {
if (ichan>=offset) {
data[iline]=idata;
iline++;
} else {
}
} else {
interrupt=1;
break;
}
}
// }
}
return iline;
};
@ -1011,7 +1038,7 @@ int slsDetectorUtils::readDataFile(string fname, short int *data, int nch){
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
readDataFile(infile, data, nch);
iline=readDataFile(infile, data, nch, 0);
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
@ -1020,14 +1047,12 @@ int slsDetectorUtils::readDataFile(string fname, short int *data, int nch){
return iline;
};
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch){
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch, int offset){
int ichan, iline=0;
short int idata;
int interrupt=0;
string str;
while (infile.good() and interrupt==0) {
getline(infile,str);
#ifdef VERBOSE
@ -1039,22 +1064,27 @@ int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch){
interrupt=1;
break;
}
if (ichan!=iline) {
std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl;
interrupt=1;
break;
} else {
if (iline<nch) {
// if (ichan!=iline) {
// std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl;
// interrupt=1;
// break;
// } else {
if (iline<nch) {
if (ichan>=offset) {
data[iline]=idata;
iline++;
} else {
interrupt=1;
break;
}
} else {
interrupt=1;
break;
}
}
// }
#ifdef VERBOSE
std::cout<< "read " << iline <<" channels " << std::endl;
#endif
}
return iline;
};
}
@ -1067,11 +1097,11 @@ int slsDetectorUtils::writeDataFile(string fname, float *data, float *err, float
return writeDataFile(fname, nch, data, err, ang, dataformat);
}
int slsDetectorUtils::writeDataFile(ofstream &outfile, float *data, float *err, float *ang, char dataformat, int nch){
int slsDetectorUtils::writeDataFile(ofstream &outfile, float *data, float *err, float *ang, char dataformat, int nch, int offset){
if (nch==-1)
nch=getTotalNumberOfChannels();
return writeDataFile(outfile, nch, data, err, ang, dataformat);
return writeDataFile(outfile, nch, data, err, ang, dataformat, offset);
}
@ -1083,9 +1113,9 @@ int slsDetectorUtils::writeDataFile(string fname, int *data){
return writeDataFile(fname, getTotalNumberOfChannels(), data);
}
int slsDetectorUtils::writeDataFile(ofstream &outfile, int *data){
int slsDetectorUtils::writeDataFile(ofstream &outfile, int *data, int offset){
return writeDataFile(outfile, getTotalNumberOfChannels(), data);
return writeDataFile(outfile, getTotalNumberOfChannels(), data, offset);
}
@ -1095,8 +1125,8 @@ int slsDetectorUtils::readDataFile(string fname, float *data, float *err, float
}
int slsDetectorUtils::readDataFile(ifstream &infile, float *data, float *err, float *ang, char dataformat) {
return readDataFile(getTotalNumberOfChannels(), infile, data, err, ang, dataformat);
int slsDetectorUtils::readDataFile(ifstream &infile, float *data, float *err, float *ang, char dataformat, int offset) {
return readDataFile(getTotalNumberOfChannels(), infile, data, err, ang, dataformat, offset);
}
@ -1108,9 +1138,9 @@ int slsDetectorUtils::readDataFile(string fname, int *data){
};
int slsDetectorUtils::readDataFile(ifstream &infile, int *data){
int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int offset){
return readDataFile(infile, data, getTotalNumberOfChannels());
return readDataFile(infile, data, getTotalNumberOfChannels(), offset);
};
@ -1123,9 +1153,9 @@ int slsDetectorUtils::readDataFile(string fname, short int *data){
};
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data){
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int offset){
return readDataFile(infile, data, getTotalNumberOfChannels());
return readDataFile(infile, data, getTotalNumberOfChannels(),offset);
};
@ -1627,12 +1657,16 @@ void* slsDetectorUtils::processData(int delflag) {
fname=createFileName();
//uses static function?!?!?!?
// writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i');
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
/** write raw data file */
if (*correctionMask==0 && delflag==1) {
writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i');
delete [] fdata;
} else {
writeDataFile (fname+string(".raw"), getTotalNumberOfChannels(),fdata, NULL, NULL, 'i');
/** rate correction */
if (*correctionMask&(1<<RATE_CORRECTION)) {
@ -1650,9 +1684,15 @@ void* slsDetectorUtils::processData(int delflag) {
ffcdata=new float[getTotalNumberOfChannels()];
ffcerr=new float[getTotalNumberOfChannels()];
#ifdef VERBOSE
cout << "array size " << getTotalNumberOfChannels() << endl;
#endif
flatFieldCorrect(rcdata,rcerr,ffcdata,ffcerr);
#ifdef VERBOSE
cout << "FF corr done " << endl;
#endif
delete [] rcdata;
delete [] rcerr;
if (rcerr) delete [] rcerr;
} else {
ffcdata=rcdata;
ffcerr=rcerr;
@ -1683,8 +1723,11 @@ void* slsDetectorUtils::processData(int delflag) {
ang=convertAngles(currentPosition);
if (*correctionMask!=0) {
if (*numberOfPositions>1)
writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang);
if (*numberOfPositions>1) {
//uses static function?!?!?!?
//writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang);
writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang);
}
}
addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask );
@ -1694,6 +1737,7 @@ void* slsDetectorUtils::processData(int delflag) {
currentPositionIndex++;
fname=createFileName();
if (*correctionMask!=0) {
//uses static function?!?!?!?
writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f');
}
if (delflag) {
@ -1715,7 +1759,9 @@ void* slsDetectorUtils::processData(int delflag) {
delete [] ang;
} else {
if (*correctionMask!=0) {
writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr);
//uses static function?!?!?!?
//writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr);
writeDataFile (fname+string(".dat"), ffcdata, ffcerr);
}
if (delflag) {
if (ffcdata)
@ -1841,10 +1887,14 @@ void slsDetectorUtils::startThread(int delflag) {
int slsDetectorUtils::fillBadChannelMask() {
int nbad=0;
if (*correctionMask&(1<< DISCARD_BAD_CHANNELS)) {
nbad=getBadChannelCorrection();
#ifdef VERBOSE
cout << "number of bad channels is " << nbad << endl;
#endif
if (nbad>0) {
int *badChansList=new int[nbad];
@ -1853,9 +1903,16 @@ int slsDetectorUtils::fillBadChannelMask() {
if (badChannelMask)
delete [] badChannelMask;
badChannelMask=new int[getTotalNumberOfChannels()];
#ifdef VERBOSE
cout << " pointer to bad channel mask is " << badChannelMask << endl;
#endif
for (int ichan=0; ichan<getTotalNumberOfChannels(); ichan++)
badChannelMask[ichan]=0;
for (int ichan=0; ichan<*nBadChans; ichan++) {
#ifdef VERBOSE
cout << " badChanMask has be reset" << badChannelMask << endl;
#endif
for (int ichan=0; ichan<nbad; ichan++) {
if (badChansList[ichan]<getTotalNumberOfChannels() && badChansList[ichan]>=0 ) {
if (badChannelMask[badChansList[ichan]]==0)
nbad++;
@ -1867,18 +1924,31 @@ int slsDetectorUtils::fillBadChannelMask() {
} else {
if (badChannelMask) {
#ifdef VERBOSE
cout << "deleting bad channel mask beacuse number of bad channels is 0" << endl;
#endif
delete [] badChannelMask;
badChannelMask=NULL;
}
}
} else {
#ifdef VERBOSE
cout << "bad channel correction is disabled " << nbad << endl;
#endif
if (badChannelMask) {
#ifdef VERBOSE
cout << "deleting bad channel mask beacuse no bad channel correction is selected" << endl;
#endif
delete [] badChannelMask;
badChannelMask=NULL;
}
}
#ifdef VERBOSE
cout << "number of bad channels is " << nbad << endl;
#endif
return nbad;
}

View File

@ -159,11 +159,10 @@ class slsDetectorUtils : public slsDetectorBase {
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
\param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector
\returns OK or FAIL if it could not write the file or data=NULL
\sa mythenDetector::writeDataFile
*/
int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
virtual int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1, int offset=0);
/**
@ -174,8 +173,8 @@ class slsDetectorUtils : public slsDetectorBase {
\returns OK or FAIL if it could not write the file or data=NULL
\sa mythenDetector::writeDataFile
*/
int writeDataFile(string fname, int *data);
int writeDataFile(ofstream &outfile, int *data);
virtual int writeDataFile(string fname, int *data);
int writeDataFile(ofstream &outfile, int *data, int offset=0);
/**
@ -189,10 +188,9 @@ class slsDetectorUtils : public slsDetectorBase {
\param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
int readDataFile(ifstream& infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
virtual int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
int readDataFile(ifstream& infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0);
/**
@ -200,10 +198,9 @@ class slsDetectorUtils : public slsDetectorBase {
\param name of the file to be read
\param data array of data values
\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(ifstream &infile, int *data);
virtual int readDataFile(string fname, int *data);
int readDataFile(ifstream &infile, int *data, int offset=0);
/**
@ -211,10 +208,9 @@ class slsDetectorUtils : public slsDetectorBase {
\param name of the file to be read
\param data array of data values
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
int readDataFile(string fname, short int *data);
int readDataFile(ifstream &infile, short int *data);
virtual int readDataFile(string fname, short int *data);
int readDataFile(ifstream &infile, short int *data, int offset=0);
/**
@ -232,7 +228,7 @@ 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');
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
@ -242,7 +238,7 @@ class slsDetectorUtils : public slsDetectorBase {
\sa mythenDetector::writeDataFile
*/
static int writeDataFile(string fname,int nch, int *data);
static int writeDataFile(ofstream &outfile,int nch, int *data);
static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0);
/**
@ -259,7 +255,7 @@ class slsDetectorUtils : public slsDetectorBase {
\sa mythenDetector::readDataFile
*/
static int readDataFile(int nch, string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
static int readDataFile(int nch, ifstream &infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
static int readDataFile(int nch, ifstream &infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int offset=0);
/**
@ -270,7 +266,7 @@ class slsDetectorUtils : public slsDetectorBase {
\sa mythenDetector::readDataFile
*/
static int readDataFile(string fname, int *data, int nch);
static int readDataFile(ifstream &infile, int *data, int nch);
static int readDataFile(ifstream &infile, int *data, int nch, int offset=0);
/**
@ -281,7 +277,7 @@ class slsDetectorUtils : public slsDetectorBase {
\sa mythenDetector::readDataFile
*/
static int readDataFile(string fname, short int *data, int nch);
static int readDataFile(ifstream &infile, short int *data, int nch);
static int readDataFile(ifstream &infile, short int *data, int nch, int offset=0);
/**
@ -735,6 +731,7 @@ s
virtual int flatFieldCorrect(float*, float*, float*, float*)=0;
virtual int getTotalNumberOfChannels()=0;
virtual int getMaxNumberOfChannels()=0;

View File

@ -3,6 +3,8 @@
#include <stdio.h>
float pos;
float i0=0;
#ifdef EPICS
#include <cadef.h>
@ -10,6 +12,11 @@
static double timeout = 3.0;
chid ch_pos,ch_i0, ch_getpos;
/* connect to a PV */
int connect_channel(const char *name, chid *ch_id) {
int status = ECA_NORMAL;
@ -88,44 +95,12 @@ int caput(chid ch_id, double value) {
return status;
}
/* int main(int argc, char *argv[]) { */
/* double value = 256; */
/* /\* channel name *\/ */
/* const char *name = "ARIDI-PCT:CURRENT"; */
/* /\* channel id *\/ */
/* chid ch_id; */
/* /\* status code *\/ */
/* int status; */
//int main(int argc, char *argv[]) {
/* /\* init channel access context before any caget/put *\/ */
/* ca_context_create(ca_enable_preemptive_callback); */
/* /\* open the channel by name and return ch_id *\/ */
/* status = connect_channel(name, &ch_id); */
/* if (status == ECA_NORMAL) */
/* printf("channel connected %s\n", name); */
/* else { */
/* printf(ca_message(status)); */
/* return -1; */
/* } */
/* /\* caput and wait until done *\/ */
/* if ((status = caput(ch_id, value)) == ECA_NORMAL) */
/* printf("caput: success\n"); */
/* else */
/* printf(ca_message(status)); */
/* /\* caget *\/ */
/* if (caget(ch_id, &value) == ECA_NORMAL) */
/* printf("caget: %f\n", value); */
/* else */
/* printf(ca_message(status)); */
/* /\* close channel connect *\/ */
/* disconnect_channel(ch_id); */
/* /\* delete channel access context before program exits *\/ */
/* ca_context_destroy(); */
/* } */
@ -137,10 +112,6 @@ int caput(chid ch_id, double value) {
float pos;
float i0=0;
/*
contains the conversion channel-angle for a module channel
conv_r=pitch/radius
@ -149,11 +120,11 @@ float i0=0;
float angle(int ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction) {
(void) offset; /* to avoid warning: unused parameter */
(void) tilt; /* to avoid warning: unused parameter */
float ang;
ang=180./PI*(center*conv_r+atan((float)(ichan-center)*conv_r))+encoder+totalOffset;
ang=180./PI*(center*conv_r+atan((float)(ichan-center)*conv_r))+encoder+totalOffset+offset;
return direction*ang;
@ -165,17 +136,55 @@ float get_position() {
#ifdef VERBOSE
printf("Getting motor position \n");
#endif
// caget X04SA-ES2-TH2:RO.RBV
#ifdef EPICS
int status;
double value = 256;
if (ch_getpos<0) return -1;
/* /\* caget *\/ */
if (caget(ch_getpos, &value) == ECA_NORMAL) {
#ifdef VERBOSE
printf("caget: %f\n", value);
#endif
pos=value;
} else
printf(ca_message(status));
#endif
return pos;
}
/* moves the encoder to position p */
int go_to_position(float p) {
#ifdef VERBOSE
printf("Setting motor position \n");
#endif
pos=p;
return pos;
#ifdef EPICS
int status;
if (ch_pos<0) return -1;
/* /\* caput and wait until done *\/ */
if ((status = caput(ch_pos, p)) == ECA_NORMAL) {
;
#ifdef VERBOSE
printf("caput: success\n");
#endif
} else
printf(ca_message(status));
#else
pos=p;
#endif
//"caputq X04SA-ES2-TH2:RO p"
//cawait -nounit -timeout 3600 X04SA-ES2-TH2:RO.DMOV '==1'
return p;
}
/* moves the encoder to position p without waiting */
@ -184,6 +193,29 @@ int go_to_position_no_wait(float p) {
#ifdef VERBOSE
printf("Setting motor position no wait \n");
#endif
#ifdef EPICS
int status;
if (ch_pos<0) return -1;
/* /\* caput and wait until done *\/ */
if ((status = caputq(ch_pos, p)) == ECA_NORMAL) {
;
#ifdef VERBOSE
printf("caputq: success\n");
#endif
} else
printf(ca_message(status));
#else
pos=p;
#endif
//"caputq X04SA-ES2-TH2:RO p"
return p;
pos=p;
return pos;
}
@ -195,8 +227,92 @@ float get_i0() {
#ifdef VERBOSE
printf("Getting I0 readout \n");
#endif
return i0++;
#ifdef EPICS
int status;
double value = 256;
/* /\* caget *\/ */
if (ch_i0<0) return -1;
if (caget(ch_i0, &value) == ECA_NORMAL) {
#ifdef VERBOSE
printf("caget: %f\n", value);
#endif
i0=value;
} else
printf(ca_message(status));
#else
i0++;
#endif
//"ca_get X04SA-ES2-SC:CH6"
return i0;
}
int disconnect_channels() { }
int connect_channels() {}
int connect_channels() {
#ifdef EPICS
//double value = 256;
/* channel name */
//const char *name = "ARIDI-PCT:CURRENT";
/* channel id */
/* status code */
int status;
printf("starting...\n");
/* init channel access context before any caget/put */
ca_context_create(ca_enable_preemptive_callback);
printf("context created\n");
//"caputq X04SA-ES2-TH2:RO p"
//"ca_get X04SA-ES2-SC:CH6"
/* open the channel by name and return ch_id */
status = connect_channel("X04SA-ES2-SC:CH6", &ch_i0);
if (status == ECA_NORMAL)
printf("I0 channel connected \n");
else {
printf(ca_message(status));
//ch_i0=-1;;
}
status = connect_channel("X04SA-ES2-TH2:RO", &ch_pos);
if (status == ECA_NORMAL)
printf("Detector position channel connected \n");
else {
printf(ca_message(status));
//ch_i0=-1;;
}
status = connect_channel("X04SA-ES2-TH2:RO.RBV", &ch_getpos);
if (status == ECA_NORMAL)
printf("Detector get position channel connected \n");
else {
printf(ca_message(status));
//ch_getpos=-1;;
}
// caget X04SA-ES2-TH2:RO.RBV
//cawait -nounit -timeout 3600 X04SA-ES2-TH2:RO.DMOV '==1'
#endif
}
int disconnect_channels() {
#ifdef EPICS
/* close channel connect */
disconnect_channel(ch_i0);
disconnect_channel(ch_pos);
disconnect_channel(ch_getpos);
/* delete channel access context before program exits */
ca_context_destroy();
#endif
}

View File

@ -26,7 +26,6 @@ extern "C" {
int caputq(chid ch_id, double value);
void put_callback(struct event_handler_args args);
int caput(chid ch_id, double value);
#endif
@ -34,11 +33,9 @@ extern "C" {
float get_position();
int go_to_position(float p);
int go_to_position_no_wait(float p);
int connect_channels();
int disconnect_channels();
float get_i0();