mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
works for get setttings and for loadsettingsfile
This commit is contained in:
@ -293,10 +293,14 @@ int multiSlsDetector::createThreadPool(){
|
|||||||
cerr << "Failed to initialize thread pool!" << endl;
|
cerr << "Failed to initialize thread pool!" << endl;
|
||||||
return FAIL;
|
return FAIL;
|
||||||
case 1:
|
case 1:
|
||||||
|
#ifdef VERBOSE
|
||||||
cout << "Not initializing threads, only one detector" << endl;
|
cout << "Not initializing threads, only one detector" << endl;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
#ifdef VERBOSE
|
||||||
cout << "Initialized Threadpool" << endl;
|
cout << "Initialized Threadpool" << endl;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
@ -306,7 +310,9 @@ void multiSlsDetector::destroyThreadPool(){
|
|||||||
if(threadpool){
|
if(threadpool){
|
||||||
threadpool->destroy_threadpool();
|
threadpool->destroy_threadpool();
|
||||||
threadpool=0;
|
threadpool=0;
|
||||||
|
#ifdef VERBOSE
|
||||||
cout<<"Destroyed Threadpool"<<endl;
|
cout<<"Destroyed Threadpool"<<endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1127,7 +1133,7 @@ int multiSlsDetector::setThresholdEnergy(int e_eV, int pos, detectorSettings ise
|
|||||||
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
||||||
|
|
||||||
int i, posmin, posmax;
|
int i, posmin, posmax;
|
||||||
int ret1=-100, ret=-1;
|
int ret1=-1, ret=-100;
|
||||||
|
|
||||||
if (pos<0) {
|
if (pos<0) {
|
||||||
posmin=0;
|
posmin=0;
|
||||||
@ -1137,21 +1143,22 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
|||||||
posmax=pos+1;
|
posmax=pos+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if(!threadpool){
|
||||||
if(!threadpool){cout << "Error in creating threadpool. Exiting" << endl;return GET_SETTINGS;}
|
cout << "Error in creating threadpool. Exiting" << endl;
|
||||||
else{
|
return GET_SETTINGS;
|
||||||
|
}else{
|
||||||
//return storage values
|
//return storage values
|
||||||
int* iret[posmax-posmin];
|
int* iret[posmax-posmin];
|
||||||
for(int idet=posmin; idet<posmax; idet++){
|
for(int idet=posmin; idet<posmax; idet++){
|
||||||
if(detectors[idet]){
|
if(detectors[idet]){
|
||||||
iret[idet]= new int(-1);
|
iret[idet]= new int(-1);
|
||||||
Task* task = new Task(new func_t<detectorSettings,slsDetector,int,int>(&slsDetector::getSettings,
|
Task* task = new Task(new func1_t<detectorSettings,slsDetector,int,int>(&slsDetector::getSettings,
|
||||||
detectors[idet],-1,iret[idet]));
|
detectors[idet],-1,iret[idet]));
|
||||||
threadpool->add_task(task);
|
threadpool->add_task(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
threadpool->wait_for_tasks_to_complete();
|
threadpool->wait_for_tasks_to_complete();
|
||||||
for(int idet=posmin; idet<posmax; idet++){cout<<"final iret:"<<*iret[idet]<<endl;
|
for(int idet=posmin; idet<posmax; idet++){
|
||||||
if(detectors[idet]){
|
if(detectors[idet]){
|
||||||
if(iret[idet] != NULL){
|
if(iret[idet] != NULL){
|
||||||
ret1 = *iret[idet];
|
ret1 = *iret[idet];
|
||||||
@ -1164,20 +1171,7 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
for (i=posmin; i<posmax; i++) {
|
|
||||||
if (detectors[i]) {
|
|
||||||
ret1=detectors[i]->getSettings();cout<<"ret1:"<<ret1<<endl;
|
|
||||||
if(detectors[i]->getErrorMask())
|
|
||||||
setErrorMask(getErrorMask()|(1<<i));
|
|
||||||
if (ret==GET_SETTINGS)
|
|
||||||
ret=ret;
|
|
||||||
else if (ret!=ret1)
|
|
||||||
ret=GET_SETTINGS;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thisMultiDetector->currentSettings=(detectorSettings)ret;
|
thisMultiDetector->currentSettings=(detectorSettings)ret;
|
||||||
return (detectorSettings)ret;
|
return (detectorSettings)ret;
|
||||||
}
|
}
|
||||||
@ -3837,7 +3831,7 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo
|
|||||||
|
|
||||||
|
|
||||||
int multiSlsDetector::loadSettingsFile(string fname, int imod) {
|
int multiSlsDetector::loadSettingsFile(string fname, int imod) {
|
||||||
int id, im, ret;
|
int id, im, ret=-100,ret1=-1;
|
||||||
|
|
||||||
if (decodeNMod(imod, id, im)>=0) {
|
if (decodeNMod(imod, id, im)>=0) {
|
||||||
if (detectors[id]) {
|
if (detectors[id]) {
|
||||||
@ -3847,13 +3841,47 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
} else if (imod<0) {
|
} else if (imod<0) {
|
||||||
|
|
||||||
|
|
||||||
|
if(!threadpool){
|
||||||
|
cout << "Error in creating threadpool. Exiting" << endl;
|
||||||
|
return -1;
|
||||||
|
}else{
|
||||||
|
//return storage values
|
||||||
|
int* iret[thisMultiDetector->numberOfDetectors];
|
||||||
|
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||||
|
if(detectors[idet]){
|
||||||
|
iret[idet]= new int(-1);
|
||||||
|
Task* task = new Task(new func2_t <int,slsDetector,string,int,int>(&slsDetector::loadSettingsFile,
|
||||||
|
detectors[idet],fname,imod,iret[idet]));
|
||||||
|
threadpool->add_task(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
threadpool->wait_for_tasks_to_complete();
|
||||||
|
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
|
||||||
|
if(detectors[idet]){
|
||||||
|
if(iret[idet] != NULL){
|
||||||
|
ret1 = *iret[idet];
|
||||||
|
delete iret[idet];
|
||||||
|
}
|
||||||
|
if(detectors[idet]->getErrorMask())
|
||||||
|
setErrorMask(getErrorMask()|(1<<idet));
|
||||||
|
if (ret==-100)
|
||||||
|
ret=ret1;
|
||||||
|
else if (ret!=ret1)
|
||||||
|
ret=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||||
if (detectors[idet]) {
|
if (detectors[idet]) {
|
||||||
ret=detectors[idet]->loadSettingsFile(fname, imod);
|
ret=detectors[idet]->loadSettingsFile(fname, imod);
|
||||||
if(detectors[idet]->getErrorMask())
|
if(detectors[idet]->getErrorMask())
|
||||||
setErrorMask(getErrorMask()|(1<<idet));
|
setErrorMask(getErrorMask()|(1<<idet));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3099,9 +3099,9 @@ slsDetectorDefs::detectorSettings slsDetector::getSettings(int imod){
|
|||||||
} else{
|
} else{
|
||||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
thisDetector->currentSettings=(detectorSettings)retval;
|
thisDetector->currentSettings=(detectorSettings)retval;
|
||||||
//#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Settings are "<< retval << std::endl;
|
std::cout<< "Settings are "<< retval << std::endl;
|
||||||
//#endif
|
#endif
|
||||||
}
|
}
|
||||||
disconnectControl();
|
disconnectControl();
|
||||||
if (ret==FORCE_UPDATE)
|
if (ret==FORCE_UPDATE)
|
||||||
|
@ -94,7 +94,7 @@ int Multi::printNumber(int inum){
|
|||||||
iret[i]= new int(-1);
|
iret[i]= new int(-1);
|
||||||
//func_t <int,Single,int, int>* binder =
|
//func_t <int,Single,int, int>* binder =
|
||||||
// new func_t<int, Single,int, int>(&Single::printNumber,singles[i],inum,iret[i]);
|
// new func_t<int, Single,int, int>(&Single::printNumber,singles[i],inum,iret[i]);
|
||||||
Task* task = new Task(new func_t<int, Single,int, int>(&Single::printNumber,singles[i],inum,iret[i]));
|
Task* task = new Task(new func1_t<int, Single,int, int>(&Single::printNumber,singles[i],inum,iret[i]));
|
||||||
threadpool->add_task(task);
|
threadpool->add_task(task);
|
||||||
}
|
}
|
||||||
threadpool->wait_for_tasks_to_complete();
|
threadpool->wait_for_tasks_to_complete();
|
||||||
@ -125,8 +125,8 @@ string Multi::printString(string s){
|
|||||||
|
|
||||||
for(int i=0;i<numSingles;i++){
|
for(int i=0;i<numSingles;i++){
|
||||||
sret[i]= new string("sss");
|
sret[i]= new string("sss");
|
||||||
func_t <string,Single,string,string>* binder =
|
func1_t <string,Single,string,string>* binder =
|
||||||
new func_t<string,Single,string,string>(&Single::printString,singles[i],s,sret[i]);
|
new func1_t<string,Single,string,string>(&Single::printString,singles[i],s,sret[i]);
|
||||||
Task* task = new Task(binder);
|
Task* task = new Task(binder);
|
||||||
threadpool->add_task(task);
|
threadpool->add_task(task);
|
||||||
}
|
}
|
||||||
@ -164,8 +164,8 @@ char* Multi::printCharArray(char a[]){
|
|||||||
for(int i=0;i<numSingles;i++){
|
for(int i=0;i<numSingles;i++){
|
||||||
sret[i]= new string("sss");
|
sret[i]= new string("sss");
|
||||||
//std::fill_n(cret[i],1000,0);
|
//std::fill_n(cret[i],1000,0);
|
||||||
func_t <char*,Single,char*,string>* binder =
|
func1_t <char*,Single,char*,string>* binder =
|
||||||
new func_t <char*,Single,char*,string>(&Single::printCharArray,singles[i],a,sret[i]);
|
new func1_t <char*,Single,char*,string>(&Single::printCharArray,singles[i],a,sret[i]);
|
||||||
Task* task = new Task(binder);
|
Task* task = new Task(binder);
|
||||||
threadpool->add_task(task);
|
threadpool->add_task(task);
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,12 @@ class slsDetector;
|
|||||||
|
|
||||||
|
|
||||||
template<typename _Ret, typename _Class,typename _Arg1, typename _Store>
|
template<typename _Ret, typename _Class,typename _Arg1, typename _Store>
|
||||||
class func_t{
|
class func1_t{
|
||||||
public:
|
public:
|
||||||
func_t(_Ret (_Class::*fn)(_Arg1),_Class* ptr,_Arg1 arg1, _Store* sto):m_fn(fn),m_ptr(ptr),m_arg1(arg1),m_store(sto){}
|
func1_t(_Ret (_Class::*fn)(_Arg1),_Class* ptr,_Arg1 arg1, _Store* sto):
|
||||||
~func_t() {}
|
m_fn(fn),m_ptr(ptr),m_arg1(arg1),m_store(sto){}
|
||||||
|
~func1_t() {}
|
||||||
void operator()() const {*m_store = ((m_ptr->*m_fn)(m_arg1));}
|
void operator()() const {*m_store = ((m_ptr->*m_fn)(m_arg1));}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
_Class* m_ptr;
|
_Class* m_ptr;
|
||||||
_Ret (_Class::*m_fn)(_Arg1);
|
_Ret (_Class::*m_fn)(_Arg1);
|
||||||
@ -32,22 +31,53 @@ private:
|
|||||||
_Store* m_store;
|
_Store* m_store;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename _Ret, typename _Class,typename _Arg1, typename _Arg2,typename _Store>
|
||||||
|
class func2_t{
|
||||||
|
public:
|
||||||
|
func2_t(_Ret (_Class::*fn)(_Arg1,_Arg2),_Class* ptr,_Arg1 arg1,_Arg2 arg2,_Store* sto):
|
||||||
|
m_fn(fn),m_ptr(ptr),m_arg1(arg1),m_arg2(arg2),m_store(sto){}
|
||||||
|
~func2_t() {}
|
||||||
|
void operator()() const {*m_store = ((m_ptr->*m_fn)(m_arg1,m_arg2));}
|
||||||
|
private:
|
||||||
|
_Class* m_ptr;
|
||||||
|
_Ret (_Class::*m_fn)(_Arg1,_Arg2);
|
||||||
|
_Arg1 m_arg1;
|
||||||
|
_Arg2 m_arg2;
|
||||||
|
_Store* m_store;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename _Ret, typename _Class,typename _Arg1, typename _Arg2, typename _Arg3, typename _Arg4,typename _Store>
|
||||||
|
class func4_t{
|
||||||
|
public:
|
||||||
|
func4_t(_Ret (_Class::*fn)(_Arg1,_Arg2,_Arg3,_Arg4),_Class* ptr,_Arg1 arg1,_Arg2 arg2,_Arg3 arg3,_Arg4 arg4,_Store* sto):
|
||||||
|
m_fn(fn),m_ptr(ptr),m_arg1(arg1),m_arg2(arg2),m_arg3(arg3),m_arg4(arg4),m_store(sto){}
|
||||||
|
~func4_t() {}
|
||||||
|
void operator()() const {*m_store = ((m_ptr->*m_fn)(m_arg1,m_arg2,m_arg3,m_arg4));}
|
||||||
|
private:
|
||||||
|
_Class* m_ptr;
|
||||||
|
_Ret (_Class::*m_fn)(_Arg1,_Arg2,_Arg3,_Arg4);
|
||||||
|
_Arg1 m_arg1;
|
||||||
|
_Arg2 m_arg2;
|
||||||
|
_Arg3 m_arg3;
|
||||||
|
_Arg4 m_arg4;
|
||||||
|
_Store* m_store;
|
||||||
|
};
|
||||||
|
|
||||||
class Task: public virtual slsDetectorDefs{
|
class Task: public virtual slsDetectorDefs{
|
||||||
public:
|
public:
|
||||||
Task(func_t <int,slsDetector,int,int>* t):m_int1(t),m_string1(0),m_chararr1(0),
|
Task(func1_t <int,slsDetector,int,int>* t):
|
||||||
m_settings(0){};
|
m_int1(t),m_string1(0),m_chararr1(0),m_f2_1(0),m_settings(0){};
|
||||||
Task(func_t <string,slsDetector,string,string>* t): m_int1(0),m_string1(t),m_chararr1(0),
|
Task(func1_t <string,slsDetector,string,string>* t):
|
||||||
m_settings(0){};
|
m_int1(0),m_string1(t),m_chararr1(0),m_f2_1(0),m_settings(0){};
|
||||||
Task(func_t <char*,slsDetector,char*,string>* t):m_int1(0),m_string1(0),m_chararr1(t),
|
Task(func1_t <char*,slsDetector,char*,string>* t):
|
||||||
m_settings(0){};
|
m_int1(0),m_string1(0),m_chararr1(t),m_f2_1(0),m_settings(0){};
|
||||||
|
|
||||||
|
Task(func2_t <int,slsDetector,string,int,int>* t):
|
||||||
|
m_int1(0),m_string1(0),m_chararr1(0),m_f2_1(t),m_settings(0){};
|
||||||
|
|
||||||
//settings
|
//specialized
|
||||||
Task(func_t <slsDetectorDefs::detectorSettings,slsDetector,int,int>* t):
|
Task(func1_t <detectorSettings,slsDetector,int,int>* t):
|
||||||
m_int1(0),m_string1(0),m_chararr1(0),
|
m_int1(0),m_string1(0),m_chararr1(0),m_f2_1(0),m_settings(t){};
|
||||||
m_settings(t)
|
|
||||||
{};
|
|
||||||
|
|
||||||
~Task(){}
|
~Task(){}
|
||||||
|
|
||||||
@ -55,14 +85,22 @@ public:
|
|||||||
if(m_int1) (*m_int1)();
|
if(m_int1) (*m_int1)();
|
||||||
else if(m_string1) (*m_string1)();
|
else if(m_string1) (*m_string1)();
|
||||||
else if(m_chararr1) (*m_chararr1)();
|
else if(m_chararr1) (*m_chararr1)();
|
||||||
|
|
||||||
|
else if(m_f2_1) (*m_f2_1)();
|
||||||
|
|
||||||
|
//specialized
|
||||||
else if(m_settings) (*m_settings)();
|
else if(m_settings) (*m_settings)();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
func_t <int,slsDetector,int,int>* m_int1;
|
func1_t <int,slsDetector,int,int>* m_int1;
|
||||||
func_t <string,slsDetector,string,string>* m_string1;
|
func1_t <string,slsDetector,string,string>* m_string1;
|
||||||
func_t <char*,slsDetector,char*,string>* m_chararr1;
|
func1_t <char*,slsDetector,char*,string>* m_chararr1;
|
||||||
func_t <slsDetectorDefs::detectorSettings,slsDetector,int,int>* m_settings;
|
func2_t <int,slsDetector,string,int,int>* m_f2_1;
|
||||||
|
|
||||||
|
//specialized
|
||||||
|
func1_t <detectorSettings,slsDetector,int,int>* m_settings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size)
|
ThreadPool::ThreadPool(int pool_size) : m_pool_size(pool_size)
|
||||||
{
|
{
|
||||||
|
#ifdef VERBOSE
|
||||||
cout << "Constructed ThreadPool of size " << m_pool_size << endl;
|
cout << "Constructed ThreadPool of size " << m_pool_size << endl;
|
||||||
|
#endif
|
||||||
m_tasks_loaded = false;
|
m_tasks_loaded = false;
|
||||||
thread_started = false;
|
thread_started = false;
|
||||||
current_thread_number = -1;
|
current_thread_number = -1;
|
||||||
@ -49,8 +51,9 @@ int ThreadPool::initialize_threadpool()
|
|||||||
m_threads.push_back(tid);
|
m_threads.push_back(tid);
|
||||||
while(!thread_started);
|
while(!thread_started);
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
cout << m_pool_size << " threads created by the thread pool" << endl;
|
cout << m_pool_size << " threads created by the thread pool" << endl;
|
||||||
|
#endif
|
||||||
return m_pool_size;
|
return m_pool_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user