sharedmem: sls_detector_acquire multi and sls index scaning, error message when trying to acquire from a differet multi shm id, updateoffset and create threadpool after adding slsdetectors

This commit is contained in:
maliakal_d 2018-06-27 17:20:05 +02:00
parent 95254619c6
commit 3114512c3f
3 changed files with 88 additions and 59 deletions

View File

@ -883,14 +883,15 @@ void multiSlsDetector::initializeMembers(bool verify) {
} }
zmqSocket.clear(); zmqSocket.clear();
updateOffsets();
createThreadPool();
// get objects from single det shared memory (open) // get objects from single det shared memory (open)
for (int i = 0; i < thisMultiDetector->numberOfDetectors; i++) { for (int i = 0; i < thisMultiDetector->numberOfDetectors; i++) {
slsDetector* sdet = new slsDetector(detId, i, verify, this); slsDetector* sdet = new slsDetector(detId, i, verify, this);
detectors.push_back(sdet); detectors.push_back(sdet);
} }
// depend on number of detectors
updateOffsets();
createThreadPool();
} }

View File

@ -41,52 +41,75 @@ public:
return; \ return; \
}; \ }; \
if (action==slsDetectorDefs::READOUT_ACTION) { \
id = 0; \
// multi id scanned pos = -1; \
iv=sscanf(argv[0],"%d-%s",&id, cmd); \ if (argc) { \
if (iv != 2 || id < 0) \ // multi id scanned
id = 0; \ if (strchr(argv[0],'-')) { \
if (iv == 2 && id >= 0) { \ iv=sscanf(argv[0],"%d-%s",&id, cmd); \
argv[0] = cmd; \ //%s needn't be there (if not 1:), so 1 or 2 arguments scanned
cout << id << "-" ; \ if (iv >= 1 && id >= 0) { \
} \ argv[0] = cmd; \
cout << id << "-" ; \
// sls pos scanned } else { \
iv=sscanf(argv[0],"%d:%s", &pos, cmd); \ id = 0; \
if (iv != 2 ) \ } \
pos = -1; \ } \
if (iv == 2 && pos >= 0) { \ // single id scanned
argv[0] = cmd; \ if (strchr(argv[0],':')) { \
cout << pos << ":" ; \ iv=sscanf(argv[0],"%d:",&pos, cmd); \
} \ if (iv == 1 && pos >= 0) { \
cout << "pos " << pos << " is not allowed for readout!" << endl; \
if ((action==slsDetectorDefs::READOUT_ACTION) && (pos != -1) ) { \ return; \
cout << "pos " << pos << "is not allowed for readout!" << endl; \ } \
return; \ } \
} \ } \
} else { \
if (!strlen(cmd)) \ // multi id scanned
strcpy(cmd, argv[0]); \ iv=sscanf(argv[0],"%d-%s",&id, cmd); \
// scan success
// special commands if (iv == 2 && id >= 0) { \
string scmd = cmd; \ argv[0] = cmd; \
// free without calling multiSlsDetector constructor cout << id << "-" ; \
if (scmd == "free") { \ } else { \
if (pos != -1) \ id = 0; \
} \
// sls pos scanned
iv=sscanf(argv[0],"%d:%s", &pos, cmd); \
// scan success
if (iv == 2 && pos >= 0) { \
argv[0] = cmd; \
cout << pos << ":" ; \
} \
if (iv != 2) { \
pos = -1; \
} \
// remove the %d- and %d:
if (!strlen(cmd)) { \
strcpy(cmd, argv[0]); \
} \
// special commands
string scmd = cmd; \
// free without calling multiSlsDetector constructor
if (scmd == "free") { \
if (pos != -1) \
slsDetector::freeSharedMemory(id, pos); \ slsDetector::freeSharedMemory(id, pos); \
else \ else \
multiSlsDetector::freeSharedMemory(id); \ multiSlsDetector::freeSharedMemory(id); \
return; \ return; \
} \ } \
// get user details without verify sharedMultiSlsDetector version // get user details without verify sharedMultiSlsDetector version
else if ((scmd == "user") && (action==slsDetectorDefs::GET_ACTION)) { \ else if ((scmd == "user") && (action==slsDetectorDefs::GET_ACTION)) { \
verify = false; \ verify = false; \
update = false; \ update = false; \
myDetector=NULL; \ myDetector=NULL; \
} \
} \ } \
cout<<"id:"<<id<<" pos:"<<pos<<endl;
// create multiSlsDetector class if required // create multiSlsDetector class if required
if (myDetector==NULL) { \ if (myDetector==NULL) { \
try { \ try { \
@ -101,22 +124,24 @@ public:
del=1; \ del=1; \
} \ } \
// readout
if (action==slsDetectorDefs::READOUT_ACTION) { \
myCmd=new multiSlsDetectorCommand(myDetector); \
answer=myCmd->executeLine(argc, argv, action); \
cout << answer<< endl; \
delete myCmd; \
if (del) delete myDetector; \
return; \
}; \
//cout<<"id:"<<id<<" pos:"<<pos<<endl;
// call multi detector command line // call multi detector command line
myCmd=new multiSlsDetectorCommand(myDetector); \ myCmd=new multiSlsDetectorCommand(myDetector); \
answer=myCmd->executeLine(argc, argv, action, pos); \ try { \
cout << argv[0] << " " ; \ answer=myCmd->executeLine(argc, argv, action, pos); \
} catch (const SharedMemoryException & e) { \
cout << e.GetMessage() << endl; \
delete myCmd; \
if (del) delete myDetector; \
return; \
} catch (...) { \
cout << " caught exception" << endl; \
delete myCmd; \
if (del) delete myDetector; \
return; \
} \
if (action!=slsDetectorDefs::READOUT_ACTION) { \
cout << argv[0] << " " ; \
} \
cout << answer<< endl; \ cout << answer<< endl; \
delete myCmd; \ delete myCmd; \
if (del) delete myDetector; \ if (del) delete myDetector; \

View File

@ -2496,7 +2496,10 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
if (action==HELP_ACTION) { if (action==HELP_ACTION) {
return helpAcquire(narg,args,HELP_ACTION); return helpAcquire(narg,args,HELP_ACTION);
} }
if (!myDet->getNumberOfDetectors()) {
cprintf(RED, "Error: This shared memory has no detectors added. Aborting.\n");
return string("acquire unsuccessful");
}
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
int r_online = myDet->setReceiverOnline(ONLINE_FLAG); int r_online = myDet->setReceiverOnline(ONLINE_FLAG);