From b52f9a85691decaf5a265a19f4dd8ddf4f349147 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Wed, 24 Oct 2012 11:59:04 +0000 Subject: [PATCH] filepath, filename and index set from slsdet or multislsdet, moving all receiver coding from slsdetectorcommand to slsdetector git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@312 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/Makefile | 6 +- .../commonFiles/sls_detector_funcs.h | 6 +- .../multiSlsDetector/multiSlsDetector.cpp | 121 ++-- .../multiSlsDetector/multiSlsDetector.h | 57 +- .../slsDetector/slsDetector.cpp | 674 ++++++++++-------- slsDetectorSoftware/slsDetector/slsDetector.h | 49 +- .../slsDetector/slsDetectorBase.h | 22 - .../slsDetector/slsDetectorCommand.cpp | 183 ++--- .../slsDetector/slsDetectorUsers.h | 2 +- .../slsDetector/slsDetectorUtils.cpp | 13 +- .../slsDetector/slsDetectorUtils.h | 29 +- .../slsDetectorAnalysis/fileIO.h | 28 +- 12 files changed, 596 insertions(+), 594 deletions(-) diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index b364c0d4d..eee7e1138 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -40,12 +40,12 @@ picassoServer: $(SRC_MYTHEN_SVC) %.o : %.cpp %.h - $(CXX) -Wall -o $@ -c $< $(INCLUDES) $(DFLAGS) $(FLAGS) -fPIC $(EPICSFLAGS) + $(CXX) -Wall -o $@ -c $< $(INCLUDES) $(DFLAGS) $(FLAGS) -fPIC $(EPICSFLAGS) -L/usr/lib64/ package: $(OBJS) - $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) - ar rcs libSlsDetector.a $(OBJS) + $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS) -L/usr/lib64/ + ar rcs libSlsDetector.a $(OBJS) clean: rm -rf libSlsDetector.a libSlsDetector.so core docs/* $(OBJS) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 7f8759016..776a9712b 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -108,11 +108,11 @@ enum { //receiver - F_SET_RECEIVER_FILE_NAME, /**< sets receiver file name */ + F_SET_FILE_PATH, /**< sets receiver file directory */ - F_SET_RECEIVER_FILE_DIR, /**< sets receiver file directory */ + F_SET_FILE_NAME, /**< sets receiver file name */ - F_SET_RECEIVER_FILE_INDEX, /**< sets receiver file index */ + F_SET_FILE_INDEX, /**< sets receiver file index */ F_START_RECEIVER, /**< starts the receiver listening mode */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 4bd82b69a..b7f87694f 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -117,14 +117,14 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) thisMultiDetector->maxNumberOfChannels=0; - - /** set trimDsdir, calDir and filePath to default to home directory*/ strcpy(thisMultiDetector->filePath,getenv("HOME")); /** set fileName to default to run*/ strcpy(thisMultiDetector->fileName,"run"); /** set fileIndex to default to 0*/ thisMultiDetector->fileIndex=0; + + /** set progress Index to default to 0*/ thisMultiDetector->progressIndex=0; /** set total number of frames to be acquired to default to 1*/ @@ -192,29 +192,8 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) thisMultiDetector->alreadyExisting=1; } - - for (int i=0; inumberOfDetectors; i++) { -#ifdef VERBOSE - cout << thisMultiDetector->detectorIds[i] << endl; -#endif - detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i], this); - - - // setAngularConversionPointer(detectors[i]->getAngularConversionPointer(),detectors[i]->getNModsPointer(),detectors[i]->getNChans()*detectors[i]->getNChips(), i); - - } - for (int i=thisMultiDetector->numberOfDetectors; ilastPID=getpid(); - - - - - + //assigned before creating detector stoppedFlag=&thisMultiDetector->stoppedFlag; threadedProcessing=&thisMultiDetector->threadedProcessing; actionMask=&thisMultiDetector->actionMask; @@ -243,13 +222,35 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) currentSettings=&thisMultiDetector->currentSettings; currentThresholdEV=&thisMultiDetector->currentThresholdEV; - filePath=thisMultiDetector->filePath; - fileName=thisMultiDetector->fileName; - fileIndex=&thisMultiDetector->fileIndex; moveFlag=NULL; sampleDisplacement=thisMultiDetector->sampleDisplacement; + filePath=thisMultiDetector->filePath; + fileName=thisMultiDetector->fileName; + fileIndex=&thisMultiDetector->fileIndex; + + + + for (int i=0; inumberOfDetectors; i++) { +#ifdef VERBOSE + cout << thisMultiDetector->detectorIds[i] << endl; +#endif + detectors[i]=new slsDetector(thisMultiDetector->detectorIds[i], this); + + + // setAngularConversionPointer(detectors[i]->getAngularConversionPointer(),detectors[i]->getNModsPointer(),detectors[i]->getNChans()*detectors[i]->getNChips(), i); + + } + for (int i=thisMultiDetector->numberOfDetectors; ilastPID=getpid(); + + getNMods(); getMaxMods(); @@ -3508,19 +3509,16 @@ int multiSlsDetector::readDataFile(string fname, int *data) { int multiSlsDetector::setReceiverOnline(int off) { - if (off!=GET_ONLINE_FLAG) { - int ret=-100,ret1; - for (int i=0; inumberOfDetectors; i++) - if (detectors[i]){ - ret1=detectors[i]->setReceiverOnline(off); - if(ret==-100) - ret=ret1; - else if (ret!=ret1) - ret=-1; - } - thisMultiDetector->receiverOnlineFlag=ret; - } - return thisMultiDetector->receiverOnlineFlag; + int ret=-100,ret1; + for (int i=0; inumberOfDetectors; i++) + if (detectors[i]){ + ret1=detectors[i]->setReceiverOnline(off); + if(ret==-100) + ret=ret1; + else if (ret!=ret1) + ret=-1; + } + return ret; } @@ -3542,31 +3540,34 @@ string multiSlsDetector::checkReceiverOnline() { +string multiSlsDetector::setFilePath(string s) { + if(!s.empty()) + fileIO::setFilePath(s); + /* + string ret="error", ret1; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret1=detectors[idet]->setFilePath(s); + if (ret=="error") + ret=ret1; + else if (ret!=ret1) + ret=""; + } + } + return ret;*/ + return fileIO::getFilePath(); +} -string multiSlsDetector::setReceiverFileName(string fileName) { + + +string multiSlsDetector::setFileName(string s) { string ret="error", ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { if(getNumberOfDetectors()>1) setDetectorIndex(idet); - ret1=detectors[idet]->setReceiverFileName(fileName); - if (ret=="error") - ret=ret1; - else if (ret!=ret1) - ret=""; - } - } - return ret; -} - - -string multiSlsDetector::setReceiverFileDir(string fileDir) { - string ret="error", ret1; - - for (int idet=0; idetnumberOfDetectors; idet++) { - if (detectors[idet]) { - ret1=detectors[idet]->setReceiverFileDir(fileDir); + ret1=detectors[idet]->setFileName(s); if (ret=="error") ret=ret1; else if (ret!=ret1) @@ -3578,12 +3579,12 @@ string multiSlsDetector::setReceiverFileDir(string fileDir) { -int multiSlsDetector::setReceiverFileIndex(int fileIndex) { +int multiSlsDetector::setFileIndex(int i) { int ret=-100, ret1; for (int idet=0; idetnumberOfDetectors; idet++) { if (detectors[idet]) { - ret1=detectors[idet]->setReceiverFileIndex(fileIndex); + ret1=detectors[idet]->setFileIndex(i); if (ret==-100) ret=ret1; else if (ret!=ret1) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index c73e89511..4aac1bb05 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -105,15 +105,12 @@ class multiSlsDetector : public slsDetectorUtils { /** total number of frames to be acquired */ int totalProgress; - - - /** current index of the output file */ + /** current index of the output file */ int fileIndex; - /** path of the output files */ - char filePath[MAX_STR_LENGTH]; - /** name root of the output files */ + /** name root of the output files */ char fileName[MAX_STR_LENGTH]; - + /** path of the output files */ + char filePath[MAX_STR_LENGTH]; /** corrections to be applied to the data \see ::correctionFlags */ int correctionMask; @@ -186,10 +183,6 @@ class multiSlsDetector : public slsDetectorUtils { int scanPrecision[MAX_SCAN_LEVELS]; - //receiver - /** online receiver flag - is set if the receiver is connected, unset if socket connection is not possible */ - int receiverOnlineFlag; - }; @@ -1027,29 +1020,45 @@ class multiSlsDetector : public slsDetectorUtils { */ string checkReceiverOnline(); - /** - Sets up the receiver file name - @param fileName file name - \returns file name - */ - string setReceiverFileName(string fileName=""); /** - Sets up the receiver file directory - @param fileName fileDir file directory + Sets up the file directory + @param s file directory \returns file dir */ - string setReceiverFileDir(string fileDir=""); + string setFilePath(string s=""); /** - Sets up the receiver file index - @param fileIndex file index + Sets up the file name + @param s file name + \returns file name + */ + string setFileName(string s=""); + + /** + Sets up the file index + @param i file index \returns file index */ - int setReceiverFileIndex(int fileIndex=-1); + int setFileIndex(int i=-1); + + /** + \returns file dir + */ + string getFilePath(){return setFilePath();}; + + /** + \returns file name + */ + string getFileName(){return setFileName();}; + + /** + \returns file index + */ + int getFileIndex(){return setFileIndex();}; - /** Starts the listening mode of receiver + /** Starts the listening mode of receiver \returns OK or FAIL */ int startReceiver(); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 9c59eeb7c..ac15b8173 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -112,6 +112,7 @@ int slsDetector::freeSharedMemory() { slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(), thisDetector(NULL), detId(id), + parentDet(p), shmId(-1), controlSocket(NULL), stopSocket(NULL), @@ -122,8 +123,7 @@ slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(), dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - parentDet(p) + chanregs(NULL) { @@ -161,6 +161,7 @@ slsDetector::slsDetector(int id,multiSlsDetector *p) :slsDetectorUtils(), slsDetector::slsDetector(detectorType type, int id,multiSlsDetector *p): slsDetectorUtils(), thisDetector(NULL), detId(id), + parentDet(p), shmId(-1), controlSocket(NULL), stopSocket(NULL), @@ -171,8 +172,7 @@ slsDetector::slsDetector(detectorType type, int id,multiSlsDetector *p): slsDete dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - parentDet(p) + chanregs(NULL) { while (shmId<0) { /**Initlializes shared memory \sa initSharedMemory @@ -213,6 +213,7 @@ slsDetector::~slsDetector(){ slsDetector::slsDetector(char *name, int id, int cport,multiSlsDetector *p) : slsDetectorUtils(), thisDetector(NULL), detId(id), + parentDet(p), shmId(-1), controlSocket(NULL), stopSocket(NULL), @@ -223,8 +224,8 @@ slsDetector::slsDetector(char *name, int id, int cport,multiSlsDetector *p) : sl dacs(NULL), adcs(NULL), chipregs(NULL), - chanregs(NULL), - parentDet(p) + chanregs(NULL) + { detectorType type=(detectorType)getDetectorType(name, cport); @@ -521,21 +522,20 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; else thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; - /** set trimDsdir, calDir and filePath to default to home directory*/ + /** set trimDsdir, calDir to default to home directory*/ strcpy(thisDetector->settingsDir,getenv("HOME")); strcpy(thisDetector->calDir,getenv("HOME")); - strcpy(thisDetector->filePath,getenv("HOME")); + /** sets trimbit file */ strcpy(thisDetector->settingsFile,"none"); - /** set fileName to default to run*/ - strcpy(thisDetector->fileName,"run"); - /** set fileIndex to default to 0*/ - thisDetector->fileIndex=0; /** set progress Index to default to 0*/ thisDetector->progressIndex=0; /** set total number of frames to be acquired to default to 1*/ thisDetector->totalProgress=1; + /** set trimDsdir, calDir and filePath to default to home directory*/ + strcpy(thisDetector->filePath,getenv("HOME")); + /** set number of trim energies to 0*/ thisDetector->nTrimEn=0; /** set correction mask to 0*/ @@ -664,13 +664,14 @@ int slsDetector::initializeDetectorSize(detectorType type) { currentSettings=&thisDetector->currentSettings; currentThresholdEV=&thisDetector->currentThresholdEV; - filePath=thisDetector->filePath; - fileName=thisDetector->fileName; - fileIndex=&thisDetector->fileIndex; moveFlag=&thisDetector->moveFlag; sampleDisplacement=NULL; settingsFile=thisDetector->settingsFile; + filePath=thisDetector->filePath; + fileName=parentDet->fileName; + fileIndex=parentDet->fileIndex; + // setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips); @@ -971,7 +972,7 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con char thisName[MAX_STR_LENGTH]; - int thisCP, thisSP, thisDP; + int thisCP, thisSP; int retval=OK; if (strcmp(name.c_str(),"")!=0) { @@ -3463,13 +3464,13 @@ int slsDetector::setPort(portType index, int num){ #ifdef VERBOSE cout << "s="<< s<< endl; cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; -#endif +#endif if (s==NULL) { #ifdef VERBOSE cout << "s=NULL"<< endl; cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; -#endif +#endif setTCPSocket("",DEFAULT_PORTNO); } if (controlSocket) { @@ -3478,7 +3479,7 @@ int slsDetector::setPort(portType index, int num){ #ifdef VERBOSE cout << "still cannot connect!"<< endl; cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; -#endif +#endif @@ -3612,7 +3613,7 @@ int slsDetector::setTotalProgress() { npos=thisDetector->numberOfPositions; if (timerValue[MEASUREMENTS_NUMBER]>0) - nc=timerValue[MEASUREMENTS_NUMBER]; + nm=timerValue[MEASUREMENTS_NUMBER]; if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & (1 << MAX_ACTIONS))) @@ -3621,7 +3622,7 @@ int slsDetector::setTotalProgress() { if ((thisDetector->nScanSteps[1]>0) && (thisDetector->actionMask & (1 << (MAX_ACTIONS+1)))) nscan[1]=thisDetector->nScanSteps[1]; - thisDetector->totalProgress=nf*nc*npos*nscan[0]*nscan[1]; + thisDetector->totalProgress=nf*nc*npos*nm*nscan[0]*nscan[1]; #ifdef VERBOSE cout << "nc " << nc << endl; @@ -4033,8 +4034,8 @@ int slsDetector::setFlatFieldCorrection(string fname) { double data[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; //double err[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; - double xmed[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; - int nmed=0; + //double xmed[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; + // int nmed=0; int im=0; int nch; thisDetector->nBadFF=0; @@ -4289,10 +4290,10 @@ int slsDetector::rateCorrect(double* datain, double *errin, double* dataout, dou int slsDetector::setBadChannelCorrection(string fname){ - - int nbadmod,ret=0; - int badchanlist[MAX_BADCHANS]; - int off; + // int nbadmod; + int ret=0; + //int badchanlist[MAX_BADCHANS]; + //int off; string fn=fname; @@ -4460,13 +4461,17 @@ char* slsDetector::setReceiverIP(string receiverIP){ } if(wrongFormat) - return ("IP Address should be VALID and in xxx.xxx.xxx.xxx format"); - - if(setReceiverTCPSocket()==FAIL) - return("Connection to Receiver failed."); + std::cout<< "IP Address should be VALID and in xxx.xxx.xxx.xxx format" << endl; + else{ + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + setFilePath(fileIO::getFilePath()); + setFileName(fileIO::getFileName()); + setFileIndex(fileIO::getFileIndex()); + }else + std::cout << "cannot connect to receiver" << endl; + } return thisDetector->receiverIP; - } @@ -4576,7 +4581,8 @@ int slsDetector::configureMAC(int adc){ updateDetector(); } } - } + }else + std::cout << "cannot connect to detector" << endl; #ifdef VERBOSE std::cout<< "Configuring MAC - returned "<< retval << std::endl; #endif @@ -4803,7 +4809,7 @@ int slsDetector::readConfigurationFile(string const fname){ string ans; string str; ifstream infile; - char *args[1000]; + //char *args[1000]; string sargname, sargval; int iline=0; @@ -5141,7 +5147,7 @@ int slsDetector::loadCalibrationFile(string fname, int imod) { ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im); } fn=ostfn.str(); - if(myMod=getModule(im)){ + if((myMod=getModule(im))){ if(readCalibrationFile(fn, myMod->gain, myMod->offset)==FAIL) return FAIL; setModule(*myMod); @@ -5287,7 +5293,7 @@ int slsDetector::setReceiverOnline(int off) { //Since flag becomes offline if receiver not online. //This ensures server to NOT send to receiver in the next command line comment if((off==ONLINE_FLAG)&&(thisDetector->receiverOnlineFlag!=ONLINE_FLAG)) - stopReceiver(); + DetectorStopReceiver(); } return thisDetector->receiverOnlineFlag; } @@ -5406,334 +5412,378 @@ int slsDetector::setReceiverTCPSocket(string const name, int const data_port){ -string slsDetector::setReceiverFileName(string fileName) { - int fnum=F_SET_RECEIVER_FILE_NAME; - int ret = FAIL; - char mess[100]; - char arg[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]=""; +string slsDetector::setFilePath(string s) { + int fnum=F_SET_FILE_PATH; + int ret = FAIL; + char mess[100]; + char arg[MAX_STR_LENGTH]; + char retval[MAX_STR_LENGTH]=""; + struct stat st; + + if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ + if(!s.empty()){ + if(stat(s.c_str(),&st)) + std::cout << "path does not exist" << endl; + else + fileIO::setFilePath(s); + } + } - if(!fileName.empty()){ - parentDet->setFileName(fileName); - fileName=parentDet->createReceiverFilePrefix(); - } - strcpy(arg,fileName.c_str()); - + else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + strcpy(arg,s.c_str()); #ifdef VERBOSE - std::cout << "Sending file name to receiver " << arg << std::endl; + std::cout << "Sending file path to receiver " << arg << std::endl; #endif - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); + fileIO::setFilePath(s); + } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } }else - dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); - } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } + std::cout << "cannot connect to receiver" << endl; + + return fileIO::getFilePath(); +} + + + +string slsDetector::setFileName(string s) { + int fnum=F_SET_FILE_NAME; + int ret = FAIL; + char mess[100]; + char arg[MAX_STR_LENGTH]; + char retval[MAX_STR_LENGTH]=""; + + + if(!s.empty()){ + fileIO::setFileName(s); + s=parentDet->createReceiverFilePrefix(); + } + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ + if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ + strcpy(arg,s.c_str()); #ifdef VERBOSE - std::cout << "retval: " << retval << std::endl; + std::cout << "Sending file name to receiver " << arg << std::endl; #endif - string ans = parentDet->getNameFromReceiverFilePrefix(string(retval)); - parentDet->setFileName(ans); - return ans; + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); +#ifdef VERBOSE + std::cout << "Complete file prefix from receiver: " << retval << std::endl; +#endif + fileIO::setFileName(parentDet->getNameFromReceiverFilePrefix(string(retval))); + } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + + }else + std::cout << "cannot connect to receiver" << endl; + } + + return fileIO::getFileName(); } -string slsDetector::setReceiverFileDir(string fileDir) { - int fnum=F_SET_RECEIVER_FILE_DIR; - int ret = FAIL; - char mess[100]; - char arg[MAX_STR_LENGTH],retval[MAX_STR_LENGTH]=""; - strcpy(arg,fileDir.c_str()); -#ifdef VERBOSE - std::cout << "Sending file dir to receiver " << arg << std::endl; -#endif - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->SendDataOnly(arg,MAX_STR_LENGTH); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - }else{ - dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH); - parentDet->setFilePath(string(retval)); + +int slsDetector::setFileIndex(int i) { + int fnum=F_SET_FILE_INDEX; + int ret = FAIL; + int retval=-1; + int arg = i; + char mess[100]; + + if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ + if(i>=0) + fileIO::setFileIndex(i); } - } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - - return string(retval); -} - - -int slsDetector::setReceiverFileIndex(int fileIndex) { - int fnum=F_SET_RECEIVER_FILE_INDEX; - int ret = FAIL; - char mess[100]; - int retval=-1; - - int arg = fileIndex; - + else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Sending file dir to receiver " << arg << std::endl; + std::cout << "Sending file dir to receiver " << arg << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(&arg,sizeof(arg)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + fileIO::setFileIndex(retval); + } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->SendDataOnly(&arg,sizeof(arg)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - }else{ - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if(fileIndex!=-1) - parentDet->setFileIndex(retval); - } - } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - return retval; + }else + std::cout << "cannot connect to receiver" << endl; + + return fileIO::getFileIndex(); } int slsDetector::startReceiver(){ - int fnum=F_START_RECEIVER; - int ret = FAIL; - char mess[100]; + int fnum=F_START_RECEIVER; + int ret = FAIL; + char mess[100]; + + if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { #ifdef VERBOSE - std::cout << "Starting Receiver " << std::endl; + std::cout << "Starting Receiver " << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + ret=updateReceiver(); + } + } + }else + std::cout << "cannot connect to receiver" << endl; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; + + //configuremac for gotthard + if(ret==OK) + if(thisDetector->myDetectorType==GOTTHARD) + ret=configureMAC(); + + if(ret==OK){ + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Setting detector to send packets via receiver " << std::endl; +#endif + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + ret=updateDetector(); + } + } + }else + std::cout << "cannot connect to detector" << endl; } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - ret=updateReceiver(); - } - } - } - //configuremac for gotthard - if(ret==OK) - if(thisDetector->myDetectorType==GOTTHARD) - ret=configureMAC(); - - //tell the server to send to receiver and not CPU - if(ret==OK){ - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - ret=updateDetector(); - } - } - } - } - - return ret; + return ret; } +int slsDetector::DetectorStopReceiver(){ + int fnum=F_STOP_RECEIVER; + int ret = FAIL; + char mess[100]; + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Setting detector to send packets via client " << std::endl; +#endif + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + }else + std::cout << "cannot connect to detector" << endl; + + return ret; +} + + int slsDetector::stopReceiver(){ - int fnum=F_STOP_RECEIVER; - //different iret for server, should not return ok if receiver didnt connect - int ret = FAIL; - char mess[100]; + int fnum=F_STOP_RECEIVER; + int ret = FAIL; + char mess[100]; + DetectorStopReceiver(); + + if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { #ifdef VERBOSE - std::cout << "Stopping Receiver " << std::endl; + std::cout << "Stopping Receiver " << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } - //tell the server to NOT send to receiver and instead to CPU - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + ret=updateReceiver(); + } + } + }else + std::cout << "cannot connect to receiver" << endl; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; + //increment file index + if(ret==OK){ + fileIO::setFileIndex(fileIO::getFileIndex()+1); + setFileIndex(fileIO::getFileIndex()); } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - ret=updateReceiver(); - } - } - } - - - return ret; + return ret; } slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ - int fnum=F_GET_RECEIVER_STATUS; - int ret = FAIL; - char mess[100]; - runStatus retval=ERROR; + int fnum=F_GET_RECEIVER_STATUS; + int ret = FAIL; + char mess[100]; + runStatus retval=ERROR; + if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { #ifdef VERBOSE - std::cout << "Getting Receiver Status" << std::endl; + std::cout << "Getting Receiver Status" << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + }else + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } }else - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - } - return retval; + std::cout << "cannot connect to receiver" << endl; + return retval; } int slsDetector::getFramesCaughtByReciver(){ - int fnum=F_GET_FRAMES_CAUGHT; - int ret = FAIL; - char mess[100]; - int retval=-1; + int fnum=F_GET_FRAMES_CAUGHT; + int ret = FAIL; + char mess[100]; + int retval=-1; + if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { #ifdef VERBOSE - std::cout << "Getting Frames Caught by Receiver " << std::endl; + std::cout << "Getting Frames Caught by Receiver " << std::endl; #endif - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else{ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - } - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - } - return retval; + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } + }else + std::cout << "cannot connect to receiver" << endl; + return retval; } int slsDetector::lockReceiver(int lock){ - int fnum=F_LOCK_RECEIVER; - int ret = FAIL; - int retval=-1; - char mess[100]; + int fnum=F_LOCK_RECEIVER; + int ret = FAIL; + int retval=-1; + char mess[100]; + int arg= lock; - int arg= lock; + if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Locking or Unlocking Receiver " << std::endl; + std::cout << "Locking or Unlocking Receiver " << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->SendDataOnly(&arg,sizeof(arg)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->SendDataOnly(&arg,sizeof(arg)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else{ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } + }else + std::cout << "cannot connect to receiver" << endl; - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - } - return retval; + return retval; } @@ -5742,35 +5792,35 @@ int slsDetector::lockReceiver(int lock){ string slsDetector::getReceiverLastClientIP(){ - int fnum=F_GET_LAST_CLIENT_IP; - int ret = FAIL; - char retval[INET_ADDRSTRLEN]; - char mess[100]; - + int fnum=F_GET_LAST_CLIENT_IP; + int ret = FAIL; + char retval[INET_ADDRSTRLEN]=""; + char mess[100]; + if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Geting Last Client IP connected to Receiver " << std::endl; + std::cout << "Geting Last Client IP connected to Receiver " << std::endl; #endif + if (dataSocket) { + if (dataSocket->Connect()>=0) { + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + dataSocket->ReceiveDataOnly(retval,sizeof(retval)); + else{ + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - if (dataSocket->Connect()>=0) { - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - dataSocket->ReceiveDataOnly(retval,sizeof(retval)); - else{ - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - } + dataSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateReceiver(); + } + } + }else + std::cout << "cannot connect to receiver" << endl; - dataSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateReceiver(); - } - } - } - return string(retval); + return string(retval); } @@ -5789,11 +5839,11 @@ int slsDetector::updateReceiverNoWait() { #endif n = dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - parentDet->setFileIndex(ind); + fileIO::setFileIndex(ind); n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - parentDet->setFilePath(path); + fileIO::setFilePath(path); n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - parentDet->setFileName(path); + fileIO::setFileName(path); return OK; } @@ -5807,7 +5857,7 @@ int slsDetector::updateReceiver() { int ret=OK; char mess[100]; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { if (dataSocket) { if (dataSocket->Connect()>=0) { dataSocket->SendDataOnly(&fnum,sizeof(fnum)); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 4870a0ecf..91258009e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -100,12 +100,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int progressIndex; /** total number of frames to be acquired */ int totalProgress; - /** current index of the output file */ - int fileIndex; - /** path of the output files */ + + /** path of the output files */ char filePath[MAX_STR_LENGTH]; - /** name root of the output files */ - char fileName[MAX_STR_LENGTH]; /* size of the detector */ @@ -1392,26 +1389,42 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int setReceiverTCPSocket(string const name="", int const data_port=-1); - /** - Sets up the receiver file name - @param fileName file name - \returns file name - */ - string setReceiverFileName(string fileName=""); /** - Sets up the receiver file directory - @param fileName fileDir file directory + Sets up the file directory + @param s fileDir file directory \returns file dir */ - string setReceiverFileDir(string fileDir=""); + string setFilePath(string s=""); /** - Sets up the receiver file index - @param fileIndex file index + Sets up the file name + @param s file name + \returns file name + */ + string setFileName(string s=""); + + /** + Sets up the file index + @param i file index \returns file index */ - int setReceiverFileIndex(int fileIndex=-1); + int setFileIndex(int i=-1); + + /** + \returns file dir + */ + string getFilePath(){return setFilePath();}; + + /** + \returns file name + */ + string getFileName(){return setFileName();}; + + /** + \returns file index + */ + int getFileIndex(){return setFileIndex();}; /** Starts the listening mode of receiver @@ -1424,6 +1437,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int stopReceiver(); + int DetectorStopReceiver(); + /** gets the status of the listening mode of receiver \returns status */ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index c9d8a10e6..b513a495d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -430,28 +430,6 @@ class slsDetectorBase : public virtual slsDetectorDefs { */ virtual int setReceiverOnline(int const online=GET_ONLINE_FLAG)=0; - /** - Sets up the receiver file name - @param fileName file name - \returns file name - */ - virtual string setReceiverFileName(string fileName="")=0; - - /** - Sets up the receiver file directory - @param fileName fileDir file directory - \returns file dir - */ - virtual string setReceiverFileDir(string fileDir="")=0; - - /** - Sets up the receiver file index - @param fileIndex file index - \returns file index - */ - virtual int setReceiverFileIndex(int fileIndex=-1)=0; - - /** Starts the listening mode of receiver \returns OK or FAIL */ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 46899ed4d..b5d59810c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -769,30 +769,24 @@ string slsDetectorCommand::helpLine(int narg, char *args[], int action) { string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { #ifdef VERBOSE - cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); + cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); #endif - myDet->setOnline(ONLINE_FLAG); - //receiver - if(myDet->setReceiverOnline()==ONLINE_FLAG){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("can not connect to receiver"); - if(myDet->getReceiverStatus()!=RUNNING){ - //update receiver index - if(myDet->setReceiverFileIndex(myDet->getFileIndex())==-1) - return string("could not set receiver file index"); - //start receiver - myDet->startReceiver(); - usleep(2000000); - if(myDet->getReceiverStatus()!=RUNNING) - return string("could not start receiver"); - } - } + myDet->setOnline(ONLINE_FLAG); + bool receiver=myDet->setReceiverOnline(); + if(receiver) + if(myDet->startReceiver()==OK) + usleep(2000000); + else return string("could not start receiver"); - myDet->acquire(); - return string(""); + myDet->acquire(); + + if(receiver) + myDet->stopReceiver(); + + return string(""); } @@ -1336,27 +1330,13 @@ string slsDetectorCommand::helpTrimEn(int narg, char *args[], int action) { string slsDetectorCommand::cmdOutDir(int narg, char *args[], int action){ - if (action==HELP_ACTION) { - return helpOutDir(narg, args, action); - } + if (action==HELP_ACTION) + return helpOutDir(narg, args, action); - if(myDet->setReceiverOnline()==ONLINE_FLAG){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("cannot connect to receiver"); - if(action==PUT_ACTION) - myDet->setReceiverFileDir(string(args[1])); - return myDet->setReceiverFileDir(); - } + else if(action==PUT_ACTION) + myDet->setFilePath(string(args[1])); - if (action==PUT_ACTION) { - struct stat st; - if(stat(args[1],&st)) - return string("path does not exist"); - else - myDet->setFilePath(string(args[1])); - } - - return string(myDet->getFilePath()); + return string(myDet->getFilePath()); } @@ -1374,22 +1354,13 @@ string slsDetectorCommand::helpOutDir(int narg, char *args[], int action){ string slsDetectorCommand::cmdFileName(int narg, char *args[], int action){ - if (action==HELP_ACTION) { - return helpFileName(narg, args, action); - } + if (action==HELP_ACTION) + return helpFileName(narg, args, action); - if(myDet->setReceiverOnline()==ONLINE_FLAG){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("cannot connect to receiver"); - if(action==PUT_ACTION) - myDet->setReceiverFileName(string(args[1])); - return myDet->setReceiverFileName(); - } + else if (action==PUT_ACTION) + myDet->setFileName(string(args[1])); - if (action==PUT_ACTION) - myDet->setFileName(string(args[1])); - - return string(myDet->getFileName()); + return string(myDet->getFileName()); } @@ -1437,30 +1408,20 @@ string slsDetectorCommand::helpEnablefwrite(int narg, char *args[], int action){ } string slsDetectorCommand::cmdFileIndex(int narg, char *args[], int action){ - char ans[100]; - int i; + char ans[100]; + int i; - if (action==HELP_ACTION) { - return helpFileName(narg, args, action); - } - else if (action==PUT_ACTION) - if(!sscanf(args[1],"%d",&i)) - return string("cannot parse file index"); + if (action==HELP_ACTION) { + return helpFileName(narg, args, action); + } + else if (action==PUT_ACTION){ + if(!sscanf(args[1],"%d",&i)) + return string("cannot parse file index"); + myDet->setFileIndex(i); + } - if(myDet->setReceiverOnline()==ONLINE_FLAG){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("cannot connect to receiver"); - if(action==PUT_ACTION) - myDet->setReceiverFileIndex(i); - sprintf(ans,"%d", myDet->setReceiverFileIndex()); - return string(ans); - } - - if (action==PUT_ACTION) - myDet->setFileIndex(i); - - sprintf(ans,"%d", myDet->getFileIndex()); - return string(ans); + sprintf(ans,"%d", myDet->getFileIndex()); + return string(ans); } @@ -2193,23 +2154,9 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio t=SERVER_MAC; } else return ("unknown network parameter")+cmd; - if (action==PUT_ACTION){ - if(!strcmp(myDet->setNetworkParameter(t, args[1]),args[1])){ - if(t==RECEIVER_IP){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("cannot connect to receiver"); - //outdir - if(myDet->setReceiverFileDir(myDet->getFilePath()).compare(myDet->getFilePath())) - return string("could not set up receiver file outdir"); - //fname - if(myDet->setReceiverFileName(myDet->getFileName()).compare(myDet->getFileName())) - return string("could not set up receiver file name"); - //index - if(myDet->setReceiverFileIndex(myDet->getFileIndex())!=myDet->getFileIndex()) - return string("could not set up receiver file index"); - } - } - } + if (action==PUT_ACTION) + myDet->setNetworkParameter(t, args[1]); + return myDet->getNetworkParameter(t); } @@ -2313,15 +2260,11 @@ string slsDetectorCommand::cmdLock(int narg, char *args[], int action) { else if(cmd=="r_lock"){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("could not connect to receiver"); - if (action==PUT_ACTION) { - if (!sscanf(args[1],"%d",&val)) - return string("could not decode lock status")+string(args[1]); - - if(myDet->lockReceiver(val)!=val) - return string("could not lock/unlock receiver"); + if (sscanf(args[1],"%d",&val)) + myDet->lockReceiver(val); + else + return string("could not decode lock status")+string(args[1]); } sprintf(ans,"%d",myDet->lockReceiver()); } @@ -2361,18 +2304,16 @@ string slsDetectorCommand::cmdLastClient(int narg, char *args[], int action) { if (action==PUT_ACTION) return string("cannot set"); + if(cmd=="lastclient"){ myDet->setOnline(ONLINE_FLAG); - return myDet->getLastClientIP(); } - else if(cmd=="r_lastclient"){ - if(myDet->setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG) - return string("could not connect to receiver"); - + else if(cmd=="r_lastclient") return myDet->getReceiverLastClientIP(); - } + + return string("cannot decode command"); } string slsDetectorCommand::helpLastClient(int narg, char *args[], int action) { @@ -3558,37 +3499,13 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - myDet->setReceiverOnline(ONLINE_FLAG); - if(cmd=="receiver"){ if (action==PUT_ACTION) { - if(!strcasecmp(args[1],"start")){ - - if(myDet->setReceiverOnline()!=ONLINE_FLAG) - return string("cannot connect to receiver"); - - if(myDet->getReceiverStatus()==IDLE){ - //update receiver index - if(myDet->setReceiverFileIndex(myDet->getFileIndex())==-1) - return string("could not set receiver file index"); - - //to configure the server - myDet->startReceiver(); - } - } - - else if(!strcasecmp(args[1],"stop")){ - - if(myDet->stopReceiver()!=FAIL){ - //update index - myDet->setFileIndex(myDet->getFileIndex()+1); - myDet->setReceiverFileIndex(myDet->getFileIndex()); - } - else if(myDet->setReceiverOnline()!=ONLINE_FLAG) - return string("cannot connect to receiver"); - } - + if(!strcasecmp(args[1],"start")) + myDet->startReceiver(); + else if(!strcasecmp(args[1],"stop")) + myDet->stopReceiver(); else return helpReceiver(narg, args, action); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h index 589a7a474..a5e807495 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUsers.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUsers.h @@ -91,7 +91,7 @@ class slsDetectorUsers \param s file path \returns file path */ - string setFilePath(string s); + string setFilePath(string s); /** @short diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index c0ceb9cc8..d8dca164b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -422,13 +422,14 @@ int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbadtot, int *b ifstream infile; string str; - int interrupt=0; - int ich; - int chmin,chmax; + //int interrupt=0; + //int ich; + //int chmin,chmax; #ifdef VERBOSE std::cout << "Setting bad channel correction to " << fname << std::endl; #endif - int modmi=0, modma=1; + // int modmi=0; + int modma=1; int singlefile=0; string fn; @@ -615,7 +616,7 @@ int slsDetectorUtils::retrieveDetectorSetup(string const fname1, int level){ slsDetectorCommand *cmd; - char ext[100]; + // char ext[100]; int skip=0; string fname; string str; @@ -749,7 +750,7 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ - char ext[100]; + // char ext[100]; int iv=0; string fname1; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 489e2a4b2..1aee9befd 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -585,7 +585,34 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual string getReceiverLastClientIP()=0; - protected: + + /** + Sets up the file directory + @param fileName fileDir file directory + \returns file dir + */ + virtual string setFilePath(string s="")=0; + + /** + Sets up the file name + @param fileName file name + \returns file name + */ + virtual string setFileName(string s="")=0; + + /** + \returns file dir + */ + virtual string getFilePath()=0; + + /** + \returns file name + */ + virtual string getFileName()=0; + + + + protected: static const int64_t thisSoftwareVersion=0x20120124; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h index d8fe5d01a..584de2722 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/fileIO.h @@ -23,7 +23,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase { public: /** default constructor */ - fileIO(): fileIOStatic() {frameIndex=-1;detIndex=-1;}; + fileIO(): fileIOStatic(){frameIndex=-1;detIndex=-1;}; /** virtual destructor */ virtual ~fileIO(){}; @@ -39,61 +39,61 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase { \param s file path \return actual file path */ - string setFilePath(string s) {sprintf(filePath, s.c_str()); return string(filePath);}; + virtual string setFilePath(string s) {sprintf(filePath, s.c_str()); return string(filePath);}; /** sets the default output files root name \param s file name to be set \returns actual file name */ - string setFileName(string s) {sprintf(fileName, s.c_str()); return string(fileName);}; + virtual string setFileName(string s) {sprintf(fileName, s.c_str()); return string(fileName);}; /** sets the default output file index \param i start file index to be set \returns actual file index */ - int setFileIndex(int i) {*fileIndex=i; return *fileIndex;}; + virtual int setFileIndex(int i) {*fileIndex=i; return *fileIndex;}; /** sets the default output file index \param i frame index to be set \returns actual frame index */ - int setFrameIndex(int i) {frameIndex=i; return frameIndex;}; + virtual int setFrameIndex(int i) {frameIndex=i; return frameIndex;}; /** sets the default output file index \param i detector index to be set \returns actual detector index */ - int setDetectorIndex(int i) {detIndex=i; return detIndex;}; + virtual int setDetectorIndex(int i) {detIndex=i;return detIndex;}; /** \returns the output files path */ - string getFilePath() {return string(filePath);}; + virtual string getFilePath() {return string(filePath);}; /** \returns the output files root name */ - string getFileName() {return string(fileName);}; + virtual string getFileName() {return string(fileName);}; /** \returns the output file index */ - int getFileIndex() {return *fileIndex;}; + virtual int getFileIndex() {return *fileIndex;}; /** \returns the output frame index */ - int getFrameIndex() {return frameIndex;}; + virtual int getFrameIndex() {return frameIndex;}; /** \returns the detector index */ - int getDetectorIndex() {return detIndex;}; + virtual int getDetectorIndex() {return detIndex;}; string createFileName(); @@ -227,6 +227,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase { */ int readDataFile(ifstream &infile, short int *data, int offset=0); + friend class slsDetector; protected: @@ -241,6 +242,9 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase { string getCurrentReceiverFilePrefix(){return currentReceiverFilePrefix;}; + + + string currentFileName; string currentReceiverFilePrefix; @@ -251,7 +255,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase { /** file root name */ char *fileName; /** file index */ - int *fileIndex; + int *fileIndex; /** frame index */ int frameIndex; /** detector id */