diff --git a/pub/CHANGELOG b/pub/CHANGELOG index eef935dded7f54432f6a6ae87def2a04e32c68cb..0ea4e9f97c9322f24f05e809aa62008ba82e1a78 100644 --- a/pub/CHANGELOG +++ b/pub/CHANGELOG @@ -4,7 +4,9 @@ Release - 'dd' now shows doc lines, 'ed' allows to edit them via vi - improved behavior: - reduce noise in lDoc (no 'cf'; basic merge in 'mfj') - +- internal changes: + - eliminate remnants of SPHERES/XML read in + Release 2.1.0c of 21may10: - bugfixes, among them: diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp index f7e64e6543fdfef7a92513286ed9969b31dd9c11..c1c81077d296d803d025a1c3bbf4d9349ffc7b80 100644 --- a/pub/src/frida2.cpp +++ b/pub/src/frida2.cpp @@ -521,49 +521,22 @@ int main() " ryd load only spectra for two directions\n" " rs load series of energy spectra\n" " rs2 load also spectra for open state\n" - " rold list old-format commands\n" - ; - - } else if (cmd == "rold") { - cout << "read old/internal RSSM data files:\n" - " rx load energy spectra\n" - " rx2 load also spectra for open state\n" - " rx4 load also chopper histograms\n" - " rx8 load spectra for two directions separately\n" - " rxd load only spectra for two directions\n" - " rxs load series of energy spectra\n" - " rxs2 load also spectra for open state\n" ; } else if (cmd == "ry" ) { - NRSSM::ReadSpec( 5, 0 ); + NRSSM::ReadSpec( 0 ); } else if (cmd == "ry2") { - NRSSM::ReadSpec( 5, 1 ); + NRSSM::ReadSpec( 1 ); } else if (cmd == "ry4") { - NRSSM::ReadSpec( 5, 3 ); + NRSSM::ReadSpec( 3 ); } else if (cmd == "ry8") { - NRSSM::ReadSpec( 5, 7 ); + NRSSM::ReadSpec( 7 ); } else if (cmd == "ryd") { - NRSSM::ReadSpec( 5, 12 ); + NRSSM::ReadSpec( 12 ); } else if (cmd == "rs") { - NRSSM::ReadSeries( 5, 0 ); + NRSSM::ReadSeries( 0 ); } else if (cmd == "rs2") { - NRSSM::ReadSeries( 5, 1 ); - - } else if (cmd == "rx") { - NRSSM::ReadSpec( 2, 0 ); - } else if (cmd == "rx2") { - NRSSM::ReadSpec( 2, 1 ); - } else if (cmd == "rx4") { - NRSSM::ReadSpec( 2, 3 ); - } else if (cmd == "rx8") { - NRSSM::ReadSpec( 2, 7 ); - } else if (cmd == "rxd") { - NRSSM::ReadSpec( 2, 12 ); - } else if (cmd == "rxx") { - NRSSM::ReadSeries( 2, 0 ); - } else if (cmd == "rxs2") { - NRSSM::ReadSeries( 2, 1 ); + NRSSM::ReadSeries( 1 ); } else if (cmd == "t") { diff --git a/pub/src/rssm.cpp b/pub/src/rssm.cpp index d7de2c98a12fad0ee75af5fc23eb4770f57f1d52..f5ffc28e9649b693b2087d7bc061e91191ac129e 100644 --- a/pub/src/rssm.cpp +++ b/pub/src/rssm.cpp @@ -22,7 +22,7 @@ using namespace std; -class RssmRawFile { +class CRawfileSpheres { public: void RdRawYam( ifstream& F_in ); double daq_time_step; @@ -38,15 +38,15 @@ class RssmRawFile { //! Read raw data file, store contents as class variables -//void RssmRawFile::RdRawYam( FILE *F_in ) -void RssmRawFile::RdRawYam( ifstream& F_in ) +//void CRawfileSpheres::RdRawYam( FILE *F_in ) +void CRawfileSpheres::RdRawYam( ifstream& F_in ) { string lin, key, val, bla, blub; CCoord co; CSpec sout; - int ndet; double num; vector<double> numvec; + uint ndet; maj_outform = 5; min_outform = 1; @@ -58,27 +58,27 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) YAML::Node doc; parser.GetNextDocument(doc); - //start to read Meta + // read Meta: if(!doc.FindValue("Meta")) throw string("no Meta" ); try { YAML::CONTENT_TYPE Metatype = doc["Meta"].GetType(); if ( Metatype != YAML::CT_MAP && doc["Meta"].size() > 0) - throw string("Meta is not a MAP type" ); + throw string("DATA BUG: Meta is not a MAP" ); if(!doc["Meta"].FindValue("format")) - throw string("no format in Meta" ); + throw string("DATA BUG: no format in Meta" ); doc["Meta"]["format"] >> val; if( strncmp( val.c_str(), "acq5.1 for yaml1", 16 ) ) - throw( string("Unexpected format: ") + val + " instead of acq5.1" ); + throw "UNEXPECTED DATA: format: " + val + " instead of acq5.1"; } catch(YAML::ParserException& e) { - std::cout << "no Meta" << e.what() << "\n"; + throw string( "DATA BUG: failed to read Meta section" ) + e.what(); } - //do nothing in History + // ignore History. - //start to read Shortpar + // read Shortpar: if(!doc.FindValue("Shortpar")) - throw string("no Shortpar" ); + throw string( "DATA BUG: no Shortpar" ); for(YAML::Iterator it=doc["Shortpar"].begin(); it!=doc["Shortpar"].end();++it) { it.first() >> key; @@ -89,8 +89,8 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) else if ( val=="false" ) incremental = false; else - throw string( "Invalid value [" ) + val + - "] of 'incremental'"; + throw string( "DATA BUG: invalid value [" ) + val + + "] of 'incremental'"; } else if ( key=="measured_until" ){ char date_string[24]; sscanf( val.c_str(), "%24c", date_string ); @@ -98,54 +98,52 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) strptime( date_string, "%F %A %H:%M:%S", &date_broken ); measured_until = mktime( &date_broken ); } else if ( key=="ndet" ){ - if( !mystd::any2int( val, &ndet ) ) - throw string( "invalid ndet" ); + if( !mystd::any2uint( val, &ndet ) ) + throw string( "DATA BUG: invalid ndet" ); } else if ( key=="daq_time_step" ){ mystd::string_extract_word( val, &bla, &blub ); mystd::any2dbl( bla, &daq_time_step ); } } if( !daq_time_step ) - throw string( "daq time step not found" ); + throw string( "DATA BUG: daq time step not found" ); - //do nothing in Longpar + // ignore Longpar. - //start to read Detectors + // read Detectors: if(!doc.FindValue("Detectors")) - throw string("no Detectors" ); - if ( doc["Detectors"].GetType() != YAML::CT_SEQUENCE && - doc["Detectors"].size() > 0 ) - throw string("Detectors is not a SEQUENCE type" ); - for (unsigned int iDet = 0; iDet < (doc["Detectors"].size()); - iDet++) { + throw string("DATA BUG: no Detectors" ); + if ( doc["Detectors"].GetType() != YAML::CT_SEQUENCE ) + throw string("DATA BUG: Detectors is not a SEQUENCE" ); + if( doc["Detectors"].size()!=ndet ) + throw string("DATA BUG: Detectors has not size ndet" ); + for (uint iDet = 0; iDet<ndet; iDet++) { if ( doc["Detectors"][iDet].GetType() != YAML::CT_MAP ) - throw string("Detectors " + strg(iDet) + - " is not a MAP type" ); + throw string("DATA BUG: Detector ") + strg(iDet) + " is not a MAP"; if( const YAML::Node *pName = doc["Detectors"][iDet].FindValue("angle") ){ *pName >> val; if( !mystd::any2dbl( val, &num ) ){ num = 0; - printf( "warning: invalid angle %s\n", + printf( "WARNING: invalid angle %s\n", val.c_str() ); } }else - throw string( "missing angle" ); + throw string( "DATA BUG: missing angle" ); // path_offset ? angles.push_back( num ); } - //start to read EnergyHistograms - if(!doc.FindValue("EnergyHistograms")) - throw string("no EnergyHistograms" ); - if ( doc["EnergyHistograms"].GetType() != YAML::CT_SEQUENCE && - doc["EnergyHistograms"].size() > 0 ) - throw string("EnergyHistograms is not a SEQUENCE type" ); - for (unsigned int iEne = 0; - iEne < (doc["EnergyHistograms"].size()); iEne++) { + // read EnergyHistograms: + if( !doc.FindValue("EnergyHistograms") ) + throw string("DATA BUG: no EnergyHistograms" ); + if ( doc["EnergyHistograms"].GetType() != YAML::CT_SEQUENCE ) + throw string("DATA BUG: EnergyHistograms is not a SEQUENCE" ); + uint nEne = doc["EnergyHistograms"].size(); + for ( uint iEne = 0; iEne<nEne; iEne++ ) { if ( doc["EnergyHistograms"][iEne].GetType() != YAML::CT_SEQUENCE ) - throw "EnergyHistograms " + strg(iEne) + - " is not a SEQUENCE type"; + throw "DATA BUUG: EnergyHistogram " + strg(iEne) + + " is not a SEQUENCE"; doc["EnergyHistograms"][iEne][0] >> val; if( !mystd::any2dbl( val, &num ) ) throw string( "E-Hist: invalid x-value " ) + val; @@ -154,61 +152,57 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) for( int i=0; i<4; ++i ){ doc["EnergyHistograms"][iEne][i+1] >> val;// cnts line if( !mystd::str2vec( val, &numvec ) ) - throw string( "cnts line extraction failed" ); + throw string( "DATA BUG: cnts line extraction failed" ); if( numvec.size()!=ndet ) - throw string( "hist: ndet incompatibility" ); + throw string( "DATA BUG: hist: ndet incompatibility" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } for( int i=0; i<4; ++i ){ doc["EnergyHistograms"][iEne][i+1+4] >> val;// time line if( !mystd::str2vec( val, &numvec ) ) - throw string( "time line extraction failed" ); + throw string( "DATA BUG: time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } } - //start to read ChopperHistograms + // read ChopperHistograms: if(!doc.FindValue("ChopperHistograms")) throw string("no ChopperHistograms" ); - if ( doc["ChopperHistograms"].GetType() != YAML::CT_SEQUENCE && - doc["ChopperHistograms"].size() > 0 ) - throw string("ChopperHistograms is not a SEQUENCE type" ); - for (unsigned int iCho = 0; - iCho < (doc["ChopperHistograms"].size()); iCho++) { + if ( doc["ChopperHistograms"].GetType() != YAML::CT_SEQUENCE ) + throw string( "DATA BUG: ChopperHistograms is not a SEQUENCE" ); + uint nCho = doc["ChopperHistograms"].size(); + for (uint iCho = 0; iCho<nCho; iCho++) { if ( doc["ChopperHistograms"][iCho].GetType() != YAML::CT_SEQUENCE ) - throw string("ChopperHistograms " + strg(iCho) + - " is not a SEQUENCE type" ); + throw string( "DATA BUG: ChopperHistograms " ) + strg(iCho) + + " is not a SEQUENCE"; doc["ChopperHistograms"][iCho][0] >> val; if( !mystd::any2dbl( val, &num ) ) - throw string( "C-Hist: invalid x-value " ) + val; + throw string( "DATA BUG: C-Hist: invalid x-value " ) + val; for( int i=4; i<6; ++i ) rawdata[i].push_back( num ); for( int i=4; i<6; ++i ){ // 2 cnts lines doc["ChopperHistograms"][iCho][i-4+1] >> val;//cnts line if( !mystd::str2vec( val, &numvec ) ) - throw string( "cnts line extraction failed" ); + throw string( "DATA BUG: cnts line extraction failed" ); if( numvec.size()!=ndet ) - throw string( "hist: ndet incompatibility" ); + throw string( "DATA BUG: hist: ndet incompatibility" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } for( int i=4; i<6; ++i ){ // 2 time lines doc["ChopperHistograms"][iCho][i-4+1+2] >> val;//time line if( !mystd::str2vec( val, &numvec ) ) - throw string( "time line extraction failed" ); + throw string( "DATA BUG: time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } } } -void NRSSM::ReadSpec( int format, int flag ) +void NRSSM::ReadSpec( int flag ) -// format values: -// 2 acq2-4 xml -// 5 acq5 yaml // flag values (to be OR'ed): // 1 save also open // 2 save also chop histo @@ -218,33 +212,13 @@ void NRSSM::ReadSpec( int format, int flag ) { string file_f, name; file_f = wask("Read SPHERES data from file"); - RssmRawFile R; - int ret; + CRawfileSpheres R; ifstream F_in; - if ( format==2 ){ - throw string( "XML support has been withdrawn from frida2 on 19may09" ); - } else if ( format==5 ){ - F_in.open (file_f.c_str(),fstream::in); - if( !(F_in.is_open()) ) { - cerr << "Cannot read " << file_f << "\n"; - return; - } - try{ - R.RdRawYam( F_in ); - } - catch( string &e) { - cerr << "Cannot read " << file_f << ":\n"; - cerr << e << endl; - if (F_in.is_open()) F_in.close(); - return; - } - ret = 0; - } else { - throw string( "invalid format" ); - } - if( ret ) - return; + F_in.open (file_f.c_str(),fstream::in); + if( !(F_in.is_open()) ) + throw "Cannot read " + file_f; + R.RdRawYam( F_in ); double tstep = R.daq_time_step; vector<double> *raw = R.rawdata; @@ -288,11 +262,11 @@ void NRSSM::ReadSpec( int format, int flag ) olf[iolf]->V.push_back(S); } - if( R.maj_outform<=2 ){ + if( R.maj_outform<=2 ){ // old data format double x, tmeas, count; // transfer data from raw arrays: for( iolf=0; iolf<6; ++iolf ){ - for( int iraw=0; iraw<(raw+iolf)->size(); iraw+=(ndet+2) ){ + for( int iraw=0; iraw<raw[iolf].size(); iraw+=(ndet+2) ){ x = raw[iolf][iraw]; tmeas = raw[iolf][iraw+ndet+1]; if( tmeas<1 ) continue; @@ -306,11 +280,9 @@ void NRSSM::ReadSpec( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - int nline = (raw+iolf0)->size(); - if( (raw+iolf1)->size()!=nline ){ - printf( "inconsistent raw array sizes\n" ); - return; - } + int nline = raw[iolf0].size(); + if( raw[iolf1].size()!=nline ) + throw string( "inconsistent raw array sizes" ); for( int iraw=0; iraw<nline; iraw+=(ndet+2) ){ x = raw[iolf0][iraw]; tmeas = raw[iolf0][iraw+ndet+1]+raw[iolf1][iraw+ndet+1]; @@ -326,7 +298,7 @@ void NRSSM::ReadSpec( int format, int flag ) double x, tmeas, count; // transfer data from raw arrays: for( iolf=0; iolf<6; ++iolf ){ - for( int iraw=0; iraw<(raw+iolf)->size(); iraw+=(1+ndet*2) ){ + for( int iraw=0; iraw<raw[iolf].size(); iraw+=(1+ndet*2) ){ x = raw[iolf][iraw]; for ( int j=0; j<ndet; ++j ){ tmeas = raw[iolf][iraw+1+ndet+j]; @@ -340,13 +312,9 @@ void NRSSM::ReadSpec( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - int nline = (raw+iolf0)->size(); - if( (raw+iolf1)->size()!=nline ){ - printf( "inconsistent raw array sizes: " - "left %zu right %zu lines\n", - (raw+iolf0)->size(), (raw+iolf1)->size() ); - return; - } + int nline = raw[iolf0].size(); + if( raw[iolf1].size()!=nline ) + throw string( "inconsistent raw array sizes" ); for( int iraw=0; iraw<nline; iraw+=(1+ndet*2) ){ x = raw[iolf0][iraw]; for ( int j=0; j<ndet; ++j ){ @@ -382,10 +350,8 @@ void NRSSM::ReadSpec( int format, int flag ) } -void NRSSM::ReadSeries( int format, int flag ) +void NRSSM::ReadSeries( int flag ) -// format values: -// as above // flag values (to be OR'ed): // 1 save also open @@ -393,42 +359,26 @@ void NRSSM::ReadSeries( int format, int flag ) char tstrg[30]; string fser, fnam, name; time_t t; - int ret, isub; - vector<RssmRawFile> RR; + int isub; + vector<CRawfileSpheres> RR; // Read consolidated files: fser = wask("Read SPHERES data from series"); for( isub=0; ; ++isub ){ - if ( format==2 ) { - throw string( - "XML support has been withdrawn from frida2 on 19may09" ); - } else if( format==5 ) { - fnam = fser+"a"+strg(isub); - ifstream F_in; - F_in.open(fnam.c_str(),fstream::in); - if( !(F_in.is_open()) ) - break; - // cout << "successfully opened "<<fnam<<"\n"; - try{ - RssmRawFile rf; - rf.RdRawYam( F_in ); - RR.push_back( rf ); - } - catch(exception& e) { - cerr << e.what() << endl; - if (F_in.is_open()) F_in.close(); - return; - } - ret = 0; - } else { - throw string( "invalid format parameter" ); - } - if ( ret ) - return; + fnam = fser+"a"+strg(isub); + ifstream F_in; + F_in.open(fnam.c_str(),fstream::in); + if( !(F_in.is_open()) ) + break; + // cout << "successfully opened "<<fnam<<"\n"; + CRawfileSpheres rf; + rf.RdRawYam( F_in ); + RR.push_back( rf ); } + int nsub = RR.size(); if( nsub==0 ) - throw string( "could not open file " ) + fnam; + throw "could not open file " + fnam; else if( nsub==1 ) throw string( "series contains just one spectrum -> use a simpler method"); printf( "successfully read %d files\n", nsub ); @@ -521,10 +471,10 @@ void NRSSM::ReadSeries( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - if( (raw+iolf1)->size()/(1+ndet*2)!=nE ){ + if( raw[iolf1].size()/(1+ndet*2)!=nE ){ printf( "inconsistent raw array sizes:\n" " chop %i raw1 %zu nE %i\n", - ichop, (raw+iolf1)->size(), nE ); + ichop, raw[iolf1].size(), nE ); return; } for( int iE=0; iE<nE; ++iE ){ @@ -569,7 +519,7 @@ void NRSSM::ReadSeries( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - if( (raw+iolf1)->size()/(ndet+2)!=nE ){ + if( raw[iolf1].size()/(ndet+2)!=nE ){ printf( "inconsistent raw array sizes\n" ); return; } diff --git a/pub/src/rssm.h b/pub/src/rssm.h index 69ebc91b5ae2f90e0729337040e73b0c970675c2..174e4d4bee98b04d69eb37a4d8410409c73fd5fc 100644 --- a/pub/src/rssm.h +++ b/pub/src/rssm.h @@ -1,4 +1,4 @@ namespace NRSSM { - void ReadSpec( int format, int flag ); - void ReadSeries( int format, int flag ); + void ReadSpec( int flag ); + void ReadSeries( int flag ); };