mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-11 07:10:02 +02:00
sharedmem: slsdetector being modified intensively
This commit is contained in:
parent
55517e6d4c
commit
5e9871720b
@ -666,6 +666,7 @@ void multiSlsDetector::freeSharedMemory()
|
||||
|
||||
// multi detector
|
||||
if (sharedMemory) {
|
||||
sharedMemory->Unmap(thisMultiDetector);
|
||||
sharedMemory->RemoveSharedMemory();
|
||||
delete sharedMemory;
|
||||
}
|
||||
@ -718,11 +719,13 @@ bool multiSlsDetector::initSharedMemory(bool verify)
|
||||
bool created = false;
|
||||
sharedMemory = new SharedMemory(detId, -1);
|
||||
if (SharedMemory::IsExisting(sharedMemory->GetName())) {
|
||||
thisMultiDetector = (sharedMultiSlsDetector*)sharedMemory->OpenSharedMemory(sz, verify);
|
||||
thisMultiDetector = (sharedMultiSlsDetector*)sharedMemory->OpenSharedMemory(sz);
|
||||
if (verify && thisMultiDetector->shmversion != MULTI_SHMVERSION) {
|
||||
cprintf(RED, "Multi shared memory version mismatch "
|
||||
"(expected 0x%x but got 0x%x)\n",
|
||||
cprintf(RED, "Multi shared memory (%d) version mismatch "
|
||||
"(expected 0x%x but got 0x%x)\n", detId,
|
||||
MULTI_SHMVERSION, thisMultiDetector->shmversion);
|
||||
sharedMemory->UnmapSharedMemory(thisMultiDetector);/** is this unncessary? */
|
||||
delete sharedMemory;/** is this unncessary? */
|
||||
throw SharedMemoryException();
|
||||
}
|
||||
} else {
|
||||
@ -930,7 +933,8 @@ std::string multiSlsDetector::exec(const char* cmd)
|
||||
|
||||
|
||||
void multiSlsDetector::setHostname(string s)
|
||||
{
|
||||
{ /* to just add at the end of list,
|
||||
command line should not clear shm upon command hostname */
|
||||
size_t p1 = 0;
|
||||
string temp = string(s);
|
||||
size_t p2 = temp.find('+', p1);
|
||||
@ -990,14 +994,14 @@ void multiSlsDetector::addSlsDetector (std::string s)
|
||||
int pos = detectors.size();
|
||||
slsDetector* sdet = new slsDetector(type, detId, pos, false, this);
|
||||
detectors.push_back(sdet);
|
||||
detectors[pos]->setTCPSocket(s.c_str());
|
||||
detectors[pos]->setOnline(ONLINE_FLAG);
|
||||
thisMultiDetector->numberOfDetectors = detectors.size();
|
||||
|
||||
++thisMultiDetector->numberOfDetectors;
|
||||
detectors[pos]->setHostname(s.c_str());
|
||||
if (detectors[pos]->setOnline() ==ONLINE_FLAG)
|
||||
detectors[pos]->updateDetector();
|
||||
|
||||
thisMultiDetector->dataBytes += detectors[pos]->getDataBytes();
|
||||
thisMultiDetector->dataBytesInclGapPixels += detectors[pos]->getDataBytesInclGapPixels();
|
||||
|
||||
thisMultiDetector->numberOfChannels += detectors[pos]->getTotalNumberOfChannels();
|
||||
thisMultiDetector->maxNumberOfChannels += detectors[pos]->getMaxNumberOfChannels();
|
||||
|
||||
@ -1444,8 +1448,16 @@ int multiSlsDetector::exitServer()
|
||||
|
||||
int multiSlsDetector::readConfigurationFile(string const fname)
|
||||
{
|
||||
freeSharedMemory();
|
||||
clearAllErrorMask();
|
||||
{
|
||||
clearAllErrorMask();
|
||||
freeSharedMemory();
|
||||
|
||||
bool created = initSharedMemory(verify);
|
||||
initializeDetectorStructure(created, verify);
|
||||
initializeMembers(); // also deletes zmq objects and destroys threadpool
|
||||
updateUserdetails();
|
||||
}
|
||||
|
||||
|
||||
multiSlsDetectorClient* cmd;
|
||||
string ans;
|
||||
@ -4886,15 +4898,6 @@ int multiSlsDetector::resetFramesCaught()
|
||||
|
||||
int multiSlsDetector::createReceivingDataSockets(const bool destroy)
|
||||
{
|
||||
|
||||
//number of sockets
|
||||
int numSockets = detectors.size();
|
||||
int numSocketsPerDetector = 1;
|
||||
if (getDetectorsType() == EIGER) {
|
||||
numSocketsPerDetector = 2;
|
||||
}
|
||||
numSockets *= numSocketsPerDetector;
|
||||
|
||||
if (destroy) {
|
||||
cprintf(MAGENTA, "Going to destroy data sockets\n");
|
||||
//close socket
|
||||
@ -4910,6 +4913,13 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy)
|
||||
|
||||
cprintf(MAGENTA, "Going to create data sockets\n");
|
||||
|
||||
int numSockets = detectors.size();
|
||||
int numSocketsPerDetector = 1;
|
||||
if (getDetectorsType() == EIGER) {
|
||||
numSocketsPerDetector = 2;
|
||||
}
|
||||
numSockets *= numSocketsPerDetector;
|
||||
|
||||
for (int i = 0; i < numSockets; ++i) {
|
||||
uint32_t portnum = 0;
|
||||
sscanf(detectors[i / numSocketsPerDetector]->getClientStreamingPort().c_str(), "%d", &portnum);
|
||||
@ -4938,19 +4948,17 @@ void multiSlsDetector::readFrameFromReceiver()
|
||||
|
||||
int nX = thisMultiDetector->numberOfDetector[X]; // to copy data in multi module
|
||||
int nY = thisMultiDetector->numberOfDetector[Y]; // for eiger, to reverse the data
|
||||
int numSockets = detectors.size();
|
||||
bool gappixelsenable = false;
|
||||
bool eiger = false;
|
||||
if (getDetectorsType() == EIGER) {
|
||||
eiger = true;
|
||||
nX *= 2;
|
||||
numSockets *= 2;
|
||||
gappixelsenable = detectors[0]->enableGapPixels(-1) >= 1 ? true : false;
|
||||
}
|
||||
|
||||
bool runningList[numSockets], connectList[numSockets];
|
||||
bool runningList[zmqSocket.size()], connectList[zmqSocket.size()];
|
||||
int numRunning = 0;
|
||||
for (int i = 0; i < numSockets; ++i) {
|
||||
for (int i = 0; i < zmqSocket.size(); ++i) {
|
||||
if (!zmqSocket[i]->Connect()) {
|
||||
connectList[i] = true;
|
||||
runningList[i] = true;
|
||||
@ -4991,7 +4999,7 @@ void multiSlsDetector::readFrameFromReceiver()
|
||||
memset(multiframe, 0xFF, multisize);
|
||||
|
||||
//get each frame
|
||||
for (int isocket = 0; isocket < numSockets; ++isocket) {
|
||||
for (int isocket = 0; isocket < zmqSocket.size(); ++isocket) {
|
||||
|
||||
//if running
|
||||
if (runningList[isocket]) {
|
||||
@ -5011,7 +5019,7 @@ void multiSlsDetector::readFrameFromReceiver()
|
||||
if (image == NULL) {
|
||||
// allocate
|
||||
size = doc["size"].GetUint();
|
||||
multisize = size * numSockets;
|
||||
multisize = size * zmqSocket.size();
|
||||
image = new char[size];
|
||||
multiframe = new char[multisize];
|
||||
memset(multiframe, 0xFF, multisize);
|
||||
@ -5132,7 +5140,7 @@ void multiSlsDetector::readFrameFromReceiver()
|
||||
running = false;
|
||||
else {
|
||||
//starting a new scan/measurement (got dummy data)
|
||||
for (int i = 0; i < numSockets; ++i)
|
||||
for (int i = 0; i < zmqSocket.size(); ++i)
|
||||
runningList[i] = connectList[i];
|
||||
numRunning = numConnected;
|
||||
}
|
||||
@ -5140,7 +5148,7 @@ void multiSlsDetector::readFrameFromReceiver()
|
||||
}
|
||||
|
||||
// Disconnect resources
|
||||
for (int i = 0; i < numSockets; ++i)
|
||||
for (int i = 0; i < zmqSocket.size(); ++i)
|
||||
if (connectList[i])
|
||||
zmqSocket[i]->Disconnect();
|
||||
|
||||
|
@ -13,6 +13,13 @@ ID: $Id$
|
||||
#ifndef MULTI_SLS_DETECTOR_H
|
||||
#define MULTI_SLS_DETECTOR_H
|
||||
|
||||
/**
|
||||
@libdoc The multiSlsDetector class is used to operate several slsDetectors in parallel.
|
||||
* @short This is the base class for multi detector system functionalities
|
||||
* @author Anna Bergamaschi
|
||||
*/
|
||||
|
||||
|
||||
#include "slsDetectorUtils.h"
|
||||
class slsDetector;
|
||||
class SharedMemory;
|
||||
@ -28,15 +35,13 @@ class ZmqSocket;
|
||||
#define SHORT_STRING_LENGTH 50
|
||||
#define DATE_LENGTH 29
|
||||
|
||||
/**
|
||||
@libdoc The multiSlsDetector class is used to operate several slsDetectors in parallel.
|
||||
* @short This is the base class for multi detector system functionalities
|
||||
* @author Anna Bergamaschi
|
||||
*/
|
||||
|
||||
class multiSlsDetector : public slsDetectorUtils {
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @short structure allocated in shared memory to store detector settings for IPC and cache
|
||||
*/
|
||||
typedef struct sharedMultiSlsDetector {
|
||||
|
||||
|
||||
@ -225,24 +230,17 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
using slsDetectorUtils::flatFieldCorrect;
|
||||
using slsDetectorUtils::rateCorrect;
|
||||
using slsDetectorUtils::setBadChannelCorrection;
|
||||
using slsDetectorUtils::readAngularConversion;
|
||||
using slsDetectorUtils::writeAngularConversion;
|
||||
|
||||
/*
|
||||
@short Structure allocated in shared memory to store detector settings and
|
||||
be accessed in parallel by several applications
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id multi detector id
|
||||
* @param verify true to verify if shared memory size matches existing one
|
||||
* @param verify true to verify if shared memory version matches existing one
|
||||
* @param update true to update last user pid, date etc
|
||||
*/
|
||||
multiSlsDetector(int id = 0, bool verify = true, bool update = true);
|
||||
@ -458,20 +456,20 @@ public:
|
||||
void setErrorMaskFromAllDetectors();
|
||||
|
||||
/**
|
||||
Set acquiring flag in shared memory
|
||||
\param b acquiring flag
|
||||
* Set acquiring flag in shared memory
|
||||
* @param b acquiring flag
|
||||
*/
|
||||
void setAcquiringFlag(bool b=false);
|
||||
|
||||
/**
|
||||
Get acquiring flag from shared memory
|
||||
\returns acquiring flag
|
||||
* Get acquiring flag from shared memory
|
||||
* @returns acquiring flag
|
||||
*/
|
||||
bool getAcquiringFlag();
|
||||
|
||||
/**
|
||||
* Check if acquiring flag is set, set error if set
|
||||
* \returns FAIL if not ready, OK if ready
|
||||
* @returns FAIL if not ready, OK if ready
|
||||
*/
|
||||
bool isAcquireReady();
|
||||
|
||||
@ -578,7 +576,7 @@ public:
|
||||
/**
|
||||
* Returns the number of detectors in the multidetector structure
|
||||
* @returns number of detectors
|
||||
*/
|
||||
*/
|
||||
int getNumberOfDetectors();
|
||||
|
||||
/**
|
||||
@ -724,9 +722,9 @@ public:
|
||||
* Checks if the multi detectors are online and sets the online flag
|
||||
* @param online if GET_ONLINE_FLAG, only returns shared memory online flag,
|
||||
* else sets the detector in online/offline state
|
||||
* if OFFLINE_FLAG, (i.e. no communication to the detector - using only local structure - no data acquisition possible!);
|
||||
* if ONLINE_FLAG, detector in online state (i.e. communication to the detector updating the local structure)
|
||||
* @returns online/offline status
|
||||
* if OFFLINE_FLAG, (i.e. no communication to the detector - using only local structure - no data acquisition possible!);
|
||||
* if ONLINE_FLAG, detector in online state (i.e. communication to the detector updating the local structure)
|
||||
* @returns online/offline status
|
||||
*/
|
||||
int setOnline(int const online=GET_ONLINE_FLAG);
|
||||
|
||||
@ -734,7 +732,7 @@ public:
|
||||
* Checks if each of the detectors are online/offline
|
||||
* @returns empty string if they are all online,
|
||||
* else returns concatenation of strings of all detectors that are offline
|
||||
*/
|
||||
*/
|
||||
std::string checkOnline();
|
||||
|
||||
/**
|
||||
@ -1841,7 +1839,7 @@ private:
|
||||
void initializeDetectorStructure(bool created, bool verify = true);
|
||||
|
||||
/**
|
||||
* Initialize class members (and from slsDetectorUtils)
|
||||
* Initialize class members (and from parent classes)
|
||||
*/
|
||||
void initializeMembers();
|
||||
|
||||
|
@ -64,7 +64,7 @@ void* SharedMemory::CreateSharedMemory(size_t sz){
|
||||
return MapSharedMemory(sz);
|
||||
}
|
||||
|
||||
void* SharedMemory::OpenSharedMemory(size_t sz, bool verify){
|
||||
void* SharedMemory::OpenSharedMemory(size_t sz){
|
||||
// open
|
||||
fd = shm_open(name.c_str(), O_RDWR, 0);
|
||||
if (fd < 0) {
|
||||
@ -73,11 +73,6 @@ void* SharedMemory::OpenSharedMemory(size_t sz, bool verify){
|
||||
throw SharedMemoryException();
|
||||
}
|
||||
|
||||
// verification required and size does not match
|
||||
if (verify)
|
||||
VerifySizeMatch(sz);
|
||||
|
||||
// map
|
||||
return MapSharedMemory(sz);
|
||||
}
|
||||
|
||||
|
@ -42,18 +42,15 @@ public:
|
||||
* Create Shared memory and call MapSharedMemory to map it to an address
|
||||
* throws a SharedMemoryException exception on failure to create, ftruncate or map
|
||||
* @param sz of shared memory
|
||||
* @param addr double pointer to address to be mapped
|
||||
*/
|
||||
void* CreateSharedMemory(size_t sz);
|
||||
|
||||
/**
|
||||
* Open existing Shared memory and call MapSharedMemory to map it to an address
|
||||
* throws a SharedMemoryException exception on failure to open, incorrect size if verify true, or map
|
||||
* throws a SharedMemoryException exception on failure to open or map
|
||||
* @param sz of shared memory
|
||||
* @param addr double pointer to address to be mapped
|
||||
* @param verify true to verify if the size matches existing one and return fail if does not match
|
||||
*/
|
||||
void* OpenSharedMemory(size_t sz, bool verify = true);
|
||||
void* OpenSharedMemory(size_t sz);
|
||||
|
||||
/**
|
||||
* Unmap shared memory from an address
|
||||
@ -85,16 +82,13 @@ private:
|
||||
/**
|
||||
* Map shared memory to an address
|
||||
* throws a SharedMemoryException exception on failure
|
||||
* @param addr double pointer to address to be mapped
|
||||
* @param sz of shared memory
|
||||
*/
|
||||
//template <typename myType>
|
||||
// void MapSharedMemory(myType*& addr, size_t sz);
|
||||
void* MapSharedMemory(size_t sz);
|
||||
|
||||
/**
|
||||
* Verify if existing shared memory size matches expected size
|
||||
* @param sz expected size of shared memory, replaced with smaller size if size does not match
|
||||
* @param expectedSize expected size of shared memory, replaced with smaller size if size does not match
|
||||
* @return 0 for success, 1 for fail
|
||||
*/
|
||||
int VerifySizeMatch(size_t expectedSize);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user