#include "gotthardDetector.h" #include #include //using namespace std; /* detector configuration (no communication to server) */ /* Every detector should have a basic configuration file containing: type (mythen, pilatus etc.) hostname portnumber communication type (default TCP/IP) eventually secondary portnumber (e.g. mythen stop function) number of modules installed if different from the detector size (x,y) */ int gotthardDetector::readConfigurationFile(string const fname){ string ans; string str; ifstream infile; int iargval; int interrupt=0; char *args[100]; for (int ia=0; ia<100; ia++) { args[ia]=new char[1000]; } string sargname, sargval; int iline=0; std::cout<< "config file name "<< fname << std::endl; infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { while (infile.good() and interrupt==0) { sargname="none"; sargval="0"; getline(infile,str); iline++; #ifdef VERBOSE std::cout<< str << std::endl; #endif if (str.find('#')!=string::npos) { #ifdef VERBOSE std::cout<< "Line is a comment " << std::endl; std::cout<< str << std::endl; #endif continue; } else if (str.length()<2) { #ifdef VERBOSE std::cout<< "Empty line " << std::endl; #endif continue; } else { istringstream ssstr(str); iargval=0; while (ssstr.good()) { ssstr >> sargname; //if (ssstr.good()) { #ifdef VERBOSE std::cout<< iargval << " " << sargname << std::endl; #endif strcpy(args[iargval],sargname.c_str()); iargval++; //} } ans=executeLine(iargval,args,PUT_ACTION); #ifdef VERBOSE std::cout<< ans << std::endl; #endif } iline++; } infile.close(); } else { std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl; return FAIL; } #ifdef VERBOSE std::cout<< "Read configuration file of " << iline << " lines" << std::endl; #endif return iline; }; int gotthardDetector::writeConfigurationFile(string const fname){ string names[]={\ "hostname",\ "caldir",\ "settingsdir",\ "trimen",\ "outdir",\ "ffdir",\ "headerbefore",\ "headerafter",\ "headerbeforepar",\ "headerafterpar",\ "nmod",\ "badchannels",\ "angconv",\ "globaloff",\ "binsize",\ "threaded",\ "waitstates",\ "setlength",\ "clkdivider"}; int nvar=19; ofstream outfile; int iv=0; char *args[100]; for (int ia=0; ia<100; ia++) { args[ia]=new char[1000]; } outfile.open(fname.c_str(),ios_base::out); if (outfile.is_open()) { for (iv=0; iv> sargname; // if (ssstr.good()) { strcpy(args[iargval],sargname.c_str()); #ifdef VERBOSE std::cout<< args[iargval] << std::endl; #endif iargval++; // } } if (level==2) { executeLine(iargval,args,PUT_ACTION); } else { if (string(args[0])==string("flatfield")) ; else if (string(args[0])==string("badchannels")) ; else if (string(args[0])==string("angconv")) ; else if (string(args[0])==string("trimbits")) ; else executeLine(iargval,args,PUT_ACTION); } } iline++; } infile.close(); } else { std::cout<< "Error opening " << fname << " for reading" << std::endl; return FAIL; } #ifdef VERBOSE std::cout<< "Read " << iline << " lines" << std::endl; #endif return iline; }; /* I/O */ sls_detector_module* gotthardDetector::readSettingsFile(string fname, sls_detector_module *myMod){ int nflag=0; if (myMod==NULL) { myMod=createModule(); nflag=1; } string myfname; string str; ifstream infile; ostringstream oss; int iline=0; string sargname,sargname2; int ival; int ichan=0, ichip=0, idac=0; string::size_type pos=0; #ifdef VERBOSE std::cout<< "reading settings file for module number "<< myMod->module << std::endl; #endif myfname=fname; #ifdef VERBOSE std::cout<< "settings file name is "<< myfname << std::endl; #endif infile.open(myfname.c_str(), ios_base::in); if (infile.is_open()) { //dacs--------------- for (int iarg=0; iargnDacs; iarg++) { getline(infile,str); iline++; #ifdef VERBOSE std::cout<< str << std::endl; #endif istringstream ssstr(str); ssstr >> sargname >> ival; #ifdef VERBOSE std::cout<< sargname << " dac nr. " << idac << " is " << ival << std::endl; #endif myMod->dacs[idac]=ival; idac++; } //config--------------- getline(infile,str); iline++; #ifdef VERBOSE std::cout<< str << std::endl; #endif istringstream ssstr(str); ssstr >> sargname >> ival; #ifdef VERBOSE std::cout<< sargname << " is " << ival << std::endl; #endif int configval = ival;//myMod->dacs[idac]=ival; //HV--------------- getline(infile,str); iline++; #ifdef VERBOSE std::cout<< str << std::endl; #endif ssstr.str(str); ssstr >> sargname >> ival; #ifdef VERBOSE std::cout<< sargname << " is " << ival << std::endl; #endif int HVval = ival;//myMod->dacs[idac]=ival; //mac address---------- getline(infile,str); iline++; #ifdef VERBOSE std::cout<< str << std::endl; #endif istringstream sstr(str); sstr >> sargname >> sargname2; #ifdef VERBOSE std::cout<< sargname << " is " << sargname2 << std::endl; #endif //getting rid of dots pos = sargname2.find("."); while(pos != string::npos) { sargname2.erase( pos, 1 ); pos = sargname2.find("."); } strcpy(thisDetector->clientMacAddress,sargname2.c_str()); cout<<"macaddress:"<clientMacAddress<> sargname >> sargname2; #ifdef VERBOSE std::cout<< sargname << " is " << sargname2 << std::endl; #endif //getting rid of dots pos = sargname2.find("."); while(pos != string::npos) { sargname2.erase( pos, 1 ); pos = sargname2.find("."); } strcpy(thisDetector->clientIPAddress,sargname2.c_str()); cout<<"ipaddress:"<clientIPAddress<settingsFile,fname.c_str()); return myMod; } else { std::cout<< "could not open settings file " << myfname << std::endl; if (nflag) deleteModule(myMod); return NULL; } }; int gotthardDetector::writeSettingsFile(string fname, sls_detector_module mod){ ofstream outfile; string names[]={"Vref", "VcascN","VcascP", "Vout", "Vcasc", "Vin", "Vref_comp", "Vib_test", "config", "HV", "macaddress","ipaddress"}; int iv, ichan, ichip; int iv1, idac; int nb; outfile.open(fname.c_str(), ios_base::out); if (outfile.is_open()) { for (idac=0; idacnChans; ichan++) { iv=mod.chanregs[ichip*thisDetector->nChans+ichan]; iv1= (iv&0x3f); outfile <>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; } else { std::cout<< "could not open trim file " << fname << std::endl; return FAIL; } }; int gotthardDetector::writeSettingsFile(string fname, int imod){ return writeSettingsFile(fname,detectorModules[imod]); }; int gotthardDetector::writeDataFile(string fname, float *data, float *err, float *ang, char dataformat, int nch){ if (nch==-1) nch=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; ofstream outfile; int idata; if (data==NULL) return FAIL; // args|=0x10; // one line per channel! outfile.open (fname.c_str(),ios_base::out); if (outfile.is_open()) { #ifdef VERBOSE std::cout<< "writeDataFile Writing to file " << fname << std::endl; #endif for (int ichan=0; ichannChans*thisDetector->nChips*thisDetector->nMods; ichan++) outfile << ichan << " " << *(data+ichan) << std::endl; outfile.close(); return OK; } else { std::cout<< "Could not open file " << fname << "for writing"<< std::endl; return FAIL; } }; int gotthardDetector::readDataFile(string fname, float *data, float *err, float *ang, char dataformat, int nch){ ifstream infile; int ichan, iline=0; int interrupt=0; float fdata, ferr, fang; int maxchans; int ich; string str; if (nch==0) maxchans=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; else if (nch<0) maxchans=0xfffffff; else maxchans=nch; #ifdef VERBOSE std::cout<< "Opening file "<< fname << std::endl; #endif infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { while (infile.good() and interrupt==0) { getline(infile,str); #ifdef VERBOSE std::cout<< str << std::endl; #endif istringstream ssstr(str); if (ang==NULL) { ssstr >> ichan >> fdata; ich=ichan; if (!ssstr.good()) { interrupt=1; break; } if (ich!=iline) std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl; } else { ssstr >> fang >> fdata; ich=iline; } if (!ssstr.good()) { interrupt=1; break; } if (err) ssstr >> ferr; if (!ssstr.good()) { interrupt=1; break; } if (ich> ichan >> idata; if (!ssstr.good()) { interrupt=1; break; } if (ichan!=iline) { std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl; interrupt=1; break; } else { if (ilinenChans*thisDetector->nChips*thisDetector->nMods) { data[iline]=idata; iline++; } else { interrupt=1; break; } } } } else { std::cout<< "Could not read file " << fname << std::endl; return -1; } return iline; }; int gotthardDetector::readCalibrationFile(string fname, float &gain, float &offset){ string str; ifstream infile; #ifdef VERBOSE std::cout<< "Opening file "<< fname << std::endl; #endif infile.open(fname.c_str(), ios_base::in); if (infile.is_open()) { getline(infile,str); #ifdef VERBOSE std::cout<< str << std::endl; #endif istringstream ssstr(str); ssstr >> offset >> gain; } else { std::cout<< "Could not open calibration file "<< fname << std::endl; gain=0.; offset=0.; return -1; } return 0; }; int gotthardDetector::writeCalibrationFile(string fname, float gain, float offset){ //std::cout<< "Function not yet implemented " << std::endl; ofstream outfile; outfile.open (fname.c_str()); // >> i/o operations here << if (outfile.is_open()) { outfile << offset << " " << gain << std::endl; } else { std::cout<< "Could not open calibration file "<< fname << " for writing" << std::endl; return -1; } outfile.close(); return 0; };