diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx index 971fc4c3f401ff82cc76688ae3f37b55c717625f..36ae845b6f33ca7ec78d0d42f09607351c5b02f9 100644 --- a/src/THcHodoscope.cxx +++ b/src/THcHodoscope.cxx @@ -292,27 +292,53 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date ) Int_t plen=strlen(parname); fNPaddle = new Int_t [fNPlanes]; - DefineArray("scin_%s_nr",fPlaneNames,fNPlanes,&fNPaddle[0]); + fSpacing = new Double_t [fNPlanes]; + fCenter = new Double_t* [fNPlanes]; + + // An alternate way to get these variables + // Can add Xscin_P_center when LoadParmValues supports arrays + + prefix[0]=tolower(GetApparatus()->GetName()[0]); + // + prefix[1]='\0'; - if (fDebug>=1) cout <<"Testing scin_nr "; for(Int_t i=0;i<fNPlanes;i++) { - if (fDebug>=1) cout << " "<<fNPaddle[i]; + + DBRequest list[]={ + {Form("scin_%s_nr",fPlaneNames[i]), &fNPaddle[i], kInt}, + {0} + }; + gHcParms->LoadParmValues((DBRequest*)&list,prefix); } - if (fDebug>=1) cout <<endl; - fSpacing = new Double_t [fNPlanes]; - DefineArray("scin_%s_spacing",fPlaneNames,fNPlanes,&fSpacing[0]); - if (fDebug>=1) cout <<"Testing scin_spacing "; for(Int_t i=0;i<fNPlanes;i++) { - if (fDebug>=1) cout << " " << fSpacing[i]; + fCenter[i] = new Double_t[fNPaddle[i]]; + DBRequest list[]={ + {Form("scin_%s_spacing",fPlaneNames[i]), &fSpacing[i], kDouble}, + {Form("scin_%s_center",fPlaneNames[i]), fCenter[i], kDouble, fNPaddle[i]}, + {0} + }; + gHcParms->LoadParmValues((DBRequest*)&list,prefix); } - if (fDebug>=1) cout << endl; + if(fDebug>=1) { + cout << "Plane: " << " nr spacing" << endl; + for(Int_t i=0;i<fNPlanes;i++) { + cout << fPlaneNames[i] << " " << fNPaddle[i] << " " << fSpacing[i] <<endl; + for(Int_t ip=0;ip<fNPaddle[i];ip++) { + cout << " " << fCenter[i][ip]; + } + cout << endl; + } + } + +#if 0 fCenter = new Double_t* [fNPlanes]; for(Int_t i=0;i<fNPlanes;i++) { parname[plen] = '\0'; strcat(parname,fPlaneNames[i]); strcat(parname,"_center"); + cout << parname << endl; Double_t* p = (Double_t *)gHcParms->Find(parname)->GetValuePointer(); fCenter[i] = new Double_t [fNPaddle[i]]; cout << parname; @@ -322,8 +348,7 @@ Int_t THcHodoscope::ReadDatabase( const TDatime& date ) } if (fDebug>=1) cout << endl; } - - +#endif // GN added // reading variables from *hodo.param prefix[1]='\0'; diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index aa19cf192a11a732b822651d1e819bd14a7d0936..ba14aee947d30f0537a2f4b7b864db6e8faf566c 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -365,12 +365,10 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) // it is an array, use the appropriateinterface switch (ti->type) { case (kDouble) : - // this_cnt = GetArray(system,ti->name,static_cast<Double_t*>(ti->var), - // ti->expected,date); + this_cnt = GetArray(key,static_cast<Double_t*>(ti->var),ti->nelem); break; case (kInt) : - // this_cnt = GetArray(system,ti->name,static_cast<Int_t*>(ti->var), - //ti->expected,date); + this_cnt = GetArray(key,static_cast<Int_t*>(ti->var),ti->nelem); break; default: Error("THcParmList","Invalid type to read %s",key); @@ -412,6 +410,54 @@ Int_t THcParmList::LoadParmValues(const DBRequest* list, const char* prefix) return cnt; } +// READING AN ARRAY INTO A C-style ARRAY +//_____________________________________________________________________________ +Int_t THcParmList::GetArray(const char* attr, Int_t* array, Int_t size) +{ + // Read in a set of Int_t's in to a C-style array. + + return ReadArray(attr,array,size); +} +//_____________________________________________________________________________ +Int_t THcParmList::GetArray(const char* attr, Double_t* array, Int_t size) +{ + // Read in a set of Double_t's in to a vector. + + return ReadArray(attr,array,size); +} + +//_____________________________________________________________________________ +template<class T> +Int_t THcParmList::ReadArray(const char* attrC, T* array, Int_t size) +{ + // Copy values from parameter store to array + // No resizing is done, so only 'size' elements may be stored. + + Int_t cnt=0; + + THaVar *var = Find(attrC); + if(!var) return(cnt); + VarType ty = var->GetType(); + if( ty != kInt && ty != kDouble) { + cout << "*** ERROR: " << attrC << " has unsupported type " << ty << endl; + return(cnt); + } + Int_t sz = var->GetLen(); + const void *vp = var->GetValuePointer(); + if(size != sz) { + cout << "*** WARNING: requested " << size << " elements of " << attrC << + " which has length " << sz << endl; + } + if(size<sz) sz = size; + for(cnt=0;cnt<sz;cnt++) { + if(ty == kInt) { + array[cnt] = ((Int_t*)vp)[cnt]; + } else + array[cnt] = ((Double_t*)vp)[cnt]; + } + return(cnt); +} + //_____________________________________________________________________________ void THcParmList::PrintFull( Option_t* option ) const { diff --git a/src/THcParmList.h b/src/THcParmList.h index 5ca753dd2fa629f015352f7309a2752e15838581..96a4d1aa252d5a1c6793b64d837f36c1e796e3ce 100644 --- a/src/THcParmList.h +++ b/src/THcParmList.h @@ -37,10 +37,16 @@ public: Int_t LoadParmValues(const DBRequest* list, const char* prefix=""); // assign values to the variables in list + Int_t GetArray(const char* attr, Int_t* array, Int_t size); + Int_t GetArray(const char* attr, Double_t* array, Int_t size); + private: THaTextvars* TextList; + template<class T> + Int_t ReadArray(const char* attrC, T* array, Int_t size); + protected: ClassDef(THcParmList,0) // List of analyzer global parameters