From 19d3c1eb0ca77f7c58c6f679b3a8a26e56452978 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Fri, 21 Jun 2013 14:25:07 +0000 Subject: [PATCH] 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 --- .../slsDetectorAnalysis/energyConversion.cpp | 330 +++++++++--------- .../slsDetectorAnalysis/energyConversion.h | 4 +- 2 files changed, 173 insertions(+), 161 deletions(-) diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp index f734f301b..a85d8e3e6 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.cpp @@ -5,6 +5,7 @@ #include #include +#include "fileIOStatic.h" 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){ - int nflag=0; @@ -95,8 +95,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string int ichan=0, ichip=0, idac=0; int nch=((myMod->nchan)/(myMod->nchip)); - - //to verify dac + //ascii settings/trim file switch (myDetectorType) { case MYTHEN: break; @@ -112,22 +111,6 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string names[id++]="Vib_test"; break; 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; default: cout << "Unknown detector type - unknown format for settings file" << endl; @@ -141,14 +124,12 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string #ifdef VERBOSE std::cout<< "file name is "<< myfname << std::endl; #endif - infile.open(myfname.c_str(), ios_base::in); - if (infile.is_open()) { + switch (myDetectorType) { - switch (myDetectorType) { - - case MYTHEN: - + case MYTHEN: + infile.open(myfname.c_str(), ios_base::in); + if (infile.is_open()) { for (int iarg=0; iargndac; iarg++) { getline(infile,str); iline++; @@ -163,25 +144,25 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string for (ichip=0; ichipnchip; ichip++) { getline(infile,str); iline++; -#ifdef VERBOSE - // std::cout<< str << std::endl; +#ifdef VERYVERBOSE + std::cout<< str << std::endl; #endif istringstream ssstr(str); ssstr >> sargname >> ival; -#ifdef VERBOSE - // std::cout<< "chip " << ichip << " " << sargname << " is " << ival << std::endl; +#ifdef VERYVERBOSE + std::cout<< "chip " << ichip << " " << sargname << " is " << ival << std::endl; #endif myMod->chipregs[ichip]=ival; for (ichan=0; ichannChans <<" iline " << iline<< std::endl; +#ifdef VERYVERBOSE + std::cout<< "channel " << ichan+ichip*thisDetector->nChans <<" iline " << iline<< std::endl; #endif iline++; myMod->chanregs[ichip*nch+ichan]=0; @@ -190,38 +171,38 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string //if (ssstr.good()) { switch (iarg) { case 0: -#ifdef VERBOSE - // std::cout<< "trimbits " << ival ; +#ifdef VERYVERBOSE + std::cout<< "trimbits " << ival ; #endif myMod->chanregs[ichip*nch+ichan]|=ival&TRIMBITMASK; break; case 1: -#ifdef VERBOSE - //std::cout<< " compen " << ival ; +#ifdef VERYVERBOSE + std::cout<< " compen " << ival ; #endif myMod->chanregs[ichip*nch+ichan]|=ival<<9; break; case 2: -#ifdef VERBOSE - //std::cout<< " anen " << ival ; +#ifdef VERYVERBOSE + std::cout<< " anen " << ival ; #endif myMod->chanregs[ichip*nch+ichan]|=ival<<8; break; case 3: -#ifdef VERBOSE - //std::cout<< " calen " << ival ; +#ifdef VERYVERBOSE + std::cout<< " calen " << ival ; #endif myMod->chanregs[ichip*nch+ichan]|=ival<<7; break; case 4: #ifdef VERBOSE - //std::cout<< " outcomp " << ival ; + std::cout<< " outcomp " << ival ; #endif myMod->chanregs[ichip*nch+ichan]|=ival<<10; break; case 5: #ifdef VERBOSE - //std::cout<< " counts " << ival << std::endl; + std::cout<< " counts " << ival << std::endl; #endif myMod->chanregs[ichip*nch+ichan]|=ival<<11; break; @@ -237,14 +218,46 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string std::cout<< "read " << ichan*ichip << " channels" <dacs,sizeof(int)*(myMod->ndac)); + infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan)); +#ifdef VERBOSE + for(int i=0;indac;i++) + std::cout << "dac " << i << ":" << myMod->dacs[i] << std::endl; +#endif + if(infile.eof()){ + cout<>nb); - outfile << iv1 << " "; - nb=8; - iv1=((iv&(1<>nb); - outfile << iv1 << " "; - nb=7; - iv1=((iv&(1<>nb); - outfile <>nb); - outfile << iv1 << " "; - nb=11; - iv1= ((iv&0xfffff800)>>nb); - outfile << iv1 << std::endl; + string names[100]; + int id=0; + switch (myDetectorType) { + case MYTHEN: + names[id++]="Vtrim"; + names[id++]="Vthresh"; + names[id++]="Rgsh1"; + names[id++]="Rgsh2"; + names[id++]="Rgpr"; + names[id++]="Vcal"; + names[id++]="outBuffEnable"; + break; + case MOENCH: + case GOTTHARD: + names[id++]="Vref"; + names[id++]="VcascN"; + names[id++]="VcascP"; + names[id++]="Vout"; + names[id++]="Vcasc"; + names[id++]="Vin"; + names[id++]="Vref_comp"; + names[id++]="Vib_test"; + break; + case EIGER: + break; + default: + cout << "Unknown detector type - unknown format for settings file" << endl; + return FAIL; } - } - } - outfile.close(); - return OK; - } else { - std::cout<< "could not open SETTINGS file " << fname << std::endl; - return FAIL; - } + + int iv, ichan, ichip; + int iv1, idac; + int nb; + + switch (myDetectorType) { + 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>nb); + outfile << iv1 << " "; + nb=8; + iv1=((iv&(1<>nb); + outfile << iv1 << " "; + nb=7; + iv1=((iv&(1<>nb); + outfile <>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; + + } + }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h index a697843be..bd95b3202 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/energyConversion.h @@ -30,7 +30,6 @@ class energyConversion /** - reads a calibration file \param fname file to be read \param gain reference to the gain variable @@ -39,7 +38,6 @@ class energyConversion static int readCalibrationFile(string fname, double &gain, double &offset); /** - writes a calibration file \param fname file to be written \param gain @@ -68,7 +66,7 @@ class energyConversion \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 \param myDetectorType detector type (needed for number of channels, chips, dacs etc.)