--- myst: substitutions: bloc: python: 1-4,6-13 cpp: 3-5,7-10 console: python: 7-19 cpp: 9-21 --- # Merging two DataServer ```{warning} This section is discussing the merging of two {{tds}} not their concatenation. The first operation consists in adding new attributes from an existing {{tds}} 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 **{{tds}}** 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 {{tds}} 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 {{tds}} **tds1** and **tds2** respectively located in the ASCII files `tds1.dat` and `tds2.dat`. Another example is also provided in [](#use_cases_macro_dataserver_merge). Data file `tds1.dat` {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/references/dataserver/tds1.dat\n" + ":language: none\n" + "```" }} Data file `tds2.dat` {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/references/dataserver/tds2.dat\n" + ":language: none\n" + "```" }} Both {{tds}} incorporate 9 patterns. These 2 {{ascii}} files must be loaded in 2 {{tds}} (cf [](#dataserver_data_import_from_ascii)), the merging being done by calling the `merge` method of the first {{tds}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/dataserver/data/" + language + "/dataserverMergeForOut." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc[language] + "\n" + "```" }} Thus, the object `tds1` also contains the attributes of the second {{tds}} `tds2` {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/dataserver/data/" + language + "/dataserverMergeForOut.log\n" + ":language: none\n" + ":lines: " + console[language] + "\n" + "```" }} ```{admonition} Summary: Merging two {{tds}} - `merge` ( `TDataServer` \*tds2, const char\* varexpinput="\*") Adds the attributes of the {{tds}} *tds2* to the current {{tds}}. 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. ```