From 47ef7bcaf74d33b1d9ac9a768887fe6e1c26b302 Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Mon, 21 Apr 2014 13:32:12 -0400 Subject: [PATCH] Experimental CCDB support improvements. Title now copied to THcParmList variable String variables copied. (Only first element of string array copied) Parameter created as int or double depending on CCDB table type Multiple column tables ignored. --- src/THcParmList.cxx | 80 ++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index 60e1f2b..0f6f9d4 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -628,39 +628,65 @@ Int_t THcParmList::LoadCCDBDirectory(const char* directory, // To what extent is there duplication here with Load() method? - // Retrieve the data as floats - vector<vector<double> > data; - CCDB_obj->GetCalib(data, namepaths[iname]); - for(UInt_t row=0; row<data.size(); row++) { - for(UInt_t col=0;col<data[0].size(); col++) { - cout << data[row][col] << "\t"; - } - cout << endl; - } - - if(data[0].size()==1) { // Only handle single column tables - // Could stuff 2d arrays in, and assume that the application knows - // the number of columns. Then the matrix stuff would just need to - // see if the variable exists, then copy the data into the right kind - // of structure instead of reading from the recon files. + // Retrieve assignment + Assignment* assignment = CCDB_obj->GetAssignment(namepaths[iname], true); + ConstantsTypeColumn::ColumnTypes ccdbtype=assignment->GetValueType(0); + Int_t ccdbncolumns=assignment->GetTypeTable()->GetNColumns(); + Int_t ccdbnrows=assignment->GetTypeTable()->GetNRows(); + std::string title = assignment->GetTypeTable()->GetComment(); + + // Only load single column tables + if(ccdbncolumns == 1) { + THaVar* existingvar=Find(varname.c_str()); - if(existingvar) { - // Does the array of data need to deleted too? - RemoveName(varname.c_str()); - } - Double_t* fp = new Double_t[data.size()]; - for(UInt_t row=0;row<data.size(); row++) { - fp[row] = data[row][0]; - } // Need to append [size] to end of varname char sizestring[20]; - sprintf(sizestring,"[%d]",(Int_t) data.size()); + sprintf(sizestring,"[%d]",ccdbnrows); std::string size_str (sizestring); varname.append(size_str); - Define(varname.c_str(), "comment", *fp); - } - } + // Select data type + if(ccdbtype==ConstantsTypeColumn::cIntColumn) { + vector<vector<int> > data; + CCDB_obj->GetCalib(data, namepaths[iname]); + + if(existingvar) { + RemoveName(varname.c_str()); + } + + Int_t* ip = new Int_t[data.size()]; + for(UInt_t row=0;row<data.size(); row++) { + ip[row] = data[row][0]; + } + Define(varname.c_str(), title.c_str(), *ip); + + } else if (ccdbtype==ConstantsTypeColumn::cDoubleColumn) { + vector<vector<double> > data; + CCDB_obj->GetCalib(data, namepaths[iname]); + + if(existingvar) { + RemoveName(varname.c_str()); + } + + Double_t* fp = new Double_t[data.size()]; + for(UInt_t row=0;row<data.size(); row++) { + fp[row] = data[row][0]; + } + Define(varname.c_str(), title.c_str(), *fp); + } else if (ccdbtype==ConstantsTypeColumn::cStringColumn) { + if(ccdbnrows > 1) { + cout << namepaths[iname] << ": Only first element of CCDB string array loaded." << endl; + } + vector<vector<string> > data; + CCDB_obj->GetCalib(data, namepaths[iname]); + AddString(varname, data[0][0]); + } else { + cout << namepaths[iname] << ": Unsupported CCDB data type: " << ccdbtype << endl; + } + } else { + cout << namepaths[iname] << ": Multicolumn CCDB variables not supported" << endl; + } + } } return 0; } -- GitLab