41#define INCLUDESTR "#include"
64#if __cplusplus < 201103L
65# define SMART_PTR auto_ptr
67# define SMART_PTR unique_ptr
75 TextList =
new Podd::Textvars;
78inline static bool IsComment(
const string& s, string::size_type
pos )
80 return (
pos != string::npos &&
pos < s.length() &&
81 (s[
pos] ==
'#' || s[
pos] ==
';' || s.substr(
pos,2) ==
"//") );
124 static const char*
const whtspc =
" \t";
126 ifstream ifiles[100];
129 ifiles[nfiles].open(fname);
130 if(ifiles[nfiles].is_open()) {
131 cout <<
"Opening parameter file: [" << nfiles <<
"] " << fname << endl;
136 static const char*
const here =
"THcParmList::LoadFromFile";
137 Error (here,
"error opening parameter file %s",fname);
144 Int_t currentindex = 0;
151 cout <<
"Reading Parameters for run " << RunNumber << endl;
157 string current_comment;
162 if(!getline(ifiles[nfiles-1],
line)) {
163 ifiles[nfiles-1].close();
171 pos =
line.find_first_not_of(whtspc);
176 char quotechar=
line[0];
177 if(quotechar ==
'"' || quotechar ==
'\'') {
179 line.erase(
line.find_first_of(quotechar));
181 line.erase(
line.find_first_of(whtspc));
184 ifiles[nfiles].open(
line.c_str());
185 if(ifiles[nfiles].is_open()) {
186 cout <<
"Opening parameter file: [" << nfiles <<
"] " <<
line << endl;
194 || (
start =
line.find_first_not_of( whtspc )) == string::npos
201 while( (
pos =
line.find_first_of(
"#;/",
pos+1)) != string::npos ) {
207 pos = current_comment.find_first_not_of(whtspc);
208 if(
pos!=string::npos &&
pos > 0 &&
pos < current_comment.length()) {
209 current_comment.erase(0,
pos);
215 pos =
line.find_last_not_of( whtspc );
216 assert(
pos != string::npos );
217 if(
pos != string::npos && ++
pos <
line.length() )
219 pos =
line.find_first_not_of(whtspc);
225 if(
line.compare(0,5,
"begin")==0 ||
226 line.compare(0,3,
"end")==0) {
227 cout <<
"Skipping: " <<
line << endl;
267 if(RunNumber>0 && nfiles==1) {
268 if(
line.find_first_not_of(
"0123456789-,")==string::npos) {
271 SMART_PTR<TObjArray> runnumarr( runnums.
Tokenize(
",") );
272 Int_t nranges=runnumarr->GetLast()+1;
276 for(
Int_t i=0;i<nranges;i++) {
279 if(RunNumber == runstr.
Atoi()) {
283 }
else if ((ind=runstr.
First(
'-'))>=0) {
287 if((RunNumber >=
start.Atoi()) && (RunNumber <=
end.Atoi())) {
297 cout <<
"WARNING: THcParmList::Load in database mode but first line is not" << endl;
298 cout <<
" a run number or run number range. Parameter definitions" << endl;
299 cout <<
" will be ignored until a run number or range is specified." << endl;
304 if(!InRunRange)
continue;
307 Int_t valuestartpos=0;
309 if((
pos=
line.find_first_of(
'='))!=string::npos) {
310 strcpy(varname, (
line.substr(0,
pos)).c_str());
311 valuestartpos =
pos+1;
316 if(
line[valuestartpos] ==
'"' ||
line[valuestartpos] ==
'\'') {
317 quotechar =
line[valuestartpos++];
334 string varnames(varname);
340 TString values((
line.substr(valuestartpos)).c_str());
347 for(
Int_t i=0;(ttype==0&&i<nvals);i++) {
380 Int_t newlength = currentindex + nvals;
383 string existingcomment;
384 existingcomment.assign(existingvar->
GetTitle());
385 if(!existingcomment.empty()) {
386 current_comment.assign(existingcomment);
390 if(newlength > existinglength ||
391 (existingtype ==
kInt && ttype > 0)) {
392 if(newlength < existinglength) newlength = existinglength;
394 if(ttype>0 || existingtype ==
kDouble) {
399 for(
Int_t i=0;i<existinglength;i++) {
400 fp[i] = existingp[i];
402 }
else if(existingtype ==
kInt) {
404 for(
Int_t i=0;i<existinglength;i++) {
405 fp[i] = existingp[i];
408 cout <<
"Whoops!" << endl;
410 }
else if(existingtype ==
kInt) {
412 ip =
new Int_t[newlength];
414 for(
Int_t i=0;i<existinglength;i++) {
415 ip[i] = existingp[i];
418 cout <<
"Whoops!" << endl;
421 for(
Int_t i=0;i<nvals;i++) {
423 if(newtype ==
kInt) {
424 ip[currentindex+i] = valstr.
Atoi();
427 fp[currentindex+i] = valstr.
Atof();
430 (
"temp",valstr.
Data(),
false,
this,
nullptr);
431 fp[currentindex+i] = formula->
Eval();
436 currentindex += nvals;
440 }
else if (existingtype ==
kInt) {
444 size_t buflen = strlen(varname) + 20;
445 char *arrayname=
new char [buflen];
446 snprintf(arrayname,buflen,
"%s[%d]",varname,newlength);
447 if(newtype ==
kInt) {
448 Define(arrayname, current_comment.c_str(), *ip);
450 Define(arrayname, current_comment.c_str(), *fp);
455 if(ttype == 0 && existingtype ==
kInt) {
457 for(
Int_t i=0;i<nvals;i++) {
459 existingp[currentindex+i] = valstr.
Atoi();
463 for(
Int_t i=0;i<nvals;i++) {
466 existingp[currentindex+i] = valstr.
Atof();
469 (
"temp",valstr.
Data(),
false,
this,
nullptr);
470 existingp[currentindex+i] = formula->
Eval();
475 currentindex += nvals;
478 if(currentindex !=0) {
479 cout <<
"currentindex=" << currentindex <<
" shouldn't be!" << endl;
482 ip =
new Int_t[nvals];
486 for(
Int_t i=0;i<nvals;i++) {
489 ip[i] = valstr.
Atoi();
492 fp[i] = valstr.
Atof();
495 (
"temp",valstr.
Data(),
false,
this,
nullptr);
496 fp[i] = formula->
Eval();
501 currentindex = nvals;
503 size_t buflen = strlen(varname)+20;
504 char *arrayname=
new char [buflen];
505 snprintf(arrayname,buflen,
"%s[%d]",varname,nvals);
507 Define(arrayname, current_comment.c_str(), *ip);
509 Define(arrayname, current_comment.c_str(), *fp);
548 const DBRequest *ti = list;
552 if( !prefix ) prefix =
"";
554 while ( ti && ti->name ) {
555 string keystr(prefix); keystr.append(ti->name);
556 const char* key = keystr.c_str();
559 if(this->
Find(key)) {
568 this_cnt =
GetArray(key,
static_cast<Int_t*
>(ti->var),ti->nelem);
571 Error(
"THcParmList",
"Invalid type to read %s",key);
583 cout <<
"*** ERROR!!! Type Mismatch " << key << endl;
593 cout <<
"*** WARNING!!! Rounded " << key <<
" to nearest integer " << endl;
595 cout <<
"*** ERROR!!! Type Mismatch " << key << endl;
600 Error(
"THcParmList",
"Invalid type to read %s",key);
608 if(ti->type == kString) {
609 *((
string*)ti->var) = string(
value);
610 }
else if (ti->type == kTString) {
613 Error(
"THcParmList",
"No conversion for strings: %s",key);
618 if ( !ti->optional ) {
619 string msg = string(
"Could not find `") + key +
"` in database!";
620 throw std::runtime_error(
"<THcParmList::LoadParmValues>: " + msg);
652 if(!var)
return(
cnt);
655 cout <<
"*** ERROR: " << attrC <<
" has unsupported type " << ty << endl;
661 cout <<
"*** ERROR: requested " <<
size <<
" elements of " << attrC <<
662 " which has only " << sz <<
" elements" << endl;
663 cout <<
"Cannot continue. Must fix database. Terminating program." << endl;
666 }
else if(
size < sz) {
667 cout <<
"*** WARNING: requested " <<
size <<
" elements of " << attrC <<
668 " which has length " << sz << endl;
672 if(ty ==
kDouble &&
typeid(array[0]) ==
typeid(
Int_t)) {
674 cout <<
"*** WARNING!!! Rounded " << attrC <<
" elements to nearest integer " << endl;
701 const char* connection_string =
gSystem->
Getenv(
"CCDB_CONNECTION");
703 return(OpenCCDB(runnum,connection_string));
705Int_t THcParmList::OpenCCDB(
Int_t runnum,
const char* connection_string)
709 std::string s (connection_string);
710 CCDB_obj =
new SQLiteCalibration(runnum);
712 if(!result)
return -1;
713 cout <<
"Opened " << s <<
" for run " << runnum << endl;
716Int_t THcParmList::CloseCCDB()
721Int_t THcParmList::LoadCCDBDirectory(
const char* directory,
727 std::string dirname (directory);
729 if(dirname[dirname.length()-1]!=
'/') {
732 Int_t dirlen=dirname.length();
734 vector<string> namepaths;
735 CCDB_obj->GetListOfNamepaths(namepaths);
736 for(
UInt_t iname=0;iname<namepaths.size();iname++) {
737 std::string varname (namepaths[iname]);
738 if(varname.compare(0,dirlen,dirname) == 0) {
739 varname.replace(0,dirlen,prefix);
745 Assignment* assignment = CCDB_obj->GetAssignment(namepaths[iname],
true);
746 ConstantsTypeColumn::ColumnTypes ccdbtype=assignment->GetValueType(0);
747 Int_t ccdbncolumns=assignment->GetColumnsCount();
748 Int_t ccdbnrows=assignment->GetRowsCount();
749 std::string title = assignment->GetTypeTable()->GetComment();
752 if(ccdbncolumns == 1) {
757 sprintf(sizestring,
"[%d]",ccdbnrows);
758 std::string size_str (sizestring);
759 std::string varnamearray (varname);
760 varnamearray.append(size_str);
763 if(ccdbtype==ConstantsTypeColumn::cIntColumn) {
764 vector<vector<int> >
data;
765 CCDB_obj->GetCalib(data, namepaths[iname]);
773 ip[row] =
data[row][0];
775 Define(varnamearray.c_str(), title.c_str(), *ip);
777 }
else if (ccdbtype==ConstantsTypeColumn::cDoubleColumn) {
778 vector<vector<double> >
data;
779 CCDB_obj->GetCalib(data, namepaths[iname]);
787 fp[row] =
data[row][0];
789 Define(varnamearray.c_str(), title.c_str(), *fp);
790 }
else if (ccdbtype==ConstantsTypeColumn::cStringColumn) {
792 cout << namepaths[iname] <<
": Only first element of CCDB string array loaded." << endl;
794 vector<vector<string> >
data;
795 CCDB_obj->GetCalib(data, namepaths[iname]);
798 cout << namepaths[iname] <<
": Unsupported CCDB data type: " << ccdbtype << endl;
801 cout << namepaths[iname] <<
": Multicolumn CCDB variables not supported" << endl;
size_t size(const MatrixT &matrix)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
ClassImp(VDC::AnalyticTTDConv) using namespace std
static bool IsComment(const string &s, string::size_type pos)
R__EXTERN TSystem * gSystem
virtual Int_t RemoveName(const char *name)
virtual void PrintFull(Option_t *opt="") const
THaVar * Define(const char *name, const Byte_t &var, const Int_t *count=nullptr)
virtual THaVar * Find(const char *name) const
const void * GetValuePointer() const
A list parameters and their values.
Int_t ReadArray(const char *attrC, T *array, Int_t size)
Dictionary of string parameters.
Podd::Textvars * TextList
Int_t GetArray(const char *attr, Int_t *array, Int_t size)
Read in a set of Int_t's in to a C-style array.
const char * GetString(const std::string &name) const
virtual void Load(const char *fname, Int_t RunNumber=0)
Load the parameter cache by reading a CTP style parameter file.
Int_t AddString(const std::string &name, const std::string &value)
virtual void PrintFull(Option_t *opt="") const
Print all the numeric parameter desciptions and value and text parameters.
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
const char * GetTitle() const override
TObject * At(Int_t idx) const override
Int_t GetLast() const override
virtual void Error(const char *method, const char *msgfmt,...) const
Ssiz_t First(char c) const
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual const char * Getenv(const char *env)