diff --git a/slsDetectorSoftware/mythenDetector/mythenDetector.cpp b/slsDetectorSoftware/mythenDetector/mythenDetector.cpp index 64fe9acfe..a6842780c 100644 --- a/slsDetectorSoftware/mythenDetector/mythenDetector.cpp +++ b/slsDetectorSoftware/mythenDetector/mythenDetector.cpp @@ -330,11 +330,12 @@ string mythenDetector::executeLine(int narg, char *args[], int action) { } else if (var=="trimen") { if (action==PUT_ACTION) { sscanf(args[1],"%d",&ival); - std::cout<< ival << std::endl ; + //std::cout<< ival << std::endl ; + if (ival>narg-2) + ival=narg-2; int ene[ival]; for (int ie=0; ienarg-2) + ival=narg-2; + float ene[ival]; + for (int ie=0; ienarg-2) + ival=narg-2; + float ene[ival]; + for (int ie=0; ietrimFile,fname.c_str()); return myMod; } else { - std::cout<< "could not open file " << myfname<< std::endl; + std::cout<< "could not open trim file " << myfname << std::endl; if (nflag) deleteModule(myMod); return NULL; @@ -1921,9 +2256,17 @@ int mythenDetector::setAngularConversion(string fname) { if (fname=="") { thisDetector->correctionMask&=~(1<< ANGULAR_CONVERSION); //strcpy(thisDetector->angConvFile,"none"); + //#ifdef VERBOSE + std::cout << "Unsetting angular conversion" << std::endl; + //#endif } else { - if (fname=="default") + if (fname=="default") { fname=string(thisDetector->angConvFile); + } + + //#ifdef VERBOSE + std::cout << "Setting angular conversion to" << fname << std:: endl; + //#endif if (readAngularConversion(fname)>=0) { thisDetector->correctionMask|=(1<< ANGULAR_CONVERSION); strcpy(thisDetector->angConvFile,fname.c_str()); @@ -1932,6 +2275,12 @@ int mythenDetector::setAngularConversion(string fname) { return thisDetector->correctionMask&(1<< ANGULAR_CONVERSION); } + + + + + + int mythenDetector::getAngularConversion(int &direction, angleConversionConstant *angconv) { direction=thisDetector->angDirection; if (angconv) { @@ -2064,7 +2413,6 @@ int mythenDetector::addToMerging(float *p1, float *v1, float *e1, float *mp, fl int ibin=0; int imod; float ang=0; - if (thisDetector->binSize>0) binsize=thisDetector->binSize; else @@ -2133,10 +2481,19 @@ int mythenDetector::addToMerging(float *p1, float *v1, float *e1, float *mp, fl void mythenDetector::acquire(int delflag){ void *status; -#ifdef VERBOSE - int iloop=0; -#endif + //#ifdef VERBOSE + //int iloop=0; + //#endif + int trimbit; + int startindex=thisDetector->fileIndex; + int lastindex=startindex; + char cmd[MAX_STR_LENGTH]; + //string sett; + thisDetector->progressIndex=0; + thisDetector->stoppedFlag=0; + + resetFinalDataQueue(); resetDataQueue(); @@ -2144,6 +2501,11 @@ void mythenDetector::acquire(int delflag){ jointhread=0; queuesize=0; + + + + + if (thisDetector->threadedProcessing) { startThread(delflag); } @@ -2152,75 +2514,269 @@ void mythenDetector::acquire(int delflag){ if (thisDetector->numberOfPositions>0) np=thisDetector->numberOfPositions; - currentPositionIndex=0; + int ns0=1; + if (thisDetector->actionMask & (1 << MAX_ACTIONS)) { + ns0=thisDetector->nScanSteps[0]; + } + if (ns0<1) + ns0=1; - for (int ip=0; ipnumberOfPositions>0) { - go_to_position (thisDetector->detPositions[ip]); - currentPositionIndex=ip+1; + + int ns1=1; + if (thisDetector->actionMask & (1 << (MAX_ACTIONS+1))) { + ns1=thisDetector->nScanSteps[1]; + } + if (ns1<1) + ns1=1; + + + + + + //action at start + if (thisDetector->stoppedFlag==0) { + if (thisDetector->actionMask & (1 << startScript)) { + //"Custom start script. The arguments are passed as nrun=n par=p."); + sprintf(cmd,"%s nrun=%d par=%s",thisDetector->actionScript[startScript],thisDetector->fileIndex,thisDetector->actionParameter[startScript]); #ifdef VERBOSE - std::cout<< "moving to position" << std::endl; + cout << "Executing start script " << cmd << endl; #endif - } - if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) - currentI0=get_i0(); - //write header before? + system(cmd); + } + } - startAndReadAll(); + for (int is0=0; is0correctionMask&(1<< I0_NORMALIZATION)) - currentI0=get_i0(); - if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) - currentPosition=get_position(); - + if (thisDetector->stoppedFlag==0) { - if (thisDetector->threadedProcessing==0) - processData(delflag); - -#ifdef ACQVERBOSE - std::cout<< "--------------------------------------------------waiting to empty raw data queue " << queuesize << std::endl ; + currentScanVariable[0]=thisDetector->scanSteps[0][is0]; + + switch(thisDetector->scanMode[0]) { + case 1: + setThresholdEnergy((int)currentScanVariable[0]); //energy scan + break; + case 2: + setDAC(currentScanVariable[0],THRESHOLD); // threshold scan + break; + case 3: + trimbit=(int)currentScanVariable[0]; + setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan + break; + case 0: + currentScanVariable[0]=0; + break; + default: + //Custom scan script level 0. The arguments are passed as nrun=n fn=filename var=v par=p" + sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",thisDetector->scanScript[0],thisDetector->fileIndex,createFileName().c_str(),currentScanVariable[0],thisDetector->scanParameter[0]); +#ifdef VERBOSE + cout << "Executing scan script 0 " << cmd << endl; #endif - //while (!dataQueue.empty()){ - while (queuesize){ - usleep(100); -// #ifdef VERBOSE -// if (iloop%10000==0) -// std::cout<< "--------------------------------------------------looping raw data queue " << queuesize << std::endl ; -// // //std::cout<< "--------------------------------------------------looping raw data queue " << dataQueue.size() << std::endl ; -// iloop++; -// //usleep(100000); -// #endif + system(cmd); + + } + } else + break; + + + for (int is1=0; is1stoppedFlag==0) { + + currentScanVariable[1]=thisDetector->scanSteps[1][is1]; + + switch(thisDetector->scanMode[1]) { + case 1: + setThresholdEnergy((int)currentScanVariable[1]); //energy scan + break; + case 2: + setDAC(currentScanVariable[1],THRESHOLD); // threshold scan + break; + case 3: + trimbit=(int)currentScanVariable[1]; + setChannel((trimbit<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan + break; + case 0: + currentScanVariable[1]=0; + break; + default: + //Custom scan script level 1. The arguments are passed as nrun=n fn=filename var=v par=p" + sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",thisDetector->scanScript[1],thisDetector->fileIndex,createFileName().c_str(),currentScanVariable[1],thisDetector->scanParameter[1]); +#ifdef VERBOSE + cout << "Executing scan script 1 " << cmd << endl; +#endif + system(cmd); + } + + } else + break; + + if (thisDetector->stoppedFlag==0) { + if (thisDetector->actionMask & (1 << scriptBefore)) { + //Custom script before each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",thisDetector->actionScript[scriptBefore],thisDetector->fileIndex,createFileName().c_str(),thisDetector->actionParameter[scriptBefore],currentScanVariable[0],currentScanVariable[1],thisDetector->scanParameter[0],thisDetector->scanParameter[1]); +#ifdef VERBOSE + cout << "Executing script before " << cmd << endl; +#endif + system(cmd); + } + } else + break; + + currentPositionIndex=0; + + for (int ip=0; ipstoppedFlag==0) { + if (thisDetector->numberOfPositions>0) { + go_to_position (thisDetector->detPositions[ip]); + currentPositionIndex=ip+1; +#ifdef VERBOSE + std::cout<< "moving to position" << std::endl; +#endif + } + } else + break; + + //write header before? + //cmd=headerBeforeScript; + //Custom script to write the header. \n The arguments will be passed as nrun=n fn=filenam acqtime=t gainmode=g threshold=thr badfile=badf angfile=angf bloffset=blo fineoffset=fo fffile=fffn tau=deadtau par=p") + + if (thisDetector->stoppedFlag==0) { + if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) + currentI0=get_i0(); + if (thisDetector->actionMask & (1 << headerBefore)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s",thisDetector->actionScript[headerBefore],thisDetector->fileIndex,createFileName().c_str(),((float)thisDetector->timerValue[ACQUISITION_TIME])*1E-9, thisDetector->currentSettings, thisDetector->currentThresholdEV, getBadChannelCorrectionFile().c_str(), getAngularConversion().c_str(), thisDetector->globalOffset, thisDetector->fineOffset,getFlatFieldCorrectionDir(),getFlatFieldCorrectionFile(), getRateCorrectionTau(), thisDetector->actionParameter[headerBefore]); +#ifdef VERBOSE + cout << "Executing header after " << cmd << endl; +#endif + system(cmd); + } + } else + break; + + + + if (thisDetector->stoppedFlag==0) { + startAndReadAll(); + + if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) + currentPosition=get_position(); + + if (thisDetector->correctionMask&(1<< I0_NORMALIZATION)) + currentI0=get_i0()-currentI0; + + + if (thisDetector->threadedProcessing==0) + processData(delflag); + + + } else + break; + + //while (!dataQueue.empty()){ + while (queuesize){ + usleep(100); + } -#ifdef ACQVERBOSE - std::cout<< "----------------------------------------------------raw data queue is empty!" << std::endl ; + + if (thisDetector->fileIndex>lastindex) + lastindex=thisDetector->fileIndex; + + if (thisDetector->stoppedFlag==0) { + if (thisDetector->actionMask & (1 << headerAfter)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s acqtime=%f gainmode=%d threshold=%d badfile=%s angfile=%s bloffset=%f fineoffset=%f fffile=%s/%s tau=%f par=%s", \ + thisDetector->actionScript[headerAfter], \ + thisDetector->fileIndex,\ + createFileName().c_str(), \ + ((float)thisDetector->timerValue[ACQUISITION_TIME])*1E-9, \ + thisDetector->currentSettings, \ + thisDetector->currentThresholdEV, \ + getBadChannelCorrectionFile().c_str(), \ + getAngularConversion().c_str(), \ + thisDetector->globalOffset, \ + thisDetector->fineOffset, \ + getFlatFieldCorrectionDir(), \ + getFlatFieldCorrectionFile(), \ + getRateCorrectionTau(), \ + thisDetector->actionParameter[headerAfter]); +#ifdef VERBOSE + cout << "Executing header after " << cmd << endl; #endif + system(cmd); + } + } else + break; + + + if (thisDetector->stoppedFlag) { #ifdef VERBOSE std::cout<< "exiting since the detector has been stopped" << std::endl; #endif break; - } else if (ip<(np-1)) - thisDetector->fileIndex=thisDetector->fileIndex-thisDetector->timerValue[FRAME_NUMBER]; -#ifdef VERBOSE - cout << "------------------------------------------------------Setting file index to " << thisDetector->fileIndex << endl; -#endif - } + } else if (ip<(np-1)) { + thisDetector->fileIndex=startindex; + } + } // loop on position finished -#ifdef ACQVERBOSE - std::cout<< "------------------------------------------------------cancelling data processing thread " << std::endl ; + //script after + if (thisDetector->stoppedFlag==0) { + if (thisDetector->actionMask & (1 << scriptAfter)) { + //Custom script after each frame. The arguments are passed as nrun=n fn=filename par=p sv0=scanvar0 sv1=scanvar1 p0=par0 p1=par1" + sprintf(cmd,"%s nrun=%d fn=%s par=%s sv0=%f sv1=%f p0=%s p1=%s",thisDetector->actionScript[scriptAfter],thisDetector->fileIndex,createFileName().c_str(),thisDetector->actionParameter[scriptAfter],currentScanVariable[0],currentScanVariable[1],thisDetector->scanParameter[0],thisDetector->scanParameter[1]); +#ifdef VERBOSE + cout << "Executing script after " << cmd << endl; #endif + system(cmd); + } + } else + break; + + + if (thisDetector->stoppedFlag) { +#ifdef VERBOSE + std::cout<< "exiting since the detector has been stopped" << std::endl; +#endif + break; + } else if (is1<(ns1-1)) { + thisDetector->fileIndex=startindex; + } + + + } + + //end scan1 loop is1 + //currentScanVariable[MAX_SCAN_LEVELS]; + + + if (thisDetector->stoppedFlag) { +#ifdef VERBOSE + std::cout<< "exiting since the detector has been stopped" << std::endl; +#endif + break; + } else if (is0<(ns0-1)) { + thisDetector->fileIndex=startindex; + } + } //end scan0 loop is0 + + thisDetector->fileIndex=lastindex; + if (thisDetector->stoppedFlag==0) { + if (thisDetector->actionMask & (1 << stopScript)) { + //Custom stop script. The arguments are passed as nrun=n par=p. + sprintf(cmd,"%s nrun=%d par=%s",thisDetector->actionScript[stopScript],thisDetector->fileIndex,thisDetector->actionParameter[stopScript]); +#ifdef VERBOSE + cout << "Executing stop script " << cmd << endl; +#endif + system(cmd); + } + } + + if (thisDetector->threadedProcessing) { jointhread=1; pthread_join(dataProcessingThread, &status); - - /* while (pthread_cancel(dataProcessingThread)) { - ; -}*/ -#ifdef ACQVERBOSE - std::cout<< "----------------------------------------------------process canceled" << std::endl; -#endif } } @@ -2240,21 +2796,11 @@ void* mythenDetector::processData(int delflag) { int np; detectorData *thisData; int dum=1; - // thisDetector->progressIndex=0; - -#ifdef VERBOSE - int iloop=0; -#endif #ifdef ACQVERBOSE std::cout<< " processing data - threaded mode " << thisDetector->threadedProcessing; #endif - //pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&outer_c_s ); - //#ifdef VERBOSE - // std::cout<< "impossible to cancel process " << std::endl; - //#endif - // pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &outer_c_s); while(dum | thisDetector->threadedProcessing) { // ???????????????????????? @@ -2264,29 +2810,20 @@ void* mythenDetector::processData(int delflag) { /** Pop data queue */ myData=dataQueue.front(); // get 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; /** write raw data file */ if (thisDetector->correctionMask==0 && delflag==1) { -#ifdef ACQVERBOSE - std::cout<< "------------------------------------no processing "<< delflag <correctionMask!=0 || delflag==0) { writing raw data file " << createFileName() <<" " << thisDetector->correctionMask<< " " << delflag << endl; -#endif + /** rate correction */ if (thisDetector->correctionMask&(1<nChans*thisDetector->nChips*thisDetector->nMods]; @@ -2314,11 +2851,7 @@ void* mythenDetector::processData(int delflag) { } if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) { - - /** angular conversion */ - /** data merging */ - // if (thisDetector->numberOfPositions) { - + if (currentPositionIndex<=1) { if (thisDetector->binSize>0) bs=thisDetector->binSize; @@ -2347,27 +2880,13 @@ void* mythenDetector::processData(int delflag) { } if (thisDetector->correctionMask!=0) -#ifdef VERBOSE - std::cout << "********************** writing dat data file if (thisDetector->correctionMask!=0) { " << createFileName() <<" " << thisDetector->correctionMask << endl; -#endif writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr,ang); - - addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - - - - if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0)) { - np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity); - /** file writing */ currentPositionIndex++; if (thisDetector->correctionMask!=0) -#ifdef VERBOSE - std::cout << "********************** writing dat data file if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0))" << createFileName() << endl; -#endif writeDataFile (createFileName().append(".dat"),mergingCounts, mergingErrors, mergingBins,'f',np); if (delflag) { delete [] mergingBins; @@ -2381,9 +2900,6 @@ void* mythenDetector::processData(int delflag) { thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),np); finalDataQueue.push(thisData); -#ifdef ACQVERBOSE - std::cout<< "------------------------------------pushing final data queue " << finalDataQueue.size() << " " << createFileName() << std::endl; -#endif } } @@ -2393,13 +2909,9 @@ void* mythenDetector::processData(int delflag) { delete [] ffcerr; if (ang) delete [] ang; - //} } else { if (thisDetector->correctionMask!=0) { writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr); -#ifdef VERBOSE - std::cout << "********************** if (thisDetector->correctionMask!=0) writing dat data file " << createFileName() << endl; -#endif } if (delflag) { if (ffcdata) @@ -2411,58 +2923,26 @@ void* mythenDetector::processData(int delflag) { } else { if (thisDetector->correctionMask!=0) { thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); - } else { + } else { thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods); } finalDataQueue.push(thisData); -#ifdef VERBOSE - std::cout<< "------------------------------------pushing final data queue with " << createFileName() << " " <fileIndex++; -#ifdef VERBOSE - cout << "setting file index to "<< thisDetector->fileIndex << endl; -#endif thisDetector->progressIndex++; -#ifdef ACQVERBOSE - std::cout<< "------------------------------------raw data queueto be popped " << dataQueue.size() << " empty " << !dataQueue.empty() << std::endl; -#endif delete [] myData; myData=NULL; dataQueue.pop(); //remove the data from the queue queuesize=dataQueue.size(); -#ifdef ACQVERBOSE - std::cout<< "------------------------------------raw data queue popped " << dataQueue.size() << " var " << queuesize << std::endl; -#endif } -#ifdef ACQVERBOSE - else - std::cout<< "could not pop data queue " << std::endl; -#endif - //#ifdef VERBOSE - // std::cout<< "possible to cancel process " << std::endl; - //#endif - // pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &outer_c_s); - // pthread_testcancel(); } - -// #ifdef VERBOSE -// if (iloop%10000==0) -// std::cout<< "------------------------------------process idle " << dataQueue.size() << " empty " << !dataQueue.empty() << std::endl; -// iloop++; -// #endif - - - if (jointhread) { -#ifdef VERBOSE - std::cout<< "acquisition finished " << dataQueue.size() << " empty " << !dataQueue.empty() << "final data queue size: " << finalDataQueue.size() <binSize=0; thisDetector->stoppedFlag=0; + thisDetector->actionMask=0; + + + for (int ia=0; iaactionMode[ia]=0; + strcpy(thisDetector->actionScript[ia],"none"); + strcpy(thisDetector->actionParameter[ia],"none"); + } + + + for (int iscan=0; iscanscanMode[iscan]=0; + strcpy(thisDetector->scanScript[iscan],"none"); + strcpy(thisDetector->scanParameter[iscan],"none"); + thisDetector->nScanSteps[iscan]=0; + thisDetector->scanPrecision[iscan]=0; + } + + + + + + /** calculates the memory offsets for flat field coefficients and errors, module structures, dacs, adcs, chips and channels */ @@ -627,11 +651,27 @@ string slsDetector::createFileName() { /*directory name +root file name */ osfn << thisDetector->filePath << "/" << thisDetector->fileName; + // scan level 0 + if (thisDetector->actionMask & (1 << (MAX_ACTIONS))) + osfn << "_S" << fixed << setprecision(thisDetector->scanPrecision[0]) << currentScanVariable[0]; + + //scan level 1 + if (thisDetector->actionMask & (1 << (MAX_ACTIONS+1))) + osfn << "_s" << fixed << setprecision(thisDetector->scanPrecision[1]) << currentScanVariable[1]; + + + //position if (currentPositionIndex>0 && currentPositionIndex<=thisDetector->numberOfPositions) osfn << "_p" << currentPositionIndex; + // file index osfn << "_" << thisDetector->fileIndex; + +#ifdef VERBOSE + cout << "created file name " << osfn.str() << endl; +#endif + return osfn.str(); } @@ -3094,11 +3134,11 @@ int slsDetector::setFlatFieldCorrection(string fname){ fillBadChannelMask(); } else { - std::cout<< "Flat field data from file " << fname << " are not valid " << std::endl; + std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl; return -1; } } else { - std::cout<< "Flat field from file " << fname << " is not valid " << std::endl; + std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl; return -1; } } @@ -3216,6 +3256,27 @@ int slsDetector::getRateCorrection(float &t){ return 0; }; +float slsDetector::getRateCorrectionTau(){ + + if (thisDetector->correctionMask&(1<tDead << std::endl; +#endif + return thisDetector->tDead; + //return 1; + } else +#ifdef VERBOSE + std::cout<< "Rate correction is disabled " << std::endl; +#endif + return 0; +}; + + + + + + + int slsDetector::getRateCorrection(){ if (thisDetector->correctionMask&(1<0 otherwise + */ +int slsDetector::setAction(int iaction, string fname, string par) { + + if (iaction>=0 && iactionactionMode[iaction]=0; + } else if (fname=="none") { + thisDetector->actionMode[iaction]=0; + strcpy(thisDetector->actionScript[iaction],fname.c_str()); + } else { + strcpy(thisDetector->actionScript[iaction],fname.c_str()); + thisDetector->actionMode[iaction]=1; + } + + if (par!="") { + strcpy(thisDetector->actionParameter[iaction],par.c_str()); + } + + if (thisDetector->actionMode[iaction]) { + +#ifdef VERBOSE + cout << iaction << " " << hex << (1 << iaction) << " " << thisDetector->actionMask << dec; +#endif + + thisDetector->actionMask |= (1 << iaction); + +#ifdef VERBOSE + cout << " set " << hex << thisDetector->actionMask << dec << endl; +#endif + + } else { +#ifdef VERBOSE + cout << iaction << " " << hex << thisDetector->actionMask << dec; +#endif + + thisDetector->actionMask &= ~(1 << iaction); + +#ifdef VERBOSE + cout << " unset " << hex << thisDetector->actionMask << dec << endl; +#endif + } +#ifdef VERBOSE + cout << iaction << " Action mask set to " << hex << thisDetector->actionMask << dec << endl; +#endif + + return thisDetector->actionMode[iaction]; + } else + return -1; +} + + +int slsDetector::setActionScript(int iaction, string fname) { +#ifdef VERBOSE + +#endif + return setAction(iaction,fname,""); +} + + + +int slsDetector::setActionParameter(int iaction, string par) { + if (iaction>=0 && iactionactionParameter[iaction],par.c_str()); + } + + if (thisDetector->actionMode[iaction]) { + thisDetector->actionMask |= (1 << iaction); + } else { + thisDetector->actionMask &= ~(1 << iaction); + } + + return thisDetector->actionMode[iaction]; + } else + return -1; +} + + /** + returns action script + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action script + */ +string slsDetector::getActionScript(int iaction){ + if (iaction>=0 && iactionactionScript[iaction]); + else + return string("wrong index"); +}; + + /** + returns action parameter + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action parameter + */ +string slsDetector::getActionParameter(int iaction){ + if (iaction>=0 && iactionactionParameter[iaction]); + else + return string("wrong index"); +} + + /** + returns action mode + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action mode + */ +int slsDetector::getActionMode(int iaction){ + if (iaction>=0 && iactionactionMode[iaction] << endl; +#endif + return thisDetector->actionMode[iaction]; + } else { +#ifdef VERBOSE + cout << "slsDetetctor : wrong action index " << iaction << endl; +#endif + return -1; + } +} + + + /** + set scan + \param index of the scan (0,1) + \param fname for script ("" disable) + \returns 0 if scan disabled, >0 otherwise + */ +int slsDetector::setScan(int iscan, string script, int nvalues, float *values, string par, int precision) { + if (iscan>=0 && iscanscanMode[iscan]=0; + } else { + strcpy(thisDetector->scanScript[iscan],script.c_str()); + if (script=="none") { + thisDetector->scanMode[iscan]=0; + } else if (script=="energy") { + thisDetector->scanMode[iscan]=1; + } else if (script=="threshold") { + thisDetector->scanMode[iscan]=2; + } else if (script=="trimbits") { + thisDetector->scanMode[iscan]=3; + } else { + thisDetector->scanMode[iscan]=4; + } + } + + + + + + + if (par!="") + strcpy(thisDetector->scanParameter[iscan],par.c_str()); + + if (nvalues>=0) { + if (nvalues==0) + thisDetector->scanMode[iscan]=0; + else { + thisDetector->nScanSteps[iscan]=nvalues; + if (nvalues>MAX_SCAN_STEPS) + thisDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; + } + } + + if (values) { + for (int iv=0; ivnScanSteps[iscan]; iv++) { + thisDetector->scanSteps[iscan][iv]=values[iv]; + } + } + if (precision>=0) + thisDetector->scanPrecision[iscan]=precision; + + if (thisDetector->scanMode[iscan]>0){ + thisDetector->actionMask |= 1 >> (iscan+MAX_ACTIONS); + } else { + thisDetector->actionMask &= ~(1 >> (iscan+MAX_ACTIONS)); + } + + + return thisDetector->scanMode[iscan]; + } else + return -1; + +} + +int slsDetector::setScanScript(int iscan, string script) { + if (iscan>=0 && iscanscanMode[iscan]=0; + } else { + strcpy(thisDetector->scanScript[iscan],script.c_str()); + if (script=="none") { + thisDetector->scanMode[iscan]=0; + } else if (script=="energy") { + thisDetector->scanMode[iscan]=1; + } else if (script=="threshold") { + thisDetector->scanMode[iscan]=2; + } else if (script=="trimbits") { + thisDetector->scanMode[iscan]=3; + } else { + thisDetector->scanMode[iscan]=4; + } + } + + if (thisDetector->scanMode[iscan]>0){ + thisDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); + } else { + thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + + + return thisDetector->scanMode[iscan]; + + + } else + return -1; + +} + + + +int slsDetector::setScanParameter(int iscan, string par) { + + + if (iscan>=0 && iscanscanParameter[iscan],par.c_str()); + return thisDetector->scanMode[iscan]; + } else + return -1; + +} + + +int slsDetector::setScanPrecision(int iscan, int precision) { + if (iscan>=0 && iscan=0) + thisDetector->scanPrecision[iscan]=precision; + return thisDetector->scanMode[iscan]; + } else + return -1; + +} + +int slsDetector::setScanSteps(int iscan, int nvalues, float *values) { + + if (iscan>=0 && iscan=0) { + if (nvalues==0) + thisDetector->scanMode[iscan]=0; + else { + thisDetector->nScanSteps[iscan]=nvalues; + if (nvalues>MAX_SCAN_STEPS) + thisDetector->nScanSteps[iscan]=MAX_SCAN_STEPS; + } + } + + if (values) { + for (int iv=0; ivnScanSteps[iscan]; iv++) { + thisDetector->scanSteps[iscan][iv]=values[iv]; + } + } + + if (thisDetector->scanMode[iscan]>0){ + thisDetector->actionMask |= (1 << (iscan+MAX_ACTIONS)); + } else { + thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS)); + } + + + return thisDetector->scanMode[iscan]; + + + } else + return -1; + + + + +} + + + + /** + returns scan script + \param iscan can be (0,1) + \returns scan script + */ +string slsDetector::getScanScript(int iscan){ + if (iscan>=0 && iscanscanScript[iscan]); + else + return string("wrong index"); + +}; + + /** + returns scan parameter + \param iscan can be (0,1) + \returns scan parameter + */ +string slsDetector::getScanParameter(int iscan){ + if (iscan>=0 && iscanscanParameter[iscan]); + else + return string("wrong index"); +} + + + /** + returns scan mode + \param iscan can be (0,1) + \returns scan mode + */ +int slsDetector::getScanMode(int iscan){ + if (iscan>=0 && iscanscanMode[iscan]; + else + return -1; +} + + + /** + returns scan steps + \param iscan can be (0,1) + \param v is the pointer to the scan steps + \returns scan steps + */ +int slsDetector::getScanSteps(int iscan, float *v) { + + if (iscan>=0 && iscannScanSteps[iscan]; iv++) { + v[iv]=thisDetector->scanSteps[iscan][iv]; + } + } + + return thisDetector->nScanSteps[iscan]; + } else + return -1; +} + + +int slsDetector::getScanPrecision(int iscan){ + if (iscan>=0 && iscanscanPrecision[iscan]; + } else + return -1; +} + + + + + + + + + + + + + + + + + + + + /* void slsDetector::startThread() { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 2344a1247..1627eb3e6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -28,6 +28,8 @@ extern "C" { #define MAX_ROIS 100 #define MAX_BADCHANS 2000 #define MAXPOS 50 +#define MAX_SCAN_LEVELS 2 +#define MAX_SCAN_STEPS 2000 #define NMODMAXX 24 #define NMODMAXY 24 @@ -43,6 +45,9 @@ extern "C" { +enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS}; + + /** data structure to hold the detector data after postprocessing (e.g. to plot, store in a root tree etc.) */ @@ -243,6 +248,7 @@ typedef struct sharedSlsDetector { /** readout flags */ readOutFlags roFlags; + /* detector setup - not needed */ /** name root of the output files */ char trimFile[MAX_STR_LENGTH]; @@ -254,9 +260,28 @@ typedef struct sharedSlsDetector { int64_t timerValue[MAX_TIMERS]; /** clock divider */ //int clkDiv; + + + /** Scans and scripts */ + + int actionMask; + + int actionMode[MAX_ACTIONS]; + char actionScript[MAX_ACTIONS][MAX_STR_LENGTH]; + char actionParameter[MAX_ACTIONS][MAX_STR_LENGTH]; + + + int scanMode[MAX_SCAN_LEVELS]; + char scanScript[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; + char scanParameter[MAX_SCAN_LEVELS][MAX_STR_LENGTH]; + int nScanSteps[MAX_SCAN_LEVELS]; + float scanSteps[MAX_SCAN_LEVELS][MAX_SCAN_STEPS]; + int scanPrecision[MAX_SCAN_LEVELS]; + + /*offsets*/ - /** memory offsets for the flat filed coefficients */ + /** memory offsets for the flat field coefficients */ int ffoff; /** memory offsets for the flat filed coefficient errors */ int fferroff; @@ -1079,7 +1104,7 @@ s get flat field corrections file name \returns flat field correction file name */ - char *getFlatFieldCorrectionFile(){return thisDetector->flatFieldFile;}; + char *getFlatFieldCorrectionFile(){ if (thisDetector->correctionMask&(1<flatFieldFile; else return "none";}; /** set rate correction @@ -1094,8 +1119,14 @@ s \param t reference for dead time \returns 0 if rate correction disabled, >0 otherwise */ - int getRateCorrection(float &t); + int getRateCorrection(float &t); + + /** + get rate correction tau + \returns 0 if rate correction disabled, otherwise the tau used for the correction + */ + float getRateCorrectionTau(); /** get rate correction \returns 0 if rate correction disabled, >0 otherwise @@ -1210,6 +1241,106 @@ s + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param fname for script ("" disable) + \param par for script + \returns 0 if action disabled, >0 otherwise + */ + int setAction(int iaction, string fname="", string par=""); + + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param fname for script ("" disable) + \returns 0 if action disabled, >0 otherwise + */ + int setActionScript(int iaction, string fname=""); + /** + set action + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, MAX_ACTIONS} + \param par for script ("" disable) + \returns 0 if action disabled, >0 otherwise + */ + int setActionParameter(int iaction, string par=""); + + /** + returns action script + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action script + */ + string getActionScript(int iaction); + + /** + returns action parameter + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action parameter + */ + string getActionParameter(int iaction); + + /** + returns action mode + \param iaction can be enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript} + \returns action mode + */ + int getActionMode(int iaction); + + + /** + set scan + \param index of the scan (0,1) + \param fname for script ("" disables, "none" disables and overwrites current) + \param nvalues number of steps (0 disables, -1 leaves current value) + \param values pointer to steps (if NULL leaves current values) + \param par parameter for the scan script ("" leaves unchanged) + \returns 0 is scan disabled, >0 otherwise + */ + int setScan(int index, string script="", int nvalues=-1, float *values=NULL, string par="", int precision=-1); + + int setScanScript(int index, string script=""); + int setScanParameter(int index, string par=""); + int setScanPrecision(int index, int precision=-1); + int setScanSteps(int index, int nvalues=-1, float *values=NULL); + /** + returns scan script + \param iscan can be (0,1) + \returns scan script + */ + string getScanScript(int iscan); + + /** + returns scan parameter + \param iscan can be (0,1) + \returns scan parameter + */ + string getScanParameter(int iscan); + + /** + returns scan mode + \param iscan can be (0,1) + \returns scan mode + */ + int getScanMode(int iscan); + + /** + returns scan steps + \param iscan can be (0,1) + \param v is the pointer to the scan steps + \returns scan steps + */ + int getScanSteps(int iscan, float *v=NULL); + + + /** + returns scan precision + \param iscan can be (0,1) + \returns scan precision + */ + int getScanPrecision(int iscan); + + + /** decode data from the detector converting them to an array of floats, one for each channle @@ -1407,6 +1538,20 @@ s */ float currentI0; + + + + /** + current scan variable of the detector + */ + float currentScanVariable[MAX_SCAN_LEVELS]; + + /** + current scan variable index of the detector + */ + int currentScanIndex[MAX_SCAN_LEVELS]; + + /** merging bins */ @@ -1421,11 +1566,6 @@ s /** merging multiplicity */ int *mergingMultiplicity; - - - - - /** pointer to flat field coefficients */ float *ffcoefficients;