Skip to content
Snippets Groups Projects
Commit 1451051c authored by Stephen A. Wood's avatar Stephen A. Wood
Browse files

Do type conversion if var in param file doesn't match DBrequest type

parent fab7f510
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "THaVar.h" #include "THaVar.h"
#include "THaFormula.h" #include "THaFormula.h"
#include "TMath.h"
/* #incluce <algorithm> include <fstream> include <cstring> */ /* #incluce <algorithm> include <fstream> include <cstring> */
#include <iostream> #include <iostream>
...@@ -445,10 +447,17 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) ...@@ -445,10 +447,17 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix)
} }
} else { } else {
VarType ty = this->Find(key)->GetType();
switch (ti->type) { switch (ti->type) {
case (kDouble) : case (kDouble) :
if (this->Find(key)) { if (this->Find(key)) {
*static_cast<Double_t*>(ti->var)=*(Double_t *)this->Find(key)->GetValuePointer(); if(ty == kInt) {
*static_cast<Double_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer();
} else if (ty == kDouble) {
*static_cast<Double_t*>(ti->var)=*(Double_t *)this->Find(key)->GetValuePointer();
} else {
cout << "*** ERROR!!! Type Mismatch " << key << endl;
}
} else { } else {
cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl;
} }
...@@ -457,7 +466,14 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) ...@@ -457,7 +466,14 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix)
break; break;
case (kInt) : case (kInt) :
if (this->Find(key)) { if (this->Find(key)) {
*static_cast<Int_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer(); if(ty == kInt) {
*static_cast<Int_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer();
} else if (ty == kDouble) {
*static_cast<Int_t*>(ti->var)=TMath::Nint(*(Double_t *)this->Find(key)->GetValuePointer());
cout << "*** WARNING!!! Rounded " << key << " to nearest integer " << endl;
} else {
cout << "*** ERROR!!! Type Mismatch " << key << endl;
}
} else { } else {
cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment