impplemented the possibility of setting the bad channels on a module basis

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@183 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-05-25 15:23:32 +00:00
parent d30ad5faac
commit c14b98d938
7 changed files with 166 additions and 57 deletions

View File

@ -1969,13 +1969,19 @@ int multiSlsDetector::setBadChannelCorrection(string fname){
int badlist[MAX_BADCHANS];// badlistdet[MAX_BADCHANS]; int badlist[MAX_BADCHANS];// badlistdet[MAX_BADCHANS];
int nbad=0;//, nbaddet=0, choff=0, idet=0; int nbad=0;//, nbaddet=0, choff=0, idet=0;
int ret=0;
if (fname=="default") if (fname=="default")
fname=string(thisMultiDetector->badChanFile); fname=string(thisMultiDetector->badChanFile);
int ret=setBadChannelCorrection(fname, nbad, badlist);
ret=setBadChannelCorrection(fname, nbad, badlist);
#ifdef VERBOSE #ifdef VERBOSE
cout << "file contained " << ret << " badcahns" << endl; cout << "file contained " << ret << " badchans" << endl;
#endif #endif
if (ret==0) { if (ret==0) {
thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS); thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
@ -2021,7 +2027,7 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
} }
} }
if (nbaddet>0) { if (nbaddet>0) {
if (detectors[idet]) { if (detectors[idet]) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "setting " << nbaddet << " badchans to detector " << idet << endl; cout << "setting " << nbaddet << " badchans to detector " << idet << endl;
@ -2035,7 +2041,7 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
nbaddet=0; nbaddet=0;
for (int i=idet; i<thisMultiDetector->numberOfDetectors; i++) { for (int i=idet; i<thisMultiDetector->numberOfDetectors; i++) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "setting " << 0 << " badchans to detector " << i << endl; cout << "setting " << 0 << " badchans to detector " << i << endl;
#endif #endif
if (detectors[i]) { if (detectors[i]) {
detectors[i]->setBadChannelCorrection(nbaddet,badlist,0); detectors[i]->setBadChannelCorrection(nbaddet,badlist,0);
@ -2047,9 +2053,9 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int *badlist, int ff) {
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) { for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[idet]) { if (detectors[idet]) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "setting " << 0 << " badchans to detector " << idet << endl; cout << "setting " << 0 << " badchans to detector " << idet << endl;
#endif #endif
detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0); detectors[idet]->setBadChannelCorrection(nbaddet,badlist,0);
} }
} }
thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS); thisMultiDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);

View File

@ -4239,23 +4239,44 @@ int slsDetector::rateCorrect(float* datain, float *errin, float* dataout, float
return 0; return 0;
}; };
int slsDetector::setBadChannelCorrection(string fname){
int slsDetector::setBadChannelCorrection(string fname){
int nbadmod,ret=0;
int badchanlist[MAX_BADCHANS];
int off;
string fn=fname;
if (fname=="default") if (fname=="default")
fname=string(thisDetector->badChanFile); fname=string(badChanFile);
int ret=setBadChannelCorrection(fname, thisDetector->nBadChans, thisDetector->badChansList);
if (nBadChans && badChansList)
ret=setBadChannelCorrection(fname, *nBadChans, badChansList);
if (ret) { if (ret) {
thisDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS); *correctionMask|=(1<<DISCARD_BAD_CHANNELS);
strcpy(thisDetector->badChanFile,fname.c_str()); strcpy(badChanFile,fname.c_str());
} else } else
thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS); *correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
fillBadChannelMask(); fillBadChannelMask();
return thisDetector->correctionMask&(1<<DISCARD_BAD_CHANNELS); return (*correctionMask)&(1<<DISCARD_BAD_CHANNELS);
} }
int slsDetector::setBadChannelCorrection(int nch, int *chs, int ff) { int slsDetector::setBadChannelCorrection(int nch, int *chs, int ff) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "setting " << nch << " bad chans " << endl; cout << "setting " << nch << " bad chans " << endl;
@ -4263,9 +4284,12 @@ int slsDetector::setBadChannelCorrection(int nch, int *chs, int ff) {
if (ff==0) { if (ff==0) {
if (nch<MAX_BADCHANS && nch>0) { if (nch<MAX_BADCHANS && nch>0) {
thisDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS); thisDetector->correctionMask|=(1<<DISCARD_BAD_CHANNELS);
thisDetector->nBadChans=nch; thisDetector->nBadChans=0;
for (int ich=0 ;ich<nch; ich++) { for (int ich=0 ;ich<nch; ich++) {
thisDetector->badChansList[ich]=chs[ich]; if (chs[ich]<getMaxNumberOfChannels()) {
thisDetector->badChansList[ich]=chs[ich];
thisDetector->nBadChans++;
}
} }
} else } else
thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS); thisDetector->correctionMask&=~(1<<DISCARD_BAD_CHANNELS);
@ -5316,7 +5340,7 @@ int slsDetector::writeSettingsFile(string fname, int imod){
int slsDetector::loadSettingsFile(string fname, int imod) { int slsDetector::loadSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL; sls_detector_module *myMod=NULL;
string fn; string fn=fname;
fn=fname; fn=fname;
int mmin=0, mmax=setNumberOfModules(); int mmin=0, mmax=setNumberOfModules();
if (imod>=0) { if (imod>=0) {
@ -5324,7 +5348,7 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
mmax=imod+1; mmax=imod+1;
} }
for (int im=mmin; im<mmax; im++) { for (int im=mmin; im<mmax; im++) {
if (fname.find(".sn")==string::npos) { if (fname.find(".sn")==string::npos && fname.find(".trim")) {
ostringstream ostfn; ostringstream ostfn;
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im); ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
fn=ostfn.str(); fn=ostfn.str();

View File

@ -1108,7 +1108,7 @@ typedef struct sharedSlsDetector {
\returns 0 if bad channel disabled, >0 otherwise \returns 0 if bad channel disabled, >0 otherwise
*/ */
int setBadChannelCorrection(string fname=""); int setBadChannelCorrection(string fname="");
/** /**
set bad channels correction set bad channels correction
\param nch number of bad channels \param nch number of bad channels

View File

@ -313,6 +313,81 @@ int slsDetectorUtils::setTotalProgress() {
int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbadtot, int *badchanlist, int off){
int nbad;
int badlist[MAX_BADCHANS];
ifstream infile;
string str;
int interrupt=0;
int ich;
int chmin,chmax;
#ifdef VERBOSE
std::cout << "Setting bad channel correction to " << fname << std::endl;
#endif
int modmi=0, modma=1;
int singlefile=0;
string fn;
int offset=off;
nbadtot=0;
if (fname=="" || fname=="none") {
;
} else {
if (fname.find(".sn")==string::npos && fname.find(".chans")==string::npos) {
modma=setNumberOfModules();
singlefile=1;
}
for (int im=0; im<modma; im++) {
if (singlefile) {
ostringstream ostfn;
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
fn=ostfn.str();
} else
fn=fname;
infile.open(fn.c_str(), ios_base::in);
if (infile.is_open()==0) {
std::cout << "could not open file " << fname <<std::endl;
return -1;
}
nbad=setBadChannelCorrection(infile, nbad, badlist, offset);
infile.close();
for (int ich=0; ich<nbad; ich++) {
if (nbadtot<MAX_BADCHANS) {
badchanlist[nbadtot]=badlist[ich];
nbadtot++;
}
}
offset+=getChansPerMod(im);
}
}
if (nbadtot>0 && nbadtot<MAX_BADCHANS) {
return nbadtot;
} else
return 0;
}
float slsDetectorUtils::getCurrentProgress() { float slsDetectorUtils::getCurrentProgress() {

View File

@ -69,7 +69,8 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
// int getPositions(float *pos=NULL){return angularConversion::getPositions(pos);}; // int getPositions(float *pos=NULL){return angularConversion::getPositions(pos);};
using slsDetectorBase::setFlatFieldCorrection; using slsDetectorBase::setFlatFieldCorrection;
using postProcessing::setBadChannelCorrection;
// string getFilePath(){return fileIO::getFilePath();}; // string getFilePath(){return fileIO::getFilePath();};
// string setFilePath(string s){return fileIO::setFilePath(s);}; // string setFilePath(string s){return fileIO::setFilePath(s);};
@ -269,6 +270,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
int setBadChannelCorrection(string fname, int &nbadtot, int *badchanlist, int off=0);

View File

@ -55,33 +55,26 @@ int postProcessing::flatFieldCorrect(float datain, float errin, float &dataout,
}; };
int postProcessing::setBadChannelCorrection(string fname, int &nbad, int *badlist){
ifstream infile;
string str;
int postProcessing::setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){
int interrupt=0; int interrupt=0;
int ich; int ich;
int chmin,chmax; int chmin,chmax;
#ifdef VERBOSE string str;
std::cout << "Setting bad channel correction to " << fname << std::endl;
#endif
if (fname=="" || fname=="none") {
nbad=0;
return 0; nbad=0;
} else { while (infile.good() and interrupt==0) {
infile.open(fname.c_str(), ios_base::in); getline(infile,str);
if (infile.is_open()==0) {
std::cout << "could not open file " << fname <<std::endl;
return -1;
}
nbad=0;
while (infile.good() and interrupt==0) {
getline(infile,str);
#ifdef VERBOSE #ifdef VERBOSE
std::cout << str << std::endl; std::cout << str << std::endl;
#endif #endif
istringstream ssstr; istringstream ssstr;
ssstr.str(str); ssstr.str(str);
if (ssstr.bad() || ssstr.fail() || infile.eof()) { if (ssstr.bad() || ssstr.fail() || infile.eof()) {
interrupt=1; interrupt=1;
break; break;
@ -117,16 +110,26 @@ int postProcessing::setBadChannelCorrection(string fname, int &nbad, int *badlis
} else } else
interrupt=1; interrupt=1;
} }
}
} }
infile.close();
if (nbad>0 && nbad<MAX_BADCHANS) { for (int ich=0; ich<nbad; ich++) {
return nbad; badlist[ich]=badlist[ich]+moff;
} else }
return 0; return nbad;
} }
void postProcessing::processFrame(int *myData, int delflag) { void postProcessing::processFrame(int *myData, int delflag) {
string fname; string fname;
@ -401,12 +404,12 @@ int postProcessing::fillBadChannelMask() {
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting bad channel mask beacuse number of bad channels is 0" << endl; cout << "deleting bad channel mask beacuse number of bad channels is 0" << endl;
#endif #endif
delete [] badChannelMask; delete [] badChannelMask;
badChannelMask=NULL; badChannelMask=NULL;
} }
} }
} else { } else {
#ifdef VERBOSE #ifdef VERBOSE
cout << "bad channel correction is disabled " << nbad << endl; cout << "bad channel correction is disabled " << nbad << endl;
@ -419,11 +422,12 @@ int postProcessing::fillBadChannelMask() {
badChannelMask=NULL; badChannelMask=NULL;
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "number of bad channels is " << nbad << endl; cout << "number of bad channels is " << nbad << endl;
#endif #endif
return nbad; return nbad;
} }

View File

@ -74,10 +74,8 @@ class postProcessing : public angularConversion, public fileIO
\returns 0 if bad channel disabled, >0 otherwise \returns 0 if bad channel disabled, >0 otherwise
*/ */
virtual int setBadChannelCorrection(string fname="")=0; virtual int setBadChannelCorrection(string fname="")=0;
static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff=0);
/** /**
set bad channels correction set bad channels correction
\param fname file with bad channel list ("" disable) \param fname file with bad channel list ("" disable)
@ -85,7 +83,7 @@ class postProcessing : public angularConversion, public fileIO
\param badlist array of badchannels \param badlist array of badchannels
\returns 0 if bad channel disabled, >0 otherwise \returns 0 if bad channel disabled, >0 otherwise
*/ */
static int setBadChannelCorrection(string fname, int &nbad, int *badlist); virtual int setBadChannelCorrection(string fname, int &nbad, int *badlist, int off=0)=0;
/** /**