2.3.5. Merging two DataServer

Warning

This section is discussing the merging of two TDataServer not their concatenation. The first operation consists in adding new attributes from an existing TDataServer into another existing one, while the seconds consists in adding the content of two TTree object with the exact same structure. For the merging operation, a specific method TDataServer::merge has been written, while for the concatenation, the interested user is invited to look at the TChain::Merge method from ROOT.

It is sometimes necessary to merge two TDataServer to form a single one. Since the merging is done line by line, one has to check that both objects contain the same number of patterns. In Uranie-version older than 3.10.0 it was assumed that the patterns were exactly stored in the same order. Now the method is looking for the iterator of both TDataServer objects and it checks that both iterators contain the same value all along (not necessary in the same order, for instance when dealing with distributed computations). If the iterators are not found or if some iterator’s values are found in one iterator but not the other (possible in some rare cases such as OAT sampling), the merging is done line-by-line and a warning is displayed.

This operation is common when you want to build a surface response between output variables Y and predictors X and these data are located in two different files.

Warning

The 2 objects must have the same number of patterns.

Let’s take a simple example. Assuming that we have 2 TDataServer tds1 and tds2 respectively located in the ASCII files tds1.dat and tds2.dat. Another example is also provided in Macro “dataserverMerge.C”.

Data file tds1.dat

#COLUMN_NAMES: x| dy| z| theta
#COLUMN_TITLES: x_{n}| "#delta y"| ""| #theta
#COLUMN_UNITS: N| Sec| KM/Sec| M^{2}

1 1 11 11
1 2 12 21
1 3 13 31
2 1 21 12
2 2 22 22
2 3 23 32
3 1 31 13
3 2 32 23
3 3 33 33

Data file tds2.dat

#COLUMN_NAMES: x2| y| u| ua

1 1 102 11
1 2 104 12
1 3 106 13
2 1 202 21
2 2 204 22
2 3 206 23
3 1 302 31
3 2 304 32
3 3 306 33

Both TDataServer incorporate 9 patterns.

These 2 ASCII files must be loaded in 2 TDataServer (cf Import data from an ASCII file), the merging being done by calling the merge method of the first TDataServer

    TDataServer * tds1 = new TDataServer();
    TDataServer * tds2 = new TDataServer();

    tds1->fileDataRead("tds1.dat");
    tds2->fileDataRead("tds2.dat");

    tds1->merge(tds2);

Thus, the object tds1 also contains the attributes of the second TDataServer tds2

**************************************************************
*    Row   * tds * x. * dy * z. * theta * x2 * y. * u.u * ua *
**************************************************************
*        0 *   1 *  1 *  1 * 11 *    11 *  1 *  1 * 102 * 11 *
*        1 *   2 *  1 *  2 * 12 *    21 *  1 *  2 * 104 * 12 *
*        2 *   3 *  1 *  3 * 13 *    31 *  1 *  3 * 106 * 13 *
*        3 *   4 *  2 *  1 * 21 *    12 *  2 *  1 * 202 * 21 *
*        4 *   5 *  2 *  2 * 22 *    22 *  2 *  2 * 204 * 22 *
*        5 *   6 *  2 *  3 * 23 *    32 *  2 *  3 * 206 * 23 *
*        6 *   7 *  3 *  1 * 31 *    13 *  3 *  1 * 302 * 31 *
*        7 *   8 *  3 *  2 * 32 *    23 *  3 *  2 * 304 * 32 *
*        8 *   9 *  3 *  3 * 33 *    33 *  3 *  3 * 306 * 33 *
**************************************************************

Summary: Merging two TDataServer

  • merge ( TDataServer *tds2, const char* varexpinput=”*”)

    Adds the attributes of the TDataServer tds2 to the current TDataServer. The method is checking for iterators and their content to perform the merging, as already stated above.

    If the second argument is precised, only the requested attributes of tds2 are added to the correct tds.