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:
bergamaschi 2012-05-22 15:34:12 +00:00
parent 0bab16cde7
commit d30ad5faac
13 changed files with 145 additions and 93 deletions

View File

@ -3135,19 +3135,6 @@ int multiSlsDetector::readConfigurationFile(string const fname){
infile.close(); 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 { } else {
std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl; std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl;
return FAIL; return FAIL;
@ -3479,15 +3466,6 @@ int multiSlsDetector::retrieveDetectorSetup(string const fname1, int level){
infile.close(); 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 { } else {
std::cout<< "Error opening " << fname << " for reading" << std::endl; std::cout<< "Error opening " << fname << " for reading" << std::endl;
return FAIL; return FAIL;

View File

@ -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 SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
OBJS= $(SRCS:%.c=%.o) OBJS= $(SRCS:%.c=%.o)
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE
#-DVERBOSE
#-DVERYVERBOSE #-DVERYVERBOSE
#-Werror #-Werror

View File

@ -5147,7 +5147,7 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
string fname1; string fname1;
ofstream outfile; ofstream outfile;
int iv;
if (level==2) { if (level==2) {
fname1=fname+string(".det"); fname1=fname+string(".det");
} else } else
@ -5156,7 +5156,7 @@ int slsDetector::dumpDetectorSetup(string const fname, int level){
outfile.open(fname1.c_str(),ios_base::out); outfile.open(fname1.c_str(),ios_base::out);
if (outfile.is_open()) { if (outfile.is_open()) {
dumpDetectorSetup(fname, outfile, level); iv=dumpDetectorSetup(fname, outfile, level);
outfile.close(); outfile.close();
} else { } else {

View File

@ -702,7 +702,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n"); cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
#endif #endif
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->acquire(1); myDet->acquire();
return string(""); return string("");
} }

View File

@ -5,7 +5,17 @@
#include <sys/shm.h> #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; // int lastindex=startindex, nowindex=startindex;
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) {
connect_channels(); if (connect_channels())
connect_channels();
}
@ -114,7 +126,8 @@ void slsDetectorUtils::acquire(int delflag){
// cout << "positions " << endl; // cout << "positions " << endl;
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
if (*numberOfPositions>0) { if (*numberOfPositions>0) {
go_to_position (detPositions[ip]); if (go_to_position)
go_to_position (detPositions[ip]);
currentPositionIndex=ip+1; currentPositionIndex=ip+1;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "moving to position" << std::endl; std::cout<< "moving to position" << std::endl;
@ -137,18 +150,23 @@ void slsDetectorUtils::acquire(int delflag){
if (*correctionMask&(1<< ANGULAR_CONVERSION)) { if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
currentPosition=get_position(); if (get_position)
currentPosition=get_position();
posfinished=0; posfinished=0;
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
} }
if (*correctionMask&(1<< I0_NORMALIZATION)) if (*correctionMask&(1<< I0_NORMALIZATION)) {
get_i0(0); if (get_i0)
get_i0(0);
}
startAndReadAll(); startAndReadAll();
if (*correctionMask&(1<< I0_NORMALIZATION)) if (*correctionMask&(1<< I0_NORMALIZATION)) {
if (get_i0)
currentI0=get_i0(1); // this is the correct i0!!!!! currentI0=get_i0(1); // this is the correct i0!!!!!
}
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
posfinished=1; posfinished=1;
@ -242,9 +260,10 @@ void slsDetectorUtils::acquire(int delflag){
} }
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION))) {
disconnect_channels(); if (disconnect_channels)
disconnect_channels();
}
} }

View File

@ -512,11 +512,23 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/ */
virtual int writeConfigurationFile(string const fname)=0; 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: protected:
static const int64_t thisSoftwareVersion=0x20120124; static const int64_t thisSoftwareVersion=0x20120124;
protected:
//protected: //protected:
int *stoppedFlag; int *stoppedFlag;
@ -530,6 +542,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
int progressIndex; 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);
}; };

View File

@ -11,7 +11,8 @@ using namespace std;
angularConversion::angularConversion(): currentPosition(0), angularConversion::angularConversion(): currentPosition(0),
currentPositionIndex(0) currentPositionIndex(0)
{ {
//angleFunctionPointer=0;
registerAngleFunctionCallback(&defaultAngleFunction);
} }

View File

@ -436,6 +436,13 @@ class angularConversion : public virtual slsDetectorBase {
int getCurrentPositionIndex() {return currentPositionIndex;}; int getCurrentPositionIndex() {return currentPositionIndex;};
void incrementPositionIndex() {currentPositionIndex++;}; void incrementPositionIndex() {currentPositionIndex++;};
void registerAngleFunctionCallback(float( *fun)(float, float, float, float, float, float, float, int)) {angle = fun;};
private: private:
/** merging bins */ /** merging bins */
float *mergingBins; float *mergingBins;
@ -449,7 +456,7 @@ class angularConversion : public virtual slsDetectorBase {
/** merging multiplicity */ /** merging multiplicity */
int *mergingMultiplicity; int *mergingMultiplicity;
float (*angle)(float, float, float, float, float, float, float, int);
}; };

View File

@ -1,7 +1,8 @@
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#ifndef DETECTOR_DATA_H
#define DETECTOR_DATA_H
/** /**
@short data structure to hold the detector data after postprocessing @short data structure to hold the detector data after postprocessing
@ -32,3 +33,5 @@ class detectorData {
int npoints;/**< number of points */ int npoints;/**< number of points */
}; };
#endif

View File

@ -1,4 +1,5 @@
#include "postProcessing.h" #include "postProcessing.h"
#include "usersFunctions.h"
postProcessing::postProcessing(){ postProcessing::postProcessing(){
@ -7,6 +8,10 @@ postProcessing::postProcessing(){
pthread_mutex_init(&mp, NULL); pthread_mutex_init(&mp, NULL);
mg=mp1; mg=mp1;
pthread_mutex_init(&mg, NULL); 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) { void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
/** write raw data file */ // /** write raw data file */
if (*correctionMask==0 && delflag==1) { // if (*correctionMask==0 && delflag==1) {
// delete [] fdata; // // delete [] fdata;
;
} else {
// ;
// } else {
@ -278,17 +286,25 @@ void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
if (delflag) { // if (delflag) {
deleteMerging(); // deleteMerging();
} else { // } else {
thisData=new detectorData(getMergedCounts(),getMergedErrors(),getMergedPositions(),getCurrentProgress(),(fname+ext).c_str(),np); thisData=new detectorData(getMergedCounts(),getMergedErrors(),getMergedPositions(),getCurrentProgress(),(fname+ext).c_str(),np);
// cout << "lock 2" << endl; // // cout << "lock 2" << endl;
pthread_mutex_lock(&mg); // pthread_mutex_lock(&mg);
finalDataQueue.push(thisData); // finalDataQueue.push(thisData);
// cout << "unlock 2" << endl; // // cout << "unlock 2" << endl;
pthread_mutex_unlock(&mg);
} // pthread_mutex_unlock(&mg);
if (dataReady) {
dataReady(thisData);
delete thisData;
}
// }
// cout << "lock 3" << endl; // cout << "lock 3" << endl;
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
} }
@ -309,21 +325,29 @@ void postProcessing::doProcessing(float *lfdata, int delflag, string fname) {
ang=NULL; ang=NULL;
} else { } else {
if (delflag) { // if (delflag) {
if (ffcdata) // if (ffcdata)
delete [] ffcdata; // delete [] ffcdata;
if (ffcerr) // if (ffcerr)
delete [] ffcerr; // delete [] ffcerr;
if ( ang) // if ( ang)
delete [] ang; // delete [] ang;
} else { // } else {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+ext).c_str(),getTotalNumberOfChannels()); 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(); incrementFileIndex();
#ifdef VERBOSE #ifdef VERBOSE

View File

@ -243,6 +243,7 @@ s
void registerDataCallback(int( *userCallback)(detectorData*)) {dataReady = userCallback;};
@ -364,6 +365,7 @@ s
/* virtual int getTotalNumberOfChannels()=0; */ /* virtual int getTotalNumberOfChannels()=0; */
int (*dataReady)(detectorData*);
}; };

View File

@ -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 */ (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 */ /* reads the encoder and returns the position */
float get_position() { float defaultGetPosition() {
#ifdef VERBOSE #ifdef VERBOSE
printf("Getting motor position \n"); printf("Getting motor position \n");
#endif #endif
@ -164,7 +164,7 @@ float get_position() {
/* moves the encoder to position p */ /* moves the encoder to position p */
int go_to_position(float p) { int defaultGoToPosition(float p) {
#ifdef VERBOSE #ifdef VERBOSE
printf("Setting motor position \n"); printf("Setting motor position \n");
#endif #endif
@ -191,7 +191,7 @@ int go_to_position(float p) {
/* moves the encoder to position p without waiting */ /* moves the encoder to position p without waiting */
int go_to_position_no_wait(float p) { int defaultGoToPositionNoWait(float p) {
#ifdef VERBOSE #ifdef VERBOSE
printf("Setting motor position no wait \n"); printf("Setting motor position no wait \n");
#endif #endif
@ -215,9 +215,6 @@ int go_to_position_no_wait(float p) {
return (int)p; return (int)p;
pos=p; pos=p;
return (int)pos; return (int)pos;
} }
@ -225,7 +222,7 @@ int go_to_position_no_wait(float p) {
/* reads I0 and returns the intensity */ /* reads I0 and returns the intensity */
float get_i0(int t) { float defaultGetI0(int t) {
#ifdef VERBOSE #ifdef VERBOSE
printf("Getting I0 readout \n"); printf("Getting I0 readout \n");
#endif #endif
@ -261,7 +258,7 @@ float get_i0(int t) {
} }
int connect_channels() { int defaultConnectChannels() {
#ifdef EPICS #ifdef EPICS
//double value = 256; //double value = 256;
/* channel name */ /* channel name */
@ -311,7 +308,7 @@ int connect_channels() {
return 0; return 0;
} }
int disconnect_channels() { int defaultDisconnectChannels() {
#ifdef EPICS #ifdef EPICS
/* close channel connect */ /* close channel connect */
disconnect_channel(ch_i0); 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;
}

View File

@ -13,7 +13,7 @@ Functions depending on the experimental setup should be defined here
#include <cadef.h> #include <cadef.h>
#include <epicsEvent.h> #include <epicsEvent.h>
#endif #endif
#include "detectorData.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -29,17 +29,15 @@ extern "C" {
#endif #endif
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);
float get_position(); float defaultGetPosition();
int go_to_position(float p); int defaultGoToPosition(float p);
int go_to_position_no_wait(float p); int defaultGoToPositionNoWait(float p);
int connect_channels(); int defaultConnectChannels();
int disconnect_channels(); int defaultDisconnectChannels();
float defaultGetI0(int t);
float get_i0(int t);
int defaultDataReadyFunc(detectorData* d);