13.7.11. Macro “relauncherCodeMultiTypeKeyEmptyVectors.C

13.7.11.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Producing outputs, with a Key format, obtained by doing:

multitype -mtKey -empty

Unlike what’s done to in Macro “relauncherCodeMultiTypeKey.C”, the “-empty” allows the code to generate empty vectors and not only vectors whose size would be between 1 and 15 elements. The resulting output file used is a key-format one in a condensate form, named _output_multitype_mt_Key_condensate_.dat looks like:

w1 = nine
v1 = [ -0.512095,0.039669,-1.3834,1.37667,0.220672,0.633267,1.37027,-0.765636 ]
v2 = [ 14.1981,14.0855,10.7848,9.45476,9.17308,6.60804,10.0711,14.1761,10.318,12.5095,15.6614,10.3452,9.41101,7.47887 ]
f1 = 32.2723
w2 = eight

13.7.11.2. Macro Uranie

    TDataServer *tds = new TDataServer("foo", "multitype usecase");

    TCanvas *Can = new TCanvas("Can","Can",10,10,1000,800);
    TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); 

    // Create the TDataServer and create the seed attribute
    tds->addAttribute( new TUniformDistribution("seed",0,100000));

    //Create DOE
    TSampling *tsam = new TSampling(tds,"lhs",100);
    tsam->generateSample();

    // Create output attribute pointers
    TAttribute *w1 = new TAttribute("w1", TAttribute::kString);
    TAttribute *w2 = new TAttribute("w2", TAttribute::kString);
    TAttribute *v1 = new TAttribute("v1", TAttribute::kVector);
    TAttribute *v2 = new TAttribute("v2", TAttribute::kVector);
    TAttribute *f1 = new TAttribute("f1");

    // Create the input files
    TFlatScript inputFile("multitype_input.dat");
    inputFile.setInputs(1, tds->getAttribute("seed"), "seed");    

    // Create the output files
    TKeyResult outputFile("_output_multitype_mt_Key_condensate_.dat");
    outputFile.addOutput(w1, "w1");
    outputFile.addOutput(v1, "v1");
    outputFile.addOutput(v2, "v2");
    outputFile.addOutput(f1, "f1");
    outputFile.addOutput(w2, "w2");
    outputFile.setVectorProperties("[",",","]");

    // Create the user's evaluation function
    TCodeEval eval("multitype -mtKey -empty");
    eval.addInputFile(&inputFile); // Add the input file
    eval.addOutputFile(&outputFile); // Add the output file

    //Create the runner
    TSequentialRun runner(&eval);

    // Start the slaves
    runner.startSlave();                                           
    if (runner.onMaster())
    {

        // Create the launcher
        TLauncher2 lanceur(tds, &runner);
        lanceur.solverLoop();

        // Stop the slave processes
        runner.stopSlave();
        
    }        

    //Produce control plot
    pad->Draw(); 
    pad->Divide(1,2);
    pad->cd(1);
    tds->getTuple()->SetLineColor(2); tds->getTuple()->SetLineWidth(2);
    tds->Draw("size__v1");
    pad->cd(2);
    tds->Draw("size__v2");

The beginning of the code is pretty common to the macro already discussed in Macro Uranie. Apart from the command difference discussed in the objective above through the “-empty” argument, the main difference with previous macro is the way the output file is declared. Despite from changing the name, the vector properties are set by calling the setVectorProperties method to emphasize how to read the information.

    // Create the output files
    TKeyResult outputFile("_output_multitype_mt_Key_condensate_.dat");
    outputFile.addOutput(w1, "w1");
    outputFile.addOutput(v1, "v1");
    outputFile.addOutput(v2, "v2");
    outputFile.addOutput(f1, "f1");
    outputFile.addOutput(w2, "w2");
    outputFile.setVectorProperties("[",",","]");

Apart from this, the code is smooth and the final results one can be interested in the size of the vectors produced when empty vectors are allowed. This is produced though the following lines, and the resulting plots are shown in Figure 13.54.

    TCanvas *Can = new TCanvas("Can","Can",10,10,1000,800);
    TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); 
    //Produce control plot
    pad->Draw(); 
    pad->Divide(1,2);
    pad->cd(1);
    tds->getTuple()->SetLineColor(2); tds->getTuple()->SetLineWidth(2);
    tds->Draw("size__v1");
    pad->cd(2);
    tds->Draw("size__v2");

If the output file was not properly formatted, then one can have issues with this specific case (empty vectors). The consequences are shown in Macro “relauncherCodeMultiTypeKeyEmptyVectorsAsFailure.C”.

13.7.11.3. Graph

../../_images/relauncherCodeMultiTypeKeyEmptyVectors.png

Figure 13.54 Graph of the macro “relauncherCodeMultiTypeKeyEmptyVectors.C”