Merge branch 'refactor' of github.com:slsdetectorgroup/slsDetectorPackage into refactor

This commit is contained in:
maliakal_d 2018-10-12 17:03:28 +02:00
commit 8df63b7767
3 changed files with 84 additions and 232 deletions

View File

@ -138,7 +138,7 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int& channelX, in
std::string multiSlsDetector::getErrorMessage(int& critical, int detPos) {
int64_t multiMask = 0, slsMask = 0;
std::string retval = "";
char sNumber[100];
// char sNumber[100];
critical = 0;
size_t posmin = 0, posmax = detectors.size();
@ -184,15 +184,15 @@ std::string multiSlsDetector::getErrorMessage(int& critical, int detPos) {
if ((multiMask & (1 << idet)) || (detPos >= 0)) {
//append detector id
sprintf(sNumber, "%ld", idet);
retval.append("Detector " + std::string(sNumber) + std::string(":\n"));
// sprintf(sNumber, "%ld", idet);
retval.append("Detector " + std::to_string(idet) + std::string(":\n"));
//get sls det error mask
slsMask = detectors[idet]->getErrorMask();
#ifdef VERYVERBOSE
//append sls det error mask
sprintf(sNumber, "0x%lx", slsMask);
retval.append("Error Mask " + std::string(sNumber) + std::string("\n"));
// sprintf(sNumber, "0x%lx", slsMask);
retval.append("Error Mask " + std::to_string(slsMask) + std::string("\n"));
#endif
//get the error critical level
@ -236,7 +236,7 @@ void multiSlsDetector::setAcquiringFlag(bool b) {
}
bool multiSlsDetector::getAcquiringFlag() {
bool multiSlsDetector::getAcquiringFlag() const {
return thisMultiDetector->acquiringFlag;
}
@ -277,23 +277,6 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) {
}
// slsDetector* multiSlsDetector::getSlsDetector(int detPos) {
// return detectors[detPos].get();
// }
// slsDetector *multiSlsDetector::operator()(int detPos) const {
// return detectors[detPos].get();
// }
// slsDetector* multiSlsDetector::operator[](int detPos) const {
// //Providing access to detectors with range checking
// //throw exception if out of range
// if (detPos >= 0 && detPos < (int)detectors.size())
// return detectors[detPos].get();
// else
// throw(std::range_error("Detector does not exist"));
// }
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
// single
if (detPos >= 0) {
@ -584,16 +567,10 @@ void multiSlsDetector::addSlsDetector (std::string s) {
return;
}
int pos = (int)detectors.size();
detectors.push_back(sls::make_unique<slsDetector>(type, detId, pos, false));
thisMultiDetector->numberOfDetectors = detectors.size();
detectors[pos]->setHostname(s.c_str()); // also updates client
thisMultiDetector->dataBytes += detectors[pos]->getDataBytes();
thisMultiDetector->dataBytesInclGapPixels += detectors[pos]->getDataBytesInclGapPixels();
thisMultiDetector->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
@ -935,78 +912,44 @@ int multiSlsDetector::execCommand(std::string cmd, int detPos) {
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
int multiSlsDetector::readConfigurationFile(const std::string& fname) {
freeSharedMemory();
setupMultiDetector();
std::string ans;
std::string str;
std::ifstream infile;
int iargval;
int interrupt = 0;
char* args[1000];
char* args[100];
char myargs[100][1000];
std::cout << "Loading configuration file: " << fname << std::endl;
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('#'));
std::ifstream input_file;
input_file.open(fname, std::ios_base::in);
if (input_file.is_open()) {
std::string current_line;
while (input_file.good()) {
getline(input_file, current_line);
if (current_line.find('#') != std::string::npos)
current_line.erase(current_line.find('#'));
#ifdef VERBOSE
std::cout << "string:" << str << std::endl;
std::cout << "current_line after removing comments:" << current_line << 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;
if (current_line.length() > 1) {
std::istringstream line_stream(current_line);
int n_arguments = 0;
std::string current_argument;
while (line_stream.good()) {
line_stream >> current_argument;
strcpy(myargs[n_arguments], current_argument.c_str());
args[n_arguments] = myargs[n_arguments];
++n_arguments;
}
#ifdef VERBOSE
std::cout << std::endl;
for (int ia = 0; ia < iargval; ia++)
std::cout << args[ia] << " ??????? ";
std::cout << std::endl;
#endif
multiSlsDetectorClient(iargval, args, PUT_ACTION, this);
multiSlsDetectorClient(n_arguments, args, PUT_ACTION, this);
}
++iline;
}
infile.close();
input_file.close();
} else {
std::cout << "Error opening configuration file " << fname << " for reading" << std::endl;
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
return FAIL;
}
#ifdef VERBOSE
std::cout << "Read configuration file of " << iline << " lines" << std::endl;
#endif
if (getErrorMask()) {
int c;
@ -1014,7 +957,6 @@ int multiSlsDetector::readConfigurationFile(const std::string& fname) {
getErrorMessage(c).c_str());
return FAIL;
}
return OK;
}
@ -1169,28 +1111,12 @@ std::string multiSlsDetector::getSettingsDir(int detPos) {
}
std::string multiSlsDetector::setSettingsDir(std::string s, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setSettingsDir(s);
}
std::string multiSlsDetector::setSettingsDir(std::string directory, int detPos) {
if (detPos >= 0)
return detectors[detPos]->setSettingsDir(directory);
// multi
size_t p1 = 0;
size_t p2 = s.find('+', p1);
int id = 0;
while (p2 != std::string::npos) {
detectors[id]->setSettingsDir(s.substr(p1, p2 - p1));
if (detectors[id]->getErrorMask())
setErrorMask(getErrorMask() | (1 << id));
++id;
s = s.substr(p2 + 1);
p2 = s.find('+');
if (id >= (int)detectors.size())
break;
}
return getSettingsDir();
auto r = parallelCall(&slsDetector::setSettingsDir, directory);
return sls::concatenateIfDifferent(r);
}
@ -1496,17 +1422,14 @@ int64_t multiSlsDetector::setNumberOfFrames(int64_t t, int detPos){
return setTimer(FRAME_NUMBER, t, detPos);
}
int64_t multiSlsDetector::setNumberOfCycles(int64_t t, int detPos){
return setTimer(CYCLES_NUMBER, t, detPos);
}
int64_t multiSlsDetector::setNumberOfGates(int64_t t, int detPos){
return setTimer(GATES_NUMBER, t, detPos);
}
int64_t multiSlsDetector::setNumberOfStorageCells(int64_t t, int detPos) {
return setTimer(STORAGE_CELL_NUMBER, t, detPos);
}
@ -1769,45 +1692,25 @@ uint32_t multiSlsDetector::clearBit(uint32_t addr, int n, int detPos) {
std::string multiSlsDetector::setNetworkParameter(networkParameter p, std::string s, int detPos) {
std::string multiSlsDetector::setNetworkParameter(networkParameter parameter, std::string value, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setNetworkParameter(p, s);
}
if (detPos >= 0)
return detectors[detPos]->setNetworkParameter(parameter, value);
// multi
// single argument for all
if (s.find('+') == std::string::npos) {
if (p != RECEIVER_STREAMING_PORT && p != CLIENT_STREAMING_PORT){
auto r = parallelCall(&slsDetector::setNetworkParameter, p, s);
return sls::concatenateIfDifferent(r);
}
// calculate ports individually
int firstPort = stoi(s);
int numSockets = (getDetectorsType() == EIGER) ? 2 : 1;
std::vector<std::string> r;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
s = std::to_string(firstPort + (idet * numSockets));
r.push_back(detectors[idet]->setNetworkParameter(p,s));
}
if (parameter != RECEIVER_STREAMING_PORT && parameter != CLIENT_STREAMING_PORT){
auto r = parallelCall(&slsDetector::setNetworkParameter, parameter, value);
return sls::concatenateIfDifferent(r);
}
//concatenated argumements for all
// calculate ports individually
int firstPort = stoi(value);
int numSockets = (getDetectorsType() == EIGER) ? 2 : 1;
std::vector<std::string> r;
size_t p1 = 0;
size_t p2 = s.find('+', p1);
int id = 0;
while (p2 != std::string::npos) {
r.push_back(detectors[id]->setNetworkParameter(p, s.substr(p1, p2 - p1)));
++id;
s = s.substr(p2 + 1);
p2 = s.find('+');
if (id >= (int)detectors.size())
break;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
auto port = std::to_string(firstPort + (idet * numSockets));
r.push_back(detectors[idet]->setNetworkParameter(parameter, port));
}
return sls::concatenateIfDifferent(r);
}
@ -3969,7 +3872,6 @@ int multiSlsDetector::setThreadedProcessing(int enable) {
void multiSlsDetector::startProcessingThread() {
setTotalProgress();
#ifdef VERBOSE
std::cout << "start thread stuff" << std::endl;
@ -3988,19 +3890,14 @@ void multiSlsDetector::startProcessingThread() {
/* Initialize and set thread detached attribute */
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
ret = pthread_setschedparam(pthread_self(), policy, &mparam);
pthread_setschedparam(pthread_self(), policy, &mparam);
ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this);
if (ret)
printf("ret %d\n", ret);
pthread_attr_destroy(&tattr);
// scheduling parameters of target thread
ret = pthread_setschedparam(dataProcessingThread, policy, &param);
pthread_setschedparam(dataProcessingThread, policy, &param);
}

View File

@ -208,7 +208,7 @@ public:
* Get acquiring flag from shared memory
* @returns acquiring flag
*/
bool getAcquiringFlag();
bool getAcquiringFlag() const;
/**
* Check if acquiring flag is set, set error if set
@ -531,7 +531,7 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns the trimbit/settings directory
*/
std::string setSettingsDir(std::string s, int detPos = -1);
std::string setSettingsDir(std::string directory, int detPos = -1);
/**
* Loads the modules settings/trimbits reading from a specific file
@ -855,7 +855,7 @@ public:
* @param detPos -1 for all detectors in list or specific detector position
* @returns network parameter value set (from getNetworkParameter)
*/
std::string setNetworkParameter(networkParameter p, std::string s, int detPos = -1);
std::string setNetworkParameter(networkParameter parameter, std::string value, int detPos = -1);
/**
* Get network parameter

View File

@ -868,7 +868,6 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int
}
char m[MAX_STR_LENGTH];
#ifdef VERBOSE
std::cout << "Getting detector type " << std::endl;
#endif
@ -881,8 +880,9 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int
std::cout << "Detector type is "<< t << std::endl;
#endif
} else {
mySocket->ReceiveDataOnly(m,sizeof(m));
std::cout<< "Detector returned error: " << m << std::endl;
char mess[MAX_STR_LENGTH];
mySocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
mySocket->Disconnect();
} else {
@ -894,14 +894,12 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int
int slsDetector::setDetectorType(detectorType const type) {
int ret=FAIL;
int fnum=F_GET_DETECTOR_TYPE,fnum2=F_GET_RECEIVER_TYPE;
detectorType retval = type;
char mess[MAX_STR_LENGTH];
memset(mess, 0, MAX_STR_LENGTH);
if (type != GET_DETECTOR_TYPE) {
#ifdef VERBOSE
std::cout<< std::endl;
@ -930,7 +928,6 @@ int slsDetector::setDetectorType(detectorType const type) {
if((thisDetector->myDetectorType != GENERIC) &&
(thisDetector->receiverOnlineFlag==ONLINE_FLAG)) {
ret = FAIL;
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending detector type to Receiver " <<
(int)thisDetector->myDetectorType << std::endl;
@ -946,9 +943,7 @@ int slsDetector::setDetectorType(detectorType const type) {
std::cout << "ERROR: Could not send detector type to receiver" << std::endl;
setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET));
}
}
}
return retval;
}
@ -1250,11 +1245,10 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in
int slsDetector::setPort(portType index, int num) {
int fnum=F_SET_PORT, fnum2 = F_SET_RECEIVER_PORT;
int retval;
// uint64_t ut;
char mess[MAX_STR_LENGTH]="";
int ret=FAIL;
bool online=false;
MySocketTCP *s = 0;
@ -1362,6 +1356,7 @@ int slsDetector::setPort(portType index, int num) {
s->SendDataOnly(&num,sizeof(num));
s->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
char mess[MAX_STR_LENGTH]="";
s->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
} else {
@ -2099,8 +2094,7 @@ int slsDetector::loadSettingsFile(std::string fname) {
int iodelay = -1;
int tau = -1;
std::string fn=fname;
fn=fname;
std::string fn = fname;
std::ostringstream ostfn;
ostfn << fname;
@ -2233,8 +2227,7 @@ int slsDetector::startAcquisition() {
int fnum=F_START_ACQUISITION;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
#ifdef VERBOSE
std::cout<< "Starting acquisition "<< std::endl;
#endif
@ -2244,6 +2237,7 @@ int slsDetector::startAcquisition() {
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
char mess[MAX_STR_LENGTH]="";
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
@ -2778,12 +2772,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
int64_t slsDetector::getTimeLeft(timerIndex index) {
int fnum=F_GET_TIME_LEFT;
int64_t retval;
char mess[MAX_STR_LENGTH]="";
int ret=OK;
int fnum = F_GET_TIME_LEFT;
int64_t retval = -1;
int ret = OK;
#ifdef VERBOSE
std::cout<< "Getting timer "<< index << std::endl;
@ -2795,6 +2786,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index) {
stopSocket->SendDataOnly(&index,sizeof(index));
stopSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
char mess[MAX_STR_LENGTH]="";
stopSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
} else {
@ -3023,16 +3015,10 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) {
int slsDetector::getADC(dacIndex index) {
int retval;
int retval = -1;
int fnum=F_GET_ADC;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
int arg;
arg=index;
int arg = index;
#ifdef VERBOSE
std::cout<< std::endl;
@ -3049,6 +3035,7 @@ int slsDetector::getADC(dacIndex index) {
*(adcs+index)=retval;
}
} else {
char mess[MAX_STR_LENGTH]="";
stopSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
@ -3064,30 +3051,18 @@ int slsDetector::getADC(dacIndex index) {
if (ret==FAIL) {
std::cout<< "Get ADC failed " << std::endl;
}
return retval;
}
slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunicationMode(
externalCommunicationMode pol) {
int arg[1];
externalCommunicationMode retval;
int arg = pol;
externalCommunicationMode retval = GET_EXTERNAL_COMMUNICATION_MODE;;
int fnum=F_SET_EXTERNAL_COMMUNICATION_MODE;
char mess[MAX_STR_LENGTH]="";
arg[0]=pol;
int ret=FAIL;
retval=GET_EXTERNAL_COMMUNICATION_MODE;
#ifdef VERBOSE
std::cout<< std::endl;
@ -3101,6 +3076,7 @@ slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunication
if (ret!=FAIL)
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
else {
char mess[MAX_STR_LENGTH]="";
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
@ -3119,7 +3095,6 @@ slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunication
std::cout<< "Setting communication mode failed" << std::endl;
}
return retval;
}
@ -3407,7 +3382,6 @@ std::string slsDetector::setNetworkParameter(networkParameter index, std::string
std::string slsDetector::getNetworkParameter(networkParameter index) {
std::ostringstream ss;std::string s;
switch (index) {
case DETECTOR_MAC:
return getDetectorMAC();
@ -3444,7 +3418,7 @@ std::string slsDetector::getNetworkParameter(networkParameter index) {
return getReceiverRealUDPSocketBufferSize();
default:
return (char*)("unknown network parameter");
return std::string("unknown network parameter");
}
}
@ -4110,13 +4084,10 @@ int slsDetector::setUDPConnection() {
int slsDetector::digitalTest( digitalTestMode mode, int ival) {
int retval;
int fnum=F_DIGITAL_TEST;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
int retval = -1;
int fnum = F_DIGITAL_TEST;
int ret = FAIL;
#ifdef VERBOSE
std::cout<< std::endl;
std::cout<< "Getting id of "<< mode << std::endl;
@ -4131,6 +4102,7 @@ int slsDetector::digitalTest( digitalTestMode mode, int ival) {
if (ret!=FAIL)
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
else {
char mess[MAX_STR_LENGTH]="";
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
@ -4211,30 +4183,22 @@ int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) {
int slsDetector::writeCounterBlockFile(std::string const fname,int startACQ) {
int ret=FAIL;
short int counterVals[thisDetector->nChans*thisDetector->nChips];
#ifdef VERBOSE
std::cout<< std::endl<< "Reading Counter to \""<<fname;
if(startACQ==1)
std::cout<<"\" and Restarting Acquisition";
std::cout<<std::endl;
#endif
ret=getCounterBlock(counterVals,startACQ);
short int counterVals[thisDetector->nChans*thisDetector->nChips];
int ret=getCounterBlock(counterVals,startACQ);
if(ret==OK)
ret=writeDataFile(fname, getTotalNumberOfChannels(), counterVals);
return ret;
}
int slsDetector::getCounterBlock(short int arg[],int startACQ) {
int ret=FAIL;
int fnum=F_READ_COUNTER_BLOCK;
char mess[MAX_STR_LENGTH]="";
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
@ -4244,6 +4208,7 @@ int slsDetector::getCounterBlock(short int arg[],int startACQ) {
if (ret!=FAIL)
controlSocket->ReceiveDataOnly(arg,thisDetector->dataBytes);
else {
char mess[MAX_STR_LENGTH]="";
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
@ -4252,13 +4217,10 @@ int slsDetector::getCounterBlock(short int arg[],int startACQ) {
updateDetector();
}
}
return ret;
}
int slsDetector::resetCounterBlock(int startACQ) {
int ret=FAIL;
@ -4678,10 +4640,8 @@ int slsDetector::setFlippedData(dimension d, int value) {
int slsDetector::setAllTrimbits(int val) {
int fnum=F_SET_ALL_TRIMBITS;
int retval;
char mess[MAX_STR_LENGTH]="";
int retval = -1;
int ret=OK;
#ifdef VERBOSE
std::cout<< "Setting all trimbits to "<< val << std::endl;
#endif
@ -4691,6 +4651,7 @@ int slsDetector::setAllTrimbits(int val) {
controlSocket->SendDataOnly(&val,sizeof(val));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
char mess[MAX_STR_LENGTH]="";
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET));
@ -4702,7 +4663,6 @@ int slsDetector::setAllTrimbits(int val) {
updateDetector();
}
}
#ifdef VERBOSE
std::cout<< "All trimbits were set to "<< retval << std::endl;
#endif
@ -6339,16 +6299,12 @@ int slsDetector::setReceiverPartialFramesPadding(int f) {
}
slsDetectorDefs::fileFormat slsDetector::setFileFormat(fileFormat f) {
if (f == GET_FILE_FORMAT)
return getFileFormat();
int fnum=F_SET_RECEIVER_FILE_FORMAT;
int ret = FAIL;
int arg = -1;
int arg = f;
int retval = -1;
arg = (int)f;
#ifdef VERBOSE
std::cout << "Sending file format to receiver " << arg << std::endl;
#endif
@ -6477,7 +6433,7 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus() {
int fnum=F_GET_RECEIVER_STATUS;
int ret = FAIL;
int retval=-1;
runStatus s=ERROR;
runStatus s = ERROR;
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
@ -6490,9 +6446,8 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus() {
if(retval!=-1)
s=(runStatus)retval;
if(ret==FORCE_UPDATE)
ret=updateReceiver();
updateReceiver();
}
return s;
}