MantisBT - JANA
View Issue Details
0000455JANABugpublic2015-02-28 19:332015-06-05 16:23
sdobbs 
davidl 
highmajoralways
resolvedfixed 
0000455: Wrong ordering when loading CCDB tables with multiple columns
When loading tables with multiple columns in JANA, the columns are loaded ordered by their column labels alphabetically, instead of the order they are stored in the CCDB.

This problem came up when loading the CCDB table /BCAL/attenuation_parameters, which has three columns, named "L1", "L2", and "L0", respectively. When loading the table in DBCALPoint_factory, the values were loaded in the order "L0", "L1", "L2".
This problem is illustrated in the plugin in the following location:

  /w/halld-scifs1a/home/sdobbs/plugins/CCDBTest

compared to the output of

  ccdb cat /BCAL/attenuation_parameters

Sample outputs are attached.
Dmitry pointed out that the problem lies in this function:

//-------------
template<class T> bool JCalibration::Get(string namepath, vector< vector<T> > &vals, int event_number)
{
    vector< map<string, string> >svals;
    bool res = GetCalib(namepath, svals, event_number);
  
    // copying them into the vals map.
    vals.clear();
    for(unsigned int i=0; i<svals.size(); i++){
        map<string,string>::const_iterator iter;
  ...
    }
    
    return res;
}

Since this function gets the calibration values as a map instead of a vector<vector<>>, and maps in C++ are ordered by key name, this is where this mis-ordering comes from.
No tags attached.
txt bug_output.txt (32,538) 2015-02-28 19:33
https://halldweb1.jlab.org/mantisbt/file_download.php?file_id=4&type=bug
Issue History
2015-02-28 19:33sdobbsNew Issue
2015-02-28 19:33sdobbsFile Added: bug_output.txt
2015-03-02 10:17davidlNote Added: 0000629
2015-06-05 16:23davidlNote Added: 0000640
2015-06-05 16:23davidlStatusnew => resolved
2015-06-05 16:23davidlResolutionopen => fixed
2015-06-05 16:23davidlAssigned To => davidl

Notes
(0000629)
davidl   
2015-03-02 10:17   
This is a feature designed into the API for JANA. The intent is to minimize the number of virtual methods that must be implemented in a class inheriting from JCalibration. The design was to allow one to access a table that had columns defined by name using:

   Get(string name path, vector< map<string, T> > &vals, int event_number)

And columns defined by position using:

   Get(string name path, vector< vector<T> > &vals, int event_number)


The idea was that if you had a table where the columns did not have names and were only defined by position, then the underlying DB was responsible for maintaining the ordering and one would request the table using the "vector" form of Get(). If had a table with named columns, then you should be using the "map" form of Get() which gives you the values indexed by column name. The only way to fix this so that one may use the "vector" form with named columns and still preserve order is to add another pair of GetCalib virtual methods to JCalibration and have CCDB implement those.
(0000640)
davidl   
2015-06-05 16:23   
This was implemented in revision 2334 and will appear in JANA 0.7.3. It also required changes to DCalibrationCCDB that exists in the DANA library in sim-recon. Those changes have already been checked in and checked that they still compile with JANA 0.7.2 this shouldn't require a synchronous upgrade between JANA and sim-recon.