From 69c71e48f6397e3fabab1cbc827fe70265678739 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 25 Jun 2018 18:19:19 +0200 Subject: [PATCH] sharedmem: updated slsdetector, changes left --- .../multiSlsDetector/multiSlsDetector.cpp | 865 +- .../multiSlsDetector/multiSlsDetector.h | 124 +- .../slsDetector/slsDetector.cpp | 14001 ++++++++-------- slsDetectorSoftware/slsDetector/slsDetector.h | 2332 +-- .../slsDetector/slsDetectorUtils.h | 8 +- 5 files changed, 8580 insertions(+), 8750 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index efc980320..a49a82cd8 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -35,8 +35,7 @@ multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) sharedMemory(0), thisMultiDetector(0), client_downstream(false), - threadpool(0) -{ + threadpool(0) { bool created = initSharedMemory(verify); initializeDetectorStructure(created, verify); initializeMembers(); @@ -46,8 +45,7 @@ multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) -multiSlsDetector::~multiSlsDetector() -{ +multiSlsDetector::~multiSlsDetector() { for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { delete(*it); } @@ -67,13 +65,11 @@ multiSlsDetector::~multiSlsDetector() } -bool multiSlsDetector::isMultiSlsDetectorClass() -{ +bool multiSlsDetector::isMultiSlsDetectorClass() { return true; } -std::string multiSlsDetector::concatResultOrPos(std::string (slsDetector::*somefunc)(int), int pos) -{ +std::string multiSlsDetector::concatResultOrPos(std::string (slsDetector::*somefunc)(int), int pos) { if (pos >= 0 && pos < detectors.size()) { return (detectors[pos]->*somefunc)(pos); } else { @@ -99,8 +95,7 @@ T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)()) return minusOneIfDifferent(values); } -std::string multiSlsDetector::callDetectorMember(string (slsDetector::*somefunc)()) -{ +std::string multiSlsDetector::callDetectorMember(string (slsDetector::*somefunc)()) { string concatenatedValue, firstValue; bool valueNotSame = false; @@ -126,8 +121,7 @@ std::string multiSlsDetector::callDetectorMember(string (slsDetector::*somefunc) } template -T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(V), V value) -{ +T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(V), V value) { //(Erik) to handle enums, probably a bad idea but follow previous code T defaultValue = static_cast(-1); std::vector values(detectors.size(), defaultValue); @@ -140,8 +134,8 @@ T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(V), V value) } template -T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(P1, P2), P1 par1, P2 par2) -{ +T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(P1, P2), + P1 par1, P2 par2) { //(Erik) to handle enums, probably a bad idea but follow previous code T defaultValue = static_cast(-1); std::vector values(detectors.size(), defaultValue); @@ -154,8 +148,7 @@ T multiSlsDetector::callDetectorMember(T (slsDetector::*somefunc)(P1, P2), P1 pa } template -T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)()) -{ +T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)()) { if (!threadpool) { cout << "Error in creating threadpool. Exiting" << endl; return -1; @@ -173,8 +166,8 @@ T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)()) } template -T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1), P1 value) -{ +T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1), + P1 value) { if (!threadpool) { cout << "Error in creating threadpool. Exiting" << endl; return -1; @@ -192,8 +185,8 @@ T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1), P } template -T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1, P2), P1 par1, P2 par2) -{ +T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1, P2), + P1 par1, P2 par2) { if (!threadpool) { cout << "Error in creating threadpool. Exiting" << endl; return -1; @@ -210,8 +203,8 @@ T multiSlsDetector::parallelCallDetectorMember(T (slsDetector::*somefunc)(P1, P2 } } -int multiSlsDetector::parallelCallDetectorMember(int (slsDetector::*somefunc)(int, int, int), int v0, int v1, int v2) -{ +int multiSlsDetector::parallelCallDetectorMember(int (slsDetector::*somefunc)(int, int, int), + int v0, int v1, int v2) { if (!threadpool) { cout << "Error in creating threadpool. Exiting" << endl; return -1; @@ -229,8 +222,7 @@ int multiSlsDetector::parallelCallDetectorMember(int (slsDetector::*somefunc)(in } template -T multiSlsDetector::minusOneIfDifferent(const std::vector& return_values) -{ +T multiSlsDetector::minusOneIfDifferent(const std::vector& return_values) { T ret = static_cast(-100); for (int idet = 0; idet < detectors.size(); ++idet) { if (ret == static_cast(-100)) @@ -244,8 +236,7 @@ T multiSlsDetector::minusOneIfDifferent(const std::vector& return_values) } -int multiSlsDetector::decodeNMod(int i, int& id, int& im) -{ +int multiSlsDetector::decodeNMod(int i, int& id, int& im) { #ifdef VERBOSE cout << " Module " << i << " belongs to detector " << id << endl; ; @@ -284,22 +275,23 @@ int multiSlsDetector::decodeNMod(int i, int& id, int& im) } -int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int& channelX, int& channelY) -{ +int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int& channelX, int& channelY) { channelX = -1; channelY = -1; //loop over for (int i = 0; i < detectors.size(); ++i) { //check x offset range if ((offsetX >= thisMultiDetector->offsetX[i]) && - (offsetX < (thisMultiDetector->offsetX[i] + detectors[i]->getMaxNumberOfChannelsInclGapPixels(X)))) { + (offsetX < (thisMultiDetector->offsetX[i] + + detectors[i]->getMaxNumberOfChannelsInclGapPixels(X)))) { if (offsetY == -1) { channelX = offsetX - thisMultiDetector->offsetX[i]; return i; } else { //check y offset range if ((offsetY >= thisMultiDetector->offsetY[i]) && - (offsetY < (thisMultiDetector->offsetY[i] + detectors[i]->getMaxNumberOfChannelsInclGapPixels(Y)))) { + (offsetY < (thisMultiDetector->offsetY[i] + + detectors[i]->getMaxNumberOfChannelsInclGapPixels(Y)))) { channelX = offsetX - thisMultiDetector->offsetX[i]; channelY = offsetY - thisMultiDetector->offsetY[i]; return i; @@ -311,8 +303,7 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int& channelX, in } -double* multiSlsDetector::decodeData(int* datain, int& nn, double* fdata) -{ +double* multiSlsDetector::decodeData(int* datain, int& nn, double* fdata) { double* dataout; if (fdata) @@ -351,8 +342,7 @@ double* multiSlsDetector::decodeData(int* datain, int& nn, double* fdata) int multiSlsDetector::writeDataFile(string fname, double* data, double* err, - double* ang, char dataformat, int nch) -{ + double* ang, char dataformat, int nch) { #ifdef VERBOSE cout << "using overloaded multiSlsDetector function to write formatted data file " << getTotalNumberOfChannels() << endl; @@ -403,8 +393,7 @@ int multiSlsDetector::writeDataFile(string fname, double* data, double* err, } } -int multiSlsDetector::writeDataFile(string fname, int* data) -{ +int multiSlsDetector::writeDataFile(string fname, int* data) { ofstream outfile; int choff = 0, off = 0; #ifdef VERBOSE @@ -420,7 +409,8 @@ int multiSlsDetector::writeDataFile(string fname, int* data) #ifdef VERBOSE cout << " write " << i << " position " << off << " offset " << choff << endl; #endif - detectors[i]->writeDataFile(outfile, detectors[i]->getTotalNumberOfChannels(), data + off, choff); + detectors[i]->writeDataFile(outfile, + detectors[i]->getTotalNumberOfChannels(), data + off, choff); if (detectors[i]->getErrorMask()) setErrorMask(getErrorMask() | (1 << i)); choff += detectors[i]->getMaxNumberOfChannels(); @@ -434,8 +424,8 @@ int multiSlsDetector::writeDataFile(string fname, int* data) } } -int multiSlsDetector::readDataFile(string fname, double* data, double* err, double* ang, char dataformat) -{ +int multiSlsDetector::readDataFile(string fname, double* data, double* err, + double* ang, char dataformat) { #ifdef VERBOSE cout << "using overloaded multiSlsDetector function to read formatted data file " << endl; #endif @@ -453,7 +443,8 @@ int multiSlsDetector::readDataFile(string fname, double* data, double* err, doub if (infile.is_open()) { for (int i = 0; i < detectors.size(); ++i) { - iline += detectors[i]->readDataFile(detectors[i]->getTotalNumberOfChannels(), infile, data + off, pe, pa, dataformat, choff); + iline += detectors[i]->readDataFile(detectors[i]->getTotalNumberOfChannels(), + infile, data + off, pe, pa, dataformat, choff); if (detectors[i]->getErrorMask()) setErrorMask(getErrorMask() | (1 << i)); choff += detectors[i]->getMaxNumberOfChannels(); @@ -472,8 +463,7 @@ int multiSlsDetector::readDataFile(string fname, double* data, double* err, doub return iline; } -int multiSlsDetector::readDataFile(string fname, int* data) -{ +int multiSlsDetector::readDataFile(string fname, int* data) { #ifdef VERBOSE cout << "using overloaded multiSlsDetector function to read raw data file " << endl; #endif @@ -489,7 +479,8 @@ int multiSlsDetector::readDataFile(string fname, int* data) if (infile.is_open()) { for (int i = 0; i < detectors.size(); ++i) { - iline += detectors[i]->readDataFile(infile, data + off, detectors[i]->getTotalNumberOfChannels(), choff); + iline += detectors[i]->readDataFile(infile, data + off, + detectors[i]->getTotalNumberOfChannels(), choff); if (detectors[i]->getErrorMask()) setErrorMask(getErrorMask() | (1 << i)); choff += detectors[i]->getMaxNumberOfChannels(); @@ -504,8 +495,7 @@ int multiSlsDetector::readDataFile(string fname, int* data) } -string multiSlsDetector::getErrorMessage(int& critical) -{ +string multiSlsDetector::getErrorMessage(int& critical) { int64_t multiMask, slsMask = 0; string retval = ""; char sNumber[100]; @@ -514,7 +504,8 @@ string multiSlsDetector::getErrorMessage(int& critical) multiMask = getErrorMask(); if (multiMask) { if (multiMask & MULTI_DETECTORS_NOT_ADDED) { - retval.append("Detectors not added:\n" + string(getNotAddedList()) + string("\n")); + retval.append("Detectors not added:\n" + string(getNotAddedList()) + + string("\n")); critical = 1; } if (multiMask & MULTI_HAVE_DIFFERENT_VALUES) { @@ -551,8 +542,7 @@ string multiSlsDetector::getErrorMessage(int& critical) return retval; } -int64_t multiSlsDetector::clearAllErrorMask() -{ +int64_t multiSlsDetector::clearAllErrorMask() { clearErrorMask(); clearNotAddedList(); for (int idet = 0; idet < detectors.size(); ++idet) @@ -561,26 +551,22 @@ int64_t multiSlsDetector::clearAllErrorMask() return getErrorMask(); } -void multiSlsDetector::setErrorMaskFromAllDetectors() -{ +void multiSlsDetector::setErrorMaskFromAllDetectors() { for (int idet = 0; idet < detectors.size(); ++idet) { if (detectors[idet]->getErrorMask()) setErrorMask(getErrorMask() | (1 << idet)); } } -void multiSlsDetector::setAcquiringFlag(bool b) -{ +void multiSlsDetector::setAcquiringFlag(bool b) { thisMultiDetector->acquiringFlag = b; } -bool multiSlsDetector::getAcquiringFlag() -{ +bool multiSlsDetector::getAcquiringFlag() { return thisMultiDetector->acquiringFlag; } -bool multiSlsDetector::isAcquireReady() -{ +bool multiSlsDetector::isAcquireReady() { if (thisMultiDetector->acquiringFlag) { std::cout << "Acquire has already started. " "If previous acquisition terminated unexpectedly, " @@ -591,13 +577,11 @@ bool multiSlsDetector::isAcquireReady() return OK; } -int multiSlsDetector::checkVersionCompatibility(portType t) -{ +int multiSlsDetector::checkVersionCompatibility(portType t) { return parallelCallDetectorMember(&slsDetector::checkVersionCompatibility, t); } -int64_t multiSlsDetector::getId(idMode mode, int imod) -{ +int64_t multiSlsDetector::getId(idMode mode, int imod) { int id, im; int64_t ret; if (decodeNMod(imod, id, im) >= 0) { @@ -613,8 +597,7 @@ int64_t multiSlsDetector::getId(idMode mode, int imod) } -slsDetector* multiSlsDetector::getSlsDetector(unsigned int pos) -{ +slsDetector* multiSlsDetector::getSlsDetector(unsigned int pos) { if (pos >= 0 && pos < detectors.size()) { return detectors[pos]; } @@ -628,8 +611,7 @@ slsDetector *multiSlsDetector::operator()(int pos) { } -void multiSlsDetector::freeSharedMemory(int multiId) -{ +void multiSlsDetector::freeSharedMemory(int multiId) { // get number of detectors int numDetectors = 0; SharedMemory* shm = new SharedMemory(multiId, -1); @@ -654,8 +636,7 @@ void multiSlsDetector::freeSharedMemory(int multiId) -void multiSlsDetector::freeSharedMemory() -{ +void multiSlsDetector::freeSharedMemory() { // single detector vector for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { @@ -674,8 +655,7 @@ void multiSlsDetector::freeSharedMemory() } -std::string multiSlsDetector::getUserDetails() -{ +std::string multiSlsDetector::getUserDetails() { std::ostringstream sstream; if (!detectors.size()) { @@ -700,8 +680,7 @@ std::string multiSlsDetector::getUserDetails() } -bool multiSlsDetector::initSharedMemory(bool verify) -{ +bool multiSlsDetector::initSharedMemory(bool verify) { // clear if (sharedMemory) @@ -743,8 +722,7 @@ bool multiSlsDetector::initSharedMemory(bool verify) } -void multiSlsDetector::initializeDetectorStructure(bool created, bool verify) -{ +void multiSlsDetector::initializeDetectorStructure(bool created, bool verify) { if (created) { thisMultiDetector->shmversion = MULTI_SHMVERSION; thisMultiDetector->numberOfDetectors = 0; @@ -830,8 +808,7 @@ void multiSlsDetector::initializeDetectorStructure(bool created, bool verify) } } -void multiSlsDetector::initializeMembers() -{ +void multiSlsDetector::initializeMembers() { //slsDetectorUtils stoppedFlag = &thisMultiDetector->stoppedFlag; timerValue = thisMultiDetector->timerValue; @@ -852,7 +829,13 @@ void multiSlsDetector::initializeMembers() flatFieldDir = thisMultiDetector->flatFieldDir; flatFieldFile = thisMultiDetector->flatFieldFile; expTime = &timerValue[ACQUISITION_TIME]; - + badChannelMask = NULL; + fdata = NULL; + thisData = NULL; + ppFun = NULL; + ang = NULL; + val = NULL; + err = NULL; //slsDetectorActions actionMask = &thisMultiDetector->actionMask; @@ -878,6 +861,10 @@ void multiSlsDetector::initializeMembers() //badChannelCorrections.h or postProcessing_Standalone.h badChanFile = thisMultiDetector->badChanFile; + nBadChans = NULL; + badChansList = NULL; + nBadFF = NULL; + badFFList = NULL; //multiSlsDetector for (vector::const_iterator it = zmqSocket.begin(); it != zmqSocket.end(); ++it) { @@ -885,19 +872,12 @@ void multiSlsDetector::initializeMembers() } zmqSocket.clear(); - getNMods(); - getMaxMods(); - getMaxMod(X); - getNMod(X); - getMaxMod(Y); - getNMod(Y); updateOffsets(); createThreadPool(); } -void multiSlsDetector::updateUserdetails() -{ +void multiSlsDetector::updateUserdetails() { thisMultiDetector->lastPID = getpid(); memset(thisMultiDetector->lastUser, 0, SHORT_STRING_LENGTH); memset(thisMultiDetector->lastDate, 0, SHORT_STRING_LENGTH); @@ -911,8 +891,7 @@ void multiSlsDetector::updateUserdetails() } -std::string multiSlsDetector::exec(const char* cmd) -{ +std::string multiSlsDetector::exec(const char* cmd) { int bufsize = 1char buffer[bufsize]; std::string result = ""; FILE* pipe = popen(cmd, "r"); @@ -932,8 +911,8 @@ std::string multiSlsDetector::exec(const char* cmd) } -void multiSlsDetector::setHostname(string s) -{ /* to just add at the end of list, +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); @@ -956,15 +935,13 @@ void multiSlsDetector::setHostname(string s) } -string multiSlsDetector::getHostname(int pos) -{ +string multiSlsDetector::getHostname(int pos) { return concatResultOrPos(&slsDetector::getHostname, pos); } -void multiSlsDetector::addSlsDetector (std::string s) -{ +void multiSlsDetector::addSlsDetector (std::string s) { #ifdef VERBOSE cout << "Adding detector " << s << endl; #endif @@ -1005,19 +982,12 @@ void multiSlsDetector::addSlsDetector (std::string s) thisMultiDetector->numberOfChannels += detectors[pos]->getTotalNumberOfChannels(); thisMultiDetector->maxNumberOfChannels += detectors[pos]->getMaxNumberOfChannels(); - getMaxMods(); - getNMods(); - getMaxMod(X); - getNMod(X); - getMaxMod(Y); - getNMod(Y); updateOffsets(); createThreadPool(); } -slsDetectorDefs::detectorType multiSlsDetector::getDetectorsType(int pos) -{ +slsDetectorDefs::detectorType multiSlsDetector::getDetectorsType(int pos) { detectorType dt = GENERIC; if (pos >= 0 && pos < detectors.size()) { return detectors[pos]->getDetectorsType(); @@ -1027,20 +997,17 @@ slsDetectorDefs::detectorType multiSlsDetector::getDetectorsType(int pos) } -std::string multiSlsDetector::sgetDetectorsType(int pos) -{ +std::string multiSlsDetector::sgetDetectorsType(int pos) { return concatResultOrPos(&slsDetector::sgetDetectorsType, pos); } -std::string getDetectorType() -{ +std::string multiSlsDetector::getDetectorType() { return sgetDetectorsType(); } -void multiSlsDetector::createThreadPool() -{ +void multiSlsDetector::createThreadPool() { if (threadpool) destroyThreadPool(); int numthreads = detectors.size(); @@ -1066,8 +1033,7 @@ void multiSlsDetector::createThreadPool() } -void multiSlsDetector::destroyThreadPool() -{ +void multiSlsDetector::destroyThreadPool() { if (threadpool) { delete threadpool; threadpool = 0; @@ -1078,23 +1044,19 @@ void multiSlsDetector::destroyThreadPool() } -int multiSlsDetector::getNumberOfDetectors() -{ +int multiSlsDetector::getNumberOfDetectors() { return detectors.size(); } -int multiSlsDetector::getNumberOfDetectors(dimension d) -{ +int multiSlsDetector::getNumberOfDetectors(dimension d) { return thisMultiDetector->numberOfDetector[d]; } -void multiSlsDetector::getNumberOfDetectors(int& nx, int& ny) -{ +void multiSlsDetector::getNumberOfDetectors(int& nx, int& ny) { nx=thisMultiDetector->numberOfDetector[X];ny=thisMultiDetector->numberOfDetector[Y]; } -int multiSlsDetector::getNMods() -{ +int multiSlsDetector::getNMods() { int nm = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { nm += (*it)->getNMods(); @@ -1102,8 +1064,7 @@ int multiSlsDetector::getNMods() return nm; } -int multiSlsDetector::getNMod(dimension d) -{ +int multiSlsDetector::getNMod(dimension d) { int nm = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { nm += (*it)->getNMod(d); @@ -1111,8 +1072,7 @@ int multiSlsDetector::getNMod(dimension d) return nm; } -int multiSlsDetector::getMaxMods() -{ +int multiSlsDetector::getMaxMods() { int ret = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { ret += (*it)->getMaxMods(); @@ -1120,13 +1080,13 @@ int multiSlsDetector::getMaxMods() return ret; } -int multiSlsDetector::getMaxMod(dimension d) -{ +int multiSlsDetector::getMaxMod(dimension d) { int ret = 0, ret1; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { ret1 = (*it)->getNMaxMod(d); #ifdef VERBOSE - cout << "detector " << (it-detectors.begin()) << " maxmods " << ret1 << " in direction " << d << endl; + cout << "detector " << (it-detectors.begin()) << " maxmods " << + ret1 << " in direction " << d << endl; #endif ret += ret1; } @@ -1137,8 +1097,7 @@ int multiSlsDetector::getMaxMod(dimension d) return ret; } -int multiSlsDetector::getMaxNumberOfModules(dimension d) -{ +int multiSlsDetector::getMaxNumberOfModules(dimension d) { int ret = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { ret += (*it)->getMaxNumberOfModules(d); @@ -1146,8 +1105,7 @@ int multiSlsDetector::getMaxNumberOfModules(dimension d) return ret; } -int multiSlsDetector::setNumberOfModules(int p, dimension d) -{ +int multiSlsDetector::setNumberOfModules(int p, dimension d) { int ret = 0; int nm = 0, mm = 0, nt = p; @@ -1181,8 +1139,7 @@ int multiSlsDetector::setNumberOfModules(int p, dimension d) return ret; } -int multiSlsDetector::getChansPerMod(int imod) -{ +int multiSlsDetector::getChansPerMod(int imod) { int id = -1, im = -1; decodeNMod(imod, id, im); if (id >= 0 && id < detectors.size()) { @@ -1191,8 +1148,7 @@ int multiSlsDetector::getChansPerMod(int imod) return -1; } -int multiSlsDetector::getTotalNumberOfChannels() -{ +int multiSlsDetector::getTotalNumberOfChannels() { thisMultiDetector->numberOfChannels = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { thisMultiDetector->numberOfChannels += (*it)->getTotalNumberOfChannels(); @@ -1200,18 +1156,15 @@ int multiSlsDetector::getTotalNumberOfChannels() return thisMultiDetector->numberOfChannels; } -int multiSlsDetector::getTotalNumberOfChannels(dimension d) -{ +int multiSlsDetector::getTotalNumberOfChannels(dimension d) { return thisMultiDetector->numberOfChannel[d]; } -int multiSlsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d) -{ +int multiSlsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d) { return thisMultiDetector->numberOfChannelInclGapPixels[d]; } -int multiSlsDetector::getMaxNumberOfChannels() -{ +int multiSlsDetector::getMaxNumberOfChannels() { thisMultiDetector->maxNumberOfChannels = 0; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { thisMultiDetector->maxNumberOfChannels += (*it)->getMaxNumberOfChannels(); @@ -1219,30 +1172,25 @@ int multiSlsDetector::getMaxNumberOfChannels() return thisMultiDetector->maxNumberOfChannels; } -int multiSlsDetector::getMaxNumberOfChannels(dimension d) -{ +int multiSlsDetector::getMaxNumberOfChannels(dimension d) { return thisMultiDetector->maxNumberOfChannel[d]; } -int multiSlsDetector::getMaxNumberOfChannelsInclGapPixels(dimension d) -{ +int multiSlsDetector::getMaxNumberOfChannelsInclGapPixels(dimension d) { return thisMultiDetector->maxNumberOfChannelInclGapPixels[d]; } -int multiSlsDetector::getMaxNumberOfChannelsPerDetector(dimension d) -{ +int multiSlsDetector::getMaxNumberOfChannelsPerDetector(dimension d) { return thisMultiDetector->maxNumberOfChannelsPerDetector[d]; } -int multiSlsDetector::setMaxNumberOfChannelsPerDetector(dimension d,int i) -{ +int multiSlsDetector::setMaxNumberOfChannelsPerDetector(dimension d,int i) { thisMultiDetector->maxNumberOfChannelsPerDetector[d] = i; return thisMultiDetector->maxNumberOfChannelsPerDetector[d]; } -void multiSlsDetector::updateOffsets() -{ +void multiSlsDetector::updateOffsets() { //cannot paralllize due to slsdetector calling this via parentdet-> #ifdef VERBOSE cout << endl @@ -1400,16 +1348,14 @@ void multiSlsDetector::updateOffsets() } -int multiSlsDetector::setOnline(int off) -{ +int multiSlsDetector::setOnline(int off) { if (off != GET_ONLINE_FLAG) thisMultiDetector->onlineFlag = parallelCallDetectorMember(&slsDetector::setOnline, off); return thisMultiDetector->onlineFlag; } -string multiSlsDetector::checkOnline() -{ +string multiSlsDetector::checkOnline() { string offlineDetectors = ""; for (vector::const_iterator it = detectors.begin(); it != detectors.end(); ++it) { string tmp = (*it)->checkOnline(); @@ -1420,23 +1366,19 @@ string multiSlsDetector::checkOnline() } -int multiSlsDetector::setPort(portType t, int p) -{ +int multiSlsDetector::setPort(portType t, int p) { return callDetectorMember(&slsDetector::setPort, t, p); } -int multiSlsDetector::lockServer(int p) -{ +int multiSlsDetector::lockServer(int p) { return callDetectorMember(&slsDetector::lockServer, p); } -string multiSlsDetector::getLastClientIP() -{ +string multiSlsDetector::getLastClientIP() { return callDetectorMember(&slsDetector::getLastClientIP); } -int multiSlsDetector::exitServer() -{ +int multiSlsDetector::exitServer() { int ival = FAIL, iv; for (int idet = 0; idet < detectors.size(); ++idet) { iv = detectors[idet]->exitServer(); @@ -1446,8 +1388,7 @@ int multiSlsDetector::exitServer() return ival; } -int multiSlsDetector::readConfigurationFile(string const fname) -{ +int multiSlsDetector::readConfigurationFile(string const fname) { { clearAllErrorMask(); freeSharedMemory(); @@ -1540,8 +1481,7 @@ int multiSlsDetector::readConfigurationFile(string const fname) } -int multiSlsDetector::writeConfigurationFile(string const fname) -{ +int multiSlsDetector::writeConfigurationFile(string const fname) { string names[] = { "detsizechan", @@ -1627,14 +1567,12 @@ int multiSlsDetector::writeConfigurationFile(string const fname) -string multiSlsDetector::getSettingsFile() -{ +string multiSlsDetector::getSettingsFile() { return callDetectorMember(&slsDetector::getSettingsFile); } -slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) -{ +slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) { int ret = -100; int posmin = 0, posmax = detectors.size(); if (pos >= 0) { @@ -1674,8 +1612,81 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) return (detectorSettings)ret; } -slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings isettings, int pos) -{ + + +int multiSlsDetector::getThresholdEnergy(int pos) { + int i, posmin, posmax; + int ret1 = -100, ret; + + if (pos < 0) { + posmin = 0; + posmax = detectors.size(); + } else { + posmin = pos; + posmax = pos + 1; + } + + for (i = posmin; i < posmax; ++i) { + ret = detectors[i]->getThresholdEnergy(); + if (detectors[i]->getErrorMask()) + setErrorMask(getErrorMask() | (1 << i)); + if (ret1 == -100) + ret1 = ret; + else if (ret < (ret1 - 200) || ret > (ret1 + 200)) + ret1 = -1; + } + thisMultiDetector->currentThresholdEV = ret1; + return ret1; +} + + +int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings, int tb) { + int posmin, posmax; + int ret = -100; + if (pos < 0) { + posmin = 0; + posmax = detectors.size(); + } else { + posmin = pos; + posmax = pos + 1; + } + + if (!threadpool) { + cout << "Error in creating threadpool. Exiting" << endl; + return -1; + } else { + //return storage values + int* iret[posmax - posmin]; + for (int idet = posmin; idet < posmax; ++idet) { + iret[idet] = new int(-1); + Task* task = new Task(new func4_t(&slsDetector::setThresholdEnergy, + detectors[idet], e_eV, -1, isettings, tb, iret[idet])); + threadpool->add_task(task); + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for (int idet = posmin; idet < posmax; ++idet) { + if (iret[idet] != NULL) { + if (ret == -100) + ret = *iret[idet]; + else if (*iret[idet] < (ret - 200) || *iret[idet] > (ret + 200)) + ret = -1; + delete iret[idet]; + } else + ret = -1; + if (detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask() | (1 << idet)); + } + } + + thisMultiDetector->currentThresholdEV = ret; + return ret; +} + + +slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings isettings, + int pos) { int ret = -100; int posmin = 0, posmax = detectors.size(); if (pos >= 0) { @@ -1720,14 +1731,12 @@ slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings } -string multiSlsDetector::getSettingsDir() -{ +string multiSlsDetector::getSettingsDir() { return callDetectorMember(&slsDetector::getSettingsDir); } -string multiSlsDetector::setSettingsDir(string s) -{ +string multiSlsDetector::setSettingsDir(string s) { if (s.find('+') == string::npos) { for (int idet = 0; idet < detectors.size(); ++idet) { @@ -1753,13 +1762,11 @@ string multiSlsDetector::setSettingsDir(string s) return getSettingsDir(); } -string multiSlsDetector::getCalDir() -{ +string multiSlsDetector::getCalDir() { return callDetectorMember(&slsDetector::getCalDir); } -string multiSlsDetector::setCalDir(string s) -{ +string multiSlsDetector::setCalDir(string s) { if (s.find('+') == string::npos) { for (int idet = 0; idet < detectors.size(); ++idet) { @@ -1789,8 +1796,7 @@ string multiSlsDetector::setCalDir(string s) } -int multiSlsDetector::loadSettingsFile(string fname, int imod) -{ +int multiSlsDetector::loadSettingsFile(string fname, int imod) { int ret = OK; // single @@ -1835,8 +1841,7 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) return ret; } -int multiSlsDetector::saveSettingsFile(string fname, int imod) -{ +int multiSlsDetector::saveSettingsFile(string fname, int imod) { int id = -1, im = -1, ret; if (decodeNMod(imod, id, im) >= 0) { @@ -1857,8 +1862,7 @@ int multiSlsDetector::saveSettingsFile(string fname, int imod) } -int multiSlsDetector::loadCalibrationFile(string fname, int imod) -{ +int multiSlsDetector::loadCalibrationFile(string fname, int imod) { int ret = OK; // single @@ -1907,8 +1911,7 @@ int multiSlsDetector::loadCalibrationFile(string fname, int imod) return ret; } -int multiSlsDetector::saveCalibrationFile(string fname, int imod) -{ +int multiSlsDetector::saveCalibrationFile(string fname, int imod) { int id = -1, im = -1, ret; if (decodeNMod(imod, id, im) >= 0) { if (id < 0 || id >= detectors.size()) @@ -1928,8 +1931,7 @@ int multiSlsDetector::saveCalibrationFile(string fname, int imod) -int multiSlsDetector::setMaster(int i) -{ +int multiSlsDetector::setMaster(int i) { int ret = -1, slave = 0; masterFlags f; #ifdef VERBOSE @@ -2007,8 +2009,7 @@ int multiSlsDetector::setMaster(int i) } -slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchronizationMode sync) -{ +slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchronizationMode sync) { synchronizationMode ret = GET_SYNCHRONIZATION_MODE, ret1 = GET_SYNCHRONIZATION_MODE; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -2027,8 +2028,7 @@ slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchr return thisMultiDetector->syncMode; } -slsDetectorDefs::runStatus multiSlsDetector::getRunStatus() -{ +slsDetectorDefs::runStatus multiSlsDetector::getRunStatus() { runStatus s = IDLE, s1 = IDLE; if (thisMultiDetector->masterPosition >= 0) { s = detectors[thisMultiDetector->masterPosition]->getRunStatus(); @@ -2050,8 +2050,7 @@ slsDetectorDefs::runStatus multiSlsDetector::getRunStatus() return s; } -int multiSlsDetector::prepareAcquisition() -{ +int multiSlsDetector::prepareAcquisition() { int i = 0; int ret = OK; @@ -2100,8 +2099,7 @@ int multiSlsDetector::prepareAcquisition() return ret; } -int multiSlsDetector::cleanupAcquisition() -{ +int multiSlsDetector::cleanupAcquisition() { int i = 0; int ret = OK, ret1 = OK; int posmin = 0, posmax = detectors.size(); @@ -2147,8 +2145,7 @@ int multiSlsDetector::cleanupAcquisition() } -int multiSlsDetector::startAcquisition() -{ +int multiSlsDetector::startAcquisition() { if (getDetectorsType() == EIGER) { if (prepareAcquisition() == FAIL) return FAIL; @@ -2201,8 +2198,7 @@ int multiSlsDetector::startAcquisition() } -int multiSlsDetector::stopAcquisition() -{ +int multiSlsDetector::stopAcquisition() { pthread_mutex_lock(&mg); // locks due to processing thread using threadpool when in use int i = 0; int ret = OK, ret1 = OK; @@ -2252,8 +2248,7 @@ int multiSlsDetector::stopAcquisition() } -int multiSlsDetector::startReadOut() -{ +int multiSlsDetector::startReadOut() { int i = 0; int ret = OK, ret1 = OK; i = thisMultiDetector->masterPosition; @@ -2276,8 +2271,7 @@ int multiSlsDetector::startReadOut() } -int* multiSlsDetector::startAndReadAll() -{ +int* multiSlsDetector::startAndReadAll() { #ifdef VERBOSE cout << "Start and read all " << endl; #endif @@ -2312,8 +2306,7 @@ int* multiSlsDetector::startAndReadAll() } -int multiSlsDetector::startAndReadAllNoWait() -{ +int multiSlsDetector::startAndReadAllNoWait() { pthread_mutex_lock(&mg); // locks due to processing thread using threadpool when in use int i = 0; int ret = OK; @@ -2364,8 +2357,7 @@ int multiSlsDetector::startAndReadAllNoWait() -int* multiSlsDetector::getDataFromDetector() -{ +int* multiSlsDetector::getDataFromDetector() { int nel = thisMultiDetector->dataBytes / sizeof(int); int n = 0; @@ -2440,8 +2432,7 @@ int* multiSlsDetector::getDataFromDetector() } -int* multiSlsDetector::readFrame() -{ +int* multiSlsDetector::readFrame() { int nel = thisMultiDetector->dataBytes / sizeof(int); int n; int* retval = new int[nel]; @@ -2473,8 +2464,7 @@ int* multiSlsDetector::readFrame() } -int* multiSlsDetector::readAll() -{ +int* multiSlsDetector::readAll() { int* retval = NULL; int i = 0; #ifdef VERBOSE @@ -2506,8 +2496,7 @@ int* multiSlsDetector::readAll() } -int* multiSlsDetector::popDataQueue() -{ +int* multiSlsDetector::popDataQueue() { int* retval = NULL; if (!dataQueue.empty()) { retval = dataQueue.front(); @@ -2516,8 +2505,7 @@ int* multiSlsDetector::popDataQueue() return retval; } -detectorData* multiSlsDetector::popFinalDataQueue() -{ +detectorData* multiSlsDetector::popFinalDataQueue() { detectorData* retval = NULL; if (!finalDataQueue.empty()) { retval = finalDataQueue.front(); @@ -2526,8 +2514,7 @@ detectorData* multiSlsDetector::popFinalDataQueue() return retval; } -void multiSlsDetector::resetDataQueue() -{ +void multiSlsDetector::resetDataQueue() { int* retval = NULL; while (!dataQueue.empty()) { retval = dataQueue.front(); @@ -2536,8 +2523,7 @@ void multiSlsDetector::resetDataQueue() } } -void multiSlsDetector::resetFinalDataQueue() -{ +void multiSlsDetector::resetFinalDataQueue() { detectorData* retval = NULL; while (!finalDataQueue.empty()) { retval = finalDataQueue.front(); @@ -2546,85 +2532,11 @@ void multiSlsDetector::resetFinalDataQueue() } } -int multiSlsDetector::configureMAC() -{ +int multiSlsDetector::configureMAC() { return callDetectorMember(&slsDetector::configureMAC); } -int multiSlsDetector::getThresholdEnergy(int pos) -{ - int i, posmin, posmax; - int ret1 = -100, ret; - - if (pos < 0) { - posmin = 0; - posmax = detectors.size(); - } else { - posmin = pos; - posmax = pos + 1; - } - - for (i = posmin; i < posmax; ++i) { - ret = detectors[i]->getThresholdEnergy(); - if (detectors[i]->getErrorMask()) - setErrorMask(getErrorMask() | (1 << i)); - if (ret1 == -100) - ret1 = ret; - else if (ret < (ret1 - 200) || ret > (ret1 + 200)) - ret1 = -1; - } - thisMultiDetector->currentThresholdEV = ret1; - return ret1; -} - - -int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings isettings, int tb) -{ - int posmin, posmax; - int ret = -100; - if (pos < 0) { - posmin = 0; - posmax = detectors.size(); - } else { - posmin = pos; - posmax = pos + 1; - } - - if (!threadpool) { - cout << "Error in creating threadpool. Exiting" << endl; - return -1; - } else { - //return storage values - int* iret[posmax - posmin]; - for (int idet = posmin; idet < posmax; ++idet) { - iret[idet] = new int(-1); - Task* task = new Task(new func4_t(&slsDetector::setThresholdEnergy, - detectors[idet], e_eV, -1, isettings, tb, iret[idet])); - threadpool->add_task(task); - } - threadpool->startExecuting(); - threadpool->wait_for_tasks_to_complete(); - for (int idet = posmin; idet < posmax; ++idet) { - if (iret[idet] != NULL) { - if (ret == -100) - ret = *iret[idet]; - else if (*iret[idet] < (ret - 200) || *iret[idet] > (ret + 200)) - ret = -1; - delete iret[idet]; - } else - ret = -1; - if (detectors[idet]->getErrorMask()) - setErrorMask(getErrorMask() | (1 << idet)); - } - } - - thisMultiDetector->currentThresholdEV = ret; - return ret; -} - - -int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t) -{ +int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t) { int64_t ret = parallelCallDetectorMember(&slsDetector::setTimer, index, t); if (index == SAMPLES_JCTB) setDynamicRange(); @@ -2633,8 +2545,7 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t) return ret; } -int64_t multiSlsDetector::getTimeLeft(timerIndex index) -{ +int64_t multiSlsDetector::getTimeLeft(timerIndex index) { int64_t ret = -100; if (thisMultiDetector->masterPosition >= 0) if (detectors[thisMultiDetector->masterPosition]) { @@ -2646,8 +2557,7 @@ int64_t multiSlsDetector::getTimeLeft(timerIndex index) return callDetectorMember(&slsDetector::getTimeLeft, index); } -int multiSlsDetector::setSpeed(speedVariable index, int value) -{ +int multiSlsDetector::setSpeed(speedVariable index, int value) { int i; int ret1 = -100, ret; @@ -2664,8 +2574,7 @@ int multiSlsDetector::setSpeed(speedVariable index, int value) return ret1; } -int multiSlsDetector::setDynamicRange(int p) -{ +int multiSlsDetector::setDynamicRange(int p) { int ret = -100; thisMultiDetector->dataBytes = 0; thisMultiDetector->dataBytesInclGapPixels = 0; @@ -2688,8 +2597,10 @@ int multiSlsDetector::setDynamicRange(int p) for (int idet = 0; idet < detectors.size(); ++idet) { if (iret[idet] != NULL) { thisMultiDetector->dataBytes += detectors[idet]->getDataBytes(); - thisMultiDetector->dataBytesInclGapPixels += detectors[idet]->getDataBytesInclGapPixels(); - thisMultiDetector->numberOfChannels += detectors[idet]->getTotalNumberOfChannels(); + thisMultiDetector->dataBytesInclGapPixels += + detectors[idet]->getDataBytesInclGapPixels(); + thisMultiDetector->numberOfChannels += + detectors[idet]->getTotalNumberOfChannels(); if (ret == -100) ret = *iret[idet]; else if (ret != *iret[idet]) @@ -2717,8 +2628,7 @@ int multiSlsDetector::setDynamicRange(int p) return ret; } -int multiSlsDetector::getDataBytes() -{ +int multiSlsDetector::getDataBytes() { int n_bytes = 0; for (int ip = 0; ip < detectors.size(); ++ip) { n_bytes += detectors[ip]->getDataBytes(); @@ -2727,8 +2637,7 @@ int multiSlsDetector::getDataBytes() } -dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) -{ +dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) { dacs_t ret = -100; // single @@ -2755,8 +2664,8 @@ dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) for (int idet = posmin; idet < posmax; ++idet) { iret[idet] = new dacs_t(-1); - Task* task = new Task(new func4_t(&slsDetector::setDAC, - detectors[idet], val, idac, mV, imod, iret[idet])); + Task* task = new Task(new func4_t + (&slsDetector::setDAC, detectors[idet], val, idac, mV, imod, iret[idet])); threadpool->add_task(task); } threadpool->startExecuting(); @@ -2785,8 +2694,7 @@ dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) return ret; } -dacs_t multiSlsDetector::getADC(dacIndex idac, int imod) -{ +dacs_t multiSlsDetector::getADC(dacIndex idac, int imod) { dacs_t ret = -100; // single @@ -2838,8 +2746,8 @@ dacs_t multiSlsDetector::getADC(dacIndex idac, int imod) } -slsDetectorDefs::externalCommunicationMode multiSlsDetector::setExternalCommunicationMode(externalCommunicationMode pol) -{ +slsDetectorDefs::externalCommunicationMode multiSlsDetector::setExternalCommunicationMode( + externalCommunicationMode pol) { externalCommunicationMode ret, ret1; //(Dhanya) FIXME: why first detector or is it the master one? if (detectors.size()) @@ -2859,8 +2767,8 @@ slsDetectorDefs::externalCommunicationMode multiSlsDetector::setExternalCommunic return ret; } -slsDetectorDefs::externalSignalFlag multiSlsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex) -{ +slsDetectorDefs::externalSignalFlag multiSlsDetector::setExternalSignalFlags( + externalSignalFlag pol, int signalindex) { externalSignalFlag ret, ret1; //(Dhanya) FIXME: why first detector or is it the master one? if (detectors.size()) @@ -2880,8 +2788,7 @@ slsDetectorDefs::externalSignalFlag multiSlsDetector::setExternalSignalFlags(ext return ret; } -int multiSlsDetector::setReadOutFlags(readOutFlags flag) -{ +int multiSlsDetector::setReadOutFlags(readOutFlags flag) { int ret = -100, ret1; for (int idet = 0; idet < detectors.size(); ++idet) { ret1 = detectors[idet]->setReadOutFlags(flag); @@ -2897,8 +2804,7 @@ int multiSlsDetector::setReadOutFlags(readOutFlags flag) } -uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val) -{ +uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val) { uint32_t ret, ret1; for (int i = 0; i < detectors.size(); ++i) { ret = detectors[i]->writeRegister(addr, val); @@ -2918,8 +2824,7 @@ uint32_t multiSlsDetector::writeRegister(uint32_t addr, uint32_t val) } -uint32_t multiSlsDetector::readRegister(uint32_t addr) -{ +uint32_t multiSlsDetector::readRegister(uint32_t addr) { uint32_t ret, ret1; for (int i = 0; i < detectors.size(); ++i) { ret = detectors[i]->readRegister(addr); @@ -2941,8 +2846,7 @@ uint32_t multiSlsDetector::readRegister(uint32_t addr) -uint32_t multiSlsDetector::setBit(uint32_t addr, int n) -{ +uint32_t multiSlsDetector::setBit(uint32_t addr, int n) { uint32_t ret, ret1; for (int i = 0; i < detectors.size(); ++i) { ret1 = detectors[i]->setBit(addr, n); @@ -2961,8 +2865,7 @@ uint32_t multiSlsDetector::setBit(uint32_t addr, int n) return ret; } -uint32_t multiSlsDetector::clearBit(uint32_t addr, int n) -{ +uint32_t multiSlsDetector::clearBit(uint32_t addr, int n) { uint32_t ret, ret1; for (int i = 0; i < detectors.size(); ++i) { ret1 = detectors[i]->clearBit(addr, n); @@ -2981,8 +2884,7 @@ uint32_t multiSlsDetector::clearBit(uint32_t addr, int n) return ret; } -string multiSlsDetector::setNetworkParameter(networkParameter p, string s) -{ +string multiSlsDetector::setNetworkParameter(networkParameter p, string s) { if (s.find('+') == string::npos) { @@ -3030,8 +2932,7 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s) return getNetworkParameter(p); } -string multiSlsDetector::getNetworkParameter(networkParameter p) -{ +string multiSlsDetector::getNetworkParameter(networkParameter p) { string s0 = "", s1 = "", s; string ans = ""; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -3056,8 +2957,7 @@ string multiSlsDetector::getNetworkParameter(networkParameter p) return ans; } -int multiSlsDetector::digitalTest(digitalTestMode mode, int imod) -{ +int multiSlsDetector::digitalTest(digitalTestMode mode, int imod) { int id, im, ret; @@ -3073,8 +2973,7 @@ int multiSlsDetector::digitalTest(digitalTestMode mode, int imod) return -1; } -int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod) -{ +int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod) { int ret = 100; // single @@ -3123,8 +3022,7 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo } -int multiSlsDetector::loadImageToDetector(imageType index, string const fname) -{ +int multiSlsDetector::loadImageToDetector(imageType index, string const fname) { int ret = -100, ret1; short int imageVals[thisMultiDetector->numberOfChannels]; @@ -3160,8 +3058,7 @@ int multiSlsDetector::loadImageToDetector(imageType index, string const fname) return ret; } -int multiSlsDetector::writeCounterBlockFile(string const fname, int startACQ) -{ +int multiSlsDetector::writeCounterBlockFile(string const fname, int startACQ) { int ret = OK, ret1 = OK; short int arg[thisMultiDetector->numberOfChannels]; ofstream outfile; @@ -3194,18 +3091,15 @@ int multiSlsDetector::writeCounterBlockFile(string const fname, int startACQ) return ret; } -int multiSlsDetector::resetCounterBlock(int startACQ) -{ +int multiSlsDetector::resetCounterBlock(int startACQ) { return callDetectorMember(&slsDetector::resetCounterBlock, startACQ); } -int multiSlsDetector::setCounterBit(int i) -{ +int multiSlsDetector::setCounterBit(int i) { return callDetectorMember(&slsDetector::setCounterBit, i); } -void multiSlsDetector::verifyMinMaxROI(int n, ROI r[]) -{ +void multiSlsDetector::verifyMinMaxROI(int n, ROI r[]) { int temp; for (int i = 0; i < n; ++i) { if ((r[i].xmax) < (r[i].xmin)) { @@ -3221,8 +3115,7 @@ void multiSlsDetector::verifyMinMaxROI(int n, ROI r[]) } } -int multiSlsDetector::setROI(int n, ROI roiLimits[]) -{ +int multiSlsDetector::setROI(int n, ROI roiLimits[]) { int ret1 = -100, ret; int i, xmin, xmax, ymin, ymax, channelX, channelY, idet, lastChannelX, lastChannelY, index, offsetX, offsetY; @@ -3354,8 +3247,7 @@ int multiSlsDetector::setROI(int n, ROI roiLimits[]) } -slsDetectorDefs::ROI* multiSlsDetector::getROI(int& n) -{ +slsDetectorDefs::ROI* multiSlsDetector::getROI(int& n) { n = 0; int num = 0, i, j; @@ -3503,8 +3395,7 @@ slsDetectorDefs::ROI* multiSlsDetector::getROI(int& n) return retval; } -int multiSlsDetector::writeAdcRegister(int addr, int val) -{ +int multiSlsDetector::writeAdcRegister(int addr, int val) { int ret, ret1 = -100; @@ -3525,23 +3416,19 @@ int multiSlsDetector::writeAdcRegister(int addr, int val) return ret1; } -int multiSlsDetector::activate(int const enable) -{ +int multiSlsDetector::activate(int const enable) { return callDetectorMember(&slsDetector::activate, enable); } -int multiSlsDetector::getFlippedData(dimension d) -{ +int multiSlsDetector::getFlippedData(dimension d) { return callDetectorMember(&slsDetector::getFlippedData, d); } -int multiSlsDetector::setFlippedData(dimension d, int value) -{ +int multiSlsDetector::setFlippedData(dimension d, int value) { return callDetectorMember(&slsDetector::setFlippedData, d, value); } -int multiSlsDetector::setAllTrimbits(int val, int imod) -{ +int multiSlsDetector::setAllTrimbits(int val, int imod) { int ret = -100; // single @@ -3587,8 +3474,7 @@ int multiSlsDetector::setAllTrimbits(int val, int imod) } -int multiSlsDetector::enableGapPixels(int val) -{ +int multiSlsDetector::enableGapPixels(int val) { if (val > 0 && getDetectorsType() != EIGER) { std::cout << "Not implemented for this detector" << std::endl; val = -1; @@ -3608,8 +3494,7 @@ int multiSlsDetector::enableGapPixels(int val) return ret; } -int multiSlsDetector::setTrimEn(int ne, int* ene) -{ +int multiSlsDetector::setTrimEn(int ne, int* ene) { int ret = -100, ret1; for (int idet = 0; idet < detectors.size(); ++idet) { ret1 = detectors[idet]->setTrimEn(ne, ene); @@ -3623,8 +3508,7 @@ int multiSlsDetector::setTrimEn(int ne, int* ene) return ret; } -int multiSlsDetector::getTrimEn(int* ene) -{ +int multiSlsDetector::getTrimEn(int* ene) { int ret = -100, ret1; for (int idet = 0; idet < detectors.size(); ++idet) { ret1 = detectors[idet]->getTrimEn(ene); @@ -3638,23 +3522,19 @@ int multiSlsDetector::getTrimEn(int* ene) return ret; } -int multiSlsDetector::pulsePixel(int n, int x, int y) -{ +int multiSlsDetector::pulsePixel(int n, int x, int y) { return parallelCallDetectorMember(&slsDetector::pulsePixel, n, x, y); } -int multiSlsDetector::pulsePixelNMove(int n, int x, int y) -{ +int multiSlsDetector::pulsePixelNMove(int n, int x, int y) { return parallelCallDetectorMember(&slsDetector::pulsePixelNMove, n, x, y); } -int multiSlsDetector::pulseChip(int n) -{ +int multiSlsDetector::pulseChip(int n) { return parallelCallDetectorMember(&slsDetector::pulseChip, n); } -int multiSlsDetector::setThresholdTemperature(int val, int imod) -{ +int multiSlsDetector::setThresholdTemperature(int val, int imod) { int ret = -100; // single @@ -3703,8 +3583,7 @@ int multiSlsDetector::setThresholdTemperature(int val, int imod) return ret; } -int multiSlsDetector::setTemperatureControl(int val, int imod) -{ +int multiSlsDetector::setTemperatureControl(int val, int imod) { int ret = -100; // single @@ -3753,8 +3632,7 @@ int multiSlsDetector::setTemperatureControl(int val, int imod) return ret; } -int multiSlsDetector::setTemperatureEvent(int val, int imod) -{ +int multiSlsDetector::setTemperatureEvent(int val, int imod) { int ret = -100; // single @@ -3803,13 +3681,11 @@ int multiSlsDetector::setTemperatureEvent(int val, int imod) return ret; } -int multiSlsDetector::setStoragecellStart(int pos) -{ +int multiSlsDetector::setStoragecellStart(int pos) { return parallelCallDetectorMember(&slsDetector::setStoragecellStart, pos); } -int multiSlsDetector::programFPGA(string fname) -{ +int multiSlsDetector::programFPGA(string fname) { int ret = OK, ret1 = OK; for (int i = 0; i < detectors.size(); ++i) { @@ -3822,8 +3698,7 @@ int multiSlsDetector::programFPGA(string fname) return ret1; } -int multiSlsDetector::resetFPGA() -{ +int multiSlsDetector::resetFPGA() { int ret = OK, ret1 = OK; for (int i = 0; i < detectors.size(); ++i) { @@ -3836,8 +3711,7 @@ int multiSlsDetector::resetFPGA() return ret1; } -int multiSlsDetector::powerChip(int ival) -{ +int multiSlsDetector::powerChip(int ival) { int ret = OK, ret1 = OK; for (int i = 0; i < detectors.size(); ++i) { @@ -3850,8 +3724,7 @@ int multiSlsDetector::powerChip(int ival) return ret1; } -int multiSlsDetector::setAutoComparatorDisableMode(int ival) -{ +int multiSlsDetector::setAutoComparatorDisableMode(int ival) { int ret = OK, ret1 = OK; for (int i = 0; i < detectors.size(); ++i) { @@ -3864,12 +3737,11 @@ int multiSlsDetector::setAutoComparatorDisableMode(int ival) return ret1; } -double multiSlsDetector::getScanStep(int index, int istep){ +double multiSlsDetector::getScanStep(int index, int istep) { return thisMultiDetector->scanSteps[index][istep]; } -int multiSlsDetector::getChanRegs(double* retval, bool fromDetector) -{ +int multiSlsDetector::getChanRegs(double* retval, bool fromDetector) { //nChansDet and currentNumChans is because of varying channel size per detector int n = thisMultiDetector->numberOfChannels, nChansDet, currentNumChans = 0; double retval1[n]; @@ -3887,8 +3759,7 @@ int multiSlsDetector::getChanRegs(double* retval, bool fromDetector) -int multiSlsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod) -{ +int multiSlsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod) { int ret, ret1 = -100; int id = -1, im = -1; int dmi = 0, dma = detectors.size(); @@ -3911,8 +3782,7 @@ int multiSlsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod) return ret1; } -int multiSlsDetector::getMoveFlag(int imod) -{ +int multiSlsDetector::getMoveFlag(int imod) { int id = -1, im = -1; if (decodeNMod(imod, id, im) >= 0) { if (id < 0 || id >= detectors.size()) @@ -3924,8 +3794,7 @@ int multiSlsDetector::getMoveFlag(int imod) return 1; } -int multiSlsDetector::fillModuleMask(int* mM) -{ +int multiSlsDetector::fillModuleMask(int* mM) { int imod = 0, off = 0; if (mM) { for (int i = 0; i < detectors.size(); ++i) { @@ -3940,14 +3809,12 @@ int multiSlsDetector::fillModuleMask(int* mM) } -int multiSlsDetector::calibratePedestal(int frames) -{ +int multiSlsDetector::calibratePedestal(int frames) { return callDetectorMember(&slsDetector::calibratePedestal, frames); } -int multiSlsDetector::setRateCorrection(double t) -{ +int multiSlsDetector::setRateCorrection(double t) { #ifdef VERBOSE std::cout << "Setting rate correction with dead time " << @@ -4018,8 +3885,7 @@ int multiSlsDetector::setRateCorrection(double t) return thisMultiDetector->correctionMask & (1 << RATE_CORRECTION); } -int multiSlsDetector::getRateCorrection(double& t) -{ +int multiSlsDetector::getRateCorrection(double& t) { if (getDetectorsType() == EIGER) { t = getRateCorrectionTau(); return t; @@ -4039,8 +3905,7 @@ int multiSlsDetector::getRateCorrection(double& t) return 0; } -double multiSlsDetector::getRateCorrectionTau() -{ +double multiSlsDetector::getRateCorrectionTau() { double ret = -100.0; int posmax = detectors.size(); @@ -4095,8 +3960,7 @@ double multiSlsDetector::getRateCorrectionTau() return ret; } -int multiSlsDetector::getRateCorrection() -{ +int multiSlsDetector::getRateCorrection() { if (getDetectorsType() == EIGER) { return getRateCorrectionTau(); } @@ -4106,8 +3970,7 @@ int multiSlsDetector::getRateCorrection() return 0; }; -int multiSlsDetector::rateCorrect(double* datain, double* errin, double* dataout, double* errout) -{ +int multiSlsDetector::rateCorrect(double* datain, double* errin, double* dataout, double* errout) { int ichdet = 0; double* perr = errin; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -4123,8 +3986,7 @@ int multiSlsDetector::rateCorrect(double* datain, double* errin, double* dataout } -int multiSlsDetector::setFlatFieldCorrection(string fname) -{ +int multiSlsDetector::setFlatFieldCorrection(string fname) { double* data = new double[thisMultiDetector->numberOfChannels]; double* ffcoefficients = new double[thisMultiDetector->numberOfChannels]; double* fferrors = new double[thisMultiDetector->numberOfChannels]; @@ -4187,8 +4049,7 @@ int multiSlsDetector::setFlatFieldCorrection(string fname) } -int multiSlsDetector::setFlatFieldCorrection(double* corr, double* ecorr) -{ +int multiSlsDetector::setFlatFieldCorrection(double* corr, double* ecorr) { int ichdet = 0; double *p, *ep; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -4208,8 +4069,7 @@ int multiSlsDetector::setFlatFieldCorrection(double* corr, double* ecorr) return 0; } -int multiSlsDetector::getFlatFieldCorrection(double* corr, double* ecorr) -{ +int multiSlsDetector::getFlatFieldCorrection(double* corr, double* ecorr) { int ichdet = 0; double *p, *ep; int ff = 1, dff; @@ -4232,8 +4092,8 @@ int multiSlsDetector::getFlatFieldCorrection(double* corr, double* ecorr) return ff; } -int multiSlsDetector::flatFieldCorrect(double* datain, double* errin, double* dataout, double* errout) -{ +int multiSlsDetector::flatFieldCorrect(double* datain, double* errin, double* dataout, + double* errout) { int ichdet = 0; double* perr = errin; //*pdata, for (int idet = 0; idet < detectors.size(); ++idet) { @@ -4251,8 +4111,7 @@ int multiSlsDetector::flatFieldCorrect(double* datain, double* errin, double* da return 0; } -int multiSlsDetector::setBadChannelCorrection(string fname) -{ +int multiSlsDetector::setBadChannelCorrection(string fname) { int badlist[MAX_BADCHANS]; int nbad = 0; int ret = 0; @@ -4277,8 +4136,7 @@ int multiSlsDetector::setBadChannelCorrection(string fname) return setBadChannelCorrection(nbad, badlist, 0); } -int multiSlsDetector::setBadChannelCorrection(int nbad, int* badlist, int ff) -{ +int multiSlsDetector::setBadChannelCorrection(int nbad, int* badlist, int ff) { int badlistdet[MAX_BADCHANS]; int nbaddet = 0, choff = 0, idet = 0; if (nbad < 1) @@ -4352,8 +4210,7 @@ int multiSlsDetector::setBadChannelCorrection(int nbad, int* badlist, int ff) } -int multiSlsDetector::getBadChannelCorrection(int* bad) -{ +int multiSlsDetector::getBadChannelCorrection(int* bad) { //int ichan; int *bd, nd, ntot = 0, choff = 0; ; @@ -4384,8 +4241,7 @@ int multiSlsDetector::getBadChannelCorrection(int* bad) } -int multiSlsDetector::readAngularConversionFile(string fname) -{ +int multiSlsDetector::readAngularConversionFile(string fname) { ifstream infile; //int nm=0; @@ -4408,8 +4264,7 @@ int multiSlsDetector::readAngularConversionFile(string fname) return 0; } -int multiSlsDetector::writeAngularConversion(string fname) -{ +int multiSlsDetector::writeAngularConversion(string fname) { ofstream outfile; // int nm=0; @@ -4429,8 +4284,7 @@ int multiSlsDetector::writeAngularConversion(string fname) return 0; } -int multiSlsDetector::getAngularConversion(int& direction, angleConversionConstant* angconv) -{ +int multiSlsDetector::getAngularConversion(int& direction, angleConversionConstant* angconv) { int dir = -100, dir1; angleConversionConstant* a1 = angconv; @@ -4455,8 +4309,7 @@ int multiSlsDetector::getAngularConversion(int& direction, angleConversionConsta return 0; } -double multiSlsDetector::setAngularConversionParameter(angleConversionParameter c, double v) -{ +double multiSlsDetector::setAngularConversionParameter(angleConversionParameter c, double v) { double ret = slsDetectorUtils::setAngularConversionParameter(c, v); for (int idet = 0; idet < detectors.size(); ++idet) { detectors[idet]->setAngularConversionParameter(c, v); @@ -4466,8 +4319,7 @@ double multiSlsDetector::setAngularConversionParameter(angleConversionParameter return ret; } -angleConversionConstant* multiSlsDetector::getAngularConversionPointer(int imod) -{ +angleConversionConstant* multiSlsDetector::getAngularConversionPointer(int imod) { int id = -1, im = -1; #ifdef VERBOSE cout << "get angular conversion pointer " << endl; @@ -4481,8 +4333,7 @@ angleConversionConstant* multiSlsDetector::getAngularConversionPointer(int imod) } -int multiSlsDetector::printReceiverConfiguration() -{ +int multiSlsDetector::printReceiverConfiguration() { int ret, ret1 = -100; std::cout << "Printing Receiver configurations for all detectors..." << std::endl; for (int i = 0; i < detectors.size(); ++i) { @@ -4502,8 +4353,7 @@ int multiSlsDetector::printReceiverConfiguration() } -int multiSlsDetector::setReceiverOnline(int off) -{ +int multiSlsDetector::setReceiverOnline(int off) { if (off != GET_ONLINE_FLAG) { thisMultiDetector->receiverOnlineFlag = parallelCallDetectorMember( &slsDetector::setReceiverOnline, off); @@ -4511,8 +4361,7 @@ int multiSlsDetector::setReceiverOnline(int off) return thisMultiDetector->receiverOnlineFlag; } -string multiSlsDetector::checkReceiverOnline() -{ +string multiSlsDetector::checkReceiverOnline() { string retval1 = "", retval; for (int idet = 0; idet < detectors.size(); ++idet) { retval = detectors[idet]->checkReceiverOnline(); @@ -4524,18 +4373,15 @@ string multiSlsDetector::checkReceiverOnline() return retval1; } -int multiSlsDetector::lockReceiver(int lock) -{ +int multiSlsDetector::lockReceiver(int lock) { return callDetectorMember(&slsDetector::lockReceiver, lock); } -string multiSlsDetector::getReceiverLastClientIP() -{ +string multiSlsDetector::getReceiverLastClientIP() { return callDetectorMember(&slsDetector::getReceiverLastClientIP); } -int multiSlsDetector::exitReceiver() -{ +int multiSlsDetector::exitReceiver() { //(Erik) logic is flawed should return fail if any fails? int ival = FAIL, iv; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -4546,12 +4392,11 @@ int multiSlsDetector::exitReceiver() return ival; } -std::string multiSlsDetector::getFilePath(){ +std::string multiSlsDetector::getFilePath() { return setFilePath(); } -string multiSlsDetector::setFilePath(string s) -{ +string multiSlsDetector::setFilePath(string s) { string ret = "errorerror", ret1; for (int idet = 0; idet < detectors.size(); ++idet) { @@ -4567,12 +4412,11 @@ string multiSlsDetector::setFilePath(string s) return fileIO::getFilePath(); } -std::string multiSlsDetector::getFileName(){ +std::string multiSlsDetector::getFileName() { return setFileName(); } -string multiSlsDetector::setFileName(string s) -{ +string multiSlsDetector::setFileName(string s) { string ret = "error"; int posmax = detectors.size(); @@ -4622,32 +4466,28 @@ string multiSlsDetector::setFileName(string s) return ret; } -int multiSlsDetector::setReceiverFramesPerFile(int f) -{ +int multiSlsDetector::setReceiverFramesPerFile(int f) { return parallelCallDetectorMember(&slsDetector::setReceiverFramesPerFile, f); } -fileFormat multiSlsDetector::getFileFormat(){ +fileFormat multiSlsDetector::getFileFormat() { return setFileFormat(); } -slsReceiverDefs::fileFormat multiSlsDetector::setFileFormat(fileFormat f) -{ +slsReceiverDefs::fileFormat multiSlsDetector::setFileFormat(fileFormat f) { return callDetectorMember(&slsDetector::setFileFormat, f); } -int multiSlsDetector::getFileIndex(){ +int multiSlsDetector::getFileIndex() { return setFileIndex(); } -int multiSlsDetector::setFileIndex(int i) -{ +int multiSlsDetector::setFileIndex(int i) { return parallelCallDetectorMember(&slsDetector::setFileIndex, i); } -int multiSlsDetector::startReceiver() -{ +int multiSlsDetector::startReceiver() { int i = 0; int ret = OK; int posmin = 0, posmax = detectors.size(); @@ -4694,8 +4534,7 @@ int multiSlsDetector::startReceiver() return ret; } -int multiSlsDetector::stopReceiver() -{ +int multiSlsDetector::stopReceiver() { int i = 0; int ret = OK, ret1 = OK; int posmin = 0, posmax = detectors.size(); @@ -4741,8 +4580,7 @@ int multiSlsDetector::stopReceiver() return ret; } -slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout() -{ +slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout() { int i = 0; runStatus s = IDLE, s1 = IDLE; i = thisMultiDetector->masterPosition; @@ -4764,8 +4602,7 @@ slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout() return s1; } -slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus() -{ +slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus() { int i = 0; runStatus ret = IDLE; int posmin = 0, posmax = detectors.size(); @@ -4812,8 +4649,7 @@ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus() return ret; } -int multiSlsDetector::getFramesCaughtByAnyReceiver() -{ +int multiSlsDetector::getFramesCaughtByAnyReceiver() { int ret = 0; int i = thisMultiDetector->masterPosition; if (i >= 0) { @@ -4835,8 +4671,7 @@ int multiSlsDetector::getFramesCaughtByAnyReceiver() return -1; } -int multiSlsDetector::getFramesCaughtByReceiver() -{ +int multiSlsDetector::getFramesCaughtByReceiver() { int ret = 0, ret1 = 0; int posmax = detectors.size(); @@ -4876,8 +4711,7 @@ int multiSlsDetector::getFramesCaughtByReceiver() } -int multiSlsDetector::getReceiverCurrentFrameIndex() -{ +int multiSlsDetector::getReceiverCurrentFrameIndex() { int ret = 0, ret1 = 0; for (int i = 0; i < detectors.size(); ++i) { ret1 += detectors[i]->getReceiverCurrentFrameIndex(); @@ -4891,13 +4725,11 @@ int multiSlsDetector::getReceiverCurrentFrameIndex() return ret; } -int multiSlsDetector::resetFramesCaught() -{ +int multiSlsDetector::resetFramesCaught() { return parallelCallDetectorMember(&slsDetector::resetFramesCaught); } -int multiSlsDetector::createReceivingDataSockets(const bool destroy) -{ +int multiSlsDetector::createReceivingDataSockets(const bool destroy) { if (destroy) { cprintf(MAGENTA, "Going to destroy data sockets\n"); //close socket @@ -4922,9 +4754,11 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) for (int i = 0; i < numSockets; ++i) { uint32_t portnum = 0; - sscanf(detectors[i / numSocketsPerDetector]->getClientStreamingPort().c_str(), "%d", &portnum); + sscanf(detectors[i / numSocketsPerDetector]->getClientStreamingPort().c_str(), + "%d", &portnum); portnum += (i % numSocketsPerDetector); - //cout<<"ip to be set to :"<getClientStreamingIP().c_str()<getClientStreamingIP().c_str()<getClientStreamingIP().c_str(), @@ -4943,8 +4777,7 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) return OK; } -void multiSlsDetector::readFrameFromReceiver() -{ +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 @@ -4966,7 +4799,8 @@ void multiSlsDetector::readFrameFromReceiver() } else { // to remember the list it connected to, to disconnect later connectList[i] = false; - cprintf(RED, "Error: Could not connect to socket %s\n", zmqSocket[i]->GetZmqServerAddress()); + cprintf(RED, "Error: Could not connect to socket %s\n", + zmqSocket[i]->GetZmqServerAddress()); runningList[i] = false; } } @@ -5007,7 +4841,8 @@ void multiSlsDetector::readFrameFromReceiver() // HEADER { rapidjson::Document doc; - if (!zmqSocket[isocket]->ReceiveHeader(isocket, doc, SLS_DETECTOR_JSON_HEADER_VERSION)) { + if (!zmqSocket[isocket]->ReceiveHeader(isocket, doc, + SLS_DETECTOR_JSON_HEADER_VERSION)) { zmqSocket[isocket]->CloseHeaderMessage(); // parse error, version error or end of acquisition for socket runningList[isocket] = false; @@ -5038,7 +4873,8 @@ void multiSlsDetector::readFrameFromReceiver() "bytesPerPixel: %f\n" "nPixelsX: %u\n" "nPixelsY: %u\n", - size, multisize, dynamicRange, bytesPerPixel, nPixelsX, nPixelsY); + size, multisize, dynamicRange, bytesPerPixel, + nPixelsX, nPixelsY); #endif } // each time, parse rest of header @@ -5063,8 +4899,10 @@ void multiSlsDetector::readFrameFromReceiver() "coordX: %u\n" "coordY: %u\n" "flippedDataX: %u\n", - currentFileName.c_str(), currentAcquisitionIndex, currentFrameIndex, - currentFileIndex, currentSubFrameIndex, coordX, coordY, flippedDataX); + currentFileName.c_str(), currentAcquisitionIndex, + currentFrameIndex, currentFileIndex, currentSubFrameIndex, + coordX, coordY, + flippedDataX); #endif zmqSocket[isocket]->CloseHeaderMessage(); } @@ -5089,13 +4927,15 @@ void multiSlsDetector::readFrameFromReceiver() #endif if (eiger && flippedDataX) { for (uint32_t i = 0; i < nPixelsY; ++i) { - memcpy(((char*)multiframe) + ((yoffset + (nPixelsY - 1 - i)) * rowoffset) + xoffset, + memcpy(((char*)multiframe) + + ((yoffset + (nPixelsY - 1 - i)) * rowoffset) + xoffset, (char*)image + (i * singledetrowoffset), singledetrowoffset); } } else { for (uint32_t i = 0; i < nPixelsY; ++i) { - memcpy(((char*)multiframe) + ((yoffset + i) * rowoffset) + xoffset, + memcpy(((char*)multiframe) + + ((yoffset + i) * rowoffset) + xoffset, (char*)image + (i * singledetrowoffset), singledetrowoffset); } @@ -5130,7 +4970,8 @@ void multiSlsDetector::readFrameFromReceiver() //all done if (!numRunning) { - // let main thread know that all dummy packets have been received (also from external process), + // let main thread know that all dummy packets have been received + //(also from external process), // main thread can now proceed to measurement finished call back sem_post(&sem_endRTAcquisition); // wait for next scan/measurement, else join thread @@ -5161,8 +5002,7 @@ void multiSlsDetector::readFrameFromReceiver() delete[] multigappixels; } -int multiSlsDetector::processImageWithGapPixels(char* image, char*& gpImage) -{ +int multiSlsDetector::processImageWithGapPixels(char* image, char*& gpImage) { // eiger 4 bit mode int nxb = thisMultiDetector->numberOfDetector[X] * (512 + 3); int nyb = thisMultiDetector->numberOfDetector[Y] * (256 + 1); @@ -5281,29 +5121,24 @@ int multiSlsDetector::processImageWithGapPixels(char* image, char*& gpImage) } -int multiSlsDetector::enableWriteToFile(int enable) -{ +int multiSlsDetector::enableWriteToFile(int enable) { return callDetectorMember(&slsDetector::enableWriteToFile, enable); } -int multiSlsDetector::overwriteFile(int enable) -{ +int multiSlsDetector::overwriteFile(int enable) { return callDetectorMember(&slsDetector::overwriteFile, enable); } -int multiSlsDetector::setReadReceiverFrequency(int freq) -{ +int multiSlsDetector::setReadReceiverFrequency(int freq) { return callDetectorMember(&slsDetector::setReadReceiverFrequency, freq); } -int multiSlsDetector::setReceiverReadTimer(int time_in_ms) -{ +int multiSlsDetector::setReceiverReadTimer(int time_in_ms) { return callDetectorMember(&slsDetector::setReceiverReadTimer, time_in_ms); } -int multiSlsDetector::enableDataStreamingToClient(int enable) -{ +int multiSlsDetector::enableDataStreamingToClient(int enable) { if (enable >= 0) { //destroy data threads if (!enable) @@ -5314,43 +5149,39 @@ int multiSlsDetector::enableDataStreamingToClient(int enable) std::cout << "Could not create data threads in client." << std::endl; //only for the first det as theres no general one setErrorMask(getErrorMask() | (1 << 0)); - detectors[0]->setErrorMask((detectors[0]->getErrorMask()) | (DATA_STREAMING)); + detectors[0]->setErrorMask((detectors[0]->getErrorMask()) | + (DATA_STREAMING)); } } } return client_downstream; } -int multiSlsDetector::enableDataStreamingFromReceiver(int enable) -{ +int multiSlsDetector::enableDataStreamingFromReceiver(int enable) { if (enable >= 0) { - thisMultiDetector->receiver_upstream = parallelCallDetectorMember(&slsDetector::enableDataStreamingFromReceiver, enable); + thisMultiDetector->receiver_upstream = parallelCallDetectorMember( + &slsDetector::enableDataStreamingFromReceiver, enable); } return thisMultiDetector->receiver_upstream; } -int multiSlsDetector::enableReceiverCompression(int i) -{ +int multiSlsDetector::enableReceiverCompression(int i) { return callDetectorMember(&slsDetector::enableReceiverCompression, i); } -int multiSlsDetector::enableTenGigabitEthernet(int i) -{ +int multiSlsDetector::enableTenGigabitEthernet(int i) { return callDetectorMember(&slsDetector::enableTenGigabitEthernet, i); } -int multiSlsDetector::setReceiverFifoDepth(int i) -{ +int multiSlsDetector::setReceiverFifoDepth(int i) { return callDetectorMember(&slsDetector::setReceiverFifoDepth, i); } -int multiSlsDetector::setReceiverSilentMode(int i) -{ +int multiSlsDetector::setReceiverSilentMode(int i) { return callDetectorMember(&slsDetector::setReceiverSilentMode, i); } -int multiSlsDetector::setCTBPattern(string fname) -{ +int multiSlsDetector::setCTBPattern(string fname) { uint64_t word; int addr = 0; FILE* fd = fopen(fname.c_str(), "r"); @@ -5369,13 +5200,11 @@ int multiSlsDetector::setCTBPattern(string fname) } -uint64_t multiSlsDetector::setCTBWord(int addr, uint64_t word) -{ +uint64_t multiSlsDetector::setCTBWord(int addr, uint64_t word) { return callDetectorMember(&slsDetector::setCTBWord, addr, word); } -int multiSlsDetector::setCTBPatLoops(int level, int& start, int& stop, int& n) -{ +int multiSlsDetector::setCTBPatLoops(int level, int& start, int& stop, int& n) { int ret = -100, ret1; for (int idet = 0; idet < detectors.size(); ++idet) { ret1 = detectors[idet]->setCTBPatLoops(level, start, stop, n); @@ -5389,12 +5218,10 @@ int multiSlsDetector::setCTBPatLoops(int level, int& start, int& stop, int& n) return ret; } -int multiSlsDetector::setCTBPatWaitAddr(int level, int addr) -{ +int multiSlsDetector::setCTBPatWaitAddr(int level, int addr) { return callDetectorMember(&slsDetector::setCTBPatWaitAddr, level, addr); } -int multiSlsDetector::setCTBPatWaitTime(int level, uint64_t t) -{ +int multiSlsDetector::setCTBPatWaitTime(int level, uint64_t t) { return callDetectorMember(&slsDetector::setCTBPatWaitTime, level, t); } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 4ac1ca527..df37d6f32 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1,15 +1,3 @@ -/******************************************************************* - -Date: $Date$ -Revision: $Rev$ -Author: $Author$ -URL: $URL$ -ID: $Id$ - - ********************************************************************/ - - - #ifndef MULTI_SLS_DETECTOR_H #define MULTI_SLS_DETECTOR_H @@ -19,8 +7,8 @@ ID: $Id$ * @author Anna Bergamaschi */ - #include "slsDetectorUtils.h" + class slsDetector; class SharedMemory; class ThreadPool; @@ -31,7 +19,7 @@ class ZmqSocket; #include -#define MULTI_SHMVERSION 0x180618 +#define MULTI_SHMVERSION 0x180625 #define SHORT_STRING_LENGTH 50 #define DATE_LENGTH 29 @@ -524,6 +512,7 @@ public: /** * Sets the hostname of all sls detectors in shared memory + * Connects to them to set up online flag * @param s concatenated hostname of all the sls detectors */ void setHostname(std::string s); @@ -554,10 +543,9 @@ public: std::string sgetDetectorsType(int pos=-1); /** - * Just to overload getDetectorType + * Just to overload getDetectorType from users * Concatenates string types of all sls detectors or * returns the detector type of the first sls detector - * @param pos position of sls detector in array, if -1, returns first detector type * @returns detector type of sls detector in position pos, if -1, concatenates */ std::string getDetectorType(); @@ -594,14 +582,14 @@ public: void getNumberOfDetectors(int& nx, int& ny); /** - * Returns sum of all modules per sls detector (Mythen) + * Returns sum of all modules per sls detector from shared memory (Mythen) * Other detectors, it is 1 * @returns sum of all modules per sls detector */ int getNMods(); /** - * Returns sum of all modules per sls detector in dimension d (Mythen) + * Returns sum of all modules per sls detector in dimension d from shared memory (Mythen) * Other detectors, it is 1 * @param d dimension d * @returns sum of all modules per sls detector in dimension d @@ -609,15 +597,14 @@ public: int getNMod(dimension d); /** - * Returns sum of all maximum modules per sls detector (Mythen). + * Returns sum of all maximum modules per sls detector from shared memory (Mythen) * Other detectors, it is 1 * @returns sum of all maximum modules per sls detector */ int getMaxMods(); - /** - * Returns sum of all maximum modules per sls detector in dimension d (Mythen) + * Returns sum of all maximum modules per sls detector in dimension d from shared memory (Mythen) * Other detectors, it is 1 * @param d dimension d * @returns sum of all maximum modules per sls detector in dimension d @@ -625,7 +612,7 @@ public: int getMaxMod(dimension d); /** - * Returns the sum of all maximum modules per sls detector in dimension d (Mythen). + * Returns the sum of all maximum modules per sls detector in dimension d Mythen) * from the detector directly. * Other detectors, it is 1 * @param d dimension d @@ -634,7 +621,7 @@ public: int getMaxNumberOfModules(dimension d=X); /** - * Sets the sum of all modules per sls detector in dimension d (Mythen). + * Sets/Gets the sum of all modules per sls detector in dimension d (Mythen) * from the detector directly. * Other detectors, it is 1 * @param i the number of modules to set to @@ -644,21 +631,22 @@ public: int setNumberOfModules(int i=-1, dimension d=X); /** - * Calculates the position of detector based on module number of entire multi - * detector list and returns the number of channels per that module (Mythen) + * Using module id, returns the number of channels per that module + * from shared memory (Mythen) * @param imod module number of entire multi detector list * @returns number of channels per module imod */ int getChansPerMod(int imod=0); /** - * Returns the total number of channels of all sls detectors + * Returns the total number of channels of all sls detectors from shared memory * @returns the total number of channels of all sls detectors */ int getTotalNumberOfChannels(); /** * Returns the total number of channels of all sls detectors in dimension d + * from shared memory * @param d dimension d * @returns the total number of channels of all sls detectors in dimension d */ @@ -666,7 +654,7 @@ public: /** * Returns the total number of channels of all sls detectors in dimension d - * including gap pixels + * including gap pixels from shared memory * @param d dimension d * @returns the total number of channels of all sls detectors in dimension d * including gap pixels @@ -674,13 +662,15 @@ public: int getTotalNumberOfChannelsInclGapPixels(dimension d); /** - * Returns the maximum number of channels of all sls detectors (Mythen) + * Returns the maximum number of channels of all sls detectors + * from shared memory (Mythen) * @returns the maximum number of channels of all sls detectors */ int getMaxNumberOfChannels(); /** - * Returns the maximum number of channels of all sls detectors in dimension d (Mythen) + * Returns the maximum number of channels of all sls detectors in dimension d + * from shared memory (Mythen) * @param d dimension d * @returns the maximum number of channels of all sls detectors in dimension d */ @@ -688,24 +678,26 @@ public: /** * Returns the total number of channels of all sls detectors in dimension d - * including gap pixels (Mythen) + * including gap pixels from shared memory(Mythen) * @param d dimension d - * @returns the total number of channels of all sls detectors in dimension d + * @returns the maximum number of channels of all sls detectors in dimension d * including gap pixels */ int getMaxNumberOfChannelsInclGapPixels(dimension d); /** - * Returns the maximum number of channels of all sls detectors in each dimension d, - * multi detector shared memory variable to calculate offsets for each sls detector + * Returns the maximum number of channels of all sls detectors in each dimension d + * from shared memory. multi detector shared memory variable to calculate + * offsets for each sls detector * @param d dimension d * @returns the maximum number of channels of all sls detectors in dimension d */ int getMaxNumberOfChannelsPerDetector(dimension d); /** - * Sets the maximum number of channels of all sls detectors in each dimension d, - * multi detector shared memory variable to calculate offsets for each sls detector + * Sets the maximum number of channels of all sls detectors in each dimension d + * from shared memory, multi detector shared memory variable to calculate + * offsets for each sls detector * @param d dimension d * @param i maximum number of channels for multi structure in dimension d * @returns the maximum number of channels of all sls detectors in dimension d @@ -736,9 +728,9 @@ public: std::string checkOnline(); /** - * Set TCP Port of detector or receiver + * Set/Gets TCP Port of detector or receiver * @param t port type - * @param p port number + * @param p port number (-1 gets) * @returns port number */ int setPort(portType t, int p); @@ -791,12 +783,31 @@ public: /** * Load detector settings from the settings file picked from the trimdir/settingsdir + * Eiger only stores in shared memory ( a get will overwrite this) + * For Eiger, one must use threshold * @param isettings settings * @param ipos position in multi list (-1 all) * @returns current settings */ detectorSettings setSettings(detectorSettings isettings, int pos=-1); + /** + * Get threshold energy (Mythen and Eiger) + * @param imod module number (-1 all) + * @returns current threshold value for imod in ev (-1 failed) + */ + int getThresholdEnergy(int imod=-1); + + /** + * Set threshold energy (Mythen and Eiger) + * @param e_eV threshold in eV + * @param imod module number (-1 all) + * @param isettings ev. change settings + * @param tb 1 to include trimbits, 0 to exclude + * @returns current threshold value for imod in ev (-1 failed) + */ + int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS,int tb=1); + /** * Returns the detector trimbit/settings directory \sa sharedSlsDetector * @returns the trimbit/settings directory @@ -827,8 +838,7 @@ public: * Loads the modules settings/trimbits reading from a specific file * file name extension is automatically generated. * @param fname specific settings/trimbits file - * @param imod module index of the entire list, - * from which will be calculated the detector index and the module index (-1 for all) + * @param imod module number (-1 for all) * returns OK or FAIL */ int loadSettingsFile(std::string fname, int imod=-1); @@ -837,8 +847,7 @@ public: * Saves the modules settings/trimbits to a specific file * file name extension is automatically generated. * @param fname specific settings/trimbits file - * @param imod module index of the entire list, - * from which will be calculated the detector index and the module index (-1 for all) + * @param imod module number (-1 for all) * returns OK or FAIL */ int saveSettingsFile(std::string fname, int imod=-1); @@ -847,8 +856,7 @@ public: * Loads the modules calibration data reading from a specific file (Mythen) * file name extension is automatically generated. * @param fname specific calibration file - * @param imod module index of the entire list, - * from which will be calculated the detector index and the module index (-1 for all) + * @param imod module number (-1 for all) * returns OK or FAIL */ int loadCalibrationFile(std::string fname, int imod=-1); @@ -857,15 +865,13 @@ public: * Saves the modules calibration data to a specific file (Mythen) * file name extension is automatically generated. * @param fname specific calibration file - * @param imod module index of the entire list, - * from which will be calculated the detector index and the module index (-1 for all) + * @param imod module number (-1 for all) * returns OK or FAIL */ int saveCalibrationFile(std::string fname, int imod=-1); /** - * (Not implemented in any detector from the client) - * Sets/gets the detector in position i as master of the structure + * Sets/gets the detector in position i as master of the structure (Mythen) * (e.g. it gates the other detectors and therefore must be started as last. * Assumes that signal 0 is gate in, signal 1 is trigger in, signal 2 is gate out * @param i position of master (-1 gets, -2 unset) @@ -873,8 +879,8 @@ public: */ int setMaster(int i=-1); - /** (Not implemented in any detector from the client) - * Sets/gets the synchronization mode of the various detector + /** + * Sets/gets the synchronization mode of the various detector (Mythen) * @param sync syncronization mode * @returns current syncronization mode */ @@ -996,23 +1002,6 @@ public: */ int configureMAC(); - /** - * Get threshold energy (Mythen and Eiger) - * @param imod module number (-1 all) - * @returns current threshold value for imod in ev (-1 failed) - */ - int getThresholdEnergy(int imod=-1); - - /** - * Set threshold energy (Mythen and Eiger) - * @param e_eV threshold in eV - * @param imod module number (-1 all) - * @param isettings ev. change settings - * @param tb 1 to include trimbits, 0 to exclude - * @returns current threshold value for imod in ev (-1 failed) - */ - int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS,int tb=1); - /** * Set/get timer value (not all implemented for all detectors) * @param index timer index @@ -1195,6 +1184,7 @@ public: /** * Set ROI (Gotthard) + * At the moment only one set allowed * @param n number of rois * @param roiLimits array of roi * @returns OK or FAIL @@ -1507,7 +1497,7 @@ public: * Reads an angular conversion file (Mythen, Gotthard) * \sa angleConversionConstant mythenDetector::readAngularConversion * @param fname file to be read - * @rreturns 0 if angular conversion disabled, >0 otherwise + * @returns 0 if angular conversion disabled, >0 otherwise */ int readAngularConversionFile(std::string fname); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 843aabbeb..93c7e453b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -31,22 +31,33 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify, Mu controlSocket(0), stopSocket(0), dataSocket(0), + ffcoefficients(0), + fferrors(0), detectorModules(0), dacs(0), adcs(0), chipregs(0), chanregs(0), gain(0), - offset(0), - ffcoefficients(0), - fferrors(0) -{ + offset(0) { /* called from put hostname command, * so sls shared memory will be created */ - freeSharedMemory(multiId, id); + + // ensure shared memory was not created before + SharedMemory* shm = new SharedMemory(multiId, id); + std::string shmname = shm->GetName(); + if (SharedMemory::IsExisting(shmname)) { + cprintf(YELLOW BOLD,"Warning: Weird, this shared memory should have been " + "deleted before! %s. Freeing it again.\n", shm->GetName().c_str()); + freeSharedMemory(multiId, id); + } + delete shm; + + initSharedMemory(true, type, multiId, verify); - initializeDetectorStructure(true, type, verify); + initializeDetectorStructure(type); initializeMembers(); + initializeDetectorStructurePointers(); } slsDetector::slsDetector(int multiId, int id, bool verify, MultiDet* m) @@ -59,27 +70,35 @@ slsDetector::slsDetector(int multiId, int id, bool verify, MultiDet* m) controlSocket(0), stopSocket(0), dataSocket(0), + ffcoefficients(0), + fferrors(0), detectorModules(0), dacs(0), adcs(0), chipregs(0), chanregs(0), gain(0), - offset(0), - ffcoefficients(0), - fferrors(0) -{ + offset(0) { /* called from multi constructor to populate structure, * so sls shared memory will be opened, not created */ - // shared memory will be opened, hence false + + + // ensure shared memory is existing + SharedMemory* shm = new SharedMemory(multiId, id); + if (!SharedMemory::IsExisting(shmname)) { + cprintf(YELLOW BOLD,"Warning: Corrupted shared memory. It should have been " + "created before! %s.\n", shm->GetName().c_str()); + delete shm; /* is this necessary ?*/ + throw SharedMemoryException(); + } + delete shm; + detectorType type = GetDetectorTypeFromShm(multiId, verify); initSharedMemory(false, type, multiId, verify); - initializeDetectorStructure(false, type, verify); initializeMembers(); } -slsDetector::~slsDetector() -{ +slsDetector::~slsDetector() { if (sharedMemory) { sharedMemory->UnmapSharedMemory(thisMultiDetector); delete sharedMemory; @@ -101,14 +120,12 @@ slsDetector::~slsDetector() } -bool slsDetector::isMultiSlsDetectorClass() -{ +bool slsDetector::isMultiSlsDetectorClass() { return false; } -double* slsDetector::decodeData(int *datain, int &nn, double *fdata) -{ +double* slsDetector::decodeData(int *datain, int &nn, double *fdata) { double *dataout = 0; if (fdata) { @@ -190,37 +207,32 @@ double* slsDetector::decodeData(int *datain, int &nn, double *fdata) } -int64_t slsDetector::clearAllErrorMask() -{ +int64_t slsDetector::clearAllErrorMask() { clearErrorMask(); - pthread_mutex_lock(&ms); + pthread_mutex_lock(&ms); for(int i=0;igetNumberOfDetectors();++i){ if(multiDet->getDetectorId(i) == getDetectorId()) multiDet->setErrorMask(multiDet->getErrorMask()|(0<setAcquiringFlag(b); } -bool slsDetector::getAcquiringFlag() -{ +bool slsDetector::getAcquiringFlag() { return multiDet->getAcquiringFlag(); } -bool slsDetector::isAcquireReady() -{ +bool slsDetector::isAcquireReady() { return multiDet->isAcquireReady(); } -int slsDetector::checkVersionCompatibility(portType t) -{ +int slsDetector::checkVersionCompatibility(portType t) { int fnum = F_CHECK_VERSION; if (t == DATA_PORT) fnum = F_RECEIVER_CHECK_VERSION; @@ -237,13 +249,15 @@ int slsDetector::checkVersionCompatibility(portType t) case JUNGFRAU: arg = APIJUNGFRAU; break; case GOTTHARD: arg = APIGOTTHARD; break; default: - std::cout<< "Check version compatibility is not implemented for this detector" << std::endl; + std::cout<< "Check version compatibility is not implemented for this " + "detector" << std::endl; setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY)); return FAIL; } #ifdef VERBOSE - std::cout<< std::endl<< "Checking version compatibility with detector with value " << hex << arg << std::endl; + std::cout<< std::endl<< "Checking version compatibility with detector with " + "value " << hex << arg << std::endl; #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { // control port @@ -255,7 +269,8 @@ int slsDetector::checkVersionCompatibility(portType t) controlSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Detector returned error: (Control Server) %s", mess); if(strstr(mess,"Unrecognized Function")!=NULL) - std::cout << "The detector server is too old to get API version. Please update detector server!" << std::endl; + std::cout << "The detector server is too old to get API version. " + "Please update detector server!" << std::endl; setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY)); thisDetector->detectorControlAPIVersion = 0; } else { @@ -275,7 +290,8 @@ int slsDetector::checkVersionCompatibility(portType t) stopSocket->ReceiveDataOnly(mess,sizeof(mess)); cprintf(RED, "Detector returned error: (Stop Server) %s", mess); if(strstr(mess,"Unrecognized Function")!=NULL) - std::cout << "The detector server is too old to get API version. Please update detector server!" << std::endl; + std::cout << "The detector server is too old to get API " + "version. Please update detector server!" << std::endl; setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY)); thisDetector->detectorStopAPIVersion = 0; } else { @@ -291,7 +307,8 @@ int slsDetector::checkVersionCompatibility(portType t) else { arg = APIRECEIVER; #ifdef VERBOSE - std::cout<< std::endl<< "Checking version compatibility with receiver with value " << hex << arg << std::endl; + std::cout<< std::endl<< "Checking version compatibility with receiver with " + "value " << hex << arg << std::endl; #endif if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { // data port @@ -302,7 +319,8 @@ int slsDetector::checkVersionCompatibility(portType t) if (ret==FAIL){ setErrorMask((getErrorMask())|(VERSION_COMPATIBILITY)); if(strstr(mess,"Unrecognized Function")!=NULL) - std::cout << "The receiver software is too old to get API version. Please update receiver software!" << std::endl; + std::cout << "The receiver software is too old to get API " + "version. Please update receiver software!" << std::endl; thisDetector->receiverAPIVersion = 0; } else { thisDetector->receiverAPIVersion = arg; @@ -318,8 +336,7 @@ int slsDetector::checkVersionCompatibility(portType t) -int64_t slsDetector::getId( idMode mode, int imod) -{ +int64_t slsDetector::getId( idMode mode, int imod) { int64_t retval=-1; int fnum=F_GET_ID,fnum2 = F_GET_RECEIVER_ID; @@ -373,24 +390,24 @@ int64_t slsDetector::getId( idMode mode, int imod) } else { #ifdef VERBOSE if (mode==MODULE_SERIAL_NUMBER) - std::cout<< "Id of "<< imod <<" is " << hex <RemoveSharedMemory(); delete shm; } -void slsDetector::freeSharedMemory() -{ +void slsDetector::freeSharedMemory() { if (sharedMemory) { sharedMemory->UnmapSharedMemory(thisDetector); sharedMemory->RemoveSharedMemory(); @@ -399,88 +416,17 @@ void slsDetector::freeSharedMemory() thisDetector = 0; } -string slsDetector::setHostname(const char *name) -{ +void slsDetector::setHostname(const char *name) { setTCPSocket(string(name)); - return getHostname(); } -string slsDetector::getHostname() -{ +string slsDetector::getHostname(int pos = -1) { return string(thisDetector->hostname); } -detectorType slsDetector::getDetectorTypeFromShm(int multiId) -{ - SharedMemory* shm = new SharedMemory(multiId, detId); - std::string shmname = shm->GetName(); - - // shm not created before - if (!SharedMemory::IsExisting(shmname)) { - cprintf(RED,"Shared memory %s does not exist.\n" - "Corrupted Multi Shared memory. Please free shared memory.\n", - shmname.c_str()); - throw SharedMemoryException(); - } - - // map basic size of sls detector structure (no need of offsets, just version is required) - slsDetector* sdet = 0; - size_t sz = sizeof(sharedSlsDetector); - - // open, map, verify version, get type - sdet = (sharedSlsDetector*)shm->OpenSharedMemory(sz); - if (verify && thisDetector->shmversion != SLS_SHMVERSION) { - cprintf(RED, "Single shared memory (%d-%d:)version mismatch " - "(expected 0x%x but got 0x%x)\n", - multiId, detId, SLS_SHMVERSION, thisDetector->shmversion); - shm->UnmapSharedMemory(sdet); /** is this unncessary? */ - delete shm;/** is this unncessary? */ - throw SharedMemoryException(); - } - detectorType type = sdet->type; - - // unmap - shm->UnmapSharedMemory(sdet); - delete shm; - - return type; -} - - -slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cport) -{ - int fnum=F_GET_DETECTOR_TYPE; - int retval = FAIL; - detectorType t=GENERIC; - MySocketTCP *s= new MySocketTCP(name, cport); - char m[MAX_STR_LENGTH]; -#ifdef VERBOSE - cout << "Getting detector type " << endl; -#endif - if (s->Connect() >= 0) { - s->SendDataOnly(&fnum,sizeof(fnum)); - s->ReceiveDataOnly(&retval,sizeof(retval)); - if (retval!=FAIL) { - s->ReceiveDataOnly(&t,sizeof(t)); -#ifdef VERBOSE - cout << "Detector type is "<< t << endl; -#endif - } else { - s->ReceiveDataOnly(m,sizeof(m)); - std::cout<< "Detector returned error: " << m << std::endl; - } - s->Disconnect(); - } else { - cout << "Cannot connect to server " << name << " over port " << cport << endl; - } - delete s; - return t; -} - - -void slsDetector::initSharedMemory(bool created, detectorType type, int multiId, bool verify) -{ +void slsDetector::initSharedMemory(bool created, detectorType type, int multiId, + bool verify) { if (sharedMemory) delete sharedMemory; thisDetector = 0; @@ -491,7 +437,7 @@ void slsDetector::initSharedMemory(bool created, detectorType type, int multiId, // shared memory object with name sharedMemory = new SharedMemory(multiId, detId); // create - if (create) { + if (created) { try { thisSingleDet = (sharedSingleDet*)sharedMemory->CreateSharedMemory(sz); } catch(...) { @@ -515,846 +461,610 @@ void slsDetector::initSharedMemory(bool created, detectorType type, int multiId, } -int slsDetector::calculateSharedMemorySize(detectorType type) -{ - int nch = 0, nm = 0, nc = 0, nd = 0, ng = 0, no = 0; - switch(type) { - case MYTHEN: - nch=128; // complete mythen system - nm=24; - nc=10; - nd=6; // dacs+adcs - ng=0; - no=0; - break; - case PICASSO: - nch=128; // complete mythen system - nm=24; - nc=12; - nd=6; // dacs+adcs - ng=0; - no=0; - break; - case GOTTHARD: - nch=128; - nm=1; - nc=10; - nd=13; // dacs+adcs - ng=0; - no=0; - break; - case PROPIX: - nch=22*22; - nm=1; - nc=1; - nd=13; // dacs+adcs - break; - case EIGER: - nch=256*256; // one EIGER half module - nm=1; //modules/detector - nc=4; //chips - nd=16; //dacs+adcs - ng=4; - no=4; - break; - case MOENCH: - nch=160*160; - nm=1; //modules/detector - nc=1; //chips - nd=9; //dacs+adcs - ng=0; - no=0; - break; - case JUNGFRAU: - nch=256*256; - nm=1; //modules/detector - nc=8; //chips - nd=16; //dacs+adcs - ng=0; - no=0; - break; - case JUNGFRAUCTB: - nch=36; //36? is using digital value as well - nm=1; //modules/detector - nc=1; //chips - nd=16; //dacs+adcs - ng=0; - no=0; - break; - default: - nch=0; // dum! - nm=0; //modules/detector - nc=0; //chips - nd=0; //dacs+adcs - ng=0; - no=0; - break; - } - - /** - The size of the shared memory is: - size of shared structure + ffcoefficents +fferrors + modules+ dacs+adcs+chips+chans+gain+offset - */ - int sz = sizeof(sharedSlsDetector) + - nm * ( - 2 * nch * nc * sizeof(double) + - sizeof(sls_detector_module) + - sizeof(int) * nc + - sizeof(dacs_t) * nd + - sizeof(int) * nch * nc + - sizeof(int) * ng + - sizeof(int) * no); -#ifdef VERBOSE - std::cout<<"Size of shared memory is " << sz << std::endl; -#endif - return sz; -} - - -void slsDetector::initializeDetectorStructure(bool created, detectorType type, bool verify) -{ - char *goff = (char*)thisDetector; - - // initialize detector structure to defaults - if (created) { - thisDetector->shmversion = SLS_SHMVERSION; - thisDetector->onlineFlag = OFFLINE_FLAG; - thisDetector->stoppedFlag = 0; - strncpy(thisDetector->hostname, DEFAULT_HOSTNAME, strlength(DEFAULT_HOSTNAME)); - thisDetector->controlPort = DEFAULT_PORTNO; - thisDetector->stopPort = DEFAULT_PORTNO + 1; - thisDetector->myDetectorType = type; - strcpy(thisDetector->settingsDir, getenv("HOME")); - strcpy(thisDetector->calDir, getenv("HOME")); -nTrimEn; -trimEnergies[100]; -progressIndex; -totalProgress; -filePath[MAX_STR_LENGTH]; -nMod[2]; -nMods; -nModMax[2]; -nModsMax; -nChans; -nChan[2]; -nChips; -nChip[2]; -nDacs; -nAdcs; -nGain; -nOffset; -dynamicRange; -dataBytes; -correctionMask; -threadedProcessing; -tDead; -flatFieldDir[MAX_STR_LENGTH]; -flatFieldFile[MAX_STR_LENGTH]; -nBadChans; -badChanFile[MAX_STR_LENGTH]; -badChansList[MAX_BADCHANS]; -nBadFF; -badFFList[MAX_BADCHANS]; -angConvFile[MAX_STR_LENGTH]; -angOff[MAXMODS]; -angDirection; -fineOffset; -globalOffset; -numberOfPositions; -detPositions[MAXPOS]; -binSize; -moveFlag; -nROI; -roiLimits[MAX_ROIS]; -roFlags; -settingsFile[MAX_STR_LENGTH]; -currentSettings; -currentThresholdEV; -timerValue[MAX_TIMERS]; -actionMask; -actionScript[MAX_ACTIONS]; -actionParameter[MAX_ACTIONS]; -scanMode[MAX_SCAN_LEVELS]; -scanScript[MAX_SCAN_LEVELS]; -scanParameter[MAX_SCAN_LEVELS]; -nScanSteps[MAX_SCAN_LEVELS]; -scanSteps[MAX_SCAN_LEVELS]; -scanPrecision[MAX_SCAN_LEVELS]; -ffoff; -fferroff; -modoff; -dacoff; -adcoff; -chipoff; -chanoff; -gainoff; -offsetoff; -receiver_hostname[MAX_STR_LENGTH]; -receiverTCPPort; -receiverUDPPort; -receiverUDPPort2; -receiverUDPIP[MAX_STR_LENGTH]; -receiverUDPMAC[MAX_STR_LENGTH]; -detectorMAC[MAX_STR_LENGTH]; -detectorIP[MAX_STR_LENGTH]; -receiverOnlineFlag; -tenGigaEnable; -flippedData[2]; -zmqport; -receiver_zmqport; -receiver_upstream; -receiver_read_freq; -zmqip[MAX_STR_LENGTH]; -receiver_zmqip[MAX_STR_LENGTH]; -gappixels; -nGappixels[2]; -dataBytesInclGapPixels; -receiver_additionalJsonHeader[MAX_STR_LENGTH]; -receiver_framesPerFile; -detectorControlAPIVersion; -detectorStopAPIVersion; -receiverAPIVersion; - +void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterList& list) { + switch (type) { + case MYTHEN: + detlist.nModMaxX = 24; + detlist.nModMaxY = 1; + detlist.nChanX = 128; + detlist.nChanY = 1; + detlist.nChipX = 10; + detlist.nChipY = 1; + detlist.nDacs = 6; + detlist.nAdcs = 0; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 24; + detlist.moveFlag = 1; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case PICASSO: /** is this needed?*/ + detlist.nModMaxX = 24; + detlist.nModMaxY = 1; + detlist.nChanX = 128; + detlist.nChanY = 1; + detlist.nChipX = 12; + detlist.nChipY = 1; + detlist.nDacs = 6; + detlist.nAdcs = 0; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 24; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case GOTTHARD: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 128; + detlist.nChanY = 1; + detlist.nChipX = 10; + detlist.nChipY = 1; + detlist.nDacs = 8; + detlist.nAdcs = 5; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case PROPIX: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 22; + detlist.nChanY = 22; + detlist.nChipX = 1; + detlist.nChipY = 1; + detlist.nDacs = 8; + detlist.nAdcs = 5; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case MOENCH: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 160; + detlist.nChanY = 160; + detlist.nChipX = 1; + detlist.nChipY = 1; + detlist.nDacs = 8; + detlist.nAdcs = 1; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case JUNGFRAU: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 256; + detlist.nChanY = 256; + detlist.nChipX = 4; + detlist.nChipY = 2; + detlist.nDacs = 16; + detlist.nAdcs = 0; + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange = 16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case JUNGFRAUCTB: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 36; + detlist.nChanY = 1; + detlist.nChipX = 1; + detlist.nChipY = 1; + detlist.nDacs = 16; + detlist.nAdcs = 9;//???? When calculating size, only d+a=16 how come?FIXME + detlist.nGain = 0; + detlist.nOffset = 0; + detlist.dynamicRange =16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 0; + detlist.nGappixelsY = 0; + break; + case EIGER: + detlist.nModMaxX = 1; + detlist.nModMaxY = 1; + detlist.nChanX = 256; + detlist.nChanY = 256; + detlist.nChipX = 4; + detlist.nChipY = 1; + detlist.nDacs = 16; + detlist.nAdcs = 0; + detlist.nGain = 0; // can be set back to 4 in case we require it again + detlist.nOffset = 0; // can be set back to 4 in case we require it again + detlist.dynamicRange = 16; + detlist.moveFlag = 0; + detlist.nGappixelsX = 6; + detlist.nGappixelsY = 1; + break; + default: + cprintf(RED,"Unknown detector type!\n"); + throw Exception(); } } +int slsDetector::calculateSharedMemorySize(detectorType type) { + // get the detector parameters based on type + detParameterList detlist; + setDetectorSpecificParameters(type, detlist); + int nm = detlist.nModMaxX * detlist.nModMaxY; + int nch = detlist.nChanX * detlist.nChanY; + int nc = detlist.nChipX * detlist.nChipY; + int nd = detlist.nDacs + detlist.nAdcs; + int ng = detlist.nGain; + int no = detlist.nOffset; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int slsDetector::initializeDetectorSize(detectorType type) { - char *goff; - goff=(char*)thisDetector; - - // cout << "init detector size" << endl; - - /** if the shared memory has newly be created, initialize the detector variables */ - if (thisDetector->alreadyExisting==0) { - - // cout << "detector not existing " << endl; - - /** set hostname to default */ - strcpy(thisDetector->hostname,DEFAULT_HOSTNAME); - - /** set receiver tcp port */ - thisDetector->receiverTCPPort=DEFAULT_PORTNO+2; - /** set receiver udp port */ - thisDetector->receiverUDPPort=DEFAULT_UDP_PORTNO; - /** set receiver udp port for Eiger */ - thisDetector->receiverUDPPort2=DEFAULT_UDP_PORTNO+1; - /** set receiver ip address/hostname */ - memset(thisDetector->receiver_hostname,0,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_hostname,"none"); - /** set receiver udp ip address */ - memset(thisDetector->receiverUDPIP,0,MAX_STR_LENGTH); - strcpy(thisDetector->receiverUDPIP,"none"); - /** set receiver udp mac address */ - memset(thisDetector->receiverUDPMAC,0,MAX_STR_LENGTH); - strcpy(thisDetector->receiverUDPMAC,"none"); - /** set detector mac address */ - memset(thisDetector->detectorMAC,0,MAX_STR_LENGTH); - strcpy(thisDetector->detectorMAC,DEFAULT_DET_MAC); - /** set detector ip address */ - memset(thisDetector->detectorIP,0,MAX_STR_LENGTH); - strcpy(thisDetector->detectorIP,DEFAULT_DET_IP); - /** set zmq tcp src ip address in client */ - memset(thisDetector->zmqip,0,MAX_STR_LENGTH); - /** set zmq tcp src ip address in receiver*/ - memset(thisDetector->receiver_zmqip,0,MAX_STR_LENGTH); - /** set additional json header in receiver*/ - memset(thisDetector->receiver_additionalJsonHeader,0,MAX_STR_LENGTH); - - - /** sets onlineFlag to OFFLINE_FLAG */ - thisDetector->onlineFlag=OFFLINE_FLAG; - /** set ports to defaults */ - thisDetector->controlPort=DEFAULT_PORTNO; - thisDetector->stopPort=DEFAULT_PORTNO+1; - - /** set thisDetector->myDetectorType to type and according to this set nChans, nChips, nDacs, nAdcs, nModMax, dynamicRange, nMod*/ - thisDetector->myDetectorType=type; - thisDetector->gappixels = 0; - thisDetector->nGappixels[X]=0; - thisDetector->nGappixels[Y]=0; - switch(thisDetector->myDetectorType) { - case MYTHEN: - thisDetector->nChan[X]=128; - thisDetector->nChan[Y]=1; - thisDetector->nChip[X]=10; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=6; - thisDetector->nAdcs=0; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=24; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=24; - thisDetector->moveFlag=1; + /** The size of the shared memory is + * size of shared structure + + * ffcoefficents+fferrors+modules+dacs+adcs+chips+chans+gain+offset */ + int sz = sizeof(sharedSlsDetector) + + nm * ( + 2 * nch * nc * sizeof(double) + + sizeof(sls_detector_module) + + sizeof(int) * nc + + sizeof(dacs_t) * nd + + sizeof(int) * nch * nc + + sizeof(int) * ng + + sizeof(int) * no); #ifdef VERBOSE - cout << "move flag" << thisDetector->moveFlag<< endl; + std::cout<<"Size of shared memory is " << sz << std::endl; #endif - break; - case PICASSO: - thisDetector->nChan[X]=128; - thisDetector->nChan[Y]=1; - thisDetector->nChip[X]=12; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=6; - thisDetector->nAdcs=0; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=6; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=24; - break; - case GOTTHARD: - thisDetector->nChan[X]=128; - thisDetector->nChan[Y]=1; - thisDetector->nChip[X]=10; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=8; - thisDetector->nAdcs=5; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - break; - case PROPIX: - thisDetector->nChan[X]=22; - thisDetector->nChan[Y]=22; - thisDetector->nChip[X]=1; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=8; - thisDetector->nAdcs=5; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - break; - case MOENCH: - thisDetector->nChan[X]=160; - thisDetector->nChan[Y]=160; - thisDetector->nChip[X]=1; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=8; - thisDetector->nAdcs=1; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - break; - case JUNGFRAU: - thisDetector->nChan[X]=256; - thisDetector->nChan[Y]=256; - thisDetector->nChip[X]=4; - thisDetector->nChip[Y]=2; - thisDetector->nDacs=16; - thisDetector->nAdcs=0; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - break; - case JUNGFRAUCTB: - thisDetector->nChan[X]=36; - thisDetector->nChan[Y]=1; - thisDetector->nChip[X]=1; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=16; - thisDetector->nAdcs=9; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - break; - case EIGER: - thisDetector->nChan[X]=256; - thisDetector->nChan[Y]=256; - thisDetector->nChip[X]=4; - thisDetector->nChip[Y]=1; - thisDetector->nDacs=16; - thisDetector->nAdcs=0; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=1; - thisDetector->nModMax[Y]=1; - thisDetector->dynamicRange=16; - thisDetector->nGappixels[X]=6; - thisDetector->nGappixels[Y]=1; - break; - default: - thisDetector->nChan[X]=0; - thisDetector->nChan[Y]=0; - thisDetector->nChip[X]=0; - thisDetector->nChip[Y]=0; - thisDetector->nDacs=0; - thisDetector->nAdcs=0; - thisDetector->nGain=0; - thisDetector->nOffset=0; - thisDetector->nModMax[X]=0; - thisDetector->nModMax[Y]=0; - thisDetector->dynamicRange=32; - } - thisDetector->nChans=thisDetector->nChan[X]*thisDetector->nChan[Y]; - thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y]; - thisDetector->nModsMax=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; - /** number of modules is initally the maximum number of modules */ - thisDetector->nMod[X]=thisDetector->nModMax[X]; - thisDetector->nMod[Y]=thisDetector->nModMax[Y]; - thisDetector->nMods=thisDetector->nModsMax; - /** calculates the expected data size */ - thisDetector->timerValue[PROBES_NUMBER]=0; - thisDetector->timerValue[FRAME_NUMBER]=1; - thisDetector->timerValue[MEASUREMENTS_NUMBER]=1; - thisDetector->timerValue[CYCLES_NUMBER]=1; - thisDetector->timerValue[SAMPLES_JCTB]=1; - - // calculating databytes (special when with gap pixels, jctb, mythen in 24bit mode or using probes) - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - thisDetector->dynamicRange/8; - - if(thisDetector->myDetectorType==JUNGFRAUCTB){ - getTotalNumberOfChannels(); - } - else if(thisDetector->myDetectorType==MYTHEN){ - if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - 4; - } - } - - /** set trimDsdir, calDir to default to home directory*/ - strcpy(thisDetector->settingsDir,getenv("HOME")); - strcpy(thisDetector->calDir,getenv("HOME")); - - /** sets trimbit file */ - strcpy(thisDetector->settingsFile,"none"); - /** set progress Index to default to 0*/ - thisDetector->progressIndex=0; - /** set total number of frames to be acquired to default to 1*/ - thisDetector->totalProgress=1; - - /** set trimDsdir, calDir and filePath to default to root directory*/ - strcpy(thisDetector->filePath,"/"); - - /** set number of trim energies to 0*/ - thisDetector->nTrimEn=0; - /** set correction mask to 0*/ - thisDetector->correctionMask=0; - /** set deat time*/ - thisDetector->tDead=0; - /** sets bad channel list file to none */ - strcpy(thisDetector->badChanFile,"none"); - /** sets flat field correction directory */ - strcpy(thisDetector->flatFieldDir,getenv("HOME")); - /** sets flat field correction file */ - strcpy(thisDetector->flatFieldFile,"none"); - /** set number of bad chans to 0*/ - thisDetector->nBadChans=0; - /** set number of bad flat field chans to 0*/ - thisDetector->nBadFF=0; - /** set angular direction to 1*/ - thisDetector->angDirection=1; - /** set fine offset to 0*/ - thisDetector->fineOffset=0; - /** set global offset to 0*/ - thisDetector->globalOffset=0; - /** set number of rois to 0*/ - thisDetector->nROI=0; - /** set readoutflags to none*/ - thisDetector->roFlags=NORMAL_READOUT; - /** set current settings to uninitialized*/ - thisDetector->currentSettings=UNINITIALIZED; - /** set threshold to -1*/ - thisDetector->currentThresholdEV=-1; - // /** set clockdivider to 1*/ - // thisDetector->clkDiv=1; - /** set number of positions to 0*/ - thisDetector->numberOfPositions=0; - /** sets angular conversion file to none */ - strcpy(thisDetector->angConvFile,"none"); - /** set binsize*/ - thisDetector->binSize=0.001; - thisDetector->stoppedFlag=0; - thisDetector->threadedProcessing=1; - - thisDetector->actionMask=0; - - thisDetector->tenGigaEnable=0; - thisDetector->flippedData[0] = 0; - thisDetector->flippedData[1] = 0; - thisDetector->zmqport = 0; - thisDetector->receiver_zmqport = 0; - thisDetector->receiver_upstream = false; - thisDetector->receiver_read_freq = 0; - thisDetector->receiver_framesPerFile = -1; - - thisDetector->detectorControlAPIVersion = 0; - thisDetector->detectorStopAPIVersion = 0; - thisDetector->receiverAPIVersion = 0; - - for (int ia=0; iaactionScript[ia],"none"); - strcpy(thisDetector->actionParameter[ia],"none"); - } - - - for (int iscan=0; iscanscanMode[iscan]=0; - strcpy(thisDetector->scanScript[iscan],"none"); - strcpy(thisDetector->scanParameter[iscan],"none"); - thisDetector->nScanSteps[iscan]=0; - thisDetector->scanPrecision[iscan]=0; - } - - /* receiver*/ - /** sets receiver onlineFlag to OFFLINE_FLAG */ - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; - - - /** calculates the memory offsets for flat field coefficients and errors, module structures, dacs, adcs, chips and channels */ - thisDetector->ffoff=sizeof(sharedSlsDetector); - thisDetector->fferroff=thisDetector->ffoff+sizeof(double)*thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax; - thisDetector->modoff= thisDetector->fferroff+sizeof(double)*thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax; - thisDetector->dacoff=thisDetector->modoff+sizeof(sls_detector_module)*thisDetector->nModsMax; - thisDetector->adcoff=thisDetector->dacoff+sizeof(dacs_t)*thisDetector->nDacs*thisDetector->nModsMax; - thisDetector->chipoff=thisDetector->adcoff+sizeof(dacs_t)*thisDetector->nAdcs*thisDetector->nModsMax; - thisDetector->chanoff=thisDetector->chipoff+sizeof(int)*thisDetector->nChips*thisDetector->nModsMax; - thisDetector->gainoff=thisDetector->chanoff+sizeof(int)*thisDetector->nGain*thisDetector->nModsMax; - thisDetector->offsetoff=thisDetector->gainoff+sizeof(int)*thisDetector->nOffset*thisDetector->nModsMax; - - if(thisDetector->myDetectorType==JUNGFRAUCTB) { - getTotalNumberOfChannels(); - } - - } - - - /** also in case thisDetector alread existed initialize the pointer for flat field coefficients and errors, module structures, dacs, adcs, chips and channels */ - ffcoefficients=(double*)(goff+thisDetector->ffoff); - fferrors=(double*)(goff+thisDetector->fferroff); - detectorModules=(sls_detector_module*)(goff+ thisDetector->modoff); -#ifdef VERBOSE - // for (int imod=0; imod< thisDetector->nModsMax; ++imod) - // std::cout<< hex << detectorModules+imod << dec <nBadChans; - badChansList=thisDetector->badChansList; - badChanFile=thisDetector->badChanFile; - nBadFF=&thisDetector->nBadFF; - badFFList=thisDetector->badFFList; - - dacs=(dacs_t*)(goff+thisDetector->dacoff); - adcs=(dacs_t*)(goff+thisDetector->adcoff); - chipregs=(int*)(goff+thisDetector->chipoff); - chanregs=(int*)(goff+thisDetector->chanoff); - gain=(int*)(goff+thisDetector->gainoff); - offset=(int*)(goff+thisDetector->offsetoff); - if (thisDetector->alreadyExisting==0) { - /** if thisDetector is new, initialize its structures \sa initializeDetectorStructure(); */ - initializeDetectorStructure(); - /** set thisDetector->alreadyExisting=1 */ - thisDetector->alreadyExisting=1; - } - -#ifdef VERBOSE - cout << "passing pointers" << endl; -#endif - - - stoppedFlag=&thisDetector->stoppedFlag; - threadedProcessing=&thisDetector->threadedProcessing; - actionMask=&thisDetector->actionMask; - actionScript=thisDetector->actionScript; - actionParameter=thisDetector->actionParameter; - nScanSteps=thisDetector->nScanSteps; - scanMode=thisDetector->scanMode; - scanScript=thisDetector->scanScript; - scanParameter=thisDetector->scanParameter; - scanSteps=thisDetector->scanSteps; - scanPrecision=thisDetector->scanPrecision; - numberOfPositions=&thisDetector->numberOfPositions; - detPositions=thisDetector->detPositions; - angConvFile=thisDetector->angConvFile; - correctionMask=&thisDetector->correctionMask; - binSize=&thisDetector->binSize; - fineOffset=&thisDetector->fineOffset; - globalOffset=&thisDetector->globalOffset; - angDirection=&thisDetector->angDirection; - flatFieldDir=thisDetector->flatFieldDir; - flatFieldFile=thisDetector->flatFieldFile; - badChanFile=thisDetector->badChanFile; - timerValue=thisDetector->timerValue; - expTime=&timerValue[ACQUISITION_TIME]; - - currentSettings=&thisDetector->currentSettings; - currentThresholdEV=&thisDetector->currentThresholdEV; - moveFlag=&thisDetector->moveFlag; - sampleDisplacement=NULL; - settingsFile=thisDetector->settingsFile; - - filePath=thisDetector->filePath; - pthread_mutex_lock(&ms); - fileName=multiDet->fileName; - fileIndex=multiDet->fileIndex; - framesPerFile=multiDet->framesPerFile; - fileFormatType=multiDet->fileFormatType; - if((thisDetector->myDetectorType==GOTTHARD)||(thisDetector->myDetectorType==PROPIX)){ - fileIO::setFramesPerFile(MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - setFileFormat(BINARY); - }else if (thisDetector->myDetectorType==EIGER){ - fileIO::setFramesPerFile(EIGER_MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - setFileFormat(BINARY); - }else if (thisDetector->myDetectorType==MOENCH){ - fileIO::setFramesPerFile(MOENCH_MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - setFileFormat(BINARY); - }else if (thisDetector->myDetectorType==JUNGFRAU){ - fileIO::setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - setFileFormat(BINARY); - }else if (thisDetector->myDetectorType==JUNGFRAUCTB){ - setFramesPerFile(JFCTB_MAX_FRAMES_PER_FILE); - fileIO::setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - setFileFormat(BINARY); - }else - pthread_mutex_unlock(&ms); - if (thisReceiver != NULL) - delete thisReceiver; - thisReceiver = new receiverInterface(dataSocket); - setReceiverFramesPerFile(); - - // zmq ports - if (posId != -1) { - if (thisDetector->zmqport == 0) - thisDetector->zmqport = DEFAULT_ZMQ_CL_PORTNO + (posId * ((thisDetector->myDetectorType == EIGER) ? 2 : 1)); - if (thisDetector->receiver_zmqport == 0) - thisDetector->receiver_zmqport = DEFAULT_ZMQ_RX_PORTNO + (posId * ((thisDetector->myDetectorType == EIGER) ? 2 : 1)); - } - - // setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips); - -#ifdef VERBOSE - cout << "done" << endl; -#endif - - - /** modifies the last PID accessing the detector */ - thisDetector->lastPID=getpid(); - -#ifdef VERBOSE - cout << "Det size initialized " << endl; -#endif - - return OK; + return sz; } -int slsDetector::initializeDetectorStructure() { - sls_detector_module *thisMod; - //char *p2; - //p2=(char*)thisDetector; - /** for each of the detector modules up to the maximum number which can be installed initlialize the sls_detector_module structure \sa ::sls_detector_module*/ - for (int imod=0; imodnModsMax; ++imod) { +void slsDetector::initializeDetectorStructure(detectorType type) { + char *goff = (char*)thisDetector; + thisDetector->shmversion = SLS_SHMVERSION; + thisDetector->onlineFlag = OFFLINE_FLAG; + thisDetector->stoppedFlag = 0; + strncpy(thisDetector->hostname, DEFAULT_HOSTNAME, strlen(DEFAULT_HOSTNAME)); + thisDetector->controlPort = DEFAULT_PORTNO; + thisDetector->stopPort = DEFAULT_PORTNO + 1; + thisDetector->myDetectorType = type; + strncpy(thisDetector->settingsDir, getenv("HOME"), strlen(getenv("HOME"))); + strncpy(thisDetector->calDir, getenv("HOME"), strlen(getenv("HOME"))); + thisDetector->nTrimEn = 0; + thisDetector->trimEnergies[100]; + thisDetector->progressIndex = 0; + thisDetector->totalProgress = 1; + strncpy(thisDetector->filePath, "/", strlen("/")); + thisDetector->correctionMask = 0; + thisDetector->threadedProcessing = 1; + thisDetector->tDead = 0; + strncpy(thisDetector->flatFieldDir, getenv("HOME"), strlen(getenv("HOME"))); + strncpy(thisDetector->flatFieldFile, "none", strlen("none")); + thisDetector->nBadChans = 0; + strncpy(thisDetector->badChanFile, "none", strlen("none")); + thisDetector->nBadFF = 0; + for (int i = 0; i < MAX_BADCHANS; ++i) { + thisDetector->badChansList[i] = 0; + thisDetector->badFFList[i] = 0; + } + strncpy(thisDetector->angConvFile, "none", strlen("none")); + memset(thisDetector->angOff, 0, MAXMODS * sizeof(angleConversionConstant)); + thisDetector->angDirection = 1; + thisDetector->fineOffset = 0; + thisDetector->globalOffset = 0; + thisDetector->numberOfPositions = 0; + for (int i = 0; i < MAXPOS; ++i) { + thisDetector->detPositions[i] = 0; + } + thisDetector->binSize = 0.001; + thisDetector->nROI = 0; + memset(thisDetector->roiLimits, 0, MAX_ROIS * sizeof(ROI)); + thisDetector->roFlags = NORMAL_READOUT; + strncpy(thisDetector->settingsFile, "none", strlen("none")); + thisDetector->currentSettings = UNINITIALIZED; + thisDetector->currentThresholdEV = -1; + thisDetector->timerValue[FRAME_NUMBER] = 1; + thisDetector->timerValue[ACQUISITION_TIME] = 0; + thisDetector->timerValue[FRAME_PERIOD] = 0; + thisDetector->timerValue[DELAY_AFTER_TRIGGER] = 0; + thisDetector->timerValue[GATES_NUMBER] = 0; + thisDetector->timerValue[PROBES_NUMBER] = 0; + thisDetector->timerValue[CYCLES_NUMBER] = 1; + thisDetector->timerValue[ACTUAL_TIME] = 0; + thisDetector->timerValue[MEASUREMENT_TIME] = 0; + thisDetector->timerValue[PROGRESS] = 0; + thisDetector->timerValue[MEASUREMENTS_NUMBER] = 1; + thisDetector->timerValue[FRAMES_FROM_START] = 0; + thisDetector->timerValue[FRAMES_FROM_START_PG] = 0; + thisDetector->timerValue[SAMPLES_JCTB] = 1; + thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME] = 0; + thisDetector->timerValue[STORAGE_CELL_NUMBER] = 0; + thisDetector->timerValue[SUBFRAME_PERIOD] = 0; + thisDetector->actionMask = 0; + for (int i = 0; i < MAX_ACTIONS; ++i) { + strncpy(thisDetector->actionScript[i], "none", strlen("none")); + strncpy(thisDetector->actionParameter[i], "none", strlen("none")); + } + for (int i = 0; i < MAX_SCAN_LEVELS; ++i) { + thisDetector->scanMode[i] = 0; + strncpy(thisDetector->scanScript[i], "none", strlen("none")); + strncpy(thisDetector->scanParameter[i], "none", strlen("none")); + thisDetector->nScanSteps[i] = 0; + thisDetector->scanSteps[i] = 0.0; + thisDetector->scanPrecision[i] = 0; + } + strncpy(thisDetector->receiver_hostname, "none", strlen("none")); + thisDetector->receiverTCPPort = DEFAULT_PORTNO+2; + thisDetector->receiverUDPPort = DEFAULT_UDP_PORTNO; + thisDetector->receiverUDPPort2 = DEFAULT_UDP_PORTNO + 1; + strncpy(thisDetector->receiverUDPIP, "none", strlen("none")); + strncpy(thisDetector->receiverUDPMAC, "none", strlen("none")); + strncpy(thisDetector->detectorMAC, DEFAULT_DET_MAC, strlen(DEFAULT_DET_MAC)); + strncpy(thisDetector->detectorIP, DEFAULT_DET_IP, strlen(DEFAULT_DET_IP)); + thisDetector->receiverOnlineFlag = OFFLINE_FLAG; + thisDetector->tenGigaEnable = 0; + thisDetector->flippedData[X] = 0; + thisDetector->flippedData[Y] = 0; + thisDetector->zmqport = DEFAULT_ZMQ_CL_PORTNO + + (detId * ((thisDetector->myDetectorType == EIGER) ? 2 : 1)); + thisDetector->receiver_zmqport = DEFAULT_ZMQ_RX_PORTNO + + (detId * ((thisDetector->myDetectorType == EIGER) ? 2 : 1)); + thisDetector->receiver_upstream = false; + thisDetector->receiver_read_freq = 0; + memset(thisDetector->zmqip, 0, MAX_STR_LENGTH); + memset(thisDetector->receiver_zmqip, 0, MAX_STR_LENGTH); + thisDetector->gappixels = 0; + memset(thisDetector->receiver_additionalJsonHeader, 0, MAX_STR_LENGTH); + thisDetector->receiver_framesPerFile = -1; + thisDetector->detectorControlAPIVersion = 0; + thisDetector->detectorStopAPIVersion = 0; + thisDetector->receiverAPIVersion = 0; - - thisMod=detectorModules+imod; - thisMod->module=imod; - - /** sets the size of the module to nChans, nChips etc. */ - thisMod->nchan=thisDetector->nChans*thisDetector->nChips; - thisMod->nchip=thisDetector->nChips; - thisMod->ndac=thisDetector->nDacs; - thisMod->nadc=thisDetector->nAdcs; + // get the detector parameters based on type + detParameterList detlist; + setDetectorSpecificParameters(type, detlist); + thisDetector->nModMax[X] = detlist.nModMaxX; + thisDetector->nModMax[Y] = detlist.nModMaxY; + thisDetector->nChan[X] = detlist.nChanX; + thisDetector->nChan[Y] = detlist.nChanY; + thisDetector->nChip[X] = detlist.nChipX; + thisDetector->nChip[Y] = detlist.nChipY; + thisDetector->nDacs = detlist.nDacs; + thisDetector->nAdcs = detlist.nAdcs; + thisDetector->nGain = detlist.nGain; + thisDetector->nOffset = detlist.nOffset; + thisDetector->dynamicRange = detlist.dynamicRange; + thisDetector->moveFlag = detlist.moveFlag; + detlist.nGappixelsY = detlist.nGappixelsX; + thisDetector->nGappixels[Y] = detlist.nGappixelsY; - /** initializes the serial number and register to 0 */ - thisMod->serialnumber=0; - thisMod->reg=0; + // derived parameters + thisDetector->nModsMax = thisDetector->nModMax[X] * thisDetector->nModMax[Y]; + thisDetector->nChans = thisDetector->nChan[X] * thisDetector->nChan[Y]; + thisDetector->nChips = thisDetector->nChip[X] * thisDetector->nChip[Y]; + // number of modules is initally the maximum number of modules + thisDetector->nMod[X] = thisDetector->nModMax[X]; + thisDetector->nMod[Y] = thisDetector->nModMax[Y]; + thisDetector->nMods = thisDetector->nModsMax; - /** initializes the dacs values to 0 */ - for (int idac=0; idacnDacs; ++idac) { - *(dacs+idac+thisDetector->nDacs*imod)=0; - } + // calculating databytes + thisDetector->dataBytes = thisDetector->nMods * thisDetector->nChips * + thisDetector->nChans * thisDetector->dynamicRange/8; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + + thisDetector->gappixels * thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + + thisDetector->gappixels * thisDetector->nGappixels[Y]) * + thisDetector->dynamicRange/8; + // special for jctb and mythen in 24 bit/ with probes + if(thisDetector->myDetectorType==JUNGFRAUCTB){ + getTotalNumberOfChannels(); + } + else if(thisDetector->myDetectorType == MYTHEN){ + if (thisDetector->dynamicRange == 24 || thisDetector->timerValue[PROBES_NUMBER] > 0) { + thisDetector->dataBytes = thisDetector->nMods * thisDetector->nChips * + thisDetector->nChans * 4; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + + thisDetector->gappixels * thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + + thisDetector->gappixels * thisDetector->nGappixels[Y]) * + 4; + } + } - /** initializes the adc values to 0 */ - for (int iadc=0; iadcnAdcs; ++iadc) { - *(adcs+iadc+thisDetector->nAdcs*imod)=0; - } + /** calculates the memory offsets for + * flat field coefficients and errors, + * module structures, dacs, adcs, chips and channels */ + thisDetector->ffoff = sizeof(sharedSlsDetector); + thisDetector->fferroff = thisDetector->ffoff + sizeof(double) * + thisDetector->nChans * thisDetector->nChips * thisDetector->nModsMax; + thisDetector->modoff = thisDetector->fferroff + sizeof(double) * + thisDetector->nChans * thisDetector->nChips * thisDetector->nModsMax; + thisDetector->dacoff = thisDetector->modoff + + sizeof(sls_detector_module) * thisDetector->nModsMax; + thisDetector->adcoff = thisDetector->dacoff + + sizeof(dacs_t) * thisDetector->nDacs * thisDetector->nModsMax; + thisDetector->chipoff = thisDetector->adcoff + + sizeof(dacs_t) * thisDetector->nAdcs * thisDetector->nModsMax; + thisDetector->chanoff = thisDetector->chipoff + + sizeof(int) * thisDetector->nChips * thisDetector->nModsMax; + thisDetector->gainoff = thisDetector->chanoff + + sizeof(int) * thisDetector->nGain * thisDetector->nModsMax; + thisDetector->offsetoff = thisDetector->gainoff + + sizeof(int) * thisDetector->nOffset * thisDetector->nModsMax; - - - /** initializes the chip registers to 0 */ - for (int ichip=0; ichipnChips; ++ichip) { - *(chipregs+ichip+thisDetector->nChips*imod)=-1; - } - - - /** initializes the channel registers to 0 */ - for (int ichan=0; ichannChans*thisDetector->nChips; ++ichan) { - *(chanregs+ichan+thisDetector->nChips*thisDetector->nChans*imod)=-1; - } - - /** initializes the gain values to 0 */ - for (int igain=0; igainnGain; ++igain) { - *(gain+igain+thisDetector->nGain*imod)=0; - } - - - /** initializes the offset values to 0 */ - for (int ioffset=0; ioffsetnOffset; ++ioffset) { - *(offset+ioffset+thisDetector->nOffset*imod)=0; - } - - /** initialize gain and offset to -1 */ - thisMod->gain=-1.; - thisMod->offset=-1.; - } - return 0; } + +void slsDetector::initializeMembers() { + // slsdetector + // assign addresses + ffcoefficients = (double*)(goff + thisDetector->ffoff); + fferrors = (double*)(goff + thisDetector->fferroff); + detectorModules = (sls_detector_module*)(goff + thisDetector->modoff); + dacs = (dacs_t*)(goff + thisDetector->dacoff); + adcs = (dacs_t*)(goff + thisDetector->adcoff); + chipregs = (int*)(goff + thisDetector->chipoff); + chanregs = (int*)(goff + thisDetector->chanoff); + gain = (int*)(goff + thisDetector->gainoff); + offset = (int*)(goff + thisDetector->offsetoff); + if (thisReceiver) + delete thisReceiver; + thisReceiver = new receiverInterface(dataSocket); + + + // slsDetectorUtils + stoppedFlag = &thisDetector->stoppedFlag; + timerValue = thisDetector->timerValue; + currentSettings = &thisDetector->currentSettings; + currentThresholdEV = &thisDetector->currentThresholdEV; + + // fileIO + filePath = thisDetector->filePath; + fileName=multiDet->fileName; + fileIndex=multiDet->fileIndex; + framesPerFile=multiDet->framesPerFile; + fileFormatType=multiDet->fileFormatType; + if (thisDetector->myDetectorType != MYTHEN) + fileIO::setFileFormat(BINARY); + switch(thisDetector->myDetectorType) { + case GOTTHARD: + case PROPIX: + fileIO::setFramesPerFile(MAX_FRAMES_PER_FILE); + break; + case EIGER: + fileIO::setFramesPerFile(EIGER_MAX_FRAMES_PER_FILE); + break; + case MOENCH: + fileIO::setFramesPerFile(MOENCH_MAX_FRAMES_PER_FILE); + break; + case JUNGFRAU: + fileIO::setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE); + break; + case JUNGFRAUCTB: + fileIO::setFramesPerFile(JFRAU_MAX_FRAMES_PER_FILE); + break; + } + + + //postProcessing + threadedProcessing = &thisDetector->threadedProcessing; + correctionMask = &thisDetector->correctionMask; + flatFieldDir = thisDetector->flatFieldDir; + flatFieldFile = thisDetector->flatFieldFile; + expTime = &timerValue[ACQUISITION_TIME]; + badChannelMask = NULL; + fdata = NULL; + thisData = NULL; + ppFun = NULL; + ang = NULL; + val = NULL; + err = NULL; + + + // slsDetectorActions + actionMask = &thisDetector->actionMask; + actionScript = thisDetector->actionScript; + actionParameter = thisDetector->actionParameter; + nScanSteps = thisDetector->nScanSteps; + scanSteps = thisDetector->scanSteps; + scanMode = thisDetector->scanMode; + scanPrecision = thisDetector->scanPrecision; + scanScript = thisDetector->scanScript; + scanParameter = thisDetector->scanParameter; + + // angularConversion + numberOfPositions = &thisDetector->numberOfPositions; + detPositions = thisDetector->detPositions; + angConvFile = thisDetector->angConvFile; + binSize = &thisDetector->binSize; + fineOffset = &thisDetector->fineOffset; + globalOffset = &thisDetector->globalOffset; + angDirection = &thisDetector->angDirection; + moveFlag = &thisDetector->moveFlag; + sampleDisplacement = NULL; + + // badChannelCorrections + badChanFile = thisDetector->badChanFile; + nBadChans = &thisDetector->nBadChans; + badChansList = thisDetector->badChansList; + nBadFF = &thisDetector->nBadFF; + badFFList = thisDetector->badFFList; + + //energyConversion + settingsFile = thisDetector->settingsFile; +} + + + + +void slsDetector::initializeDetectorStructurePointers() { + // initialize with defaults + ffcoefficients?? + fferrors?? + sls_detector_module *thisMod; + for (int imod = 0; imod < thisDetector->nModsMax; ++imod) { + + // set thisMod to point to one of the detector structure modules + thisMod = detectorModules + imod; + + thisMod->module = imod; + thisMod->serialnumber = 0; + thisMod->nchan = thisDetector->nChans*thisDetector->nChips; + thisMod->nchip = thisDetector->nChips; + thisMod->ndac = thisDetector->nDacs; + thisMod->nadc = thisDetector->nAdcs; + thisMod->reg = 0; + // dacs, adcs, chipregs and chanregs for thisMod is not allocated in + // detectorModules in shared memory as they are already allocated separately + // in shared memory (below) + thisMod->gain = -1.; + thisMod->offset = -1.; + + // initializes the dacs values to 0 + for (int i = 0; i < thisDetector->nDacs; ++i) { + *(dacs + i + thisDetector->nDacs * imod) = 0; + } + // initializes the adc values to 0 + for (int i = 0; i < thisDetector->nAdcs; ++i) { + *(adcs + i + thisDetector->nAdcs * imod) = 0; + } + // initializes the chip registers to 0 + for (int i = 0; i < thisDetector->nChips; ++i) { + *(chipregs + i + thisDetector->nChips * imod) = -1; + } + // initializes the channel registers to 0 + for (int i = 0; i < thisDetector->nChans * thisDetector->nChips; ++i) { + *(chanregs + i + thisDetector->nChans * thisDetector->nChips * imod) = -1; + } + // initializes the gain values to 0 + for (int i = 0; i < thisDetector->nGain; ++i) { + *(gain + i + thisDetector->nGain * imod) = 0; + } + // initializes the offset values to 0 + for (int i = 0; i < thisDetector->nOffset; ++i) { + *(offset + i + thisDetector->nOffset * imod) = 0; + } + } +} + + +slsDetectorDefs::sls_detector_module* slsDetector::createModule() { + return createModule(thisDetector->myDetectorType); +} + + slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t) { + // get the detector parameters based on type + detParameterList detlist; + int nch = 0, nc = 0, nd = 0, na = 0; + try { + setDetectorSpecificParameters(type, detlist); + nch = detlist.nChanX * detlist.nChanY; + nc = detlist.nChipX * detlist.nChipY; + nd = detlist.nDacs; + na = detlist.nAdcs; + } catch(...) { + // FIXME do what here? + } + dacs_t *dacs=new dacs_t[nd]; + dacs_t *adcs=new dacs_t[na]; + int *chipregs=new int[nc]; + int *chanregs=new int[nch*nc]; - sls_detector_module *myMod=(sls_detector_module*)malloc(sizeof(sls_detector_module)); - - - int nch, nc, nd, na=0; - // int nm = 0; - - switch(t) { - case MYTHEN: - nch=128; // complete mythen system -// nm=24; - nc=10; - nd=6; // dacs - break; - case PICASSO: - nch=128; // complete mythen system - // nm=24; - nc=12; - nd=6; // dacs+adcs - break; - case GOTTHARD: - nch=128; -// nm=1; - nc=10; - nd=8; // dacs+adcs - na=5; - break; - case PROPIX: - nch=22*22; -// nm=1; - nc=1; - nd=8; // dacs+adcs - na=5; - break; - case EIGER: - nch=256*256; // one EIGER half module -// nm=1; //modules/detector - nc=4*1; //chips - nd=16; //dacs - na=0; - break; - case MOENCH: - nch=160*160; -// nm=1; //modules/detector - nc=1; //chips - nd=8; //dacs - na=1; - break; - case JUNGFRAU: - nch=256*256;//32; - // nm=1; - nc=4*2; - nd=16; // dacs+adcs - na=0; - break; - case JUNGFRAUCTB: - nch=36; -// nm=1; - nc=1; - nd=8; // dacs+adcs - na=1; - break; - default: - nch=0; // dum! -// nm=0; //modules/detector - nc=0; //chips - nd=0; //dacs+adcs - na=0; - } - - dacs_t *dacs=new dacs_t[nd]; - dacs_t *adcs=new dacs_t[na]; - int *chipregs=new int[nc]; - int *chanregs=new int[nch*nc]; - myMod->ndac=nd; - myMod->nadc=na; - myMod->nchip=nc; - myMod->nchan=nch*nc; - - myMod->dacs=dacs; - myMod->adcs=adcs; - myMod->chipregs=chipregs; - myMod->chanregs=chanregs; - return myMod; + sls_detector_module *myMod = (sls_detector_module*)malloc(sizeof(sls_detector_module)); + myMod->ndac=nd; + myMod->nadc=na; + myMod->nchip=nc; + myMod->nchan=nch*nc; + myMod->dacs=dacs; + myMod->adcs=adcs; + myMod->chipregs=chipregs; + myMod->chanregs=chanregs; + return myMod; } void slsDetector::deleteModule(sls_detector_module *myMod) { - delete [] myMod->dacs; - delete [] myMod->adcs; - delete [] myMod->chipregs; - delete [] myMod->chanregs; - delete myMod; + delete [] myMod->dacs; + delete [] myMod->adcs; + delete [] myMod->chipregs; + delete [] myMod->chanregs; + delete myMod; +} + + + + +int slsDetector::connectControl() { + if (controlSocket){ + if (controlSocket->Connect() >= 0) + return OK; + else{ + std::cout << "cannot connect to detector" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); + return FAIL; + } + } + return UNDEFINED; +} + +void slsDetector::disconnectControl() { + if (controlSocket) + controlSocket->Disconnect(); +} + + + +int slsDetector::connectData() { + if (dataSocket){ + if (dataSocket->Connect() >= 0) + return OK; + else{ + std::cout << "cannot connect to receiver" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); + return FAIL;} + } + return UNDEFINED; +} + +void slsDetector::disconnectData() { + if (dataSocket) + dataSocket->Disconnect(); +} + + + +int slsDetector::connectStop() { + if (stopSocket){ + if (stopSocket->Connect() >= 0) + return OK; + else{ + std::cout << "cannot connect to stop server" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); + return FAIL; + } + } + return UNDEFINED; +} + +void slsDetector::disconnectStop() { + if (stopSocket) + stopSocket->Disconnect(); } @@ -1399,10 +1109,10 @@ int slsDetector::sendModule(sls_detector_module *myMod) { ts+=controlSocket->SendDataOnly(&(myMod->reg),sizeof(myMod->reg)); // only for sending structures like in old mythen server if (thisDetector->myDetectorType == MYTHEN) { - ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(myMod->ndac)); - ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc)); - ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip)); - ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan)); + ts+=controlSocket->SendDataOnly(myMod->dacs,sizeof(myMod->ndac)); + ts+=controlSocket->SendDataOnly(myMod->adcs,sizeof(myMod->nadc)); + ts+=controlSocket->SendDataOnly(myMod->chipregs,sizeof(myMod->nchip)); + ts+=controlSocket->SendDataOnly(myMod->chanregs,sizeof(myMod->nchan)); } ts+=controlSocket->SendDataOnly(&(myMod->gain),sizeof(myMod->gain)); ts+=controlSocket->SendDataOnly(&(myMod->offset), sizeof(myMod->offset)); @@ -1453,11 +1163,11 @@ int slsDetector::receiveChip(sls_detector_chip* myChip) { int slsDetector::receiveModule(sls_detector_module* myMod) { - dacs_t *dacptr=myMod->dacs; - dacs_t *adcptr=myMod->adcs; - int *chipptr=myMod->chipregs; - int *chanptr=myMod->chanregs; - int ts=0; + dacs_t *dacptr=myMod->dacs; + dacs_t *adcptr=myMod->adcs; + int *chipptr=myMod->chipregs; + int *chanptr=myMod->chanregs; + int ts=0; //send module structure ts+=controlSocket->ReceiveDataOnly(&(myMod->module),sizeof(myMod->module)); ts+=controlSocket->ReceiveDataOnly(&(myMod->serialnumber),sizeof(myMod->serialnumber)); @@ -1466,12 +1176,12 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { ts+=controlSocket->ReceiveDataOnly(&(myMod->ndac),sizeof(myMod->ndac)); ts+=controlSocket->ReceiveDataOnly(&(myMod->nadc),sizeof(myMod->nadc)); ts+=controlSocket->ReceiveDataOnly(&(myMod->reg),sizeof(myMod->reg)); - // only for sending structures like in old mythen server + // only for sending structures like in old mythen server if (thisDetector->myDetectorType == MYTHEN) { - ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(myMod->ndac)); - ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc)); - ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip)); - ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan)); + ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(myMod->ndac)); + ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(myMod->nadc)); + ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(myMod->nchip)); + ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(myMod->nchan)); } ts+=controlSocket->ReceiveDataOnly(&(myMod->gain), sizeof(myMod->gain)); @@ -1484,565 +1194,463 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { myMod->chanregs=chanptr; #ifdef VERBOSE - std::cout<< "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << std::endl; + std::cout<< "received module " << myMod->module << " of size "<< ts + << " register " << myMod->reg << std::endl; #endif - ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(dacs_t)*(myMod->ndac)); + ts+=controlSocket->ReceiveDataOnly(myMod->dacs,sizeof(dacs_t)*(myMod->ndac)); #ifdef VERBOSE - std::cout<< "received dacs " << myMod->module << " of size "<< ts << std::endl; + std::cout<< "received dacs " << myMod->module << " of size "<< ts << std::endl; #endif - ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc)); + ts+=controlSocket->ReceiveDataOnly(myMod->adcs,sizeof(dacs_t)*(myMod->nadc)); #ifdef VERBOSE - std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl; + std::cout<< "received adcs " << myMod->module << " of size "<< ts << std::endl; #endif - if(thisDetector->myDetectorType != JUNGFRAU){ - ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); + if(thisDetector->myDetectorType != JUNGFRAU){ + ts+=controlSocket->ReceiveDataOnly(myMod->chipregs,sizeof(int)*(myMod->nchip)); #ifdef VERBOSE - std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl; + std::cout<< "received chips " << myMod->module << " of size "<< ts << std::endl; #endif - ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); + ts+=controlSocket->ReceiveDataOnly(myMod->chanregs,sizeof(int)*(myMod->nchan)); #ifdef VERBOSE - std::cout<< "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips; - std::cout<< "mod - nchans= " << myMod->nchan << " nchips= " <nchip; - std::cout<< "received chans " << myMod->module << " of size "<< ts << std::endl; + std::cout<< "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips; + std::cout<< "mod - nchans= " << myMod->nchan << " nchips= " <nchip; + std::cout<< "received chans " << myMod->module << " of size "<< ts << std::endl; #endif - } - -#ifdef VERBOSE - std::cout<< "received module " << myMod->module << " of size "<< ts << " register " << myMod->reg << std::endl; -#endif - - return ts; -} - - -int slsDetector::setOnline(int off) { - int old=thisDetector->onlineFlag; - if (off!=GET_ONLINE_FLAG) { - thisDetector->onlineFlag=off; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - setTCPSocket(); - if (thisDetector->onlineFlag==ONLINE_FLAG && old==OFFLINE_FLAG) { - cout << "Detector connecting for the first time - updating!" << endl; - updateDetector(); - } - else if(thisDetector->onlineFlag==OFFLINE_FLAG){ - std::cout << "cannot connect to detector" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); - } - } - } - return thisDetector->onlineFlag; -} - - - -string slsDetector::checkOnline() { - string retval; - if(!controlSocket){ - //this already sets the online/offline flag - setTCPSocket(); - if(thisDetector->onlineFlag==OFFLINE_FLAG) - return string(thisDetector->hostname); - else - return string(""); - } - //still cannot connect to socket, controlSocket=0 - if(controlSocket){ - if (connectControl() == FAIL) { - controlSocket->SetTimeOut(5); - thisDetector->onlineFlag=OFFLINE_FLAG; - delete controlSocket; - controlSocket=NULL; - retval = string(thisDetector->hostname); -#ifdef VERBOSE - std::cout<< "offline!" << std::endl; -#endif - } else { - thisDetector->onlineFlag=ONLINE_FLAG; - controlSocket->SetTimeOut(100); - disconnectControl(); -#ifdef VERBOSE - std::cout<< "online!" << std::endl; -#endif - } - } - return retval; -} - - - -int slsDetector::activate(int const enable){ - int fnum = F_ACTIVATE; - int fnum2 = F_RECEIVER_ACTIVATE; - int retval = -1; - int arg = enable; - char mess[MAX_STR_LENGTH]=""; - int ret = OK; - - if(thisDetector->myDetectorType != EIGER){ - std::cout<< "Not implemented for this detector" << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); - return -1; } #ifdef VERBOSE - if(!enable) - std::cout<< "Deactivating Detector" << std::endl; - else if(enable == -1) - std::cout<< "Getting Detector activate mode" << std::endl; - else - std::cout<< "Activating Detector" << std::endl; + std::cout<< "received module " << myMod->module << " of size "<< ts << " register " + << myMod->reg << std::endl; +#endif + + return ts; +} + + +detectorType slsDetector::getDetectorTypeFromShm(int multiId) { + SharedMemory* shm = new SharedMemory(multiId, detId); + std::string shmname = shm->GetName(); + + // shm not created before + if (!SharedMemory::IsExisting(shmname)) { + cprintf(RED,"Shared memory %s does not exist.\n" + "Corrupted Multi Shared memory. Please free shared memory.\n", + shmname.c_str()); + throw SharedMemoryException(); + } + + // map basic size of sls detector structure (no need of offsets, just version is required) + slsDetector* sdet = 0; + size_t sz = sizeof(sharedSlsDetector); + + // open, map, verify version, get type + sdet = (sharedSlsDetector*)shm->OpenSharedMemory(sz); + if (verify && thisDetector->shmversion != SLS_SHMVERSION) { + cprintf(RED, "Single shared memory (%d-%d:)version mismatch " + "(expected 0x%x but got 0x%x)\n", + multiId, detId, SLS_SHMVERSION, thisDetector->shmversion); + shm->UnmapSharedMemory(sdet); /** is this unncessary? */ + delete shm;/** is this unncessary? */ + throw SharedMemoryException(); + } + detectorType type = sdet->type; + + // unmap + shm->UnmapSharedMemory(sdet); + delete shm; + + return type; +} + + +slsDetectorDefs::detectorType slsDetector::getDetectorType(const char *name, int cport) { + int fnum=F_GET_DETECTOR_TYPE; + int retval = FAIL; + detectorType t=GENERIC; + MySocketTCP *s= new MySocketTCP(name, cport); + char m[MAX_STR_LENGTH]; +#ifdef VERBOSE + cout << "Getting detector type " << endl; +#endif + if (s->Connect() >= 0) { + s->SendDataOnly(&fnum,sizeof(fnum)); + s->ReceiveDataOnly(&retval,sizeof(retval)); + if (retval!=FAIL) { + s->ReceiveDataOnly(&t,sizeof(t)); +#ifdef VERBOSE + cout << "Detector type is "<< t << endl; +#endif + } else { + s->ReceiveDataOnly(m,sizeof(m)); + std::cout<< "Detector returned error: " << m << std::endl; + } + s->Disconnect(); + } else { + cout << "Cannot connect to server " << name << " over port " << cport << endl; + } + delete s; + return t; +} + + +int slsDetector::setDetectorType(detectorType const type) { + + int arg, retval=FAIL; + int fnum=F_GET_DETECTOR_TYPE,fnum2=F_GET_RECEIVER_TYPE; + arg=int(type); + detectorType retType=type; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting detector type to " << arg << std::endl; #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if (retval!=FAIL) + controlSocket->ReceiveDataOnly(&retType,sizeof(retType)); + else { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); - } else { + } + disconnectControl(); + if (retval==FORCE_UPDATE) + updateDetector(); + } + } else { + if (type==GET_DETECTOR_TYPE) + retType=thisDetector->myDetectorType;//FIXME: throw exception? + else { + retType=type; + thisDetector->myDetectorType=type; + } + retval=OK; + } +#ifdef VERBOSE + std::cout<< "Detector type set to " << retType << std::endl; +#endif + if (retval==FAIL) { + std::cout<< "Set detector type failed " << std::endl; + retType=GENERIC; + } + else + thisDetector->myDetectorType=retType; + + + //receiver + if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG) + && (arg != GENERIC)) { + retval = FAIL; + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending detector type to Receiver " << + (int)thisDetector->myDetectorType << std::endl; +#endif + if (connectData() == OK){ + retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType); + disconnectData(); + } + if(retval==FAIL){ + cout << "ERROR: Could not send detector type to receiver" << endl; + setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); + } + } + } + + return retType; +} + + + +int slsDetector::setDetectorType(string const stype) { + return setDetectorType(getDetectorType(stype)); +} + + +slsDetectorDefs::detectorType slsDetector::getDetectorsType(int pos) { + return thisDetector->myDetectorType; +} + +string slsDetector::sgetDetectorsType(int pos=-1) { + return getDetectorType(getDetectorsType(pos)); +} + + +string slsDetector::getDetectorType() { + return sgetDetectorsType(); +} + + +int slsDetector::getNMods() { + return thisDetector->nMods; +} + +int slsDetector::getNMod(dimension d) { + return thisDetector->nMod[d]; +} + + +int slsDetector::getMaxMods() { + return thisDetector->nModsMax; +} + + +int slsDetector::getNMaxMod(dimension d) { + return thisDetector->nModMax[d]; +} + + + +int slsDetector::getMaxNumberOfModules(dimension d) { + + int retval; + int fnum=F_GET_MAX_NUMBER_OF_MODULES; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + if (dY) { + std::cout<< "Get max number of modules in wrong dimension " << d << std::endl; + return ret; + } +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Getting max number of modules in dimension "<< d <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&d,sizeof(d)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; } disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } + } else { + ret=OK; + retval=thisDetector->nModMax[d]; } #ifdef VERBOSE - if(retval==1) - std::cout << "Detector Activated" << std::endl; - else if(retval==0) - std::cout << "Detector Deactivated" << std::endl; - else - std::cout << "Detector Activation unknown:" << retval << std::endl; + std::cout<< "Max number of modules in dimension "<< d <<" is " << retval << std::endl; #endif + if (ret==FAIL) { + std::cout<< "Get max number of modules failed " << retval << std::endl; + return retval; + } else { + thisDetector->nModMax[d]=retval; + thisDetector->nModsMax=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; + + + + } + return thisDetector->nModMax[d]; +} + + + +int slsDetector::setNumberOfModules(int n, dimension d) { + + int arg[2], retval=1; + int fnum=F_SET_NUMBER_OF_MODULES; + int ret=FAIL; + char mess[MAX_STR_LENGTH]="dummy"; + int connect; + + arg[0]=d; + arg[1]=n; + + + if (dY) { + std::cout<< "Set number of modules in wrong dimension " << d << std::endl; + return ret; + } + - if(ret!=FAIL){ - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Activating/Deactivating Receiver: " << retval << std::endl; + std::cout<< std::endl; + std::cout<< "Setting number of modules of dimension "<< d << " to " << n << std::endl; #endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum2,retval,retval); - disconnectData(); + if (thisDetector->onlineFlag==ONLINE_FLAG) { + connect = connectControl(); + if (connect == UNDEFINED) + cout << "no control socket?" << endl; + else if (connect == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; } - if(ret==FAIL) - setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); } - } -#ifdef VERBOSE - if(retval==1) - std::cout << "Receiver Activated" << std::endl; - else if(retval==0) - std::cout << "Receiver Deactivated" << std::endl; - else - std::cout << "Receiver Activation unknown:" << retval << std::endl; -#endif - - - return retval; - -} - - -/* - configure the socket communication and check that the server exists - enum communicationProtocol{ - TCP, - UDP - }{}; - -*/ - -int slsDetector::setTCPSocket(string const name, int const control_port, int const stop_port){ - char thisName[MAX_STR_LENGTH]; - int thisCP, thisSP; - int retval=OK; - - if (strcmp(name.c_str(),"")!=0) { -#ifdef VERBOSE - std::cout<< "setting hostname" << std::endl; -#endif - strcpy(thisName,name.c_str()); - strcpy(thisDetector->hostname,thisName); - if (controlSocket) { - delete controlSocket; - controlSocket=NULL; - } - if (stopSocket) { - delete stopSocket; - stopSocket=NULL; - } - } else - strcpy(thisName,thisDetector->hostname); - - if (control_port>0) { -#ifdef VERBOSE - std::cout<< "setting control port" << std::endl; -#endif - thisCP=control_port; - thisDetector->controlPort=thisCP; - if (controlSocket) { - delete controlSocket; - controlSocket=NULL; - } - } else - thisCP=thisDetector->controlPort; - - if (stop_port>0) { -#ifdef VERBOSE - std::cout<< "setting stop port" << std::endl; -#endif - thisSP=stop_port; - thisDetector->stopPort=thisSP; - if (stopSocket) { - delete stopSocket; - stopSocket=NULL; - } - } else - thisSP=thisDetector->stopPort; - - - if (!controlSocket) { - controlSocket= new MySocketTCP(thisName, thisCP); - if (controlSocket->getErrorStatus()){ -#ifdef VERBOSE - std::cout<< "Could not connect Control socket " << thisName << " " << thisCP << std::endl; -#endif - delete controlSocket; - controlSocket=NULL; - retval=FAIL; - } -#ifdef VERYVERBOSE - else - std::cout<< "Control socket connected " <getErrorStatus()){ -#ifdef VERBOSE - std::cout<< "Could not connect Stop socket "<myDetectorType) { - case EIGER: - case JUNGFRAU: - case GOTTHARD: - if ((thisDetector->detectorControlAPIVersion == 0) || - (thisDetector->detectorStopAPIVersion == 0)) { - if (checkVersionCompatibility(CONTROL_PORT) == FAIL) - thisDetector->onlineFlag=OFFLINE_FLAG; - } - break; - default: - break; - } - - } else { - thisDetector->onlineFlag=OFFLINE_FLAG; -#ifdef VERBOSE - std::cout<< "offline!" << std::endl; -#endif - } - return retval; -}; - - -/** connect to the control port */ -int slsDetector::connectControl() { - if (controlSocket){ - if (controlSocket->Connect() >= 0) - return OK; - else{ - std::cout << "cannot connect to detector" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); - return FAIL; + } else { + cout << "offline" << endl; + ret=OK; + if (n==GET_FLAG) + ; + else { + if (n<=0 || n>thisDetector->nModMax[d]) { + ret=FAIL; + } else { + thisDetector->nMod[d]=n; + } } + retval=thisDetector->nMod[d]; } - return UNDEFINED; -} -/** disconnect from the control port */ -int slsDetector::disconnectControl() { - if (controlSocket) - controlSocket->Disconnect(); - return OK; -} +#ifdef VERBOSE + std::cout<< "Number of modules in dimension "<< d <<" is " << retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Set number of modules failed " << std::endl; + } else { + thisDetector->nMod[d]=retval; + thisDetector->nMods=thisDetector->nMod[X]*thisDetector->nMod[Y]; + if (thisDetector->nModsMaxnMods) + thisDetector->nModsMax=thisDetector->nMods; -/** connect to the data port */ -int slsDetector::connectData() { - if (dataSocket){ - if (dataSocket->Connect() >= 0) - return OK; - else{ - std::cout << "cannot connect to receiver" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); - return FAIL;} - } - return UNDEFINED; -}; -/** disconnect from the data port */ -int slsDetector::disconnectData(){ - if (dataSocket) - dataSocket->Disconnect(); - return OK; -} -; + if (thisDetector->nModMax[X]nMod[X]) + thisDetector->nModMax[X]=thisDetector->nMod[X]; -/** connect to the stop port */ -int slsDetector::connectStop() { - if (stopSocket){ - if (stopSocket->Connect() >= 0) - return OK; - else{ - std::cout << "cannot connect to stop server" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); - return FAIL; + if (thisDetector->nModMax[Y]nMod[Y]) + thisDetector->nModMax[Y]=thisDetector->nMod[Y]; + + int dr=thisDetector->dynamicRange; + if ((thisDetector->myDetectorType==MYTHEN) && (dr==24)) + dr=32; + + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]* + thisDetector->nChips*thisDetector->nChans*dr/8; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * + thisDetector->nChan[X] + thisDetector->gappixels * + thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + thisDetector->gappixels * + thisDetector->nGappixels[Y]) * + thisDetector->dynamicRange/8; + + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->timerValue[PROBES_NUMBER]!=0) { + thisDetector->dataBytes=thisDetector->nMod[X]* + thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * + 4; + } } + + if(thisDetector->myDetectorType==JUNGFRAUCTB){ + getTotalNumberOfChannels(); + } + + +#ifdef VERBOSE +std::cout<< "Data size is " << thisDetector->dataBytes << std::endl; +std::cout<< "nModX " << thisDetector->nMod[X] << " nModY " << thisDetector->nMod[Y] + << " nChips " << thisDetector->nChips << " nChans " << thisDetector->nChans + << " dr " << dr << std::endl; +#endif } - return UNDEFINED; -}; -/** disconnect from the stop port */ -int slsDetector::disconnectStop(){ - if (stopSocket) - stopSocket->Disconnect(); - return OK; -} -; - - - - - - - - - - - - - - - - -/* Communication to server */ - -// General purpose functions - -/* - executes a system command on the server - e.g. mount an nfs disk, reboot and returns answer etc. -*/ -int slsDetector::execCommand(string cmd, string answer){ - - char arg[MAX_STR_LENGTH], retval[MAX_STR_LENGTH]; - int fnum=F_EXEC_COMMAND; - - int ret=FAIL; - - strcpy(arg,cmd.c_str()); - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Sending command " << arg << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) { - if (controlSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0) { - if (controlSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH)>=0) { - ret=OK; - answer=retval; - } + if(n != GET_FLAG){ + pthread_mutex_lock(&ms); + multiDet->updateOffsets(); + pthread_mutex_unlock(&ms); } - } - disconnectControl(); - } -#ifdef VERBOSE - std::cout<< "Detector answer is " << answer << std::endl; -#endif - } - return ret; -}; -// Detector configuration functions - -/* - the detector knows what type of detector it is - - enum detectorType{ - GET_DETECTOR_TYPE, - GENERIC, - MYTHEN, - PILATUS, - EIGER, - GOTTHARD, - AGIPD, - MOENCH - }; - -*/ -int slsDetector::setDetectorType(detectorType const type){ - - int arg, retval=FAIL; - int fnum=F_GET_DETECTOR_TYPE,fnum2=F_GET_RECEIVER_TYPE; - arg=int(type); - detectorType retType=type; - char mess[MAX_STR_LENGTH]=""; - strcpy(mess,"dummy"); - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting detector type to " << arg << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if (retval!=FAIL) - controlSocket->ReceiveDataOnly(&retType,sizeof(retType)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (retval==FORCE_UPDATE) - updateDetector(); - } - } else { - if (type==GET_DETECTOR_TYPE) - retType=thisDetector->myDetectorType; - else { - retType=type; - thisDetector->myDetectorType=type; - } - retval=OK; - } -#ifdef VERBOSE - std::cout<< "Detector type set to " << retType << std::endl; -#endif - if (retval==FAIL) { - std::cout<< "Set detector type failed " << std::endl; - retType=GENERIC; - } - else - thisDetector->myDetectorType=retType; - - - //receiver - if((retType != GENERIC) && (thisDetector->receiverOnlineFlag==ONLINE_FLAG) && (arg != GENERIC)) { - retval = FAIL; - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending detector type to Receiver " << (int)thisDetector->myDetectorType << std::endl; -#endif - if (connectData() == OK){ - retval=thisReceiver->sendInt(fnum2,arg,(int)thisDetector->myDetectorType); - disconnectData(); - } - if(retval==FAIL){ - cout << "ERROR: Could not send detector type to receiver" << endl; - setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTTYPE_NOT_SET)); - } - } - } - - - - return retType; -}; - -int slsDetector::setDetectorType(string const stype){ - return setDetectorType(getDetectorType(stype)); -}; - -slsDetectorDefs::detectorType slsDetector::getDetectorsType(int pos){ - return thisDetector->myDetectorType; + return thisDetector->nMod[d]; } - // /** number of rois defined */ - // int nROI; - // /** list of rois */ - // ROI roiLimits[MAX_ROIS]; - - // /** readout flags */ - // readOutFlags roFlags; + +int slsDetector::getChansPerMod(int imod=0) { + return thisDetector->nChans*thisDetector->nChips; +} + +int slsDetector::getChansPerMod( dimension d,int imod=0) { + return thisDetector->nChan[d]*thisDetector->nChip[d]; +} int slsDetector::getTotalNumberOfChannels() { #ifdef VERBOSE - cout << "total number of channels" << endl; + cout << "total number of channels" << endl; #endif - if(thisDetector->myDetectorType==JUNGFRAUCTB){ - if (thisDetector->roFlags&DIGITAL_ONLY) - thisDetector->nChan[X]=4; - else if (thisDetector->roFlags&ANALOG_AND_DIGITAL) - thisDetector->nChan[X]=36; - else - thisDetector->nChan[X]=32; - - if (thisDetector->nChan[X]>=32) { - if (thisDetector->nROI>0) { - thisDetector->nChan[X]-=32; - for (int iroi=0; iroinROI; ++iroi) - thisDetector->nChan[X]+=thisDetector->roiLimits[iroi].xmax-thisDetector->roiLimits[iroi].xmin+1; - } - } - thisDetector->nChans=thisDetector->nChan[X]; - thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips*thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB]; - thisDetector->dataBytesInclGapPixels = thisDetector->dataBytes; - } else { + if(thisDetector->myDetectorType==JUNGFRAUCTB){ + if (thisDetector->roFlags&DIGITAL_ONLY) + thisDetector->nChan[X]=4; + else if (thisDetector->roFlags&ANALOG_AND_DIGITAL) + thisDetector->nChan[X]=36; + else + thisDetector->nChan[X]=32; + + if (thisDetector->nChan[X]>=32) { + if (thisDetector->nROI>0) { + thisDetector->nChan[X]-=32; + for (int iroi=0; iroinROI; ++iroi) + thisDetector->nChan[X]+= + thisDetector->roiLimits[iroi].xmax- + thisDetector->roiLimits[iroi].xmin+1; + } + } + thisDetector->nChans=thisDetector->nChan[X]; + thisDetector->dataBytes=thisDetector->nChans*thisDetector->nChips* + thisDetector->nMods*2*thisDetector->timerValue[SAMPLES_JCTB]; + thisDetector->dataBytesInclGapPixels = thisDetector->dataBytes; + } else { #ifdef VERBOSE - cout << "det type is "<< thisDetector->myDetectorType << endl; - cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips*thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl; // excluding gap pixels +cout << "det type is "<< thisDetector->myDetectorType << endl; +cout << "Total number of channels is "<< thisDetector->nChans*thisDetector->nChips* + thisDetector->nMods << " data bytes is " << thisDetector->dataBytes << endl; +// excluding gap pixels #endif - ; - } - return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; +; + } + return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods; } int slsDetector::getTotalNumberOfChannels(dimension d) { - getTotalNumberOfChannels(); - return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d]; -}; + getTotalNumberOfChannels(); + return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d]; +} int slsDetector::getTotalNumberOfChannelsInclGapPixels(dimension d) { getTotalNumberOfChannels(); - return (thisDetector->nChan[d] * thisDetector->nChip[d] + thisDetector->gappixels * thisDetector->nGappixels[d]) * thisDetector->nMod[d]; + return (thisDetector->nChan[d] * thisDetector->nChip[d] + thisDetector->gappixels + * thisDetector->nGappixels[d]) * thisDetector->nMod[d]; } -int slsDetector::getMaxNumberOfChannels(){ - if(thisDetector->myDetectorType==JUNGFRAUCTB) return 36*thisDetector->nChips*thisDetector->nModsMax; - return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax; -}; +int slsDetector::getMaxNumberOfChannels() { + if(thisDetector->myDetectorType==JUNGFRAUCTB) return 36*thisDetector->nChips* + thisDetector->nModsMax; + return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax; +} -int slsDetector::getMaxNumberOfChannels(dimension d){ - if(thisDetector->myDetectorType==JUNGFRAUCTB) { - if (d==X) return 36*thisDetector->nChip[d]*thisDetector->nModMax[d]; - else return 1*thisDetector->nChip[d]*thisDetector->nModMax[d]; - } - return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d]; +int slsDetector::getMaxNumberOfChannels(dimension d) { + if(thisDetector->myDetectorType==JUNGFRAUCTB) { + if (d==X) return 36*thisDetector->nChip[d]*thisDetector->nModMax[d]; + else return 1*thisDetector->nChip[d]*thisDetector->nModMax[d]; + } + return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d]; }; int slsDetector::getMaxNumberOfChannelsInclGapPixels(dimension d) { @@ -2050,2915 +1658,198 @@ int slsDetector::getMaxNumberOfChannelsInclGapPixels(dimension d) { if (d==X) return 36*thisDetector->nChip[d]*thisDetector->nModMax[d]; else return 1*thisDetector->nChip[d]*thisDetector->nModMax[d]; } - return (thisDetector->nChan[d] * thisDetector->nChip[d] + thisDetector->gappixels * thisDetector->nGappixels[d]) * thisDetector->nModMax[d]; -} - -/* needed to set/get the size of the detector */ -// if n=GET_FLAG returns the number of installed modules, -int slsDetector::setNumberOfModules(int n, dimension d){ - - int arg[2], retval=1; - int fnum=F_SET_NUMBER_OF_MODULES; - int ret=FAIL; - char mess[MAX_STR_LENGTH]="dummy"; - int connect; - - arg[0]=d; - arg[1]=n; - - - if (dY) { - std::cout<< "Set number of modules in wrong dimension " << d << std::endl; - return ret; - } - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting number of modules of dimension "<< d << " to " << n << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - connect = connectControl(); - if (connect == UNDEFINED) - cout << "no control socket?" << endl; - else if (connect == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - cout << "offline" << endl; - ret=OK; - if (n==GET_FLAG) - ; - else { - if (n<=0 || n>thisDetector->nModMax[d]) { - ret=FAIL; - } else { - thisDetector->nMod[d]=n; - } - } - retval=thisDetector->nMod[d]; - } -#ifdef VERBOSE - std::cout<< "Number of modules in dimension "<< d <<" is " << retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Set number of modules failed " << std::endl; - } else { - thisDetector->nMod[d]=retval; - thisDetector->nMods=thisDetector->nMod[X]*thisDetector->nMod[Y]; - - - if (thisDetector->nModsMaxnMods) - thisDetector->nModsMax=thisDetector->nMods; - - if (thisDetector->nModMax[X]nMod[X]) - thisDetector->nModMax[X]=thisDetector->nMod[X]; - - if (thisDetector->nModMax[Y]nMod[Y]) - thisDetector->nModMax[Y]=thisDetector->nMod[Y]; - - int dr=thisDetector->dynamicRange; - if ((thisDetector->myDetectorType==MYTHEN) && (dr==24)) - dr=32; - - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - thisDetector->dynamicRange/8; - - if(thisDetector->myDetectorType==MYTHEN){ - if (thisDetector->timerValue[PROBES_NUMBER]!=0) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - 4; - } - } - - if(thisDetector->myDetectorType==JUNGFRAUCTB){ - getTotalNumberOfChannels(); - } - - -#ifdef VERBOSE - std::cout<< "Data size is " << thisDetector->dataBytes << std::endl; - std::cout<< "nModX " << thisDetector->nMod[X] << " nModY " << thisDetector->nMod[Y] << " nChips " << thisDetector->nChips << " nChans " << thisDetector->nChans<< " dr " << dr << std::endl; -#endif - } - - if(n != GET_FLAG){ - pthread_mutex_lock(&ms); - multiDet->updateOffsets(); - pthread_mutex_unlock(&ms); - } - - return thisDetector->nMod[d]; -}; - - - -int slsDetector::getMaxNumberOfModules(dimension d){ - - int retval; - int fnum=F_GET_MAX_NUMBER_OF_MODULES; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - if (dY) { - std::cout<< "Get max number of modules in wrong dimension " << d << std::endl; - return ret; - } -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Getting max number of modules in dimension "<< d <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&d,sizeof(d)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - ret=OK; - retval=thisDetector->nModMax[d]; - } -#ifdef VERBOSE - std::cout<< "Max number of modules in dimension "<< d <<" is " << retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Get max number of modules failed " << retval << std::endl; - return retval; - } else { - thisDetector->nModMax[d]=retval; - thisDetector->nModsMax=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; - - - - } - return thisDetector->nModMax[d]; -}; - - - - - -int slsDetector::setFlippedData(dimension d, int value){ - int retval=-1; - int fnum=F_SET_FLIPPED_DATA_RECEIVER; - int ret=FAIL; - int args[2]={X,-1}; - - - if(thisDetector->myDetectorType!= EIGER){ - std::cout << "Flipped Data is not implemented in this detector" << std::endl; - setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); - return -1; - } - -#ifdef VERBOSE - std::cout << std::endl; - std::cout << "Setting/Getting flipped data across axis " << d <<" with value " << value << std::endl; -#endif - if(value > -1){ - thisDetector->flippedData[d] = value; - args[1] = value; - }else - args[1] = thisDetector->flippedData[d]; - - args[0] = d; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK){ - ret=thisReceiver->sendIntArray(fnum,retval,args); - - disconnectData(); - } - - if((args[1] != retval && args[1]>=0) || (ret==FAIL)){ - ret = FAIL; - setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); - } - - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - - return thisDetector->flippedData[d]; + return (thisDetector->nChan[d] * thisDetector->nChip[d] + thisDetector->gappixels * + thisDetector->nGappixels[d]) * thisDetector->nModMax[d]; } +int slsDetector::getNChans() { + return thisDetector->nChans; +} +int slsDetector::getNChans(dimension d) { + return thisDetector->nChan[d]; +} -int slsDetector::enableGapPixels(int val) { +int slsDetector::getNChips() { + return thisDetector->nChips; +} - if(val > 0 && thisDetector->myDetectorType!= EIGER) - val = -1; - - if (val >= 0) { - val=(val>0)?1:0; - - // send to receiver - int ret=OK; - int retval=-1; - int fnum=F_ENABLE_GAPPIXELS_IN_RECEIVER; - int arg=val; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); - } - if((arg != retval) || (ret==FAIL)){ - ret = FAIL; - setErrorMask((getErrorMask())|(RECEIVER_ENABLE_GAPPIXELS_NOT_SET)); - } - - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - - // update client - if (ret == OK) { - thisDetector->gappixels = val; - thisDetector->dataBytesInclGapPixels = 0; - - if (thisDetector->dynamicRange != 4) { - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - thisDetector->dynamicRange/8; - // set data bytes for other detector ( for future use) - if(thisDetector->myDetectorType==JUNGFRAUCTB) - getTotalNumberOfChannels(); - else if(thisDetector->myDetectorType==MYTHEN){ - if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0) { - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - 4; - } - } - } - } - } - - return thisDetector->gappixels; +int slsDetector::getNChips(dimension d) { + return thisDetector->nChip[d]; } -/* - This function is used to set the polarity and meaning of the digital I/O signals (signal index) - - enum externalSignalFlag { - GET_EXTERNAL_SIGNAL_FLAG, - SIGNAL_OFF, - GATE_ACTIVE_HIGH, - GATE_ACTIVE_LOW, - TRIGGER_RISING_EDGE, - TRIGGER_FALLING_EDGE - }{}; -*/ - -slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags(externalSignalFlag pol, int signalindex){ - - - - - int arg[2]; - externalSignalFlag retval; - int ret=FAIL; - int fnum=F_SET_EXTERNAL_SIGNAL_FLAG; - char mess[MAX_STR_LENGTH]=""; - - arg[0]=signalindex; - arg[1]=pol; - - retval=GET_EXTERNAL_SIGNAL_FLAG; - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting signal "<< signalindex << " to flag" << pol << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - retval=GET_EXTERNAL_SIGNAL_FLAG; - ret=FAIL; - } -#ifdef VERBOSE - std::cout<< "Signal "<< signalindex << " flag set to" << retval << std::endl; - if (ret==FAIL) { - std::cout<< "Set signal flag failed " << std::endl; - } -#endif - return retval; - - - - - - -}; - -/* - this function is used to select wether the detector is triggered or gated and in which mode - enum externalCommunicationMode{ - GET_EXTERNAL_COMMUNICATION_MODE, - AUTO, - TRIGGER_EXPOSURE, - TRIGGER_READOUT, - TRIGGER_COINCIDENCE_WITH_INTERNAL_ENABLE, - GATE_FIX_NUMBER, - GATE_FIX_DURATION, - GATE_WITH_START_TRIGGER, - BURST_TRIGGER, - //GATE_COINCIDENCE_WITH_INTERNAL_ENABLE - }; - -*/ - -slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunicationMode( externalCommunicationMode pol){ - - - - - int arg[1]; - externalCommunicationMode retval; - int fnum=F_SET_EXTERNAL_COMMUNICATION_MODE; - char mess[MAX_STR_LENGTH]=""; - - arg[0]=pol; - - int ret=FAIL; - retval=GET_EXTERNAL_COMMUNICATION_MODE; - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting communication to mode " << pol << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - retval=GET_EXTERNAL_COMMUNICATION_MODE; - ret=FAIL; - } -#ifdef VERBOSE - std::cout<< "Communication mode "<< " set to" << retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Setting communication mode failed" << std::endl; - } - return retval; - -}; - - - - - - -/* - Digital test of the modules - - enum digitalTestMode { - CHIP_TEST, - MODULE_FIRMWARE_TEST, - DETECTOR_FIRMWARE_TEST, - DETECTOR_MEMORY_TEST, - DETECTOR_BUS_TEST, - DETECTOR_SOFTWARE_TEST - }{}; - returns ok or error mask -*/ - -int slsDetector::digitalTest( digitalTestMode mode, int imod){ - - - int retval; - int fnum=F_DIGITAL_TEST; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Getting id of "<< mode << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - if ((mode==CHIP_TEST)|| (mode==DIGITAL_BIT_TEST)) - controlSocket->SendDataOnly(&imod,sizeof(imod)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - ret=FAIL; - } -#ifdef VERBOSE - std::cout<< "Id "<< mode <<" is " << retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Get id failed " << std::endl; - return ret; - } else - return retval; -}; - - - -/* - analog test of the modules - enum analogTestMode { - COUNT_CALIBRATION_PULSES, - I_DON_T_KNOW - }{}; - -*/ -/* - int* slsDetector::analogTest(analogTestMode mode){ - std::cout<< "function not yet implemented " << std::endl; - }; -*/ -/* - enable analog output of channel -*/ -/* - int slsDetector::enableAnalogOutput(int ichan){ - int imod=ichan/(nChans*nChips); - ichan-=imod*(nChans*nChips); - int ichip=ichan/nChans; - ichan-=ichip*(nChans); - enableAnalogOutput(imod,ichip,ichan); - - }; - int slsDetector::enableAnalogOutput(int imod, int ichip, int ichan){ - std::cout<< "function not yet implemented " << std::endl; - }; -*/ -/* - give a train of calibration pulses -*/ -/* - int slsDetector::giveCalibrationPulse(double vcal, int npulses){ - std::cout<< "function not yet implemented " << std::endl; - }; -*/ -// Expert low level functions - - - -/* write or read register */ - -uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val){ - - uint32_t retval = 0; - int fnum=F_WRITE_REGISTER; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - uint32_t arg[2]; - arg[0]=addr; - arg[1]=val; - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Writing to register "<< hex<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } -#ifdef VERBOSE - std::cout<< "Register returned "<< retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Write to register failed " << std::endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); - } - - return retval; -} - - -int slsDetector::writeAdcRegister(int addr, int val){ - - int retval=-1; - int fnum=F_WRITE_ADC_REG; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - uint32_t arg[2]; - arg[0]=addr; - arg[1]=val; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Writing to adc register "<< hex<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } -#ifdef VERBOSE - std::cout<< "ADC Register returned "<< retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Write ADC to register failed " << std::endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); - } - return retval; - -}; - - - - -uint32_t slsDetector::readRegister(uint32_t addr){ - - uint32_t retval = 0; - int fnum=F_READ_REGISTER; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - uint32_t arg; - arg=addr; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Reading register "<< hex<onlineFlag==ONLINE_FLAG) { - // if (connectControl() == OK){ - if (stopSocket) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectStop(); - } - } - } -#ifdef VERBOSE - std::cout<< "Register returned "<< retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Read register failed " << std::endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); - } - return retval; - -} - - -uint32_t slsDetector::setBit(uint32_t addr, int n) { - if (n<0 || n>31) { - std::cout << "Bit number out of Range" << std:: endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); - } - - // normal bit range - //TODO! (Erik) Check for errors! cannot use value since reg is 32bits - else { - uint32_t val = readRegister(addr); - writeRegister(addr,val | 1<31) { - std::cout << "Bit number out of Range" << std:: endl; - setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); - } - - // normal bit range - else { - uint32_t val = readRegister(addr); - writeRegister(addr,val & ~(1<myDetectorType == GOTTHARD) || (thisDetector->myDetectorType == PROPIX))) - index=HV_POT; - - arg[0]=index; - arg[1]=imod; - arg[2]=mV; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting DAC "<< index << " of module " << imod << " to " << val << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->SendDataOnly(&val,sizeof(val)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(retval,sizeof(retval)); - if (index < thisDetector->nDacs){ - - if (dacs) { - if (imod>=0) { - *(dacs+index+imod*thisDetector->nDacs)=retval[0]; - } - else { - for (imod=0; imodnModsMax; ++imod) - *(dacs+index+imod*thisDetector->nDacs)=retval[0]; - } - } - } - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - - } - } -#ifdef VERBOSE - std::cout<< "Dac set to "<< retval[0] << " dac units (" << retval[1] << "mV)" << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Set dac " << index << " of module " << imod << " to " << val << " failed." << std::endl; - } - if(mV) - return retval[1]; - - return retval[0]; -}; - - -dacs_t slsDetector::getADC(dacIndex index, int imod){ - - dacs_t retval; - int fnum=F_GET_ADC; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - int arg[2]; - arg[0]=index; - arg[1]=imod; - - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Getting ADC "<< index << " of module " << imod << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK){ - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if (adcs) { - *(adcs+index+imod*thisDetector->nAdcs)=retval; - } - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectStop(); - /*commented out to allow adc read during acquire, also not required - if (ret==FORCE_UPDATE) - updateDetector();*/ - } - } -#ifdef VERBOSE - std::cout<< "ADC returned "<< retval << std::endl; -#endif - if (ret==FAIL) { - std::cout<< "Get ADC failed " << std::endl; - } - - return retval; - - - -}; - - - - -int slsDetector::setThresholdTemperature(int val, int imod) { - - int retval = -1; - int fnum = F_THRESHOLD_TEMP; - int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; - - int arg[2]; - arg[0]=val; - arg[1]=imod; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " << imod << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK){ - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - std::cout<< "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } - } - - return retval; -} - - - -int slsDetector::setTemperatureControl(int val, int imod) { - - int retval = -1; - int fnum = F_TEMP_CONTROL; - int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; - - int arg[2]; - arg[0]=val; - arg[1]=imod; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " << imod << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK){ - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - std::cout<< "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } - } - - return retval; -} - - - - -int slsDetector::setTemperatureEvent(int val, int imod) { - - int retval = -1; - int fnum = F_TEMP_EVENT; - int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; - - int arg[2]; - arg[0]=val; - arg[1]=imod; - - -#ifdef VERBOSE - std::cout<< std::endl; - std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " << imod << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectStop() == OK){ - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(arg,sizeof(arg)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); -#ifdef VERBOSE - std::cout<< "Threshold Temperature returned "<< retval << std::endl; -#endif - } else { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); - } - disconnectStop(); - } - } - - return retval; -} - - -/* - configure single channel - enum channelRegisterBit { - COMPARATOR_ENABLE_OFF, - ANALOG_SIGNAL_ENABLE_OFF, - CALIBRATION_ENABLE_OFF, - TRIMBIT_OFF // should always be the last! - } - -*/ - -int slsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod){ - sls_detector_channel myChan; -#ifdef VERBOSE - std::cout<< "Setting channel "<< ichan << " " << ichip << " " << imod << " to " << reg << std::endl; -#endif - //int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, chamax=ichan+1; - - int ret; - - /* if (imod==-1) { - mmin=0; - mmax=thisDetector->nModsMax; - } - - if (ichip==-1) { - chimin=0; - chimax=thisDetector->nChips; - } - - if (ichan==-1) { - chamin=0; - chamax=thisDetector->nChans; - }*/ - - // for (int im=mmin; imonlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - sendChannel(&chan); - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (chanregs) { - - int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, chamax=ichan+1; - - if (imod==-1) { - mmin=0; - mmax=thisDetector->nModsMax; - } - - if (ichip==-1) { - chimin=0; - chimax=thisDetector->nChips; - } - - if (ichan==-1) { - chamin=0; - chamax=thisDetector->nChans; - } - - - - - - - for (int im=mmin; imnChans*thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; - - } - } - } - - } - } -#ifdef VERBOSE - std::cout<< "Channel register returned "<< retval << std::endl; -#endif - return retval; - -} - - - - - - - - - - - - - - - - - - -slsDetectorDefs::sls_detector_channel slsDetector::getChannel(int ichan, int ichip, int imod){ - - - int fnum=F_GET_CHANNEL; - sls_detector_channel myChan; - int arg[3]; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - arg[0]=ichan; - arg[1]=ichip; - arg[2]=imod; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - receiveChannel(&myChan); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (chanregs) { - *(chanregs+imod*thisDetector->nChans*thisDetector->nChips+ichip*thisDetector->nChips+ichan)=myChan.reg; - } - } - -#ifdef VERBOSE - std::cout<< "Returned channel "<< ichan << " " << ichip << " " << imod << " " << myChan.reg << std::endl; -#endif - return myChan; -} - -/* - configure chip - enum chipRegisterBit { - ENABLE_ANALOG_OUTPUT, - OUTPUT_WIDTH // should always be the last - }{}; -*/ -int slsDetector::setChip(int reg, int ichip, int imod){ - sls_detector_chip myChip; - -#ifdef VERBOSE - std::cout<< "Setting chip "<< ichip << " " << imod << " to " << reg << std::endl; -#endif - - - int chregs[thisDetector->nChans]; - int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1; - int ret=FAIL; - if (imod==-1) { - mmin=0; - mmax=thisDetector->nModsMax; - } - - if (ichip==-1) { - chimin=0; - chimax=thisDetector->nChips; - } - - myChip.nchan=thisDetector->nChans; - myChip.reg=reg; - for (int im=mmin; imnChans+im*thisDetector->nChans*thisDetector->nChips); - else { - for (int i=0; inChans; ++i) - chregs[i]=-1; - myChip.chanregs=chregs; - } - ret=setChip(myChip); - } - } - return ret; -} - -int slsDetector::setChip(sls_detector_chip chip){ - - int fnum=F_SET_CHIP; - int retval; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - int ichi=chip.chip; - int im=chip.module; - - - - - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - sendChip(&chip); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (chipregs) - *(chipregs+ichi+im*thisDetector->nChips)=retval; - } - -#ifdef VERBOSE - std::cout<< "Chip register returned "<< retval << std::endl; -#endif - return retval; -}; - - -slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod){ - - int fnum=F_GET_CHIP; - sls_detector_chip myChip; - int chanreg[thisDetector->nChans]; - - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - - myChip.chip=ichip; - myChip.module=imod; - myChip.nchan=thisDetector->nChans; - myChip.chanregs=chanreg; - - int arg[2]; - arg[0]=ichip; - arg[1]=imod; - - - - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - receiveChip(&myChip); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (chipregs) - *(chipregs+ichip+imod*thisDetector->nChips)=myChip.reg; - if (chanregs) { - for (int ichan=0; ichannChans; ++ichan) - *(chanregs+imod*thisDetector->nChans*thisDetector->nChips+ichip*thisDetector->nChans+ichan)=*((myChip.chanregs)+ichan); - } - } -#ifdef VERBOSE - std::cout<< "Returned chip "<< ichip << " " << imod << " " << myChip.reg << std::endl; -#endif - - return myChip; -}; - -/* - configure module - enum moduleRegisterBit { - I_DON_T_KNOW, - OUTPUT_WIDTH // should always be the last - }{}; -*/ - -int slsDetector::setModule(int reg, int imod){ - sls_detector_module myModule; - - #ifdef VERBOSE - std::cout << "slsDetector set module " << std::endl; -#endif - int charegs[thisDetector->nChans*thisDetector->nChips]; - int chiregs[thisDetector->nChips]; - dacs_t das[thisDetector->nDacs], ads[thisDetector->nAdcs]; - int mmin=imod, mmax=imod+1; - int ret=FAIL; - - if (imod==-1) { - mmin=0; - mmax=thisDetector->nModsMax; - } - - - - for (int im=mmin; imnChans; - myModule.nchip=thisDetector->nChips; - myModule.ndac=thisDetector->nDacs; - myModule.nadc=thisDetector->nAdcs; - - myModule.reg=reg; - if (detectorModules) { - myModule.gain=(detectorModules+im)->gain; - myModule.offset=(detectorModules+im)->offset; - myModule.serialnumber=(detectorModules+im)->serialnumber; - } else { - myModule.gain=-1; - myModule.offset=-1; - myModule.serialnumber=-1; - } - - - for (int i=0; inAdcs; ++i) - ads[i]=-1; - - if (chanregs) - myModule.chanregs=chanregs+im*thisDetector->nChips*thisDetector->nChans; - else { - for (int i=0; inChans*thisDetector->nChips; ++i) - charegs[i]=-1; - myModule.chanregs=charegs; - } - if (chipregs) - myModule.chipregs=chanregs+im*thisDetector->nChips; - else { - for (int ichip=0; ichipnChips; ++ichip) - chiregs[ichip]=-1; - myModule.chipregs=chiregs; - } - if (dacs) - myModule.dacs=dacs+im*thisDetector->nDacs; - else { - for (int i=0; inDacs; ++i) - das[i]=-1; - myModule.dacs=das; - } - if (adcs) - myModule.adcs=adcs+im*thisDetector->nAdcs; - else { - for (int i=0; inAdcs; ++i) - ads[i]=-1; - myModule.adcs=ads; - } - ret=setModule(myModule,-1,-1,-1,0,0); - } - return ret; - - -}; - -int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval, int* offsetval, int tb){ - - int fnum=F_SET_MODULE; - int retval=-1; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - - int imod=module.module; - - -#ifdef VERBOSE - std::cout << "slsDetector set module " << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - //to exclude trimbits - if(!tb) { - module.nchan=0; - module.nchip=0; - } - sendModule(&module); - - //not included in module - if(gainval && (thisDetector->nGain)) - controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if(offsetval && (thisDetector->nOffset)) - controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - if(thisDetector->myDetectorType == EIGER) { - controlSocket->SendDataOnly(&iodelay,sizeof(iodelay)); - controlSocket->SendDataOnly(&tau,sizeof(tau)); - controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); - } - - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - if(strstr(mess,"default tau")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (detectorModules) { - if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { - if(tb) { - (detectorModules+imod)->nchan=module.nchan; - (detectorModules+imod)->nchip=module.nchip; - } - (detectorModules+imod)->ndac=module.ndac; - (detectorModules+imod)->nadc=module.nadc; - if(tb) { - thisDetector->nChips=module.nchip; - thisDetector->nChans=module.nchan/module.nchip; - } - thisDetector->nDacs=module.ndac; - thisDetector->nAdcs=module.nadc; - - if(thisDetector->myDetectorType != JUNGFRAU){ - if(tb) { - for (int ichip=0; ichipnChips; ++ichip) { - if (chipregs) - chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip]; - - if (chanregs) { - for (int i=0; inChans; ++i) { - chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i]; - } - } - } - } - if (adcs) { - for (int i=0; inAdcs; ++i) - adcs[i+imod*thisDetector->nAdcs]=module.adcs[i]; - } - } - - if (dacs) { - for (int i=0; inDacs; ++i) - dacs[i+imod*thisDetector->nDacs]=module.dacs[i]; - } - - (detectorModules+imod)->gain=module.gain; - (detectorModules+imod)->offset=module.offset; - (detectorModules+imod)->serialnumber=module.serialnumber; - (detectorModules+imod)->reg=module.reg; - } - } - - if ((thisDetector->nGain) && (gainval) && (gain)) { - for (int i=0; inGain; ++i) - gain[i+imod*thisDetector->nGain]=gainval[i]; - } - - if ((thisDetector->nOffset) && (offsetval) && (offset)) { - for (int i=0; inOffset; ++i) - offset[i+imod*thisDetector->nOffset]=offsetval[i]; - } - - if (e_eV != -1) - thisDetector->currentThresholdEV = e_eV; - - } - -#ifdef VERBOSE - std::cout<< "Module register returned "<< retval << std::endl; -#endif - - return retval; -}; - - - - - -slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod){ - -#ifdef VERBOSE - std::cout << "slsDetector get module " << std::endl; -#endif - - int fnum=F_GET_MODULE; - sls_detector_module *myMod=createModule(); - - int* gainval=0, *offsetval=0; - if(thisDetector->nGain) - gainval=new int[thisDetector->nGain]; - if(thisDetector->nOffset) - offsetval=new int[thisDetector->nOffset]; - - //char *ptr, *goff=(char*)thisDetector; - - // int chanreg[thisDetector->nChans*thisDetector->nChips]; - //int chipreg[thisDetector->nChips]; - //double dac[thisDetector->nDacs], adc[thisDetector->nAdcs]; - - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - // int n; - -#ifdef VERBOSE - std::cout<< "getting module " << imod << std::endl; -#endif - - myMod->module=imod; - // myMod.nchan=thisDetector->nChans*thisDetector->nChips; - //myMod.chanregs=chanreg; - //myMod.nchip=thisDetector->nChips; - //myMod.chipregs=chipreg; - //myMod.ndac=thisDetector->nDacs; - //myMod.dacs=dac; - //myMod.ndac=thisDetector->nAdcs; - //myMod.dacs=adc; - - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&imod,sizeof(imod)); - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - receiveModule(myMod); - - //extra gain and offset - eiger - if(thisDetector->nGain) - controlSocket->ReceiveDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if(thisDetector->nOffset) - controlSocket->ReceiveDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - - if (ret!=FAIL) { - if (detectorModules) { - if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { - (detectorModules+imod)->nchan=myMod->nchan; - (detectorModules+imod)->nchip=myMod->nchip; - (detectorModules+imod)->ndac=myMod->ndac; - (detectorModules+imod)->nadc=myMod->nadc; - thisDetector->nChips=myMod->nchip; - thisDetector->nChans=myMod->nchan/myMod->nchip; - thisDetector->nDacs=myMod->ndac; - thisDetector->nAdcs=myMod->nadc; - - if(thisDetector->myDetectorType != JUNGFRAU){ - for (int ichip=0; ichipnChips; ++ichip) { - if (chipregs) - chipregs[ichip+thisDetector->nChips*imod]=myMod->chipregs[ichip]; - - if (chanregs) { - for (int i=0; inChans; ++i) { - chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=myMod->chanregs[ichip*thisDetector->nChans+i]; - } - } - } - - if (adcs) { - for (int i=0; inAdcs; ++i) - adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i]; - } - } - - if (dacs) { - for (int i=0; inDacs; ++i) { - dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; - //cprintf(BLUE,"dac%d:%d\n",i, myMod->dacs[i]); - } - } - (detectorModules+imod)->gain=myMod->gain; - (detectorModules+imod)->offset=myMod->offset; - (detectorModules+imod)->serialnumber=myMod->serialnumber; - (detectorModules+imod)->reg=myMod->reg; - } - } - - if ((thisDetector->nGain) && (gainval) && (gain)) { - for (int i=0; inGain; ++i) - gain[i+imod*thisDetector->nGain]=gainval[i]; - } - - if ((thisDetector->nOffset) && (offsetval) && (offset)) { - for (int i=0; inOffset; ++i) - offset[i+imod*thisDetector->nOffset]=offsetval[i]; - } - - } else { - deleteModule(myMod); - myMod=NULL; - } - - if(gainval) delete[]gainval; - if(offsetval) delete[]offsetval; - - return myMod; -} - - - - -// calibration functions -/* - really needed? - - int slsDetector::setCalibration(int imod, detectorSettings isettings, double gain, double offset){ - std::cout<< "function not yet implemented " << std::endl; - - - - return OK; - - } - int slsDetector::getCalibration(int imod, detectorSettings isettings, double &gain, double &offset){ - - std::cout<< "function not yet implemented " << std::endl; - - - - } -*/ - -/* - calibrated setup of the threshold -*/ - -int slsDetector::getThresholdEnergy(int imod){ - - int fnum= F_GET_THRESHOLD_ENERGY; - int retval; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; -#ifdef VERBOSE - std::cout<< "Getting threshold energy "<< std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&imod,sizeof(imod)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - std::cout<< "Detector returned error: "<< std::endl; - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->currentThresholdEV=retval; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return thisDetector->currentThresholdEV; -}; - -int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings, int tb){ - - //currently only for eiger - if (thisDetector->myDetectorType == EIGER) { - setThresholdEnergyAndSettings(e_eV,isettings,tb); - return thisDetector->currentThresholdEV; - } - - int fnum= F_SET_THRESHOLD_ENERGY; - int retval; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; -#ifdef VERBOSE - std::cout<< "Setting threshold energy "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); - controlSocket->SendDataOnly(&imod,sizeof(imod)); - controlSocket->SendDataOnly(&isettings,sizeof(isettings)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - std::cout<< "Detector returned error: "<< std::endl; - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< mess << std::endl; - } else { -#ifdef VERBOSE - std::cout<< "Detector returned OK "<< std::endl; -#endif - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->currentThresholdEV=retval; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - thisDetector->currentThresholdEV=e_eV; - } - return thisDetector->currentThresholdEV; -}; - - - -int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb) { - - //if settings provided, use that, else use the shared memory variable - detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: thisDetector->currentSettings); - string ssettings; - switch (is) { - case STANDARD: - ssettings="/standard"; - thisDetector->currentSettings=STANDARD; - break; - case HIGHGAIN: - ssettings="/highgain"; - thisDetector->currentSettings=HIGHGAIN; - break; - case LOWGAIN: - ssettings="/lowgain"; - thisDetector->currentSettings=LOWGAIN; - break; - case VERYHIGHGAIN: - ssettings="/veryhighgain"; - thisDetector->currentSettings=VERYHIGHGAIN; - break; - case VERYLOWGAIN: - ssettings="/verylowgain"; - thisDetector->currentSettings=VERYLOWGAIN; - break; - default: - printf("Error: Unknown settings %s for this detector!\n", getDetectorSettings(is).c_str()); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - return FAIL; - } - - //verify e_eV exists in trimEneregies[] - if (!thisDetector->nTrimEn || - (e_eV < thisDetector->trimEnergies[0]) || - (e_eV > thisDetector->trimEnergies[thisDetector->nTrimEn-1]) ) { - printf("Error: This energy %d not defined for this module!\n", e_eV); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - return FAIL; - } - - //find if interpolation required - bool interpolate = true; - for (int i = 0; i < thisDetector->nTrimEn; ++i) { - if (thisDetector->trimEnergies[i] == e_eV) { - interpolate = false; - break; - } - } - - //fill detector module structure - sls_detector_module *myMod = NULL; - int iodelay = -1; //not included in the module - int tau = -1; //not included in the module - - //normal - if(!interpolate) { - //find their directory names - ostringstream ostfn; - ostfn << thisDetector->settingsDir << ssettings << "/" << e_eV << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); - string settingsfname = ostfn.str(); -#ifdef VERBOSE - printf("Settings File is %s\n", settingsfname.c_str()); -#endif - //read the files - myMod=createModule(); - if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, iodelay, tau, myMod, tb)) { - if(myMod)deleteModule(myMod); - return FAIL; - } - } - - - //interpolate - else { - //find the trim values - int trim1 = -1, trim2 = -1; - for (int i = 0; i < thisDetector->nTrimEn; ++i) { - if (e_eV < thisDetector->trimEnergies[i]) { - trim2 = thisDetector->trimEnergies[i]; - trim1 = thisDetector->trimEnergies[i-1]; - break; - } - } - //find their directory names - ostringstream ostfn; - ostfn << thisDetector->settingsDir << ssettings << "/" << trim1 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); - string settingsfname1 = ostfn.str(); - ostfn.str(""); ostfn.clear(); - ostfn << thisDetector->settingsDir << ssettings << "/" << trim2 << "eV" << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); - string settingsfname2 = ostfn.str(); - //read the files -#ifdef VERBOSE - printf("Settings Files are %s and %s\n",settingsfname1.c_str(), settingsfname2.c_str()); -#endif - sls_detector_module *myMod1=createModule(); - sls_detector_module *myMod2=createModule(); - int iodelay1 = -1; //not included in the module - int tau1 = -1; //not included in the module - int iodelay2 = -1; //not included in the module - int tau2 = -1; //not included in the module - if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, iodelay1, tau1, myMod1, tb)) { - setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); - deleteModule(myMod1); - deleteModule(myMod2); - return FAIL; - } - if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, iodelay2, tau2, myMod2, tb)) { - setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); - deleteModule(myMod1); - deleteModule(myMod2); - return FAIL; - } - if (iodelay1 != iodelay2) { - printf("iodelays do not match between files\n"); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - deleteModule(myMod1); - deleteModule(myMod2); - return FAIL; - } - iodelay = iodelay1; - - //interpolate module - myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, e_eV, trim1, trim2, tb); - if (myMod == NULL) { - printf("Could not interpolate, different dac values in files\n"); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - deleteModule(myMod1); - deleteModule(myMod2); - return FAIL; - } - //interpolate tau - tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2); - //printf("new tau:%d\n",tau); - - deleteModule(myMod1); - deleteModule(myMod2); - } - - - myMod->module=0; - myMod->reg=thisDetector->currentSettings; - setModule(*myMod, iodelay, tau, e_eV, 0, 0, tb); - deleteModule(myMod); - if (getSettings(-1) != is){ - std::cout << "Could not set settings in detector" << endl; - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - return FAIL; - } - - return OK; -} - - - -/* - select detector settings -*/ -slsDetectorDefs::detectorSettings slsDetector::getSettings(int imod){ - - return sendSettingsOnly(GET_SETTINGS, imod); -} - - - -slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings isettings, int imod){ -#ifdef VERBOSE - std::cout<< "slsDetector setSettings " << isettings << std::endl; -#endif - - detectorType detType = thisDetector->myDetectorType; - switch (detType) { - - // eiger: only set client shared memory variable for Eiger, - // settings threshold loads the module data (trimbits, dacs etc.) - case EIGER: - switch(isettings) { - case STANDARD: - case HIGHGAIN: - case LOWGAIN: - case VERYHIGHGAIN: - case VERYLOWGAIN: - thisDetector->currentSettings = isettings; - break; - default: - printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str()); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - break; - } - return thisDetector->currentSettings; - - // send only the settings, detector server will update dac values already in server - case GOTTHARD: - case PROPIX: - case JUNGFRAU: - case MOENCH: - return sendSettingsOnly(isettings); - break; - - // others send whole module to detector - default: - break; - } - - - - // MYTHEN ONLY (sends whole detector to module) - - sls_detector_module *myMod=createModule(); - int modmi=imod, modma=imod+1, im=imod; - string settingsfname, calfname; - string ssettings; - - //not included in module structure - int iodelay = -1; - int tau = -1; - int* gainval=0, *offsetval=0; - if(thisDetector->nGain) - gainval=new int[thisDetector->nGain]; - if(thisDetector->nOffset) - offsetval=new int[thisDetector->nOffset]; - - - switch (isettings) { - case STANDARD: - ssettings="/standard"; - thisDetector->currentSettings=STANDARD; - break; - case FAST: - ssettings="/fast"; - thisDetector->currentSettings=FAST; - break; - case HIGHGAIN: - ssettings="/highgain"; - thisDetector->currentSettings=HIGHGAIN; - break; - default: - break; - } - - - if (isettings != thisDetector->currentSettings) { - printf("Unknown settings %s for this detector!\n", getDetectorSettings(isettings).c_str()); - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - }else{ - if (imod<0) { - modmi=0; - // modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; - modma=thisDetector->nMod[X]*thisDetector->nMod[Y]; - } - - for (im=modmi; immodule=im; - - std::cout << std::endl << "Loading settings for module:" << im << std::endl; - - //create file names - ostfn << thisDetector->settingsDir << ssettings <<"/noise.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10); - oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10); - - - //settings file**** - settingsfname=ostfn.str(); -#ifdef VERBOSE - cout << "the settings file name is "<settingsDir << ssettings << ssettings << ".trim"; - settingsfname=ostfn_default.str(); -#ifdef VERBOSE - cout << settingsfname << endl; -#endif - if (NULL == readSettingsFile(settingsfname,detType, iodelay, tau, myMod)) { - //if default doesnt work, return error - std::cout << "Could not open settings file" << endl; - setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); - return thisDetector->currentSettings; - } - } - - - - //calibration file**** - int ret=0; - calfname=oscfn.str(); -#ifdef VERBOSE - cout << "Specific file:"<< calfname << endl; -#endif - //extra gain and offset - if(thisDetector->nGain) - ret = readCalibrationFile(calfname,gainval, offsetval); - //normal gain and offset inside sls_detector_module - else - ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); - - //if it didnt open, try default - if(ret != OK){ - ostringstream oscfn_default; - oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal"; - calfname=oscfn_default.str(); -#ifdef VERBOSE - cout << "Default file:" << calfname << endl; -#endif - //extra gain and offset - if(thisDetector->nGain) - ret = readCalibrationFile(calfname,gainval, offsetval); - //normal gain and offset inside sls_detector_module - else - ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); - } - //if default doesnt work, return error - if(ret != OK){ - std::cout << "Could not open calibration file" << calfname << endl; - setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); - return thisDetector->currentSettings; - } - - - //if everything worked, set module**** - setModule(*myMod,iodelay,tau,-1,gainval,offsetval); - } - } - - - - deleteModule(myMod); - if(gainval) delete [] gainval; - if(offsetval) delete [] offsetval; - - if (thisDetector->correctionMask&(1<-1 && isett<3) { - thisDetector->tDead=t[isett]; - } - } - - - if (getSettings(imod) != isettings){ - std::cout << "Could not set settings" << endl; - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - } - - return thisDetector->currentSettings; -} - - - -int slsDetector::getChanRegs(double* retval,bool fromDetector){ - int n=getTotalNumberOfChannels(); - if(fromDetector){ - for(int im=0;imonlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); - } else{ - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->currentSettings = (detectorSettings)retval; -#ifdef VERBOSE - std::cout<< "Settings are " << retval << std::endl; -#endif - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return thisDetector->currentSettings; -} - - -int slsDetector::updateDetectorNoWait() { - - enum readOutFlags ro; - // int ret=OK; - enum detectorSettings t; - int thr, n = 0, nm; - // int it; - int64_t retval;// tns=-1; - char lastClientIP[INET_ADDRSTRLEN]; - - n += controlSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); -#ifdef VERBOSE - cout << "Updating detector last modified by " << lastClientIP << std::endl; -#endif - n += controlSocket->ReceiveDataOnly(&nm,sizeof(nm)); - thisDetector->nMod[X]=nm; - n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); - /// Should be overcome at a certain point! - - if (thisDetector->myDetectorType==MYTHEN) { - thisDetector->nModMax[X]=nm; - thisDetector->nModMax[Y]=1; - thisDetector->nModsMax=thisDetector->nModMax[Y]*thisDetector->nModMax[X]; - thisDetector->nMod[Y]=1; - } else { - thisDetector->nMod[Y]=nm; - } - - thisDetector->nMods=thisDetector->nMod[Y]*thisDetector->nMod[X]; - if (thisDetector->nModsMaxnMods) - thisDetector->nModsMax=thisDetector->nMods; - - if (thisDetector->nModMax[X]nMod[X]) - thisDetector->nModMax[X]=thisDetector->nMod[X]; - - if (thisDetector->nModMax[Y]nMod[Y]) - thisDetector->nModMax[Y]=thisDetector->nMod[Y]; - - n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); - thisDetector->dynamicRange=nm; - - n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); - thisDetector->dataBytes=nm; - - //t=setSettings(GET_SETTINGS); - n += controlSocket->ReceiveDataOnly( &t,sizeof(t)); - thisDetector->currentSettings=t; - - if((thisDetector->myDetectorType == EIGER) || (thisDetector->myDetectorType == MYTHEN)){ - //thr=getThresholdEnergy(); - n += controlSocket->ReceiveDataOnly( &thr,sizeof(thr)); - thisDetector->currentThresholdEV=thr; - } - - //retval=setFrames(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[FRAME_NUMBER]=retval; - - // retval=setExposureTime(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[ACQUISITION_TIME]=retval; - - if(thisDetector->myDetectorType == EIGER){ - //retval=setSubFrameExposureTime(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]=retval; - - //retval=setSubFramePeriod(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[SUBFRAME_PERIOD]=retval; - } - - //retval=setPeriod(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[FRAME_PERIOD]=retval; - - if(thisDetector->myDetectorType != EIGER) { - //retval=setDelay(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[DELAY_AFTER_TRIGGER]=retval; - } - - // retval=setGates(tns); - if ((thisDetector->myDetectorType != JUNGFRAU) && (thisDetector->myDetectorType != EIGER)){ - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[GATES_NUMBER]=retval; - } - - //retval=setProbes(tns); - if (thisDetector->myDetectorType == MYTHEN){ - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[PROBES_NUMBER]=retval; - } - - //retval=setTrains(tns); - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - thisDetector->timerValue[CYCLES_NUMBER]=retval; - - //retval=setProbes(tns); - if (thisDetector->myDetectorType == JUNGFRAUCTB){ - n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); - if (retval>=0) - thisDetector->timerValue[SAMPLES_JCTB]=retval; - n += controlSocket->ReceiveDataOnly( &ro,sizeof(ro)); - - thisDetector->roFlags=ro; - - //retval=setProbes(tns); - getTotalNumberOfChannels(); - // thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; - } - - - if (!n) - printf("n: %d\n", n); - - return OK; - -} - - - - -int slsDetector::updateDetector() { - int fnum=F_UPDATE_CLIENT; - int ret=OK; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - 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; - } else - updateDetectorNoWait(); - disconnectControl(); - } - } - return ret; -} - - - -// 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(){ - - - int fnum=F_START_ACQUISITION; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<< "Starting acquisition "<< std::endl; -#endif - thisDetector->stoppedFlag=0; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - 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(); - } - } - return ret; - - - -}; - - -int slsDetector::stopAcquisition(){ - - // get status before stopping acquisition - runStatus s = ERROR, r = ERROR; - if (thisDetector->receiver_upstream) { - s = getRunStatus(); - r = getReceiverStatus(); - } - - int fnum=F_STOP_ACQUISITION; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<< "Stopping acquisition "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (stopSocket) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectStop(); - } - } - } - thisDetector->stoppedFlag=1; - - // if rxr streaming and acquisition finished, restream dummy stop packet - if ((thisDetector->receiver_upstream) && (s == IDLE) && (r == IDLE)) { - restreamStopFromReceiver(); - } - - return ret; - - -}; - -int slsDetector::startReadOut(){ - - int fnum=F_START_READOUT; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<< "Starting readout "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - 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(); - } - } - return ret; -}; - - -slsDetectorDefs::runStatus slsDetector::getRunStatus(){ - int fnum=F_GET_RUN_STATUS; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - strcpy(mess,"could not get run status"); - runStatus retval=ERROR; -#ifdef VERBOSE - std::cout<< "Getting status "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (stopSocket) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - - //cout << "________:::____________" << ret << endl; - - if (ret==FAIL) { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); - //cout << "____________________" << retval << endl; - } - disconnectStop(); - } - } - } - return retval; - - -}; - - -int* slsDetector::readFrame(){ - - int fnum=F_READ_FRAME; - int* retval=NULL; - -#ifdef VERBOSE - std::cout<< "slsDetector: Reading frame "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - retval=getDataFromDetector(); - if (retval) { - dataQueue.push(retval); - disconnectControl(); - } - } - } - return retval; -}; - - - - -int* slsDetector::getDataFromDetector(int *retval){ - int ret=FAIL; - char mess[MAX_STR_LENGTH]="Nothing"; - int nel=thisDetector->dataBytes/sizeof(int); - int n; - int *r=retval; - - int nodatadetectortype = false; - detectorType types = getDetectorsType(); - if(types == EIGER || types == JUNGFRAU){ - nodatadetectortype = true; - } - - - if (!nodatadetectortype && retval==NULL) - retval=new int[nel]; - - -#ifdef VERBOSE - std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl; -#endif - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); -#ifdef VERBOSE - cout << "ret=" << ret << endl; -#endif - - if (ret!=OK) { - n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - // if(thisDetector->receiverOnlineFlag == OFFLINE_FLAG) - if (ret==FAIL) { - thisDetector->stoppedFlag=1; - std::cout<< "Detector returned: " << mess << " " << n << std::endl; - } else { - ; -#ifdef VERBOSE - std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; -#endif - } - if ((!nodatadetectortype) && (r==NULL)){ - delete [] retval; - } - return NULL; - } else if (!nodatadetectortype){ - - n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); - -#ifdef VERBOSE - std::cout<< "Received "<< n << " data bytes" << std::endl; -#endif - if (n!=thisDetector->dataBytes) { - std::cout<< "wrong data size received from detector: received " << n << " but expected " << thisDetector->dataBytes << std::endl; - thisDetector->stoppedFlag=1; - ret=FAIL; - if (r==NULL) { - delete [] retval; - } - return NULL; - } - // for (int ib=0; ibdataBytes/8; ++ib) - // cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ; - - - } - // cout << "get data returning " << endl; - // cout << endl; - return retval; - -}; - - - - - - -int* slsDetector::readAll(){ - - int fnum=F_READ_ALL; - int* retval; // check what we return! - -#ifdef VERBOSE - int i=0; - std::cout<< "Reading all frames "<< std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - - while ((retval=getDataFromDetector())){ -#ifdef VERBOSE - ++i; - std::cout<< i << std::endl; -#endif - dataQueue.push(retval); - } - disconnectControl(); - } - } -#ifdef VERBOSE - std::cout<< "received "<< i<< " frames" << std::endl; -#endif - return dataQueue.front(); // check what we return! - -}; - - - - - -int slsDetector::readAllNoWait(){ - - int fnum= F_READ_ALL; - -#ifdef VERBOSE - std::cout<< "Reading all frames "<< std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - return OK; - } - } - return FAIL; -}; - - - - - - - - -int* slsDetector::startAndReadAll(){ - //cout << "Start and read all "<< endl; - - int* retval; - //#ifdef VERBOSE -#ifdef VERBOSE - int i=0; -#endif - //#endif - if(thisDetector->myDetectorType == EIGER) { - if (prepareAcquisition() == FAIL) - return NULL; - } - startAndReadAllNoWait(); - //#ifdef VERBOSE - // std::cout<< "started" << std::endl; - //#endif - while ((retval=getDataFromDetector())){ -#ifdef VERBOSE - ++i; - std::cout<< i << std::endl; - //#else - //std::cout<< "-" << flush; -#endif - dataQueue.push(retval); - - //std::cout<< "pushed" << std::endl; - } - disconnectControl(); - -#ifdef VERBOSE - std::cout<< "received "<< i<< " frames" << std::endl; - //#else - // std::cout << std::endl; -#endif - return dataQueue.front(); // check what we return! - /* while ((retval=getDataFromDetectorNoWait())) - ++i; - #ifdef VERBOSE - std::cout<< "Received " << i << " frames"<< std::endl; - #endif - return dataQueue.front(); // check what we return! - */ - -}; - - - -int slsDetector::startAndReadAllNoWait(){ - - int fnum= F_START_AND_READ_ALL; - -#ifdef VERBOSE - std::cout<< "Starting and reading all frames "<< std::endl; -#endif - thisDetector->stoppedFlag=0; - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - //std::cout<< "connected" << std::endl; - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - return OK; - } - } - return FAIL; -}; - - - -/* - set or read the acquisition timers - enum timerIndex { - FRAME_NUMBER, - ACQUISITION_TIME, - FRAME_PERIOD, - DELAY_AFTER_TRIGGER, - GATES_NUMBER, - PROBES_NUMBER - CYCLES_NUMBER, - GATE_INTEGRATED_TIME - } -*/ -int64_t slsDetector::setTimer(timerIndex index, int64_t t){ - - - int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER; - int64_t retval = -1; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - - if (index!=MEASUREMENTS_NUMBER) { - - -#ifdef VERBOSE - std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl; -#endif +int slsDetector::setOnline(int off) { + int old=thisDetector->onlineFlag; + if (off!=GET_ONLINE_FLAG) { + thisDetector->onlineFlag=off; if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - controlSocket->SendDataOnly(&t,sizeof(t)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_TIMER_VALUE_NOT_SET)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->timerValue[index]=retval; - } - disconnectControl(); - if (ret==FORCE_UPDATE) { - updateDetector(); -#ifdef VERBOSE - std::cout<< "Updated!" << std::endl; -#endif - - } + setTCPSocket(); + if (thisDetector->onlineFlag==ONLINE_FLAG && old==OFFLINE_FLAG) { + cout << "Detector connecting for the first time - updating!" << endl; + updateDetector(); } - } else { - //std::cout<< "offline " << std::endl; - if (t>=0) - thisDetector->timerValue[index]=t; - if((thisDetector->myDetectorType==GOTTHARD)|| - (thisDetector->myDetectorType==PROPIX)|| - (thisDetector->myDetectorType==JUNGFRAU)|| - (thisDetector->myDetectorType==MOENCH)) - thisDetector->timerValue[PROBES_NUMBER]=0; - if(thisDetector->myDetectorType==JUNGFRAUCTB && index==SAMPLES_JCTB) { - getTotalNumberOfChannels(); - // thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + else if(thisDetector->onlineFlag==OFFLINE_FLAG){ + std::cout << "cannot connect to detector" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); } - } + } + return thisDetector->onlineFlag; +} + + + +string slsDetector::checkOnline() { + string retval=""; + if(!controlSocket){ + //this already sets the online/offline flag + setTCPSocket(); + if(thisDetector->onlineFlag==OFFLINE_FLAG) + return string(thisDetector->hostname); + else + return string(""); + } + //still cannot connect to socket, controlSocket=0 + if(controlSocket){ + if (connectControl() == FAIL) { + controlSocket->SetTimeOut(5); + thisDetector->onlineFlag=OFFLINE_FLAG; + delete controlSocket; + controlSocket=NULL; + retval = string(thisDetector->hostname); +#ifdef VERBOSE + std::cout<< "offline!" << std::endl; +#endif + } else { + thisDetector->onlineFlag=ONLINE_FLAG; + controlSocket->SetTimeOut(100); + disconnectControl(); +#ifdef VERBOSE + std::cout<< "online!" << std::endl; +#endif + } + } + return retval; +} + + + + +int slsDetector::setTCPSocket(string const name, int const control_port, int const stop_port) { + char thisName[MAX_STR_LENGTH]; + int thisCP, thisSP; + int retval=OK; + + if (strcmp(name.c_str(),"")!=0) { +#ifdef VERBOSE + std::cout<< "setting hostname" << std::endl; +#endif + strcpy(thisName,name.c_str()); + strcpy(thisDetector->hostname,thisName); + if (controlSocket) { + delete controlSocket; + controlSocket=NULL; + } + if (stopSocket) { + delete stopSocket; + stopSocket=NULL; + } + } else + strcpy(thisName,thisDetector->hostname); + + if (control_port>0) { +#ifdef VERBOSE + std::cout<< "setting control port" << std::endl; +#endif + thisCP=control_port; + thisDetector->controlPort=thisCP; + if (controlSocket) { + delete controlSocket; + controlSocket=NULL; + } + } else + thisCP=thisDetector->controlPort; + + if (stop_port>0) { +#ifdef VERBOSE + std::cout<< "setting stop port" << std::endl; +#endif + thisSP=stop_port; + thisDetector->stopPort=thisSP; + if (stopSocket) { + delete stopSocket; + stopSocket=NULL; + } + } else + thisSP=thisDetector->stopPort; + + + if (!controlSocket) { + controlSocket= new MySocketTCP(thisName, thisCP); + if (controlSocket->getErrorStatus()){ +#ifdef VERBOSE + std::cout<< "Could not connect Control socket " << thisName << " " + << thisCP << std::endl; +#endif + delete controlSocket; + controlSocket=NULL; + retval=FAIL; + } +#ifdef VERYVERBOSE + else + std::cout<< "Control socket connected " <getErrorStatus()){ +#ifdef VERBOSE + std::cout<< "Could not connect Stop socket "<myDetectorType) { + case EIGER: + case JUNGFRAU: + case GOTTHARD: + if ((thisDetector->detectorControlAPIVersion == 0) || + (thisDetector->detectorStopAPIVersion == 0)) { + if (checkVersionCompatibility(CONTROL_PORT) == FAIL) + thisDetector->onlineFlag=OFFLINE_FLAG; + } + break; + default: + break; + } + } else { - if (t>=0) - thisDetector->timerValue[index]=t; - } + thisDetector->onlineFlag=OFFLINE_FLAG; #ifdef VERBOSE - std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; + std::cout<< "offline!" << std::endl; #endif - - if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { - setDynamicRange(); - //cout << "Changing probes: data size = " << thisDetector->dataBytes <myDetectorType==JUNGFRAUCTB) && (index==SAMPLES_JCTB)) { - setDynamicRange(); - cout << "Changing samples: data size = " << thisDetector->dataBytes <myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { - setDynamicRange(); - //cout << "Changing probes: data size = " << thisDetector->dataBytes <myDetectorType == EIGER) && - getRateCorrection(r) && - (t>=0) && - - (((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->dynamicRange == 32))|| - ((index == ACQUISITION_TIME) && (thisDetector->dynamicRange == 16))) - - && (t>=0) && getRateCorrection(r)){ - setRateCorrection(r); - } - } - - - - - //send acquisiton time/period/subexptime/frame/cycles/samples to receiver - if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)|| - (index==ACQUISITION_TIME) || (index==SUBFRAME_ACQUISITION_TIME) || - (index==SUBFRAME_PERIOD) || - (index==SAMPLES_JCTB) || (index==STORAGE_CELL_NUMBER)){ - string timername = getTimerType(index); - if(ret != FAIL){ - int64_t args[2]; - retval = -1; - args[0] = index; - args[1] = thisDetector->timerValue[index]; - - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ - - //set #frames * #cycles - if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)||(index==STORAGE_CELL_NUMBER)){ - timername.assign("(Number of Frames) * (Number of cycles) * (Number of storage cells)"); - args[1] = thisDetector->timerValue[FRAME_NUMBER] * - ((thisDetector->timerValue[CYCLES_NUMBER] > 0) ? (thisDetector->timerValue[CYCLES_NUMBER]) : 1) * - ((thisDetector->timerValue[STORAGE_CELL_NUMBER] > 0) ? (thisDetector->timerValue[STORAGE_CELL_NUMBER])+1 : 1); -#ifdef VERBOSE - std::cout << "Setting/Getting " << timername << " " << index <<" to/from receiver " << args[1] << std::endl; -#endif - } -#ifdef VERBOSE - // set period/exptime/subexptime/subperiod - else std::cout << "Setting/Getting " << timername << " " << index << " to/from receiver " << args[1] << std::endl; -#endif - - char mess[MAX_STR_LENGTH]=""; - if (connectData() == OK){ - ret=thisReceiver->sendIntArray(fnum2,retval,args,mess); - disconnectData(); - } - if((args[1] != retval)|| (ret==FAIL)){ - ret = FAIL; - cout << "ERROR: " << timername << " in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - - if(strstr(mess,"receiver is not idle")==NULL) { - switch(index) { - case ACQUISITION_TIME: - setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); - break; - case FRAME_PERIOD: - setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); - break; - case SUBFRAME_ACQUISITION_TIME: - case SUBFRAME_PERIOD: - case SAMPLES_JCTB: - setErrorMask((getErrorMask())|(RECEIVER_TIMER_NOT_SET)); - break; - default: - setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); - break; - } - } - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - } - } - return thisDetector->timerValue[index]; -}; - -int slsDetector::lockServer(int lock) { - int fnum=F_LOCK_SERVER; - int retval=-1; - int ret=OK; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&lock,sizeof(lock)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return retval; - - + return retval; } -string slsDetector::getLastClientIP() { - int fnum=F_GET_LAST_CLIENT_IP; - char clientName[INET_ADDRSTRLEN]; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - 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; - } else { - controlSocket->ReceiveDataOnly(clientName,sizeof(clientName)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return string(clientName); - -} - - -int slsDetector::setPort(portType index, int num){ +int slsDetector::setPort(portType index, int num) { int fnum=F_SET_PORT, fnum2 = F_SET_RECEIVER_PORT; int retval; @@ -4975,13 +1866,15 @@ int slsDetector::setPort(portType index, int num){ retval=thisDetector->controlPort; #ifdef VERBOSE cout << "s="<< s<< endl; - cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; + cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort + << endl; #endif if (s==NULL) { #ifdef VERBOSE cout << "s=NULL"<< endl; - cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; + cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort + << endl; #endif setTCPSocket("",DEFAULT_PORTNO); } @@ -4990,7 +1883,8 @@ int slsDetector::setPort(portType index, int num){ } else { #ifdef VERBOSE cout << "still cannot connect!"<< endl; - cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl; + cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort + << endl; #endif setTCPSocket("",retval); @@ -5075,13 +1969,13 @@ int slsDetector::setPort(portType index, int num){ } s->Disconnect(); }else{ - if (index == CONTROL_PORT){ - std::cout << "cannot connect to detector" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); - }else if (index == DATA_PORT){ - std::cout << "cannot connect to receiver" << endl; - setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); - } + if (index == CONTROL_PORT){ + std::cout << "cannot connect to detector" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_DETECTOR)); + }else if (index == DATA_PORT){ + std::cout << "cannot connect to receiver" << endl; + setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); + } } } } @@ -5157,1007 +2051,2839 @@ int slsDetector::setPort(portType index, int num){ #ifdef VERBOSE - cout << thisDetector->controlPort<< " " << thisDetector->receiverTCPPort << " " << thisDetector->stopPort << endl; + cout << thisDetector->controlPort<< " " << thisDetector->receiverTCPPort + << " " << thisDetector->stopPort << endl; #endif return retval; -}; +} - - - - - - - - - - - -//Naveen change - -int slsDetector::setTotalProgress() { - - int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1, ns=1; - - if (thisDetector->timerValue[FRAME_NUMBER]) - nf=thisDetector->timerValue[FRAME_NUMBER]; - - if (thisDetector->timerValue[CYCLES_NUMBER]>0) - nc=thisDetector->timerValue[CYCLES_NUMBER]; - - if (thisDetector->timerValue[STORAGE_CELL_NUMBER]>0) - ns=thisDetector->timerValue[STORAGE_CELL_NUMBER]+1; - - if (thisDetector->numberOfPositions>0) - npos=thisDetector->numberOfPositions; - - if (timerValue[MEASUREMENTS_NUMBER]>0) - nm=timerValue[MEASUREMENTS_NUMBER]; - - - if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & (1 << MAX_ACTIONS))) - nscan[0]=thisDetector->nScanSteps[0]; - - if ((thisDetector->nScanSteps[1]>0) && (thisDetector->actionMask & (1 << (MAX_ACTIONS+1)))) - nscan[1]=thisDetector->nScanSteps[1]; - - thisDetector->totalProgress=nf*nc*ns*npos*nm*nscan[0]*nscan[1]; - -#ifdef VERBOSE - cout << "nc " << nc << endl; - cout << "nm " << nm << endl; - cout << "nf " << nf << endl; - cout << "ns " << ns << endl; - cout << "npos " << npos << endl; - cout << "nscan[0] " << nscan[0] << endl; - cout << "nscan[1] " << nscan[1] << endl; - - cout << "Set total progress " << thisDetector->totalProgress << endl; -#endif - return thisDetector->totalProgress; +int slsDetector::getControlPort() { + return thisDetector->controlPort; +} +int slsDetector::getStopPort() { + return thisDetector->stopPort; +} +int slsDetector::getReceiverPort() { + return thisDetector->receiverTCPPort; } -double slsDetector::getCurrentProgress() { +int slsDetector::lockServer(int lock) { + int fnum=F_LOCK_SERVER; + int retval=-1; + int ret=OK; + char mess[MAX_STR_LENGTH]=""; - return 100.*((double)thisDetector->progressIndex)/((double)thisDetector->totalProgress); -} - - - - - - - - - - - - - - - -/* - important speed parameters - - enum speedVariable { - CLOCK_DIVIDER, - WAIT_STATES, - SET_SIGNAL_LENGTH - }; -*/ - -int slsDetector::setSpeed(speedVariable sp, int value) { - - - int fnum=F_SET_SPEED; - int retval=-1; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - -#ifdef VERBOSE - std::cout<< "Setting speed variable"<< sp << " to " << value << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&sp,sizeof(sp)); - controlSocket->SendDataOnly(&value,sizeof(value)); -#ifdef VERBOSE - std::cout<< "Sent "<< n << " bytes " << std::endl; -#endif - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_SET_SPEED_PARAMETERS)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } -#ifdef VERBOSE - std::cout<< "Speed set to "<< retval << std::endl; -#endif - return retval; - -} - - - - -int64_t slsDetector::getTimeLeft(timerIndex index){ - - - int fnum=F_GET_TIME_LEFT; - int64_t retval; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - -#ifdef VERBOSE - std::cout<< "Getting timer "<< index << std::endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (stopSocket) { - if (connectStop() == OK) { - stopSocket->SendDataOnly(&fnum,sizeof(fnum)); - stopSocket->SendDataOnly(&index,sizeof(index)); - stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - stopSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectStop(); - } - } - } -#ifdef VERBOSE - std::cout<< "Time left is "<< retval << std::endl; -#endif - return retval; - -}; - - -int slsDetector::setStoragecellStart(int pos) { - int ret=FAIL; - int fnum=F_STORAGE_CELL_START; - char mess[MAX_STR_LENGTH]; - memset(mess, 0, MAX_STR_LENGTH); - int retval=-1; - -#ifdef VERBOSE - std::cout<< "Sending storage cell start index " << pos << endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&pos,sizeof(pos)); - //check opening error - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(STORAGE_CELL_START)); - }else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return retval; -} - - - -// Flags -int slsDetector::setDynamicRange(int n){ - - // cout << "single " << endl; - int fnum=F_SET_DYNAMIC_RANGE,fnum2=F_SET_RECEIVER_DYNAMIC_RANGE; - int retval=-1,retval1; - char mess[MAX_STR_LENGTH]=""; - int ret=OK, rateret=OK; - -#ifdef VERBOSE - std::cout<< "Setting dynamic range to "<< n << std::endl; -#endif - if ((thisDetector->myDetectorType == MYTHEN) &&(n==24)) - n=32; - - - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&n,sizeof(n)); - //rate correction is switched off if not 32 bit mode - if(thisDetector->myDetectorType == EIGER){ - controlSocket->ReceiveDataOnly(&rateret,sizeof(rateret)); - if (rateret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - if(strstr(mess,"Rate Correction")!=NULL){ - if(strstr(mess,"32")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); - else - setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); - } - } - } - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else if(thisDetector->myDetectorType==MYTHEN){ - if (n>0) - thisDetector->dynamicRange=n; - retval=thisDetector->dynamicRange; - } - //cout << "detector returned dynamic range " << retval << endl; - if (ret!=FAIL && retval>0) { - /* checking the number of probes to chose the data size */ - - - - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*retval/8; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - retval/8; - if (thisDetector->myDetectorType==JUNGFRAUCTB) { - // thisDetector->nChip[X]=retval/16; - // thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y]; - // cout << thisDetector->nMod[X]*thisDetector->nMod[Y] << " " << thisDetector->nChans*thisDetector->nChips << " " << retval<< " "; - getTotalNumberOfChannels(); - //thisDetector->dataBytes=getTotalNumberOfChannels()*retval/8*thisDetector->timerValue[SAMPLES_JCTB]; - //cout << "data bytes: "<< thisDetector->dataBytes << endl; - } - if(thisDetector->myDetectorType==MYTHEN){ - if (thisDetector->timerValue[PROBES_NUMBER]!=0) { - thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; - thisDetector->dataBytesInclGapPixels = - (thisDetector->nMod[X] * thisDetector->nChip[X] * thisDetector->nChan[X] + thisDetector->gappixels * thisDetector->nGappixels[X]) * - (thisDetector->nMod[Y] * thisDetector->nChip[Y] * thisDetector->nChan[Y] + thisDetector->gappixels * thisDetector->nGappixels[Y]) * - 4; - } - - if (retval==32) - thisDetector->dynamicRange=24; - } - - thisDetector->dynamicRange=retval; - - -#ifdef VERBOSE - std::cout<< "Dynamic range set to "<< thisDetector->dynamicRange << std::endl; - std::cout<< "Data bytes "<< thisDetector->dataBytes << std::endl; -#endif - } - - - //receiver - if(ret != FAIL){ - retval = thisDetector->dynamicRange; - if((n==-1) && (ret!= FORCE_UPDATE)) n =-1; - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending/Getting dynamic range to/from receiver " << n << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum2,retval1,n); - disconnectData(); - } - if ((ret==FAIL) || (retval1 != retval)){ - ret = FAIL; - cout << "ERROR:Dynamic range in receiver set incorrectly to " << retval1 << " instead of " << retval << endl; - setErrorMask((getErrorMask())|(RECEIVER_DYNAMIC_RANGE)); - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - } - - return thisDetector->dynamicRange; -}; - - - - -int slsDetector::setROI(int n,ROI roiLimits[]){ - int ret = FAIL; - //sort ascending order - int temp; - - for(int i=0;ionlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&lock,sizeof(lock)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); } - // cout << "UUU ROI "<< i << " xmin " << roiLimits[i].xmin << " xmax "<< roiLimits[i].xmax << endl; } - ret = sendROI(n,roiLimits); - if(ret==FAIL) - setErrorMask((getErrorMask())|(COULDNOT_SET_ROI)); + return retval; - - if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + +} + + +string slsDetector::getLastClientIP() { + + int fnum=F_GET_LAST_CLIENT_IP; + char clientName[INET_ADDRSTRLEN]; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + 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; + } else { + controlSocket->ReceiveDataOnly(clientName,sizeof(clientName)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return string(clientName); + +} + + +int slsDetector::exitServer() { + + int retval; + int fnum=F_EXIT_SERVER; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + controlSocket->Connect(); + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + disconnectControl(); + } + } + if (retval!=OK) { + std::cout<< std::endl; + std::cout<< "Shutting down the server" << std::endl; + std::cout<< std::endl; + } + return retval; + +} + + +int slsDetector::execCommand(string cmd, string answer) { + + char arg[MAX_STR_LENGTH], retval[MAX_STR_LENGTH]; + int fnum=F_EXEC_COMMAND; + + int ret=FAIL; + + strcpy(arg,cmd.c_str()); + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Sending command " << arg << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + if (controlSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) { + if (controlSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0) { + if (controlSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH)>=0) { + ret=OK; + answer=retval; + } + } + } + disconnectControl(); + } +#ifdef VERBOSE + std::cout<< "Detector answer is " << answer << std::endl; +#endif + } return ret; } -slsDetectorDefs::ROI* slsDetector::getROI(int &n){ - sendROI(-1,NULL); - n=thisDetector->nROI; - if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); - return thisDetector->roiLimits; -} +int slsDetector::updateDetectorNoWait() { + enum readOutFlags ro; + // int ret=OK; + enum detectorSettings t; + int thr, n = 0, nm; + // int it; + int64_t retval;// tns=-1; + char lastClientIP[INET_ADDRSTRLEN]; -int slsDetector::sendROI(int n,ROI roiLimits[]){ - int ret=FAIL; - int fnum=F_SET_ROI; - char mess[MAX_STR_LENGTH]=""; - int arg = n; - int retvalsize=0; - ROI retval[MAX_ROIS]; - int nrec=-1; - if (roiLimits==NULL) - roiLimits=thisDetector->roiLimits; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - if(arg==-1){; + n += controlSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); #ifdef VERBOSE - cout << "Getting ROI from detector" << endl; + cout << "Updating detector last modified by " << lastClientIP << std::endl; #endif - }else{ -#ifdef VERBOSE - cout << "Sending ROI of size " << arg << " to detector" << endl; -#endif - controlSocket->SendDataOnly(roiLimits,arg*sizeof(ROI)); - } - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + n += controlSocket->ReceiveDataOnly(&nm,sizeof(nm)); + thisDetector->nMod[X]=nm; + n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); + /// Should be overcome at a certain point! - if (ret!=FAIL){ - controlSocket->ReceiveDataOnly(&retvalsize,sizeof(retvalsize)); - nrec = controlSocket->ReceiveDataOnly(retval,retvalsize*sizeof(ROI)); - if(nrec!=(retvalsize*(int)sizeof(ROI))){ - ret=FAIL; - std::cout << " wrong size received: received " << nrec << "but expected " << retvalsize*sizeof(ROI) << endl; + if (thisDetector->myDetectorType==MYTHEN) { + thisDetector->nModMax[X]=nm; + thisDetector->nModMax[Y]=1; + thisDetector->nModsMax=thisDetector->nModMax[Y]*thisDetector->nModMax[X]; + thisDetector->nMod[Y]=1; + } else { + thisDetector->nMod[Y]=nm; } - }else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - //update client - if(ret!=FAIL){ - for(int i=0;iroiLimits[i]=retval[i]; - thisDetector->nROI = retvalsize; - } + thisDetector->nMods=thisDetector->nMod[Y]*thisDetector->nMod[X]; + if (thisDetector->nModsMaxnMods) + thisDetector->nModsMax=thisDetector->nMods; - //#ifdef VERBOSE - for(int j=0;jnROI;++j) - cout<<"get"<< roiLimits[j].xmin<<"\t"<nModMax[X]nMod[X]) + thisDetector->nModMax[X]=thisDetector->nMod[X]; - return ret; -} + if (thisDetector->nModMax[Y]nMod[Y]) + thisDetector->nModMax[Y]=thisDetector->nMod[Y]; + n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); + thisDetector->dynamicRange=nm; + n += controlSocket->ReceiveDataOnly( &nm,sizeof(nm)); + thisDetector->dataBytes=nm; + //t=setSettings(GET_SETTINGS); + n += controlSocket->ReceiveDataOnly( &t,sizeof(t)); + thisDetector->currentSettings=t; - -int slsDetector::setReadOutFlags(readOutFlags flag){ - - - int fnum=F_SET_READOUT_FLAGS; - readOutFlags retval; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - -#ifdef VERBOSE - std::cout<< "Setting readout flags to "<< flag << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&flag,sizeof(flag)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_SET_READOUT_FLAGS)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->roFlags=retval; - if (thisDetector->myDetectorType==JUNGFRAUCTB) { - - getTotalNumberOfChannels(); - //thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + if((thisDetector->myDetectorType == EIGER) || + (thisDetector->myDetectorType == MYTHEN)){ + //thr=getThresholdEnergy(); + n += controlSocket->ReceiveDataOnly( &thr,sizeof(thr)); + thisDetector->currentThresholdEV=thr; } - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } else { - if (flag!=GET_READOUT_FLAGS) - thisDetector->roFlags=flag; - } -#ifdef VERBOSE - std::cout<< "Readout flag set to "<< retval << std::endl; -#endif - return thisDetector->roFlags; -}; + //retval=setFrames(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[FRAME_NUMBER]=retval; -//Trimming -/* - enum trimMode { - NOISE_TRIMMING, - BEAM_TRIMMING, - IMPROVE_TRIMMING, - FIXEDSETTINGS_TRIMMING, - OFFLINE_TRIMMING - }{}; -*/ -int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){ + // retval=setExposureTime(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[ACQUISITION_TIME]=retval; - int fnum= F_EXECUTE_TRIMMING; - int retval=FAIL; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - int arg[3]; - arg[0]=imod; - arg[1]=par1; - arg[2]=par2; + if(thisDetector->myDetectorType == EIGER){ + //retval=setSubFrameExposureTime(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]=retval; - -#ifdef VERBOSE - std::cout<< "Trimming module " << imod << " with mode "<< mode << " parameters " << par1 << " " << par2 << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); -#ifdef VERBOSE - std::cout<< "sending mode bytes= "<< controlSocket->SendDataOnly(&mode,sizeof(mode)) << std::endl; -#endif - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { -#ifdef VERBOSE - std::cout<< "Detector trimmed "<< ret << std::endl; -#endif - /* - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - thisDetector->roFlags=retval; - */ - retval=ret; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return retval; - -}; - - - -//Correction -/* - enum correctionFlags { - DISCARD_BAD_CHANNELS, - AVERAGE_NEIGHBOURS_FOR_BAD_CHANNELS, - FLAT_FIELD_CORRECTION, - RATE_CORRECTION, - ANGULAR_CONVERSION - } -*/ - -int slsDetector::setFlatFieldCorrection(string fname) - -{ - double data[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; - //double err[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; - //double xmed[thisDetector->nModMax[X]*thisDetector->nModMax[Y]*thisDetector->nChans*thisDetector->nChips]; - // int nmed=0; - int im=0; - int nch; - thisDetector->nBadFF=0; - - char ffffname[MAX_STR_LENGTH*2]; - if (fname=="default") { - fname=string(thisDetector->flatFieldFile); - } - - if (fname=="") { -#ifdef VERBOSE - std::cout<< "disabling flat field correction" << std::endl; -#endif - thisDetector->correctionMask&=~(1<flatFieldDir,fname.c_str()); - nch=readDataFile(string(ffffname),data); - if (nch>0) { - - //???? bad ff chans? - int nm=getNMods(); - int chpm[nm]; - int mMask[nm]; - for (int i=0; i=0) { - strcpy(thisDetector->flatFieldFile,fname.c_str()); - - - thisDetector->correctionMask|=(1<correctionMask&(1<nMod[Y]*thisDetector->nMod[X]*thisDetector->nChans*thisDetector->nChips; ++ichan) { - // #ifdef VERBOSE - // std::cout<< ichan << " "<< corr[ichan] << std::endl; - // #endif - ffcoefficients[ichan]=corr[ichan]; - if (ecorr!=NULL) - fferrors[ichan]=ecorr[ichan]; - else - fferrors[ichan]=1; - - cout << ichan << " " << ffcoefficients[ichan] << endl; - } - thisDetector->correctionMask|=(1<correctionMask&=~(1<correctionMask)&(1<correctionMask&(1<correctionMask&(1<nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ++ichan) { - // corr[ichan]=(ffcoefficients[ichan]*ffcoefficients[ichan])/(fferrors[ichan]*fferrors[ichan]); - corr[ichan]=ffcoefficients[ichan]; - if (ecorr) { - //ecorr[ichan]=ffcoefficients[ichan]/fferrors[ichan]; - ecorr[ichan]=fferrors[ichan]; + //retval=setSubFramePeriod(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[SUBFRAME_PERIOD]=retval; } - } - } - return 1; - } else { -#ifdef VERBOSE - std::cout<< "Flat field correction is disabled" << std::endl; -#endif - if (corr) - for (int ichan=0; ichannMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ++ichan) { - corr[ichan]=1; - if (ecorr) - ecorr[ichan]=0; - } - return 0; - } + + //retval=setPeriod(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[FRAME_PERIOD]=retval; + + if(thisDetector->myDetectorType != EIGER) { + //retval=setDelay(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[DELAY_AFTER_TRIGGER]=retval; + } + + // retval=setGates(tns); + if ((thisDetector->myDetectorType != JUNGFRAU) && + (thisDetector->myDetectorType != EIGER)){ + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[GATES_NUMBER]=retval; + } + + //retval=setProbes(tns); + if (thisDetector->myDetectorType == MYTHEN){ + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[PROBES_NUMBER]=retval; + } + + //retval=setTrains(tns); + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + thisDetector->timerValue[CYCLES_NUMBER]=retval; + + //retval=setProbes(tns); + if (thisDetector->myDetectorType == JUNGFRAUCTB){ + n += controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); + if (retval>=0) + thisDetector->timerValue[SAMPLES_JCTB]=retval; + n += controlSocket->ReceiveDataOnly( &ro,sizeof(ro)); + + thisDetector->roFlags=ro; + + //retval=setProbes(tns); + getTotalNumberOfChannels(); + // thisDetector->dataBytes=getTotalNumberOfChannels()* + //thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + } + + + if (!n) + printf("n: %d\n", n); + + return OK; } -int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout, double *errout){ + + +int slsDetector::updateDetector() { + int fnum=F_UPDATE_CLIENT; + int ret=OK; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + 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; + } else + updateDetectorNoWait(); + disconnectControl(); + } + } + return ret; +} + + +int slsDetector::readConfigurationFile(string const fname) { + + + + string ans; + string str; + ifstream infile; + //char *args[1000]; + + string sargname, sargval; #ifdef VERBOSE - std::cout<< "Flat field correcting data" << std::endl; + int iline=0; + std::cout<< "config file name "<< fname << std::endl; #endif - double e, eo; - if (thisDetector->correctionMask & (1<nMod[X]*thisDetector->nChans*thisDetector->nChips; ++ichan) { - if (errin==NULL) { - e=0; - } else { - e=errin[ichan]; - } - postProcessingFuncs::flatFieldCorrect(datain[ichan],e,dataout[ichan],eo,ffcoefficients[ichan],fferrors[ichan]); - if (errout) - errout[ichan]=eo; - // #ifdef VERBOSE - // cout << ichan << " " <> sargname; + //if (ssstr.good()) { +#ifdef VERBOSE + std::cout<< iargval << " " << sargname << std::endl; +#endif + strcpy(myargs[iargval],sargname.c_str()); + args[iargval]=myargs[iargval]; + ++iargval; + //} + } + ans=cmd->executeLine(iargval,args,PUT_ACTION); +#ifdef VERBOSE + std::cout<< ans << std::endl; +#endif + } + ++iline; + } + delete cmd; + return OK; + +} + + + + + + + + + + +int slsDetector::writeConfigurationFile(string const fname) { + + ofstream outfile; +#ifdef VERBOSE + int ret; +#endif + outfile.open(fname.c_str(),ios_base::out); + if (outfile.is_open()) { +#ifdef VERBOSE + ret=writeConfigurationFile(outfile); +#else + writeConfigurationFile(outfile); +#endif + outfile.close(); + } + else { + std::cout<< "Error opening configuration file " << fname << + " for writing" << std::endl; + setErrorMask((getErrorMask())|(CONFIG_FILE)); + return FAIL; + } +#ifdef VERBOSE + std::cout<< "wrote " <myDetectorType; + string names[100]; + int nvar=0; + + // common config + names[nvar++] = "hostname"; + names[nvar++] = "port"; + names[nvar++] = "stopport"; + names[nvar++] = "settingsdir"; + names[nvar++] = "caldir"; + names[nvar++] = "ffdir"; + names[nvar++] = "outdir"; + names[nvar++] = "angdir"; + names[nvar++] = "moveflag"; + names[nvar++] = "lock"; + + // receiver config + if (type != MYTHEN) { + names[nvar++] = "detectormac"; + names[nvar++] = "detectorip"; + names[nvar++] = "zmqport"; + names[nvar++] = "rx_zmqport"; + names[nvar++] = "zmqip"; + names[nvar++] = "rx_zmqip"; + names[nvar++] = "rx_tcpport"; + names[nvar++] = "rx_udpport"; + names[nvar++] = "rx_udpport2"; + names[nvar++] = "rx_udpip"; + names[nvar++] = "rx_hostname"; + names[nvar++] = "r_readfreq"; + } + + // detector specific config + switch (type) { + case MYTHEN: + names[nvar++] = "nmod"; + names[nvar++] = "waitstates"; + names[nvar++] = "setlength"; + names[nvar++] = "clkdivider"; + names[nvar++] = "extsig"; + break; + case GOTTHARD: + case PROPIX: + names[nvar++] = "extsig"; + names[nvar++] = "vhighvoltage"; + break; + break; + case MOENCH: + names[nvar++] = "extsig"; + names[nvar++] = "vhighvoltage"; + break; + case EIGER: + names[nvar++] = "vhighvoltage"; + names[nvar++] = "trimen"; + names[nvar++] = "iodelay"; + names[nvar++] = "tengiga"; + break; + case JUNGFRAU: + names[nvar++] = "powerchip"; + names[nvar++] = "vhighvoltage"; + break; + case JUNGFRAUCTB: + names[nvar++] = "powerchip"; + names[nvar++] = "vhighvoltage"; + break; + default: + std::cout << "detector type " << + getDetectorType(thisDetector->myDetectorType) << " not implemented in " + "writing config file" << std::endl; + nvar = 0; + break; + } + + +f + int nsig=4;//-1; + int iv=0; + char *args[100]; + char myargs[100][1000]; + + for (int ia=0; ia<100; ++ia) { + args[ia]=myargs[ia]; + } + + + for (iv=0; iv=0) + outfile << id << ":"; + + outfile << args[0] << " " << cmd->executeLine(1,args,GET_ACTION) + << std::endl; + } + } else { + strcpy(args[0],names[iv].c_str()); + if (id>=0) + outfile << id << ":"; + outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) + << std::endl; + } + } + + delete cmd; + return OK; +} + + + +string slsDetector::getSettingsFile() { + string s(thisDetector->settingsFile); + if (s.length()>6) { + if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) + return s.substr(0,s.length()-6); + } + return string(thisDetector->settingsFile); +} + + +int slsDetector::writeSettingsFile(string fname, int imod, int iodelay, int tau) { + + return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], + iodelay, tau); + +} + +slsDetectorDefs::detectorSettings slsDetector::getSettings(int imod) { + + return sendSettingsOnly(GET_SETTINGS, imod); +} + + +slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings isettings, + int imod) { +#ifdef VERBOSE + std::cout<< "slsDetector setSettings " << isettings << std::endl; +#endif + + detectorType detType = thisDetector->myDetectorType; + switch (detType) { + + // eiger: only set client shared memory variable for Eiger, + // settings threshold loads the module data (trimbits, dacs etc.) + case EIGER: + switch(isettings) { + case STANDARD: + case HIGHGAIN: + case LOWGAIN: + case VERYHIGHGAIN: + case VERYLOWGAIN: + thisDetector->currentSettings = isettings; + break; + default: + printf("Unknown settings %s for this detector!\n", + getDetectorSettings(isettings).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + break; + } + return thisDetector->currentSettings; + + // send only the settings, detector server will update dac values already in server + case GOTTHARD: + case PROPIX: + case JUNGFRAU: + case MOENCH: + return sendSettingsOnly(isettings); + break; + + // others send whole module to detector + default: + break; + } + + + + // MYTHEN ONLY (sends whole detector to module) + + sls_detector_module *myMod=createModule(); + int modmi=imod, modma=imod+1, im=imod; + string settingsfname, calfname; + string ssettings; + + //not included in module structure + int iodelay = -1; + int tau = -1; + int* gainval=0, *offsetval=0; + if(thisDetector->nGain) + gainval=new int[thisDetector->nGain]; + if(thisDetector->nOffset) + offsetval=new int[thisDetector->nOffset]; + + + switch (isettings) { + case STANDARD: + ssettings="/standard"; + thisDetector->currentSettings=STANDARD; + break; + case FAST: + ssettings="/fast"; + thisDetector->currentSettings=FAST; + break; + case HIGHGAIN: + ssettings="/highgain"; + thisDetector->currentSettings=HIGHGAIN; + break; + default: + break; + } + + + if (isettings != thisDetector->currentSettings) { + printf("Unknown settings %s for this detector!\n", + getDetectorSettings(isettings).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + }else{ + if (imod<0) { + modmi=0; + // modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y]; + modma=thisDetector->nMod[X]*thisDetector->nMod[Y]; + } + + for (im=modmi; immodule=im; + + std::cout << std::endl << "Loading settings for module:" << im << std::endl; + + //create file names + ostfn << thisDetector->settingsDir << ssettings <<"/noise.sn" + << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) + << setbase(10); + oscfn << thisDetector->calDir << ssettings << "/calibration.sn" + << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) + << setbase(10); + + + //settings file**** + settingsfname=ostfn.str(); +#ifdef VERBOSE + cout << "the settings file name is "<settingsDir << ssettings + << ssettings << ".trim"; + settingsfname=ostfn_default.str(); +#ifdef VERBOSE + cout << settingsfname << endl; +#endif + if (NULL == readSettingsFile(settingsfname,detType, iodelay, tau, + myMod)) { + //if default doesnt work, return error + std::cout << "Could not open settings file" << endl; + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + return thisDetector->currentSettings; + } + } + + + + //calibration file**** + int ret=0; + calfname=oscfn.str(); +#ifdef VERBOSE + cout << "Specific file:"<< calfname << endl; +#endif + //extra gain and offset + if(thisDetector->nGain) + ret = readCalibrationFile(calfname,gainval, offsetval); + //normal gain and offset inside sls_detector_module + else + ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); + + //if it didnt open, try default + if(ret != OK){ + ostringstream oscfn_default; + oscfn_default << thisDetector->calDir << ssettings << ssettings << ".cal"; + calfname=oscfn_default.str(); +#ifdef VERBOSE + cout << "Default file:" << calfname << endl; +#endif + //extra gain and offset + if(thisDetector->nGain) + ret = readCalibrationFile(calfname,gainval, offsetval); + //normal gain and offset inside sls_detector_module + else + ret = readCalibrationFile(calfname,myMod->gain, myMod->offset); + } + //if default doesnt work, return error + if(ret != OK){ + std::cout << "Could not open calibration file" << calfname << endl; + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + return thisDetector->currentSettings; + } + + + //if everything worked, set module**** + setModule(*myMod,iodelay,tau,-1,gainval,offsetval); + } + } + + + + deleteModule(myMod); + if(gainval) delete [] gainval; + if(offsetval) delete [] offsetval; + + if (thisDetector->correctionMask&(1<-1 && isett<3) { + thisDetector->tDead=t[isett]; + } + } + + + if (getSettings(imod) != isettings){ + std::cout << "Could not set settings" << endl; + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + } + + return thisDetector->currentSettings; +} + + + +slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings isettings, + int imod) { + int fnum = F_SET_SETTINGS; + int ret = FAIL; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); + int retval = -1; + int arg[2]; + arg[0] = isettings; + arg[1] = imod; +#ifdef VERBOSE + std::cout<< "Setting settings of module " << arg[1] << " to " << arg[0] << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + } else{ + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentSettings = (detectorSettings)retval; +#ifdef VERBOSE + std::cout<< "Settings are " << retval << std::endl; +#endif + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return thisDetector->currentSettings; +} + + + +int slsDetector::getThresholdEnergy(int imod) { + + int fnum= F_GET_THRESHOLD_ENERGY; + int retval; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; +#ifdef VERBOSE + std::cout<< "Getting threshold energy "<< std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&imod,sizeof(imod)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + std::cout<< "Detector returned error: "<< std::endl; + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentThresholdEV=retval; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return thisDetector->currentThresholdEV; +} + +int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isettings, int tb) { + + //currently only for eiger + if (thisDetector->myDetectorType == EIGER) { + setThresholdEnergyAndSettings(e_eV,isettings,tb); + return thisDetector->currentThresholdEV; + } + + int fnum= F_SET_THRESHOLD_ENERGY; + int retval; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; +#ifdef VERBOSE + std::cout<< "Setting threshold energy "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); + controlSocket->SendDataOnly(&imod,sizeof(imod)); + controlSocket->SendDataOnly(&isettings,sizeof(isettings)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + std::cout<< "Detector returned error: "<< std::endl; + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< mess << std::endl; + } else { +#ifdef VERBOSE + std::cout<< "Detector returned OK "<< std::endl; +#endif + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->currentThresholdEV=retval; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + thisDetector->currentThresholdEV=e_eV; + } + return thisDetector->currentThresholdEV; +} + + + +int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb) { + + //if settings provided, use that, else use the shared memory variable + detectorSettings is = ((isettings != GET_SETTINGS) ? isettings: + thisDetector->currentSettings); + string ssettings; + switch (is) { + case STANDARD: + ssettings="/standard"; + thisDetector->currentSettings=STANDARD; + break; + case HIGHGAIN: + ssettings="/highgain"; + thisDetector->currentSettings=HIGHGAIN; + break; + case LOWGAIN: + ssettings="/lowgain"; + thisDetector->currentSettings=LOWGAIN; + break; + case VERYHIGHGAIN: + ssettings="/veryhighgain"; + thisDetector->currentSettings=VERYHIGHGAIN; + break; + case VERYLOWGAIN: + ssettings="/verylowgain"; + thisDetector->currentSettings=VERYLOWGAIN; + break; + default: + printf("Error: Unknown settings %s for this detector!\n", + getDetectorSettings(is).c_str()); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + //verify e_eV exists in trimEneregies[] + if (!thisDetector->nTrimEn || + (e_eV < thisDetector->trimEnergies[0]) || + (e_eV > thisDetector->trimEnergies[thisDetector->nTrimEn-1]) ) { + printf("Error: This energy %d not defined for this module!\n", e_eV); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + //find if interpolation required + bool interpolate = true; + for (int i = 0; i < thisDetector->nTrimEn; ++i) { + if (thisDetector->trimEnergies[i] == e_eV) { + interpolate = false; + break; + } + } + + //fill detector module structure + sls_detector_module *myMod = NULL; + int iodelay = -1; //not included in the module + int tau = -1; //not included in the module + + //normal + if(!interpolate) { + //find their directory names + ostringstream ostfn; + ostfn << thisDetector->settingsDir << ssettings << "/" << e_eV << "eV" + << "/noise.sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname = ostfn.str(); +#ifdef VERBOSE + printf("Settings File is %s\n", settingsfname.c_str()); +#endif + //read the files + myMod=createModule(); + if (NULL == readSettingsFile(settingsfname,thisDetector->myDetectorType, + iodelay, tau, myMod, tb)) { + if(myMod)deleteModule(myMod); + return FAIL; + } + } + + + //interpolate + else { + //find the trim values + int trim1 = -1, trim2 = -1; + for (int i = 0; i < thisDetector->nTrimEn; ++i) { + if (e_eV < thisDetector->trimEnergies[i]) { + trim2 = thisDetector->trimEnergies[i]; + trim1 = thisDetector->trimEnergies[i-1]; + break; + } + } + //find their directory names + ostringstream ostfn; + ostfn << thisDetector->settingsDir << ssettings << "/" << trim1 << "eV" + << "/noise.sn" << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname1 = ostfn.str(); + ostfn.str(""); ostfn.clear(); + ostfn << thisDetector->settingsDir << ssettings << "/" << trim2 << "eV" + << "/noise.sn" << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER) << setbase(10); + string settingsfname2 = ostfn.str(); + //read the files +#ifdef VERBOSE + printf("Settings Files are %s and %s\n",settingsfname1.c_str(), + settingsfname2.c_str()); +#endif + sls_detector_module *myMod1=createModule(); + sls_detector_module *myMod2=createModule(); + int iodelay1 = -1; //not included in the module + int tau1 = -1; //not included in the module + int iodelay2 = -1; //not included in the module + int tau2 = -1; //not included in the module + if (NULL == readSettingsFile(settingsfname1,thisDetector->myDetectorType, + iodelay1, tau1, myMod1, tb)) { + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + if (NULL == readSettingsFile(settingsfname2,thisDetector->myDetectorType, + iodelay2, tau2, myMod2, tb)) { + setErrorMask((getErrorMask())|(SETTINGS_FILE_NOT_OPEN)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + if (iodelay1 != iodelay2) { + printf("iodelays do not match between files\n"); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + iodelay = iodelay1; + + //interpolate module + myMod = interpolateTrim(thisDetector->myDetectorType, myMod1, myMod2, + e_eV, trim1, trim2, tb); + if (myMod == NULL) { + printf("Could not interpolate, different dac values in files\n"); + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + deleteModule(myMod1); + deleteModule(myMod2); + return FAIL; + } + //interpolate tau + tau = linearInterpolation(e_eV, trim1, trim2, tau1, tau2); + //printf("new tau:%d\n",tau); + + deleteModule(myMod1); + deleteModule(myMod2); + } + + + myMod->module=0; + myMod->reg=thisDetector->currentSettings; + setModule(*myMod, iodelay, tau, e_eV, 0, 0, tb); + deleteModule(myMod); + if (getSettings(-1) != is){ + std::cout << "Could not set settings in detector" << endl; + setErrorMask((getErrorMask())|(SETTINGS_NOT_SET)); + return FAIL; + } + + return OK; +} + + + + +string slsDetector::getSettingsDir() { + return std::string(thisDetector->settingsDir); +} +string slsDetector::setSettingsDir(string s) { + sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir; +} +string slsDetector::getCalDir() { + return thisDetector->calDir; +} +string slsDetector::setCalDir(string s) { + sprintf(thisDetector->calDir, s.c_str()); return thisDetector->calDir; +} + + + + + +int slsDetector::loadSettingsFile(string fname, int imod) { + + sls_detector_module *myMod=NULL; + + int iodelay = -1; + int tau = -1; + + string fn=fname; + fn=fname; + int mmin=0, mmax=setNumberOfModules(); + if (imod>=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; immyDetectorType) { + case MYTHEN: + if (fname.find(".sn")==string::npos && fname.find(".trim")== + string::npos && fname.find(".settings")==string::npos) { + ostfn << ".sn" << setfill('0') << setw(3) << hex << + getId(MODULE_SERIAL_NUMBER, im); + } + break; + case EIGER: + if (fname.find(".sn")==string::npos && fname.find(".trim")== + string::npos && fname.find(".settings")==string::npos) { + ostfn << ".sn" << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER, im); + } + break; + default: + break; + } + fn=ostfn.str(); + myMod=readSettingsFile(fn, thisDetector->myDetectorType,iodelay, tau, myMod); + + if (myMod) { + myMod->module=im; + //settings is saved in myMod.reg for all except mythen + if(thisDetector->myDetectorType!=MYTHEN) + myMod->reg=-1; + setModule(*myMod,iodelay,tau,-1,0,0); + deleteModule(myMod); + } else + return FAIL; + } + return OK; +} + + +int slsDetector::saveSettingsFile(string fname, int imod) { + + sls_detector_module *myMod=NULL; + int ret=FAIL; + int iodelay = -1; + int tau = -1; + + int mmin=0, mmax=setNumberOfModules(); + if (imod>=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; immyDetectorType) { + case MYTHEN: + ostfn << ".sn" << setfill('0') << setw(3) << hex << + getId(MODULE_SERIAL_NUMBER,im); + break; + case EIGER: + ostfn << ".sn" << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER); + break; + default: + break; + } + fn=ostfn.str(); + if ((myMod=getModule(im))) { + + if(thisDetector->myDetectorType == EIGER){ + iodelay = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1); + tau = (int64_t)getRateCorrectionTau(); + } + ret=writeSettingsFile(fn, thisDetector->myDetectorType, *myMod, + iodelay, tau); + deleteModule(myMod); + } + } + return ret; +} + + + + +int slsDetector::loadCalibrationFile(string fname, int imod) { + + if(thisDetector->myDetectorType == EIGER) { + std::cout << "Not required for this detector!" << std::endl; + return FAIL; + } + + sls_detector_module *myMod=NULL; + string fn=fname; + + int* gainval=0; int* offsetval=0; + if(thisDetector->nGain){ + gainval=new int[thisDetector->nGain]; + for(int i=0;inGain;++i) + gainval[i] = -1; + } + if(thisDetector->nOffset){ + offsetval=new int[thisDetector->nOffset]; + for(int i=0;inOffset;++i) + offsetval[i] = -1; + } + + fn=fname; + + + int mmin=0, mmax=setNumberOfModules(); + if (imod>=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; immyDetectorType) { + case MYTHEN: + if (fname.find(".sn")==string::npos && fname.find(".cal")==string::npos) { + ostfn << ".sn" << setfill('0') << setw(3) << hex << + getId(MODULE_SERIAL_NUMBER, im); + } + break; + case EIGER: + if (fname.find(".sn")==string::npos && fname.find(".cal")==string::npos) { + ostfn << "." << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER); + } + break; + default: + break; + } + fn=ostfn.str(); + if((myMod=getModule(im))){ + //extra gain and offset + if(thisDetector->nGain){ + if(readCalibrationFile(fn, gainval, offsetval)==FAIL) + return FAIL; + } //normal gain and offset inside sls_detector_module + else{ + if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL) + return FAIL; + } + setModule(*myMod,-1,-1,-1,gainval,offsetval); + + deleteModule(myMod); + if(gainval) delete[]gainval; + if(offsetval) delete[] offsetval; + } else + return FAIL; + } + return OK; +} + + +int slsDetector::saveCalibrationFile(string fname, int imod) { + + + sls_detector_module *myMod=NULL; + int ret=FAIL; + + int mmin=0, mmax=setNumberOfModules(); + if (imod>=0) { + mmin=imod; + mmax=imod+1; + } + for (int im=mmin; immyDetectorType) { + case MYTHEN: + ostfn << ".sn" << setfill('0') << setw(3) << hex << + getId(MODULE_SERIAL_NUMBER,im); + break; + case EIGER: + ostfn << ".sn" << setfill('0') << setw(3) << dec << + getId(DETECTOR_SERIAL_NUMBER); + break; + default: + break; + } + fn=ostfn.str(); + if ((myMod=getModule(im))) { + //extra gain and offset + if(thisDetector->nGain) + ret=writeCalibrationFile(fn,gain, offset); + //normal gain and offset inside sls_detector_module + else + ret=writeCalibrationFile(fn,myMod->gain, myMod->offset); + + deleteModule(myMod); + }else + return FAIL; + } + return ret; +} + + + + +slsDetectorDefs::masterFlags slsDetector::setMaster(masterFlags flag) { + + + int fnum=F_SET_MASTER; + masterFlags retval=GET_MASTER; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; #ifdef VERBOSE - std::cout<< "Setting Rate Correction to " << arg << endl; + std::cout<< "Setting master flags to "<< flag << std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&flag,sizeof(flag)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + +#ifdef VERBOSE + std::cout<< "Master flag set to "<< retval << std::endl; +#endif + return retval; +} + + + + +slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchronizationMode flag) { + + + + int fnum=F_SET_SYNCHRONIZATION_MODE; + synchronizationMode retval=GET_SYNCHRONIZATION_MODE; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + +#ifdef VERBOSE + std::cout<< "Setting synchronization mode to "<< flag << std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&flag,sizeof(flag)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + +#ifdef VERBOSE + std::cout<< "Readout flag set to "<< retval << std::endl; +#endif + return retval; + +} + + +int slsDetector::setTotalProgress() { + + int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1, ns=1; + + if (thisDetector->timerValue[FRAME_NUMBER]) + nf=thisDetector->timerValue[FRAME_NUMBER]; + + if (thisDetector->timerValue[CYCLES_NUMBER]>0) + nc=thisDetector->timerValue[CYCLES_NUMBER]; + + if (thisDetector->timerValue[STORAGE_CELL_NUMBER]>0) + ns=thisDetector->timerValue[STORAGE_CELL_NUMBER]+1; + + if (thisDetector->numberOfPositions>0) + npos=thisDetector->numberOfPositions; + + if (timerValue[MEASUREMENTS_NUMBER]>0) + nm=timerValue[MEASUREMENTS_NUMBER]; + + + if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & + (1 << MAX_ACTIONS))) + nscan[0]=thisDetector->nScanSteps[0]; + + if ((thisDetector->nScanSteps[1]>0) && (thisDetector->actionMask & + (1 << (MAX_ACTIONS+1)))) + nscan[1]=thisDetector->nScanSteps[1]; + + thisDetector->totalProgress=nf*nc*ns*npos*nm*nscan[0]*nscan[1]; + +#ifdef VERBOSE +cout << "nc " << nc << endl; +cout << "nm " << nm << endl; +cout << "nf " << nf << endl; +cout << "ns " << ns << endl; +cout << "npos " << npos << endl; +cout << "nscan[0] " << nscan[0] << endl; +cout << "nscan[1] " << nscan[1] << endl; + +cout << "Set total progress " << thisDetector->totalProgress << endl; +#endif +return thisDetector->totalProgress; +} + +double slsDetector::getCurrentProgress() { + + return 100.*((double)thisDetector->progressIndex)/((double)thisDetector->totalProgress); +} + + + +slsDetectorDefs::runStatus slsDetector::getRunStatus() { + int fnum=F_GET_RUN_STATUS; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + strcpy(mess,"could not get run status"); + runStatus retval=ERROR; +#ifdef VERBOSE + std::cout<< "Getting status "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (stopSocket) { + if (connectStop() == OK) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + + //cout << "________:::____________" << ret << endl; + + if (ret==FAIL) { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + //cout << "____________________" << retval << endl; + } + disconnectStop(); + } + } + } + return retval; + + +} + + +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() { + + + int fnum=F_START_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<< "Starting acquisition "<< std::endl; +#endif + thisDetector->stoppedFlag=0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + 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(); + } + } + return ret; + + + +} + + +int slsDetector::stopAcquisition() { + + // get status before stopping acquisition + runStatus s = ERROR, r = ERROR; + if (thisDetector->receiver_upstream) { + s = getRunStatus(); + r = getReceiverStatus(); + } + + int fnum=F_STOP_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<< "Stopping acquisition "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (stopSocket) { + if (connectStop() == OK) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectStop(); + } + } + } + thisDetector->stoppedFlag=1; + + // if rxr streaming and acquisition finished, restream dummy stop packet + if ((thisDetector->receiver_upstream) && (s == IDLE) && (r == IDLE)) { + restreamStopFromReceiver(); + } + + return ret; + + +} + +int slsDetector::startReadOut() { + + int fnum=F_START_READOUT; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<< "Starting readout "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + 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(); + } + } + return ret; +} + + + +int* slsDetector::startAndReadAll() { + //cout << "Start and read all "<< endl; + + int* retval; + //#ifdef VERBOSE +#ifdef VERBOSE + int i=0; +#endif + //#endif + if(thisDetector->myDetectorType == EIGER) { + if (prepareAcquisition() == FAIL) + return NULL; + } + startAndReadAllNoWait(); + //#ifdef VERBOSE + // std::cout<< "started" << std::endl; + //#endif + while ((retval=getDataFromDetector())){ +#ifdef VERBOSE + ++i; + std::cout<< i << std::endl; + //#else + //std::cout<< "-" << flush; +#endif + dataQueue.push(retval); + + //std::cout<< "pushed" << std::endl; + } + disconnectControl(); + +#ifdef VERBOSE + std::cout<< "received "<< i<< " frames" << std::endl; + //#else + // std::cout << std::endl; +#endif + return dataQueue.front(); // check what we return! + /* while ((retval=getDataFromDetectorNoWait())) + ++i; + #ifdef VERBOSE + std::cout<< "Received " << i << " frames"<< std::endl; + #endif + return dataQueue.front(); // check what we return! + */ + +} + + + +int slsDetector::startAndReadAllNoWait() { + + int fnum= F_START_AND_READ_ALL; + +#ifdef VERBOSE + std::cout<< "Starting and reading all frames "<< std::endl; +#endif + thisDetector->stoppedFlag=0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + //std::cout<< "connected" << std::endl; + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + return OK; + } + } + return FAIL; +} + + + + +int* slsDetector::getDataFromDetector(int *retval) { + int ret=FAIL; + char mess[MAX_STR_LENGTH]="Nothing"; + int nel=thisDetector->dataBytes/sizeof(int); + int n; + int *r=retval; + + int nodatadetectortype = false; + detectorType types = getDetectorsType(); + if(types == EIGER || types == JUNGFRAU){ + nodatadetectortype = true; + } + + + if (!nodatadetectortype && retval==NULL) + retval=new int[nel]; + + +#ifdef VERBOSE + std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl; +#endif + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); +#ifdef VERBOSE + cout << "ret=" << ret << endl; +#endif + + if (ret!=OK) { + n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + // if(thisDetector->receiverOnlineFlag == OFFLINE_FLAG) + if (ret==FAIL) { + thisDetector->stoppedFlag=1; + std::cout<< "Detector returned: " << mess << " " << n << std::endl; + } else { + ; +#ifdef VERBOSE + std::cout<< "Detector successfully returned: " << mess << " " << n + << std::endl; +#endif + } + if ((!nodatadetectortype) && (r==NULL)){ + delete [] retval; + } + return NULL; + } else if (!nodatadetectortype){ + + n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); + +#ifdef VERBOSE + std::cout<< "Received "<< n << " data bytes" << std::endl; +#endif + if (n!=thisDetector->dataBytes) { + std::cout<< "wrong data size received from detector: received " << + n << " but expected " << thisDetector->dataBytes << std::endl; + thisDetector->stoppedFlag=1; + ret=FAIL; + if (r==NULL) { + delete [] retval; + } + return NULL; + } + // for (int ib=0; ibdataBytes/8; ++ib) + // cout << ((*(((u_int64_t*)retval)+ib))>>17&1) ; + + + } + // cout << "get data returning " << endl; + // cout << endl; + return retval; + +} + + + +int* slsDetector::readFrame() { + + int fnum=F_READ_FRAME; + int* retval=NULL; + +#ifdef VERBOSE + std::cout<< "slsDetector: Reading frame "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + retval=getDataFromDetector(); + if (retval) { + dataQueue.push(retval); + disconnectControl(); + } + } + } + return retval; +} + + + + +int* slsDetector::readAll() { + + int fnum=F_READ_ALL; + int* retval; // check what we return! + +#ifdef VERBOSE + int i=0; + std::cout<< "Reading all frames "<< std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + + while ((retval=getDataFromDetector())){ +#ifdef VERBOSE + ++i; + std::cout<< i << std::endl; +#endif + dataQueue.push(retval); + } + disconnectControl(); + } + } +#ifdef VERBOSE + std::cout<< "received "<< i<< " frames" << std::endl; +#endif + return dataQueue.front(); // check what we return! + +} + + +int slsDetector::readAllNoWait() { + + int fnum= F_READ_ALL; + +#ifdef VERBOSE + std::cout<< "Reading all frames "<< std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + return OK; + } + } + return FAIL; +} + + + +int slsDetector::configureMAC() { + int i; + int ret=FAIL; + int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME; + char mess[MAX_STR_LENGTH]=""; + char arg[6][50];memset(arg,0,sizeof(char)*6*50); + int retval=-1; + + // to send 3d positions to detector + bool sendpos = 0; + int pos[3]={0,0,0}; + + // only jungfrau and eiger, send x, y and z in detector udp header + if (thisDetector->myDetectorType == JUNGFRAU || + thisDetector->myDetectorType == EIGER) { + sendpos = true; + int max = multiDet->getNumberOfDetectors(X); + if(!detId) { + pos[0] = 0; + pos[1] = 0; + } else { + pos[1] = detId / max; + pos[0] = (detId % max) * ((thisDetector->myDetectorType == EIGER) ? 2 : 1); // for horiz. udp ports + } + } +#ifdef VERBOSE + cout << "SLS [" << detId << "] - (" << pos[0] << "," << pos[1] << "," << + pos[2] << ")" << endl; +#endif + + + //if udpip wasnt initialized in config file + if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ + //hostname is an ip address + if(strchr(thisDetector->receiver_hostname,'.')!=NULL) + strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); + //if hostname not ip, convert it to ip + else{ + struct addrinfo *result; + if (!dataSocket->ConvertHostnameToInternetAddress( + thisDetector->receiver_hostname, &result)) { + // on success + memset(thisDetector->receiverUDPIP, 0, MAX_STR_LENGTH); + // on failure, back to none + if (dataSocket->ConvertInternetAddresstoIpString(result, + thisDetector->receiverUDPIP, MAX_STR_LENGTH)) { + strcpy(thisDetector->receiverUDPIP, "none"); + } + } + } + } + strcpy(arg[0],thisDetector->receiverUDPIP); + strcpy(arg[1],thisDetector->receiverUDPMAC); + sprintf(arg[2],"%x",thisDetector->receiverUDPPort); + strcpy(arg[3],thisDetector->detectorMAC); + strcpy(arg[4],thisDetector->detectorIP); + sprintf(arg[5],"%x",thisDetector->receiverUDPPort2); +#ifdef VERBOSE + std::cout<< "Configuring MAC"<< std::endl; +#endif + + + + for(i=0;i<2;++i){ + if(!strcmp(arg[i],"none")){ + std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + return FAIL; + } + } + +#ifdef VERBOSE + std::cout<< "IP/MAC Addresses valid "<< std::endl; +#endif + + + { + //converting IPaddress to hex + stringstream ss(arg[0]); + char cword[50]=""; + bzero(cword, 50); + string s; + while (getline(ss, s, '.')) { + sprintf(cword,"%s%02x",cword,atoi(s.c_str())); + } + bzero(arg[0], 50); + strcpy(arg[0],cword); +#ifdef VERBOSE + std::cout<<"receiver udp ip:"<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + if(sendpos) + controlSocket->SendDataOnly(pos,sizeof(pos)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if (thisDetector->myDetectorType == EIGER) { + //rewrite detectormac, detector ip + char arg[2][50]; + memset(arg,0,sizeof(arg)); + uint64_t idetectormac = 0; + uint32_t idetectorip = 0; + controlSocket->ReceiveDataOnly(arg,sizeof(arg)); + sscanf(arg[0], "%lx", &idetectormac); + sscanf(arg[1], "%x", &idetectorip); + sprintf(arg[0],"%02x:%02x:%02x:%02x:%02x:%02x", + (unsigned int)((idetectormac>>40)&0xFF), + (unsigned int)((idetectormac>>32)&0xFF), + (unsigned int)((idetectormac>>24)&0xFF), + (unsigned int)((idetectormac>>16)&0xFF), + (unsigned int)((idetectormac>>8)&0xFF), + (unsigned int)((idetectormac>>0)&0xFF)); + sprintf(arg[1],"%d.%d.%d.%d", + (idetectorip>>24)&0xff, + (idetectorip>>16)&0xff, + (idetectorip>>8)&0xff, + (idetectorip)&0xff); + if (strcasecmp(arg[0],thisDetector->detectorMAC)) { + memset(thisDetector->detectorMAC, 0, MAX_STR_LENGTH); + strcpy(thisDetector->detectorMAC, arg[0]); + cprintf(RESET,"%d: Detector MAC updated to %s\n", detId, + thisDetector->detectorMAC); + } + if (strcasecmp(arg[1],thisDetector->detectorIP)) { + memset(thisDetector->detectorIP, 0, MAX_STR_LENGTH); + strcpy(thisDetector->detectorIP, arg[1]); + cprintf(RESET,"%d: Detector IP updated to %s\n", detId, + thisDetector->detectorIP); + } + } + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + if (ret==FAIL) { + ret=FAIL; + std::cout<< "Configuring MAC failed " << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + else if (thisDetector->myDetectorType==GOTTHARD){ + //set frames per file - only for gotthard + pthread_mutex_lock(&ms); + if(retval==-1) + setFramesPerFile(MAX_FRAMES_PER_FILE); + else + setFramesPerFile(SHORT_MAX_FRAMES_PER_FILE); + pthread_mutex_unlock(&ms); + //connect to receiver + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending adc val to receiver " << retval << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum2,retval,retval); + disconnectData(); + } + if(ret==FAIL) + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + } + + return ret; +} + + + + +int64_t slsDetector::setTimer(timerIndex index, int64_t t) { + + + int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER; + int64_t retval = -1; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + + if (index!=MEASUREMENTS_NUMBER) { + + +#ifdef VERBOSE + std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl; #endif if (thisDetector->onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->SendDataOnly(&index,sizeof(index)); + controlSocket->SendDataOnly(&t,sizeof(t)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); if (ret==FAIL) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; - if(strstr(mess,"default tau")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); - if(strstr(mess,"32")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); - else - setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + setErrorMask((getErrorMask())|(DETECTOR_TIMER_VALUE_NOT_SET)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->timerValue[index]=retval; } disconnectControl(); - if (ret==FORCE_UPDATE) + if (ret==FORCE_UPDATE) { updateDetector(); +#ifdef VERBOSE + std::cout<< "Updated!" << std::endl; +#endif + + } + } + } else { + //std::cout<< "offline " << std::endl; + if (t>=0) + thisDetector->timerValue[index]=t; + if((thisDetector->myDetectorType==GOTTHARD)|| + (thisDetector->myDetectorType==PROPIX)|| + (thisDetector->myDetectorType==JUNGFRAU)|| + (thisDetector->myDetectorType==MOENCH)) + thisDetector->timerValue[PROBES_NUMBER]=0; + if(thisDetector->myDetectorType==JUNGFRAUCTB && index==SAMPLES_JCTB) { + getTotalNumberOfChannels(); + // thisDetector->dataBytes=getTotalNumberOfChannels()* + //thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + } + + } + } else { + if (t>=0) + thisDetector->timerValue[index]=t; + } +#ifdef VERBOSE + std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] + << "ns" << std::endl; +#endif + + if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { + setDynamicRange(); + //cout << "Changing probes: data size = " << thisDetector->dataBytes <myDetectorType==JUNGFRAUCTB) && (index==SAMPLES_JCTB)) { + setDynamicRange(); + cout << "Changing samples: data size = " << thisDetector->dataBytes <myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) { + setDynamicRange(); + //cout << "Changing probes: data size = " << thisDetector->dataBytes <myDetectorType == EIGER) && + getRateCorrection(r) && + (t>=0) && + + (((index == SUBFRAME_ACQUISITION_TIME) && + (thisDetector->dynamicRange == 32))|| + ((index == ACQUISITION_TIME) && + (thisDetector->dynamicRange == 16))) + + && (t>=0) && getRateCorrection(r)){ + setRateCorrection(r); + } + } + + + + + //send acquisiton time/period/subexptime/frame/cycles/samples to receiver + if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)|| + (index==ACQUISITION_TIME) || (index==SUBFRAME_ACQUISITION_TIME) || + (index==SUBFRAME_PERIOD) || + (index==SAMPLES_JCTB) || (index==STORAGE_CELL_NUMBER)){ + string timername = getTimerType(index); + if(ret != FAIL){ + int64_t args[2]; + retval = -1; + args[0] = index; + args[1] = thisDetector->timerValue[index]; + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ + + //set #frames * #cycles + if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)|| + (index==STORAGE_CELL_NUMBER)){ + timername.assign("(Number of Frames) * (Number of cycles) " + "* (Number of storage cells)"); + args[1] = thisDetector->timerValue[FRAME_NUMBER] * + ((thisDetector->timerValue[CYCLES_NUMBER] > 0) ? + (thisDetector->timerValue[CYCLES_NUMBER]) : 1) * + ((thisDetector->timerValue[STORAGE_CELL_NUMBER] > 0) + ? (thisDetector->timerValue[STORAGE_CELL_NUMBER])+1 : 1); +#ifdef VERBOSE + std::cout << "Setting/Getting " << timername << " " << index + <<" to/from receiver " << args[1] << std::endl; +#endif + } +#ifdef VERBOSE + // set period/exptime/subexptime/subperiod + else std::cout << "Setting/Getting " << timername << " " << index + << " to/from receiver " << args[1] << std::endl; +#endif + + char mess[MAX_STR_LENGTH]=""; + if (connectData() == OK){ + ret=thisReceiver->sendIntArray(fnum2,retval,args,mess); + disconnectData(); + } + if((args[1] != retval)|| (ret==FAIL)){ + ret = FAIL; + cout << "ERROR: " << timername << " in receiver set incorrectly to " + << retval << " instead of " << args[1] << endl; + + if(strstr(mess,"receiver is not idle")==NULL) { + switch(index) { + case ACQUISITION_TIME: + setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); + break; + case FRAME_PERIOD: + setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET)); + break; + case SUBFRAME_ACQUISITION_TIME: + case SUBFRAME_PERIOD: + case SAMPLES_JCTB: + setErrorMask((getErrorMask())|(RECEIVER_TIMER_NOT_SET)); + break; + default: + setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET)); + break; + } + } + } + if(ret==FORCE_UPDATE) + updateReceiver(); } } - return ret; //only success/fail } + return thisDetector->timerValue[index]; +} - //mythen - double tdead[]=defaultTDead; - if (t==0) { + +int64_t slsDetector::getTimeLeft(timerIndex index) { + + + int fnum=F_GET_TIME_LEFT; + int64_t retval; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + #ifdef VERBOSE - std::cout<< "unsetting rate correction" << std::endl; + std::cout<< "Getting timer "<< index << std::endl; #endif - thisDetector->correctionMask&=~(1<correctionMask|=(1<0) - thisDetector->tDead=t; - else { - if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1) - thisDetector->tDead=tdead[thisDetector->currentSettings]; - else - thisDetector->tDead=0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (stopSocket) { + if (connectStop() == OK) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(&index,sizeof(index)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectStop(); + } } -#ifdef VERBOSE - std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl; -#endif } - return thisDetector->correctionMask&(1<myDetectorType == EIGER){ - t = getRateCorrectionTau(); - return t; +int slsDetector::setSpeed(speedVariable sp, int value) { + + + int fnum=F_SET_SPEED; + int retval=-1; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + +#ifdef VERBOSE + std::cout<< "Setting speed variable"<< sp << " to " << value << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&sp,sizeof(sp)); + controlSocket->SendDataOnly(&value,sizeof(value)); +#ifdef VERBOSE + std::cout<< "Sent "<< n << " bytes " << std::endl; +#endif + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_SET_SPEED_PARAMETERS)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } } - - if (thisDetector->correctionMask&(1<tDead << std::endl; + std::cout<< "Speed set to "<< retval << std::endl; #endif - t=thisDetector->tDead; - return 1; - } else - t=0; + return retval; + +} + + +int slsDetector::setDynamicRange(int n) { + + // cout << "single " << endl; + int fnum=F_SET_DYNAMIC_RANGE,fnum2=F_SET_RECEIVER_DYNAMIC_RANGE; + int retval=-1,retval1; + char mess[MAX_STR_LENGTH]=""; + int ret=OK, rateret=OK; + #ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; + std::cout<< "Setting dynamic range to "<< n << std::endl; #endif - return 0; -}; + if ((thisDetector->myDetectorType == MYTHEN) &&(n==24)) + n=32; -double slsDetector::getRateCorrectionTau(){ - if(thisDetector->myDetectorType == EIGER){ - int fnum=F_GET_RATE_CORRECT; - int ret=FAIL; - char mess[MAX_STR_LENGTH]=""; - int64_t retval = -1; - #ifdef VERBOSE - std::cout<< "Setting Rate Correction to " << arg << endl; - #endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&n,sizeof(n)); + //rate correction is switched off if not 32 bit mode + if(thisDetector->myDetectorType == EIGER){ + controlSocket->ReceiveDataOnly(&rateret,sizeof(rateret)); + if (rateret==FAIL) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; + if(strstr(mess,"Rate Correction")!=NULL){ + if(strstr(mess,"32")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); + else + setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + } } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); } + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else if(thisDetector->myDetectorType==MYTHEN){ + if (n>0) + thisDetector->dynamicRange=n; + retval=thisDetector->dynamicRange; + } + //cout << "detector returned dynamic range " << retval << endl; + if (ret!=FAIL && retval>0) { + /* checking the number of probes to chose the data size */ + + + + thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]* + thisDetector->nChips*thisDetector->nChans*retval/8; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * + thisDetector->nChan[X] + thisDetector->gappixels * + thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + thisDetector->gappixels * + thisDetector->nGappixels[Y]) * + retval/8; + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + // thisDetector->nChip[X]=retval/16; + // thisDetector->nChips=thisDetector->nChip[X]*thisDetector->nChip[Y]; + // cout << thisDetector->nMod[X]*thisDetector->nMod[Y] << " " + //<< thisDetector->nChans*thisDetector->nChips << " " << retval<< " "; + getTotalNumberOfChannels(); + //thisDetector->dataBytes=getTotalNumberOfChannels()* + //retval/8*thisDetector->timerValue[SAMPLES_JCTB]; + //cout << "data bytes: "<< thisDetector->dataBytes << endl; + } + if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->timerValue[PROBES_NUMBER]!=0) { + thisDetector->dataBytes=thisDetector->nMod[X]*t + hisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4; + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * + thisDetector->nChan[X] + thisDetector->gappixels * + thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + thisDetector->gappixels * + thisDetector->nGappixels[Y]) * + 4; + } + + if (retval==32) + thisDetector->dynamicRange=24; } - return double(retval); + thisDetector->dynamicRange=retval; + + +#ifdef VERBOSE + std::cout<< "Dynamic range set to "<< thisDetector->dynamicRange << std::endl; + std::cout<< "Data bytes "<< thisDetector->dataBytes << std::endl; +#endif } - //mythen only - if (thisDetector->correctionMask&(1<dynamicRange; + if((n==-1) && (ret!= FORCE_UPDATE)) n =-1; + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout<< "Rate correction is enabled with dead time "<< thisDetector->tDead << std::endl; + std::cout << "Sending/Getting dynamic range to/from receiver " << + n << std::endl; #endif - return thisDetector->tDead; - //return 1; - } else -#ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; -#endif - return 0; -}; - - - - - -int slsDetector::getRateCorrection(){ - - if (thisDetector->myDetectorType == EIGER){ - double t = getRateCorrectionTau(); - return (int)t; + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum2,retval1,n); + disconnectData(); + } + if ((ret==FAIL) || (retval1 != retval)){ + ret = FAIL; + cout << "ERROR:Dynamic range in receiver set incorrectly to " << + retval1 << " instead of " << retval << endl; + setErrorMask((getErrorMask())|(RECEIVER_DYNAMIC_RANGE)); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } } - if (thisDetector->correctionMask&(1<dynamicRange; +} +int slsDetector::getDataBytes() { + return thisDetector->dataBytes; +} + + +int slsDetector::getDataBytesInclGapPixels() { + return thisDetector->dataBytesInclGapPixels; +} + + +dacs_t slsDetector::setDAC(dacs_t val, dacIndex index, int mV, int imod) { + + + dacs_t retval[2]; + retval[0] = -1; + retval[1] = -1; + int fnum=F_SET_DAC; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int arg[3]; + + + if ( (index==HV_NEW) &&((thisDetector->myDetectorType == GOTTHARD) || + (thisDetector->myDetectorType == PROPIX))) + index=HV_POT; + + arg[0]=index; + arg[1]=imod; + arg[2]=mV; -int slsDetector::rateCorrect(double* datain, double *errin, double* dataout, double *errout){ - double tau=thisDetector->tDead; - double t=thisDetector->timerValue[ACQUISITION_TIME]; - // double data; - double e; - if (thisDetector->correctionMask&(1<nMod[X]*thisDetector->nMod[Y]*thisDetector->nChans*thisDetector->nChips; ++ichan) { + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->SendDataOnly(&val,sizeof(val)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(retval,sizeof(retval)); + if (index < thisDetector->nDacs){ - if (errin==NULL) { - e=sqrt(datain[ichan]); - } else - e=errin[ichan]; + if (dacs) { + if (imod>=0) { + *(dacs+index+imod*thisDetector->nDacs)=retval[0]; + } + else { + for (imod=0; imodnModsMax; ++imod) + *(dacs+index+imod*thisDetector->nDacs)=retval[0]; + } + } + } + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); - postProcessingFuncs::rateCorrect(datain[ichan], e, dataout[ichan], errout[ichan], tau, t); - } - } + } + } +#ifdef VERBOSE + std::cout<< "Dac set to "<< retval[0] << " dac units (" << retval[1] << "mV)" + << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Set dac " << index << " of module " << imod << " to " << + val << " failed." << std::endl; + } + if(mV) + return retval[1]; - return 0; -}; - - - - - - - -int slsDetector::setBadChannelCorrection(string fname){ - - // int nbadmod; - int ret=0; - //int badchanlist[MAX_BADCHANS]; - //int off; - - string fn=fname; - - if (fname=="default") - fname=string(badChanFile); - - if (nBadChans && badChansList) - ret=setBadChannelCorrection(fname, *nBadChans, badChansList); - - if (ret) { - *correctionMask|=(1<0) { - thisDetector->correctionMask|=(1<nBadChans=0; - for (int ich=0 ;ich=0 && chs[ich]badChansList[ich]=chs[ich]; - ++thisDetector->nBadChans; - // cout << "det : " << thisDetector->nBadChans << " " << thisDetector->badChansList[ich] << endl; - } - } - } else - thisDetector->correctionMask&=~(1<0) { - thisDetector->nBadFF=nch; - for (int ich=0 ;ichbadFFList[ich]=chs[ich]; - } - } - } #ifdef VERBOSE - cout << "badchans flag is "<< (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) << endl; + std::cout<< std::endl; + std::cout<< "Getting ADC "<< index << " of module " << imod << std::endl; #endif - // fillBadChannelMask(); - if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) { - return thisDetector->nBadChans+thisDetector->nBadFF; - } else - return 0; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectStop() == OK){ + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if (adcs) { + *(adcs+index+imod*thisDetector->nAdcs)=retval; + } + } else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectStop(); + /*commented out to allow adc read during acquire, also not required + if (ret==FORCE_UPDATE) + updateDetector();*/ + } + } +#ifdef VERBOSE + std::cout<< "ADC returned "<< retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Get ADC failed " << std::endl; + } + + return retval; + + + +} + + + +slsDetectorDefs::externalCommunicationMode slsDetector::setExternalCommunicationMode( + externalCommunicationMode pol) { + + + + + int arg[1]; + externalCommunicationMode retval; + int fnum=F_SET_EXTERNAL_COMMUNICATION_MODE; + char mess[MAX_STR_LENGTH]=""; + + arg[0]=pol; + + int ret=FAIL; + retval=GET_EXTERNAL_COMMUNICATION_MODE; + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting communication to mode " << pol << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + retval=GET_EXTERNAL_COMMUNICATION_MODE; + ret=FAIL; + } +#ifdef VERBOSE + std::cout<< "Communication mode "<< " set to" << retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Setting communication mode failed" << std::endl; + } + return retval; + +} + + + +slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags( + externalSignalFlag pol, int signalindex) { + + + + + int arg[2]; + externalSignalFlag retval; + int ret=FAIL; + int fnum=F_SET_EXTERNAL_SIGNAL_FLAG; + char mess[MAX_STR_LENGTH]=""; + + arg[0]=signalindex; + arg[1]=pol; + + retval=GET_EXTERNAL_SIGNAL_FLAG; + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting signal "<< signalindex << " to flag" << pol << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + retval=GET_EXTERNAL_SIGNAL_FLAG; + ret=FAIL; + } +#ifdef VERBOSE + std::cout<< "Signal "<< signalindex << " flag set to" << retval << std::endl; + if (ret==FAIL) { + std::cout<< "Set signal flag failed " << std::endl; + } +#endif + return retval; + + + + + } +int slsDetector::setReadOutFlags(readOutFlags flag) { + + + int fnum=F_SET_READOUT_FLAGS; + readOutFlags retval; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + +#ifdef VERBOSE + std::cout<< "Setting readout flags to "<< flag << std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&flag,sizeof(flag)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_SET_READOUT_FLAGS)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->roFlags=retval; + if (thisDetector->myDetectorType==JUNGFRAUCTB) { + + getTotalNumberOfChannels(); + //thisDetector->dataBytes=getTotalNumberOfChannels()* + //thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB]; + } + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + if (flag!=GET_READOUT_FLAGS) + thisDetector->roFlags=flag; + } + +#ifdef VERBOSE + std::cout<< "Readout flag set to "<< retval << std::endl; +#endif + return thisDetector->roFlags; +} + + +uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) { + + uint32_t retval = 0; + int fnum=F_WRITE_REGISTER; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + uint32_t arg[2]; + arg[0]=addr; + arg[1]=val; + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Writing to register "<< hex<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } +#ifdef VERBOSE + std::cout<< "Register returned "<< retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Write to register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + + return retval; +} +uint32_t slsDetector::readRegister(uint32_t addr) { + + uint32_t retval = 0; + int fnum=F_READ_REGISTER; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + uint32_t arg; + arg=addr; + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Reading register "<< hex<onlineFlag==ONLINE_FLAG) { + // if (connectControl() == OK){ + if (stopSocket) { + if (connectStop() == OK) { + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(&arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectStop(); + } + } + } +#ifdef VERBOSE + std::cout<< "Register returned "<< retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Read register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + return retval; -int slsDetector::getBadChannelCorrection(int *bad) { - int ichan; - if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) { - if (bad) { - for (ichan=0; ichannBadChans; ++ichan) - bad[ichan]=thisDetector->badChansList[ichan]; - for (int ich=0; ichnBadFF; ++ich) - bad[ichan+ich]=thisDetector->badFFList[ich]; - } - return thisDetector->nBadChans+thisDetector->nBadFF; - } else - return 0; } +uint32_t slsDetector::setBit(uint32_t addr, int n) { + if (n<0 || n>31) { + std::cout << "Bit number out of Range" << std:: endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + + // normal bit range + //TODO! (Erik) Check for errors! cannot use value since reg is 32bits + else { + uint32_t val = readRegister(addr); + writeRegister(addr,val | 1<31) { + std::cout << "Bit number out of Range" << std:: endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + // normal bit range + else { + uint32_t val = readRegister(addr); + writeRegister(addr,val & ~(1<onlineFlag==ONLINE_FLAG) { - if (controlSocket) { - controlSocket->Connect(); - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - } - } - if (retval!=OK) { - std::cout<< std::endl; - std::cout<< "Shutting down the server" << std::endl; - std::cout<< std::endl; - } - return retval; - -}; - string slsDetector::setNetworkParameter(networkParameter index, string value) { int i; @@ -6200,15 +4926,15 @@ string slsDetector::setNetworkParameter(networkParameter index, string value) { case RECEIVER_STREAMING_SRC_IP: return setReceiverStreamingIP(value); case ADDITIONAL_JSON_HEADER: - return setAdditionalJsonHeader(value); + return setAdditionalJsonHeader(value); case RECEIVER_UDP_SCKT_BUF_SIZE: - sscanf(value.c_str(),"%d",&i); - setReceiverUDPSocketBufferSize(i); - return getReceiverUDPSocketBufferSize(); + sscanf(value.c_str(),"%d",&i); + setReceiverUDPSocketBufferSize(i); + return getReceiverUDPSocketBufferSize(); - default: - return (char*)("unknown network parameter"); - } + default: + return (char*)("unknown network parameter"); + } } @@ -6216,76 +4942,157 @@ string slsDetector::setNetworkParameter(networkParameter index, string value) { string slsDetector::getNetworkParameter(networkParameter index) { ostringstream ss;string s; - switch (index) { - case DETECTOR_MAC: - return getDetectorMAC(); - case DETECTOR_IP: - return getDetectorIP(); - case RECEIVER_HOSTNAME: - return getReceiver(); - case RECEIVER_UDP_IP: - return getReceiverUDPIP(); - case RECEIVER_UDP_MAC: - return getReceiverUDPMAC(); - case RECEIVER_UDP_PORT: - return getReceiverUDPPort(); - case RECEIVER_UDP_PORT2: - return getReceiverUDPPort2(); - case DETECTOR_TXN_DELAY_LEFT: - case DETECTOR_TXN_DELAY_RIGHT: - case DETECTOR_TXN_DELAY_FRAME: - case FLOW_CONTROL_10G: - return setDetectorNetworkParameter(index, -1); - case CLIENT_STREAMING_PORT: - return getClientStreamingPort(); - case RECEIVER_STREAMING_PORT: - return getReceiverStreamingPort(); - case CLIENT_STREAMING_SRC_IP: - return getClientStreamingIP(); - case RECEIVER_STREAMING_SRC_IP: - return getReceiverStreamingIP(); - case ADDITIONAL_JSON_HEADER: - return getAdditionalJsonHeader(); - case RECEIVER_UDP_SCKT_BUF_SIZE: - return getReceiverUDPSocketBufferSize(); - case RECEIVER_REAL_UDP_SCKT_BUF_SIZE: - return getReceiverRealUDPSocketBufferSize(); + switch (index) { + case DETECTOR_MAC: + return getDetectorMAC(); + case DETECTOR_IP: + return getDetectorIP(); + case RECEIVER_HOSTNAME: + return getReceiver(); + case RECEIVER_UDP_IP: + return getReceiverUDPIP(); + case RECEIVER_UDP_MAC: + return getReceiverUDPMAC(); + case RECEIVER_UDP_PORT: + return getReceiverUDPPort(); + case RECEIVER_UDP_PORT2: + return getReceiverUDPPort2(); + case DETECTOR_TXN_DELAY_LEFT: + case DETECTOR_TXN_DELAY_RIGHT: + case DETECTOR_TXN_DELAY_FRAME: + case FLOW_CONTROL_10G: + return setDetectorNetworkParameter(index, -1); + case CLIENT_STREAMING_PORT: + return getClientStreamingPort(); + case RECEIVER_STREAMING_PORT: + return getReceiverStreamingPort(); + case CLIENT_STREAMING_SRC_IP: + return getClientStreamingIP(); + case RECEIVER_STREAMING_SRC_IP: + return getReceiverStreamingIP(); + case ADDITIONAL_JSON_HEADER: + return getAdditionalJsonHeader(); + case RECEIVER_UDP_SCKT_BUF_SIZE: + return getReceiverUDPSocketBufferSize(); + case RECEIVER_REAL_UDP_SCKT_BUF_SIZE: + return getReceiverRealUDPSocketBufferSize(); - default: - return (char*)("unknown network parameter"); - } + default: + return (char*)("unknown network parameter"); + } } -string slsDetector::setDetectorMAC(string detectorMAC){ - if(detectorMAC.length()==17){ - if((detectorMAC[2]==':')&&(detectorMAC[5]==':')&&(detectorMAC[8]==':')&& - (detectorMAC[11]==':')&&(detectorMAC[14]==':')){ - strcpy(thisDetector->detectorMAC,detectorMAC.c_str()); - if(!strcmp(thisDetector->receiver_hostname,"none")) + + +string slsDetector::getDetectorMAC() { + return string(thisDetector->detectorMAC); +} + +string slsDetector::getDetectorIP() { + return string(thisDetector->detectorIP); +} + +string slsDetector::getReceiver() { + return string(thisDetector->receiver_hostname); +} + +string slsDetector::getReceiverUDPIP() { + return string(thisDetector->receiverUDPIP); +} + +string slsDetector::getReceiverUDPMAC() { + return string(thisDetector->receiverUDPMAC); +} +string slsDetector::getReceiverUDPPort() { + ostringstream ss; ss << thisDetector->receiverUDPPort; string s = ss.str(); + return s; +} +string slsDetector::getReceiverUDPPort2() { + ostringstream ss; ss << thisDetector->receiverUDPPort2; string s = ss.str(); + return s; +} +string slsDetector::getClientStreamingPort() { + ostringstream ss; ss << thisDetector->zmqport; string s = ss.str(); + return s; +} +string slsDetector::getReceiverStreamingPort() { + ostringstream ss; ss << thisDetector->receiver_zmqport; string s = ss.str(); + return s; +} +string slsDetector::getClientStreamingIP() { + return string(thisDetector->zmqip); +} +string slsDetector::getReceiverStreamingIP() { + return string(thisDetector->receiver_zmqip); +} +string slsDetector::getAdditionalJsonHeader() { + return string(thisDetector->receiver_additionalJsonHeader); +} +string slsDetector::getReceiverUDPSocketBufferSize() { + return setReceiverUDPSocketBufferSize(); +} + +string slsDetector::getReceiverRealUDPSocketBufferSize() { + + int fnum=F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE; + int ret = FAIL; + int retval = -1; + + if(thisDetector->receiverOnlineFlag == ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << endl; -#else - ; + std::cout << "Getting real UDP Socket Buffer size to receiver " << std::endl; #endif - else if(setUDPConnection()==FAIL) - std::cout<< "Warning: UDP connection set up failed" << std::endl; - }else{ - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: server MAC Address should be in xx:xx:xx:xx:xx:xx format" << endl; - } - } - else{ - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: server MAC Address should be in xx:xx:xx:xx:xx:xx format" << std::endl; - } + if (connectData() == OK){ + ret=thisReceiver->getInt(fnum,retval); + disconnectData(); + } + if(ret==FAIL) { + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + printf("Warning: Could not get real socket buffer size\n"); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } - return string(thisDetector->detectorMAC); -}; + ostringstream ss; + ss << retval; + string s = ss.str(); + return s; +} + + +string slsDetector::setDetectorMAC(string detectorMAC) { + if(detectorMAC.length()==17){ + if((detectorMAC[2]==':')&&(detectorMAC[5]==':')&&(detectorMAC[8]==':')&& + (detectorMAC[11]==':')&&(detectorMAC[14]==':')){ + strcpy(thisDetector->detectorMAC,detectorMAC.c_str()); + if(!strcmp(thisDetector->receiver_hostname,"none")) +#ifdef VERBOSE + std::cout << "Warning: Receiver hostname not set yet." << endl; +#else + ; +#endif + else if(setUDPConnection()==FAIL) + std::cout<< "Warning: UDP connection set up failed" << std::endl; + }else{ + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: server MAC Address should be in xx:xx:xx:xx:xx:xx " + "format" << endl; + } + } + else{ + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: server MAC Address should be in xx:xx:xx:xx:xx:xx " + "format" << std::endl; + } + + return string(thisDetector->detectorMAC); +} -string slsDetector::setDetectorIP(string detectorIP){ +string slsDetector::setDetectorIP(string detectorIP) { struct sockaddr_in sa; //taking function arguments into consideration if(detectorIP.length()){ @@ -6297,13 +5104,14 @@ string slsDetector::setDetectorIP(string detectorIP){ #ifdef VERBOSE std::cout << "Warning: Receiver hostname not set yet." << endl; #else - ; + ; #endif else if(setUDPConnection()==FAIL) std::cout<< "Warning: UDP connection set up failed" << std::endl; }else{ - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: Detector IP Address should be VALID and in xxx.xxx.xxx.xxx format" << std::endl; + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: Detector IP Address should be VALID and in " + "xxx.xxx.xxx.xxx format" << std::endl; } } } @@ -6312,7 +5120,7 @@ string slsDetector::setDetectorIP(string detectorIP){ -string slsDetector::setReceiver(string receiverIP){ +string slsDetector::setReceiver(string receiverIP) { if(receiverIP == "none") { memset(thisDetector->receiver_hostname, 0, MAX_STR_LENGTH); @@ -6332,8 +5140,9 @@ string slsDetector::setReceiver(string receiverIP){ if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ #ifdef VERBOSE std::cout << "Setting up receiver with" << endl; - std::cout << "detector type:" << slsDetectorBase::getDetectorType(thisDetector->myDetectorType) << endl; - std::cout << "detector id:" << posId << endl; + std::cout << "detector type:" << slsDetectorBase::getDetectorType( + thisDetector->myDetectorType) << endl; + std::cout << "detector id:" << detId << endl; std::cout << "detector hostname:" << thisDetector->hostname << endl; std::cout << "file path:" << fileIO::getFilePath() << endl; std::cout << "file name:" << fileIO::getFileName() << endl; @@ -6343,25 +5152,27 @@ string slsDetector::setReceiver(string receiverIP){ std::cout << "write enable:" << multiDet->enableWriteToFileMask() << endl; std::cout << "overwrite enable:" << multiDet->enableOverwriteMask() << endl; pthread_mutex_unlock(&ms); - std::cout << "frame index needed:" << ((thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER])>1) << endl; + std::cout << "frame index needed:" << ((thisDetector->timerValue[FRAME_NUMBER] + *thisDetector->timerValue[CYCLES_NUMBER])>1) << endl; std::cout << "frame period:" << thisDetector->timerValue[FRAME_PERIOD] << endl; std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl; - std::cout << "sub exp time:" << thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME] << endl; + std::cout << "sub exp time:" << thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME] + << endl; std::cout << "sub period:" << thisDetector->timerValue[SUBFRAME_PERIOD] << endl; std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl; std::cout << "flippeddatax:" << thisDetector->flippedData[d] << endl; std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl; std::cout << "rx streaming source ip:" << thisDetector->receiver_zmqip << endl; - std::cout << "rx additional json header:" << thisDetector->receiver_additionalJsonHeader << endl; + std::cout << "rx additional json header:" << thisDetector->receiver_additionalJsonHeader << endl; std::cout << "enable gap pixels:" << thisDetector->gappixels << endl; std::cout << "rx streaming port:" << thisDetector->receiver_zmqport << endl; std::cout << "r_readfreq:" << thisDetector->receiver_read_freq << endl << endl; std::cout << "rx_datastream:" << enableDataStreamingFromReceiver(-1) << endl << endl; std::cout << "r_framesperfile:" << thisDetector->receiver_framesPerFile << endl; -/** enable compresison, */ + /** enable compresison, */ #endif if(setDetectorType()!= GENERIC){ - if(!posId) + if(!detId) sendMultiDetectorSize(); setDetectorId(); setDetectorHostname(); @@ -6385,7 +5196,8 @@ string slsDetector::setReceiver(string receiverIP){ setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]); setTimer(ACQUISITION_TIME,thisDetector->timerValue[ACQUISITION_TIME]); if(thisDetector->myDetectorType == EIGER) { - setTimer(SUBFRAME_ACQUISITION_TIME,thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]); + setTimer(SUBFRAME_ACQUISITION_TIME, + thisDetector->timerValue[SUBFRAME_ACQUISITION_TIME]); setTimer(SUBFRAME_PERIOD,thisDetector->timerValue[SUBFRAME_PERIOD]); } if(thisDetector->myDetectorType == JUNGFRAUCTB) @@ -6410,13 +5222,13 @@ string slsDetector::setReceiver(string receiverIP){ } } - return string(thisDetector->receiver_hostname); + return string(thisDetector->receiver_hostname); } -string slsDetector::setReceiverUDPIP(string udpip){ +string slsDetector::setReceiverUDPIP(string udpip) { struct sockaddr_in sa; //taking function arguments into consideration if(udpip.length()){ @@ -6424,7 +5236,8 @@ string slsDetector::setReceiverUDPIP(string udpip){ int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr)); if(result==0){ setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: Receiver UDP IP Address should be VALID and in xxx.xxx.xxx.xxx format" << std::endl; + std::cout << "Warning: Receiver UDP IP Address should be VALID " + "and in xxx.xxx.xxx.xxx format" << std::endl; }else{ strcpy(thisDetector->receiverUDPIP,udpip.c_str()); if(!strcmp(thisDetector->receiver_hostname,"none")) { @@ -6446,61 +5259,64 @@ string slsDetector::setReceiverUDPIP(string udpip){ -string slsDetector::setReceiverUDPMAC(string udpmac){ - if(udpmac.length()!=17){ - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: receiver udp mac address should be in xx:xx:xx:xx:xx:xx format" << std::endl; - } - else{ - if((udpmac[2]==':')&&(udpmac[5]==':')&&(udpmac[8]==':')&& - (udpmac[11]==':')&&(udpmac[14]==':')){ - strcpy(thisDetector->receiverUDPMAC,udpmac.c_str()); - if(!strcmp(thisDetector->receiver_hostname,"none")) +string slsDetector::setReceiverUDPMAC(string udpmac) { + if(udpmac.length()!=17){ + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: receiver udp mac address should be in xx:xx:xx:xx:xx:xx " + "format" << std::endl; + } + else{ + if((udpmac[2]==':')&&(udpmac[5]==':')&&(udpmac[8]==':')&& + (udpmac[11]==':')&&(udpmac[14]==':')){ + strcpy(thisDetector->receiverUDPMAC,udpmac.c_str()); + if(!strcmp(thisDetector->receiver_hostname,"none")) #ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << endl; + std::cout << "Warning: Receiver hostname not set yet." << endl; #else - ; + ; #endif - /* else if(setUDPConnection()==FAIL){ commented out to be replaced by user defined udpmac + /* else if(setUDPConnection()==FAIL){ commented out to be replaced by user + * defined udpmac std::cout<< "Warning: UDP connection set up failed" << std::endl; }*/ - }else{ - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: receiver udp mac address should be in xx:xx:xx:xx:xx:xx format" << std::endl; - } - } + }else{ + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: receiver udp mac address should be in xx:xx:xx:xx:xx:xx " + "format" << std::endl; + } + } - return string(thisDetector->receiverUDPMAC); + return string(thisDetector->receiverUDPMAC); } -int slsDetector::setReceiverUDPPort(int udpport){ +int slsDetector::setReceiverUDPPort(int udpport) { thisDetector->receiverUDPPort = udpport; if(!strcmp(thisDetector->receiver_hostname,"none")) #ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << endl; + std::cout << "Warning: Receiver hostname not set yet." << endl; #else - ; + ; #endif else if(setUDPConnection()==FAIL){ std::cout<< "Warning: UDP connection set up failed" << std::endl; - } + } return thisDetector->receiverUDPPort; } -int slsDetector::setReceiverUDPPort2(int udpport){ +int slsDetector::setReceiverUDPPort2(int udpport) { thisDetector->receiverUDPPort2 = udpport; if(!strcmp(thisDetector->receiver_hostname,"none")) #ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << endl; + std::cout << "Warning: Receiver hostname not set yet." << endl; #else - ; + ; #endif else if(setUDPConnection()==FAIL){ - std::cout<< "Warning: UDP connection set up failed" << std::endl; - } + std::cout<< "Warning: UDP connection set up failed" << std::endl; + } return thisDetector->receiverUDPPort2; } @@ -6515,7 +5331,7 @@ string slsDetector::setClientStreamingPort(string port) { if(found != string::npos) { port.erase(found,5); sscanf(port.c_str(),"%d",&defaultport); - arg = defaultport + (posId * numsockets); + arg = defaultport + (detId * numsockets); } else sscanf(port.c_str(),"%d",&arg); @@ -6537,12 +5353,12 @@ string slsDetector::setReceiverStreamingPort(string port) { if(found != string::npos) { port.erase(found,5); sscanf(port.c_str(),"%d",&defaultport); - arg = defaultport + (posId * numsockets); + arg = defaultport + (detId * numsockets); } else sscanf(port.c_str(),"%d",&arg); - thisDetector->receiver_zmqport = arg; + thisDetector->receiver_zmqport = arg; // send to receiver int fnum=F_SET_RECEIVER_STREAMING_PORT; @@ -6572,14 +5388,16 @@ string slsDetector::setClientStreamingIP(string sourceIP) { struct addrinfo *result; // on failure to convert to a valid ip if (dataSocket->ConvertHostnameToInternetAddress(sourceIP.c_str(), &result)) { - std::cout << "Warning: Could not convert zmqip into a valid IP" << sourceIP << std::endl; - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - return getClientStreamingIP(); + std::cout << "Warning: Could not convert zmqip into a valid IP" << sourceIP + << std::endl; + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + return getClientStreamingIP(); } // on success put IP as string into arg else { memset(thisDetector->zmqip, 0, MAX_STR_LENGTH); - dataSocket->ConvertInternetAddresstoIpString(result, thisDetector->zmqip, MAX_STR_LENGTH); + dataSocket->ConvertInternetAddresstoIpString(result, thisDetector->zmqip, + MAX_STR_LENGTH); } return getClientStreamingIP(); @@ -6598,7 +5416,8 @@ string slsDetector::setReceiverStreamingIP(string sourceIP) { // if empty, give rx_hostname if (sourceIP.empty()) { if(!strcmp(thisDetector->receiver_hostname,"none")) { - std::cout << "Receiver hostname not set yet. Cannot create rx_zmqip from none\n" << endl; + std::cout << "Receiver hostname not set yet. Cannot create rx_zmqip " + "from none\n" << endl; setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); return getReceiverStreamingIP(); } @@ -6610,7 +5429,8 @@ string slsDetector::setReceiverStreamingIP(string sourceIP) { struct addrinfo *result; // on failure to convert to a valid ip if (dataSocket->ConvertHostnameToInternetAddress(sourceIP.c_str(), &result)) { - std::cout << "Warning: Could not convert rx_zmqip into a valid IP" << sourceIP << std::endl; + std::cout << "Warning: Could not convert rx_zmqip into a valid IP" << + sourceIP << std::endl; setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); return getReceiverStreamingIP(); } @@ -6632,15 +5452,16 @@ string slsDetector::setReceiverStreamingIP(string sourceIP) { if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Sending receiver streaming source ip to receiver " << arg << std::endl; + std::cout << "Sending receiver streaming source ip to receiver " << arg << + std::endl; #endif if (connectData() == OK){ ret=thisReceiver->sendString(fnum,retval,arg); disconnectData(); } if(ret==FAIL) { - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: Could not set rx_zmqip" << std::endl; + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: Could not set rx_zmqip" << std::endl; } if(ret==FORCE_UPDATE) updateReceiver(); @@ -6653,96 +5474,70 @@ string slsDetector::setReceiverStreamingIP(string sourceIP) { string slsDetector::setAdditionalJsonHeader(string jsonheader) { - int fnum=F_ADDITIONAL_JSON_HEADER; - int ret = FAIL; - char arg[MAX_STR_LENGTH]; - memset(arg,0,sizeof(arg)); - char retval[MAX_STR_LENGTH]; - memset(retval,0, sizeof(retval)); + int fnum=F_ADDITIONAL_JSON_HEADER; + int ret = FAIL; + char arg[MAX_STR_LENGTH]; + memset(arg,0,sizeof(arg)); + char retval[MAX_STR_LENGTH]; + memset(retval,0, sizeof(retval)); - strcpy(arg, jsonheader.c_str()); + strcpy(arg, jsonheader.c_str()); - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Sending additional json header " << arg << std::endl; + std::cout << "Sending additional json header " << arg << std::endl; #endif - if (connectData() == OK){ - ret=thisReceiver->sendString(fnum,retval,arg); - disconnectData(); - } - if(ret==FAIL) { - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - std::cout << "Warning: Could not set additional json header" << std::endl; - } else - strcpy(thisDetector->receiver_additionalJsonHeader, retval); - if(ret==FORCE_UPDATE) - updateReceiver(); - } + if (connectData() == OK){ + ret=thisReceiver->sendString(fnum,retval,arg); + disconnectData(); + } + if(ret==FAIL) { + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + std::cout << "Warning: Could not set additional json header" << std::endl; + } else + strcpy(thisDetector->receiver_additionalJsonHeader, retval); + if(ret==FORCE_UPDATE) + updateReceiver(); + } - return getAdditionalJsonHeader(); + return getAdditionalJsonHeader(); } string slsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize) { - int fnum=F_RECEIVER_UDP_SOCK_BUF_SIZE; - int ret = FAIL; - int retval = -1; - int arg = udpsockbufsize; + int fnum=F_RECEIVER_UDP_SOCK_BUF_SIZE; + int ret = FAIL; + int retval = -1; + int arg = udpsockbufsize; - if(thisDetector->receiverOnlineFlag == ONLINE_FLAG){ + if(thisDetector->receiverOnlineFlag == ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Sending UDP Socket Buffer size to receiver " << arg << std::endl; + std::cout << "Sending UDP Socket Buffer size to receiver " << arg << std::endl; #endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); - } - if(ret==FAIL) { - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - printf("Warning: Could not set udp socket buffer size\n"); - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if(ret==FAIL) { + setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); + printf("Warning: Could not set udp socket buffer size\n"); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } - ostringstream ss; - ss << retval; - string s = ss.str(); - return s; + ostringstream ss; + ss << retval; + string s = ss.str(); + return s; } -string slsDetector::getReceiverRealUDPSocketBufferSize() { - - int fnum=F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE; - int ret = FAIL; - int retval = -1; - - if(thisDetector->receiverOnlineFlag == ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Getting real UDP Socket Buffer size to receiver " << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->getInt(fnum,retval); - disconnectData(); - } - if(ret==FAIL) { - setErrorMask((getErrorMask())|(COULDNOT_SET_NETWORK_PARAMETER)); - printf("Warning: Could not get real socket buffer size\n"); - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - ostringstream ss; - ss << retval; - string s = ss.str(); - return s; -} -string slsDetector::setDetectorNetworkParameter(networkParameter index, int delay){ + +string slsDetector::setDetectorNetworkParameter(networkParameter index, int delay) { int fnum = F_SET_NETWORK_PARAMETER; int ret = FAIL; int retval = -1; @@ -6779,7 +5574,7 @@ string slsDetector::setDetectorNetworkParameter(networkParameter index, int dela } -int slsDetector::setUDPConnection(){ +int slsDetector::setUDPConnection() { int ret = FAIL; int fnum = F_SETUP_RECEIVER_UDP; @@ -6791,7 +5586,7 @@ int slsDetector::setUDPConnection(){ //called before set up if(!strcmp(thisDetector->receiver_hostname,"none")){ #ifdef VERBOSE - std::cout << "Warning: Receiver hostname not set yet." << endl; + std::cout << "Warning: Receiver hostname not set yet." << endl; #endif return FAIL; } @@ -6804,11 +5599,13 @@ int slsDetector::setUDPConnection(){ //if hostname not ip, convert it to ip else{ struct addrinfo *result; - if (!dataSocket->ConvertHostnameToInternetAddress(thisDetector->receiver_hostname, &result)) { + if (!dataSocket->ConvertHostnameToInternetAddress( + thisDetector->receiver_hostname, &result)) { // on success memset(thisDetector->receiverUDPIP, 0, MAX_STR_LENGTH); // on failure, back to none - if (dataSocket->ConvertInternetAddresstoIpString(result, thisDetector->receiverUDPIP, MAX_STR_LENGTH)) { + if (dataSocket->ConvertInternetAddresstoIpString(result, + thisDetector->receiverUDPIP, MAX_STR_LENGTH)) { strcpy(thisDetector->receiverUDPIP, "none"); } } @@ -6844,7 +5641,8 @@ int slsDetector::setUDPConnection(){ if(ret==FORCE_UPDATE) updateReceiver(); - //configure detector with udp details, -100 is so it doesnt overwrite the previous value + //configure detector with udp details, -100 is so it doesnt overwrite + //the previous value if(configureMAC()==FAIL){ setReceiverOnline(OFFLINE_FLAG); std::cout << "could not configure mac" << endl; @@ -6860,226 +5658,152 @@ int slsDetector::setUDPConnection(){ -int slsDetector::configureMAC(){ - int i; +int slsDetector::digitalTest( digitalTestMode mode, int imod) { + + + int retval; + int fnum=F_DIGITAL_TEST; int ret=FAIL; - int fnum=F_CONFIGURE_MAC,fnum2=F_RECEIVER_SHORT_FRAME; char mess[MAX_STR_LENGTH]=""; - char arg[6][50];memset(arg,0,sizeof(char)*6*50); - int retval=-1; - - // to send 3d positions to detector - bool sendpos = 0; - int pos[3]={0,0,0}; - - // only jungfrau and eiger, send x, y and z in detector udp header - if (thisDetector->myDetectorType == JUNGFRAU || thisDetector->myDetectorType == EIGER) { - sendpos = true; - int max = multiDet->getNumberOfDetectors(X); - if(!posId) { - pos[0] = 0; - pos[1] = 0; - } else { - pos[1] = posId / max; - pos[0] = (posId % max) * ((thisDetector->myDetectorType == EIGER) ? 2 : 1); // for horiz. udp ports - } - } -#ifdef VERBOSE - cout << "SLS [" << posId << "] - (" << pos[0] << "," << pos[1] << "," << pos[2] << ")" << endl; -#endif - - - //if udpip wasnt initialized in config file - if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ - //hostname is an ip address - if(strchr(thisDetector->receiver_hostname,'.')!=NULL) - strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); - //if hostname not ip, convert it to ip - else{ - struct addrinfo *result; - if (!dataSocket->ConvertHostnameToInternetAddress(thisDetector->receiver_hostname, &result)) { - // on success - memset(thisDetector->receiverUDPIP, 0, MAX_STR_LENGTH); - // on failure, back to none - if (dataSocket->ConvertInternetAddresstoIpString(result, thisDetector->receiverUDPIP, MAX_STR_LENGTH)) { - strcpy(thisDetector->receiverUDPIP, "none"); - } - } - } - } - strcpy(arg[0],thisDetector->receiverUDPIP); - strcpy(arg[1],thisDetector->receiverUDPMAC); - sprintf(arg[2],"%x",thisDetector->receiverUDPPort); - strcpy(arg[3],thisDetector->detectorMAC); - strcpy(arg[4],thisDetector->detectorIP); - sprintf(arg[5],"%x",thisDetector->receiverUDPPort2); -#ifdef VERBOSE - std::cout<< "Configuring MAC"<< std::endl; -#endif - - - - for(i=0;i<2;++i){ - if(!strcmp(arg[i],"none")){ - std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - return FAIL; - } - } #ifdef VERBOSE - std::cout<< "IP/MAC Addresses valid "<< std::endl; + std::cout<< std::endl; + std::cout<< "Getting id of "<< mode << std::endl; #endif - - { - //converting IPaddress to hex - stringstream ss(arg[0]); - char cword[50]=""; - bzero(cword, 50); - string s; - while (getline(ss, s, '.')) { - sprintf(cword,"%s%02x",cword,atoi(s.c_str())); - } - bzero(arg[0], 50); - strcpy(arg[0],cword); -#ifdef VERBOSE - std::cout<<"receiver udp ip:"<onlineFlag==ONLINE_FLAG) { if (connectControl() == OK){ controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - if(sendpos) - controlSocket->SendDataOnly(pos,sizeof(pos)); + controlSocket->SendDataOnly(&mode,sizeof(mode)); + if ((mode==CHIP_TEST)|| (mode==DIGITAL_BIT_TEST)) + controlSocket->SendDataOnly(&imod,sizeof(imod)); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); } - else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if (thisDetector->myDetectorType == EIGER) { - //rewrite detectormac, detector ip - char arg[2][50]; - memset(arg,0,sizeof(arg)); - uint64_t idetectormac = 0; - uint32_t idetectorip = 0; - controlSocket->ReceiveDataOnly(arg,sizeof(arg)); - sscanf(arg[0], "%lx", &idetectormac); - sscanf(arg[1], "%x", &idetectorip); - sprintf(arg[0],"%02x:%02x:%02x:%02x:%02x:%02x", - (unsigned int)((idetectormac>>40)&0xFF), - (unsigned int)((idetectormac>>32)&0xFF), - (unsigned int)((idetectormac>>24)&0xFF), - (unsigned int)((idetectormac>>16)&0xFF), - (unsigned int)((idetectormac>>8)&0xFF), - (unsigned int)((idetectormac>>0)&0xFF)); - sprintf(arg[1],"%d.%d.%d.%d", - (idetectorip>>24)&0xff, - (idetectorip>>16)&0xff, - (idetectorip>>8)&0xff, - (idetectorip)&0xff); - if (strcasecmp(arg[0],thisDetector->detectorMAC)) { - memset(thisDetector->detectorMAC, 0, MAX_STR_LENGTH); - strcpy(thisDetector->detectorMAC, arg[0]); - cprintf(RESET,"%d: Detector MAC updated to %s\n", detId, thisDetector->detectorMAC); - } - if (strcasecmp(arg[1],thisDetector->detectorIP)) { - memset(thisDetector->detectorIP, 0, MAX_STR_LENGTH); - strcpy(thisDetector->detectorIP, arg[1]); - cprintf(RESET,"%d: Detector IP updated to %s\n", detId, thisDetector->detectorIP); - } - } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } else { + ret=FAIL; + } +#ifdef VERBOSE + std::cout<< "Id "<< mode <<" is " << retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Get id failed " << std::endl; + return ret; + } else + return retval; +} + + + +int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod) { + + int fnum= F_EXECUTE_TRIMMING; + int retval=FAIL; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; + int arg[3]; + arg[0]=imod; + arg[1]=par1; + arg[2]=par2; + + +#ifdef VERBOSE + std::cout<< "Trimming module " << imod << " with mode "<< mode << " parameters " + << par1 << " " << par2 << std::endl; +#endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); +#ifdef VERBOSE + std::cout<< "sending mode bytes= "<< controlSocket->SendDataOnly( + &mode,sizeof(mode)) << std::endl; +#endif + controlSocket->SendDataOnly(&mode,sizeof(mode)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } else { +#ifdef VERBOSE + std::cout<< "Detector trimmed "<< ret << std::endl; +#endif + /* + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + thisDetector->roFlags=retval; + */ + retval=ret; } disconnectControl(); if (ret==FORCE_UPDATE) updateDetector(); } } - if (ret==FAIL) { - ret=FAIL; - std::cout<< "Configuring MAC failed " << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - } - else if (thisDetector->myDetectorType==GOTTHARD){ - //set frames per file - only for gotthard - pthread_mutex_lock(&ms); - if(retval==-1) - setFramesPerFile(MAX_FRAMES_PER_FILE); - else - setFramesPerFile(SHORT_MAX_FRAMES_PER_FILE); - pthread_mutex_unlock(&ms); - //connect to receiver - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ + return retval; + +} + + + +int slsDetector::loadImageToDetector(imageType index,string const fname) { + + int ret=FAIL; + short int arg[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; + #ifdef VERBOSE - std::cout << "Sending adc val to receiver " << retval << std::endl; + std::cout<< std::endl<< "Loading "; + if(!index) + std::cout<<"Dark"; + else + std::cout<<"Gain"; + std::cout<<" image from file " << fname << std::endl; #endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum2,retval,retval); - disconnectData(); + + if(readDataFile(fname,arg)){ + ret = sendImageToDetector(index,arg); + return ret; + } + std::cout<< "Could not open file "<< fname << std::endl; + return ret; +} + + +int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) { + + int ret=FAIL; + int retval; + int fnum=F_LOAD_IMAGE; + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<<"Sending image to detector " <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&index,sizeof(index)); + controlSocket->SendDataOnly(imageVals,thisDetector->dataBytes); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; } - if(ret==FAIL) - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); } } @@ -7088,200 +5812,90 @@ int slsDetector::configureMAC(){ -//Corrections +int slsDetector::writeCounterBlockFile(string const fname,int startACQ) { - - - - - - -int slsDetector::getAngularConversion(int &direction, angleConversionConstant *angconv) { - direction=thisDetector->angDirection; - if (angconv) { - for (int imod=0; imodnMods; ++imod) { - (angconv+imod)->center=thisDetector->angOff[imod].center; - (angconv+imod)->r_conversion=thisDetector->angOff[imod].r_conversion; - (angconv+imod)->offset=thisDetector->angOff[imod].offset; - (angconv+imod)->ecenter=thisDetector->angOff[imod].ecenter; - (angconv+imod)->er_conversion=thisDetector->angOff[imod].er_conversion; - (angconv+imod)->eoffset=thisDetector->angOff[imod].eoffset; - } - } - if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) { - return 1; - } else { - return 0; - } -} - - - -int slsDetector::readAngularConversionFile(string fname) { - - return readAngularConversion(fname,thisDetector->nModsMax, thisDetector->angOff); - -} - -int slsDetector::readAngularConversion(ifstream& ifs) { - - return readAngularConversion(ifs,thisDetector->nModsMax, thisDetector->angOff); - -} - - -int slsDetector:: writeAngularConversion(string fname) { - - return writeAngularConversion(fname, thisDetector->nMods, thisDetector->angOff); - -} - - -int slsDetector:: writeAngularConversion(ofstream &ofs) { - - return writeAngularConversion(ofs, thisDetector->nMods, thisDetector->angOff); - -} - - - - - -int slsDetector::loadImageToDetector(imageType index,string const fname){ - - int ret=FAIL; - short int arg[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; + int ret=FAIL; + short int counterVals[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; #ifdef VERBOSE - std::cout<< std::endl<< "Loading "; - if(!index) - std::cout<<"Dark"; - else - std::cout<<"Gain"; - std::cout<<" image from file " << fname << std::endl; + std::cout<< std::endl<< "Reading Counter to \""<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(arg,thisDetector->dataBytes); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return ret; +} + + + + +int slsDetector::resetCounterBlock(int startACQ) { + + int ret=FAIL; + int fnum=F_RESET_COUNTER_BLOCK; + char mess[MAX_STR_LENGTH]=""; #ifdef VERBOSE - std::cout<<"Sending image to detector " <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - controlSocket->SendDataOnly(imageVals,thisDetector->dataBytes); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); + 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(); + } + } - return ret; -} -int slsDetector::getCounterBlock(short int arg[],int startACQ){ - - int ret=FAIL; - int fnum=F_READ_COUNTER_BLOCK; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(arg,thisDetector->dataBytes); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return ret; -} - - -int slsDetector::writeCounterBlockFile(string const fname,int startACQ){ - - int ret=FAIL; - short int counterVals[thisDetector->nChans*thisDetector->nChips*thisDetector->nMods]; - -#ifdef VERBOSE - std::cout<< std::endl<< "Reading Counter to \""<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&startACQ,sizeof(startACQ)); - 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(); - } - } - - return ret; -} - - - -int slsDetector::setCounterBit(int i){ +int slsDetector::setCounterBit(int i) { int fnum=F_SET_COUNTER_BIT; int ret = FAIL; int retval=-1; @@ -7319,302 +5933,692 @@ int slsDetector::setCounterBit(int i){ +int slsDetector::setROI(int n,ROI roiLimits[]) { + int ret = FAIL; + //sort ascending order + int temp; + + for(int i=0;imyDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + return ret; +} + + +slsDetectorDefs::ROI* slsDetector::getROI(int &n) { + sendROI(-1,NULL); + n=thisDetector->nROI; + if(thisDetector->myDetectorType==JUNGFRAUCTB) getTotalNumberOfChannels(); + return thisDetector->roiLimits; +} + +int slsDetector::getNRoi(){ + return thisDetector->nROI; +} + + +int slsDetector::sendROI(int n,ROI roiLimits[]) { + int ret=FAIL; + int fnum=F_SET_ROI; + char mess[MAX_STR_LENGTH]=""; + int arg = n; + int retvalsize=0; + ROI retval[MAX_ROIS]; + int nrec=-1; + if (roiLimits==NULL) + roiLimits=thisDetector->roiLimits; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + if(arg==-1){; +#ifdef VERBOSE + cout << "Getting ROI from detector" << endl; +#endif + }else{ +#ifdef VERBOSE + cout << "Sending ROI of size " << arg << " to detector" << endl; +#endif + controlSocket->SendDataOnly(roiLimits,arg*sizeof(ROI)); + } + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + + if (ret!=FAIL){ + controlSocket->ReceiveDataOnly(&retvalsize,sizeof(retvalsize)); + nrec = controlSocket->ReceiveDataOnly(retval,retvalsize*sizeof(ROI)); + if(nrec!=(retvalsize*(int)sizeof(ROI))){ + ret=FAIL; + std::cout << " wrong size received: received " << nrec << + "but expected " << retvalsize*sizeof(ROI) << endl; + } + }else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + //update client + if(ret!=FAIL){ + for(int i=0;iroiLimits[i]=retval[i]; + thisDetector->nROI = retvalsize; + } + + //#ifdef VERBOSE + for(int j=0;jnROI;++j) + cout<<"get"<< roiLimits[j].xmin<<"\t"<myDetectorType == EIGER) - std::cout << "Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2) << std::endl; + uint32_t arg[2]; + arg[0]=addr; + arg[1]=val; + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Writing to adc register "<< hex<onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } +#ifdef VERBOSE + std::cout<< "ADC Register returned "<< retval << std::endl; +#endif + if (ret==FAIL) { + std::cout<< "Write ADC to register failed " << std::endl; + setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); + } + return retval; + +} + + +int slsDetector::activate(int const enable) { + int fnum = F_ACTIVATE; + int fnum2 = F_RECEIVER_ACTIVATE; + int retval = -1; + int arg = enable; + char mess[MAX_STR_LENGTH]=""; + int ret = OK; + + if(thisDetector->myDetectorType != EIGER){ + std::cout<< "Not implemented for this detector" << std::endl; + setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); + return -1; + } + +#ifdef VERBOSE + if(!enable) + std::cout<< "Deactivating Detector" << std::endl; + else if(enable == -1) + std::cout<< "Getting Detector activate mode" << std::endl; + else + std::cout<< "Activating Detector" << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } +#ifdef VERBOSE + if(retval==1) + std::cout << "Detector Activated" << std::endl; + else if(retval==0) + std::cout << "Detector Deactivated" << std::endl; + else + std::cout << "Detector Activation unknown:" << retval << std::endl; +#endif + + if(ret!=FAIL){ + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Activating/Deactivating Receiver: " << retval << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum2,retval,retval); + disconnectData(); + } + if(ret==FAIL) + setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE)); + } + } +#ifdef VERBOSE + if(retval==1) + std::cout << "Receiver Activated" << std::endl; + else if(retval==0) + std::cout << "Receiver Deactivated" << std::endl; + else + std::cout << "Receiver Activation unknown:" << retval << std::endl; +#endif + + + return retval; + +} + + + + +int slsDetector::getFlippedData(dimension d=X) { + return thisDetector->flippedData[d]; +} + + + + + +int slsDetector::setFlippedData(dimension d, int value) { + int retval=-1; + int fnum=F_SET_FLIPPED_DATA_RECEIVER; + int ret=FAIL; + int args[2]={X,-1}; + + + if(thisDetector->myDetectorType!= EIGER){ + std::cout << "Flipped Data is not implemented in this detector" << std::endl; + setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); + return -1; + } + +#ifdef VERBOSE std::cout << std::endl; + std::cout << "Setting/Getting flipped data across axis " << d <<" with value " + << value << std::endl; +#endif + if(value > -1){ + thisDetector->flippedData[d] = value; + args[1] = value; + }else + args[1] = thisDetector->flippedData[d]; - return OK; + args[0] = d; + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (connectData() == OK){ + ret=thisReceiver->sendIntArray(fnum,retval,args); + + disconnectData(); + } + + if((args[1] != retval && args[1]>=0) || (ret==FAIL)){ + ret = FAIL; + setErrorMask((getErrorMask())|(RECEIVER_FLIPPED_DATA_NOT_SET)); + } + + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + + return thisDetector->flippedData[d]; } -int slsDetector::readConfigurationFile(string const fname){ +int slsDetector::setAllTrimbits(int val, int imod) { + int fnum=F_SET_ALL_TRIMBITS; + int retval; + char mess[MAX_STR_LENGTH]=""; + int ret=OK; - - - string ans; - string str; - ifstream infile; - //char *args[1000]; - - string sargname, sargval; #ifdef VERBOSE - int iline=0; - std::cout<< "config file name "<< fname << std::endl; + std::cout<< "Setting all trimbits to "<< val << std::endl; #endif - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { -#ifdef VERBOSE - iline=readConfigurationFile(infile); -#else - readConfigurationFile(infile); -#endif - infile.close(); - } else { - std::cout<< "Error opening configuration file " << fname << " for reading" << std::endl; - setErrorMask((getErrorMask())|(CONFIG_FILE)); - return FAIL; - } -#ifdef VERBOSE - std::cout<< "Read configuration file of " << iline << " lines" << std::endl; -#endif - return OK; + if (getDetectorsType() == MYTHEN) { + if (val>=0) { + setChannel((val<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan + } + return val; + } else { + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&val,sizeof(val)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET)); + } else { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + } +#ifdef VERBOSE + std::cout<< "All trimbits were set to "<< retval << std::endl; +#endif + return retval; } -int slsDetector::readConfigurationFile(ifstream &infile){ + +int slsDetector::enableGapPixels(int val) { + + if(val > 0 && thisDetector->myDetectorType!= EIGER) + val = -1; + + if (val >= 0) { + val=(val>0)?1:0; + + // send to receiver + int ret=OK; + int retval=-1; + int fnum=F_ENABLE_GAPPIXELS_IN_RECEIVER; + int arg=val; + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if((arg != retval) || (ret==FAIL)){ + ret = FAIL; + setErrorMask((getErrorMask())|(RECEIVER_ENABLE_GAPPIXELS_NOT_SET)); + } + + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + + // update client + if (ret == OK) { + thisDetector->gappixels = val; + thisDetector->dataBytesInclGapPixels = 0; + + if (thisDetector->dynamicRange != 4) { + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * + thisDetector->nChan[X] + thisDetector->gappixels * + thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + thisDetector->gappixels * + thisDetector->nGappixels[Y]) * + thisDetector->dynamicRange/8; + // set data bytes for other detector ( for future use) + if(thisDetector->myDetectorType==JUNGFRAUCTB) + getTotalNumberOfChannels(); + else if(thisDetector->myDetectorType==MYTHEN){ + if (thisDetector->dynamicRange==24 || + thisDetector->timerValue[PROBES_NUMBER]>0) { + thisDetector->dataBytesInclGapPixels = + (thisDetector->nMod[X] * thisDetector->nChip[X] * + thisDetector->nChan[X] + thisDetector->gappixels * + thisDetector->nGappixels[X]) * + (thisDetector->nMod[Y] * thisDetector->nChip[Y] * + thisDetector->nChan[Y] + thisDetector->gappixels * + thisDetector->nGappixels[Y]) * + 4; + } + } + } + } + } + + return thisDetector->gappixels; +} +int slsDetector::setTrimEn(int nen, int *en=NULL) { +{ + if (en) { + for (int ien=0; ientrimEnergies[ien]=en[ien]; + thisDetector->nTrimEn=nen; + } + return (thisDetector->nTrimEn); +} - slsDetectorCommand *cmd=new slsDetectorCommand(this); - - string ans; - string str; - int iargval; - int interrupt=0; - char *args[100]; - char myargs[1000][1000]; - - string sargname, sargval; - int iline=0; - while (infile.good() and interrupt==0) { - sargname="none"; - sargval="0"; - getline(infile,str); - ++iline; -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - if (str.find('#')!=string::npos) { -#ifdef VERBOSE - std::cout<< "Line is a comment " << std::endl; - std::cout<< str << std::endl; -#endif - continue; - } else if (str.length()<2) { -#ifdef VERBOSE - std::cout<< "Empty line " << std::endl; -#endif - continue; - } else { - istringstream ssstr(str); - iargval=0; - while (ssstr.good()) { - ssstr >> sargname; - //if (ssstr.good()) { -#ifdef VERBOSE - std::cout<< iargval << " " << sargname << std::endl; -#endif - strcpy(myargs[iargval],sargname.c_str()); - args[iargval]=myargs[iargval]; - ++iargval; - //} - } - ans=cmd->executeLine(iargval,args,PUT_ACTION); -#ifdef VERBOSE - std::cout<< ans << std::endl; -#endif - } - ++iline; - } - delete cmd; - return OK; +int slsDetector::getTrimEn(int *en=NULL) { + if (en) { + for (int ien=0; iennTrimEn; ien++) + en[ien]=thisDetector->trimEnergies[ien]; + } + return (thisDetector->nTrimEn);}; } +int slsDetector::pulsePixel(int n,int x,int y) { + int ret=FAIL; + int fnum=F_PULSE_PIXEL; + char mess[MAX_STR_LENGTH]=""; + int arg[3]; + arg[0] = n; arg[1] = x; arg[2] = y; - - - - - -int slsDetector::writeConfigurationFile(string const fname){ - - ofstream outfile; #ifdef VERBOSE - int ret; + std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times at (" << + x << "," << "y)" << endl << endl; #endif - outfile.open(fname.c_str(),ios_base::out); - if (outfile.is_open()) { -#ifdef VERBOSE - ret=writeConfigurationFile(outfile); -#else - writeConfigurationFile(outfile); -#endif - outfile.close(); - } - else { - std::cout<< "Error opening configuration file " << fname << " for writing" << std::endl; - setErrorMask((getErrorMask())|(CONFIG_FILE)); - return FAIL; - } -#ifdef VERBOSE - std::cout<< "wrote " <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return ret; } -int slsDetector::writeConfigurationFile(ofstream &outfile, int id){ -; - slsDetectorCommand *cmd=new slsDetectorCommand(this); - detectorType type = thisDetector->myDetectorType; - string names[100]; - int nvar=0; +int slsDetector::pulsePixelNMove(int n,int x,int y) { + int ret=FAIL; + int fnum=F_PULSE_PIXEL_AND_MOVE; + char mess[MAX_STR_LENGTH]=""; + int arg[3]; + arg[0] = n; arg[1] = x; arg[2] = y; - // common config - names[nvar++] = "hostname"; - names[nvar++] = "port"; - names[nvar++] = "stopport"; - names[nvar++] = "settingsdir"; - names[nvar++] = "caldir"; - names[nvar++] = "ffdir"; - names[nvar++] = "outdir"; - names[nvar++] = "angdir"; - names[nvar++] = "moveflag"; - names[nvar++] = "lock"; +#ifdef VERBOSE + std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times and move " + "by deltax:" << x << " deltay:" << y << endl << endl; +#endif - // receiver config - if (type != MYTHEN) { - names[nvar++] = "detectormac"; - names[nvar++] = "detectorip"; - names[nvar++] = "zmqport"; - names[nvar++] = "rx_zmqport"; - names[nvar++] = "zmqip"; - names[nvar++] = "rx_zmqip"; - names[nvar++] = "rx_tcpport"; - names[nvar++] = "rx_udpport"; - names[nvar++] = "rx_udpport2"; - names[nvar++] = "rx_udpip"; - names[nvar++] = "rx_hostname"; - names[nvar++] = "r_readfreq"; - } + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL_NMOVE)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } - // detector specific config - switch (type) { - case MYTHEN: - names[nvar++] = "nmod"; - names[nvar++] = "waitstates"; - names[nvar++] = "setlength"; - names[nvar++] = "clkdivider"; - names[nvar++] = "extsig"; - break; - case GOTTHARD: - case PROPIX: - names[nvar++] = "extsig"; - names[nvar++] = "vhighvoltage"; - break; - break; - case MOENCH: - names[nvar++] = "extsig"; - names[nvar++] = "vhighvoltage"; - break; - case EIGER: - names[nvar++] = "vhighvoltage"; - names[nvar++] = "trimen"; - names[nvar++] = "iodelay"; - names[nvar++] = "tengiga"; - break; - case JUNGFRAU: - names[nvar++] = "powerchip"; - names[nvar++] = "vhighvoltage"; - break; - case JUNGFRAUCTB: - names[nvar++] = "powerchip"; - names[nvar++] = "vhighvoltage"; - break; - default: - std::cout << "detector type " << getDetectorType(thisDetector->myDetectorType) << " not implemented in writing config file" << std::endl; - nvar = 0; - break; - } + return ret; +} - int nsig=4;//-1; - int iv=0; - char *args[100]; - char myargs[100][1000]; - - for (int ia=0; ia<100; ++ia) { - args[ia]=myargs[ia]; - } +int slsDetector::pulseChip(int n) { + int ret=FAIL; + int fnum=F_PULSE_CHIP; + char mess[MAX_STR_LENGTH]=""; - for (iv=0; iv=0) - outfile << id << ":"; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&n,sizeof(n)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_PULSE_CHIP)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } - outfile << args[0] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl; - } - } else { - strcpy(args[0],names[iv].c_str()); - if (id>=0) - outfile << id << ":"; - outfile << names[iv] << " " << cmd->executeLine(1,args,GET_ACTION) << std::endl; - } - } - - delete cmd; - return OK; + return ret; } +int slsDetector::setThresholdTemperature(int val, int imod) { + + int retval = -1; + int fnum = F_THRESHOLD_TEMP; + int ret = FAIL; + char mess[MAX_STR_LENGTH] = ""; + + int arg[2]; + arg[0]=val; + arg[1]=imod; + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " + << imod << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectStop() == OK){ + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); +#ifdef VERBOSE +std::cout<< "Threshold Temperature returned "<< retval << std::endl; +#endif + } else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } + disconnectStop(); + } + } + + return retval; +} + + + +int slsDetector::setTemperatureControl(int val, int imod) { + + int retval = -1; + int fnum = F_TEMP_CONTROL; + int ret = FAIL; + char mess[MAX_STR_LENGTH] = ""; + + int arg[2]; + arg[0]=val; + arg[1]=imod; + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " + << imod << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectStop() == OK){ + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); +#ifdef VERBOSE +std::cout<< "Threshold Temperature returned "<< retval << std::endl; +#endif + } else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } + disconnectStop(); + } + } + + return retval; +} +int slsDetector::setTemperatureEvent(int val, int imod) { + + int retval = -1; + int fnum = F_TEMP_EVENT; + int ret = FAIL; + char mess[MAX_STR_LENGTH] = ""; + + int arg[2]; + arg[0]=val; + arg[1]=imod; + + +#ifdef VERBOSE + std::cout<< std::endl; + std::cout<< "Setting/Getting Threshold Temperature to "<< val << " of module " + << imod << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectStop() == OK){ + stopSocket->SendDataOnly(&fnum,sizeof(fnum)); + stopSocket->SendDataOnly(arg,sizeof(arg)); + stopSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + stopSocket->ReceiveDataOnly(&retval,sizeof(retval)); +#ifdef VERBOSE +std::cout<< "Threshold Temperature returned "<< retval << std::endl; +#endif + } else { + stopSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(TEMPERATURE_CONTROL)); + } + disconnectStop(); + } + } + + return retval; +} +int slsDetector::setStoragecellStart(int pos) { + int ret=FAIL; + int fnum=F_STORAGE_CELL_START; + char mess[MAX_STR_LENGTH]; + memset(mess, 0, MAX_STR_LENGTH); + int retval=-1; + +#ifdef VERBOSE + std::cout<< "Sending storage cell start index " << pos << endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&pos,sizeof(pos)); + //check opening error + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(STORAGE_CELL_START)); + }else + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return retval; +} - -int slsDetector::writeSettingsFile(string fname, int imod, int iodelay, int tau){ - - return writeSettingsFile(fname,thisDetector->myDetectorType, detectorModules[imod], iodelay, tau); - -}; - - - - -int slsDetector::programFPGA(string fname){ +int slsDetector::programFPGA(string fname) { int ret=FAIL; int fnum=F_PROGRAM_FPGA; char mess[MAX_STR_LENGTH]=""; size_t filesize=0; char* fpgasrc = NULL; - if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB){ + if(thisDetector->myDetectorType != JUNGFRAU && + thisDetector->myDetectorType != JUNGFRAUCTB){ std::cout << "Not implemented for this detector" << std::endl; return FAIL; } @@ -7631,33 +6635,34 @@ int slsDetector::programFPGA(string fname){ // open src FILE* src = fopen(fname.c_str(),"rb"); if (src == NULL) { - std::cout << "Could not open source file for programming: " << fname << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; + std::cout << "Could not open source file for programming: " << fname << std::endl; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; } // create temp destination file char destfname[] = "/tmp/Jungfrau_MCB.XXXXXX"; int dst = mkstemp(destfname); // create temporary file and open it in r/w if (dst == -1) { - std::cout << "Could not create destination file in /tmp for programming: " << destfname << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; + std::cout << "Could not create destination file in /tmp for programming: " + << destfname << std::endl; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; } // convert src to dst rawbin #ifdef VERBOSE - std::cout << "Converting " << fname << " to " << destfname << std::endl; + std::cout << "Converting " << fname << " to " << destfname << std::endl; #endif - int filepos,x,y,i; + int filepos,x,y,i; // Remove header (0...11C) for (filepos=0; filepos < 0x11C; ++filepos) fgetc(src); // Write 0x80 times 0xFF (0...7F) { - char c = 0xFF; - for (filepos=0; filepos < 0x80; ++filepos) - write(dst, &c, 1); + char c = 0xFF; + for (filepos=0; filepos < 0x80; ++filepos) + write(dst, &c, 1); } // Swap bits and write to file for (filepos=0x80; filepos < 0x1000000; ++filepos) { @@ -7669,20 +6674,21 @@ int slsDetector::programFPGA(string fname){ write(dst, &y, 1); } if (filepos < 0x1000000){ - std::cout << "Could not convert programming file. EOF before end of flash" << std::endl; + std::cout << "Could not convert programming file. EOF before end of flash" + << std::endl; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); return FAIL; } if(fclose(src)){ - std::cout << "Could not close source file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; + std::cout << "Could not close source file" << std::endl; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; + } + if(close(dst)){ + std::cout << "Could not close destination file" << std::endl; + setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); + return FAIL; } - if(close(dst)){ - std::cout << "Could not close destination file" << std::endl; - setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); - return FAIL; - } #ifdef VERBOSE std::cout << "File has been converted to " << destfname << std::endl; #endif @@ -7752,7 +6758,8 @@ int slsDetector::programFPGA(string fname){ std::cout<< "This can take awhile. Please be patient..." << endl; printf("Erasing Flash:%d%%\r",0); std::cout << flush; - //erasing takes 65 seconds, printing here (otherwise need threads in server-unnecessary) + //erasing takes 65 seconds, printing here (otherwise need threads + //in server-unnecessary) int count = 66; while(count>0){ usleep(1 * 1000 * 1000); @@ -7776,7 +6783,8 @@ int slsDetector::programFPGA(string fname){ if(unitprogramsize > filesize) //less than 2mb unitprogramsize = filesize; #ifdef VERBOSE - std::cout << "unitprogramsize:" << unitprogramsize << "\t filesize:" << filesize << std::endl; + std::cout << "unitprogramsize:" << unitprogramsize << "\t filesize:" + << filesize << std::endl; #endif controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize); controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -7785,7 +6793,8 @@ int slsDetector::programFPGA(string fname){ currentPointer+=unitprogramsize; //print progress - printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100)); + printf("Writing to Flash:%d%%\r", + (int) (((double)(totalsize-filesize)/totalsize)*100)); std::cout << flush; }else{ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); @@ -7844,7 +6853,7 @@ int slsDetector::programFPGA(string fname){ } -int slsDetector::resetFPGA(){ +int slsDetector::resetFPGA() { int ret=FAIL; int fnum=F_RESET_FPGA; char mess[MAX_STR_LENGTH]=""; @@ -7877,13 +6886,14 @@ int slsDetector::resetFPGA(){ -int slsDetector::powerChip(int ival){ +int slsDetector::powerChip(int ival) { int ret=FAIL; int fnum=F_POWER_CHIP; char mess[MAX_STR_LENGTH]=""; int retval=-1; - if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB ){ + if(thisDetector->myDetectorType != JUNGFRAU && + thisDetector->myDetectorType != JUNGFRAUCTB ){ std::cout << "Not implemented for this detector" << std::endl; return FAIL; } @@ -7912,371 +6922,1113 @@ int slsDetector::powerChip(int ival){ } -int slsDetector::setAutoComparatorDisableMode(int ival){ - int ret=FAIL; - int fnum=F_AUTO_COMP_DISABLE; - char mess[MAX_STR_LENGTH]=""; - int retval=-1; - - if(thisDetector->myDetectorType != JUNGFRAU){ - std::cout << "Not implemented for this detector" << std::endl; - return FAIL; - } -#ifdef VERBOSE - std::cout<< "Enabling/disabling Auto comp disable mode " << endl; -#endif - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&ival,sizeof(ival)); - //check opening error - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(AUTO_COMP_DISABLE)); - }else - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - return retval; - -} - - -int slsDetector::loadSettingsFile(string fname, int imod) { - - sls_detector_module *myMod=NULL; - - int iodelay = -1; - int tau = -1; - - string fn=fname; - fn=fname; - int mmin=0, mmax=setNumberOfModules(); - if (imod>=0) { - mmin=imod; - mmax=imod+1; - } - for (int im=mmin; immyDetectorType) { - case MYTHEN: - if (fname.find(".sn")==string::npos && fname.find(".trim")==string::npos && fname.find(".settings")==string::npos) { - ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im); - } - break; - case EIGER: - if (fname.find(".sn")==string::npos && fname.find(".trim")==string::npos && fname.find(".settings")==string::npos) { - ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER, im); - } - break; - default: - break; - } - fn=ostfn.str(); - myMod=readSettingsFile(fn, thisDetector->myDetectorType,iodelay, tau, myMod); - - if (myMod) { - myMod->module=im; - //settings is saved in myMod.reg for all except mythen - if(thisDetector->myDetectorType!=MYTHEN) - myMod->reg=-1; - setModule(*myMod,iodelay,tau,-1,0,0); - deleteModule(myMod); - } else - return FAIL; - } - return OK; -} - - -int slsDetector::saveSettingsFile(string fname, int imod) { - - sls_detector_module *myMod=NULL; - int ret=FAIL; - int iodelay = -1; - int tau = -1; - - int mmin=0, mmax=setNumberOfModules(); - if (imod>=0) { - mmin=imod; - mmax=imod+1; - } - for (int im=mmin; immyDetectorType) { - case MYTHEN: - ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im); - break; - case EIGER: - ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER); - break; - default: - break; - } - fn=ostfn.str(); - if ((myMod=getModule(im))) { - - if(thisDetector->myDetectorType == EIGER){ - iodelay = (int)setDAC((dacs_t)-1,IO_DELAY,0,-1); - tau = (int64_t)getRateCorrectionTau(); - } - ret=writeSettingsFile(fn, thisDetector->myDetectorType, *myMod, iodelay, tau); - deleteModule(myMod); - } - } - return ret; -} - - - -int slsDetector::setAllTrimbits(int val, int imod){ - int fnum=F_SET_ALL_TRIMBITS; - int retval; +int slsDetector::setAutoComparatorDisableMode(int ival) { + int ret=FAIL; + int fnum=F_AUTO_COMP_DISABLE; char mess[MAX_STR_LENGTH]=""; - int ret=OK; + int retval=-1; + + if(thisDetector->myDetectorType != JUNGFRAU){ + std::cout << "Not implemented for this detector" << std::endl; + return FAIL; + } +#ifdef VERBOSE + std::cout<< "Enabling/disabling Auto comp disable mode " << endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&ival,sizeof(ival)); + //check opening error + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(AUTO_COMP_DISABLE)); + }else + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return retval; + +} + + + +int slsDetector::getChanRegs(double* retval,bool fromDetector) { + int n=getTotalNumberOfChannels(); + if(fromDetector){ + for(int im=0;im=0) { - setChannel((val<<((int)TRIMBIT_OFF))|((int)COMPARATOR_ENABLE)); // trimbit scan - } - return val; - } else { - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&val,sizeof(val)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(ALLTIMBITS_NOT_SET)); - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - } + int charegs[thisDetector->nChans*thisDetector->nChips]; + int chiregs[thisDetector->nChips]; + dacs_t das[thisDetector->nDacs], ads[thisDetector->nAdcs]; + int mmin=imod, mmax=imod+1; + int ret=FAIL; + + if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; + } + + + + for (int im=mmin; imnChans; + myModule.nchip=thisDetector->nChips; + myModule.ndac=thisDetector->nDacs; + myModule.nadc=thisDetector->nAdcs; + + myModule.reg=reg; + if (detectorModules) { + myModule.gain=(detectorModules+im)->gain; + myModule.offset=(detectorModules+im)->offset; + myModule.serialnumber=(detectorModules+im)->serialnumber; + } else { + myModule.gain=-1; + myModule.offset=-1; + myModule.serialnumber=-1; + } + + + for (int i=0; inAdcs; ++i) + ads[i]=-1; + + if (chanregs) + myModule.chanregs=chanregs+im*thisDetector->nChips*thisDetector->nChans; + else { + for (int i=0; inChans*thisDetector->nChips; ++i) + charegs[i]=-1; + myModule.chanregs=charegs; + } + if (chipregs) + myModule.chipregs=chanregs+im*thisDetector->nChips; + else { + for (int ichip=0; ichipnChips; ++ichip) + chiregs[ichip]=-1; + myModule.chipregs=chiregs; + } + if (dacs) + myModule.dacs=dacs+im*thisDetector->nDacs; + else { + for (int i=0; inDacs; ++i) + das[i]=-1; + myModule.dacs=das; + } + if (adcs) + myModule.adcs=adcs+im*thisDetector->nAdcs; + else { + for (int i=0; inAdcs; ++i) + ads[i]=-1; + myModule.adcs=ads; + } + ret=setModule(myModule,-1,-1,-1,0,0); + } + return ret; + + +} + +int slsDetector::setModule(sls_detector_module module, int iodelay, int tau, + int e_eV, int* gainval, int* offsetval, int tb) { + + int fnum=F_SET_MODULE; + int retval=-1; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + int imod=module.module; + #ifdef VERBOSE - std::cout<< "All trimbits were set to "<< retval << std::endl; + std::cout << "slsDetector set module " << std::endl; #endif + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + //to exclude trimbits + if(!tb) { + module.nchan=0; + module.nchip=0; + } + sendModule(&module); + + //not included in module + if(gainval && (thisDetector->nGain)) + controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); + if(offsetval && (thisDetector->nOffset)) + controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); + if(thisDetector->myDetectorType == EIGER) { + controlSocket->SendDataOnly(&iodelay,sizeof(iodelay)); + controlSocket->SendDataOnly(&tau,sizeof(tau)); + controlSocket->SendDataOnly(&e_eV,sizeof(e_eV)); + } + + + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + if(strstr(mess,"default tau")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + + if (ret!=FAIL) { + if (detectorModules) { + if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { + if(tb) { + (detectorModules+imod)->nchan=module.nchan; + (detectorModules+imod)->nchip=module.nchip; + } + (detectorModules+imod)->ndac=module.ndac; + (detectorModules+imod)->nadc=module.nadc; + if(tb) { + thisDetector->nChips=module.nchip; + thisDetector->nChans=module.nchan/module.nchip; + } + thisDetector->nDacs=module.ndac; + thisDetector->nAdcs=module.nadc; + + if(thisDetector->myDetectorType != JUNGFRAU){ + if(tb) { + for (int ichip=0; ichipnChips; ++ichip) { + if (chipregs) + chipregs[ichip+thisDetector->nChips*imod]= + module.chipregs[ichip]; + + if (chanregs) { + for (int i=0; inChans; ++i) { + chanregs[i+ichip* + thisDetector->nChans+ + thisDetector->nChips*thisDetector->nChans* + imod]=module.chanregs[ichip*thisDetector->nChans+i]; + } + } + } + } + if (adcs) { + for (int i=0; inAdcs; ++i) + adcs[i+imod*thisDetector->nAdcs]=module.adcs[i]; + } + } + + if (dacs) { + for (int i=0; inDacs; ++i) + dacs[i+imod*thisDetector->nDacs]=module.dacs[i]; + } + + (detectorModules+imod)->gain=module.gain; + (detectorModules+imod)->offset=module.offset; + (detectorModules+imod)->serialnumber=module.serialnumber; + (detectorModules+imod)->reg=module.reg; + } + } + + if ((thisDetector->nGain) && (gainval) && (gain)) { + for (int i=0; inGain; ++i) + gain[i+imod*thisDetector->nGain]=gainval[i]; + } + + if ((thisDetector->nOffset) && (offsetval) && (offset)) { + for (int i=0; inOffset; ++i) + offset[i+imod*thisDetector->nOffset]=offsetval[i]; + } + + if (e_eV != -1) + thisDetector->currentThresholdEV = e_eV; + + } + +#ifdef VERBOSE + std::cout<< "Module register returned "<< retval << std::endl; +#endif + return retval; } -int slsDetector::loadCalibrationFile(string fname, int imod) { - if(thisDetector->myDetectorType == EIGER) { - std::cout << "Not required for this detector!" << std::endl; - return FAIL; +slsDetectorDefs::sls_detector_module *slsDetector::getModule(int imod) { + +#ifdef VERBOSE + std::cout << "slsDetector get module " << std::endl; +#endif + + int fnum=F_GET_MODULE; + sls_detector_module *myMod=createModule(); + + int* gainval=0, *offsetval=0; + if(thisDetector->nGain) + gainval=new int[thisDetector->nGain]; + if(thisDetector->nOffset) + offsetval=new int[thisDetector->nOffset]; + + //char *ptr, *goff=(char*)thisDetector; + + // int chanreg[thisDetector->nChans*thisDetector->nChips]; + //int chipreg[thisDetector->nChips]; + //double dac[thisDetector->nDacs], adc[thisDetector->nAdcs]; + + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + // int n; + +#ifdef VERBOSE + std::cout<< "getting module " << imod << std::endl; +#endif + + myMod->module=imod; + // myMod.nchan=thisDetector->nChans*thisDetector->nChips; + //myMod.chanregs=chanreg; + //myMod.nchip=thisDetector->nChips; + //myMod.chipregs=chipreg; + //myMod.ndac=thisDetector->nDacs; + //myMod.dacs=dac; + //myMod.ndac=thisDetector->nAdcs; + //myMod.dacs=adc; + + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&imod,sizeof(imod)); + + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + receiveModule(myMod); + + //extra gain and offset - eiger + if(thisDetector->nGain) + controlSocket->ReceiveDataOnly(gainval,sizeof(int)*thisDetector->nGain); + if(thisDetector->nOffset) + controlSocket->ReceiveDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } } - sls_detector_module *myMod=NULL; - string fn=fname; - int* gainval=0; int* offsetval=0; - if(thisDetector->nGain){ - gainval=new int[thisDetector->nGain]; - for(int i=0;inGain;++i) - gainval[i] = -1; - } - if(thisDetector->nOffset){ - offsetval=new int[thisDetector->nOffset]; - for(int i=0;inOffset;++i) - offsetval[i] = -1; - } + if (ret!=FAIL) { + if (detectorModules) { + if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { + (detectorModules+imod)->nchan=myMod->nchan; + (detectorModules+imod)->nchip=myMod->nchip; + (detectorModules+imod)->ndac=myMod->ndac; + (detectorModules+imod)->nadc=myMod->nadc; + thisDetector->nChips=myMod->nchip; + thisDetector->nChans=myMod->nchan/myMod->nchip; + thisDetector->nDacs=myMod->ndac; + thisDetector->nAdcs=myMod->nadc; - fn=fname; + if(thisDetector->myDetectorType != JUNGFRAU){ + for (int ichip=0; ichipnChips; ++ichip) { + if (chipregs) + chipregs[ichip+thisDetector->nChips*imod]= + myMod->chipregs[ichip]; + + if (chanregs) { + for (int i=0; inChans; ++i) { + chanregs[i+ichip*thisDetector->nChans+ + thisDetector->nChips*thisDetector->nChans*imod]= + myMod->chanregs[ichip*thisDetector->nChans+i]; + } + } + } + + if (adcs) { + for (int i=0; inAdcs; ++i) + adcs[i+imod*thisDetector->nAdcs]=myMod->adcs[i]; + } + } + + if (dacs) { + for (int i=0; inDacs; ++i) { + dacs[i+imod*thisDetector->nDacs]=myMod->dacs[i]; + //cprintf(BLUE,"dac%d:%d\n",i, myMod->dacs[i]); + } + } + (detectorModules+imod)->gain=myMod->gain; + (detectorModules+imod)->offset=myMod->offset; + (detectorModules+imod)->serialnumber=myMod->serialnumber; + (detectorModules+imod)->reg=myMod->reg; + } + } + + if ((thisDetector->nGain) && (gainval) && (gain)) { + for (int i=0; inGain; ++i) + gain[i+imod*thisDetector->nGain]=gainval[i]; + } + + if ((thisDetector->nOffset) && (offsetval) && (offset)) { + for (int i=0; inOffset; ++i) + offset[i+imod*thisDetector->nOffset]=offsetval[i]; + } + + } else { + deleteModule(myMod); + myMod=NULL; + } + + if(gainval) delete[]gainval; + if(offsetval) delete[]offsetval; + + return myMod; +} - int mmin=0, mmax=setNumberOfModules(); - if (imod>=0) { - mmin=imod; - mmax=imod+1; - } - for (int im=mmin; immyDetectorType) { - case MYTHEN: - if (fname.find(".sn")==string::npos && fname.find(".cal")==string::npos) { - ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im); - } - break; - case EIGER: - if (fname.find(".sn")==string::npos && fname.find(".cal")==string::npos) { - ostfn << "." << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER); - } - break; - default: - break; - } - fn=ostfn.str(); - if((myMod=getModule(im))){ - //extra gain and offset - if(thisDetector->nGain){ - if(readCalibrationFile(fn, gainval, offsetval)==FAIL) - return FAIL; - } //normal gain and offset inside sls_detector_module - else{ - if(readCalibrationFile(fn,myMod->gain, myMod->offset)==FAIL) - return FAIL; + + +int slsDetector::setChannel(int64_t reg, int ichan, int ichip, int imod) { + sls_detector_channel myChan; +#ifdef VERBOSE + std::cout<< "Setting channel "<< ichan << " " << ichip << " " << imod << + " to " << reg << std::endl; +#endif + //int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, + //chamax=ichan+1; + + int ret; + + /* if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; } - setModule(*myMod,-1,-1,-1,gainval,offsetval); - deleteModule(myMod); - if(gainval) delete[]gainval; - if(offsetval) delete[] offsetval; - } else - return FAIL; - } - return OK; -} - - -int slsDetector::saveCalibrationFile(string fname, int imod) { - - - sls_detector_module *myMod=NULL; - int ret=FAIL; - - int mmin=0, mmax=setNumberOfModules(); - if (imod>=0) { - mmin=imod; - mmax=imod+1; - } - for (int im=mmin; immyDetectorType) { - case MYTHEN: - ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER,im); - break; - case EIGER: - ostfn << ".sn" << setfill('0') << setw(3) << dec << getId(DETECTOR_SERIAL_NUMBER); - break; - default: - break; - } - fn=ostfn.str(); - if ((myMod=getModule(im))) { - //extra gain and offset - if(thisDetector->nGain) - ret=writeCalibrationFile(fn,gain, offset); - //normal gain and offset inside sls_detector_module - else - ret=writeCalibrationFile(fn,myMod->gain, myMod->offset); - - deleteModule(myMod); - }else - return FAIL; - } - return ret; -} - - - - -/* returns if the detector is Master, slave or nothing - \param flag can be GET_MASTER, NO_MASTER, IS_MASTER, IS_SLAVE - \returns master flag of the detector -*/ -slsDetectorDefs::masterFlags slsDetector::setMaster(masterFlags flag) { - - - int fnum=F_SET_MASTER; - masterFlags retval=GET_MASTER; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; - -#ifdef VERBOSE - std::cout<< "Setting master flags to "<< flag << std::endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&flag,sizeof(flag)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + if (ichip==-1) { + chimin=0; + chimax=thisDetector->nChips; } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + if (ichan==-1) { + chamin=0; + chamax=thisDetector->nChans; + }*/ + + // for (int im=mmin; imonlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + sendChannel(&chan); + + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + + if (ret!=FAIL) { + if (chanregs) { + + int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1, chamin=ichan, + chamax=ichan+1; + + if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; + } + + if (ichip==-1) { + chimin=0; + chimax=thisDetector->nChips; + } + + if (ichan==-1) { + chamin=0; + chamax=thisDetector->nChans; + } + + + + + + + for (int im=mmin; imnChans* + thisDetector->nChips+ichi*thisDetector->nChips+icha)=retval; + + } + } + } + + } + } #ifdef VERBOSE - std::cout<< "Master flag set to "<< retval << std::endl; + std::cout<< "Channel register returned "<< retval << std::endl; #endif - return retval; + return retval; + } -/* - Sets/gets the synchronization mode of the various detectors - \param sync syncronization mode can be GET_SYNCHRONIZATION_MODE, NO_SYNCHRONIZATION, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS - \returns current syncronization mode -*/ -slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchronizationMode flag) { + +slsDetectorDefs::sls_detector_channel slsDetector::getChannel(int ichan, int ichip, + int imod) { + int fnum=F_GET_CHANNEL; + sls_detector_channel myChan; + int arg[3]; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + arg[0]=ichan; + arg[1]=ichip; + arg[2]=imod; + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); - int fnum=F_SET_SYNCHRONIZATION_MODE; - synchronizationMode retval=GET_SYNCHRONIZATION_MODE; - char mess[MAX_STR_LENGTH]=""; - int ret=OK; + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + receiveChannel(&myChan); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + + if (ret!=FAIL) { + if (chanregs) { + *(chanregs+imod*thisDetector->nChans*thisDetector->nChips+ichip* + thisDetector->nChips+ichan)=myChan.reg; + } + } #ifdef VERBOSE - std::cout<< "Setting synchronization mode to "<< flag << std::endl; + std::cout<< "Returned channel "<< ichan << " " << ichip << " " << imod << " " + << myChan.reg << std::endl; #endif + return myChan; +} - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&flag,sizeof(flag)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } else { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + + +int slsDetector::setChip(int reg, int ichip, int imod) { + sls_detector_chip myChip; #ifdef VERBOSE - std::cout<< "Readout flag set to "<< retval << std::endl; + std::cout<< "Setting chip "<< ichip << " " << imod << " to " << reg << std::endl; #endif - return retval; + + int chregs[thisDetector->nChans]; + int mmin=imod, mmax=imod+1, chimin=ichip, chimax=ichip+1; + int ret=FAIL; + if (imod==-1) { + mmin=0; + mmax=thisDetector->nModsMax; + } + + if (ichip==-1) { + chimin=0; + chimax=thisDetector->nChips; + } + + myChip.nchan=thisDetector->nChans; + myChip.reg=reg; + for (int im=mmin; imnChans+im* + thisDetector->nChans*thisDetector->nChips); + else { + for (int i=0; inChans; ++i) + chregs[i]=-1; + myChip.chanregs=chregs; + } + ret=setChip(myChip); + } + } + return ret; +} + +int slsDetector::setChip(sls_detector_chip chip) { + + int fnum=F_SET_CHIP; + int retval; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + int ichi=chip.chip; + int im=chip.module; + + + + + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + sendChip(&chip); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + + if (ret!=FAIL) { + if (chipregs) + *(chipregs+ichi+im*thisDetector->nChips)=retval; + } + +#ifdef VERBOSE + std::cout<< "Chip register returned "<< retval << std::endl; +#endif + return retval; +} + + +slsDetectorDefs::sls_detector_chip slsDetector::getChip(int ichip, int imod) { + + int fnum=F_GET_CHIP; + sls_detector_chip myChip; + int chanreg[thisDetector->nChans]; + + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + + myChip.chip=ichip; + myChip.module=imod; + myChip.nchan=thisDetector->nChans; + myChip.chanregs=chanreg; + + int arg[2]; + arg[0]=ichip; + arg[1]=imod; + + + + + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + receiveChip(&myChip); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + + if (ret!=FAIL) { + if (chipregs) + *(chipregs+ichip+imod*thisDetector->nChips)=myChip.reg; + if (chanregs) { + for (int ichan=0; ichannChans; ++ichan) + *(chanregs+imod*thisDetector->nChans*thisDetector->nChips+ichip* + thisDetector->nChans+ichan)=*((myChip.chanregs)+ichan); + } + } +#ifdef VERBOSE + std::cout<< "Returned chip "<< ichip << " " << imod << " " << myChip.reg << std::endl; +#endif + + return myChip; +} + + + +int slsDetector::getMoveFlag(int imod) { + if (moveFlag) + return *moveFlag; + else return 1; +} + + +int slsDetector::fillModuleMask(int *mM) { + if (mM) + for (int i=0; ionlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&frames,sizeof(frames)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return retval; +} + + + +int slsDetector::setRateCorrection(double t) { + + if (getDetectorsType() == EIGER){ + int fnum=F_SET_RATE_CORRECT; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int64_t arg = t; + +#ifdef VERBOSE + std::cout<< "Setting Rate Correction to " << arg << endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + if(strstr(mess,"default tau")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); + if(strstr(mess,"32")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); + else + setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + return ret; //only success/fail + } + + + //mythen + double tdead[]=defaultTDead; + if (t==0) { +#ifdef VERBOSE + std::cout<< "unsetting rate correction" << std::endl; +#endif + thisDetector->correctionMask&=~(1<correctionMask|=(1<0) + thisDetector->tDead=t; + else { + if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1) + thisDetector->tDead=tdead[thisDetector->currentSettings]; + else + thisDetector->tDead=0; + } +#ifdef VERBOSE + std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead + << std::endl; +#endif + } + return thisDetector->correctionMask&(1<myDetectorType == EIGER){ + t = getRateCorrectionTau(); + return t; + } + + if (thisDetector->correctionMask&(1<tDead << std::endl; +#endif + t=thisDetector->tDead; + return 1; + } else + t=0; +#ifdef VERBOSE + std::cout<< "Rate correction is disabled " << std::endl; +#endif + return 0; +}; + +double slsDetector::getRateCorrectionTau() { + + if(thisDetector->myDetectorType == EIGER){ + int fnum=F_GET_RATE_CORRECT; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + int64_t retval = -1; +#ifdef VERBOSE + std::cout<< "Setting Rate Correction to " << arg << endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return double(retval); + } + + + //mythen only + if (thisDetector->correctionMask&(1<tDead << std::endl; +#endif + return thisDetector->tDead; + //return 1; + } else +#ifdef VERBOSE + std::cout<< "Rate correction is disabled " << std::endl; +#endif + return 0; +} + + +int slsDetector::getRateCorrection() { + + if (thisDetector->myDetectorType == EIGER){ + double t = getRateCorrectionTau(); + return (int)t; + } + + if (thisDetector->correctionMask&(1<tDead; + double t=thisDetector->timerValue[ACQUISITION_TIME]; + // double data; + double e; + if (thisDetector->correctionMask&(1<nMod[X]*thisDetector->nMod[Y]* + thisDetector->nChans*thisDetector->nChips; ++ichan) { + + if (errin==NULL) { + e=sqrt(datain[ichan]); + } else + e=errin[ichan]; + + postProcessingFuncs::rateCorrect(datain[ichan], e, dataout[ichan], + errout[ichan], tau, t); + } + } + + return 0; +} + + + +int slsDetector::setFlatFieldCorrection(string fname) { + double data[thisDetector->nModMax[X]*thisDetector->nModMax[Y]* + thisDetector->nChans*thisDetector->nChips]; + int im=0; + int nch; + thisDetector->nBadFF=0; + + char ffffname[MAX_STR_LENGTH*2]; + if (fname=="default") { + fname=string(thisDetector->flatFieldFile); + } + + if (fname=="") { +#ifdef VERBOSE + std::cout<< "disabling flat field correction" << std::endl; +#endif + thisDetector->correctionMask&=~(1<flatFieldDir,fname.c_str()); + nch=readDataFile(string(ffffname),data); + if (nch>0) { + + //???? bad ff chans? + int nm=getNMods(); + int chpm[nm]; + int mMask[nm]; + for (int i=0; i=0) { + strcpy(thisDetector->flatFieldFile,fname.c_str()); + + + thisDetector->correctionMask|=(1<correctionMask&(1<nMod[Y]*thisDetector->nMod[X]* + thisDetector->nChans*thisDetector->nChips; ++ichan) { + // #ifdef VERBOSE + // std::cout<< ichan << " "<< corr[ichan] << std::endl; + // #endif + ffcoefficients[ichan]=corr[ichan]; + if (ecorr!=NULL) + fferrors[ichan]=ecorr[ichan]; + else + fferrors[ichan]=1; + + cout << ichan << " " << ffcoefficients[ichan] << endl; + } + thisDetector->correctionMask|=(1<correctionMask&=~(1<correctionMask)& + (1<correctionMask&(1<correctionMask&(1<nMod[X]*thisDetector->nMod[Y]* + thisDetector->nChans*thisDetector->nChips; ++ichan) { + corr[ichan]=ffcoefficients[ichan]; + if (ecorr) { + //ecorr[ichan]=ffcoefficients[ichan]/fferrors[ichan]; + ecorr[ichan]=fferrors[ichan]; + } + } + } + return 1; + } else { +#ifdef VERBOSE + std::cout<< "Flat field correction is disabled" << std::endl; +#endif + if (corr) + for (int ichan=0; ichannMod[X]*thisDetector->nMod[Y]* + thisDetector->nChans*thisDetector->nChips; ++ichan) { + corr[ichan]=1; + if (ecorr) + ecorr[ichan]=0; + } + return 0; + } + +} + + + +int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout, + double *errout) { +#ifdef VERBOSE + std::cout<< "Flat field correcting data" << std::endl; +#endif + double e, eo; + if (thisDetector->correctionMask & (1<nMod[X]*thisDetector->nChans* + thisDetector->nChips; ++ichan) { + if (errin==NULL) { + e=0; + } else { + e=errin[ichan]; + } + postProcessingFuncs::flatFieldCorrect(datain[ichan],e,dataout[ichan], + eo,ffcoefficients[ichan],fferrors[ichan]); + if (errout) + errout[ichan]=eo; + } + } + return 0; + +} + + + + +int slsDetector::setBadChannelCorrection(string fname) { + + // int nbadmod; + int ret=0; + //int badchanlist[MAX_BADCHANS]; + //int off; + + string fn=fname; + + if (fname=="default") + fname=string(badChanFile); + + if (nBadChans && badChansList) + ret=setBadChannelCorrection(fname, *nBadChans, badChansList); + + if (ret) { + *correctionMask|=(1<0) { + thisDetector->correctionMask|=(1<nBadChans=0; + for (int ich=0 ;ich=0 && chs[ich]badChansList[ich]=chs[ich]; + ++thisDetector->nBadChans; + } + } + } else + thisDetector->correctionMask&=~(1<0) { + thisDetector->nBadFF=nch; + for (int ich=0 ;ichbadFFList[ich]=chs[ich]; + } + } + } +#ifdef VERBOSE + cout << "badchans flag is "<< (thisDetector->correctionMask& + (1<< DISCARD_BAD_CHANNELS)) << endl; +#endif + // fillBadChannelMask(); + if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) { + return thisDetector->nBadChans+thisDetector->nBadFF; + } else + return 0; + +} + + +int slsDetector::getBadChannelCorrection(int *bad) { + int ichan; + if (thisDetector->correctionMask&(1<< DISCARD_BAD_CHANNELS)) { + if (bad) { + for (ichan=0; ichannBadChans; ++ichan) + bad[ichan]=thisDetector->badChansList[ichan]; + for (int ich=0; ichnBadFF; ++ich) + bad[ichan+ich]=thisDetector->badFFList[ich]; + } + return thisDetector->nBadChans+thisDetector->nBadFF; + } else + return 0; +} + + +int slsDetector::readAngularConversionFile(string fname) { + + return readAngularConversion(fname,thisDetector->nModsMax, thisDetector->angOff); + +} + +int slsDetector::readAngularConversion(ifstream& ifs) { + + return readAngularConversion(ifs,thisDetector->nModsMax, thisDetector->angOff); + +} + + +int slsDetector:: writeAngularConversion(string fname) { + + return writeAngularConversion(fname, thisDetector->nMods, thisDetector->angOff); + +} + + +int slsDetector:: writeAngularConversion(ofstream &ofs) { + + return writeAngularConversion(ofs, thisDetector->nMods, thisDetector->angOff); + +} + +int slsDetector::getAngularConversion(int &direction, angleConversionConstant *angconv) { + direction=thisDetector->angDirection; + if (angconv) { + for (int imod=0; imodnMods; ++imod) { + (angconv+imod)->center=thisDetector->angOff[imod].center; + (angconv+imod)->r_conversion=thisDetector->angOff[imod].r_conversion; + (angconv+imod)->offset=thisDetector->angOff[imod].offset; + (angconv+imod)->ecenter=thisDetector->angOff[imod].ecenter; + (angconv+imod)->er_conversion=thisDetector->angOff[imod].er_conversion; + (angconv+imod)->eoffset=thisDetector->angOff[imod].eoffset; + } + } + if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) { + return 1; + } else { + return 0; + } +} + + + +angleConversionConstant* slsDetector::getAngularConversionPointer(int imod=0) { + return &thisDetector->angOff[imod]; +} + + +int slsDetector::printReceiverConfiguration() { + + std::cout << "Detector IP:\t\t" << getNetworkParameter(DETECTOR_IP) << std::endl; + std::cout << "Detector MAC:\t\t" << getNetworkParameter(DETECTOR_MAC) << std::endl; + + std::cout << "Receiver Hostname:\t" << getNetworkParameter(RECEIVER_HOSTNAME) << std::endl; + std::cout << "Receiver UDP IP:\t" << getNetworkParameter(RECEIVER_UDP_IP) << std::endl; + std::cout << "Receiver UDP MAC:\t" << getNetworkParameter(RECEIVER_UDP_MAC) << std::endl; + std::cout << "Receiver UDP Port:\t" << getNetworkParameter(RECEIVER_UDP_PORT) << std::endl; + + if(thisDetector->myDetectorType == EIGER) + std::cout << "Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2) + << std::endl; + std::cout << std::endl; + + return OK; +} + + -/*receiver*/ int slsDetector::setReceiverOnline(int off) { if (off!=GET_ONLINE_FLAG) { // no receiver @@ -8313,123 +8187,378 @@ int slsDetector::setReceiverOnline(int off) { string slsDetector::checkReceiverOnline() { - string retval = ""; - //if it doesnt exits, create data socket - if(!dataSocket){ - //this already sets the online/offline flag - setReceiverTCPSocket(); - if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG) - return string(thisDetector->receiver_hostname); - else - return string(""); - } - //still cannot connect to socket, dataSocket=0 - if(dataSocket){ - if (connectData() == FAIL) { - dataSocket->SetTimeOut(5); - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; - delete dataSocket; - dataSocket=NULL; + string retval = ""; + //if it doesnt exits, create data socket + if(!dataSocket){ + //this already sets the online/offline flag + setReceiverTCPSocket(); + if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG) + return string(thisDetector->receiver_hostname); + else + return string(""); + } + //still cannot connect to socket, dataSocket=0 + if(dataSocket){ + if (connectData() == FAIL) { + dataSocket->SetTimeOut(5); + thisDetector->receiverOnlineFlag=OFFLINE_FLAG; + delete dataSocket; + dataSocket=NULL; #ifdef VERBOSE - std::cout<< "receiver offline!" << std::endl; + std::cout<< "receiver offline!" << std::endl; #endif - return string(thisDetector->receiver_hostname); - } else { - thisDetector->receiverOnlineFlag=ONLINE_FLAG; - dataSocket->SetTimeOut(100); - disconnectData(); + return string(thisDetector->receiver_hostname); + } else { + thisDetector->receiverOnlineFlag=ONLINE_FLAG; + dataSocket->SetTimeOut(100); + disconnectData(); #ifdef VERBOSE - std::cout<< "receiver online!" << std::endl; + std::cout<< "receiver online!" << std::endl; #endif - return string(""); - } - } - return retval; + return string(""); + } + } + return retval; } -int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port){ +int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port) { - char thisName[MAX_STR_LENGTH]; - int thisRP; - int retval=OK; + char thisName[MAX_STR_LENGTH]; + int thisRP; + int retval=OK; - //if receiver ip given - if (strcmp(name.c_str(),"")!=0) { + //if receiver ip given + if (strcmp(name.c_str(),"")!=0) { #ifdef VERBOSE - std::cout<< "setting receiver" << std::endl; + std::cout<< "setting receiver" << std::endl; #endif - strcpy(thisName,name.c_str()); - strcpy(thisDetector->receiver_hostname,thisName); - if (dataSocket){ - delete dataSocket; - dataSocket=NULL; - } - } else - strcpy(thisName,thisDetector->receiver_hostname); + strcpy(thisName,name.c_str()); + strcpy(thisDetector->receiver_hostname,thisName); + if (dataSocket){ + delete dataSocket; + dataSocket=NULL; + } + } else + strcpy(thisName,thisDetector->receiver_hostname); - //if receiverTCPPort given - if (receiver_port>0) { + //if receiverTCPPort given + if (receiver_port>0) { #ifdef VERBOSE - std::cout<< "setting data port" << std::endl; + std::cout<< "setting data port" << std::endl; #endif - thisRP=receiver_port; - thisDetector->receiverTCPPort=thisRP; - if (dataSocket){ - delete dataSocket; - dataSocket=NULL; - } - } else - thisRP=thisDetector->receiverTCPPort; + thisRP=receiver_port; + thisDetector->receiverTCPPort=thisRP; + if (dataSocket){ + delete dataSocket; + dataSocket=NULL; + } + } else + thisRP=thisDetector->receiverTCPPort; - //create data socket - if (!dataSocket) { - dataSocket=new MySocketTCP(thisName, thisRP); - if (dataSocket->getErrorStatus()){ + //create data socket + if (!dataSocket) { + dataSocket=new MySocketTCP(thisName, thisRP); + if (dataSocket->getErrorStatus()){ #ifdef VERBOSE - std::cout<< "Could not connect Data socket "<setSocket(dataSocket); - // check for version compatibility - switch (thisDetector->myDetectorType) { - case EIGER: - case JUNGFRAU: - case GOTTHARD: - if (thisDetector->receiverAPIVersion == 0){ - if (checkVersionCompatibility(DATA_PORT) == FAIL) - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; - } - break; - default: - break; - } + } + //check if it connects + if (retval!=FAIL) { + checkReceiverOnline(); + thisReceiver->setSocket(dataSocket); + // check for version compatibility + switch (thisDetector->myDetectorType) { + case EIGER: + case JUNGFRAU: + case GOTTHARD: + if (thisDetector->receiverAPIVersion == 0){ + if (checkVersionCompatibility(DATA_PORT) == FAIL) + thisDetector->receiverOnlineFlag=OFFLINE_FLAG; + } + break; + default: + break; + } - } else { - thisDetector->receiverOnlineFlag=OFFLINE_FLAG; + } else { + thisDetector->receiverOnlineFlag=OFFLINE_FLAG; #ifdef VERBOSE - std::cout<< "offline!" << std::endl; + std::cout<< "offline!" << std::endl; #endif - } - return retval; -}; + } + return retval; +} +int slsDetector::lockReceiver(int lock) { + int fnum=F_LOCK_RECEIVER; + int ret = FAIL; + int retval=-1; + int arg=lock; + + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Locking or Unlocking Receiver " << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + return retval; +} + + + + + + +string slsDetector::getReceiverLastClientIP() { + int fnum=F_GET_LAST_RECEIVER_CLIENT_IP; + int ret = FAIL; + char retval[INET_ADDRSTRLEN]=""; + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Geting Last Client IP connected to Receiver " << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->getLastClientIP(fnum,retval); + disconnectData(); + } + if(ret==FORCE_UPDATE) + updateReceiver(); + } + + return string(retval); +} + + +int slsDetector::exitReceiver() { + + int retval; + int fnum=F_EXIT_RECEIVER; + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (dataSocket) { + dataSocket->Connect(); + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); + disconnectData(); + } + } + if (retval!=OK) { + std::cout<< std::endl; + std::cout<< "Shutting down the receiver" << std::endl; + std::cout<< std::endl; + } + return retval; + +} + + +int slsDetector::updateReceiverNoWait() { + + int n = 0,ind; + char path[MAX_STR_LENGTH]; + char lastClientIP[INET_ADDRSTRLEN]; + + n += dataSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); +#ifdef VERBOSE + cout << "Updating receiver last modified by " << lastClientIP << std::endl; +#endif + + // filepath + n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); + pthread_mutex_lock(&ms); + fileIO::setFilePath(path); + pthread_mutex_unlock(&ms); + + // filename + n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); + pthread_mutex_lock(&ms); + fileIO::setFileName(path); + pthread_mutex_unlock(&ms); + + // index + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + fileIO::setFileIndex(ind); + pthread_mutex_unlock(&ms); + + //file format + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + fileIO::setFileFormat(ind); + pthread_mutex_unlock(&ms); + + // file write enable + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + multiDet->enableWriteToFileMask(ind); + pthread_mutex_unlock(&ms); + + // file overwrite enable + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + pthread_mutex_lock(&ms); + multiDet->enableOverwriteMask(ind); + pthread_mutex_unlock(&ms); + + // receiver read frequency + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + thisDetector->receiver_read_freq = ind; + + // receiver streaming port + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + thisDetector->receiver_zmqport = ind; + + // receiver streaming enable + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + thisDetector->receiver_upstream = ind; + + // streaming source ip + n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); + strcpy(thisDetector->receiver_zmqip, path); + + // additional json header + n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); + strcpy(thisDetector->receiver_additionalJsonHeader, path); + + // gap pixels + n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); + thisDetector->gappixels = ind; + + if (!n) printf("n: %d\n", n); + + return OK; + +} + + + + + +int slsDetector::updateReceiver() { + int fnum=F_UPDATE_RECEIVER_CLIENT; + int ret=OK; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { + if (connectData() == OK){ + dataSocket->SendDataOnly(&fnum,sizeof(fnum)); + dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret == FAIL) { + dataSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + else + updateReceiverNoWait(); + + //if ret is force update, do not update now as client is updating + //receiver currently + disconnectData(); + } + } + + return ret; +} + + + +void slsDetector::sendMultiDetectorSize() { + int fnum=F_SEND_RECEIVER_MULTIDETSIZE; + int ret = FAIL; + int retval = -1; + int arg[2]; + + pthread_mutex_lock(&ms); + multiDet->getNumberOfDetectors(arg[0],arg[1]); + pthread_mutex_unlock(&ms); + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending multi detector size to Receiver (" << arg[0] << "," + << arg[1] << ")" << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendIntArray(fnum,retval,arg); + disconnectData(); + } + if((ret==FAIL)){ + std::cout << "Could not set position Id" << std::endl; + setErrorMask((getErrorMask())|(RECEIVER_MULTI_DET_SIZE_NOT_SET)); + } + } +} + + +void slsDetector::setDetectorId() { + int fnum=F_SEND_RECEIVER_DETPOSID; + int ret = FAIL; + int retval = -1; + int arg = detId; + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending detector pos id to Receiver " << detId << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendInt(fnum,retval,arg); + disconnectData(); + } + if((ret==FAIL) || (retval != arg)){ + std::cout << "Could not set position Id" << std::endl; + setErrorMask((getErrorMask())|(RECEIVER_DET_POSID_NOT_SET)); + } + } +} + + +void slsDetector::setDetectorHostname() { + int fnum=F_SEND_RECEIVER_DETHOSTNAME; + int ret = FAIL; + char retval[MAX_STR_LENGTH]=""; + + + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ +#ifdef VERBOSE + std::cout << "Sending detector hostname to Receiver " << + thisDetector->hostname << std::endl; +#endif + if (connectData() == OK){ + ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname); + disconnectData(); + } + if((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) + setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); + } +} + + +string slsDetector::getFilePath() { + return setFilePath(); +} + + @@ -8483,6 +8612,9 @@ string slsDetector::setFilePath(string s) { } +string slsDetector::getFileName() { + return setFileName(); +} string slsDetector::setFileName(string s) { int fnum=F_SET_RECEIVER_FILE_NAME; @@ -8524,16 +8656,16 @@ string slsDetector::setFileName(string s) { return sretval; } else { - if(!s.empty()){ - pthread_mutex_lock(&ms); - fileIO::setFileName(s); - pthread_mutex_unlock(&ms); - } - pthread_mutex_lock(&ms); - s = fileIO::getFileName(); - pthread_mutex_unlock(&ms); + if(!s.empty()){ + pthread_mutex_lock(&ms); + fileIO::setFileName(s); + pthread_mutex_unlock(&ms); + } + pthread_mutex_lock(&ms); + s = fileIO::getFileName(); + pthread_mutex_unlock(&ms); - return s; + return s; } @@ -8565,7 +8697,7 @@ int slsDetector::setReceiverFramesPerFile(int f) { return thisDetector->receiver_framesPerFile; } -slsReceiverDefs::fileFormat slsDetector::setFileFormat(fileFormat f){ +slsReceiverDefs::fileFormat slsDetector::setFileFormat(fileFormat f) { int fnum=F_SET_RECEIVER_FILE_FORMAT; int ret = FAIL; int arg = -1; @@ -8606,7 +8738,13 @@ slsReceiverDefs::fileFormat slsDetector::setFileFormat(fileFormat f){ +fileFormat slsDetector::getFileFormat() { + return setFileFormat(); +} +int slsDetector::getFileIndex() { + return setFileIndex(); +} int slsDetector::setFileIndex(int i) { int fnum=F_SET_RECEIVER_FILE_INDEX; @@ -8646,7 +8784,8 @@ int slsDetector::setFileIndex(int i) { -int slsDetector::startReceiver(){ + +int slsDetector::startReceiver() { int fnum=F_START_RECEIVER; int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; @@ -8674,7 +8813,8 @@ int slsDetector::startReceiver(){ // tell detector to send to receiver (if start receiver failed, this is not executed) - if(((thisDetector->myDetectorType == GOTTHARD || thisDetector->myDetectorType == PROPIX) && ret!= FAIL)) + if(((thisDetector->myDetectorType == GOTTHARD || + thisDetector->myDetectorType == PROPIX) && ret!= FAIL)) return prepareAcquisition(); // send data to receiver for these detectors @@ -8684,13 +8824,15 @@ int slsDetector::startReceiver(){ -int slsDetector::stopReceiver(){ +int slsDetector::stopReceiver() { int fnum=F_STOP_RECEIVER; int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; - if(thisDetector->myDetectorType == GOTTHARD || thisDetector->myDetectorType == PROPIX) - cleanupAcquisition(); // reset (send data to receiver) for these detectors, so back to CPU (dont care about ok/fail at this point) + if(thisDetector->myDetectorType == GOTTHARD || + thisDetector->myDetectorType == PROPIX) + 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 @@ -8712,7 +8854,7 @@ int slsDetector::stopReceiver(){ -slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ +slsDetectorDefs::runStatus slsDetector::startReceiverReadout() { int fnum=F_START_RECEIVER_READOUT; int ret = FAIL; int retval=-1; @@ -8739,7 +8881,7 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ -slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ +slsDetectorDefs::runStatus slsDetector::getReceiverStatus() { int fnum=F_GET_RECEIVER_STATUS; int ret = FAIL; int retval=-1; @@ -8765,7 +8907,7 @@ slsDetectorDefs::runStatus slsDetector::getReceiverStatus(){ -int slsDetector::getFramesCaughtByReceiver(){ +int slsDetector::getFramesCaughtByReceiver() { int fnum=F_GET_RECEIVER_FRAMES_CAUGHT; int ret = FAIL; int retval=-1; @@ -8787,7 +8929,13 @@ int slsDetector::getFramesCaughtByReceiver(){ -int slsDetector::getReceiverCurrentFrameIndex(){ +int slsDetector::getFramesCaughtByAnyReceiver() { + return getFramesCaughtByReceiver(); +} + + + +int slsDetector::getReceiverCurrentFrameIndex() { int fnum=F_GET_RECEIVER_FRAME_INDEX; int ret = FAIL; int retval=-1; @@ -8810,7 +8958,7 @@ int slsDetector::getReceiverCurrentFrameIndex(){ -int slsDetector::resetFramesCaught(){ +int slsDetector::resetFramesCaught() { int fnum=F_RESET_RECEIVER_FRAMES_CAUGHT; int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; @@ -8831,245 +8979,15 @@ int slsDetector::resetFramesCaught(){ } -// int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){ -// int fnum=F_READ_RECEIVER_FRAME; -// int nel=thisDetector->dataBytes/sizeof(int); -// int* retval=new int[nel]; -// int ret=FAIL; -// int n; -// char mess[MAX_STR_LENGTH]="Nothing"; -// if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) { -// #ifdef VERBOSE -// std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <SendDataOnly(&fnum,sizeof(fnum)); -// dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); -// if (ret==FAIL) { -// n= dataSocket->ReceiveDataOnly(mess,sizeof(mess)); -// std::cout<< "Detector returned: " << mess << " " << n << std::endl; -// delete [] retval; -// disconnectData(); -// return NULL; -// } else { -// n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH); -// n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex)); -// n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex)); -// if(thisDetector->myDetectorType == EIGER) -// n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex)); -// n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); -// #ifdef VERBOSE -// std::cout<< "Received "<< n << " data bytes" << std::endl; -// #endif -// if (n!=thisDetector->dataBytes) { -// std::cout<dataBytes << std::endl; -// ret=FAIL; -// delete [] retval; -// disconnectData(); -// return NULL; } -// //jungfrau masking adcval -// if(thisDetector->myDetectorType == JUNGFRAU){ -// for(unsigned int i=0;ireceiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Locking or Unlocking Receiver " << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - return retval; -} -string slsDetector::getReceiverLastClientIP(){ - int fnum=F_GET_LAST_RECEIVER_CLIENT_IP; - int ret = FAIL; - char retval[INET_ADDRSTRLEN]=""; - - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Geting Last Client IP connected to Receiver " << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->getLastClientIP(fnum,retval); - disconnectData(); - } - if(ret==FORCE_UPDATE) - updateReceiver(); - } - - return string(retval); -} - - - -int slsDetector::updateReceiverNoWait() { - - int n = 0,ind; - char path[MAX_STR_LENGTH]; - char lastClientIP[INET_ADDRSTRLEN]; - - n += dataSocket->ReceiveDataOnly(lastClientIP,sizeof(lastClientIP)); -#ifdef VERBOSE - cout << "Updating receiver last modified by " << lastClientIP << std::endl; -#endif - - // filepath - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - pthread_mutex_lock(&ms); - fileIO::setFilePath(path); - pthread_mutex_unlock(&ms); - - // filename - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - pthread_mutex_lock(&ms); - fileIO::setFileName(path); - pthread_mutex_unlock(&ms); - - // index - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - pthread_mutex_lock(&ms); - fileIO::setFileIndex(ind); - pthread_mutex_unlock(&ms); - - //file format - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - pthread_mutex_lock(&ms); - fileIO::setFileFormat(ind); - pthread_mutex_unlock(&ms); - - // file write enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - pthread_mutex_lock(&ms); - multiDet->enableWriteToFileMask(ind); - pthread_mutex_unlock(&ms); - - // file overwrite enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - pthread_mutex_lock(&ms); - multiDet->enableOverwriteMask(ind); - pthread_mutex_unlock(&ms); - - // receiver read frequency - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_read_freq = ind; - - // receiver streaming port - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_zmqport = ind; - - // receiver streaming enable - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->receiver_upstream = ind; - - // streaming source ip - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_zmqip, path); - - // additional json header - n += dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH); - strcpy(thisDetector->receiver_additionalJsonHeader, path); - - // gap pixels - n += dataSocket->ReceiveDataOnly(&ind,sizeof(ind)); - thisDetector->gappixels = ind; - - if (!n) printf("n: %d\n", n); - - return OK; - -} - - - - - -int slsDetector::updateReceiver() { - int fnum=F_UPDATE_RECEIVER_CLIENT; - int ret=OK; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (connectData() == OK){ - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret == FAIL) { - dataSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Receiver returned error: " << mess << std::endl; - } - else - updateReceiverNoWait(); - - //if ret is force update, do not update now as client is updating receiver currently - disconnectData(); - } - } - - return ret; -} - - - - - - -int slsDetector::exitReceiver(){ - - int retval; - int fnum=F_EXIT_RECEIVER; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - if (dataSocket) { - dataSocket->Connect(); - dataSocket->SendDataOnly(&fnum,sizeof(fnum)); - dataSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectData(); - } - } - if (retval!=OK) { - std::cout<< std::endl; - std::cout<< "Shutting down the receiver" << std::endl; - std::cout<< std::endl; - } - return retval; - -} - - - - - -int slsDetector::enableWriteToFile(int enable){ +int slsDetector::enableWriteToFile(int enable) { int fnum=F_ENABLE_RECEIVER_FILE_WRITE; int ret = FAIL; int retval=-1; @@ -9111,7 +9029,7 @@ int slsDetector::enableWriteToFile(int enable){ -int slsDetector::overwriteFile(int enable){ +int slsDetector::overwriteFile(int enable) { int fnum=F_ENABLE_RECEIVER_OVERWRITE; int ret = FAIL; int retval=-1; @@ -9120,7 +9038,7 @@ int slsDetector::overwriteFile(int enable){ if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ if(enable>=0){ - pthread_mutex_lock(&ms); + pthread_mutex_lock(&ms); multiDet->enableOverwriteMask(enable); pthread_mutex_unlock(&ms); } @@ -9155,35 +9073,6 @@ int slsDetector::overwriteFile(int enable){ -int slsDetector::calibratePedestal(int frames){ - int ret=FAIL; - int retval=-1; - int fnum=F_CALIBRATE_PEDESTAL; - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Calibrating Pedestal " <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&frames,sizeof(frames)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return retval; -} @@ -9191,7 +9080,7 @@ int slsDetector::calibratePedestal(int frames){ -int slsDetector::setReadReceiverFrequency(int freq){ +int slsDetector::setReadReceiverFrequency(int freq) { if (freq >= 0) { thisDetector->receiver_read_freq = freq; @@ -9210,7 +9099,8 @@ int slsDetector::setReadReceiverFrequency(int freq){ disconnectData(); } if((ret == FAIL) || (retval != freq)) { - cout << "could not set receiver read frequency to " << freq <<" Returned:" << retval << endl; + cout << "could not set receiver read frequency to " << freq + <<" Returned:" << retval << endl; setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY)); } @@ -9224,7 +9114,7 @@ int slsDetector::setReadReceiverFrequency(int freq){ -int slsDetector::setReceiverReadTimer(int time_in_ms){ +int slsDetector::setReceiverReadTimer(int time_in_ms) { int fnum=F_READ_RECEIVER_TIMER; int ret = FAIL; int arg = time_in_ms; @@ -9243,15 +9133,24 @@ int slsDetector::setReceiverReadTimer(int time_in_ms){ } if ((time_in_ms > 0) && (retval != time_in_ms)){ - cout << "could not set receiver read timer to " << time_in_ms <<" Returned:" << retval << endl; + cout << "could not set receiver read timer to " << time_in_ms + <<" Returned:" << retval << endl; setErrorMask((getErrorMask())|(RECEIVER_READ_TIMER)); } return retval; } +int slsDetector::enableDataStreamingToClient(int enable=-1) { + cprintf(RED,"ERROR: Must be called from the multi Detector level\n"); + return 0; +} -int slsDetector::enableDataStreamingFromReceiver(int enable){ + + + + +int slsDetector::enableDataStreamingFromReceiver(int enable) { if (enable >= 0) { int fnum=F_STREAM_DATA_FROM_RECEIVER; @@ -9262,7 +9161,8 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl; + std::cout << "***************Sending Data Streaming in Receiver " + << arg << std::endl; #endif if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,arg); @@ -9270,7 +9170,8 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ } if(ret==FAIL) { retval = -1; - cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl; + cout << "could not set data streaming in receiver to " << + enable <<" Returned:" << retval << endl; setErrorMask((getErrorMask())|(DATA_STREAMING)); } else { thisDetector->receiver_upstream = retval; @@ -9285,7 +9186,7 @@ int slsDetector::enableDataStreamingFromReceiver(int enable){ -int slsDetector::enableReceiverCompression(int i){ +int slsDetector::enableReceiverCompression(int i) { int fnum=F_ENABLE_RECEIVER_COMPRESSION; int ret = FAIL; int retval=-1; @@ -9293,7 +9194,8 @@ int slsDetector::enableReceiverCompression(int i){ if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ #ifdef VERBOSE - std::cout << "Getting/Enabling/Disabling Receiver Compression with argument " << i << std::endl; + std::cout << "Getting/Enabling/Disabling Receiver Compression with argument " + << i << std::endl; #endif if (connectData() == OK){ ret=thisReceiver->sendInt(fnum,retval,i); @@ -9307,76 +9209,10 @@ int slsDetector::enableReceiverCompression(int i){ -void slsDetector::sendMultiDetectorSize(){ - int fnum=F_SEND_RECEIVER_MULTIDETSIZE; - int ret = FAIL; - int retval = -1; - int arg[2]; - - pthread_mutex_lock(&ms); - multiDet->getNumberOfDetectors(arg[0],arg[1]); - pthread_mutex_unlock(&ms); - - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending multi detector size to Receiver (" << arg[0] << "," << arg[1] << ")" << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->sendIntArray(fnum,retval,arg); - disconnectData(); - } - if((ret==FAIL)){ - std::cout << "Could not set position Id" << std::endl; - setErrorMask((getErrorMask())|(RECEIVER_MULTI_DET_SIZE_NOT_SET)); - } - } -} - - -void slsDetector::setDetectorId(){ - int fnum=F_SEND_RECEIVER_DETPOSID; - int ret = FAIL; - int retval = -1; - int arg = posId; - - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending detector pos id to Receiver " << posId << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->sendInt(fnum,retval,arg); - disconnectData(); - } - if((ret==FAIL) || (retval != arg)){ - std::cout << "Could not set position Id" << std::endl; - setErrorMask((getErrorMask())|(RECEIVER_DET_POSID_NOT_SET)); - } - } -} - - -void slsDetector::setDetectorHostname(){ - int fnum=F_SEND_RECEIVER_DETHOSTNAME; - int ret = FAIL; - char retval[MAX_STR_LENGTH]=""; - - - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -#ifdef VERBOSE - std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl; -#endif - if (connectData() == OK){ - ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname); - disconnectData(); - } - if((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) - setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); - } -} -int slsDetector::enableTenGigabitEthernet(int i){ +int slsDetector::enableTenGigabitEthernet(int i) { int ret=FAIL; int retval = -1; int fnum=F_ENABLE_TEN_GIGA,fnum2 = F_ENABLE_RECEIVER_TEN_GIGA; @@ -9394,7 +9230,7 @@ int slsDetector::enableTenGigabitEthernet(int i){ if (ret==FAIL){ controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_TEN_GIGA)); + setErrorMask((getErrorMask())|(DETECTOR_TEN_GIGA)); } controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); disconnectControl(); @@ -9412,7 +9248,8 @@ int slsDetector::enableTenGigabitEthernet(int i){ ret = FAIL; retval=-1; #ifdef VERBOSE - std::cout << "Enabling / Disabling 10Gbe in receiver: " << i << std::endl; + std::cout << "Enabling / Disabling 10Gbe in receiver: " + << i << std::endl; #endif if (connectData() == OK){ ret=thisReceiver->sendInt(fnum2,retval,i); @@ -9432,7 +9269,7 @@ int slsDetector::enableTenGigabitEthernet(int i){ -int slsDetector::setReceiverFifoDepth(int i){ +int slsDetector::setReceiverFifoDepth(int i) { int fnum=F_SET_RECEIVER_FIFO_DEPTH; int ret = FAIL; int retval=-1; @@ -9457,7 +9294,7 @@ int slsDetector::setReceiverFifoDepth(int i){ -int slsDetector::setReceiverSilentMode(int i){ +int slsDetector::setReceiverSilentMode(int i) { int fnum=F_SET_RECEIVER_SILENT_MODE; int ret = FAIL; int retval=-1; @@ -9482,351 +9319,8 @@ int slsDetector::setReceiverSilentMode(int i){ - /******** CTB funcs */ - /** opens pattern file and sends pattern to CTB - @param fname pattern file to open - @returns OK/FAIL - */ -int slsDetector::setCTBPattern(string fname) { - - - //int fnum=F_SET_CTB_PATTERN; - //int ret = FAIL; - //char retval[MAX_STR_LENGTH]=""; - - -// if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ -// #ifdef VERBOSE -// std::cout << "Sending detector hostname to Receiver " << thisDetector->hostname << std::endl; -// #endif -// if (connectData() == OK) -// ret=thisReceiver->sendString(fnum,retval,thisDetector->hostname); -// if((ret==FAIL) || (strcmp(retval,thisDetector->hostname))) -// setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); -// } - - - - uint64_t word; - - int addr=0; - - FILE *fd=fopen(fname.c_str(),"r"); - if (fd>0) { - while (fread(&word, sizeof(word), 1,fd)) { - setCTBWord(addr,word); - // cout << hex << addr << " " << word << dec << endl; - ++addr; - } - - fclose(fd); - } else - return -1; - - - - - - return addr; - - -} - - - /** Writes a pattern word to the CTB - @param addr address of the word, -1 is I/O control register, -2 is clk control register - @param word 64bit word to be written, -1 gets - @returns actual value - */ -uint64_t slsDetector::setCTBWord(int addr,uint64_t word) { - - //uint64_t ret; - - int ret=FAIL; - uint64_t retval=-1; - int fnum=F_SET_CTB_PATTERN; - int mode=0; //sets word - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&addr,sizeof(addr)); - controlSocket->SendDataOnly(&word,sizeof(word)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return retval; - - -} - - /** Sets the pattern or loop limits in the CTB - @param level -1 complete pattern, 0,1,2, loop level - @param start start address if >=0 - @param stop stop address if >=0 - @param n number of loops (if level >=0) - @returns OK/FAIL - */ -int slsDetector::setCTBPatLoops(int level,int &start, int &stop, int &n) { - - - int retval[3], args[4]; - - args[0]=level; - args[1]=start; - args[2]=stop; - args[3]=n; - - - int ret=FAIL; - int fnum=F_SET_CTB_PATTERN; - int mode=1; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&args,sizeof(args)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - start=retval[0]; - stop=retval[1]; - n=retval[2]; - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return ret; - - -} - - - /** Sets the wait address in the CTB - @param level 0,1,2, wait level - @param addr wait address, -1 gets - @returns actual value - */ -int slsDetector::setCTBPatWaitAddr(int level, int addr) { - - - - - int retval=-1; - - - int ret=FAIL; - int fnum=F_SET_CTB_PATTERN; - int mode=2; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&level,sizeof(level)); - controlSocket->SendDataOnly(&addr,sizeof(addr)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return retval; - - - -} - - /** Sets the wait time in the CTB - @param level 0,1,2, wait level - @param t wait time, -1 gets - @returns actual value - */ -int slsDetector::setCTBPatWaitTime(int level, uint64_t t) { - - - - - - uint64_t retval=-1; - - - int ret=FAIL; - // uint64_t retval=-1; - int fnum=F_SET_CTB_PATTERN; - int mode=3; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&level,sizeof(level)); - controlSocket->SendDataOnly(&t,sizeof(t)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return retval; - - -} - -int slsDetector::pulsePixel(int n,int x,int y) { - int ret=FAIL; - int fnum=F_PULSE_PIXEL; - char mess[MAX_STR_LENGTH]=""; - int arg[3]; - arg[0] = n; arg[1] = x; arg[2] = y; - -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times at (" << x << "," << "y)" << endl << endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return ret; -} - - -int slsDetector::pulsePixelNMove(int n,int x,int y) { - int ret=FAIL; - int fnum=F_PULSE_PIXEL_AND_MOVE; - char mess[MAX_STR_LENGTH]=""; - int arg[3]; - arg[0] = n; arg[1] = x; arg[2] = y; - -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times and move by deltax:" << x << " deltay:" << y << endl << endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE_PIXEL_NMOVE)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return ret; -} - - - -int slsDetector::pulseChip(int n) { - int ret=FAIL; - int fnum=F_PULSE_CHIP; - char mess[MAX_STR_LENGTH]=""; - - -#ifdef VERBOSE - std::cout<< std::endl<< "Pulsing Pixel " << n << " number of times" << endl << endl; -#endif - - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&n,sizeof(n)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_PULSE_CHIP)); - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - - return ret; -} - - - - - -int slsDetector::restreamStopFromReceiver(){ +int slsDetector::restreamStopFromReceiver() { int fnum=F_RESTREAM_STOP_FROM_RECEIVER; int ret = FAIL; char mess[MAX_STR_LENGTH] = ""; @@ -9851,3 +9345,208 @@ int slsDetector::restreamStopFromReceiver(){ return ret; } + + + +int slsDetector::setCTBPattern(string fname) { + + uint64_t word; + + int addr=0; + + FILE *fd=fopen(fname.c_str(),"r"); + if (fd>0) { + while (fread(&word, sizeof(word), 1,fd)) { + setCTBWord(addr,word); + // cout << hex << addr << " " << word << dec << endl; + ++addr; + } + + fclose(fd); + } else + return -1; + + + + + + return addr; + + +} + + +uint64_t slsDetector::setCTBWord(int addr,uint64_t word) { + + //uint64_t ret; + + int ret=FAIL; + uint64_t retval=-1; + int fnum=F_SET_CTB_PATTERN; + int mode=0; //sets word + + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&mode,sizeof(mode)); + controlSocket->SendDataOnly(&addr,sizeof(addr)); + controlSocket->SendDataOnly(&word,sizeof(word)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return retval; + + +} + + +int slsDetector::setCTBPatLoops(int level,int &start, int &stop, int &n) { + + + int retval[3], args[4]; + + args[0]=level; + args[1]=start; + args[2]=stop; + args[3]=n; + + + int ret=FAIL; + int fnum=F_SET_CTB_PATTERN; + int mode=1; //sets loop + + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&mode,sizeof(mode)); + controlSocket->SendDataOnly(&args,sizeof(args)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + start=retval[0]; + stop=retval[1]; + n=retval[2]; + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return ret; + + +} + + +int slsDetector::setCTBPatWaitAddr(int level, int addr) { + + + + + int retval=-1; + + + int ret=FAIL; + int fnum=F_SET_CTB_PATTERN; + int mode=2; //sets loop + + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&mode,sizeof(mode)); + controlSocket->SendDataOnly(&level,sizeof(level)); + controlSocket->SendDataOnly(&addr,sizeof(addr)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return retval; + + + +} + + +int slsDetector::setCTBPatWaitTime(int level, uint64_t t) { + + + uint64_t retval=-1; + + int ret=FAIL; + // uint64_t retval=-1; + int fnum=F_SET_CTB_PATTERN; + int mode=3; //sets loop + + char mess[MAX_STR_LENGTH]=""; + +#ifdef VERBOSE + std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&mode,sizeof(mode)); + controlSocket->SendDataOnly(&level,sizeof(level)); + controlSocket->SendDataOnly(&t,sizeof(t)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) { + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return retval; + + +} + + + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index e9cdd0ca3..4f9638f6b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -19,14 +19,31 @@ class multiSlsDetector; class SharedMemory; class receiverInterface; - -#define SLS_SHMVERSION 0x180620 +#define SLS_SHMVERSION 0x180625 #define NMODMAXX 24 #define NMODMAXY 24 #define NCHIPSMAX 10 #define NCHANSMAX 65536 #define NDACSMAX 16 +typedef struct detParameterList { + int nModMaxX; + int nModMaxY; + int nChanX; + int nChanY; + int nChipX; + int nChipY; + int nDacs; + int nAdcs; + int nGain; + int nOffset; + int dynamicRange; + int moveFlag; + int nGappixelsX; + int nGappixelsY; +} detParameterList; + + class slsDetector : public slsDetectorUtils, public energyConversion { private: @@ -363,6 +380,7 @@ public: using angularConversion::writeAngularConversion; using slsDetectorUtils::getAngularConversion; + //FIXME: all pos or id arguments needed only for same multi signature /** * Constructor called when creating new shared memory @@ -463,1177 +481,1277 @@ public: */ void freeSharedMemory(); - - - /** returns the detector hostname \sa sharedSlsDetector */ - string setHostname(const char *name); - - - /** returns the detector hostname \sa sharedSlsDetector */ - string getHostname(); - + /** + * Sets the hostname of all sls detectors in shared memory + * Connects to them to set up online flag + * @param s hostname + */ + void setHostname(const char *name); /** - returns the detector type from hostname and controlport - \param - \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) + * Gets the hostname of detector + * @param pos insignificant + * @returns hostname + */ + string getHostname(int pos = -1); + + /** + * Get detector type by connecting to the detector without creating an object + * @param name hostname of detector + * @param cport TCP control port + * @returns detector tpe or GENERIC if failed */ static detectorType getDetectorType(const char *name, int cport=DEFAULT_PORTNO); - - - /** - sets/gets detector type - normally the detector knows what type of detector it is - \param type is the detector type (defaults to GET_DETECTOR_TYPE) - \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH, -1 command failed) + * Gets detector type from detector and set it in receiver + * @param type the detector type + * @returns detector type in receiver */ int setDetectorType(detectorType type=GET_DETECTOR_TYPE); /** - sets/gets detector type - normally the detector knows what type of detector it is - \param type is the detector type ("Mythen", "Pilatus", "XFS", "Gotthard", Agipd", "Mönch") - \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH, -1 command failed) - */ - int setDetectorType(string type); + * Gets detector type (string) from detector and set it in receiver + * @param type string of detector type + * @returns detector type in receiver + */ + int setDetectorType(string stype); /** - gets detector type - normally the detector knows what type of detector it is - \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH,-1 command failed) + * Get Detector type from shared memory variable + * @param pos insignificant + * @returns detector type from shared memory variable */ - detectorType getDetectorsType(int pos=-1); - - detectorType setDetectorsType(detectorType type=GET_DETECTOR_TYPE, int pos=-1){return getDetectorsType(pos);}; - - string sgetDetectorsType(int pos=-1){return getDetectorType(getDetectorsType(pos));}; - - string ssetDetectorsType(detectorType type=GET_DETECTOR_TYPE, int pos=-1){return getDetectorType(getDetectorsType(pos));}; - string ssetDetectorsType(string t, int pos=-1){return getDetectorType(getDetectorsType(pos));} - - string getDetectorType(){return sgetDetectorsType();}; - - - + detectorType getDetectorsType(int pos = -1); /** - returns the detector type from hostname and controlport - \param - \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) + * Gets string version of detector type from shared memory variable + * @param pos insignificant + * @returns string version of detector type from shared memory variable */ - static detectorType getDetectorType(int id); - - - - - /** Returns the number of modules (without connecting to the detector) */ - int getNMods(){return thisDetector->nMods;}; // - - /** Returns the number of modules in direction d (without connecting to the detector) */ - int getNMod(dimension d){return thisDetector->nMod[d];}; // - - - /** Returns the number of modules (without connecting to the detector) */ - int getMaxMods(){return thisDetector->nModsMax;}; // - - /** Returns the max number of modules in direction d (without connecting to the detector) */ - int getNMaxMod(dimension d){return thisDetector->nModMax[d];}; // + string sgetDetectorsType(int pos=-1); /** - get the maximum size of the detector - \param d dimension - \returns maximum number of modules that can be installed in direction d + * Just to overload getDetectorType from users + * Gets string version of detector type from shared memory variable + * @returns gets string version of detector type from shared memory variable + */ + string getDetectorType(); + + /** + * Returns number of modules from shared memory (Mythen) + * Other detectors, it is 1 + * @returns number of modules + */ + int getNMods(); + + /** + * Returns number of modules in dimension d from shared memory (Mythen) + * Other detectors, it is 1 + * @param d dimension d + * @returns number of modules in dimension d + */ + int getNMod(dimension d); + + /** + * Returns maximum number of modules from shared memory (Mythen) + * Other detectors, it is 1 + * @returns maximum number of modules + */ + int getMaxMods(); + + /** + * Returns maximum number of modules in dimension d from shared memory (Mythen) + * Other detectors, it is 1 + * @param d dimension d + * @returns maximum number of modules in dimension d + */ + int getNMaxMod(dimension d); + + /** + * Returns maximum number of modules in dimension d (Mythen) + * from the detector directly. + * Other detectors, it is 1 + * @param d dimension d + * @returns maximum number of modules in dimension d */ int getMaxNumberOfModules(dimension d=X); // + /** + * Sets/Gets the number of modules in dimension d (Mythen) + * from the detector directly. + * Other detectors, it is 1 + * @param i the number of modules to set to (-1 gets) + * @param d dimension d + * @returns the number of modules in dimension d + */ + int setNumberOfModules(int n=GET_FLAG, dimension d=X); /** - set/get the size of the detector - \param n number of modules - \param d dimension - \returns current number of modules in direction d + * returns the number of channels per that module + * from shared memory (Mythen) + * @param imod insignificant + * @returns number of channels per module */ - int setNumberOfModules(int n=GET_FLAG, dimension d=X); // if n=GET_FLAG returns the number of installed modules - - - int getChansPerMod(int imod=0){return thisDetector->nChans*thisDetector->nChips;}; - - int getChansPerMod( dimension d,int imod=0){return thisDetector->nChan[d]*thisDetector->nChip[d];}; + int getChansPerMod(int imod=0); + /** + * returns the number of channels per that module in dimension d + * from shared memory (Mythen) + * @param d dimension d + * @param imod insignificant + * @returns number of channels per module in dimension d + */ + int getChansPerMod( dimension d,int imod=0); + /** + * Returns the total number of channels from shared memory + * @returns the total number of channels + */ int getTotalNumberOfChannels(); - //{return thisDetector->nChans*thisDetector->nChips*thisDetector->nMods;}; + /** + * Returns the total number of channels in dimension d from shared memory + * @param d dimension d + * @returns the total number of channels in dimension d + */ int getTotalNumberOfChannels(dimension d); - //{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nMod[d];}; + /** + * Returns the total number of channels of in dimension d including gap pixels + * from shared memory + * @param d dimension d + * @returns the total number of channels including gap pixels in dimension d + * including gap pixels + */ int getTotalNumberOfChannelsInclGapPixels(dimension d); + /** + * Returns the maximum number of channels from shared memory (Mythen) + * @returns the maximum number of channels + */ + int getMaxNumberOfChannels(); - int getMaxNumberOfChannels();//{return thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;}; - - int getMaxNumberOfChannels(dimension d);//{return thisDetector->nChan[d]*thisDetector->nChip[d]*thisDetector->nModMax[d];}; + /** + * Returns the maximum number of channels in dimension d from shared memory (Mythen) + * @param d dimension d + * @returns the maximum number of channels in dimension d + */ + int getMaxNumberOfChannels(dimension d); + /** + * Returns the maximum number of channels in dimension d from shared memory (Mythen) + * @param d dimension d + * @returns the maximum number of channels in dimension d + */ int getMaxNumberOfChannelsInclGapPixels(dimension d); + /** + * returns the number of channels per chip from shared memory (Mythen) + * @returns number of channels per chip + */ + int getNChans(); + /** + * returns the number of channels per chip in dimension d from shared memory (Mythen) + * @param d dimension d + * @returns number of channels per chip in dimension d + */ + int getNChans(dimension d); - /** Returns the number of channels per chip (without connecting to the detector) */ - int getNChans(){return thisDetector->nChans;}; // + /** + * returns the number of chips per module from shared memory (Mythen) + * @returns number of chips per module + */ + int getNChips(); - /** Returns the number of channels per chip (without connecting to the detector) in one direction */ - int getNChans(dimension d){return thisDetector->nChan[d];}; // - - /** Returns the number of chips per module (without connecting to the detector) */ - int getNChips(){return thisDetector->nChips;}; // - - /** Returns the number of chips per module (without connecting to the detector) */ - int getNChips(dimension d){return thisDetector->nChip[d];}; // + /** + * returns the number of chips per module in dimension d from shared memory (Mythen) + * @param d dimension d + * @returns number of chips per module in dimension d + */ + int getNChips(dimension d); + /** + * Checks if the detector is 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 + */ int setOnline(int const online=GET_ONLINE_FLAG); + /** + * Checks if each of the detector is online/offline + * @returns empty string if it is online + * else returns hostnameif it is offline + */ string checkOnline(); /** - configure the socket communication and initializes the socket instances - - \param name hostname - if "" the current hostname is used - \param control_port port for control commands - if -1 the current is used - \param stop_port port for stop command - if -1 the current is used - - \returns OK is connection succeded, FAIL otherwise - \sa sharedSlsDetector + * Configure the TCP socket communciation and initializes the socket instances + * @param name hostname, empty if current hostname + * @param control_port TCP port for control commands, -1 if current is used + * @param stop_port TCP port for data commands, -1 if current is used + * @returns OK or FAIL + * \sa sharedSlsDetector */ int setTCPSocket(string const name="", int const control_port=-1, int const stop_port=-1); /** - changes/gets the port number - \param type port type - \param num new port number (-1 gets) - \returns actual port number + * Set/Gets TCP Port of detector or receiver + * @param t port type + * @param p port number (-1 gets) + * @returns port number */ int setPort(portType type, int num=-1); - /** returns the detector control port \sa sharedSlsDetector */ - int getControlPort() {return thisDetector->controlPort;}; - /** returns the detector stop port \sa sharedSlsDetector */ - int getStopPort() {return thisDetector->stopPort;}; - /** returns the receiver port \sa sharedSlsDetector */ - int getReceiverPort() {return thisDetector->receiverTCPPort;}; + /** + * Returns the detector TCP control port \sa sharedSlsDetector + * @returns the detector TCP control port + */ + int getControlPort(); + /** + * Returns the detector TCP stop port \sa sharedSlsDetector + * @returns the detector TCP stop port + */ + int getStopPort(); + /** + * Returns the receiver TCP port \sa sharedSlsDetector + * @returns the receiver TCP port + */ + int getReceiverPort(); - /** Locks/Unlocks the connection to the server - /param lock sets (1), usets (0), gets (-1) the lock - /returns lock status of the server + /** + * Lock server for this client IP + * @param p 0 to unlock, 1 to lock (-1 gets) + * @returns 1 for locked or 0 for unlocked */ int lockServer(int lock=-1); /** - Returns the IP of the last client connecting to the detector + * Get last client IP saved on detector server + * @returns last client IP saved on detector server */ string getLastClientIP(); + /** - turns off server + * Exit detector server + * @returns OK or FAIL */ int exitServer(); /** - executes a system command on the server - e.g. mount an nfs disk, reboot and returns answer etc. - \param cmd is the command to be executed - \param answer is the answer from the detector - \returns OK or FAIL depending on the command outcome + * Executes a system command on the detector server + * e.g. mount an nfs disk, reboot and returns answer etc. + * @param cmd command to be executed + * @param answer is the answer from the detector + * @returns OK or FAIL */ int execCommand(string cmd, string answer); /** - updates the shared memory receiving the data from the detector (without asking and closing the connection - /returns OK + * Updates some of the shared memory receiving the data from the detector + * @returns OK */ int updateDetectorNoWait(); /** - updates the shared memory receiving the data from the detector - /returns OK - + * Updates soem of the shared memory receiving the data from the detector + * calls updateDetectorNoWait + * @returns OK or FAIL or FORCE_RET */ int updateDetector(); - - /** connect to the control port */ - int connectControl(); - /** disconnect from the control port */ - int disconnectControl(); - - /** connect to the receiver port */ - int connectData(); - /** disconnect from the receiver port */ - int disconnectData(); - - /** connect to the stop port */ - int connectStop(); - /** disconnect from the stop port */ - int disconnectStop(); - - /** Allocates the memory for a sls_detector_module structure and initializes it - \returns myMod the pointer to the allocate dmemory location - - */ - sls_detector_module* createModule(){return createModule(thisDetector->myDetectorType);}; - - - /** Allocates the memory for a sls_detector_module structure and initializes it - \returns myMod the pointer to the allocate dmemory location - - */ - sls_detector_module* createModule(detectorType myDetectorType); - - /** frees the memory for a sls_detector_module structure - \param myMod the pointer to the memory to be freed - - */ - - void deleteModule(sls_detector_module *myMod); - /** - Reads the configuration file fname - \param fname file name - \returns OK or FAIL + * Load configuration from a configuration File + * calls readConfigurationFile and gives it the stream + * @param fname configuration file name + * @return OK or FAIL */ int readConfigurationFile(string const fname); - + /** + * Load configuration from a stream + * @param infile stream + * @return OK or FAIL + */ int readConfigurationFile(ifstream &infile); - /** - - Writes the configuration file fname - \param fname file name - \returns OK or FAIL - + * Write current configuration to a file + * calls writeConfigurationFile giving it a stream to write to + * @param fname configuration file name + * @returns OK or FAIL */ int writeConfigurationFile(string const fname); + + /** + * Write current configuration to a stream + * @param outfile outstream + * @param id detector id + * @returns OK or FAIL + */ int writeConfigurationFile(ofstream &outfile, int id=-1); - /** - returns currently the loaded trimfile/settingsfile name + * Returns the trimfile or settings file name (Useless??) + * @returns the trimfile or settings file name */ - string getSettingsFile(){\ - string s(thisDetector->settingsFile); \ - if (s.length()>6) {\ - if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) \ - return s.substr(0,s.length()-6); \ - } \ - return string(thisDetector->settingsFile);\ - }; - + string getSettingsFile(); /** - writes a trim/settings file for module number imod - the values will be read from the current detector structure - \param fname name of the file to be written - \param imod module number - \param iodelay io delay (detector specific) - \param tau tau (detector specific) - \returns OK or FAIL if the file could not be written - \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) + * Writes a trim/settings file for module number imod, + * the values will be read from the current detector structure + * @param fname name of the file to be written + * @param imod module number + * @param iodelay io delay (detector specific) + * @param tau tau (detector specific) + * @returns OK or FAIL if the file could not be written + * \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) */ using energyConversion::writeSettingsFile; int writeSettingsFile(string fname, int imod, int iodelay, int tau); - - /** - get detector settings - \param imod module number (-1 all) - \returns current settings detectorSettings sendSettingsOnly(detectorSettings isettings); + * Get detector settings + * @param imod module number (-1 all) + * @returns current settings */ detectorSettings getSettings(int imod=-1); /** - set detector settings - \param isettings settings - \param imod module number (-1 all) - \returns current settings - - in this function trimbits/settings and calibration files are searched in the settingsDir and calDir directories and the detector is initialized + * Load detector settings from the settings file picked from the trimdir/settingsdir + * Eiger only stores in shared memory ( a get will overwrite this) + * For Eiger, one must use threshold + * Gotthard, Propix, Jungfrau and Moench only sends the settings enum to the detector + * @param isettings settings + * @param imod module number (-1 all) + * @returns current settings */ detectorSettings setSettings(detectorSettings isettings, int imod=-1); - - - /** returns the detector trimbit/settings directory \sa sharedSlsDetector */ - std::string getSettingsDir() {return std::string(thisDetector->settingsDir);}; - /** sets the detector trimbit/settings directory \sa sharedSlsDetector */ - std::string setSettingsDir(string s) {sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir;}; - - + /** + * Send detector settings only (set only for Jungfrau, Gotthard, Moench, get for all) + * Only the settings enum is sent to the detector, where it will + * initialize al the dacs already hard coded in the detector server + * @param isettings settings + * @param imod module number (-1 all) + * @returns current settings + */ + detectorSettings sendSettingsOnly(detectorSettings isettings, int imod=-1); /** - returns the location of the calibration files - \sa sharedSlsDetector - */ - std::string getCalDir() {return thisDetector->calDir;}; - /** - sets the location of the calibration files - \sa sharedSlsDetector - */ - std::string setCalDir(string s) {sprintf(thisDetector->calDir, s.c_str()); return thisDetector->calDir;}; - - /** loads the modules settings/trimbits reading from a file - \param fname file name . If not specified, extension is automatically generated! - \param imod module number, -1 means all modules - \returns OK or FAIL - */ - int loadSettingsFile(string fname, int imod=-1); - - - /** saves the modules settings/trimbits writing to a file - \param fname file name . Axtension is automatically generated! - \param imod module number, -1 means all modules - \returns OK or FAIL - */ - int saveSettingsFile(string fname, int imod=-1); - - - /** loads the modules calibration data reading from a file - \param fname file name . If not specified, extension is automatically generated! - \param imod module number, -1 means all modules - \returns OK or FAIL - */ - int loadCalibrationFile(string fname, int imod=-1); - - - /** saves the modules calibration data writing to a file - \param fname file name . Axtension is automatically generated! - \param imod module number, -1 means all modules - \returns OK or FAIL - */ - int saveCalibrationFile(string fname, int imod=-1); - - - /** returns if the detector is Master, slave or nothing - \param flag can be GET_MASTER, NO_MASTER, IS_MASTER, IS_SLAVE - \returns master flag of the detector - */ - masterFlags setMaster(masterFlags flag); - - - /** - Sets/gets the synchronization mode of the various detectors - \param sync syncronization mode can be GET_SYNCHRONIZATION_MODE, NONE, MASTER_GATES, MASTER_TRIGGERS, SLAVE_STARTS_WHEN_MASTER_STOPS - \returns current syncronization mode - */ - synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE); - - /** calcualtes the total number of steps of the acquisition. - called when number of frames, number of cycles, number of positions and scan steps change - */ - int setTotalProgress(); - - /** returns the current progress in % */ - double getCurrentProgress(); - - runStatus getRunStatus(); - - /** - prepares detector for acquisition - \returns OK/FAIL - */ - int prepareAcquisition(); - - /** - prepares detector for acquisition - \returns OK/FAIL - */ - int cleanupAcquisition(); - - /** - start detector acquisition - \returns OK/FAIL - */ - int startAcquisition(); - - /** - stop detector acquisition - \returns OK/FAIL - */ - int stopAcquisition(); - - /** - start readout (without exposure or interrupting exposure) - \returns OK/FAIL - */ - int startReadOut(); - - /** - start detector acquisition and read all data putting them a data queue - \returns pointer to the front of the data queue - \sa startAndReadAllNoWait getDataFromDetector dataQueue - */ - int* startAndReadAll(); - - - /** - start detector acquisition and read out, but does not read data from socket leaving socket opened - \returns OK or FAIL - - */ - int startAndReadAllNoWait(); - - /** - Receives a data frame from the detector socket - \returns pointer to the data (or NULL if failed) - - */ - int* getDataFromDetector(int *retval=NULL); - - /** - asks and receives a data frame from the detector and puts it in the data queue - \returns pointer to the data or NULL. - \sa getDataFromDetector - */ - int* readFrame(); - - /** - asks and receives all data from the detector and puts them in a data queue - \returns pointer to the front of the queue or NULL. - \sa getDataFromDetector dataQueue - */ - int* readAll(); - - /** - asks and receives all data from the detector and leaves the socket opened - \returns OK or FAIL - */ - int readAllNoWait(); - - /** - configures mac for gotthard, moench readout - \returns OK or FAIL - */ - int configureMAC(); - - /** - get threshold energy - \param imod module number (-1 all) - \returns current threshold value for imod in ev (-1 failed) + * Get threshold energy (Mythen and Eiger) + * @param imod module number (-1 all) + * @returns current threshold value for imod in ev (-1 failed) */ int getThresholdEnergy(int imod=-1); /** - set threshold energy - \param e_eV threshold in eV - \param imod module number (-1 all) - \param isettings ev. change settings - \param tb 1 to include trimbits, 0 to exclude - \returns current threshold value for imod in ev (-1 failed) + * Set threshold energy (Mythen and Eiger) + * For Eiger, calls setThresholdEneryAndSettings + * @param e_eV threshold in eV + * @param imod module number (-1 all) + * @param isettings ev. change settings + * @param tb 1 to include trimbits, 0 to exclude + * @returns current threshold value for imod in ev (-1 failed) */ int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS, int tb=1); /** - set threshold energy - \param e_eV threshold in eV - \param isettings ev. change settings - \param tb 1 to include trimbits, 0 to exclude - \returns OK if successful, else FAIL + * Set threshold energy and settings (Eiger only) + * @param e_eV threshold in eV + * @param isettings ev. change settings + * @param tb 1 to include trimbits, 0 to exclude + * @returns OK if successful, else FAIL */ int setThresholdEnergyAndSettings(int e_eV, detectorSettings isettings, int tb=1); - /** - send detector settings only (set only for Jungfrau, Gotthard, Moench, get for all) - \param isettings settings - \param imod module number (-1 all) - \returns current settings - - in this function only the settings is sent to the detector, where it will initialize all the dacs already stored in the detector server. + * Returns the detector trimbit/settings directory \sa sharedSlsDetector + * @returns the trimbit/settings directory */ - detectorSettings sendSettingsOnly(detectorSettings isettings, int imod=-1); - - + std::string getSettingsDir(); /** - set/get timer value - \param index timer index - \param t time in ns or number of...(e.g. frames, gates, probes) - \returns timer set value in ns or number of...(e.g. frames, gates, probes) + * Sets the detector trimbit/settings directory \sa sharedSlsDetector + * @param s trimbits/settings directory + * @returns the trimbit/settings directory + */ + std::string setSettingsDir(string s); + + /** + * Returns the calibration files directory \sa sharedSlsDetector (Mythen) + * @returns the calibration files directory + */ + std::string getCalDir(); + + /** + * Sets the calibration files directory \sa sharedSlsDetector (Mythen) + * @param s the calibration files directory + * @returns the calibration files directory + */ + std::string setCalDir(string s); + + /** + * Loads the modules settings/trimbits reading from a specific file + * file name extension is automatically generated. + * @param fname specific settings/trimbits file + * @param imod module index of the entire list, + * from which will be calculated the detector index and the module index (-1 for all) + * returns OK or FAIL + */ + int loadSettingsFile(string fname, int imod=-1); + + /** + * Saves the modules settings/trimbits to a specific file + * file name extension is automatically generated. + * @param fname specific settings/trimbits file + * @param imod module number (-1 for all) + * returns OK or FAIL + */ + int saveSettingsFile(string fname, int imod=-1); + + /** + * Loads the modules calibration data reading from a specific file (Mythen) + * file name extension is automatically generated. + * @param fname specific calibration file + * @param imod module number (-1 for all) + * returns OK or FAIL + */ + int loadCalibrationFile(string fname, int imod=-1); + + /** + * Saves the modules calibration data to a specific file (Mythen) + * file name extension is automatically generated. + * @param fname specific calibration file + * @param imod module number (-1 for all) + * returns OK or FAIL + */ + int saveCalibrationFile(string fname, int imod=-1); + + /** + * Sets/gets the detector in position i as master of the structure (Mythen) + * (e.g. it gates the other detectors and therefore must be started as last. + * Assumes that signal 0 is gate in, signal 1 is trigger in, signal 2 is gate out + * @param i position of master (-1 gets, -2 unset) + * @return master's position (-1 none) + */ + masterFlags setMaster(masterFlags flag); + + /** + * Sets/gets the synchronization mode of the various detector (Mythen) + * @param sync syncronization mode + * @returns current syncronization mode + */ + synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE); + + /** + * Calcualtes the total number of steps of the acquisition + * Called when number of frames, number of cycles, number of positions and scan steps change + * @returns the total number of steps of the acquisition + */ + int setTotalProgress(); + + /** + * Returns the current progress in % + * @returns the current progress in % + */ + double getCurrentProgress(); + + /** + * Get run status of the detector + * @returns the status of the detector + */ + runStatus getRunStatus(); + + /** + * Prepares detector for acquisition (Eiger and Gotthard) + * For Gotthard, it sets the detector data transmission mode (CPU or receiver) + * @returns OK or FAIL + */ + int prepareAcquisition(); + + /** + * Cleans up after acquisition (Gotthard only) + * For Gotthard, it sets the detector data transmission to default (via CPU) + * @returns OK or FAIL + */ + int cleanupAcquisition(); + + /** + * Start detector acquisition (Non blocking) + * @returns OK or FAIL if even one does not start properly + */ + int startAcquisition(); + + /** + * Stop detector acquisition + * @returns OK or FAIL + */ + int stopAcquisition(); + + /** + * Start readout (without exposure or interrupting exposure) (Mythen) + * @returns OK or FAIL + */ + int startReadOut(); + + /** + * Start detector acquisition and read all data (Blocking until end of acquisition) + * (Mythen, puts all data into a data queue. Others, data at receiver via udp packets) + * @returns pointer to the front of the data queue (return significant only for Mythen) + * \sa startAndReadAllNoWait getDataFromDetector dataQueue + */ + int* startAndReadAll(); + + /** + * Start detector acquisition and call read out, but not reading (data for Mythen, + * and status for other detectors) from the socket. + * (startAndReadAll calls this and getDataFromDetector. Client is not blocking, + * but server is blocked until getDataFromDetector is called. so not recommended + * for users) + * @returns OK or FAIL + */ + int startAndReadAllNoWait(); + + /** + * Reads from the detector socket (data frame for Mythen and status for other + * detectors) + * @returns pointer to the data or NULL. If NULL disconnects the socket + * (return significant only for Mythen) + * Other detectors return NULL + * \sa getDataFromDetector + */ + int* getDataFromDetector(int *retval=NULL); + + /** + * Requests and receives a single data frame from the detector + * (Mythen: and puts it in the data queue) + * @returns pointer to the data or NULL. (return Mythen significant) + * Other detectors return NULL + * \sa getDataFromDetector + */ + int* readFrame(); + + /** + * Receives all data from the detector + * (Mythen: and puts them in a data queue) + * @returns pointer to the front of the queue or NULL (return Mythen significant) + * Other detectors return NULL + * \sa getDataFromDetector dataQueue + */ + int* readAll(); + + /** + * Requests detector for all data, calls readAll afterwards + * (Mythen: and puts them in a data queue) + * @returns pointer to the front of the queue or NULL (return Mythen significant) + * Other detectors return NULL + * \sa getDataFromDetector dataQueue + */ + int readAllNoWait(); + + /** + * Configures in detector the destination for UDP packets (Not Mythen) + * @returns OK or FAIL + */ + int configureMAC(); + + /** + * Set/get timer value (not all implemented for all detectors) + * @param index timer index + * @param t time in ns or number of...(e.g. frames, gates, probes) + * @returns timer set value in ns or number of...(e.g. frames, gates, probes) */ int64_t setTimer(timerIndex index, int64_t t=-1); /** - get current timer value - \param index timer index - \returns elapsed time value in ns or number of...(e.g. frames, gates, probes) + * Set/get timer value left in acquisition (not all implemented for all detectors) + * @param index timer index + * @param t time in ns or number of...(e.g. frames, gates, probes) + * @returns timer set value in ns or number of...(e.g. frames, gates, probes) */ int64_t getTimeLeft(timerIndex index); - /** sets/gets the value of important readout speed parameters - \param sp is the parameter to be set/get - \param value is the value to be set, if -1 get value - \returns current value for the specified parameter - \sa speedVariable + /** + * Set speed + * @param sp speed type (clkdivider option for Jungfrau and Eiger, others for Mythen/Gotthard) + * @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual + * @returns value of speed set */ int setSpeed(speedVariable sp, int value=-1); - // Flags /** - set/get dynamic range - \param n dynamic range (-1 get) - \returns current dynamic range - updates the size of the data expected from the detector - \sa sharedSlsDetector + * Set/get dynamic range and updates the number of dataBytes + * (Eiger: If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to 1) + * @param i dynamic range (-1 get) + * @returns current dynamic range + * \sa sharedSlsDetector */ int setDynamicRange(int n=-1); /** - set/get dynamic range - \returns number of bytes sent by the detector - \sa sharedSlsDetector + * Recalculated number of data bytes + * @returns tota number of data bytes */ - int getDataBytes(){return thisDetector->dataBytes;}; + int getDataBytes(); /** - * returns number of bytes sent by detector including gap pixels - * \sa sharedSlsDetector + * Recalculated number of data bytes including gap pixels + * @returns tota number of data bytes including gap pixels */ - int getDataBytesInclGapPixels(){return thisDetector->dataBytesInclGapPixels;}; + int getDataBytesInclGapPixels(); /** - set dacs value - \param val value (in V) - \param index DAC index - \param mV 0 in dac units or 1 in mV - \param imod module number (if -1 alla modules) - \returns current DAC value + * Set/get dacs value + * @param val value (in V) + * @param index DAC index + * @param mV 0 in dac units or 1 in mV + * @param imod module number (if -1 all modules) + * @returns current DAC value */ dacs_t setDAC(dacs_t val, dacIndex index , int mV, int imod=-1); /** - set dacs value - \param index ADC index - \param imod module number - \returns current ADC value (temperature for eiger and jungfrau in millidegrees) + * Get adc value + * @param index adc(DAC) index + * @param imod module number (if -1 all modules) + * @returns current adc value (temperature for eiger and jungfrau in millidegrees) */ dacs_t getADC(dacIndex index, int imod=0); - /** - set/get the external communication mode - obsolete \sa setExternalSignalFlags - \param pol value to be set \sa externalCommunicationMode - \returns current external communication mode + /** + * Set/get timing mode + * @param pol timing mode (-1 gets) + * @returns current timing mode */ externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE); /** - set/get the use of an external signal - \param pol meaning of the signal \sa externalSignalFlag - \param signalIndex index of the signal - \returns current meaning of signal signalIndex + * Set/get external signal flags (to specify triggerinrising edge etc) (Gotthard, Mythen) + * @param pol external signal flag (-1 gets) + * @param signalindex singal index (0 - 3) + * @returns current timing mode */ externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0); /** - set/get readout flags - \param flag readout flag to be set - \returns current flag + * Set/get readout flags (Eiger, Mythen) + * @param flag readout flag (Eiger options: parallel, nonparallel, safe etc.) (-1 gets) + * @returns readout flag */ int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS); /** - write register - \param addr address - \val value - \returns current register value - + * Write in a register. For Advanced users + * @param addr address of register + * @param val value to write into register + * @returns value read after writing */ uint32_t writeRegister(uint32_t addr, uint32_t val); /** - read register - \param addr address - \returns current register value - + * Read from a register. For Advanced users + * @param addr address of register + * @returns value read from register */ uint32_t readRegister(uint32_t addr); /** - sets a bit in a register - \param addr address - \param n nth bit ranging from 0 to 31 - \returns current register value - - DO NOT USE!!! ONLY EXPERT USER!!! + * Set bit in a register. For Advanced users + * @param addr address of register + * @param n nth bit + * @returns value read from register */ uint32_t setBit(uint32_t addr, int n); - /** - clear a bit in a register - \param addr address - \param n nth bit ranging from 0 to 31 - \returns current register value - - DO NOT USE!!! ONLY EXPERT USER!!! + * Clear bit in a register. For Advanced users + * @param addr address of register + * @param n nth bit + * @returns value read from register */ uint32_t clearBit(uint32_t addr, int n); /** - sets the network parameters - must restart streaming in client/receiver if to do with zmq after calling this function - \param i network parameter type - \param s value to be set - \returns parameter - + * Set network parameter + * @param p network parameter type + * @param s network parameter value + * @returns network parameter value set (from getNetworkParameter) */ string setNetworkParameter(networkParameter index, string value); /** - gets the network parameters - \param i network parameter type can be RECEIVER_IP, RECEIVER_MAC, SERVER_MAC - \returns parameter - + * Get network parameter + * @param p network parameter type + * @returns network parameter value set (from getNetworkParameter) */ string getNetworkParameter(networkParameter index); /** - Digital test of the modules - \param mode test mode - \param imod module number for chip test or module firmware test - \returns OK or error mask + * Execute a digital test (Gotthard, Mythen) + * @param mode testmode type + * @param imod module index (-1 for all) + * @returns result of test */ int digitalTest(digitalTestMode mode, int imod=0); - /** - execute trimming - \param mode trim mode - \param par1 if noise, beam or fixed setting trimming it is count limit, if improve maximum number of iterations - \param par2 if noise or beam nsigma, if improve par2!=means vthreshold will be optimized, if fixed settings par2<0 trimwith median, par2>=0 trim with level - \param imod module number (-1 all) - \returns OK or FAIl (FAIL also if some channel are 0 or 63 + * Execute trimming (Mythen) + * @param mode trimming mode type + * @param par1 parameter 1 + * @param par2 parameter 2 + * @param imod module index (-1 for all) + * @returns result of trimming */ int executeTrimming(trimMode mode, int par1, int par2, int imod=-1); - /** - Loads dark image or gain image from a file and sends it to the detector - \param index is 0 for dark image and 1 for gain image - \param fname file name to load data from + /** + * Load dark or gain image to detector (Gotthard) + * @param index image type, 0 for dark image and 1 for gain image + * @param fname file name from which to load image + * @returns OK or FAIL */ int loadImageToDetector(imageType index,string const fname); /** - Called from loadImageToDetector to send the image to detector - \param index is 0 for dark image and 1 for gain image - \param arg image - + * Called from loadImageToDetector to send the image to detector + * @param index image type, 0 for dark image and 1 for gain image + * @param imageVals image + * @returns OK or FAIL */ int sendImageToDetector(imageType index,short int imageVals[]); /** - writes the counter memory block from the detector - \param startACQ is 1 to start acquisition after reading counter - \param fname file name to load data from - \returns OK or FAIL + * Writes the counter memory block from the detector (Gotthard) + * @param fname file name to load data from + * @param startACQ is 1 to start acquisition after reading counter + * @returns OK or FAIL */ int writeCounterBlockFile(string const fname,int startACQ=0); - /** - gets counter memory block in detector - \param startACQ is 1 to start acquisition after reading counter - \param arg counter memory block from detector - \returns OK or FAIL + * Gets counter memory block in detector (Gotthard) + * @param arg counter memory block from detector + * @param startACQ 1 to start acquisition afterwards, else 0 + * @returns OK or FAIL */ int getCounterBlock(short int arg[],int startACQ=0); - /** - Resets counter in detector - \param startACQ is 1 to start acquisition after resetting counter - \returns OK or FAIL + * Resets counter in detector + * @param startACQ is 1 to start acquisition after resetting counter + * @returns OK or FAIL */ int resetCounterBlock(int startACQ=0); - /** set/get counter bit in detector + /** + * Set/get counter bit in detector (Gotthard) * @param i is -1 to get, 0 to reset and any other value to set the counter bit - /returns the counter bit in detector + * @returns the counter bit in detector */ int setCounterBit(int i = -1); - /** - set roi - \param n number of rois - \param roiLimits array of roi - \returns success or failure + * Set ROI (Gotthard) + * At the moment only one set allowed + * @param n number of rois + * @param roiLimits array of roi + * @returns OK or FAIL */ int setROI(int n=-1,ROI roiLimits[]=NULL); /** - get roi from each detector and convert it to the multi detector scale - \param n number of roi - \returns an array of multidetector's rois + * Get ROI from each detector and convert it to the multi detector scale (Gotthard) + * @param n number of rois + * @returns OK or FAIL */ slsDetectorDefs::ROI* getROI(int &n); - - /** Returns number of rois */ - int getNRoi(){return thisDetector->nROI;}; - - - int sendROI(int n=-1,ROI roiLimits[]=NULL); - + /** + * Returns number of rois + * @returns number of ROIs + */ + int getNRoi(); /** - write register - \param addr address - \val value - \returns current register value + * Send ROI to the detector after calculating + * from setROI + * @param n number of ROIs (-1 to get) + * @param roiLimits ROI + * @returns OK or FAIL + */ + int sendROI(int n=-1,ROI roiLimits[]=NULL); + /** + * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert users + * @param addr address of adc register + * @param val value + * @returns return value (mostly -1 as it can't read adc register) */ int writeAdcRegister(int addr, int val); - - /** @short activates the detector (detector specific) - \param enable can be: -1 returns wether the detector is in active (1) or inactive (0) state - \returns 0 (inactive) or 1 (active) + /** + * Activates the detector (Eiger only) + * @param enable active (1) or inactive (0), -1 gets + * @returns 0 (inactive) or 1 (active) */ int activate(int const enable=GET_ONLINE_FLAG); - - /** returns the enable if data will be flipped across x or y axis - * \param d axis across which data is flipped - * returns 1 or 0 + /** + * Returns the enable if data will be flipped across x or y axis (Eiger) + * @param d axis across which data is flipped + * @returns 1 for flipped, else 0 */ int getFlippedData(dimension d=X){return thisDetector->flippedData[d];}; - /** sets the enable which determines if data will be flipped across x or y axis - * \param d axis across which data is flipped - * \param value 0 or 1 to reset/set or -1 to get value - * \return enable flipped data across x or y axis + /** + * Sets the enable which determines if + * data will be flipped across x or y axis (Eiger) + * @param d axis across which data is flipped + * @param value 0 or 1 to reset/set or -1 to get value + * @returns enable flipped data across x or y axis */ int setFlippedData(dimension d=X, int value=-1); - /** sets all the trimbits to a particular value - \param val trimbit value - \param imod module number, -1 means all modules - \returns OK or FAIL + + /** + * Sets all the trimbits to a particular value (Eiger) + * @param val trimbit value + * @param imod module number, -1 means all modules + * @returns OK or FAIL */ int setAllTrimbits(int val, int imod=-1); /** - * Enable gap pixels, only for Eiger and for 8,16 and 32 bit mode. 4 bit mode gap pixels only in gui call back + * Enable gap pixels, only for Eiger and for 8,16 and 32 bit mode. (Eiger) + * 4 bit mode gap pixels only in gui call back * @param val 1 sets, 0 unsets, -1 gets - * @return gap pixel enable or -1 for error + * @returns gap pixel enable or -1 for error */ int enableGapPixels(int val=-1); - /** sets the number of trim energies and their value \sa sharedSlsDetector - \param nen number of energies - \param en array of energies - \returns number of trim energies - - unused! - - \sa sharedSlsDetector - */ - int setTrimEn(int nen, int *en=NULL) {if (en) {for (int ien=0; ientrimEnergies[ien]=en[ien]; thisDetector->nTrimEn=nen;} return (thisDetector->nTrimEn);}; - - - /** returns the number of trim energies and their value \sa sharedSlsDetector - \param point to the array that will contain the trim energies (in ev) - \returns number of trim energies - - - unused! - - \sa sharedSlsDetector - */ - int getTrimEn(int *en=NULL) {if (en) {for (int ien=0; iennTrimEn; ien++) en[ien]=thisDetector->trimEnergies[ien];} return (thisDetector->nTrimEn);}; /** - Pulse Pixel - \param n is number of times to pulse - \param x is x coordinate - \param y is y coordinate - \returns OK or FAIL + * Sets the number of trim energies and their value (Eiger) + * \sa sharedSlsDetector + * @param nen number of energies + * @param en array of energies + * @returns number of trim energies + */ + int setTrimEn(int nen, int *en=NULL); + + /** + * Returns the number of trim energies and their value (Eiger) + * \sa sharedSlsDetector + * @param en array of energies + * @returns number of trim energies + */ + int getTrimEn(int *en=NULL); + + /** + * Pulse Pixel (Eiger) + * @param n is number of times to pulse + * @param x is x coordinate + * @param y is y coordinate + * @returns OK or FAIL */ int pulsePixel(int n=0,int x=0,int y=0); /** - Pulse Pixel and move by a relative value - \param n is number of times to pulse - \param x is relative x value - \param y is relative y value - \returns OK or FAIL + * Pulse Pixel and move by a relative value (Eiger) + * @param n is number of times to pulse + * @param x is relative x value + * @param y is relative y value + * @returns OK or FAIL */ int pulsePixelNMove(int n=0,int x=0,int y=0); /** - Pulse Chip - \param n is number of times to pulse - \returns OK or FAIL + * Pulse Chip (Eiger) + * @param n is number of times to pulse + * @returns OK or FAIL */ int pulseChip(int n=0); /** - set/gets threshold temperature (Jungfrau only) - \param val value in millidegrees, -1 gets - \param imod module number, -1 is all - \returns threshold temperature in millidegrees + * Set/gets threshold temperature (Jungfrau) + * @param val value in millidegrees, -1 gets + * @param imod module number, -1 is all + * @returns threshold temperature in millidegrees */ int setThresholdTemperature(int val=-1, int imod=-1); /** - enables/disables temperature control (Jungfrau only) - \param val value, -1 gets - \param imod module number, -1 is all - \returns temperature control enable + * Enables/disables temperature control (Jungfrau) + * @param val value, -1 gets + * @param imod module number, -1 is all + * @returns temperature control enable */ int setTemperatureControl(int val=-1, int imod=-1); /** - Resets/ gets over-temperature event (Jungfrau only) - \param val value, -1 gets - \param imod module number, -1 is all - \returns over-temperature event + * Resets/ gets over-temperature event (Jungfrau) + * @param val value, -1 gets + * @param imod module number, -1 is all + * @returns over-temperature event */ int setTemperatureEvent(int val=-1, int imod=-1); /** - * set storage cell that stores first acquisition of the series (Jungfrau only) - * \param value storage cell index. Value can be 0 to 15. (-1 gets) - * \returns the storage cell that stores the first acquisition of the series + * Set storage cell that stores first acquisition of the series (Jungfrau) + * @param value storage cell index. Value can be 0 to 15. (-1 gets) + * @returns the storage cell that stores the first acquisition of the series */ int setStoragecellStart(int pos=-1); - - /** programs FPGA with pof file - \param fname file name - \returns OK or FAIL + /** + * Programs FPGA with pof file (Jungfrau) + * @param fname file name + * @returns OK or FAIL */ int programFPGA(string fname); - /** resets FPGA - \returns OK or FAIL + /** + * Resets FPGA (Jungfrau) + * @returns OK or FAIL */ int resetFPGA(); - /** power on/off the chip - \param ival on is 1, off is 0, -1 to get - \returns OK or FAIL + /** + * Power on/off Chip (Jungfrau) + * @param ival on is 1, off is 0, -1 to get + * @returns OK or FAIL */ int powerChip(int ival= -1); - /** automatic comparator disable for Jungfrau only - \param ival on is 1, off is 0, -1 to get - \returns OK or FAIL + /** + * Automatic comparator disable (Jungfrau) + * @param ival on is 1, off is 0, -1 to get + * @returns OK or FAIL */ int setAutoComparatorDisableMode(int ival= -1); /** - gets the trimbits from shared memory *chanRegs - \param retval is the array with the trimbits - \param fromDetector is true if the trimbits shared memory have to be uploaded from detector - \returns the total number of channels for the detector - \sa ::sls_detector_module + * Returns the trimbits from the detector's shared memmory (Mythen, Eiger) + * @param retval is the array with the trimbits + * @param fromDetector is true if the trimbits shared memory have to be + * uploaded from detector + * @returns total number of channels for the detector */ int getChanRegs(double* retval,bool fromDetector); /** - configure module - \param imod module number (-1 all) - \returns current register value - \sa ::sls_detector_module + * Configure module (who calls this?) + * @param imod module number (-1 all) + * @returns current register value + * \sa ::sls_detector_module */ int setModule(int reg, int imod=-1); - //virtual int setModule(int reg, int imod=-1); /** - configure chip - \param module module to be set - must contain correct module number and also channel and chip registers - \param iodelay iodelay (detector specific) - \param tau tau (detector specific) - \param e_eV threashold in eV (detector specific) - \param gainval pointer to extra gain values - \param offsetval pointer to extra offset values - \param tb 1 to include trimbits, 0 to exclude (used for eiger) - \returns current register value - \sa ::sls_detector_module + * Configure Module (Mythen, Eiger) + * Called for loading trimbits and settings settings to the detector + * @param module module to be set - must contain correct module number and + * also channel and chip registers + * @param iodelay iodelay (detector specific) + * @param tau tau (detector specific) + * @param e_eV threashold in eV (detector specific) + * @param gainval pointer to extra gain values + * @param offsetval pointer to extra offset values + * @param tb 1 to include trimbits, 0 to exclude (used for eiger) + * @returns current register value + * \sa ::sls_detector_module */ - int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, int* gainval=0, int* offsetval=0, int tb=1); - //virtual int setModule(sls_detector_module module); + int setModule(sls_detector_module module, int iodelay, int tau, int e_eV, + int* gainval=0, int* offsetval=0, int tb=1); + /** - get module - \param imod module number - \returns pointer to module structure (which has bee created and must then be deleted) + * Get module structure from detector (all detectors) + * @param imod module number + * @returns pointer to module structure (which has been created and must then be deleted) */ sls_detector_module *getModule(int imod); /** - configure channel - \param reg channel register - \param ichan channel number (-1 all) - \param ichip chip number (-1 all) - \param imod module number (-1 all) - \returns current register value - \sa ::sls_detector_channel + * Configure channel (Mythen) + * @param reg channel register + * @param ichan channel number (-1 all) + * @param ichip chip number (-1 all) + * @param imod module number (-1 all) + * @returns current register value + * \sa ::sls_detector_channel */ int setChannel(int64_t reg, int ichan=-1, int ichip=-1, int imod=-1); /** - configure channel - \param chan channel to be set - must contain correct channel, module and chip number - \returns current register value + * Configure channel (Mythen) + * @param chan channel to be set - + * must contain correct channel, module and chip number + * @returns current register value */ int setChannel(sls_detector_channel chan); /** - get channel - \param ichan channel number - \param ichip chip number - \param imod module number - \returns current channel structure for channel + * Get channel (Mythen) + * @param ichan channel number + * @param ichip chip number + * @param imod module number + * @returns current channel structure for channel */ sls_detector_channel getChannel(int ichan, int ichip, int imod); /** - configure chip - \param reg chip register - \param ichip chip number (-1 all) - \param imod module number (-1 all) - \returns current register value - \sa ::sls_detector_chip + * Configure chip (Mythen) + * @param reg chip register + * @param ichip chip number (-1 all) + * @param imod module number (-1 all) + * @returns current register value + * \sa ::sls_detector_chip */ int setChip(int reg, int ichip=-1, int imod=-1); /** - configure chip - \param chip chip to be set - must contain correct module and chip number and also channel registers - \returns current register value - \sa ::sls_detector_chip + * Configure chip (Mythen) + * @param chip chip to be set + * must contain correct module and chip number and also channel registers + * @returns current register value + * \sa ::sls_detector_chip */ int setChip(sls_detector_chip chip); /** - get chip - \param ichip chip number - \param imod module number - \returns current chip structure for channel - - \bug probably does not return corretly! + * Get chip (Mythen) + * @param ichip chip number + * @param imod module number + * @returns current chip structure for channel + * \bug probably does not return corretly! */ sls_detector_chip getChip(int ichip, int imod); - int getMoveFlag(int imod){if (moveFlag) return *moveFlag; else return 1;}; + /** + * Get Move Flag (Mythen) + * @param imod module number (-1 all) + * @param istep step index + * @returns move flag + */ + int getMoveFlag(int imod); + /** + * Fill Module mask for flat field corrections (Mythen) + * @param mM array + * @returns number of modules + */ int fillModuleMask(int *mM); - /** Starts acquisition, calibrates pedestal and writes to fpga - /returns number of frames + /** + * Calibrate Pedestal (ChipTestBoard) + * Starts acquisition, calibrates pedestal and writes to fpga + * @param frames number of frames + * @returns number of frames */ int calibratePedestal(int frames = 0); /** - set rate correction - \param t dead time in ns - if 0 disable correction, if >0 set dead time to t, if <0 set deadtime to default dead time for current settings - \returns 0 if rate correction disabled, >0 otherwise + * Set Rate correction (Mythen, Eiger) + * @param t dead time in ns - if 0 disable correction, + * if >0 set dead time to t, if < 0 set deadtime to default dead time + * for current settings + * @returns 0 if rate correction disabled, >0 otherwise */ int setRateCorrection(double t=0); - /** - get rate correction - \param t reference for dead time - \returns 0 if rate correction disabled, >0 otherwise + * Get rate correction (Mythen, Eiger) + * @param t reference for dead time + * @returns 0 if rate correction disabled, > 0 otherwise */ int getRateCorrection(double &t); - /** - get rate correction tau - \returns 0 if rate correction disabled, otherwise the tau used for the correction + * Get rate correction tau (Mythen, Eiger) + * @returns 0 if rate correction disabled, otherwise the tau used for the correction */ double getRateCorrectionTau(); + /** - get rate correction - \returns 0 if rate correction disabled, >0 otherwise + * Get rate correction (Mythen, Eiger) + * @returns 0 if rate correction disabled, > 0 otherwise */ int getRateCorrection(); - /** - rate correct data - \param datain data array - \param errin error array on data (if NULL will default to sqrt(datain) - \param dataout array of corrected data - \param errout error on corrected data (if not NULL) - \returns 0 + * Rate correct data (Mythen) + * @param datain data array + * @param errin error array on data (if NULL will default to sqrt(datain) + * @param dataout array of corrected data + * @param errout error on corrected data (if not NULL) + * @returns 0 */ int rateCorrect(double* datain, double *errin, double* dataout, double *errout); - /** - set flat field corrections - \param fname name of the flat field file (or "" if disable) - \returns 0 if disable (or file could not be read), >0 otherwise + * Set flat field corrections (Mythen) + * @param fname name of the flat field file (or "" if disable) + * @returns 0 if disable (or file could not be read), >0 otherwise */ int setFlatFieldCorrection(string fname=""); /** - set flat field corrections - \param corr if !=NULL the flat field corrections will be filled with corr (NULL usets ff corrections) - \param ecorr if !=NULL the flat field correction errors will be filled with ecorr (1 otherwise) - \returns 0 if ff correction disabled, >0 otherwise + * Set flat field corrections (Mythen) + * @param corr if !=NULL the flat field corrections will be filled with + * corr (NULL usets ff corrections) + * @param ecorr if !=NULL the flat field correction errors will be filled + * with ecorr (1 otherwise) + * @returns 0 if ff correction disabled, >0 otherwise */ int setFlatFieldCorrection(double *corr, double *ecorr=NULL); - /** - get flat field corrections - \param corr if !=NULL will be filled with the correction coefficients - \param ecorr if !=NULL will be filled with the correction coefficients errors - \returns 0 if ff correction disabled, >0 otherwise + * Get flat field corrections (Mythen) + * @param corr if !=NULL will be filled with the correction coefficients + * @param ecorr if !=NULL will be filled with the correction coefficients errors + * @returns 0 if ff correction disabled, >0 otherwise */ int getFlatFieldCorrection(double *corr=NULL, double *ecorr=NULL); /** - flat field correct data - \param datain data array - \param errin error array on data (if NULL will default to sqrt(datain) - \param dataout array of corrected data - \param errout error on corrected data (if not NULL) - \returns 0 + * Flat field correct data (Mythen) + * @param datain data array + * @param errin error array on data (if NULL will default to sqrt(datain) + * @param dataout array of corrected data + * @param errout error on corrected data (if not NULL) + * @returns 0 */ int flatFieldCorrect(double* datain, double *errin, double* dataout, double *errout); - - /** - set bad channels correction - \param fname file with bad channel list ("" disable) - \returns 0 if bad channel disabled, >0 otherwise + * Set bad channels correction (Mythen) + * @param fname file with bad channel list ("" disable) + * @returns 0 if bad channel disabled, >0 otherwise */ int setBadChannelCorrection(string fname=""); /** - set bad channels correction - \param nch number of bad channels - \param chs array of channels - \param ff 0 if normal bad channels, 1 if ff bad channels - \returns 0 if bad channel disabled, >0 otherwise + * Set bad channels correction (Mythen) + * @param nch number of bad channels + * @param chs array of channels + * @param ff 0 if normal bad channels, 1 if ff bad channels + * @returns 0 if bad channel disabled, >0 otherwise */ int setBadChannelCorrection(int nch, int *chs, int ff=0); /** - get bad channels correction - \param bad pointer to array that if bad!=NULL will be filled with the bad channel list - \returns 0 if bad channel disabled or no bad channels, >0 otherwise + * Get bad channels correction (Mythen) + * @param bad pointer to array that if bad!=NULL will be filled with the + * bad channel list + * @returns 0 if bad channel disabled or no bad channels, >0 otherwise */ int getBadChannelCorrection(int *bad=NULL); /** - - reads an angular conversion file - \param fname file to be read - \sa angleConversionConstant mythenDetector::readAngularConversion + * Reads an angular conversion file (Mythen, Gotthard) + * \sa angleConversionConstant mythenDetector::readAngularConversion + * @param fname file to be read + * @returns 0 if angular conversion disabled, >0 otherwise */ int readAngularConversionFile(string fname=""); - /** - - reads an angular conversion file - \param fname file to be read - \sa angleConversionConstant mythenDetector::readAngularConversion + * Reads an angular conversion file (Mythen, Gotthard) + * \sa angleConversionConstant mythenDetector::readAngularConversion + * @param ifs input stream + * @returns 0 if angular conversion disabled, >0 otherwise */ int readAngularConversion(ifstream& ifs); - - /** - Pure virtual function - writes an angular conversion file - \param fname file to be written - \sa angleConversionConstant mythenDetector::writeAngularConversion + * Writes an angular conversion file (Mythen, Gotthard) + * \sa angleConversionConstant mythenDetector::writeAngularConversion + * @param fname file to be written + * @returns 0 if angular conversion disabled, >0 otherwise */ int writeAngularConversion(string fname=""); - - /** - Pure virtual function - writes an angular conversion file - \param fname file to be written - \sa angleConversionConstant mythenDetector::writeAngularConversion + * Writes an angular conversion file (Mythen, Gotthard) + * \sa angleConversionConstant mythenDetector::writeAngularConversion + * @param ofs output stream + * @returns 0 if angular conversion disabled, >0 otherwise */ int writeAngularConversion(ofstream &ofs); - /** - pure virtual function - get angular conversion - \param reference to diffractometer direction - \param angconv array that will be filled with the angular conversion constants - \returns 0 if angular conversion disabled, >0 otherwise - \sa mythenDetector::getAngularConversion + * Get angular conversion (Mythen, Gotthard) + * \sa angleConversionConstant mythenDetector::getAngularConversion + * @param direction reference to diffractometer + * @param angconv array that will be filled with the angular conversion constants + * @returns 0 if angular conversion disabled, >0 otherwise */ int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL) ; - angleConversionConstant *getAngularConversionPointer(int imod=0) {return &thisDetector->angOff[imod];}; - + /** + * Return angular conversion pointer (Mythen, Gotthard) + * @param imod module number + * @returns angular conversion pointer + */ + angleConversionConstant *getAngularConversionPointer(int imod=0); /** - Prints receiver configuration - \returns OK or FAIL + * Prints receiver configuration + * @returns OK or FAIL */ int printReceiverConfiguration(); - /** - calls setReceiverTCPSocket if online and sets the flag + * Checks if receiver is online and set flag + * Also initializes the data socekt + * @param online 1 to set online, 0 to set offline, -1 gets + * @returns online, offline (from shared memory) */ int setReceiverOnline(int const online=GET_ONLINE_FLAG); /** - Checks if the receiver is really online + * Checks if the receiver is really online + * @returns empty string if online, else returns receiver hostname */ string checkReceiverOnline(); /** - configure the socket communication and initializes the socket instances - - \param name receiver ip - if "" the current receiver hostname is used - \param receiver_port port for receiving data - if -1 the current is used - - \returns OK is connection succeded, FAIL otherwise - \sa sharedSlsDetector + * Configure the socket communication and initializes the socket instances + * @param name receiver ip - if "" the current receiver hostname is used + * @param receiver_port port for receiving data - if -1 the current is used + * @returns OK is connection succeded, FAIL otherwise + * \sa sharedSlsDetector */ int setReceiverTCPSocket(string const name="", int const receiver_port=-1); - - - /** Locks/Unlocks the connection to the receiver - /param lock sets (1), usets (0), gets (-1) the lock - /returns lock status of the receiver + /** + * Locks/Unlocks the connection to the receiver + * @param lock sets (1), usets (0), gets (-1) the lock + * @returns lock status of the receiver */ int lockReceiver(int lock=-1); /** - Returns the IP of the last client connecting to the receiver + * Returns the IP of the last client connecting to the receiver + * @returns the IP of the last client connecting to the receiver */ string getReceiverLastClientIP(); + /** - Turns off the receiver server! + * Exits the receiver TCP server + * @retutns OK or FAIL */ int exitReceiver(); + /** updates the shared memory receiving the data from the detector (without asking and closing the connection /returns OK @@ -1641,8 +1759,8 @@ public: int updateReceiverNoWait(); /** - updates the shared memory receiving the data from the detector - /returns OK + * Updates the shared memory receiving the data from the detector + * @returns OK or FAIL */ int updateReceiver(); @@ -1651,148 +1769,157 @@ public: */ void sendMultiDetectorSize(); - /** send the detector pos id to the receiver + /** + * Send the detector pos id to the receiver * for various file naming conventions for multi detectors in receiver */ void setDetectorId(); - /** send the detector host name to the receiver + /** + * Send the detector host name to the receiver * for various handshaking required with the detector */ void setDetectorHostname(); - /** - \returns file dir + * Returns output file directory + * @returns output file directory */ - string getFilePath(){return setFilePath();}; + string getFilePath(); /** - Sets up the file directory - @param s fileDir file directory - \returns file dir + * Sets up the file directory + * @param s file directory + * @returns file dir */ string setFilePath(string s=""); + /** + * Returns file name prefix + * @returns file name prefix + */ + string getFileName(); /** - \returns file name - */ - string getFileName(){return setFileName();}; - /** - Sets up the file name - @param s file name - \returns file name + * Sets up the file name prefix + * @param s file name prefix + * @returns file name prefix */ string setFileName(string s=""); - /** - Sets the max frames per file in receiver - @param f max frames per file - \returns max frames per file in receiver + * Sets the max frames per file in receiver + * @param f max frames per file + * @returns max frames per file in receiver */ int setReceiverFramesPerFile(int f = -1); /** - \returns file name + * Returns file format + * @returns file name */ - fileFormat getFileFormat(){return setFileFormat();}; + fileFormat getFileFormat(); /** - Sets up the file format - @param f file format - \returns file format + * Sets up the file format + * @param f file format + * @returns file format */ fileFormat setFileFormat(fileFormat f=GET_FILE_FORMAT); /** - \returns file index + * Returns file index + * @returns file index */ int getFileIndex(){return setFileIndex();}; + /** - Sets up the file index - @param i file index - \returns file index + * Sets up the file index + * @param i file index + * @returns file index */ int setFileIndex(int i=-1); - - - - /** Starts the listening mode of receiver - \returns OK or FAIL + /** + * Receiver starts listening to packets + * @returns OK or FAIL */ int startReceiver(); - /** Stops the listening mode of receiver - \returns OK or FAIL + /** + * Stops the listening mode of receiver + * @returns OK or FAIL */ int stopReceiver(); - /** Sets the receiver to start any readout remaining in the fifo and - * change status to transmitting. + /** + * Sets the receiver to start any readout remaining in the fifo and + * change status to transmitting (Mythen) * The status changes to run_finished when fifo is empty */ runStatus startReceiverReadout(); - - /** gets the status of the listening mode of receiver - \returns status + /** + * Gets the status of the listening mode of receiver + * @returns status */ runStatus getReceiverStatus(); - /** gets the number of frames caught by receiver - \returns number of frames caught by receiver + /** + * Gets the number of frames caught by receiver + * @returns number of frames caught by receiver */ int getFramesCaughtByReceiver(); - /** gets the number of frames caught by any one receiver (to avoid using threadpool) - \returns number of frames caught by any one receiver (master receiver if exists) + /** + * Gets the number of frames caught by any one receiver (to avoid using threadpool) + * @returns number of frames caught by any one receiver (master receiver if exists) */ - int getFramesCaughtByAnyReceiver() {return getFramesCaughtByReceiver();}; + int getFramesCaughtByAnyReceiver(); - /** gets the current frame index of receiver - \returns current frame index of receiver + /** + * Gets the current frame index of receiver + * @returns current frame index of receiver */ int getReceiverCurrentFrameIndex(); /** - * resets framescaught - * @param index frames caught by receiver + * Resets framescaught in receiver + * Use this when using startAcquisition instead of acquire + * @returns OK or FAIL */ int resetFramesCaught(); - - /** - Sets/Gets receiver file write enable - @param enable 1 or 0 to set/reset file write enable - /returns file write enable + * Sets/Gets receiver file write enable + * @param enable 1 or 0 to set/reset file write enable + * @returns file write enable */ int enableWriteToFile(int enable=-1); /** - Sets/Gets file overwrite enable - @param enable 1 or 0 to set/reset file overwrite enable - /returns file overwrite enable + * Sets/Gets file overwrite enable + * @param enable 1 or 0 to set/reset file overwrite enable + * @returns file overwrite enable */ int overwriteFile(int enable=-1); - - /** Sets the read receiver frequency - if data required from receiver randomly readRxrFrequency=0, - else every nth frame to be sent to gui - @param freq is the receiver read frequency - /returns read receiver frequency + /** + * Sets the read receiver frequency + * if data required from receiver randomly readRxrFrequency=0, + * else every nth frame to be sent to gui/callback + * @param freq is the receiver read frequency. Value 0 is 200 ms timer (other + * frames not sent), 1 is every frame, 2 is every second frame etc. + * @returns read receiver frequency */ int setReadReceiverFrequency(int freq=-1); - /** Sets the read receiver timer - if data required from receiver randomly readRxrFrequency=0, - then the timer between each data stream is set with time_in_ms - @param time_in_ms timer between frames - /returns read receiver timer + /** + * Sets the read receiver timer + * if data required from receiver randomly readRxrFrequency=0, + * then the timer between each data stream is set with time_in_ms + * @param time_in_ms timer between frames + * @returns read receiver timer */ int setReceiverReadTimer(int time_in_ms=500); @@ -1801,186 +1928,95 @@ public: * @param enable 0 to disable, 1 to enable, -1 to get the value * @returns data streaming to client enable */ - int enableDataStreamingToClient(int enable=-1) { - cprintf(RED,"ERROR: Must be called from the multi Detector level\n"); - return 0; - } + int enableDataStreamingToClient(int enable=-1); - /** Enable or disable streaming data from receiver to client + /** + * Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value * @returns data streaming from receiver enable */ int enableDataStreamingFromReceiver(int enable=-1); - /** enable/disable or get data compression in receiver + /** + * Enable/disable or get data compression in receiver * @param i is -1 to get, 0 to disable and 1 to enable - /returns data compression in receiver + * @returns data compression in receiver */ int enableReceiverCompression(int i = -1); - /** enable/disable or 10Gbe + /** + * Enable/disable or 10Gbe * @param i is -1 to get, 0 to disable and 1 to enable - /returns if 10Gbe is enabled + * @returns if 10Gbe is enabled */ int enableTenGigabitEthernet(int i = -1); - /** set/get receiver fifo depth + /** + * Set/get receiver fifo depth * @param i is -1 to get, any other value to set the fifo deph - /returns the receiver fifo depth + * @returns the receiver fifo depth */ int setReceiverFifoDepth(int i = -1); - /** set/get receiver silent mode + /** + * Set/get receiver silent mode * @param i is -1 to get, 0 unsets silent mode, 1 sets silent mode - /returns the receiver silent mode enable + * @returns the receiver silent mode enable */ int setReceiverSilentMode(int i = -1); /** - If data streaming in receiver is enabled, - restream the stop dummy packet from receiver - Used usually for Moench, - in case it is lost in network due to high data rate - \returns OK if success else FAIL + * If data streaming in receiver is enabled, + * restream the stop dummy packet from receiver + * Used usually for Moench, + * in case it is lost in network due to high data rate + * @returns OK if success else FAIL */ int restreamStopFromReceiver(); - /** opens pattern file and sends pattern to CTB - @param fname pattern file to open - @returns OK/FAIL + /** + * Opens pattern file and sends pattern to CTB + * @param fname pattern file to open + * @returns OK/FAIL */ int setCTBPattern(string fname); - - /** Writes a pattern word to the CTB - @param addr address of the word, -1 is I/O control register, -2 is clk control register - @param word 64bit word to be written, -1 gets - @returns actual value + /** + * Writes a pattern word to the CTB + * @param addr address of the word, -1 is I/O control register, -2 is clk control register + * @param word 64bit word to be written, -1 gets + * @returns actual value */ uint64_t setCTBWord(int addr,uint64_t word=-1); - /** Sets the pattern or loop limits in the CTB - @param level -1 complete pattern, 0,1,2, loop level - @param start start address if >=0 - @param stop stop address if >=0 - @param n number of loops (if level >=0) - @returns OK/FAIL + /** + * Sets the pattern or loop limits in the CTB + * @param level -1 complete pattern, 0,1,2, loop level + * @param start start address if >=0 + * @param stop stop address if >=0 + * @param n number of loops (if level >=0) + * @returns OK/FAIL */ int setCTBPatLoops(int level,int &start, int &stop, int &n); - - /** Sets the wait address in the CTB - @param level 0,1,2, wait level - @param addr wait address, -1 gets - @returns actual value + /** + * Sets the wait address in the CTB + * @param level 0,1,2, wait level + * @param addr wait address, -1 gets + * @returns actual value */ int setCTBPatWaitAddr(int level, int addr=-1); - /** Sets the wait time in the CTB - @param level 0,1,2, wait level - @param t wait time, -1 gets - @returns actual value + /** + * Sets the wait time in the CTB + * @param level 0,1,2, wait level + * @param t wait time, -1 gets + * @returns actual value */ int setCTBPatWaitTime(int level, uint64_t t=-1); - /** returns the detector MAC address\sa sharedSlsDetector */ - string getDetectorMAC() {return string(thisDetector->detectorMAC);}; - /** returns the detector IP address\sa sharedSlsDetector */ - string getDetectorIP() {return string(thisDetector->detectorIP);}; - /** returns the receiver IP address \sa sharedSlsDetector */ - string getReceiver() {return string(thisDetector->receiver_hostname);}; - /** returns the receiver UDP IP address \sa sharedSlsDetector */ - string getReceiverUDPIP() {return string(thisDetector->receiverUDPIP);}; - /** returns the receiver UDP MAC address \sa sharedSlsDetector */ - string getReceiverUDPMAC() {return string(thisDetector->receiverUDPMAC);}; - /** returns the receiver UDP IP address \sa sharedSlsDetector */ - string getReceiverUDPPort() {ostringstream ss; ss << thisDetector->receiverUDPPort; string s = ss.str(); return s;}; - /** returns the receiver UDP2 for Eiger IP address \sa sharedSlsDetector */ - string getReceiverUDPPort2() {ostringstream ss; ss << thisDetector->receiverUDPPort2; string s = ss.str(); return s;}; - /** returns the client zmq port \sa sharedSlsDetector */ - string getClientStreamingPort() {ostringstream ss; ss << thisDetector->zmqport; string s = ss.str(); return s;}; - /** returns the receiver zmq port \sa sharedSlsDetector */ - string getReceiverStreamingPort() {ostringstream ss; ss << thisDetector->receiver_zmqport; string s = ss.str(); return s;}; - /** gets the zmq source ip in client, returns "none" if default setting and no custom ip set*/ - string getClientStreamingIP(){return string(thisDetector->zmqip);}; - /** gets the zmq source ip in receiver, returns "none" if default setting and no custom ip set*/ - string getReceiverStreamingIP(){return string(thisDetector->receiver_zmqip);}; - /** gets the additional json header, returns "none" if default setting and no custom set*/ - string getAdditionalJsonHeader(){return string(thisDetector->receiver_additionalJsonHeader);}; - /** returns the receiver UDP socket buffer size */ - string getReceiverUDPSocketBufferSize() {return setReceiverUDPSocketBufferSize();}; - /** returns the real receiver UDP socket buffer size */ - string getReceiverRealUDPSocketBufferSize(); - - - /** validates the format of detector MAC address and sets it \sa sharedSlsDetector */ - string setDetectorMAC(string detectorMAC); - /** validates the format of detector IP address and sets it \sa sharedSlsDetector */ - string setDetectorIP(string detectorIP); - /** validates and sets the receiver IP address/hostname \sa sharedSlsDetector */ - string setReceiver(string receiver); - /** validates the format of receiver udp ip and sets it \sa sharedSlsDetector */ - string setReceiverUDPIP(string udpip); - /** validates the format of receiver udp mac and sets it \sa sharedSlsDetector */ - string setReceiverUDPMAC(string udpmac); - /** sets the receiver udp port \sa sharedSlsDetector */ - int setReceiverUDPPort(int udpport); - /** sets the receiver udp port2 for Eiger \sa sharedSlsDetector */ - int setReceiverUDPPort2(int udpport); - /** sets the zmq port in client (includes "multi" at the end if it should calculate individual ports \sa sharedSlsDetector */ - string setClientStreamingPort(string port); - /** sets the zmq port in receiver (includes "multi" at the end if it should calculate individual ports \sa sharedSlsDetector */ - string setReceiverStreamingPort(string port); - /** sets the zmq source ip in client */ - string setClientStreamingIP(string sourceIP); - /** sets the zmq source ip in receiver. if empty, uses rx_hostname*/ - string setReceiverStreamingIP(string sourceIP); - /** additional json header, returns "none" if default setting and no custom set */ - string setAdditionalJsonHeader(string jsonheader); - /** sets the receiver UDP socket buffer size */ - string setReceiverUDPSocketBufferSize(int udpsockbufsize=-1); - - /** sets the transmission delay for left or right port or for an entire frame*/ - string setDetectorNetworkParameter(networkParameter index, int delay); - - - - /** - analog test - \param modte test mode - \return pointer to acquired data - - not yet implemented - */ - - int* analogTest(analogTestMode mode); - - /** - enable analog output of channel ichan - - not yet implemented - */ - int enableAnalogOutput(int ichan); - - /** - enable analog output of channel ichan, chip ichip, module imod - - not yet implemented - */ - int enableAnalogOutput(int imod, int ichip, int ichan); - - /** - give a train of calibration pulses - \param vcal pulse amplitude - \param npulses number of pulses - - not yet implemented - - */ - int giveCalibrationPulse(double vcal, int npulses); - - private: + /** * Get Detector Type from Shared Memory (opening shm without verifying size) * @param multiId multi detector Id @@ -1988,6 +2024,7 @@ private: * @returns detector type */ detectorType getDetectorTypeFromShm(int multiId, bool verify = true); + /** * Initialize shared memory * @param created true if shared memory must be created, else false to open @@ -1998,56 +2035,333 @@ private: */ void initSharedMemory(bool created, detectorType type, int multiId, bool verify = true); + /** + * Sets detector parameters depending detector type + * @param type detector type + * @param list structure of parameters to initialize depending on detector type + */ + void setDetectorSpecificParameters(detectorType type, detParameterList& list); + /** * Calculate shared memory size based on detector type * @param type type of detector + * @returns size of shared memory of sharedSlsDetector structure */ int calculateSharedMemorySize(detectorType type); /** - * Initialize detector structure - * @param created true if shared memory was just created now + * Initialize detector structure to defaults + * Called when new shared memory is created * @param type type of detector - * @param verify true to verify if shm size matches existing one */ - void initializeDetectorStructure(bool created, detectorType type, bool verify = true); + void initializeDetectorStructure(detectorType type); /** * Initialize class members (and from parent classes) + * Also connect member pointers to detector structure pointers + * Called when shared memory created/existed */ void initializeMembers(); - /** Gets MAC from receiver and sets up UDP Connection */ + /** + * Initialize detector structure + * Called when new shared memory created + * Initializes the member pointers to defaults as well + */ + void initializeDetectorStructurePointers(); + + /** + * Allocates the memory for a sls_detector_module structure and initializes it + * Uses current detector type + * @returns myMod the pointer to the allocate dmemory location + */ + sls_detector_module* createModule(); + + /** + * Allocates the memory for a sls_detector_module structure and initializes it + * Has detector type + * @param myDetectorType detector type + * @returns myMod the pointer to the allocate dmemory location + */ + sls_detector_module* createModule(detectorType myDetectorType); + + /** + * Frees the memory for a sls_detector_module structure + * @param myMod the pointer to the memory to be freed + */ + void deleteModule(sls_detector_module *myMod); + + /** + * Connect to the control port + * @returns OK, FAIL or undefined + */ + int connectControl(); + + /** + * Disconnect the control port + */ + void disconnectControl(); + + /** + * Connect to the data port + * @returns OK, FAIL or undefined + */ + int connectData(); + + /** + * Disconnect the data port + */ + int disconnectData(); + + /** + * Connect to the stop port + * @returns OK, FAIL or undefined + */ + int connectStop(); + + /** + * Disconnect the stop port + */ + int disconnectStop(); + + /** + * Send a sls_detector_channel structure over socket + * @param myChan channel structure to send + * @returns number of bytes sent to the detector + */ + int sendChannel(sls_detector_channel* myChan); + + /** + * Send a sls_detector_chip structure over socket + * @param myChip chip structure to send + * @returns number of bytes sent to the detector + */ + int sendChip(sls_detector_chip* myChip); + + /** + * Send a sls_detector_module structure over socket + * @param myMod module structure to send + * @returns number of bytes sent to the detector + */ + int sendModule(sls_detector_module* myMod); + + /** + * Receive a sls_detector_channel structure over socket + * @param myChan channel structure to receive + * @returns number of bytes received from the detector + */ + int receiveChannel(sls_detector_channel* myChan); + + /** + * Receive a sls_detector_chip structure over socket + * @param myChip chip structure to receive + * @returns number of bytes received from the detector + */ + int receiveChip(sls_detector_chip* myChip); + + /** + * Receive a sls_detector_module structure over socket + * @param myMod module structure to receive + * @returns number of bytes received from the detector + */ + int receiveModule(sls_detector_module* myMod); + + /** + * Returns the detector MAC address\sa sharedSlsDetector + * @returns the detector MAC address + */ + string getDetectorMAC(); + + /** + * Returns the detector IP address\sa sharedSlsDetector + * @returns the detector IP address + */ + string getDetectorIP(); + + /** + * Returns the receiver IP address\sa sharedSlsDetector + * @returns the receiver IP address + */ + string getReceiver(); + + /** + * Returns the receiver UDP IP address\sa sharedSlsDetector + * @returns the receiver UDP IP address + */ + string getReceiverUDPIP(); + + /** + * Returns the receiver UDP MAC address\sa sharedSlsDetector + * @returns the receiver UDP MAC address + */ + string getReceiverUDPMAC(); + + /** + * Returns the receiver UDP port\sa sharedSlsDetector + * @returns the receiver UDP port + */ + string getReceiverUDPPort(); + + /** + * Returns the receiver UDP port 2 of same interface\sa sharedSlsDetector + * @returns the receiver UDP port 2 of same interface + */ + string getReceiverUDPPort2(); + + /** + * Returns the client zmq port \sa sharedSlsDetector + * @returns the client zmq port + */ + string getClientStreamingPort(); + + /** + * Returns the receiver zmq port \sa sharedSlsDetector + * @returns the receiver zmq port + */ + string getReceiverStreamingPort(); + + /** + * Returns the client zmq ip \sa sharedSlsDetector + * @returns the client zmq ip, returns "none" if default setting and no custom ip set + */ + string getClientStreamingIP(); + + /** + * Returns the receiver zmq ip \sa sharedSlsDetector + * @returns the receiver zmq ip, returns "none" if default setting and no custom ip set + */ + string getReceiverStreamingIP(); + + /** + * Returns the additional json header \sa sharedSlsDetector + * @returns the additional json header, returns "none" if default setting and no custom ip set + */ + string getAdditionalJsonHeader(); + + /** + * Returns the receiver UDP socket buffer size\sa sharedSlsDetector + * @returns the receiver UDP socket buffer size + */ + string getReceiverUDPSocketBufferSize() ; + + /** + * Returns the receiver real UDP socket buffer size\sa sharedSlsDetector + * @returns the receiver real UDP socket buffer size + */ + string getReceiverRealUDPSocketBufferSize(); + + /** + * Validates the format of the detector MAC address and sets it \sa sharedSlsDetector + * @param detectorMAC detector MAC address + * @returns the detector MAC address + */ + string setDetectorMAC(string detectorMAC); + + /** + * Validates the format of the detector IP address and sets it \sa sharedSlsDetector + * @param detectorIP detector IP address + * @returns the detector IP address + */ + string setDetectorIP(string detectorIP); + + /** + * Validates and sets the receiver. + * Also updates the receiver with all the shared memory parameters significant for the receiver + * Also configures the detector to the receiver as UDP destination + * @param receiver receiver hostname or IP address + * @returns the receiver IP address from shared memory + */ + string setReceiver(string receiver); + + /** + * Validates the format of the receiver UDP IP address and sets it \sa sharedSlsDetector + * @param udpip receiver UDP IP address + * @returns the receiver UDP IP address + */ + string setReceiverUDPIP(string udpip); + + /** + * Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector + * @param udpmac receiver UDP MAC address + * @returns the receiver UDP MAC address + */ + string setReceiverUDPMAC(string udpmac); + + /** + * Sets the receiver UDP port\sa sharedSlsDetector + * @param udpport receiver UDP port + * @returns the receiver UDP port + */ + int setReceiverUDPPort(int udpport); + + /** + * Sets the receiver UDP port 2\sa sharedSlsDetector + * @param udpport receiver UDP port 2 + * @returns the receiver UDP port 2 + */ + int setReceiverUDPPort2(int udpport); + + /** + * Sets the client zmq port\sa sharedSlsDetector + * @param port client zmq port (includes "multi" at the end if it should + * calculate individual ports) + * @returns the client zmq port + */ + string setClientStreamingPort(string port); + + /** + * Sets the receiver zmq port\sa sharedSlsDetector + * @param port receiver zmq port (includes "multi" at the end if it should + * calculate individual ports) + * @returns the receiver zmq port + */ + string setReceiverStreamingPort(string port); + + /** + * Sets the client zmq ip\sa sharedSlsDetector + * @param sourceIP client zmq ip + * @returns the client zmq ip, returns "none" if default setting and no custom ip set + */ + string setClientStreamingIP(string sourceIP); + + /** + * Sets the receiver zmq ip\sa sharedSlsDetector + * @param sourceIP receiver zmq ip. If empty, uses rx_hostname + * @returns the receiver zmq ip, returns "none" if default setting and no custom ip set + */ + string setReceiverStreamingIP(string sourceIP); + + /** + * Sets the additional json header\sa sharedSlsDetector + * @param jsonheader additional json header + * @returns additional json header, returns "none" if default setting and no custom ip set + */ + string setAdditionalJsonHeader(string jsonheader); + + /** + * Sets the receiver UDP socket buffer size + * @param udpsockbufsize additional json header + * @returns receiver udp socket buffer size + */ + string setReceiverUDPSocketBufferSize(int udpsockbufsize=-1); + + /** + * Sets the transmission delay for left, right or entire frame + * (Eiger, Jungfrau(only entire frame)) + * @param index type of delay + * @param delay delay + * @returns transmission delay + */ + string setDetectorNetworkParameter(networkParameter index, int delay); + + + /** + * Get MAC from the receiver using udpip and + * set up UDP connection in detector + * @returns Ok or FAIL + */ int setUDPConnection(); - - /** - send a sls_detector_channel structure over socket - */ - int sendChannel(sls_detector_channel*); - /** - send a sls_detector_chip structure over socket - */ - int sendChip(sls_detector_chip*); - /** - send a sls_detector_module structure over socket - */ - int sendModule(sls_detector_module*); - /** - receive a sls_detector_channel structure over socket - */ - int receiveChannel(sls_detector_channel*); - /** - receive a sls_detector_chip structure over socket - */ - int receiveChip(sls_detector_chip*); - /** - receive a sls_detector_module structure over socket - */ - int receiveModule(sls_detector_module*); - - - /** slsDetector Id or position in the detectors list */ int detId; @@ -2062,35 +2376,41 @@ private: receiverInterface *thisReceiver; - /** socket for control commands */ + /** socket for control commands */ MySocketTCP *controlSocket; - /** socket for emergency stop */ + /** socket for emergency stop */ MySocketTCP *stopSocket; - /** socket for data acquisition */ + /** socket for data acquisition */ MySocketTCP *dataSocket; - /** pointer to detector module structures in shared memory */ - sls_detector_module *detectorModules; - /** pointer to dac valuse in shared memory */ - dacs_t *dacs; - /** pointer to adc valuse in shared memory */ - dacs_t *adcs; - /** pointer to chip registers in shared memory */ - int *chipregs; - /** pointer to channal registers in shared memory */ - int *chanregs; - /** pointer to gain values in shared memory */ - int *gain; - /** pointer to offset values in shared memory */ - int *offset; - /** pointer to flat field coefficients in shared memory */ double *ffcoefficients; + /** pointer to flat field coefficient errors in shared memory */ double *fferrors; + /** pointer to detector module structures in shared memory */ + sls_detector_module *detectorModules; + + /** pointer to dac valuse in shared memory */ + dacs_t *dacs; + + /** pointer to adc valuse in shared memory */ + dacs_t *adcs; + + /** pointer to chip registers in shared memory */ + int *chipregs; + + /** pointer to channal registers in shared memory */ + int *chanregs; + + /** pointer to gain values in shared memory */ + int *gain; + + /** pointer to offset values in shared memory */ + int *offset; }; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 73c60900b..6a677cfde 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -216,13 +216,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual std::string sgetDetectorsType(int pos=-1)=0; - /** returns the detector type - \param pos position in the multi detector structure (is -1 returns type of detector with id -1) - \returns type - */ - virtual detectorType setDetectorsType(detectorType t=GET_DETECTOR_TYPE, int pos=-1)=0; - virtual std::string ssetDetectorsType(detectorType t=GET_DETECTOR_TYPE, int pos=-1)=0; - virtual std::string ssetDetectorsType(std::string s, int pos=-1)=0; +