From 38aad40fefaa1bb62785ba2770278cd805765930 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 6 Jan 2020 18:16:41 +0100 Subject: [PATCH] read/write of config/parameter file rewritten so that parameter file can take in slsdetector level commands --- slsDetectorSoftware/commonFiles/error_defs.h | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 496 +++++++++++++----- .../multiSlsDetector/multiSlsDetector.h | 20 + .../slsDetector/slsDetector.cpp | 286 +++------- slsDetectorSoftware/slsDetector/slsDetector.h | 33 +- .../slsDetector/slsDetectorBase.h | 6 +- .../slsDetector/slsDetectorUtils.cpp | 312 +---------- .../slsDetector/slsDetectorUtils.h | 19 - 8 files changed, 480 insertions(+), 696 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 2416cc3d2..10897aab0 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -25,6 +25,8 @@ #define MULTI_DETECTORS_NOT_ADDED 0x8000000000000000ULL #define MULTI_HAVE_DIFFERENT_VALUES 0x4000000000000000ULL #define MULTI_CONFIG_FILE_ERROR 0x2000000000000000ULL +#define MULTI_PARM_FILE_ERROR 0x1000000000000000ULL + // sls errors #define CRITICAL_ERROR_MASK 0xFFFFFFF @@ -302,7 +304,7 @@ public: retval.append("Could not set/get auto comparator disable\n"); if(slsErrorMask&CONFIG_FILE) - retval.append("Could not load/write config file\n"); + retval.append("Could not load/write config/parameter file\n"); //------------------------------------------------------ length of message diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 1ee67092c..0425e3f60 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -26,6 +26,7 @@ ID: $Id$ #include //json header in zmq stream #include #include +#include @@ -523,7 +524,10 @@ std::string multiSlsDetector::getErrorMessage(int& critical) { retval.append("Could not load Config File\n"); critical = 0; } - + if (multiMask & MULTI_PARM_FILE_ERROR) { + retval.append("Could not load parameter File\n"); + critical = 0; + } for (unsigned int idet = 0; idet < detectors.size(); ++idet) { //if the detector has error if (multiMask & (1 << idet)) { @@ -1441,176 +1445,382 @@ int multiSlsDetector::readConfigurationFile(std::string const fname) { freeSharedMemory(); setupMultiDetector(); - - multiSlsDetectorClient* cmd; - std::string ans; - std::string str; - std::ifstream infile; - int iargval; - int interrupt = 0; - char* args[1000]; - - char myargs[1000][1000]; - - std::string sargname, sargval; - int iline = 0; - std::cout << "config file name " << fname << std::endl; - infile.open(fname.c_str(), std::ios_base::in); - if (infile.is_open()) { - - while (infile.good() and interrupt == 0) { - sargname = "none"; - sargval = "0"; - getline(infile, str); - ++iline; - - // remove comments that come after - if (str.find('#') != std::string::npos) - str.erase(str.find('#')); -#ifdef VERBOSE - std::cout << "string:" << str << std::endl; -#endif - if (str.length() < 2) { -#ifdef VERBOSE - std::cout << "Empty line or Comment " << std::endl; -#endif - continue; - } else { - std::istringstream ssstr(str); - iargval = 0; - while (ssstr.good()) { - ssstr >> sargname; -#ifdef VERBOSE - std::cout << iargval << " " << sargname << std::endl; -#endif - strcpy(myargs[iargval], sargname.c_str()); - args[iargval] = myargs[iargval]; -#ifdef VERBOSE - std::cout << "--" << iargval << " " << args[iargval] << std::endl; -#endif - ++iargval; - } -#ifdef VERBOSE - cout << endl; - for (int ia = 0; ia < iargval; ia++) - cout << args[ia] << " ??????? "; - cout << endl; -#endif - cmd = new multiSlsDetectorClient(iargval, args, PUT_ACTION, this); - delete cmd; - } - ++iline; - } - - infile.close(); - } else { - std::cout << "Error opening configuration file " << fname << " for reading" << std::endl; - setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); - return FAIL; + std::ifstream inFile; + inFile.open(fname.c_str(), std::ifstream::in); + if (!inFile.is_open()) { + cprintf(RED, "Cannot open config file %s\n", fname.c_str()); + setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); + return FAIL; } -#ifdef VERBOSE - std::cout << "Read configuration file of " << iline << " lines" << std::endl; -#endif + + while(inFile.good()) { + std::string sLine; + getline(inFile,sLine); + // delete lines after comments + if (sLine.find('#') != std::string::npos) { + sLine.erase(sLine.find('#')); + } + // scan arguments + std::istringstream iss(sLine); + std::vector vec = std::vector(std::istream_iterator(iss), std::istream_iterator()); + // blank lines + if (vec.size() == 0 || vec[0].empty()) { + continue; + } + int iarg = vec.size(); + // copy to char array + char arr[iarg][MAX_STR_LENGTH]; + memset(arr, 0, sizeof(arr)); + char* args[iarg]; + for (int i = 0; i < iarg; ++i) { + args[i] = arr[i]; + strcpy(args[i], vec[i].c_str()); + } + // execute command + multiSlsDetectorClient(iarg, args, PUT_ACTION, this); + } + + inFile.close(); setNumberOfModules(-1); getMaxNumberOfModules(); + // check error if (getErrorMask()) { int c; cprintf(RED, "\n----------------\n Error Messages\n----------------\n%s\n", getErrorMessage(c).c_str()); return FAIL; } + return OK; +} + + +int multiSlsDetector::writeConfigurationFile(std::string const fname) { + + std::vector commands; + commands.push_back("master"); + commands.push_back("sync"); + commands.push_back("outdir"); + commands.push_back("ffdir"); + commands.push_back("headerbefore"); + commands.push_back("headerafter"); + commands.push_back("headerbeforepar"); + commands.push_back("headerafterpar"); + commands.push_back("badchannels"); + commands.push_back("angconv"); + commands.push_back("globaloff"); + commands.push_back("binsize"); + commands.push_back("threaded"); + + std::ofstream outfile; + outfile.open(fname.c_str(), std::ios_base::out); + if (!outfile.is_open()) { + cprintf(RED, "Cannot open config file %s for writing\n", fname.c_str()); + setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); + return FAIL; + } + + int ret = OK; + slsDetectorCommand* cmd = new slsDetectorCommand(this); + char arr[MAX_STR_LENGTH]; + char* args[1]; + args[0] = arr; + + // detsizechan + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], "detsizechan"); + outfile << args[0] << ' ' << cmd->executeLine(1, args, GET_ACTION) << std::endl; + // hostname + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], "hostname"); + outfile << args[0] << ' ' << cmd->executeLine(1, args, GET_ACTION) << std::endl; + + // single detector configuration + for (unsigned int idet = 0; idet < detectors.size(); ++idet) { + outfile << endl; + int ret1 = detectors[idet]->writeConfigurationFile(outfile, idet); + if (detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask() | (1 << idet)); + if (ret1 == FAIL) + ret = FAIL; + } + + // other configurations + outfile << endl; + for (unsigned int i = 0; i < commands.size(); ++i) { + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], commands[i].c_str()); + outfile << commands[i] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; + } + + delete cmd; + outfile.close(); + + if (ret == FAIL || getErrorMask()) { + int c; + cprintf(RED, "\n----------------\n Error Messages\n----------------\n%s\n", + getErrorMessage(c).c_str()); + return FAIL; + } return OK; } -int multiSlsDetector::writeConfigurationFile(std::string const fname) { +int multiSlsDetector::retrieveDetectorSetup(std::string const fname1, int level){ + std::string fname = fname1; + // setup + if (level==2) { + fname += std::string(".det"); + } - std::string names[] = { - "detsizechan", - "hostname", - "master", - "sync", - "outdir", - "ffdir", - "headerbefore", - "headerafter", - "headerbeforepar", - "headerafterpar", - "badchannels", - "angconv", - "globaloff", - "binsize", - "threaded" - }; - - int nvar = 15; - char* args[100]; - for (int ia = 0; ia < 100; ++ia) { - args[ia] = new char[1000]; + std::ifstream inFile; + inFile.open(fname.c_str(), std::ifstream::in); + if (!inFile.is_open()) { + cprintf(RED, "Cannot open parameter file %s\n", fname.c_str()); + setErrorMask(getErrorMask() | MULTI_PARM_FILE_ERROR); + return FAIL; } - int ret = OK, ret1 = OK; - std::ofstream outfile; - int iline = 0; - - outfile.open(fname.c_str(), std::ios_base::out); - if (outfile.is_open()) { - - slsDetectorCommand* cmd = new slsDetectorCommand(this); - - // complete size of detector - cout << iline << " " << names[iline] << endl; - strcpy(args[0], names[iline].c_str()); - outfile << names[iline] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; - ++iline; - - // hostname of the detectors - cout << iline << " " << names[iline] << endl; - strcpy(args[0], names[iline].c_str()); - outfile << names[iline] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; - ++iline; - - // single detector configuration - for (unsigned int idet = 0; idet < detectors.size(); ++idet) { - outfile << endl; - ret1 = detectors[idet]->writeConfigurationFile(outfile, idet); - if (detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask() | (1 << idet)); - if (ret1 == FAIL) - ret = FAIL; + while(inFile.good()) { + std::string sLine; + getline(inFile,sLine); + // delete lines after comments + if (sLine.find('#') != std::string::npos) { + sLine.erase(sLine.find('#')); + } + // scan arguments + std::istringstream iss(sLine); + std::vector vec = std::vector(std::istream_iterator(iss), std::istream_iterator()); + // blank lines + if (vec.size() == 0 || vec[0].empty()) { + continue; } - outfile << endl; - //other configurations - while (iline < nvar) { - cout << iline << " " << names[iline] << endl; - strcpy(args[0], names[iline].c_str()); - outfile << names[iline] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; - ++iline; + // skip commands according to level (setup=2) + if (level!=2) { + if (vec[0] == "flatfield" || + vec[0] == "badchannels" || + vec[0] == "trimbits") { + continue; + } } - - delete cmd; - outfile.close(); -#ifdef VERBOSE - std::cout << "wrote " << iline << " lines to configuration file " << std::endl; -#endif - } else { - std::cout << "Error opening configuration file " << fname << " for writing" << std::endl; - setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); - ret = FAIL; + int iarg = vec.size(); + // copy to char array + char arr[iarg][MAX_STR_LENGTH]; + memset(arr, 0, sizeof(arr)); + char* args[iarg]; + for (int i = 0; i < iarg; ++i) { + args[i] = arr[i]; + strcpy(args[i], vec[i].c_str()); + } + // execute command + multiSlsDetectorClient(iarg, args, PUT_ACTION, this); } - for (int ia = 0; ia < 100; ++ia) { - delete[] args[ia]; - } + inFile.close(); - return ret; + // check error + if (getErrorMask()) { + int c; + cprintf(RED, "\n----------------\n Error Messages\n----------------\n%s\n", + getErrorMessage(c).c_str()); + return FAIL; + } + return OK; } +int multiSlsDetector::dumpDetectorSetup(std::string const fname1, int level){ + + std::vector commands; + // common config + commands.push_back("fname"); + commands.push_back("index"); + commands.push_back("enablefwrite"); + commands.push_back("overwrite"); + commands.push_back("dr"); + commands.push_back("settings"); + commands.push_back("exptime"); + commands.push_back("period"); + commands.push_back("frames"); + commands.push_back("cycles"); + commands.push_back("measurements"); + commands.push_back("timing"); + + switch (getDetectorsType()) { + case EIGER: + commands.push_back("flags"); + commands.push_back("clkdivider"); + commands.push_back("threshold"); + commands.push_back("ratecorr"); + break; + case GOTTHARD: + case PROPIX: + commands.push_back("flags"); + commands.push_back("delay"); + commands.push_back("gates"); + commands.push_back("ratecorr"); + break; + case JUNGFRAU: + commands.push_back("flags"); + commands.push_back("delay"); + commands.push_back("gates"); + commands.push_back("ratecorr"); + commands.push_back("clkdivider"); + break; + case MYTHEN: + commands.push_back("flags"); + commands.push_back("threshold"); + commands.push_back("delay"); + commands.push_back("gates"); + commands.push_back("probes"); + commands.push_back("fineoff"); + commands.push_back("ratecorr"); + break; + case JUNGFRAUCTB: + commands.push_back("dac:0"); + commands.push_back("dac:1"); + commands.push_back("dac:2"); + commands.push_back("dac:3"); + commands.push_back("dac:4"); + commands.push_back("dac:5"); + commands.push_back("dac:6"); + commands.push_back("dac:7"); + commands.push_back("dac:8"); + commands.push_back("dac:9"); + commands.push_back("dac:10"); + commands.push_back("dac:11"); + commands.push_back("dac:12"); + commands.push_back("dac:13"); + commands.push_back("dac:14"); + commands.push_back("dac:15"); + commands.push_back("adcvpp"); + commands.push_back("adcclk"); + commands.push_back("clkdivider"); + commands.push_back("adcphase"); + commands.push_back("adcpipeline"); + commands.push_back("adcinvert"); // + commands.push_back("adcdisable"); + commands.push_back("patioctrl"); + commands.push_back("patclkctrl"); + commands.push_back("patlimits"); + commands.push_back("patloop0"); + commands.push_back("patnloop0"); + commands.push_back("patwait0"); + commands.push_back("patwaittime0"); + commands.push_back("patloop1"); + commands.push_back("patnloop1"); + commands.push_back("patwait1"); + commands.push_back("patwaittime1"); + commands.push_back("patloop2"); + commands.push_back("patnloop2"); + commands.push_back("patwait2"); + commands.push_back("patwaittime2"); + break; + default: + break; + } + + // more common config + commands.push_back("startscript"); + commands.push_back("startscriptpar"); + commands.push_back("stopscript"); + commands.push_back("stopscriptpar"); + commands.push_back("scriptbefore"); + commands.push_back("scriptbeforepar"); + commands.push_back("scriptafter"); + commands.push_back("scriptafterpar"); + commands.push_back("scan0script"); + commands.push_back("scan0par"); + commands.push_back("scan0prec"); + commands.push_back("scan0steps"); + commands.push_back("scan1script"); + commands.push_back("scan1par"); + commands.push_back("scan1prec"); + commands.push_back("scan1steps"); + + std::string fname = fname1; + // setup + if (level == 2) { + // config + fname += std::string(".config"); + writeConfigurationFile(fname); + // parameters + fname = fname1 + std::string(".det"); + } + + std::ofstream outfile; + outfile.open(fname.c_str(), std::ios_base::out); + if (!outfile.is_open()) { + cprintf(RED, "Cannot open parameter file %s for writing\n", fname.c_str()); + setErrorMask(getErrorMask() | MULTI_PARM_FILE_ERROR); + return FAIL; + } + + slsDetectorCommand* cmd = new slsDetectorCommand(this); + char arr[2][MAX_STR_LENGTH]; + char* args[2]; + args[0] = arr[0]; + args[1] = arr[1]; + memset(args[1], 0, MAX_STR_LENGTH); + + for (unsigned int i = 0; i < commands.size(); ++i) { + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], commands[i].c_str()); + outfile << commands[i] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; + } + + if (getDetectorsType() == MYTHEN) { + // flatfield + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], "flatfield "); + if (level == 2) { + fname = fname1 + std::string(".ff"); + memset(args[1], 0, MAX_STR_LENGTH); + strcpy(args[1], fname.c_str()); + } + outfile << "flatfield " << cmd->executeLine(2, args, GET_ACTION) << std::endl; + + // badchannels + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], "badchannels "); + if (level == 2) { + fname = fname1 + std::string(".bad"); + memset(args[1], 0, MAX_STR_LENGTH); + strcpy(args[1], fname.c_str()); + } + outfile << "badchannels " << cmd->executeLine(2, args, GET_ACTION) << std::endl; + + // trimbits + if (level == 2) { + size_t c = fname1.rfind('/'); + if (c < std::string::npos) { + fname = fname1.substr(0, c + 1) + std::string("trim_") + fname.substr(c + 1); + } else { + fname = std::string("trim_") + fname1; + } + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], "trimbits "); + memset(args[1], 0, MAX_STR_LENGTH); + strcpy(args[1], fname.c_str()); + outfile << "trimbits " << cmd->executeLine(2, args, GET_ACTION) << std::endl; + } + } + + delete cmd; + outfile.close(); + + if (getErrorMask()) { + int c; + cprintf(RED, "\n----------------\n Error Messages\n----------------\n%s\n", + getErrorMessage(c).c_str()); + return FAIL; + } + return OK; +} + std::string multiSlsDetector::getSettingsFile() { return callDetectorMember(&slsDetector::getSettingsFile); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index e33bfce44..d9494c9fa 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -795,6 +795,26 @@ public: */ int writeConfigurationFile(std::string const fname); + /** + * Saves the detector setup to file + * @param fname file to write to + * @param level if 2 reads also trimbits, flat field, angular + * correction etc. and writes them to files with automatically + * added extension + * @returns OK or FAIL + */ + int dumpDetectorSetup(std::string const fname1, int level=0); + + /** + * Loads the detector setup from file + * @param fname file to read from + * @param level if 2 reads also reads trimbits, angular + * conversion coefficients etc. from files with default + * extensions as generated by dumpDetectorSetup + * @returns OK or FAIL + */ + int retrieveDetectorSetup(std::string const fname1, int level=0); + /** * Returns the trimfile or settings file name (Useless??) * @returns the trimfile or settings file name diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 7e4e77a53..ebf2f90b4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -2407,254 +2407,126 @@ int slsDetector::updateDetector() { int slsDetector::readConfigurationFile(string const fname) { - - - - string ans; - string str; - ifstream infile; - //char *args[1000]; - - string sargname, sargval; -#ifdef VERBOSE - int iline=0; - std::cout<< "config file name "<< fname << std::endl; -#endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { -#ifdef VERBOSE - iline=readConfigurationFile(infile); -#else - readConfigurationFile(infile); -#endif - infile.close(); - } else { - std::cout<< "Error opening configuration file " << fname << - " for reading" << std::endl; - setErrorMask((getErrorMask())|(CONFIG_FILE)); - return FAIL; - } -#ifdef VERBOSE - std::cout<< "Read configuration file of " << iline << " lines" << std::endl; -#endif - return OK; - + std::cout << "Cannot read config file from slsDetector level" << std::endl; + setErrorMask((getErrorMask())|(CONFIG_FILE)); + return FAIL; } - -int slsDetector::readConfigurationFile(ifstream &infile) { - - - - - slsDetectorCommand *cmd=new slsDetectorCommand(this); - - string ans; - string str; - int iargval; - int interrupt=0; - char *args[100]; - char myargs[1000][1000]; - - string sargname, sargval; - int iline=0; - 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(myargs[iargval],sargname.c_str()); - args[iargval]=myargs[iargval]; - ++iargval; - //} - } - ans=cmd->executeLine(iargval,args,PUT_ACTION); -#ifdef VERBOSE - std::cout<< ans << std::endl; -#endif - } - ++iline; - } - delete cmd; - return OK; - -} - - - - - - - - - - int slsDetector::writeConfigurationFile(string const fname) { - - ofstream outfile; -#ifdef VERBOSE - int ret; -#endif - outfile.open(fname.c_str(),ios_base::out); - if (outfile.is_open()) { -#ifdef VERBOSE - ret=writeConfigurationFile(outfile); -#else - writeConfigurationFile(outfile); -#endif - outfile.close(); - } - else { - std::cout<< "Error opening configuration file " << fname << - " for writing" << std::endl; - setErrorMask((getErrorMask())|(CONFIG_FILE)); - return FAIL; - } -#ifdef VERBOSE - std::cout<< "wrote " <myDetectorType; - string names[100]; - int nvar=0; + std::vector commands; // common config - names[nvar++] = "hostname"; - names[nvar++] = "port"; - names[nvar++] = "stopport"; - names[nvar++] = "settingsdir"; - names[nvar++] = "caldir"; - names[nvar++] = "ffdir"; - names[nvar++] = "outdir"; - names[nvar++] = "angdir"; - names[nvar++] = "moveflag"; - names[nvar++] = "lock"; + commands.push_back("port"); + commands.push_back("stopport"); + commands.push_back("settingsdir"); + commands.push_back("caldir"); + commands.push_back("ffdir"); + commands.push_back("outdir"); + commands.push_back("angdir"); + commands.push_back("moveflag"); + commands.push_back("lock"); // receiver config - if (type != MYTHEN) { - names[nvar++] = "detectormac"; - names[nvar++] = "detectorip"; - names[nvar++] = "zmqport"; - names[nvar++] = "rx_zmqport"; - names[nvar++] = "zmqip"; - names[nvar++] = "rx_zmqip"; - names[nvar++] = "rx_tcpport"; - names[nvar++] = "rx_udpport"; - names[nvar++] = "rx_udpport2"; - names[nvar++] = "rx_udpip"; - names[nvar++] = "rx_hostname"; - names[nvar++] = "r_readfreq"; + if (thisDetector->myDetectorType != MYTHEN) { + commands.push_back("detectormac"); + commands.push_back("detectorip"); + commands.push_back("zmqport"); + commands.push_back("rx_zmqport"); + commands.push_back("zmqip"); + commands.push_back("rx_zmqip"); + commands.push_back("rx_tcpport"); + commands.push_back("rx_udpport"); + commands.push_back("rx_udpport2"); + commands.push_back("rx_udpip"); + commands.push_back("rx_hostname"); + commands.push_back("r_readfreq"); } // detector specific config - switch (type) { + switch (thisDetector->myDetectorType) { case MYTHEN: - names[nvar++] = "nmod"; - names[nvar++] = "waitstates"; - names[nvar++] = "setlength"; - names[nvar++] = "clkdivider"; - names[nvar++] = "extsig"; + commands.push_back("waitstates"); + commands.push_back("setlength"); + commands.push_back("clkdivider"); + commands.push_back("extsig"); break; case GOTTHARD: case PROPIX: - names[nvar++] = "extsig"; - names[nvar++] = "vhighvoltage"; - break; - break; case MOENCH: - names[nvar++] = "extsig"; - names[nvar++] = "vhighvoltage"; + commands.push_back("vhighvoltage"); break; case EIGER: - names[nvar++] = "vhighvoltage"; - names[nvar++] = "trimen"; - names[nvar++] = "iodelay"; - names[nvar++] = "tengiga"; + commands.push_back("vhighvoltage"); + commands.push_back("trimen"); + commands.push_back("iodelay"); + commands.push_back("tengiga"); break; case JUNGFRAU: - names[nvar++] = "powerchip"; - names[nvar++] = "vhighvoltage"; - break; case JUNGFRAUCTB: - names[nvar++] = "powerchip"; - names[nvar++] = "vhighvoltage"; + commands.push_back("powerchip"); + commands.push_back("vhighvoltage"); break; default: std::cout << "detector type " << getDetectorType(thisDetector->myDetectorType) << " not implemented in " "writing config file" << std::endl; - nvar = 0; - break; + return FAIL; } - - int nsig=4; - int iv=0; - char *args[100]; - char myargs[100][1000]; - - for (int ia=0; ia<100; ++ia) { - args[ia]=myargs[ia]; - } - - - for (iv=0; iv=0) + slsDetectorCommand *cmd = new slsDetectorCommand(this); + char* args[2]; + args[0] = new char[MAX_STR_LENGTH]; + for (unsigned int i = 0; i < commands.size(); ++i) { + if (commands[i] == "extsig") { + for (int is = 0; is < 4; ++is) { + if (id >= 0) { outfile << id << ":"; - - outfile << args[0] << " " << cmd->executeLine(1,args,GET_ACTION) - << std::endl; + } + memset(args[0], 0, MAX_STR_LENGTH); + sprintf(args[0],"extsig:%d", is); + outfile << args[0] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; } } else { - strcpy(args[0],names[iv].c_str()); - if (id>=0) + if (id >= 0) { outfile << id << ":"; - outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) - << std::endl; + } + memset(args[0], 0, MAX_STR_LENGTH); + strcpy(args[0], commands[i].c_str()); + outfile << commands[i] << " " << cmd->executeLine(1, args, GET_ACTION) << std::endl; } } - delete cmd; + delete args[0]; + delete cmd; + + if (getErrorMask()) { + int c = 0; + cprintf(RED, "\n----------------\n Error Messages\n----------------\n%s\n", + getErrorMessage(c).c_str()); + return FAIL; + } + return OK; } +int slsDetector::retrieveDetectorSetup(std::string const fname, int level) { + std::cout << "Cannot read parameter file from slsDetector level" << std::endl; + setErrorMask((getErrorMask())|(CONFIG_FILE)); + return FAIL; +} + +int slsDetector::dumpDetectorSetup(std::string const fname, int level) { + std::cout << "Cannot write parameter file from slsDetector level" << std::endl; + setErrorMask((getErrorMask())|(CONFIG_FILE)); + return FAIL; +} string slsDetector::getSettingsFile() { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index adc8a3f6e..149780de0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -852,20 +852,11 @@ public: int updateDetector(); /** - * Load configuration from a configuration File - * calls readConfigurationFile and gives it the stream - * @param fname configuration file name - * @return OK or FAIL + * should not be called at this level + * @return FAIL */ int readConfigurationFile(std::string const fname); - /** - * Load configuration from a stream - * @param infile stream - * @return OK or FAIL - */ - int readConfigurationFile(std::ifstream &infile); - /** * Write current configuration to a file * calls writeConfigurationFile giving it a stream to write to @@ -882,6 +873,26 @@ public: */ int writeConfigurationFile(std::ofstream &outfile, int id=-1); + /** + * Loads the detector setup from file + * @param fname file to read from + * @param level if 2 reads also reads trimbits, angular + * conversion coefficients etc. from files with default + * extensions as generated by dumpDetectorSetup + * @returns OK or FAIL + */ + int retrieveDetectorSetup(std::string const fname, int level=0); + + /** + * Saves the detector setup to file + * @param fname file to write to + * @param level if 2 reads also trimbits, flat field, angular + * correction etc. and writes them to files with automatically + * added extension + * @returns OK or FAIL + */ + int dumpDetectorSetup(std::string const fname, int level=0); + /** * Returns the trimfile or settings file name (Useless??) * @returns the trimfile or settings file name diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 3344aa0ec..33a662e98 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -540,10 +540,8 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef */ virtual int readConfigurationFile(std::string const fname)=0; - virtual int dumpDetectorSetup(std::string const fname, int level)=0; - int dumpDetectorSetup(std::string const fname){return dumpDetectorSetup(fname,0);}; - virtual int retrieveDetectorSetup(std::string const fname, int level)=0; - int retrieveDetectorSetup(std::string const fname){return retrieveDetectorSetup(fname,0);}; + virtual int dumpDetectorSetup(std::string const fname, int level = 0)=0; + virtual int retrieveDetectorSetup(std::string const fname, int level = 0)=0; /** @short \returns the default output file index diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 69ad5f4a4..6bb8a6322 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -10,6 +10,7 @@ #include #include //clock() #include +#include using namespace std; slsDetectorUtils::slsDetectorUtils() { @@ -638,316 +639,5 @@ void slsDetectorUtils::setCurrentProgress(int i){ } -int slsDetectorUtils::retrieveDetectorSetup(string const fname1, int level){ - - - - slsDetectorCommand *cmd; - - - // char ext[100]; - int skip=0; - string fname; - string str; - ifstream infile; - int iargval; - int interrupt=0; - char *args[10]; - - char myargs[10][1000]; - - //args[0]=myargs[0]; - //args[1]=myargs[1]; - - string sargname, sargval; - int iline=0; - - if (level==2) { - // fname=fname1+string(".config"); - // readConfigurationFile(fname); -#ifdef VERBOSE - cout << "config file read" << endl; -#endif - fname=fname1+string(".det"); - } else - fname=fname1; - - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - cmd=new slsDetectorCommand(this); - 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 { - istringstream ssstr(str); - iargval=0; - while (ssstr.good()) { - ssstr >> sargname; - // if (ssstr.good()) { - strcpy(myargs[iargval],sargname.c_str()); - args[iargval]=myargs[iargval]; -#ifdef VERBOSE - std::cout<< args[iargval] << std::endl; -#endif - iargval++; - // } - skip=0; - } - - if (level!=2) { - if (string(args[0])==string("flatfield")) - skip=1; - else if (string(args[0])==string("badchannels")) - skip=1; - else if (string(args[0])==string("trimbits")) - skip=1; - } - if (skip==0) - cmd->executeLine(iargval,args,PUT_ACTION); - } - iline++; - } - delete cmd; - infile.close(); - - } else { - std::cout<< "Error opening " << fname << " for reading" << std::endl; - return FAIL; - } -#ifdef VERBOSE - std::cout<< "Read " << iline << " lines" << std::endl; -#endif - - if (getErrorMask()) - return FAIL; - - return OK; - - -} - - -int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ - - slsDetectorCommand *cmd; - detectorType type = getDetectorsType(); - string names[100]; - int nvar=0; - - // common config - names[nvar++]="fname"; - names[nvar++]="index"; - names[nvar++]="enablefwrite"; - names[nvar++]="overwrite"; - names[nvar++]="dr"; - names[nvar++]="settings"; - names[nvar++]="exptime"; - names[nvar++]="period"; - names[nvar++]="frames"; - names[nvar++]="cycles"; - names[nvar++]="measurements"; - names[nvar++]="timing"; - names[nvar++]="flatfield"; - names[nvar++]="badchannels"; - - switch (type) { - case EIGER: - names[nvar++]="flags"; - names[nvar++]="clkdivider"; - names[nvar++]="threshold"; - names[nvar++]="ratecorr"; - names[nvar++]="trimbits"; - break; - case GOTTHARD: - case PROPIX: - names[nvar++]="flags"; - names[nvar++]="delay"; - names[nvar++]="gates"; - names[nvar++]="ratecorr"; - break; - case JUNGFRAU: - names[nvar++]="flags"; - names[nvar++]="delay"; - names[nvar++]="gates"; - names[nvar++]="ratecorr"; - names[nvar++]="clkdivider"; - break; - case MYTHEN: - names[nvar++]="flags"; - names[nvar++]="threshold"; - names[nvar++]="delay"; - names[nvar++]="gates"; - names[nvar++]="probes"; - names[nvar++]="fineoff"; - names[nvar++]="ratecorr"; - names[nvar++]="trimbits"; - break; - case JUNGFRAUCTB: - names[nvar++]="dac:0"; - names[nvar++]="dac:1"; - names[nvar++]="dac:2"; - names[nvar++]="dac:3"; - names[nvar++]="dac:4"; - names[nvar++]="dac:5"; - names[nvar++]="dac:6"; - names[nvar++]="dac:7"; - names[nvar++]="dac:8"; - names[nvar++]="dac:9"; - names[nvar++]="dac:10"; - names[nvar++]="dac:11"; - names[nvar++]="dac:12"; - names[nvar++]="dac:13"; - names[nvar++]="dac:14"; - names[nvar++]="dac:15"; - names[nvar++]="adcvpp"; - - - - names[nvar++]="adcclk"; - names[nvar++]="clkdivider"; - names[nvar++]="adcphase"; - names[nvar++]="adcpipeline"; - names[nvar++]="adcinvert"; // - names[nvar++]="adcdisable"; - names[nvar++]="patioctrl"; - names[nvar++]="patclkctrl"; - names[nvar++]="patlimits"; - names[nvar++]="patloop0"; - names[nvar++]="patnloop0"; - names[nvar++]="patwait0"; - names[nvar++]="patwaittime0"; - names[nvar++]="patloop1"; - names[nvar++]="patnloop1"; - names[nvar++]="patwait1"; - names[nvar++]="patwaittime1"; - names[nvar++]="patloop2"; - names[nvar++]="patnloop2"; - names[nvar++]="patwait2"; - names[nvar++]="patwaittime2"; - break; - default: - break; - } - - - names[nvar++]="startscript"; - names[nvar++]="startscriptpar"; - names[nvar++]="stopscript"; - names[nvar++]="stopscriptpar"; - names[nvar++]="scriptbefore"; - names[nvar++]="scriptbeforepar"; - names[nvar++]="scriptafter"; - names[nvar++]="scriptafterpar"; - names[nvar++]="scan0script"; - names[nvar++]="scan0par"; - names[nvar++]="scan0prec"; - names[nvar++]="scan0steps"; - names[nvar++]="scan1script"; - names[nvar++]="scan1par"; - names[nvar++]="scan1prec"; - names[nvar++]="scan1steps"; - - - int iv=0; - string fname1; - - - - ofstream outfile; - char *args[4]; - for (int ia=0; ia<4; ia++) { - args[ia]=new char[1000]; - } - - - int nargs; - if (level==2) - nargs=2; - else - nargs=1; - - - if (level==2) { - fname1=fname+string(".config"); - writeConfigurationFile(fname1); - fname1=fname+string(".det"); - } else - fname1=fname; - - - - outfile.open(fname1.c_str(),ios_base::out); - if (outfile.is_open()) { - cmd=new slsDetectorCommand(this); - for (iv=0; ivexecuteLine(1,args,GET_ACTION) << std::endl; - } - - - strcpy(args[0],names[iv].c_str()); - if (level==2) { - fname1=fname+string(".ff"); - strcpy(args[1],fname1.c_str()); - } - outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; - iv++; - - strcpy(args[0],names[iv].c_str()); - if (level==2) { - fname1=fname+string(".bad"); - strcpy(args[1],fname1.c_str()); - } - outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; - iv++; - - - - if (level==2) { - strcpy(args[0],names[iv].c_str()); - size_t c=fname.rfind('/'); - if (cexecuteLine(nargs,args,GET_ACTION) << std::endl; - iv++; - - - } - - - delete cmd; - - outfile.close(); - } - else { - std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl; - return FAIL; - } - -#ifdef VERBOSE - std::cout<< "wrote " <