From 3114512c3f353c15f99880f639faf0e1a210f05d Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 27 Jun 2018 17:20:05 +0200 Subject: [PATCH] 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 --- .../multiSlsDetector/multiSlsDetector.cpp | 7 +- .../multiSlsDetector/multiSlsDetectorClient.h | 135 +++++++++++------- .../slsDetector/slsDetectorCommand.cpp | 5 +- 3 files changed, 88 insertions(+), 59 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index c5022d8af..69e86450f 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -883,14 +883,15 @@ void multiSlsDetector::initializeMembers(bool verify) { } zmqSocket.clear(); - updateOffsets(); - createThreadPool(); - // get objects from single det shared memory (open) for (int i = 0; i < thisMultiDetector->numberOfDetectors; i++) { slsDetector* sdet = new slsDetector(detId, i, verify, this); detectors.push_back(sdet); } + + // depend on number of detectors + updateOffsets(); + createThreadPool(); } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h index 7eb28830c..80f1e9994 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetectorClient.h @@ -41,52 +41,75 @@ public: return; \ }; \ - - - // multi id scanned - iv=sscanf(argv[0],"%d-%s",&id, cmd); \ - if (iv != 2 || id < 0) \ - id = 0; \ - if (iv == 2 && id >= 0) { \ - argv[0] = cmd; \ - cout << id << "-" ; \ - } \ - - // sls pos scanned - iv=sscanf(argv[0],"%d:%s", &pos, cmd); \ - if (iv != 2 ) \ - pos = -1; \ - if (iv == 2 && pos >= 0) { \ - argv[0] = cmd; \ - cout << pos << ":" ; \ - } \ - - if ((action==slsDetectorDefs::READOUT_ACTION) && (pos != -1) ) { \ - cout << "pos " << pos << "is not allowed for readout!" << endl; \ - return; \ - } \ - - if (!strlen(cmd)) \ - strcpy(cmd, argv[0]); \ - - // special commands - string scmd = cmd; \ - // free without calling multiSlsDetector constructor - if (scmd == "free") { \ - if (pos != -1) \ + if (action==slsDetectorDefs::READOUT_ACTION) { \ + id = 0; \ + pos = -1; \ + if (argc) { \ + // multi id scanned + if (strchr(argv[0],'-')) { \ + iv=sscanf(argv[0],"%d-%s",&id, cmd); \ + //%s needn't be there (if not 1:), so 1 or 2 arguments scanned + if (iv >= 1 && id >= 0) { \ + argv[0] = cmd; \ + cout << id << "-" ; \ + } else { \ + id = 0; \ + } \ + } \ + // single id scanned + if (strchr(argv[0],':')) { \ + iv=sscanf(argv[0],"%d:",&pos, cmd); \ + if (iv == 1 && pos >= 0) { \ + cout << "pos " << pos << " is not allowed for readout!" << endl; \ + return; \ + } \ + } \ + } \ + } else { \ + // multi id scanned + iv=sscanf(argv[0],"%d-%s",&id, cmd); \ + // scan success + if (iv == 2 && id >= 0) { \ + argv[0] = cmd; \ + cout << id << "-" ; \ + } else { \ + 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); \ - else \ + else \ multiSlsDetector::freeSharedMemory(id); \ - return; \ - } \ - // get user details without verify sharedMultiSlsDetector version - else if ((scmd == "user") && (action==slsDetectorDefs::GET_ACTION)) { \ - verify = false; \ - update = false; \ - myDetector=NULL; \ + return; \ + } \ + // get user details without verify sharedMultiSlsDetector version + else if ((scmd == "user") && (action==slsDetectorDefs::GET_ACTION)) { \ + verify = false; \ + update = false; \ + myDetector=NULL; \ + } \ } \ + + cout<<"id:"<executeLine(argc, argv, action); \ - cout << answer<< endl; \ - delete myCmd; \ - if (del) delete myDetector; \ - return; \ - }; \ - - //cout<<"id:"<executeLine(argc, argv, action, pos); \ - cout << argv[0] << " " ; \ + try { \ + 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; \ delete myCmd; \ if (del) delete myDetector; \ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index bb1e7d15e..385599a33 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -2496,7 +2496,10 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { if (action==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); int r_online = myDet->setReceiverOnline(ONLINE_FLAG);