moved receiver start to status start and to startandreadall (acquire), parallelized status start, moved prepare and clean up to multi level and called by start and stop receiver for gotthard, moench and propix

This commit is contained in:
Dhanya Maliakal 2017-08-10 18:46:10 +02:00
parent f084efd263
commit e8d83a085f
5 changed files with 295 additions and 97 deletions

View File

@ -43,7 +43,8 @@ using namespace std;
#define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL
#define RECEIVER_DET_POSID_NOT_SET 0x0000400000000000ULL
#define RECEIVER_MULTI_DET_SIZE_NOT_SET 0x0000200000000000ULL
#define PREPARE_ACQUISITION 0x0000100000000000ULL
#define CLEANUP_ACQUISITION 0x0000080000000000ULL
// 0xFFFFFFF000000000ULL
// 0x0000000FFFFFFFFFULL
@ -146,6 +147,12 @@ public:
if(slsErrorMask&RECEIVER_MULTI_DET_SIZE_NOT_SET)
retval.append("Could not set multi detector size\n");
if(slsErrorMask&PREPARE_ACQUISITION)
retval.append("Could not prepare acquisition in detector\n");
if(slsErrorMask&CLEANUP_ACQUISITION)
retval.append("Could not clean up after acquisition in detector\n");

View File

@ -1359,75 +1359,219 @@ int multiSlsDetector::getChanRegs(double* retval,bool fromDetector){
/* Communication to server */
int multiSlsDetector::prepareAcquisition(){
int i=0;
int ret=OK;
int posmin=0, posmax=thisMultiDetector->numberOfDetectors;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return FAIL;
}else{
int* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
iret[idet]= new int(OK);
Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::prepareAcquisition,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){
if(*iret[idet] != OK)
ret = FAIL;
delete iret[idet];
}else ret = FAIL;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
//master
int ret1=OK;
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret1=detectors[i]->prepareAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret1!=OK)
ret=FAIL;
}
}
return ret;
}
int multiSlsDetector::cleanupAcquisition(){
int i=0;
int ret=OK,ret1=OK;
int posmin=0, posmax=thisMultiDetector->numberOfDetectors;
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret1=detectors[i]->cleanupAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret1!=OK)
ret=FAIL;
}
}
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return FAIL;
}else{
int* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
iret[idet]= new int(OK);
Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::cleanupAcquisition,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){
if(*iret[idet] != OK)
ret = FAIL;
delete iret[idet];
}else ret = FAIL;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
return ret;
}
// Acquisition functions
/* change these funcs accepting also ok/fail */
int multiSlsDetector::startAcquisition(){
int i=0;
int ret=OK, ret1=OK;
for (i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (i!=thisMultiDetector->masterPosition)
if (detectors[i]) {
ret=detectors[i]->startAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK)
ret1=FAIL;
}
}
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret=detectors[i]->startAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK)
ret1=FAIL;
}
}
return ret1;
if (getDetectorsType() == EIGER) {
if (prepareAcquisition() == FAIL)
return FAIL;
}
int i=0;
int ret=OK;
int posmin=0, posmax=thisMultiDetector->numberOfDetectors;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return FAIL;
}else{
int* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
iret[idet]= new int(OK);
Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::startAcquisition,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){
if(*iret[idet] != OK)
ret = FAIL;
delete iret[idet];
}else ret = FAIL;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
//master
int ret1=OK;
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret1=detectors[i]->startAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret1!=OK)
ret=FAIL;
}
}
return ret;
};
int multiSlsDetector::stopAcquisition(){
int i=0;
int ret=OK, ret1=OK;
int i=0;
int ret=OK,ret1=OK;
int posmin=0, posmax=thisMultiDetector->numberOfDetectors;
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret1=detectors[i]->stopAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret1!=OK)
ret=FAIL;
}
}
i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (detectors[i]) {
ret=detectors[i]->stopAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK)
ret1=FAIL;
}
}
for (i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
ret=detectors[i]->stopAcquisition();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret!=OK)
ret1=FAIL;
}
}
*stoppedFlag=1;
setAcquiringFlag(false);
return ret1;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return FAIL;
}else{
int* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
iret[idet]= new int(OK);
Task* task = new Task(new func0_t<int,slsDetector,int>(&slsDetector::stopAcquisition,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){
if(*iret[idet] != OK)
ret = FAIL;
delete iret[idet];
}else ret = FAIL;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
*stoppedFlag=1;
setAcquiringFlag(false);
return ret;
};
int multiSlsDetector::startReadOut(){
int i=0;
@ -1633,8 +1777,12 @@ int* multiSlsDetector::startAndReadAll(){
int* retval;
int i=0;
if (thisMultiDetector->onlineFlag==ONLINE_FLAG) {
startAndReadAllNoWait();
if(getDetectorsType() == EIGER) {
if (prepareAcquisition() == FAIL)
return NULL;
}
startAndReadAllNoWait();
while ((retval=getDataFromDetector())){
i++;

View File

@ -561,7 +561,17 @@ class multiSlsDetector : public slsDetectorUtils {
// Acquisition functions
/**
prepares detector for acquisition
\returns OK if all detectors are properly started, FAIL otherwise
*/
int prepareAcquisition();
/**
prepares detector for acquisition
\returns OK if all detectors are properly started, FAIL otherwise
*/
int cleanupAcquisition();
/**
start detector acquisition (master is started as last)

View File

@ -3976,6 +3976,62 @@ int slsDetector::updateDetector() {
// Acquisition functions
/* change these funcs accepting also ok/fail */
int slsDetector::prepareAcquisition() {
int fnum = F_PREPARE_ACQUISITION;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
if (thisDetector->onlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Preparing Detector for Acquisition" << std::endl;
#endif
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL){
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PREPARE_ACQUISITION));
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}else
std::cout << "cannot connect to detector" << endl;
return ret;
}
int slsDetector::cleanupAcquisition() {
int fnum = F_CLEANUP_ACQUISITION;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
if (thisDetector->onlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Cleaning up Detector after Acquisition " << std::endl;
#endif
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL){
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(CLEANUP_ACQUISITION));
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}else
std::cout << "cannot connect to detector" << endl;
return ret;
}
int slsDetector::startAcquisition(){
@ -4258,6 +4314,10 @@ int* slsDetector::startAndReadAll(){
int i=0;
#endif
//#endif
if(thisDetector->myDetectorType == EIGER) {
if (prepareAcquisition() == FAIL)
return NULL;
}
startAndReadAllNoWait();
//#ifdef VERBOSE
// std::cout<< "started" << std::endl;
@ -4485,7 +4545,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
ret = FAIL;
cout << "ERROR: " << timername << " in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
if(strstr(mess,"receiver not idle")==NULL) {
if(strstr(mess,"receiver is not idle")==NULL) {
switch(index) {
case ACQUISITION_TIME:
setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET));
@ -7859,12 +7919,9 @@ int slsDetector::startReceiver(){
}
}
//let detector prepare anyway even if receiver didnt work (for those not using the receiver)
if((thisDetector->myDetectorType != JUNGFRAU)) {
int ret1 = detectorSendToReceiver(true);
if (ret != FAIL)
ret = ret1;
}
// tell detector to send to receiver (if start receiver failed, this is not executed)
if((thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != EIGER && ret!= FAIL))
return prepareAcquisition(); // send data to receiver for these detectors
return ret;
}
@ -7878,7 +7935,7 @@ int slsDetector::stopReceiver(){
char mess[MAX_STR_LENGTH] = "";
if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU)
detectorSendToReceiver(false);
cleanupAcquisition(); // reset (send data to receiver) for these detectors, so back to CPU (dont care about ok/fail at this point)
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
@ -7924,37 +7981,6 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){
}
int slsDetector::detectorSendToReceiver(bool set){
int fnum;
if(set) fnum=F_PREPARE_ACQUISITION;
else fnum=F_CLEANUP_ACQUISITION;
int ret = FAIL;
char mess[MAX_STR_LENGTH]="";
if (thisDetector->onlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Setting detector to send packets via client to: " << set << std::endl;
#endif
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL){
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}else
std::cout << "cannot connect to detector" << endl;
return ret;
}

View File

@ -1063,6 +1063,17 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
// Acquisition functions
/**
prepares detector for acquisition
\returns OK/FAIL
*/
int prepareAcquisition();
/**
prepares detector for acquisition
\returns OK/FAIL
*/
int cleanupAcquisition();
/**
start detector acquisition
@ -1614,10 +1625,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
runStatus startReceiverReadout();
/** Sets(false) or Resets(true) the CPU bit in detector
\returns OK or FAIL
*/
int detectorSendToReceiver(bool set);
/** gets the status of the listening mode of receiver
\returns status