included parallelization for setsettings, setalltrimbits, pulsechip, pulsepixel, pulsepixelnmove

This commit is contained in:
Dhanya Maliakal 2016-03-16 11:18:35 +01:00
parent 4c5736db5e
commit a2c41b58d9
2 changed files with 221 additions and 102 deletions

View File

@ -1178,34 +1178,50 @@ slsDetectorDefs::detectorSettings multiSlsDetector::getSettings(int pos) {
slsDetectorDefs::detectorSettings multiSlsDetector::setSettings(detectorSettings isettings, int pos) {
int posmin, posmax;
int ret1=-1, ret=-100;
int i, posmin, posmax;
detectorSettings ret1=GET_SETTINGS, ret;
if (pos<0) {
posmin=0;
posmax=thisMultiDetector->numberOfDetectors;
} else {
posmin=pos;
posmax=pos+1;
}
if (pos<0) {
posmin=0;
posmax=thisMultiDetector->numberOfDetectors;
} else {
posmin=pos;
posmax=pos+1;
}
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return GET_SETTINGS;
}else{
//return storage values
int* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if(detectors[idet]){
iret[idet]= new int(-1);
Task* task = new Task(new func2_t<detectorSettings,slsDetector,detectorSettings,int,int>(&slsDetector::setSettings,
detectors[idet],isettings,-1,iret[idet]));
threadpool->add_task(task);
}
}
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; 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=GET_SETTINGS;
}
}
}
for (i=posmin; i<posmax; i++) {
if (detectors[i]) {
ret=detectors[i]->setSettings(isettings);
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret1==GET_SETTINGS)
ret1=ret;
else if (ret!=ret1)
ret1=GET_SETTINGS;
}
}
thisMultiDetector->currentSettings=ret1;
return ret1;
thisMultiDetector->currentSettings=(detectorSettings)ret1;
return (detectorSettings)ret1;
}
@ -3873,16 +3889,8 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) {
}
}
}
/*
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret=detectors[idet]->loadSettingsFile(fname, imod);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}*/
return ret;
return ret;
}
return -1;
@ -3917,7 +3925,7 @@ int multiSlsDetector::saveSettingsFile(string fname, int imod) {
int multiSlsDetector::setAllTrimbits(int val, int imod){
int ret=-100, ret1,id, im;
int ret=-100, ret1=-1,id, im;
if (decodeNMod(imod, id, im)>=0) {
if (detectors[id]) {
@ -3927,15 +3935,35 @@ int multiSlsDetector::setAllTrimbits(int val, int imod){
}
}
else if (imod<0) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setAllTrimbits(val,imod);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
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,int,int,int>(&slsDetector::setAllTrimbits,
detectors[idet],val,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;
}
}
}
}
@ -5265,49 +5293,113 @@ int multiSlsDetector::setCTBPatWaitTime(int level, uint64_t t) {
int multiSlsDetector::pulsePixel(int n,int x,int y) {
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->pulsePixel(n,x,y);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
int ret=-100,ret1=-1;
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 func3_t <int,slsDetector,int,int,int,int>(&slsDetector::pulsePixel,
detectors[idet],n,x,y,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;
}
}
}
return ret;
}
int multiSlsDetector::pulsePixelNMove(int n,int x,int y) {
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->pulsePixelNMove(n,x,y);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
int ret=-100,ret1=-1;
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 func3_t <int,slsDetector,int,int,int,int>(&slsDetector::pulsePixelNMove,
detectors[idet],n,x,y,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;
}
}
}
return ret;
}
int multiSlsDetector::pulseChip(int n) {
int ret=-100,ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++)
if (detectors[idet]){
ret1=detectors[idet]->pulseChip(n);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
int ret=-100,ret1=-1;
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 func1_t <int,slsDetector,int,int>(&slsDetector::pulseChip,
detectors[idet],n,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;
}
}
}
return ret;
}

View File

@ -46,6 +46,22 @@ private:
_Store* m_store;
};
template<typename _Ret, typename _Class,typename _Arg1, typename _Arg2, typename _Arg3, typename _Store>
class func3_t{
public:
func3_t(_Ret (_Class::*fn)(_Arg1,_Arg2,_Arg3),_Class* ptr,_Arg1 arg1,_Arg2 arg2,_Arg3 arg3,_Store* sto):
m_fn(fn),m_ptr(ptr),m_arg1(arg1),m_arg2(arg2),m_arg3(arg3),m_store(sto){}
~func3_t() {}
void operator()() const {*m_store = ((m_ptr->*m_fn)(m_arg1,m_arg2,m_arg3));}
private:
_Class* m_ptr;
_Ret (_Class::*m_fn)(_Arg1,_Arg2,_Arg3);
_Arg1 m_arg1;
_Arg2 m_arg2;
_Arg3 m_arg3;
_Store* m_store;
};
template<typename _Ret, typename _Class,typename _Arg1, typename _Arg2, typename _Arg3, typename _Arg4,typename _Store>
class func4_t{
public:
@ -65,42 +81,53 @@ private:
class Task: public virtual slsDetectorDefs{
public:
Task(func1_t <int,slsDetector,int,int>* t):
m_int1(t),m_string1(0),m_chararr1(0),m_f2_1(0),m_settings(0){};
Task(func1_t <string,slsDetector,string,string>* t):
m_int1(0),m_string1(t),m_chararr1(0),m_f2_1(0),m_settings(0){};
Task(func1_t <char*,slsDetector,char*,string>* t):
m_int1(0),m_string1(0),m_chararr1(t),m_f2_1(0),m_settings(0){};
/* Return: int, Param: int */
Task(func1_t <int,slsDetector,int,int>* t): m1(t),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0){};
/* Return: int, Param: string,int */
Task(func2_t <int,slsDetector,string,int,int>* t): m1(0),m2(t),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0){};
/* Return: string, Param: string */
Task(func1_t <string,slsDetector,string,string>* t): m1(0),m2(0),m3(t),m4(0),m5(0),m6(0),m7(0),m8(0){};
/* Return: char*, Param: char* */
Task(func1_t <char*,slsDetector,char*,string>* t): m1(0),m2(0),m3(0),m4(t),m5(0),m6(0),m7(0),m8(0){};
/* Return: detectorSettings, Param: int */
Task(func1_t <detectorSettings,slsDetector,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(t),m6(0),m7(0),m8(0){};
/* Return: detectorSettings, Param: detectorSettings,int */
Task(func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(t),m7(0),m8(0){};
/* Return: int, Param: int,int */
Task(func2_t <int,slsDetector,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(t),m8(0){};
/* Return: int, Param: int,int */
Task(func3_t <int,slsDetector,int,int,int,int>* t): m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(t){};
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){};
//specialized
Task(func1_t <detectorSettings,slsDetector,int,int>* t):
m_int1(0),m_string1(0),m_chararr1(0),m_f2_1(0),m_settings(t){};
~Task(){}
void operator()(){
if(m_int1) (*m_int1)();
else if(m_string1) (*m_string1)();
else if(m_chararr1) (*m_chararr1)();
else if(m_f2_1) (*m_f2_1)();
//specialized
else if(m_settings) (*m_settings)();
if(m1) (*m1)();
else if(m2) (*m2)();
else if(m3) (*m3)();
else if(m4) (*m4)();
else if(m5) (*m5)();
else if(m6) (*m6)();
else if(m7) (*m7)();
}
private:
func1_t <int,slsDetector,int,int>* m_int1;
func1_t <string,slsDetector,string,string>* m_string1;
func1_t <char*,slsDetector,char*,string>* m_chararr1;
func2_t <int,slsDetector,string,int,int>* m_f2_1;
//specialized
func1_t <detectorSettings,slsDetector,int,int>* m_settings;
/* Return: int, Param: int */
func1_t <int,slsDetector,int,int>* m1;
/* Return: int, Param: string,int */
func2_t <int,slsDetector,string,int,int>* m2;
/* Return: string, Param: string */
func1_t <string,slsDetector,string,string>* m3;
/* Return: char*, Param: char* */
func1_t <char*,slsDetector,char*,string>* m4;
/* Return: detectorSettings, Param: int */
func1_t <detectorSettings,slsDetector,int,int>* m5;
/* Return: detectorSettings, Param: detectorSettings,int */
func2_t <detectorSettings,slsDetector,detectorSettings,int,int>* m6;
/* Return: int, Param: int,int */
func2_t <int,slsDetector,int,int,int>* m7;
/* Return: int, Param: int,int */
func3_t <int,slsDetector,int,int,int,int>* m8;
};