From cf59729c474a8315e0b36e20f55cfb62d67296bc Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Thu, 6 Sep 2012 14:46:42 -0400 Subject: [PATCH] Add a "prefix" argument to THcParmList::LoadValues. The prefix gets prepended to all variables in the DBRequest list. --- src/THcHodoscope.cxx | 14 +++++++------- src/THcParmList.cxx | 26 +++++++++++++++----------- src/THcParmList.h | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx index 5c417dc..971fc4c 100644 --- a/src/THcHodoscope.cxx +++ b/src/THcHodoscope.cxx @@ -330,15 +330,15 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date ) DBRequest list[]={ - {Form("%sstart_time_center",prefix),&fStartTimeCenter, kDouble}, - {Form("%sstart_time_slop",prefix) , &fStartTimeSlop, kDouble}, - {Form("%sscin_tdc_to_time",prefix), &fScinTdcToTime, kDouble}, - {Form("%sscin_tdc_min",prefix), &fScinTdcMin, kDouble}, - {Form("%sscin_tdc_max",prefix), &fScinTdcMax, kDouble}, - {Form("%stof_tolerance",prefix), &fTofTolerance, kDouble}, + {"start_time_center", &fStartTimeCenter, kDouble}, + {"start_time_slop", &fStartTimeSlop, kDouble}, + {"scin_tdc_to_time", &fScinTdcToTime, kDouble}, + {"scin_tdc_min", &fScinTdcMin, kDouble}, + {"scin_tdc_max", &fScinTdcMax, kDouble}, + {"tof_tolerance", &fTofTolerance, kDouble}, {0} }; - gHcParms->LoadParmValues((DBRequest*)&list); + gHcParms->LoadParmValues((DBRequest*)&list,prefix); cout <<"******* Testing *** "<<fStartTimeCenter<<" "<<fStartTimeSlop; cout <<" "<<fScinTdcToTime; cout <<" "<<fScinTdcMin; diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index 624a673..aa19cf1 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -343,7 +343,7 @@ void THcParmList::Load( const char* fname, Int_t RunNumber ) } //_____________________________________________________________________________ -Int_t THcParmList::LoadParmValues(const DBRequest* list) +Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) { // Load a number of entries from the database. // For array entries, the number of elements to be read in @@ -355,10 +355,14 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list) Int_t cnt=0; Int_t this_cnt=0; + if( !prefix ) prefix = ""; + while ( ti && ti->name ) { + 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 appropriate interface + // it is an array, use the appropriateinterface switch (ti->type) { case (kDouble) : // this_cnt = GetArray(system,ti->name,static_cast<Double_t*>(ti->var), @@ -369,37 +373,37 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list) //ti->expected,date); break; default: - Error("THcParmList","Invalid type to read %s",ti->name); + Error("THcParmList","Invalid type to read %s",key); break; } } else { switch (ti->type) { case (kDouble) : - if (this->Find(ti->name)) { - *static_cast<Double_t*>(ti->var)=*(Double_t *)this->Find(ti->name)->GetValuePointer(); + if (this->Find(key)) { + *static_cast<Double_t*>(ti->var)=*(Double_t *)this->Find(key)->GetValuePointer(); } else { - cout << "*** ERROR!!! Could not find " << ti->name << " in the list of variables! ***" << endl; + cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; } this_cnt=1; break; case (kInt) : - if (this->Find(ti->name)) { - *static_cast<Int_t*>(ti->var)=*(Int_t *)this->Find(ti->name)->GetValuePointer(); + if (this->Find(key)) { + *static_cast<Int_t*>(ti->var)=*(Int_t *)this->Find(key)->GetValuePointer(); } else { - cout << "*** ERROR!!! Could not find " << ti->name << " in the list of variables! ***" << endl; + cout << "*** ERROR!!! Could not find " << key << " in the list of variables! ***" << endl; } this_cnt=1; break; default: - Error("THcParmList","Invalid type to read %s",ti->name); + Error("THcParmList","Invalid type to read %s",key); break; } } if (this_cnt<=0) { if ( !ti->optional ) { - Fatal("THcParmList","Could not find %s in database!",ti->name); + Fatal("THcParmList","Could not find %s in database!",key); } } cnt += this_cnt; diff --git a/src/THcParmList.h b/src/THcParmList.h index 9cd2c73..5ca753d 100644 --- a/src/THcParmList.h +++ b/src/THcParmList.h @@ -35,7 +35,7 @@ public: TextList->Remove(name); } - Int_t LoadParmValues(const DBRequest* list); // assign values to the variables in list + Int_t LoadParmValues(const DBRequest* list, const char* prefix=""); // assign values to the variables in list private: -- GitLab