mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
added callbacks (but should still implement them in the base classes)
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@182 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
0bab16cde7
commit
d30ad5faac
@ -3134,19 +3134,6 @@ int multiSlsDetector::readConfigurationFile(string const fname){
|
||||
|
||||
infile.close();
|
||||
|
||||
|
||||
// for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
// sprintf(ext,".det%d",i);
|
||||
// if (detectors[i]) {
|
||||
// detectors[i]->readConfigurationFile(fname+string(ext));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl;
|
||||
@ -3479,15 +3466,6 @@ int multiSlsDetector::retrieveDetectorSetup(string const fname1, int level){
|
||||
infile.close();
|
||||
|
||||
|
||||
|
||||
// for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
// sprintf(ext,".det%d",i);
|
||||
// if (detectors[i]) {
|
||||
// detectors[i]->retrieveDetectorSetup(fname1+string(ext), level);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
} else {
|
||||
std::cout<< "Error opening " << fname << " for reading" << std::endl;
|
||||
return FAIL;
|
||||
|
@ -13,8 +13,7 @@ INSTMODE= 0777
|
||||
SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
||||
OBJS= $(SRCS:%.c=%.o)
|
||||
|
||||
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS
|
||||
#-DVERBOSE
|
||||
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE
|
||||
#-DVERYVERBOSE
|
||||
#-Werror
|
||||
|
||||
|
@ -5147,7 +5147,7 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
|
||||
|
||||
string fname1;
|
||||
ofstream outfile;
|
||||
|
||||
int iv;
|
||||
if (level==2) {
|
||||
fname1=fname+string(".det");
|
||||
} else
|
||||
@ -5156,7 +5156,7 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
|
||||
outfile.open(fname1.c_str(),ios_base::out);
|
||||
if (outfile.is_open()) {
|
||||
|
||||
dumpDetectorSetup(fname, outfile, level);
|
||||
iv=dumpDetectorSetup(fname, outfile, level);
|
||||
|
||||
outfile.close();
|
||||
} else {
|
||||
|
@ -702,7 +702,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
|
||||
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
|
||||
#endif
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
myDet->acquire(1);
|
||||
myDet->acquire();
|
||||
return string("");
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,17 @@
|
||||
#include <sys/shm.h>
|
||||
|
||||
|
||||
slsDetectorUtils::slsDetectorUtils() {};
|
||||
slsDetectorUtils::slsDetectorUtils() {
|
||||
cout << "setting callbacks" << endl;
|
||||
registerGetPositionCallback(&defaultGetPosition);
|
||||
registerConnectChannelsCallback(&defaultConnectChannels);
|
||||
registerDisconnectChannelsCallback(&defaultDisconnectChannels);
|
||||
registerGoToPositionCallback(&defaultGoToPosition);
|
||||
registerGoToPositionNoWaitCallback(&defaultGoToPositionNoWait);
|
||||
registerGetI0Callback(&defaultGetI0);
|
||||
cout << "done " << endl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -28,8 +38,10 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
// int lastindex=startindex, nowindex=startindex;
|
||||
|
||||
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)))
|
||||
connect_channels();
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) {
|
||||
if (connect_channels())
|
||||
connect_channels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -114,7 +126,8 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
// cout << "positions " << endl;
|
||||
if (*stoppedFlag==0) {
|
||||
if (*numberOfPositions>0) {
|
||||
go_to_position (detPositions[ip]);
|
||||
if (go_to_position)
|
||||
go_to_position (detPositions[ip]);
|
||||
currentPositionIndex=ip+1;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "moving to position" << std::endl;
|
||||
@ -137,18 +150,23 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
|
||||
pthread_mutex_lock(&mp);
|
||||
currentPosition=get_position();
|
||||
if (get_position)
|
||||
currentPosition=get_position();
|
||||
posfinished=0;
|
||||
pthread_mutex_unlock(&mp);
|
||||
}
|
||||
|
||||
if (*correctionMask&(1<< I0_NORMALIZATION))
|
||||
get_i0(0);
|
||||
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
||||
if (get_i0)
|
||||
get_i0(0);
|
||||
}
|
||||
|
||||
startAndReadAll();
|
||||
|
||||
if (*correctionMask&(1<< I0_NORMALIZATION))
|
||||
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
||||
if (get_i0)
|
||||
currentI0=get_i0(1); // this is the correct i0!!!!!
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
posfinished=1;
|
||||
@ -242,9 +260,10 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
}
|
||||
|
||||
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)))
|
||||
disconnect_channels();
|
||||
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) {
|
||||
if (disconnect_channels)
|
||||
disconnect_channels();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -512,11 +512,23 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||
*/
|
||||
virtual int writeConfigurationFile(string const fname)=0;
|
||||
|
||||
|
||||
|
||||
|
||||
void registerGetPositionCallback( float (*func)(void)){get_position=func;};
|
||||
void registerConnectChannelsCallback( int (*func)(void)){connect_channels=func;};
|
||||
void registerDisconnectChannelsCallback( int (*func)(void)){disconnect_channels=func;};
|
||||
|
||||
void registerGoToPositionCallback( int (*func)(float)){go_to_position=func;};
|
||||
void registerGoToPositionNoWaitCallback( int (*func)(float)){go_to_position_no_wait=func;};
|
||||
void registerGetI0Callback( float (*func)(int)){get_i0=func;};
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
static const int64_t thisSoftwareVersion=0x20120124;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//protected:
|
||||
int *stoppedFlag;
|
||||
@ -530,6 +542,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||
|
||||
int progressIndex;
|
||||
|
||||
float (*get_position)(void);
|
||||
int (*go_to_position)(float);
|
||||
int (*go_to_position_no_wait)(float);
|
||||
int (*connect_channels)(void);
|
||||
int (*disconnect_channels)(void);
|
||||
float (*get_i0)(int);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -11,7 +11,8 @@ using namespace std;
|
||||
angularConversion::angularConversion(): currentPosition(0),
|
||||
currentPositionIndex(0)
|
||||
{
|
||||
|
||||
//angleFunctionPointer=0;
|
||||
registerAngleFunctionCallback(&defaultAngleFunction);
|
||||
|
||||
}
|
||||
|
||||
|
@ -436,6 +436,13 @@ class angularConversion : public virtual slsDetectorBase {
|
||||
int getCurrentPositionIndex() {return currentPositionIndex;};
|
||||
void incrementPositionIndex() {currentPositionIndex++;};
|
||||
|
||||
|
||||
|
||||
|
||||
void registerAngleFunctionCallback(float( *fun)(float, float, float, float, float, float, float, int)) {angle = fun;};
|
||||
|
||||
|
||||
|
||||
private:
|
||||
/** merging bins */
|
||||
float *mergingBins;
|
||||
@ -449,7 +456,7 @@ class angularConversion : public virtual slsDetectorBase {
|
||||
/** merging multiplicity */
|
||||
int *mergingMultiplicity;
|
||||
|
||||
|
||||
float (*angle)(float, float, float, float, float, float, float, int);
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
|
||||
#ifndef DETECTOR_DATA_H
|
||||
#define DETECTOR_DATA_H
|
||||
/**
|
||||
@short data structure to hold the detector data after postprocessing
|
||||
|
||||
@ -32,3 +33,5 @@ class detectorData {
|
||||
int npoints;/**< number of points */
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "postProcessing.h"
|
||||
#include "usersFunctions.h"
|
||||
|
||||
|
||||
postProcessing::postProcessing(){
|
||||
@ -7,6 +8,10 @@ postProcessing::postProcessing(){
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
mg=mp1;
|
||||
pthread_mutex_init(&mg, NULL);
|
||||
//cout << "reg callback "<< endl;
|
||||
dataReady = 0;
|
||||
registerDataCallback(&defaultDataReadyFunc);
|
||||
//cout << "done "<< endl;
|
||||
}
|
||||
|
||||
|
||||
@ -164,11 +169,14 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
|
||||
|
||||
|
||||
/** write raw data file */
|
||||
if (*correctionMask==0 && delflag==1) {
|
||||
// delete [] fdata;
|
||||
;
|
||||
} else {
|
||||
// /** write raw data file */
|
||||
// if (*correctionMask==0 && delflag==1) {
|
||||
// // delete [] fdata;
|
||||
|
||||
|
||||
|
||||
// ;
|
||||
// } else {
|
||||
|
||||
|
||||
|
||||
@ -278,17 +286,25 @@ void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
|
||||
|
||||
|
||||
|
||||
if (delflag) {
|
||||
deleteMerging();
|
||||
} else {
|
||||
// if (delflag) {
|
||||
// deleteMerging();
|
||||
// } else {
|
||||
thisData=new detectorData(getMergedCounts(),getMergedErrors(),getMergedPositions(),getCurrentProgress(),(fname+ext).c_str(),np);
|
||||
|
||||
// cout << "lock 2" << endl;
|
||||
pthread_mutex_lock(&mg);
|
||||
finalDataQueue.push(thisData);
|
||||
// cout << "unlock 2" << endl;
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
// // cout << "lock 2" << endl;
|
||||
// pthread_mutex_lock(&mg);
|
||||
// finalDataQueue.push(thisData);
|
||||
// // cout << "unlock 2" << endl;
|
||||
|
||||
// pthread_mutex_unlock(&mg);
|
||||
|
||||
if (dataReady) {
|
||||
|
||||
dataReady(thisData);
|
||||
delete thisData;
|
||||
}
|
||||
|
||||
// }
|
||||
// cout << "lock 3" << endl;
|
||||
pthread_mutex_lock(&mp);
|
||||
}
|
||||
@ -309,21 +325,29 @@ void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
|
||||
ang=NULL;
|
||||
|
||||
} else {
|
||||
if (delflag) {
|
||||
if (ffcdata)
|
||||
delete [] ffcdata;
|
||||
if (ffcerr)
|
||||
delete [] ffcerr;
|
||||
if ( ang)
|
||||
delete [] ang;
|
||||
} else {
|
||||
// if (delflag) {
|
||||
// if (ffcdata)
|
||||
// delete [] ffcdata;
|
||||
// if (ffcerr)
|
||||
// delete [] ffcerr;
|
||||
// if ( ang)
|
||||
// delete [] ang;
|
||||
// } else {
|
||||
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+ext).c_str(),getTotalNumberOfChannels());
|
||||
pthread_mutex_lock(&mg);
|
||||
finalDataQueue.push(thisData);
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
|
||||
if (dataReady) {
|
||||
dataReady(thisData);
|
||||
delete thisData;
|
||||
}
|
||||
// pthread_mutex_lock(&mg);
|
||||
// finalDataQueue.push(thisData);
|
||||
|
||||
|
||||
// pthread_mutex_unlock(&mg);
|
||||
// }
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
incrementFileIndex();
|
||||
#ifdef VERBOSE
|
||||
|
@ -243,7 +243,8 @@ s
|
||||
|
||||
|
||||
|
||||
|
||||
void registerDataCallback(int( *userCallback)(detectorData*)) {dataReady = userCallback;};
|
||||
|
||||
|
||||
|
||||
|
||||
@ -363,7 +364,8 @@ s
|
||||
/* virtual float* decodeData(int *datain, float *fdata=NULL)=0; */
|
||||
/* virtual int getTotalNumberOfChannels()=0; */
|
||||
|
||||
|
||||
|
||||
int (*dataReady)(detectorData*);
|
||||
|
||||
|
||||
};
|
||||
|
@ -118,7 +118,7 @@ int caput(chid ch_id, double value) {
|
||||
*/
|
||||
|
||||
|
||||
float angle(float ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction) {
|
||||
float defaultAngleFunction(float ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction) {
|
||||
|
||||
|
||||
(void) tilt; /* to avoid warning: unused parameter */
|
||||
@ -134,7 +134,7 @@ float angle(float ichan, float encoder, float totalOffset, float conv_r, float c
|
||||
|
||||
/* reads the encoder and returns the position */
|
||||
|
||||
float get_position() {
|
||||
float defaultGetPosition() {
|
||||
#ifdef VERBOSE
|
||||
printf("Getting motor position \n");
|
||||
#endif
|
||||
@ -164,7 +164,7 @@ float get_position() {
|
||||
/* moves the encoder to position p */
|
||||
|
||||
|
||||
int go_to_position(float p) {
|
||||
int defaultGoToPosition(float p) {
|
||||
#ifdef VERBOSE
|
||||
printf("Setting motor position \n");
|
||||
#endif
|
||||
@ -191,7 +191,7 @@ int go_to_position(float p) {
|
||||
|
||||
/* moves the encoder to position p without waiting */
|
||||
|
||||
int go_to_position_no_wait(float p) {
|
||||
int defaultGoToPositionNoWait(float p) {
|
||||
#ifdef VERBOSE
|
||||
printf("Setting motor position no wait \n");
|
||||
#endif
|
||||
@ -215,9 +215,6 @@ int go_to_position_no_wait(float p) {
|
||||
|
||||
return (int)p;
|
||||
|
||||
|
||||
|
||||
|
||||
pos=p;
|
||||
return (int)pos;
|
||||
}
|
||||
@ -225,7 +222,7 @@ int go_to_position_no_wait(float p) {
|
||||
|
||||
/* reads I0 and returns the intensity */
|
||||
|
||||
float get_i0(int t) {
|
||||
float defaultGetI0(int t) {
|
||||
#ifdef VERBOSE
|
||||
printf("Getting I0 readout \n");
|
||||
#endif
|
||||
@ -261,7 +258,7 @@ float get_i0(int t) {
|
||||
}
|
||||
|
||||
|
||||
int connect_channels() {
|
||||
int defaultConnectChannels() {
|
||||
#ifdef EPICS
|
||||
//double value = 256;
|
||||
/* channel name */
|
||||
@ -311,7 +308,7 @@ int connect_channels() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disconnect_channels() {
|
||||
int defaultDisconnectChannels() {
|
||||
#ifdef EPICS
|
||||
/* close channel connect */
|
||||
disconnect_channel(ch_i0);
|
||||
@ -326,6 +323,11 @@ int disconnect_channels() {
|
||||
|
||||
|
||||
|
||||
|
||||
int defaultDataReadyFunc(detectorData* d) {
|
||||
#ifdef VERBOSE
|
||||
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Data received \n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ Functions depending on the experimental setup should be defined here
|
||||
#include <cadef.h>
|
||||
#include <epicsEvent.h>
|
||||
#endif
|
||||
|
||||
#include "detectorData.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -29,17 +29,15 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
float angle(float ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction);
|
||||
float get_position();
|
||||
int go_to_position(float p);
|
||||
int go_to_position_no_wait(float p);
|
||||
int connect_channels();
|
||||
int disconnect_channels();
|
||||
|
||||
float get_i0(int t);
|
||||
|
||||
|
||||
float defaultAngleFunction(float ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction);
|
||||
float defaultGetPosition();
|
||||
int defaultGoToPosition(float p);
|
||||
int defaultGoToPositionNoWait(float p);
|
||||
int defaultConnectChannels();
|
||||
int defaultDisconnectChannels();
|
||||
float defaultGetI0(int t);
|
||||
|
||||
int defaultDataReadyFunc(detectorData* d);
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user