From 687535308ed708becb1cf8269b9fd22459d6aefa Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Thu, 7 Feb 2013 13:49:35 -0500 Subject: [PATCH] Print error instead of crashing when DBRequested variable doesn't exist --- src/THcParmList.cxx | 60 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index b3a4a1a..c45b170 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -432,25 +432,25 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) string keystr(prefix); keystr.append(ti->name); const char* key = keystr.c_str(); /// cout <<"Now at "<<ti->name<<endl; - if (ti->nelem>1) { - // it is an array, use the appropriateinterface - switch (ti->type) { - case (kDouble) : - this_cnt = GetArray(key,static_cast<Double_t*>(ti->var),ti->nelem); - break; - case (kInt) : - this_cnt = GetArray(key,static_cast<Int_t*>(ti->var),ti->nelem); - break; - default: - Error("THcParmList","Invalid type to read %s",key); - break; - } - - } else { + if(this->Find(key)) { VarType ty = this->Find(key)->GetType(); - switch (ti->type) { - case (kDouble) : - if (this->Find(key)) { + if (ti->nelem>1) { + // it is an array, use the appropriateinterface + switch (ti->type) { + case (kDouble) : + this_cnt = GetArray(key,static_cast<Double_t*>(ti->var),ti->nelem); + break; + case (kInt) : + this_cnt = GetArray(key,static_cast<Int_t*>(ti->var),ti->nelem); + break; + default: + Error("THcParmList","Invalid type to read %s",key); + break; + } + + } else { + switch (ti->type) { + case (kDouble) : if(ty == kInt) { *static_cast<Double_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer(); } else if (ty == kDouble) { @@ -458,14 +458,10 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) } else { cout << "*** ERROR!!! Type Mismatch " << key << endl; } - } else { - cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; - } - this_cnt=1; + this_cnt=1; - break; - case (kInt) : - if (this->Find(key)) { + break; + case (kInt) : if(ty == kInt) { *static_cast<Int_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer(); } else if (ty == kDouble) { @@ -474,15 +470,15 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) } else { cout << "*** ERROR!!! Type Mismatch " << key << endl; } - } else { - cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; + this_cnt=1; + break; + default: + Error("THcParmList","Invalid type to read %s",key); + break; } - this_cnt=1; - break; - default: - Error("THcParmList","Invalid type to read %s",key); - break; } + } else { + cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; } if (this_cnt<=0) { if ( !ti->optional ) { -- GitLab