added loadCalibrationfile and saving it

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@236 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-09-03 09:21:25 +00:00
parent b0eea2a6e6
commit 2b59857032
6 changed files with 130 additions and 5 deletions

View File

@ -1,7 +1,7 @@
CFLAGS= -DC_ONLY
#FLAGS+= #-DVERBOSE -DVERYVERBOSE
DFLAGS= -DDACS_INT
#DFLAGS= -DDACS_INT
INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis

View File

@ -3040,6 +3040,52 @@ int multiSlsDetector::saveSettingsFile(string fname, int imod) {
}
int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
int id, im, ret;
if (decodeNMod(imod, id, im)>=0) {
if (detectors[id]) {
return detectors[id]->loadCalibrationFile(fname, im);
}
} else if (imod<0) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret=detectors[idet]->loadCalibrationFile(fname, imod);
}
}
return ret;
}
return -1;
}
int multiSlsDetector::saveCalibrationFile(string fname, int imod) {
int id, im, ret;
if (decodeNMod(imod, id, im)>=0) {
if (detectors[id]) {
return detectors[id]->saveCalibrationFile(fname, im);
}
} else if (imod<0) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret=detectors[idet]->saveCalibrationFile(fname, imod);
}
}
return ret;
}
return -1;
}
int multiSlsDetector::writeRegister(int addr, int val){
int i;//imi, ima,

View File

@ -441,6 +441,13 @@ class multiSlsDetector : public slsDetectorUtils {
int saveSettingsFile(string fname, int nmod=0);
/** loads the modules calibration data reading from a file - file name extension is automatically generated! */
int loadCalibrationFile(string fname, int nmod=0);
/** gets the modules calibration data and writes them to file - file name extension is automatically generated! */
int saveCalibrationFile(string fname, int nmod=0);

View File

@ -5111,6 +5111,62 @@ int slsDetector::saveSettingsFile(string fname, int imod) {
int slsDetector::loadCalibrationFile(string fname, int imod) {
sls_detector_module *myMod=NULL;
string fn=fname;
fn=fname;
int mmin=0, mmax=setNumberOfModules();
if (imod>=0) {
mmin=imod;
mmax=imod+1;
}
for (int im=mmin; im<mmax; im++) {
if (fname.find(".sn")==string::npos && fname.find(".cal")) {
ostringstream ostfn;
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
fn=ostfn.str();
}
if(myMod=getModule(im)){
if(readCalibrationFile(fn, myMod->gain, myMod->offset)==FAIL)
return FAIL;
setModule(*myMod);
deleteModule(myMod);
} else
return FAIL;
}
return OK;
}
int slsDetector::saveCalibrationFile(string fname, int imod) {
sls_detector_module *myMod=NULL;
int ret=FAIL;
int mmin=0, mmax=setNumberOfModules();
if (imod>=0) {
mmin=imod;
mmax=imod+1;
}
for (int im=mmin; im<mmax; im++) {
ostringstream ostfn;
ostfn << fname << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
if ((myMod=getModule(im))) {
ret=writeCalibrationFile(ostfn.str(), myMod->gain, myMod->offset);
deleteModule(myMod);
}else
return FAIL;
}
return ret;
}
/* returns if the detector is Master, slave or nothing
\param flag can be GET_MASTER, NO_MASTER, IS_MASTER, IS_SLAVE
\returns master flag of the detector

View File

@ -491,6 +491,22 @@ typedef struct sharedSlsDetector {
int saveSettingsFile(string fname, int imod=-1);
/** loads the modules calibration data reading from a file
\param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int loadCalibrationFile(string fname, int imod=-1);
/** saves the modules calibration data writing to a file
\param fname file name . Axtension is automatically generated!
\param imod module number, -1 means all modules
\returns OK or FAIL
*/
int saveCalibrationFile(string fname, int imod=-1);
/**
reads an angular conversion file

View File

@ -31,9 +31,9 @@ int energyConversion::readCalibrationFile(string fname, double &gain, double &of
std::cout<< "Could not open calibration file "<< fname << std::endl;
gain=0.;
offset=0.;
return -1;
return FAIL;
}
return 0;
return OK;
};
int energyConversion::writeCalibrationFile(string fname, double gain, double offset){
@ -47,12 +47,12 @@ int energyConversion::writeCalibrationFile(string fname, double gain, double off
outfile << offset << " " << gain << std::endl;
} else {
std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl;
return -1;
return FAIL;
}
outfile.close();
return 0;
return OK;
};