#include "slsDetectorUtils.h" #include "usersFunctions.h" #include "slsDetectorCommand.h" #include "postProcessing.h" #include "enCalLogClass.h" #include "angCalLogClass.h" #include #include #include using namespace std; slsDetectorUtils::slsDetectorUtils() { #ifdef VERBOSE cout << "setting callbacks" << endl; #endif acquisition_finished=NULL; acqFinished_p=NULL; measurement_finished=NULL; measFinished_p=NULL; progress_call=0; pProgressCallArg=0; registerGetPositionCallback(&defaultGetPosition, NULL); registerConnectChannelsCallback(&defaultConnectChannels,NULL); registerDisconnectChannelsCallback(&defaultDisconnectChannels,NULL); registerGoToPositionCallback(&defaultGoToPosition,NULL); registerGoToPositionNoWaitCallback(&defaultGoToPositionNoWait,NULL); registerGetI0Callback(&defaultGetI0,NULL); #ifdef VERBOSE registerAcquisitionFinishedCallback(&dummyAcquisitionFinished,this); registerMeasurementFinishedCallback(&dummyMeasurementFinished,this); cout << "done " << endl; #endif }; void slsDetectorUtils::acquire(int delflag){ bool receiver = (setReceiverOnline()==ONLINE_FLAG); if(!receiver) setDetectorIndex(-1); int nc=setTimer(CYCLES_NUMBER,-1); int nf=setTimer(FRAME_NUMBER,-1); if (nc==0) nc=1; if (nf==0) nf=1; int multiframe = nc*nf; cout << "multiframe:"<< multiframe<0) { moveDetector(detPositions[ip]); IncrementPositionIndex(); #ifdef VERBOSE std::cout<< "moving to position" << std::endl; #endif } } else break; pthread_mutex_lock(&mp); createFileName(); pthread_mutex_unlock(&mp); if (*stoppedFlag==0) { executeAction(scriptBefore); } else break; if (*stoppedFlag==0) { executeAction(headerBefore); if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog){// || eclog) { positionFinished(0); setCurrentPosition(getDetectorPosition()); } if (aclog) aclog->addStep(getCurrentPosition(), getCurrentFileName()); if (eclog) eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName()); if (*correctionMask&(1<< I0_NORMALIZATION)) { if (get_i0) get_i0(0, IOarg); } setCurrentFrameIndex(0); //if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1) { if (multiframe>1){ setFrameIndex(0); } else { setFrameIndex(-1); } cout <<"frame index:"<0) nc=timerValue[CYCLES_NUMBER]; if (timerValue[MEASUREMENTS_NUMBER]>0) nm=timerValue[MEASUREMENTS_NUMBER]; if (*numberOfPositions>0) npos=*numberOfPositions; if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS))) nscan[0]=nScanSteps[0]; if ((nScanSteps[1]>0) && (*actionMask & (1 << (MAX_ACTIONS+1)))) nscan[1]=nScanSteps[1]; totalProgress=nm*nf*nc*npos*nscan[0]*nscan[1]; #ifdef VERBOSE cout << "nc " << nc << endl; cout << "nm " << nm << endl; cout << "nf " << nf << endl; cout << "npos " << npos << endl; cout << "nscan[0] " << nscan[0] << endl; cout << "nscan[1] " << nscan[1] << endl; cout << "Set total progress " << totalProgress << endl; #endif return totalProgress; } int slsDetectorUtils::setBadChannelCorrection(string fname, int &nbadtot, int *badchanlist, int off){ int nbad; int badlist[MAX_BADCHANS]; ifstream infile; string str; //int interrupt=0; //int ich; //int chmin,chmax; #ifdef VERBOSE std::cout << "utils: Setting bad channel correction to " << fname << std::endl; #endif // int modmi=0; int modma=1; int singlefile=0; string fn; int offset=off; nbadtot=0; if (fname=="" || fname=="none") { ; } else { if (fname.find(".sn")==string::npos && fname.find(".chans")==string::npos) { modma=setNumberOfModules(); singlefile=1; } for (int im=0; im0 && nbadtot> sargname; // if (ssstr.good()) { strcpy(myargs[iargval],sargname.c_str()); args[iargval]=myargs[iargval]; #ifdef VERBOSE std::cout<< args[iargval] << std::endl; #endif iargval++; // } skip=0; } if (level!=2) { if (string(args[0])==string("flatfield")) skip=1; else if (string(args[0])==string("badchannels")) skip=1; else if (string(args[0])==string("trimbits")) skip=1; } if (skip==0) cmd->executeLine(iargval,args,PUT_ACTION); } iline++; } delete cmd; infile.close(); } else { std::cout<< "Error opening " << fname << " for reading" << std::endl; return FAIL; } #ifdef VERBOSE std::cout<< "Read " << iline << " lines" << std::endl; #endif return iline; } int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ slsDetectorCommand *cmd; string names[]={ "fname",\ "index",\ "flags",\ "dr",\ "settings",\ "threshold",\ "exptime",\ "period",\ "delay",\ "gates",\ "frames",\ "cycles",\ "probes",\ "timing",\ "fineoff",\ "startscript",\ "startscriptpar",\ "stopscript",\ "stopscriptpar",\ "scriptbefore",\ "scriptbeforepar",\ "scriptafter",\ "scriptafterpar",\ "scan0script",\ "scan0par",\ "scan0prec",\ "scan0steps",\ "scan1script",\ "scan1par",\ "scan1prec",\ "scan1steps",\ "ratecorr",\ "flatfield",\ "badchannels",\ "trimbits" }; int nvar=35; // char ext[100]; int iv=0; string fname1; ofstream outfile; char *args[2]; for (int ia=0; ia<2; ia++) { args[ia]=new char[1000]; } int nargs; if (level==2) nargs=2; else nargs=1; if (level==2) { fname1=fname+string(".config"); writeConfigurationFile(fname1); fname1=fname+string(".det"); } else fname1=fname; outfile.open(fname1.c_str(),ios_base::out); if (outfile.is_open()) { cmd=new slsDetectorCommand(this); for (iv=0; ivexecuteLine(1,args,GET_ACTION) << std::endl; } strcpy(args[0],names[iv].c_str()); if (level==2) { fname1=fname+string(".ff"); strcpy(args[1],fname1.c_str()); } outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; iv++; strcpy(args[0],names[iv].c_str()); if (level==2) { fname1=fname+string(".bad"); strcpy(args[1],fname1.c_str()); } outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; iv++; if (level==2) { strcpy(args[0],names[iv].c_str()); size_t c=fname.rfind('/'); if (cexecuteLine(nargs,args,GET_ACTION) << std::endl; iv++; } delete cmd; outfile.close(); } else { std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl; return FAIL; } #ifdef VERBOSE std::cout<< "wrote " <