mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-17 23:37:14 +02:00
client: removed slsDetectorutils and postprocessing. yet to compile, yet to add detpos index for every multi sls detector command and call from command interface, removed multiple threading, yet to interface with eriks single template for multiple threading
This commit is contained in:
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ MANAPIDIR = $(MANDIR)/manual-api
|
||||
TABSPACE := "\t"
|
||||
|
||||
|
||||
INCLUDES=-I. -I$(WD)/commonFiles -I$(LIBRARYDIR)/slsDetector -I$(LIBRARYDIR)/usersFunctions -I$(LIBRARYDIR)/multiSlsDetector -I$(LIBRARYDIR)/slsDetectorUtils -I$(LIBRARYDIR)/slsDetectorCommand -I$(LIBRARYDIR)/slsDetectorAnalysis -I$(LIBRARYDIR)/slsReceiverInterface -I$(LIBRARYRXRDIR)/include -I$(LIBRARYDIR)/threadFiles -I$(LIBRARYDIR)/sharedMemory -I$(ASM)
|
||||
INCLUDES=-I. -I$(WD)/commonFiles -I$(LIBRARYDIR)/slsDetector -I$(LIBRARYDIR)/usersFunctions -I$(LIBRARYDIR)/multiSlsDetector -I$(LIBRARYDIR)/slsReceiverInterface -I$(LIBRARYRXRDIR)/include -I$(LIBRARYDIR)/threadFiles -I$(LIBRARYDIR)/sharedMemory -I$(ASM)
|
||||
|
||||
INCLUDESRXR += -I. -I$(LIBRARYRXRDIR)/include -I$(WD)/commonFiles -I$(CALIBDIR) -I$(ASM)
|
||||
#LIBFLAGRXR +=
|
||||
|
@ -2,10 +2,8 @@ set(SOURCES
|
||||
multiSlsDetector/multiSlsDetector.cpp
|
||||
sharedMemory/SharedMemory.cpp
|
||||
slsDetector/slsDetectorUsers.cpp
|
||||
slsDetector/slsDetectorUtils.cpp
|
||||
slsDetector/slsDetectorCommand.cpp
|
||||
slsDetector/slsDetector.cpp
|
||||
slsDetectorAnalysis/postProcessing.cpp
|
||||
slsReceiverInterface/receiverInterface.cpp
|
||||
threadFiles/CondVar.cpp
|
||||
threadFiles/Mutex.cpp
|
||||
@ -21,9 +19,6 @@ include_directories(
|
||||
multiSlsDetector
|
||||
sharedMemory
|
||||
slsDetector
|
||||
slsDetectorUtils
|
||||
slsDetectorCommand
|
||||
slsDetectorAnalysis
|
||||
slsReceiverInterface
|
||||
threadFiles
|
||||
)
|
||||
@ -65,12 +60,10 @@ set(PUBLICHEADERS
|
||||
../commonFiles/sls_receiver_exceptions.h
|
||||
../commonFiles/utilties.h
|
||||
sharedMemory/SharedMemory.h
|
||||
slsDetector/slsDetectorUtils.h
|
||||
slsDetector/slsDetector.h
|
||||
slsDetector/slsDetectorBase.h
|
||||
slsDetector/slsDetectorUsers.h
|
||||
slsDetectorAnalysis/postProcessing.h
|
||||
slsDetectorAnalysis/detectorData.h
|
||||
slsDetector/detectorData.h
|
||||
multiSlsDetector/multiSlsDetector.h
|
||||
slsReceiverInterface/receiverInterface.h
|
||||
)
|
||||
|
@ -9,15 +9,15 @@ CFLAGS= -g -DC_ONLY -fPIC
|
||||
|
||||
DFLAGS= -g -DDACS_INT
|
||||
|
||||
INCLUDES?= -I../commonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis -IslsReceiverInterface -I../slsReceiverSoftware/include -IthreadFiles -IsharedMemory -I$(ASM)
|
||||
INCLUDES?= -I../commonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP -ImultiSlsDetector -IslsReceiverInterface -I../slsReceiverSoftware/include -IthreadFiles -IsharedMemory -I$(ASM)
|
||||
|
||||
#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/$(EPICS_HOST_ARCH) -Wl,-R/usr/local/epics/base/lib/$(EPICS_HOST_ARCH) -lca -lCom
|
||||
|
||||
LIBZMQDIR = ../commonFiles
|
||||
LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq
|
||||
|
||||
SRC_CLNT= slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp sharedMemory/SharedMemory.cpp ../commonFiles/utilities.cpp#../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp
|
||||
DEPSINCLUDES = ../commonFiles/sls_receiver_defs.h ../commonFiles/sls_receiver_funcs.h ../commonFiles/ansi.h ../commonFiles/sls_detector_defs.h ../commonFiles/sls_detector_funcs.h ../commonFiles/error_defs.h slsDetector/slsDetectorBase.h slsDetectorAnalysis/detectorData.h threadFiles/Global.h threadFiles/Task.h sharedMemory/SharedMemory.h ../commonFiles/sls_receiver_exceptions.h ../commonFiles/versionAPI.h ../commonFiles/utilities.h
|
||||
SRC_CLNT= slsDetector/slsDetectorCommand.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp sharedMemory/SharedMemory.cpp ../commonFiles/utilities.cpp#../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp
|
||||
DEPSINCLUDES = ../commonFiles/sls_receiver_defs.h ../commonFiles/sls_receiver_funcs.h ../commonFiles/ansi.h ../commonFiles/sls_detector_defs.h ../commonFiles/sls_detector_funcs.h ../commonFiles/error_defs.h slsDetector/slsDetectorBase.h slsDetector/detectorData.h threadFiles/Global.h threadFiles/Task.h sharedMemory/SharedMemory.h ../commonFiles/sls_receiver_exceptions.h ../commonFiles/versionAPI.h ../commonFiles/utilities.h
|
||||
|
||||
|
||||
|
||||
@ -77,6 +77,6 @@ install: package
|
||||
|
||||
install_inc:
|
||||
$(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR))
|
||||
cp -P slsDetector/slsDetectorUsers.h slsDetectorAnalysis/detectorData.h $(DESTDIR)
|
||||
cp -P slsDetector/slsDetectorUsers.h slsDetector/detectorData.h $(DESTDIR)
|
||||
|
||||
|
||||
|
@ -99,9 +99,7 @@ INPUT = ../commonfiles/communication_funcs.h \
|
||||
slsDetector/slsDetectorCommand.h \
|
||||
slsDetector/slsDetector.h \
|
||||
slsDetector/slsDetectorUsers.h \
|
||||
slsDetector/slsDetectorUtils.h \
|
||||
slsDetectorAnalysis/detectorData.h \
|
||||
slsDetectorAnalysis/postProcessing.h \
|
||||
slsDetector/detectorData.h \
|
||||
slsReceiverInterface/receiverInterface.h \
|
||||
threadFiles/CondVar.h \
|
||||
threadFiles/Global.h \
|
||||
|
@ -1 +0,0 @@
|
||||
../slsDetectorAnalysis/detectorData.h
|
@ -1 +0,0 @@
|
||||
../slsDetector/slsDetectorUsers.h
|
@ -1 +0,0 @@
|
||||
../../slsReceiverSoftware/include/slsReceiverUsers.h
|
@ -7,6 +7,7 @@
|
||||
#include "multiSlsDetectorClient.h"
|
||||
#include "multiSlsDetectorCommand.h"
|
||||
#include "utilities.h"
|
||||
#include "detectorData.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <iostream>
|
||||
@ -27,14 +28,30 @@ multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
|
||||
threadpool(0),
|
||||
totalProgress(0),
|
||||
progressIndex(0),
|
||||
acquisition_finished(NULL),
|
||||
measurement_finished(NULL),
|
||||
acqFinished_p(NULL),
|
||||
measFinished_p(NULL),
|
||||
threadedProcessing(1),
|
||||
jointhread(0),
|
||||
acquiringDone(0),
|
||||
fdata(0),
|
||||
thisData(0),
|
||||
acquisition_finished(0),
|
||||
acqFinished_p(0),
|
||||
measurement_finished(0),
|
||||
measFinished_p(0),
|
||||
progress_call(0),
|
||||
pProgressCallArg(0)
|
||||
pProgressCallArg(0),
|
||||
dataReady(0),
|
||||
pCallbackArg(0)
|
||||
{
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
mg=mp1;
|
||||
pthread_mutex_init(&mg, NULL);
|
||||
ms=mp1;
|
||||
pthread_mutex_init(&ms, NULL);
|
||||
|
||||
setupMultiDetector(verify, update);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -60,10 +77,6 @@ multiSlsDetector::~multiSlsDetector() {
|
||||
}
|
||||
|
||||
|
||||
bool multiSlsDetector::isMultiSlsDetectorClass() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void multiSlsDetector::setupMultiDetector(bool verify, bool update) {
|
||||
if (initSharedMemory(verify))
|
||||
// shared memory just created, so initialize the structure
|
||||
@ -4175,6 +4188,17 @@ void multiSlsDetector::registerProgressCallback(int( *func)(double,void*), void
|
||||
}
|
||||
|
||||
|
||||
void multiSlsDetector::registerDataCallback(int( *userCallback)(detectorData*, int, int, void*),
|
||||
void *pArg) {
|
||||
dataReady = userCallback;
|
||||
pCallbackArg = pArg;
|
||||
if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) {
|
||||
enableDataStreamingToClient(1);
|
||||
enableDataStreamingFromReceiver(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::setTotalProgress() {
|
||||
int nf=1, nc=1, ns=1, nm=1;
|
||||
|
||||
@ -4227,7 +4251,7 @@ void multiSlsDetector::incrementProgress() {
|
||||
cout << "\r" << flush;
|
||||
#endif
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void multiSlsDetector::setCurrentProgress(int i){
|
||||
@ -4282,8 +4306,8 @@ int multiSlsDetector::acquire(){
|
||||
}
|
||||
|
||||
// start processing thread
|
||||
if (*threadedProcessing)
|
||||
startThread();
|
||||
if (threadedProcessing)
|
||||
startProcessingThread();
|
||||
|
||||
|
||||
//resets frames caught in receiver
|
||||
@ -4320,7 +4344,7 @@ int multiSlsDetector::acquire(){
|
||||
// detector start
|
||||
startAndReadAll();
|
||||
|
||||
if (*threadedProcessing==0){
|
||||
if (threadedProcessing==0){
|
||||
processData();
|
||||
}
|
||||
|
||||
@ -4333,7 +4357,7 @@ int multiSlsDetector::acquire(){
|
||||
pthread_mutex_unlock(&mg);
|
||||
} else {
|
||||
pthread_mutex_unlock(&mg);
|
||||
if (*threadedProcessing && dataReady)
|
||||
if (threadedProcessing && dataReady)
|
||||
sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui
|
||||
}
|
||||
}
|
||||
@ -4357,7 +4381,7 @@ int multiSlsDetector::acquire(){
|
||||
|
||||
|
||||
// waiting for the data processing thread to finish!
|
||||
if (*threadedProcessing) {
|
||||
if (threadedProcessing) {
|
||||
setJoinThread(1);
|
||||
|
||||
//let processing thread continue and checkjointhread
|
||||
@ -4388,3 +4412,144 @@ int multiSlsDetector::acquire(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int multiSlsDetector::setThreadedProcessing(int enable=-1) {
|
||||
if (enable>=0)
|
||||
threadedProcessing=enable;
|
||||
return threadedProcessing;
|
||||
}
|
||||
|
||||
|
||||
void multiSlsDetector::startProcessingThread() {
|
||||
|
||||
setTotalProgress();
|
||||
#ifdef VERBOSE
|
||||
std::cout << "start thread stuff" << std::endl;
|
||||
#endif
|
||||
|
||||
pthread_attr_t tattr;
|
||||
int ret;
|
||||
sched_param param, mparam;
|
||||
int policy= SCHED_OTHER;
|
||||
|
||||
// set the priority; others are unchanged
|
||||
//newprio = 30;
|
||||
mparam.sched_priority =1;
|
||||
param.sched_priority =1;
|
||||
|
||||
/* Initialize and set thread detached attribute */
|
||||
pthread_attr_init(&tattr);
|
||||
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), policy, &mparam);
|
||||
|
||||
|
||||
ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this);
|
||||
|
||||
if (ret)
|
||||
printf("ret %d\n", ret);
|
||||
|
||||
pthread_attr_destroy(&tattr);
|
||||
|
||||
// scheduling parameters of target thread
|
||||
ret = pthread_setschedparam(dataProcessingThread, policy, ¶m);
|
||||
}
|
||||
|
||||
|
||||
void* multiSlsDetector::startProcessData(void *n) {
|
||||
postProcessing *myDet=(postProcessing*)n;
|
||||
myDet->processData();
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
||||
void* multiSlsDetector::processData() {
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
return 0;
|
||||
} //receiver
|
||||
else{
|
||||
//cprintf(RED,"In post processing threads\n");
|
||||
|
||||
if(dataReady) {
|
||||
readFrameFromReceiver();
|
||||
}
|
||||
//only update progress
|
||||
else{
|
||||
int caught = -1;
|
||||
char c;
|
||||
int ifp;
|
||||
while(true){
|
||||
|
||||
// set only in startThread
|
||||
if (*threadedProcessing==0)
|
||||
setTotalProgress();
|
||||
|
||||
// to exit acquire by typing q
|
||||
ifp=kbhit();
|
||||
if (ifp!=0){
|
||||
c=fgetc(stdin);
|
||||
if (c=='q') {
|
||||
std::cout<<"Caught the command to stop acquisition"<<std::endl;
|
||||
stopAcquisition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//get progress
|
||||
if(setReceiverOnline() == ONLINE_FLAG){
|
||||
pthread_mutex_lock(&mg);
|
||||
caught = getFramesCaughtByAnyReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
|
||||
//updating progress
|
||||
if(caught!= -1){
|
||||
setCurrentProgress(caught);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
std::cout << "caught:" << caught << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// exiting loop
|
||||
if (*threadedProcessing==0)
|
||||
break;
|
||||
if (checkJoinThread()){
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::checkJoinThread() {
|
||||
int retval;
|
||||
pthread_mutex_lock(&mp);
|
||||
retval=jointhread;
|
||||
pthread_mutex_unlock(&mp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void multiSlsDetector::setJoinThread( int v) {
|
||||
pthread_mutex_lock(&mp);
|
||||
jointhread=v;
|
||||
pthread_mutex_unlock(&mp);
|
||||
}
|
||||
|
||||
|
||||
int multiSlsDetector::kbhit() {
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0
|
||||
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
|
||||
return FD_ISSET(STDIN_FILENO, &fds);
|
||||
}
|
||||
|
@ -7,13 +7,13 @@
|
||||
* @author Anna Bergamaschi
|
||||
*/
|
||||
|
||||
#include "slsDetectorUtils.h"
|
||||
#include "slsDetectorBase.h"
|
||||
|
||||
class slsDetector;
|
||||
class SharedMemory;
|
||||
class ThreadPool;
|
||||
class ZmqSocket;
|
||||
|
||||
class detectorData;
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -23,7 +23,7 @@ class ZmqSocket;
|
||||
#define SHORT_STRING_LENGTH 50
|
||||
#define DATE_LENGTH 30
|
||||
|
||||
class multiSlsDetector : public postProcessing {
|
||||
class multiSlsDetector : public slsDetectorBase {
|
||||
|
||||
private:
|
||||
|
||||
@ -142,12 +142,6 @@ public:
|
||||
*/
|
||||
virtual ~multiSlsDetector();
|
||||
|
||||
/**
|
||||
* returns true. Used when reference is slsDetectorUtils and to determine
|
||||
* if command can be implemented as slsDetector/multiSlsDetector object/
|
||||
*/
|
||||
bool isMultiSlsDetectorClass();
|
||||
|
||||
/**
|
||||
* Creates/open shared memory, initializes detector structure and members
|
||||
* Called by constructor/ set hostname / read config file
|
||||
@ -1450,6 +1444,17 @@ public:
|
||||
*/
|
||||
void registerProgressCallback(int( *func)(double,void*), void *pArg);
|
||||
|
||||
/**
|
||||
* register calbback for accessing detector final data,
|
||||
* also enables data streaming in client and receiver
|
||||
* @param userCallback function for plotting/analyzing the data.
|
||||
* Its arguments are
|
||||
* the data structure d and the frame number f,
|
||||
* s is for subframe number for eiger for 32 bit mode
|
||||
* @param pArg argument
|
||||
*/
|
||||
void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg);
|
||||
|
||||
/**
|
||||
* Performs a complete acquisition
|
||||
* resets frames caught in receiver, starts receiver, starts detector,
|
||||
@ -1459,6 +1464,12 @@ public:
|
||||
*/
|
||||
int acquire();
|
||||
|
||||
/**
|
||||
* Set/get if the data processing thread si enabled
|
||||
* @param enable 0 no data processing thread, 1 separate thread, -1 get
|
||||
*/
|
||||
int setThreadedProcessing(int enable=-1);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initialize (open/create) shared memory for the sharedMultiDetector structure
|
||||
@ -1528,6 +1539,39 @@ private:
|
||||
*/
|
||||
void setCurrentProgress(int i=0);
|
||||
|
||||
/**
|
||||
* Start data processing thread
|
||||
*/
|
||||
void startProcessingThread();
|
||||
|
||||
/**
|
||||
* Static function to call processing thread
|
||||
*/
|
||||
static void* startProcessData(void *n);
|
||||
|
||||
/**
|
||||
* Combines data from all readouts and gives it to the gui
|
||||
* or just gives progress of acquisition by polling receivers
|
||||
*/
|
||||
void* processData();
|
||||
|
||||
/**
|
||||
* Check if processing thread is ready to join main thread
|
||||
* @returns true if ready, else false
|
||||
*/
|
||||
int checkJoinThread();
|
||||
|
||||
/**
|
||||
* Main thread sets if the processing thread should join it
|
||||
* @param v true if it should join, else false
|
||||
*/
|
||||
void setJoinThread(int v);
|
||||
|
||||
/**
|
||||
* Listen to key event to stop acquiring
|
||||
* when using acquire command
|
||||
*/
|
||||
int kbhit(void);
|
||||
|
||||
|
||||
/** Multi detector Id */
|
||||
@ -1552,20 +1596,54 @@ private:
|
||||
ThreadPool* threadpool;
|
||||
|
||||
|
||||
int totalProgress;
|
||||
int progressIndex;
|
||||
|
||||
int (*acquisition_finished)(double,int,void*);
|
||||
int (*measurement_finished)(int,int,void*);
|
||||
void *acqFinished_p, *measFinished_p;
|
||||
int (*progress_call)(double,void*);
|
||||
void *pProgressCallArg;
|
||||
|
||||
/** semaphore to let postprocessing thread continue for next scan/measurement */
|
||||
sem_t sem_newRTAcquisition;
|
||||
|
||||
/** semaphore to let main thread know it got all the dummy packets (also from ext. process) */
|
||||
sem_t sem_endRTAcquisition;
|
||||
|
||||
int totalProgress;
|
||||
int progressIndex;
|
||||
/** mutex to synchronize main and data processing threads */
|
||||
pthread_mutex_t mp;
|
||||
|
||||
/** mutex to synchronizedata processing and plotting threads */
|
||||
pthread_mutex_t mg;
|
||||
|
||||
/** mutex to synchronize slsdetector threads */
|
||||
pthread_mutex_t ms;
|
||||
|
||||
int threadedProcessing;
|
||||
|
||||
/** sets when the acquisition is finished */
|
||||
int jointhread;
|
||||
|
||||
/** set when detector finishes acquiring */
|
||||
int acquiringDone;
|
||||
|
||||
/** the data processing thread */
|
||||
pthread_t dataProcessingThread;
|
||||
|
||||
double *fdata;
|
||||
detectorData *thisData;
|
||||
|
||||
int (*acquisition_finished)(double,int,void*);
|
||||
void *acqFinished_p;
|
||||
|
||||
int (*measurement_finished)(int,int,void*);
|
||||
void *measFinished_p;
|
||||
|
||||
int (*progress_call)(double,void*);
|
||||
void *pProgressCallArg;
|
||||
|
||||
int (*dataReady)(detectorData*,int, int, void*);
|
||||
void *pCallbackArg;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -14,54 +14,43 @@
|
||||
|
||||
class multiSlsDetectorCommand : public slsDetectorCommand {
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
|
||||
multiSlsDetectorCommand(multiSlsDetector *det) : slsDetectorCommand(det) {myDet=det;};
|
||||
multiSlsDetectorCommand(multiSlsDetector *det) : slsDetectorCommand(det) {myDet=det;};
|
||||
|
||||
|
||||
/* /\** */
|
||||
/* executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing */
|
||||
/* \param narg number of arguments */
|
||||
/* \param args array of string arguments */
|
||||
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
|
||||
/* \returns answer string */
|
||||
/* *\/ */
|
||||
/* /\** */
|
||||
/* executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing */
|
||||
/* \param narg number of arguments */
|
||||
/* \param args array of string arguments */
|
||||
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
|
||||
/* \returns answer string */
|
||||
/* *\/ */
|
||||
|
||||
std::string executeLine(int narg, char *args[], int action, int id=-1) { \
|
||||
std::string s; \
|
||||
if (id>=0) {
|
||||
slsDetector *d=myDet->getSlsDetector(id); \
|
||||
if (d) { \
|
||||
slsDetectorCommand *cmd=new slsDetectorCommand(d); \
|
||||
s=cmd->executeLine(narg, args, action); \
|
||||
if(d->getErrorMask()) \
|
||||
myDet->setErrorMask((myDet->getErrorMask())|(1<<id)); \
|
||||
delete cmd;
|
||||
} else
|
||||
s=std::string("detector does no exist"); \
|
||||
} else \
|
||||
s=slsDetectorCommand::executeLine(narg,args,action); \
|
||||
return s;
|
||||
};
|
||||
std::string executeLine(int narg, char *args[], int action, int id=-1) { \
|
||||
std::string s; \
|
||||
s=slsDetectorCommand::executeLine(narg,args,action, id); \
|
||||
return s;
|
||||
};
|
||||
|
||||
/**
|
||||
* calls executeLine with PUT_ACTION
|
||||
*/
|
||||
std::string putCommand(int narg, char *args[], int pos=-1){\
|
||||
return executeLine(narg, args,slsDetectorDefs::PUT_ACTION,pos);\
|
||||
};
|
||||
/**
|
||||
* calls executeLine with GET_ACTION
|
||||
*/
|
||||
std::string getCommand(int narg, char *args[], int pos=-1){\
|
||||
return executeLine(narg, args,slsDetectorDefs::GET_ACTION,pos);\
|
||||
};
|
||||
/**
|
||||
* calls executeLine with PUT_ACTION
|
||||
*/
|
||||
std::string putCommand(int narg, char *args[], int pos=-1){\
|
||||
return executeLine(narg, args,slsDetectorDefs::PUT_ACTION,pos);\
|
||||
};
|
||||
/**
|
||||
* calls executeLine with GET_ACTION
|
||||
*/
|
||||
std::string getCommand(int narg, char *args[], int pos=-1){\
|
||||
return executeLine(narg, args,slsDetectorDefs::GET_ACTION,pos);\
|
||||
};
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
|
||||
multiSlsDetector *myDet;
|
||||
multiSlsDetector *myDet;
|
||||
|
||||
|
||||
};
|
||||
|
@ -1 +0,0 @@
|
||||
AXIS_BUILDTYPE ?= cris-axis-linux-gnu
|
@ -1,46 +0,0 @@
|
||||
# $Id: Makefile,v 1.1.1.1 2006/02/04 03:35:01 freza Exp $
|
||||
# first compile
|
||||
# make cris-axis-linux-gnu
|
||||
|
||||
AXIS_USABLE_LIBS = UCLIBC GLIBC
|
||||
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
|
||||
|
||||
PROGS= mythenDetectorServer
|
||||
|
||||
INSTDIR= $(prefix)/bin
|
||||
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)
|
||||
|
||||
VFLAGS=
|
||||
#-DVERBOSE
|
||||
#-DVERYVERBOSE
|
||||
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DDACS_INT $(VFLAGS)
|
||||
#-Werror
|
||||
|
||||
LDLIBS+= -lm
|
||||
|
||||
mythen: clean versioning $(PROGS)
|
||||
all: versioning $(PROGS)
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
versioning:
|
||||
@echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;`
|
||||
|
||||
|
||||
$(PROGS): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) -o $@ -DVERBOSE
|
||||
|
||||
install: $(PROGS)
|
||||
$(INSTALL) -d $(INSTDIR)
|
||||
$(INSTALL) -m $(INSTMODE) $(PROGS) $(INSTDIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGS) $(PICASSO) *.o
|
||||
|
||||
depend:
|
||||
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null
|
||||
|
@ -1,40 +0,0 @@
|
||||
# $Id: Makefile,v 1.1.1.1 2006/02/04 03:35:01 freza Exp $
|
||||
# first compile
|
||||
# make cris-axis-linux-gnu
|
||||
|
||||
AXIS_USABLE_LIBS = UCLIBC GLIBC
|
||||
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
|
||||
|
||||
PROGS= dummy
|
||||
|
||||
INSTDIR= $(prefix)/bin
|
||||
INSTMODE= 0777
|
||||
|
||||
SRCS= dummy_main.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 -DVERBOSE
|
||||
#-Werror
|
||||
|
||||
LDLIBS+= -lm
|
||||
|
||||
all: versioning $(PROGS)
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
$(PROGS): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
install: $(PROGS)
|
||||
$(INSTALL) -d $(INSTDIR)
|
||||
$(INSTALL) -m $(INSTMODE) $(PROGS) $(INSTDIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGS) *.o
|
||||
|
||||
depend:
|
||||
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null
|
||||
|
||||
versioning:
|
||||
@echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;`
|
@ -1,49 +0,0 @@
|
||||
# $Id: Makefile,v 1.1.1.1 2006/02/04 03:35:01 freza Exp $
|
||||
# first compile
|
||||
# make cris-axis-linux-gnu
|
||||
|
||||
AXIS_USABLE_LIBS = UCLIBC GLIBC
|
||||
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
|
||||
|
||||
PROGS= mythenDetectorServer
|
||||
PICASSO= picassoDetectorServer
|
||||
PICASSOFLAGS= -DPICASSOD
|
||||
|
||||
INSTDIR= $(prefix)/bin
|
||||
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 -DVERYVERBOSE -DPICASSOD
|
||||
#-Werror
|
||||
|
||||
LDLIBS+= -lm
|
||||
|
||||
picasso: $(PICASSO)
|
||||
mythen: versioning $(PROGS)
|
||||
all: versioning $(PROGS) $(PICASSO)
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
$(PROGS): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) -o $@
|
||||
|
||||
$(PICASSO): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) $(CFLAGS) $(PICASSOFLAGS) -o $@
|
||||
|
||||
|
||||
install: $(PROGS)
|
||||
$(INSTALL) -d $(INSTDIR)
|
||||
$(INSTALL) -m $(INSTMODE) $(PROGS) $(INSTDIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGS) $(PICASSO) *.o
|
||||
|
||||
depend:
|
||||
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null
|
||||
|
||||
versioning:
|
||||
@echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;`
|
@ -1,18 +0,0 @@
|
||||
DESTDIR?= ./
|
||||
PROGS= $(DESTDIR)/mythenVirtualServer
|
||||
|
||||
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 -DDACS_INT $(VFLAGS) -DVIRTUAL -DVERBOSE
|
||||
|
||||
LDLIBS+= -lm
|
||||
mythenVirtualServer : clean $(PROGS)
|
||||
|
||||
$(PROGS): $(SRCS)
|
||||
gcc $(LDFLAGS) $(SRCS) $(LDLIBS) $(CFLAGS) -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o $(PROGS)
|
||||
|
@ -1 +0,0 @@
|
||||
../../slsReceiverSoftware/include/ansi.h
|
File diff suppressed because it is too large
Load Diff
@ -1,153 +0,0 @@
|
||||
#ifndef FIRMWARE_FUNCS_H
|
||||
#define FIRMWARE_FUNCS_H
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/page.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
int mapCSP0(void);
|
||||
u_int32_t bus_w(u_int32_t offset, u_int32_t data);
|
||||
u_int32_t bus_r(u_int32_t offset);
|
||||
|
||||
|
||||
u_int32_t putout(char *s, int modnum);
|
||||
u_int32_t readin(int modnum);
|
||||
u_int32_t setClockDivider(int d);
|
||||
u_int32_t getClockDivider();
|
||||
u_int32_t setSetLength(int d);
|
||||
u_int32_t getSetLength();
|
||||
u_int32_t setWaitStates(int d);
|
||||
u_int32_t getWaitStates();
|
||||
u_int32_t setTotClockDivider(int d);
|
||||
u_int32_t getTotClockDivider();
|
||||
u_int32_t setTotDutyCycle(int d);
|
||||
u_int32_t getTotDutyCycle();
|
||||
|
||||
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
|
||||
int getExtSignal(int d);
|
||||
|
||||
u_int32_t setFPGASignal(int d, enum externalSignalFlag mode);
|
||||
int getFPGASignal(int d);
|
||||
|
||||
int setTiming(int t);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int setConfigurationRegister(int d);
|
||||
int setToT(int d);
|
||||
int setContinousReadOut(int d);
|
||||
|
||||
int setDACRegister(int idac, int val, int imod);
|
||||
|
||||
|
||||
u_int64_t getMcsNumber();
|
||||
u_int32_t getMcsVersion();
|
||||
u_int32_t testFifos(void);
|
||||
u_int32_t testFpga(void);
|
||||
u_int32_t testRAM(void);
|
||||
int testBus(void);
|
||||
int64_t set64BitReg(int64_t value, int aLSB, int aMSB);
|
||||
int64_t get64BitReg(int aLSB, int aMSB);
|
||||
|
||||
int64_t setFrames(int64_t value);
|
||||
int64_t getFrames();
|
||||
|
||||
int64_t setExposureTime(int64_t value);
|
||||
int64_t getExposureTime();
|
||||
|
||||
int64_t setGates(int64_t value);
|
||||
int64_t getGates();
|
||||
|
||||
int64_t setDelay(int64_t value);
|
||||
int64_t getDelay();
|
||||
|
||||
int64_t setPeriod(int64_t value);
|
||||
int64_t getPeriod();
|
||||
|
||||
int64_t setTrains(int64_t value);
|
||||
int64_t getTrains();
|
||||
|
||||
int64_t setProbes(int64_t value);
|
||||
int64_t getProbes();
|
||||
|
||||
int64_t getProgress();
|
||||
int64_t setProgress();
|
||||
|
||||
int64_t getActualTime();
|
||||
int64_t getMeasurementTime();
|
||||
|
||||
u_int32_t runBusy(void);
|
||||
u_int32_t runState(void);
|
||||
u_int32_t dataPresent(void);
|
||||
|
||||
|
||||
u_int32_t startStateMachine();
|
||||
u_int32_t stopStateMachine();
|
||||
u_int32_t startReadOut();
|
||||
u_int32_t fifoReset(void);
|
||||
u_int32_t fifoReadCounter(int fifonum);
|
||||
u_int32_t fifoReadStatus();
|
||||
|
||||
|
||||
u_int32_t fifo_full(void);
|
||||
|
||||
|
||||
|
||||
u_int32_t* fifo_read_event();
|
||||
u_int32_t* decode_data(int* datain);
|
||||
//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout);
|
||||
int setDynamicRange(int dr);
|
||||
int getDynamicRange();
|
||||
int getNModBoard();
|
||||
int setNMod(int n);
|
||||
int setStoreInRAM(int b);
|
||||
int allocateRAM();
|
||||
int clearRAM();
|
||||
|
||||
|
||||
int setMaster(int f);
|
||||
int setSynchronization(int s);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
u_int32_t setNBits(u_int32_t);
|
||||
u_int32_t getNBits();
|
||||
*/
|
||||
|
||||
/*
|
||||
//move to mcb_funcs?
|
||||
|
||||
int readOutChan(int *val);
|
||||
u_int32_t getModuleNumber(int modnum);
|
||||
int testShiftIn(int imod);
|
||||
int testShiftOut(int imod);
|
||||
int testShiftStSel(int imod);
|
||||
int testDataInOut(int num, int imod);
|
||||
int testExtPulse(int imod);
|
||||
int testExtPulseMux(int imod, int ow);
|
||||
int testDataInOutMux(int imod, int ow, int num);
|
||||
int testOutMux(int imod);
|
||||
int testFpgaMux(int imod);
|
||||
int calibration_sensor(int num, int *values, int *dacs) ;
|
||||
int calibration_chip(int num, int *values, int *dacs);
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
@ -1,9 +0,0 @@
|
||||
Path: slsDetectorsPackage/slsDetectorSoftware/mythenDetectorServer
|
||||
URL:
|
||||
Repository Root:
|
||||
Repsitory UUID:
|
||||
Revision: 0
|
||||
Branch:
|
||||
Last Changed Author: _
|
||||
Last Changed Rev: 0
|
||||
Last Changed Date: 2018-01-30 10:42:45.000000000 +0100 ./Makefile
|
@ -1,6 +0,0 @@
|
||||
#define GITURL "URL:"
|
||||
#define GITREPUUID "UUID:"
|
||||
#define GITAUTH "_"
|
||||
#define GITREV 0x0
|
||||
#define GITDATE 0x20180130
|
||||
#define GITBRANCH "Branch:"
|
@ -1,6 +0,0 @@
|
||||
#define GITURL ""
|
||||
#define GITREPUUID ""
|
||||
#define GITAUTH ""
|
||||
#define GITREV ""
|
||||
#define GITDATE ""
|
||||
#define GITBRANCH ""
|
File diff suppressed because it is too large
Load Diff
@ -1,157 +0,0 @@
|
||||
#ifdef MCB_FUNCS
|
||||
|
||||
#ifndef MCB_FUNCS_H
|
||||
#define MCB_FUNCS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#define RGPRVALS {100,50,200}
|
||||
#define RGSH1VALS {300,200,400}
|
||||
#define RGSH2VALS {260,300,260}
|
||||
|
||||
#define DEFAULTGAIN {11.66,9.32,14.99}
|
||||
#define DEFAULTOFFSET {817.5,828.6,804.2}
|
||||
|
||||
|
||||
|
||||
// DAC definitions
|
||||
|
||||
enum {VTRIM,VTHRESH,RGSH1,RGSH2,VCAL,RGPR};
|
||||
|
||||
/* DAC adresses */
|
||||
#define DACCS {0,0,1,1,2,2}
|
||||
#define DACADDR {0,1,0,1,0,1}
|
||||
|
||||
//dynamic range
|
||||
#define MAX5523
|
||||
#ifndef MAX5523
|
||||
#define MAX5533
|
||||
#endif
|
||||
#ifdef MAX5533
|
||||
#define DAC_DR 4096
|
||||
#endif
|
||||
#ifdef MAX5523
|
||||
#define DAC_DR 1024
|
||||
#endif
|
||||
|
||||
|
||||
//reference voltage
|
||||
#define DAC_REFOUT1
|
||||
#ifdef DAC_REFOUT2
|
||||
#define DAC_MAX 2.425
|
||||
#define DAC_REFOUT 2
|
||||
#define DAC_REFOUT1
|
||||
#endif
|
||||
#ifdef DAC_REFOUT3
|
||||
#define DAC_MAX 3.885
|
||||
#define DAC_REFOUT 3
|
||||
#define DAC_REFOUT1
|
||||
#endif
|
||||
#ifdef DAC_REFOUT0
|
||||
#define DAC_MAX 1.214
|
||||
#define DAC_REFOUT 0
|
||||
#endif
|
||||
#ifdef DAC_REFOUT1
|
||||
#define DAC_MAX 1.940
|
||||
#define DAC_REFOUT 1
|
||||
#endif
|
||||
|
||||
/* dac calibration constants */
|
||||
|
||||
#define VA 1.11
|
||||
|
||||
#define CVTRIM 52.430851
|
||||
#define BVTRIM -0.102022
|
||||
#define AVTRIM 0.000050
|
||||
|
||||
#define PARTREF {100,1.55,-2.5,-2.5,0,-2.5}
|
||||
#define PARTR1 {78,10,10,10,10,10}
|
||||
#define PARTR2 {0,4.7,27,47,22,47}
|
||||
|
||||
|
||||
//chip shiftin register meaning
|
||||
#define OUTMUX_OFFSET 20
|
||||
#define PROBES_OFFSET 4
|
||||
#define OUTBUF_OFFSET 0
|
||||
|
||||
|
||||
int initDetector();
|
||||
int copyChannel(sls_detector_channel *destChan, sls_detector_channel *srcChan);
|
||||
int copyChip(sls_detector_chip *destChip, sls_detector_chip *srcChip);
|
||||
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
|
||||
|
||||
/* Register commands */
|
||||
int clearDACSregister(int imod );
|
||||
int nextDAC(int imod );
|
||||
int clearCSregister(int imod );
|
||||
int setCSregister(int imod );
|
||||
int nextChip(int imod );
|
||||
int firstChip(int imod );
|
||||
int clearSSregister(int imod );
|
||||
int setSSregister(int imod );
|
||||
int nextStrip(int imod );
|
||||
int selChannel(int strip,int imod );
|
||||
int selChip(int chip,int imod );
|
||||
int selMod(int mod,int imod );
|
||||
|
||||
/* DACs routines */
|
||||
int program_one_dac(int addr, int value,int imod );
|
||||
int set_one_dac(int imod);
|
||||
int initDAC(int dac_cs, int dac_addr, int value,int imod );
|
||||
int initDACs(int* v,int imod );
|
||||
int setSettings(int i);
|
||||
dacs_t initDACbyIndex(int ind,dacs_t val, int imod);
|
||||
dacs_t initDACbyIndexDACU(int ind,dacs_t val, int imod);
|
||||
dacs_t getDACbyIndexDACU(int ind, int imod);
|
||||
int getThresholdEnergy();
|
||||
int setThresholdEnergy(int ethr);
|
||||
/* Initialization*/
|
||||
int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod );
|
||||
int initChannelbyNumber(sls_detector_channel myChan);
|
||||
int getChannelbyNumber(sls_detector_channel*);
|
||||
|
||||
int getTrimbit(int imod, int ichip, int ichan);
|
||||
|
||||
int initChip(int obe, int ow,int imod );
|
||||
|
||||
int initChipWithProbes(int obe, int ow,int nprobes, int imod);
|
||||
//int getNProbes();
|
||||
|
||||
int initChipbyNumber(sls_detector_chip myChip);
|
||||
int getChipbyNumber(sls_detector_chip*);
|
||||
int initMCBregisters(int cm,int imod );
|
||||
int initModulebyNumber(sls_detector_module);
|
||||
int getModulebyNumber(sls_detector_module*);
|
||||
|
||||
/* To chips */
|
||||
int clearCounter(int imod );
|
||||
int clearOutReg(int imod);
|
||||
int setOutReg(int imod );
|
||||
int extPulse(int ncal,int imod );
|
||||
int calPulse(int ncal,int imod );
|
||||
int counterClear(int imod );
|
||||
int countEnable(int imod );
|
||||
int counterSet(int imod );
|
||||
|
||||
|
||||
/* moved from firmware_funcs */
|
||||
|
||||
int readOutChan(int *val);
|
||||
|
||||
int getModuleNumber(int modnum);
|
||||
int testShiftIn(int imod);
|
||||
int testShiftOut(int imod);
|
||||
int testShiftStSel(int imod);
|
||||
int testDataInOut(int num, int imod);
|
||||
int testExtPulse(int imod);
|
||||
int testExtPulseMux(int imod, int ow);
|
||||
int testDataInOutMux(int imod, int ow, int num);
|
||||
int testOutMux(int imod);
|
||||
int testFpgaMux(int imod);
|
||||
int calibration_sensor(int num, int *values, int *dacs) ;
|
||||
int calibration_chip(int num, int *values, int *dacs);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,42 +0,0 @@
|
||||
#ifndef SERVER_DEFS_H
|
||||
#define SERVER_DEFS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Hardware definitions
|
||||
|
||||
#define NCHAN 128
|
||||
#define NCHIP 12 //10 modified for PICASSO
|
||||
#define NMAXMODX 24
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD NMAXMODX*NMAXMODY
|
||||
#define NDAC 6
|
||||
#define NADC 0
|
||||
|
||||
#define NCHANS NCHAN*NCHIP*NMAXMOD
|
||||
#define NDACS NDAC*NMAXMOD
|
||||
|
||||
#define NTRIMBITS 6
|
||||
#define NCOUNTBITS 24
|
||||
|
||||
//#define TRIM_DR ((2**NTRIMBITS)-1)
|
||||
//#define COUNT_DR ((2**NCOUNTBITS)-1)
|
||||
#define TRIM_DR (((int)pow(2,NTRIMBITS))-1)
|
||||
#define COUNT_DR (((int)pow(2,NCOUNTBITS))-1)
|
||||
|
||||
|
||||
#define ALLMOD 0xffff
|
||||
#define ALLFIFO 0xffff
|
||||
|
||||
#ifdef VIRTUAL
|
||||
#define DEBUGOUT
|
||||
#endif
|
||||
|
||||
#define CLK_FREQ 100E+6
|
||||
|
||||
|
||||
#define THIS_SOFTWARE_VERSION 0x20090205
|
||||
#endif
|
@ -1,184 +0,0 @@
|
||||
#ifndef REGISTERS_H
|
||||
#define REGISTERS_H
|
||||
|
||||
|
||||
|
||||
/* Definitions for FPGA*/
|
||||
#define CSP0 0x90000000 // Base Addresse CSP0
|
||||
#define CSP4 0xa0000000 // Base Addresse CSP4
|
||||
|
||||
//#define MEM_SIZE 0xFFFFFF // map so much memory
|
||||
#define MEM_SIZE 0xFFFFFFF // map so much memory
|
||||
|
||||
|
||||
|
||||
/* registers defined in FPGA */
|
||||
#define FIX_PATT_REG 0x000000
|
||||
#define FPGA_VERSION_REG 0x001000
|
||||
#define DUMMY_REG 0x002000
|
||||
#define CONTROL_REG 0x003000
|
||||
#define STATUS_REG 0x004000
|
||||
#define CONFIG_REG 0x005000
|
||||
#define SPEED_REG 0x006000
|
||||
#define EXT_SIGNAL_REG 0x007000
|
||||
#define SET_NBITS_REG 0x008000
|
||||
#define LOOK_AT_ME_REG 0x009000
|
||||
|
||||
#define SET_FRAMES_LSB_REG 0x00A000
|
||||
#define SET_FRAMES_MSB_REG 0x00B000
|
||||
#define GET_FRAMES_LSB_REG 0x00C000
|
||||
#define GET_FRAMES_MSB_REG 0x00D000
|
||||
|
||||
#define SET_EXPTIME_LSB_REG 0x00E000
|
||||
#define SET_EXPTIME_MSB_REG 0x00F000
|
||||
#define GET_EXPTIME_LSB_REG 0x010000
|
||||
#define GET_EXPTIME_MSB_REG 0x011000
|
||||
|
||||
#define SET_GATES_LSB_REG 0x012000
|
||||
#define SET_GATES_MSB_REG 0x013000
|
||||
#define GET_GATES_LSB_REG 0x014000
|
||||
#define GET_GATES_MSB_REG 0x015000
|
||||
|
||||
#define SET_PERIOD_LSB_REG 0x016000
|
||||
#define SET_PERIOD_MSB_REG 0x017000
|
||||
#define GET_PERIOD_LSB_REG 0x018000
|
||||
#define GET_PERIOD_MSB_REG 0x019000
|
||||
|
||||
#define SET_DELAY_LSB_REG 0x01A000
|
||||
#define SET_DELAY_MSB_REG 0x01B000
|
||||
#define GET_DELAY_LSB_REG 0x01C000
|
||||
#define GET_DELAY_MSB_REG 0x01D000
|
||||
|
||||
#define SET_TRAINS_LSB_REG 0x01E000
|
||||
#define SET_TRAINS_MSB_REG 0x01F000
|
||||
#define GET_TRAINS_LSB_REG 0x020000
|
||||
#define GET_TRAINS_MSB_REG 0x021000
|
||||
|
||||
|
||||
#define GET_SHIFT_IN_REG 0x022000
|
||||
|
||||
#define GET_MEASUREMENT_TIME_LSB_REG 0x023000
|
||||
#define GET_MEASUREMENT_TIME_MSB_REG 0x024000
|
||||
|
||||
#define GET_ACTUAL_TIME_LSB_REG 0x025000
|
||||
#define GET_ACTUAL_TIME_MSB_REG 0x026000
|
||||
|
||||
#define MOD_DACS1_REG 0x030000
|
||||
#define MOD_DACS2_REG 0x040000
|
||||
|
||||
#define MCB_CNTRL_REG_OFF 0x100000
|
||||
#define MCB_DOUT_REG_OFF 0x200000
|
||||
#define FIFO_CNTRL_REG_OFF 0x300000
|
||||
#define FIFO_COUNTR_REG_OFF 0x400000
|
||||
#define FIFO_DATA_REG_OFF 0x800000
|
||||
|
||||
#define SHIFTMOD 2
|
||||
#define SHIFTFIFO 9
|
||||
|
||||
|
||||
|
||||
/* values defined for FPGA */
|
||||
#define MCSNUM 0x0
|
||||
#define MCSVERSION 0x101
|
||||
#define FIXED_PATT_VAL 0xacdc1980
|
||||
#define FPGA_VERSION_VAL 0x00090514
|
||||
#define FPGA_INIT_PAT 0x60008
|
||||
#define FPGA_INIT_ADDR 0xb0000000
|
||||
|
||||
/* for control register */
|
||||
#define START_ACQ_BIT 0x00000001
|
||||
#define STOP_ACQ_BIT 0x00000002
|
||||
#define START_FIFOTEST_BIT 0x00000004 // ?????
|
||||
#define STOP_FIFOTEST_BIT 0x00000008 // ??????
|
||||
#define START_READOUT_BIT 0x00000010
|
||||
#define STOP_READOUT_BIT 0x00000020
|
||||
#define START_EXPOSURE_BIT 0x00000040
|
||||
#define STOP_EXPOSURE_BIT 0x00000080
|
||||
#define START_TRAIN_BIT 0x00000100
|
||||
#define STOP_TRAIN_BIT 0x00000200
|
||||
#define SYNC_RESET 0x80000000
|
||||
|
||||
/* for status register */
|
||||
#define RUN_BUSY_BIT 0x00000001
|
||||
#define READOUT_BUSY_BIT 0x00000002
|
||||
#define FIFOTEST_BUSY_BIT 0x00000004 //????
|
||||
#define WAITING_FOR_TRIGGER_BIT 0x00000008
|
||||
#define DELAYBEFORE_BIT 0x00000010
|
||||
#define DELAYAFTER_BIT 0x00000020
|
||||
#define EXPOSING_BIT 0x00000040
|
||||
#define COUNT_ENABLE_BIT 0x00000080
|
||||
#define SOME_FIFO_FULL_BIT 0x00008000 // error!
|
||||
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
|
||||
|
||||
/* for fifo status register */
|
||||
#define FIFO_ENABLED_BIT 0x80000000
|
||||
#define FIFO_DISABLED_BIT 0x01000000
|
||||
#define FIFO_ERROR_BIT 0x08000000
|
||||
#define FIFO_EMPTY_BIT 0x04000000
|
||||
#define FIFO_DATA_READY_BIT 0x02000000
|
||||
#define FIFO_COUNTER_MASK 0x000001ff
|
||||
#define FIFO_NM_MASK 0x00e00000
|
||||
#define FIFO_NM_OFF 21
|
||||
#define FIFO_NC_MASK 0x001ffe00
|
||||
#define FIFO_NC_OFF 9
|
||||
|
||||
/* for config register */
|
||||
|
||||
#define TOT_ENABLE_BIT 0x00000002
|
||||
#define TIMED_GATE_BIT 0x00000004
|
||||
#define CONT_RO_ENABLE_BIT 0x00080000
|
||||
|
||||
|
||||
|
||||
/* for speed register */
|
||||
|
||||
#define CLK_DIVIDER_MASK 0x000000ff
|
||||
#define CLK_DIVIDER_OFFSET 0
|
||||
#define SET_LENGTH_MASK 0x00000f00
|
||||
#define SET_LENGTH_OFFSET 8
|
||||
#define WAIT_STATES_MASK 0x0000f000
|
||||
#define WAIT_STATES_OFFSET 12
|
||||
#define TOTCLK_DIVIDER_MASK 0xff000000
|
||||
#define TOTCLK_DIVIDER_OFFSET 24
|
||||
#define TOTCLK_DUTYCYCLE_MASK 0x00ff0000
|
||||
#define TOTCLK_DUTYCYCLE_OFFSET 16
|
||||
|
||||
/* for external signal register */
|
||||
|
||||
#define SIGNAL_OFFSET 4
|
||||
#define SIGNAL_MASK 0xF
|
||||
#define EXT_SIG_OFF 0x0
|
||||
#define EXT_GATE_IN_ACTIVEHIGH 0x1
|
||||
#define EXT_GATE_IN_ACTIVELOW 0x2
|
||||
#define EXT_TRIG_IN_RISING 0x3
|
||||
#define EXT_TRIG_IN_FALLING 0x4
|
||||
#define EXT_RO_TRIG_IN_RISING 0x5
|
||||
#define EXT_RO_TRIG_IN_FALLING 0x6
|
||||
#define EXT_GATE_OUT_ACTIVEHIGH 0x7
|
||||
#define EXT_GATE_OUT_ACTIVELOW 0x8
|
||||
#define EXT_TRIG_OUT_RISING 0x9
|
||||
#define EXT_TRIG_OUT_FALLING 0xA
|
||||
#define EXT_RO_TRIG_OUT_RISING 0xB
|
||||
#define EXT_RO_TRIG_OUT_FALLING 0xC
|
||||
#define EXT_OUT_LOW 0xD // to be implemented in firmware (and corrected in software)
|
||||
#define EXT_OUT_HIGH 0xE // to be implemented in firmware (and corrected in software)
|
||||
#define EXT_MASTER_SLAVE_SYNC 0xF // to be implemented in firmware (and corrected in software)
|
||||
|
||||
|
||||
|
||||
/* fifo control register */
|
||||
#define FIFO_RESET_BIT 0x00000001
|
||||
#define FIFO_DISABLE_TOGGLE_BIT 0x00000002
|
||||
|
||||
|
||||
//chip shiftin register meaning
|
||||
|
||||
#define OUTMUX_OFF 20
|
||||
#define OUTMUX_MASK 0x1f
|
||||
#define PROBES_OFF 4
|
||||
#define PROBES_MASK 0x7f
|
||||
#define OUTBUF_OFF 0
|
||||
#define OUTBUF_MASK 1
|
||||
|
||||
|
||||
#endif
|
@ -1,91 +0,0 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
#include "server_funcs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
extern int sockfd;
|
||||
|
||||
|
||||
void error(char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno, b;
|
||||
char cmd[100];
|
||||
int retval=OK;
|
||||
int sd, fd;
|
||||
|
||||
|
||||
if (argc==1) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
|
||||
printf("opening control server on port %d\n",portno );
|
||||
system(cmd);
|
||||
b=1;
|
||||
} else {
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
if ( sscanf(argv[1],"%d",&portno) ==0) {
|
||||
printf("could not open stop server: unknown port\n");
|
||||
return 1;
|
||||
}
|
||||
b=0;
|
||||
printf("opening stop server on port %d\n",portno);
|
||||
}
|
||||
|
||||
|
||||
|
||||
init_detector(b); //defined in server_funcs
|
||||
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
|
||||
sockfd=sd;
|
||||
|
||||
|
||||
if (getServerError(sd)) { //defined in communication_funcs
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table(); //defined in server_funcs
|
||||
#ifdef VERBOSE
|
||||
printf("function table assigned \n");
|
||||
#endif
|
||||
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for client call\n");
|
||||
#endif
|
||||
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
if (fd>0) {
|
||||
retval=decode_function(fd); //defined in server_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection(fd); //defined in communication_funcs
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
exitServer(sockfd); //defined in communication_funcs
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
#ifndef SERVER_DEFS_H
|
||||
#define SERVER_DEFS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Hardware definitions
|
||||
|
||||
#define NCHAN 128
|
||||
#define NCHIP 10
|
||||
#define NMAXMODX 24
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD NMAXMODX*NMAXMODY
|
||||
#define NDAC 6
|
||||
#define NADC 0
|
||||
|
||||
#define NCHANS NCHAN*NCHIP*NMAXMOD
|
||||
#define NDACS NDAC*NMAXMOD
|
||||
|
||||
#define NTRIMBITS 6
|
||||
#define NCOUNTBITS 24
|
||||
|
||||
//#define TRIM_DR ((2**NTRIMBITS)-1)
|
||||
//#define COUNT_DR ((2**NCOUNTBITS)-1)
|
||||
#define TRIM_DR (((int)pow(2,NTRIMBITS))-1)
|
||||
#define COUNT_DR (((int)pow(2,NCOUNTBITS))-1)
|
||||
|
||||
|
||||
#define ALLMOD 0xffff
|
||||
#define ALLFIFO 0xffff
|
||||
|
||||
#ifdef VIRTUAL
|
||||
#define DEBUGOUT
|
||||
#endif
|
||||
|
||||
#define CLK_FREQ 100E+6
|
||||
|
||||
|
||||
#define THIS_SOFTWARE_VERSION 0x20120419
|
||||
#define THIS_REVISION "$Rev: 379 $"
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,79 +0,0 @@
|
||||
#ifndef SERVER_FUNCS_H
|
||||
#define SERVER_FUNCS_H
|
||||
#include <stdio.h>
|
||||
/*
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
#include "communication_funcs.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define GOODBYE -200
|
||||
|
||||
int sockfd;
|
||||
|
||||
int function_table();
|
||||
|
||||
int decode_function(int);
|
||||
|
||||
int init_detector(int);
|
||||
|
||||
int M_nofunc(int);
|
||||
int exit_server(int);
|
||||
|
||||
|
||||
|
||||
|
||||
// General purpose functions
|
||||
int get_detector_type(int);
|
||||
int set_number_of_modules(int);
|
||||
int get_max_number_of_modules(int);
|
||||
|
||||
|
||||
int exec_command(int);
|
||||
int set_external_signal_flag(int);
|
||||
int set_external_communication_mode(int);
|
||||
int get_id(int);
|
||||
int digital_test(int);
|
||||
int write_register(int);
|
||||
int read_register(int);
|
||||
int set_dac(int);
|
||||
int get_adc(int);
|
||||
int set_channel(int);
|
||||
int set_chip(int);
|
||||
int set_module(int);
|
||||
int get_channel(int);
|
||||
int get_chip(int);
|
||||
int get_module(int);
|
||||
|
||||
int get_threshold_energy(int);
|
||||
int set_threshold_energy(int);
|
||||
int set_settings(int);
|
||||
int start_acquisition(int);
|
||||
int stop_acquisition(int);
|
||||
int start_readout(int);
|
||||
int get_run_status(int);
|
||||
int read_frame(int);
|
||||
int read_all(int);
|
||||
int start_and_read_all(int);
|
||||
int set_timer(int);
|
||||
int get_time_left(int);
|
||||
int set_dynamic_range(int);
|
||||
int set_roi(int);
|
||||
int get_roi(int);
|
||||
int set_speed(int);
|
||||
int set_readout_flags(int);
|
||||
int execute_trimming(int);
|
||||
int lock_server(int);
|
||||
int set_port(int);
|
||||
int get_last_client_ip(int);
|
||||
int set_master(int);
|
||||
int set_synchronization(int);
|
||||
|
||||
int update_client(int);
|
||||
int send_update(int);
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
#include "sharedmemory.h"
|
||||
|
||||
struct statusdata *stdata;
|
||||
|
||||
int inism(int clsv) {
|
||||
|
||||
static int scansmid;
|
||||
|
||||
if (clsv==SMSV) {
|
||||
if ( (scansmid=shmget(SMKEY,1024,IPC_CREAT | 0666 ))==-1 ) {
|
||||
return -1;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (clsv==SMCL) {
|
||||
if ( (scansmid=shmget(SMKEY,0,0) )==-1 ) {
|
||||
return -3;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void write_status_sm(char *status) {
|
||||
strcpy(stdata->status,status);
|
||||
}
|
||||
|
||||
void write_istatus_sm(int i) {
|
||||
stdata->istatus=i;
|
||||
}
|
||||
int read_istatus_sm() {
|
||||
return stdata->istatus;
|
||||
}
|
||||
|
||||
void write_stop_sm(int v) {
|
||||
stdata->stop=v;
|
||||
}
|
||||
|
||||
void write_runnumber_sm(int v) {
|
||||
stdata->runnumber=v;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#ifndef SM
|
||||
#define SM
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <asm/page.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* key for shared memory */
|
||||
#define SMKEY 10001
|
||||
|
||||
#define SMSV 1
|
||||
#define SMCL 2
|
||||
|
||||
|
||||
struct statusdata {
|
||||
int runnumber;
|
||||
int stop;
|
||||
int istatus;
|
||||
char status[20];
|
||||
} ;
|
||||
|
||||
|
||||
/* for shared memory */
|
||||
|
||||
int inism(int clsv);
|
||||
void write_status_sm(char *status);
|
||||
void write_stop_sm(int v);
|
||||
void write_runnumber_sm(int v);
|
||||
|
||||
void write_istatus_sm(int v);
|
||||
|
||||
int read_istatus_sm();
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
../../slsReceiverSoftware/include/sls_receiver_defs.h
|
@ -1 +0,0 @@
|
||||
../../slsReceiverSoftware/include/sls_receiver_funcs.h
|
@ -1,41 +0,0 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
#include "firmware_funcs.h"
|
||||
|
||||
|
||||
int sockfd;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno;
|
||||
int retval=0;
|
||||
|
||||
portno = DEFAULT_PORTNO;
|
||||
|
||||
|
||||
bindSocket(portno);
|
||||
if (getServerError())
|
||||
return -1;
|
||||
|
||||
|
||||
|
||||
/* waits for connection */
|
||||
while(retval!=GOODBYE) {
|
||||
#ifdef VERBOSE
|
||||
printf("\n");
|
||||
#endif
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Stop server: waiting for client call\n");
|
||||
#endif
|
||||
acceptConnection();
|
||||
retval=stopStateMachine();
|
||||
closeConnection();
|
||||
}
|
||||
|
||||
exitServer();
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,789 +0,0 @@
|
||||
#ifndef PICASSOD
|
||||
#include "server_defs.h"
|
||||
#else
|
||||
#include "picasso_defs.h"
|
||||
#endif
|
||||
#include "trimming_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
extern int nModX;
|
||||
//extern int *values;
|
||||
|
||||
extern const int nChans;
|
||||
extern const int nChips;
|
||||
extern const int nDacs;
|
||||
extern const int nAdcs;
|
||||
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int im)
|
||||
{
|
||||
|
||||
int retval=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming with fixed settings\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
if (par2<=0)
|
||||
retval=trim_with_level(countlim, im);
|
||||
else
|
||||
retval=trim_with_median(countlim,im);
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int trim_with_noise(int countlim, int nsigma, int im)
|
||||
{
|
||||
|
||||
|
||||
int retval1=OK, retval2=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming using noise\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
/* threshold scan */
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("trimming with noise.....\n");
|
||||
#endif
|
||||
if (retval1==OK)
|
||||
retval2=trim_with_level(countlim, im);
|
||||
else
|
||||
retval2=-1;
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
//if (retval1==OK && retval2==OK)
|
||||
// retval=OK;
|
||||
//else
|
||||
// retval=FAIL;
|
||||
|
||||
return retval2;
|
||||
|
||||
}
|
||||
|
||||
int trim_with_beam(int countlim, int nsigma, int im) //rpc
|
||||
{
|
||||
|
||||
|
||||
int retval1=OK, retval2=OK;
|
||||
|
||||
printf("Trimming using beam\n");
|
||||
//return OK;
|
||||
#ifdef VIRTUAL
|
||||
printf("Trimming using beam\n");
|
||||
return OK;
|
||||
#endif
|
||||
/* threshold scan */
|
||||
#ifdef DEBUGOUT
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
|
||||
if (retval1==OK)
|
||||
retval2=trim_with_median(TRIM_DR, im);
|
||||
else return -1;
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
|
||||
// if (retval1==OK && retval2==OK)
|
||||
// retval=OK;
|
||||
//else
|
||||
// retval=FAIL;
|
||||
|
||||
return retval2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int trim_improve(int maxit, int par2, int im) //rpc
|
||||
{
|
||||
|
||||
int retval1=OK, retval2=OK;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Improve the trimming\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
|
||||
if (par2!=0 && im==ALLMOD)
|
||||
retval1=choose_vthresh();
|
||||
if (retval1==OK)
|
||||
retval2=trim_with_median(2*maxit+1, im);
|
||||
else
|
||||
return -1;
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
// if (retval1==OK && retval2==OK)
|
||||
// retval=OK;
|
||||
//else
|
||||
//retval=FAIL;
|
||||
|
||||
return retval2;
|
||||
|
||||
}
|
||||
|
||||
int calcthr_from_vcal(int vcal) {
|
||||
int thrmin;
|
||||
//thrmin=140+3*vcal/5;
|
||||
thrmin=180+3*vcal/5;
|
||||
return thrmin;
|
||||
}
|
||||
|
||||
int calccal_from_vthr(int vthr) {
|
||||
int vcal;
|
||||
vcal=5*(vthr-140)/3;
|
||||
return vcal;
|
||||
}
|
||||
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int modma, modmi, nm;
|
||||
int thr, thrstep=5, nthr=31;
|
||||
|
||||
int *fifodata;
|
||||
|
||||
float vthreshmean, vthreshSTDev;
|
||||
int *thrmi, *thrma;
|
||||
float c;
|
||||
float b=BVTRIM;
|
||||
float a=AVTRIM;
|
||||
int *trim;
|
||||
int ich, imod, ichan;
|
||||
int nvalid=0;
|
||||
u_int32_t *scan;
|
||||
int ithr;
|
||||
sls_detector_channel myChan;
|
||||
|
||||
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
trim=malloc(sizeof(int)*nChans*nChips*nModX);
|
||||
thrmi=malloc(sizeof(int)*nModX);
|
||||
thrma=malloc(sizeof(int)*nModX);
|
||||
|
||||
|
||||
for (ich=0; ich<nChans*nChips*nm; ich++)
|
||||
trim[ich]=-1;
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
counterClear(im);
|
||||
clearSSregister(im);
|
||||
usleep(500);
|
||||
*/
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE;
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
|
||||
for (ithr=0; ithr<nthr; ithr++) {
|
||||
fifoReset();
|
||||
/* scanning threshold */
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
thr=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if (ithr==0) {
|
||||
thrmi[imod]=thr;
|
||||
initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
} else
|
||||
initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
|
||||
}
|
||||
|
||||
/* setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChips*nChans+ichan;
|
||||
if (scan[ich]>countlim && trim[ich]==-1) {
|
||||
trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
#ifdef VERBOSE
|
||||
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
#endif
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else {
|
||||
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
vthreshmean=0;
|
||||
vthreshSTDev=0;
|
||||
nvalid=0;
|
||||
thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChans*nChips+ichan;
|
||||
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
|
||||
vthreshmean=vthreshmean+trim[ich];
|
||||
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
|
||||
nvalid++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvalid>0) {
|
||||
vthreshmean=vthreshmean/nvalid;
|
||||
vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean);
|
||||
} else {
|
||||
vthreshmean=thrmi[imod];
|
||||
vthreshSTDev=nthr*thrstep;
|
||||
printf("No valid channel for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
|
||||
#endif
|
||||
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
|
||||
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
|
||||
if (thr<0 || thr>(DAC_DR-1)) {
|
||||
thr=thrmi[imod]/2;
|
||||
printf("Can't find correct threshold for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
#ifdef VERBOSE
|
||||
printf("vthresh=%d \n",thr);
|
||||
#endif
|
||||
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
|
||||
thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a));
|
||||
if (thr<500 || thr>(DAC_DR-1)) {
|
||||
thr=750;
|
||||
printf("Can't find correct trimbit size for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
initDACbyIndexDACU(VTRIM,thr,imod);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("vtrim=%d \n",thr);
|
||||
#endif
|
||||
|
||||
}
|
||||
free(trim);
|
||||
free(thrmi);
|
||||
free(thrma);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_level(int countlim, int im) {
|
||||
int ich, itrim, ichan, ichip, imod;
|
||||
u_int32_t *scan;
|
||||
int *inttrim;
|
||||
int modma, modmi, nm;
|
||||
int retval=0;
|
||||
int *fifodata;
|
||||
sls_detector_channel myChan;
|
||||
printf("trimming module number %d", im);
|
||||
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
|
||||
printf("countlim=%d\n",countlim);
|
||||
for (ich=0; ich<nChans*nChips*nModX; ich++)
|
||||
inttrim[ich]=-1;
|
||||
|
||||
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
|
||||
fifoReset();
|
||||
printf("Trimbit %d\n",itrim);
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(itrim,0,0,1,0,0,ALLMOD);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
||||
ich=ichan+imod*nChans*nChips;
|
||||
if (inttrim[ich]==-1) {
|
||||
if (scan[ich]>countlim){
|
||||
inttrim[ich]=itrim;
|
||||
if (scan[ich]>2*countlim && itrim>0) {
|
||||
//if (scan[ich]>2*countlim || itrim==0) {
|
||||
inttrim[ich]=itrim-1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else
|
||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
clearCSregister(imod);
|
||||
firstChip(im);
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
clearSSregister(imod);
|
||||
for (ichan=0; ichan<nChans; ichan++) {
|
||||
nextStrip(imod);
|
||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
||||
//if (*(inttrim+ich)==-1) {
|
||||
if (*(inttrim+ich)<1) {
|
||||
if (*(inttrim+ich)==-1) {
|
||||
*(inttrim+ich)=TRIM_DR;
|
||||
}
|
||||
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
||||
retval++;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
// else
|
||||
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
||||
#endif
|
||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
||||
}
|
||||
nextChip(imod);
|
||||
}
|
||||
}
|
||||
free(inttrim);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
||||
|
||||
int kth_smallest(int *a, int n, int k)
|
||||
{
|
||||
register int i,j,l,m ;
|
||||
register float x ;
|
||||
|
||||
l=0 ; m=n-1 ;
|
||||
while (l<m) {
|
||||
x=a[k] ;
|
||||
i=l ;
|
||||
j=m ;
|
||||
do {
|
||||
while (a[i]<x) i++ ;
|
||||
while (x<a[j]) j-- ;
|
||||
if (i<=j) {
|
||||
ELEM_SWAP(a[i],a[j]) ;
|
||||
i++ ; j-- ;
|
||||
}
|
||||
} while (i<=j) ;
|
||||
if (j<k) l=i ;
|
||||
if (k<i) m=j ;
|
||||
}
|
||||
return a[k] ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int median(int *a,int n) {
|
||||
|
||||
int i=0, k=n/2;
|
||||
float k1=0.5*n;
|
||||
|
||||
//discard zeroes and 0xffffff
|
||||
for (i=0; i<n; i++) {
|
||||
if (a[i]==0)
|
||||
k1+=0.5;
|
||||
else if (a[i]==0xffffff)
|
||||
k1-=0.5;
|
||||
}
|
||||
|
||||
kth_smallest(a, n, k1);
|
||||
|
||||
|
||||
/* for (k=0; k<n; k++) { */
|
||||
/* printf("%d ",a[k]); */
|
||||
/* } */
|
||||
/* printf("\n"); */
|
||||
|
||||
k=k1;
|
||||
|
||||
return a[k] ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int ave(int *a, int n)
|
||||
{
|
||||
int av=0,i;
|
||||
for (i=0; i<n; i++)
|
||||
av=av+((float)*(a+i))/((float)n);
|
||||
return av;
|
||||
}
|
||||
|
||||
|
||||
int choose_vthresh() {
|
||||
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], med1[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int maxiterations=10;
|
||||
int vthreshmean=0;
|
||||
int vthresh;
|
||||
int im=ALLMOD;
|
||||
int modma, modmi, nm;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
|
||||
|
||||
setDynamicRange(32);
|
||||
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
//printf(".");
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//
|
||||
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
||||
olddiff[imod]=0xffffff;
|
||||
direction[imod]=0;
|
||||
printf("Median of module %d=%d\n",imod,med[imod]);
|
||||
}
|
||||
vthreshmean=vthreshmean/nm;
|
||||
//media=median(scan,nChans*nChips*nModX);
|
||||
//printf("Median overall=%d\n",media);
|
||||
media=median(med1+modmi,nm);
|
||||
printf("Median of modules=%d\n",media);
|
||||
free(scan);
|
||||
free(scan1);
|
||||
|
||||
|
||||
while(change_flag && iteration<maxiterations) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
change_flag=0;
|
||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
||||
for (ichan=modmi; ichan<modma; ichan++) {
|
||||
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
media=median(med1+modmi,nm);
|
||||
|
||||
diff=med[ichan]-media;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
direction[ichan]=1;
|
||||
else
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
vthresh=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
vthresh=vthresh-direction[ichan];
|
||||
if (vthresh>(DAC_DR-1)) {
|
||||
vthresh=(DAC_DR-1);
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (vthresh<0) {
|
||||
vthresh=0;
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
vthresh=vthresh+direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
initDACbyIndex(VTHRESH,vthresh, ichan);
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_median(int stop, int im) {
|
||||
|
||||
|
||||
int retval=0;
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
u_int32_t *scan, *scan1;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int me[nModX], me1[nModX];
|
||||
int modma, modmi, nm;
|
||||
int trim;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
olddiff=malloc(4*nModX*nChips*nChans);
|
||||
direction=malloc(4*nModX*nChips*nChans);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0x0fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
/********
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
scan=decode_data(fifo_read_event());
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
free(scan);
|
||||
**************/
|
||||
while(change_flag && iteration<stop) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
me1[imod]=me[imod];
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me1,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
selChip(ichip,imod);
|
||||
clearSSregister(imod);
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-me[imod];
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
} else {
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
}
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
if (trim>TRIM_DR) {
|
||||
trim=63;
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
retval++;
|
||||
}
|
||||
if (trim<0) {
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
trim=0;
|
||||
retval++;
|
||||
}
|
||||
initChannel(trim,0,0,1,0,0,imod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
free(olddiff);
|
||||
free(direction);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef TRIMMING_FUNCS_H
|
||||
#define TRIMMING_FUNCS_H
|
||||
int trim_fixed_settings(int countlim, int par2, int imod);
|
||||
int trim_with_noise(int countlim, int nsigma, int imod);
|
||||
int trim_with_beam(int countlim, int nsigma, int imod);
|
||||
int trim_improve(int maxit, int par2, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
|
||||
|
||||
int choose_vthresh();
|
||||
int trim_with_level(int countlim, int imod);
|
||||
int trim_with_median(int stop, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
int median(int *a,int n);
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
SERVER=mythenDetectorServer
|
||||
MAINDIR=slsDetectorsPackage
|
||||
SPECDIR=slsDetectorSoftware/$SERVER
|
||||
TMPFILE=gitInfoMythenTmp.h
|
||||
INCLFILE=gitInfoMythen.h
|
||||
|
||||
|
||||
#evaluate the variables
|
||||
EVALFILE=../../evalVersionVariables.sh
|
||||
source $EVALFILE
|
||||
|
||||
|
||||
#get modified date
|
||||
#RDATE1='git log --pretty=format:"%ci" -1'
|
||||
RDATE1="find ../slsDetectorServer . -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | egrep -v 'gitInfo|bin|.git|updateGitVersion|.o' | head -n 1"
|
||||
RDATE=`eval $RDATE1`
|
||||
NEWDATE=$(sed "s/-//g" <<< $RDATE | awk '{print $1;}')
|
||||
NEWDATE=${NEWDATE/#/0x}
|
||||
|
||||
|
||||
#get old date from INCLFILE
|
||||
OLDDATE=$(more $INCLFILE | grep '#define GITDATE' | awk '{print $3}')
|
||||
|
||||
|
||||
#update INCLFILE if changes
|
||||
if [ "$OLDDATE" != "$NEWDATE" ]; then
|
||||
echo Path: ${MAINDIR}/${SPECDIR} $'\n'URL: ${GITREPO} $'\n'Repository Root: ${GITREPO} $'\n'Repsitory UUID: ${REPUID} $'\n'Revision: ${FOLDERREV} $'\n'Branch: ${BRANCH} $'\n'Last Changed Author: ${AUTH1}_${AUTH2} $'\n'Last Changed Rev: ${REV} $'\n'Last Changed Date: ${RDATE} > gitInfo.txt
|
||||
cd ../../
|
||||
./genVersionHeader.sh $SPECDIR/gitInfo.txt $SPECDIR/$TMPFILE $SPECDIR/$INCLFILE
|
||||
cd $WD
|
||||
fi
|
@ -108,10 +108,6 @@ slsDetector::~slsDetector() {
|
||||
}
|
||||
|
||||
|
||||
bool slsDetector::isMultiSlsDetectorClass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int64_t slsDetector::clearAllErrorMask() {
|
||||
clearErrorMask();
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @author Anna Bergamaschi
|
||||
*/
|
||||
|
||||
#include "slsDetectorUtils.h"
|
||||
#include "slsDetectorBase.h"
|
||||
#include "MySocketTCP.h"
|
||||
|
||||
class multiSlsDetector;
|
||||
@ -38,7 +38,7 @@ typedef struct detParameterList {
|
||||
} detParameterList;
|
||||
|
||||
|
||||
class slsDetector : public postProcessing {
|
||||
class slsDetector : public slsDetectorBase {
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -316,12 +316,6 @@ public:
|
||||
*/
|
||||
virtual ~slsDetector();
|
||||
|
||||
/**
|
||||
* returns false. Used when reference is slsDetectorUtils and to determine
|
||||
* if command can be implemented as slsDetector/multiSlsDetector object/
|
||||
*/
|
||||
bool isMultiSlsDetectorClass();
|
||||
|
||||
/**
|
||||
* Clears error mask and also the bit in parent det multi error mask
|
||||
* @returns error mask
|
||||
|
@ -541,11 +541,6 @@ virtual int enableDataStreamingFromReceiver(int enable=-1)=0;
|
||||
return atoi(sret.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when reference is slsDetectorUtils and to determine
|
||||
* if command can be implemented as slsDetector/multiSlsDetector object/
|
||||
*/
|
||||
virtual bool isMultiSlsDetectorClass() = 0;
|
||||
|
||||
/**
|
||||
* Set acquiring flag in shared memory
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,8 @@
|
||||
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorUtils.h"
|
||||
|
||||
class multiSlsDetector;
|
||||
|
||||
|
||||
|
||||
@ -16,67 +17,69 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
public:
|
||||
|
||||
|
||||
slsDetectorCommand(slsDetectorUtils *det);
|
||||
slsDetectorCommand(multiSlsDetector *det);
|
||||
virtual ~slsDetectorCommand(){};
|
||||
|
||||
/* /\** */
|
||||
/* executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing */
|
||||
/* \param narg number of arguments */
|
||||
/* \param args array of string arguments */
|
||||
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
|
||||
/* \returns answer string */
|
||||
/* *\/ */
|
||||
virtual std::string executeLine(int narg, char *args[], int action);
|
||||
/*
|
||||
* Executes a set of string arguments according to a given format.
|
||||
* It is used to read/write configuration file, dump and retrieve detector
|
||||
* settings and for the command line interface command parsing
|
||||
* @param narg number of arguments
|
||||
* @param args array of string arguments
|
||||
* @param action can be PUT_ACTION or GET_ACTION(from text client even READOUT_ACTION for acquisition)
|
||||
* @param detPos -1 for all detectors in multi detector list or position of a specific detector in list
|
||||
*/
|
||||
virtual std::string executeLine(int narg, char *args[], int action, int detPos = -1);
|
||||
|
||||
/* /\** */
|
||||
/* returns the help for the executeLine command */
|
||||
/* \param os output stream to return the help to */
|
||||
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
|
||||
/* *\/ */
|
||||
std::string helpLine(int narg, char *args[], int action=HELP_ACTION);
|
||||
static std::string helpAcquire(int narg, char *args[], int action);
|
||||
static std::string helpData(int narg, char *args[], int action);
|
||||
static std::string helpStatus(int narg, char *args[], int action);
|
||||
static std::string helpDataStream(int narg, char *args[], int action);
|
||||
static std::string helpFree(int narg, char *args[], int action);
|
||||
static std::string helpHostname(int narg, char *args[], int action);
|
||||
static std::string helpUser(int narg, char *args[], int action);
|
||||
static std::string helpExitServer(int narg, char *args[], int action);
|
||||
static std::string helpSettingsDir(int narg, char *args[], int action);
|
||||
static std::string helpCalDir(int narg, char *args[], int action);
|
||||
static std::string helpTrimEn(int narg, char *args[], int action);
|
||||
static std::string helpOutDir(int narg, char *args[], int action);
|
||||
static std::string helpFileName(int narg, char *args[], int action);
|
||||
static std::string helpFileIndex(int narg, char *args[], int action);
|
||||
static std::string helpRateCorr(int narg, char *args[], int action);
|
||||
static std::string helpThreaded(int narg, char *args[], int action);
|
||||
static std::string helpNetworkParameter(int narg, char *args[], int action);
|
||||
static std::string helpPort(int narg, char *args[], int action);
|
||||
static std::string helpLock(int narg, char *args[], int action);
|
||||
static std::string helpLastClient(int narg, char *args[], int action);
|
||||
static std::string helpOnline(int narg, char *args[], int action);
|
||||
static std::string helpConfigureMac(int narg, char *args[], int action);
|
||||
static std::string helpDetectorSize(int narg, char *args[], int action);
|
||||
static std::string helpSettings(int narg, char *args[], int action);
|
||||
static std::string helpSN(int narg, char *args[], int action);
|
||||
static std::string helpDigiTest(int narg, char *args[], int action);
|
||||
static std::string helpRegister(int narg, char *args[], int action);
|
||||
static std::string helpDAC(int narg, char *args[], int action);
|
||||
static std::string helpTimer(int narg, char *args[], int action);
|
||||
static std::string helpTiming(int narg, char *args[], int action);
|
||||
static std::string helpTimeLeft(int narg, char *args[], int action);
|
||||
static std::string helpSpeed(int narg, char *args[], int action);
|
||||
static std::string helpAdvanced(int narg, char *args[], int action);
|
||||
static std::string helpConfiguration(int narg, char *args[], int action);
|
||||
static std::string helpImage(int narg, char *args[], int action);
|
||||
static std::string helpCounter(int narg, char *args[], int action);
|
||||
static std::string helpADC(int narg, char *args[], int action);
|
||||
static std::string helpTempControl(int narg, char *args[], int action);
|
||||
static std::string helpEnablefwrite(int narg, char *args[], int action);
|
||||
static std::string helpOverwrite(int narg, char *args[], int action);
|
||||
static std::string helpReceiver(int narg, char *args[], int action);
|
||||
static std::string helpPattern(int narg, char *args[], int action);
|
||||
static std::string helpPulse(int narg, char *args[], int action);
|
||||
std::string helpLine(int narg, int action=HELP_ACTION);
|
||||
static std::string helpAcquire(int action);
|
||||
static std::string helpData(int action);
|
||||
static std::string helpStatus(int action);
|
||||
static std::string helpDataStream(int action);
|
||||
static std::string helpFree(int action);
|
||||
static std::string helpHostname(int action);
|
||||
static std::string helpUser(int action);
|
||||
static std::string helpExitServer(int action);
|
||||
static std::string helpSettingsDir(int action);
|
||||
static std::string helpCalDir(int action);
|
||||
static std::string helpTrimEn(int action);
|
||||
static std::string helpOutDir(int action);
|
||||
static std::string helpFileName(int action);
|
||||
static std::string helpFileIndex(int action);
|
||||
static std::string helpRateCorr(int action);
|
||||
static std::string helpThreaded(int action);
|
||||
static std::string helpNetworkParameter(int action);
|
||||
static std::string helpPort(int action);
|
||||
static std::string helpLock(int action);
|
||||
static std::string helpLastClient(int action);
|
||||
static std::string helpOnline(int action);
|
||||
static std::string helpConfigureMac(int action);
|
||||
static std::string helpDetectorSize(int action);
|
||||
static std::string helpSettings(int action);
|
||||
static std::string helpSN(int action);
|
||||
static std::string helpDigiTest(int action);
|
||||
static std::string helpRegister(int action);
|
||||
static std::string helpDAC(int action);
|
||||
static std::string helpTimer(int action);
|
||||
static std::string helpTiming(int action);
|
||||
static std::string helpTimeLeft(int action);
|
||||
static std::string helpSpeed(int action);
|
||||
static std::string helpAdvanced(int action);
|
||||
static std::string helpConfiguration(int action);
|
||||
static std::string helpImage(int action);
|
||||
static std::string helpCounter(int action);
|
||||
static std::string helpADC(int action);
|
||||
static std::string helpTempControl(int action);
|
||||
static std::string helpEnablefwrite(int action);
|
||||
static std::string helpOverwrite(int action);
|
||||
static std::string helpReceiver(int action);
|
||||
static std::string helpPattern(int action);
|
||||
static std::string helpPulse(int action);
|
||||
|
||||
|
||||
|
||||
@ -92,60 +95,60 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
private:
|
||||
|
||||
|
||||
slsDetectorUtils *myDet;
|
||||
multiSlsDetector *myDet;
|
||||
|
||||
std::string cmdUnderDevelopment(int narg, char *args[], int action);
|
||||
std::string cmdUnknown(int narg, char *args[], int action);
|
||||
std::string cmdAcquire(int narg, char *args[], int action);
|
||||
std::string cmdData(int narg, char *args[], int action);
|
||||
std::string cmdStatus(int narg, char *args[], int action);
|
||||
std::string cmdDataStream(int narg, char *args[], int action);
|
||||
std::string cmdFree(int narg, char *args[], int action);
|
||||
std::string cmdHostname(int narg, char *args[], int action);
|
||||
std::string cmdUser(int narg, char *args[], int action);
|
||||
std::string cmdHelp(int narg, char *args[], int action);
|
||||
std::string cmdExitServer(int narg, char *args[], int action);
|
||||
std::string cmdSettingsDir(int narg, char *args[], int action);
|
||||
std::string cmdCalDir(int narg, char *args[], int action);
|
||||
std::string cmdTrimEn(int narg, char *args[], int action);
|
||||
std::string cmdOutDir(int narg, char *args[], int action);
|
||||
std::string cmdFileName(int narg, char *args[], int action);
|
||||
std::string cmdFileIndex(int narg, char *args[], int action);
|
||||
std::string cmdRateCorr(int narg, char *args[], int action);
|
||||
std::string cmdThreaded(int narg, char *args[], int action);
|
||||
std::string cmdNetworkParameter(int narg, char *args[], int action);
|
||||
std::string cmdPort(int narg, char *args[], int action);
|
||||
std::string cmdLock(int narg, char *args[], int action);
|
||||
std::string cmdLastClient(int narg, char *args[], int action);
|
||||
std::string cmdOnline(int narg, char *args[], int action);
|
||||
std::string cmdConfigureMac(int narg, char *args[], int action);
|
||||
std::string cmdDetectorSize(int narg, char *args[], int action);
|
||||
std::string cmdSettings(int narg, char *args[], int action);
|
||||
std::string cmdSN(int narg, char *args[], int action);
|
||||
std::string cmdDigiTest(int narg, char *args[], int action);
|
||||
std::string cmdRegister(int narg, char *args[], int action);
|
||||
std::string cmdDAC(int narg, char *args[], int action);
|
||||
std::string cmdTiming(int narg, char *args[], int action);
|
||||
std::string cmdTimer(int narg, char *args[], int action);
|
||||
std::string cmdTimeLeft(int narg, char *args[], int action);
|
||||
std::string cmdSpeed(int narg, char *args[], int action);
|
||||
std::string cmdAdvanced(int narg, char *args[], int action);
|
||||
std::string cmdConfiguration(int narg, char *args[], int action);
|
||||
std::string cmdImage(int narg, char *args[], int action);
|
||||
std::string cmdCounter(int narg, char *args[], int action);
|
||||
std::string cmdADC(int narg, char *args[], int action);
|
||||
std::string cmdTempControl(int narg, char *args[], int action);
|
||||
std::string cmdEnablefwrite(int narg, char *args[], int action);
|
||||
std::string cmdOverwrite(int narg, char *args[], int action);
|
||||
std::string cmdReceiver(int narg, char *args[], int action);
|
||||
std::string cmdPattern(int narg, char *args[], int action);
|
||||
std::string cmdPulse(int narg, char *args[], int action);
|
||||
std::string cmdUnderDevelopment(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdUnknown(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdAcquire(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdData(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdStatus(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdDataStream(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdFree(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdHostname(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdUser(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdHelp(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdExitServer(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdSettingsDir(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdCalDir(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdTrimEn(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdOutDir(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdFileName(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdFileIndex(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdRateCorr(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdNetworkParameter(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdPort(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdLock(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdLastClient(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdOnline(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdConfigureMac(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdDetectorSize(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdSettings(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdSN(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdDigiTest(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdRegister(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdDAC(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdTiming(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdTimer(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdTimeLeft(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdSpeed(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdAdvanced(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdConfiguration(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdImage(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdCounter(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdADC(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdTempControl(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdEnablefwrite(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdOverwrite(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdReceiver(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdPattern(int narg, char *args[], int action, int detPos = -1);
|
||||
std::string cmdPulse(int narg, char *args[], int action, int detPos = -1);
|
||||
|
||||
|
||||
int numberOfCommands;
|
||||
std::string cmd;
|
||||
|
||||
typedef std::string (slsDetectorCommand::*MemFuncGetter)(int narg, char *args[], int action);
|
||||
typedef std::string (slsDetectorCommand::*MemFuncGetter)(int narg, char *args[], int action, int detPos = -1);
|
||||
|
||||
|
||||
struct FuncTable
|
||||
|
@ -1,29 +0,0 @@
|
||||
#include "slsDetectorUtils.h"
|
||||
#include "slsDetectorCommand.h"
|
||||
#include "postProcessing.h"
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <time.h> //clock()
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
slsDetectorUtils::slsDetectorUtils():
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
|
||||
|
||||
#ifndef SLS_DETECTOR_UTILS_H
|
||||
#define SLS_DETECTOR_UTILS_H
|
||||
|
||||
|
||||
#ifdef __CINT__
|
||||
class pthread_mutex_t;
|
||||
class pthread_t;
|
||||
#endif
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include <pthread.h>
|
||||
}
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <queue>
|
||||
#include <math.h>
|
||||
#include <semaphore.h>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
|
||||
#include "postProcessing.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@short class containing all the possible detector functionalities
|
||||
|
||||
(used in the PSi command line interface)
|
||||
*/
|
||||
|
||||
|
||||
class slsDetectorUtils : public postProcessing {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
slsDetectorUtils();
|
||||
|
||||
virtual ~slsDetectorUtils(){};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,175 +0,0 @@
|
||||
#include "postProcessing.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
static void* startProcessData(void *n){
|
||||
postProcessing *myDet=(postProcessing*)n;
|
||||
myDet->processData();
|
||||
pthread_exit(NULL);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
int postProcessing::kbhit(){
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0
|
||||
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
|
||||
return FD_ISSET(STDIN_FILENO, &fds);
|
||||
}
|
||||
|
||||
|
||||
postProcessing::postProcessing():
|
||||
threadedProcessing(0),
|
||||
jointhread(0),
|
||||
acquiringDone(0),
|
||||
fdata(0),
|
||||
thisData(0),
|
||||
dataReady(0),
|
||||
pCallbackArg(0)
|
||||
{
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
mg=mp1;
|
||||
pthread_mutex_init(&mg, NULL);
|
||||
ms=mp1;
|
||||
pthread_mutex_init(&ms, NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
postProcessing::~postProcessing(){
|
||||
}
|
||||
|
||||
|
||||
void* postProcessing::processData() {
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
return 0;
|
||||
} //receiver
|
||||
else{
|
||||
//cprintf(RED,"In post processing threads\n");
|
||||
|
||||
if(dataReady) {
|
||||
readFrameFromReceiver();
|
||||
}
|
||||
//only update progress
|
||||
else{
|
||||
int caught = -1;
|
||||
char c;
|
||||
int ifp;
|
||||
while(true){
|
||||
|
||||
// set only in startThread
|
||||
if (*threadedProcessing==0)
|
||||
setTotalProgress();
|
||||
|
||||
// to exit acquire by typing q
|
||||
ifp=kbhit();
|
||||
if (ifp!=0){
|
||||
c=fgetc(stdin);
|
||||
if (c=='q') {
|
||||
std::cout<<"Caught the command to stop acquisition"<<std::endl;
|
||||
stopAcquisition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//get progress
|
||||
if(setReceiverOnline() == ONLINE_FLAG){
|
||||
pthread_mutex_lock(&mg);
|
||||
caught = getFramesCaughtByAnyReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
|
||||
//updating progress
|
||||
if(caught!= -1){
|
||||
setCurrentProgress(caught);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
std::cout << "caught:" << caught << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// exiting loop
|
||||
if (*threadedProcessing==0)
|
||||
break;
|
||||
if (checkJoinThread()){
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int postProcessing::checkJoinThread() {
|
||||
int retval;
|
||||
pthread_mutex_lock(&mp);
|
||||
retval=jointhread;
|
||||
pthread_mutex_unlock(&mp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void postProcessing::setJoinThread( int v) {
|
||||
pthread_mutex_lock(&mp);
|
||||
jointhread=v;
|
||||
pthread_mutex_unlock(&mp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void postProcessing::startThread() {
|
||||
|
||||
|
||||
setTotalProgress();
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout << "start thread stuff" << std::endl;
|
||||
#endif
|
||||
|
||||
pthread_attr_t tattr;
|
||||
int ret;
|
||||
sched_param param, mparam;
|
||||
int policy= SCHED_OTHER;
|
||||
|
||||
// set the priority; others are unchanged
|
||||
//newprio = 30;
|
||||
mparam.sched_priority =1;
|
||||
param.sched_priority =1;
|
||||
|
||||
|
||||
/* Initialize and set thread detached attribute */
|
||||
pthread_attr_init(&tattr);
|
||||
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
ret = pthread_setschedparam(pthread_self(), policy, &mparam);
|
||||
|
||||
|
||||
ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this);
|
||||
|
||||
if (ret)
|
||||
printf("ret %d\n", ret);
|
||||
|
||||
pthread_attr_destroy(&tattr);
|
||||
|
||||
// scheduling parameters of target thread
|
||||
ret = pthread_setschedparam(dataProcessingThread, policy, ¶m);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,102 +0,0 @@
|
||||
#ifndef POSTPROCESSING_H
|
||||
#define POSTPROCESSING_H
|
||||
|
||||
|
||||
#include "detectorData.h"
|
||||
#include "slsDetectorBase.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <queue>
|
||||
#include <math.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@short methods for data postprocessing
|
||||
(including thread for writing data files and plotting in parallel with the acquisition)
|
||||
*/
|
||||
|
||||
class postProcessing: public virtual slsDetectorBase {
|
||||
|
||||
public:
|
||||
postProcessing();
|
||||
virtual ~postProcessing();
|
||||
|
||||
|
||||
/**
|
||||
set/get if the data processing and file writing should be done by a separate threads
|
||||
\param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get
|
||||
\returns thread flag
|
||||
*/
|
||||
|
||||
int setThreadedProcessing(int b=-1) {if (b>=0) *threadedProcessing=b; return *threadedProcessing;};
|
||||
|
||||
/** processes the data
|
||||
\returns nothing
|
||||
*/
|
||||
void *processData();
|
||||
|
||||
int checkJoinThread();
|
||||
void setJoinThread(int v);
|
||||
|
||||
|
||||
void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg) { \
|
||||
dataReady = userCallback; \
|
||||
pCallbackArg = pArg; \
|
||||
if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { \
|
||||
enableDataStreamingToClient(1); \
|
||||
enableDataStreamingFromReceiver(1);}}; \
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
start data processing thread
|
||||
*/
|
||||
void startThread();
|
||||
|
||||
/** mutex to synchronize main and data processing threads */
|
||||
pthread_mutex_t mp;
|
||||
|
||||
/** mutex to synchronizedata processing and plotting threads */
|
||||
pthread_mutex_t mg;
|
||||
|
||||
/** mutex to synchronize slsdetector threads */
|
||||
pthread_mutex_t ms;
|
||||
|
||||
int *threadedProcessing;
|
||||
|
||||
/** sets when the acquisition is finished */
|
||||
int jointhread;
|
||||
|
||||
/** set when detector finishes acquiring */
|
||||
int acquiringDone;
|
||||
|
||||
|
||||
/** the data processing thread */
|
||||
|
||||
pthread_t dataProcessingThread;
|
||||
|
||||
double *fdata;
|
||||
detectorData *thisData;
|
||||
|
||||
int (*dataReady)(detectorData*,int, int, void*);
|
||||
void *pCallbackArg;
|
||||
|
||||
|
||||
private:
|
||||
int kbhit(void);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
../commonFiles/communication_funcs.c
|
@ -1 +0,0 @@
|
||||
../commonFiles/communication_funcs.h
|
@ -1 +0,0 @@
|
||||
../commonFiles/sls_detector_defs.h
|
@ -1 +0,0 @@
|
||||
../commonFiles/sls_detector_funcs.h
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user