#ifndef NDPluginXTCAV_H #define NDPluginXTCAV_H #include #include #include "NDPluginDriver.h" #include "TimeUtil.h" #include "ImageProcessor.h" #include "BLDMCastReceiver.h" #include "NDPluginXTCAVProperties.h" #include /* XTCAV general parameters */ #define XTCAV_NAME_PARAM "NAME" /* (asynOctet, r/w) Name of this XTCAV */ /* XTCAV definition */ #define CURRENT_PULSEID_PARAM "PULSEID" /* (asynInt32, r/o) Image PULSEID */ #define MAX_PROC_TIME_PARAM "MAXTIME" /* (asynInt32, r/o) Image max processing time */ #define MIN_PROC_TIME_PARAM "MINTIME" /* (asynInt32, r/o) Image min processing time */ #define AVG_PROC_TIME_PARAM "AVGTIME" /* (asynInt32, r/o) Image avg processing time */ #define RST_PROC_TIME_PARAM "RSTTIME" /* (asynInt32, r/w) Reset processing time stats */ #define MAX_CB_TIME_PARAM "MAXCBTIME" /* (asynInt32, r/o) Image max time between cbacks */ #define MIN_CB_TIME_PARAM "MINCBTIME" /* (asynInt32, r/o) Image min time between cbacks */ #define AVG_CB_TIME_PARAM "AVGCBTIME" /* (asynInt32, r/o) Image avg time between cbacks */ #define RST_CB_TIME_PARAM "RSTCBTIME" /* (asynInt32, r/w) Reset time between cbacks */ #define RATE_CB_TIME_PARAM "RATECBTIME" /* (asynInt32, r/o) Reset processing time stats */ #define PROCESS_FAIL_COUNT_PARAM "PROCESSFAILCOUNT" /* (asynInt32, r/o) Number of times plugin failed calculations */ #define ROI_ARRAY_DATA_PARAM "ROI_ARRAY_DATA" /* (asynXXXArray, r/o) ROI around beam image */ #define ROI_ARRAY_DATA_FULL_PARAM "ROI_ARRAY_DATA_FULL" /* (asynXXXArray, r/o) ROI around beam image (full size) */ #define ROI_ARRAY_SIZE0_PARAM "ROI_ARRAY_SIZE0" /* (asynInt32, r/o) ROI width */ #define ROI_ARRAY_SIZE1_PARAM "ROI_ARRAY_SIZE1" /* (asynInt32, r/o) ROI height */ #define ROI_ARRAY_STATUS_PARAM "ROI_ARRAY_STATUS" /* (asynInt32, r/o) ROI status */ #define ROI_ARRAY_SLICES_PARAM "ROI_ARRAY_SLICES" /* (asynInt32, r/w) Set the number of slices for the ROI */ #define ROI_PROFILE_PARAM "ROI_PROFILE" /* (asynInt32Array, r/o) ROI horizontal profile */ #define ROI_VERTICAL_SLICE_PARAM "ROI_VERTICAL_SLICE" /* (asynInt32, r/w) Selected vertical slice profile */ #define ROI_VERTICAL_PROFILE_PARAM "ROI_VERTICAL_PROFILE" /* (asynInt32Array, r/o) ROI vertical slice profile */ #define ROI_VERTICAL_ENERGY_PROFILE_PARAM "ROI_VERTICAL_ENERGY_PROFILE" /* (asynFloat64Array, r/o) ROI vertical slice energy profile */ #define ROI_AVG_BACKGROUND_PARAM "ROI_AVG_BACKGROUND" /* (asynInt32, r/o) Read back of sampled background intensity */ #define ROI_SCAN_X_PARAM "ROI_SCAN_X" /* (asynInt32, r/w) Scan interval in X (pixels) */ #define ROI_SCAN_Y_PARAM "ROI_SCAN_Y" /* (asynInt32, r/w) Scan interval in Y (pixels) */ #define ENABLE_TEST_FILE_PARAM "ENABLE_TEST_FILE" #define TEST_FILE_NAME_PARAM "TEST_FILE_NAME" #define ROI_TOP_LEFT_X_PARAM "ROI_TOP_LEFT_X" #define ROI_TOP_LEFT_Y_PARAM "ROI_TOP_LEFT_Y" #define ROI_BOTTOM_RIGHT_X_PARAM "ROI_BOTTOM_RIGHT_X" #define ROI_BOTTOM_RIGHT_Y_PARAM "ROI_BOTTOM_RIGHT_Y" #define CHARGE_PARAM "CHARGE" /* (asynFloat64, r/w) User input for the beam charge at the DMP */ #define USE_CHARGE_PARAM "USE_CHARGE" /* (asynInt32, r/w) Define if user provided change is used */ #define STRENGTH_PARAM_PARAM "STRENGTH_PARAM" /* (asynFloat64, r/w) Stregth param S - horz position time (tcav_gui.m) */ #define ROI_ENERGY_PARAM "ROI_ENERGY" /* (asynFloat64Array, r/o) ROI energy profile */ #define ROI_ENERGY_CENTER_PARAM "ROI_ENERGY_CENTER" /* (asynFloat64Array, r/o) Max energy for each slice */ #define ROI_ENERGY_CENTER_DIFF_PARAM "ROI_ENERGY_CENTER_DIFF" /* (asynFloat64Array, r/o) Diff between FEL OFF/FEL ON for each slice */ #define ROI_ENERGY_PROFILE_PARAM "ROI_ENERGY_PROFILE" /* (asynFloat64Array, r/o) Diff between FEL OFF/FEL ON multiplied by the BPM TMIT (charge) */ #define ROI_ENERGY_RMS_PARAM "ROI_ENERGY_RMS" /* (asynFloat64Array, r/o) RMS of max energy for each slice */ #define ENABLE_AUTO_ROI_PARAM "ENABLE_AUTO_ROI" /* (asynInt32, r/w) Control Automatic ROI cropping */ #define ROI_MAX_WINDOW_PARAM "ROI_MAX_WINDOW" /* (asynInt32, r/w) Window around the scanned max pixel for threshold calc */ #define ROI_THRESHOLD_PARAM "ROI_THRESHOLD" /* (asynInt32, r/w) Percentage of thres. around max window to use for segmentation */ #define ROI_EXTRA_X_PARAM "ROI_EXTRA_X" /* (asynInt32, r/w) Additional ROI pixels in the X dimension */ #define ROI_EXTRA_Y_PARAM "ROI_EXTRA_Y" /* (asynInt32, r/w) Additional ROI pixels in the Y dimension */ #define ROI_MAX_WIDTH_PARAM "ROI_MAX_WIDTH" /* (asynInt32, r/w) Maximum ROI Width */ #define ROI_MAX_HEIGHT_PARAM "ROI_MAX_HEIGHT" /* (asynInt32, r/w) Maximum ROI Height */ #define SAVE_BACKGROUND_PARAM "SAVE_BACKGROUND" /* (asynInt32, r/w) Define if current image should be save as background */ #define BACKGROUND_LOAD_FILE_NAME_PARAM "BACKGROUND_LOAD_FILE_NAME" #define BACKGROUND_SAVE_FILE_NAME_PARAM "BACKGROUND_SAVE_FILE_NAME" #define SAVE_REFERENCE_PARAM "SAVE_REFERENCE" /* (asynInt32, r/w) Define if current image should be save as reference */ #define REFERENCE_LOAD_FILE_NAME_PARAM "REFERENCE_LOAD_FILE_NAME" #define REFERENCE_SAVE_FILE_NAME_PARAM "REFERENCE_SAVE_FILE_NAME" #define BG_ARRAY_DATA_PARAM "BG_ARRAY_DATA" /* (asynXXXArray, r/o) Background image */ #define BG_ARRAY_SIZE0_PARAM "BG_ARRAY_SIZE0" /* (asynInt32, r/o) Background width */ #define BG_ARRAY_SIZE1_PARAM "BG_ARRAY_SIZE1" /* (asynInt32, r/o) Background height */ #define REF_ARRAY_DATA_PARAM "REF_ARRAY_DATA" /* (asynXXXArray, r/o) Reference image */ #define REF_ARRAY_SIZE0_PARAM "REF_ARRAY_SIZE0" /* (asynInt32, r/o) Reference width */ #define REF_ARRAY_SIZE1_PARAM "REF_ARRAY_SIZE1" /* (asynInt32, r/o) Reference height */ #define PROCESS_REFERENCE_PARAM "PROCESS_REFERENCE" /* (asynInt32, r/w) Process current reference image */ #define REFROI_ARRAY_DATA_PARAM "REFROI_ARRAY_DATA" /* (asynXXXArray, r/o) Reference image */ #define REFROI_ARRAY_SIZE0_PARAM "REFROI_ARRAY_SIZE0" /* (asynInt32, r/o) Reference width */ #define REFROI_ARRAY_SIZE1_PARAM "REFROI_ARRAY_SIZE1" /* (asynInt32, r/o) Reference height */ #define REFROI_PROFILE_PARAM "REFROI_PROFILE" /* (asynInt32Array, r/o) Reference ROI horizontal profile */ #define REFROI_VERTICAL_PROFILE_PARAM "REFROI_VERTICAL_PROFILE" /* (asynInt32Array, r/o) Reference ROI vertical slice profile */ #define REFROI_VERTICAL_ENERGY_PROFILE_PARAM "REFROI_VERTICAL_ENERGY_PROFILE" /* (asynFloat64Array, r/o) Reference ROI vertical slice energy profile */ #define REFROI_VERTICAL_SLICE_PARAM "REFROI_VERTICAL_SLICE" /* (asynInt32, r/w) Selected vertical slice profile */ #define REFROI_ENERGY_PARAM "REFROI_ENERGY" /* (asynFloat64Array, r/o) ROI energy profile */ #define REFROI_ENERGY_CENTER_PARAM "REFROI_ENERGY_CENTER" /* (asynFloat64Array, r/o) Max energy for each slice */ #define REFROI_ENERGY_RMS_PARAM "REFROI_ENERGY_RMS" /* (asynFloat64Array, r/o) RMS of max energy for each slice */ #define ROI_STATUS_COUNTER_PARAM "ROI_STATUS_COUNTER" /* (asynInt32Array, r/o) */ #define REFROI_STATUS_PARAM "REFROI_STATUS" /* (asynInt32, r/o) Ref ROI status */ #define REFROI_STATUS_COUNTER_PARAM "REFROI_STATUS_COUNTER" /* (asynInt32Array, r/o) */ #define ENERGYPROFILE_STATUS_PARAM "ENERGYPROFILE_STATUS" /* (asynInt32, r/o) Ref ROI status */ #define ENABLE_WAVEFORMS_PARAM "ENABLE_WAVEFORMS" /* Used to enable/disable waveform updates */ #define BUNCH_ENERGY_PARAM "BUNCH_ENERGY" #define BLD_GDET_PARAM "BLD_GDET" /* (asynFloat64, r/w) Gas detector reading from BLD */ #define BLD_CHARGE_PARAM "BLD_CHARGE" /* (asynFloat64, r/w) DMP charge reading from BLD */ /** * Extract XTCAV properties from NDArray data; the plugin can be a source of NDArray callbacks for * other plugins, passing these sub-arrays. */ class NDPluginXTCAV : public NDPluginDriver { public: NDPluginXTCAV(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int maxBuffers, size_t maxMemory, int priority, int stackSize); /* These methods override the virtual methods in the base class */ void processCallbacks(NDArray *pArray); /* virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value, */ /* size_t nElements, size_t *nIn); */ virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t nChars, size_t *nActual); protected: ImageProcessor _processor; ImageProcessor _refProcessor; NDPluginXTCAVProperties _properties; TimeAverage _processingTime; TimeAverage _timeBetweenCallbacks; int _roiInitialized; int _roiFullInitialized; // Charge at DMP receiver BLDMCastReceiver *_ebeamBLDReceiver; EBeamPayloadReader _ebeamBLDReader; // GDET receiver BLDMCastReceiver *_gdetBLDReceiver; GDETPayloadReader _gdetBLDReader; // Background array NDArray *_backgroundArray; int _name; /* XTCAV general parameters */ #define FIRST_NDPLUGIN_XTCAV_PARAM _name int _maxProcTime; int _minProcTime; int _avgProcTime; int _rstProcTime; int _maxCbTime; int _minCbTime; int _avgCbTime; int _rstCbTime; int _rateCbTime; int _processFailCount; int _roiArrayData; int _roiArrayDataFull; int _roiSize0; int _roiSize1; int _roiStatus; int _roiSlices; int _roiProfile; int _roiVerticalSlice; int _roiVerticalProfile; int _roiVerticalEnergyProfile; int _roiScanX; int _roiScanY; int _saveBackground; int _backgroundSaveFileName; int _backgroundLoadFileName; int _testFileName; int _enableTestFile; int _roiTopLeftX; int _roiTopLeftY; int _roiBottomRightX; int _roiBottomRightY; int _charge; int _useCharge; int _strengthParam; int _roiEnergy; int _roiEnergyCenter; int _roiEnergyCenterDiff; int _roiEnergyRMS; int _enableAutoROI; int _roiMaxWindow; int _roiThresholdPercent; int _roiExtraX; int _roiExtraY; int _roiMaxW; int _roiMaxH; int _saveReference; int _referenceSaveFileName; int _referenceLoadFileName; int _backgroundArrayData; int _backgroundSize0; int _backgroundSize1; int _referenceArrayData; int _referenceSize0; int _referenceSize1; int _processReference; int _refROIArrayData; int _refROISize0; int _refROISize1; int _refROIProfile; int _refROIVerticalProfile; int _refROIVerticalEnergyProfile; int _refROIEnergy; int _refROIEnergyCenter; int _refROIEnergyRMS; int _roiStatusCounter; int _refROIStatus; int _refROIStatusCounter; int _energyProfileStatus; int _energyProfile; int _enableWaveforms; int _bunchEnergy; int _bldGDET; int _bldCharge; int _currentPulseId; /* XTCAV definition */ #define LAST_NDPLUGIN_XTCAV_PARAM _currentPulseId private: int _counter; NDArray _testImage; epicsUInt16 _testImageArray[2000 * 2000]; Waveform _roiStatusCounterArray; Waveform _refROIStatusCounterArray; bool validate(NDArray *pArray); void printImageInfo(NDArray *pArray); void exitCallback(); void arrayInterruptCallback(NDArray *pArray, NDArrayPool *pNDArrayPool, void *interruptPvt, int *initialized, NDDataType_t signedType); void updateReferenceWaveforms(); perfParm_ts *p1; }; #define NUM_NDPLUGIN_XTCAV_PARAMS (&LAST_NDPLUGIN_XTCAV_PARAM - &FIRST_NDPLUGIN_XTCAV_PARAM + 1) #endif