mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
fixed reading settings file for eiger
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@624 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
47377a02e9
commit
19d3c1eb0c
@ -5,6 +5,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "fileIOStatic.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -74,7 +75,6 @@ int energyConversion::writeCalibrationFile(string fname, double gain, double off
|
|||||||
|
|
||||||
|
|
||||||
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod){
|
slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string fname, detectorType myDetectorType, sls_detector_module *myMod){
|
||||||
|
|
||||||
int nflag=0;
|
int nflag=0;
|
||||||
|
|
||||||
|
|
||||||
@ -95,8 +95,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
int ichan=0, ichip=0, idac=0;
|
int ichan=0, ichip=0, idac=0;
|
||||||
int nch=((myMod->nchan)/(myMod->nchip));
|
int nch=((myMod->nchan)/(myMod->nchip));
|
||||||
|
|
||||||
|
//ascii settings/trim file
|
||||||
//to verify dac
|
|
||||||
switch (myDetectorType) {
|
switch (myDetectorType) {
|
||||||
case MYTHEN:
|
case MYTHEN:
|
||||||
break;
|
break;
|
||||||
@ -112,22 +111,6 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
names[id++]="Vib_test";
|
names[id++]="Vib_test";
|
||||||
break;
|
break;
|
||||||
case EIGER:
|
case EIGER:
|
||||||
names[id++]="SvP";
|
|
||||||
names[id++]="SvN";
|
|
||||||
names[id++]="Vtr";
|
|
||||||
names[id++]="Vrf";
|
|
||||||
names[id++]="Vrs";
|
|
||||||
names[id++]="Vtgstv";
|
|
||||||
names[id++]="Vcmp_ll";
|
|
||||||
names[id++]="Vcmp_lr";
|
|
||||||
names[id++]="cal";
|
|
||||||
names[id++]="Vcmp_rl";
|
|
||||||
names[id++]="Vcmp_rr";
|
|
||||||
names[id++]="rxb_rb";
|
|
||||||
names[id++]="rxb_lb";
|
|
||||||
names[id++]="Vcp";
|
|
||||||
names[id++]="Vcn";
|
|
||||||
names[id++]="Vis";
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Unknown detector type - unknown format for settings file" << endl;
|
cout << "Unknown detector type - unknown format for settings file" << endl;
|
||||||
@ -141,14 +124,12 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "file name is "<< myfname << std::endl;
|
std::cout<< "file name is "<< myfname << std::endl;
|
||||||
#endif
|
#endif
|
||||||
infile.open(myfname.c_str(), ios_base::in);
|
|
||||||
if (infile.is_open()) {
|
|
||||||
|
|
||||||
|
switch (myDetectorType) {
|
||||||
|
|
||||||
switch (myDetectorType) {
|
case MYTHEN:
|
||||||
|
infile.open(myfname.c_str(), ios_base::in);
|
||||||
case MYTHEN:
|
if (infile.is_open()) {
|
||||||
|
|
||||||
for (int iarg=0; iarg<myMod->ndac; iarg++) {
|
for (int iarg=0; iarg<myMod->ndac; iarg++) {
|
||||||
getline(infile,str);
|
getline(infile,str);
|
||||||
iline++;
|
iline++;
|
||||||
@ -163,25 +144,25 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
for (ichip=0; ichip<myMod->nchip; ichip++) {
|
for (ichip=0; ichip<myMod->nchip; ichip++) {
|
||||||
getline(infile,str);
|
getline(infile,str);
|
||||||
iline++;
|
iline++;
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
// std::cout<< str << std::endl;
|
std::cout<< str << std::endl;
|
||||||
#endif
|
#endif
|
||||||
istringstream ssstr(str);
|
istringstream ssstr(str);
|
||||||
ssstr >> sargname >> ival;
|
ssstr >> sargname >> ival;
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
// std::cout<< "chip " << ichip << " " << sargname << " is " << ival << std::endl;
|
std::cout<< "chip " << ichip << " " << sargname << " is " << ival << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
myMod->chipregs[ichip]=ival;
|
myMod->chipregs[ichip]=ival;
|
||||||
for (ichan=0; ichan<nch; ichan++) {
|
for (ichan=0; ichan<nch; ichan++) {
|
||||||
getline(infile,str);
|
getline(infile,str);
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
// std::cout<< str << std::endl;
|
std::cout<< str << std::endl;
|
||||||
#endif
|
#endif
|
||||||
istringstream ssstr(str);
|
istringstream ssstr(str);
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
// std::cout<< "channel " << ichan+ichip*thisDetector->nChans <<" iline " << iline<< std::endl;
|
std::cout<< "channel " << ichan+ichip*thisDetector->nChans <<" iline " << iline<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
iline++;
|
iline++;
|
||||||
myMod->chanregs[ichip*nch+ichan]=0;
|
myMod->chanregs[ichip*nch+ichan]=0;
|
||||||
@ -190,38 +171,38 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
//if (ssstr.good()) {
|
//if (ssstr.good()) {
|
||||||
switch (iarg) {
|
switch (iarg) {
|
||||||
case 0:
|
case 0:
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
// std::cout<< "trimbits " << ival ;
|
std::cout<< "trimbits " << ival ;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival&TRIMBITMASK;
|
myMod->chanregs[ichip*nch+ichan]|=ival&TRIMBITMASK;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
//std::cout<< " compen " << ival ;
|
std::cout<< " compen " << ival ;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival<<9;
|
myMod->chanregs[ichip*nch+ichan]|=ival<<9;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
//std::cout<< " anen " << ival ;
|
std::cout<< " anen " << ival ;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival<<8;
|
myMod->chanregs[ichip*nch+ichan]|=ival<<8;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#ifdef VERBOSE
|
#ifdef VERYVERBOSE
|
||||||
//std::cout<< " calen " << ival ;
|
std::cout<< " calen " << ival ;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival<<7;
|
myMod->chanregs[ichip*nch+ichan]|=ival<<7;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
//std::cout<< " outcomp " << ival ;
|
std::cout<< " outcomp " << ival ;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival<<10;
|
myMod->chanregs[ichip*nch+ichan]|=ival<<10;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
//std::cout<< " counts " << ival << std::endl;
|
std::cout<< " counts " << ival << std::endl;
|
||||||
#endif
|
#endif
|
||||||
myMod->chanregs[ichip*nch+ichan]|=ival<<11;
|
myMod->chanregs[ichip*nch+ichan]|=ival<<11;
|
||||||
break;
|
break;
|
||||||
@ -237,14 +218,46 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
std::cout<< "read " << ichan*ichip << " channels" <<std::endl;
|
std::cout<< "read " << ichan*ichip << " channels" <<std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
infile.close();
|
||||||
|
strcpy(settingsFile,fname.c_str());
|
||||||
|
|
||||||
break;
|
return myMod;
|
||||||
|
|
||||||
case EIGER:
|
}
|
||||||
case MOENCH:
|
|
||||||
case GOTTHARD:
|
|
||||||
//---------------dacs---------------
|
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EIGER:
|
||||||
|
infile.open(myfname.c_str(),ifstream::binary);
|
||||||
|
if (infile.is_open()) {
|
||||||
|
infile.read((char*) myMod->dacs,sizeof(int)*(myMod->ndac));
|
||||||
|
infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan));
|
||||||
|
#ifdef VERBOSE
|
||||||
|
for(int i=0;i<myMod->ndac;i++)
|
||||||
|
std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl;
|
||||||
|
#endif
|
||||||
|
if(infile.eof()){
|
||||||
|
cout<<endl<<"Error, could not load trimbits end of file, "<<myfname<<", reached."<<endl<<endl;
|
||||||
|
if (nflag)
|
||||||
|
deleteModule(myMod);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
infile.close();
|
||||||
|
strcpy(settingsFile,fname.c_str());
|
||||||
|
|
||||||
|
return myMod;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOENCH:
|
||||||
|
case GOTTHARD:
|
||||||
|
//---------------dacs---------------
|
||||||
|
infile.open(myfname.c_str(), ios_base::in);
|
||||||
|
if (infile.is_open()) {
|
||||||
while(infile.good()) {
|
while(infile.good()) {
|
||||||
getline(infile,str);
|
getline(infile,str);
|
||||||
iline++;
|
iline++;
|
||||||
@ -271,132 +284,133 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
|
|||||||
}else
|
}else
|
||||||
std::cout<< "Unknown dac " << sargname << std::endl;
|
std::cout<< "Unknown dac " << sargname << std::endl;
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
std::cout<< "Unknown detector type - don't know how to read file" << myfname << std::endl;
|
|
||||||
infile.close();
|
infile.close();
|
||||||
deleteModule(myMod);
|
strcpy(settingsFile,fname.c_str());
|
||||||
return NULL;
|
|
||||||
|
return myMod;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cout<< "Unknown detector type - don't know how to read file" << myfname << std::endl;
|
||||||
infile.close();
|
infile.close();
|
||||||
strcpy(settingsFile,fname.c_str());
|
deleteModule(myMod);
|
||||||
return myMod;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
std::cout<< "could not open settings file " << myfname << std::endl;
|
|
||||||
|
|
||||||
if (nflag)
|
|
||||||
deleteModule(myMod);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout<< "could not open settings file " << myfname << std::endl;
|
||||||
|
if (nflag)
|
||||||
|
deleteModule(myMod);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod){
|
int energyConversion::writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod){
|
||||||
|
|
||||||
ofstream outfile;
|
ofstream outfile;
|
||||||
|
|
||||||
int nch=((mod.nchan)/(mod.nchip));
|
int nch=((mod.nchan)/(mod.nchip));
|
||||||
|
|
||||||
string names[100];
|
string names[100];
|
||||||
int id=0;
|
int id=0;
|
||||||
switch (myDetectorType) {
|
switch (myDetectorType) {
|
||||||
case MYTHEN:
|
case MYTHEN:
|
||||||
names[id++]="Vtrim";
|
names[id++]="Vtrim";
|
||||||
names[id++]="Vthresh";
|
names[id++]="Vthresh";
|
||||||
names[id++]="Rgsh1";
|
names[id++]="Rgsh1";
|
||||||
names[id++]="Rgsh2";
|
names[id++]="Rgsh2";
|
||||||
names[id++]="Rgpr";
|
names[id++]="Rgpr";
|
||||||
names[id++]="Vcal";
|
names[id++]="Vcal";
|
||||||
names[id++]="outBuffEnable";
|
names[id++]="outBuffEnable";
|
||||||
break;
|
break;
|
||||||
case MOENCH:
|
case MOENCH:
|
||||||
case GOTTHARD:
|
case GOTTHARD:
|
||||||
names[id++]="Vref";
|
names[id++]="Vref";
|
||||||
names[id++]="VcascN";
|
names[id++]="VcascN";
|
||||||
names[id++]="VcascP";
|
names[id++]="VcascP";
|
||||||
names[id++]="Vout";
|
names[id++]="Vout";
|
||||||
names[id++]="Vcasc";
|
names[id++]="Vcasc";
|
||||||
names[id++]="Vin";
|
names[id++]="Vin";
|
||||||
names[id++]="Vref_comp";
|
names[id++]="Vref_comp";
|
||||||
names[id++]="Vib_test";
|
names[id++]="Vib_test";
|
||||||
break;
|
break;
|
||||||
case EIGER:
|
case EIGER:
|
||||||
names[id++]="SvP";
|
break;
|
||||||
names[id++]="SvN";
|
default:
|
||||||
names[id++]="Vtr";
|
cout << "Unknown detector type - unknown format for settings file" << endl;
|
||||||
names[id++]="Vrf";
|
return FAIL;
|
||||||
names[id++]="Vrs";
|
|
||||||
names[id++]="Vin";
|
|
||||||
names[id++]="Vtgstv";
|
|
||||||
names[id++]="Vcmp_ll";
|
|
||||||
names[id++]="Vcmp_lr";
|
|
||||||
names[id++]="cal";
|
|
||||||
names[id++]="Vcmp_rl";
|
|
||||||
names[id++]="Vcmp_rr";
|
|
||||||
names[id++]="rxb_rb";
|
|
||||||
names[id++]="rxb_lb";
|
|
||||||
names[id++]="Vcmp_lr";
|
|
||||||
names[id++]="Vcp";
|
|
||||||
names[id++]="Vcmp_rl";
|
|
||||||
names[id++]="Vcn";
|
|
||||||
names[id++]="Vis";
|
|
||||||
names[id++]="iodelay";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cout << "Unknown detector type - unknown format for settings file" << endl;
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int iv, ichan, ichip;
|
|
||||||
int iv1, idac;
|
|
||||||
int nb;
|
|
||||||
outfile.open(fname.c_str(), ios_base::out);
|
|
||||||
|
|
||||||
if (outfile.is_open()) {
|
|
||||||
for (idac=0; idac<mod.ndac; idac++) {
|
|
||||||
iv=(int)mod.dacs[idac];
|
|
||||||
outfile << names[idac] << " " << iv << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((myDetectorType!=GOTTHARD)&&(myDetectorType!=MOENCH)&&(myDetectorType!=EIGER)){
|
|
||||||
for (ichip=0; ichip<mod.nchip; ichip++) {
|
|
||||||
iv1=mod.chipregs[ichip]&1;
|
|
||||||
outfile << names[idac] << " " << iv1 << std::endl;
|
|
||||||
for (ichan=0; ichan<nch; ichan++) {
|
|
||||||
iv=mod.chanregs[ichip*nch+ichan];
|
|
||||||
iv1= (iv&TRIMBITMASK);
|
|
||||||
outfile <<iv1 << " ";
|
|
||||||
nb=9;
|
|
||||||
iv1=((iv&(1<<nb))>>nb);
|
|
||||||
outfile << iv1 << " ";
|
|
||||||
nb=8;
|
|
||||||
iv1=((iv&(1<<nb))>>nb);
|
|
||||||
outfile << iv1 << " ";
|
|
||||||
nb=7;
|
|
||||||
iv1=((iv&(1<<nb))>>nb);
|
|
||||||
outfile <<iv1 << " ";
|
|
||||||
nb=10;
|
|
||||||
iv1=((iv&(1<<nb))>>nb);
|
|
||||||
outfile << iv1 << " ";
|
|
||||||
nb=11;
|
|
||||||
iv1= ((iv&0xfffff800)>>nb);
|
|
||||||
outfile << iv1 << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
int iv, ichan, ichip;
|
||||||
outfile.close();
|
int iv1, idac;
|
||||||
return OK;
|
int nb;
|
||||||
} else {
|
|
||||||
std::cout<< "could not open SETTINGS file " << fname << std::endl;
|
switch (myDetectorType) {
|
||||||
return FAIL;
|
case EIGER:
|
||||||
}
|
outfile.open(fname.c_str(), ofstream::binary);
|
||||||
|
if (outfile.is_open()) {
|
||||||
|
iv = 1150;
|
||||||
|
outfile.write((char*)mod.dacs, sizeof(int)*(mod.ndac));
|
||||||
|
outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan));
|
||||||
|
outfile.close();
|
||||||
|
return slsDetectorDefs::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<< "could not open SETTINGS file " << fname << std::endl;
|
||||||
|
return slsDetectorDefs::FAIL;
|
||||||
|
default:
|
||||||
|
|
||||||
|
|
||||||
|
outfile.open(fname.c_str(), ios_base::out);
|
||||||
|
|
||||||
|
if (outfile.is_open()) {
|
||||||
|
for (idac=0; idac<mod.ndac; idac++) {
|
||||||
|
iv=(int)mod.dacs[idac];
|
||||||
|
outfile << names[idac] << " " << iv << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(myDetectorType==MYTHEN){
|
||||||
|
for (ichip=0; ichip<mod.nchip; ichip++) {
|
||||||
|
iv1=mod.chipregs[ichip]&1;
|
||||||
|
outfile << names[idac] << " " << iv1 << std::endl;
|
||||||
|
for (ichan=0; ichan<nch; ichan++) {
|
||||||
|
iv=mod.chanregs[ichip*nch+ichan];
|
||||||
|
iv1= (iv&TRIMBITMASK);
|
||||||
|
outfile <<iv1 << " ";
|
||||||
|
nb=9;
|
||||||
|
iv1=((iv&(1<<nb))>>nb);
|
||||||
|
outfile << iv1 << " ";
|
||||||
|
nb=8;
|
||||||
|
iv1=((iv&(1<<nb))>>nb);
|
||||||
|
outfile << iv1 << " ";
|
||||||
|
nb=7;
|
||||||
|
iv1=((iv&(1<<nb))>>nb);
|
||||||
|
outfile <<iv1 << " ";
|
||||||
|
nb=10;
|
||||||
|
iv1=((iv&(1<<nb))>>nb);
|
||||||
|
outfile << iv1 << " ";
|
||||||
|
nb=11;
|
||||||
|
iv1= ((iv&0xfffff800)>>nb);
|
||||||
|
outfile << iv1 << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outfile.close();
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
std::cout<< "could not open SETTINGS file " << fname << std::endl;
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ class energyConversion
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
reads a calibration file
|
reads a calibration file
|
||||||
\param fname file to be read
|
\param fname file to be read
|
||||||
\param gain reference to the gain variable
|
\param gain reference to the gain variable
|
||||||
@ -39,7 +38,6 @@ class energyConversion
|
|||||||
static int readCalibrationFile(string fname, double &gain, double &offset);
|
static int readCalibrationFile(string fname, double &gain, double &offset);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
writes a calibration file
|
writes a calibration file
|
||||||
\param fname file to be written
|
\param fname file to be written
|
||||||
\param gain
|
\param gain
|
||||||
@ -68,7 +66,7 @@ class energyConversion
|
|||||||
|
|
||||||
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
||||||
*/
|
*/
|
||||||
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod);
|
int writeSettingsFile(string fname, detectorType myDetectorType, sls_detector_module mod);
|
||||||
|
|
||||||
/** allocates the momery for a detector module structure
|
/** allocates the momery for a detector module structure
|
||||||
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
\param myDetectorType detector type (needed for number of channels, chips, dacs etc.)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user