From 2ceb966c731c86d4c1d813bf506a8fc6566cf48a Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 10 Dec 2009 16:25:29 +0000 Subject: [PATCH] some more changes - mianly configuration file, and dump and retrieve detector settings added + set speed function git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@8 951219d9-93cf-4727-9268-0efd64621fa3 --- .../mythenDetector/mythenDetector.cpp | 1471 ++++++++++++++--- .../mythenDetector/mythenDetector.h | 83 +- .../communication_funcs.c | 2 +- .../communication_funcs.h | 2 +- .../mythenDetectorServer/server_funcs.c | 2 +- .../mythenDetectorServer/sls_detector_defs.h | 2 +- .../slsDetector/slsDetector.cpp | 387 +++-- slsDetectorSoftware/slsDetector/slsDetector.h | 118 +- 8 files changed, 1627 insertions(+), 440 deletions(-) diff --git a/slsDetectorSoftware/mythenDetector/mythenDetector.cpp b/slsDetectorSoftware/mythenDetector/mythenDetector.cpp index 4d2deea85..bc5a2e9f8 100644 --- a/slsDetectorSoftware/mythenDetector/mythenDetector.cpp +++ b/slsDetectorSoftware/mythenDetector/mythenDetector.cpp @@ -4,6 +4,936 @@ using namespace std; + + + + + + +string mythenDetector::executeLine(int narg, char *args[], int action) { + + +#ifdef VERBOSE + for (int ia=0; ia1) + sval=string(args[1]); + else + sval="none"; + float corr[24*1280], ecorr[24*1280]; + if (getFlatFieldCorrection(corr,ecorr)) { + if (sval!="none") { + writeDataFile(sval,corr,ecorr,NULL,'i'); + return sval; + } + return string(getFlatFieldCorrectionFile()); + } else { + return string("none"); + } + } + } else if (var=="ratecorr") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval); + setRateCorrection(fval); + } + float t; + if (getRateCorrection(t)) { + sprintf(answer,"%f",t); + } else { + sprintf(answer,"%f",0); + } + return string(answer); + } else if (var=="badchannels") { + if (action==PUT_ACTION) { + sval=string(args[1]); + if (sval=="none") + sval=""; + setBadChannelCorrection(sval); + } else if (action==GET_ACTION) { + if (narg>1) + sval=string(args[1]); + else + sval="none"; + int bch[24*1280], nbch; + if ((nbch=getBadChannelCorrection(bch))) { + if (sval!="none") { + ofstream outfile; + outfile.open (sval.c_str(),ios_base::out); + if (outfile.is_open()) { + for (int ich=0; ich1) + sval=string(args[1]); + else + sval="none"; + int dir; + if (getAngularConversion(dir)) { + if (sval!="none") { + writeAngularConversion(sval.c_str()); + return sval; + } + return string(getAngularConversion()); + } else { + return string("none"); + } + } + } else if (var=="globaloff") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval); + setGlobalOffset(fval); + } + sprintf(answer,"%f",getGlobalOffset()); + return string(answer); + } else if (var=="fineoff") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval); + setFineOffset(fval); + } + sprintf(answer,"%f",getFineOffset()); + return string(answer); + } else if (var=="binsize") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval); + setBinSize(fval); + } + sprintf(answer,"%f",getBinSize()); + return string(answer); + } else if (var=="positions") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + float pos[ival]; + for (int ip=0; ip> ival; + externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG; + if (action==PUT_ACTION) { + sval=string(args[1]); +#ifdef VERBOSE + cout << "sig " << ival << " flag " << sval; +#endif + if (sval=="off") flag=SIGNAL_OFF; + else if (sval=="gate_in_active_high") flag=GATE_IN_ACTIVE_HIGH; + else if (sval=="gate_in_active_low") flag=GATE_IN_ACTIVE_LOW; + else if (sval=="trigger_in_rising_edge") flag=TRIGGER_IN_RISING_EDGE; + else if (sval=="trigger_in_falling_edge") flag=TRIGGER_IN_FALLING_EDGE; + else if (sval=="ro_trigger_in_rising_edge") flag=RO_TRIGGER_IN_RISING_EDGE; + else if (sval=="ro_trigger_in_falling_edge") flag=RO_TRIGGER_IN_FALLING_EDGE; + else if (sval=="gate_out_active_high") flag=GATE_OUT_ACTIVE_HIGH; + else if (sval=="gate_out_active_low") flag=GATE_OUT_ACTIVE_LOW; + else if (sval=="trigger_out_rising_edge") flag=TRIGGER_OUT_RISING_EDGE; + else if (sval=="trigger_out_falling_edge") flag=TRIGGER_OUT_FALLING_EDGE; + else if (sval=="ro_trigger_out_rising_edge") flag=RO_TRIGGER_OUT_RISING_EDGE; + else if (sval=="ro_trigger_out_falling_edge") flag=RO_TRIGGER_OUT_FALLING_EDGE; + setExternalSignalFlags(flag,ival); + + } + switch (setExternalSignalFlags( GET_EXTERNAL_SIGNAL_FLAG,ival)) { + case SIGNAL_OFF: + return string( "off"); + case GATE_IN_ACTIVE_HIGH: + return string( "gate_in_active_high"); + case GATE_IN_ACTIVE_LOW: + return string( "gate_in_active_low"); + case TRIGGER_IN_RISING_EDGE: + return string( "trigger_in_rising_edge"); + case TRIGGER_IN_FALLING_EDGE: + return string( "trigger_in_falling_edge"); + case RO_TRIGGER_IN_RISING_EDGE: + return string( "ro_trigger_in_rising_edge"); + case RO_TRIGGER_IN_FALLING_EDGE: + return string( "ro_trigger_in_falling_edge"); + case GATE_OUT_ACTIVE_HIGH: + return string( "gate_out_active_high"); + case GATE_OUT_ACTIVE_LOW: + return string( "gate_out_active_low"); + case TRIGGER_OUT_RISING_EDGE: + return string( "trigger_out_rising_edge"); + case TRIGGER_OUT_FALLING_EDGE: + return string( "trigger_out_falling_edge"); + case RO_TRIGGER_OUT_RISING_EDGE: + return string( "ro_trigger_out_rising_edge"); + case RO_TRIGGER_OUT_FALLING_EDGE: + return string( "ro_trigger_out_falling_edge"); + default: + return string( "unknown"); + } + } else if (var=="modulenumber") { + + if (action==PUT_ACTION) { + return string("cannot set"); + } + istringstream vvstr(var.substr(7)); + vvstr >> ival; + sprintf(answer,"%x",getId(MODULE_SERIAL_NUMBER,ival)); + return string(answer); + } else if (var=="moduleversion") { + if (action==PUT_ACTION) { + return string("cannot set" ); + } + sprintf(answer,"%x",getId(MODULE_FIRMWARE_VERSION)); + return string(answer); + } else if (var=="detectornumber") { + if (action==PUT_ACTION) { + return string("cannot set "); + } + sprintf(answer,"%x",getId(DETECTOR_SERIAL_NUMBER)); + return string(answer); + } else if (var=="detectorversion") { + if (action==PUT_ACTION) { + return string("cannot set "); + } + sprintf(answer,"%x",getId(DETECTOR_FIRMWARE_VERSION)); + return string(answer); + } else if (var=="softwareversion") { + if (action==PUT_ACTION) { + return string("cannot set "); + } + sprintf(answer,"%x",getId(DETECTOR_SOFTWARE_VERSION)); + return string(answer); + } else if (var=="digitest") { + if (action==PUT_ACTION) { + return string("cannot set "); + } + istringstream vvstr(var.substr(9)); + vvstr >> ival; + sprintf(answer,"%x",digitalTest(CHIP_TEST, ival)); + return string(answer); + } else if (var=="bustest") { + if (action==PUT_ACTION) { + return string("cannot set "); + } + sprintf(answer,"%x",digitalTest(DETECTOR_BUS_TEST)); + return string(answer); + } else if (var=="settings") { + if (action==PUT_ACTION) { + sval=string(args[1]); + detectorSettings sett=GET_SETTINGS; + if (sval=="standard") + sett=STANDARD; + else if (sval=="fast") + sett=FAST; + else if (sval=="highgain") + sett=HIGHGAIN; + setSettings(sett); + } + switch (setSettings( GET_SETTINGS)) { + case STANDARD: + return string("standard"); + case FAST: + return string("fast"); + case HIGHGAIN: + return string("highgain"); + default: + return string("undefined"); + } + } else if (var=="threshold") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setThresholdEnergy(ival); + + } + sprintf(answer,"%d",getThresholdEnergy()); + return string(answer); + } + //timers + + else if (var=="exptime") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval);// in seconds! + setTimer(ACQUISITION_TIME,fval*1E+9); + + } + + sprintf(answer,"%f",(float)setTimer(ACQUISITION_TIME)*1E-9); + return string(answer); + } else if (var=="period") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval);// in seconds! + setTimer(FRAME_PERIOD,fval*1E+9); + } + sprintf(answer,"%f",(float)setTimer(FRAME_PERIOD)*1E-9); + return string(answer); + } else if (var=="delay") { + if (action==PUT_ACTION) { + sscanf(args[1],"%f",&fval);// in seconds! + setTimer(DELAY_AFTER_TRIGGER,fval*1E+9); + } + sprintf(answer,"%f",(float)setTimer(DELAY_AFTER_TRIGGER)*1E-9); + return string(answer); + } else if (var=="gates") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setTimer( GATES_NUMBER,ival); + } + + sprintf(answer,"%d",setTimer(GATES_NUMBER)); + return string(answer); + } else if (var=="frames") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setTimer(FRAME_NUMBER,ival); + } + sprintf(answer,"%d",setTimer(FRAME_NUMBER)); + return string(answer); + } else if (var=="cycles") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setTimer(CYCLES_NUMBER,ival); + } + sprintf(answer,"%d",setTimer(CYCLES_NUMBER)); + return string(answer); + + } else if (var=="probes") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setTimer(PROBES_NUMBER,ival); + } + sprintf(answer,"%d",setTimer(PROBES_NUMBER)); + return string(answer); + } + else if (var=="dr") { + if (action==PUT_ACTION) { + sscanf(args[1],"%d",&ival); + setDynamicRange(ival); + + } + sprintf(answer,"%d",setDynamicRange()); + return string(answer); + } else if (var=="flags") { + if (action==PUT_ACTION) { + sval=string(args[1]); + readOutFlags flag=GET_READOUT_FLAGS; + if (sval=="none") + flag=NORMAL_READOUT; + else if (sval=="pumpprobe") + flag=PUMP_PROBE_MODE; + else if (sval=="storeinram") + flag=STORE_IN_RAM; + setReadOutFlags(flag); + + } + + switch (setReadOutFlags(GET_READOUT_FLAGS)) { + case NORMAL_READOUT: + return string("none"); + case STORE_IN_RAM: + return string("storeinram"); + default: + return string("unknown"); + } + } else if (var=="trimbits") { + if (narg>=2) { + cout << " writing trimfile " << endl; + int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y); + sls_detector_module *myMod=NULL; + sval=string(args[1]); + + for (int im=0; immodule=im; + setModule(*myMod); + deleteModule(myMod); + } + } + } + cout << " rturning trimfile " << endl; + return string(getTrimFile()); + } else if (var.find("trim")==0) { + if (action==GET_ACTION) { + trimMode mode=NOISE_TRIMMING; + int par1=0, par2=0; + if (var.substr(5)=="noise") { + // par1 is countlim; par2 is nsigma + mode=NOISE_TRIMMING; + par1=500; + par2=4; + } else if (var.substr(5)=="beam") { + // par1 is countlim; par2 is nsigma + mode=BEAM_TRIMMING; + par1=1000; + par2=4; + } else if (var.substr(5)=="improve") { + // par1 is maxit; if par2!=0 vthresh will be optimized + mode=IMPROVE_TRIMMING; + par1=5; + par2=0; + } else if (var.substr(5)=="fix") { + // par1 is countlim; if par2<0 then trimwithlevel else trim with median + mode=FIXEDSETTINGS_TRIMMING; + par1=1000; + par2=1; + } else if (var.substr(5)=="offline") { + mode=OFFLINE_TRIMMING; + } else { + return string("Unknown trim mode ")+var.substr(5); + } + executeTrimming(mode, par1, par2); + sval=string(args[1]); + sls_detector_module *myMod=NULL; + int nm=setNumberOfModules(GET_FLAG,X)*setNumberOfModules(GET_FLAG,Y); + for (int im=0; im> sargname; - if (!ssstr.good()) { -#ifdef VERBOSE - cout << "bad stream out" << endl; -#endif - interrupt=1; - break; - } else { - for (int iname=0; iname> sargval; - strcpy(hostname,sargval.c_str()); - break; - case 1: - ssstr>> nmx; - break; - case 2: - ssstr >> nmy; - break; - case 3: - ssstr >> dtype; - break; - case 4: - ssstr >> iargval; - cport=iargval; - break; - case 5: - ssstr >> iargval; - sport=iargval; - break; - case 6: - ssstr >> iargval; - dport=iargval; - break; - case 7: - ssstr>> sargval; - strcpy(thisDetector->trimDir,sargval.c_str()); - break; - case 8: - thisDetector->nTrimEn=0; - while (ssstr.good()) { - ssstr >> farg; - thisDetector->trimEnergies[thisDetector->nTrimEn]=farg; - thisDetector->nTrimEn++; - } - break; - case 9: - ssstr>> sargval; - strcpy(thisDetector->calDir,sargval.c_str()); - break; - case 10: - ssstr>> sargval; - strcpy(thisDetector->badChanFile,sargval.c_str()); - break; - case 11: - ssstr>> sargval; - strcpy(thisDetector->angConvFile,sargval.c_str()); - setAngularConversion(thisDetector->angConvFile); - break; - case 12: - ssstr>> iargval; - thisDetector->angDirection=iargval; - break; - case 13: - ssstr>> farg; - thisDetector->fineOffset=farg; - break; - case 14: - ssstr>> farg; - thisDetector->globalOffset=farg; -#ifdef VERBOSE - cout << "global offset is "<< farg << endl; -#endif - break; - case 15: - ssstr>> iargval; - thisDetector->clkDiv=iargval; -#ifdef VERBOSE - cout << "clock divider is "<< iargval << endl; -#endif - break; - case 16: - ssstr>> farg; - thisDetector->binSize=farg; -#ifdef VERBOSE - cout << "binsize is "<< farg << endl; -#endif - break; - default: - cout << "unknown!" << endl; - } - break; + iargval=0; + while (ssstr.good()) { + ssstr >> sargname; + if (ssstr.good()) { + strcpy(args[iargval],sargname.c_str()); + iargval++; } } - } + ans=executeLine(iargval,args,PUT_ACTION); +#ifdef VERBOSE + cout << ans << endl; +#endif } + iline++; } infile.close(); - } - else - { + } else { cout << "Error opening configuration file " << fname << " for reading" << endl; return FAIL; } - - setTCPSocket(hostname,cport,sport,dport); - setDetectorType(dtype); - setNumberOfModules(nmx,X); - setNumberOfModules(nmy,Y); #ifdef VERBOSE - cout << "Finished reading configuration file " << endl; + cout << "Read configuration file of " << iline << " lines" << endl; #endif - return OK; + return iline; }; int mythenDetector::writeConfigurationFile(string const fname){ - - string names[]={"Hostname", "NmodX", "NmodY", "Detector", "ControlPort", "StopPort", "DataPort", "TrimBitDir", "TrimBitEnergies","CalDir", "BadChanList", "AngCal", "AngDirection", "AngOffset", "ClkDiv"}; + string names[]={\ + "hostname",\ + "caldir",\ + "trimdir",\ + "trimen",\ + "outdir",\ + "nmod",\ + "badchannels",\ + "angconv",\ + "globaloff",\ + "binsize",\ + "threaded",\ + "waitstates",\ + "setlength",\ + "clkdivider"}; + int nvar=14; ofstream outfile; - char hostname[1000]=""; + int iv=0; + char *args[2]; + for (int ia=0; ia<2; ia++) { + args[ia]=new char[1000]; + } + int nargs; - outfile.open (fname.c_str(),ios_base::out); - if (outfile.is_open()) - { - while (outfile.good()) { - if (controlSocket) { - controlSocket->getHostname(hostname); - } - outfile << "Hostname " << hostname << endl; - outfile << "NModX " << setNumberOfModules(GET_FLAG, X) << endl; - outfile << "NModY " << setNumberOfModules(GET_FLAG, Y) << endl; - switch (thisDetector->myDetectorType) { - case MYTHEN: - outfile << "Detector Mythen" << endl; - break; - case PILATUS: - outfile << "Detector Pilatus" << endl; - break; - case EIGER: - outfile << "Detector EIGER" << endl; - break; - case GOTTHARD: - outfile << "Detector Gotthard" << endl; - break; - case AGIPD: - outfile << "Detector Agipd" << endl; - break; - default: - outfile << "Detector Generic" << endl; - break; - - } - if (controlSocket) - outfile << "ControlPort " << controlSocket->getPortNumber() << endl; - if (stopSocket) - outfile << "StopPort " << stopSocket->getPortNumber() << endl; - if (dataSocket) - outfile << "DataPort" << dataSocket->getPortNumber() << endl; - outfile << "TrimBitDir " << thisDetector->trimDir << endl; - outfile << "TrimBitEnergies" ; - for (int ien=0; ien< thisDetector->nTrimEn; ien++) - outfile << " " << thisDetector->trimEnergies[ien]<< endl; - outfile << endl; - outfile << "CalDir " << thisDetector->calDir << endl; - // outfile << "BadChanList " << thisDetector->badChanFile << endl; - //outfile << "AngCal " << thisDetector->angConvFile << endl; - outfile << "AngDirection " << thisDetector->angDirection << endl; - outfile << "FineOffset " << thisDetector->fineOffset<< endl; - outfile << "GlobalOffset " << thisDetector->globalOffset<< endl; - outfile << "ClkDiv " << thisDetector->clkDiv << endl; + outfile.open(fname.c_str(),ios_base::out); + if (outfile.is_open()) { + for (iv=0; iv> sargname; + if (ssstr.good()) { + strcpy(args[iargval],sargname.c_str()); + iargval++; + } + } + if (level==2) { + executeLine(iargval,args,PUT_ACTION); + } else { + if (string(args[0])==string("flatfield")) + ; + else if (string(args[0])==string("badchannels")) + ; + else if (string(args[0])==string("angconv")) + ; + else if (string(args[0])==string("trimbits")) + ; + else + executeLine(iargval,args,PUT_ACTION); + } + } + iline++; + } + infile.close(); + } else { + cout << "Error opening " << fname << " for reading" << endl; + return FAIL; + } +#ifdef VERBOSE + cout << "Read " << iline << " lines" << endl; +#endif + return iline; }; @@ -395,6 +1391,7 @@ int mythenDetector::dumpDetectorSetup(string fname){ cout << "read " << ichan*ichip << " channels" <trimFile,fname.c_str()); return myMod; } else { cout << "could not open file " << endl; @@ -737,9 +1734,10 @@ int mythenDetector::setROI(int nroi, int *xmin, int *xmax, int *ymin, int *ymax) int mythenDetector::setAngularConversion(string fname) { if (fname=="") { thisDetector->correctionMask&=~(1<< ANGULAR_CONVERSION); + //strcpy(thisDetector->angConvFile,"none"); } else { if (fname=="default") - fname=thisDetector->angConvFile; + fname=string(thisDetector->angConvFile); if (readAngularConversion(fname)>=0) { thisDetector->correctionMask|=(1<< ANGULAR_CONVERSION); strcpy(thisDetector->angConvFile,fname.c_str()); @@ -948,8 +1946,9 @@ int mythenDetector::addToMerging(float *p1, float *v1, float *e1, float *mp, fl return OK; } -void mythenDetector::acquire(){ - +void mythenDetector::acquire(int delflag){ + + int np=1; if (thisDetector->numberOfPositions>0) np=thisDetector->numberOfPositions; @@ -960,17 +1959,49 @@ void mythenDetector::acquire(){ if (thisDetector->numberOfPositions>0) { go_to_position (thisDetector->detPositions[ip]); currentPositionIndex=ip+1; +#ifdef VERBOSE + cout << "moving to position" << endl; +#endif } if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) currentI0=get_i0(); //write header before? + + if (thisDetector->threadedProcessing) + startThread(); + startAndReadAll(); //write header after? if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) currentI0=get_i0(); if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) - currentPosition=get_position(); - processData(); + currentPosition=get_position(); + if (thisDetector->threadedProcessing==0) + processData(); + + while (!dataQueue.empty()){ + ; + //#ifdef VERBOSE + //cout << "waiting for the data to be postprocessed before moving" << endl; + //#endif + } +#ifdef VERBOSE + cout << "queue empty" << endl; +#endif + if (thisDetector->threadedProcessing) { + while (pthread_cancel(dataProcessingThread)) { + ; + } +#ifdef VERBOSE + cout << "process canceled" << endl; +#endif + } + if (thisDetector->stoppedFlag) { +#ifdef VERBOSE + cout << "exiting since the detector has been stopped" << endl; +#endif + break; + } } } @@ -989,26 +2020,41 @@ void* mythenDetector::processData(int delflag) { int nb; int np; detectorData *thisData; + int outer_c_s; + int dum=1; - // while(1) { // ???????????????????????? this was needed in case of a thread....but one should take care of the position and run indexes!!!!!! +#ifdef VERBOSE + cout << " processing data - threaded mode " << thisDetector->threadedProcessing; +#endif + + //pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&outer_c_s ); + //#ifdef VERBOSE + // cout << "impossible to cancel process " << endl; + //#endif + // pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &outer_c_s); + + while(dum | thisDetector->threadedProcessing) { // ???????????????????????? - if( !dataQueue.empty() ) { + while( !dataQueue.empty() ) { + /** Pop data queue */ myData=dataQueue.front(); // get the data from the queue - dataQueue.pop(); //remove the data from the queue + //dataQueue.pop(); //remove the data from the queue if (myData) { //process data - /** decode data */ fdata=decodeData(myData); - delete [] myData; - myData=NULL; + //delete [] myData; + // myData=NULL; /** write raw data file */ writeDataFile (createFileName().append(".raw"), fdata, NULL, NULL, 'i'); - +#ifdef VERBOSE + +#endif + /** rate correction */ if (thisDetector->correctionMask&(1<nChans*thisDetector->nChips*thisDetector->nMods]; @@ -1051,7 +2097,7 @@ void* mythenDetector::processData(int delflag) { thisDetector->binSize=bs; - nb=360./bs; + nb=(360./bs); mergingBins=new float[nb]; mergingCounts=new float[nb]; @@ -1081,7 +2127,7 @@ void* mythenDetector::processData(int delflag) { delete [] mergingErrors; delete [] mergingMultiplicity; } else { - thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->fileIndex,createFileName().append(".dat"),np); + thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->fileIndex,(createFileName().append(".dat")).c_str(),np); finalDataQueue.push(thisData); } @@ -1106,20 +2152,32 @@ void* mythenDetector::processData(int delflag) { if (ang) delete [] ang; } else { - thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->fileIndex,createFileName().append(".dat")); + thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->fileIndex,(createFileName().append(".dat")).c_str()); finalDataQueue.push(thisData); } thisDetector->fileIndex++; } - + dataQueue.pop(); //remove the data from the queue + delete [] myData; + myData=NULL; } +#ifdef VERBOSE + else + cout << "could not pop data queue " << endl; +#endif + //#ifdef VERBOSE + // cout << "possible to cancel process " << endl; + //#endif + // pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &outer_c_s); + // pthread_testcancel(); } - // } // ???????????????????????? + dum=0; + } // ???????????????????????? } -/* + void mythenDetector::startThread() { pthread_attr_t tattr, mattr; int ret; @@ -1133,26 +2191,21 @@ void mythenDetector::startThread() { // set the priority; others are unchanged //newprio = 30; mparam.sched_priority = 30; + param.sched_priority = 1; // scheduling parameters of main thread ret = pthread_setschedparam(pthread_self(), policy, &mparam); - - printf("current priority is %d\n",param.sched_priority); ret = pthread_create(&dataProcessingThread, NULL,startProcessData, (void*)this); - - - param.sched_priority = 1; - // scheduling parameters of target thread - ret = pthread_setschedparam(dataProcessingThread, policy, ¶m); - + // scheduling parameters of target thread + ret = pthread_setschedparam(dataProcessingThread, policy, ¶m); } -void* startProcessData(void *n) { - //void* processData(void *n) { - void *w; - mythenDetector *myDet=(mythenDetector*)n; - myDet->processData(0); -} -*/ + void* startProcessData(void *n) { + //void* processData(void *n) { + void *w; + mythenDetector *myDet=(mythenDetector*)n; + myDet->processData(1); + + } diff --git a/slsDetectorSoftware/mythenDetector/mythenDetector.h b/slsDetectorSoftware/mythenDetector/mythenDetector.h index 0fb02c2f2..a5ca68e0d 100644 --- a/slsDetectorSoftware/mythenDetector/mythenDetector.h +++ b/slsDetectorSoftware/mythenDetector/mythenDetector.h @@ -4,6 +4,7 @@ #ifndef MYTHEN_DETECTOR_H #define MYTHEN_DETECTOR_H +#include #include "slsDetector.h" #define defaultTDead {170,90,750} @@ -22,50 +23,62 @@ using namespace std; class mythenDetector : public slsDetector{ - - + + public: -/** - (default) constructor -*/ - mythenDetector(int id=0) : slsDetector(MYTHEN, id){}; + /** + (default) constructor + */ + mythenDetector(int id=0, detectorType t=MYTHEN) : slsDetector(t, id){}; //slsDetector(string const fname); // ~slsDetector(){while(dataQueue.size()>0){}}; /** destructor */ - ~mythenDetector(){}; + ~mythenDetector(){}; + + /** + executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing + \param narg number of arguments + \param args array of string arguments + \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) + \returns answer string + */ + string executeLine(int narg, char *args[], int action=GET_ACTION); + + /** + returns the help for the executeLine command + \param os output stream to return the help to + \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) + */ + static ostream helpLine(int action=GET_ACTION); + /** + type of action performed + */ +enum {GET_ACTION, PUT_ACTION, READOUT_ACTION}; + + + /** + reads configuration file fname calling executeLine + \param fname file to be read + */ int readConfigurationFile(string const fname); /** - Every detector should have a basic configuration file containing: - type (mythen, pilatus etc.) - hostname - portnumber - communication type (default TCP/IP) - eventually secondary portnumber (e.g. mythen stop function) - number of modules installed if different from the detector size (x,y) - - to be changed + writes configuration file calling executeLine + \param fname file to write to */ int writeConfigurationFile(string const fname); - - - /* - It should be possible to dump all the settings of the detector (including trimbits, threshold energy, gating/triggering, acquisition time etc. - in a file and retrieve it for repeating the measurement with identicals ettings, if necessary - */ /** - not yet implemented - - should dump to a file all the current detector parameters + dumps all the possible detector parameters calling executeLine + \param fname file to write to + \param level 0 dumps only main parameters and filenames for flat field correction etc.; 2 dumps really the complete configuration including flat field files, badchannels files, trimbits, angular conversion etc. */ - int dumpDetectorSetup(string const fname); + int dumpDetectorSetup(string const fname, int level=0); /** - not yet implemented - - should retrieve from a file all the current detector parameters + retrieves alld possible detector parameters from file calling executeLine + \param fname file to be read */ - int retrieveDetectorSetup(string const fname); + int retrieveDetectorSetup(string const fname, int level=0); @@ -198,7 +211,7 @@ class mythenDetector : public slsDetector{ /** returns the angular conversion file */ - char *getAngularConversion() {return thisDetector->angConvFile;}; + string getAngularConversion() {if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) return string(thisDetector->angConvFile); else return string("none");}; /** set detector global offset @@ -289,8 +302,16 @@ class mythenDetector : public slsDetector{ void acquire(int delflag=1); + private: + /** + start data processing thread + */ + void startThread(); // + /** the data processing thread */ + pthread_t dataProcessingThread; }; +static void* startProcessData(void *n); #endif diff --git a/slsDetectorSoftware/mythenDetectorServer/communication_funcs.c b/slsDetectorSoftware/mythenDetectorServer/communication_funcs.c index 87a4f95d1..bbf5485ed 120000 --- a/slsDetectorSoftware/mythenDetectorServer/communication_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/communication_funcs.c @@ -1 +1 @@ -../commonFiles/communication_funcs.c \ No newline at end of file +/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorSoftware/mythenDetectorServer/communication_funcs.h b/slsDetectorSoftware/mythenDetectorServer/communication_funcs.h index f220903b2..256965d9d 120000 --- a/slsDetectorSoftware/mythenDetectorServer/communication_funcs.h +++ b/slsDetectorSoftware/mythenDetectorServer/communication_funcs.h @@ -1 +1 @@ -../commonFiles/communication_funcs.h \ No newline at end of file +/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c index 66c9c00e6..782ae98e4 100755 --- a/slsDetectorSoftware/mythenDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/mythenDetectorServer/server_funcs.c @@ -1600,7 +1600,7 @@ int get_run_status(int fnum) { printf("Getting status\n"); #endif - retval= runState();; + retval= runState(); if (ret!=OK) { printf("get status failed\n"); diff --git a/slsDetectorSoftware/mythenDetectorServer/sls_detector_defs.h b/slsDetectorSoftware/mythenDetectorServer/sls_detector_defs.h index c5062e03f..0d667c264 120000 --- a/slsDetectorSoftware/mythenDetectorServer/sls_detector_defs.h +++ b/slsDetectorSoftware/mythenDetectorServer/sls_detector_defs.h @@ -1 +1 @@ -../commonFiles/sls_detector_defs.h \ No newline at end of file +/afs/psi.ch/project/mythen/slsDetectorSoftware/commonFiles/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index d239944ad..dcabe1d3c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -28,6 +28,12 @@ int slsDetector::initSharedMemory(detectorType type, int id) { nc=10; nd=6; // dacs+adcs break; + case PICASSO: + nch=128; // complete mythen system + nm=24; + nc=10; + nd=6; // dacs+adcs + break; default: nch=65535; // one EIGER module nm=1; //modules/detector @@ -54,7 +60,7 @@ int slsDetector::initSharedMemory(detectorType type, int id) { thisDetector = (sharedSlsDetector*) shmat(shm_id, NULL, 0); /* attach */ - if ((int) thisDetector == -1) { + if (thisDetector == (void*)-1) { cout <<"*** shmat error (server) ***" << endl; return shm_id; } @@ -93,8 +99,6 @@ slsDetector::slsDetector(detectorType type, int id): badChannelMask(NULL), detectorModules(NULL) { - /** sets onlineFlag to OFFLINE_FLAG */ - onlineFlag=OFFLINE_FLAG; while (shmId<0) { /**Initlializes shared memory \sa initSharedMemory @@ -111,7 +115,6 @@ slsDetector::slsDetector(detectorType type, int id): /**Initializes the detector stucture \sa initializeDetectorSize */ initializeDetectorSize(type); - } @@ -124,6 +127,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { if (thisDetector->alreadyExisting==0) { /** set hostname to default */ strcpy(thisDetector->hostname,DEFAULT_HOSTNAME); + /** sets onlineFlag to OFFLINE_FLAG */ + thisDetector->onlineFlag=OFFLINE_FLAG; /** set ports to defaults */ thisDetector->controlPort=DEFAULT_PORTNO; thisDetector->stopPort=DEFAULT_PORTNO+1; @@ -139,7 +144,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->nAdcs=0; thisDetector->nModMax[X]=24; thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=32; + thisDetector->dynamicRange=24; break; default: thisDetector->nChans=65536; @@ -164,6 +169,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { strcpy(thisDetector->trimDir,getenv("HOME")); strcpy(thisDetector->calDir,getenv("HOME")); strcpy(thisDetector->filePath,getenv("HOME")); + /** sets trimbit file */ + strcpy(thisDetector->trimFile,"none"); /** set fileName to default to run*/ strcpy(thisDetector->fileName,"run"); /** set fileIndex to default to 0*/ @@ -177,6 +184,8 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->tDead=0; /** sets bad channel list file to none */ strcpy(thisDetector->badChanFile,"none"); + /** sets flat field correction file */ + strcpy(thisDetector->flatFieldFile,"none"); /** set number of bad chans to 0*/ thisDetector->nBadChans=0; /** set number of bad flat field chans to 0*/ @@ -195,14 +204,15 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->currentSettings=UNINITIALIZED; /** set threshold to -1*/ thisDetector->currentThresholdEV=-1; - /** set clockdivider to 1*/ - thisDetector->clkDiv=1; + // /** set clockdivider to 1*/ + // thisDetector->clkDiv=1; /** set number of positions to 0*/ thisDetector->numberOfPositions=0; /** sets angular conversion file to none */ strcpy(thisDetector->angConvFile,"none"); /** set binsize*/ thisDetector->binSize=0; + thisDetector->stoppedFlag=0; @@ -223,6 +233,10 @@ int slsDetector::initializeDetectorSize(detectorType type) { ffcoefficients=(float*)(goff+thisDetector->ffoff); fferrors=(float*)(goff+thisDetector->fferroff); detectorModules=(sls_detector_module*)(goff+ thisDetector->modoff); +#ifdef VERBOSE + for (int imod=0; imod< thisDetector->nModsMax; imod++) + cout << hex << detectorModules+imod << dec <dacoff); adcs=(float*)(goff+thisDetector->adcoff); chipregs=(int*)(goff+thisDetector->chipoff); @@ -252,7 +266,7 @@ int slsDetector::initializeDetectorStructure() { thisMod->module=imod; /** sets the size of the module to nChans, nChips etc. */ - thisMod->nchan=thisDetector->nChans; + thisMod->nchan=thisDetector->nChans*thisDetector->nChips; thisMod->nchip=thisDetector->nChips; thisMod->ndac=thisDetector->nDacs; thisMod->nadc=thisDetector->nAdcs; @@ -283,7 +297,7 @@ int slsDetector::initializeDetectorStructure() { /** initializes the channel registers to 0 */ for (int ichan=0; ichannChans*thisDetector->nChips; ichan++) { - *(chanregs+ichan+thisDetector->nChans*imod)=-1; + *(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1; } /** initialize gain and offset to -1 */ thisMod->gain=-1.; @@ -385,10 +399,28 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { myMod->chipregs=chipptr; myMod->chanregs=chanptr; +#ifdef VERBOSE + cout << "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << endl; +#endif ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(float)*(myMod->ndac)); +#ifdef VERBOSE + cout << "received dacs " << myMod->module << " of size "<< ts << endl; +#endif ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(float)*(myMod->nadc)); +#ifdef VERBOSE + cout << "received adcs " << myMod->module << " of size "<< ts << endl; +#endif ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); +#ifdef VERBOSE + cout << "received chips " << myMod->module << " of size "<< ts << endl; +#endif ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); +#ifdef VERBOSE + cout << "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips; + cout << "mod - nchans= " << myMod->nchan << " nchips= " <nchip; + + cout << "received chans " << myMod->module << " of size "<< ts << endl; +#endif #ifdef VERBOSE cout << "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << endl; #endif @@ -399,8 +431,8 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { int slsDetector::setOnline(int off) { if (off!=GET_ONLINE_FLAG) - onlineFlag=off; - return onlineFlag; + thisDetector->onlineFlag=off; + return thisDetector->onlineFlag; }; @@ -523,43 +555,20 @@ int slsDetector::setTCPSocket(string const name, int const control_port, int con cout << "Data socket connected "<< thisName << " " << thisDP << endl; #endif } - if (retval!=FAIL) - onlineFlag=ONLINE_FLAG; - else - onlineFlag=OFFLINE_FLAG; - - - /* - test control port - if (retval!=FAIL) - onlineFlag=ONLINE_FLAG; - int i=controlSocket->Connect(); - cout << "socket connection " << i<< endl; - if (i>=0) { - cout << "Could connect to socket" << endl; - getMaxNumberOfModules(X); - getMaxNumberOfModules(Y); - controlSocket->Disconnect(); - } else { - retval=FAIL; + if (retval!=FAIL) { #ifdef VERBOSE - cout << "could not connect to detector" << endl; - cout << "setting offline" << endl; + cout << "online!" << endl; #endif + thisDetector->onlineFlag=ONLINE_FLAG; + } else { + thisDetector->onlineFlag=OFFLINE_FLAG; +#ifdef VERBOSE + cout << "offline!" << endl; +#endif + } - - if (retval==FAIL) { - onlineFlag=OFFLINE_FLAG; - if (controlSocket) - delete controlSocket; - if (stopSocket) - delete stopSocket; - if (dataSocket) - delete dataSocket; - } - */ return retval; }; @@ -609,7 +618,7 @@ int slsDetector::execCommand(string cmd, string answer){ cout << endl; cout << "Sending command " << arg << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) { @@ -661,7 +670,7 @@ int slsDetector::setDetectorType(detectorType const type){ cout << endl; cout << "Setting detector type to " << arg << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -764,7 +773,7 @@ int slsDetector::setNumberOfModules(int n, dimension d){ cout << endl; cout << "Setting number of modules of dimension "<< d << " to " << n << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -830,7 +839,7 @@ int slsDetector::getMaxNumberOfModules(dimension d){ cout << endl; cout << "Getting max number of modules in dimension "<< d <onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -897,7 +906,7 @@ enum externalSignalFlag { cout << endl; cout << "Setting signal "<< signalindex << " to flag" << pol << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -918,10 +927,10 @@ enum externalSignalFlag { } #ifdef VERBOSE cout << "Signal "<< signalindex << " flag set to" << retval << endl; -#endif if (ret==FAIL) { cout << "Set signal flag failed " << endl; } +#endif return retval; }; @@ -960,7 +969,7 @@ enum externalSignalFlag { cout << endl; cout << "Setting communication to mode " << pol << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1011,7 +1020,7 @@ enum externalSignalFlag { int64_t slsDetector::getId( idMode mode, int imod){ - int64_t retval; + int64_t retval=-1; int fnum=F_GET_ID; int ret=FAIL; @@ -1021,7 +1030,7 @@ int64_t slsDetector::getId( idMode mode, int imod){ cout << endl; cout << "Getting id of "<< mode << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1081,7 +1090,7 @@ int slsDetector::digitalTest( digitalTestMode mode, int imod){ cout << endl; cout << "Getting id of "<< mode << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { @@ -1176,7 +1185,7 @@ int slsDetector::writeRegister(int addr, int val){ cout << endl; cout << "Writing to register "<< addr << " data " << val << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1222,7 +1231,7 @@ int slsDetector::readRegister(int addr){ cout << endl; cout << "Reding register "<< addr << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1281,7 +1290,7 @@ float slsDetector::setDAC(float val, dacIndex index, int imod){ cout << endl; cout << "Setting DAC "<< index << "of module " << imod << " to " << val << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1338,7 +1347,7 @@ float slsDetector::getADC(dacIndex index, int imod){ cout << endl; cout << "Getting ADC "<< index << "of module " << imod << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1430,7 +1439,7 @@ int slsDetector::setChannel(sls_detector_channel chan){ int ichi=chan.chip; int im=chan.module; - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1472,7 +1481,7 @@ int slsDetector::setChannel(sls_detector_channel chan){ arg[0]=ichan; arg[1]=ichip; arg[2]=imod; - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1564,7 +1573,7 @@ int slsDetector::setChip(sls_detector_chip chip){ - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1616,7 +1625,7 @@ int slsDetector::setChip(sls_detector_chip chip){ - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1748,7 +1757,7 @@ int slsDetector::setModule(sls_detector_module module){ - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1817,7 +1826,7 @@ sls_detector_module *slsDetector::getModule(int imod){ - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1837,25 +1846,40 @@ sls_detector_module *slsDetector::getModule(int imod){ if (ret==OK) { + + if (detectorModules) { +#ifdef VERBOSE + cout << hex << detectorModules+imod <nchan=myMod->nchan; (detectorModules+imod)->nchip=myMod->nchip; (detectorModules+imod)->ndac=myMod->ndac; (detectorModules+imod)->nadc=myMod->nadc; +#ifdef VERBOSE + cout << " before " << thisDetector->nChans << " " << thisDetector->nChips << endl << " chan " << myMod->nchan << " chip " << myMod->nchip<< endl; +#endif + thisDetector->nChips=myMod->nchip; thisDetector->nChans=myMod->nchan/myMod->nchip; + +#ifdef VERBOSE + cout << " after " << thisDetector->nChans << " " << thisDetector->nChips<< endl; +#endif + thisDetector->nDacs=myMod->ndac; thisDetector->nAdcs=myMod->nadc; - + for (int ichip=0; ichipnChips; ichip++) { if (chipregs) chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip]; + if (chanregs) { for (int i=0; inChans; i++) { chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i]; } } - } + } if (dacs) { for (int i=0; inDacs; i++) dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; @@ -1864,11 +1888,13 @@ sls_detector_module *slsDetector::getModule(int imod){ for (int i=0; inAdcs; i++) adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i]; } + (detectorModules+imod)->gain=myMod->gain; (detectorModules+imod)->offset=myMod->offset; (detectorModules+imod)->serialnumber=myMod->serialnumber; (detectorModules+imod)->reg=myMod->reg; } + } else { deleteModule(myMod); myMod=NULL; @@ -1920,7 +1946,7 @@ int slsDetector::getThresholdEnergy(int imod){ cout << "Getting threshold energy "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1931,13 +1957,14 @@ int slsDetector::getThresholdEnergy(int imod){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); cout << mess << endl; } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentThresholdEV=retval; } controlSocket->Disconnect(); } } - } - return retval; + } + return thisDetector->currentThresholdEV; }; int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings){ @@ -1949,7 +1976,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti #ifdef VERBOSE cout << "Getting threshold energy "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -1965,13 +1992,16 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti #ifdef VERBOSE cout << "Detector returned OK "<< endl; #endif - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentThresholdEV=retval; } controlSocket->Disconnect(); } } + } else { + thisDetector->currentThresholdEV=e_eV; } - return retval; + return thisDetector->currentThresholdEV; }; /* @@ -1990,7 +2020,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti #ifdef VERBOSE cout << "Getting settings "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2024,12 +2054,15 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti switch (isettings) { case STANDARD: ssettings="/standard"; + thisDetector->currentSettings=STANDARD; break; case FAST: ssettings="/fast"; + thisDetector->currentSettings=FAST; break; case HIGHGAIN: ssettings="/highgain"; + thisDetector->currentSettings=HIGHGAIN; break; default: cout << "Unknown settings!" << endl; @@ -2040,7 +2073,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti // modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; modma=thisDetector->nMod[X]*thisDetector->nMod[Y]; } - + for (im=modmi; immodule=im; @@ -2092,17 +2125,18 @@ int slsDetector::startAcquisition(){ #ifdef VERBOSE cout << "Starting acquisition "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + thisDetector->stoppedFlag=0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=OK) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - cout << "Detector returned error: " << mess << endl; - } + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=OK) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + cout << "Detector returned error: " << mess << endl; + } controlSocket->Disconnect(); - } + } } } return ret; @@ -2120,7 +2154,7 @@ int slsDetector::stopAcquisition(){ #ifdef VERBOSE cout << "Stopping acquisition "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (stopSocket) { if (stopSocket->Connect()>=0) { stopSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2133,6 +2167,7 @@ int slsDetector::stopAcquisition(){ } } } + thisDetector->stoppedFlag=1; return ret; @@ -2147,7 +2182,7 @@ int slsDetector::startReadOut(){ #ifdef VERBOSE cout << "Starting readout "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2173,7 +2208,7 @@ int slsDetector::getRunStatus(){ #ifdef VERBOSE cout << "Getting status "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2195,18 +2230,21 @@ int slsDetector::getRunStatus(){ int* slsDetector::readFrame(){ int fnum=F_READ_FRAME, n; - int* retval; + int* retval=NULL; #ifdef VERBOSE cout << "slsDetector: Reading frame "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - retval=getDataFromDetector(); - controlSocket->Disconnect(); - } + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + retval=getDataFromDetector(); + if (retval) { + dataQueue.push(retval); + controlSocket->Disconnect(); + } + } } } return retval; @@ -2218,7 +2256,7 @@ int* slsDetector::getDataFromDetector(){ int n; int* retval=new int[nel]; int ret=FAIL; - char mess[100]; + char mess[100]="Nothing"; #ifdef VERY_VERBOSE int i; #endif @@ -2229,10 +2267,15 @@ int* slsDetector::getDataFromDetector(){ controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret!=OK) { n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); -#ifndef VERBOSE - if (ret==FAIL) -#endif + if (ret==FAIL) { + thisDetector->stoppedFlag=1; cout << "Detector returned: " << mess << " " << n << endl; + } else { + ; +#ifdef VERBOSE + cout << "Detector successfully returned: " << mess << " " << n << endl; +#endif + } delete [] retval; retval=NULL; } else { @@ -2243,6 +2286,7 @@ int* slsDetector::getDataFromDetector(){ #endif if (n!=thisDetector->dataBytes) { cout << "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << endl; + thisDetector->stoppedFlag=1; ret=FAIL; delete [] retval; retval=NULL; @@ -2265,7 +2309,7 @@ int* slsDetector::readAll(){ #ifdef VERBOSE cout << "Reading all frames "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2329,7 +2373,8 @@ int slsDetector::startAndReadAllNoWait(){ #ifdef VERBOSE cout << "Starting and reading all frames "<< endl; #endif - if (onlineFlag==ONLINE_FLAG) { + thisDetector->stoppedFlag=0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2342,7 +2387,7 @@ int slsDetector::startAndReadAllNoWait(){ int* slsDetector::getDataFromDetectorNoWait() { int *retval=getDataFromDetector(); - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (retval==NULL){ controlSocket->Disconnect(); @@ -2408,32 +2453,32 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ cout << "Setting timer "<< index << " to " << t << "ns" << endl; #endif ut=t; - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - n=controlSocket->SendDataOnly(&t,sizeof(t)); -#ifdef VERBOSE - cout << "Sent "<< n << " bytes " << endl; -#endif - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=OK) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - cout << "Detector returned error: " << mess << endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - controlSocket->Disconnect(); - } + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&index,sizeof(index)); + n=controlSocket->SendDataOnly(&t,sizeof(t)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=OK) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + cout << "Detector returned error: " << mess << endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->timerValue[index]=retval; + } + controlSocket->Disconnect(); + } } + } else { + //cout << "offline " << endl; + if (t>=0) + thisDetector->timerValue[index]=t; } #ifdef VERBOSE - cout << "Timer set to "<< retval << "ns" << endl; + cout << "Timer set to "<< thisDetector->timerValue[index] << "ns" << endl; #endif - if (t>0) - thisDetector->timerValue[index]=retval; - return retval; + return thisDetector->timerValue[index]; }; @@ -2451,14 +2496,14 @@ int slsDetector::setSpeed(speedVariable sp, int value) { int fnum=F_SET_SPEED; - int retval; + int retval=-1; char mess[100]; int ret=OK; int n=0; #ifdef VERBOSE cout << "Setting speed variable"<< sp << " to " << value << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2511,7 +2556,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index){ #ifdef VERBOSE cout << "Getting timer "<< index << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2549,35 +2594,40 @@ int slsDetector::setDynamicRange(int n){ #endif if (n==24) n=32; - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&n,sizeof(n)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=OK) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - cout << "Detector returned error: " << mess << endl; + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&n,sizeof(n)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=OK) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + cout << "Detector returned error: " << mess << endl; } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + controlSocket->Disconnect(); + } } - controlSocket->Disconnect(); + } else { + if (n>0) + thisDetector->dynamicRange=n; + retval=thisDetector->dynamicRange; } - } - } - if (ret==OK) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; - if (retval==32) - thisDetector->dynamicRange=24; - else - thisDetector->dynamicRange=retval; - + if (ret==OK && retval>0) { + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; + if (retval==32) + thisDetector->dynamicRange=24; + else + thisDetector->dynamicRange=retval; + + #ifdef VERBOSE - cout << "Dynamic range set to "<< thisDetector->dynamicRange << endl; - cout << "Data bytes "<< thisDetector->dataBytes << endl; + cout << "Dynamic range set to "<< thisDetector->dynamicRange << endl; + cout << "Data bytes "<< thisDetector->dataBytes << endl; #endif - + } return thisDetector->dynamicRange; }; @@ -2614,7 +2664,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag){ cout << "Setting readout flags to "<< flag << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2630,11 +2680,15 @@ int slsDetector::setReadOutFlags(readOutFlags flag){ controlSocket->Disconnect(); } } + } else { + if (flag!=GET_READOUT_FLAGS) + thisDetector->roFlags=flag; } + #ifdef VERBOSE cout << "Readout flag set to "<< retval << endl; #endif - return retval; + return thisDetector->roFlags; }; //Trimming @@ -2663,7 +2717,7 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ cout << "Trimming module " << imod << " with mode "<< mode << " parameters " << par1 << " " << par2 << endl; #endif - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); @@ -2809,12 +2863,14 @@ int slsDetector::setFlatFieldCorrection(string fname){ cout << "disabling flat field correction" << endl; #endif thisDetector->correctionMask&=~(1<flatFieldFile,"none"); } else { #ifdef VERBOSE cout << "Setting flat field correction from file " << fname << endl; #endif nch=readDataFile(fname,data); if (nch>0) { + strcpy(thisDetector->flatFieldFile,fname.c_str()); for (int ichan=0; ichan0) { /* add to median */ @@ -2827,11 +2883,14 @@ int slsDetector::setFlatFieldCorrection(string fname){ nmed++; } else { //add the channel to the ff bad channel list - thisDetector->badFFList[thisDetector->nBadFF]=ichan; - (thisDetector->nBadFF)++; + if (thisDetector->nBadFFbadFFList[thisDetector->nBadFF]=ichan; + (thisDetector->nBadFF)++; #ifdef VERBOSE cout << "Channel " << ichan << " added to the bad channel list" << endl; #endif + } else + cout << "Too many bad channels " << endl; } } @@ -2877,9 +2936,10 @@ int slsDetector::getFlatFieldCorrection(float *corr, float *ecorr) { #endif if (corr) { for (int ichan=0; ichannMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ichan++) { - corr[ichan]=ffcoefficients[ichan]; - if (ecorr) - ecorr[ichan]=fferrors[ichan]; + corr[ichan]=(ffcoefficients[ichan]*ffcoefficients[ichan])/(fferrors[ichan]*fferrors[ichan]); + if (ecorr) { + ecorr[ichan]=ffcoefficients[ichan]/fferrors[ichan]; + } } } return 1; @@ -3042,7 +3102,8 @@ int slsDetector::setBadChannelCorrection(string fname){ thisDetector->correctionMask&=~(1<< DISCARD_BAD_CHANNELS); thisDetector->nBadChans=0; } else { - thisDetector->correctionMask|=(1<< DISCARD_BAD_CHANNELS); + if (fname=="default") + fname=string(thisDetector->badChanFile); infile.open(fname.c_str(), ios_base::in); thisDetector->nBadChans=0; while (infile.good() and interrupt==0) { @@ -3063,11 +3124,14 @@ int slsDetector::setBadChannelCorrection(string fname){ } else { ssstr.str(str); ssstr >> ich; - thisDetector->badChansList[thisDetector->nBadChans]=ich; - thisDetector->nBadChans++; + if (thisDetector->nBadChansbadChansList[thisDetector->nBadChans]=ich; + thisDetector->nBadChans++; #ifdef VERBOSE cout << thisDetector->nBadChans << " Found bad channel "<< ich << endl; #endif + } else + interrupt=1; } @@ -3077,7 +3141,10 @@ int slsDetector::setBadChannelCorrection(string fname){ } } - + if (thisDetector->nBadChans>0 && thisDetector->nBadChanscorrectionMask|=(1<< DISCARD_BAD_CHANNELS); + strcpy(thisDetector->badChanFile,fname.c_str()); + } } fillBadChannelMask(); return thisDetector->nBadChans; @@ -3092,7 +3159,7 @@ int slsDetector::getBadChannelCorrection(int *bad) { for (int ich=0; ichnBadFF; ich++) bad[ichan+ich]=thisDetector->badFFList[ich]; } - return thisDetector->nBadChans+ thisDetector->nBadFF; + return thisDetector->nBadChans+thisDetector->nBadFF; } else return 0; } @@ -3129,7 +3196,7 @@ int slsDetector::exitServer(){ int fnum=F_EXIT_SERVER; - if (onlineFlag==ONLINE_FLAG) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { if (controlSocket) { controlSocket->Connect(); controlSocket->SendDataOnly(&fnum,sizeof(fnum)); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 8cd16ce70..fa6a44ef0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -56,7 +56,7 @@ class detectorData { \param fname file name to which the data are saved \param np number of points defaults to the number of detector channels */ - detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, int f_ind=-1, char *fname="", int np=-1) : values(val), errors(err), angles(ang), fileIndex(f_ind), npoints(np){strcpy(fileName,fname);}; + detectorData(float *val=NULL, float *err=NULL, float *ang=NULL, int f_ind=-1, const char *fname="", int np=-1) : values(val), errors(err), angles(ang), fileIndex(f_ind), npoints(np){strcpy(fileName,fname);}; /** the destructor deletes also the arrays pointing to data/errors/angles if not NULL @@ -73,13 +73,6 @@ class detectorData { - - - - - - - using namespace std; /** \mainpage Common C++ library for SLS detectors data acquisition @@ -128,9 +121,9 @@ class slsDetector { /** online flags enum \sa setOnline*/ - enum {GET_ONLINE_FLAG, /**< returns wether the detector is in online or offline state */ - OFFLINE_FLAG, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */ - ONLINE_FLAG /**< detector in online state (i.e. communication to the detector updating the local structure) */ + enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */ + OFFLINE_FLAG=0, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */ + ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */ }; @@ -142,7 +135,14 @@ class slsDetector { typedef struct sharedSlsDetector { /** already existing flag. If the detector does not yet exist (alreadyExisting=0) the sharedMemory will be created, otherwise it will simly be linked */ int alreadyExisting; - + /* + /** online flag - is set if the detector is connected, unset if socket connection is not possible */ + int onlineFlag; + + + /** stopped flag - is set if an acquisition error occurs or the detector is stopped manually. Is reset to 0 at the start of the acquisition */ + int stoppedFlag; + /** is the hostname (or IP address) of the detector. needs to be set before startin the communication */ char hostname[MAX_STR_LENGTH]; /** is the port used for control functions normally it should not be changed*/ @@ -198,8 +198,12 @@ typedef struct sharedSlsDetector { /** corrections to be applied to the data \see ::correctionFlags */ int correctionMask; + /** threaded processing flag (i.e. if data are processed and written to file in a separate thread) */ + int threadedProcessing; /** dead time (in ns) for rate corrections */ float tDead; + /** file used for flat field corrections */ + char flatFieldFile[MAX_STR_LENGTH]; /** number of bad channels from bad channel list */ int nBadChans; /** file with the bad channels */ @@ -237,14 +241,16 @@ typedef struct sharedSlsDetector { readOutFlags roFlags; /* detector setup - not needed */ - /** detector settings (standard, fast, etc.) */ - detectorSettings currentSettings; - /** detector threshold (eV) */ - int currentThresholdEV; - /** timer values */ - int64_t timerValue[MAX_TIMERS]; - /** clock divider */ - int clkDiv; + /** name root of the output files */ + char trimFile[MAX_STR_LENGTH]; + /** detector settings (standard, fast, etc.) */ + detectorSettings currentSettings; + /** detector threshold (eV) */ + int currentThresholdEV; + /** timer values */ + int64_t timerValue[MAX_TIMERS]; + /** clock divider */ + //int clkDiv; /*offsets*/ /** memory offsets for the flat filed coefficients */ @@ -281,7 +287,7 @@ typedef struct sharedSlsDetector { /** sets the onlineFlag \param off can be:
GET_ONLINE_FLAG, returns wether the detector is in online or offline state;
OFFLINE_FLAG, detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!);
ONLINE_FLAG detector in online state (i.e. communication to the detector updating the local structure) */ - int setOnline(int const online); + int setOnline(int const online=GET_ONLINE_FLAG); /** sets the onlineFlag \returns 1 if the detector structure has already be initlialized, 0 otherwise */ int exists() {return thisDetector->alreadyExisting;}; @@ -311,13 +317,13 @@ typedef struct sharedSlsDetector { Should be implemented in the specific detector class /sa mythenDetector::dumpDetectorSetup */ - virtual int dumpDetectorSetup(string const fname)=0; + virtual int dumpDetectorSetup(string const fname, int level)=0; /** Purely virtual function Should be implemented in the specific detector class /sa mythenDetector::retrieveDetectorSetup */ - virtual int retrieveDetectorSetup(string const fname)=0; + virtual int retrieveDetectorSetup(string const fname, int level)=0; /** configure the socket communication and initializes the socket instances @@ -350,9 +356,21 @@ typedef struct sharedSlsDetector { \param point to the array that will contain the trim energies (in ev) \returns number of trim energies + unused! + \sa sharedSlsDetector */ int getTrimEn(int *en=NULL) {if (en) {for (int ien=0; iennTrimEn; ien++) en[ien]=thisDetector->trimEnergies[ien];} return (thisDetector->nTrimEn);}; + /** sets the number of trim energies and their value \sa sharedSlsDetector + \param nen number of energies + \param en array of energies + \returns number of trim energies + + unused! + + \sa sharedSlsDetector + */ + int setTrimEn(int nen, int *en=NULL) {if (en) {for (int ien=0; ientrimEnergies[ien]=en[ien]; thisDetector->nTrimEn=nen;} return (thisDetector->nTrimEn);}; /** Pure virtual function @@ -376,6 +394,19 @@ typedef struct sharedSlsDetector { */ virtual int writeTrimFile(string fname, sls_detector_module mod)=0; + /** + returns currently the loaded trimfile name + */ + + const char *getTrimFile(){\ + string s(thisDetector->trimFile); \ + if (s.length()>6) {\ + if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) \ + return s.substr(0,s.length()-6).c_str(); \ + } \ + return thisDetector->trimFile;\ + }; + /** Pure virtual function writes a trim file for module number imod - the values will be read from the current detector structure @@ -491,7 +522,7 @@ typedef struct sharedSlsDetector { returns the location of the calibration files \sa sharedSlsDetector */ - char* getCalDir() {cout << "cal dir is " << thisDetector->calDir; return thisDetector->calDir;}; + char* getCalDir() {return thisDetector->calDir;}; /** @@ -867,7 +898,7 @@ typedef struct sharedSlsDetector { /** start detector acquisition and read all data putting them a data queue - \returns pointer to the fron tof the data queue + \returns pointer to the front of the data queue \sa startAndReadAllNoWait getDataFromDetector dataQueue */ int* startAndReadAll(); @@ -886,8 +917,8 @@ typedef struct sharedSlsDetector { int* getDataFromDetectorNoWait(); /** - asks and receives a data frame from the detector - \returns pointer to the data or NULL. If NULL disconnects the socket + asks and receives a data frame from the detector and puts it in the data queue + \returns pointer to the data or NULL. \sa getDataFromDetector */ int* readFrame(); @@ -975,7 +1006,16 @@ typedef struct sharedSlsDetector { int executeTrimming(trimMode mode, int par1, int par2, int imod=-1); - //Corrections + //Corrections + + /** + set/get if the data processing and file writing should be done by a separate thread +s + \param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get + \returns thread flag + */ + + int setThreadedProcessing(int b=-1) {if (b>=0) thisDetector->threadedProcessing=b; return thisDetector->threadedProcessing;} /** set flat field corrections @@ -992,6 +1032,12 @@ typedef struct sharedSlsDetector { */ int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL); + /** + get flat field corrections file name + \returns flat field correction file name + */ + char *getFlatFieldCorrectionFile(){return thisDetector->flatFieldFile;}; + /** set rate correction \param t dead time in ns - if 0 disable correction, if >0 set dead time to t, if <0 set deadtime to default dead time for current settings @@ -1028,7 +1074,7 @@ typedef struct sharedSlsDetector { int getBadChannelCorrection(int *bad=NULL); /** returns the bad channel list file */ - char *getBadChannelCorrectionFile() {return thisDetector->badChanFile;}; + string getBadChannelCorrectionFile() {if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) return string(thisDetector->badChanFile); else return string("none");}; /** @@ -1055,7 +1101,7 @@ typedef struct sharedSlsDetector { pure virtual function returns the angular conversion file \sa mythenDetector::getAngularConversion */ - virtual char *getAngularConversion()=0; + virtual string getAngularConversion()=0; /** pure virtual function @@ -1259,10 +1305,10 @@ typedef struct sharedSlsDetector { */ sharedSlsDetector *thisDetector; - /** - \sa setOnline - */ - int onlineFlag; + // /** + // \sa setOnline + // */ + //int onlineFlag; /** detector ID @@ -1405,9 +1451,9 @@ typedef struct sharedSlsDetector { int receiveModule(sls_detector_module*); /** - start data processing threas + start data processing thread */ - void startThread(); + //void startThread(); /** fill bad channel mask (0 if channel is good, 1 if bad)